2016-07-10 5 views
0

Ich brauche etwas Hilfe mit Scapy und Python. ich Anfrage spesific Website senden ... und dann mit Schnüffeln und HTTP-Filter I die entsprechenden Pakete ist Filterung und ich mag dann nur den HTML-Code erhalten, aber ich weiß nicht, wie diese ...Wie HTML-Datei nach HTTP-GET-Anfrage in Scapy erstellen

os.system('iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP') 
os.system('iptables -L') 

randport = random.randint(1024,65535) 
syn = IP(dst=ip)/TCP(sport = randport, dport=80, flags='S') 

syn_ack = sr1(syn) #getting the ack 
getstr = 'GET/HTTP/1.1\r\nHost:' + url + '\r\n\r\n' 
ack = IP(dst=ip)/TCP(dport=80, sport=syn_ack[TCP].dport, 
       seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1, flags='A')/getstr 

send(ack) 
packets = sniff(count=0, lfilter=http_filter, timeout=20) 
http = open(url + ".html", "w") 

for p in packets: 
    if p[IP].src == ip: 
     #what i need to do here? 
zu tun

Hilf mir, was ich tun muss, um nur den HTML-Code zu speichern, den ganzen Code? Speichern Sie den Code ohne den HTTP-Header, nur HTML, dass ich öffnen kann und es wird mir die Website wie die Online laden

Antwort

-1

So etwas wie das?

import urllib2 
re = urllib2.urlopen("http://www.website.org") 
html = re.read() 
f = open("html.html", "w") 
f.write(html) 
f.close() 
0
from scapy. all import * 
def stopfilter(x): 
if x[IP].dst == 'src_ip': #src_ip 
    return True 
else: 
    return False 

get = 'GET /index.html HTTP/1.1\n\n' 
syn_ip = IP(src='src_ip', dst='dst_ip') #enter your ip's here 
syn_syn = TCP(sport = 5558, dport=80, flags='S',seq = 1000) 
syn_ack = sr1(syn_ip/syn_syn,verbose=0) 

if syn_ack: 
temp = syn_ack.seq 
myack = temp + 1 
ack_packet = TCP(sport=5558,dport=80,flags='A',seq=syn_ack.ack,ack=myack) 
send(syn_ip/ack_packet,verbose=0) 
payload_packet = TCP(sport=5558,dport=80,flags='A',seq=syn_ack.ack, ack=myack) 
p = syn_ip/payload_packet/get 
server_resp = sr1(p,verbose=0) 
a = sniff(iface = "eth9",filter = "tcp port 80",stop_filter=stopfilter) 

for packet in a: 
    if packet.getlayer(Raw): 
     l = packet.getlayer(Raw).load 
     rawr=Raw(l) 
     rawr.show()