tanli 0.0.1b0__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.
Files changed (83) hide show
  1. tanli-0.0.1b0/LICENSE +201 -0
  2. tanli-0.0.1b0/PKG-INFO +234 -0
  3. tanli-0.0.1b0/README.md +198 -0
  4. tanli-0.0.1b0/pyproject.toml +64 -0
  5. tanli-0.0.1b0/setup.cfg +4 -0
  6. tanli-0.0.1b0/src/redteam/__init__.py +3 -0
  7. tanli-0.0.1b0/src/redteam/agent.py +649 -0
  8. tanli-0.0.1b0/src/redteam/auth.py +196 -0
  9. tanli-0.0.1b0/src/redteam/cli.py +1043 -0
  10. tanli-0.0.1b0/src/redteam/config.py +103 -0
  11. tanli-0.0.1b0/src/redteam/cve_lookup.py +461 -0
  12. tanli-0.0.1b0/src/redteam/cvss.py +233 -0
  13. tanli-0.0.1b0/src/redteam/engagement.py +170 -0
  14. tanli-0.0.1b0/src/redteam/findings.py +432 -0
  15. tanli-0.0.1b0/src/redteam/guardtext.py +73 -0
  16. tanli-0.0.1b0/src/redteam/interactor.py +114 -0
  17. tanli-0.0.1b0/src/redteam/judge.py +164 -0
  18. tanli-0.0.1b0/src/redteam/knowledge.py +239 -0
  19. tanli-0.0.1b0/src/redteam/planner.py +87 -0
  20. tanli-0.0.1b0/src/redteam/playbook.py +411 -0
  21. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_1.yaml +75 -0
  22. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_10.yaml +113 -0
  23. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_11.yaml +103 -0
  24. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_2.yaml +58 -0
  25. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_3.yaml +59 -0
  26. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_4.yaml +43 -0
  27. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_5.yaml +37 -0
  28. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_6.yaml +101 -0
  29. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_7.yaml +100 -0
  30. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_8.yaml +115 -0
  31. tanli-0.0.1b0/src/redteam/playbooks/llm/playbook_9.yaml +102 -0
  32. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_10.yaml +21 -0
  33. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_11.yaml +21 -0
  34. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_12.yaml +22 -0
  35. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_13.yaml +21 -0
  36. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_14.yaml +20 -0
  37. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_15.yaml +23 -0
  38. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_16.yaml +21 -0
  39. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_17.yaml +23 -0
  40. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_18.yaml +25 -0
  41. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_19.yaml +29 -0
  42. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_20.yaml +25 -0
  43. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_21.yaml +30 -0
  44. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_22.yaml +24 -0
  45. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_23.yaml +28 -0
  46. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_24.yaml +29 -0
  47. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_25.yaml +27 -0
  48. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_26.yaml +29 -0
  49. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_6.yaml +29 -0
  50. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_7.yaml +23 -0
  51. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_8.yaml +24 -0
  52. tanli-0.0.1b0/src/redteam/playbooks/web/playbook_9.yaml +22 -0
  53. tanli-0.0.1b0/src/redteam/report.py +292 -0
  54. tanli-0.0.1b0/src/redteam/sandbox.py +101 -0
  55. tanli-0.0.1b0/src/redteam/scanners.py +435 -0
  56. tanli-0.0.1b0/src/redteam/target_lab.py +287 -0
  57. tanli-0.0.1b0/src/redteam/triage.py +86 -0
  58. tanli-0.0.1b0/src/redteam/version_watch.py +218 -0
  59. tanli-0.0.1b0/src/redteam/web_config.py +289 -0
  60. tanli-0.0.1b0/src/redteam/workspace.py +167 -0
  61. tanli-0.0.1b0/src/tanli.egg-info/PKG-INFO +234 -0
  62. tanli-0.0.1b0/src/tanli.egg-info/SOURCES.txt +81 -0
  63. tanli-0.0.1b0/src/tanli.egg-info/dependency_links.txt +1 -0
  64. tanli-0.0.1b0/src/tanli.egg-info/entry_points.txt +3 -0
  65. tanli-0.0.1b0/src/tanli.egg-info/requires.txt +14 -0
  66. tanli-0.0.1b0/src/tanli.egg-info/top_level.txt +1 -0
  67. tanli-0.0.1b0/tests/test_agent_loop.py +198 -0
  68. tanli-0.0.1b0/tests/test_cli.py +91 -0
  69. tanli-0.0.1b0/tests/test_cvss.py +146 -0
  70. tanli-0.0.1b0/tests/test_findings.py +279 -0
  71. tanli-0.0.1b0/tests/test_improvements_v002.py +253 -0
  72. tanli-0.0.1b0/tests/test_knowledge_playbook.py +128 -0
  73. tanli-0.0.1b0/tests/test_llm_lab.py +158 -0
  74. tanli-0.0.1b0/tests/test_playbook.py +168 -0
  75. tanli-0.0.1b0/tests/test_playbook_e2e.py +83 -0
  76. tanli-0.0.1b0/tests/test_playbooks_top10.py +103 -0
  77. tanli-0.0.1b0/tests/test_readonly_auth_cve.py +186 -0
  78. tanli-0.0.1b0/tests/test_report.py +89 -0
  79. tanli-0.0.1b0/tests/test_review_fixes.py +237 -0
  80. tanli-0.0.1b0/tests/test_scanners.py +181 -0
  81. tanli-0.0.1b0/tests/test_smoke.py +70 -0
  82. tanli-0.0.1b0/tests/test_target_lab.py +110 -0
  83. tanli-0.0.1b0/tests/test_web_config.py +232 -0
