Skip to content

Commit

Permalink
Created sniffing file and less basic framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ecthros committed Oct 8, 2016
1 parent 8ecc007 commit 84c4db7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
6 changes: 5 additions & 1 deletion master.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 25 additions & 2 deletions scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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))

Expand Down
26 changes: 23 additions & 3 deletions sniff.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 84c4db7

Please sign in to comment.