diff --git a/src/main.py b/src/main.py index 110b638..51318bd 100755 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,10 @@ #! /usr/bin/python -import packet_processer, reporter +import packet_processer, reporter, sniffer def main(): - packet_processer.sniff("walfa0", 200) + print(sniffer.run_cmd("echo 1")) + snfr = Sniffer("walfa0") + print(snfr.sniff(1)) if __name__ == "__main__": main() \ No newline at end of file diff --git a/src/sniffer.py b/src/sniffer.py new file mode 100644 index 0000000..09dd93d --- /dev/null +++ b/src/sniffer.py @@ -0,0 +1,61 @@ +import subprocess +import string, random, csv + +def run_cmd(cmd, out=subprocess.PIPE): + # Just runs a command, supports changing the pipe n stuff + + proc = subprocess.Popen(cmd, stdout = out, stderr = subprocess.PIPE, shell=True) + proc.wait() + + if proc.stdout: + return (proc.stdout.read().decode(), proc.returncode) + else: + return (None, proc.returncode) + + + + +class Sniffer: + def __init__(self, interface_name): + self.ifname = interface_name + + tmp_folder = "".join(random.choice(string.ascii_letters) for _ in range(5)) + self.base_dir = f"/tmp/SUSTMP_{tmp_folder}" + + self.enable_monitor_mode() + self.create_dir( self.base_dir ) + + def enable_monitor_mode(self): + stdout, code = run_cmd( f"airmon-ng start {self.ifname}" ) + return code == 0 + + def disable_monitor_mode(self): + stdout, code = run_cmd( f"airmon-ng stop {self.ifname}" ) + return code == 0 + + def create_dir(self, base_dir): + stdout, code = run_cmd( f"mkdir -p {base_dir}" ) + return code == 0 + + + def sniff(self, time): + time = int(time+0.5) + dump_file = f"{self.base_dir}/cap-{ int(time.time()) }" + + stdout, code = run_cmd(f"airodump-ng --write {dump_file} --write-interval 1 --output-format csv walfa0") + if code != 0: + return code + + time.sleep(time+.1) # Give a bit of time for airodump to write + + stdout, code = run_cmd(f"killall -i airodump-ng") + + full_filepath = f"{dump_file}-01.csv" + + return self.parse_sniff(full_filepath) + + def parse_sniff(self, full_filepath): + with open(full_filepath,'r') as file: + return csv.DictReader(file) + +