Warning: session_start(): open(/tmp/sess_970f60b15303f90b6be626008739e41e, O_RDWR) failed: No space left on device (28) in /var/www/html/inc/init.php on line 265

Warning: session_start(): Failed to read session data: files (path: ) in /var/www/html/inc/init.php on line 265

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/inc/init.php:265) in /var/www/html/inc/auth.php on line 432

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/inc/init.php:265) in /var/www/html/inc/actions.php on line 38
bash_portscan_banners [Ben's notes]

Ben's notes

Linux, Unix, network, radio...

User Tools

Site Tools


bash_portscan_banners

Pure bash TCP portscan and bannergrabber

Sequential portscan

#!/bin/bash

IP=1.2.3.4

for port in {1..1023}
do
	echo -n "${IP} port ${port} - "
	timeout 1s bash -c "</dev/tcp/${IP}/${port}" 2>/dev/null && echo open || echo closed
done

Parallel portscan

Test 10 ports in parallel.

#!/bin/bash

PAR=10
IP=127.0.0.1

(
for port in {1..1000}
do
	((i=i%PAR)); ((i++==0)) && wait
	timeout 1s bash -c "</dev/tcp/${IP}/${port}" 2>/dev/null && echo ${port} open || echo ${port} closed &
done
)

Bannergrab

#!/bin/bash

IP=1.2.3.4

for i in {1..1000}
do
	echo -n "${IP} port ${i} - "
	timeout 1s bash -c "head -1 </dev/tcp/${IP}/${i}" 2>/dev/null || echo closed
done
bash_portscan_banners.txt · Last modified: 2021/10/09 15:14 by 127.0.0.1