feat: 打卡记录拉取/缺卡统计工具(iEPMS token直连, 无需签名)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""mitmproxy addon: append every HTTP flow to a JSONL file.
|
||||
|
||||
Usage:
|
||||
mitmdump -s tools/capture/dump_flows.py --set dump_path=data/captures/flows.jsonl
|
||||
"""
|
||||
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
from mitmproxy import ctx, http
|
||||
|
||||
|
||||
def _body(message: http.Message | None) -> dict | None:
|
||||
if message is None:
|
||||
return None
|
||||
raw = message.get_content(strict=False) or b""
|
||||
try:
|
||||
return {"text": raw.decode("utf-8"), "size": len(raw)}
|
||||
except UnicodeDecodeError:
|
||||
return {"b64": base64.b64encode(raw).decode(), "size": len(raw)}
|
||||
|
||||
|
||||
class DumpFlows:
|
||||
def load(self, loader):
|
||||
loader.add_option("dump_path", str, "data/captures/flows.jsonl", "JSONL output path")
|
||||
|
||||
def response(self, flow: http.HTTPFlow):
|
||||
self._write(flow)
|
||||
|
||||
def error(self, flow: http.HTTPFlow):
|
||||
self._write(flow)
|
||||
|
||||
def _write(self, flow: http.HTTPFlow):
|
||||
req, resp = flow.request, flow.response
|
||||
record = {
|
||||
"ts": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(req.timestamp_start)),
|
||||
"method": req.method,
|
||||
"url": req.pretty_url,
|
||||
"req_headers": list(req.headers.items(multi=True)),
|
||||
"req_body": _body(req),
|
||||
"status": resp.status_code if resp else None,
|
||||
"resp_headers": list(resp.headers.items(multi=True)) if resp else None,
|
||||
"resp_body": _body(resp),
|
||||
"error": str(flow.error) if flow.error else None,
|
||||
}
|
||||
path = ctx.options.dump_path
|
||||
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
||||
with open(path, "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps(record, ensure_ascii=False) + "\n")
|
||||
|
||||
|
||||
addons = [DumpFlows()]
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/system/bin/sh
|
||||
# Temporarily trust a CA system-wide on Android 14+ (APEX conscrypt store).
|
||||
# Effective until reboot. Run as root: sh inject_ca.sh /data/local/tmp/<hash>.0
|
||||
CERT="$1"
|
||||
DIR=/data/local/tmp/cacerts
|
||||
APEX=/apex/com.android.conscrypt/cacerts
|
||||
|
||||
[ -f "$CERT" ] || { echo "cert not found: $CERT"; exit 1; }
|
||||
|
||||
rm -rf "$DIR"
|
||||
mkdir -p "$DIR"
|
||||
cp "$APEX"/* "$DIR"/
|
||||
cp "$CERT" "$DIR"/
|
||||
chown -R root:root "$DIR"
|
||||
chmod 755 "$DIR"
|
||||
chmod 644 "$DIR"/*
|
||||
chcon -R u:object_r:system_file:s0 "$DIR"
|
||||
echo "certs prepared: $(ls "$DIR" | wc -l)"
|
||||
|
||||
bind_into() {
|
||||
nsenter --mount=/proc/$1/ns/mnt -- /system/bin/mount --bind "$DIR" "$APEX" 2>/dev/null
|
||||
}
|
||||
|
||||
ZYGOTES="$(pidof zygote) $(pidof zygote64)"
|
||||
for Z in $ZYGOTES; do
|
||||
bind_into "$Z" && echo "zygote $Z ok"
|
||||
done
|
||||
|
||||
for Z in $ZYGOTES; do
|
||||
for P in $(ps -o PID= -P "$Z"); do
|
||||
bind_into "$P" &
|
||||
done
|
||||
done
|
||||
wait
|
||||
echo done
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Print full details of captured flows by index.
|
||||
|
||||
Usage:
|
||||
python tools/capture/show.py <index> [index ...] [--file flows.jsonl] [--max N]
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def fmt_body(body: dict | None, limit: int) -> str:
|
||||
if not body:
|
||||
return "<empty>"
|
||||
text = body.get("text")
|
||||
if text is None:
|
||||
return f"<binary {body['size']} bytes, b64>"
|
||||
try:
|
||||
text = json.dumps(json.loads(text), ensure_ascii=False, indent=2)
|
||||
except ValueError:
|
||||
pass
|
||||
return text if len(text) <= limit else text[:limit] + f"\n... <{len(text) - limit} more chars>"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("indexes", nargs="+", type=int)
|
||||
ap.add_argument("--file", default="data/captures/flows.jsonl")
|
||||
ap.add_argument("--max", type=int, default=4000)
|
||||
args = ap.parse_args()
|
||||
|
||||
lines = Path(args.file).read_text(encoding="utf-8").splitlines()
|
||||
for i in args.indexes:
|
||||
r = json.loads(lines[i])
|
||||
print(f"===== [{i}] {r['ts']} {r['method']} {r['url']}")
|
||||
print("--- request headers")
|
||||
for k, v in r["req_headers"]:
|
||||
print(f"{k}: {v}")
|
||||
print("--- request body")
|
||||
print(fmt_body(r["req_body"], args.max))
|
||||
print(f"--- response {r['status']} headers")
|
||||
for k, v in r["resp_headers"] or []:
|
||||
print(f"{k}: {v}")
|
||||
print("--- response body")
|
||||
print(fmt_body(r["resp_body"], args.max))
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Print a one-line summary for each captured flow.
|
||||
|
||||
Usage:
|
||||
python tools/capture/summarize.py [flows.jsonl] [keyword ...]
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = sys.argv[1:]
|
||||
path = Path(args[0]) if args and args[0].endswith(".jsonl") else Path("data/captures/flows.jsonl")
|
||||
keywords = [a.lower() for a in args if not a.endswith(".jsonl")]
|
||||
|
||||
for i, line in enumerate(path.read_text(encoding="utf-8").splitlines()):
|
||||
r = json.loads(line)
|
||||
if keywords and not any(k in line.lower() for k in keywords):
|
||||
continue
|
||||
size = (r["resp_body"] or {}).get("size", 0)
|
||||
print(f"{i:4d} {r['ts'][11:]} {r['method']:6s} {r['status']} {size:7d} {r['url'][:150]}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user