how to get the html content and edit with scapy and see the edited result in browser?

Ho Yeung Lee jobmattcon at gmail.com
Tue Jun 20 19:34:32 EDT 2017


then i further googled a code, but the google chrome browser and
microsoft edge browser can not see the new html from the fakehttp server

is there something changed to prevent edit html after intercept?
originally i hope to edit https html

Begin emission:
.*
Received 2 packets, got 1 answers, remaining 0 packets
192.168.4.52: http
GET /photo/tv33.bmp HTTP/1.1
Host: 192.168.3.245
Connection: keep-alive
If-None-Match: "100980-9e2bb-5526c85bb2d00"
If-Modified-Since: Tue, 20 Jun 2017 23:22:17 GMT
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Accept: image/webp,image/*,*/*;q=0.8
Referer: http://192.168.3.245/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8


Begin emission:
.*
Received 2 packets, got 1 answers, remaining 0 packets
.
Sent 1 packets.


second time to run

Begin emission:
......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Received 3254 packets, got 0 answers, remaining 1 packets
192.168.3.245: 54302
≡hx≡ΩIDA
       ╧╞s%╒╣δU╫╡δτR₧√╕2¡▀╞~]■N1I┐»÷╜ì Φ@d"Aê╟üXy})═7AV# ƒΩ '}&»D=╝àª)■
 K╬Γw ┼ü
|üâÉ

k,W╢÷å,p!å.9■@â┴!üíçê&CB┘#╜R╛└ü⌡Y╡\gkσ├f ⌐r-╥Θ╓⌡¬┴OÇÄ=Ų≡°Åò╚ç╥åÅcÑÅ@~Q┼╚┼¬Kå⌐+^*a]¼!RAê*6Θ╔ít      z╤
╦ Æ2L⌠á1üìÆ£≥î
─z╥Y╟┴DΣ%4ÄΘPZ╛!éº÷8╬å
╔ö*ÿ
f╢ºΘΣτK╚≥r^ƒ⌐@pr╞FºDúEc÷╠É╛±úíπkg ╟íª=Ç≡0é}áqφàS>╖⌡≥2ZwH_╛£·╥▄╢Tεªσû∞ « è%[i╔v¡+ïc╛sÅ1 ç├┌ƒΣ╛Éâ╨yR╤
 ╔± s 1hî ╥ $#$ⁿ.8òvdqbu┐Å ét_°
τ┼=3┐Åö =╢╢
)δìHç¡=α╚}⌐║╚Oⁿ]'Ñ
H√_·
>
 ì⌐>É«1▌/K Γ.T%#Ä$αÉSµS÷▐┌║█7∞nπ;ÿ└I=°⌠|X{n{╕/_âßAτ╔"-MD╦▒
