DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Shrink a Bloated Git Repository and Optimize Pack Files
  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Developer Git Commit Hygiene
  • A Comprehensive Guide to GitHub

Trending

  • Beyond Manual Mapping: AI-Orchestrated Governance for Hybrid Cloud
  • A Software Factory on Kubernetes: Gemini Builds, jev Decides (Genkit + senro in Go)
  • Google Cloud KMS vs. AWS KMS: Java Encryption Guide
  • GET, POST, PUT, DELETE: Choosing HTTP Verbs in a Real .NET Core Web API, Not Just by the Textbook

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Some Image-Based Exploits With Their Prevention

Some Image-Based Exploits With Their Prevention

We take a look at image-based exploits that are common to websites, in this case, those that are backed by PHP. We also look at what devs can do to prevent them.

By 
Anurag Jain
·
Jul. 25, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
4.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Images can be used to run malicious scripts over the browser and can also be used to download Trojans if not handled carefully by your website. Too much trust on user input can cause damage to your clients.

In this post, we will run malicious scripts using a simple image viewer functionality and lastly we will discuss how we can resolve this.

Programming Language

HTML, PHP

Git Repository

https://github.com/csanuragjain/extra/tree/master/ImageExploit

Website

https://cooltrickshome.blogspot.in/2017/07/some-image-based-exploits-with-their.html

One of Image Vulnerability I reported:

https://hackerone.com/reports/221928

Scenario #1:

In this scenario, we will show how lacking Content-Type while displaying images can run malicious scripts.

 Malicious Image



Description

1)  Right Click on the above Image and then choose 'Save Image As.'

2) Name it as exifxss.jpg and save it.

3) Otherwise, you can also get it from the git location.

showImage.php

 <?php  
 include('exifxss.jpg');  
 ?>  

Description

A simple PHP file showing the above .jpg file.

Output:

  1. When you access showImage.php on your browser, you will expect to see the image but instead, you will see several pop-ups coming up.
  2. This happens because the PHP page is not setting the Content-Type which makes PHP show the image as HTML. Since the image has several alert messages, they start popping up.
  3. showImage.php needs to make sure that it sets the correct Content-Type and also make sure that it does not set the user provided Content-Type.


Scenario #2:

In this scenario, we will show how a simple looking image when downloaded can become an exploit.

Caution: This will run notepad, calc, msconfig, services.msc on your computer, although it won't perform anything malicious.

Malicious Image


Description

1)  Right Click on above Image and then choose 'Save Image As.'

2) Name it as exifxss.bat and Save it.

3) Otherwise, you can also get it from the git location.


showImage2.html

 <img src="image.bat" width=500 height=500/>  


Description

A simple HTML file showing the image image.bat.

Output:

  1. On accessing the above HTML, you would see the Bugs Bunny image (nothing suspicious).
  2. Now, right click on the image and save the image. It should be saved as image.bat.
  3. On opening it, the malicious payload gets executed, opening up notepad, services.msc, msconfig, and calc.
  4. To prevent it, make sure that users are never allowed to store any non-image extension file.

Please let me know your suggestions and comments.

Hope it helps!

HTML PHP Git Trust (business) Vulnerability Repository (version control) POST (HTTP) Payload (computing)

Published at DZone with permission of Anurag Jain. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Shrink a Bloated Git Repository and Optimize Pack Files
  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Developer Git Commit Hygiene
  • A Comprehensive Guide to GitHub

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook