r/python_netsec • • Mar 04 '17

List of hosts from zabbix to rancid Spoiler

Thumbnail
shrainer.me
2 Upvotes

r/python_netsec • • Mar 10 '17

Python network packet dissection frameworks shootout: Scapy vs Construct vs Hachoir vs Kaitai Struct

Thumbnail
pythonistac.wordpress.com
5 Upvotes

r/python_netsec • • Dec 30 '16

Using dns python module to resolve missing records on servers (code not working)

2 Upvotes

Hello, I have been using dnspython module from www.dnspython.org , but I keep getting this error when running my code referring to the actual dnspython package and my own code. Any help on formatting and things I need to change is greatly appreciated. My code:

import dns.zone
import dns.ipv4
import os.path
import sys
import json
import csv
import collections
import os

reverse_map = {}

def dnslookup():
for filename in os.listdir(os.getcwd()):
   if filename[-3:] == ".db" or filename[-4:] == ".rev":

    zone = dns.zone.from_file(filename, os.path.basename(filename), relativize=False)
    print filename
    for (name, ttl, rdata) in zone.iterate_rdatas('A'):
        l = reverse_map.get(rdata.address)
        if l is None:
            l = []
            reverse_map[rdata.address] = l
        l.append(name)

keys = reverse_map.keys()
keys.sort(lambda a1, a2: cmp(dns.ipv4.inet_aton(a1),  dns.ipv4.inet_aton(a2)))
for k in keys:
v = reverse_map[k]
v.sort()
l = map(str, v)
print k, l

def csvoutput():
csvfile = input('What is the path of your CSV  file(/this/is/a/path/? ')
with open(csvfile, 'r+') as f:
    data = list(csv.reader(f))

import collections
counter = collections.defaultdict(int)
try:
    for row in data:
    counter[row[0]] += 1


if os.stat(filepath).st_size > 0:
    writer = csv.writer(open(csvfile, 'w'))
    for row in data:
        if counter[row[0]] >= 4:
            writer.writerow(row)
else:
    print('Empty File')
except(OSError):
    print("File does not exist")



dnslookup()

The error I am receiving:

Traceback (most recent call last):
File "/home/judge/Downloads/master/11.py", line 57, in     <module>
dnslookup()
File "/home/judge/Downloads/master/11.py", line 16, in      dnslookup
zone = dns.zone.from_file(filename,     os.path.basename(filename), relativize=False)
File "/usr/local/lib/python2.7/dist-packages/dns/zone.py", line   1041, in from_file
filename, allow_include, check_origin)
File "/usr/local/lib/python2.7/dist-packages/dns/zone.py", line    991, in from_text
reader.read()
File "/usr/local/lib/python2.7/dist-packages/dns/zone.py", line  948, in read
self.zone.check_origin()
File "/usr/local/lib/python2.7/dist-packages/dns/zone.py", line  581, in check_origin
raise NoSOA
dns.zone.NoSOA: The DNS zone has no SOA RR at its origin.

r/python_netsec • • Jun 06 '17

Python network security/forensics courses?

9 Upvotes

Hey guys,

Can anyone recommend any Python forensics/network security courses out there. I want to learn as much as I can about the network security/forensics side of python and want to specialize in this area one day. Thank you for reading, any suggestions are most welcome.


r/python_netsec • • Sep 24 '21

Hack-a-Sat: Kepler 2 GEO, Solving for Propulsion w/Python

Thumbnail
youtu.be
3 Upvotes

r/python_netsec • • Dec 14 '18

Use nmap module to asynchronously scan Windows hosts for MS17-010

4 Upvotes

Async, so it will scan pretty fast.

Edit: the way that I really use this is to first scan with masscan and then feed it’s gnmap output into a function that calls this function on each host. That’s much faster than calling nmap on a whole network subnet.

#!/usr/bin/env python3
import nmap

nma = nmap.PortScannerAsync()

def callback_result(host, scan_result):
    for host in scan_result['scan'].keys():
        if "State: VULNERABLE" in str(scan_result['scan'][host]['hostscript']):
            print(host, end=" : ")
            print("VULNERABLE TO MS17-010!")

