Skip to content

Commit 72e214b

Browse files
committed
添加了爬取cve编号的支持
1 parent f852b50 commit 72e214b

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

src/main/java/xin/ctkqiang/controller/DatabaseController.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public void CreateTableIfNotExists() {
142142
+ "type VARCHAR(50),"
143143
+ "platform VARCHAR(50),"
144144
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP,"
145+
+ "cve VARCHAR(20),"
145146
+ "PRIMARY KEY (id)"
146147
+ ");";
147148

@@ -211,8 +212,8 @@ public int AddExploit(List<Exploit> exploit_list) {
211212
long SuccessCount = 0;
212213

213214
// 准备参数化SQL语句
214-
stringBuilder.append("INSERT INTO records (id, description, date, author, type, platform) ");
215-
stringBuilder.append("VALUES (?, ?, ?, ?, ?, ?)");
215+
stringBuilder.append("INSERT INTO records (id, description, date, author, type, platform, cve) ");
216+
stringBuilder.append("VALUES (?, ?, ?, ?, ?, ?, ?)");
216217

217218
// 确保输入列表不为空
218219
assert exploit_list != null;
@@ -235,6 +236,7 @@ public int AddExploit(List<Exploit> exploit_list) {
235236
PSTMT.setString(4, exploit.getAuthor());
236237
PSTMT.setString(5, exploit.getType());
237238
PSTMT.setString(6, exploit.getPlatform());
239+
PSTMT.setString(7, exploit.getCve());
238240

239241
PSTMT.addBatch();
240242
}
@@ -289,6 +291,7 @@ public List<Exploit> GetAllExploits() {
289291
exploit.setAuthor(rs.getString("author"));
290292
exploit.setType(rs.getString("type"));
291293
exploit.setPlatform(rs.getString("platform"));
294+
exploit.setCve(rs.getString("cve"));
292295

293296
// 添加到结果列表
294297
exploits.add(exploit);
@@ -403,13 +406,14 @@ public int ExportToSQL(List<Exploit> exploits) {
403406
// 为每条记录生成INSERT语句
404407
for (Exploit e : exploits) {
405408
String sql = String.format(
406-
"INSERT INTO exploits (id, description, date, author, type, platform) VALUES (%d, '%s', '%s', '%s', '%s', '%s');\n",
409+
"INSERT INTO exploits (id, description, date, author, type, platform, cve) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s');\n",
407410
e.getId(),
408411
EscapeSql(e.getDescription()),
409412
e.getDate(),
410413
EscapeSql(e.getAuthor()),
411414
EscapeSql(e.getType()),
412-
EscapeSql(e.getPlatform()));
415+
EscapeSql(e.getPlatform()),
416+
EscapeSql(e.getCve()));
413417
writer.write(sql);
414418
}
415419

@@ -452,15 +456,16 @@ public int ExportToCSV(List<Exploit> exploits) {
452456

453457
try (FileWriter Writer = new FileWriter(FilePath)) {
454458
// 写入CSV表头
455-
Writer.write("描述,日期,作者,类型,平台\n");
459+
Writer.write("描述,日期,作者,类型,平台,CVE编号\n");
456460

457461
// 写入每条记录
458462
for (Exploit e : exploits) {
459463
Writer.write(CsvSafe(e.getDescription()) + "," +
460464
CsvSafe(e.getDate()) + "," +
461465
CsvSafe(e.getAuthor()) + "," +
462466
CsvSafe(e.getType()) + "," +
463-
CsvSafe(e.getPlatform()) + "\n");
467+
CsvSafe(e.getPlatform()) + "," +
468+
CsvSafe(e.getCve()) + "\n");
464469
}
465470

466471
System.out.println("✅ CSV 导出完成,保存路径:" + FilePath);

src/main/java/xin/ctkqiang/controller/ExploitDbController.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public void Crawl(int pageSize, boolean isExport, String extension) {
144144
JsonNode authorNode = Node.get("author");
145145
JsonNode typeNode = Node.get("type");
146146
JsonNode platformNode = Node.get("platform");
147+
// 添加获取CVE编号的节点
148+
JsonNode codeNode = Node.get("code");
147149

148150
// 解析描述信息(数组格式)
149151
if (descriptionNode != null && descriptionNode.isArray() && descriptionNode.size() > 1) {
@@ -180,6 +182,23 @@ public void Crawl(int pageSize, boolean isExport, String extension) {
180182
exploit.setPlatform("");
181183
}
182184

185+
// 解析CVE编号
186+
if (codeNode != null && codeNode.isArray()) {
187+
// 遍历code数组,查找code_type为"cve"的项
188+
for (JsonNode codeItem : codeNode) {
189+
JsonNode codeTypeNode = codeItem.get("code_type");
190+
if (codeTypeNode != null && "cve".equals(codeTypeNode.asText())) {
191+
JsonNode cveCodeNode = codeItem.get("code");
192+
if (cveCodeNode != null) {
193+
exploit.setCve("CVE-" + cveCodeNode.asText());
194+
} else {
195+
exploit.setCve("N/A");
196+
}
197+
break;
198+
}
199+
}
200+
}
201+
183202
// 添加到结果列表
184203
exploits.add(exploit);
185204
}
@@ -281,14 +300,14 @@ public int ExportToSQL(List<Exploit> exploits) {
281300
*/
282301
public static void PrintExploitTable(List<Exploit> exploits) {
283302
// 定义表格格式
284-
String format = "| %-4s | %-40s | %-10s | %-15s | %-10s | %-10s |%n";
303+
String format = "| %-2s | %-40s | %-10s | %-15s | %-10s | %-10s | %-20s |%n";
285304

286305
// 打印表头
287306
System.out.println(
288-
"+------+------------------------------------------+------------+-----------------+------------+------------+");
289-
System.out.printf(format, "编号", "描述", "日期", "作者", "类型", "平台");
307+
"+------+------------------------------------------+------------+-----------------+------------+------------+----------------------+");
308+
System.out.printf(format, "编号", "描述", "日期", "作者", "类型", "平台", "CVE编号");
290309
System.out.println(
291-
"+------+------------------------------------------+------------+-----------------+------------+------------+");
310+
"+------+------------------------------------------+------------+-----------------+------------+------------+----------------------+");
292311

293312
// 打印表格内容
294313
int index = 1;
@@ -299,14 +318,15 @@ public static void PrintExploitTable(List<Exploit> exploits) {
299318
String author = truncateAndPad(e.getAuthor().trim(), 15);
300319
String type = padRight(e.getType().trim(), 10);
301320
String platform = padRight(e.getPlatform().trim(), 10);
321+
String cve = padRight(e.getCve().trim(), 20);
302322

303323
// 打印一行数据
304-
System.out.printf(format, index++, desc, date, author, type, platform);
324+
System.out.printf(format, index++, desc, date, author, type, platform, cve);
305325
}
306326

307327
// 打印表格底部
308328
System.out.println(
309-
"+------+------------------------------------------+------------+-----------------+------------+------------+");
329+
"+------+------------------------------------------+------------+-----------------+------------+------------+----------------------+");
310330
}
311331

312332
/**

src/main/java/xin/ctkqiang/dto/Exploit.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class Exploit {
77
private String author;
88
private String type;
99
private String platform;
10+
private String cve;
1011

1112
public String getId() {
1213
return id;
@@ -56,4 +57,12 @@ public void setPlatform(String platform) {
5657
this.platform = platform;
5758
}
5859

60+
public String getCve() {
61+
return cve == null ? "N/A" : cve;
62+
}
63+
64+
public void setCve(String cve) {
65+
this.cve = cve;
66+
}
67+
5968
}

0 commit comments

Comments
 (0)