This is a simple TCP Port scanner written in awk scripting language. It scans for ports and then checks against the /etc/services file to identify the ports open.
#!/usr/bin/env gawk -f BEGIN { ## How we check for open ports o_port = "Connection timed out" print "\nPORT\tSERVICE\tSTATE\n" } ## MAIN { ## Scan loopZ while ((getline host0) { for (port=0;port<1024;port++) { Service = "/inet/tcp/0/" host "/" port PROCINFO[Service, "READ_TIMEOUT"] = 1000 Service |& getline ## Try to enumerate port service if (ERRNO ~ o_port) { s_index=0; p_index=0; while ((getline service[s_index++]<"/etc/services") > 0) { if (service[p_index] ~ port) { sub("\t.*", " ", service[p_index]) print port "\t" service[p_index] "\t" "OPEN\n" next } p_index++ } } close("/net/tcp/0/"host"/"port) } } } ## Fin END { print "Finished" }
If we run the script we get...
root@asus:~/pentest_notes/SCANNING% echo "127.0.0.1" > awk.txt root@asus:~/pentest_notes/SCANNING% awk -f tcp_connect_scanner.awk awk.txt PORT SERVICE STATE 53 domain OPEN Finished root@asus:~/pentest_notes/SCANNING%
As you can see we got some results from our scan. This is really a novel port scanner it is obviously better to use something like nmap for more reliable results.
No comments:
Post a Comment