wrote out a new sniffing method that leans on airodump, which should be more robust than the approach i was using before
This commit is contained in:
parent
edace37836
commit
ddfe6db7bb
@ -1,8 +1,10 @@
|
|||||||
#! /usr/bin/python
|
#! /usr/bin/python
|
||||||
import packet_processer, reporter
|
import packet_processer, reporter, sniffer
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
packet_processer.sniff("walfa0", 200)
|
print(sniffer.run_cmd("echo 1"))
|
||||||
|
snfr = Sniffer("walfa0")
|
||||||
|
print(snfr.sniff(1))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
61
src/sniffer.py
Normal file
61
src/sniffer.py
Normal file
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user