Pikachu-File Inclusion, Unsafe file download & Unsafe file upload

Pikachu-File Inclusion, Unsafe file download & Unsafe file upload

File Inclusion Vulnerabilities

File Inclusion (file contains loopholes) file contains an overview, it is a function. In various development languages provide built-in file containing function, which allows developers include direct a code file (introducing) a further code file. For example, in PHP, there is provided:
the include (), include_once ()
the require (), require_once ()
These files contain functions that are frequently used in the code design.
In most cases, the file containing the code file that contains the function is fixed, and therefore will not be security problems. However, in some cases, the code contained in the file is written as a variable, and this variable can pass by the front-end user in, in this case, if you do not have enough security considerations, it may lead to a file that contains the vulnerability. Attack with a specified "unexpected" file contains the function will allow to execute, causing malicious actions. Depending on the configuration environment, the file containing the vulnerability divided into the following two situations:
1. Local file contains Vulnerability: only capable of local file server comprising, because the file is not an attacker on the server can be controlled, so that the case , the attack will contain some of the more fixed system configuration files, so read the system sensitive information. Many times local file that contains the vulnerability will be combined with some special file upload vulnerability, to form more powerful.
2. Remote File Inclusion Vulnerabilities: able to include remote files via url address, which means that an attacker can pass arbitrary code, this is nothing to say, ready wounded. Therefore, in the functional design web application front-end system, try not to let the user to directly pass variable contains the function, if you must do so, it must be done in strict whitelist filtering strategies.                     

1、File Inclusion(local)

 

 The url little thing Ha

 

 There guess file contains loopholes, so give it a try and see

 

 放一个马在目录里面

 

 然后读取康康:

 

 成功利用马进入服务器后端

2、File Inclusion(remote)

 

 

 

 这个地方对filename传参有了include的过滤,但可能存在ssrf漏洞。

http://xx.xx.xx.xx/pikachu/vul/fileinclude/fi_remote.php?filename=https://www.cnblogs.com/p201721420021/&submit=%E6%8F%90%E4%BA%A4%E6%9F%A5%E8%AF%A2

 

 

成功跳转进我自己的博客中。

不安全的文件下载

文件下载功能在很多web系统上都会出现,一般我们当点击下载链接,便会向后台发送一个下载请求,一般这个请求会包含一个需要下载的文件名称,后台在收到请求后 会开始执行下载代码,将该文件名对应的文件response给浏览器,从而完成下载。 如果后台在收到请求的文件名后,将其直接拼进下载文件的路径中而不对其进行安全判断的话,则可能会引发不安全的文件下载漏洞。
此时如果 攻击者提交的不是一个程序预期的的文件名,而是一个精心构造的路径(比如../../../etc/passwd),则很有可能会直接将该指定的文件下载下来。 从而导致后台敏感信息(密码文件、源代码等)被下载。
所以,在设计文件下载功能时,如果下载的目标文件是由前端传进来的,则一定要对传进来的文件进行安全考虑。 切记:所有与前端交互的数据都是不安全的,不能掉以轻心!
                     

 

 3、unsafe filedownload

 

 

 要求是点击图片可以下载

 那还是科比吧链接如下:

http://192.168.1.108/pikachu/vul/unsafedownload/execdownload.php?filename=kb.png

既然可以直接通过filename读取文件,那就直接构造payload:

http://192.168.1.108/pikachu/vul/unsafedownload/execdownload.php?filename=../../../shengcheng.txt

 

读取网站后台服务器上的文件成功。

 

不安全的文件上传漏洞

不安全的文件上传漏洞概述文件上传功能在web应用系统很常见,比如很多网站注册的时候需要上传头像、上传附件等等。当用户点击上传按钮后,后台会对上传的文件进行判断 比如是否是指定的类型、后缀名、大小等等,然后将其按照设计的格式进行重命名后存储在指定的目录。 如果说后台对上传的文件没有进行任何的安全判断或者判断条件不够严谨,则攻击着可能会上传一些恶意的文件,比如一句话木马,从而导致后台服务器被webshell。 所以,在设计文件上传功能时,一定要对传进来的文件进行严格的安全考虑。比如:
--验证文件类型、后缀名、大小;
--验证文件的上传方式;
--对文件进行一定复杂的重命名;
--不要暴露文件上传后的路径

4、client check

 

 

 有一个提示。

 先判断是在前端还是后端有验证:

 

 查看该函数源码

 1 function checkFileExt(filename)
 2     {
 3         var flag = false; //状态
 4         var arr = ["jpg","png","gif"];
 5         //取出上传文件的扩展名
 6         var index = filename.lastIndexOf(".");
 7         var ext = filename.substr(index+1);
 8         //比较
 9         for(var i=0;i<arr.length;i++)
10         {
11             if(ext == arr[i])
12             {
13                 flag = true; //一旦找到合适的,立即退出循环
14                 break;
15             }
16         }
17         //条件判断
18         if(!flag)
19         {
20             alert("上传的文件不符合要求,请重新选择!");
21             location.reload(true);
22         }
23     }

那可以直接上传。

按照要求包装好一个假的gif

 

 burpsuite抓包抓到手:

 

 修改文件后缀为php

 

 可以看到已经上传成功了

 

 小马被成功上传

 

 构造payload

http://your ip/pikachu/vul/unsafeupload/uploads/shengcheng.php?x=1

 

 成功读取服务器后端数据库

5、MIME type

 

 这一次并不是在前端进行验证。

 

根据要求修改后缀后上传

 

 抓包后修改包内内容后上传:

 

这里只是加了一个文件类型的判断。可以直接略过。

同理:

 

 

5、getimagesize()

 

 发现仍然没有前端的过滤,但是会判定是否为真的图片。

 (我欺骗你不就是为了完成作业的吗我容易嘛我……)

 

提示里说是对图片的大小有判定,那我们可以尝试把木马藏在图片里上传

 

 先准备一张图片:

(小声bb:祢豆子天下第一可爱)

然后修改一下:

 

 发现上传成功了:

 

 抓包看一下:

 

 老规矩,修改后缀

 

报错了

 

 而且从之前上传成功的那一张来看,后端会重新命名你的照片,所以单纯修改文件后缀貌似是没有用的。

 

 (00截断也不行)

既然我们已经能把含有木马的文件上传至后端,那可以利用文件包含漏洞读取木马了。

先保存路径:

 

 然后找到之前的文件包含漏洞的网页:

url修改一下:

 

 多试几次就可以了:

http://your ip/pikachu/vul/fileinclude/fi_local.php?filename=../../unsafeupload/uploads/2019/12/22/1787915dfedbd8b2786128645616.jpg&submit=%E6%8F%90%E4%BA%A4%E6%9F%A5%E8%AF%A2

 

 成功读取出后端数据库。

Guess you like

Origin www.cnblogs.com/p201721420021/p/12078205.html