-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
67 lines (53 loc) · 2.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
#! /usr/bin/env python3
from os import makedirs, path
from sys import argv, exit
from time import sleep, time
from multiprocessing import Queue
from typing import Optional
from sniffer import Sniffer
from analyzer import Analyzer
"""
Intrusion Detection System (IDS) implemented in Python.
"""
def print_banner() -> None:
banner = '''
█████╗ ██████╗███████╗██╗ ██╗██████╗ ███████╗
██╔══██╗██╔════╝██╔════╝██║ ██║██╔══██╗██╔════╝
███████║██║ ███████╗██║ ██║██║ ██║███████╗
██╔══██║██║ ╚════██║██║ ██║██║ ██║╚════██║
██║ ██║╚██████╗███████║███████╗ ██║██████╔╝███████║
╚═╝ ╚═╝ ╚═════╝╚══════╝╚══════╝ ╚═╝╚═════╝ ╚══════╝
'''
print(banner)
def main() -> None:
print_banner()
if len(argv) < 2:
exit("[@] No interface was passed. Usage: main.py <INTERFACE> [RULE_PATH]")
interface = argv[1]
rule_path = argv[2] if len(argv) > 2 else 'default.rules'
if not path.exists('logs'):
makedirs('logs')
print(f"[*] Loading {rule_path}")
queue = Queue()
timestamp = str(int(time()))
log_file_path = path.join('logs', f"{timestamp}.log")
with open(log_file_path, "w") as log_file:
sniffer = Sniffer(interface, queue, timestamp)
show_summary = False
analyzer = Analyzer(queue, log_file, rule_path, show_summary)
try:
print('[*] Start sniffing')
sniffer.start()
print('[*] Start analyzing')
analyzer.start()
while True:
sleep(100)
except KeyboardInterrupt:
print('[*] Stopping IDS')
analyzer.join()
sleep(0.1)
sniffer.join()
print('[*] Bye')
if __name__ == '__main__':
main()