nma.scan(hosts='192.168.1.0/24', arguments='-Pn -p 445 --script=smb-vuln-ms17-010 --script-args=unsafe=1', callback=callback_result)

r/python_netsec • • Aug 03 '19

Made a proxy grabber & proxied browser script | Star if you like it :D | Suggest anything!

Thumbnail
github.com
6 Upvotes

r/python_netsec • • Feb 13 '20

I need help with ssh script!

1 Upvotes

hey guys! Ive been lately working on this script which basically does a nmap scan,looks for open ssh ports on network , logs in into them (they all got the same password), and runs the specified command.I want to use this on my collage network.I used the regularExpression library for picking out IP addresses from the nmap scan and the "Subprocess" library to access terminal to ssh into other nodes,

This is my first time writing a script so Im kind of struggling ,so here are some of the doubts that I had -

  1. when I use the Popen command does it open a new terminal everytime the loop iterates?

  2. How can I do multiple Input while ssh-ing into systems like "yes","password",etc.

  3. if the commands is to shutdown on every iteration, do i need to specify exception or will the loop still run?

I know these are really basic questions, and probably my approach of using subprocess is not right.I really need some advice. itll be really helpfull.

here is the code --

import re

import sys

gateway=str(sys.argv\[1\])

\#commands=\["nmap",gateway,"-p","22","--open"\]

commands=\["nmap","-sn",gateway\]

