JavaScript逆向分析instagram登入過程
一、流程分析
分析發(fā)現(xiàn)密碼加密,且發(fā)送POST請(qǐng)求時(shí)header必須攜帶x-csrftoken,否則是報(bào)403。

而x-csrftoken是在第一次訪問主頁的時(shí)候設(shè)置的。

二、逆向分析
通過查看請(qǐng)求堆棧找到生成處,當(dāng)然也可以直接采用搜索大法,白貓黑貓抓到耗子就是好貓。

通過逐步下斷點(diǎn)分析函數(shù)作用及各種參數(shù)傳入返回,慢慢溯源最終找到生成處。

其中 i(d[1]).encrypt(t, c, u, f) 是主要邏輯,放到Node中缺啥補(bǔ)啥跑起來就ok,當(dāng)然也可以用其他語言重寫。
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
})
}
};

三、模擬請(qǐng)求
首先訪問主頁,獲取到csrftoken,然后把加密后的密碼還有csrftoken組裝起來,POST即可,因?yàn)橘~號(hào)密碼是我瞎填的所以u(píng)ser和authenticated都是false,試了下提交正常賬號(hào)也是完美沒有問題滴。
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服務(wù)
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)
# 運(yùn)行結(jié)果
#PWD_INSTAGRAM_BROWSER:10:1658217374:AVtQAGM39dHHEHtO7U0tFDVnhUk+Wg2VMRNtL+jtmdLx5fpegdgNyMnTmBPfBWUP0lBNGBK9rrAyX4PZfdVMEf0ksXa5s98X/SlIVF78g92WU4w0JnQHArjoIlNzLNcb+wyuy1SBDRsN92Wy5dw+ghaBC7hSUNpVrmE=
200
{"user":false,"authenticated":false,"status":"ok"}

到此這篇關(guān)于JavaScript逆向分析instagram登入過程的文章就介紹到這了,更多相關(guān)js逆向分析instagram登入內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談javascript中for in 和 for each in的區(qū)別
兩個(gè)的作用都用來遍歷對(duì)象,但為什么有了for in語句了還要for each in語句呢,后來看了下for each in開發(fā)的文檔,for each in是作為E4X標(biāo)準(zhǔn)的一部分在javascript 1.6中發(fā)布的,而且它不是ECMAScript標(biāo)準(zhǔn)的一部分2015-04-04
JavaScript手寫源碼之實(shí)現(xiàn)arrify轉(zhuǎn)數(shù)組
這篇文章主要為大家詳細(xì)介紹了如何利用JavaScript實(shí)現(xiàn)arrify轉(zhuǎn)數(shù)組,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)JavaScript有一點(diǎn)的幫助,需要的可以參考一下2023-02-02
javascript中使用replaceAll()函數(shù)實(shí)現(xiàn)字符替換的方法
第一次發(fā)現(xiàn)JavaScript中replace()?方法如果直接用str.replace("-","!")?只會(huì)替換第一個(gè)匹配的字符.2010-12-12
淺述節(jié)點(diǎn)的創(chuàng)建及常見功能的實(shí)現(xiàn)
本文主要對(duì)節(jié)點(diǎn)的創(chuàng)建及常見功能的實(shí)現(xiàn)方法進(jìn)行介紹,希望會(huì)對(duì)大家學(xué)習(xí)javascript有所幫助,下面就跟小編一起來看下吧2016-12-12
JS數(shù)組按指定字段轉(zhuǎn)map-list結(jié)構(gòu)(示例詳解)
在開發(fā)過程中經(jīng)常會(huì)出現(xiàn)接口返回整個(gè)數(shù)組,我們需要將數(shù)組進(jìn)行二次處理,這篇文章主要介紹了js?數(shù)組按指定字段轉(zhuǎn)map-list結(jié)構(gòu),需要的朋友可以參考下2023-11-11
JavaScript如何實(shí)現(xiàn)圖片處理與合成
這篇文章主要介紹了JavaScript如何實(shí)現(xiàn)圖片處理與合成,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05

