Today, In This Tutorial, I'm Gonna to Show You How We Can Capture HTTP Header Packet Using Python and Socket Module.
Information Gathering is a very important concept in Profession Of Ethical Hacking and Penetration Testing. Basically, Web Sniffing is a very useful concept for testing any web application. So, Today We are going to learn a simple script that will help us to grab HTTP response header. Actually, This Simple script can help us in various ways like this Script can help us to examine any website cookies techniques, server information, information gathering, website scraping and much more.
Ok So, Let's Start Here,
How it's Going To Works
Basically, readers With the help of this script, we only have to Sniff established HTTP connection between our client browser and online server. Whenever Our client browser will send a request to the HTTP server. Of course after receiving a client request, the Online server will definitely response back and at the time, our script will sniff that response data and print it on the terminal. I hope now you got the basic structure of our method. now, it's time to implement it in code.
first of all, we have to Capture packets from local sockets using python socket module and after capturing packets. we have to extract packets for filtering out our useful data.
Hmm, Not getting how it's going to work?
Let me explain you step by step.
- 1st line is for importing socket module
- 3rd line is creating socket handler for packet sniffing. this simple configuration will help us to sniff data from the local socket.
- 5th line for loop
- 6th line for reading packets from local socket
- 8th line for verifying that extracted packet is HTTP Header
- 10th line is for extracting the header from raw data.
I know This script looks very easy. So let's try it.
HTTP Header Sniffing Python Codes
s=socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0800))
if "HTTP" in data[54:]:
if "\r\n\r\n" in raw:
print "[*] Header Captured "
I Hope You Enjoyed It.
For Any Question And Suggestion