pistol-rs
The library must be run as root (Linux, *BSD) or administrator (Windows), the stable version of rust is recommended.
Import from crates.io
[]
= "^1"
On Windows, download winpcap here, then place Packet.lib from the x64 folder in your root of code. The other lib like npcap did not test by libpnet.
Cross Platform Support
| Platform | Note |
|---|---|
| Linux | supported |
| Unix (*BSD, MacOS) | supported |
libpnet bug on Windows
Bug issues: https://github.com/libpnet/libpnet/issues/707, the libpnet cannot get IPv6 address on Windows.
Therefore, until libpnet fixes this bug, Windows is not supported yet.
libpnet bug on rust nightly version
Bug issue: https://github.com/libpnet/libpnet/issues/686
Host Discovery (Ping Scanning)
The implementation of the `pistol' host discovery according to the nmap documentation.
| Method | Detailed Documentation | Note |
|---|---|---|
| [x] TCP SYN Ping | nmap reference | IPv4 & IPv6 |
| [x] TCP ACK Ping | nmap reference | IPv4 & IPv6 |
| [x] UDP Ping | nmap reference | IPv4 & IPv6 |
| [x] ICMP Ping | nmap reference | IPv4 & IPv6 (ICMP, ICMPv6) |
| [x] ARP Scan | nmap reference | IPv4 |
| [ ] IP Protocol Ping | nmap reference | Complicated and not very useful |
Port Scanning Techniques and Algorithms
The implementation of the pistol port scan according to the nmap pdf and documentation.
| Method | Detailed Documentation | Note |
|---|---|---|
| [x] TCP SYN Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP Connect() Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP FIN Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP Null Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP Xmas Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP ACK Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP Window Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP Maimon Scan | nmap reference | IPv4 & IPv6 |
| [x] UDP Scan | nmap reference | IPv4 & IPv6 |
| [x] TCP Idle Scan | nmap reference | IPv4 |
| [ ] IP Protocol Scan | nmap reference | Complicated and not very useful |
| [ ] TCP FTP Bounce Scan | nmap reference | The bugs exploited have long been fixed |
Flood Attack
| Method | Note |
|---|---|
| [x] TCP SYN Flood | IPv4 & IPv6 support |
| [x] TCP ACK Flood | IPv4 & IPv6 support |
| [x] UDP Flood | IPv4 & IPv6 support |
| [x] ICMP Flood | IPv4 & IPv6 support (ICMP, ICMPv6) |
Remote OS Detection
| Method | Detailed Documentation | Note |
|---|---|---|
| [x] IPv4 OS Detect | nmap reference | Print fingerprint as nmap format now supported |
| [x] IPv6 OS Detect | nmap reference | Print fingerprint as nmap format now supported |
OS Detection on IPv6?
On ipv6, the fingerprints are unreadable and meaningless to humans, see here for details, and nmap uses logistic regression to match target OS on ipv6, but the matching algorithm is quite outdated with confusing design logic.
The first is about the ST, RT and EXTRA metrics in fingerprints in detection on ipv6, these three metrics are not used at all in the code, at the same time, there is no detailed description of how ST and RT are calculated, I don't know why nmap would keep them in the final fingerprint.
The second is NI probes. In the relevant document of nmap, it describes the specific structure of NI probe, but I don't see anything about it in the code, and it seems to completely ignore this probe when do predict use logistic regression.
Furthermore, for the current mainstream operating systems, ipv6 fingerprint support is not as rich as ipv4, so try the ipv4 first.
Service and Application Version Detection
| Methods | Detailed Documentation |
|---|---|
| [x] IPv4 Service Scan | nmap reference |
| [x] IPv6 Service Scan | nmap reference |
Debugs
use Logger;
Examples
1. SYN Port Scan Example
use tcp_syn_scan;
use Target;
use Host;
use Ipv4Addr;
use Duration;
use Result;
Output
2. Remote OS Detect Example
- 192.168.72.129 - CentOS 7
- 192.168.72.136 - Ubuntu 22.04
use os_detect;
use Target;
use Host;
use Ipv4Addr;
use Duration;
use Result;
Output
Ubuntu 22.04
>>> IP:
192.168.72.136
>>> Pistol fingerprint:
SCAN(V=PISTOL%D=12/14%OT=22%CT=8765%CU=9876PV=Y%DS=1%DC=D%G=Y%M=0C29%TM=657B21AA%P=RUST)
SEQ(SP=107%GCD=1%ISR=105%TI=Z%CI=Z%II=I%TS=A)
OPS(O1=M5B4ST11NW7%O2=M5B4ST11NW7%O3=M5B4NNT11NW7%O4=M5B4ST11NW7%O5=M5B4ST11NW7%O6=M5B4ST11)
WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)
ECN(R=Y%DF=Y%TG=40%W=FAF0%O=M5B4NNSNW7%CC=Y%Q=)
T1(R=Y%DF=Y%TG=40%S=O%A=S+%F=AS%RD=0%Q=)
T2(R=N)
T3(R=N)
T4(R=Y%DF=Y%TG=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)
T5(R=Y%DF=Y%TG=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)
T6(R=Y%DF=Y%TG=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)
T7(R=Y%DF=Y%TG=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)
U1(R=Y%DF=N%TG=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)
IE(R=Y%DFI=N%TG=40%CD=S)
>>> Details:
>>> Score:
83/101
>>> Info:
Linux 4.15.0-88-generic #88~16.04.1-Ubuntu SMP Wed Feb 12 04:19:15 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Linux 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2 (2020-04-29) x86_64 GNU/Linux
Linux 5.0.0-32-generic #34~18.04.2-Ubuntu SMP Thu Oct 10 10:36:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Linux 5.2.10-yocto-standard #1 SMP PREEMPT Fri Oct 4 11:58:01 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Linux 5.3.0-kali3-amd64
Linux 5.3.16-200.fc30.x86_64 #1 SMP Fri Dec 13 17:48:38 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Linux 5.4.6-amd64.gbcm #3 SMP Thu Dec 26 13:55:41 -03 2019 x86_64 GNU/Linux
Linux 5.6.15-arch1-1 #1 SMP PREEMPT Wed, 27 May 2020 23:42:26 +0000 x86_64 GNU/Linux
Linux 5.2.11-arch1-1-ARCH
Linux 5.4.0-1012-raspi #12-Ubuntu SMP Wed May 27 04:08:35 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux
>>> Fingerprint:
Linux 4.15 - 5.6
>>> Class:
Linux | Linux | 4.X | general purpose
Linux | Linux | 5.X | general purpose
>>> CPE:
cpe:/o:linux:linux_kernel:4 auto
cpe:/o:linux:linux_kernel:5 auto
...
CentOS 7
>>> IP:
192.168.72.129
>>> Pistol fingerprint:
SCAN(V=PISTOL%D=12/14%OT=22%CT=54532%CU=34098PV=Y%DS=1%DC=D%G=Y%M=0C29%TM=657B21AA%P=RUST)
SEQ(SP=103%GCD=1%ISR=101%TI=Z%II=I%TS=A)
OPS(O1=M5B4ST11NW7%O2=M5B4ST11NW7%O3=M5B4NNT11NW7%O4=M5B4ST11NW7%O5=M5B4ST11NW7%O6=M5B4ST11)
WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=7120)
ECN(R=Y%DF=Y%TG=40%W=7210%O=M5B4NNSNW7%CC=Y%Q=)
T1(R=Y%DF=Y%TG=40%S=O%A=S+%F=AS%RD=0%Q=)
T2(R=N)
T3(R=N)
T4(R=Y%DF=Y%TG=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)
T5(R=N)
T6(R=N)
T7(R=N)
U1(R=Y%DF=N%TG=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)
IE(R=Y%DFI=N%TG=40%CD=S)
>>> Details:
>>> Score:
55/101
>>> Info:
Linux 3.10.0-327.13.1.el7.x86_64
Linux 3.12.5-200.fc19.i686 #1 SMP Tue Dec 17 22:46:33 UTC 2013 i686 i686 i386 GNU/Linux
Linux 3.13.5-200.fc20.x86_64 #1 SMP Mon Feb 24 16:51:35 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Linux 3.11.0-17-generic #31-Ubuntu SMP Mon Feb 3 21:52:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Linux 3.13.0-19-generic #40-Ubuntu SMP Mon Mar 24 02:36:06 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Linux 3.14.3-1-ARCH #1 SMP PREEMPT Tue May 6 22:44:19 CEST 2014 x86_64 GNU/Linux
Linux 3.12.21-gentoo-r1 #1 SMP PREEMPT x86_64
Linux 3.12.28-1-ARCH #1 PREEMPT Tue Sep 9 12:57:11 MDT 2014 armv6l GNU/Linux
Linux 3.19.2-1-ARCH #1 SMP PREEMPT Wed Mar 18 16:36:01 CET 2015 i686 GNU/Linux
Linux 3.10.72 #10878 Thu Mar 19 04:41:15 CET 2015 mips GNU/Linux
Linux raspberrypi 4.1.7+ #817 PREEMPT Sat Sep 19 15:25:36 BST 2015 armv6l GNU/Linux
Linux 3.18.26 #8771 Fri Feb 5 03:08:28 CET 2016 mips
Linux 3.18.31 DD-WRT
Linux 4.2.0-27-generic #32~14.04.1-Ubuntu SMP Fri Jan 22 15:32:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
4.8.6-201.fc24.x86_64 #1 SMP Thu Nov 3 14:38:57 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Linux 4.11.6-3-ARCH #1 SMP PREEMPT Thu Jun 22 12:21:46 CEST 2017 x86_64 GNU/Linux
>>> Fingerprint:
Linux 3.10 - 4.11
>>> Class:
Linux | Linux | 3.X | general purpose
Linux | Linux | 4.X | general purpose
>>> CPE:
cpe:/o:linux:linux_kernel:3 auto
cpe:/o:linux:linux_kernel:4 auto
...
3. Remote OS Detect Example on IPv6
- fe80::6445:b9f8:cc82:3015 - CentOS 7
- fe80::20c:29ff:feb6:8d99 - Ubuntu 22.04
use os_detect6;
use Target;
use Host;
use Ipv4Addr;
use Duration;
use Result;
Output
CentOS 7
>>> IP:
fe80::6445:b9f8:cc82:3015
>>> Novelty:
18.900423183803554
According to the nmap documentation, the novelty value must be less than 15 for the probe result to be meaningful, so when this value is greater than 15, an empty list is returned. Same when the two highest OS classes have scores that differ by less than 10%, the classification is considered ambiguous and not a successful match.
Ubuntu 22.04
>>> IP:
fe80::20c:29ff:feb6:8d99
>>> Novelty:
8.970839832634503
>>> Score:
92.00%
>>> Fingerprint:
Linux 4.19
>>> Class:
Linux | Linux | 4.X | general purpose
>>> CPE:
cpe:/o:linux:linux_kernel:4.19
>>> Score:
71.04%
>>> Fingerprint:
Linux 3.13 - 4.6
>>> Class:
Linux | Linux | 3.X | general purpose
Linux | Linux | 4.X | general purpose
>>> CPE:
cpe:/o:linux:linux_kernel:3
cpe:/o:linux:linux_kernel:4
...
3. Remote Service Detect Example
- 192.168.1.51 - Ubuntu 22.04 (ssh: 22, httpd: 80)
use vs_scan;
use ExcludePorts;
use Target;
use Host;
use Ipv4Addr;
use Duration;
use Result;
Output
>>> port:
22
>>> services:
ssh
>>> versioninfo:
p/OpenSSH/ v/8.9p1 Ubuntu 3ubuntu0.7/ i/Ubuntu Linux; protocol 2.0/ o/Linux/ cpe:/a:openbsd:openssh:8.9p1/ cpe:/o:canonical:ubuntu_linux/ cpe:/o:linux:linux_kernel/
>>> port:
80
>>> services:
http
>>> versioninfo:
p/Apache httpd/ v/2.4.52/ i/(Ubuntu)/ cpe:/a:apache:http_server:2.4.52/