pikachu-file

1. Download the file unsafe

1.1 Overview

File download function will appear on many web systems, generally when we click on the download link, it will send a download request to the background, this request will usually contain the name of a file to be downloaded, backstage after receiving the request will begin to download the code , the file name of the corresponding file response to the browser to complete the download. If the file name backstage after receiving the request, it will download the file directly into the fight in the path of its security without judgment, then it could lead to unsafe file download vulnerability.
At this time, if the attacker is not expected to submit a program file name , but a carefully constructed path (such as ../../../etc/passwd), it is likely to be the specified file directly download. Resulting in a sensitive background information (password files, source code, etc.) is downloaded. Therefore, in the design file download function, if the downloaded file is passed by the goal came in the front, then the file must be passed in safety considerations.

Remember: All data and front-end interaction is unsafe and can not be taken lightly!

1.2. Experiment
Our first test, select kobe

 

Find url changes occur

 

 

 

 http://172.22.215.51:88/pikachu/vul/unsafedownload/execdownload.php?filename=XXXX

2.File Inclusion(remote)

 

Second, file download
Open the site you can find tips click on the link to download the picture.
 

 

After seeing this link to download the use ../ file to download,
 
 
 

 

2. unsafe file upload

 

2.1 Overview

Because the business functional needs, many Web sites have a file upload interface, such as:

  • Upload registration avatar picture (such as jpg, png, gif, etc.)
  • Upload file attachments (doc, xls, etc.)

而在后台开发时,并没有对上传的文件进行安全考虑,或者采用了有缺陷的措施,导致攻击者可以通过一些手段绕过安全措施从而上传一些恶意文件(如:一句话木马)

从而通过对该恶意文件的访问来控制整个 Web 后台

 

2.2.测试流程

  • 对文件上传的地方按照要求上传文件,查看返回结果(路径,提示等)
  • 尝试上传不同类型的 “ 恶意 ” 文件,比如 xx.php 文件,分析结果
  • 查看 html 源码,看是否通过 js 在前端做了限制,可以绕过
  • 尝试使用不同方式进行绕过:黑白名单绕过 / MIME类型绕过 / 目录0x00截断绕过等
  • 猜测或者结合其他漏洞(比如敏感信息泄露等)得到木马路径,连接测试
 

2.3.客户端 check

我们先进行 客户端check 这个实验,这里只允许我们上传图片

 

 下面看一下这个限制是不是通过前端完成的

 

但是前端做的限制只是辅助作用,是可以绕过的,比如直接删掉 onchange 中的内容

 

 

 成功上传

2.4.服务端check

MIME

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

每个MIME类型由两部分组成,前面是数据的大类别,例如声音audio、图象image等,后面定义具体的种类。常见的 MIME 类型,比如:

  • 超文本标记语言:.html,.html text.html
  • 普通文件:.txt text/plain
  • RTF文件:.rtf application/rtf
  • GIF图形:.gif image/gif
  • JPEG图形:.jpeg,.jpg image/jpeg

$_FILES()函数

它从浏览器的HTTP头里获取 Content-Type ,这个 Content-Type 前端用户是可以控制的

通过使用 PHP 的全局数组 $_FILES,你可以从客户计算机向远程服务器上传文件

第一个参数是表单的 input name,第二个下标可以是 “name”,“type”,“size”,“tmp_name” 或 “error”,就像这样:

  • $_FILES['file']['name']:被上传文件的名称
  • $_FILES['file']['type']:被上传文件的类型
  • $_FILES['file']['size']:被上传文件的大小
  • $_FILES['file']['tmp_name']:存储在服务器的文件的临时副本的名称
  • $_FILES['file']['error']:由文件上传导致的错误代码

实验

当我们上传一个 php 文件时,会报错,下面通过 BurpSuite 修改请求头

 

 

Guess you like

Origin www.cnblogs.com/P201721210044/p/12061808.html