当前位置:   article > 正文

JS逆向爬虫(一)_nodejs逆向实现爬虫

nodejs逆向实现爬虫

目录

需要做的事情

一、安装与配置文档

1、node.js安装与配置

2、VSCode安装

3、在VSCode中运行

二、JS常用算法

1、md5 线性散列算法

 2、DES/AES对称加密算法

3、RSA 非对称加密算法

4、base64 伪加密算法

三、js逆向案例

1、有道笔记翻译(MD5)

 进行js代码调试的流程

 2、微信公众平台登录(MD5)

3、模拟凡客登录(MD5)

4、房天下( RSA)

5、模拟闪职登陆-RSA加密


需要做的事情

  • 找到加密的字段
  • 借助加密字段找到客户端(浏览器端)进行加密的代码(js调试,找到加密的位置)
  • 运行加密代码(找到加密代码之后,要通过python执行js代码)
  • 最后把加密之后的密码和其他参数一起提交到服务器(通过python代码实现)

一、安装与配置文档

1、node.js安装与配置

win10安装nodejs及配置cnpm详细教程_秋枫萧竹的博客-CSDN博客_nodejs配置cnpm一、安装环境二、开始安装三、验证安装四、修改全局模块下载路径(可选)五、更换npm源为淘宝镜像六、全局安装基于淘宝源的cnpm总结https://blog.csdn.net/qq_44697728/article/details/114276438?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-6.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-

2、VSCode安装

VsCode下载与安装https://www.cnblogs.com/csji/p/13558221.html

3、在VSCode中运行

注意:

vscode不会自动默认保存(执行)修改之后的代码

如果需要自动保存->settings->把off改成onFocusChange

注如何无法运行js程序,安装code Runner插件即可

安装一个模块:

pip install PyExecJs -i https://pypi.douban.com/simple

另外:

        在运行npm install express -g 这一步的时候,一定要用管理员运行cmd才能安装成功。

        这里还要注意一个地方,我碰到的情况是,在安装完node.js等一系列软件之后,execjs执行js报错 TypeError: 'console' 未定义,需要重新启动一下pycharm.

二、JS常用算法

1、md5 线性散列算法

为了提高密码的安全性,一般会在密码后面追加一个盐(如:时间戳)。

MD5是一种被广泛使用的线性散列算法,可以产出一个128位(16字节)的散列值(hash value),用于确保信息传输完整的一致性。且MD5加密之后产生的是一个固定长度(32位或16位)数据

https://cdn.bootcdn.net/ajax/libs/blueimp-md5/1.0.1/js/md5.js

 2、DES/AES对称加密算法

1、DES对称加密,是一种比较传统的加密方式,其加密运算、解密运算使用的是同样的密钥,信息的发送者和信息的接收者在进行信息的传输与处理时,必须共同持有该密钥(称为对称密码),是一种对称加密算法

2、AES和DES的区别加密后密文长度不同:

        DES加密后密文长度是8的整数倍,AES加密后密文的长度是16的整数倍

3、安全度不同

         一般情况下DES足够安全,如果要求高可以使用AES,DES和AES切换只需要修改CryptoJS.DES =>CryptoJS.AES

3、RSA 非对称加密算法

RSA加密算法是一种非对称加密算法。在公开密钥加密和电子商业中RSA被广泛使用。

非对称加密需要2个密钥

  • 公开密钥(publickey:公钥)
  • 私有密钥(privatekey:私钥)
  • 公钥和私钥是一对

base64加密算法

base64是一种用64个字符来表示任意二进制数据的方法。

base64使用 A--Z a--z 0--9 + / 这64个字符实现对数据的加密

4、base64 伪加密算法

三、js逆向案例

1、有道笔记翻译(MD5)

总结:

1、通过加密码字段salt、sign额lts

2、通过加密字段定位到相关js代码 调试代码

3、通过python执行js代码(使用python执行之前,需要确保js代码是正确的)

4、携带参数发送请求

 进行js代码调试的流程

调试工具:灰色箭头是执行当前的下一条语句 蓝色三角形是跳到下一个断点处
1、确定加密字段
2、利用某个加密字段搜索:开发工具右上角有三个点-》选择search-》搜索
     点击搜索结果里面-》点击左下角的花括号进行格式化处理
     在当前文件里面用鼠标进行聚焦-》再次搜索加密字段
     找到可疑的加密字段打上断点进行调试
     借助花括号下面的下划线找到函数开始和结束的位置

 2、微信公众平台登录(MD5)

通过查看请求调用栈,找到加密代码

- 抓包 确定加密字段

- 定位到加密的大致位置

- 打断点分析 确定加密的具体位置

- 拷贝js加密部分的代码 进行调试(vscode中进行的)

