Downloads/uploads

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Downloads/uploads

    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)

    Code:
    /////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[&#39;filetoupload&#39;][&#39;tmp_name&#39;]))$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,&#39;$type&#39;,&#39;$file_name&#39;,&#39;/downloads/$file_name&#39;,&#39;$category&#39;,&#39;$uid&#39;,&#39;$time&#39;");
    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;
    }

    #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...
    _______
    Info & Tips
    php.net
    w3schools.com

    Comment


      #3
      try a htaccess file to deny all but the files you want mate
      :p:p:p

      Comment


        #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

        Comment


          #5
          upload name ?

          Code:
          /////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[&#39;filetoupload&#39;][name],&#39;.&#39;));
          $file_type=$_FILES[&#39;filetoupload&#39;][&#39;type&#39;];
          $file_name=$_FILES[&#39;filetoupload&#39;][&#39;name&#39;];
          $file_size=$_FILES[&#39;filetoupload&#39;][&#39;size&#39;];
          $file_tmp=$_FILES[&#39;filetoupload&#39;][&#39;tmp_name&#39;];
          $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[&#39;filetoupload&#39;][&#39;tmp_name&#39;]))$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,&#39;$type&#39;,&#39;$file_name&#39;,&#39;/downloads/$file_name&#39;,&#39;$category&#39;,&#39;$uid&#39;,&#39;$time&#39;");
          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...
          _______
          Info & Tips
          php.net
          w3schools.com

          Comment


            #6
            what about the upload name?

            Comment


              #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...
              _______
              Info & Tips
              php.net
              w3schools.com

              Comment


                #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

                Comment


                  #9
                  here is a tutorial for you.

                  http://www.howtoforge.com/scan_virus..._php_clamavlib

                  Comment


                    #10
                    You will need to block it by the server.. i ain&#39;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&#39;ll see if i can find out how to block them or find the coding that blocks them...

                    Comment


                      #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

                      Comment


                        #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!

                        Comment


                          #13
                          Thanks for the pdf

                          Comment

                          Working...
                          X