[JS reverse hundred examples] you haven't seen the encryption of socialist core values

Focus on official account dry cargo WeChat public: K brother crawler, keep sharing crawler advance, JS/ Android reverse technology dry goods!

statement

All contents in this article are for learning and communication only. The packet capturing content, sensitive website and data interface have been desensitized. It is strictly prohibited to use them for commercial and illegal purposes, otherwise all the consequences have nothing to do with the author. If there is infringement, please contact me and delete them immediately!

Reverse target

  • Objective: to analyze the encryption principle of socialist core values
  • Home page: aHR0cHM6Ly93d3cuYXBwbWl1LmNvbS9rZXkv

backward analysis

Brother K's colleagues sent an interesting encryption today. No matter what string you enter, the encrypted result is a random combination of 24 word socialist core values, as shown in the figure below:

First, let's try to capture packets to see if there is any contracting operation on the network. In fact, there is no such operation. This shows that the logic of encryption and decryption is in the loaded JavaScript code. Here are three methods to locate the encryption entry:

1. We note that the encryption result is always composed of socialist core values. Some operations must be done on the basis of the original 24 words, that is, these 24 words must be defined somewhere. We can search one of them globally, as shown in the figure below:

2. The encryption and decryption results are generated only after clicking the button. Then this button must be bound to some events, such as mouse click events. We can locate the encryption entry through the DOM event breakpoint, as shown in the following figure:

3. We note that the encrypted and decrypted button s have an id, so it is possible that after the id is obtained in JavaScript, use the addEventListener() method to add a mouse click event handle to the element, so you can also search its id globally, that is, encode BTN and decode BTN, or getelementbyid ("encode BTN") or getelementbyid ("decode BTN"), Of course, you can also search the method keyword addEventListener. As shown in the figure below:

After locating the encryption location, bury the breakpoint for debugging. Let's take a look at the encryption logic:

Encryption process: the variable v gets the plaintext area through the element id (decoded area), and clicking the encrypt button (encode BTN) will trigger an event to enter the following function. v.value is the plaintext value, which is encrypted by the l() function and assigned to n, and then assigned to p.value, that is, displayed in the encoded area of the ciphertext.

Decryption process: the variable p obtains the ciphertext area through the element id (encoded area). Clicking the decryption button (decode BTN) will trigger an event and enter the following function. p.value is the ciphertext value, which is decrypted by the s() function and assigned to n, and then assigned to v.value, that is, displayed in the plaintext text area.

The whole code logic is relatively simple, and these functions used are all together. You can copy them all directly.

Complete code

GitHub pays attention to brother K crawler and continues to share crawler related codes! Welcome, star! https://github.com/kgepachong/

JavaScript encryption and decryption code

var e = function () {
    for (var t = arguments.length, n = Array(t), r = 0; r < t; r++)
        n[r] = arguments[r];
    var e = n.length
        , i = "string" == typeof n[e - 1] ? n[e - 1] : "Assert Error"
        , o = !0
        , u = !1
        , c = void 0;
    try {
        for (var f, a = n[Symbol.iterator](); !(o = (f = a.next()).done); o = !0) {
            if (!f.value)
                throw new Error(i)
        }
    } catch (t) {
        u = !0,
            c = t
    } finally {
        try {
            !o && a.return && a.return()
        } finally {
            if (u)
                throw c
        }
    }
}
    , i = function () {
    return Math.random() >= .5
}
    , o = function (t) {
    var n = /[A-Za-z0-9\-\_\.\!\~\*\'\(\)]/g
        , r = t.replace(n, function (t) {
        return t.codePointAt(0).toString(16)
    });
    return encodeURIComponent(r).replace(/%/g, "").toUpperCase()
}
    , u = function (t) {
    e("string" == typeof t, "utfs Error");
    var n = t.length;
    e(0 == (1 & n));
    for (var r = [], i = 0; i < n; i++)
        0 == (1 & i) && r.push("%"),
            r.push(t[i]);
    return decodeURIComponent(r.join(""))
}
    , c = function (t) {
    e("string" == typeof t);
    var n = []
        , r = !0
        , o = !1
        , u = void 0;
    try {
        for (var c, f = t[Symbol.iterator](); !(r = (c = f.next()).done); r = !0) {
            var a = c.value
                , s = Number.parseInt(a, 16);
            s < 10 ? n.push(s) : i() ? (n.push(10),
                n.push(s - 10)) : (n.push(11),
                n.push(s - 6))
        }
    } catch (t) {
        o = !0,
            u = t
    } finally {
        try {
            !r && f.return && f.return()
        } finally {
            if (o)
                throw u
        }
    }
    return n
}
    , f = function (t) {
    e(t instanceof Array);
    for (var n = [], r = t.length, i = 0; i < r;)
        t[i] < 10 ? n.push(t[i]) : 10 === t[i] ? (i++,
            n.push(t[i] + 10)) : (i++,
            n.push(t[i] + 6)),
            i++;
    return n.map(function (t) {
        return t.toString(16).toUpperCase()
    }).join("")
}
    , a = function (t) {
    return t.map(function (t) {
        return h[2 * t] + h[2 * t + 1]
    }).join("")
}
    , s = function (t) {
    var n = []
        , r = !0
        , i = !1
        , o = void 0;
    try {
        for (var c, a = t[Symbol.iterator](); !(r = (c = a.next()).done); r = !0) {
            var s = c.value
                , l = h.indexOf(s);
            -1 !== l && (1 & l || n.push(l >> 1))
        }
    } catch (t) {
        i = !0,
            o = t
    } finally {
        try {
            !r && a.return && a.return()
        } finally {
            if (i)
                throw o
        }
    }
    var v = f(n);
    e(0 == (1 & v.length));
    var p = void 0;
    try {
        p = u(v)
    } catch (t) {
        throw t
    }
    return p
}
    , h = "Prosperity, democracy, civilization, harmony, freedom, equality, justice, rule of law, patriotism, professionalism, integrity and friendliness"

function encrypt(t) {
    return a(c(o(t)))
}

function decrypt(t) {
    return s(t)
}

// Test sample
// console.log(encrypt("1234"))
// console.log(decrypt("harmonious democracy, harmonious civilization, harmonious freedom")

Tags: Python

Posted on Thu, 25 Nov 2021 20:18:03 -0500 by Diggler