欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

response body加密如何破解方法詳解

 更新時間:2023年01月11日 10:24:30   作者:程序媛最可愛  
這篇文章主要為大家介紹了response body加密如何破解的方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

正文

最近聽了一個 web 安全的分享,其中提到了響應(yīng)加密,我去看了下是怎么實現(xiàn)的,于是就有了這篇文章。

見過賬號密碼加密,沒見過響應(yīng)體加密吧? 打開控制臺的 response,嚇了一跳:

截屏2023-01-06 下午2.46.41.png

咦,響應(yīng)不是 json,這還是第一次見。先別著急,既然只能看見字符串,說明是對整個響應(yīng)體加密的,那么解密一定是在前端。 哈哈,只要是前端解密,作為一個老前端,還能難得倒我?
看我怎么取密鑰

取密鑰

既然是響應(yīng)體統(tǒng)一的加密,那解密函數(shù)大概率在響應(yīng)攔截器里。

添加 fetch breakpoints
devtools -> sources -> XHR/fetch Breakpoints -> +
對指定的 url 添加斷點

一路 debug 發(fā)現(xiàn)密文是在 xhr.onReadyStateChange 函數(shù)里解密的。這里找到了加密方法是對稱加密 AES192 以及對稱加密密鑰 key_string:

!(function (t) {
  var e = c.createDecipher("aes192", "key_string"),
    a = e.update(t.data, "hex", "utf8");
  (a += e.final("utf8")), (a = JSON.parse(a)), (t.data = a);
})(t);

yes,是不是很容易就破解啦?

解密

本地模擬解密 根據(jù)上一個步驟的加密方法和密鑰,啟動一個 node 服務(wù),來模擬客戶端和服務(wù)端,讓我們來看看是否解密正常,以及 NetWork 中的展示是否一致

初始化一個 egg 工程,簡單的改造一下。

$ mkdir egg-example && cd egg-example
$ npm init egg --type=simple
$ npm i
$ npm run dev
$ open http://localhost:7001

添加兩個 controller:

加密接口

// http://127.0.0.1:7001/encode
// 加密
const encrypt = require("./../../encrypt");
const { Controller } = require("egg");
class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = encrypt.aes192_encode(ctx.query.data);
  }
}
module.exports = HomeController;

解密接口

// http://127.0.0.1:7001/decode
// 解密
const encrypt = require("./../../encrypt");
const { Controller } = require("egg");
class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = encrypt.aes192_decode(ctx.query.data);
  }
}
module.exports = HomeController;

添加加解密方法:

const crypto = require("crypto");
function aes192_encode(text, key) {
  const cipher = crypto.createCipher("aes192", key);
  let crypted = cipher.update(text + "", "utf8", "hex");
  crypted += cipher.final("hex"); // 加密之后的值
  return crypted;
}
function aes192_decode(message, key) {
  const decipher = crypto.createDecipher("aes192", key);
  let dec = decipher.update(message, "hex", "utf8");
  dec += decipher.final("utf8"); // 解密之后的值
  return dec;
}
module.exports = { aes192_encode, aes192_decode };

修改 router.js

"use strict";
/**
 * @param {Egg.Application} app - egg application
 */
module.exports = (app) => {
  const { router, controller } = app;
  router.get("/", controller.home.index);
  router.get("/encode", controller.encode.index);
  router.get("/decode", controller.decode.index);
};

在瀏覽器訪問 http://127.0.0.1:7001/encode?data=abc控制臺 response 返回 62ff5059fd64c139378f1a370a09ad02

在瀏覽器訪問 http://127.0.0.1:7001/decode?data=62ff5059fd64c139378f1a370a09ad02 控制臺 response 返回 abc

把我們目標網(wǎng)站的響應(yīng)體拿來試試,結(jié)果也是直接就解出來啦!

考慮到啟動一個 node 服務(wù)還是有點麻煩,我們直接在控制臺安裝對應(yīng)的 npm 包,直接在控制臺解密。

如何在控制臺安裝 npm 包?

安裝 chrome 插件 console importor 安裝好之后 在控制臺輸入:

$i("package name");

這里我們安裝 crypto 試試

$i("crypto")
importer.js:2 [$i]: Searching for crypto, please be patient...
importer.js:2 [$i]: crypto not found, import crypto-js instead.
importer.js:2 [$i]: crypto-js is loading, please be patient...
importer.js:2 [$i]: crypto-js(https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js) is loaded.
importer.js:2 [$i]: The new global variables are as follows: CryptoJS . Maybe you can use them.

控制臺安裝 crypto 找不到, 自動安裝了 cryptojs, 道理是一樣的

// Encrypt
var ciphertext = CryptoJS.AES.encrypt("data", "key_string").toString();
// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, "key_string");
var originalText = bytes.toString(CryptoJS.enc.Utf8);

到這里我們就可以直接在控制臺解密響應(yīng)體啦,如果大家感興趣的話,可以自己寫一個響應(yīng)攔截器插件,可以對指定接口解密,這樣的話,線上環(huán)境也能夠排查 response 啦!

加密響應(yīng)體有必要?

現(xiàn)在回到文章開頭,想想加密響應(yīng)體有沒有價值?
能拿到響應(yīng)體肯定是擁有登錄令牌的,既然都能正常訪問頁面了,那么對響應(yīng)加密其實意義不太大,反而增加了開發(fā)人員排查問題的成本。如果是為了防止抓包信息泄露,使用 https 后抓包拿到的數(shù)據(jù)已經(jīng)是加密過且不能破解的。(可能想得不全面,歡迎大家討論)

最后

密鑰只要是放在前端,無論怎么做代碼混淆,一定是有辦法解密的,差別在于時間長短。

以上就是response body加密如何破解方法詳解的詳細內(nèi)容,更多關(guān)于response body加密破解的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論