Article original Publié le : 30 décembre 2022 Mise à jour le : – |
Utiles pour voir ce qui est en écoute sur ces machines
Différente méthodes, testé sur une instance vagrant avec un apache et un serveur ssh ..
lsof
1 |
$ sudo lsof -nP -iTCP -sTCP:LISTEN |
1 2 3 4 5 6 7 8 9 10 |
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd-r 929 systemd-resolve 13u IPv4 15448 0t0 TCP 127.0.0.53:53 (LISTEN) sshd 2256 root 3u IPv4 24583 0t0 TCP *:22 (LISTEN) sshd 2256 root 4u IPv6 24585 0t0 TCP *:22 (LISTEN) apache2 2878 www-data 4u IPv6 115163 0t0 TCP *:80 (LISTEN) apache2 2878 www-data 6u IPv6 115167 0t0 TCP *:443 (LISTEN) apache2 2879 www-data 4u IPv6 115163 0t0 TCP *:80 (LISTEN) apache2 2879 www-data 6u IPv6 115167 0t0 TCP *:443 (LISTEN) apache2 26002 root 4u IPv6 115163 0t0 TCP *:80 (LISTEN) apache2 26002 root 6u IPv6 115167 0t0 TCP *:443 (LISTEN) |
loop
1 |
$ for i in {1..65535}; do (echo < /dev/tcp/127.0.0.1/$i) &>/dev/null && printf "\n[+] Port Ouvert \n: \t%d\n" "$i"; done |
1 2 3 4 5 6 7 8 |
[+] Port Ouvert : 22 [+] Port Ouvert : 80 [+] Port Ouvert : 443 |
netstat
1 |
$ sudo netstat -lntu |
1 2 3 4 5 6 |
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 :::443 :::* LISTEN |
ss
1 |
$ sudo ss -lntu |
1 2 3 4 5 |
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* tcp LISTEN 0 128 *:80 *:* tcp LISTEN 0 128 [::]:22 [::]:* tcp LISTEN 0 128 *:443 *:* |
nmap
1 |
$ sudo nmap -sT -O 127.0.0.1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Starting Nmap 7.60 ( https://nmap.org ) at 2022-12-30 18:57 UTC Nmap scan report for localhost (127.0.0.1) Host is up (0.000058s latency). Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp open https Device type: general purpose Running: Linux 2.6.X OS CPE: cpe:/o:linux:linux_kernel:2.6.32 OS details: Linux 2.6.32 Network Distance: 0 hops |
ou (-T<0-5>: Set timing template (higher is faster))
1 |
$ sudo nmap -p0-65535 127.0.0.1 -T5 |
netcat
1 |
$ nc -vz 127.0.0.1 1-65535 2>&1 | grep succeeded |
1 2 3 |
Connection to 127.0.0.1 22 port [tcp/ssh] succeeded! Connection to 127.0.0.1 80 port [tcp/http] succeeded! Connection to 127.0.0.1 443 port [tcp/https] succeeded! |