1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problem in .htaccess setting

Discussion in 'Security' started by skylux, Sep 15, 2007.

  1. #1
    I'm operating a media content website and customers can upload freely any media (.jpg, .wmv etc) files for sharing. However, recently, I was hacked by hacker who loaded a .php file into the media content directory. Is it any measure I can prevent it to do so. I think I need to set the .htaccess file, can anyone suggest method of solution?
     
    skylux, Sep 15, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Your upload script should be checking the extension and mime type of the uploaded file.

    Assuming PHP, you can use:
    $mime_type = $_FILES['upload']['type'];
    $extension = end(explode('.', $_FILES['upload']['name']));
    PHP:
    Then you can do some simple validation. Check your server config to see what file extensions files need to be parsed as PHP and prevent them from being uploaded.
     
    krt, Sep 15, 2007 IP
  3. skylux

    skylux Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can we set in the .htaccess file to prevent execution of files in the \images\ directory?
     
    skylux, Sep 16, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    <Directory "images">
    php_admin_flag engine off
    AddType text/plain .php .php3 .phtm .phtml
    </Directory>

    Though I don't see why you don't want to prevent them from being uploaded in the first place.
     
    krt, Sep 16, 2007 IP
  5. HostJail

    HostJail Active Member

    Messages:
    180
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Exactly,
    You can keep execution of the files from taking place, but preventing the uload to begin with is essential.
     
    HostJail, Sep 18, 2007 IP
  6. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #6
    after above is done
    next step is to find out who and how the hackers did their job. find the precise application that allowed penetration of your server and secure it. to do so you may have to manually screen your access_log files. use grep / zgrep to find the first occurrence of that .php file, then manually check the access log lines before that first occurrance, typically it may start with a Google search referrer entry, etc. secure that ONE application that allowed upload by fixing the upload as above - then check for all different IP's used by hackers and block all either using .htaccess or iptables for additional security.
     
    hans, Sep 29, 2007 IP
  7. zebulon

    zebulon Well-Known Member

    Messages:
    198
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    130
    #7
    find yourself a copy of c99 shell and test your server against it. upload the shell as shell.php.jpg or shell.php.gif or shell.php.png to ensure that the settings are working properly and the shell is not executing.
     
    zebulon, Oct 8, 2007 IP