From 50a3a3f05aeef2e17c0705751b6614eed442d4bc Mon Sep 17 00:00:00 2001 From: George Hughey Date: Mon, 24 Oct 2016 21:37:31 +0000 Subject: [PATCH] Integrated master and network --- cli.py | 5 +++++ master.py | 4 ++-- network.py | 22 +++++++++++++++++++--- packets/sniff.py | 33 --------------------------------- scans.py | 1 - 5 files changed, 26 insertions(+), 39 deletions(-) delete mode 100644 packets/sniff.py diff --git a/cli.py b/cli.py index 098cc95..c895a4e 100644 --- a/cli.py +++ b/cli.py @@ -4,6 +4,8 @@ import traceback import netifaces as ni import core +from sniff import * +from network import * from colorama import * from Tkinter import * @@ -25,6 +27,9 @@ def __init__(self): self.ctrlc = False ascii() print "Welcome to Pina Colada, a powerful Wifi Pineapple. Type \"help\" to see the list of available commands." + print "Packets are being stored in the packets directory." + start_sniffing() + init_network() def print_help(self, lst): it = iter(lst) diff --git a/master.py b/master.py index 2ceb122..a7eaed5 100644 --- a/master.py +++ b/master.py @@ -2,7 +2,7 @@ import subprocess from network import * from scapy import * -from packets/sniff import * +from sniff import * import time if __name__ == "__main__": @@ -10,5 +10,5 @@ print "Please run me as root!" sys.exit() start_sniffing() - init_scan() + init_network() time.sleep(3600) diff --git a/network.py b/network.py index ba29305..38922c2 100644 --- a/network.py +++ b/network.py @@ -51,10 +51,9 @@ def __init__(self): self.profile() self.connect() -def init_scan(): - thisComp = Network() +def begin_scan(thisComp, portLow, portHigh): for comp in thisComp.comps: - ports = syn_scan(comp.ip, (0,1000)) + ports = syn_scan(comp.ip, (portLow, portHigh)) ports = ','.join(ports) ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') @@ -70,3 +69,20 @@ def init_scan(): .format(st, network, network, st, network)) thisComp.conn.commit() thisComp.cur.close() + return thisComp + +def init_network(): + print "Initializing Network DB..." + thisComp = Network() + + try: + thread.start_new_thread(begin_scan, (thisComp, 22, 22)) + except Exception as e: + print "Thread creation failed :(" + print e + + + return thisComp + + + diff --git a/packets/sniff.py b/packets/sniff.py deleted file mode 100644 index dcef72c..0000000 --- a/packets/sniff.py +++ /dev/null @@ -1,33 +0,0 @@ -from scapy.all import * -import logging -import thread -import time -import datetime - -def log_packet(): - pass #TODO log packet in another thread so database communication is not a bottleneck - -def cb(packet): - # TODO decide what fields we want to pull out of the packet - pass - -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/pina-colada/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 - diff --git a/scans.py b/scans.py index 485e7c0..317935a 100644 --- a/scans.py +++ b/scans.py @@ -22,7 +22,6 @@ def slow_syn_scan(host, ports): #This is a fast syn scan. def syn_scan(target, ports): - print "Beginning Scan...\n" ans,unans = sr(IP(dst=target)/TCP(dport=ports),timeout=.1,verbose=0) rep = [] for s,r in ans: