Guest User

Untitled

a guest
Apr 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. #include <Array.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <WindowsConstants.au3>
  4. #Include <GuiListView.au3>
  5. #include <StaticConstants.au3>
  6. #include <EditConstants.au3>
  7. #Include <WinAPI.au3>
  8. #include <ComboConstants.au3>
  9.  
  10. #include <Winpcap.au3>
  11.  
  12. $winpcap=_PcapSetup()
  13. If ($winpcap=-1) Then
  14. MsgBox(16,"Pcap error !","WinPcap not found !")
  15. exit
  16. EndIf
  17.  
  18. $pcap_devices=_PcapGetDeviceList()
  19. If ($pcap_devices=-1) Then
  20. MsgBox(16,"Pcap error !",_PcapGetLastError())
  21. exit
  22. EndIf
  23.  
  24. $int=SelectInterface($pcap_devices)
  25.  
  26. $pcap=_PcapStartCapture($pcap_devices[$int][0],"host "&$pcap_devices[$int][7]&" and tcp port (80 or 8080)",0,65536,2^24,0)
  27. If IsInt($pcap) Then
  28. MsgBox(16,"Pcap error !",_PcapGetLastError())
  29. _PcapFree()
  30. exit
  31. EndIf
  32.  
  33. $file = FileOpen("domains.txt", 1)
  34.  
  35. ; Check if file opened for writing OK
  36. If $file = -1 Then
  37. MsgBox(0, "Error", "Unable to open file.")
  38. Exit
  39. EndIf
  40.  
  41. $i=0
  42. Do
  43.  
  44. If IsPtr($pcap) Then ; If $pcap is a Ptr, then the capture is running
  45. $time0=TimerInit()
  46. While (TimerDiff($time0)<500) ; Retrieve packets from queue for maximum 500ms before returning to main loop, not to "hang" the window for user
  47. $packet=_PcapGetPacket($pcap)
  48. If IsInt($packet) Then ExitLoop
  49.  
  50. $http=HttpCapture($packet[3])
  51.  
  52. If $http == False Then ContinueLoop
  53.  
  54. FileWriteLine($file, $http & @CRLF)
  55. $i+=1
  56. Wend
  57. EndIf
  58.  
  59. Until false
  60.  
  61. ; close all remaining open captures
  62. For $j=0 to Ubound($recordings)-2
  63. _WinAPI_CloseHandle($recordings[$j][1])
  64. Next
  65.  
  66. ; close winpcap wrapper
  67. _PcapStopCapture($pcap)
  68. _PcapFree()
  69.  
  70. Func HttpCapture ($data)
  71. Local $ipheaderlen=BitAnd(_PcapBinaryGetVal($data,15,1),0xF)*4
  72. Local $tcpoffset=$ipheaderlen+14
  73. Local $tcplen=_PcapBinaryGetVal($data,17,2)-$ipheaderlen ; ip total len - ip header len
  74. Local $tcpheaderlen=BitShift(_PcapBinaryGetVal($data, $tcpoffset+13,1),4)*4
  75. Local $tcpsrcport=_PcapBinaryGetVal($data,$tcpoffset+1,2)
  76. Local $tcpdstport=_PcapBinaryGetVal($data,$tcpoffset+3,2)
  77. Local $tcpsequence=_PcapBinaryGetVal($data,$tcpoffset+5,4)
  78. Local $tcpflags=_PcapBinaryGetVal($data, $tcpoffset+14,1)
  79. Local $r[2]=["",""]
  80.  
  81. ; From here, we are watching http payload
  82. Local $httpoffset=$tcpoffset+$tcpheaderlen+1
  83. Local $httplen=$tcplen-$tcpheaderlen
  84. If $httplen=0 Then return false
  85.  
  86. Local $http=BinaryToString(BinaryMid ($data, $httpoffset, $httplen))
  87.  
  88. Local $host = StringRegExp ( $http, "Host: (.*)" , 1)
  89.  
  90. If @Error<>0 Then return false
  91.  
  92. return $host[0]
  93. EndFunc
  94.  
  95. Func SelectInterface($devices) ; auto selects an ethernet pcap interface or prompt user for choice
  96. Local $ipv4=0,$int=0,$i,$win0,$first,$interface,$ok,$which,$msg
  97. For $i=0 To Ubound($devices)-1
  98. If $devices[$i][3]="EN10MB" AND StringLen($devices[$i][7])>6 Then ; for ethernet devices with valid ip address only !
  99. $ipv4+=1
  100. $int=$i
  101. EndIf
  102. Next
  103. If $ipv4=0 Then
  104. MsgBox(16,"Error","No network interface found with a valid IPv4 address !")
  105. _PcapFree()
  106. Exit
  107. EndIf
  108. If $ipv4>1 Then
  109. $win0=GUICreate("Interface choice", 500, 50)
  110. $interface=GUICtrlCreateCombo("", 10, 15, 400,default,$CBS_DROPDOWNLIST)
  111. $first=true
  112. For $i = 0 to Ubound($devices)-1
  113. If $devices[$i][3]="EN10MB" AND StringLen($devices[$i][7])>6 Then
  114. If $first Then
  115. GUICtrlSetData(-1, $devices[$i][7]&" - "&_PcapCleanDeviceName($devices[$i][1]),$devices[$i][7]&" - "&_PcapCleanDeviceName($devices[$i][1]))
  116. $first=false
  117. Else
  118. GUICtrlSetData(-1, $devices[$i][7]&" - "&_PcapCleanDeviceName($devices[$i][1]))
  119. EndIf
  120. EndIf
  121. Next
  122. $ok=GUICtrlCreateButton ( " Ok ", 430, 15,60)
  123. GUISetState()
  124. While true
  125. $msg = GUIGetMsg()
  126. If $msg=$ok Then
  127. $which=GUICtrlRead($interface)
  128. For $i=0 To Ubound($devices)-1
  129. If StringLen($devices[$i][7])>6 AND StringInStr($which,$devices[$i][7]) Then
  130. $int=$i
  131. ExitLoop
  132. EndIf
  133. Next
  134. GUIDelete($win0)
  135. ExitLoop
  136. EndIf
  137. If $msg=$GUI_EVENT_CLOSE Then Exit
  138. Wend
  139. EndIF
  140. return $int
  141. EndFunc
Add Comment
Please, Sign In to add comment