From 47f89370307b1be034c6e64113afc2956651f2d2 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 27 Jan 2017 15:54:30 +0100 Subject: [PATCH] Fixed die() --- lib/api/send | 60 ++++++++++++++++------------ lib/cyclic-hash/decr | 90 ++++++++++++++++++++++++++---------------- lib/cyclic-hash/hash | 46 ++++++++++++--------- lib/cyclic-hash/new | 52 +++++++++++++----------- lib/cyclic-hash/secret | 1 - lib/include/const | 1 - lib/include/func | 23 ++++++----- 7 files changed, 160 insertions(+), 113 deletions(-) delete mode 100644 lib/cyclic-hash/secret mode change 100644 => 100755 lib/include/const mode change 100644 => 100755 lib/include/func diff --git a/lib/api/send b/lib/api/send index f571558..e24449c 100755 --- a/lib/api/send +++ b/lib/api/send @@ -6,40 +6,50 @@ // will send the request using `auth` for cyclic hash - /* [1] Fetch useful data - =========================================================*/ - /* (1) Fetch target url */ - $url = @file_get_contents(URL_CONF); + function api_send(){ - if( $url === false ) - die(1); + /* [1] Fetch useful data + =========================================================*/ + /* (1) Fetch target url */ + $url = @file_get_contents(URL_CONF); - /* (2) Fetch cyclic hash */ - $hash = syscall(SOURCE_DIR.'/lib/cyclic-hash/hash'); - echo $hash; + if( $url === false ) + return 127; - die(0); - + /* (2) Fetch cyclic hash */ + $hash = syscall(SOURCE_DIR.'/lib/cyclic-hash/hash'); - - + var_dump($hash); + if( strlen($hash) != 128 ) + return 127; - + /* (3) Try new hash if available */ + $new = syscall(SOURCE_DIR.'/lib/cyclic-hash/new'); + + var_dump('new'); var_dump($new); + - /* [1] Create httpRequest basis - =========================================================*/ - /* (1) Set URL */ - $curl = curl_init($url); + /* (4) Decrement the hash */ + var_dump( 'decr: ',syscall(SOURCE_DIR.'/lib/cyclic-hash/decr') ); - /* (2) Specify that we want to catch result instead of displaying it */ - curl_setopt($curl, CURLOPT_RETURNTRANSFERER, true); + - /* (3) Set HTTP method -> POST */ - curl_setopt($curl, CURLOPT_POST, true); + /* [1] Create httpRequest basis + =========================================================*/ + /* (1) Set URL */ + $curl = curl_init($url); - /* (4) Section Title */ - - + /* (2) Set HTTP method -> POST */ + curl_setopt($curl, CURLOPT_POST, true); + + /* (3) Set headers */ + curl_setopt($curl, CURLOPT_HTTPHEADER, [ + 'Content-Type: multipart/form-data; boundary=' + ]); + + } + + echo api_send(); diff --git a/lib/cyclic-hash/decr b/lib/cyclic-hash/decr index f7d35e5..bbf384f 100755 --- a/lib/cyclic-hash/decr +++ b/lib/cyclic-hash/decr @@ -25,48 +25,68 @@ } - /* [2] Fetch necessary data - =========================================================*/ - /* (1) Fetch secret file */ - $secret = @file_get_contents(SECRET_CONF); - - /* (2) Check secret file format */ - if( !is_string($secret) || !preg_match("/^(.{250}):(\d+)$/", $secret, $match) ){ - // Generate new secret - $secret = generate_secret().':1000'; + function cyclichash_decr(){ - // Try to override the secret file - @file_put_contents(SECRET_CONF, $secret) && die(0) || die(127); - } + /* [2] Fetch necessary data + =========================================================*/ - /* (3) Extract data */ - $key = (string) $match[1]; - $depth = (int) $match[2]; - - - /* [3] If can decrement, decrement - =========================================================*/ - if( $depth > 1 ){ - - /* (1) Decrement the depth */ - $depth--; - - /* (2) Try to override the secret file */ - @file_put_contents(SECRET_CONF, "$key:$depth") && die(0) || die(127); - - - /* [4] If cannot decrement, generate new password - =========================================================*/ - }else{ + /* (1) Fetch secret file */ + $secret = @file_get_contents(SECRET_CONF); - // Generate new secret - $secret = generate_secret().':1000'; + /* (2) Check secret file format */ + if( !is_string($secret) || !preg_match("/^(.{250}):(\d+)$/", $secret, $match) ){ + + // Generate new secret + $secret = generate_secret().':1000'; + + // Try to override the secret file + if( @file_put_contents(SECRET_CONF, $secret) ) + return 0; + else + return 127; + } + + /* (3) Extract data */ + $key = (string) $match[1]; + $depth = (int) $match[2]; + + + /* [3] If can decrement, decrement + =========================================================*/ + if( $depth > 1 ){ + + /* (1) Decrement the depth */ + $depth--; + + /* (2) Try to override the secret file */ + if( @file_put_contents(SECRET_CONF, "$key:$depth") ) + return 0; + else + return 127; + + + /* [4] If cannot decrement, generate new password + =========================================================*/ + }else{ + + // Generate new secret + $secret = generate_secret().':999'; + + // Try to override the secret file + if( @file_put_contents(SECRET_CONF, $secret) ) + return 0; + else + return 127; + + } + + return 0; - // Try to override the secret file - file_put_contents(SECRET_CONF, $secret) && die(0) || die(127); } + echo cyclichash_decr(); + ?> diff --git a/lib/cyclic-hash/hash b/lib/cyclic-hash/hash index 0301b95..a719f70 100755 --- a/lib/cyclic-hash/hash +++ b/lib/cyclic-hash/hash @@ -5,28 +5,36 @@ require_once __DIR__.'/../include/const'; - /* [1] Fetch necessary data - =========================================================*/ - /* (1) Fetch secret file */ - $secret = @file_get_contents(SECRET_CONF); - - /* (2) Check secret file format */ - if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+)$/", $secret, $match) ) - die(127); + function cyclichash_hash(){ - /* (3) Extract data for hashing from @secret */ - $key = (string) $match[1]; - $depth = (int) $match[2]; + /* [1] Fetch necessary data + =========================================================*/ + /* (1) Fetch secret file */ + $secret = @file_get_contents(SECRET_CONF); + + /* (2) Check secret file format */ + if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+)$/", $secret, $match) ) + return 127; + + /* (3) Extract data for hashing from @secret */ + $key = (string) $match[1]; + $depth = (int) $match[2]; - /* [2] Hash data - =========================================================*/ - /* (1) Initialize with data */ - $hash = $key; + /* [2] Hash data + =========================================================*/ + /* (1) Initialize with data */ + $hash = $key; - /* (2) Hash @depth times */ - for( $d = 0 ; $d < $depth ; $d++ ) - $hash = hash('sha512', $hash); + /* (2) Hash @depth times */ + for( $d = 0 ; $d < $depth ; $d++ ) + $hash = hash('sha512', $hash); - echo $hash; + return $hash; + + } + + + echo cyclichash_hash(); ?> + diff --git a/lib/cyclic-hash/new b/lib/cyclic-hash/new index ba224e4..8c136ad 100755 --- a/lib/cyclic-hash/new +++ b/lib/cyclic-hash/new @@ -5,33 +5,39 @@ require_once __DIR__.'/../include/const'; - /* [1] Fetch necessary data - =========================================================*/ - /* (1) Fetch secret file */ - $secret = @file_get_contents(SECRET_CONF); - - /* (2) Check secret file format */ - if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+)$/", $secret, $match) ) - die(127); + function cyclichash_new(){ - /* (3) Extract data for hashing from @secret */ - $key = (string) $match[1]; - $depth = (int) $match[2]; + /* [1] Fetch necessary data + =========================================================*/ + /* (1) Fetch secret file */ + $secret = @file_get_contents(SECRET_CONF); + + /* (2) Check secret file format */ + if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+)$/", $secret, $match) ) + return 127; + + /* (3) Extract data for hashing from @secret */ + $key = (string) $match[1]; + $depth = (int) $match[2]; - /* (4) Die if not token not changed */ - if( $depth < 1000 ) - die(0); - + /* (4) Die if not token not changed */ + if( $depth < 999 ) + return 0; + - /* [2] If hash have just been created (original depth = 1000) - =========================================================*/ - /* (1) Return new hash */ - $newhash = $key; + /* [2] If hash have just been created (original depth = 1000) + =========================================================*/ + /* (1) Return new hash */ + $newhash = $key; - /* (2) Hash @depth times = 1000 */ - for( $d = 0 ; $d < 1000 ; $d++ ) - $newhash = hash('sha512', $newhash); + /* (2) Hash @depth times = 1000 */ + for( $d = 0 ; $d < 1000 ; $d++ ) + $newhash = hash('sha512', $newhash); - die($newhash); + return $newhash; + + } + + echo cyclichash_new(); ?> diff --git a/lib/cyclic-hash/secret b/lib/cyclic-hash/secret deleted file mode 100644 index bb470df..0000000 --- a/lib/cyclic-hash/secret +++ /dev/null @@ -1 +0,0 @@ -2wFkoxlQvF8S3twsVAm705_8HuUCV3dYzTiXpDNUiWLmohOjR9qRfq_XUUyPYMMxE3u3HgXZbIkAZ7TQhjHwJHsCA0ryNc4rgyuXOrW_8fz7nsYELEatkC5VDwspJwR_3kXSMSRU7q1uSZ8CDi5XVbSxIkXrQNqU7mMTeDNl2OPVMYxofCl9OdHvxDWmpmgwI1pWEbhHZ5BL378iKusxH82dLZAakQH2S5ZvgfbflN_oU8HEC8bjgew1c5:992 \ No newline at end of file diff --git a/lib/include/const b/lib/include/const old mode 100644 new mode 100755 index f90fa3a..3e5c777 --- a/lib/include/const +++ b/lib/include/const @@ -1,5 +1,4 @@ #!/usr/bin/php -