【IP地址防护】-预防WebRTC泄露

【IP地址防护】-预防WebRTC泄露

什么是 WebRTC 泄露(WebRTC Leak),如何预防

WebRTC(Web Real-Time Communication)是浏览器提供的实时音视频与点对点数据通道技术。WebRTC 泄露 指的是在使用浏览器或某些应用时,WebRTC 的连接流程(ICE 候选交换)意外暴露了本地或真实公网 IP 地址,导致即便你在用 VPN/代理,目标网站或第三方仍可能看到你的真实 IP 地址或局域网地址,从而破坏隐私与匿名性。

WebRTC 泄露简要原理

  1. 建立 P2P 连接时,浏览器会通过 STUN/TURN server 获取 ICE candidates(候选连接地址),这些候选包括:

    • host(本机局域网 IP)
    • srflx(通过 STUN 获得的公网映射 IP)
    • relay(通过 TURN 中继的地址)
  2. 如果浏览器本地或网页脚本暴露/发送了 hostsrflx 类型的候选,第三方就可能获知本机真实 IP(包括局域网 IP 与公网真实 IP)。

  3. VPN/代理通常只影响浏览器的普通 HTTP(S) 流量,但 WebRTC 的 STUN 请求可能绕过这些路径,从而暴露真实地址。

chrome需要安装扩展来避免WebRTC 泄露,推荐一个开源扩展
chrome扩展地址

使用 IPPure 检查 WebRTC 泄露情况

安装前:

IPPure链接地址

安装后 :


阅读更多
【爬虫脚本自动化录制】playwright-codegen使用教程

【爬虫脚本自动化录制】playwright-codegen使用教程

前言

在做 Web 自动化测试、爬虫脚本开发时,手动写定位、写操作步骤往往耗时又容易出错。Playwright 官方提供了一个零代码录制神器:codegen,只需要在浏览器里用鼠标点击,就能自动生成可直接运行的 Python/Java/JS 自动化代码,极大提升开发效率。


什么是 playwright codegen?

codegen 是 Playwright 内置的交互式录制工具,核心功能:

  • 记录鼠标点击、输入、选择、滚动、切换页面等操作

  • 实时生成高质量、可直接运行的代码

  • 自动识别 iframe、弹窗、下拉框等复杂场景

  • 支持 Python / Node. js / Java / C# 多语言导出

适用场景:快速生成登录脚本、表单提交、页面遍历、爬虫操作等。


环境准备

安装 Playwright

阅读更多
【爬虫项目解析】-小鹅通m3u8逆向解密

【爬虫项目解析】-小鹅通m3u8逆向解密

打开 F12, 勾选保留日志,进行手动登录,找到请求方法为 POST 的信息,这就是登录时向服务器发送的请求,找到 cookie 的信息并记录。

点击负载可以找到发起登录请求时传入的参数信息

  • ticket:验证码票据(用来校验你输入的验证码)

  • randstr:随机字符串(防重放攻击)

  • verification_type:验证类型(1 通常代表密码登录)

  • session_id:当前会话 ID

  • phone:你的登录手机号(明文)

  • password:你的密码(这里看起来是部分掩码显示,实际传输时大概率是加密或脱敏后的)

  • keep_login:是否记住登录状态(false 代表不记住)

  • nation_login:国家 / 地区登录标识(1 通常代表国内)

播放视频时产生一系列 Session 会话,这些视频相关行都是客户端向服务器请求的视频分片 TS分片的会话,类型时 video/mp2t,也就是 HLS 流媒体切片文件,第四第五列分别是目标服务器域名以及请求的视频分片 url 路径,但是知识 ts 切片,需要找到完整的 m3u8 文件

ctrl+f 搜索 m3u8 的session会话

请求头中包含 url 信息,需要加上 host 域名前缀

阅读更多
【cv-AI攻防】-Task1:赛题方案解读

【cv-AI攻防】-Task1:赛题方案解读

步骤一:构建YOLO数据集

由于比赛原始数据集较大,我们采样部分数据构建训练集和验证集:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if os.path.exists('yolo_seg_dataset'):
shutil.rmtree('yolo_seg_dataset')