D^╙rx{çx
)N2æ│∩«ΣOΩ▄╜uΩù+pÄ°`┐┼°{ós┼q░≥Ü▀k9±{£Ωx┬æªn├7╣¿δ

\Gy-∙<÷z»'≥=Å▄ ╩4 ₧╬∙¥ù├Fñc[│»zù{{ ½Gé        └      0

w_  x╣çO÷▐ëä▓ô/í≈ Γ(╚@á#╬¡╘ƒoïk?Å÷√H£'O@|═XΣu₧
Ñj╨óLh\Gt"σsó}α\°|0e Bå
ƒ'αí╖k9½│%xLτì∙6╕<┬q║Q:αô«Fnⁿ╟å╜çÅÇ║5DÜJ£ε@╟▄╢Zn∞bò╩oy:Ü¡αúáâ7y) è*?w┴@T1Ω&╚╓╓÷¢éÉ╫ÄçmÑ╣,╕$╕Q»u±:"]²+*╩èä°ëÅΣΩ¬╘Φ≥╘├iG╝╘@ñç
 Dj▌ÉÜ=≤
x0u≈$;±╩ I╫T╫bsvφ
#Ñ╦av╘πJ
Begin emission:
..................................................................................................................................................................................................................................................................................................................


from scapy.all import *
import os

# Interacts with a client by going through the three-way handshake.
# Shuts down the connection immediately after the connection has been established.
# Akaljed Dec 2010, http://www.akaljed.wordpress.com

# Wait for client to connect.
a=sniff(count=1,filter="tcp and host 192.168.3.245 and port 80")

# some variables for later use.
ValueOfPort=a[0].sport
SeqNr=a[0].seq
AckNr=a[0].seq+1

# Generating the IP layer:
ip=IP(src="192.168.3.245", dst="192.168.100.1")
# Generating TCP layer:
TCP_SYNACK=TCP(sport=80, dport=ValueOfPort, flags="SA", seq=SeqNr, ack=AckNr, options=[('MSS', 1460)])

#send SYNACK to remote host AND receive ACK.
ANSWER=sr1(ip/TCP_SYNACK)

# Capture next TCP packets with dport 80. (contains http GET request)
GEThttp = sniff(filter="tcp and port 80",count=1,prn=lambda x:x.sprintf("{IP:%IP.src%: %TCP.dport%}"))
AckNr=AckNr+len(GEThttp[0].load)
SeqNr=a[0].seq+1

# Print the GET request
# (Sanity check: size of data should be greater than 1.)
if len(GEThttp[0].load)>1: print GEThttp[0].load

# Generate custom http file content.
html1="HTTP/1.1 200 OK\x0d\x0aDate: Wed, 29 Sep 2010 20:19:05 GMT\x0d\x0aServer: Testserver\x0d\x0aConnection: Keep-Alive\x0d\x0aContent-Type: text/html; charset=UTF-8\x0d\x0aContent-Length: 291\x0d\x0a\x0d\x0a<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"><html><head><title>Testserver</title></head><body bgcolor=\"black\" text=\"white\" link=\"blue\" vlink=\"purple\" alink=\"red\"><p><font face=\"Courier\" color=\"blue\">-Welcome to test server-------------------------------</font></p></body></html>"

# Generate TCP data
data1=TCP(sport=80, dport=ValueOfPort, flags="PA", seq=SeqNr, ack=AckNr, options=[('MSS', 1460)])

# Construct whole network packet, send it and fetch the returning ack.
ackdata1=sr1(ip/data1/html1)
# Store new sequence number.
SeqNr=ackdata1.ack

# Generate RST-ACK packet
Bye=TCP(sport=80, dport=ValueOfPort, flags="FA", seq=SeqNr, ack=AckNr, options=[('MSS', 1460)])

send(ip/Bye)


from scapy.all import *
import os

# Interacts with a client by going through the three-way handshake.
# Shuts down the connection immediately after the connection has been established.
# Akaljed Dec 2010, http://www.akaljed.wordpress.com

# Wait for client to connect.
a=sniff(count=1,filter="tcp and host 192.168.3.245 and port 80")

# some variables for later use.
ValueOfPort=a[0].sport
SeqNr=a[0].seq
AckNr=a[0].seq+1

# Generating the IP layer:
ip=IP(src="192.168.3.245", dst="192.168.100.1")
# Generating TCP layer:
TCP_SYNACK=TCP(sport=80, dport=ValueOfPort, flags="SA", seq=SeqNr, ack=AckNr, options=[('MSS', 1460)])

#send SYNACK to remote host AND receive ACK.
ANSWER=sr1(ip/TCP_SYNACK)

# Capture next TCP packets with dport 80. (contains http GET request)
GEThttp = sniff(filter="tcp and port 80",count=1,prn=lambda x:x.sprintf("{IP:%IP.src%: %TCP.dport%}"))
AckNr=AckNr+len(GEThttp[0].load)
SeqNr=a[0].seq+1

# Print the GET request
# (Sanity check: size of data should be greater than 1.)
if len(GEThttp[0].load)>1: print GEThttp[0].load

# Generate custom http file content.
html1="HTTP/1.1 200 OK\x0d\x0aDate: Wed, 29 Sep 2010 20:19:05 GMT\x0d\x0aServer: Testserver\x0d\x0aConnection: Keep-Alive\x0d\x0aContent-Type: text/html; charset=UTF-8\x0d\x0aContent-Length: 291\x0d\x0a\x0d\x0a<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"><html><head><title>Testserver</title></head><body bgcolor=\"black\" text=\"white\" link=\"blue\" vlink=\"purple\" alink=\"red\"><p><font face=\"Courier\" color=\"blue\">-Welcome to test server-------------------------------</font></p></body></html>"

# Generate TCP data
data1=TCP(sport=80, dport=ValueOfPort, flags="PA", seq=SeqNr, ack=AckNr, options=[('MSS', 1460)])

# Construct whole network packet, send it and fetch the returning ack.
ackdata1=sr1(ip/data1/html1)
# Store new sequence number.
SeqNr=ackdata1.ack

# Generate RST-ACK packet
Bye=TCP(sport=80, dport=ValueOfPort, flags="FA", seq=SeqNr, ack=AckNr, options=[('MSS', 1460)])

send(ip/Bye)



On Tuesday, June 20, 2017 at 11:36:07 PM UTC+8, Ho Yeung Lee wrote:
> pkts = sniff(prn=lambda x:x.sprintf("{IP:%IP.src% -> %IP.dst%\n}{Raw:%Raw.load%\n}"), filter="tcp port 80")
> 
> for i in range(1,len(pkts)):
>     #if pkts[i][IP].sport == 80:
>         i,pkts[i][TCP].payload
> 
> i find pkts[10] do not have html source code
> 
> (8, <Raw  load='GET /index2.html HTTP/1.1\r\nHost: 192.168.3.245\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-US,en;q=0.8\r\nIf-None-Match: "100a41-15-552657bea38d3"\r\nIf-Modified-Since: Tue, 20 Jun 2017 14:58:27 GMT\r\n\r\n' |>)
> (9, <Padding  load='\x00\x00\x00\x00\x00\x00' |>)
> (10, <Raw  load='HTTP/1.1 304 Not Modified\r\nDate: Tue, 20 Jun 2017 15:28:54 GMT\r\nServer: Apache/2.2.15 (CentOS)\r\nConnection: close\r\nETag: "100a41-15-552657bea38d3"\r\n\r\n' |>)
> (11, <Padding  load='\x00\x00\x00\x00\x00\x00' |>)
> 
> dir(pkts[10][TCP])




More information about the Python-list mailing list