Linux filename xss

Source: Internet
Author: User

1. File Name
We all know that in windows, there are rules for file names and some reserved characters are defined. They are:

< (less than)> (greater than): (colon)" (double quote)/ (forward slash) (backslash)| (vertical bar or pipe)? (question mark)* (asterisk)

In linux, most of these characters are not restricted and can be defined at will. Therefore, we can store XSS Pyload in the file name ,:

We can see that xss pyload is successfully stored in the file name.
Ii. Attack
Most of the time, the various code environments make it possible for us to launch attacks. Check the following PHP file upload code:

<?phpif ($_FILES["file"]["error"] > 0)  {  echo "Error: " . $_FILES["file"]["error"] . "<br />";  }else  {  echo "Upload: " . $_FILES["file"]["name"] . "<br />";  echo "Type: " . $_FILES["file"]["type"] . "<br />";  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";  echo "Stored in: " . $_FILES["file"]["tmp_name"];  }?> 

When the file is uploaded successfully, the program outputs the file information. At this time, the file name is not processed. If we upload the file name of the defined special character and output it through the program, we can attack it ,:

We can see that the attack was successful! Not all upload locations exist. Only the following conditions must be met:
1. An original output is made before the file is uploaded and saved.
2. Store them directly by the original file name.
3. Check the program logic for other specific environments.
4. web server is linux.
5. Upload the attacker to linux.
Sample Code: http://code.google.com/p/madal-example-project/source/browse/trunk/controllers/image_uploader.php? R = 2
For more information, see http://code.google.com/query/?q===_files=%22file=22???=22name=22].
Online attack test: http://www.woyigui.cn/fileupload.php

Iii. Prevention
1. Save as a random file name during storage.
2. After processing the file name at any time, the file name can be output after html encoding.

Iv. Statement
The idea of this article comes from the idea of drinking miao at night. I just want to summarize and verify it.

Refer:

Http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx

Reprinted Please note: woyiguis blog

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.