Beispiel #1
0
 public function __construct(Am_Paysystem_Abstract $plugin, Am_Request $request, Zend_Controller_Response_Http $response, $invokeArgs)
 {
     $DR = preg_replace("/\\s/", "+", $request->get('DR', $_GET['DR']));
     $rc4 = new Crypt_RC4($plugin->getConfig('secret', 'ebskey'));
     $QueryString = base64_decode($DR);
     $rc4->decrypt($QueryString);
     $QueryString = split('&', $QueryString);
     foreach ($QueryString as $param) {
         $param = split('=', $param);
         $request->setParam($param[0], $param[1]);
     }
     parent::__construct($plugin, $request, $request, $invokeArgs);
 }
 /**
  *  Success response from Secure Ebs
  *
  *  @return	  void
  */
 public function successAction()
 {
     if (isset($_GET['DR'])) {
         $DR = preg_replace("/\\s/", "+", $_GET['DR']);
         $secret_key = Mage::getSingleton('secureebs/config')->getSecretKey();
         // Your Secret Key
         $rc4 = new Crypt_RC4($secret_key);
         $QueryString = base64_decode($DR);
         $rc4->decrypt($QueryString);
         $QueryString = split('&', $QueryString);
         $response = array();
         foreach ($QueryString as $param) {
             $param = split('=', $param);
             $response[$param[0]] = urldecode($param[1]);
         }
     }
     if ($response['ResponseCode'] == 0) {
         $session = Mage::getSingleton('checkout/session');
         $session->setQuoteId($session->getSecureebsStandardQuoteId());
         $session->unsSecureebsStandardQuoteId();
         $order = $this->getOrder();
         if (!$order->getId()) {
             $this->norouteAction();
             return;
         }
         $order->addStatusToHistory($order->getStatus(), Mage::helper('secureebs')->__('Customer successfully returned from Secureebs'));
         $order->save();
         //Changes by basant
         //		$order->sendNewOrderEmail();
         if ($order->canInvoice()) {
             /**
              * Create invoice
              * The invoice will be in 'Pending' state
              */
             $invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(), array());
             $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId);
             $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
             /**
              * Pay invoice
              * i.e. the invoice state is now changed to 'Paid'
              */
             $invoice->capture()->save();
             $invoice->sendEmail(true);
         }
         //changes ends
         $this->_redirect('checkout/onepage/success');
     } else {
         $this->_redirect('secureebs/standard/failure');
     }
 }
Beispiel #3
0
/**
 * Generate a random value.
 *
 * On 32-bit machines, the largest distance that can exist between $min and $max is 2**31.
 * If $min and $max are farther apart than that then the last ($max - range) numbers.
 *
 * Depending on how this is being used, it may be worth while to write a replacement.  For example,
 * a PHP-based web app that stores its data in an SQL database can collect more entropy than this function
 * can.
 *
 * @param optional Integer $min
 * @param optional Integer $max
 * @return Integer
 * @access public
 */
