tarpit-guard 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tarpit_guard-0.2.0/LICENSE +21 -0
- tarpit_guard-0.2.0/PKG-INFO +316 -0
- tarpit_guard-0.2.0/README.md +287 -0
- tarpit_guard-0.2.0/pyproject.toml +46 -0
- tarpit_guard-0.2.0/setup.cfg +4 -0
- tarpit_guard-0.2.0/tarpit_guard/__init__.py +4 -0
- tarpit_guard-0.2.0/tarpit_guard/cli.py +87 -0
- tarpit_guard-0.2.0/tarpit_guard/detector.py +184 -0
- tarpit_guard-0.2.0/tarpit_guard/mcp_server.py +66 -0
- tarpit_guard-0.2.0/tarpit_guard.egg-info/PKG-INFO +316 -0
- tarpit_guard-0.2.0/tarpit_guard.egg-info/SOURCES.txt +13 -0
- tarpit_guard-0.2.0/tarpit_guard.egg-info/dependency_links.txt +1 -0
- tarpit_guard-0.2.0/tarpit_guard.egg-info/entry_points.txt +2 -0
- tarpit_guard-0.2.0/tarpit_guard.egg-info/requires.txt +3 -0
- tarpit_guard-0.2.0/tarpit_guard.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maniram
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tarpit-guard
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Flag AI-reverse-engineering tarpits (obfuscated / token-burning code) before you waste a budget analyzing them.
|
|
5
|
+
Author: Maniram
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ManiraM-1/tarpit-guard
|
|
8
|
+
Project-URL: Repository, https://github.com/ManiraM-1/tarpit-guard
|
|
9
|
+
Project-URL: Issues, https://github.com/ManiraM-1/tarpit-guard/issues
|
|
10
|
+
Keywords: mcp,llm,ai-agents,obfuscation,reverse-engineering,static-analysis,security,developer-tools
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Provides-Extra: mcp
|
|
27
|
+
Requires-Dist: fastmcp>=2.0; extra == "mcp"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# 🪤 tarpit-guard
|
|
31
|
+
|
|
32
|
+
**A pre-flight guard for AI code-analysis agents.** It scores a file or repository for signs of deliberate *anti-analysis hardening* — the obfuscation and "token-burning" tricks that tools like [BLA](https://github.com/qybaihe/bla) apply to make AI reverse-engineering expensive — and tells an agent, **before it spends a budget**, whether a target is a tarpit and what to do instead.
|
|
33
|
+
|
|
34
|
+
> One ~1K-token check that prevents a 60K-token mistake.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Table of contents
|
|
39
|
+
|
|
40
|
+
- [The problem](#the-problem)
|
|
41
|
+
- [What this is — and what it is not](#what-this-is--and-what-it-is-not)
|
|
42
|
+
- [How it works](#how-it-works)
|
|
43
|
+
- [Signals](#signals)
|
|
44
|
+
- [Tool fingerprints](#tool-fingerprints)
|
|
45
|
+
- [Scoring and thresholds](#scoring-and-thresholds)
|
|
46
|
+
- [Install](#install)
|
|
47
|
+
- [CLI usage](#cli-usage)
|
|
48
|
+
- [MCP usage (for agents)](#mcp-usage-for-agents)
|
|
49
|
+
- [Example output](#example-output)
|
|
50
|
+
- [Project layout](#project-layout)
|
|
51
|
+
- [Limitations and false positives](#limitations-and-false-positives)
|
|
52
|
+
- [Roadmap](#roadmap)
|
|
53
|
+
- [FAQ](#faq)
|
|
54
|
+
- [License](#license)
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## The problem
|
|
59
|
+
|
|
60
|
+
Source-hardening tools defend software by making it hostile to static analysis. A tiny, readable source file is transformed into a large, deliberately confusing one that still behaves identically:
|
|
61
|
+
|
|
62
|
+
| | Original | Hardened |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| Size | 418 B | 184 KB (**~440×**) |
|
|
65
|
+
| Lines | 15 | 2,998 |
|
|
66
|
+
| Secret string in cleartext | yes | no (encrypted) |
|
|
67
|
+
| Output when run | identical | identical |
|
|
68
|
+
|
|
69
|
+
The hardened file pads real logic with decoy functions, wraps branches behind opaque-predicate math, encrypts string literals behind runtime decoder loops, and plants jargon "canaries" written specifically to mislead a reading agent.
|
|
70
|
+
|
|
71
|
+
For an AI agent, the trap is cost. Read-and-trace the whole thing and you burn input tokens on ingestion and reasoning tokens on dead ends — and often still reach a wrong conclusion. The cheap counter is not to out-analyze the obfuscation; it is to **detect the tarpit first** and switch to dynamic analysis (run it in a sandbox, observe its behavior), which walks past nearly all static obfuscation for almost no tokens.
|
|
72
|
+
|
|
73
|
+
`tarpit-guard` is that detection step.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## What this is — and what it is not
|
|
78
|
+
|
|
79
|
+
**It is** a detector and triage guard. It answers one question: *does this look deliberately hardened, and if so, what is the cheaper way in?* It emits a score, the signals that fired, and a recommended strategy.
|
|
80
|
+
|
|
81
|
+
**It is not** a deobfuscator, a cracker, or a secret extractor. It never reverses anyone's protection or recovers hidden values. That is precisely the reverse-engineering these hardening tools exist to stop — building it would make this project the thing it is meant to warn about. The line is deliberate and permanent: `tarpit-guard` reads *shape*, never *meaning*.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## How it works
|
|
86
|
+
|
|
87
|
+
The engine is pure Python standard library — no dependencies, no network, nothing to install for the core. It runs entirely on local text.
|
|
88
|
+
|
|
89
|
+
1. **Repository sweep** (directory mode): walk the tree, skipping `node_modules`, `.git`, `dist`, `build`, and the like, and look for tool fingerprints.
|
|
90
|
+
2. **Per-file analysis**: for each candidate file, compute a set of cheap structural and statistical signals from the raw text — no execution, no parsing of untrusted code.
|
|
91
|
+
3. **Weighted score**: combine the signals into a 0–100 score and a confidence derived from how many independent signals fired.
|
|
92
|
+
4. **Verdict**: above the threshold, the file is a tarpit; the engine returns the evidence and a recommended strategy instead of a pile of extracted facts.
|
|
93
|
+
|
|
94
|
+
Because every signal is a count or ratio over text, the check is orders of magnitude cheaper than the analysis it protects.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Signals
|
|
99
|
+
|
|
100
|
+
Detection keys on signals that benign code — even heavily minified code — essentially never produces. This is deliberate: the hard problem is not spotting that a file is *machine-generated* (minified bundles are too); it is telling *hostile* obfuscation apart from *ordinary* minification. Size and line-length are explicitly **not** primary signals, because that is exactly what minification trips.
|
|
101
|
+
|
|
102
|
+
| Signal | Weight | What it catches |
|
|
103
|
+
|---|---:|---|
|
|
104
|
+
| `opaque_predicate_density` | 0.28 | `Math.imul` tautology chains that guard real branches behind always-true math (BLA) |
|
|
105
|
+
| `hex_identifier_array` | 0.28 | dense `_0x…` string-array identifiers (javascript-obfuscator family) |
|
|
106
|
+
| `decoder_loops` | 0.22 | `fromCharCode` + `charCodeAt` loops that reconstruct encrypted string literals at runtime |
|
|
107
|
+
| `obfuscator_control_tricks` | 0.12 | self-defending / control-flow tricks (`!![]`, `.split('\|')` dispatch) |
|
|
108
|
+
| `decoy_vocabulary_density` | 0.06 | planted jargon clusters (enclave / attestation / TPM / canary) meant to mislead a reader |
|
|
109
|
+
| `garbled_identifier_ratio` | 0.04 | mangled names such as `encodeFrozenScopeV4ue7` |
|
|
110
|
+
|
|
111
|
+
On top of the weighted score, four **categorical markers** apply a decisive floor, because they are signatures essentially impossible in hand-written or merely-minified code: a dense `_0x` identifier array, three or more runtime decoder loops, `Math.imul` opaque-predicate chains, or repeated `!![]` self-defending tricks. Any one present pushes the file over the line.
|
|
112
|
+
|
|
113
|
+
Conversely, a file **dominated by 1–2 character identifiers** (the minification tell — 60–70% in jQuery/Lodash builds, versus ~10% in hostile files) with **none** of those markers is recognized as benign minification and capped low, with the strategy "read the original source or a source map, not the bundle."
|
|
114
|
+
|
|
115
|
+
The `evidence` block reports the raw counts (`Math.imul`, hex identifiers, decoder pairs, decoy hits, short-identifier ratio, …) so a human or agent can sanity-check *why* a file scored as it did.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Tool fingerprints
|
|
120
|
+
|
|
121
|
+
Some artifacts are near-certain evidence of deliberate hardening on their own, independent of file contents. Directory scans report them separately as a strong standalone signal:
|
|
122
|
+
|
|
123
|
+
| Fingerprint | Tool |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `.bla-hardened/` directory | BLA |
|
|
126
|
+
| `.blarc` | BLA |
|
|
127
|
+
| `bla-harden-summary.json` | BLA |
|
|
128
|
+
|
|
129
|
+
The fingerprint map is a plain table in `detector.py` and is meant to grow as more hardeners are catalogued.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Scoring and thresholds
|
|
134
|
+
|
|
135
|
+
- **Score** — 0–100, the weighted sum of signals.
|
|
136
|
+
- **Confidence** — rises with the number of independent signals that cross their own half-way mark; four or more means full confidence.
|
|
137
|
+
- **Threshold** — default **55**. At or above it, `hardened` is true. Tunable with `--threshold` (CLI) or the `threshold` argument (MCP).
|
|
138
|
+
|
|
139
|
+
### Evaluation
|
|
140
|
+
|
|
141
|
+
`eval_corpus.py` scores a labelled corpus (`corpus/`) of clean source, real
|
|
142
|
+
minified bundles, and hostile obfuscation, and reports false positives /
|
|
143
|
+
negatives. It doubles as a regression test (non-zero exit on any miss).
|
|
144
|
+
|
|
145
|
+
v0.2 results (threshold 55):
|
|
146
|
+
|
|
147
|
+
| Bucket | File | Score | Verdict |
|
|
148
|
+
|---|---|---:|---|
|
|
149
|
+
| clean | jquery.source.js / lodash.source.js | 0.0 | ok |
|
|
150
|
+
| clean | detector.py (contains the decoy word list) | 9.5 | ok |
|
|
151
|
+
| minified | jquery.min.js | 0.0 | ok |
|
|
152
|
+
| minified | lodash.min.js | 0.0 | ok |
|
|
153
|
+
| obfuscated | bla_hardened_app.js | 78.0 | **TARPIT** |
|
|
154
|
+
| obfuscated | js-obfuscator_sample.js | 85.0 | **TARPIT** |
|
|
155
|
+
|
|
156
|
+
**0 false positives, 0 false negatives.** Highest benign score 9.5, lowest
|
|
157
|
+
hostile score 78.0 — a **+68.5** margin, stable across any threshold from ~10 to
|
|
158
|
+
~77. (For contrast, v0.1 leaned on file size and scored minified jQuery *above*
|
|
159
|
+
a real obfuscated file; that regression is what this corpus exists to prevent.)
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Install
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
git clone https://github.com/ManiraM-1/tarpit-guard.git
|
|
167
|
+
cd tarpit-guard
|
|
168
|
+
|
|
169
|
+
pip install -e . # core CLI — standard library only
|
|
170
|
+
pip install -e ".[mcp]" # adds the FastMCP server (fastmcp>=2.0)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Requires Python 3.9+.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## CLI usage
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
tarpit-guard path/to/file.js # score a single file
|
|
181
|
+
tarpit-guard path/to/repo # scan a tree + report fingerprints
|
|
182
|
+
tarpit-guard path/to/repo --quiet # only show flagged files
|
|
183
|
+
tarpit-guard path/to/repo --json # machine-readable report
|
|
184
|
+
tarpit-guard path/to/repo --threshold 45
|
|
185
|
+
|
|
186
|
+
python -m tarpit_guard.cli path/to/file.js # run without installing
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Exit codes** make it a drop-in CI gate:
|
|
190
|
+
|
|
191
|
+
| Code | Meaning |
|
|
192
|
+
|---:|---|
|
|
193
|
+
| `0` | nothing flagged |
|
|
194
|
+
| `1` | at least one tarpit found |
|
|
195
|
+
| `2` | path not found |
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
# e.g. fail a job if a dependency ships hardened artifacts
|
|
199
|
+
- run: tarpit-guard ./vendor --quiet
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## MCP usage (for agents)
|
|
205
|
+
|
|
206
|
+
Run the server:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
python -m tarpit_guard.mcp_server
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
It exposes three tools:
|
|
213
|
+
|
|
214
|
+
| Tool | Use |
|
|
215
|
+
|---|---|
|
|
216
|
+
| `check_file(path)` | score one file before reading it |
|
|
217
|
+
| `check_source(text, label)` | score a raw snippet without touching disk |
|
|
218
|
+
| `scan_repo(root, threshold)` | sweep a tree for fingerprints and tarpit files |
|
|
219
|
+
|
|
220
|
+
**The intended agent loop:**
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
encounter unfamiliar file
|
|
224
|
+
│
|
|
225
|
+
â–¼
|
|
226
|
+
check_file(path)
|
|
227
|
+
│
|
|
228
|
+
hardened? ──no──▶ analyze normally
|
|
229
|
+
│
|
|
230
|
+
yes
|
|
231
|
+
│
|
|
232
|
+
â–¼
|
|
233
|
+
skip the full read →
|
|
234
|
+
run it in a sandbox and observe I/O,
|
|
235
|
+
or escalate to a human
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The guard turns "read everything and hope" into a deliberate, budgeted decision.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Example output
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
$ tarpit-guard ./BLA
|
|
246
|
+
|
|
247
|
+
Tool fingerprints found (strong signal of deliberate hardening):
|
|
248
|
+
[bla] dir: ./BLA/.bla-hardened
|
|
249
|
+
[bla] file: ./BLA/.blarc
|
|
250
|
+
[bla] file: ./BLA/.bla-hardened/bla-harden-summary.json
|
|
251
|
+
|
|
252
|
+
[TARPIT] score= 78 conf=1.00 ./BLA/.bla-hardened/app.js
|
|
253
|
+
182865B / 2998 lines, Math.imul×246, decoder_pairs=8, garbled_idents=190, decoy_hits=487
|
|
254
|
+
fired: opaque_predicate_density, decoder_loops, decoy_vocabulary_density
|
|
255
|
+
-> Treat as a tarpit. Do NOT read the whole file or trace it statically.
|
|
256
|
+
Prefer dynamic analysis (run in a sandbox and observe I/O) or escalate to a human.
|
|
257
|
+
[ok] score= 0.0 conf=0.00 ./BLA/app.js
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Project layout
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
tarpit-guard/
|
|
266
|
+
├── pyproject.toml
|
|
267
|
+
├── README.md
|
|
268
|
+
├── LICENSE
|
|
269
|
+
├── .gitignore
|
|
270
|
+
├── eval_corpus.py # scores corpus/, reports false positives/negatives
|
|
271
|
+
├── corpus/ # labelled samples: clean / minified / obfuscated
|
|
272
|
+
└── tarpit_guard/
|
|
273
|
+
├── __init__.py # public API: analyze_file, analyze_text, repo_fingerprints
|
|
274
|
+
├── detector.py # scoring engine (stdlib only)
|
|
275
|
+
├── cli.py # command-line entry point
|
|
276
|
+
└── mcp_server.py # FastMCP wrapper
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Limitations and false positives
|
|
282
|
+
|
|
283
|
+
This is a v0.2 heuristic, and honesty about its edges matters more than a clean pitch:
|
|
284
|
+
|
|
285
|
+
- **Small corpus.** It is calibrated on two hardeners (BLA, javascript-obfuscator) against clean source and real minified bundles — nine files. The separation is wide and clean, but a larger corpus (more obfuscators, more real-world bundles) is needed before leaning on it blindly.
|
|
286
|
+
- **Minified vs hardened is handled, not solved.** v0.2 correctly passes minified jQuery and Lodash while flagging both obfuscators, using short-identifier dominance plus categorical markers. An exotic bundler or a deliberately minification-mimicking obfuscator could still fool it; that is what growing the corpus guards against.
|
|
287
|
+
- **Static only.** It reads the file as text. It does not and should not execute anything it scans.
|
|
288
|
+
- **Thresholds are empirical.** 55 is the default, with a stable margin from ~10 to ~77 on the current corpus — but it is tuned, not derived. Expect to revisit it per language and per codebase.
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Roadmap
|
|
293
|
+
|
|
294
|
+
- [x] False-positive corpus: normal + minified + obfuscated samples to calibrate against (`corpus/`, `eval_corpus.py`).
|
|
295
|
+
- [x] Detect a second hardener family (javascript-obfuscator) alongside BLA.
|
|
296
|
+
- [x] Separate hostile obfuscation from ordinary minification.
|
|
297
|
+
- [ ] More tool fingerprints (webpack/terser signatures, PyArmor, obfuscator.io variants).
|
|
298
|
+
- [ ] Grow the corpus (more real bundles, more obfuscators) and pin thresholds against it.
|
|
299
|
+
- [ ] Per-language signal profiles (JS/TS vs Python vs WASM-glue).
|
|
300
|
+
- [ ] Optional sandbox-runner helper that an agent can call after a tarpit verdict.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## FAQ
|
|
305
|
+
|
|
306
|
+
**Does this crack or defeat BLA?** No. It detects that hardening is present and recommends a cheaper strategy. It never reverses the protection or extracts secrets.
|
|
307
|
+
|
|
308
|
+
**Is "burning all the AI's tokens" real?** Partly. Hardening genuinely raises the cost of *static* analysis and genuinely hides string secrets. It does not reliably exhaust a budget — a dynamic approach (run it, watch it) or a budget-aware agent that probes instead of ingesting sidesteps most of it. `tarpit-guard` exists to make that cheaper path the default.
|
|
309
|
+
|
|
310
|
+
**Why stdlib-only for the core?** Portability and auditability. The thing that inspects untrusted code should itself be tiny, dependency-free, and easy to read.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
MIT (see `LICENSE`).
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# 🪤 tarpit-guard
|
|
2
|
+
|
|
3
|
+
**A pre-flight guard for AI code-analysis agents.** It scores a file or repository for signs of deliberate *anti-analysis hardening* — the obfuscation and "token-burning" tricks that tools like [BLA](https://github.com/qybaihe/bla) apply to make AI reverse-engineering expensive — and tells an agent, **before it spends a budget**, whether a target is a tarpit and what to do instead.
|
|
4
|
+
|
|
5
|
+
> One ~1K-token check that prevents a 60K-token mistake.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of contents
|
|
10
|
+
|
|
11
|
+
- [The problem](#the-problem)
|
|
12
|
+
- [What this is — and what it is not](#what-this-is--and-what-it-is-not)
|
|
13
|
+
- [How it works](#how-it-works)
|
|
14
|
+
- [Signals](#signals)
|
|
15
|
+
- [Tool fingerprints](#tool-fingerprints)
|
|
16
|
+
- [Scoring and thresholds](#scoring-and-thresholds)
|
|
17
|
+
- [Install](#install)
|
|
18
|
+
- [CLI usage](#cli-usage)
|
|
19
|
+
- [MCP usage (for agents)](#mcp-usage-for-agents)
|
|
20
|
+
- [Example output](#example-output)
|
|
21
|
+
- [Project layout](#project-layout)
|
|
22
|
+
- [Limitations and false positives](#limitations-and-false-positives)
|
|
23
|
+
- [Roadmap](#roadmap)
|
|
24
|
+
- [FAQ](#faq)
|
|
25
|
+
- [License](#license)
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## The problem
|
|
30
|
+
|
|
31
|
+
Source-hardening tools defend software by making it hostile to static analysis. A tiny, readable source file is transformed into a large, deliberately confusing one that still behaves identically:
|
|
32
|
+
|
|
33
|
+
| | Original | Hardened |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| Size | 418 B | 184 KB (**~440×**) |
|
|
36
|
+
| Lines | 15 | 2,998 |
|
|
37
|
+
| Secret string in cleartext | yes | no (encrypted) |
|
|
38
|
+
| Output when run | identical | identical |
|
|
39
|
+
|
|
40
|
+
The hardened file pads real logic with decoy functions, wraps branches behind opaque-predicate math, encrypts string literals behind runtime decoder loops, and plants jargon "canaries" written specifically to mislead a reading agent.
|
|
41
|
+
|
|
42
|
+
For an AI agent, the trap is cost. Read-and-trace the whole thing and you burn input tokens on ingestion and reasoning tokens on dead ends — and often still reach a wrong conclusion. The cheap counter is not to out-analyze the obfuscation; it is to **detect the tarpit first** and switch to dynamic analysis (run it in a sandbox, observe its behavior), which walks past nearly all static obfuscation for almost no tokens.
|
|
43
|
+
|
|
44
|
+
`tarpit-guard` is that detection step.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## What this is — and what it is not
|
|
49
|
+
|
|
50
|
+
**It is** a detector and triage guard. It answers one question: *does this look deliberately hardened, and if so, what is the cheaper way in?* It emits a score, the signals that fired, and a recommended strategy.
|
|
51
|
+
|
|
52
|
+
**It is not** a deobfuscator, a cracker, or a secret extractor. It never reverses anyone's protection or recovers hidden values. That is precisely the reverse-engineering these hardening tools exist to stop — building it would make this project the thing it is meant to warn about. The line is deliberate and permanent: `tarpit-guard` reads *shape*, never *meaning*.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## How it works
|
|
57
|
+
|
|
58
|
+
The engine is pure Python standard library — no dependencies, no network, nothing to install for the core. It runs entirely on local text.
|
|
59
|
+
|
|
60
|
+
1. **Repository sweep** (directory mode): walk the tree, skipping `node_modules`, `.git`, `dist`, `build`, and the like, and look for tool fingerprints.
|
|
61
|
+
2. **Per-file analysis**: for each candidate file, compute a set of cheap structural and statistical signals from the raw text — no execution, no parsing of untrusted code.
|
|
62
|
+
3. **Weighted score**: combine the signals into a 0–100 score and a confidence derived from how many independent signals fired.
|
|
63
|
+
4. **Verdict**: above the threshold, the file is a tarpit; the engine returns the evidence and a recommended strategy instead of a pile of extracted facts.
|
|
64
|
+
|
|
65
|
+
Because every signal is a count or ratio over text, the check is orders of magnitude cheaper than the analysis it protects.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Signals
|
|
70
|
+
|
|
71
|
+
Detection keys on signals that benign code — even heavily minified code — essentially never produces. This is deliberate: the hard problem is not spotting that a file is *machine-generated* (minified bundles are too); it is telling *hostile* obfuscation apart from *ordinary* minification. Size and line-length are explicitly **not** primary signals, because that is exactly what minification trips.
|
|
72
|
+
|
|
73
|
+
| Signal | Weight | What it catches |
|
|
74
|
+
|---|---:|---|
|
|
75
|
+
| `opaque_predicate_density` | 0.28 | `Math.imul` tautology chains that guard real branches behind always-true math (BLA) |
|
|
76
|
+
| `hex_identifier_array` | 0.28 | dense `_0x…` string-array identifiers (javascript-obfuscator family) |
|
|
77
|
+
| `decoder_loops` | 0.22 | `fromCharCode` + `charCodeAt` loops that reconstruct encrypted string literals at runtime |
|
|
78
|
+
| `obfuscator_control_tricks` | 0.12 | self-defending / control-flow tricks (`!![]`, `.split('\|')` dispatch) |
|
|
79
|
+
| `decoy_vocabulary_density` | 0.06 | planted jargon clusters (enclave / attestation / TPM / canary) meant to mislead a reader |
|
|
80
|
+
| `garbled_identifier_ratio` | 0.04 | mangled names such as `encodeFrozenScopeV4ue7` |
|
|
81
|
+
|
|
82
|
+
On top of the weighted score, four **categorical markers** apply a decisive floor, because they are signatures essentially impossible in hand-written or merely-minified code: a dense `_0x` identifier array, three or more runtime decoder loops, `Math.imul` opaque-predicate chains, or repeated `!![]` self-defending tricks. Any one present pushes the file over the line.
|
|
83
|
+
|
|
84
|
+
Conversely, a file **dominated by 1–2 character identifiers** (the minification tell — 60–70% in jQuery/Lodash builds, versus ~10% in hostile files) with **none** of those markers is recognized as benign minification and capped low, with the strategy "read the original source or a source map, not the bundle."
|
|
85
|
+
|
|
86
|
+
The `evidence` block reports the raw counts (`Math.imul`, hex identifiers, decoder pairs, decoy hits, short-identifier ratio, …) so a human or agent can sanity-check *why* a file scored as it did.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Tool fingerprints
|
|
91
|
+
|
|
92
|
+
Some artifacts are near-certain evidence of deliberate hardening on their own, independent of file contents. Directory scans report them separately as a strong standalone signal:
|
|
93
|
+
|
|
94
|
+
| Fingerprint | Tool |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `.bla-hardened/` directory | BLA |
|
|
97
|
+
| `.blarc` | BLA |
|
|
98
|
+
| `bla-harden-summary.json` | BLA |
|
|
99
|
+
|
|
100
|
+
The fingerprint map is a plain table in `detector.py` and is meant to grow as more hardeners are catalogued.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Scoring and thresholds
|
|
105
|
+
|
|
106
|
+
- **Score** — 0–100, the weighted sum of signals.
|
|
107
|
+
- **Confidence** — rises with the number of independent signals that cross their own half-way mark; four or more means full confidence.
|
|
108
|
+
- **Threshold** — default **55**. At or above it, `hardened` is true. Tunable with `--threshold` (CLI) or the `threshold` argument (MCP).
|
|
109
|
+
|
|
110
|
+
### Evaluation
|
|
111
|
+
|
|
112
|
+
`eval_corpus.py` scores a labelled corpus (`corpus/`) of clean source, real
|
|
113
|
+
minified bundles, and hostile obfuscation, and reports false positives /
|
|
114
|
+
negatives. It doubles as a regression test (non-zero exit on any miss).
|
|
115
|
+
|
|
116
|
+
v0.2 results (threshold 55):
|
|
117
|
+
|
|
118
|
+
| Bucket | File | Score | Verdict |
|
|
119
|
+
|---|---|---:|---|
|
|
120
|
+
| clean | jquery.source.js / lodash.source.js | 0.0 | ok |
|
|
121
|
+
| clean | detector.py (contains the decoy word list) | 9.5 | ok |
|
|
122
|
+
| minified | jquery.min.js | 0.0 | ok |
|
|
123
|
+
| minified | lodash.min.js | 0.0 | ok |
|
|
124
|
+
| obfuscated | bla_hardened_app.js | 78.0 | **TARPIT** |
|
|
125
|
+
| obfuscated | js-obfuscator_sample.js | 85.0 | **TARPIT** |
|
|
126
|
+
|
|
127
|
+
**0 false positives, 0 false negatives.** Highest benign score 9.5, lowest
|
|
128
|
+
hostile score 78.0 — a **+68.5** margin, stable across any threshold from ~10 to
|
|
129
|
+
~77. (For contrast, v0.1 leaned on file size and scored minified jQuery *above*
|
|
130
|
+
a real obfuscated file; that regression is what this corpus exists to prevent.)
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Install
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
git clone https://github.com/ManiraM-1/tarpit-guard.git
|
|
138
|
+
cd tarpit-guard
|
|
139
|
+
|
|
140
|
+
pip install -e . # core CLI — standard library only
|
|
141
|
+
pip install -e ".[mcp]" # adds the FastMCP server (fastmcp>=2.0)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Requires Python 3.9+.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## CLI usage
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
tarpit-guard path/to/file.js # score a single file
|
|
152
|
+
tarpit-guard path/to/repo # scan a tree + report fingerprints
|
|
153
|
+
tarpit-guard path/to/repo --quiet # only show flagged files
|
|
154
|
+
tarpit-guard path/to/repo --json # machine-readable report
|
|
155
|
+
tarpit-guard path/to/repo --threshold 45
|
|
156
|
+
|
|
157
|
+
python -m tarpit_guard.cli path/to/file.js # run without installing
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Exit codes** make it a drop-in CI gate:
|
|
161
|
+
|
|
162
|
+
| Code | Meaning |
|
|
163
|
+
|---:|---|
|
|
164
|
+
| `0` | nothing flagged |
|
|
165
|
+
| `1` | at least one tarpit found |
|
|
166
|
+
| `2` | path not found |
|
|
167
|
+
|
|
168
|
+
```yaml
|
|
169
|
+
# e.g. fail a job if a dependency ships hardened artifacts
|
|
170
|
+
- run: tarpit-guard ./vendor --quiet
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## MCP usage (for agents)
|
|
176
|
+
|
|
177
|
+
Run the server:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
python -m tarpit_guard.mcp_server
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
It exposes three tools:
|
|
184
|
+
|
|
185
|
+
| Tool | Use |
|
|
186
|
+
|---|---|
|
|
187
|
+
| `check_file(path)` | score one file before reading it |
|
|
188
|
+
| `check_source(text, label)` | score a raw snippet without touching disk |
|
|
189
|
+
| `scan_repo(root, threshold)` | sweep a tree for fingerprints and tarpit files |
|
|
190
|
+
|
|
191
|
+
**The intended agent loop:**
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
encounter unfamiliar file
|
|
195
|
+
│
|
|
196
|
+
â–¼
|
|
197
|
+
check_file(path)
|
|
198
|
+
│
|
|
199
|
+
hardened? ──no──▶ analyze normally
|
|
200
|
+
│
|
|
201
|
+
yes
|
|
202
|
+
│
|
|
203
|
+
â–¼
|
|
204
|
+
skip the full read →
|
|
205
|
+
run it in a sandbox and observe I/O,
|
|
206
|
+
or escalate to a human
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The guard turns "read everything and hope" into a deliberate, budgeted decision.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Example output
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
$ tarpit-guard ./BLA
|
|
217
|
+
|
|
218
|
+
Tool fingerprints found (strong signal of deliberate hardening):
|
|
219
|
+
[bla] dir: ./BLA/.bla-hardened
|
|
220
|
+
[bla] file: ./BLA/.blarc
|
|
221
|
+
[bla] file: ./BLA/.bla-hardened/bla-harden-summary.json
|
|
222
|
+
|
|
223
|
+
[TARPIT] score= 78 conf=1.00 ./BLA/.bla-hardened/app.js
|
|
224
|
+
182865B / 2998 lines, Math.imul×246, decoder_pairs=8, garbled_idents=190, decoy_hits=487
|
|
225
|
+
fired: opaque_predicate_density, decoder_loops, decoy_vocabulary_density
|
|
226
|
+
-> Treat as a tarpit. Do NOT read the whole file or trace it statically.
|
|
227
|
+
Prefer dynamic analysis (run in a sandbox and observe I/O) or escalate to a human.
|
|
228
|
+
[ok] score= 0.0 conf=0.00 ./BLA/app.js
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Project layout
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
tarpit-guard/
|
|
237
|
+
├── pyproject.toml
|
|
238
|
+
├── README.md
|
|
239
|
+
├── LICENSE
|
|
240
|
+
├── .gitignore
|
|
241
|
+
├── eval_corpus.py # scores corpus/, reports false positives/negatives
|
|
242
|
+
├── corpus/ # labelled samples: clean / minified / obfuscated
|
|
243
|
+
└── tarpit_guard/
|
|
244
|
+
├── __init__.py # public API: analyze_file, analyze_text, repo_fingerprints
|
|
245
|
+
├── detector.py # scoring engine (stdlib only)
|
|
246
|
+
├── cli.py # command-line entry point
|
|
247
|
+
└── mcp_server.py # FastMCP wrapper
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Limitations and false positives
|
|
253
|
+
|
|
254
|
+
This is a v0.2 heuristic, and honesty about its edges matters more than a clean pitch:
|
|
255
|
+
|
|
256
|
+
- **Small corpus.** It is calibrated on two hardeners (BLA, javascript-obfuscator) against clean source and real minified bundles — nine files. The separation is wide and clean, but a larger corpus (more obfuscators, more real-world bundles) is needed before leaning on it blindly.
|
|
257
|
+
- **Minified vs hardened is handled, not solved.** v0.2 correctly passes minified jQuery and Lodash while flagging both obfuscators, using short-identifier dominance plus categorical markers. An exotic bundler or a deliberately minification-mimicking obfuscator could still fool it; that is what growing the corpus guards against.
|
|
258
|
+
- **Static only.** It reads the file as text. It does not and should not execute anything it scans.
|
|
259
|
+
- **Thresholds are empirical.** 55 is the default, with a stable margin from ~10 to ~77 on the current corpus — but it is tuned, not derived. Expect to revisit it per language and per codebase.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Roadmap
|
|
264
|
+
|
|
265
|
+
- [x] False-positive corpus: normal + minified + obfuscated samples to calibrate against (`corpus/`, `eval_corpus.py`).
|
|
266
|
+
- [x] Detect a second hardener family (javascript-obfuscator) alongside BLA.
|
|
267
|
+
- [x] Separate hostile obfuscation from ordinary minification.
|
|
268
|
+
- [ ] More tool fingerprints (webpack/terser signatures, PyArmor, obfuscator.io variants).
|
|
269
|
+
- [ ] Grow the corpus (more real bundles, more obfuscators) and pin thresholds against it.
|
|
270
|
+
- [ ] Per-language signal profiles (JS/TS vs Python vs WASM-glue).
|
|
271
|
+
- [ ] Optional sandbox-runner helper that an agent can call after a tarpit verdict.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## FAQ
|
|
276
|
+
|
|
277
|
+
**Does this crack or defeat BLA?** No. It detects that hardening is present and recommends a cheaper strategy. It never reverses the protection or extracts secrets.
|
|
278
|
+
|
|
279
|
+
**Is "burning all the AI's tokens" real?** Partly. Hardening genuinely raises the cost of *static* analysis and genuinely hides string secrets. It does not reliably exhaust a budget — a dynamic approach (run it, watch it) or a budget-aware agent that probes instead of ingesting sidesteps most of it. `tarpit-guard` exists to make that cheaper path the default.
|
|
280
|
+
|
|
281
|
+
**Why stdlib-only for the core?** Portability and auditability. The thing that inspects untrusted code should itself be tiny, dependency-free, and easy to read.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## License
|
|
286
|
+
|
|
287
|
+
MIT (see `LICENSE`).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tarpit-guard"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Flag AI-reverse-engineering tarpits (obfuscated / token-burning code) before you waste a budget analyzing them."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Maniram" }]
|
|
10
|
+
keywords = [
|
|
11
|
+
"mcp", "llm", "ai-agents", "obfuscation", "reverse-engineering",
|
|
12
|
+
"static-analysis", "security", "developer-tools",
|
|
13
|
+
]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Security",
|
|
26
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
27
|
+
]
|
|
28
|
+
dependencies = []
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
mcp = ["fastmcp>=2.0"]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/ManiraM-1/tarpit-guard"
|
|
35
|
+
Repository = "https://github.com/ManiraM-1/tarpit-guard"
|
|
36
|
+
Issues = "https://github.com/ManiraM-1/tarpit-guard/issues"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
tarpit-guard = "tarpit_guard.cli:main"
|
|
40
|
+
|
|
41
|
+
[build-system]
|
|
42
|
+
requires = ["setuptools>=77"]
|
|
43
|
+
build-backend = "setuptools.build_meta"
|
|
44
|
+
|
|
45
|
+
[tool.setuptools]
|
|
46
|
+
packages = ["tarpit_guard"]
|