Advertisement
opexxx

http_client.py

Apr 10th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.17 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Created on 08.04.2012
  4.  
  5. @author: gescheit
  6. '''
  7. from scapy.all import *
  8. import sys
  9. import random
  10. import time
  11. import IPy
  12. from threading import Thread
  13. import os
  14.  
  15. dst = "2a02:6b8::1000:1000" #ipv6.yandex.ru
  16. #dst = "77.88.16.67"
  17. dport = 12345
  18. my_payload = "GET /testdata HTTP/1.0\r\n\r\n"
  19. #my_payload = "GET /?ncrnd=1394397669 HTTP/1.1\r\nHost:ipv6.yandex.ru\r\n\r\n"
  20. mss = 9000
  21.  
  22. dst_type = IPy.IP(dst).version()
  23. if dst_type == 4:
  24.     ip = IP(dst=dst, flags="DF")
  25. elif dst_type == 6:
  26.     ip = IPv6(dst=dst)
  27.  
  28. soport = random.randint(1024, 65000)
  29. packets = []
  30.  
  31.  
  32. def arp_monitor_callback(pkt):
  33.     packets.append(pkt)
  34.     #if ARP in pkt and pkt[ARP].op in (1, 2): #who-has or is-at
  35.     #    return pkt.sprintf("%ARP.hwsrc% %ARP.psrc%")
  36. #запускаем снифер
  37. sfilter = "tcp and port %s" % soport
  38.  
  39.  
  40. def snifff():
  41.     sniff(prn=arp_monitor_callback, filter=sfilter, store=0)
  42.  
  43. t = Thread(target=snifff)
  44. t.start()
  45.  
  46. SYN = TCP(dport=dport, flags="S", options=[("MSS", mss)], sport=soport, seq=RandNum(100, 150), window=18000)
  47. ans, unans = sr(ip / SYN)
  48.  
  49. print "SEND:", ans[0][0].show()
  50. print "RCV:", ans[0][1].show()
  51.  
  52. #my_payload = "GET /javascripts/jquery.fcbkcomplete.js?1322596141 HTTP/1.0\r\n\r\n"
  53. #my_payload = "GET /jquery/1.6.2/jquery.min.js HTTP/1.0\r\nHost: yandex.st\r\n\r\n"
  54. #my_payload = "GET /testdata HTTP/1.0\r\n\r\n"
  55.  
  56. #просто подтверждает SYN/ACK
  57. ACK = TCP(dport=dport, flags="A", sport=soport, ack=ans[0][1].seq + 1, seq=ans[0][1].ack)
  58. send(ip / ACK)
  59. #rint "SEND:", ans[0][0].show()
  60. #nt "RCV:", ans[0][1].show()
  61.  
  62.  
  63. #делаем запрос
  64. ACK = TCP(dport=dport, flags="PA", sport=soport, ack=ans[0][1].seq + 1, seq=ans[0][1].ack)
  65. ans, unans = sr(ip / ACK / my_payload, retry=0, timeout=3)
  66. print "SEND:", ans[0][0].show()
  67. print "RCV:", ans[0][1].show()
  68.  
  69. if dst_type == 4:
  70.     tcp_payload_size = packets[-1][IP].len - packets[-1][TCP].dataofs * 8
  71. elif dst_type == 6:
  72.     tcp_payload_size = packets[-1][IPv6].plen - packets[-1][TCP].dataofs * 8
  73.  
  74. #подтверждание? хрен, надо payload tcp, который во втором пакете на предыдущий запрос
  75. ACK = TCP(dport=dport, flags="A", sport=soport, ack=ans[0][1].seq + tcp_payload_size, seq=ans[0][1].ack)
  76. ans, unans = sr(ip / ACK, retry=0, timeout=1)
  77. #print "SEND:", ans[0][0].show()
  78. #print "RCV:", ans[0][1].show()
  79.  
  80. os._exit(1)
  81.  
  82. #TOOBIG = ICMPv6PacketTooBig(mtu=1001)
  83. #ans2, unans2 = sr(ip / TOOBIG / ans[0][1], retry=0, timeout=3)
  84. #print "SEND:", ans2[0][0].show()
  85. #print "RCV:", ans2[0][1].show()
  86.  
  87. TOOBIG = ICMP(type=3, code=4, unused=200)
  88. ans2, unans2 = sr(ip / TOOBIG / ans[0][1], retry=0, timeout=3)
  89. if ans2:
  90.     print "SEND:", ans2[0][0].show()
  91.     print "RCV:", ans2[0][1].show()
  92.  
  93.  
  94. ACK = TCP(dport=dport, flags="A+DF", sport=soport, ack=ans[0][1].seq + 1, seq=ans[0][1].ack)
  95. ans, unans = sr(ip / ACK, retry=0, timeout=3)
  96. print "SEND:", ans[0][0].show()
  97. print "RCV:", ans[0][1].show()
  98.  
  99.  
  100.  
  101.  
  102. #time.sleep(2)
  103. FIN = TCP(dport=80, flags="F", sport=soport, ack=ans[0][1].seq + 1, seq=ans[0][1].ack)
  104. ans, unans = sr(ip / FIN)
  105. print "SEND:", ans[0][0].show()
  106. print "RCV:", ans[0][1].show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement