-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.php
executable file
·225 lines (173 loc) · 6.08 KB
/
classes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
function dbproc($results,$table)
{
$key = substr($_COOKIE['keymas'],0,16);
$cryptox = new Crypto($key);
//echo count($results);
for($i=0;$i<count($results);$i++)
{
$q = "insert into ".$table." values(\"";
for($j=0;$j<count($results[$i]);$j++)
{
$valx = utf8_decode($results[$i][$j]);
$val = mysql_aes_decrypt($valx, $key);
if($j == count($results[$i])-1)
$q .= $val."\"";
else
$q .= $val."\",\"";
}
mysql_query($q.")");
}
echo " <h2>Rows : ".$i."</h2>";
}
function createTable($table)
{
require_once 'connectioncli.php';
mysql_query("create table ".$table." (srno text,sname text,subcode text,subname text,intm text,extm text,cre text)");
}
function insertResult($resname,$table)
{
require_once 'connectioncli.php';
//echo "insert into MRESULTT values(\"".$table."\",\"".$name."\")";
mysql_query("insert into MRESULTT values(\"".$table."\",\"".$resname."\")");
}
function mysql_aes_decrypt($val,$ky)
{
$key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
for($a=0;$a<strlen($ky);$a++)
$key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
$mode = MCRYPT_MODE_ECB;
$enc = MCRYPT_RIJNDAEL_128;
$dec = @mcrypt_decrypt($enc, $key, $val, $mode, @mcrypt_create_iv( @mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM ) );
return rtrim($dec,(( ord(substr($dec,strlen($dec)-1,1))>=0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null));
}
function authorize($string){
if(array_key_exists("auth",$_COOKIE)){
//echo $_COOKIE["auth"];
$pbkdf2 = new PBKDF2();
$key = $pbkdf2->deriveKey($string);
$crypto = new Crypto($key);
$c = $crypto->aesDecrypt($_COOKIE["auth"]);
if($c != $string)
echo "<script type='text/javascript'>window.location='auth.php?goto=$string'</script>";
}
else
echo "<script type='text/javascript'>window.location='auth.php?goto=$string'</script>";
}
class Crypto {
public function __construct($key) {
include_once("aes/AES.class.php");
$this->aes = new AES($key);
$this->key = $key;
}
public function aesEncrypt($contents) {
$data = $contents;
$aes = $this->aes;
return $aes->encrypt($data);
}
public function aesDecrypt($contents) {
$data = $contents;
$aes = $this->aes;
return $aes->decrypt($data);
}
}
class PBKDF2 {
public function __construct() {
$this->salt = "12345678";
$this->iterations = 2000;
$this->keyLen = 32;
}
public function deriveKey($p) {
return substr(strtoupper($this->strToHex($this->pbkdf2($p, $this->salt, $this->iterations, $this->keyLen, 'sha1'))),0,32);
}
function pbkdf2($p, $s, $c, $kl, $a = 'sha256', $st=0) {
$kb = $st + $kl; // Key blocks to compute
$dk = ''; // Derived key
for ($block = 1; $block <= $kb; $block++) {
$ib = $h = hash_hmac($a, $s . pack('N', $block), $p, true);
for ($i = 1; $i < $c; $i++) {
$ib ^= ($h = hash_hmac($a, $h, $p, true));
}
$dk .= $ib; // Append iterated block
}
return substr($dk, $st, $kl);
}
function strToHex($string) {
$hex = '';
for ($i = 0; $i < strlen($string); $i++) {
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
}
function strToHex($string) {
$hex = '';
for ($i = 0; $i < strlen($string); $i++) {
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function hexToStr($string) {
$hex = '';
for ($i = 0; $i < strlen($string); $i++) {
$hex .= hexdec($string[$i]) ;
}
return $hex;
}
class pJSON
{
public static function getJSON($array)
{
$json = json_encode($array);
return $json;
}
public static function getParam($json,$param,$decode = "false")
{
if($decode == "true")
{
$x = json_decode($json);
return utf8_decode($x->$param);
}
else
return $x->$param;
}
}
class Operator{
public function phase1($username,$passphrase){
$challenge=uniqid();
$x=$username.$passphrase;
$pbkdf2 = new PBKDF2();
$key = $pbkdf2->deriveKey($x);
$keymas = $pbkdf2->deriveKey($key.":".$challenge);
$crypto = new Crypto($keymas);
require_once "settings.php";
$url = getSHOST()."?mode=handshake&values=".$username.":".$challenge;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "www.google.com");
$body = curl_exec($ch);
$json = json_decode($body);
$emsg = utf8_decode($json->message);
$token = $crypto->aesDecrypt(utf8_decode($json->token));
$plain = $crypto->aesDecrypt($emsg);
$pl = $plain;
if($pl == "Standard Message#1")
{
setcookie("username",$username);
setcookie("passphrase",$passphrase);
setcookie("key",$key);
setcookie("keymas",$keymas);
setcookie("token",$token);
echo "<script type='text/javascript'>window.location = \"phase2.php\";</script>";
}
else
{
//redirect("?err=true");
}
}
function redirectTo($location){
echo "Hello";
}
}
?>