淘宝某站源码泄露及SQL注入分析拿下淘宝某站源码,分析sql注入漏洞及绕过svn导致源码泄露:http://ip.taobao.com/.svn/entries
拿下源码
接下来分析源码:
1.敏感信息泄露,数据库信息:
2.sql注入分析
getFeedbackRecord.php源码:
<?php
require_once("./common.php");
require_once('../runtime_start.php');
if (!is_user_login()) {
response_data(FAILED, 'user not login');
exit(1);
}
$page = 1;
$rows = 1;
if (!isset($_REQUEST['page'])) {
response_data(FAILED, 'no page param.');
exit(1);
} else {
$page = $_REQUEST['page'];
}
if (!isset($_REQUEST['rows'])) {
response_data(FAILED, 'no rows param.');
exit(1);
} else {
$rows = $_REQUEST['rows'];
}
$wangwang_id = $_COOKIE['wangwang_id'];
$start = $rows * ($page-1);
$len = $rows;
$con = init_db();
if (!$con) {
response_data(FAILED, 'database error');
echo "conn error\n";
exit(1);
}
$query_sql = "SELECT SQL_CALC_FOUND_ROWS ip, country, region, city, county, isp, feedback_type, feedback_date FROM user_feedback_item WHERE wangwang_id='".addslashes($wangwang_id). "' order by id desc LIMIT ".intval($start).", ".intval($len);
$res = mysql_query($query_sql, $con);
if ($res) {
$rows = array();
while($temp = mysql_fetch_array($res, MYSQL_ASSOC)) {
$rows[] = $temp;
}
$item_num = 0;
$ttl_sql = "SELECT FOUND_ROWS() as item_num ";
$ttl_rlt = mysql_query($ttl_sql, $con);
if($ttl_rlt && $ttl_row = mysql_fetch_array($ttl_rlt, MYSQL_ASSOC)) {
$item_num = $ttl_row['item_num'];
mysql_free_result($ttl_rlt);
}
$items = array();
$items['total'] = ceil($item_num/$len);
$items['rows'] = $rows;
$items['records'] = $item_num;
$items['page'] = $page;
response_data(SUCCESS, $items);
mysql_free_result($res);
} else {
response_data(FAILED, 'database error');
}
mysql_close($con);
?>
可知只要登录账户,提交page,rows参数,控制$_COOKIE['wangwang_id'],可构造$query_sql 语句执行。其中:
$query_sql = "SELECT SQL_CALC_FOUND_ROWS ip, country, region, city, county, isp, feedback_type, feedback_date FROM user_feedback_item WHERE wangwang_id='".addslashes($wangwang_id). "' order by id desc LIMIT ".intval($start).", ".intval($len);
$wangwang_id经过addslashes处理,但仍让可以通过双字符绕过,形成注入。page,rows参数最终经过取整,无法利用,于是抓包构造cookies。
额。。。修改了wangwang_id导致is_user_login()判断用户未登录。伤心
于是查看文件function.inc.php
//判断用户是否登陆
function is_user_login() {
return !empty($_COOKIE['_t'])
&& !empty($_COOKIE['wangwang_id'])
&& get_passport_token($_COOKIE['wangwang_id']) == $_COOKIE['_t'];
}
额...如此坑爹的程序员,判断是否登录都能这么屌,完全是$_COOKIE['_t'])和$_COOKIE['wangwang_id']两个用户能自己构造的参数来判断,两个参数还不是HttpOnly
不过我目的不是绕过登录任意用户,俺要的是注入时绕过is_user_login(),于是再看看get_passport_token():
define(ALIBENCH_ENCRYPT_KEY, 'XXX专业打码30年');
//获取登陆密钥
function get_passport_token($uid)
{
return substr(md5($uid . ALIBENCH_ENCRYPT_KEY), 0, 12);
}
这样一来只要构造$_COOKIE['wangwang_id']为注入语句,并且通过上面的算法构造$_COOKIE['_t']就能无视注入时is_user_login()判断用户是否登录的限制了。
功夫不负有心人,懒得自己写脚本去构造注入了,于是乎。。。。你们自己搞定