tanli-0.0.1b0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
tanli-0.0.1b0/PKG-INFO ADDED
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: tanli
3
+ Version: 0.0.1b0
4
+ Summary: 探驪 Tanli - 自主紅隊測試 Agent(LLM + Web 雙軌安全評估)
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/ADT109119/Tanli
7
+ Project-URL: Repository, https://github.com/ADT109119/Tanli
8
+ Project-URL: Issues, https://github.com/ADT109119/Tanli/issues
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Information Technology
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Security
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: typer>=0.12
24
+ Requires-Dist: rich>=13
25
+ Requires-Dist: httpx>=0.27
26
+ Requires-Dist: pydantic>=2
27
+ Requires-Dist: PyJWT>=2.8
28
+ Requires-Dist: cryptography>=42
29
+ Requires-Dist: pyyaml>=6
30
+ Provides-Extra: llm
31
+ Requires-Dist: openai>=1.40; extra == "llm"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=8; extra == "dev"
34
+ Requires-Dist: cvss>=3; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ <p align="center">
38
+ <img src="https://raw.githubusercontent.com/ADT109119/Tanli/main/assets/logo.png" alt="Tanli logo" width="160" />
39
+ </p>
40
+
41
+ <h1 align="center">探驪 Tanli</h1>
42
+
43
+ <p align="center">
44
+ <em>"The pearl worth a thousand taels of gold lies beneath the chin of the dragon, in the deepest of nine abysses." — Zhuangzi</em>
45
+ </p>
46
+
47
+ <p align="center">
48
+ <strong>English</strong> | <a href="docs/README.zh-TW.md">繁體中文</a>
49
+ </p>
50
+
51
+ <p align="center">
52
+ <a href="#license">License: Apache-2.0</a> ·
53
+ <a href="SECURITY.md">Security &amp; Responsible Use</a> ·
54
+ <a href="CONTRIBUTING.md">Contributing</a>
55
+ </p>
56
+
57
+ <p align="center">
58
+ <img src="https://raw.githubusercontent.com/ADT109119/Tanli/main/assets/banner.jpg" alt="Tanli banner — dive into the target, back with the findings" width="92%" />
59
+ </p>
60
+
61
+ **An autonomous red-team agent** that assesses both LLM applications and classic web services. Dive into the abyss of the target; come back with the pearl of the finding.
62
+
63
+ Tanli is an autonomous red-team testing agent: you give it an authorized target, and it plans multi-step attack paths on its own, invokes tools, runs probes, judges results, and produces a structured security report with reproduction steps.
64
+
65
+ > **Authorized testing only.** Scanning or attacking any system without authorization is illegal in most jurisdictions. By using this tool you agree to test only targets for which you hold explicit written authorization. See [SECURITY.md](SECURITY.md).
66
+
67
+ ## Why "Tanli" (探驪)
68
+
69
+ The name comes from the idiom 探驪得珠 ("diving for the dragon's pearl"; also written 探珠驪頷), from the Zhuangzi, chapter Lie Yukou: the pearl is said to hide beneath the chin of the 驪龍, a dark dragon that dwells in the deepest abyss — to win it, one must dive to the bottom of the abyss, wait for the dragon to fall asleep, and seize it only then. It originally meant winning a treasure of immense value, and later also described writing that grasps the very essence of a subject.
70
+
71
+ Red teaming is that same dive: the truly critical vulnerabilities hide in the depths of the system, with defenses coiled beside them like the sleeping dragon — you plan stealthily, take your moment, and retrieve the pearl.
72
+
73
+ - **The abyss** = the target system (a black box of unknown depth)
74
+ - **The sleeping dragon** = the defenses you must not wake (low-noise, stealthy tradecraft)
75
+ - **The strike** = multi-step autonomous planning: probe → hypothesize → exploit → judge → review
76
+ - **The pearl** = the real vulnerability (with a CVSS score and a PoC)
77
+
78
+ ## Dual attack surface
79
+
80
+ | Track | Targets | Framework covered |
81
+ |:--|:--|:--|
82
+ | **LLM applications** | LLM APIs, RAG systems, AI agents | OWASP GenAI LLM Top 10 (jailbreaks, prompt injection, system-prompt leakage, excessive agency, output handling…) |
83
+ | **Web services** | Web apps, REST/GraphQL APIs | OWASP Top 10 2021 (injection, authn, access control, misconfiguration, SSRF…) |
84
+
85
+ ## Core capabilities
86
+
87
+ - **Multi-step autonomous execution**: DAG planner + ReAct execution loop; the attack surface is routed automatically by target type
88
+ - **Scanner automation**: nuclei / sqlmap / OWASP ZAP run fully autonomously inside Docker sandboxes; results are converted into findings automatically
89
+ - **LLM attack playbooks**: eleven OWASP GenAI playbooks covering direct jailbreak, multi-turn escalation (Crescendo/Many-shot/Skeleton Key), persona virtualization, encoding obfuscation (Base64/cipher/low-resource/ASCII-art), indirect-injection weaponization (zero-click exfil/confused deputy/memory poisoning), reasoning-model attacks (Bad Likert Judge/Echo Chamber) and multimodal injection — baseline control + sentinel markers + deterministic rules + an LLM-judge second pass for false-positive filtering
90
+ - **Automatic CVSS v3.1 scoring**: the official formula embedded (zero deviation from the authoritative library across all 2,592 vectors), with severity/category → vector mapping
91
+ - **Human review gate**: every High/Critical finding is flagged "awaiting human confirmation"; the CLI warns explicitly until the report is finalized, so drafts never get published as official reports
92
+ - **Signed authorization model**: localhost-only by default; widening scope requires an Ed25519 JWS-signed credential plus mandatory Scope Statement validation — crossing the line aborts the run
93
+ - **Offline lab self-test**: built-in `TargetLab` (a pure-stdlib dual-behavior vulnerable/hardened lab including an LLM chat endpoint); one `self-test` command validates the whole engine end-to-end — no Docker, no external network
94
+ - **Reporting**: Markdown reports with CVSS vectors, PoC reproduction steps, exfiltrated data / achieved impact, and remediation advice deduplicated by OWASP category
95
+
96
+ ## Installation
97
+
98
+ Requires Python >= 3.11.
99
+
100
+ ```bash
101
+ git clone https://github.com/ADT109119/Tanli.git && cd Tanli
102
+ pip install -e .
103
+
104
+ # smoke test (no dependencies)
105
+ tanli --help
106
+ ```
107
+
108
+ Full-auto scanner mode requires Docker (pulls the official nuclei/sqlmap/zap images); the LLM judge requires any OpenAI-compatible endpoint (optional — falls back to deterministic rules without it).
109
+
110
+ ## Quick start
111
+
112
+ ```bash
113
+ # 1. Offline self-test: spins up the local lab, 7 assertions end-to-end (recommended first step)
114
+ tanli self-test
115
+
116
+ # 2. Preview the plan against a local target (no actual attacks)
117
+ tanli run http://127.0.0.1:8080 -t web_service --dry-run
118
+
119
+ # 3. Fully automated web scan (scanners + judge + CVSS + report)
120
+ tanli run http://127.0.0.1:8080 -t web_service --scanners all
121
+
122
+ # 4. LLM app red-team (target is an OpenAI-compatible chat/completions endpoint)
123
+ tanli run http://127.0.0.1:8080 -t llm_app --scanners llm_playbook
124
+
125
+ # 5. Single scanner / single playbook
126
+ tanli scan http://127.0.0.1:8080 --scanner nuclei
127
+ tanli run http://127.0.0.1:8080 -t llm_app --playbook src/redteam/playbooks/llm/playbook_1.yaml
128
+
129
+ # 6. CVE lookup: exact CVE id, or product-level (ALL published CVEs of a package/framework)
130
+ # Enriched with EPSS exploit-likelihood + CISA KEV (known-exploited) flags.
131
+ tanli cve CVE-2025-55182
132
+ tanli cve django -e pip # GHSA + OSV merged, no version filter
133
+ tanli cve nginx # non-package ecosystems fall back to NVD keyword search
134
+
135
+ # 7. Autonomous agent mode: LLM tool-loop plans every step itself
136
+ # (fingerprint -> product-level CVE lookup -> dynamic attempt; never trusts
137
+ # self-reported versions). All tools run inside ScopeGuard/read-only/budget fences.
138
+ # Engagement discipline: --roe loads a Rules-of-Engagement file and injects
139
+ # RoE + MITRE ATT&CK-mapped OPPLAN before the first packet (Decepticon-style);
140
+ # --workspace gives per-target cross-session memory + large-output offload
141
+ # (RedAmon-style); target responses pass prompt-injection guards.
142
+ tanli agent http://127.0.0.1:8080 --steps 30 --probes 60
143
+ tanli agent TARGET --auth-cred credential.jws --public-key signer_public.pem --read-only
144
+ tanli roe --init roe.yaml && tanli agent TARGET --roe roe.yaml
145
+ ```
146
+
147
+ `--scanners`: `auto` (default: web → all, llm_app → playbooks) | `none` | `web_config` | `nuclei` | `sqlmap` | `zap` | `llm_playbook`.
148
+ ZAP depth: `--zap-mode baseline|full|api`; nuclei narrowing: `--nuclei-severity`, `--nuclei-exclude-protocols`.
149
+
150
+ ## Authorization model
151
+
152
+ The default scope is limited to `localhost` / `127.0.0.1` / `example.com`. Operating against any internal or external target requires a signed credential:
153
+
154
+ ```bash
155
+ # Issue an authorization credential with an Ed25519 private key
156
+ tanli gen-cred --scope scope.yaml --key signer_private.pem --out credential.jws
157
+
158
+ # Run with the credential
159
+ tanli run TARGET --auth-cred credential.jws --public-key signer_public.pem
160
+ ```
161
+
162
+ ScopeGuard checks every request against the credential scope; any violation aborts the run with an audit trail. This is a hard gate, not a warning.
163
+
164
+ ## LLM judge setup
165
+
166
+ Judging uses any OpenAI-compatible endpoint, provider-agnostic:
167
+
168
+ ```bash
169
+ export REDTEAM_JUDGE_BASE_URL="https://your-endpoint/v1" # vLLM / ollama / cloud — anything
170
+ export REDTEAM_JUDGE_MODEL="your-model"
171
+ export REDTEAM_JUDGE_API_KEY="***" # optional for local endpoints
172
+ ```
173
+
174
+ - Deterministic parameters (`temperature=0`, fixed seed) for reproducibility
175
+ - Graceful degradation without an endpoint: LLM judging is skipped, deterministic rules only — the scan flow is unaffected
176
+
177
+ ## LLM attack playbooks
178
+
179
+ | Playbook | OWASP GenAI | Attack surface |
180
+ |:--|:--|:--|
181
+ | llm-001 | LLM01 | Direct jailbreak / guardrail bypass (DAN roleplay, prefill, obfuscation) |
182
+ | llm-002 | LLM08 | Indirect prompt injection (hidden context / RAG override) |
183
+ | llm-003 | LLM02 | System-prompt leakage (instruction self-disclosure / translation / roleplay) |
184
+ | llm-004 | LLM10 | Insecure output handling (Markdown/HTML XSS, hybrid) |
185
+ | llm-005 | LLM03 | Excessive agency introspection (tool/plan self-disclosure) |
186
+ | llm-006 | LLM01 | Multi-turn & fabricated-history jailbreak (Crescendo, Many-shot, Skeleton Key, prefill) |
187
+ | llm-007 | LLM01 | Persona virtualization & narrative wrapper (DeepInception, Policy Puppetry, emotional leverage) |
188
+ | llm-008 | LLM01 | Encoding & obfuscation bypass (Base64, custom cipher, low-resource language, zero-width, ASCII-art) |
189
+ | llm-009 | LLM01 | Indirect injection weaponization (zero-click markdown exfil, confused deputy, memory poisoning) |
190
+ | llm-010 | LLM01 | Reasoning-model attacks & guardrail mismatch (Bad Likert Judge, Echo Chamber, reasoning budget) |
191
+ | llm-011 | LLM01 | Multimodal vision-language injection (OCR-smuggled instructions, invisible contrast, layout hijack) |
192
+
193
+ Safety by design: all payloads are benignized (`payload_policy: benign`), token-budget circuit breaker, and any playbook with side effects requires an authorization credential.
194
+
195
+ Playbooks double as the autonomous agent's **attack-theory knowledge base**: `tanli agent` exposes a `get_playbook` tool (catalog / keyword / OWASP filters) so the LLM plans against standard procedures instead of improvising — no vector store needed, the YAMLs are the knowledge base, fully auditable. Web methodology playbooks (e.g. web-006 SQLi flow) are queryable reference; execution still goes through the scanner pipeline under ScopeGuard/read-only fences.
196
+
197
+ ## Reports
198
+
199
+ Every run outputs `report_<target>_<timestamp>.md`:
200
+
201
+ 1. Executive summary with severity statistics (including the count of unreviewed high-risk findings)
202
+ 2. OWASP category rollup (including the OWASP GenAI LLM surface)
203
+ 3. Per finding: CVSS v3.1 vector and score, PoC reproduction steps, evidence, human-review status
204
+ 4. Remediation advice: category → OWASP class → generic three-tier mapping, automatically deduplicated
205
+
206
+ ## For AI agents
207
+
208
+ This repo ships an agent-facing skill file: [SKILL.md](SKILL.md) — a compact operations manual
209
+ (any AI agent: Hermes / OpenCode / Codex / Claude Code) covering the six-step engagement flow
210
+ (RoE → credential → agent run → report review), command cheatsheet, safety fences, and
211
+ battle-tested pitfalls (WAF false positives, CVE-source lag, token budgets, workspace memory).
212
+ Read it before driving `tanli` autonomously.
213
+
214
+ Tanli's own agent also ingests user skills from `~/.tanli/skills/*.md` at runtime
215
+ (served through its `get_playbook` knowledge base — drop a file, no reinstall needed).
216
+
217
+ ## Development
218
+
219
+ ```bash
220
+ pip install -e ".[dev]"
221
+ pytest tests/ -q # 191 tests, fully offline
222
+ tanli self-test # lab end-to-end smoke, all-PASS required
223
+ ```
224
+
225
+ - Specification: `SPECIFICATION-FINAL.md` (v3.4, planned collaboratively by the agy + opencode dual-agent pipeline)
226
+ - Contributing: [CONTRIBUTING.md](CONTRIBUTING.md) · Security policy: [SECURITY.md](SECURITY.md)
227
+
228
+ ## Project status
229
+
230
+ M1–M6 complete: CLI / authorization model / planner / scanner bridge / findings conversion / LLM judge / eleven attack playbooks (5 execution + 6 jailbreak-methodology) / CVSS scoring layer / report gate & remediation advice / dual-behavior lab self-test / RoE engagement discipline / workspace memory / EPSS-KEV CVE intelligence / triage scoring / user-injectable skills. All 191 tests green.
231
+
232
+ ## License
233
+
234
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,198 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/ADT109119/Tanli/main/assets/logo.png" alt="Tanli logo" width="160" />
3
+ </p>
4
+
5
+ <h1 align="center">探驪 Tanli</h1>
6
+
7
+ <p align="center">
8
+ <em>"The pearl worth a thousand taels of gold lies beneath the chin of the dragon, in the deepest of nine abysses." — Zhuangzi</em>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <strong>English</strong> | <a href="docs/README.zh-TW.md">繁體中文</a>
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="#license">License: Apache-2.0</a> ·
17
+ <a href="SECURITY.md">Security &amp; Responsible Use</a> ·
18
+ <a href="CONTRIBUTING.md">Contributing</a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <img src="https://raw.githubusercontent.com/ADT109119/Tanli/main/assets/banner.jpg" alt="Tanli banner — dive into the target, back with the findings" width="92%" />
23
+ </p>
24
+
25
+ **An autonomous red-team agent** that assesses both LLM applications and classic web services. Dive into the abyss of the target; come back with the pearl of the finding.
26
+
27
+ Tanli is an autonomous red-team testing agent: you give it an authorized target, and it plans multi-step attack paths on its own, invokes tools, runs probes, judges results, and produces a structured security report with reproduction steps.
28
+
29
+ > **Authorized testing only.** Scanning or attacking any system without authorization is illegal in most jurisdictions. By using this tool you agree to test only targets for which you hold explicit written authorization. See [SECURITY.md](SECURITY.md).
30
+
31
+ ## Why "Tanli" (探驪)
32
+
33
+ The name comes from the idiom 探驪得珠 ("diving for the dragon's pearl"; also written 探珠驪頷), from the Zhuangzi, chapter Lie Yukou: the pearl is said to hide beneath the chin of the 驪龍, a dark dragon that dwells in the deepest abyss — to win it, one must dive to the bottom of the abyss, wait for the dragon to fall asleep, and seize it only then. It originally meant winning a treasure of immense value, and later also described writing that grasps the very essence of a subject.
34
+
35
+ Red teaming is that same dive: the truly critical vulnerabilities hide in the depths of the system, with defenses coiled beside them like the sleeping dragon — you plan stealthily, take your moment, and retrieve the pearl.
36
+
37
+ - **The abyss** = the target system (a black box of unknown depth)
38
+ - **The sleeping dragon** = the defenses you must not wake (low-noise, stealthy tradecraft)
39
+ - **The strike** = multi-step autonomous planning: probe → hypothesize → exploit → judge → review
40
+ - **The pearl** = the real vulnerability (with a CVSS score and a PoC)
41
+
42
+ ## Dual attack surface
43
+
44
+ | Track | Targets | Framework covered |
45
+ |:--|:--|:--|
46
+ | **LLM applications** | LLM APIs, RAG systems, AI agents | OWASP GenAI LLM Top 10 (jailbreaks, prompt injection, system-prompt leakage, excessive agency, output handling…) |
47
+ | **Web services** | Web apps, REST/GraphQL APIs | OWASP Top 10 2021 (injection, authn, access control, misconfiguration, SSRF…) |
48
+
49
+ ## Core capabilities
50
+
51
+ - **Multi-step autonomous execution**: DAG planner + ReAct execution loop; the attack surface is routed automatically by target type
52
+ - **Scanner automation**: nuclei / sqlmap / OWASP ZAP run fully autonomously inside Docker sandboxes; results are converted into findings automatically
53
+ - **LLM attack playbooks**: eleven OWASP GenAI playbooks covering direct jailbreak, multi-turn escalation (Crescendo/Many-shot/Skeleton Key), persona virtualization, encoding obfuscation (Base64/cipher/low-resource/ASCII-art), indirect-injection weaponization (zero-click exfil/confused deputy/memory poisoning), reasoning-model attacks (Bad Likert Judge/Echo Chamber) and multimodal injection — baseline control + sentinel markers + deterministic rules + an LLM-judge second pass for false-positive filtering
54
+ - **Automatic CVSS v3.1 scoring**: the official formula embedded (zero deviation from the authoritative library across all 2,592 vectors), with severity/category → vector mapping
55
+ - **Human review gate**: every High/Critical finding is flagged "awaiting human confirmation"; the CLI warns explicitly until the report is finalized, so drafts never get published as official reports
56
+ - **Signed authorization model**: localhost-only by default; widening scope requires an Ed25519 JWS-signed credential plus mandatory Scope Statement validation — crossing the line aborts the run
57
+ - **Offline lab self-test**: built-in `TargetLab` (a pure-stdlib dual-behavior vulnerable/hardened lab including an LLM chat endpoint); one `self-test` command validates the whole engine end-to-end — no Docker, no external network
58
+ - **Reporting**: Markdown reports with CVSS vectors, PoC reproduction steps, exfiltrated data / achieved impact, and remediation advice deduplicated by OWASP category
59
+
60
+ ## Installation
61
+
62
+ Requires Python >= 3.11.
63
+
64
+ ```bash
65
+ git clone https://github.com/ADT109119/Tanli.git && cd Tanli
66
+ pip install -e .
67
+
68
+ # smoke test (no dependencies)
69
+ tanli --help
70
+ ```
71
+
72
+ Full-auto scanner mode requires Docker (pulls the official nuclei/sqlmap/zap images); the LLM judge requires any OpenAI-compatible endpoint (optional — falls back to deterministic rules without it).
73
+
74
+ ## Quick start
75
+
76
+ ```bash
77
+ # 1. Offline self-test: spins up the local lab, 7 assertions end-to-end (recommended first step)
78
+ tanli self-test
79
+
80
+ # 2. Preview the plan against a local target (no actual attacks)
81
+ tanli run http://127.0.0.1:8080 -t web_service --dry-run
82
+
83
+ # 3. Fully automated web scan (scanners + judge + CVSS + report)
84
+ tanli run http://127.0.0.1:8080 -t web_service --scanners all
85
+
86
+ # 4. LLM app red-team (target is an OpenAI-compatible chat/completions endpoint)
87
+ tanli run http://127.0.0.1:8080 -t llm_app --scanners llm_playbook
88
+
89
+ # 5. Single scanner / single playbook
90
+ tanli scan http://127.0.0.1:8080 --scanner nuclei
91
+ tanli run http://127.0.0.1:8080 -t llm_app --playbook src/redteam/playbooks/llm/playbook_1.yaml
92
+
93
+ # 6. CVE lookup: exact CVE id, or product-level (ALL published CVEs of a package/framework)
94
+ # Enriched with EPSS exploit-likelihood + CISA KEV (known-exploited) flags.
95
+ tanli cve CVE-2025-55182
96
+ tanli cve django -e pip # GHSA + OSV merged, no version filter
97
+ tanli cve nginx # non-package ecosystems fall back to NVD keyword search
98
+
99
+ # 7. Autonomous agent mode: LLM tool-loop plans every step itself
100
+ # (fingerprint -> product-level CVE lookup -> dynamic attempt; never trusts
101
+ # self-reported versions). All tools run inside ScopeGuard/read-only/budget fences.
102
+ # Engagement discipline: --roe loads a Rules-of-Engagement file and injects
103
+ # RoE + MITRE ATT&CK-mapped OPPLAN before the first packet (Decepticon-style);
104
+ # --workspace gives per-target cross-session memory + large-output offload
105
+ # (RedAmon-style); target responses pass prompt-injection guards.
106
+ tanli agent http://127.0.0.1:8080 --steps 30 --probes 60
107
+ tanli agent TARGET --auth-cred credential.jws --public-key signer_public.pem --read-only
108
+ tanli roe --init roe.yaml && tanli agent TARGET --roe roe.yaml
109
+ ```
110
+
111
+ `--scanners`: `auto` (default: web → all, llm_app → playbooks) | `none` | `web_config` | `nuclei` | `sqlmap` | `zap` | `llm_playbook`.
112
+ ZAP depth: `--zap-mode baseline|full|api`; nuclei narrowing: `--nuclei-severity`, `--nuclei-exclude-protocols`.
113
+
114
+ ## Authorization model
115
+
116
+ The default scope is limited to `localhost` / `127.0.0.1` / `example.com`. Operating against any internal or external target requires a signed credential:
117
+
118
+ ```bash
119
+ # Issue an authorization credential with an Ed25519 private key
120
+ tanli gen-cred --scope scope.yaml --key signer_private.pem --out credential.jws
121
+
122
+ # Run with the credential
123
+ tanli run TARGET --auth-cred credential.jws --public-key signer_public.pem
124
+ ```
125
+
126
+ ScopeGuard checks every request against the credential scope; any violation aborts the run with an audit trail. This is a hard gate, not a warning.
127
+
128
+ ## LLM judge setup
129
+
130
+ Judging uses any OpenAI-compatible endpoint, provider-agnostic:
131
+
132
+ ```bash
133
+ export REDTEAM_JUDGE_BASE_URL="https://your-endpoint/v1" # vLLM / ollama / cloud — anything
134
+ export REDTEAM_JUDGE_MODEL="your-model"
135
+ export REDTEAM_JUDGE_API_KEY="***" # optional for local endpoints
136
+ ```
137
+
138
+ - Deterministic parameters (`temperature=0`, fixed seed) for reproducibility
139
+ - Graceful degradation without an endpoint: LLM judging is skipped, deterministic rules only — the scan flow is unaffected
140
+
141
+ ## LLM attack playbooks
142
+
143
+ | Playbook | OWASP GenAI | Attack surface |
144
+ |:--|:--|:--|
145
+ | llm-001 | LLM01 | Direct jailbreak / guardrail bypass (DAN roleplay, prefill, obfuscation) |
146
+ | llm-002 | LLM08 | Indirect prompt injection (hidden context / RAG override) |
147
+ | llm-003 | LLM02 | System-prompt leakage (instruction self-disclosure / translation / roleplay) |
148
+ | llm-004 | LLM10 | Insecure output handling (Markdown/HTML XSS, hybrid) |
149
+ | llm-005 | LLM03 | Excessive agency introspection (tool/plan self-disclosure) |
150
+ | llm-006 | LLM01 | Multi-turn & fabricated-history jailbreak (Crescendo, Many-shot, Skeleton Key, prefill) |
151
+ | llm-007 | LLM01 | Persona virtualization & narrative wrapper (DeepInception, Policy Puppetry, emotional leverage) |
152
+ | llm-008 | LLM01 | Encoding & obfuscation bypass (Base64, custom cipher, low-resource language, zero-width, ASCII-art) |
153
+ | llm-009 | LLM01 | Indirect injection weaponization (zero-click markdown exfil, confused deputy, memory poisoning) |
154
+ | llm-010 | LLM01 | Reasoning-model attacks & guardrail mismatch (Bad Likert Judge, Echo Chamber, reasoning budget) |
155
+ | llm-011 | LLM01 | Multimodal vision-language injection (OCR-smuggled instructions, invisible contrast, layout hijack) |
156
+
157
+ Safety by design: all payloads are benignized (`payload_policy: benign`), token-budget circuit breaker, and any playbook with side effects requires an authorization credential.
158
+
159
+ Playbooks double as the autonomous agent's **attack-theory knowledge base**: `tanli agent` exposes a `get_playbook` tool (catalog / keyword / OWASP filters) so the LLM plans against standard procedures instead of improvising — no vector store needed, the YAMLs are the knowledge base, fully auditable. Web methodology playbooks (e.g. web-006 SQLi flow) are queryable reference; execution still goes through the scanner pipeline under ScopeGuard/read-only fences.
160
+
161
+ ## Reports
162
+
163
+ Every run outputs `report_<target>_<timestamp>.md`:
164
+
165
+ 1. Executive summary with severity statistics (including the count of unreviewed high-risk findings)
166
+ 2. OWASP category rollup (including the OWASP GenAI LLM surface)
167
+ 3. Per finding: CVSS v3.1 vector and score, PoC reproduction steps, evidence, human-review status
168
+ 4. Remediation advice: category → OWASP class → generic three-tier mapping, automatically deduplicated
169
+
170
+ ## For AI agents
171
+
172
+ This repo ships an agent-facing skill file: [SKILL.md](SKILL.md) — a compact operations manual
173
+ (any AI agent: Hermes / OpenCode / Codex / Claude Code) covering the six-step engagement flow
174
+ (RoE → credential → agent run → report review), command cheatsheet, safety fences, and
175
+ battle-tested pitfalls (WAF false positives, CVE-source lag, token budgets, workspace memory).
176
+ Read it before driving `tanli` autonomously.
177
+
178
+ Tanli's own agent also ingests user skills from `~/.tanli/skills/*.md` at runtime
179
+ (served through its `get_playbook` knowledge base — drop a file, no reinstall needed).
180
+
181
+ ## Development
182
+
183
+ ```bash
184
+ pip install -e ".[dev]"
185
+ pytest tests/ -q # 191 tests, fully offline
186
+ tanli self-test # lab end-to-end smoke, all-PASS required
187
+ ```
188
+
189
+ - Specification: `SPECIFICATION-FINAL.md` (v3.4, planned collaboratively by the agy + opencode dual-agent pipeline)
190
+ - Contributing: [CONTRIBUTING.md](CONTRIBUTING.md) · Security policy: [SECURITY.md](SECURITY.md)
191
+
192
+ ## Project status
193
+
194
+ M1–M6 complete: CLI / authorization model / planner / scanner bridge / findings conversion / LLM judge / eleven attack playbooks (5 execution + 6 jailbreak-methodology) / CVSS scoring layer / report gate & remediation advice / dual-behavior lab self-test / RoE engagement discipline / workspace memory / EPSS-KEV CVE intelligence / triage scoring / user-injectable skills. All 191 tests green.
195
+
196
+ ## License
197
+
198
+ [Apache-2.0](LICENSE)