websocket--hook

代码不全,大致思路
原理:
浏览器(客户端):在浏览器中注入一段JS代码,与服务端建立连接。调用浏览器中的js方法,把返回的数据发送给服务端
node启动js代码,监听某端口(客户端):服务端把参数(python发过来的)发送给客户端处理,并接收处理结果,再次把接收的结果返回给python处理
python(调用者):把参数发送给node,接收node传回来的数据 优点:
1.对于js混淆加密较深的,可以采用此方法。
2.不用扣js加密代码,直接调用浏览器环境
缺点:
1.如果有selenium监测,要想使用此方法,必须先绕过selenium监测,否则只能使用真机进行js注入
2.需要node环境,写一个websocket服务端和客户端
3.速度没有直接破解js快

服务端--WebSocketServer.js

let iconv = require('iconv-lite')
var ws = require("nodejs-websocket"); console.log("开始建立连接...") var server = ws.createServer(function(conn){
let cached = {}; conn.on("text", function (msg) {
if (!msg) return;
// console.log("msg", msg); var key = conn.key;
if ((msg === "Browser") || (msg === "Python")){
// browser或者python第一次连接
cached[msg] = key;
// console.log("cached",cached);
return;
}
if (Object.values(cached).includes(key)){
// console.log(server.connections.forEach(conn=>conn.key));
var targetConn = server.connections.filter(function(conn){
return conn.key !== key;
})
// console.log("将要发送的实参:",msg);
targetConn.forEach(conn=>{
conn.send(msg);
})
}
})
conn.on("close", function (code, reason) {
// console.log("关闭连接")
});
conn.on("error", function (code, reason) {
console.log("异常关闭")
});
conn.on("connection", function (conn) {
console.log(conn)
});
}).listen(10512) console.log("WebSocket建立完毕")

客户端注入JS代码

createSocket();

function createSocket() {
window.ws = new WebSocket('ws://127.0.0.1:10512/');
window.ws.onopen = function (e) {
console.log("连接服务器成功");
window.ws.send("Browser");
}
window.ws.onclose = function (e) {
console.log("服务器关闭");
setTimeout(createSocket, 60000);
}
window.ws.onerror = function () {
console.log("连接出错");
} window.ws.onmessage = function (e) {
var xmlhttp = new glb.XMLHttpRequest();
function state_Change() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) { let result = xmlhttp.responseText
result = JSON.parse(result)
result = JSON.stringify(result)
// result = String.fromCharCode(result)
//发送给Python
// console.log(result);
window.ws.send(result);
} else {
alert("Problem retrieving XML data");
}
}
}
xmlhttp.onreadystatechange = state_Change;
xmlhttp.open('GET', e.data, true);
xmlhttp.send(null);
}
}

python开端口

# -*- coding: utf-8 -*-
from sanic import Sanic
from sanic.response import json
import os
import urllib3 from toutiao2_文件方式.get_data import get_data
from toutiao2_文件方式.get_user_id import get_user urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
app = Sanic(__name__) @app.route("/get_user_id", methods=["GET"])
def captcha_server(request):
try:
data = request.args
media_id = data['media_id'][0]
return get_user_id(media_id)
except Exception as e:
pass @app.route("/get_data", methods=["GET"])
def captcha_server(request):
try:
data = request.args
user_id = data['user_id'][0]
offset = data['offset'][0]
return get_res(user_id, offset)
except Exception as e:
pass def get_user_id(media_id):
html = get_user(media_id)
return html def get_res(user_id, offset):
html = get_data(user_id,offset)
return html if __name__ == "__main__":
app.run(host="127.0.0.1", port=4007)

get_data.py 文件方式

