Technology sharing: How to Use File Upload to execute XSS?

Source: Internet
Author: User

Technology sharing: How to Use File Upload to execute XSS?

ExploitationFile UploadImplement XSS attacksIs a HackingThere are good opportunities for Web applications, especially in the case of ubiquitous upload of user portraits, which gives us many opportunities to discover developers' errors. Basic File Upload XSS attacks include.

1) file name

The file name itself may be part of a webpage that can cause reflection. Therefore, you can insert XSS statements into the file name to trigger reflection.

 

Although not intentionally, this XSS can be used in W3Schools.

2) Metadata

You can use the exiftool to modify the EXIF metadata, causing reflection in some places:

$ exiftool -FIELD=XSS FILE

Example:

$ exiftool -Artist=’ “>’ brute.jpeg

 

3) Content

If a Web application allows the upload of an SVG (an image type) extension, the following content can be used to trigger XSS:

<svg xmlns="http://www.w3.org/2000/svg" onload="alert(document.domain)"/>

A poc can be seen here in brutelogic.com.br/poc.svg.

4) source code

We can easily create a GIF image containing javascript payload and reference it as the source code. If we can successfully inject the same domain name, as shown below, this can effectively help us bypass CSP (Content Security Policy) Protection (which cannot be executed for Example<script>alert(1)</script>)

 

To create such an image, you can use the following content and name the file as. gif Suffix:

GIF89a/*
  
   */=alert(document.domain)//;
  

The GIF File ID GIF89a is assigned to the alert function as a javascript variable. The XSS of the intermediate annotation is used to prevent the image from being retrieved as the text/html mime type, and the payload is executed by the request file.

We can find that both the PHP function exif_imagetype () and getimagesize () of UNIX Commands recognize this file as a GIF file. Generally, Web applications use these functions to verify the image type. Therefore, such a file can be uploaded (but it may be scanned and killed by anti-virus software ).

Related Article

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.