function crypt_random($min = 0, $max = 0x7fffffff)
{
    if ($min == $max) {
        return $min;
    }
    // see http://en.wikipedia.org/wiki//dev/random
    // if open_basedir is enabled file_exists() will ouput an "open_basedir restriction in effect" warning,
    // so we suppress it.
    if (@file_exists('/dev/urandom')) {
        static $fp;
        if (!$fp) {
            $fp = fopen('/dev/urandom', 'rb');
        }
        extract(unpack('Nrandom', fread($fp, 4)));
        // say $min = 0 and $max = 3.  if we didn't do abs() then we could have stuff like this:
        // -4 % 3 + 0 = -1, even though -1 < $min
        return abs($random) % ($max - $min) + $min;
    }
    /* Prior to PHP 4.2.0, mt_srand() had to be called before mt_rand() could be called.
           Prior to PHP 5.2.6, mt_rand()'s automatic seeding was subpar, as elaborated here:
    
           http://www.suspekt.org/2008/08/17/mt_srand-and-not-so-random-numbers/
    
           The seeding routine is pretty much ripped from PHP's own internal GENERATE_SEED() macro:
    
           http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3_2/ext/standard/php_rand.h?view=markup */
    if (version_compare(PHP_VERSION, '5.2.5', '<=')) {
        static $seeded;
        if (!isset($seeded)) {
            $seeded = true;
            mt_srand(fmod(time() * getmypid(), 0x7fffffff) ^ fmod(1000000 * lcg_value(), 0x7fffffff));
        }
    }
    static $crypto;
    // The CSPRNG's Yarrow and Fortuna periodically reseed.  This function can be reseeded by hitting F5
    // in the browser and reloading the page.
    if (!isset($crypto)) {
        $key = $iv = '';
        for ($i = 0; $i < 8; $i++) {
            $key .= pack('n', mt_rand(0, 0xffff));
            $iv .= pack('n', mt_rand(0, 0xffff));
        }
        switch (true) {
            case class_exists('Crypt_AES'):
                $crypto = new Crypt_AES(CRYPT_AES_MODE_CTR);
                break;
            case class_exists('Crypt_TripleDES'):
                $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
                break;
            case class_exists('Crypt_DES'):
                $crypto = new Crypt_DES(CRYPT_DES_MODE_CTR);
                break;
            case class_exists('Crypt_RC4'):
                $crypto = new Crypt_RC4();
                break;
            default:
                extract(unpack('Nrandom', pack('H*', sha1(mt_rand(0, 0x7fffffff)))));
                return abs($random) % ($max - $min) + $min;
        }
        $crypto->setKey($key);
        $crypto->setIV($iv);
        $crypto->enableContinuousBuffer();
    }
    extract(unpack('Nrandom', $crypto->encrypt("")));
    return abs($random) % ($max - $min) + $min;
}
Beispiel #4
0
 /**
  * Generate a random string.
  *
  * Although microoptimizations are generally discouraged as they impair
  * readability this function is ripe with
  * microoptimizations because this function has the potential of being
  * called a huge number of times.
  * eg. for RSA key generation.
  *
  * @param Integer $length        	
  * @return String
  * @access public
  */
 function crypt_random_string($length)
 {
     if (CRYPT_RANDOM_IS_WINDOWS) {
         // method 1. prior to PHP 5.3 this would call rand() on windows
         // hence the function_exists('class_alias') call.
         // ie. class_alias is a function that was introduced in PHP 5.3
         if (function_exists('mcrypt_create_iv') && function_exists('class_alias')) {
             return mcrypt_create_iv($length);
         }
         // method 2. openssl_random_pseudo_bytes was introduced in PHP 5.3.0
         // but prior to PHP 5.3.4 there was,
         // to quote <http://php.net/ChangeLog-5.php#5.3.4>, "possible
         // blocking behavior". as of 5.3.4
         // openssl_random_pseudo_bytes and mcrypt_create_iv do the exact
         // same thing on Windows. ie. they both
         // call php_win32_get_random_bytes():
         //
         // https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/openssl/openssl.c#L5008
         // https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/mcrypt/mcrypt.c#L1392
         //
         // php_win32_get_random_bytes() is defined thusly:
         //
         // https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/win32/winutil.c#L80
         //
         // we're calling it, all the same, in the off chance that the mcrypt
         // extension is not available
         if (function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>=')) {
             return openssl_random_pseudo_bytes($length);
         }
     } else {
         // method 1. the fastest
         if (function_exists('openssl_random_pseudo_bytes')) {
             return openssl_random_pseudo_bytes($length);
         }
         // method 2
         static $fp = true;
         if ($fp === true) {
             // warning's will be output unles the error suppression operator
             // is used. errors such as
             // "open_basedir restriction in effect", "Permission denied",
             // "No such file or directory", etc.
             $fp = @fopen('/dev/urandom', 'rb');
         }
         if ($fp !== true && $fp !== false) {
             // surprisingly faster than
             // !is_bool() or is_resource()
             return fread($fp, $length);
         }
         // method 3. pretty much does the same thing as method 2 per the
         // following url:
         // https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/mcrypt/mcrypt.c#L1391
         // surprisingly slower than method 2. maybe that's because
         // mcrypt_create_iv does a bunch of error checking that we're
         // not doing. regardless, this'll only be called if this PHP script
         // couldn't open /dev/urandom due to open_basedir
         // restrictions or some such
         if (function_exists('mcrypt_create_iv')) {
             return mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
         }
     }
     // at this point we have no choice but to use a pure-PHP CSPRNG
     // cascade entropy across multiple PHP instances by fixing the session
     // and collecting all
     // environmental variables, including the previous session data and the
     // current session
     // data.
     //
     // mt_rand seeds itself by looking at the PID and the time, both of
     // which are (relatively)
     // easy to guess at. linux uses mouse clicks, keyboard timings, etc, as
     // entropy sources, but
     // PHP isn't low level to be able to use those as sources and on a web
     // server there's not likely
     // going to be a ton of keyboard or mouse action. web servers do have
     // one thing that we can use
     // however, a ton of people visiting the website. obviously you don't
     // want to base your seeding
     // soley on parameters a potential attacker sends but (1) not everything
     // in $_SERVER is controlled
     // by the user and (2) this isn't just looking at the data sent by the
     // current user - it's based
     // on the data sent by all users. one user requests the page and a hash
     // of their info is saved.
     // another user visits the page and the serialization of their data is
     // utilized along with the
     // server envirnment stuff and a hash of the previous http request data
     // (which itself utilizes
     // a hash of the session data before that). certainly an attacker should
     // be assumed to have
     // full control over his own http requests. he, however, is not going to
     // have control over
     // everyone's http requests.
     static $crypto = false, $v;
     if ($crypto === false) {
         // save old session data
         $old_session_id = session_id();
         $old_use_cookies = ini_get('session.use_cookies');
         $old_session_cache_limiter = session_cache_limiter();
         $_OLD_SESSION = isset($_SESSION) ? $_SESSION : false;
         if ($old_session_id != '') {
             session_write_close();
         }
         session_id(1);
         ini_set('session.use_cookies', 0);
         session_cache_limiter('');
         session_start();
         $v = $seed = $_SESSION['seed'] = pack('H*', sha1(serialize($_SERVER) . serialize($_POST) . serialize($_GET) . serialize($_COOKIE) . serialize($GLOBALS) . serialize($_SESSION) . serialize($_OLD_SESSION)));
         if (!isset($_SESSION['count'])) {
             $_SESSION['count'] = 0;
         }
         $_SESSION['count']++;
         session_write_close();
         // restore old session data
         if ($old_session_id != '') {
             session_id($old_session_id);
             session_start();
             ini_set('session.use_cookies', $old_use_cookies);
             session_cache_limiter($old_session_cache_limiter);
         } else {
             if ($_OLD_SESSION !== false) {
                 $_SESSION = $_OLD_SESSION;
                 unset($_OLD_SESSION);
             } else {
                 unset($_SESSION);
             }
         }
         // in SSH2 a shared secret and an exchange hash are generated
         // through the key exchange process.
         // the IV client to server is the hash of that "nonce" with the
         // letter A and for the encryption key it's the letter C.
         // if the hash doesn't produce enough a key or an IV that's long
         // enough concat successive hashes of the
         // original hash and the current hash. we'll be emulating that. for
         // more info see the following URL:
         //
         // http://tools.ietf.org/html/rfc4253#section-7.2
         //
         // see the is_string($crypto) part for an example of how to expand
         // the keys
         $key = pack('H*', sha1($seed . 'A'));
         $iv = pack('H*', sha1($seed . 'C'));
         // ciphers are used as per the nist.gov link below. also, see this
         // link:
         //
         // http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Designs_based_on_cryptographic_primitives
         switch (true) {
             case phpseclib_resolve_include_path('Crypt/AES.php'):
                 if (!class_exists('Crypt_AES')) {
                     include_once 'AES.php';
                 }
                 $crypto = new Crypt_AES(CRYPT_AES_MODE_CTR);
                 break;
             case phpseclib_resolve_include_path('Crypt/Twofish.php'):
                 if (!class_exists('Crypt_Twofish')) {
                     include_once 'Twofish.php';
                 }
                 $crypto = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
                 break;
             case phpseclib_resolve_include_path('Crypt/Blowfish.php'):
                 if (!class_exists('Crypt_Blowfish')) {
                     include_once 'Blowfish.php';
                 }
                 $crypto = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
                 break;
             case phpseclib_resolve_include_path('Crypt/TripleDES.php'):
                 if (!class_exists('Crypt_TripleDES')) {
                     include_once 'TripleDES.php';
                 }
                 $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
                 break;
             case phpseclib_resolve_include_path('Crypt/DES.php'):
                 if (!class_exists('Crypt_DES')) {
                     include_once 'DES.php';
                 }
                 $crypto = new Crypt_DES(CRYPT_DES_MODE_CTR);
                 break;
             case phpseclib_resolve_include_path('Crypt/RC4.php'):
                 if (!class_exists('Crypt_RC4')) {
                     include_once 'RC4.php';
                 }
                 $crypto = new Crypt_RC4();
                 break;
             default:
                 user_error('crypt_random_string requires at least one symmetric cipher be loaded');
                 return false;
         }
         $crypto->setKey($key);
         $crypto->setIV($iv);
         $crypto->enableContinuousBuffer();
     }
     // return $crypto->encrypt(str_repeat("\0", $length));
     // the following is based off of ANSI X9.31:
     //
     // http://csrc.nist.gov/groups/STM/cavp/documents/rng/931rngext.pdf
     //
     // OpenSSL uses that same standard for it's random numbers:
     //
     // http://www.opensource.apple.com/source/OpenSSL/OpenSSL-38/openssl/fips-1.0/rand/fips_rand.c
     // (do a search for "ANS X9.31 A.2.4")
     $result = '';
     while (strlen($result) < $length) {
         $i = $crypto->encrypt(microtime());
         // strlen(microtime()) == 21
         $r = $crypto->encrypt($i ^ $v);
         // strlen($v) == 20
         $v = $crypto->encrypt($r ^ $i);
         // strlen($r) == 20
         $result .= $r;
     }
     return substr($result, 0, $length);
 }
