Downloads/uploads

Started on the old forum in October 2008 · view the original in the archive · old links redirect here

12 replies · 1,145 views · started 18 years ago · 2 min read

6 participants
ori Lead · 512 posts #1

i am trying to secure my uploader so ppl cant upload trojans/viruses best way i can see is using content type from what they upload does any1 no if theres more i can do to make this upload code more secure fanx :o)

/////UPLOAD A FILE/////
else if($mode=="upload")
{
$time=time();
$page=get_var("page");
$category=get_var("category");
$upload=get_var("upload");
$size_bytes=10485760;
$size=round($size_bytes/1048576,1);
$limitedext=array(
".jpg",".jpeg",".gif",".png",".bmp",
".mid",".mp3",".wma",".amr",
".sis",".sisx",".jar",".jad",
".3gp",".mp4",".avi",".mov",".wmv",".mpg",".mpeg"
);
$content_type=array(
"image/jpeg","image/pjpeg","image/gif","image/x-png","image/bmp",
"audio/mid","audio/mpeg","audio/x-ms-wma","audio/wav","audio/amr",
"application/octet-stream","application/x-zip-compressed",
"video/3gpp","video/mp4","video/x-msvideo","video/quicktime","video/x-ms-wmv","video/mpeg"
);
$ext=strtolower(strrchr($_FILES['filetoupload'][name],'.'));
$file_type=$_FILES['filetoupload']['type'];
$file_name=$_FILES['filetoupload']['name'];
$file_size=$_FILES['filetoupload']['size'];
$file_tmp=$_FILES['filetoupload']['tmp_name'];
$file_name=str_replace(" ","_",$file_name);
if(strpos($file_type,"image"))$type="I";
if(strpos($file_type,"audio"))$type="A";
if(strpos($file_type,"video"))$type="V";
if(strpos($file_type,"application"))$type="A";
if($upload==1){
if(!is_uploaded_file($_FILES['filetoupload']['tmp_name']))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]no file selected!![/size]";
else if(!in_array($ext,$limitedext))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]invalid file type!![/size]";
else if(!in_array($file_type,$content_type))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]content type does not match file type!![/size]";
else if($file_size>$size_bytes)$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]exceeded File size limit!! maximum $size mb.[/size]";
else if(file_exists("./downloads/$file_name"))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>file name already exists!!</small>";
else if($file_size){
insert(downloads,"NULL,'$type','$file_name','/downloads/$file_name','$category','$uid','$time'");
move_uploaded_file($file_tmp,"./downloads/$file_name");
$msg="<img src=\"./images/point.gif\" alt=\"[!]\"/>[size="1"]successfully uploaded $file_type file!![/size]";
}
else $msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]unknown error!![/size]";
}
$what=Array("sitename","username","size","msg","page","category");
$with=Array($sitename,users_table("username",$uid),$size,$msg,$page,$category);
script($global_what,$global_with,$what,$with,"upload");
exit;
}
subzero Super moderator Fellow · 3,954 posts #2

lol virus ?

all you wont to scan it daily by using corn jobs in your cpanel set it to scan daily or ech 5 hours.

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

darkdesire Senior · 250 posts #3

try a htaccess file to deny all but the files you want mate

:p:p:p

ori Lead · 512 posts #4

u no ppl that make php files but rename them and class the content type as php so it can be run? its quite easy 2 do

subzero Super moderator Fellow · 3,954 posts #5

upload name ?

/////UPLOAD A FILE/////
else if($mode=="upload")
{
$time=time();
$page=get_var("page");
$category=get_var("category");
$upload=get_var("upload");
$size_bytes=10485760;
$size=round($size_bytes/1048576,1);
$limitedext=array(
".jpg",".jpeg",".gif",".png",".bmp",
".mid",".mp3",".wma",".amr",
".sis",".sisx",".jar",".jad",
".3gp",".mp4",".avi",".mov",".wmv",".mpg",".mpeg"
);
$content_type=array(
"image/jpeg","image/pjpeg","image/gif","image/x-png","image/bmp",
"audio/mid","audio/mpeg","audio/x-ms-wma","audio/wav","audio/amr",
"application/octet-stream","application/x-zip-compressed",
"video/3gpp","video/mp4","video/x-msvideo","video/quicktime","video/x-ms-wmv","video/mpeg"
);
$ext=strtolower(strrchr($_FILES['filetoupload'][name],'.'));
$file_type=$_FILES['filetoupload']['type'];
$file_name=$_FILES['filetoupload']['name'];
$file_size=$_FILES['filetoupload']['size'];
$file_tmp=$_FILES['filetoupload']['tmp_name'];
$file_name=str_replace(" ","_",$file_name);
if(strpos($file_type,"image"))$type="I";
if(strpos($file_type,"audio"))$type="A";
if(strpos($file_type,"video"))$type="V";
if(strpos($file_type,"application"))$type="A";

//md5 coding
$file_name = md5($file_name);

//Edit out of use php 
//$file_name = str_replace("php","_",$file_name);

if($upload==1){
if(!is_uploaded_file($_FILES['filetoupload']['tmp_name']))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]no file selected!![/size]";
else if(!in_array($ext,$limitedext))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]invalid file type!![/size]";
else if(!in_array($file_type,$content_type))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]content type does not match file type!![/size]";
else if($file_size>$size_bytes)$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]exceeded File size limit!! maximum $size mb.[/size]";
else if(file_exists("./downloads/$file_name"))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>file name already exists!!</small>";
else if($file_size){
insert(downloads,"NULL,'$type','$file_name','/downloads/$file_name','$category','$uid','$time'");
move_uploaded_file($file_tmp,"./downloads/$file_name");
$msg="<img src=\"./images/point.gif\" alt=\"[!]\"/>[size="1"]successfully uploaded $file_type file!![/size]";
}
else $msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]unknown error!![/size]";
}
$what=Array("sitename","username","size","msg","page","category");
$with=Array($sitename,users_table("username",$uid),$size,$msg,$page,$category);
script($global_what,$global_with,$what,$with,"upload");
exit;
}

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

ori Lead · 512 posts #6

what about the upload name?

subzero Super moderator Fellow · 3,954 posts #7

that will change the file name to 2y74w8qeyvhcdjxzycvh823

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

ori Lead · 512 posts #8

i did that on my other script uploader as a validation process but once they were validated it would rename them to there original name i dnt think its reali needed if the upload process is secured

WhiteWarrior Principal · 1,419 posts #10

You will need to block it by the server.. i ain't 100% sure how its done but i know thats how you can block the shell scripts...

Allen he means people go around hacking scripts by uploading a shell script but renamed to something like c99.php.jpg or even shell.jpg and in the script coding it opens as a script even tho the the exe is jpg.. quite smart scripts unless there blocked..

anyway chris, i'll see if i can find out how to block them or find the coding that blocks them...

ori Lead · 512 posts #11

ive neva had any1 try it but theres always a 1st its beta 2 b safe then sorry i think my uploader will do a gud job of checking content

Guest #12

There is very big process on how to make uploader secure, i read an article about it, where the uploaded file is moved to a folder which is outside of public_html, so no one can directly access it through url. This process needs sql, so you can store the file names and a download code for it. When you want to download the file, the code reads the directory which is out side the public_html and the lets you download the file. I had the complete pdf on how to code it. Im not sure where it is, let me search it for ya.

Here it is: http://www.scanit.be/uploads/php-file-upload.pdf

Read it completely, and you will understand how people hack through uploaders using shell scripts. And best of luck for you in making a secure uploader! 🙂

chris Junior · 39 posts #13

Thanks for the pdf 🙂

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close