- 调试到js代码没有问题使用python执行js代码生成加密字段

  • python代码
  1. import requests
  2. import execjs
  3. from fake_useragent import UserAgent
  4. def get_js(file_name,fun_name,fun_args = None):
  5. with open(file_name,'r',encoding='utf-8') as file:
  6. js_code = file.read()
  7. csj = execjs.compile(js_code)
  8. return csj.call(fun_name,fun_args)
  9. if __name__ == '__main__':
  10. username = '82232778@qq.com'
  11. password = 'aimama412304'
  12. data_dict = {}
  13. pwd = get_js('wechat.js','md5',password)
  14. data_dict['username'] = username
  15. data_dict['pwd'] = pwd
  16. data_dict['imgcode'] = ''
  17. data_dict['f'] = 'json'
  18. data_dict['userlang'] = 'zh_CN'
  19. data_dict['redirect_url'] = ''
  20. data_dict['token'] = ''
  21. data_dict['lang'] = 'zh_CN'
  22. data_dict['ajax'] = 1
  23. header = {
  24. 'cookie':'pgv_pvid=1606564294054066; RK=zOsAcrfhEZ; ptcz=4e31d0f9f461559f799a55923c2b76a83682e517c6552accf56b80830b89bea9; tvfe_boss_uuid=ed5f7109bdc6d8a5; ua_id=HK1ZbbA8NMNWqflhAAAAAMF02MKxhr1S7oOE1LMNtl8=; wxuin=65975220034367; mm_lang=zh_CN; logTrackKey=5cf4b4dc3ac54f0a83b521b0ab609c2b; o_cookie=824104778; _clck=3508202292|1|f6a|0; ts_uid=5328249324; _hjSessionUser_2765497=eyJpZCI6IjU1ZjgwMzIzLWE1YjQtNTM2ZS1iNDY1LWEyZTBiZTJmMWVjOSIsImNyZWF0ZWQiOjE2NjgwNDk3MTA2NDEsImV4aXN0aW5nIjpmYWxzZX0=; _ga=GA1.2.2108284859.1668049711; pac_uid=1_824104778; iip=0; _hp2_id.1405110977=%7B%22userId%22%3A%227829766777300571%22%2C%22pageviewId%22%3A%221289756376712607%22%2C%22sessionId%22%3A%22395270926496724%22%2C%22identity%22%3Anull%2C%22trackerVersion%22%3A%224.0%22%7D; xid=dacc3c34f2ed5e218861b31766e20b5c; cert=UHdf106vaBuswqlrmUZp9zHUuvEkc93n; uuid=517ae204db37da5cfd4232e25c93dcf7',
  25. 'Referer': 'https://mp.weixin.qq.com/',
  26. 'User-Agent': UserAgent().random
  27. }
  28. url = 'https://mp.weixin.qq.com/cgi-bin/bizlogin?action=startlogin'
  29. result = requests.post(url, data=data_dict, headers=header)
  30. print(result.json())
  • js代码
  1. function l(e, t) {
  2. var n = (65535 & e) + (65535 & t);
  3. return (e >> 16) + (t >> 16) + (n >> 16) << 16 | 65535 & n
  4. }
  5. function a(e, t, n, o, r, i) {
  6. return l((t = l(l(t, e), l(o, i))) << r | t >>> 32 - r, n)
  7. }
  8. function p(e, t, n, o, r, i, s) {
  9. return a(t & n | ~t & o, e, t, r, i, s)
  10. }
  11. function f(e, t, n, o, r, i, s) {
  12. return a(t & o | n & ~o, e, t, r, i, s)
  13. }
  14. function m(e, t, n, o, r, i, s) {
  15. return a(t ^ n ^ o, e, t, r, i, s)
  16. }
  17. function g(e, t, n, o, r, i, s) {
  18. return a(n ^ (t | ~o), e, t, r, i, s)
  19. }
  20. function s(e, t) {
  21. e[t >> 5] |= 128 << t % 32,
  22. e[14 + (t + 64 >>> 9 << 4)] = t;
  23. for (var n, o, r, d, i = 1732584193, s = -271733879, a = -1732584194, c = 271733878, u = 0; u < e.length; u += 16)
  24. i = p(n = i, o = s, r = a, d = c, e[u], 7, -680876936),
  25. c = p(c, i, s, a, e[u + 1], 12, -389564586),
  26. a = p(a, c, i, s, e[u + 2], 17, 606105819),
  27. s = p(s, a, c, i, e[u + 3], 22, -1044525330),
  28. i = p(i, s, a, c, e[u + 4], 7, -176418897),
  29. c = p(c, i, s, a, e[u + 5], 12, 1200080426),
  30. a = p(a, c, i, s, e[u + 6], 17, -1473231341),
  31. s = p(s, a, c, i, e[u + 7], 22, -45705983),
  32. i = p(i, s, a, c, e[u + 8], 7, 1770035416),
  33. c = p(c, i, s, a, e[u + 9], 12, -1958414417),
  34. a = p(a, c, i, s, e[u + 10], 17, -42063),
  35. s = p(s, a, c, i, e[u + 11], 22, -1990404162),
  36. i = p(i, s, a, c, e[u + 12], 7, 1804603682),
  37. c = p(c, i, s, a, e[u + 13], 12, -40341101),
  38. a = p(a, c, i, s, e[u + 14], 17, -1502002290),
  39. i = f(i, s = p(s, a, c, i, e[u + 15], 22, 1236535329), a, c, e[u + 1], 5, -165796510),
  40. c = f(c, i, s, a, e[u + 6], 9, -1069501632),
  41. a = f(a, c, i, s, e[u + 11], 14, 643717713),
  42. s = f(s, a, c, i, e[u], 20, -373897302),
  43. i = f(i, s, a, c, e[u + 5], 5, -701558691),
  44. c = f(c, i, s, a, e[u + 10], 9, 38016083),
  45. a = f(a, c, i, s, e[u + 15], 14, -660478335),
  46. s = f(s, a, c, i, e[u + 4], 20, -405537848),
  47. i = f(i, s, a, c, e[u + 9], 5, 568446438),
  48. c = f(c, i, s, a, e[u + 14], 9, -1019803690),
  49. a = f(a, c, i, s, e[u + 3], 14, -187363961),
  50. s = f(s, a, c, i, e[u + 8], 20, 1163531501),
  51. i = f(i, s, a, c, e[u + 13], 5, -1444681467),
  52. c = f(c, i, s, a, e[u + 2], 9, -51403784),
  53. a = f(a, c, i, s, e[u + 7], 14, 1735328473),
  54. i = m(i, s = f(s, a, c, i, e[u + 12], 20, -1926607734), a, c, e[u + 5], 4, -378558),
  55. c = m(c, i, s, a, e[u + 8], 11, -2022574463),
  56. a = m(a, c, i, s, e[u + 11], 16, 1839030562),
  57. s = m(s, a, c, i, e[u + 14], 23, -35309556),
  58. i = m(i, s, a, c, e[u + 1], 4, -1530992060),
  59. c = m(c, i, s, a, e[u + 4], 11, 1272893353),
  60. a = m(a, c, i, s, e[u + 7], 16, -155497632),
  61. s = m(s, a, c, i, e[u + 10], 23, -1094730640),
  62. i = m(i, s, a, c, e[u + 13], 4, 681279174),
  63. c = m(c, i, s, a, e[u], 11, -358537222),
  64. a = m(a, c, i, s, e[u + 3], 16, -722521979),
  65. s = m(s, a, c, i, e[u + 6], 23, 76029189),
  66. i = m(i, s, a, c, e[u + 9], 4, -640364487),
  67. c = m(c, i, s, a, e[u + 12], 11, -421815835),
  68. a = m(a, c, i, s, e[u + 15], 16, 530742520),
  69. i = g(i, s = m(s, a, c, i, e[u + 2], 23, -995338651), a, c, e[u], 6, -198630844),
  70. c = g(c, i, s, a, e[u + 7], 10, 1126891415),
  71. a = g(a, c, i, s, e[u + 14], 15, -1416354905),
  72. s = g(s, a, c, i, e[u + 5], 21, -57434055),
  73. i = g(i, s, a, c, e[u + 12], 6, 1700485571),
  74. c = g(c, i, s, a, e[u + 3], 10, -1894986606),
  75. a = g(a, c, i, s, e[u + 10], 15, -1051523),
  76. s = g(s, a, c, i, e[u + 1], 21, -2054922799),
  77. i = g(i, s, a, c, e[u + 8], 6, 1873313359),
  78. c = g(c, i, s, a, e[u + 15], 10, -30611744),
  79. a = g(a, c, i, s, e[u + 6], 15, -1560198380),
  80. s = g(s, a, c, i, e[u + 13], 21, 1309151649),
  81. i = g(i, s, a, c, e[u + 4], 6, -145523070),
  82. c = g(c, i, s, a, e[u + 11], 10, -1120210379),
  83. a = g(a, c, i, s, e[u + 2], 15, 718787259),
  84. s = g(s, a, c, i, e[u + 9], 21, -343485551),
  85. i = l(i, n),
  86. s = l(s, o),
  87. a = l(a, r),
  88. c = l(c, d);
  89. return [i, s, a, c]
  90. }
  91. function c(e) {
  92. for (var t = "", n = 0; n < 32 * e.length; n += 8)
  93. t += String.fromCharCode(e[n >> 5] >>> n % 32 & 255);
  94. return t
  95. }
  96. function u(e) {
  97. var t, n = [];
  98. for (n[(e.length >> 2) - 1] = void 0,
  99. t = 0; t < n.length; t += 1)
  100. n[t] = 0;
  101. for (t = 0; t < 8 * e.length; t += 8)
  102. n[t >> 5] |= (255 & e.charCodeAt(t / 8)) << t % 32;
  103. return n
  104. }
  105. function o(e) {
  106. for (var t, n = "0123456789abcdef", o = "", r = 0; r < e.length; r += 1)
  107. t = e.charCodeAt(r),
  108. o += n.charAt(t >>> 4 & 15) + n.charAt(15 & t);
  109. return o
  110. }
  111. function d(e) {
  112. return unescape(encodeURIComponent(e))
  113. }
  114. function r(e) {
  115. return c(s(u(e = d(e)), 8 * e.length))
  116. }
  117. function i(e, t) {
  118. var n, e = d(e), t = d(t), o = u(e), r = [], i = [];
  119. for (r[15] = i[15] = void 0,
  120. 16 < o.length && (o = s(o, 8 * e.length)),
  121. n = 0; n < 16; n += 1)
  122. r[n] = 909522486 ^ o[n],
  123. i[n] = 1549556828 ^ o[n];
  124. return e = s(r.concat(u(t)), 512 + 8 * t.length),
  125. c(s(i.concat(e), 640))
  126. }
  127. // e 为原始密码
  128. function md5(e,t,n) {
  129. return t ? n ? i(t, e) : o(i(t, e)) : n ? r(e) : o(r(e))
  130. }

3、模拟凡客登录(MD5)

  • python代码
  1. import requests
  2. import execjs
  3. from fake_useragent import UserAgent
  4. url = 'https://i.fkw.com/ajax/login_h.jsp?dogSrc=3'
  5. headers = {
  6. 'User-Agent':UserAgent().random,
  7. 'Cookie':'_faiHeDistictId=18443f9af272e3c2; _cliid=AqLXwGi1sFotrNYL; loginComeForm=fkjz; first_ta=3; _ta=3; _tp=-; _newUnion=0; _kw=0; _vid_url=https%3A%2F%2Fi.fkw.com%2F%3F_ta%3D3; _s_pro=i.fkw.com%2F; _c_pro=i.fkw.com%2F; reg_sid=0; wxRegBiz=none; _FSESSIONID=; loginSign=',
  8. 'Referer':'https://i.fkw.com/?_ta=3'
  9. }
  10. def get_js(file_name,fun_name,fun_args):
  11. # 1、读取js文件
  12. with open(file_name, 'r', encoding='utf-8') as file_obj:
  13. js_code = file_obj.read()
  14. # 2、编译js文件
  15. cjs = execjs.compile(js_code)
  16. # 3、 执行js代码
  17. return cjs.call(fun_name, fun_args)
  18. password = '123456'
  19. data = {
  20. "cacct": "18735109041",
  21. "pwd": get_js('./fanke.js','md5',password),
  22. "autoLogin": "false",
  23. "staffLogin": "false",
  24. "bizType": 5,
  25. "dogId": 0,
  26. "fromsite":"false",
  27. "cmd": "loginCorpNews",
  28. "vc_type": 2,
  29. "checkSign": "AgpMTDZKZzhjNHZCCg8xODMuMTI4LjIyMi4xNjAQARoGMTY1MTM3",
  30. "fallbacked":"false",
  31. }
  32. response = requests.post(url,headers=headers,data=data)
  33. print(response.json())
  • js代码
  1. function o(u, z) {
  2. var w = (u & 65535) + (z & 65535)
  3. , v = (u >> 16) + (z >> 16) + (w >> 16);
  4. return (v << 16) | (w & 65535)
  5. }
  6. function s(u, v) {
  7. return (u << v) | (u >>> (32 - v))
  8. }
  9. function c(A, w, v, u, z, y) {
  10. return o(s(o(o(w, A), o(u, y)), z), v)
  11. }
  12. function b(w, v, B, A, u, z, y) {
  13. return c((v & B) | ((~v) & A), w, v, u, z, y)
  14. }
  15. function i(w, v, B, A, u, z, y) {
  16. return c((v & A) | (B & (~A)), w, v, u, z, y)
  17. }
  18. function n(w, v, B, A, u, z, y) {
  19. return c(v ^ B ^ A, w, v, u, z, y)
  20. }
  21. function a(w, v, B, A, u, z, y) {
  22. return c(B ^ (v | (~A)), w, v, u, z, y)
  23. }
  24. function d(F, A) {
  25. F[A >> 5] |= 128 << ((A) % 32);
  26. F[(((A + 64) >>> 9) << 4) + 14] = A;
  27. var w, z, y, v, u, E = 1732584193, D = -271733879, C = -1732584194, B = 271733878;
  28. for (w = 0; w < F.length; w += 16) {
  29. z = E;
  30. y = D;
  31. v = C;
  32. u = B;
  33. E = b(E, D, C, B, F[w], 7, -680876936);
  34. B = b(B, E, D, C, F[w + 1], 12, -389564586);
  35. C = b(C, B, E, D, F[w + 2], 17, 606105819);
  36. D = b(D, C, B, E, F[w + 3], 22, -1044525330);
  37. E = b(E, D, C, B, F[w + 4], 7, -176418897);
  38. B = b(B, E, D, C, F[w + 5], 12, 1200080426);
  39. C = b(C, B, E, D, F[w + 6], 17, -1473231341);
  40. D = b(D, C, B, E, F[w + 7], 22, -45705983);
  41. E = b(E, D, C, B, F[w + 8], 7, 1770035416);
  42. B = b(B, E, D, C, F[w + 9], 12, -1958414417);
  43. C = b(C, B, E, D, F[w + 10], 17, -42063);
  44. D = b(D, C, B, E, F[w + 11], 22, -1990404162);
  45. E = b(E, D, C, B, F[w + 12], 7, 1804603682);
  46. B = b(B, E, D, C, F[w + 13], 12, -40341101);
  47. C = b(C, B, E, D, F[w + 14], 17, -1502002290);
  48. D = b(D, C, B, E, F[w + 15], 22, 1236535329);
  49. E = i(E, D, C, B, F[w + 1], 5, -165796510);
  50. B = i(B, E, D, C, F[w + 6], 9, -1069501632);
  51. C = i(C, B, E, D, F[w + 11], 14, 643717713);
  52. D = i(D, C, B, E, F[w], 20, -373897302);
  53. E = i(E, D, C, B, F[w + 5], 5, -701558691);
  54. B = i(B, E, D, C, F[w + 10], 9, 38016083);
  55. C = i(C, B, E, D, F[w + 15], 14, -660478335);
  56. D = i(D, C, B, E, F[w + 4], 20, -405537848);
  57. E = i(E, D, C, B, F[w + 9], 5, 568446438);
  58. B = i(B, E, D, C, F[w + 14], 9, -1019803690);
  59. C = i(C, B, E, D, F[w + 3], 14, -187363961);
  60. D = i(D, C, B, E, F[w + 8], 20, 1163531501);
  61. E = i(E, D, C, B, F[w + 13], 5, -1444681467);
  62. B = i(B, E, D, C, F[w + 2], 9, -51403784);
  63. C = i(C, B, E, D, F[w + 7], 14, 1735328473);
  64. D = i(D, C, B, E, F[w + 12], 20, -1926607734);
  65. E = n(E, D, C, B, F[w + 5], 4, -378558);
  66. B = n(B, E, D, C, F[w + 8], 11, -2022574463);
  67. C = n(C, B, E, D, F[w + 11], 16, 1839030562);
  68. D = n(D, C, B, E, F[w + 14], 23, -35309556);
  69. E = n(E, D, C, B, F[w + 1], 4, -1530992060);
  70. B = n(B, E, D, C, F[w + 4], 11, 1272893353);
  71. C = n(C, B, E, D, F[w + 7], 16, -155497632);
  72. D = n(D, C, B, E, F[w + 10], 23, -1094730640);
  73. E = n(E, D, C, B, F[w + 13], 4, 681279174);
  74. B = n(B, E, D, C, F[w], 11, -358537222);
  75. C = n(C, B, E, D, F[w + 3], 16, -722521979);
  76. D = n(D, C, B, E, F[w + 6], 23, 76029189);
  77. E = n(E, D, C, B, F[w + 9], 4, -640364487);
  78. B = n(B, E, D, C, F[w + 12], 11, -421815835);
  79. C = n(C, B, E, D, F[w + 15], 16, 530742520);
  80. D = n(D, C, B, E, F[w + 2], 23, -995338651);
  81. E = a(E, D, C, B, F[w], 6, -198630844);
  82. B = a(B, E, D, C, F[w + 7], 10, 1126891415);
  83. C = a(C, B, E, D, F[w + 14], 15, -1416354905);
  84. D = a(D, C, B, E, F[w + 5], 21, -57434055);
  85. E = a(E, D, C, B, F[w + 12], 6, 1700485571);
  86. B = a(B, E, D, C, F[w + 3], 10, -1894986606);
  87. C = a(C, B, E, D, F[w + 10], 15, -1051523);
  88. D = a(D, C, B, E, F[w + 1], 21, -2054922799);
  89. E = a(E, D, C, B, F[w + 8], 6, 1873313359);
  90. B = a(B, E, D, C, F[w + 15], 10, -30611744);
  91. C = a(C, B, E, D, F[w + 6], 15, -1560198380);
  92. D = a(D, C, B, E, F[w + 13], 21, 1309151649);
  93. E = a(E, D, C, B, F[w + 4], 6, -145523070);
  94. B = a(B, E, D, C, F[w + 11], 10, -1120210379);
  95. C = a(C, B, E, D, F[w + 2], 15, 718787259);
  96. D = a(D, C, B, E, F[w + 9], 21, -343485551);
  97. E = o(E, z);
  98. D = o(D, y);
  99. C = o(C, v);
  100. B = o(B, u)
  101. }
  102. return [E, D, C, B]
  103. }
  104. function p(v) {
  105. var w, u = "";
  106. for (w = 0; w < v.length * 32; w += 8) {
  107. u += String.fromCharCode((v[w >> 5] >>> (w % 32)) & 255)
  108. }
  109. return u
  110. }
  111. function j(v) {
  112. var w, u = [];
  113. u[(v.length >> 2) - 1] = undefined;
  114. for (w = 0; w < u.length; w += 1) {
  115. u[w] = 0
  116. }
  117. for (w = 0; w < v.length * 8; w += 8) {
  118. u[w >> 5] |= (v.charCodeAt(w / 8) & 255) << (w % 32)
  119. }
  120. return u
  121. }
  122. function k(u) {
  123. return p(d(j(u), u.length * 8))
  124. }
  125. function f(w, z) {
  126. var v, y = j(w), u = [], x = [], A;
  127. u[15] = x[15] = undefined;
  128. if (y.length > 16) {
  129. y = d(y, w.length * 8)
  130. }
  131. for (v = 0; v < 16; v += 1) {
  132. u[v] = y[v] ^ 909522486;
  133. x[v] = y[v] ^ 1549556828
  134. }
  135. A = d(u.concat(j(z)), 512 + z.length * 8);
  136. return p(d(x.concat(A), 512 + 128))
  137. }
  138. function t(w) {
  139. var z = "0123456789abcdef", v = "", u, y;
  140. for (y = 0; y < w.length; y += 1) {
  141. u = w.charCodeAt(y);
  142. v += z.charAt((u >>> 4) & 15) + z.charAt(u & 15)
  143. }
  144. return v
  145. }
  146. function m(u) {
  147. return unescape(encodeURIComponent(u))
  148. }
  149. function q(u) {
  150. return k(m(u))
  151. }
  152. function l(u) {
  153. return t(q(u))
  154. }
  155. function h(u, v) {
  156. return f(m(u), m(v))
  157. }
  158. function r(u, v) {
  159. return t(h(u, v))
  160. }
  161. function md5(v, w, u) {
  162. if (!w) {
  163. if (!u) {
  164. return l(v)
  165. } else {
  166. return q(v)
  167. }
  168. }
  169. if (!u) {
  170. return r(w, v)
  171. } else {
  172. return h(w, v)
  173. }
  174. }

4、房天下( RSA)

在js中看到encrypt格外注意

- 抓包 确定了加密字段 pwd

- 找到加密的大致位置

- 打上断点 确定加密的具体 找到需要出阿迪的参数 开始在vscode中调试

- 通过python执行js代码

  • python代码
  1. import requests
  2. import execjs
  3. from fake_useragent import UserAgent
  4. url = 'https://passport.fang.com/login.api'
  5. # 获取加密后的密码
  6. def get_pwd(file_name,fun_name,fun_args):
  7. with open(file_name,'r',encoding='utf-8') as file:
  8. js_code = file.read()
  9. js = execjs.compile(js_code)
  10. return js.call(fun_name,fun_args)
  11. data = {
  12. "uid":"18735109041",
  13. "pwd": get_pwd('./fang.js','encryptedString','412304'),
  14. "Service": "soufun-passport-web",
  15. "AutoLogin": 1
  16. }
  17. headers = {
  18. 'User-Agent':UserAgent().random,
  19. 'Referer':'https://passport.fang.com/'
  20. }
  21. response = requests.post(url,headers=headers,data=data)
  22. print(response.json())
  • js代码
  1. function setMaxDigits(n) {
  2. maxDigits = n;
  3. ZERO_ARRAY = new Array(maxDigits);
  4. for (var t = 0; t < ZERO_ARRAY.length; t++)
  5. ZERO_ARRAY[t] = 0;
  6. bigZero = new BigInt;
  7. bigOne = new BigInt;
  8. bigOne.digits[0] = 1
  9. }
  10. function BigInt(n) {
  11. this.digits = typeof n == "boolean" && n == !0 ? null : ZERO_ARRAY.slice(0);
  12. this.isNeg = !1
  13. }
  14. function biFromDecimal(n) {
  15. for (var u = n.charAt(0) == "-", t = u ? 1 : 0, i, f, r; t < n.length && n.charAt(t) == "0"; )
  16. ++t;
  17. if (t == n.length)
  18. i = new BigInt;
  19. else {
  20. for (f = n.length - t,
  21. r = f % dpl10,
  22. r == 0 && (r = dpl10),
  23. i = biFromNumber(Number(n.substr(t, r))),
  24. t += r; t < n.length; )
  25. i = biAdd(biMultiply(i, lr10), biFromNumber(Number(n.substr(t, dpl10)))),
  26. t += dpl10;
  27. i.isNeg = u
  28. }
  29. return i
  30. }
  31. function biCopy(n) {
  32. var t = new BigInt(!0);
  33. return t.digits = n.digits.slice(0),
  34. t.isNeg = n.isNeg,
  35. t
  36. }
  37. function biFromNumber(n) {
  38. var t = new BigInt, i;
  39. for (t.isNeg = n < 0,
  40. n = Math.abs(n),
  41. i = 0; n > 0; )
  42. t.digits[i++] = n & maxDigitVal,
  43. n = Math.floor(n / biRadix);
  44. return t
  45. }
  46. function reverseStr(n) {
  47. for (var i = "", t = n.length - 1; t > -1; --t)
  48. i += n.charAt(t);
  49. return i
  50. }
  51. function biToString(n, t) {
  52. var r = new BigInt, i, u;
  53. for (r.digits[0] = t,
  54. i = biDivideModulo(n, r),
  55. u = hexatrigesimalToChar[i[1].digits[0]]; biCompare(i[0], bigZero) == 1; )
  56. i = biDivideModulo(i[0], r),
  57. digit = i[1].digits[0],
  58. u += hexatrigesimalToChar[i[1].digits[0]];
  59. return (n.isNeg ? "-" : "") + reverseStr(u)
  60. }
  61. function biToDecimal(n) {
  62. var i = new BigInt, t, r;
  63. for (i.digits[0] = 10,
  64. t = biDivideModulo(n, i),
  65. r = String(t[1].digits[0]); biCompare(t[0], bigZero) == 1; )
  66. t = biDivideModulo(t[0], i),
  67. r += String(t[1].digits[0]);
  68. return (n.isNeg ? "-" : "") + reverseStr(r)
  69. }
  70. function digitToHex(n) {
  71. var t = "";
  72. for (i = 0; i < 4; ++i)
  73. t += hexToChar[n & 15],
  74. n >>>= 4;
  75. return reverseStr(t)
  76. }
  77. function biToHex(n) {
  78. for (var i = "", r = biHighIndex(n), t = biHighIndex(n); t > -1; --t)
  79. i += digitToHex(n.digits[t]);
  80. return i
  81. }
  82. function charToHex(n) {
  83. var t = 48
  84. , u = t + 9
  85. , i = 97
  86. , f = i + 25
  87. , r = 65;
  88. return n >= t && n <= u ? n - t : n >= r && n <= 90 ? 10 + n - r : n >= i && n <= f ? 10 + n - i : 0
  89. }
  90. function hexToDigit(n) {
  91. for (var t = 0, r = Math.min(n.length, 4), i = 0; i < r; ++i)
  92. t <<= 4,
  93. t |= charToHex(n.charCodeAt(i));
  94. return t
  95. }
  96. function biFromHex(n) {
  97. for (var i = new BigInt, u = n.length, t = u, r = 0; t > 0; t -= 4,
  98. ++r)
  99. i.digits[r] = hexToDigit(n.substr(Math.max(t - 4, 0), Math.min(t, 4)));
  100. return i
  101. }
  102. function biFromString(n, t) {
  103. var f = n.charAt(0) == "-", e = f ? 1 : 0, i = new BigInt, r = new BigInt, u;
  104. for (r.digits[0] = 1,
  105. u = n.length - 1; u >= e; u--) {
  106. var o = n.charCodeAt(u)
  107. , s = charToHex(o)
  108. , h = biMultiplyDigit(r, s);
  109. i = biAdd(i, h);
  110. r = biMultiplyDigit(r, t)
  111. }
  112. return i.isNeg = f,
  113. i
  114. }
  115. function biDump(n) {
  116. return (n.isNeg ? "-" : "") + n.digits.join(" ")
  117. }
  118. function biAdd(n, t) {
  119. var r, u, f, i;
  120. if (n.isNeg != t.isNeg)
  121. t.isNeg = !t.isNeg,
  122. r = biSubtract(n, t),
  123. t.isNeg = !t.isNeg;
  124. else {
  125. for (r = new BigInt,
  126. u = 0,
  127. i = 0; i < n.digits.length; ++i)
  128. f = n.digits[i] + t.digits[i] + u,
  129. r.digits[i] = f % biRadix,
  130. u = Number(f >= biRadix);
  131. r.isNeg = n.isNeg
  132. }
  133. return r
  134. }
  135. function biSubtract(n, t) {
  136. var r, f, u, i;
  137. if (n.isNeg != t.isNeg)
  138. t.isNeg = !t.isNeg,
  139. r = biAdd(n, t),
  140. t.isNeg = !t.isNeg;
  141. else {
  142. for (r = new BigInt,
  143. u = 0,
  144. i = 0; i < n.digits.length; ++i)
  145. f = n.digits[i] - t.digits[i] + u,
  146. r.digits[i] = f % biRadix,
  147. r.digits[i] < 0 && (r.digits[i] += biRadix),
  148. u = 0 - Number(f < 0);
  149. if (u == -1) {
  150. for (u = 0,
  151. i = 0; i < n.digits.length; ++i)
  152. f = 0 - r.digits[i] + u,
  153. r.digits[i] = f % biRadix,
  154. r.digits[i] < 0 && (r.digits[i] += biRadix),
  155. u = 0 - Number(f < 0);
  156. r.isNeg = !n.isNeg
  157. } else
  158. r.isNeg = n.isNeg
  159. }
  160. return r
  161. }
  162. function biHighIndex(n) {
  163. for (var t = n.digits.length - 1; t > 0 && n.digits[t] == 0; )
  164. --t;
  165. return t
  166. }
  167. function biNumBits(n) {
  168. for (var i = biHighIndex(n), r = n.digits[i], u = (i + 1) * bitsPerDigit, t = u; t > u - bitsPerDigit; --t) {
  169. if ((r & 32768) != 0)
  170. break;
  171. r <<= 1
  172. }
  173. return t
  174. }
  175. function biMultiply(n, t) {
  176. for (var i = new BigInt, u, o = biHighIndex(n), s = biHighIndex(t), e, f, r = 0; r <= s; ++r) {
  177. for (u = 0,
  178. f = r,
  179. j = 0; j <= o; ++j,
  180. ++f)
  181. e = i.digits[f] + n.digits[j] * t.digits[r] + u,
  182. i.digits[f] = e & maxDigitVal,
  183. u = e >>> biRadixBits;
  184. i.digits[r + o + 1] = u
  185. }
  186. return i.isNeg = n.isNeg != t.isNeg,
  187. i
  188. }
  189. function biMultiplyDigit(n, t) {
  190. var u, r, f, i;
  191. for (result = new BigInt,
  192. u = biHighIndex(n),
  193. r = 0,
  194. i = 0; i <= u; ++i)
  195. f = result.digits[i] + n.digits[i] * t + r,
  196. result.digits[i] = f & maxDigitVal,
  197. r = f >>> biRadixBits;
  198. return result.digits[1 + u] = r,
  199. result
  200. }
  201. function arrayCopy(n, t, i, r, u) {
  202. for (var o = Math.min(t + u, n.length), f = t, e = r; f < o; ++f,
  203. ++e)
  204. i[e] = n[f]
  205. }
  206. function biShiftLeft(n, t) {
  207. var e = Math.floor(t / bitsPerDigit), i = new BigInt, u, o, r, f;
  208. for (arrayCopy(n.digits, 0, i.digits, e, i.digits.length - e),
  209. u = t % bitsPerDigit,
  210. o = bitsPerDigit - u,
  211. r = i.digits.length - 1,
  212. f = r - 1; r > 0; --r,
  213. --f)
  214. i.digits[r] = i.digits[r] << u & maxDigitVal | (i.digits[f] & highBitMasks[u]) >>> o;
  215. return i.digits[0] = i.digits[r] << u & maxDigitVal,
  216. i.isNeg = n.isNeg,
  217. i
  218. }
  219. function biShiftRight(n, t) {
  220. var e = Math.floor(t / bitsPerDigit), i = new BigInt, u, o, r, f;
  221. for (arrayCopy(n.digits, e, i.digits, 0, n.digits.length - e),
  222. u = t % bitsPerDigit,
  223. o = bitsPerDigit - u,
  224. r = 0,
  225. f = r + 1; r < i.digits.length - 1; ++r,
  226. ++f)
  227. i.digits[r] = i.digits[r] >>> u | (i.digits[f] & lowBitMasks[u]) << o;
  228. return i.digits[i.digits.length - 1] >>>= u,
  229. i.isNeg = n.isNeg,
  230. i
  231. }
  232. function biMultiplyByRadixPower(n, t) {
  233. var i = new BigInt;
  234. return arrayCopy(n.digits, 0, i.digits, t, i.digits.length - t),
  235. i
  236. }
  237. function biDivideByRadixPower(n, t) {
  238. var i = new BigInt;
  239. return arrayCopy(n.digits, t, i.digits, 0, i.digits.length - t),
  240. i
  241. }
  242. function biModuloByRadixPower(n, t) {
  243. var i = new BigInt;
  244. return arrayCopy(n.digits, 0, i.digits, 0, t),
  245. i
  246. }
  247. function biCompare(n, t) {
  248. if (n.isNeg != t.isNeg)
  249. return 1 - 2 * Number(n.isNeg);
  250. for (var i = n.digits.length - 1; i >= 0; --i)
  251. if (n.digits[i] != t.digits[i])
  252. return n.isNeg ? 1 - 2 * Number(n.digits[i] > t.digits[i]) : 1 - 2 * Number(n.digits[i] < t.digits[i]);
  253. return 0
  254. }
  255. function biDivideModulo(n, t) {
  256. var a = biNumBits(n), s = biNumBits(t), v = t.isNeg, r, i, u, e, h, o, f, y, p;
  257. if (a < s)
  258. return n.isNeg ? (r = biCopy(bigOne),
  259. r.isNeg = !t.isNeg,
  260. n.isNeg = !1,
  261. t.isNeg = !1,
  262. i = biSubtract(t, n),
  263. n.isNeg = !0,
  264. t.isNeg = v) : (r = new BigInt,
  265. i = biCopy(n)),
  266. [r, i];
  267. for (r = new BigInt,
  268. i = n,
  269. u = Math.ceil(s / bitsPerDigit) - 1,
  270. e = 0; t.digits[u] < biHalfRadix; )
  271. t = biShiftLeft(t, 1),
  272. ++e,
  273. ++s,
  274. u = Math.ceil(s / bitsPerDigit) - 1;
  275. for (i = biShiftLeft(i, e),
  276. a += e,
  277. h = Math.ceil(a / bitsPerDigit) - 1,
  278. o = biMultiplyByRadixPower(t, h - u); biCompare(i, o) != -1; )
  279. ++r.digits[h - u],
  280. i = biSubtract(i, o);
  281. for (f = h; f > u; --f) {
  282. var c = f >= i.digits.length ? 0 : i.digits[f]
  283. , w = f - 1 >= i.digits.length ? 0 : i.digits[f - 1]
  284. , b = f - 2 >= i.digits.length ? 0 : i.digits[f - 2]
  285. , l = u >= t.digits.length ? 0 : t.digits[u]
  286. , k = u - 1 >= t.digits.length ? 0 : t.digits[u - 1];
  287. for (r.digits[f - u - 1] = c == l ? maxDigitVal : Math.floor((c * biRadix + w) / l),
  288. y = r.digits[f - u - 1] * (l * biRadix + k),
  289. p = c * biRadixSquared + (w * biRadix + b); y > p; )
  290. --r.digits[f - u - 1],
  291. y = r.digits[f - u - 1] * (l * biRadix | k),
  292. p = c * biRadix * biRadix + (w * biRadix + b);
  293. o = biMultiplyByRadixPower(t, f - u - 1);
  294. i = biSubtract(i, biMultiplyDigit(o, r.digits[f - u - 1]));
  295. i.isNeg && (i = biAdd(i, o),
  296. --r.digits[f - u - 1])
  297. }
  298. return i = biShiftRight(i, e),
  299. r.isNeg = n.isNeg != v,
  300. n.isNeg && (r = v ? biAdd(r, bigOne) : biSubtract(r, bigOne),
  301. t = biShiftRight(t, e),
  302. i = biSubtract(t, i)),
  303. i.digits[0] == 0 && biHighIndex(i) == 0 && (i.isNeg = !1),
  304. [r, i]
  305. }
  306. function biDivide(n, t) {
  307. return biDivideModulo(n, t)[0]
  308. }
  309. function biModulo(n, t) {
  310. return biDivideModulo(n, t)[1]
  311. }
  312. function biMultiplyMod(n, t, i) {
  313. return biModulo(biMultiply(n, t), i)
  314. }
  315. function biPow(n, t) {
  316. for (var r = bigOne, i = n; ; ) {
  317. if ((t & 1) != 0 && (r = biMultiply(r, i)),
  318. t >>= 1,
  319. t == 0)
  320. break;
  321. i = biMultiply(i, i)
  322. }
  323. return r
  324. }
  325. function biPowMod(n, t, i) {
  326. for (var f = bigOne, u = n, r = t; ; ) {
  327. if ((r.digits[0] & 1) != 0 && (f = biMultiplyMod(f, u, i)),
  328. r = biShiftRight(r, 1),
  329. r.digits[0] == 0 && biHighIndex(r) == 0)
  330. break;
  331. u = biMultiplyMod(u, u, i)
  332. }
  333. return f
  334. }
  335. function BarrettMu(n) {
  336. this.modulus = biCopy(n);
  337. this.k = biHighIndex(this.modulus) + 1;
  338. var t = new BigInt;
  339. t.digits[2 * this.k] = 1;
  340. this.mu = biDivide(t, this.modulus);
  341. this.bkplus1 = new BigInt;
  342. this.bkplus1.digits[this.k + 1] = 1;
  343. this.modulo = BarrettMu_modulo;
  344. this.multiplyMod = BarrettMu_multiplyMod;
  345. this.powMod = BarrettMu_powMod
  346. }
  347. function BarrettMu_modulo(n) {
  348. var r = biDivideByRadixPower(n, this.k - 1), u = biMultiply(r, this.mu), f = biDivideByRadixPower(u, this.k + 1), e = biModuloByRadixPower(n, this.k + 1), o = biMultiply(f, this.modulus), s = biModuloByRadixPower(o, this.k + 1), t = biSubtract(e, s), i;
  349. for (t.isNeg && (t = biAdd(t, this.bkplus1)),
  350. i = biCompare(t, this.modulus) >= 0; i; )
  351. t = biSubtract(t, this.modulus),
  352. i = biCompare(t, this.modulus) >= 0;
  353. return t
  354. }
  355. function BarrettMu_multiplyMod(n, t) {
  356. var i = biMultiply(n, t);
  357. return this.modulo(i)
  358. }
  359. function BarrettMu_powMod(n, t) {
  360. var u = new BigInt, r, i;
  361. for (u.digits[0] = 1,
  362. r = n,
  363. i = t; ; ) {
  364. if ((i.digits[0] & 1) != 0 && (u = this.multiplyMod(u, r)),
  365. i = biShiftRight(i, 1),
  366. i.digits[0] == 0 && biHighIndex(i) == 0)
  367. break;
  368. r = this.multiplyMod(r, r)
  369. }
  370. return u
  371. }
  372. function RSAKeyPair(n, t, i) {
  373. this.e = biFromHex(n);
  374. this.d = biFromHex(t);
  375. this.m = biFromHex(i);
  376. this.digitSize = 2 * biHighIndex(this.m) + 2;
  377. this.chunkSize = this.digitSize - 11;
  378. this.radix = 16;
  379. this.barrett = new BarrettMu(this.m)
  380. }
  381. function twoDigit(n) {
  382. return (n < 10 ? "0" : "") + String(n)
  383. }
  384. function encryptedString(t) {
  385. var n = new RSAKeyPair("010001", "", "978C0A92D2173439707498F0944AA476B1B62595877DD6FA87F6E2AC6DCB3D0BF0B82857439C99B5091192BC134889DFF60C562EC54EFBA4FF2F9D55ADBCCEA4A2FBA80CB398ED501280A007C83AF30C3D1A142D6133C63012B90AB26AC60C898FB66EDC3192C3EC4FF66925A64003B72496099F4F09A9FB72A2CF9E4D770C41");
  386. var e, o, s, h, c, i, f, u, v, l, y;
  387. if (n.chunkSize > n.digitSize - 11)
  388. return "Error";
  389. for (var a = [], p = t.length, r = 0; r < p; )
  390. a[r] = t.charCodeAt(r),
  391. r++;
  392. for (e = a.length,
  393. o = "",
  394. r = 0; r < e; r += n.chunkSize) {
  395. for (c = new BigInt,
  396. s = 0,
  397. f = r + n.chunkSize > e ? e % n.chunkSize : n.chunkSize,
  398. u = [],
  399. i = 0; i < f; i++)
  400. u[i] = a[r + f - 1 - i];
  401. for (u[f] = 0,
  402. v = Math.max(8, n.digitSize - 3 - f),
  403. i = 0; i < v; i++)
  404. u[f + 1 + i] = Math.floor(Math.random() * 254) + 1;
  405. for (u[n.digitSize - 2] = 2,
  406. u[n.digitSize - 1] = 0,
  407. h = 0; h < n.digitSize; ++s)
  408. c.digits[s] = u[h++],
  409. c.digits[s] += u[h++] << 8;
  410. l = n.barrett.powMod(c, n.e);
  411. y = n.radix == 16 ? biToHex(l) : biToString(l, n.radix);
  412. o += y + " "
  413. }
  414. return o.substring(0, o.length - 1)
  415. }
  416. function decryptedString(n, t) {
  417. for (var e = t.split(" "), i = "", r, u, o, f = 0; f < e.length; ++f)
  418. for (o = n.radix == 16 ? biFromHex(e[f]) : biFromString(e[f], n.radix),
  419. u = n.barrett.powMod(o, n.d),
  420. r = 0; r <= biHighIndex(u); ++r)
  421. i += String.fromCharCode(u.digits[r] & 255, u.digits[r] >> 8);
  422. return i.charCodeAt(i.length - 1) == 0 && (i = i.substring(0, i.length - 1)),
  423. i
  424. }
  425. var biRadixBase = 2, biRadixBits = 16, bitsPerDigit = biRadixBits, biRadix = 65536, biHalfRadix = biRadix >>> 1, biRadixSquared = biRadix * biRadix, maxDigitVal = biRadix - 1, maxInteger = 9999999999999998, maxDigits, ZERO_ARRAY, bigZero, bigOne, dpl10, lr10, hexatrigesimalToChar, hexToChar, highBitMasks, lowBitMasks;
  426. setMaxDigits(20);
  427. dpl10 = 15;
  428. lr10 = biFromNumber(1e15);
  429. hexatrigesimalToChar = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
  430. hexToChar = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
  431. highBitMasks = [0, 32768, 49152, 57344, 61440, 63488, 64512, 65024, 65280, 65408, 65472, 65504, 65520, 65528, 65532, 65534, 65535];
  432. lowBitMasks = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535];
  433. setMaxDigits(129);
  434. // key_to_encode 通过搜索获取
  435. //console.log(encryptedString(key_to_encode,'412304'))

