-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplot_vulnerabilities.py
More file actions
191 lines (157 loc) · 6.63 KB
/
Copy pathplot_vulnerabilities.py
File metadata and controls
191 lines (157 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import json
import matplotlib.pyplot as plt
import numpy as np
def main():
# try:
# with open("cross_referenced_results_pocgen.json", "r") as f:
# data = json.load(f)
# except FileNotFoundError:
# print("Error: cross_referenced_results_pocgen.json not found.")
# return
vuln_types = [
"path_traversal",
"prototype_pollution",
"command_injection",
"code_injection",
"ReDoS"
]
formatted_labels = [
"Path Traversal",
"Prototype Pollution",
"Command Injection",
"Code Injection",
"ReDoS"
]
categories = ["success", "failure", "false positive"]
explodejs_results = {
"Path Traversal": [81, 86, 0],
"Prototype Pollution": [50, 130, 0],
"Command Injection": [47, 45, 0],
"Code Injection": [4, 31, 0],
"ReDoS": [0, 86, 0]
}
agent_results = {
"Path Traversal": [2, 18, 0],
"Prototype Pollution": [8, 11, 1],
"Command Injection": [8, 11, 1],
"Code Injection": [6, 14, 0],
"ReDoS": [4, 16, 0]
}
agent_4omini_results = { # 74% success rate
"Path Traversal": [0, 18, 2],
"Prototype Pollution": [2, 12, 6],
"Command Injection": [4, 4, 12],
"Code Injection": [6, 9, 5],
"ReDoS": [3, 10, 7]
}
pocgen_results = {
"Path Traversal": [133, 32, 2],
"Prototype Pollution": [122, 31, 27],
"Command Injection": [81, 10, 1],
"Code Injection": [24, 10, 1],
"ReDoS": [39, 44, 2]
}
pocgen_4omini_results = { # 77.14% success rate
"Path Traversal": [148, 18, 1],
"Prototype Pollution": [152, 25, 3],
"Command Injection": [85, 6, 1],
"Code Injection": [12, 7, 16],
"ReDoS": [35, 49, 2]
}
# Combine data
methods_dict = {
"ExplodeJS": explodejs_results,
"Mini-SWE-Agent": agent_results,
"PoCGen (gpt-4o-mini)": pocgen_4omini_results,
"Mini-SWE-Agent (gpt-4o-mini)": agent_4omini_results,
"PoCGen": pocgen_results
}
all_methods = ["PoCGen", "ExplodeJS", "Mini-SWE-Agent", "PoCGen (gpt-4o-mini)", "Mini-SWE-Agent (gpt-4o-mini)"]
all_method_counts = {m: {lbl: {cat: 0 for cat in categories} for lbl in formatted_labels} for m in all_methods}
# 1. PoCGen data from JSON
# for vuln, lbl in zip(vuln_types, formatted_labels):
# if vuln in data:
# for key, outcome in data[vuln].items():
# if outcome in categories:
# all_method_counts["PoCGen"][lbl][outcome] += 1
# Fill the rest
for m in ["ExplodeJS", "Mini-SWE-Agent", "PoCGen (gpt-4o-mini)", "Mini-SWE-Agent (gpt-4o-mini)", "PoCGen"]:
res_dict = methods_dict[m]
for lbl in formatted_labels:
if lbl in res_dict:
all_method_counts[m][lbl]["success"] = res_dict[lbl][0]
all_method_counts[m][lbl]["failure"] = res_dict[lbl][1]
all_method_counts[m][lbl]["false positive"] = res_dict[lbl][2]
# Plotting setup
fig = plt.figure(figsize=(18, 14))
gs = fig.add_gridspec(4, 3)
locations = {
"PoCGen": gs[0:2, 0],
"PoCGen (gpt-4o-mini)": gs[2:4, 0],
"ExplodeJS": gs[1:3, 2],
"Mini-SWE-Agent": gs[0:2, 1],
"Mini-SWE-Agent (gpt-4o-mini)": gs[2:4, 1]
}
ax_dict = {}
main_ax = None
for method, pos in locations.items():
if main_ax is None:
ax = fig.add_subplot(pos)
main_ax = ax
else:
ax = fig.add_subplot(pos, sharey=main_ax)
ax_dict[method] = ax
x = np.arange(len(formatted_labels))
width = 0.75
colors = {"success": "mediumseagreen", "failure": "orange", "false positive": "red"}
for method, ax in ax_dict.items():
method_counts = all_method_counts[method]
# Calculate percentages
percentages = {cat: [] for cat in categories}
for lbl in formatted_labels:
total = sum(method_counts[lbl][cat] for cat in categories)
for cat in categories:
if total > 0:
percentages[cat].append((method_counts[lbl][cat] / total) * 100)
else:
percentages[cat].append(0)
bottoms = np.zeros(len(formatted_labels))
for cat in categories:
# We only label the first subplot to avoid duplicate legends
label = cat.title() if method == "PoCGen" else None
ax.bar(x, percentages[cat], width, label=label, bottom=bottoms, color=colors[cat])
# Add text in the middle of each bar segment (absolute counts)
for i in range(len(formatted_labels)):
lbl = formatted_labels[i]
pct_value = percentages[cat][i]
abs_value = method_counts[lbl][cat]
if pct_value > 0:
ax.text(x[i], bottoms[i] + pct_value / 2, f"{abs_value}", ha='center', va='center', color='black', fontweight='bold', fontsize=13)
bottoms += np.array(percentages[cat])
# Calculate overall success rate
total_success = sum(method_counts[lbl]["success"] for lbl in formatted_labels)
total_all = sum(method_counts[lbl][cat] for lbl in formatted_labels for cat in categories)
overall_success_rate = (total_success / total_all) * 100 if total_all > 0 else 0
# Formulate the title to display
display_title = method
if method == "PoCGen":
display_title = "PoCGen (gpt-5-mini)"
elif method == "Mini-SWE-Agent":
display_title = "Mini-SWE-Agent (gpt-5-mini)"
display_title += f"\nSuccess Rate: {overall_success_rate:.1f}%"
# Place the title at the top of the main ax
ax.set_title(display_title, fontsize=16)
ax.set_xticks(x)
ax.set_xticklabels(formatted_labels, rotation=45, ha="right", fontsize=14)
ax.set_ylim(0, 100)
ax_dict["PoCGen"].set_ylabel('Success Rate (%)', fontsize=16)
ax_dict["PoCGen (gpt-4o-mini)"].set_ylabel('Success Rate (%)', fontsize=16)
# One legend for the whole figure, placed on top
fig.legend(loc='upper right', bbox_to_anchor=(0.9, 0.9), fontsize=16, ncol=1)
# Adjust layout to make room for legend and title
# plt.subplots_adjust(hspace=1.5, top=0.85, bottom=0.25)
plt.tight_layout()
plt.savefig("vulnerability_plot.png", dpi=300)
print("Plot saved to vulnerability_plot.png")
if __name__ == "__main__":
main()