Reconstructs and verifies mobile app HTTP API signatures, headers (sign/token/nonce), and encrypted payloads into standalone Python scripts during authorized security audits. Use when diffing mitmproxy/Burp requests, tracing OkHttp/Retrofit/NSURLSession interceptors to Java/ObjC/JNI crypto routines, or verifying AES/HMAC/RSA/Protobuf Python implementations against captured ground-truth test vectors.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Protocol Sign Reconstruct?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/muyang520-protocol-sign-reconstruct)
---
name: protocol-sign-reconstruct
description: >-
Reconstructs and verifies mobile app HTTP API signatures, headers (sign/token/nonce), and encrypted payloads into standalone Python scripts during authorized security audits.
Use when diffing mitmproxy/Burp requests, tracing OkHttp/Retrofit/NSURLSession interceptors to Java/ObjC/JNI crypto routines,
or verifying AES/HMAC/RSA/Protobuf Python implementations against captured ground-truth test vectors.
---
# Mobile API Signature & Protocol Reconstruction SOP
The #1 failure mode when asking an LLM to reconstruct an Android/iOS request signature (`X-Sign`, `sign`, `wua`, encrypted body) is **unverified guessing**: the model writes a plausible-looking Python AES/HMAC script that produces a completely different hash from the real app packet due to subtle byte-encoding, parameter-sorting, IV, or Hex-case mismatches.
Follow this **4-step Ground-Truth Test Vector Loop** strictly. **Never declare an algorithm "reconstructed" until your standalone Python script reproduces the exact captured signature byte-for-byte.**
---
## Step 1: Multi-Packet Differential Triage (`mitmproxy-mcp` / `Burp MCP`)
Run the bundled HTTP packet differ on 2–3 captured raw HTTP requests to automatically classify timestamps, UUID nonces, and 128/160/256-bit hex or Base64 block-aligned signatures:
```bash
python skills/protocol-sign-reconstruct/scripts/http_packet_differ.py req1.http req2.http req3.http
```
- **Bundled Helper**: [http_packet_differ.py](./scripts/http_packet_differ.py)
Capture at least **3 controlled requests** to the same endpoint before opening a decompiler:
1. **Request A & Request B (Identical action, 5 seconds apart)**:
- Fields that stay constant -> static app key, device ID, SDK version.
- Fields that change -> `timestamp` (10-digit sec vs 13-digit ms), `nonce` / `uuid`, and the target `sign`!
2. **Request C (Change exactly 1 query/body character, e.g., `page=1` -> `page=2`)**:
- Confirm whether query params, JSON body, or custom headers (`X-Device-Id`, `Authorization`) are included in the signature input.
3. **Check Output Length & Encoding**:
- `32` hex chars (`16` bytes) -> MD5, HMAC-MD5, or AES-128 block.
- `40` hex chars (`20` bytes) -> SHA-1 / HMAC-SHA1.
- `64` hex chars (`32` bytes) -> SHA-256 / HMAC-SHA256 / SM3.
- Base64 (`=` padding or URL-safe `-_`) -> check decoded byte length (`len(raw)` multiple of 16 => block cipher AES/SM4 CBC/ECB; `12 + N + 16` => AES-GCM `[nonce || ciphertext || tag]`).
---
## Step 2: Locate the Interceptor Injection Point (Top-Down, Not Bottom-Up)
Do **not** search `"MD5"` or `"AES"` globally across a 50 MB APK (returns 500+ irrelevant analytics SDK hits). Trace **backward from the exact header/field name**:
1. **Android (`jadx-ai-mcp`)**:
- Search exact header string (e.g., `"X-Sign"`, `"x-mini-wua"`).
- If built dynamically, search `okhttp3.Interceptor` implementations (`chain.request().newBuilder().addHeader(...)`).
2. **iOS (`ida-pro-mcp` / `GhidraMCP` / `ios-macho-re`)**:
- Search selector `setValue:forHTTPHeaderField:` or `allHTTPHeaderFields` cross-references.
---
## Step 3: Capture One Ground-Truth Test Vector via Frida
Before writing Python code, hook the boundary function (Java `SignUtil.sign(...)` or JNI `RegisterNatives` target) and dump **one complete ground-truth tuple** from a real request:
- `raw_plaintext_hex` (exact bytes fed into hash/cipher — eliminates UTF-8 vs Latin-1 and `\r\n` vs `\n` ambiguity!)
- `raw_plaintext_utf8` (human-readable canonical string showing key sorting, delimiter `&`, prefix/suffix salt)
- `key_hex` & `iv_hex` (exact key/IV bytes at runtime, avoiding static `.init_array` obfuscation traps)
- `expected_output` (exact string sent over the wire)
---
## Step 4: Deterministic Python Verification Script
Write and execute a self-checking Python script (`pycryptodome` / `hashlib` / `hmac`) that asserts `actual == expected_output`. Check these **6 classic mismatch pitfalls** whenever `actual != expected`:
1. **Hex Case**: Lowercase `.hexdigest()` vs uppercase `.hexdigest().upper()` before outer Base64 or secondary hashing!
2. **Hash Chaining (Hex String vs Raw Digest Bytes)**: Did the app feed `hashlib.md5(x).digest()` (16 raw bytes) or `hashlib.md5(x).hexdigest().encode()` (32 ASCII bytes) into the next stage?
3. **JSON Canonicalization**: `json.dumps(obj, separators=(',', ':'), ensure_ascii=False)` (no spaces after `:` and `,`, unescaped UTF-8 CJK characters!).
4. **URL Encoding Case & Safe Chars**: `urllib.parse.quote(v, safe='')` (`%2F` uppercase vs `%2f`, space as `%20` vs `+`).
5. **Signed Java `byte` Bug**: Custom Java byte-to-hex loops without `& 0xff` turn negative bytes into 8-char `ffffffxx` strings or drop leading zeros (`Integer.toHexString(b & 0xff)` without zero-padding!).
6. **Zero-Padding vs PKCS#7**: Native C/C++ AES implementations frequently pad trailing blocks with `0x00` instead of PKCS#7.
```python
# Mandatory verification template before reporting completion
expected = "PASTE_CAPTURED_WIRE_SIGN_HERE"
actual = compute_sign(sample_params, timestamp="1732953600000", nonce="abc123")
assert actual == expected, f"Mismatch!\nExpected: {expected}\nActual: {actual}"
print("[VERIFIED] 1:1 exact match against live packet!")
```