JS逆向 | instagram登入enc_password

*本文章仅供学习交流,切勿用于非法通途,如有侵犯贵司请及时联系删除

一、流程分析

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

在这里插入图片描述而x-csrftoken是在第一次访问主页的时候设置的。

在这里插入图片描述

二、逆向分析

通过查看请求堆栈找到生成处,当然也可以直接采用搜索大法,白猫黑猫抓到耗子就是好猫。
在这里插入图片描述
通过逐步下断点分析函数作用及各种参数传入返回,慢慢溯源最终找到生成处。
在这里插入图片描述
其中 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
            })
        }
    };

在这里插入图片描述

三、模拟请求

首先访问主页,获取到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"}

在这里插入图片描述代码就不贴出来了,偷偷放在知识星球<虫术>里面了,公众号有星球的优惠券,其实整个分析过程还是挺简单,有兴趣的同学可以自己试试

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

404NooFound

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值