Waraxe IT Security Portal
Login or Register
November 21, 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: 87
Members: 0
Total: 87
Full disclosure
SEC Consult SA-20241112-0 :: Multiple vulnerabilities in Siemens Energy Omnivise T3000 (CVE-2024-38876, CVE-2024-38877, CVE-2024-38878, CVE-2024-38879)
Security issue in the TX Text Control .NET Server for ASP.NET.
SEC Consult SA-20241107-0 :: Multiple Vulnerabilities in HASOMED Elefant and Elefant Software Updater
Unsafe eval() in TestRail CLI
4 vulnerabilities in ibmsecurity
32 vulnerabilities in IBM Security Verify Access
xlibre Xnest security advisory & bugfix releases
APPLE-SA-10-29-2024-1 Safari 18.1
SEC Consult SA-20241030-0 :: Query Filter Injection in Ping Identity PingIDM (formerly known as ForgeRock Identity Management) (CVE-2024-23600)
SEC Consult SA-20241023-0 :: Authenticated Remote Code Execution in Multiple Xerox printers (CVE-2024-6333)
APPLE-SA-10-28-2024-8 visionOS 2.1
APPLE-SA-10-28-2024-7 tvOS 18.1
APPLE-SA-10-28-2024-6 watchOS 11.1
APPLE-SA-10-28-2024-5 macOS Ventura 13.7.1
APPLE-SA-10-28-2024-4 macOS Sonoma 14.7.1
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.046 Seconds