diff --git a/master.py b/master.py index dc86ca4..003d7e6 100644 --- a/master.py +++ b/master.py @@ -2,9 +2,13 @@ import subprocess from network import * from scapy import * +from sniff import * +import time if __name__ == "__main__": if os.getuid() != 0: print "Please run me as root!" sys.exit() - print wifi_scan() + start_sniffing() + init_scan() + time.sleep(3600) diff --git a/scans.py b/scans.py index 6c9b1cf..485e7c0 100644 --- a/scans.py +++ b/scans.py @@ -15,8 +15,6 @@ def slow_syn_scan(host, ports): if(resp.getlayer(TCP).flags == 0x12): send_rst = sr(IP(dst=host)/TCP(sport=srcPort,dport=dstPort,flags="R"),timeout=1,verbose=0) print host + ":" + str(dstPort) + " is open." - #elif (resp.getlayer(TCP).flags == 0x14): - #print host + ":" + str(dstPort) + " is closed." elif(resp.haslayer(ICMP)): if(int(resp.getlayer(ICMP).type)==3 and int(resp.getlayer(ICMP).code) in [1,2,3,9,10,13]): print host + ":" + str(dstPort) + " is filtered (silently dropped) but host is up." @@ -33,6 +31,31 @@ def syn_scan(target, ports): rep.append(r.sprintf("%sport%")) return rep + +#Scan all networks in wifi range and return an array of all of them. +def wifi_scan(): + proc = subprocess.Popen(["iwlist wlan0 scan | grep ESSID | sort | uniq | awk -F \"\\\"\" \'{print $2}\'"], stdout=subprocess.PIPE, shell=True) + networks = proc.stdout.read()[:-1].split('\n') + networks2 = [] + for item in networks: + valid = False + for char in item: + if char != '\\' and char != '0' and char != 'x': + valid = True + else: + if valid == True: + valid = True + else: + valid = False + if item == "" or valid == False: + networks2.append("Hidden Network") + else: + networks2.append(item) + return networks2 + + +def service_scan(): + pass #TESTING - syn scans first 500 ports (slow) #syn_scan("10.0.0.35", range(1,500)) diff --git a/sniff.py b/sniff.py index 59de605..67d33fb 100644 --- a/sniff.py +++ b/sniff.py @@ -1,6 +1,8 @@ from scapy.all import * import logging -import threading +import thread +import time +import datetime def log_packet(): pass #TODO log packet in another thread so database communication is not a bottleneck @@ -9,5 +11,23 @@ def cb(packet): # TODO decide what fields we want to pull out of the packet pass -def listen(filter=None, count=None): - sniff(prn=cb) +def listen(timeout=5): + while True: + try: + pkts = sniff(timeout=timeout) + ts = time.time() + st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') + wrpcap('/home/aces/pinyapwn/packets/{0}.pcap'.format(st), pkts) + except Exception as e: + print "failure" + print e + #print pkts + + +def start_sniffing(): + try: + thread.start_new_thread (listen, ()) + except Exception as e: + print "Thread creation failed" + print e +