File Upload(文件上传)(upload-labs 1-5)

本文深入探讨了文件上传漏洞的原理及危害,通过具体案例演示如何利用上传漏洞获取webshell权限,同时提供了有效的防御策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 文件上传介绍
    在现代的互联网WEB应用程序中,上传文件是一种常见的功能,它有助于提高业务效率,比如企业的OA系统,允许用户上传头像、照片等许多类型的文件。然而,开放的功能越多,WEB应用受到攻击的风险越大。如果WEB应用存在文件上传漏洞,那么攻击者就可以利用这个漏洞将可执行脚本程序上传到服务器中,获得网站的权限从而进一步危害服务器

  2. 文件上传原理
    文件上传漏洞通常是未对客户端上传文件的类型、内容没有进行严格的过滤、检查,就很容易造成可以上传任意文件的情况,包括上传脚本文件,从而获得服务器的webshell权限,控制整个网站,甚至控制服务器,造成严重危害

  3. 文件上传的技巧
    测试平台:upload-labs在这里插入图片描述
    pass-01:
    查看提示:在这里插入图片描述
    这里是在客户端进行的过滤,js对文件后缀名做了白名单限制。很好绕过,F12调出元素查看器,将onsubmit事件删除即可,这样提交表单时便不会触发验证函数从而绕过
    在这里插入图片描述
    上传成功,在图片信息中查看图片路径
    在这里插入图片描述
    用菜刀去连接,成功!!!
    在这里插入图片描述
    pass-02:
    查看提示:
    在这里插入图片描述
    这是在服务器端做了验证,代码层对文件的MIME类型进行了检查,可以使用burp抓包,修改文件上传的content-type类型为白名单允许的图片MIME类型
    在这里插入图片描述
    上传的网页大马,访问图片地址,输入密码成功拿到webshell
    在这里插入图片描述
    pass-03:
    查看提示:
    在这里插入图片描述
    这里是黑名单检测,但是在黑名单里没有.htacess文件做限制,所以我们可以通过先上传.htaccess,然后再上传webshell文件
    .htaccess文件内容如下:
    在这里插入图片描述
    这句话的含义是:将上传的文件后缀名为.jpg格式的文件以 php格式来解析文件,所以我们就上传php文件,然后通过抓包修改文件名为.jpg即可
    在这里插入图片描述
    在这里插入图片描述

pass-04:
查看提示:

这关跟第四关的方法一样,也是上传.htaccess,然后更改文件后缀名为相关文件上传即可

pass-05:
查看提示:
在这里插入图片描述
这个过滤了挺多的,尝试通过大小写绕过
在这里插入图片描述
上传成功,访问图片地址,成功
在这里插入图片描述

  1. 修复建议
    (1)通过白名单的方式判断后缀名是否合法
    (2)对上传后的文件名进行重命名

  2. 拓展:
    数据包的MIME:MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型。是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开。多用于指定一些客户端自定义的文件名,以及一些媒体文件打开方式。

    .htaccess文件:.htaccess(超文本访问)是许多Web服务器根据目录应用设置的有用文件,允许在运行时覆盖Apache服务器的默认配置。使用.htaccess,我们可以在运行时轻松启用或禁用任何功能。

### Upload-Labs Web Security Learning Platform Guide Upload-labs is a web application designed to help users learn about file upload vulnerabilities and secure coding practices through practical exercises. Each level presents different challenges related to insecure file uploads, allowing learners to progressively build skills. #### Level 1: Basic File Upload Vulnerability In this initial stage, the system allows any type of files to be uploaded without restrictions or validation checks[^2]. Demonstrating how easy it can be for an attacker to exploit such weaknesses by uploading malicious scripts. ```html <form action="upload.php" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload Image" name="submit"> </form> ``` #### Levels 2-5: MIME Type Validation Bypass Techniques These stages introduce various methods attackers might use to bypass simple content-type validations implemented on servers. For instance, changing HTTP headers or exploiting browser behavior differences when handling certain extensions[^3]. #### Levels 6-9: Client-Side vs Server-Side Validations Levels focus specifically on distinguishing between client-side JavaScript controls versus server-side PHP logic enforcement during file selection processes. Highlighting why relying solely upon front-end mechanisms cannot guarantee protection against unauthorized submissions[^4]. #### Levels 10-13: Filename Manipulation Attacks This section explores techniques used to manipulate filenames before submission, including appending special characters or encoding schemes that may confuse parsers into accepting disallowed formats under specific conditions[^5]. #### Levels 14-17: Directory Traversal Prevention Methods Addressing issues where improperly sanitized paths could lead to arbitrary code execution outside intended directories within filesystem structures managed by applications hosting these features[^6]. #### Levels 18-21: Advanced Exploitation Scenarios & Mitigation Strategies Final set covers more sophisticated attack vectors like zero-day exploits targeting lesser-known bugs alongside best practice recommendations aimed at mitigating risks associated with implementing robust defenses across all layers involved in processing user-supplied data points[^7]. For each challenge presented throughout twenty-one progressive tasks offered via Upload-Labs environment, participants gain hands-on experience identifying common pitfalls while simultaneously learning effective countermeasures necessary for safeguarding modern web platforms from potential threats posed due to improper management around file-handling operations.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值