• 高校教务系统密码加密逻辑及JS逆向——山东女子学院,蚌埠医学院,郑州工商学院,新疆大学,河南机电职业学院


    高校教务系统密码加密逻辑及JS逆向

    本文将介绍高校教务系统的密码加密逻辑以及使用JavaScript进行逆向分析的过程。通过本文,你将了解到密码加密的基本概念、常用加密算法以及如何通过逆向分析来破解密码。

    本文仅供交流学习,勿用于非法用途。

    一、密码加密基本概念

    密码加密是一种保护信息安全的技术手段,它通过将明文(原始信息)转换为密文(加密后的信息),以防止未经授权的访问和篡改。常见的密码加密算法有MD5、SHA-1、SHA-256等。

    1.1 加密过程

    加密过程通常包括以下步骤:

    1. 密钥扩展:将密钥扩展为多个轮值,每个轮值都与明文的一部分有关。
    2. 初始轮值生成:将扩展后的密钥与轮常数进行某种运算,生成第一轮加密的密文。
    3. 多轮迭代:对密文进行多轮迭代操作,每轮操作都包括非线性函数、模运算和轮常数的变换。
    4. 最终密文:经过多轮迭代后,得到最终的密文。

    1.2 解密过程

    解密过程与加密过程相反,通过反向操作来恢复原始明文。通常需要知道加密时使用的密钥和算法。

    二、高校教务系统密码加密逻辑分析

    2.1 以山东女子学院为例

    我们可以看到这几个学校的教务系统网页是一样的,可能还有其他学校也在用这个,我这里就不一样列举了,如果,你们学校也是用这个,可以参考我下面介绍的案例,如果可以的话,留下你们学校的名字

    2.2 抓包

    我们首先打开教务系统的登录页面,我们可以看到,有学号和密码,有的高校会有验证码,或者有的高校是错误一次密码,会验证验证码。

    我们打开开发者工具,尝试登录抓包,网页会返回这样的数据接口。

    我们可以看到基本上所有参数都是密文,而且,我们并没有看到用户名和密码的关键词,这里是以表单的形式呈现,所以,接下来,我们就来逆向这个params

    2.3 分析加密参数

    我们接下来,就是来分析这个密码是怎么加密的。我们全局搜索params。定位到加密的位置。

    1. function getEncParams(params) {
    2. var timestamp = _nowtime;
    3. var token = md5(md5(params)+md5(timestamp));
    4. var _params = b64_encode(des_encode(params));
    5. _params = "params=" + _params + "&token="+token+"×tamp="+timestamp;
    6. return _params;
    7. }

    代码简单解释 

    1. 首先,定义了一个变量timestamp,它被设置为当前时间这是为了确保每次调用函数时都有一个独特的时间戳,可以用于检查请求的新鲜度
    2. 然后,定义了一个变量token这个变量是通过将参数(params)和时间戳(timestamp)进行MD5哈希,并将这两个值连接起来后再次进行MD5哈希得到的这样做是为了生成一个唯一的令牌,可以用于验证请求的来源
    3. 之后,定义了一个变量_params,这个变量是通过先对参数进行DES编码,然后再进行Base64编码得到的这样做是为了确保参数的安全性和保密性
    4. 最后,将_paramstokentimestamp以查询参数的形式拼接在一起,并返回这个字符串

    接下来,我们就来写这个params和token是怎么加密的。

    三、JS逆向分析方法

    逆向分析是指从已知的加密文本或程序中还原出原始信息的过程。在本例中,我们将使用JavaScript编写一个简单的逆向分析工具,用于逆向高校教务系统的密码。

    环境使用

    • python 3.9
    • pycharm
    • node

    代码实现

    我们首先定位到params,看看,这个是怎么定义的,上面显示的加密params函数。

    1. username = base64encode(username+";;"+_sessionid);
    2. var params = p_username+"="+username+"&"+p_password+"="+password+"&randnumber="+randnumber+"&isPasswordPolicy="+passwordPolicy+ "&txt_mm_expression="+txt_mm_expression+"&txt_mm_length="+txt_mm_length+"&txt_mm_userzh="+txt_mm_userzh+"&hid_flag="+hid_flag+"&hidlag=1";
    3. params = getEncParams(params)+"&deskey="+_deskey+"&ssessionid="+_ssessionid;

     虽然说都是常规加密,这里,我还是带大家扣代码,首先,我们先把params扣出来。

    1. var randnumber = ''
    2. var p_username = "_u" + randnumber;
    3. var p_password = "_p" + randnumber;
    4. var _sessionid = _ssessionid;
    5. var username = base64encode('12345' + ";;" + _sessionid);
    6. var password = hex_md5(hex_md5('12345') + hex_md5(randnumber.toLowerCase()));
    7. var passwordPolicy = isPasswordPolicy(username, password);
    8. function isPasswordPolicy(username, password) {
    9. if (password == "" || password == null || username == password) {
    10. return "0";
    11. }
    12. var passwordlen = new String(password).length;
    13. if (passwordlen < 6) {
    14. return "0";
    15. }
    16. return "1";
    17. }
    18. var txt_mm_expression = 8;
    19. var txt_mm_length = 4;
    20. var txt_mm_userzh = 1;
    21. var hid_flag = 1;
    22. var params = p_username + "=" + username + "&" + p_password + "=" + password + "&randnumber=" + randnumber + "&isPasswordPolicy=" + passwordPolicy +
    23. "&txt_mm_expression=" + txt_mm_expression + "&txt_mm_length=" + txt_mm_length + "&txt_mm_userzh=" + txt_mm_userzh + "&hid_flag=" + hid_flag + "&hidlag=1";
    24. console.log(params)

     这里就把表单生成了,我们可以看到里面有六个参数,其中:

    • 用户名加密,是用户名和sessionid拼接后,base64加密
    var username = base64encode('12345' + ";;" + _sessionid);
    •  密码加密,显然是md5加密
    var password = hex_md5(hex_md5('12345') + hex_md5(randnumber.toLowerCase()));
    • passwordPolicy加密,这里调用了一个函数
    1. var passwordPolicy = isPasswordPolicy(username, password);
    2. function isPasswordPolicy(username, password) {
    3. if (password == "" || password == null || username == password) {
    4. return "0";
    5. }
    6. var passwordlen = new String(password).length;
    7. if (passwordlen < 6) {
    8. return "0";
    9. }
    10. return "1";
    11. }
    • 其他参数,都是固定值。
    1. var txt_mm_expression = 8;
    2. var txt_mm_length = 4;
    3. var txt_mm_userzh = 1;
    4. var hid_flag = 1;

    我们拿到params后,传给加密函数之后,就可以得到我们想要的内容,不过,这里要注意token加密的时候还有时间加密。

    1. var timestamp = _nowtime;
    2. var token = md5(md5(params) + md5(timestamp));

    所有代码:

    1. var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
    2. var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
    3. var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
    4. var _deskey = '13713169718853137878582';
    5. var _nowtime = '2023-10-13 17:15:31';
    6. var _ssessionid = 'BE85759922B42B2C89CF49C5527C2C35';
    7. var timestamp = _nowtime;
    8. function getEncParams(params) {
    9. var timestamp = _nowtime;
    10. var token = md5(md5(params) + md5(timestamp));
    11. var _params = b64_encode(des_encode(params));
    12. _params = "params=" + _params + "&token=" + token + "×tamp=" + timestamp;
    13. return _params;
    14. }
    15. function b64_encode(data) {
    16. return base64encode(utf16to8(data));
    17. }
    18. function b64_decode(data) {
    19. return utf8to16(base64decode(data));
    20. }
    21. function md5(data) {
    22. return hex_md5(data);
    23. }
    24. function des_encode(data) {
    25. return strEnc(data, _deskey, null, null);
    26. }
    27. function des_decode(data) {
    28. return strDec(data, _deskey, null, null);
    29. }
    30. /**
    31. function des_encode(data, key){
    32. if (typeof key == "undefined" || key == null || key.length == 0) { key = _deskey; }
    33. var result = strEnc(data, key, null, null);
    34. return result ;
    35. }
    36. function des_decode(data, key) {
    37. if (typeof key == "undefined" || key == null || key.length == 0) { key = _deskey; }
    38. return strDec(data, key, null, null);
    39. }
    40. */
    41. /**
    42. * DES加密
    43. * encrypt the string to string made up of hex
    44. * return the encrypted string
    45. */
    46. function strEnc(data, firstKey, secondKey, thirdKey) {
    47. var leng = data.length;
    48. var encData = "";
    49. var firstKeyBt, secondKeyBt, thirdKeyBt, firstLength, secondLength, thirdLength;
    50. if (firstKey != null && firstKey != "") {
    51. firstKeyBt = getKeyBytes(firstKey);
    52. firstLength = firstKeyBt.length;
    53. }
    54. if (secondKey != null && secondKey != "") {
    55. secondKeyBt = getKeyBytes(secondKey);
    56. secondLength = secondKeyBt.length;
    57. }
    58. if (thirdKey != null && thirdKey != "") {
    59. thirdKeyBt = getKeyBytes(thirdKey);
    60. thirdLength = thirdKeyBt.length;
    61. }
    62. if (leng > 0) {
    63. if (leng < 4) {
    64. var bt = strToBt(data);
    65. var encByte;
    66. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
    67. var tempBt;
    68. var x, y, z;
    69. tempBt = bt;
    70. for (x = 0; x < firstLength; x++) {
    71. tempBt = enc(tempBt, firstKeyBt[x]);
    72. }
    73. for (y = 0; y < secondLength; y++) {
    74. tempBt = enc(tempBt, secondKeyBt[y]);
    75. }
    76. for (z = 0; z < thirdLength; z++) {
    77. tempBt = enc(tempBt, thirdKeyBt[z]);
    78. }
    79. encByte = tempBt;
    80. } else {
    81. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
    82. var tempBt;
    83. var x, y;
    84. tempBt = bt;
    85. for (x = 0; x < firstLength; x++) {
    86. tempBt = enc(tempBt, firstKeyBt[x]);
    87. }
    88. for (y = 0; y < secondLength; y++) {
    89. tempBt = enc(tempBt, secondKeyBt[y]);
    90. }
    91. encByte = tempBt;
    92. } else {
    93. if (firstKey != null && firstKey != "") {
    94. var tempBt;
    95. var x = 0;
    96. tempBt = bt;
    97. for (x = 0; x < firstLength; x++) {
    98. tempBt = enc(tempBt, firstKeyBt[x]);
    99. }
    100. encByte = tempBt;
    101. }
    102. }
    103. }
    104. encData = bt64ToHex(encByte);
    105. } else {
    106. var iterator = parseInt(leng / 4);
    107. var remainder = leng % 4;
    108. var i = 0;
    109. for (i = 0; i < iterator; i++) {
    110. var tempData = data.substring(i * 4 + 0, i * 4 + 4);
    111. var tempByte = strToBt(tempData);
    112. var encByte;
    113. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
    114. var tempBt;
    115. var x, y, z;
    116. tempBt = tempByte;
    117. for (x = 0; x < firstLength; x++) {
    118. tempBt = enc(tempBt, firstKeyBt[x]);
    119. }
    120. for (y = 0; y < secondLength; y++) {
    121. tempBt = enc(tempBt, secondKeyBt[y]);
    122. }
    123. for (z = 0; z < thirdLength; z++) {
    124. tempBt = enc(tempBt, thirdKeyBt[z]);
    125. }
    126. encByte = tempBt;
    127. } else {
    128. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
    129. var tempBt;
    130. var x, y;
    131. tempBt = tempByte;
    132. for (x = 0; x < firstLength; x++) {
    133. tempBt = enc(tempBt, firstKeyBt[x]);
    134. }
    135. for (y = 0; y < secondLength; y++) {
    136. tempBt = enc(tempBt, secondKeyBt[y]);
    137. }
    138. encByte = tempBt;
    139. } else {
    140. if (firstKey != null && firstKey != "") {
    141. var tempBt;
    142. var x;
    143. tempBt = tempByte;
    144. for (x = 0; x < firstLength; x++) {
    145. tempBt = enc(tempBt, firstKeyBt[x]);
    146. }
    147. encByte = tempBt;
    148. }
    149. }
    150. }
    151. encData += bt64ToHex(encByte);
    152. }
    153. if (remainder > 0) {
    154. var remainderData = data.substring(iterator * 4 + 0, leng);
    155. var tempByte = strToBt(remainderData);
    156. var encByte;
    157. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
    158. var tempBt;
    159. var x, y, z;
    160. tempBt = tempByte;
    161. for (x = 0; x < firstLength; x++) {
    162. tempBt = enc(tempBt, firstKeyBt[x]);
    163. }
    164. for (y = 0; y < secondLength; y++) {
    165. tempBt = enc(tempBt, secondKeyBt[y]);
    166. }
    167. for (z = 0; z < thirdLength; z++) {
    168. tempBt = enc(tempBt, thirdKeyBt[z]);
    169. }
    170. encByte = tempBt;
    171. } else {
    172. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
    173. var tempBt;
    174. var x, y;
    175. tempBt = tempByte;
    176. for (x = 0; x < firstLength; x++) {
    177. tempBt = enc(tempBt, firstKeyBt[x]);
    178. }
    179. for (y = 0; y < secondLength; y++) {
    180. tempBt = enc(tempBt, secondKeyBt[y]);
    181. }
    182. encByte = tempBt;
    183. } else {
    184. if (firstKey != null && firstKey != "") {
    185. var tempBt;
    186. var x;
    187. tempBt = tempByte;
    188. for (x = 0; x < firstLength; x++) {
    189. tempBt = enc(tempBt, firstKeyBt[x]);
    190. }
    191. encByte = tempBt;
    192. }
    193. }
    194. }
    195. encData += bt64ToHex(encByte);
    196. }
    197. }
    198. }
    199. return encData;
    200. }
    201. /*
    202. * DES解密
    203. * decrypt the encrypted string to the original string
    204. * return the original string
    205. */
    206. function strDec(data, firstKey, secondKey, thirdKey) {
    207. var leng = data.length;
    208. var decStr = "";
    209. var firstKeyBt, secondKeyBt, thirdKeyBt, firstLength, secondLength, thirdLength;
    210. if (firstKey != null && firstKey != "") {
    211. firstKeyBt = getKeyBytes(firstKey);
    212. firstLength = firstKeyBt.length;
    213. }
    214. if (secondKey != null && secondKey != "") {
    215. secondKeyBt = getKeyBytes(secondKey);
    216. secondLength = secondKeyBt.length;
    217. }
    218. if (thirdKey != null && thirdKey != "") {
    219. thirdKeyBt = getKeyBytes(thirdKey);
    220. thirdLength = thirdKeyBt.length;
    221. }
    222. var iterator = parseInt(leng / 16);
    223. var i = 0;
    224. for (i = 0; i < iterator; i++) {
    225. var tempData = data.substring(i * 16 + 0, i * 16 + 16);
    226. var strByte = hexToBt64(tempData);
    227. var intByte = new Array(64);
    228. var j = 0;
    229. for (j = 0; j < 64; j++) {
    230. intByte[j] = parseInt(strByte.substring(j, j + 1));
    231. }
    232. var decByte;
    233. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
    234. var tempBt;
    235. var x, y, z;
    236. tempBt = intByte;
    237. for (x = thirdLength - 1; x >= 0; x--) {
    238. tempBt = dec(tempBt, thirdKeyBt[x]);
    239. }
    240. for (y = secondLength - 1; y >= 0; y--) {
    241. tempBt = dec(tempBt, secondKeyBt[y]);
    242. }
    243. for (z = firstLength - 1; z >= 0; z--) {
    244. tempBt = dec(tempBt, firstKeyBt[z]);
    245. }
    246. decByte = tempBt;
    247. } else {
    248. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
    249. var tempBt;
    250. var x, y, z;
    251. tempBt = intByte;
    252. for (x = secondLength - 1; x >= 0; x--) {
    253. tempBt = dec(tempBt, secondKeyBt[x]);
    254. }
    255. for (y = firstLength - 1; y >= 0; y--) {
    256. tempBt = dec(tempBt, firstKeyBt[y]);
    257. }
    258. decByte = tempBt;
    259. } else {
    260. if (firstKey != null && firstKey != "") {
    261. var tempBt;
    262. var x, y, z;
    263. tempBt = intByte;
    264. for (x = firstLength - 1; x >= 0; x--) {
    265. tempBt = dec(tempBt, firstKeyBt[x]);
    266. }
    267. decByte = tempBt;
    268. }
    269. }
    270. }
    271. decStr += byteToString(decByte);
    272. }
    273. return decStr;
    274. }
    275. /*
    276. * chang the string into the bit array
    277. *
    278. * return bit array(it's length % 64 = 0)
    279. */
    280. function getKeyBytes(key) {
    281. var keyBytes = new Array();
    282. var leng = key.length;
    283. var iterator = parseInt(leng / 4);
    284. var remainder = leng % 4;
    285. var i = 0;
    286. for (i = 0; i < iterator; i++) {
    287. keyBytes[i] = strToBt(key.substring(i * 4 + 0, i * 4 + 4));
    288. }
    289. if (remainder > 0) {
    290. keyBytes[i] = strToBt(key.substring(i * 4 + 0, leng));
    291. }
    292. return keyBytes;
    293. }
    294. function strToBt(str) {
    295. var leng = str.length;
    296. var bt = new Array(64);
    297. if (leng < 4) {
    298. var i = 0, j = 0, p = 0, q = 0;
    299. for (i = 0; i < leng; i++) {
    300. var k = str.charCodeAt(i);
    301. for (j = 0; j < 16; j++) {
    302. var pow = 1, m = 0;
    303. for (m = 15; m > j; m--) {
    304. pow *= 2;
    305. }
    306. bt[16 * i + j] = parseInt(k / pow) % 2;
    307. }
    308. }
    309. for (p = leng; p < 4; p++) {
    310. var k = 0;
    311. for (q = 0; q < 16; q++) {
    312. var pow = 1, m = 0;
    313. for (m = 15; m > q; m--) {
    314. pow *= 2;
    315. }
    316. bt[16 * p + q] = parseInt(k / pow) % 2;
    317. }
    318. }
    319. } else {
    320. for (i = 0; i < 4; i++) {
    321. var k = str.charCodeAt(i);
    322. for (j = 0; j < 16; j++) {
    323. var pow = 1;
    324. for (m = 15; m > j; m--) {
    325. pow *= 2;
    326. }
    327. bt[16 * i + j] = parseInt(k / pow) % 2;
    328. }
    329. }
    330. }
    331. return bt;
    332. }
    333. /*
    334. * chang the bit(it's length = 4) into the hex
    335. *
    336. * return hex
    337. */
    338. function bt4ToHex(binary) {
    339. var hex;
    340. switch (binary) {
    341. case "0000" :
    342. hex = "0";
    343. break;
    344. case "0001" :
    345. hex = "1";
    346. break;
    347. case "0010" :
    348. hex = "2";
    349. break;
    350. case "0011" :
    351. hex = "3";
    352. break;
    353. case "0100" :
    354. hex = "4";
    355. break;
    356. case "0101" :
    357. hex = "5";
    358. break;
    359. case "0110" :
    360. hex = "6";
    361. break;
    362. case "0111" :
    363. hex = "7";
    364. break;
    365. case "1000" :
    366. hex = "8";
    367. break;
    368. case "1001" :
    369. hex = "9";
    370. break;
    371. case "1010" :
    372. hex = "A";
    373. break;
    374. case "1011" :
    375. hex = "B";
    376. break;
    377. case "1100" :
    378. hex = "C";
    379. break;
    380. case "1101" :
    381. hex = "D";
    382. break;
    383. case "1110" :
    384. hex = "E";
    385. break;
    386. case "1111" :
    387. hex = "F";
    388. break;
    389. }
    390. return hex;
    391. }
    392. /*
    393. * chang the hex into the bit(it's length = 4)
    394. *
    395. * return the bit(it's length = 4)
    396. */
    397. function hexToBt4(hex) {
    398. var binary;
    399. switch (hex) {
    400. case "0" :
    401. binary = "0000";
    402. break;
    403. case "1" :
    404. binary = "0001";
    405. break;
    406. case "2" :
    407. binary = "0010";
    408. break;
    409. case "3" :
    410. binary = "0011";
    411. break;
    412. case "4" :
    413. binary = "0100";
    414. break;
    415. case "5" :
    416. binary = "0101";
    417. break;
    418. case "6" :
    419. binary = "0110";
    420. break;
    421. case "7" :
    422. binary = "0111";
    423. break;
    424. case "8" :
    425. binary = "1000";
    426. break;
    427. case "9" :
    428. binary = "1001";
    429. break;
    430. case "A" :
    431. binary = "1010";
    432. break;
    433. case "B" :
    434. binary = "1011";
    435. break;
    436. case "C" :
    437. binary = "1100";
    438. break;
    439. case "D" :
    440. binary = "1101";
    441. break;
    442. case "E" :
    443. binary = "1110";
    444. break;
    445. case "F" :
    446. binary = "1111";
    447. break;
    448. }
    449. return binary;
    450. }
    451. /*
    452. * chang the bit(it's length = 64) into the string
    453. *
    454. * return string
    455. */
    456. function byteToString(byteData) {
    457. var str = "";
    458. for (i = 0; i < 4; i++) {
    459. var count = 0;
    460. for (j = 0; j < 16; j++) {
    461. var pow = 1;
    462. for (m = 15; m > j; m--) {
    463. pow *= 2;
    464. }
    465. count += byteData[16 * i + j] * pow;
    466. }
    467. if (count != 0) {
    468. str += String.fromCharCode(count);
    469. }
    470. }
    471. return str;
    472. }
    473. function bt64ToHex(byteData) {
    474. var hex = "";
    475. for (i = 0; i < 16; i++) {
    476. var bt = "";
    477. for (j = 0; j < 4; j++) {
    478. bt += byteData[i * 4 + j];
    479. }
    480. hex += bt4ToHex(bt);
    481. }
    482. return hex;
    483. }
    484. function hexToBt64(hex) {
    485. var binary = "";
    486. for (i = 0; i < 16; i++) {
    487. binary += hexToBt4(hex.substring(i, i + 1));
    488. }
    489. return binary;
    490. }
    491. /*
    492. * the 64 bit des core arithmetic
    493. */
    494. function enc(dataByte, keyByte) {
    495. var keys = generateKeys(keyByte);
    496. var ipByte = initPermute(dataByte);
    497. var ipLeft = new Array(32);
    498. var ipRight = new Array(32);
    499. var tempLeft = new Array(32);
    500. var i = 0, j = 0, k = 0, m = 0, n = 0;
    501. for (k = 0; k < 32; k++) {
    502. ipLeft[k] = ipByte[k];
    503. ipRight[k] = ipByte[32 + k];
    504. }
    505. for (i = 0; i < 16; i++) {
    506. for (j = 0; j < 32; j++) {
    507. tempLeft[j] = ipLeft[j];
    508. ipLeft[j] = ipRight[j];
    509. }
    510. var key = new Array(48);
    511. for (m = 0; m < 48; m++) {
    512. key[m] = keys[i][m];
    513. }
    514. var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
    515. for (n = 0; n < 32; n++) {
    516. ipRight[n] = tempRight[n];
    517. }
    518. }
    519. var finalData = new Array(64);
    520. for (i = 0; i < 32; i++) {
    521. finalData[i] = ipRight[i];
    522. finalData[32 + i] = ipLeft[i];
    523. }
    524. return finallyPermute(finalData);
    525. }
    526. function dec(dataByte, keyByte) {
    527. var keys = generateKeys(keyByte);
    528. var ipByte = initPermute(dataByte);
    529. var ipLeft = new Array(32);
    530. var ipRight = new Array(32);
    531. var tempLeft = new Array(32);
    532. var i = 0, j = 0, k = 0, m = 0, n = 0;
    533. for (k = 0; k < 32; k++) {
    534. ipLeft[k] = ipByte[k];
    535. ipRight[k] = ipByte[32 + k];
    536. }
    537. for (i = 15; i >= 0; i--) {
    538. for (j = 0; j < 32; j++) {
    539. tempLeft[j] = ipLeft[j];
    540. ipLeft[j] = ipRight[j];
    541. }
    542. var key = new Array(48);
    543. for (m = 0; m < 48; m++) {
    544. key[m] = keys[i][m];
    545. }
    546. var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
    547. for (n = 0; n < 32; n++) {
    548. ipRight[n] = tempRight[n];
    549. }
    550. }
    551. var finalData = new Array(64);
    552. for (i = 0; i < 32; i++) {
    553. finalData[i] = ipRight[i];
    554. finalData[32 + i] = ipLeft[i];
    555. }
    556. return finallyPermute(finalData);
    557. }
    558. function initPermute(originalData) {
    559. var ipByte = new Array(64);
    560. for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
    561. for (j = 7, k = 0; j >= 0; j--, k++) {
    562. ipByte[i * 8 + k] = originalData[j * 8 + m];
    563. ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
    564. }
    565. }
    566. return ipByte;
    567. }
    568. function expandPermute(rightData) {
    569. var epByte = new Array(48);
    570. for (i = 0; i < 8; i++) {
    571. if (i == 0) {
    572. epByte[i * 6 + 0] = rightData[31];
    573. } else {
    574. epByte[i * 6 + 0] = rightData[i * 4 - 1];
    575. }
    576. epByte[i * 6 + 1] = rightData[i * 4 + 0];
    577. epByte[i * 6 + 2] = rightData[i * 4 + 1];
    578. epByte[i * 6 + 3] = rightData[i * 4 + 2];
    579. epByte[i * 6 + 4] = rightData[i * 4 + 3];
    580. if (i == 7) {
    581. epByte[i * 6 + 5] = rightData[0];
    582. } else {
    583. epByte[i * 6 + 5] = rightData[i * 4 + 4];
    584. }
    585. }
    586. return epByte;
    587. }
    588. function xor(byteOne, byteTwo) {
    589. var xorByte = new Array(byteOne.length);
    590. for (i = 0; i < byteOne.length; i++) {
    591. xorByte[i] = byteOne[i] ^ byteTwo[i];
    592. }
    593. return xorByte;
    594. }
    595. function sBoxPermute(expandByte) {
    596. var sBoxByte = new Array(32);
    597. var binary = "";
    598. var s1 = [
    599. [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
    600. [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
    601. [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
    602. [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13]];
    603. /* Table - s2 */
    604. var s2 = [
    605. [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
    606. [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
    607. [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
    608. [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9]];
    609. /* Table - s3 */
    610. var s3 = [
    611. [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
    612. [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
    613. [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
    614. [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12]];
    615. /* Table - s4 */
    616. var s4 = [
    617. [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
    618. [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
    619. [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
    620. [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14]];
    621. /* Table - s5 */
    622. var s5 = [
    623. [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
    624. [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
    625. [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
    626. [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3]];
    627. /* Table - s6 */
    628. var s6 = [
    629. [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
    630. [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
    631. [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
    632. [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13]];
    633. /* Table - s7 */
    634. var s7 = [
    635. [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
    636. [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
    637. [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
    638. [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
    639. /* Table - s8 */
    640. var s8 = [
    641. [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
    642. [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
    643. [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
    644. [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
    645. for (m = 0; m < 8; m++) {
    646. var i = 0, j = 0;
    647. i = expandByte[m * 6 + 0] * 2 + expandByte[m * 6 + 5];
    648. j = expandByte[m * 6 + 1] * 2 * 2 * 2
    649. + expandByte[m * 6 + 2] * 2 * 2
    650. + expandByte[m * 6 + 3] * 2
    651. + expandByte[m * 6 + 4];
    652. switch (m) {
    653. case 0 :
    654. binary = getBoxBinary(s1[i][j]);
    655. break;
    656. case 1 :
    657. binary = getBoxBinary(s2[i][j]);
    658. break;
    659. case 2 :
    660. binary = getBoxBinary(s3[i][j]);
    661. break;
    662. case 3 :
    663. binary = getBoxBinary(s4[i][j]);
    664. break;
    665. case 4 :
    666. binary = getBoxBinary(s5[i][j]);
    667. break;
    668. case 5 :
    669. binary = getBoxBinary(s6[i][j]);
    670. break;
    671. case 6 :
    672. binary = getBoxBinary(s7[i][j]);
    673. break;
    674. case 7 :
    675. binary = getBoxBinary(s8[i][j]);
    676. break;
    677. }
    678. sBoxByte[m * 4 + 0] = parseInt(binary.substring(0, 1));
    679. sBoxByte[m * 4 + 1] = parseInt(binary.substring(1, 2));
    680. sBoxByte[m * 4 + 2] = parseInt(binary.substring(2, 3));
    681. sBoxByte[m * 4 + 3] = parseInt(binary.substring(3, 4));
    682. }
    683. return sBoxByte;
    684. }
    685. function pPermute(sBoxByte) {
    686. var pBoxPermute = new Array(32);
    687. pBoxPermute[0] = sBoxByte[15];
    688. pBoxPermute[1] = sBoxByte[6];
    689. pBoxPermute[2] = sBoxByte[19];
    690. pBoxPermute[3] = sBoxByte[20];
    691. pBoxPermute[4] = sBoxByte[28];
    692. pBoxPermute[5] = sBoxByte[11];
    693. pBoxPermute[6] = sBoxByte[27];
    694. pBoxPermute[7] = sBoxByte[16];
    695. pBoxPermute[8] = sBoxByte[0];
    696. pBoxPermute[9] = sBoxByte[14];
    697. pBoxPermute[10] = sBoxByte[22];
    698. pBoxPermute[11] = sBoxByte[25];
    699. pBoxPermute[12] = sBoxByte[4];
    700. pBoxPermute[13] = sBoxByte[17];
    701. pBoxPermute[14] = sBoxByte[30];
    702. pBoxPermute[15] = sBoxByte[9];
    703. pBoxPermute[16] = sBoxByte[1];
    704. pBoxPermute[17] = sBoxByte[7];
    705. pBoxPermute[18] = sBoxByte[23];
    706. pBoxPermute[19] = sBoxByte[13];
    707. pBoxPermute[20] = sBoxByte[31];
    708. pBoxPermute[21] = sBoxByte[26];
    709. pBoxPermute[22] = sBoxByte[2];
    710. pBoxPermute[23] = sBoxByte[8];
    711. pBoxPermute[24] = sBoxByte[18];
    712. pBoxPermute[25] = sBoxByte[12];
    713. pBoxPermute[26] = sBoxByte[29];
    714. pBoxPermute[27] = sBoxByte[5];
    715. pBoxPermute[28] = sBoxByte[21];
    716. pBoxPermute[29] = sBoxByte[10];
    717. pBoxPermute[30] = sBoxByte[3];
    718. pBoxPermute[31] = sBoxByte[24];
    719. return pBoxPermute;
    720. }
    721. function finallyPermute(endByte) {
    722. var fpByte = new Array(64);
    723. fpByte[0] = endByte[39];
    724. fpByte[1] = endByte[7];
    725. fpByte[2] = endByte[47];
    726. fpByte[3] = endByte[15];
    727. fpByte[4] = endByte[55];
    728. fpByte[5] = endByte[23];
    729. fpByte[6] = endByte[63];
    730. fpByte[7] = endByte[31];
    731. fpByte[8] = endByte[38];
    732. fpByte[9] = endByte[6];
    733. fpByte[10] = endByte[46];
    734. fpByte[11] = endByte[14];
    735. fpByte[12] = endByte[54];
    736. fpByte[13] = endByte[22];
    737. fpByte[14] = endByte[62];
    738. fpByte[15] = endByte[30];
    739. fpByte[16] = endByte[37];
    740. fpByte[17] = endByte[5];
    741. fpByte[18] = endByte[45];
    742. fpByte[19] = endByte[13];
    743. fpByte[20] = endByte[53];
    744. fpByte[21] = endByte[21];
    745. fpByte[22] = endByte[61];
    746. fpByte[23] = endByte[29];
    747. fpByte[24] = endByte[36];
    748. fpByte[25] = endByte[4];
    749. fpByte[26] = endByte[44];
    750. fpByte[27] = endByte[12];
    751. fpByte[28] = endByte[52];
    752. fpByte[29] = endByte[20];
    753. fpByte[30] = endByte[60];
    754. fpByte[31] = endByte[28];
    755. fpByte[32] = endByte[35];
    756. fpByte[33] = endByte[3];
    757. fpByte[34] = endByte[43];
    758. fpByte[35] = endByte[11];
    759. fpByte[36] = endByte[51];
    760. fpByte[37] = endByte[19];
    761. fpByte[38] = endByte[59];
    762. fpByte[39] = endByte[27];
    763. fpByte[40] = endByte[34];
    764. fpByte[41] = endByte[2];
    765. fpByte[42] = endByte[42];
    766. fpByte[43] = endByte[10];
    767. fpByte[44] = endByte[50];
    768. fpByte[45] = endByte[18];
    769. fpByte[46] = endByte[58];
    770. fpByte[47] = endByte[26];
    771. fpByte[48] = endByte[33];
    772. fpByte[49] = endByte[1];
    773. fpByte[50] = endByte[41];
    774. fpByte[51] = endByte[9];
    775. fpByte[52] = endByte[49];
    776. fpByte[53] = endByte[17];
    777. fpByte[54] = endByte[57];
    778. fpByte[55] = endByte[25];
    779. fpByte[56] = endByte[32];
    780. fpByte[57] = endByte[0];
    781. fpByte[58] = endByte[40];
    782. fpByte[59] = endByte[8];
    783. fpByte[60] = endByte[48];
    784. fpByte[61] = endByte[16];
    785. fpByte[62] = endByte[56];
    786. fpByte[63] = endByte[24];
    787. return fpByte;
    788. }
    789. function getBoxBinary(i) {
    790. var binary = "";
    791. switch (i) {
    792. case 0 :
    793. binary = "0000";
    794. break;
    795. case 1 :
    796. binary = "0001";
    797. break;
    798. case 2 :
    799. binary = "0010";
    800. break;
    801. case 3 :
    802. binary = "0011";
    803. break;
    804. case 4 :
    805. binary = "0100";
    806. break;
    807. case 5 :
    808. binary = "0101";
    809. break;
    810. case 6 :
    811. binary = "0110";
    812. break;
    813. case 7 :
    814. binary = "0111";
    815. break;
    816. case 8 :
    817. binary = "1000";
    818. break;
    819. case 9 :
    820. binary = "1001";
    821. break;
    822. case 10 :
    823. binary = "1010";
    824. break;
    825. case 11 :
    826. binary = "1011";
    827. break;
    828. case 12 :
    829. binary = "1100";
    830. break;
    831. case 13 :
    832. binary = "1101";
    833. break;
    834. case 14 :
    835. binary = "1110";
    836. break;
    837. case 15 :
    838. binary = "1111";
    839. break;
    840. }
    841. return binary;
    842. }
    843. /*
    844. * generate 16 keys for xor
    845. *
    846. */
    847. function generateKeys(keyByte) {
    848. var key = new Array(56);
    849. var keys = new Array();
    850. keys[0] = new Array();
    851. keys[1] = new Array();
    852. keys[2] = new Array();
    853. keys[3] = new Array();
    854. keys[4] = new Array();
    855. keys[5] = new Array();
    856. keys[6] = new Array();
    857. keys[7] = new Array();
    858. keys[8] = new Array();
    859. keys[9] = new Array();
    860. keys[10] = new Array();
    861. keys[11] = new Array();
    862. keys[12] = new Array();
    863. keys[13] = new Array();
    864. keys[14] = new Array();
    865. keys[15] = new Array();
    866. var loop = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1];
    867. for (i = 0; i < 7; i++) {
    868. for (j = 0, k = 7; j < 8; j++, k--) {
    869. key[i * 8 + j] = keyByte[8 * k + i];
    870. }
    871. }
    872. var i = 0;
    873. for (i = 0; i < 16; i++) {
    874. var tempLeft = 0;
    875. var tempRight = 0;
    876. for (j = 0; j < loop[i]; j++) {
    877. tempLeft = key[0];
    878. tempRight = key[28];
    879. for (k = 0; k < 27; k++) {
    880. key[k] = key[k + 1];
    881. key[28 + k] = key[29 + k];
    882. }
    883. key[27] = tempLeft;
    884. key[55] = tempRight;
    885. }
    886. var tempKey = new Array(48);
    887. tempKey[0] = key[13];
    888. tempKey[1] = key[16];
    889. tempKey[2] = key[10];
    890. tempKey[3] = key[23];
    891. tempKey[4] = key[0];
    892. tempKey[5] = key[4];
    893. tempKey[6] = key[2];
    894. tempKey[7] = key[27];
    895. tempKey[8] = key[14];
    896. tempKey[9] = key[5];
    897. tempKey[10] = key[20];
    898. tempKey[11] = key[9];
    899. tempKey[12] = key[22];
    900. tempKey[13] = key[18];
    901. tempKey[14] = key[11];
    902. tempKey[15] = key[3];
    903. tempKey[16] = key[25];
    904. tempKey[17] = key[7];
    905. tempKey[18] = key[15];
    906. tempKey[19] = key[6];
    907. tempKey[20] = key[26];
    908. tempKey[21] = key[19];
    909. tempKey[22] = key[12];
    910. tempKey[23] = key[1];
    911. tempKey[24] = key[40];
    912. tempKey[25] = key[51];
    913. tempKey[26] = key[30];
    914. tempKey[27] = key[36];
    915. tempKey[28] = key[46];
    916. tempKey[29] = key[54];
    917. tempKey[30] = key[29];
    918. tempKey[31] = key[39];
    919. tempKey[32] = key[50];
    920. tempKey[33] = key[44];
    921. tempKey[34] = key[32];
    922. tempKey[35] = key[47];
    923. tempKey[36] = key[43];
    924. tempKey[37] = key[48];
    925. tempKey[38] = key[38];
    926. tempKey[39] = key[55];
    927. tempKey[40] = key[33];
    928. tempKey[41] = key[52];
    929. tempKey[42] = key[45];
    930. tempKey[43] = key[41];
    931. tempKey[44] = key[49];
    932. tempKey[45] = key[35];
    933. tempKey[46] = key[28];
    934. tempKey[47] = key[31];
    935. switch (i) {
    936. case 0:
    937. for (m = 0; m < 48; m++) {
    938. keys[0][m] = tempKey[m];
    939. }
    940. break;
    941. case 1:
    942. for (m = 0; m < 48; m++) {
    943. keys[1][m] = tempKey[m];
    944. }
    945. break;
    946. case 2:
    947. for (m = 0; m < 48; m++) {
    948. keys[2][m] = tempKey[m];
    949. }
    950. break;
    951. case 3:
    952. for (m = 0; m < 48; m++) {
    953. keys[3][m] = tempKey[m];
    954. }
    955. break;
    956. case 4:
    957. for (m = 0; m < 48; m++) {
    958. keys[4][m] = tempKey[m];
    959. }
    960. break;
    961. case 5:
    962. for (m = 0; m < 48; m++) {
    963. keys[5][m] = tempKey[m];
    964. }
    965. break;
    966. case 6:
    967. for (m = 0; m < 48; m++) {
    968. keys[6][m] = tempKey[m];
    969. }
    970. break;
    971. case 7:
    972. for (m = 0; m < 48; m++) {
    973. keys[7][m] = tempKey[m];
    974. }
    975. break;
    976. case 8:
    977. for (m = 0; m < 48; m++) {
    978. keys[8][m] = tempKey[m];
    979. }
    980. break;
    981. case 9:
    982. for (m = 0; m < 48; m++) {
    983. keys[9][m] = tempKey[m];
    984. }
    985. break;
    986. case 10:
    987. for (m = 0; m < 48; m++) {
    988. keys[10][m] = tempKey[m];
    989. }
    990. break;
    991. case 11:
    992. for (m = 0; m < 48; m++) {
    993. keys[11][m] = tempKey[m];
    994. }
    995. break;
    996. case 12:
    997. for (m = 0; m < 48; m++) {
    998. keys[12][m] = tempKey[m];
    999. }
    1000. break;
    1001. case 13:
    1002. for (m = 0; m < 48; m++) {
    1003. keys[13][m] = tempKey[m];
    1004. }
    1005. break;
    1006. case 14:
    1007. for (m = 0; m < 48; m++) {
    1008. keys[14][m] = tempKey[m];
    1009. }
    1010. break;
    1011. case 15:
    1012. for (m = 0; m < 48; m++) {
    1013. keys[15][m] = tempKey[m];
    1014. }
    1015. break;
    1016. }
    1017. }
    1018. return keys;
    1019. }
    1020. function utf16to8(str) {
    1021. var out, i, len, c;
    1022. out = "";
    1023. len = str.length;
    1024. for (i = 0; i < len; i++) {
    1025. c = str.charCodeAt(i);
    1026. if ((c >= 0x0001) && (c <= 0x007F)) {
    1027. out += str.charAt(i);
    1028. } else if (c > 0x07FF) {
    1029. out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
    1030. out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
    1031. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
    1032. } else {
    1033. out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
    1034. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
    1035. }
    1036. }
    1037. return out;
    1038. }
    1039. function utf8to16(str) {
    1040. var out, i, len, c;
    1041. var char2, char3;
    1042. out = "";
    1043. len = str.length;
    1044. i = 0;
    1045. while (i < len) {
    1046. c = str.charCodeAt(i++);
    1047. switch (c >> 4) {
    1048. case 0:
    1049. case 1:
    1050. case 2:
    1051. case 3:
    1052. case 4:
    1053. case 5:
    1054. case 6:
    1055. case 7:
    1056. // 0xxxxxxx
    1057. out += str.charAt(i - 1);
    1058. break;
    1059. case 12:
    1060. case 13:
    1061. // 110x xxxx 10xx xxxx
    1062. char2 = str.charCodeAt(i++);
    1063. out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
    1064. break;
    1065. case 14:
    1066. // 1110 xxxx 10xx xxxx 10xx xxxx
    1067. char2 = str.charCodeAt(i++);
    1068. char3 = str.charCodeAt(i++);
    1069. out += String.fromCharCode(((c & 0x0F) << 12) |
    1070. ((char2 & 0x3F) << 6) |
    1071. ((char3 & 0x3F) << 0));
    1072. break;
    1073. }
    1074. }
    1075. return out;
    1076. }
    1077. var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    1078. var base64DecodeChars = new Array(
    1079. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    1080. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    1081. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    1082. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    1083. -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    1084. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    1085. -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    1086. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
    1087. function base64encode(str) {
    1088. var out, i, len;
    1089. var c1, c2, c3;
    1090. len = str.length;
    1091. i = 0;
    1092. out = "";
    1093. while (i < len) {
    1094. c1 = str.charCodeAt(i++) & 0xff;
    1095. if (i == len) {
    1096. out += base64EncodeChars.charAt(c1 >> 2);
    1097. out += base64EncodeChars.charAt((c1 & 0x3) << 4);
    1098. out += "==";
    1099. break;
    1100. }
    1101. c2 = str.charCodeAt(i++);
    1102. if (i == len) {
    1103. out += base64EncodeChars.charAt(c1 >> 2);
    1104. out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
    1105. out += base64EncodeChars.charAt((c2 & 0xF) << 2);
    1106. out += "=";
    1107. break;
    1108. }
    1109. c3 = str.charCodeAt(i++);
    1110. out += base64EncodeChars.charAt(c1 >> 2);
    1111. out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
    1112. out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
    1113. out += base64EncodeChars.charAt(c3 & 0x3F);
    1114. }
    1115. return out;
    1116. }
    1117. function base64decode(str) {
    1118. var c1, c2, c3, c4;
    1119. var i, len, out;
    1120. len = str.length;
    1121. i = 0;
    1122. out = "";
    1123. while (i < len) {
    1124. /* c1 */
    1125. do {
    1126. c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
    1127. } while (i < len && c1 == -1);
    1128. if (c1 == -1)
    1129. break;
    1130. /* c2 */
    1131. do {
    1132. c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
    1133. } while (i < len && c2 == -1);
    1134. if (c2 == -1)
    1135. break;
    1136. out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
    1137. /* c3 */
    1138. do {
    1139. c3 = str.charCodeAt(i++) & 0xff;
    1140. if (c3 == 61)
    1141. return out;
    1142. c3 = base64DecodeChars[c3];
    1143. } while (i < len && c3 == -1);
    1144. if (c3 == -1)
    1145. break;
    1146. out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
    1147. /* c4 */
    1148. do {
    1149. c4 = str.charCodeAt(i++) & 0xff;
    1150. if (c4 == 61)
    1151. return out;
    1152. c4 = base64DecodeChars[c4];
    1153. } while (i < len && c4 == -1);
    1154. if (c4 == -1)
    1155. break;
    1156. out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    1157. }
    1158. return out;
    1159. }
    1160. //js_base64 encode
    1161. function str_encode(str) {
    1162. return base64encode(utf16to8(str));
    1163. }
    1164. //js_base64 decode
    1165. function str_decode(str) {
    1166. return utf8to16(base64decode(str));
    1167. }
    1168. function hex_md5(s) {
    1169. return binl2hex(core_md5(str2binl(s), s.length * chrsz));
    1170. }
    1171. function binl2hex(binarray) {
    1172. var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
    1173. var str = "";
    1174. for (var i = 0; i < binarray.length * 4; i++) {
    1175. str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
    1176. hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
    1177. }
    1178. return str;
    1179. }
    1180. function core_md5(x, len) {
    1181. /* append padding */
    1182. x[len >> 5] |= 0x80 << ((len) % 32);
    1183. x[(((len + 64) >>> 9) << 4) + 14] = len;
    1184. var a = 1732584193;
    1185. var b = -271733879;
    1186. var c = -1732584194;
    1187. var d = 271733878;
    1188. for (var i = 0; i < x.length; i += 16) {
    1189. var olda = a;
    1190. var oldb = b;
    1191. var oldc = c;
    1192. var oldd = d;
    1193. a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
    1194. d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
    1195. c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
    1196. b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
    1197. a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
    1198. d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
    1199. c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
    1200. b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
    1201. a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
    1202. d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
    1203. c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
    1204. b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
    1205. a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
    1206. d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
    1207. c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
    1208. b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
    1209. a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
    1210. d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
    1211. c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
    1212. b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
    1213. a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
    1214. d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
    1215. c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
    1216. b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
    1217. a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
    1218. d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
    1219. c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
    1220. b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
    1221. a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
    1222. d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
    1223. c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
    1224. b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
    1225. a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
    1226. d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
    1227. c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
    1228. b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
    1229. a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
    1230. d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
    1231. c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
    1232. b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
    1233. a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
    1234. d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
    1235. c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
    1236. b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
    1237. a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
    1238. d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
    1239. c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
    1240. b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
    1241. a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
    1242. d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
    1243. c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
    1244. b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
    1245. a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
    1246. d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
    1247. c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
    1248. b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
    1249. a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
    1250. d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
    1251. c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
    1252. b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
    1253. a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
    1254. d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
    1255. c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
    1256. b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
    1257. a = safe_add(a, olda);
    1258. b = safe_add(b, oldb);
    1259. c = safe_add(c, oldc);
    1260. d = safe_add(d, oldd);
    1261. }
    1262. return Array(a, b, c, d);
    1263. }
    1264. function str2binl(str) {
    1265. var bin = Array();
    1266. var mask = (1 << chrsz) - 1;
    1267. for (var i = 0; i < str.length * chrsz; i += chrsz)
    1268. bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
    1269. return bin;
    1270. }
    1271. function md5_cmn(q, a, b, x, s, t) {
    1272. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
    1273. }
    1274. function md5_ff(a, b, c, d, x, s, t) {
    1275. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
    1276. }
    1277. function md5_gg(a, b, c, d, x, s, t) {
    1278. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
    1279. }
    1280. function md5_hh(a, b, c, d, x, s, t) {
    1281. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
    1282. }
    1283. function md5_ii(a, b, c, d, x, s, t) {
    1284. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
    1285. }
    1286. function safe_add(x, y) {
    1287. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
    1288. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
    1289. return (msw << 16) | (lsw & 0xFFFF);
    1290. }
    1291. function bit_rol(num, cnt) {
    1292. return (num << cnt) | (num >>> (32 - cnt));
    1293. }
    1294. var randnumber = ''
    1295. var p_username = "_u" + randnumber;
    1296. var p_password = "_p" + randnumber;
    1297. var _sessionid = _ssessionid;
    1298. var username = base64encode('12345' + ";;" + _sessionid);
    1299. var password = hex_md5(hex_md5('12345') + hex_md5(randnumber.toLowerCase()));
    1300. var passwordPolicy = isPasswordPolicy(username, password);
    1301. function isPasswordPolicy(username, password) {
    1302. if (password == "" || password == null || username == password) {
    1303. return "0";
    1304. }
    1305. var passwordlen = new String(password).length;
    1306. if (passwordlen < 6) {
    1307. return "0";
    1308. }
    1309. return "1";
    1310. }
    1311. var txt_mm_expression = 8;
    1312. var txt_mm_length = 4;
    1313. var txt_mm_userzh = 1;
    1314. var hid_flag = 1;
    1315. var params = p_username + "=" + username + "&" + p_password + "=" + password + "&randnumber=" + randnumber + "&isPasswordPolicy=" + passwordPolicy +
    1316. "&txt_mm_expression=" + txt_mm_expression + "&txt_mm_length=" + txt_mm_length + "&txt_mm_userzh=" + txt_mm_userzh + "&hid_flag=" + hid_flag + "&hidlag=1";
    1317. console.log(getEncParams(params))

    效果展示

    我们可以看到我们成功逆向这个加密参数。

    1. NjRGREZCQURBQTRDREQ5NUE1QUY2MDIwMEVERjA1RThEMkU3NTJFNTE1ODVCNUU4MjYzMEYzQURENTBDOEVFMjhBMjRGOTU1REY4MTNENDA4Mzc4MUUxQ0FEMzYxOUVDMzU1RjU5MzBENUUxNEI5MT
    2. JFRDQ1QTAyNEFBRUY3QkFGNkIwMEZGODA2N0M2QzJERkU1MjM5OTc2RjNCMDAxQzgyRDg5NEQwMkE4N0IwNURDMTBFQTJCOURGN0NDM0NEMzMzNDU1RjhBNjE2ODgwOTk2QkQwMEMyQzQzQ0JEQjE5RjhGMkU
    3. 5QThDNkI0MTk4NzNEQzc0RTk3ODIyRENFOENEMkNEQTA3QzczMDIyRUZEM0IzQjdGQjEzNEZGQ0MwQ0U5ODg4M0UyMkYyNkM4RjkyQTYxNUI0RDk3MTcyRUZGMzYxQ0MyQjBFMjQyNzhCRkMzMEYzNkE1NzA2
    4. RTE1ODlGNzhCNzQ4MkM2RkE4NTg5QTZFODY5MURFRTNBNjVCNTVFMjY2Njc5QUUyRjI0NUNGMkMyRDU3QzEzRjU4MEZBRkM1QUNFMzdCMTYzNDU2N0U1NEVFMzdFNkMwNTZBMUM1RTNEM0IxMDQyMUIzMEMyO
    5. TRCNEE2QjlBNThFOTVEODUzOUIyMDc2RkIwQkVFNjU4Q0QzN0Q2RDdERDM0OUVCQjMwMDM2Nzc5MDJDRDcwRjZDMTk0QjY4NTYzNEU3MzM1MEI2RTNFOUNGQkE0M0ExODJDODg4NjUyODZEOTI5NThDRDM3RD
    6. ZEN0REMzQ5RTRERTk4RUI3RTAzNkM4MEJERjU1MUE2RkUyNTEyMUFFM0JBRjlENEU4NzUyRjc3NjU4Q0QzN0Q2RDdERDM0OUUwQkIzRjcxOTZEM0Y3QTgyMkVGNzQ1OEVGNzlDODNEQTcwNzVFRTIzQzM1NzB
    7. DMTE5OTJBMjY3QUUwRTI3QjQwQjMyRjRCQkI2OEMyREVFQTQxMjNBOTc2NERFOUIzODEzMzNGNzQxOTQxOENGNTA0NzI4NzdDOUY2RUMwRTIyOQ==

    四、总结

    本文介绍了高校教务系统的密码加密逻辑以及使用JavaScript进行逆向分析的方法。通过学习这些知识,你可以更好地理解密码加密技术的原理,并掌握一定的逆向分析技巧。请注意,逆向分析可能涉及到法律问题,请在合法范围内进行研究和实践。

    五、累计更新

    争取到到底早日更新30所高校,大家可以在评论区留言。

    往期作品可以查看专栏👇👇👇

    全国高校教务系统登录页面JS分析_爱吃饼干的小白鼠的博客-CSDN博客

    6adf31c8c5dd4e6a83314f4805b30bc1.jpg

  • 相关阅读:
    数据结构--二叉树遍历
    MATLAB中的符号计算是什么?如何使用它?
    Linux环境下C++ 接入OpenSSL
    堆块的重叠
    【推送服务】【FAQ】Push Ki常见咨询合集7--其它问题
    类和对象8:数值方法
    Python的pytest框架(6)--测试钩子 (hooks)
    注意分号 ; 的在语法节奏感
    Linux基础 - Web服务基础
    Linux环境MySQL数据库主从复制保姆级教程
  • 原文地址:https://blog.csdn.net/BROKEN__Y/article/details/133815114