In nano, enter this code, as shown below:
import socket s = socket.socket() s.connect(("target1.bowneconsulting.com", 22)) print s.recv(1024) s.close()
Save the file with Ctrl+X, Y, Enter.
ExplanationThe first line imports the "socket" library, which contains networking functions.
The second line creates a socket object named "s".
The third line connects to the server "target1.bowneconsulting.com" on port 22.
The fourth line receives data from the server and prints it, up to a maximum of 1024 characters.
The fifth line closes the connection.
You should see an SSH banner, as shown below:
Change the port number from 22 to 80, as shown below, and save the modified file.
Run the script again. There is no banner from an HTTP server, so it just freezes up, waiting for a banner. To stop the script, press Ctrl+C.
To make it timeout more quickly, add this line to your script, as shown below:
Run the script again. Now it times out, as shown below.
Modify grab2.py to use variables for the target and port, as shown below.
cp grab.py grab2.py
Save and run the script--it should time out in a few seconds, just as it did before.
Save and run the script. Enter a URL and port to scan. The script halts with an error saying "TypeError: an integer is required".
To fix that, enclose the raw_input statement for tport in the int() function, as shown below.
Now the port scanner works. Use it to grab the port 22 banner again, as shown below.
Revised for WCIL 5-20-19