mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 23:11:52 +08:00
feat: support probe shell generation
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
export type ProbeMethod = "ResponseBody" | "DNSLog" | "Sleep";
|
||||
|
||||
export type ProbeContent = "BasicInfo" | "Server" | "OS" | "JDK" | "Bytecode" | "Command";
|
||||
|
||||
export interface ProbeConfig {
|
||||
probeMethod: string;
|
||||
probeContent: string;
|
||||
shellClassName?: string;
|
||||
targetJreVersion?: string;
|
||||
debug?: boolean;
|
||||
byPassJavaModule?: boolean;
|
||||
shrink?: boolean;
|
||||
}
|
||||
|
||||
export interface ProbeContentConfig {
|
||||
host?: string;
|
||||
seconds?: number;
|
||||
sleepServer?: string;
|
||||
server?: string;
|
||||
reqParamName?: string;
|
||||
reqHeaderName?: string;
|
||||
}
|
||||
|
||||
export interface DNSLogConfig {
|
||||
host: string;
|
||||
}
|
||||
|
||||
export interface SleepConfig {
|
||||
server: string;
|
||||
sleepServer: string;
|
||||
}
|
||||
|
||||
export interface ResponseBodyConfig {
|
||||
server: string;
|
||||
reqParamName: string;
|
||||
reqHeaderName: string;
|
||||
}
|
||||
|
||||
export interface PayloadFormValues {
|
||||
probeMethod: ProbeMethod;
|
||||
probeContent?: ProbeContent;
|
||||
debug?: boolean;
|
||||
byPassJavaModule?: boolean;
|
||||
shrink?: boolean;
|
||||
host?: string;
|
||||
server?: string;
|
||||
reqParamName?: string;
|
||||
reqHeaderName?: string;
|
||||
sleepServer?: string;
|
||||
seconds?: number;
|
||||
packingMethod: string;
|
||||
}
|
||||
|
||||
export interface ProbeGenerateResponse {
|
||||
probeResult: ProbeGenerateResult;
|
||||
packResult?: string;
|
||||
allPackResults?: Map<string, string>;
|
||||
}
|
||||
|
||||
export interface ProbeGenerateResult {
|
||||
shellClassName: string;
|
||||
shellSize: number;
|
||||
shellBytesBase64Str: string;
|
||||
probeConfig: ProbeConfig;
|
||||
probeContentConfig: DNSLogConfig | ResponseBodyConfig | SleepConfig;
|
||||
}
|
||||
+94
-16
@@ -1,15 +1,15 @@
|
||||
import { TFunction } from "i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
import { useCallback } from "react";
|
||||
import { FieldErrors } from "react-hook-form";
|
||||
import type { FieldErrors } from "react-hook-form";
|
||||
import * as yup from "yup";
|
||||
import { ShellToolType } from "./shell";
|
||||
|
||||
export const formSchema = yup.object({
|
||||
export const shellFormSchema = yup.object({
|
||||
server: yup.string().required().min(1),
|
||||
serverVersion: yup.string().required().min(1),
|
||||
targetJdkVersion: yup.string().optional(),
|
||||
debug: yup.boolean().optional(),
|
||||
bypassJavaModule: yup.boolean().optional(),
|
||||
byPassJavaModule: yup.boolean().optional(),
|
||||
shellClassName: yup.string().optional(),
|
||||
shellTool: yup.string().required().min(1),
|
||||
shellType: yup.string().required().min(1),
|
||||
@@ -30,8 +30,8 @@ export const formSchema = yup.object({
|
||||
});
|
||||
|
||||
interface ValidationResult {
|
||||
values: FormSchema;
|
||||
errors: FieldErrors<FormSchema>;
|
||||
values: ShellFormSchema;
|
||||
errors: FieldErrors<ShellFormSchema>;
|
||||
}
|
||||
|
||||
const urlPatternIsNeeded = (shellType: string) => {
|
||||
@@ -52,15 +52,15 @@ const isInvalidUrl = (urlPattern: string | undefined) =>
|
||||
|
||||
export const useYupValidationResolver = (validationSchema: yup.ObjectSchema<any>, t: TFunction) =>
|
||||
useCallback(
|
||||
async (data: FormSchema): Promise<ValidationResult> => {
|
||||
async (data: ShellFormSchema): Promise<ValidationResult> => {
|
||||
try {
|
||||
const values = (await validationSchema.validate(data, {
|
||||
abortEarly: false,
|
||||
})) as FormSchema;
|
||||
})) as ShellFormSchema;
|
||||
|
||||
const urlPattern: keyof FormSchema = "urlPattern";
|
||||
const shellClassBase64: keyof FormSchema = "shellClassBase64";
|
||||
const serverVersion: keyof FormSchema = "serverVersion";
|
||||
const urlPattern: keyof ShellFormSchema = "urlPattern";
|
||||
const shellClassBase64: keyof ShellFormSchema = "shellClassBase64";
|
||||
const serverVersion: keyof ShellFormSchema = "serverVersion";
|
||||
const errors = {} as any;
|
||||
|
||||
if (urlPatternIsNeeded(values?.shellType) && isInvalidUrl(values?.urlPattern)) {
|
||||
@@ -89,22 +89,22 @@ export const useYupValidationResolver = (validationSchema: yup.ObjectSchema<any>
|
||||
} catch (errors) {
|
||||
if (errors instanceof yup.ValidationError) {
|
||||
return {
|
||||
values: {} as FormSchema,
|
||||
values: {} as ShellFormSchema,
|
||||
errors: errors.inner.reduce(
|
||||
(allErrors, currentError) => {
|
||||
allErrors[currentError.path as keyof FormSchema] = {
|
||||
allErrors[currentError.path as keyof ShellFormSchema] = {
|
||||
type: currentError.type ?? "validation",
|
||||
message: currentError.message,
|
||||
};
|
||||
return allErrors;
|
||||
},
|
||||
{} as FieldErrors<FormSchema>,
|
||||
{} as FieldErrors<ShellFormSchema>,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
values: {} as FormSchema,
|
||||
values: {} as ShellFormSchema,
|
||||
errors: {
|
||||
server: {
|
||||
type: "unknown",
|
||||
@@ -117,4 +117,82 @@ export const useYupValidationResolver = (validationSchema: yup.ObjectSchema<any>
|
||||
[validationSchema, t],
|
||||
);
|
||||
|
||||
export type FormSchema = yup.InferType<typeof formSchema>;
|
||||
export type ShellFormSchema = yup.InferType<typeof shellFormSchema>;
|
||||
|
||||
export type ProbeFormSchema = yup.InferType<typeof probeFormSchema>;
|
||||
|
||||
export const probeFormSchema = yup.object().shape({
|
||||
probeMethod: yup.string().required(),
|
||||
probeContent: yup.string().required(),
|
||||
shellClassName: yup.string().optional(),
|
||||
host: yup.string().optional(),
|
||||
server: yup.string().optional(),
|
||||
reqParamName: yup.string().optional(),
|
||||
reqHeaderName: yup.string().optional(),
|
||||
seconds: yup.number().optional(),
|
||||
sleepServer: yup.string().optional(),
|
||||
packingMethod: yup.string().required(),
|
||||
targetJdkVersion: yup.string().optional(),
|
||||
debug: yup.boolean().optional(),
|
||||
byPassJavaModule: yup.boolean().optional(),
|
||||
shrink: yup.boolean().optional(),
|
||||
});
|
||||
|
||||
interface ProbeValidationResult {
|
||||
values: ProbeFormSchema;
|
||||
errors: FieldErrors<ProbeFormSchema>;
|
||||
}
|
||||
|
||||
export const useYupValidationProbeResolver = (validationSchema: yup.ObjectSchema<any>, t: TFunction) =>
|
||||
useCallback(
|
||||
async (data: ProbeFormSchema): Promise<ProbeValidationResult> => {
|
||||
try {
|
||||
const values = (await validationSchema.validate(data, {
|
||||
abortEarly: false,
|
||||
})) as ProbeFormSchema;
|
||||
|
||||
const host: keyof ProbeFormSchema = "host";
|
||||
const errors = {} as any;
|
||||
|
||||
if (values.probeMethod === "DNSLog" && !values.host) {
|
||||
errors[host] = {
|
||||
type: "custom",
|
||||
message: t("tips.customShellClass"),
|
||||
};
|
||||
}
|
||||
return {
|
||||
values,
|
||||
errors,
|
||||
};
|
||||
} catch (errors) {
|
||||
console.log(errors)
|
||||
if (errors instanceof yup.ValidationError) {
|
||||
return {
|
||||
values: {} as ProbeFormSchema,
|
||||
errors: errors.inner.reduce(
|
||||
(allErrors, currentError) => {
|
||||
allErrors[currentError.path as keyof ProbeFormSchema] = {
|
||||
type: currentError.type ?? "validation",
|
||||
message: currentError.message,
|
||||
};
|
||||
console.log(allErrors)
|
||||
return allErrors;
|
||||
},
|
||||
{} as FieldErrors<ProbeFormSchema>,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
values: {} as ProbeFormSchema,
|
||||
errors: {
|
||||
server: {
|
||||
type: "unknown",
|
||||
message: "An unexpected validation error occurred",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
[validationSchema, t],
|
||||
);
|
||||
Reference in New Issue
Block a user