Tuesday, 22 April 2014

HTTP Banner grab

Simple http banner grab tool using raw sockets. I created this because I am always forgetting the command to get the HTTP banner once connected. I used to use netcat to banner grab.

#!/usr/bin/python

import sys #For errors
import socket

host = sys.argv[1]
port = 80

print"Creating Socket"

try:
tcpSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#Set the socket to be re-used.
tcpSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
except socket.error, msg:
print "Failed to create socket. Error: " + str(msg[0])  + " , Error message " + str(msg[1])
sys.exit()

print "Socket created"

try:
remote_ip = socket.gethostbyname(host)
except socket.gaierror:
#Could not resolve
print "Host name could not be resolved. Exiting..."
sys.exit()

print "IP address of " + host + " is " + remote_ip + " \n\n"

#Banner grab command
data = "HEAD / HTTP/1.1\n\n"


#Connect to IP
tcpSocket.connect((host, port))

try:
tcpSocket.sendall(data)
except socket.error:
print "Failed to retrieve HTTP information"
sys.exit()

reply = tcpSocket.recv(4096)
print reply

print"\nSuccessfully received HTTP HEADER information"
tcpSocket.close()

Output:
Quite a lot of info in that one...

No comments:

Post a Comment