针对这个说明一下方法:

1、首先通过查看请求链接参数,可以看到pwd是经过加密的,那么在search里搜索pwd,定位到如下位置

 

2、截下来我们打断点找到该方法 ,该方法中还有一个参数key_to_encode,同样的方法进行搜索

 

 3、接下来,查找其余需要的代码。如果该js文件代码不多的话,可以全部进行复制。这样,js加密代码就完成了,剩下的就是通过python代码进行密码加密,然后发起登录请求操作

5、模拟闪职登陆-RSA加密

  • 方法一、加密方式通过python重构

1、模拟登陆:

使用python重构了rsa加密方式,得到加密之后的密码

从网页源码中获取到了csrfmiddlewaretoken和pk

携带data发送post进行模拟登陆

2、遇到RSA加密的

如果加密代码不是很长,复制所有的

如果加密代码比较长,最好使用python重构一下加密过程(需要得到重构时所必须的一些参数)

重构的时候要特别注意:有没有对一些细节方面的小处理(如果有,还是要回归js代码的)

setPublicKey----->RSA

encrypt decrypt  --->DES/AES

代码部分:

  1. 分析:首先需要的参数:
  2. username:
  3. password: KaYiT7HiFfadM2S7S31w3mgTHA/Z5idogLXrVi6hdROy6M837ilwXVaV+m4hbLE/SRXTiB+sjbbGP0VsNKK5TNdnuq3/ukRSbr5WtAMF8eoH2f/NhSa4OmZZR3BN+JcOSmdk8qLgsI9FaR8xCRu+P6hc+n/liAq+DfEfjgfI31I=
  4. csrfmiddlewaretoken: HS5stw6ug7ZVnj5WP6eEoxG96NydfsYToEQ2eYPLlBc2uhbyLvKEhk6PKs3vr4Cd
  5. 搜索password:
  6. 索索到
  7. eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4 2(){e 8=$("#1").d();e 3=6 0();e a=$("#9").d();3.b(a);e 7=3.3(8);$("#1").d(7);$("#5").c()}',62,15,'JSEncrypt|MemberPassword|doLogin|encrypt|function|login_button|new|pass_new|password_old|pk|public_key|setPublicKey|submit|val|var'.split('|'),0,{}))
  8. }这种基本上就是经过加密的,
  9. 通过以下链接进行解密查看源代码:解密工具地址:http://www.ab173.com/enc/eval_package.php
  10. 经过解密之后:
  11. function doLogin() {
  12. var password_old = $("#MemberPassword").val(); # 输入密码
  13. var encrypt = new JSEncrypt(); # 加密类
  14. var public_key = $("#pk").val(); # 源码中可以获得pk(公钥)
  15. encrypt.setPublicKey(public_key); # 由setPublickKey函数基本可以确定是RSA加密
  16. var pass_new = encrypt.encrypt(password_old);# 进行加密
  17. $("#MemberPassword").val(pass_new);
  18. $("#login_button").submit()
  19. }
  1. shanzhi_rsa.py
  2. 这里因为是引入了外部加密文件,加密代码比较长,这里使用方法通过python重构加密过程
  3. # 安装需要的包: pip install pycryptodome -i https://pypi.tuna.tsinghua.edu.cn/simple
  4. from Crypto.PublicKey import RSA
  5. from Crypto.Cipher import PKCS1_v1_5 as cry_pksc1_v1_5
  6. import base64
  7. # Pk公钥 password 密码
  8. def encrypto(pk, password):
  9. """
  10. 使用公钥对密码进行加密处理
  11. :param pk: 公钥
  12. :param password: 明文密码
  13. :return: RAS加密之后的密码
  14. """
  15. public_key = "-----BEGIN PUBLIC KEY-----\n{}\n-----END PUBLIC KEY-----".format(pk)
  16. # 导入公钥 返回一个RSA秘钥对象
  17. rsakey = RSA.importKey(public_key)
  18. # 对需要加密的内容进行PKCS#1 v1.5加密
  19. cipher = cry_pksc1_v1_5.new(rsakey)
  20. # 使用公钥加密密码 密码必须是二进制
  21. miwen_encode = cipher.encrypt(password.encode())
  22. # 再使用Base64对类似字节的对象进行编码
  23. cipher_text = base64.b64encode(miwen_encode).decode()
  24. return cipher_text
  1. shanzhi_login.py
  2. import requests
  3. from shanzhi_rsa import encrypto
  4. from lxml import etree
  5. # lxml.etree._Element
  6. from lxml.etree import _Element
  7. url = 'http://shanzhi.spbeen.com/login/'
  8. header = {
  9. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36',
  10. 'Cookie': 'shanzhi_kmer=h9wm0ptr9kcuza527as3a43a6zuwzsid; csrftoken=yHdq0AaPEO1pyiC2zji4MmeyLRNcXVcZLNoHCT3izQ52lwvASvHv0jgsGG9kEXUN'
  11. }
  12. # 先从网页源码中得到csrfmiddlewaretoken和pk
  13. reponse_obj = requests.get(url, headers=header)
  14. tree = etree.HTML(reponse_obj.text)
  15. csrfmiddlewaretoken = tree.xpath('//input[@name="csrfmiddlewaretoken"]/@value')[0]
  16. pk = tree.xpath('//input[@id="pk"]/@value')[0]
  17. old_password = 'logic_00'
  18. password = encrypto(pk, old_password)
  19. data_dict = {
  20. 'username': 'logic_00',
  21. 'password': password,
  22. 'csrfmiddlewaretoken': csrfmiddlewaretoken
  23. }
  24. res = requests.post(url, headers=header, data=data_dict)
  25. print(res.text)
  • 方法二、使用js加密

