@@ -10,7 +10,153 @@ At present, it doesn't detect horizontal port scans (single port scanned across
10
10
or single port scans (single port scanned in single host).
11
11
12
12
# Capabilities
13
- pyscanlogd3 can detect most port scan techniques available using ` nmap ` and some by ` hping3 ` .
13
+ pyscanlogd3 can detect most port scan techniques available using ` nmap ` and some by ` hping3 ` . It uses ` pypcap ` library
14
+ for packet capturing and ` dpkt ` library for packet processing.
15
+
16
+ # Requirements.
17
+
18
+ 1 . A * nix (linux or similar) system with Python3 installed with support for sqlite3. The program is tested with Python3.11.
19
+ 2 . Root (sudo) access
20
+
21
+ The program needs root privilges to listen to the network interfaces in promiscious mode.
14
22
15
23
# Setup
16
- Coming soon.
24
+
25
+ 1 . Checkout the source code
26
+ 2 . Create a Python 3 virtualenv - Python 3.11 and higher are suggested.
27
+ 3 . Inside the virtual env,
28
+ * pip install -r requirements.txt
29
+ * python setup.py install
30
+
31
+ Once installation is complete, you can run the program using ` pyscanlogd3 ` command.
32
+
33
+ # Running
34
+
35
+ Just running the program without any arguments,
36
+
37
+ $ pyscanlogd3
38
+ Scan logs will be saved to /var/log/pyscanlogd3.log
39
+ listening to [None]
40
+ duplicate scans will be logged
41
+ config => threshold: 8, timeout: 5s, bufsize: 8192
42
+ creating scan db /root/.config/pyscanlogd3/scan.db ...
43
+ scan db created.
44
+ listening on wlp0s20f3:
45
+
46
+ NOTE: The ` pyscanlogd3 ` is a shell-script which runs with sudo access. It may ask you for your password if required. There is no need to run it with ` sudo ` .
47
+
48
+ The program by default runs in medium threshold mode. Scans are logged to a sqlite3 database and on the console.
49
+
50
+ For detailed command line options,
51
+
52
+ $ pyscanlogd3 -h
53
+ usage: pyscanlogd3 [-h] [-f LOGFILE] [-l {max,high,medium,low}] [-i [INTERFACE ...]] [-I]
54
+
55
+ pyscanlogd3: Python3 port-scan detection program
56
+
57
+ options:
58
+ -h, --help show this help message and exit
59
+ -f LOGFILE, --logfile LOGFILE
60
+ File to save logs to
61
+ -l {max,high,medium,low}, --level {max,high,medium,low}
62
+ Default threshold level for detection
63
+ -i [INTERFACE ...], --interface [INTERFACE ...]
64
+ The network interface(s) to listen to
65
+ -I, --ignore_duplicates
66
+ Ignore continued (duplicate) scans
67
+
68
+ To listen to more than one interface, pass them to the ` -i ` option.
69
+
70
+ $ pyscanlogd3 -i wlp0s20f3 lo
71
+ Scan logs will be saved to /var/log/pyscanlogd3.log
72
+ listening to ['wlp0s20f3', 'lo']
73
+ duplicate scans will be logged
74
+ config => threshold: 8, timeout: 5s, bufsize: 8192
75
+ scan db /root/.config/pyscanlogd3/scan.db already exists.
76
+ listening on wlp0s20f3:
77
+ listening on lo:
78
+
79
+ For exiting press Ctrl-C. (once per interface).
80
+
81
+ listening on wlp0s20f3:
82
+ listening on lo:
83
+ ^CPress Ctrl-C again to exit
84
+ stats for network interface: wlp0s20f3
85
+
86
+ 1 packets received by filter
87
+ 0 packets dropped by kernel
88
+ ^Cstats for network interface: lo
89
+
90
+ 2 packets received by filter
91
+ 0 packets dropped by kernel
92
+
93
+ # Scan detection and logging (nmap Examples)
94
+
95
+ While the program is running, try an ` nmap ` scan.
96
+
97
+ $ sudo nmap -sX nmap.org
98
+
99
+ You should see the scan detected and logged on the console.
100
+
101
+ [2024-08-25 19:36:14]: TCP Xmas scan (flags:41) from 192.168.1.6 to 50.116.1.184 (ports: [443, 80, 993, 1025, 1723])
102
+
103
+ As the scan continues, you will see more log lines like this as ` nmap ` scans more ports.
104
+
105
+ [2024-08-25 19:36:14]: Continuing TCP Xmas scan (flags:41) from 192.168.1.6 to 50.116.1.184 (ports: [22, 23, 587, 139])
106
+ [2024-08-25 19:36:16]: Continuing TCP Xmas scan (flags:41) from 192.168.1.6 to 50.116.1.184 (ports: [443, 8888, 110, 139, 587, 23, 22, 1723, 1025, 993, 1720, 5900, 3306, 3389, 143, 80, 113, 554, 199, 135, 8080, 21, 256])
107
+
108
+ The ` Continuing ` lines show a duplicate scan, i.e the same scan is detected as still running. To avoid detecting duplicate scans, you can pass the ` -I ` option.
109
+
110
+ Do another scan, this time an ` ACK ` scan.
111
+
112
+ $ sudo nmap -sA nmap.org
113
+
114
+ [2024-08-25 19:38:05]: TCP Ack scan (flags:16) from 192.168.1.6 to 50.116.1.184 (ports: [443, 1025, 8888, 113, 143, 111, 8080, 993, 23, 110, 21, 5900, 1723, 3389, 80, 25, 53, 135, 139, 445, 587, 256])
115
+
116
+ Let us do a UDP scan now.
117
+
118
+ [2024-08-25 19:39:12]: UDP scan (flags:0) from 192.168.1.6 to 50.116.1.184 (ports: [36893, 40708, 5355, 20848, 8000, 43514, 215 68, 1434, 20164, 17824, 20154, 34555, 19017, 1900, 17487, 49158, 20560, 25337, 623, 20004, 997, 51972, 40539, 21333, 20, 45928, 1035, 49194, 177, 19161, 443, 50919, 30656, 43824, 16786, 34570, 33459, 518, 30718])
119
+
120
+ Scans are also logged to the scan db. By default this is created at ` /root/.config/pyscanlogd3/scan.db ` .
121
+
122
+ You can inspect the scans by opening the db.
123
+
124
+ $ sudo sqlite3 /root/.config/pyscanlogd3/scan.db
125
+ # Show all detected scans so far
126
+ sqlite> select distinct type from scan;
127
+ TCP Xmas
128
+ TCP Ack
129
+ TCP Null
130
+ UDP
131
+ # Show all distinct scans originating from 192.168.1.6 grouped by scan hash and type
132
+ sqlite> select src,dst,type,hash,timestamp,utc_timestamp from scan group by hash,type;
133
+ 192.168.1.6|50.116.1.184|TCP Ack|3654|1724594885.92384|2024-08-25 14:08:05
134
+ 192.168.1.6|50.116.1.184|TCP Null|3654|1724594941.4765|2024-08-25 14:09:01
135
+ 192.168.1.6|50.116.1.184|TCP Xmas|3654|1724594774.34435|2024-08-25 14:06:14
136
+ 192.168.1.6|50.116.1.184|UDP|3654|1724594952.29163|2024-08-25 14:09:12
137
+
138
+ NOTE: The tool right now ignores scans where src and dst IPs are the same.
139
+
140
+ # Slow scan detection
141
+
142
+ The tool is able to detect slow scans as well. Use the ` -T ` option of nmap to try this out.
143
+
144
+ $ sudo nmap -sS -T2 nmap.org
145
+ [2024-08-25 19:43:27]: TCP Syn scan (flags:2) from 192.168.1.6 to 50.116.1.184 (ports: [256, 587, 3306, 23, 8080])
146
+
147
+ Paranod (` -T0 ` ) and sneaky (` -T1 ` ) scan types are very slow, so takes a while to detect.
148
+
149
+ # Known Issues
150
+
151
+ 1 . Detects spurious NULL TCP scans sometimes.
152
+ 2 . Detects spurious NULL UDP scans sometimes.
153
+ 3 . Slow scan detection is a work in progress.
154
+
155
+ # Bugs and Suggestions
156
+ For bugs file issues in the project. For feedback checkout my email in setup.py.
157
+
158
+ # LICENSE
159
+ The program is licensed under BSD 3-Clause license. Checkout ` LICENSE ` for details.
160
+
161
+
162
+
0 commit comments