爬虫逆向实战(十二)--某交易所登录

news/2024/7/19 8:35:48 标签: 爬虫

一、数据接口分析

主页地址:某交易所

1、抓包

通过抓包可以发现登录是通过表单提交的
在这里插入图片描述

2、判断是否有加密参数

  1. 请求参数是否加密?
    通过查看“载荷”模块,可以发现有两个加密参数passwordexecution
    在这里插入图片描述
  2. 请求头是否加密?
  3. 响应是否加密?
  4. cookie是否加密?

二、加密位置定位

1、password

(1)看启动器

因为这个登录是表单提交,所以无法通过启动器点位

(2)搜索关键字

通过搜索关键字password =可以找到password的加密位置
在这里插入图片描述

2、execution

通过搜索关键字execution可以发现,这个值是直接写在html静态页面中的。
在这里插入图片描述

三、扣js代码

从定位到的password加密位置可以发现,网站仅仅使用了一个encode64方法转码,但是为了防止网站是改写的,我们还是先测试一下。将刚刚抓到的包中的password密文进行转码,可以发现成功转码成了明文,这就说明这个网站真的是只转了一下码。所以我们也就没有必要扣js代码了。在这里插入图片描述
execution是直接写在静态页面上的,所以我们只需要先请求静态页面,再使用正则表达式'<input type="hidden" name="execution" value="(.*?)"'execution的值匹配出来就可以了。

四、验证码

1、接口分析

通过点击图片更换验证码可以发现,每次更换验证码,网站都会发一个包请求sso/picture
在这里插入图片描述
通过查看“载荷”模块,可以发现这个请求会携带receiverenuuidmarkrand四个参数。其中mark是账号,rand是随机数,所以这两个参数不需要关心。而receiverenuuid这两个参数,我们仔细观察抓包可以发现,这两个参数来自于一个enuuid的接口
在这里插入图片描述
所以我们可以请求这个接口获取到这两个参数。
当我们在输入框输入图片验证码时,网站会请求sso/validlogin接口,携带输入的验证码来校验我们输入的验证码。
在这里插入图片描述

五、发送请求

1、思路

结合上面的分析,我们可以先请求html静态页面获取到execution参数,然后请求enuuid接口获取到uuidenuuid参数,获取到这两个参数之后,我们就可以获取图片验证码了,请求sso/picture接口获取到图片验证码,然后识别图片验证码(我这里使用的打码平台进行的识别)。携带识别出的验证码请求sso/validlogin接口,返回成功响应后,将密码进行encode64转码,再发包进行登录即可。

2、源代码

"""
Email:912917367@qq.com
Date: 2023/8/14 13:37
"""
import base64
import re
import time

import requests

from utils.chaojiying import ChaojiyingClient


class Spider:
    def __init__(self, username, password):
        self.session = requests.session()
        self.session.headers = {
            "Origin": "https://owssso.szse.cn",
            "Referer": "https://owssso.szse.cn/sso/login?service=https://www.szse.cn/application/userCenter/accountinfo/&locale=zh",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
        }
        self.execution = ''
        self.uuid = ''
        self.enuuid = ''
        self.pic_str = ''
        self.username = username
        self.password = password

    def get_execution(self):
        url = 'https://owssso.szse.cn/sso/login?service=https://www.szse.cn/application/userCenter/accountinfo/&locale=zh'
        response = self.session.get(url=url)
        pattern = r'<input type="hidden" name="execution" value="(.*?)"'
        self.execution = re.findall(pattern, response.text)[0]

    def get_uuid(self):
        url = "https://owssso.szse.cn/sso/enuuid"
        params = {
            "service": "https://www.szse.cn/application/userCenter/accountinfo/",
            "locale": "zh",
            "_": int(time.time() * 1000)
        }
        response = self.session.get(url, params=params)

        info_data = response.json()
        self.uuid = info_data['uuid']
        self.enuuid = info_data['enuuid']

    def get_img_code(self):
        url = "https://owssso.szse.cn/sso/picture"
        params = {
            "receiver": self.uuid,
            "enuuid": self.enuuid,
            "rand": "0.004521081820116013"
        }
        response = self.session.get(url, params=params)

        with open('img.png', 'wb') as f:
            f.write(response.content)

        cjy = ChaojiyingClient('超级鹰账号', '超级鹰密码', '超级鹰应用id')
        im = open('img.png', 'rb').read()
        pic_data = cjy.post_pic(im, 1902)
        self.pic_str = pic_data['pic_str']
        print(self.pic_str)

    def check_img_code(self):
        url = "https://owssso.szse.cn/sso/validlogin"
        params = {
            "text": self.pic_str,
            "receiver": self.uuid,
            "mark": self.username,
            "type": "3",
            "_": int(time.time() * 1000)
        }
        response = self.session.get(url, params=params)
        if '正确' in response.json()['message']:
            return True
        return False

    def login(self):
        encoded_bytes = base64.b64encode(self.password.encode('utf-8'))
        pwd = encoded_bytes.decode('utf-8')

        url = "https://owssso.szse.cn/sso/login"
        params = {
            "service": "https://www.szse.cn/application/userCenter/accountinfo/",
            "locale": "zh"
        }
        data = {
            "receiver": self.username,
            "iframe": "false",
            "password": pwd,
            "text": self.pic_str,
            "uuid": self.uuid,
            "type": "PL",
            "execution": self.execution,
            "_eventId": "submit"
        }
        response = self.session.post(url, params=params, data=data)

        print(response.text)
        print(response)

    def run(self):
        self.get_execution()
        self.get_uuid()
        while True:
            self.get_img_code()
            if self.check_img_code():
                break
        self.login()


if __name__ == '__main__':
    spider = Spider('账号', '密码')
    spider.run()

http://www.niftyadmin.cn/n/4945756.html

相关文章

【Python】Web学习笔记_flask(5)——会话cookie对象

HTTP是无状态协议&#xff0c;一次请求响应结束后&#xff0c;服务器不会留下对方信息&#xff0c;对于大部分web程序来说&#xff0c;是不方便的&#xff0c;所以有了cookie技术&#xff0c;通过在请求和响应保温中添加cookie数据来保存客户端的状态。 html代码&#xff1a; …

UI界面设置

文章目录 1. 修改 share.html 内容如下&#xff1a;2. 修改 html 文件格式为 utf-83.保存&#xff0c;运行程序4. 访问页面 1. 修改 share.html 内容如下&#xff1a; <!DOCTYPE html><html> <head><meta charset"utf-8"><title>1v1屏…

JVM - 垃圾回收机制

JVM的垃圾回收机制(简称GC) JVM的垃圾回收机制非常强大&#xff0c;是JVM的一个很重要的功能&#xff0c;而且这也是跟对象实例息息相关的&#xff0c;如果对象实例不用了要怎么清除呢&#xff1f; 如何判断对象已经没用了 当JVM认为一个对像已经没用了&#xff0c;就会把这个…

avue表单验证;avue自定义表单验证;avue-curd在配置项中进行验证

avue自定义表单验证 data() {var validateSpeed (rule, value, callback) > {if (value ) {callback(new Error(请输入默认速度));} else if (value < 0 || value > 0.5) {callback(new Error(请输入0-0.5之间的数字));} else {callback();}};var validateDistance …

C++ volatile

volatile 一、volatile 使用场景 volatile 是 C 和 C 中的一个关键字&#xff0c;用于告诉编译器不要对标记为 volatile 的变量进行优化&#xff0c;以确保每次访问都从内存中读取变量的最新值。主要用于以下情况&#xff1a; 硬件寄存器和内存映射设备&#xff1a;在访问硬…

Hadoop的DataNode无法启动的解决方案

Hadoop重启一次&#xff0c;里面的数据需要重新导入&#xff0c;发现无法导入数据&#xff0c;查看jps发现是DataNode没有启动&#xff0c;重新启动发现也无法启动&#xff0c;原因是前面重新启动NameNode&#xff0c;里面的文件格式化一次&#xff0c;DataNode的文件不一致&am…

Python教程(9)——Python变量类型列表list的用法介绍

列表操作 创建列表访问列表更改列表元素增加列表元素修改列表元素删除列表元素 删除列表 在Python中&#xff0c;列表&#xff08;list&#xff09;是一种有序、可变的数据结构&#xff0c;用于存储多个元素。列表可以包含不同类型的元素&#xff0c;包括整数、浮点数、字符串等…

Practices10(数组)|238. 除自身以外数组的乘积、189. 轮转数组(做过)、56. 合并区间(做过)

238. 除自身以外数组的乘积 1.题目&#xff1a; 给你一个整数数组 nums&#xff0c;返回 数组 answer &#xff0c;其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。…