网络编程
位置:首页>> 网络编程>> JavaScript>> JavaScript逆向分析instagram登入过程

JavaScript逆向分析instagram登入过程

作者:ZRocket  发布时间:2023-09-08 19:51:52 

标签:js,逆向分析,instagram,登入

一、流程分析

分析发现密码加密,且发送POST请求时header必须携带x-csrftoken,否则是报403。

JavaScript逆向分析instagram登入过程

而x-csrftoken是在第一次访问主页的时候设置的。

JavaScript逆向分析instagram登入过程

二、逆向分析

通过查看请求堆栈找到生成处,当然也可以直接采用搜索 * ,白猫黑猫抓到耗子就是好猫。

JavaScript逆向分析instagram登入过程

通过逐步下断点分析函数作用及各种参数传入返回,慢慢溯源最终找到生成处。

JavaScript逆向分析instagram登入过程

其中 i(d[1]).encrypt(t, c, u, f) 是主要逻辑,放到Node中缺啥补啥跑起来就ok,当然也可以用其他语言重写。

s = {
       encrypt: async function(s, c, h, l) {
           const u = o + h.length;
           if (64 !== c.length)
               throw new Error('public key is not a valid hex sting');
           const w = n(c);
           if (!w)
               throw new Error('public key is not a valid hex string');
           const y = new Uint8Array(u);
           let f = 0;
           y[f] = 1,
           y[f += 1] = s,
           f += 1;
           const p = {
               name: 'AES-GCM',
               iv: new Uint8Array(12),
               additionalData: l,
               tagLen: 16
           }
             , A = window.crypto || window.msCrypto;
           return A.subtle.generateKey({
               name: 'AES-GCM',
               length: 256
           }, !0, ['encrypt', 'decrypt']).then(function(t) {
               const n = A.subtle.exportKey('raw', t)
                 , o = A.subtle.encrypt(p, t, h.buffer);
               return Promise.all([n, o])
           }).then(function(n) {
               const o = t(new Uint8Array(n[0]), w);
               if (y[f] = 255 & o.length,
               y[f + 1] = o.length >> 8 & 255,
               f += 2,
               y.set(o, f),
               f += 32,
               f += r(d[0]).overheadLength,
               o.length !== 32 + r(d[0]).overheadLength)
                   throw new Error('encrypted key is the wrong length');
               const s = new Uint8Array(n[1])
                 , c = s.slice(-16)
                 , h = s.slice(0, -16);
               return y.set(c, f),
               f += 16,
               y.set(h, f),
               y
           }).catch(function(t) {
               throw t
           })
       }
   };

JavaScript逆向分析instagram登入过程

三、模拟请求

首先访问主页,获取到csrftoken,然后把加密后的密码还有csrftoken组装起来,POST即可,因为账号密码是我瞎填的所以user和authenticated都是false,试了下提交正常账号也是完美没有问题滴。

import requests
def get_proxy():
   return {
       "http":"http://"+ip,
       "https": "https://" + ip,
   }
headers = {
   'authority': 'www.instagram.com',
   'origin': 'https://www.instagram.com',
   'referer': 'https://www.instagram.com/',
   'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
}
cookie = requests.get('https://www.instagram.com/',headers=headers, proxies=get_proxy()).cookies
headers['x-csrftoken']= cookie.get('csrftoken')
# node服务
enc_password = requests.get('http://localhost:23346/instagram?password=1111111111111111111111').text
print(enc_password)
data = {
 'enc_password': enc_password,
 'username': '15566678899',
 'queryParams': '{}',
 'optIntoOneTap': 'false',
 'stopDeletionNonce': '',
 'trustedDeviceRecords': '{}'
}
response = requests.post('https://www.instagram.com/accounts/login/ajax/', headers=headers, data=data, proxies=get_proxy())
print(response.status_code)
print(response.text)

# 运行结果
#PWD_INSTAGRAM_BROWSER:10:1658217374:AVtQAGM39dHHEHtO7U0tFDVnhUk+Wg2VMRNtL+jtmdLx5fpegdgNyMnTmBPfBWUP0lBNGBK9rrAyX4PZfdVMEf0ksXa5s98X/SlIVF78g92WU4w0JnQHArjoIlNzLNcb+wyuy1SBDRsN92Wy5dw+ghaBC7hSUNpVrmE=
200
{"user":false,"authenticated":false,"status":"ok"}

JavaScript逆向分析instagram登入过程

来源:https://blog.csdn.net/qq_41179280/article/details/125872984?

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com