Waraxe IT Security Portal
Login or Register
November 23, 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: 79
Members: 0
Total: 79
Full disclosure
APPLE-SA-11-19-2024-5 macOS Sequoia 15.1.1
Local Privilege Escalations in needrestart
APPLE-SA-11-19-2024-4 iOS 17.7.2 and iPadOS 17.7.2
APPLE-SA-11-19-2024-3 iOS 18.1.1 and iPadOS 18.1.1
APPLE-SA-11-19-2024-2 visionOS 2.1.1
APPLE-SA-11-19-2024-1 Safari 18.1.1
Reflected XSS - fronsetiav1.1
XXE OOB - fronsetiav1.1
St. Poelten UAS | Path Traversal in Korenix JetPort 5601
St. Poelten UAS | Multiple Stored Cross-Site Scripting in SEH utnserver Pro
Apple web content filter bypass allows unrestricted access to blocked content (macOS/iOS/iPadOS/visionO S/watchOS)
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
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.047 Seconds