【问题标题】:How to create html file after HTTP GET request in scapy如何在scapy中的HTTP GET请求后创建html文件
【发布时间】:2023-03-06 13:50:01
【问题描述】:

我需要一些关于 scapy 和 python 的帮助。 我向特定站点发送获取请求...然后使用嗅探和 HTTP 过滤器过滤相关数据包,然后我只想获取 HTML 代码,但我不知道该怎么做...

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?

帮帮我,我需要做什么才能只保存 HTML 代码,整个代码?保存不带 HTTP 标头的代码,只是我可以打开的 HTML,它会像在线网站一样加载我的网站

【问题讨论】:

    标签: python html http scapy packets


    【解决方案1】:
    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()
    

    【讨论】:

      【解决方案2】:

      这样的?

      import urllib2
      re = urllib2.urlopen("http://www.website.org")
      html = re.read()
      f = open("html.html", "w")
      f.write(html)
      f.close()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-12
        • 2015-08-20
        • 1970-01-01
        • 2016-03-05
        • 2017-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多