PHP SAFE UPLOAD: New anti-shell ideea (maybe)

Started on the old forum in July 2011 · view the original in the archive · old links redirect here

4 replies · 1,206 views · started 15 years ago · 1 min read

4 participants
i0nutzxp Developer · 150 posts #1

I had an ideea to secure the upload via php code. Can you try to broke my test site (no httacces protection): Upload Here Shells:>, to let me know if this protectection actually works.

Protection Class Source Code:

<?php

//@package Simple safe-upload
//@author: Ionutxp
//@email: ionut_gerrard@yahoo.com

class SafeUpload
{
   const upload_to = 'safe';

   private $disalowed_tags = array('<html>', '<head>', 'href', '<td>', '<table>',
      '<div', '<b>', 'function');
   public $curent_location = null;

   public function __construct($location)
   {
      $this->curent_location = $location;
      if (count($_FILES) > 0)
      {
         foreach ($_FILES as & $file)
         {
            $goto = self::upload_to . '/' . mt_rand(1000000, 9999999) . '.php';
            if (copy($file['tmp_name'], $goto))
            {
               self::check_file($goto);
            }
         }
         return;
      }
   }
   private function call_curl($goto)
   {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $goto);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      $webrep = curl_exec($curl);
      curl_close($curl);
      return $webrep;
   }
   private function check_file($url)
   {
      $content = $this->call_curl($this->curent_location . '/' . $url);
      foreach ($this->disalowed_tags as $val)
      {
         if (substr_count($content, $val) > 0 && substr_count($content, 'syntax error') ==
            0)
         {
            echo 'This site is protected.';
            unset($_FILES);
            break;
         }
      }
      unlink($url);
   }
}

$safe = new SafeUpload('http://mytester.host.org/'); // path to your uploader
?>

And a demo in attachment.

<?php unlink('World/Europe/Romania.country'); ?>
Attachments: safe.rar
metulj Super moderator Principal · 1,726 posts #2

i0nutzxp wrote: I had an ideea to secure the upload via php code. Can you try to broke my test site (no httacces protection): Upload Here Shells:>, to let me know if this protectection actually works.

Protection Class Source Code:

<?php

//@package Simple safe-upload
//@author: Ionutxp
//@email: ionut_gerrard@yahoo.com

class SafeUpload
{
   const upload_to = 'safe';

   private $disalowed_tags = array('<html>', '<head>', 'href', '<td>', '<table>',
      '<div', '<b>', 'function');
   public $curent_location = null;

   public function __construct($location)
   {
      $this->curent_location = $location;
      if (count($_FILES) > 0)
      {
         foreach ($_FILES as & $file)
         {
            $goto = self::upload_to . '/' . mt_rand(1000000, 9999999) . '.php';
            if (copy($file['tmp_name'], $goto))
            {
               self::check_file($goto);
            }
         }
         return;
      }
   }
   private function call_curl($goto)
   {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $goto);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      $webrep = curl_exec($curl);
      curl_close($curl);
      return $webrep;
   }
   private function check_file($url)
   {
      $content = $this->call_curl($this->curent_location . '/' . $url);
      foreach ($this->disalowed_tags as $val)
      {
         if (substr_count($content, $val) > 0 && substr_count($content, 'syntax error') ==
            0)
         {
            echo 'This site is protected.';
            unset($_FILES);
            break;
         }
      }
      unlink($url);
   }
}

$safe = new SafeUpload('http://mytester.host.org/'); // path to your uploader
?>

And a demo in attachment.

this is secured against uploading shell, etc... how bout against execution ?

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

i0nutzxp Developer · 150 posts #3

I found some holes ... tomorow i'll post a updated version:D ( and If you can stop uploading a virused file , you wont need to disalow executing that files..)

<?php unlink('World/Europe/Romania.country'); ?>
phzone Junior · 18 posts #4

its not safe for shell. . maybe try to recode that uploader

subzero Super moderator Fellow · 3,954 posts #5

i had made anti hack uploader 🙂

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... _______…

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