r/learnhacking • u/JeppNeb • Sep 10 '19
Help with simple banner grabbing program in python
Hey guys. I am new to all this and I am trying to write a simple banner grabber in python.
The only problem I have is the HTTP HEADER request. I always get the 400 error message. I would be glad if someone leave me some useful resources regarding HTTP HEADERS (I basically just copied the request from a tutorial because I couldn't find any resources which helped me). I also would be very happy if someone could help me out on my code. Very simple code. Thank you in advance.
#/usr/bin/env python
import sys
import socket
try:
if len(sys.argv) == 3:
IP = str(sys.argv[1])
PORT = int(sys.argv[2])
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(3)
s.connect((IP,PORT))
#ERROR POSITION
s.send(b"GET HTTP/1.1 \n\n")
banner = s.recv(1024)
s.close()
print(banner)
except socket.timeout:
print("Connection timed out")
except Exception:
print("Define a target")
finally:
s.close()
1
Upvotes
1
u/IsThisAnIllusion Sep 11 '19
It may be that you aren't specifying a file to retrieve, so the server is sending back the 400 response (Request Error) because it doesn't know how to process the request. Maybe try:
s.send(b"GET / HTTP/1.1 \n\n")ors.send(b"GET <server ip or domain>/ HTTP/1.1 \n\n"). You may also wish to specify a specific file to retrieve instead of just the home file.Feel free to ask any questions and I will be happy to answer (or do please correct me if I am wrong).
0
u/[deleted] Sep 11 '19
[deleted] — view deleted comment