Waraxe IT Security Portal
Login or Register
July 27, 2024
Menu
Home
Logout
Discussions
Forums
Members List
IRC chat
Tools
Base64 coder
MD5 hash
CRC32 checksum
ROT13 coder
SHA-1 hash
URL-decoder
Sql Char Encoder
Affiliates
y3dips ITsec
Md5 Cracker
User Manuals
AlbumNow
Content
Content
Sections
FAQ
Top
Info
Feedback
Recommend Us
Search
Journal
Your Account
User Info
Welcome, Anonymous
Nickname
Password
(Register)

Membership:
Latest: MichaelSnaRe
New Today: 0
New Yesterday: 0
Overall: 9144

People Online:
Visitors: 215
Members: 0
Total: 215
Full disclosure
CyberDanube Security Research 20240722-0 | Multiple Vulnerabilities in Perten/PerkinElmer ProcessPlus
[KIS-2024-06] XenForo <= 2.2.15 (Template System) Remote Code Execution Vulnerability
[KIS-2024-05] XenForo <= 2.2.15 (Widget::actionSave) Cross-Site Request Forgery Vulnerability
CVE-2024-33326
CVE-2024-33327
CVE-2024-33328
CVE-2024-33329
CyberDanube Security Research 20240703-0 | Authenticated Command Injection in Helmholz Industrial Router REX100
SEC Consult SA-20240627-0 :: Local Privilege Escalation via MSI installer in SoftMaker Office / FreeOffice
SEC Consult SA-20240626-0 :: Multiple Vulnerabilities in Siemens Power Automation Products
Novel DoS Vulnerability Affecting WebRTC Media Servers
APPLE-SA-06-25-2024-1 AirPods Firmware Update 6A326, AirPods Firmware Update 6F8, and Beats Firmware Update 6F8
40 vulnerabilities in Toshiba Multi-Function Printers
17 vulnerabilities in Sharp Multi-Function Printers
SEC Consult SA-20240624-0 :: Multiple Vulnerabilities allowing complete bypass in Faronics WINSelect (Standard + Enterprise)
Log in Register Forum FAQ Memberlist Search
IT Security and Insecurity Portal

www.waraxe.us Forum Index -> Remote file inclusion -> Upload shell little help
Post new topicReply to topic View previous topic :: View next topic
Upload shell little help
PostPosted: Tue Aug 28, 2012 1:40 am Reply with quote
Frenkie
Advanced user
Advanced user
Joined: Nov 10, 2008
Posts: 60




Hello guys,

I need advice is there any chance someone to upload shell in my website. I use following code to prevent malicious uploads.

First:
Code:
function getFileExtension($str) {

$i = strrpos($str,".");
if (!$i) { return ""; }

$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);

return $ext;

}

$pext = getFileExtension($imgfile_name);
$pext = strtolower($pext);

$uploaddir = "./files";

if (($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif") && ($pext != "swf"))
{

?>
Wrong extension. File must be jpg,jpeg,gif or swf.
<?
exit();
}


Then
Code:
$final_filename = str_replace(" ", "_", $imgfile_name);
$final_filename2 = "$imgfile_name";
$newfile = $uploaddir . "/$final_filename2";

if (is_uploaded_file($imgfile))
{
if (!copy($imgfile,"$newfile"))
{
print "Error Uploading File.";
exit();
}
}


If you know way to bypass this please post here.

Thanks
View user's profile Send private message
PostPosted: Tue Aug 28, 2012 9:26 am Reply with quote
demon
Moderator
Moderator
Joined: Sep 22, 2010
Posts: 485




a shell with .gif extension easily can be uploaded Wink

just save the shell with this name: shell.php.gif and edit it so the first line in the shell mush be:
Code:
GIF89a;


and then it will be uploaded without problem Wink

and remember LFI can bypass .htaccess

_________________
Go BIG or go HOME !
View user's profile Send private message
PostPosted: Tue Aug 28, 2012 1:24 pm Reply with quote
Frenkie
Advanced user
Advanced user
Joined: Nov 10, 2008
Posts: 60




Any solution without LFI
View user's profile Send private message
PostPosted: Wed Aug 29, 2012 4:07 pm Reply with quote
Cyko
Moderator
Moderator
Joined: Jul 21, 2009
Posts: 375




A few suggestions:

1) You should use move_uploaded_file() instead of copy(), when allowing visitors to upload.

php.net wrote:
This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.


2) When saving files you should rename them (and not save them as they were).

3) You should avoid making custom functions, when they are already functions which exist internally (i.e. for the ext validation).

4) You should add a max file size limit (validate it via filesize).

5) Using exit() is unnecessary; when creating something like this - you should really be using If...Else statements, but it will do.


See below code for example use:

Code:
<?php

//replaced your method of getting the ext with an internal one...
$pext = pathinfo($imgfile_name, PATHINFO_EXTENSION);

$uploaddir = './files';

//replaced your method of validating with a better approach...
if (!in_array($pext, array(
'jpg',
'jpeg',
'gif',
'swf'
))) {
?>
Wrong extension. File must be jpg,jpeg,gif or swf.
<?php
exit();
}

//replace the original filename with a 'unique' alphanumeric one...
$final_filename = md5(uniqid(microtime(), true)) . ".{$pext}";

$newfile = $uploaddir . "/{$final_filename}";

if (is_uploaded_file($imgfile)) {
//used move_uploaded_file() instead of copy()...
if (!move_uploaded_file($imgfile, $newfile)) {
print 'Error Uploading File.';
exit();
}
}


Untested Smile


Last edited by Cyko on Thu Aug 30, 2012 1:11 am; edited 1 time in total
View user's profile Send private message
PostPosted: Thu Aug 30, 2012 12:50 am Reply with quote
Frenkie
Advanced user
Advanced user
Joined: Nov 10, 2008
Posts: 60




Thank you Cyko for your reply. Its really useful.
Also can you tell me is there any way someone to bypass my initial code na upload shell to my website ?

Thanks
View user's profile Send private message
PostPosted: Thu Aug 30, 2012 1:30 am Reply with quote
Cyko
Moderator
Moderator
Joined: Jul 21, 2009
Posts: 375




Frenkie wrote:
Thank you Cyko for your reply. Its really useful.
Also can you tell me is there any way someone to bypass my initial code na upload shell to my website ?

Thanks


I can't think of any way to bypass your code.

But theres an issue with your code....

By default on apache any file which starts with .ht can not be viewed by the visitor.

So if a visitor uploads a file like .httest.gif, it will pass validation and get uploaded to the server, but you won't be able to view it (therefore can't embed it via img tags).

The code which I provided in my previous post; fixes this issue.
View user's profile Send private message
Upload shell little help
www.waraxe.us Forum Index -> Remote file inclusion
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT
Page 1 of 1

Post new topicReply to topic


Powered by phpBB © 2001-2008 phpBB Group



Space Raider game for Android, free download - Space Raider gameplay video - Zone Raider mobile games
All logos and trademarks in this site are property of their respective owner. The comments and posts are property of their posters, all the rest (c) 2004-2024 Janek Vind "waraxe"
Page Generation: 0.306 Seconds