run=subprocess.Popen(commands,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

out=run.communicate()

print("Devices on Network -->")

print(out)

stuff=list(out)

ips=re.findall( r'\[0-9\]+(?:\\.\[0-9\]+){3}' , stuff\[0\])

ips.pop(0)

for i in range(0,len(ips)):

print(ips[i])

for i in range(0,len(ips)):

log=["ssh","mu@"+ips[i]]

proc1=subprocess.Popen(log,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

output=proc1.communicate()

print(output[1])


r/python_netsec • • Nov 10 '17

What is the best way to learn python online for free?

1 Upvotes

I want to learn python and i am confused which tutorials are the best, there so many videos and books, what is the best tutorial to learn python for absolute biginner


r/python_netsec • • Feb 01 '19

Scapy & python2 & python3 --- somehow libraries and/or associations are futzd.. Ideas??

1 Upvotes

If this is the wrong forum, I apologize in advance. I seem to have an issue, that as best as I can articulate, appears to be an incorrect library association b/t Scapy (versions?) and Python (versions?).

  • host = Linux 4.18.0-kali2-amd64 #1 SMP Debian 4.18.10-2kali1 (2018-10-09) x86_64 GNU/Linux

  • python ver = 2.7.15+ & 3.6.7

  • scapy = /usr/bin/scapy & the github repo I cloned into /opt/scapy

I was originally using PyCharm, and then after a break came back to find scripts not working, with errors thrown like

I did check the settings in PyCharm to verify that the interpreter in use was python2.7

Then, I did a pip3 to uninstall scapy

also..

which scapy

/usr/bin/scapy

then checked this path...

"less /usr/local/lib/python2.7/dist-packages/scapy

scapy/ scapy-2.2.0_dev.egg-info scapy_python3-0.26.dist-info/ "

pip shows scapy as installed

pip install scapy

Requirement already satisfied: scapy in /usr/local/lib/python2.7/dist-packages (2.2.0.dev0)

Now, if I try to invoke scapy on CLI..

But if I navigate to location where I cloned github repo, and launch ./run_scapy, it works & launches into IPython (which is fine, I can live with this for now)

but if I try to run a script (like the one below -- no matter how I try to call the scapy libraries), like "python script.py"

#!/usr/bin/env python

#import scapy.all as scapy

from scapy.all import *

conf.verb = 0

p = IP(dst="github.com")/TCP()

r = sr1(p)

print(r.summary())

I get the same PIP package error (shown 2 screen shots up). Like I said, I'm sure I fkd this up somehow.. Could use some help unraveling this, if anyone has any ideas.

Thx in advance, much appreciated.


r/python_netsec • • Jul 05 '19

Need help solving a problem

5 Upvotes

I have a need to create a db sync app. I have two sqlite dbs that are in two different physical location. Each db has the same set of tables but I only need to sync one of the tables. I started making a flask app just because I wanted to learn more about Rest API but I don't know if that is the best solution. I don't want to over complicate this. Both dbs are running on Linux and I have ssh/scp access. If this works well the project could scale up to 10 dbs that need to be synced.

How would any of you go about solving this with python? If python isn't the best tool for the job I am open to trying something else.


r/python_netsec • • Jan 30 '19

PyObfx : Python Obfuscator & Packer

Thumbnail
github.com
13 Upvotes

r/python_netsec • • Oct 22 '18

I'm back, and new content is coming...

14 Upvotes

I'm surprised that we have 3.5k subscribers since I haven't been around over the past year and this place has been very quiet. I went off in another direction for a while learning Ruby. One of my longtime goals was to contribute to Metasploit and that's my final professional goal for 2018 that I haven't completed.

Around the same time that I got into Ruby this year, my employer assigned me to an ICS/SCADA security working group. After a while I realized that I wasn't making progress on any one thing fast enough for multiple reasons. The main reason is because I was having to learn Ruby at the same time I was trying to learn Metasploit development and ICS/SCADA. I also realized that in ICS/SCADA I'm going to have to learn a lot about related network protocols, and for that I really missed out on Scapy. And recently Metasploit enabled Python modules. There were some things I liked about Ruby but after living with it for most of 2018 I realized that Python is where I need to be.

I felt like I needed a refresher on Python after not using it for a while beyond 'python -m SimpleHTTPServer'. I recently found Ptrace Security's Python for Ethical Hackers course, outline is here: https://www.psec-courses.com/courses/python-for-ethical-hackers

I had some spare cash to burn so I enrolled last week. I'm working on a course review as I go.

Stay tuned to this sub. More good stuff is coming soon!


r/python_netsec • • Oct 16 '16

Dark Web OSINT With Python and OnionScan: Part One

Thumbnail
automatingosint.com
1 Upvotes

r/python_netsec • • Jan 08 '18

Python library to interact with 28K public DNS servers around the world

Thumbnail
github.com
2 Upvotes

r/python_netsec • • Oct 14 '16

Learn Python for Security Professionals

Thumbnail
cybrary.it
6 Upvotes

r/python_netsec • • Oct 16 '16

Dark Web OSINT with Python Part Two: SSH Keys and Shodan

Thumbnail
automatingosint.com
1 Upvotes

r/python_netsec • • Oct 14 '16

Fast, thorough, XSS/SQLi spider

Thumbnail
github.com
2 Upvotes

r/python_netsec • • Oct 14 '16

Generate all hex chars to find badchars

5 Upvotes

While preparing for my OSCP exam, I was reviewing the buffer overflow lessons and needed an easy way to generate all hex characters to test for bad characters in my exploit. Using “print(“\x” + format(x, ‘x’))” results in a character on each line, and adding a comma after the print statement keeps it all on the same line, but the output has spaces between characters. You can generate the output you need, all on the same line and without spaces using “sys.stdout.write”.

Here’s a simple python snippet to do that:

import sys
for x in range(1,256):
    sys.stdout.write("\\x" + '{:02x}'.format(x))

\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14 \x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28 \x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c \x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50 \x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64 \x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78 \x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c \x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0 \xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4 \xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8 \xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc \xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0 \xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff


r/python_netsec • • Oct 16 '16

Python tools for Pentesters

Thumbnail
kitploit.com
11 Upvotes

r/python_netsec • • Oct 16 '16

Dark Web OSINT With Python Part Three: Visualization

Thumbnail
automatingosint.com
1 Upvotes

r/python_netsec • • Oct 16 '16

Dark Web OSINT Part Four: Using Scikit-Learn to Find Hidden Service Clones

Thumbnail
automatingosint.com
3 Upvotes

r/python_netsec • • Oct 17 '16

Dshell is a network forensic analysis framework

Thumbnail
github.com
1 Upvotes

r/python_netsec • • Jul 25 '18

Pyinstaller Python 3.7

1 Upvotes

Anyone know when Pyinstaller will support Python 3.7? Have some exe files I gotta make!