Beispiel #5
0
 public static function jieMi($string)
 {
     $key = zmf::config('authorCode');
     $plain_text = trim($string);
     Yii::import('application.vendors.*');
     require_once 'rc4crypt.php';
     $rc4 = new Crypt_RC4();
     $rc4->setKey($key);
     $text = $plain_text;
     $x = $rc4->decrypt($text);
     return $x;
 }
Beispiel #6
0
/**
 * Generate a random value.
 *
 * On 32-bit machines, the largest distance that can exist between $min and $max is 2**31.
 * If $min and $max are farther apart than that then the last ($max - range) numbers.
 *
 * Depending on how this is being used, it may be worth while to write a replacement.  For example,
 * a PHP-based web app that stores its data in an SQL database can collect more entropy than this function
 * can.
 *
 * @param optional Integer $min
 * @param optional Integer $max
 * @return Integer
 * @access public
 */
function crypt_random($min = 0, $max = 0x7fffffff)
{
    if ($min == $max) {
        return $min;
    }
    if (function_exists('openssl_random_pseudo_bytes')) {
        // openssl_random_pseudo_bytes() is slow on windows per the following:
        // http://stackoverflow.com/questions/1940168/openssl-random-pseudo-bytes-is-slow-php
        if ((PHP_OS & "ßßß") !== 'WIN') {
            // PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster
            extract(unpack('Nrandom', openssl_random_pseudo_bytes(4)));
            return abs($random) % ($max - $min) + $min;
        }
    }
    // see http://en.wikipedia.org/wiki//dev/random
    static $urandom = true;
    if ($urandom === true) {
        // Warning's will be output unles the error suppression operator is used.  Errors such as
        // "open_basedir restriction in effect", "Permission denied", "No such file or directory", etc.
        $urandom = @fopen('/dev/urandom', 'rb');
    }
    if (!is_bool($urandom)) {
        extract(unpack('Nrandom', fread($urandom, 4)));
        // say $min = 0 and $max = 3.  if we didn't do abs() then we could have stuff like this:
        // -4 % 3 + 0 = -1, even though -1 < $min
        return abs($random) % ($max - $min) + $min;
    }
    /* Prior to PHP 4.2.0, mt_srand() had to be called before mt_rand() could be called.
           Prior to PHP 5.2.6, mt_rand()'s automatic seeding was subpar, as elaborated here:
    
           http://www.suspekt.org/2008/08/17/mt_srand-and-not-so-random-numbers/
    
           The seeding routine is pretty much ripped from PHP's own internal GENERATE_SEED() macro:
    
           http://svn.php.net/viewvc/php/php-src/tags/php_5_3_2/ext/standard/php_rand.h?view=markup */
    if (version_compare(PHP_VERSION, '5.2.5', '<=')) {
        static $seeded;
        if (!isset($seeded)) {
            $seeded = true;
            mt_srand(fmod(time() * getmypid(), 0x7fffffff) ^ fmod(1000000 * lcg_value(), 0x7fffffff));
        }
    }
    static $crypto;
    // The CSPRNG's Yarrow and Fortuna periodically reseed.  This function can be reseeded by hitting F5
    // in the browser and reloading the page.
    if (!isset($crypto)) {
        $key = $iv = '';
        for ($i = 0; $i < 8; $i++) {
            $key .= pack('n', mt_rand(0, 0xffff));
            $iv .= pack('n', mt_rand(0, 0xffff));
        }
        switch (true) {
            case class_exists('Crypt_AES'):
                $crypto = new Crypt_AES(CRYPT_AES_MODE_CTR);
                break;
            case class_exists('Crypt_TripleDES'):
                $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
                break;
            case class_exists('Crypt_DES'):
                $crypto = new Crypt_DES(CRYPT_DES_MODE_CTR);
                break;
            case class_exists('Crypt_RC4'):
                $crypto = new Crypt_RC4();
                break;
            default:
                extract(unpack('Nrandom', pack('H*', sha1(mt_rand(0, 0x7fffffff)))));
                return abs($random) % ($max - $min) + $min;
        }
        $crypto->setKey($key);
        $crypto->setIV($iv);
        $crypto->enableContinuousBuffer();
    }
    extract(unpack('Nrandom', $crypto->encrypt("")));
    return abs($random) % ($max - $min) + $min;
}
Beispiel #7
0
 /**
  * Deep scan
  */
 private function deepscanAction()
 {
     if (file_exists('tmp/corefiles.sql')) {
         bfLog::log('Found core files - marking them as such');
         $this->db->setQuery(file_get_contents('tmp/corefiles.sql'));
         $this->db->query();
         unlink('tmp/corefiles.sql');
         $this->saveState(FALSE, __LINE__);
     }
     if (file_exists('tmp/hashfailed.sql')) {
         bfLog::log('Found modified core files - adding to deepscan');
         $this->db->setQuery(file_get_contents('tmp/hashfailed.sql'));
         $this->db->query();
         unlink('tmp/hashfailed.sql');
         $this->saveState(FALSE, __LINE__);
     }
     try {
         // if we are not complete
         $this->db->setQuery('SELECT COUNT(*) FROM bf_files WHERE queued = 1');
         $queueCount = $this->db->loadResult();
         if ($queueCount == 0 && $this->deepscancomplete == TRUE) {
             // use known md5 100% certain positive hacker files database to flag even more
             $this->db->setQuery(sprintf('UPDATE bf_files
                                          SET suspectcontent = 1
                                          WHERE currenthash
                                          IN (%s)', file_get_contents('db/suspectfiles.txt')));
             $this->db->query();
             $this->deepscancomplete = TRUE;
             $this->nextStepPlease();
         }
         if (!$queueCount && !$this->deepscancomplete) {
             bfLog::log('Adding files to the scan queue');
             $sql = "SELECT id FROM bf_files\n                            WHERE\n                                (\n                                  SIZE < 524288                                 -- 512k Limit\n                                AND\n                                  SIZE > 0                                      -- Must have content!\n                                )\n                            AND\n                                (\n                                  iscorefile = 0                                -- No Core Files\n                                OR\n                                  iscorefile IS NULL                            -- No Core Files - NULL !== 0 -- IDIOT PHIL!!!!\n                                OR\n                                  hashfailed = 1                                -- Or core files which hash has failed\n                                )\n                            AND                                                 -- Filter out the probably ok file extensions and other stuff we are 'fairly' happy to ignore\n                            (\n                                currenthash != 'f96aa8838dffa02a4a8438f2a8596025' -- ok blank index.html file\n                                AND currenthash != '86de3aeb6bd953d656a6994eaa495a6d' -- /libraries/fof/autoloader/component.php\n\n                                AND filewithpath NOT LIKE '/plugins/system/bfnetwork%' -- Our stuff\n                                AND filewithpath NOT LIKE '%.DS_Store%'         -- Mac finder files\n                                AND filewithpath NOT LIKE '%.zip'               -- cant preg_match inside a zip!\n                                AND filewithpath NOT LIKE '%.gzip'              -- cant preg_match inside a zip!\n                                AND filewithpath NOT LIKE '%.gz'                -- cant preg_match inside a zip!\n                                AND filewithpath NOT LIKE '%.doc'\n                                AND filewithpath NOT LIKE '%.docx'\n                                AND filewithpath NOT LIKE '%.xls'\n                                AND filewithpath NOT LIKE '%.ppt'\n                                AND filewithpath NOT LIKE '%.pdf'\n                                AND filewithpath NOT LIKE '%.rtf'               -- never seen anything bad in a rtf\n                                AND filewithpath NOT LIKE '%.mno'\n                                AND filewithpath NOT LIKE '%.ashx'\n                                AND filewithpath NOT LIKE '%.png'               -- never seen anything bad in a png\n                                AND filewithpath NOT LIKE '%.psd'               -- Photoshop, normally a massive file too\n                                AND filewithpath NOT LIKE '%.wott'              -- font file\n                                AND filewithpath NOT LIKE '%.ttf'               -- font file\n                                AND filewithpath NOT LIKE '%.css'               -- plain text css, never seen Joomla hack in css file\n                                AND filewithpath NOT LIKE '%.swf'               -- flash\n                                AND filewithpath NOT LIKE '%.flv'               -- flash\n                                AND filewithpath NOT LIKE '%.po'                -- language files\n                                AND filewithpath NOT LIKE '%.mo'\n                                AND filewithpath NOT LIKE '%.pot'\n                                AND filewithpath NOT LIKE '%.eot'\n                                AND filewithpath NOT LIKE '%.ini'\n                                AND filewithpath NOT LIKE '%.svg'\n                                AND filewithpath NOT LIKE '%.mpeg'              -- No need to audit inside audio files, never seen a Joomla hack in these\n                                AND filewithpath NOT LIKE '%.mvk'               -- No need to audit inside audio files, never seen a Joomla hack in these\n                                AND filewithpath NOT LIKE '%.mp3'               -- No need to audit inside audio files, never seen a Joomla hack in these\n                                AND filewithpath NOT LIKE '%.less'\n                                AND filewithpath NOT LIKE '%.sql'\n                                AND filewithpath NOT LIKE '%.wsdl'\n                                AND filewithpath NOT LIKE '%.woff'\n                                AND filewithpath NOT LIKE '%.xml'               -- never seen a hack in an xml file\n                                AND filewithpath NOT LIKE '%.php_expire'        -- Expired cache file\n                                AND filewithpath NOT LIKE '%.jpa'               -- Akeeba backup files\n                                AND filewithpath NOT LIKE '%/akeeba_json.php'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%/administrator/components/com_akeeba/backup/akeeba_json'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%/akeeba_backend.id%.php'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%/akeeba_backend.php'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%/akeeba_backend.id%.log'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%/akeeba_backend.log'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%/akeeba_lazy.php'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%/akeeba_frontend.php'           -- Akeeba json state file\n                                AND filewithpath NOT LIKE '%error_log'      -- PHP error logs, we alert to ALL these in another check\n                                AND filewithpath NOT LIKE '%/stats/webalizer.current'           -- Crappy file\n                                AND filewithpath NOT LIKE '%/stats/usage_%.html'           -- Crappy file\n                                AND filewithpath NOT LIKE '%/components/libraries/cmslib/cache/cache__%' -- Massive folder of cache files\n                                AND filewithpath NOT LIKE '%/plugins/system/akgeoip/lib/vendor/guzzle/guzzle/%' -- Akeeba GeoIP Docs\n                                AND filewithpath NOT LIKE '%/components/com_jce/editor/tiny_mce/plugins/code/img/icons.gif' -- JCE Code icons\n                            )";
             $this->db->setQuery($sql);
             if (method_exists($this->db, 'loadColumn')) {
                 $ids = $this->db->loadColumn();
             } else {
                 $ids = $this->db->loadResultArray();
             }
             bfLog::log($this->db->getErrorMsg());
             if (!count($ids)) {
                 bfLog::log('NO FILES TO DEEP SCAN = THIS CANNOT BE POSSIBLE RIGHT?');
                 $this->db->setQuery($sql);
                 $some = $this->db->query();
             } else {
                 $sql = "UPDATE bf_files SET queued = 1 WHERE id IN ( %s )";
                 if (strlen(sprintf($sql, implode(', ', $ids))) > $this->max_allowed_packet) {
                     $parts = $this->array_split($ids, 4);
                     $sqlToRun1 = sprintf($sql, implode(', ', $parts[0]));
                     bfLog::log('sql size 1= ' . strlen($sqlToRun1));
                     $this->db->setQuery($sqlToRun1);
                     $this->db->query();
                     $sqlToRun2 = sprintf($sql, implode(', ', $parts[1]));
                     bfLog::log('sql size 2= ' . strlen($sqlToRun2));
                     $this->db->setQuery($sqlToRun2);
                     $this->db->query();
                     $sqlToRun3 = sprintf($sql, implode(', ', $parts[2]));
                     bfLog::log('sql size 3= ' . strlen($sqlToRun3));
                     $this->db->setQuery($sqlToRun3);
                     $this->db->query();
                     $sqlToRun4 = sprintf($sql, implode(', ', $parts[3]));
                     bfLog::log('sql size 4= ' . strlen($sqlToRun4));
                     $this->db->setQuery($sqlToRun4);
                     $this->db->query();
                 } else {
                     $sql = "UPDATE bf_files SET queued = 1 WHERE id IN\n                        (\n                        " . implode(',', $ids) . "\n                        )";
                     $this->db->setQuery($sql);
                     $this->db->query();
                 }
             }
             // DEQUEUE known clean files not changed
             bfLog::log('DONE Adding ' . count($ids) . ' files to the scan queue db table');
             // Cache our patterns
             $pattern = file_get_contents('tmp/tmp.pattern');
             if (file_exists('tmp/tmp.pattern.lastmd5')) {
                 $lastPatternmd5 = file_get_contents('tmp/tmp.pattern.lastmd5');
             } else {
                 $lastPatternmd5 = "";
             }
             // if encrypted - decrypt
             if (substr($pattern, 0, 4) == 'RC4:') {
                 $pattern = base64_decode(substr($pattern, 4, strlen($pattern) - 4));
                 $RC4 = new Crypt_RC4();
                 $RC4->setKey('NotMeantToBeSecure');
                 // just to hide from other server side scanners
                 $pattern = $RC4->decrypt($pattern);
                 file_put_contents('tmp/tmp.pattern.lastmd5', md5($pattern));
                 //file_put_contents('tmp/tmp.pattern.unenc', $pattern);
                 bfLog::log('LAST PATTERN TEST =   ' . $lastPatternmd5 . '==' . md5($pattern));
                 if ($lastPatternmd5 == md5($pattern)) {
                     $doSpeedup = TRUE;
                 } else {
                     $doSpeedup = FALSE;
                 }
             }
             // load up the false positives hashes
             $falsepositives = file_get_contents('./tmp/tmp.false');
             if ($doSpeedup && (_BF_SPEED == 'DEFAULT' || _BF_SPEED == 'FAST')) {
                 $this->db->setQuery('SHOW TABLES LIKE "bf_files_last"');
                 if ($this->db->loadResult()) {
                     $speedupSQL = 'UPDATE bf_files AS NEWTABLE
                             INNER JOIN  (
                                 SELECT
                                     bf_files_last.filewithpath, bf_files_last.suspectcontent,  bf_files_last.falsepositive,  bf_files_last.encrypted  FROM bf_files_last
                                 LEFT JOIN
                                     bf_files ON bf_files_last.filewithpath = bf_files.filewithpath
                                 WHERE
                                     bf_files_last.currenthash = bf_files.currenthash
                                 AND
                                     bf_files_last.filemtime = bf_files.filemtime
                                 AND
                                     bf_files_last.fileperms = bf_files.fileperms
                                 AND
                                     bf_files_last.filewithpath = bf_files.filewithpath
                             ) AS
                                 OLDTABLE
                                ON
                                 NEWTABLE.filewithpath = OLDTABLE.filewithpath
                             SET
                                 NEWTABLE.filewithpath = OLDTABLE.filewithpath,
                                 NEWTABLE.suspectcontent = OLDTABLE.suspectcontent,
                                 NEWTABLE.falsepositive = OLDTABLE.falsepositive,
                                 NEWTABLE.encrypted = OLDTABLE.encrypted,
                                 NEWTABLE.queued = 0
                             WHERE
                               OLDTABLE.suspectcontent != 1
                          ';
                     file_put_contents('tmp/speedup.sql', $speedupSQL);
                 }
             }
             // ok this took a lot of time, so to be careful we will re-tick
             $this->saveState(FALSE, __LINE__);
         }
         $pattern = file_get_contents('tmp/tmp.pattern');
         // if encrypted - decrypt
         if (substr($pattern, 0, 4) == 'RC4:') {
             $pattern = base64_decode(substr($pattern, 4, strlen($pattern) - 4));
             $RC4 = new Crypt_RC4();
             $RC4->setKey('NotMeantToBeSecure');
             // just to hide from other server side scanners
             $pattern = $RC4->decrypt($pattern);
         }
         // load up the false positives hashes
         $falsepositives = file_get_contents('./tmp/tmp.false');
         if (file_exists('tmp/speedup.sql') && (_BF_SPEED == 'DEFAULT' || _BF_SPEED == 'FAST')) {
             bfLog::log('Found speedup sql files - removing files to deepscan');
             $this->db->setQuery(file_get_contents('tmp/speedup.sql'));
             $this->db->query();
             // force at least one file to be audited to prevent broken loop
             $this->db->setQuery('UPDATE bf_files SET queued = 1 WHERE filewithpath = "/configuration.php"');
             $this->db->query();
             unlink('tmp/speedup.sql');
             $this->saveState(FALSE, __LINE__);
         } else {
             if (file_exists(dirname(__FILE__) . '/tmp/speedup.sql')) {
                 @unlink(dirname(__FILE__) . '/tmp/speedup.sql');
             }
         }
         // A nice while loop while we have time left
         if (count($this->getmergedIds())) {
             $this->db->setQuery("SELECT count(*) FROM bf_files WHERE queued = 1 AND id NOT IN (" . implode(',', $this->getmergedIds()) . ")");
         } else {
             $this->db->setQuery("SELECT COUNT(*) FROM bf_files WHERE queued = 1");
         }
         while ($this->db->loadResult() > 0 && $this->_timer->getTimeLeft() > _BF_CONFIG_DEEPSCAN_TIMER_ONE) {
             // ok so we have a load of files....
             if (count($this->getmergedIds())) {
                 $this->db->setQuery("SELECT * FROM bf_files WHERE queued = 1 AND id NOT IN (" . implode(',', $this->getmergedIds()) . ") ORDER BY id ASC LIMIT " . _BF_CONFIG_DEEPSCAN_COUNT_ONE);
             } else {
                 $this->db->setQuery("SELECT * FROM bf_files WHERE queued = 1 ORDER BY id ASC LIMIT " . _BF_CONFIG_DEEPSCAN_COUNT_ONE);
             }
             $files_to_scan = $this->db->loadObjectList();
             // still, while we have files and time left
             while (count($files_to_scan) && $this->_timer->getTimeLeft() > _BF_CONFIG_DEEPSCAN_TIMER_ONE) {
                 // get one file
                 $file_to_scan = array_pop($files_to_scan);
                 /**
                  * If this is a large JS file like jquery.ui.src.js then we need more time dammit!
                  * Also need to do this on WSDL files for some reason
                  */
                 $size = filesize(JPATH_BASE . $file_to_scan->filewithpath);
                 if ((strpos($file_to_scan->filewithpath, 'wsdl') || strpos($file_to_scan->filewithpath, 'jquery')) && $this->_timer->getTimeLeft() < 4 || $size > 100000 && (_BF_SPEED != 'DEFAULT' && _BF_SPEED != 'FAST') && $this->_timer->getTimeLeft() < 4) {
                     bfLog::log('Next file is a problematic JS/wsdl is of size ' . $size . ' and we only had ' . $this->_timer->getTimeLeft() . ' left so we are Zzz... and will come back next tick');
                     $this->updateFilesFromDeepscan(__LINE__);
                     $this->saveState(FALSE, __LINE__);
                 }
                 // toggle if we can safely skip ip
                 $skip = FALSE;
                 // Is this a suspect file
                 $isSuspect = FALSE;
                 // Is this file encrypted
                 $encrypted = FALSE;
                 // Is this a false positive
                 $falsepositive = FALSE;
                 $file_extension = strtolower(pathinfo(JPATH_BASE . $file_to_scan->filewithpath, PATHINFO_EXTENSION));
                 // If the file no longer exists then skip
                 if (!file_exists(JPATH_BASE . $file_to_scan->filewithpath)) {
                     bfLog::log('FILE WAS SKIPPED AS DOES NOT EXIST!!! ' . $file_to_scan->filewithpath);
                     $skip = TRUE;
                 }
                 if ($skip == FALSE && $file_extension == 'gif') {
                     if ($this->is_ani(JPATH_BASE . $file_to_scan->filewithpath)) {
                         bfLog::log('FILE WAS ANIMATED GIF - skipping ' . $file_to_scan->filewithpath);
                         $skip = TRUE;
                     }
                 }
                 // example skip
                 if ($file_to_scan->filewithpath == '/backups/akeeba_json.php') {
                     bfLog::log('skipping ' . $file_to_scan->filewithpath);
                     $skip = TRUE;
                 }
                 // example skip
                 if ($file_to_scan->filewithpath == '/stats/webalizer.current') {
                     bfLog::log('skipping ' . $file_to_scan->filewithpath);
                     $skip = TRUE;
                 }
                 // example skip
                 if (preg_match('/\\/stats\\/usage_.*\\.html/', $file_to_scan->filewithpath)) {
                     bfLog::log('skipping ' . $file_to_scan->filewithpath);
                     $skip = TRUE;
                 }
                 if ($skip == FALSE) {
                     // If this is in our known false positives list then skip it
                     $lookfor = md5($file_to_scan->filewithpath) . md5_file(JPATH_BASE . $file_to_scan->filewithpath);
                     if (preg_match('/' . $lookfor . '/', $falsepositives)) {
                         $skip = TRUE;
                         $falsepositive = TRUE;
                         bfLog::log('FILE WAS SKIPPED AS FALSE POSITIVE!!! ' . $file_to_scan->filewithpath);
                     }
                 }
                 if ($skip == FALSE && filesize(JPATH_BASE . $file_to_scan->filewithpath) > 524288) {
                     bfLog::log('FILE WAS OVER 1Mb - skipping ' . $file_to_scan->filewithpath);
                     $skip = TRUE;
                 }
                 if ($skip === TRUE) {
                     // mark it as false positive (-2) or skipped (-1)
                     $status = $falsepositive == TRUE ? "-2" : "-1";
                     $sql = sprintf("UPDATE bf_files SET queued = 0, suspectcontent = %s WHERE id = '%s'", $status, addslashes($file_to_scan->id));
                     $this->db->setQuery($sql);
                     $this->db->query();
                     continue;
                     // no more processing on this file - skipped
                 }
                 // cleanup
                 $fff = JPATH_BASE . stripslashes($file_to_scan->filewithpath);
                 // WINDOWS I HATE YOU! - bodge it
                 $fff = str_replace('\\:', '/:', $fff);
                 // need a @ to prevent access denied
                 $chunk = @file_get_contents($fff);
                 // remove stuff that is likely to be marked as suspect, when we are happy its not
                 $chunk = $this->applyStringExceptions($chunk, $file_to_scan);
                 // Not really a chunk now, as we load the whole file into memory
                 if (trim($chunk)) {
                     // Need at least 3 seconds to run the preg_match on
                     // average slow machine
                     if ($this->_timer->getTimeLeft() < _BF_CONFIG_DEEPSCAN_TIMER_TWO) {
                         $this->saveState(FALSE, __LINE__);
                     }
                     // hard to audit c99 clones
                     preg_match('/(auth_pass).*(default_use_ajax)/ism', $chunk, $matches);
                     if (count($matches) >= 3) {
                         $isSuspect = true;
                     } else {
                         // Test if suspect
                         bfLog::log('Auditing File: ' . $file_to_scan->filewithpath . ' - ' . $file_to_scan->size . ' bytes');
                         $isSuspect = preg_match('/' . $pattern . '/ism', $chunk) ? TRUE : FALSE;
                     }
                     // Test If encrypted
                     $regex = "/OOO000000|if\\(!extension_loaded\\('ionCube\\sLoader'\\)\\)|<\\?php\\s@Zend;|This\\sfile\\swas\\sencoded\\sby\\sthe.*Zend Encoder/i";
                     $encrypted = preg_match($regex, $chunk) ? 1 : 0;
                 } else {
                     bfLog::log('FILE WAS EMPTY!!! ' . $file_to_scan->filewithpath);
                 }
                 // free up memory
                 unset($chunk);
                 $encrypted == (int) $encrypted;
                 $isSuspect = (int) $isSuspect;
                 if ($encrypted && $isSuspect) {
                     $this->_encryptedAndSuspectIds[] = $file_to_scan->id;
                 } else {
                     if ($encrypted) {
                         $this->_encryptedIds[] = $file_to_scan->id;
                     } else {
                         if ($isSuspect) {
                             $this->_suspectIds[] = $file_to_scan->id;
                         } else {
                             $this->_notencryptedAndSuspectIds[] = $file_to_scan->id;
                         }
                     }
                 }
                 if (_BF_SPEED == 'CRAPPYWEBHOST' || $this->_timer->getTimeLeft() < _BF_CONFIG_DEEPSCAN_TIMER_TWO) {
                     $this->updateFilesFromDeepscan(__LINE__);
                     $this->saveState(FALSE, __LINE__);
                 }
             }
             if ($this->_timer->getTimeLeft() < _BF_CONFIG_DEEPSCAN_TIMER_TWO) {
                 $this->updateFilesFromDeepscan(__LINE__);
                 $this->saveState(FALSE, __LINE__);
             }
             // needed to go back up to the top of the loop
             if (count($this->getmergedIds())) {
                 $this->db->setQuery("SELECT count(*) FROM bf_files WHERE queued = 1 AND id NOT IN (" . implode(',', $this->getmergedIds()) . ")");
             } else {
                 $this->db->setQuery("SELECT COUNT(*) FROM bf_files WHERE queued = 1");
             }
         }
         if (count($this->getmergedIds())) {
             $this->db->setQuery("SELECT count(*) FROM bf_files WHERE queued = 1 AND id NOT IN (" . implode(',', $this->getmergedIds()) . ")");
         } else {
             $this->db->setQuery("SELECT COUNT(*) FROM bf_files WHERE queued = 1");
         }
         if ($this->db->loadResult() == 0) {
             bfLog::log(' ======== deepscancomplete ========');
             $this->deepscancomplete = TRUE;
             $this->updateFilesFromDeepscan(__LINE__);
             $this->nextStepPlease();
         } else {
             bfLog::log(' ======== deepscancomplete NOT COMPLETE========');
             $this->updateFilesFromDeepscan(__LINE__);
             $this->saveState(FALSE, __LINE__);
         }
     } catch (Exception $e) {
         // Just continue...
         if (!defined('_BF_LAST_BREATH')) {
             define('_BF_LAST_BREATH', $e->getMessage());
         }
         bfLog::log(' ======== EXCEPTION =========' . $e->getMessage());
     }
 }
Beispiel #8
0
<?php

$secret_key = "7d7e206d9e5b4e491d087828736f4ea8";
// Your Secret Key
if (isset($_GET['DR'])) {
    require 'Rc43.php';
    $DR = preg_replace("/\\s/", "+", $_GET['DR']);
    $rc4 = new Crypt_RC4($secret_key);
    $QueryString = base64_decode($DR);
    $rc4->decrypt($QueryString);
    $QueryString = split('&', $QueryString);
    $response = array();
    foreach ($QueryString as $param) {
        $param = split('=', $param);
        $response[$param[0]] = urldecode($param[1]);
    }
}
?>
<HTML>
<HEAD>
<TITLE>Payment Made on E-Billing Solutions Pvt Ltd </TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<style>
	h1       { font-family:Arial,sans-serif; font-size:24pt; color:#08185A; font-weight:100; margin-bottom:0.1em}
    h2.co    { font-family:Arial,sans-serif; font-size:24pt; color:#FFFFFF; margin-top:0.1em; margin-bottom:0.1em; font-weight:100}
    h3.co    { font-family:Arial,sans-serif; font-size:16pt; color:#000000; margin-top:0.1em; margin-bottom:0.1em; font-weight:100}
    h3       { font-family:Arial,sans-serif; font-size:16pt; color:#08185A; margin-top:0.1em; margin-bottom:0.1em; font-weight:100}
    body     { font-family:Verdana,Arial,sans-serif; font-size:11px; color:#08185A;}
	th 		 { font-size:12px;background:#015289;color:#FFFFFF;font-weight:bold;height:30px;}
	td 		 { font-size:12px;background:#DDE8F3}
	.pageTitle { font-size:24px;}
Beispiel #9
0
 /**
  * Encrypt a string using the RC4 Key provided in the encrypted request
  * from the service backend
  *
  * @param string $msg
  *
  * @return string Base64encoded message
  */
 public static function getEncrypted($msg)
 {
     $start = time();
     bfLog::log('Starting Encryption....');
     // check our msg is a string
     if (is_object($msg) || is_array($msg)) {
         $msg = json_encode($msg);
     }
     // init a RC4 encryption routine - MUCH faster than public/private key
     $rc4 = new Crypt_RC4();
     if (!defined('RC4_KEY')) {
         bfLog::log('NO RC4_KEY FOUND!!');
         die('No Encryption Key');
     }
     // Use the one time encryption key the requester provided
     $rc4->setKey(RC4_KEY);
     // encrypt the data
     $encrypted = $rc4->encrypt($msg);
     // return the data, encoded just in case
     $str = base64_encode($encrypted);
     bfLog::log('Finished Encryption.... took ' . (time() - $start) . ' seconds');
     return $str;
 }
Beispiel #10
0
function sixscan_common_decrypt_string($encr_data, $key)
{
    if (class_exists('Crypt_RC4') == FALSE) {
        require_once SIXSCAN_PLUGIN_DIR . "modules/signatures/Crypt/RC4.php";
    }
    $rc4_encr = new Crypt_RC4();
    $rc4_encr->setKey($key);
    return $rc4_encr->decrypt($encr_data);
}
Beispiel #11
0
 /**
  * Attempts to finalize an accepted transaction
  *
  * @result string Should be 'accepted' unless something has gone quite wrong
  */
 public function finalizeOrder($response)
 {
     global $smarty, $cart, $cookie;
     require dirname(__FILE__) . '/Rc43.php';
     $DR = $response;
     $secret_key = Configuration::get('SECRET_KEY');
     //print_r($secret_key);
     if (isset($DR)) {
         $DR = preg_replace("/\\s/", "+", $DR);
         $rc4 = new Crypt_RC4($secret_key);
         $QueryString = base64_decode($DR);
         $rc4->decrypt($QueryString);
         $QueryString = split('&', $QueryString);
         $response = array();
         foreach ($QueryString as $param) {
             $param = split('=', $param);
             $response[$param[0]] = urldecode($param[1]);
         }
         //print_r($response);
     }
     $cartID = $response['MerchantRefNo'];
     $cart = new Cart($cartID);
     $deliveryAddress = new Address($cart->id_address_delivery);
     $op = $cod = 0;
     Carrier::getPreferredCarriers($deliveryAddress->postcode, $cod, $op);
     if ($op > 0) {
         $cart->id_carrier = (int) $op;
         $cart->update();
     }
     if ($response['ResponseCode'] == 0) {
         $responseMsg = "Your Order has Been Processed";
     } else {
         $responseMsg = "Transaction Failed, Retry!!";
     }
     $cart = new Cart(intval($response['MerchantRefNo']));
     //echo "<pre>";print_r($cart);
     //if (!$cart->id)
     //	return $this->l('Cart not found');
     if ($response['ResponseCode'] == 0) {
         $status = _PS_OS_PREPARATION_;
     } else {
         $status = Configuration::get('EBS_ID_ORDER_FAILED');
     }
     $this->validateOrder($response['MerchantRefNo'], $status, $response['Amount'], $this->displayName, $this->l('EBS transaction ID: ') . $response['PaymentID'], $response['ResponseMessage']);
     $customer = new Customer((int) $cart->id_customer);
     if ($response['ResponseCode'] == 0) {
         Tools::redirectLink(__PS_BASE_URI__ . 'order-confirmation.php?key=' . $customer->secure_key . '&id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->id . '&id_order=' . (int) $this->currentOrder);
     }
     $smarty->assign(array('this_path' => $this->_path, 'responseMsg' => $responseMsg, 'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/'));
 }