os.makedirs('yolo_seg_dataset/train')
os.makedirs('yolo_seg_dataset/valid')

def normalize_polygon(polygon, img_width, img_height):
return [(x / img_width, y / img_height) for x, y in polygon]

# 采样训练集
for row in training_anno.iloc[:10000].iterrows():
shutil.copy(row[1].Path, 'yolo_seg_dataset/train')

img = cv2.imread(row[1].Path)
img_height, img_width = img.shape[:2]
txt_filename = os.path.join('yolo_seg_dataset/train/' + row[1].Path.split('/')[-1][:-4] + '.txt')
with open(txt_filename, 'w') as up:
for polygon in row[1].Polygons:
normalized_polygon = normalize_polygon(polygon, img_width, img_height)
normalized_coords = ' '.join([f'{coord[0]:.3f} {coord[1]:.3f}' for coord in normalized_polygon])
up.write(f'0 {normalized_coords}\n')

# 采用验证集
for row in training_anno.iloc[10000:10150].iterrows():
shutil.copy(row[1].Path, 'yolo_seg_dataset/valid')

img = cv2.imread(row[1].Path)
img_height, img_width = img.shape[:2]
txt_filename = os.path.join('yolo_seg_dataset/valid/' + row[1].Path.split('/')[-1][:-4] + '.txt')
with open(txt_filename, 'w') as up:
for polygon in row[1].Polygons:
normalized_polygon = normalize_polygon(polygon, img_width, img_height)
normalized_coords = ' '.join([f'{coord[0]:.3f} {coord[1]:.3f}' for coord in normalized_polygon])
up.write(f'0 {normalized_coords}\n')

逐行代码分析

好的,我们逐行分析这段代码,它的主要功能是将训练集和验证集的数据从原始数据集中复制到新的目录中,并将多边形的坐标标准化为相对坐标。

代码逐行分析

1
2
if os.path.exists('yolo_seg_dataset'):
shutil.rmtree('yolo_seg_dataset')
  • 功能: 检查yolo_seg_dataset目录是否存在。如果存在,则使用shutil.rmtree删除该目录及其内容。shutil常用于文件与目录的处理。

  • 目的: 确保每次运行代码时,数据集是干净的,没有旧的数据。

1
2
os.makedirs('yolo_seg_dataset/train')
os.makedirs('yolo_seg_dataset/valid')
  • 功能: 创建两个新的子目录trainvalid,用于存放训练集和验证集数据。

  • 目的: 为之后的文件复制和标签文件创建所需的目录结构。

阅读更多
【lagent】agent搭建

【lagent】agent搭建

启动webui服务

使用lmdeploy启动一个api_server

1
2
conda activate agent_camp3
lmdeploy serve api_server /share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat --model-name internlm2_5-7b-chat

另开一个终端使用stremlit启动agent_web应用

1
2
3
cd /root/agent_camp3/lagent
conda activate agent_camp3
streamlit run examples/internlm2_agent_web_demo.py

本地powershell建立ssh连接,进行端口映射

Q&A

阅读更多
【评测】opencompass-司南
【Fine-tuning】XTuner微调个人小助手
【RAG】使用Llamaindex框架部署InternLM2-1.8B

【RAG】使用Llamaindex框架部署InternLM2-1.8B

一、前置知识

  • 给模型注入新知识的方式
    • 内部方式:更新模型的权重,但训练代价较大。
    • 外部方式:给模型注入额外的上下文或外部信息,不改变其权重。
  • RAG 工作原理
    • 将问题编码成向量,在向量数据库中找到最相关的文档块(top-k chunks)。
    • 将知识源分割成小块,编码成向量并存储在向量数据库中。
    • 将检索到的文档块与原始问题一起作为提示输入到 LLM 中,生成最终的回答。
  • RAG 效果比对
    • 由于 xtuner 是较新的框架,InternLM2-Chat-1.8B 训练数据库中未收录相关信息,使用 RAG 前问答均未给出准确答案,使用后能获得想要的答案。

二、环境、模型准备

(一)配置基础环境

  • Intern Studio 服务器上部署 LlamaIndex

    • 打开 Intern Studio 界面,点击 创建开发机 配置开发机系统。
    • 填写 开发机名称 后,点击 选择镜像 使用 Cuda11.7-conda 镜像,在资源配置中选择 30% A100 * 1 的选项,立即创建开发机器。
    • 进入开发机后,创建新的 conda 环境,命名为 llamaindex,运行以下命令:
    1
    2
    3
    4
    5
    conda create -n llamaindex python=3.10
    conda env list
    conda activate llamaindex
    conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
    pip install einops==0.7.0 protobuf==5.26.1
    • 环境激活后,命令行左边会显示当前环境名称。

(二)安装 LlamaIndex

  • 安装 LlamaIndex 和相关的包:

    1
    2
    conda activate llamaindex
    pip install llama-index==0.10.38 llama-index-llms-huggingface==0.2.0 "transformers[torch]==4.41.1" "huggingface_hub[inference]==0.23.1" huggingface_hub==0.23.1 sentence-transformers==2.7.0 sentencepiece==0.2.0

(三)下载 Sentence Transformer 词嵌入模型

  • 新建一个 python 文件,贴入以下代码:

    1
    2
    3
    4
    5
    6
    7
    import os

    # 设置环境变量
    os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

    # 下载模型
    os.system('huggingface-cli download --resume-download sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 --local-dir /root/model/sentence-transformer')
  • /root/llamaindex_demo 目录下执行该脚本自动开始下载。

(四)下载 NLTK 相关资源

阅读更多
【Prompt Engineering】LangGPT结构化提示词编写

【Prompt Engineering】LangGPT结构化提示词编写

前言

在日常使用大模型时,我发现它经常在数字比对这类基础问题上出错,并且输出结果很不严谨。为了解决这个问题,我尝试使用Prompt Engineering,并在网上找到了一个开源的「结构化提示词框架」-- LangGPT,以下是我的使用过程记录。


实现步骤

step0:前期准备

  1. 创建虚拟环境->激活虚拟环境->安装必要包文件

  2. 创建项目路径->进入项目

  3. 安装必要软件,如tmux

step1:模型部署模型下载->部署模型为OpenAI server->图形化界面调用
‬⁠⁠⁠
step3:langgpt结构化提示词⁠‬编写⁠‍‬⁠‬‬‬‌‌‌‍‌‌
偷懒大法:GPTS有LangGPT提示词专家,用大模型生成即可


tmux使用

tmux可以在终端中创建终端,将进程维持在后台。

阅读更多
8G显存玩转书生大模型Demo

8G显存玩转书生大模型Demo

环境配置

1
2
3
4
5
6
7
8
9
10
11
12
13
# 创建环境
conda create -n demo python=3.10 -y
# 激活环境
conda activate demo
# 安装 torch
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia -y
# 安装其他依赖
pip install transformers==4.38
pip install sentencepiece==0.1.99
pip install einops==0.8.0
pip install protobuf==5.27.2
pip install accelerate==0.33.0
pip install streamlit==1.37.0

InternLM2-Chat-1.8B 模型部署

一、用Cli Demo 部署

1.创建demo文件夹,用于存放代码。并创建 cli_demo.py文件

1
2
mkdir -p /root/demo
touch /root/demo/cli_demo.py

其中cli_demo.py 的代码为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM


model_name_or_path = "/root/share/new_models/Shanghai_AI_Laboratory/internlm2-chat-1_8b"

tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True, device_map='cuda:0')
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='cuda:0')
model = model.eval()

system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文.
"""

messages = [(system_prompt, '')]

print("=============Welcome to InternLM chatbot, type 'exit' to exit.=============")

while True:
input_text = input("\nUser >>> ")
input_text = input_text.replace(' ', '')
if input_text == "exit":
break

length = 0
for response, _ in model.stream_chat(tokenizer, input_text, messages):
if response is not None:
print(response[length:], flush=True, end="")
length = len(response)
阅读更多