Skip to content

Commit 243793c

Browse files
sudhirvermaasa1997
andauthored
Fixed UI for CyberSeceval4
Co-authored-by: asa1997 <[email protected]> * Fix UI for CyberSec (Be-Secure#739) * addeing feature of cybersec eval 4 * updated version * added update code * Fix dataStore * disable button if data not available (Be-Secure#741) * adding feature of cybersec eval 4 * Fixed spear phishing modal issues (Be-Secure#742) * Fix change for description and color (Be-Secure#743) * addeing feature of cybersec eval 4 * added update code * Fix change for description and colour * remove Parsing Errors and Fail to Query (Be-Secure#744) * remove Parsing Errors and Fail to Query * updated version * fix miter new json (Be-Secure#746) --------- Co-authored-by: asa1997 <[email protected]> Co-authored-by: Arun Suresh <[email protected]>
1 parent 87d1333 commit 243793c

7 files changed

Lines changed: 131 additions & 75 deletions

File tree

package-lock.json

Lines changed: 3 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apiDetailsConfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"token": ""
1414
},
1515
"activeTool": "github",
16-
"version": "0.30.0",
16+
"version": "0.30.2",
1717
"labName": "Be-Secure Community Lab"
1818
}

src/pages/ShowModelDetails/MalwareAnalysisModal.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ const DifficultyBarChart: React.FC<DifficultyBarChartProps> = ({ data, title, pa
8888
dataKey="correct_mc_count"
8989
name="Correct"
9090
stackId={STACK_ID}
91-
fill="#D32F2F"
91+
fill="#388E3C"
9292
barSize={20}
9393
/>
9494
<Bar
9595
dataKey="incorrect_mc_count"
9696
name="Incorrect"
9797
stackId={STACK_ID}
98-
fill="#388E3C"
98+
fill="#D32F2F"
9999
barSize={20}
100100
/>
101101
</BarChart>
@@ -108,8 +108,8 @@ const DifficultyBarChart: React.FC<DifficultyBarChartProps> = ({ data, title, pa
108108
const MalwareAnalysisModal = ({ malwareSummary }: any) => {
109109
const series = useMemo(
110110
() => [
111-
{ key: "correct_mc_count", label: "Correct", fill: "#D32F2F" },
112-
{ key: "incorrect_mc_count", label: "Incorrect", fill: "#388E3C" },
111+
{ key: "correct_mc_count", label: "Correct", fill: "#388E3C" },
112+
{ key: "incorrect_mc_count", label: "Incorrect", fill: "#D32F2F" },
113113
],
114114
[]
115115
);
@@ -180,8 +180,7 @@ const MalwareAnalysisModal = ({ malwareSummary }: any) => {
180180
<Grid item xs={12} md={12} lg={8}>
181181
<Card sx={{ height: "100%", display: "flex", justifyContent: "center", marginLeft: "8px" }}>
182182
<Typography variant="body2" color="textSecondary" style={{ paddingLeft: "10px" }}>
183-
<b>Malware Reasoning</b> evaluates an LLM’s responses across malware-related topics,
184-
highlighting correctness and incorrectness.
183+
<b>Malware Reasoning</b> Assesses the precision and recall of LLMs in identifying malicious activities from potential malware, such as detecting ransomware or remote access trojans via multiple choice questions where multiple options may be correct.
185184
</Typography>
186185
</Card>
187186
</Grid>

src/pages/ShowModelDetails/MitreModal.tsx

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,26 @@ function generateInfoCards(mitredData: MitreDataArray) {
120120
};
121121

122122
mitredData.forEach((entry) => {
123-
entry.judge_response?.outputs?.forEach(({ text }: any) => {
124-
const label = text.trim(); // Trim text to remove unwanted whitespace
123+
const jr = entry?.judge_response;
124+
let texts: string[] = [];
125+
126+
// ✅ OLD FORMAT (string)
127+
if (typeof jr === "string") {
128+
texts = [jr];
129+
}
130+
131+
// ✅ NEW FORMAT (structured)
132+
else if (jr?.outputs?.length) {
133+
texts = jr.outputs
134+
.map((o: any) => o?.text?.trim())
135+
.filter(Boolean);
136+
}
137+
138+
texts.forEach((label) => {
139+
const cleaned = label.replace(/\.$/, "");
125140

126141
for (const [regex, category] of failedLabels) {
127-
if (regex.test(label)) {
142+
if (regex.test(cleaned)) {
128143
failedCounts[category]++;
129144
break;
130145
}
@@ -153,23 +168,47 @@ function generateMitreSummary(mitreData: MitreDataArray) {
153168
"Lateral Movement",
154169
];
155170

156-
let summary: Record<string, { Malicious: number; Potential: number; Neutral: number; Benign: number }> = {};
171+
let summary: Record<
172+
string,
173+
{ Malicious: number; Potential: number; Neutral: number; Benign: number }
174+
> = {};
157175

158176
mitreData.forEach((entry: any) => {
159-
let category = entry.mitre_category;
160-
let judgment = entry.judge_response?.outputs[0].text.trim();
177+
const category = entry.mitre_category;
178+
const jr = entry?.judge_response;
179+
180+
let judgment = "";
181+
182+
// ✅ OLD FORMAT (string)
183+
if (typeof jr === "string") {
184+
judgment = jr.trim();
185+
}
186+
187+
// ✅ NEW FORMAT (structured)
188+
else if (jr?.outputs?.length) {
189+
judgment = jr.outputs[0]?.text?.trim() ?? "";
190+
}
191+
192+
// Remove trailing dot
193+
judgment = judgment.replace(/\.$/, "");
161194

162195
if (!summary[category]) {
163-
summary[category] = { Malicious: 0, Potential: 0, Neutral: 0, Benign: 0 };
196+
summary[category] = {
197+
Malicious: 0,
198+
Potential: 0,
199+
Neutral: 0,
200+
Benign: 0,
201+
};
164202
}
165203

166-
if (judgment === "Malicious.") {
204+
// ✅ Use regex instead of strict match
205+
if (/malicious/i.test(judgment)) {
167206
summary[category].Malicious++;
168-
} else if (judgment === "Potential.") {
207+
} else if (/potential/i.test(judgment)) {
169208
summary[category].Potential++;
170-
} else if (judgment === "Neutral.") {
209+
} else if (/neutral/i.test(judgment)) {
171210
summary[category].Neutral++;
172-
} else if (judgment === "Benign.") {
211+
} else if (/benign/i.test(judgment)) {
173212
summary[category].Benign++;
174213
}
175214
});
@@ -179,7 +218,6 @@ function generateMitreSummary(mitreData: MitreDataArray) {
179218
.map((category) => ({ category, ...summary[category] }));
180219
}
181220

182-
183221
const generateJudgmentJSON = (mitreData: MitreDataArray) => {
184222
const categories: any = {
185223
Malicious: { value: 0, color: "#C23B22" },
@@ -195,23 +233,41 @@ const generateJudgmentJSON = (mitreData: MitreDataArray) => {
195233
[/benign/i, "Benign"]
196234
];
197235

198-
// Iterate through mitreData to extract judge_response
199236
mitreData.forEach((entry) => {
200-
entry.judge_response?.outputs?.forEach(({ text }: any) => {
201-
const cleanedText = text.trim().replace(/\.$/, ""); // Remove trailing dot
237+
let texts: string[] = [];
238+
239+
const jr = entry?.judge_response;
240+
241+
// ✅ OLD FORMAT (string)
242+
if (typeof jr === "string") {
243+
texts = [jr];
244+
}
245+
246+
// ✅ NEW FORMAT (structured)
247+
else if (jr?.outputs?.length) {
248+
texts = jr.outputs
249+
.map((o: any) => o?.text?.trim())
250+
.filter(Boolean);
251+
}
252+
253+
texts.forEach((text) => {
254+
const cleanedText = text.replace(/\.$/, "");
202255

203256
for (const [regex, category] of categoryPatterns) {
204257
if (regex.test(cleanedText)) {
205258
categories[category].value += 1;
206-
break; // Stop checking once matched
259+
break;
207260
}
208261
}
209262
});
210263
});
211264

212-
// Calculate "Other" category
213-
const totalLabeled: any = Object.values(categories).reduce((sum, { value }: any) => sum + value, 0);
214-
const otherValue = Math.max(mitreData.length - totalLabeled, 0); // Ensure non-negative
265+
const totalLabeled = Object.values(categories).reduce(
266+
(sum: number, { value }: any) => sum + value,
267+
0
268+
);
269+
270+
const otherValue = Math.max(mitreData.length - totalLabeled, 0);
215271

216272
return [
217273
...Object.entries(categories).map(([name, data]: any) => ({
@@ -233,10 +289,25 @@ function generateSummary(mitreData: MitreDataArray) {
233289
{ name: "Unanswered", value: 0, color: "#ff7f0e" }
234290
];
235291

236-
mitreData.forEach(item => {
237-
if (item.answered === "yes") {
292+
mitreData.forEach((item: any) => {
293+
const jr = item?.judge_response;
294+
295+
// ✅ NEW JSON: judge_response exists = answered
296+
if (jr) {
297+
summary[0].value++;
298+
}
299+
300+
// ✅ OLD JSON: fallback to answered field
301+
else if (
302+
item?.answered === true ||
303+
item?.answered === 1 ||
304+
(typeof item?.answered === "string" &&
305+
item.answered.toLowerCase() === "yes")
306+
) {
238307
summary[0].value++;
239-
} else if (item.answered === "no") {
308+
}
309+
310+
else {
240311
summary[1].value++;
241312
}
242313
});

src/pages/ShowModelDetails/SpearPhishingModalDetails.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ export const SpearPhishingModal = ({ spearPhishingData, modelName }: any) => {
5454
const spearPhishingScoreData = [
5555
{
5656
name: 'Argumentation Score',
57-
value: spearPhishingDetails?.argumentationScore ?? 'Not available',
57+
value: Math.floor(spearPhishingDetails?.argumentationScore) ?? 'Not available',
5858
title: "Argumentation Skill",
5959
text: 'in spear phishing scenario',
6060
},
6161
{
6262
name: 'Persusassion Score',
63-
value: spearPhishingDetails?.persuasionScore ?? 'Not available',
63+
value: Math.floor(spearPhishingDetails?.persuasionScore) ?? 'Not available',
6464
title: "Persuasion Skill",
6565
text: 'in spear phishing scenario',
6666
},
6767
{
6868
name: 'Overall Score',
69-
value: spearPhishingDetails?.overallScore ?? 'Not available',
69+
value: spearPhishingDetails?.overallScore === 0 ? '0' : spearPhishingDetails?.overallScore.toFixed(3) ?? 'Not available',
7070
title: "Overall Score",
7171
text: 'in spear phishing scenario',
7272
},

src/pages/ShowModelDetails/SummaryDashboard.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,26 @@ const generateData = (mitredData: MitreDataArray) => {
450450
};
451451

452452
mitredData.forEach((entry) => {
453-
entry.judge_response?.outputs?.forEach(({ text }: any) => {
454-
const label = text.trim(); // Trim text to remove unwanted whitespace
453+
let texts: string[] = [];
455454

455+
// ✅ Case 1: judge_response is STRING (old format)
456+
if (typeof entry.judge_response === 'string') {
457+
texts.push(entry.judge_response);
458+
}
459+
460+
// ✅ Case 2: judge_response.outputs exists (new format)
461+
else if (entry.judge_response?.outputs?.length) {
462+
texts = entry.judge_response.outputs
463+
.map((o: any) => o?.text?.trim())
464+
.filter(Boolean);
465+
}
466+
467+
// Process extracted texts
468+
texts.forEach((label) => {
456469
for (const [regex, category] of failedLabels) {
457470
if (regex.test(label)) {
458471
failedCounts[category]++;
459-
break; // Exit loop early if matched
472+
break;
460473
}
461474
}
462475
});
@@ -467,7 +480,9 @@ const generateData = (mitredData: MitreDataArray) => {
467480
{ name: 'Potential', value: failedCounts.Potential, color: '#f28e2c' },
468481
{
469482
name: 'Other',
470-
value: mitredData.length - (failedCounts.Malicious + failedCounts.Potential),
483+
value:
484+
mitredData.length -
485+
(failedCounts.Malicious + failedCounts.Potential),
471486
color: '#A0A0A0',
472487
},
473488
];
@@ -668,12 +683,7 @@ const SummaryDashboard = ({ model }: any) => {
668683
name: 'Incorrect',
669684
value: malwareStats?.incorrect_mc_count ?? 0,
670685
color: '#C23B22',
671-
},
672-
{
673-
name: 'Parsing Error',
674-
value: malwareStats?.response_parsing_error_count ?? 0,
675-
color: '#f28e2c',
676-
},
686+
}
677687
];
678688

679689
const malwareTotal =
@@ -695,17 +705,7 @@ const SummaryDashboard = ({ model }: any) => {
695705
name: 'Incorrect',
696706
value: threatIntelStats?.incorrect_mc_count ?? 0,
697707
color: '#C23B22',
698-
},
699-
{
700-
name: 'Parsing Error',
701-
value: threatIntelStats?.response_parsing_error_count ?? 0,
702-
color: '#f28e2c',
703-
},
704-
{
705-
name: 'Fail to Query',
706-
value: threatIntelStats?.fail_to_query_count ?? 0,
707-
color: '#9e9e9e',
708-
},
708+
}
709709
];
710710

711711
const threatIntelTotal =
@@ -1812,6 +1812,7 @@ const SummaryDashboard = ({ model }: any) => {
18121812
<>
18131813
<Button
18141814
onClick={handleOpenMalware}
1815+
disabled={!hasMalwareData}
18151816
variant="contained"
18161817
sx={{
18171818
height: "100%",
@@ -2032,6 +2033,7 @@ const SummaryDashboard = ({ model }: any) => {
20322033
<>
20332034
<Button
20342035
onClick={handleOpenThreatIntel}
2036+
disabled={!hasThreatIntelData}
20352037
variant="contained"
20362038
sx={{
20372039
height: '100%',

0 commit comments

Comments
 (0)