1

Really simple code that just fires one pcap (packet) using scapy,

If I just want to do simple cgi-bin POSTS to myself to run a set of 10 easy tests why is this just kicking back as text (rather than a website). If I comment out the line

sendp(a, iface="em1")

Then the below code actually generates the website fine... but it won't actually send the packet, I imagine this is something with stdout.... suggestions are welcome!

#!/usr/local/bin/python

from scapy.all import *
#import v6tester_main

print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>NPD Automation Tool - GCT-USG</title>'
print '</head>'
print '<body>'
print '<font> NPD Automation Tool </font>'

a = Ether() / IP() / IPv6() / ICMPv6EchoRequest()
sendp(a, iface="em1")

print '<br>'
print '<font>End of Test</font>'
print '</body>'
print '</html>'

If I view source I see this->

<html>
<head>
<title>NPD Automation Tool - GCT-USG</title>
</head>
<body>
<font> NPD Automation Tool </font>

Sent 1 packets.
<br>
<font>End of Test</font>
</body>
</html>
Sean Cav
  • 133
  • 1
  • 14

3 Answers3

1

As I understand it, sendp doesn't just echo the package to stdout; it sends it "down the wire" at a lower protocol level. So if you want to send an html header you'll need to wrap it inside a package, not the other way around.

But are you sure you need to mess with scapy? If all you want is to send POST requests to a webserver, you can just use urllib2.urlopen. Put your POST data in the optional data argument, and it will use POST instead of GET for the request.

alexis
  • 48,685
  • 16
  • 101
  • 161
  • Haha sorry the two are completely separate, the website is just a wrapper so I can test a firewall with pcaps. The web server is controlled through the em0 interface but the em1 interface is separate for FW testing, this is just a dummy pcap I am sending. – Sean Cav Mar 01 '12 at 14:55
1

Most probably the output of sendp brakes the HTML so bad it shows as text, what you can do is try pass verbose=0 to sendp (if the output is not important), or try other verbose level. if the output of sendp is important to you, you can run it in a separate script with subprocess.Popen and try to format the output so it fit in the HTML page.

edit: ops, someone already answered with almost the same

Emil M
  • 336
  • 1
  • 5
  • Could you link me to what you are saying? I am not sure I understand verbose=0... – Sean Cav Mar 01 '12 at 14:55
  • I am up voting you buy not marking correct yet, trying to use the subprocess module right now and asked a different question [here](http://stackoverflow.com/questions/9521055/why-cant-i-execute-another-python-script-using-the-subprocess-module-via-a-webs) going your route – Sean Cav Mar 01 '12 at 17:35
0

It doesn't appear that you are sending http data(eg Response Headers).

You should be because it is being run off a web server.

mikek3332002
  • 3,546
  • 4
  • 37
  • 47
  • the pcap is just being sent out the wire, this is for firewall testing, this is just a dummy pcap so its just empty. It is sent when its not commented out, but the website is then not generated... – Sean Cav Mar 01 '12 at 14:54
  • I thought my first line is generating real HTML... it works for a lot of my other scripts... do you have a faq or how to page for what you are talking about :) – Sean Cav Mar 01 '12 at 15:59
  • I didn't realise the script was running in a webserver(I looked at [your other question](http://stackoverflow.com/questions/9521055/why-cant-i-execute-another-python-script-using-the-subprocess-module-via-a-webs) ) so you should be sending the http data. – mikek3332002 Mar 02 '12 at 05:22