preface

Recently, I have been working on the js knowledge. By the way, I would like to share with you a small project of practicing and learning, so that I can know more about the charm of crawlers. Js reverse login mango TV

The target address

Web site:www.mgtv.com/

Tool use

Development tools: pycharm development environment: python3.7, Windows10 using toolkits: requests, time, execjs

Project idea analysis

First need to define the basic process of login, web logs in can see roughly four data need to submit the form data from account, password and verification code, remember the password, and some web pages will have agreement, account or phone number is usually clear, and the password is encrypted data, verification code generated by the way would be a little not sure, may be the front end, It may be the back end, or other platforms, but the verification code will also be passed to the back end for comparison. It is necessary to obtain the cookie value of the verification code. After a little clarity, we start to get to the topic.

The first step is to find the corresponding login interface and open the debugging tool to see if the data is a dynamic request with the wrong request attempt



Data that needs to be passed



Pretty much what we figured out account number, password, CAPtCHA, two other fixed parameters

First solve the problem of verification code, verification code is also updated in real time, there must be a verification code interface



Request the verification code data to manually identify the verification code

session = requests.session() captcha_url = f"https://i.mgtv.com/vcode?from=pcclient&time={int(time.time() * 1000)}" Headers = {" user-agent ": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit / 537.36 (KHTML, Like Gecko) Chrome/76.0.3809.87 Safari/537.36"} captcha_res = session. Get (captcha_url, headers=headers) with open("captcha.jpg", "wb") as f: f.write(captcha_res.content)Copy the code

Get the picture data manually input

Now the only problem is that the data is encrypted and the data is encrypted, so we need to find out where the encryption is, and directly search globally for the key value of the word,





The function where the data is being parsed over here, the arguments are all passed in by e and you need to find the location of this method call



The password is generated by the c parameter



Honey is the parsing function for the entire JS password and we copy the entire code with the login.js file

 function s(i, t, s) {
        this.e = c(i),
        this.d = c(t),
        this.m = c(s),
        this.chunkSize = 2 * B(this.m),
        this.radix = 16,
        this.barrett = new O(this.m)
    }

function login(i){
        return e(131),
        time = String(Date.parse(new Date)).substring(0, 10),
        rd = String(Math.random()),
        nonce = String(rd + time + time + rd).substring(0, 32),
        i = time + nonce + i,
        function(i, t) {
            var s = new Array
              , r = t.length
              , e = 0;
            for (; e < r; )
                s[e] = t.charCodeAt(e),
                e++;
            for (; s.length % i.chunkSize != 0; )
                s[e++] = 0;
            var g, n, d, u = s.length, o = "";
            for (e = 0; e < u; e += i.chunkSize) {
                for (d = new k,
                g = 0,
                n = e; n < e + i.chunkSize; ++g)
                    d.digits[g] = s[n++],
                    d.digits[g] += s[n++] << 8;
                var a = i.barrett.powMod(d, i.e)
                  , h = 16 == i.radix ? l(a) : f(a, i.radix);
                o += h + " "
            }
            return o.substring(0, o.length - 1)
        }(new s("10001","","A5245A4630DD7CE9D8A967E33A50EB52C2634FD042C4BFBCF5A5C1317A234FD0D1D2C75D083946AF70CE480C399FAD8EEBE9F5A904F30E4D3C91CDD7C27C4D07E27015D46B29A003E9D49834E19041A7BA45A95E6161697975721E88949E8023DA682895086223683593F054E7AAE0E07C40DB33BD80EE5909CE48D17C07D097"), i)
};
    var r, g, A, o = 16, D = o, E = 65536, b = E >>> 1, M = E * E, C = E - 1;
    function e(i) {
        r = new Array(i);
        for (var t = 0; t < r.length; t++)
            r[t] = 0;
        g = new k,
        (A = new k).digits[0] = 1
    }
    e(20);
    n(1e15);
    function k(i) {
        this.digits = "boolean" == typeof i && 1 == i ? null : r.slice(0),
        this.isNeg = !1
    }
    function y(i) {
        var t = new k(!0);
        return t.digits = i.digits.slice(0),
        t.isNeg = i.isNeg,
        t
    }
    function n(i) {
        var t = new k;
        t.isNeg = i < 0,
        i = Math.abs(i);
        for (var s = 0; 0 < i; )
            t.digits[s++] = i & C,
            i = Math.floor(i / E);
        return t
    }
    function d(i) {
        for (var t = "", s = i.length - 1; -1 < s; --s)
            t += i.charAt(s);
        return t
    }
    var u = new Array("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");
    function f(i, t) {
        var s = new k;
        s.digits[0] = t;
        for (var r = L(i, s), e = u[r[1].digits[0]]; 1 == K(r[0], g); )
            r = L(r[0], s),
            digit = r[1].digits[0],
            e += u[r[1].digits[0]];
        return (i.isNeg ? "-" : "") + d(e)
    }
    var a = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
    function h(t) {
        var s = "";
        for (i = 0; i < 4; ++i)
            s += a[15 & t],
            t >>>= 4;
        return d(s)
    }
    function l(i) {
        for (var t = "", s = (B(i),
        B(i)); -1 < s; --s)
            t += h(i.digits[s]);
        return t
    }
    function N(i) {
        return 48 <= i && i <= 57 ? i - 48 : 65 <= i && i <= 90 ? 10 + i - 65 : 97 <= i && i <= 122 ? 10 + i - 97 : 0
    }
    function v(i) {
        for (var t = 0, s = Math.min(i.length, 4), r = 0; r < s; ++r)
            t <<= 4,
            t |= N(i.charCodeAt(r));
        return t
    }
    function c(i) {
        for (var t = new k, s = i.length, r = 0; 0 < s; s -= 4,
        ++r)
            t.digits[r] = v(i.substr(Math.max(s - 4, 0), Math.min(s, 4)));
        return t
    }
    function p(i, t) {
        var s;
        if (i.isNeg != t.isNeg)
            t.isNeg = !t.isNeg,
            s = F(i, t),
            t.isNeg = !t.isNeg;
        else {
            s = new k;
            for (var r, e = 0, g = 0; g < i.digits.length; ++g)
                r = i.digits[g] + t.digits[g] + e,
                s.digits[g] = r % E,
                e = Number(E <= r);
            s.isNeg = i.isNeg
        }
        return s
    }
    function F(i, t) {
        var s;
        if (i.isNeg != t.isNeg)
            t.isNeg = !t.isNeg,
            s = p(i, t),
            t.isNeg = !t.isNeg;
        else {
            var r, e;
            s = new k;
            for (var g = e = 0; g < i.digits.length; ++g)
                r = i.digits[g] - t.digits[g] + e,
                s.digits[g] = r % E,
                s.digits[g] < 0 && (s.digits[g] += E),
                e = 0 - Number(r < 0);
            if (-1 == e) {
                for (g = e = 0; g < i.digits.length; ++g)
                    r = 0 - s.digits[g] + e,
                    s.digits[g] = r % E,
                    s.digits[g] < 0 && (s.digits[g] += E),
                    e = 0 - Number(r < 0);
                s.isNeg = !i.isNeg
            } else
                s.isNeg = i.isNeg
        }
        return s
    }
    function B(i) {
        for (var t = i.digits.length - 1; 0 < t && 0 == i.digits[t]; )
            --t;
        return t
    }
    function S(i) {
        var t, s = B(i), r = i.digits[s], e = (s + 1) * D;
        for (t = e; e - D < t && 0 == (32768 & r); --t)
            r <<= 1;
        return t
    }
    function w(i, t) {
        for (var s, r, e, g = new k, n = B(i), d = B(t), u = 0; u <= d; ++u) {
            for (s = 0,
            e = u,
            j = 0; j <= n; ++j,
            ++e)
                r = g.digits[e] + i.digits[j] * t.digits[u] + s,
                g.digits[e] = r & C,
                s = r >>> o;
            g.digits[u + n + 1] = s
        }
        return g.isNeg = i.isNeg != t.isNeg,
        g
    }
    function x(i, t) {
        var s, r, e;
        result = new k,
        s = B(i);
        for (var g = r = 0; g <= s; ++g)
            e = result.digits[g] + i.digits[g] * t + r,
            result.digits[g] = e & C,
            r = e >>> o;
        return result.digits[1 + s] = r,
        result
    }
    function m(i, t, s, r, e) {
        for (var g = Math.min(t + e, i.length), n = t, d = r; n < g; ++n,
        ++d)
            s[d] = i[n]
    }
    var z = new Array(0,32768,49152,57344,61440,63488,64512,65024,65280,65408,65472,65504,65520,65528,65532,65534,65535);
    function q(i, t) {
        var s = Math.floor(t / D)
          , r = new k;
        m(i.digits, 0, r.digits, s, r.digits.length - s);
        for (var e = t % D, g = D - e, n = r.digits.length - 1, d = n - 1; 0 < n; --n,
        --d)
            r.digits[n] = r.digits[n] << e & C | (r.digits[d] & z[e]) >>> g;
        return r.digits[0] = r.digits[n] << e & C,
        r.isNeg = i.isNeg,
        r
    }
    var P = new Array(0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535);
    function G(i, t) {
        var s = Math.floor(t / D)
          , r = new k;
        m(i.digits, s, r.digits, 0, i.digits.length - s);
        for (var e = t % D, g = D - e, n = 0, d = n + 1; n < r.digits.length - 1; ++n,
        ++d)
            r.digits[n] = r.digits[n] >>> e | (r.digits[d] & P[e]) << g;
        return r.digits[r.digits.length - 1] >>>= e,
        r.isNeg = i.isNeg,
        r
    }
    function H(i, t) {
        var s = new k;
        return m(i.digits, 0, s.digits, t, s.digits.length - t),
        s
    }
    function I(i, t) {
        var s = new k;
        return m(i.digits, t, s.digits, 0, s.digits.length - t),
        s
    }
    function J(i, t) {
        var s = new k;
        return m(i.digits, 0, s.digits, 0, t),
        s
    }
    function K(i, t) {
        if (i.isNeg != t.isNeg)
            return 1 - 2 * Number(i.isNeg);
        for (var s = i.digits.length - 1; 0 <= s; --s)
            if (i.digits[s] != t.digits[s])
                return i.isNeg ? 1 - 2 * Number(i.digits[s] > t.digits[s]) : 1 - 2 * Number(i.digits[s] < t.digits[s]);
        return 0
    }
    function L(i, t) {
        var s, r, e = S(i), g = S(t), n = t.isNeg;
        if (e < g)
            return i.isNeg ? ((s = y(A)).isNeg = !t.isNeg,
            i.isNeg = !1,
            t.isNeg = !1,
            r = F(t, i),
            i.isNeg = !0,
            t.isNeg = n) : (s = new k,
            r = y(i)),
            new Array(s,r);
        s = new k,
        r = i;
        for (var d = Math.ceil(g / D) - 1, u = 0; t.digits[d] < b; )
            t = q(t, 1),
            ++u,
            ++g,
            d = Math.ceil(g / D) - 1;
        r = q(r, u),
        e += u;
        for (var o = Math.ceil(e / D) - 1, a = H(t, o - d); -1 != K(r, a); )
            ++s.digits[o - d],
            r = F(r, a);
        for (var h = o; d < h; --h) {
            var f = h >= r.digits.length ? 0 : r.digits[h]
              , l = h - 1 >= r.digits.length ? 0 : r.digits[h - 1]
              , N = h - 2 >= r.digits.length ? 0 : r.digits[h - 2]
              , v = d >= t.digits.length ? 0 : t.digits[d]
              , c = d - 1 >= t.digits.length ? 0 : t.digits[d - 1];
            s.digits[h - d - 1] = f == v ? C : Math.floor((f * E + l) / v);
            for (var w = s.digits[h - d - 1] * (v * E + c), m = f * M + (l * E + N); m < w; )
                --s.digits[h - d - 1],
                w = s.digits[h - d - 1] * (v * E | c),
                m = f * E * E + (l * E + N);
            (r = F(r, x(a = H(t, h - d - 1), s.digits[h - d - 1]))).isNeg && (r = p(r, a),
            --s.digits[h - d - 1])
        }
        return r = G(r, u),
        s.isNeg = i.isNeg != n,
        i.isNeg && (s = n ? p(s, A) : F(s, A),
        r = F(t = G(t, u), r)),
        0 == r.digits[0] && 0 == B(r) && (r.isNeg = !1),
        new Array(s,r)
    }
    function O(i) {
        this.modulus = y(i),
        this.k = B(this.modulus) + 1;
        var t, s, r = new k;
        r.digits[2 * this.k] = 1,
        this.mu = (t = r,
        s = this.modulus,
        L(t, s)[0]),
        this.bkplus1 = new k,
        this.bkplus1.digits[this.k + 1] = 1,
        this.modulo = Q,
        this.multiplyMod = R,
        this.powMod = T
    }
    function Q(i) {
        var t = I(w(I(i, this.k - 1), this.mu), this.k + 1)
          , s = F(J(i, this.k + 1), J(w(t, this.modulus), this.k + 1));
        s.isNeg && (s = p(s, this.bkplus1));
        for (var r = 0 <= K(s, this.modulus); r; )
            r = 0 <= K(s = F(s, this.modulus), this.modulus);
        return s
    }
    function R(i, t) {
        var s = w(i, t);
        return this.modulo(s)
    }
    function T(i, t) {
        var s = new k;
        s.digits[0] = 1;
        for (var r = i, e = t; 0 != (1 & e.digits[0]) && (s = this.multiplyMod(s, r)),
        0 != (e = G(e, 1)).digits[0] || 0 != B(e); )
            r = this.multiplyMod(r, r);
        return s
    };


Copy the code

Call the file directly from Python, then it’s time to patch up the environment and modify the JS code

I am white and white I, a program yuan like to share knowledge ❤️ if there is no contact with this piece of programming friends see this blog, found that can not program or want to learn, you can directly leave a message + private ME ~ [thank you very much for your likes, favorites, concerns, comments, three even support]