Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:04:51+00:00 2026-06-13T12:04:51+00:00

I am trying to sniff an out going http packet using scapy, add a

  • 0

I am trying to sniff an out going http packet using scapy, add a few new http headers in it and send it ahead. The intention here is to only insert new headers while keeping the packet intact. At max any checksum recalculation should be done if needed.

Have been through almost all questions on SO but didn’t exactly get a solution.

Following is what i have done.

def parse(pkt):

    if pkt.haslayer(TCP) and pkt.getlayer(TCP).dport == 80 and pkt.haslayer(Raw):
        pkt = pkt / "New Header:value\r\n\r\n"

        # OR i tried this
        #pkt = pkt.getlayer(Raw).load / Raw.load(load="New Header:value\r\n\r\n")

        #pkt.getlayer(Raw).load("New Header:value\r\n\r\n")
        pkt.show()
        #del pkt[IP].chksum
        send(pkt)
#end parse function

# start sniffing
a=sniff(filter="tcp and ( port 80 )", prn=parse)

The problem is that above code inserts a new raw payload section instead of adding a plain header. There is already a double newline \r\n\r\n to indicate header termination according to HTTP standard.

To overcome this i tried removing the last \r\n by doing as follows

   #pkt = pkt.getlayer(Raw).load[-2:] / Raw.load(load="New Header:value\r\n\r\n")

But this strips all of the previously existing headers and only the “New Header” remains.

I have tried this on Linux mint.

UPDATE:
I am trying to create a new http payload which would contain previous headers and i will add some. Can some one help with how to removing an existing layer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:04:52+00:00Added an answer on June 13, 2026 at 12:04 pm

    If I understand correctly, the problem you’re having is that you want to update an existing HTTP request with a new header. What you want is to update a string in place, which Python can’t do directly (strings are immutable).

    So what you should do is take the HTTP header:

    old_hdr = pkt[Raw] or old_hdr = pkt[TCP].payload

    and manipulate it like a string:

    new_hdr = 'New Header: value'
    hdr = old_hdr.split('\r\n') # This is a crappy hack. Parsing HTTP headers
    hdr.insert(new_hdr, 2)      # is a [solved problem][1].
    send_hdr = '\r\n'.join(hdr)
    pkt[TCP].payload = send_hdr
    

    If you find checksums are not updating, delete them before sending the packet:

    del pkt[TCP].chksum
    

    and Scapy will put them back for you, with the right values.

    Edit: I just noticed that my link is fail. Here is how to parse HTTP headers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to sniff the http headers by using tcpdump. This filter works
I've been trying to write a script that will sniff HTTP headers. So far
I am trying so sniff a multi-part POST request using Wireshark. When viewing the
I am trying to sniff HTTP data through libpcap and get all the http
I'm using C++/boost::asio under Win7. I'm trying to sniff trafic over a given TCP/IP
I am actually trying to send SMS using CDYNE and their API. To do
I was trying to sniff HTTP packets though wireshark on my localhost, when i
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.