hacktricks-mcp-server 1.3.1

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.
@@ -0,0 +1,49 @@
1
+ name: Publish to MCP Registry
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ id-token: write # Required for OIDC token generation
13
+ contents: read
14
+
15
+ steps:
16
+ - name: Checkout repository
17
+ uses: actions/checkout@v4
18
+
19
+ - name: Set up Node.js
20
+ uses: actions/setup-node@v4
21
+ with:
22
+ node-version: '18'
23
+ registry-url: 'https://registry.npmjs.org'
24
+
25
+ - name: Install dependencies
26
+ run: npm install
27
+
28
+ - name: Build package
29
+ run: npm run build
30
+
31
+ - name: Publish to npm
32
+ run: npm publish --access public
33
+ env:
34
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
35
+
36
+ - name: Download mcp-publisher CLI
37
+ run: |
38
+ curl -L "https://github.com/modelcontextprotocol/registry/releases/download/v1.0.0/mcp-publisher_1.0.0_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz
39
+ chmod +x mcp-publisher
40
+
41
+ - name: Publish to MCP Registry
42
+ env:
43
+ ACTIONS_ID_TOKEN_REQUEST_TOKEN: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN }}
44
+ ACTIONS_ID_TOKEN_REQUEST_URL: ${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }}
45
+ run: |
46
+ ./mcp-publisher publish \
47
+ --registry-url "https://registry.modelcontextprotocol.io" \
48
+ --mcp-file "./server.json" \
49
+ --auth-method github-oidc
@@ -0,0 +1,9 @@
1
+ {
2
+ "ref": "refs/tags/v1.3.1",
3
+ "repository": {
4
+ "name": "hacktricks-mcp-server",
5
+ "owner": {
6
+ "name": "Xplo8E"
7
+ }
8
+ }
9
+ }
package/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "hacktricks"]
2
+ path = hacktricks
3
+ url = https://github.com/carlospolop/hacktricks.git
package/.mcp.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "hacktricks": {
4
+ "command": "node",
5
+ "args": [
6
+ "dist/index.js"
7
+ ],
8
+ "env": {}
9
+ }
10
+ }
11
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ ## [1.3.0] - 2025-12-26
4
+
5
+ ### Tools
6
+
7
+ | Tool | Description |
8
+ |------|-------------|
9
+ | `search_hacktricks` | Search with results grouped by file, showing title, match count, and relevant sections |
10
+ | `get_hacktricks_page` | Get full page content |
11
+ | `get_hacktricks_outline` | Get table of contents (section headers) |
12
+ | `get_hacktricks_section` | Extract specific section by name |
13
+ | `get_hacktricks_cheatsheet` | Extract only code blocks/payloads |
14
+ | `list_hacktricks_categories` | Browse categories and file structure |
15
+ | `hacktricks_quick_lookup` | ⚡ One-shot exploitation lookup with alias support |
16
+
17
+ ### Features
18
+
19
+ - **Grouped search results** - Results aggregated by file with title, match count, sections, and top matches
20
+ - **Section extraction** - Read specific sections (~200 tokens) instead of full pages (~3000 tokens)
21
+ - **Quick lookup** - One-shot "how do I exploit X" answers with alias expansion (sqli, xss, rce, etc.)
22
+ - **Smart tool descriptions** - Guide Claude toward efficient usage patterns
23
+ - **Category filtering** - Narrow searches to specific categories
24
+ - **Code block extraction** - Get just the commands/payloads
25
+
26
+ ### Security
27
+
28
+ - Command injection protection via `execFile()`
29
+ - Path traversal prevention
30
+ - Input validation on all parameters
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Xplo8E
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.
package/README.md ADDED
@@ -0,0 +1,238 @@
1
+ # HackTricks MCP Server
2
+
3
+ MCP (Model Context Protocol) server for searching and querying [HackTricks](https://github.com/carlospolop/hacktricks) pentesting documentation directly from Claude.
4
+
5
+ ## Features
6
+
7
+ - **Quick lookup** - One-shot exploitation info with alias support (sqli, xss, ssrf, etc.)
8
+ - **Grouped search results** - Results aggregated by file with match count, title, and relevant sections
9
+ - **Page outline** - Quick table of contents to identify relevant sections
10
+ - **Section extraction** - Read specific sections instead of full pages (token-efficient)
11
+ - **Cheatsheet mode** - Extract only code blocks/commands from pages
12
+ - **Category browsing** - Discover available topics and file paths
13
+ - **Fast grep search** - Uses ripgrep for instant results
14
+ - **Security hardened** - Protection against command injection and path traversal
15
+
16
+ ## Setup
17
+
18
+ ### 1. Clone and Initialize
19
+
20
+ ```bash
21
+ git clone https://github.com/Xplo8E/hacktricks-mcp-server.git
22
+ cd hacktricks-mcp-server
23
+ git submodule update --init --recursive
24
+ ```
25
+
26
+ ### 2. Install Dependencies
27
+
28
+ ```bash
29
+ bun install
30
+ ```
31
+
32
+ ### 3. Build
33
+
34
+ ```bash
35
+ bun run build
36
+ ```
37
+
38
+ ### 4. Configure Claude
39
+
40
+ Add to your Claude settings (`~/.claude/settings.json`):
41
+
42
+ ```json
43
+ {
44
+ "mcpServers": {
45
+ "hacktricks": {
46
+ "command": "node",
47
+ "args": ["/path/to/hacktricks-mcp/dist/index.js"],
48
+ "disabled": false
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### 5. Restart Claude
55
+
56
+ After adding the MCP server configuration, restart Claude for the changes to take effect.
57
+
58
+ ## Available Tools
59
+
60
+ ### `hacktricks_quick_lookup`
61
+
62
+ ⚡ **One-shot exploitation lookup**. Searches, finds best page, and returns exploitation sections + code blocks in one call.
63
+
64
+ **Parameters:**
65
+ - `topic` (string, required): Attack/technique to look up (e.g., 'SUID', 'sqli', 'xss', 'docker escape')
66
+ - `category` (string, optional): Category filter for faster results
67
+
68
+ **Supported aliases:** `sqli`, `xss`, `rce`, `lfi`, `rfi`, `ssrf`, `csrf`, `xxe`, `ssti`, `idor`, `jwt`, `suid`, `privesc`
69
+
70
+ **Example:**
71
+ ```
72
+ hacktricks_quick_lookup("SSRF", category="pentesting-web")
73
+ ```
74
+
75
+ **Benefits:** Reduces 3+ tool calls to 1 for "how do I exploit X" questions.
76
+
77
+ ---
78
+
79
+ ### `search_hacktricks`
80
+
81
+ Search through HackTricks documentation. **Returns results GROUPED BY FILE** with match count, page title, and relevant section headers.
82
+
83
+ **Parameters:**
84
+ - `query` (string, required): Search term or regex pattern
85
+ - `category` (string, optional): Filter to specific category (e.g., 'pentesting-web')
86
+ - `limit` (number, optional): Max grouped results (default: 20)
87
+
88
+ **Example output:**
89
+ ```
90
+ Found matches in 5 files for: "SUID"
91
+
92
+ ────────────────────────────────────────────────────────────
93
+
94
+ 📄 **Linux Privilege Escalation**
95
+ Path: src/linux-hardening/privilege-escalation/README.md
96
+ Matches: 12
97
+ Sections: SUID Binaries | Finding SUID | GTFOBins
98
+ Preview:
99
+ L45: Find files with SUID bit set...
100
+ L78: Common SUID exploitation techniques...
101
+
102
+ ────────────────────────────────────────────────────────────
103
+ ```
104
+
105
+ ---
106
+
107
+ ### `get_hacktricks_outline`
108
+
109
+ Get the **table of contents** of a page (all section headers). Use this BEFORE reading full pages to understand structure.
110
+
111
+ **Parameters:**
112
+ - `path` (string): Relative path to markdown file
113
+
114
+ **Example output:**
115
+ ```
116
+ # Linux Privilege Escalation
117
+ ## Enumeration
118
+ ### System Information
119
+ ### Network
120
+ ## SUID Binaries
121
+ ### Finding SUID Files
122
+ ### Exploiting SUID
123
+ ## Capabilities
124
+ ```
125
+
126
+ **Benefits:** See page structure in ~20 lines vs reading 500+ lines.
127
+
128
+ ---
129
+
130
+ ### `get_hacktricks_section`
131
+
132
+ Extract a **specific section** from a page by header name. Much more efficient than reading the full page.
133
+
134
+ **Parameters:**
135
+ - `path` (string): Relative path to markdown file
136
+ - `section` (string): Section header to extract (partial match, case-insensitive)
137
+
138
+ **Example:**
139
+ ```
140
+ get_hacktricks_section("src/linux-hardening/privilege-escalation/README.md", "SUID")
141
+ ```
142
+
143
+ **Benefits:** Read just "SUID Binaries" section (~200 tokens) instead of entire page (~3000 tokens).
144
+
145
+ ---
146
+
147
+ ### `get_hacktricks_cheatsheet`
148
+
149
+ Extract **only code blocks** from a page. Perfect when you just need commands, payloads, or examples.
150
+
151
+ **Parameters:**
152
+ - `path` (string): Relative path to markdown file
153
+
154
+ **Example output:**
155
+ ```bash
156
+ find / -perm -4000 2>/dev/null
157
+ ```
158
+
159
+ ```bash
160
+ ./vulnerable_suid -p
161
+ ```
162
+
163
+ **Benefits:** Skip explanatory text when you just need "give me the command".
164
+
165
+ ---
166
+
167
+ ### `get_hacktricks_page`
168
+
169
+ Get **full content** of a HackTricks page.
170
+
171
+ **Parameters:**
172
+ - `path` (string): Relative path to markdown file
173
+
174
+ **Warning:** Pages can be very long (3000+ tokens). Consider using `get_hacktricks_outline` + `get_hacktricks_section` instead.
175
+
176
+ ---
177
+
178
+ ### `list_hacktricks_categories`
179
+
180
+ List categories and their contents.
181
+
182
+ **Parameters:**
183
+ - `category` (string, optional): Category to expand
184
+
185
+ **Without category:** Lists top-level categories
186
+ **With category:** Shows full directory tree with file paths
187
+
188
+ ## Efficient Usage Pattern
189
+
190
+ For optimal token usage, Claude should:
191
+
192
+ 1. **Search with category filter** → Get grouped results with context
193
+ 2. **Get outline of relevant page** → See structure before reading
194
+ 3. **Extract specific section** → Read only what's needed
195
+ 4. **Get cheatsheet** → Quick command reference
196
+
197
+ **Before (inefficient):**
198
+ ```
199
+ search_hacktricks("SUID") → 50 raw lines
200
+ get_page(file1) → 3000 tokens
201
+ get_page(file2) → 2500 tokens
202
+ Total: ~5500 tokens, 3 calls
203
+ ```
204
+
205
+ **After (efficient):**
206
+ ```
207
+ search_hacktricks("SUID", category="linux-hardening") → Grouped results
208
+ get_outline(best_match) → 20 lines
209
+ get_section(best_match, "SUID") → 200 tokens
210
+ Total: ~400 tokens, 3 calls
211
+ ```
212
+
213
+ ## Requirements
214
+
215
+ - Node.js (v18 or higher)
216
+ - ripgrep (`rg`) - usually pre-installed on macOS/Linux
217
+ - Bun (for package management)
218
+
219
+ ## Development
220
+
221
+ **Watch mode:**
222
+ ```bash
223
+ bun run dev
224
+ ```
225
+
226
+ **Test locally:**
227
+ ```bash
228
+ bun run start
229
+ ```
230
+
231
+ ## License
232
+
233
+ MIT
234
+
235
+ ## Credits
236
+
237
+ - [HackTricks](https://github.com/carlospolop/hacktricks) by Carlos Polop
238
+ - Built with [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk)
package/TESTING.md ADDED
@@ -0,0 +1,188 @@
1
+ # Testing the HackTricks MCP Server
2
+
3
+ This document describes how to test the MCP server functionality.
4
+
5
+ ## Manual Testing
6
+
7
+ ### Prerequisites
8
+ ```bash
9
+ cd ~/projects/hacktricks-mcp
10
+ bun install
11
+ bun run build
12
+ ```
13
+
14
+ ### Test 1: Verify Build Output
15
+ ```bash
16
+ ls -la dist/
17
+ # Should show index.js
18
+ ```
19
+
20
+ ### Test 2: Test Search Functionality (CLI)
21
+ ```bash
22
+ # Test basic search
23
+ rg -n -i --type md "SUID" hacktricks/ | head -10
24
+
25
+ # Test regex search
26
+ rg -n -i --type md "docker.*escape" hacktricks/ | head -5
27
+
28
+ # Test no results
29
+ rg -n -i --type md "xyznotfound12345" hacktricks/
30
+ ```
31
+
32
+ ### Test 3: Test File Reading
33
+ ```bash
34
+ # Test reading a valid file
35
+ cat hacktricks/src/linux-hardening/privilege-escalation/README.md | head -20
36
+
37
+ # Test path traversal protection (should fail)
38
+ cat hacktricks/../../../etc/passwd 2>&1
39
+ ```
40
+
41
+ ### Test 4: List Categories
42
+ ```bash
43
+ ls hacktricks/src/ | grep -v "\.md$" | grep -v "^images$" | sort
44
+ ```
45
+
46
+ ## Integration Testing with Claude Code
47
+
48
+ ### 1. Add to Claude Code Settings
49
+
50
+ Edit `~/.claude/settings.json`:
51
+ ```json
52
+ {
53
+ "mcpServers": {
54
+ "hacktricks": {
55
+ "command": "node",
56
+ "args": ["/Users/vinay/projects/hacktricks-mcp/dist/index.js"],
57
+ "disabled": false
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### 2. Restart Claude Code
64
+
65
+ ### 3. Test Commands
66
+
67
+ Try these queries with Claude Code:
68
+
69
+ **Search Test:**
70
+ ```
71
+ "Search HackTricks for SUID privilege escalation"
72
+ ```
73
+
74
+ **Category List Test:**
75
+ ```
76
+ "What categories are available in HackTricks?"
77
+ ```
78
+
79
+ **Page Retrieval Test:**
80
+ ```
81
+ "Show me the Linux privilege escalation page from HackTricks"
82
+ ```
83
+
84
+ **Edge Cases:**
85
+ ```
86
+ "Search HackTricks for: XXE|SSRF|CSRF" # Regex test
87
+ "Search HackTricks for: docker.*escape" # Regex test
88
+ ```
89
+
90
+ ## Expected Results
91
+
92
+ ### Search Results Format
93
+ ```
94
+ Found X matches for: "query"
95
+
96
+ 📄 path/to/file.md:123
97
+ Content of matching line
98
+
99
+ 📄 path/to/another.md:456
100
+ Another matching line
101
+ ```
102
+
103
+ ### Category List Format
104
+ ```
105
+ Available HackTricks Categories (X):
106
+
107
+ - AI
108
+ - binary-exploitation
109
+ - crypto
110
+ - linux-hardening
111
+ ...
112
+ ```
113
+
114
+ ### Page Content Format
115
+ ```
116
+ [Full markdown content of the page]
117
+ ```
118
+
119
+ ## Debugging
120
+
121
+ Check MCP server logs in Claude Code console:
122
+ ```
123
+ [HackTricks MCP] Searching for: "query"
124
+ [HackTricks MCP] Found X results (showing Y)
125
+ [HackTricks MCP] Reading file: path/to/file.md
126
+ [HackTricks MCP] File size: XXXX bytes
127
+ ```
128
+
129
+ ## Error Testing
130
+
131
+ ### Test Empty Query
132
+ ```
133
+ search_hacktricks("")
134
+ # Expected: "Search query cannot be empty"
135
+ ```
136
+
137
+ ### Test Invalid Path
138
+ ```
139
+ get_hacktricks_page("../../../etc/passwd")
140
+ # Expected: "Invalid file path: directory traversal not allowed"
141
+ ```
142
+
143
+ ### Test Non-existent File
144
+ ```
145
+ get_hacktricks_page("src/nonexistent.md")
146
+ # Expected: "File not found: src/nonexistent.md"
147
+ ```
148
+
149
+ ### Test Invalid Regex
150
+ ```
151
+ search_hacktricks("[[invalid")
152
+ # Expected: "Invalid search pattern: ..."
153
+ ```
154
+
155
+ ## Performance Testing
156
+
157
+ ### Large Query Results
158
+ ```bash
159
+ # Search for common term
160
+ rg -n -i --type md "privilege" hacktricks/ | wc -l
161
+ # Should handle large result sets (limited to 50)
162
+ ```
163
+
164
+ ### File Size Limits
165
+ ```bash
166
+ # Find largest markdown file
167
+ find hacktricks/src -name "*.md" -type f -exec du -h {} + | sort -rh | head -5
168
+ # Ensure server can handle large files
169
+ ```
170
+
171
+ ## Security Testing
172
+
173
+ ### Command Injection Prevention
174
+ Test that special characters in queries don't execute commands:
175
+ ```
176
+ search_hacktricks("test; ls -la")
177
+ search_hacktricks("test && whoami")
178
+ search_hacktricks("test $(whoami)")
179
+ ```
180
+ All should search for the literal strings, not execute commands.
181
+
182
+ ### Path Traversal Prevention
183
+ ```
184
+ get_hacktricks_page("../../../etc/passwd")
185
+ get_hacktricks_page("/etc/passwd")
186
+ get_hacktricks_page("src/../../..")
187
+ ```
188
+ All should be rejected with appropriate error messages.