Wednesday, April 6, 2011

Port scanning in bash

There was a short discussion over at securityoverride on port scanning using only bash, and I whipped up the short piece of code below. Unfortunately, while udp scans are possible, I don't think stealth scans are possible using bash alone.

#!/bin/bash

for p in {1..1024}
do
(echo >/dev/tcp/192.168.0.50/$p) && echo "port $p is open."&
done



If you don't want Connection refuses and Connection timeouts cluttering your screen, add in the /dev/null stuff:

(echo >/dev/tcp/192.168.0.50/$p) >/dev/null 2>&1 && echo "port $p is open."&

And keep an eye on the number of ports you are scanning -> number of child processes being spawned.

No comments:

Post a Comment