diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a55cc59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.yaml +__pycache__ \ No newline at end of file diff --git a/common/__init__.py b/common/__init__.py index e69de29..e3fa2b3 100644 --- a/common/__init__.py +++ b/common/__init__.py @@ -0,0 +1 @@ +# comment to be gittable \ No newline at end of file diff --git a/common/config.yaml b/common/config.yaml deleted file mode 100644 index 0c8c2ed..0000000 --- a/common/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -server: - host: '127.0.0.1' - port: 35293 \ No newline at end of file diff --git a/common/sample_config.yaml b/common/sample_config.yaml new file mode 100644 index 0000000..0304f54 --- /dev/null +++ b/common/sample_config.yaml @@ -0,0 +1,6 @@ +server: + host: "127.0.0.1" + port: 35293 + +sniff: + host: "127.0.0.1" diff --git a/main.py b/main.py index a5f6b18..08c214c 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,30 @@ -from menu import MenuState +from menu import MenuState, LeafMenu +from sniff import udp +from common import config_loader, log def init_menus(): main_menu = MenuState("NOS0S\nselect an option", "NOS0S MAIN") - net = MenuState("net attacks", "tools to attack network devices") + net = MenuState("net recon", "tools to gain intel on network devices") + sniffer = LeafMenu("Sniffer", "Sniffs for network traffic. CTRL+C to cancel.") + sniffer.set_action(udp.sniff, (config_loader.config['sniff']['host'], log.warning)) + net.add_submenu(sniffer) main_menu.add_submenu(net) return main_menu def main(): + log.set_lvl(log.LogLevel.DEBUG) main_menu = init_menus() current_menu = main_menu while current_menu != None: - print(current_menu.display_CLI()) + display, return_to_parent = current_menu.display_CLI() + print(display) + + if(return_to_parent): + current_menu = current_menu.nav_to_parent() + continue + res = input('> ') if res == 'q': break diff --git a/menu.py b/menu.py index 073acc9..4482741 100644 --- a/menu.py +++ b/menu.py @@ -1,4 +1,3 @@ - class MenuState: def __init__(self, title, desc): self.title = title @@ -11,14 +10,14 @@ class MenuState: menu.parent = self def display_CLI(self): - display_text = f'{self.title}\n' + display_text = f'\n{self.title}\n' if self.parent != None: - display_text += f' b. Back' + display_text += f' b. Back\n' for i in range(0, len(self.subs)): sub = self.subs[i] display_text += f' {i}. {sub.title}\n' display_text += f' - {sub.description}\n' - return display_text + return display_text, False def nav_to_sub(self, sub_index): if sub_index <= len(self.subs): @@ -31,23 +30,13 @@ class MenuState: return self.parent else: return self + +class LeafMenu(MenuState): -class LeafMenu(MenuState): - def __init__(self, title, desc): - super.__init__(title, desc) - self.subs = None - self.actions = [] + def set_action(self, action, args): + self.action = action + self.args = args - def add_submenu(self, menu): - return - - def add_action(self, action): - self.actions.append(action) - - def execute_action(self, act_index): - if act_index <= len(self.actions): - # what - self.actions[act_index]() - else: - return + def display_CLI(self): + return self.action(self.args), True \ No newline at end of file diff --git a/sniff/__init__.py b/sniff/__init__.py new file mode 100644 index 0000000..e3fa2b3 --- /dev/null +++ b/sniff/__init__.py @@ -0,0 +1 @@ +# comment to be gittable \ No newline at end of file diff --git a/sniff/ip_ctype.py b/sniff/ip_ctype.py index 3190d01..ab5f144 100644 --- a/sniff/ip_ctype.py +++ b/sniff/ip_ctype.py @@ -2,6 +2,7 @@ from ctypes import * import socket import struct import ipaddress +import os class IP_ctype(Structure): _fields_ = [ @@ -24,6 +25,12 @@ class IP_ctype(Structure): def __init__(self, socket_buffer=None): self.src_address = socket.inet_ntoa(struct.pack(" {ip_header.dst_address}') + packets_sniffed += 1 + except AttributeError as e: + continue + + except KeyboardInterrupt: + if os.name == 'nt': + sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) + return f'Packets Sniffed: {packets_sniffed}' def main(): - udp_single_packet_sniff() + host = input('Host IP > ') + udp_single_packet_sniff(host) + sniff((host, print)) if __name__ == '__main__':