Skip to content

Commit 9694f93

Browse files
committed
feat: add diff tips for attacher
1 parent 42b183d commit 9694f93

File tree

6 files changed

+77
-43
lines changed

6 files changed

+77
-43
lines changed

web/src/components/results/agent.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { downloadBytes } from "@/lib/utils";
1+
import { downloadBytes, formatBytes } from "@/lib/utils";
22
import { GenerateResult } from "@/types/shell";
33
import { ScrollTextIcon } from "lucide-react";
44
import { useTranslation } from "react-i18next";
55
import { Button } from "../ui/button";
66
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
77
import { Separator } from "../ui/separator";
88

9-
export function AgentResult({ packResult, generateResult }: { packResult: string; generateResult?: GenerateResult }) {
9+
export function AgentResult({
10+
packMethod,
11+
packResult,
12+
generateResult,
13+
}: Readonly<{ packMethod: string; packResult: string; generateResult?: GenerateResult }>) {
1014
const { t } = useTranslation();
15+
console.log(packMethod);
16+
const isPureAgent = packMethod === "AgentJar";
1117
return (
1218
<Card>
1319
<CardHeader>
@@ -19,7 +25,9 @@ export function AgentResult({ packResult, generateResult }: { packResult: string
1925
<CardContent>
2026
<ol className="list-decimal list-inside space-y-4 text-sm">
2127
<li className="flex items-center justify-between">
22-
<span>{t("download")} MemShellAgent.jar</span>
28+
<span>
29+
{t("download")} MemShellAgent.jar ({formatBytes(atob(packResult).length)})
30+
</span>
2331
<Button
2432
size="sm"
2533
variant="outline"
@@ -33,25 +41,27 @@ export function AgentResult({ packResult, generateResult }: { packResult: string
3341
)
3442
}
3543
>
36-
{t("download")} Jar
37-
</Button>
38-
</li>
39-
<li className="flex items-center justify-between">
40-
<span>{t("tips.download-jattach")}</span>
41-
<Button
42-
size="sm"
43-
variant="outline"
44-
className="w-28"
45-
type="button"
46-
onClick={() => window.open("https://github.com/jattach/jattach/releases")}
47-
>
48-
{t("download")} Jattach
44+
{t("download")}
4945
</Button>
5046
</li>
47+
{isPureAgent && (
48+
<li className="flex items-center justify-between">
49+
<span>{t("tips.download-jattach")}</span>
50+
<Button
51+
size="sm"
52+
variant="outline"
53+
className="w-28"
54+
type="button"
55+
onClick={() => window.open("https://github.com/jattach/jattach/releases")}
56+
>
57+
{t("download")}
58+
</Button>
59+
</li>
60+
)}
5161
<Separator />
52-
<li>{t("tips.move-to-container")}</li>
62+
<li>{isPureAgent ? t("tips.agent-move-to-target") : t("tips.agent-move-to-target1")}</li>
5363
<li>{t("tips.get-pid")}</li>
54-
<li>{t("tips.execute-command")}</li>
64+
<li>{isPureAgent ? t("tips.execute-command") : t("tips.execute-command1")}</li>
5565
<li>{t("tips.try-to-use-shell")}</li>
5666
</ol>
5767
</CardContent>

web/src/components/results/jar-result.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GenerateResult } from "@/types/shell";
33
import { useTranslation } from "react-i18next";
44
import { Button } from "../ui/button";
55

6-
export function JarResult({ packResult, generateResult }: { packResult: string; generateResult?: GenerateResult }) {
6+
export function JarResult({ packResult, generateResult }: Readonly<{ packResult: string; generateResult?: GenerateResult }>) {
77
const { t } = useTranslation();
88
return (
99
<div className="flex items-center justify-center">

web/src/components/results/result-component.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export function ResultComponent({
1212
packMethod,
1313
t,
1414
generateResult,
15-
}: {
15+
}: Readonly<{
1616
packResult: string | undefined;
1717
allPackResults: Map<string, string> | undefined;
1818
packMethod: string;
1919
t: TFunction;
2020
generateResult?: GenerateResult;
21-
}) {
21+
}>) {
2222
const showCode = packMethod === "JSP";
2323
const isAgent = packMethod.startsWith("Agent");
2424
const isJar = packMethod === "Jar";
@@ -27,30 +27,28 @@ export function ResultComponent({
2727
}
2828

2929
if (isAgent) {
30-
return <AgentResult packResult={packResult ?? ""} generateResult={generateResult} />;
30+
return <AgentResult packMethod={packMethod} packResult={packResult ?? ""} generateResult={generateResult} />;
3131
}
3232
if (isJar) {
3333
return <JarResult packResult={packResult ?? ""} generateResult={generateResult} />;
3434
}
3535
if (!isAgent && !isJar) {
3636
return (
37-
<Fragment>
38-
<CodeViewer
39-
code={packResult ?? ""}
40-
header={
41-
<div className="flex items-center justify-between text-xs gap-2">
42-
<span>
43-
{t("packageConfig.title")}{packMethod}
44-
</span>
45-
<span className="text-muted-foreground">({packResult?.length})</span>
46-
</div>
47-
}
48-
wrapLongLines={!showCode}
49-
showLineNumbers={showCode}
50-
language={showCode ? "java" : "text"}
51-
height={350}
52-
/>
53-
</Fragment>
37+
<CodeViewer
38+
code={packResult ?? ""}
39+
header={
40+
<div className="flex items-center justify-between text-xs gap-2">
41+
<span>
42+
{t("packageConfig.title")}{packMethod}
43+
</span>
44+
<span className="text-muted-foreground">({packResult?.length})</span>
45+
</div>
46+
}
47+
wrapLongLines={!showCode}
48+
showLineNumbers={showCode}
49+
language={showCode ? "java" : "text"}
50+
height={350}
51+
/>
5452
);
5553
}
5654
return null;

web/src/i18n/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@
119119
"tips": {
120120
"controllerUrlPattern": "ControllerHandler type requires a specific URL Pattern, e.g., /hello_controller",
121121
"decompileTip": "Decompilation is still under development, so the current only sees the base64 encoding format",
122-
"download-jattach": "Download the Jattach tool (consider it directly encapsulated in Jar later)",
122+
"download-jattach": "Download the Jattach tool",
123123
"execute-command": "Execute the command to inject: /path/to/jattach pid load instrument false /path/to/agent.jar",
124+
"execute-command1": "Execute the command to inject: java -jar /path/to/agent.jar pid",
124125
"get-pid": "Get the process pid of the target jvm (use jps or ps)",
125126
"handlerUrlPattern": "HandlerMethod/HandlerFunction type requires a specific URL Pattern, e.g., /hello_handler",
126127
"jreTip": "Target JRE version, generally speaking, Java 6 is the default version for maximum compatibility, and Java high versions can load low version bytecode.",
127128
"jreTip2": "In specific cases, such as JDK8 being able to use lambda expressions, and JDK9 and above having module restrictions, a specific version is required.",
128-
"move-to-container": "Move MemShellAgent.jar and jattach to the container (if the test environment uses a container deployment)",
129+
"agent-move-to-target": "Move MemShellAgent.jar and jattach to target host",
130+
"agent-move-to-target1": "Move MemShellAgent.jar to target host",
129131
"servletUrlPattern": "Servlet type requires a specific URL Pattern, e.g., /hello_servlet",
130132
"shellBytesEmpty": "Shell bytes is empty, please generate shell first",
131133
"shellToolNotSelected": "Please select a shell tool type first",

web/src/i18n/zh-CN.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@
119119
"tips": {
120120
"controllerUrlPattern": "ControllerHandler 类型的需要填写具体的 URL Pattern,例如 /hello_controller",
121121
"decompileTip": "反编译还在开发中,因此当前仅能看到 base64 编码格式",
122-
"download-jattach": "下载 Jattach 工具(后期考虑直接封装在 Jar 中)",
122+
"download-jattach": "下载 Jattach 工具",
123123
"execute-command": "执行命令进行注入:/path/to/jattach pid load instrument false /path/to/agent.jar",
124+
"execute-command1": "执行命令进行注入:java -jar /path/to/agent.jar pid",
124125
"get-pid": "获取目标 jvm 的进程 pid(使用 jps 或 ps)",
125126
"handlerUrlPattern": "HandlerMethod/HandlerFunction 类型的需要填写具体的 URL Pattern,例如 /hello_handler",
126127
"jreTip": "目标 JRE 版本,一般而言为了最大的兼容性,默认 Java 6 即可,Java 高版本能加载低版本的字节码。",
127128
"jreTip2": "特定情况下,例如 JDK8 才能使用 lambda 表达式,JDK9 以上存在模块限制时才需要选择特定的版本。",
128-
"move-to-container": "将 MemShellAgent.jar 和 jattach 移动到容器中(如果测试环境使用容器部署)",
129+
"agent-move-to-target": "将 MemShellAgent.jar 和 jattach 移到到目标服务磁盘上",
130+
"agent-move-to-target1": "将 MemShellAgent.jar 移到到目标服务磁盘上",
129131
"servletUrlPattern": "Servlet 类型的需要填写具体的 URL Pattern,例如 /hello_servlet",
130132
"shellBytesEmpty": "内存马字节码为空,无法下载,请先生成内存马",
131133
"shellToolNotSelected": "请先选择内存马工具类型",

web/src/lib/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ export function downloadBytes(base64String: string, className?: string, jarName?
2525
link.click();
2626
document.body.removeChild(link);
2727
}
28+
29+
export function formatBytes(bytes: number) {
30+
if (bytes === 0) return '0 Bytes';
31+
if (Number.isNaN(bytes) || !Number.isFinite(bytes)) return 'N/A';
32+
33+
const k = 1024;
34+
const sizes = ['Bytes', 'KB', 'MB']; // Add more units like GB, TB if needed
35+
36+
if (bytes < k) {
37+
return `${bytes.toFixed(0)} ${sizes[0]}`; // Bytes, no decimal
38+
}
39+
40+
const i = Math.floor(Math.log(bytes) / Math.log(k));
41+
42+
// Prefer MB if KB value is 1000 or more, or if it's already in MB (i >= 2)
43+
if (i >= 2 || (bytes / k ** 1) >= 1000) {
44+
const mbValue = Number.parseFloat((bytes / k ** 2).toFixed(2));
45+
return `${mbValue} ${sizes[2]}`;
46+
}
47+
const kbValue = Number.parseFloat((bytes / k ** 1).toFixed(1));
48+
return `${kbValue} ${sizes[1]}`;
49+
}

0 commit comments

Comments
 (0)