1、cd 进项目目录

2、做国内资源映射:

           npm install -g cnpm --registry=https://registry.npm.taobao.org,

最后安装:cnpm install node-jsencrypt

  1. shanzhi.js:
  2. const JSEncrypt = require('node-jsencrypt')
  3. // 登陆
  4. function doLogin(pass_old,pk) {
  5. var encrypt = new JSEncrypt()
  6. var public_key = pk
  7. encrypt.setPublicKey(public_key)
  8. var pass_new = encrypt.encrypt(pass_old)
  9. return pass_new
  10. }
  1. tools.py
  2. import execjs
  3. def get_js(file_name,fun_name,*args):
  4. with open(file_name,'r',encoding='utf-8') as file_obj:
  5. js_code = file_obj.read()
  6. # 1、编译js文件
  7. cjs = execjs.compile(js_code)
  8. # 2、 执行js代码
  9. return cjs.call(fun_name,*args)
  1. shanzhi.py
  2. import requests
  3. from lxml import etree
  4. from tools import get_js
  5. # 目标url
  6. url = 'http://shanzhi.spbeen.com/login/'
  7. # 请求头
  8. header = {
  9. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36',
  10. 'Cookie': 'shanzhi_kmer=h9wm0ptr9kcuza527as3a43a6zuwzsid; csrftoken=yHdq0AaPEO1pyiC2zji4MmeyLRNcXVcZLNoHCT3izQ52lwvASvHv0jgsGG9kEXUN'
  11. }
  12. # 先从网页源码中得到csrfmiddlewaretoken和pk
  13. reponse_obj = requests.get(url, headers=header)
  14. tree = etree.HTML(reponse_obj.text)
  15. # 获取csrfmiddlewaretoken
  16. csrfmiddlewaretoken = tree.xpath('//input[@name="csrfmiddlewaretoken"]/@value')[0]
  17. # 获取pk
  18. pk = tree.xpath('//input[@id="pk"]/@value')[0]
  19. old_password = 'logic_00'
  20. new_password = get_js('shanzhi.js','doLogin',old_password,pk)
  21. data_dict = {
  22. 'username': 'logic_00',
  23. 'password': new_password,
  24. 'csrfmiddlewaretoken': csrfmiddlewaretoken
  25. }
  26. res = requests.post(url, headers=header, data=data_dict)
  27. print(res.text)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/709402
推荐阅读
相关标签
  

闽ICP备14008679号