# -*- coding: utf-8 -*-
import time
from ws4py.client.threadedclient import WebSocketClient
import _locale _locale._getdefaultlocale = (lambda *args: ['zh_CN', 'utf8'])
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) class CG_Client(WebSocketClient):
def opened(self):
self.max_cursor = 0
self.send("Python") def closed(self, code, reason=None):
# print("Closed down:", code, reason)
pass def received_message(self, resp):
data = resp.data.decode("utf-8")
write_data(data)
ws.close() def write_data(data):
with open('./data.txt', 'w', encoding='utf-8') as f:
f.write(data)
f.close() def get_data(user_id, offset):
ws = CG_Client('ws://127.0.0.1:10512/')
ws.connect()
try:
real_arg = f"/api/feed_backflow/profile_share/v1/?category=profile_article&visited_uid={user_id}&stream_api_version=82&request_source=1&offset={offset}&user_id={user_id}&appId=1286&appType=mobile_detail_web&isAndroid=true&isIOS=false&isMobile=true&cookie_enabled=true&screen_width=288&screen_height=511&browser_language=zh-CN&browser_platform=MacIntel&browser_name=firefox&browser_version=85.0.4183.83&browser_online=true&timezone_name=Asia%2FShanghai"
time.sleep(0.1)
ws.send(real_arg)
ws.run_forever()
except KeyboardInterrupt:
print('异常关闭')
ws.close()

get_user_id.py 文件方式

# -*- coding: utf-8 -*-
import time
from ws4py.client.threadedclient import WebSocketClient
import _locale
_locale._getdefaultlocale = (lambda *args: ['zh_CN', 'utf8'])
import io
import sys
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
# media_id = sys.argv[1].split(',', 1)[0] # sys.argv--> [get_attention.py,user_id,cursor] class CG_Client(WebSocketClient):
def opened(self):
self.max_cursor = 0
self.send("Python") def closed(self, code, reason=None):
# print("Closed down:", code, reason)
pass def received_message(self, resp):
data = resp.data.decode("utf-8")
write_user(data)
ws.close()
def write_user(data):
with open('./user.txt', 'w', encoding='utf-8') as f:
f.write(data)
f.close() def get_user(media_id):
ws = CG_Client('ws://127.0.0.1:10512/')
ws.connect()
try:
real_arg = f"/user/profile/homepage/share/v7/?media_id={media_id}&request_source=1&appId=1286&appType=mobile_detail_web&isAndroid=true&isIOS=false&isMobile=true&cookie_enabled=true&screen_width=393&screen_height=882&browser_language=zh-CN&browser_platform=MacIntel&browser_name=Chrome&browser_version=85.0.4183.83&browser_online=true&timezone_name=Asia%2FShanghai"
time.sleep(0.1)
ws.send(real_arg)
ws.run_forever()
except KeyboardInterrupt:
print('异常关闭')
ws.close()

get_data.py 终端方式

# -*- coding: utf-8 -*-
import time
from ws4py.client.threadedclient import WebSocketClient
import _locale _locale._getdefaultlocale = (lambda *args: ['zh_CN', 'utf8'])
import io
import sys
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
user_id = sys.argv[1].split(',', 1)[0] # sys.argv--> [get_attention.py,user_id,cursor]
offset = str(sys.argv[2]) class CG_Client(WebSocketClient): def opened(self):
print("连接成功")
self.max_cursor = 0
self.send("Python") def closed(self, code, reason=None):
print("Closed down:", code, reason) def received_message(self, resp):
data = resp.data.decode("utf-8")
print(data)
ws.close() try:
ws = CG_Client('ws://127.0.0.1:10512/')
ws.connect() real_arg = f"/api/feed_backflow/profile_share/v1/?category=profile_article&visited_uid={user_id}&stream_api_version=82&request_source=1&offset={offset}&user_id={user_id}&appId=1286&appType=mobile_detail_web&isAndroid=true&isIOS=false&isMobile=true&cookie_enabled=true&screen_width=288&screen_height=511&browser_language=zh-CN&browser_platform=MacIntel&browser_name=firefox&browser_version=85.0.4183.83&browser_online=true&timezone_name=Asia%2FShanghai"
time.sleep(0.1)
ws.send(real_arg)
ws.run_forever()
except KeyboardInterrupt:
ws.close()

get_user_id.py 终端方式

# -*- coding: utf-8 -*-
import time
from ws4py.client.threadedclient import WebSocketClient
import _locale
_locale._getdefaultlocale = (lambda *args: ['zh_CN', 'utf8'])
import io
import sys
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
media_id = sys.argv[1].split(',', 1)[0] # sys.argv--> [get_attention.py,user_id,cursor] class CG_Client(WebSocketClient): def opened(self):
print("连接成功")
self.max_cursor = 0
self.send("Python") def closed(self, code, reason=None):
print("Closed down:", code, reason) def received_message(self, resp):
data = resp.data.decode("utf-8")
# data = resp.data.decode("gbk")
print(data)
ws.close() try:
ws = CG_Client('ws://127.0.0.1:10512/')
ws.connect() real_arg = f"/user/profile/homepage/share/v7/?media_id={media_id}&request_source=1&appId=1286&appType=mobile_detail_web&isAndroid=true&isIOS=false&isMobile=true&cookie_enabled=true&screen_width=393&screen_height=882&browser_language=zh-CN&browser_platform=MacIntel&browser_name=Chrome&browser_version=85.0.4183.83&browser_online=true&timezone_name=Asia%2FShanghai"
time.sleep(0.1)
ws.send(real_arg)
ws.run_forever()
except KeyboardInterrupt:
ws.close()

爬虫调用者

import time

import requests
import json
import urllib3 from toutiao2_文件方式.get_user_id import get_user, CG_Client urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) def open_user():
with open('./user.txt', 'r', encoding='utf-8') as f:
user = json.loads(f.read())
f.close()
return user def open_data():
with open('./data.txt', 'r', encoding='utf-8') as f:
data = json.loads(f.read())
f.close()
return data # media_id换user_id
def start_ocean_toutiao_user_id(media_id):
data = {
'media_id': media_id,
}
requests.get('http://127.0.0.1:4007/get_user_id', params=data, timeout=3)
time.sleep(2)
response = open_user()
res_media_id = response.get('data').get('media_id')
if int(res_media_id) == int(media_id):
user_id = response.get('data').get('user_id')
return user_id
else:
print('media不对应,请检查')
return None # 通过websocket获取数据
def start_ocean_toutiao_data(user_id, offset):
if user_id == None:
print('没有获取到user_id,请检查原因。可能消息堆积错误')
return None
data = {
'user_id': user_id,
'offset': offset
}
requests.get('http://127.0.0.1:4007/get_data', params=data, timeout=3)
response = open_data()
return response def get_response(media_id,offset):
user_id = start_ocean_toutiao_user_id(media_id)
print(user_id)
data = start_ocean_toutiao_data(user_id, offset)
print(data)
return data if __name__ == '__main__':
for i in range(1):
offset = 1587744000
# media_id = 6860767764
media_id = 6989633739
user_id = start_ocean_toutiao_user_id(media_id)
print(user_id)
# user_id = 6860406890
data = start_ocean_toutiao_data(user_id, offset)
print(data)
get_response(media_id, offset)
pass

websocket直接绕过JS加密的方式的更多相关文章

  1. 使用selenium进行密码破解(绕过账号密码JS加密)

    经常碰到网站,账号密码通过js加密后进行提交.通过burp拦截抓到的账号密码是加密后的,所以无法通过burp instruder进行破解.只能模拟浏览器填写表单并点击登录按钮进行破解.于是想到了自动化 ...

  2. AES加密解密——AES在JavaWeb项目中前台JS加密,后台Java解密的使用

    一:前言 在软件开发中,经常要对数据进行传输,数据在传输的过程中可能被拦截,被监听,所以在传输数据的时候使用数据的原始内容进行传输的话,安全隐患是非常大的.因此就要对需要传输的数据进行在客户端进行加密 ...

  3. 爬虫之图片懒加载技术及js加密

    图片懒加载 图片懒加载概念: 图片懒加载是一种网页优化技术.图片作为一种网络资源,在被请求时也与普通静态资源一样,将占用网络资源,而一次性将整个页面的所有图片加载完,将大大增加页面的首屏加载时间.为了 ...

  4. 爬虫破解js加密(一) 有道词典js加密参数 sign破解

    在爬虫过程中,经常给服务器造成压力(比如耗尽CPU,内存,带宽等),为了减少不必要的访问(比如爬虫),网页开发者就发明了反爬虫技术. 常见的反爬虫技术有封ip,user_agent,字体库,js加密, ...

  5. 当爬虫遇到js加密

    当爬虫遇到js加密 我们在做python爬虫的时候经常会遇到许多的反爬措施,js加密就是其中一种. 破解js加密的方法也有很多种: 1.直接驱动浏览器抓取数据,无视js加密. 2.找到本地加密的js代 ...

  6. post 传递参数中包含 html 代码解决办法,js加密,.net解密

    今天遇到一个问题,就是用post方式传递参数,程序在vs中完美调试,但是在iis中,就无法运行了,显示传递的参数获取不到,报错了,查看浏览器请求情况,错误500,服务器内部错误,当时第一想法是接收方式 ...

  7. js 加密 crypto-js des加密

    js 加密 crypto-js    https://www.npmjs.com/package/crypto-js   DES  举例:   js 引入:   <script src=&quo ...

  8. js中对arry数组的各种操作小结 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据 web前端url传递值 js加密解密 HTML中让表单input等文本框为只读不可编辑的方法 js监听用户的键盘敲击事件,兼容各大主流浏览器 HTML特殊字符

    js中对arry数组的各种操作小结   最近工作比较轻松,于是就花时间从头到尾的对js进行了详细的学习和复习,在看书的过程中,发现自己平时在做项目的过程中有很多地方想得不过全面,写的不够合理,所以说啊 ...

  9. python爬虫爬小说网站涉及到(js加密,CSS加密)

    我是对于xxxx小说网进行爬取只讲思路不展示代码请见谅 一.涉及到的反爬 js加密 css加密 请求头中的User-Agent以及 cookie 二.思路 1.对于js加密 对于有js加密信息,我们一 ...

随机推荐

  1. 程序员深夜惨遭老婆鄙视,原因竟是CAS原理太简单?| 每一张图都力求精美

    悟空 种树比较好的时间是十年前,其次是现在. 自主开发了Java学习平台.PMP刷题小程序.目前主修Java.多线程.SpringBoot.SpringCloud.k8s. 本公众号不限于分享技术,也 ...

  2. java23种设计模式——五、建造者模式

    源码在我的github和gitee中获取 目录 java23种设计模式-- 一.设计模式介绍 java23种设计模式-- 二.单例模式 java23种设计模式--三.工厂模式 java23种设计模式- ...

  3. [CSP-S2019]划分 题解

    CSP-S2 2019 D2T2 考场上读完题感觉是DP就直接扔了开T3了,考完才发现部分分好像不难拿,枯了 题意分析 给出一个数列,要求将其分成几段,使每段的和非严格递增,求最小的每段的和的平方和. ...

  4. 【WEB自动化测试之控件定位】基于HTML5控件的唯一控件属性定位

      一.WEB控件定位是什么 要想弄懂这个问题,我们还是基于实践来学习.我们先来看一条入门级别自动化测试用例的构成. DemoCase:正确用户名和密码登录博客园,登录成功 URL: https:// ...

  5. 常用Oracle SQL集锦

    常用dml和query开并行 --开并行 ALTER SESSION FORCE PARALLEL DML PARALLEL 16; ALTER SESSION FORCE PARALLEL QUER ...

  6. 科赫雪花利用python海龟绘图代码

    #KochDraw.py import turtle //海龟绘图 def koch(size, n): if n == 0: turtle.fd(size) else: for angle in [ ...

  7. springBoot整合spring security实现权限管理(单体应用版)--筑基初期

    写在前面 在前面的学习当中,我们对spring security有了一个小小的认识,接下来我们整合目前的主流框架springBoot,实现权限的管理. 在这之前,假定你已经了解了基于资源的权限管理模型 ...

  8. 1.OpenGL mac开发环境搭建记录

    1.安装GLEW 和GLFW,转摘至:https://www.cnblogs.com/pretty-guy/p/11357793.html 2.开始测试,整个工程报错,关键信息如下: code sig ...

  9. webpack3.10.0(入门系列基本概念1)

    一.概念 webpack的核心是一个用于现代JavaScript应用程序的静态模块打包程序.当webpack处理您的应用程序时,它会递归地构建一个依赖图,其中包含应用程序所需的每个模块,然后将所有这些 ...

  10. mysql如何查询多样同样的表/sql分表查询、java项目日志表分表的开发思路/按月分表

    之前开发的一个监控系统,数据库的日志表是单表,虽然现在数据还不大并且做了查询sql优化,不过以后数据库的日志表数据肯定会越来越庞大,将会导致查询缓慢,所以把日志表改成分表,日志表可以按时间做水平分表, ...