Skip to content

Commit

Permalink
Security patch
Browse files Browse the repository at this point in the history
  • Loading branch information
warhawk3407 committed Oct 11, 2014
1 parent 2907188 commit bbfc662
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<Files cron.php>
AuthName "403"
deny from all
</Files>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Expand Down
2 changes: 2 additions & 0 deletions app/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AuthName "403"
deny from all
2 changes: 1 addition & 1 deletion app/app.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
break;

default:
// PHP 5.5 Function Implementation
// PHP 5.5 Functions Implementation
require( LIBS_DIR . '/php5.5/func.inc.php');

// Database Handle Manager
Expand Down
52 changes: 38 additions & 14 deletions app/core/auth.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

class Core_AuthService
{
// Handle
public static $authService;

// Username
private $username;

Expand Down Expand Up @@ -75,23 +78,22 @@ function __construct( $username = '', $auth_key = APP_LOGGED_IN_KEY, $rsa_privat
}

/**
* Decrypt Session Credentials
* Service Handler
*
* @param Array $session
* @return array
* @param String $username
* @param String $auth_key
* @param String $rsa_private_key
* @param String $rsa_public_key
* @return Core_AuthService
* @access public
*/
public static function decryptSessionCredentials( $session ) {
if ( !empty($session) && array_key_exists('CREDENTIALS', $session) ) {
$rsa = new Crypt_RSA();
$rsa->loadKey( $this->rsa_private_key ); // private key

$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$credentials = unserialize( $rsa->decrypt( $session['CREDENTIALS'] ) );
public static function getAuthService( $username = '', $auth_key = APP_LOGGED_IN_KEY, $rsa_private_key = RSA_PRIVATE_KEY, $rsa_public_key = RSA_PUBLIC_KEY ) {
if ( empty(self::$authService) || !is_object(self::$authService) || (get_class(self::$authService) != 'Core_AuthService') ) {

return $credentials;
self::$authService = new Core_AuthService( $username, $auth_key, $rsa_private_key, $rsa_public_key );
}
return array();

return self::$authService;
}

/**
Expand All @@ -102,7 +104,9 @@ public static function decryptSessionCredentials( $session ) {
* @access public
*/
public static function getSessionPrivilege() {
$credentials = Core_AuthService::decryptSessionCredentials( $_SESSION );
$authService = Core_AuthService::getAuthService();

$credentials = $authService->decryptSessionCredentials();

if ( !empty($credentials['role']) ) {
return $credentials['role'];
Expand All @@ -119,7 +123,7 @@ public static function getSessionPrivilege() {
*/
public function getSessionValidity() {
if ( !empty($this->username) ) {
$credentials = Core_AuthService::decryptSessionCredentials( $this->session );
$credentials = $this->decryptSessionCredentials();

if ( $credentials['username'] == $this->username && $credentials['key'] == $this->auth_key && $credentials['token'] == session_id() ) {
return TRUE;
Expand All @@ -128,6 +132,26 @@ public function getSessionValidity() {
return FALSE;
}

/**
* Decrypt Session Credentials
*
* @param none
* @return array
* @access private
*/
private function decryptSessionCredentials() {
if ( !empty($this->session) && array_key_exists('CREDENTIALS', $this->session) ) {
$rsa = new Crypt_RSA();
$rsa->loadKey( $this->rsa_private_key ); // private key

$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$credentials = unserialize( $rsa->decrypt( $this->session['CREDENTIALS'] ) );

return $credentials;
}
return array();
}

/**
* Create A New Legit Session
*
Expand Down
2 changes: 1 addition & 1 deletion app/routing.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Flight::route('GET|POST /', function() {
// User Authentication

$authService = new Core_AuthService();
$authService = Core_AuthService::getAuthService();

// Test if the user has a whitecard to access the system

Expand Down
1 change: 1 addition & 0 deletions gui/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Options -Indexes
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* @link http://www.bgpanel.net/
*/

define('LICENSE', 'GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007');

/**
* Bright Game Panel Init
*/
Expand Down
6 changes: 5 additions & 1 deletion init.app.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
* @link http://www.bgpanel.net/
*/

define('LICENSE', 'GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007');
// Prevent direct access
if (!defined('LICENSE'))
{
exit('Access Denied');
}

/**
* ERROR Handling
Expand Down
2 changes: 2 additions & 0 deletions logs/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AuthName "403"
deny from all

0 comments on commit bbfc662

Please sign in to comment.