Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c03c69

Browse files
committed
Parsers refactoring
1 parent7a2a6ca commit2c03c69

File tree

15 files changed

+302
-133
lines changed

15 files changed

+302
-133
lines changed

‎server/constants.py‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎server/constants/__init__.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
Constants module initialization
3+
"""
4+
5+
# Import all constants explicitly
6+
from .api_endpointsimport (
7+
EPSS_API_URL,
8+
PACKETSTORM_URL,
9+
NUCLEI_URL,
10+
KEV_URL,
11+
GITHUB_API_URL,
12+
VULNCHECK_API_URL,
13+
NVD_API_URL,
14+
EXPLOITDB_URL,
15+
)
16+
17+
from .thresholdsimport (
18+
CVSS_THRESHOLD,
19+
EPSS_THRESHOLD,
20+
)
21+
22+
from .directoriesimport (
23+
DATA_ROOT,
24+
UPLOADS_DIRECTORY,
25+
CACHE_DIRECTORY,
26+
REPORTS_DIRECTORY,
27+
LOGS_DIRECTORY,
28+
DATABASES_DIR,
29+
)
30+
31+
from .messagesimportMESSAGES
32+
33+
# Export all constants for backward compatibility
34+
__all__= [
35+
# API Endpoints
36+
"EPSS_API_URL",
37+
"PACKETSTORM_URL",
38+
"NUCLEI_URL",
39+
"KEV_URL",
40+
"GITHUB_API_URL",
41+
"VULNCHECK_API_URL",
42+
"NVD_API_URL",
43+
"EXPLOITDB_URL",
44+
# Thresholds
45+
"CVSS_THRESHOLD",
46+
"EPSS_THRESHOLD",
47+
# Directories
48+
"DATA_ROOT",
49+
"UPLOADS_DIRECTORY",
50+
"CACHE_DIRECTORY",
51+
"REPORTS_DIRECTORY",
52+
"LOGS_DIRECTORY",
53+
"DATABASES_DIR",
54+
# Messages
55+
"MESSAGES",
56+
]

‎server/constants/api_endpoints.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# API endpoints for external services
2+
EPSS_API_URL="https://api.first.org/data/v1/epss?cve={cve_id}"
3+
PACKETSTORM_URL="https://packetstormsecurity.com/search/?q={cve_id}"
4+
NUCLEI_URL= (
5+
"https://raw.githubusercontent.com/projectdiscovery/nuclei-templates/main/cves.json"
6+
)
7+
KEV_URL="https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json"
8+
GITHUB_API_URL="https://poc-in-github.motikan2010.net/api/v1/"
9+
VULNCHECK_API_URL="https://api.vulncheck.com/v3/index/vulncheck-kev"
10+
NVD_API_URL="https://services.nvd.nist.gov/rest/json/cves/2.0"
11+
EXPLOITDB_URL="https://gitlab.com/exploit-database/exploitdb/-/raw/main/files_exploits.csv?ref_type=heads"

‎server/constants/directories.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
importos
2+
3+
# Base directory for all app data
4+
DATA_ROOT=os.path.join(os.path.dirname(__file__),"..","exploit_seek_data")
5+
6+
# Directories
7+
UPLOADS_DIRECTORY=os.path.join(DATA_ROOT,"uploads")
8+
CACHE_DIRECTORY=os.path.join(DATA_ROOT,"cache")
9+
REPORTS_DIRECTORY=os.path.join(DATA_ROOT,"reports")
10+
LOGS_DIRECTORY=os.path.join(DATA_ROOT,"logs")
11+
DATABASES_DIR=os.path.join(DATA_ROOT,"databases")
12+
13+
# Create directories
14+
fordirectoryin [
15+
DATA_ROOT,
16+
UPLOADS_DIRECTORY,
17+
CACHE_DIRECTORY,
18+
REPORTS_DIRECTORY,
19+
LOGS_DIRECTORY,
20+
DATABASES_DIR,
21+
]:
22+
os.makedirs(directory,exist_ok=True)

‎server/constants/messages.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
MESSAGES= {
2+
"ENG": {
3+
"empty_input":"Empty input",
4+
"no_valid_cves":"No valid CVEs found in the input",
5+
"no_file_uploaded":"No file uploaded",
6+
"no_file_selected":"No file selected",
7+
"invalid_file_format":"Invalid file format. Only XML, PDF, and TXT files are allowed.",
8+
"no_cves_in_file":"No CVEs found in the file",
9+
},
10+
"RUS": {
11+
"empty_input":"Пустой ввод",
12+
"no_valid_cves":"Не найдено допустимых CVE во введенных данных",
13+
"no_file_uploaded":"Файл не загружен",
14+
"no_file_selected":"Файл не выбран",
15+
"invalid_file_format":"Неверный формат файла. Разрешены только файлы XML, PDF и TXT.",
16+
"no_cves_in_file":"В файле не найдено CVE",
17+
},
18+
}

‎server/constants/thresholds.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Thresholds for vulnerability assessment
2+
CVSS_THRESHOLD=6.0
3+
EPSS_THRESHOLD=0.2

‎server/cve_parsers.py‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

‎server/parsers/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .redcheck_parserimportRedCheckParser
2+
from .nmap_parserimportNmapParser
3+
from .manual_parserimportManualParser
4+
5+
__all__= ["RedCheckParser","NmapParser","ManualParser"]

‎server/parsers/base_parser.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fromabcimportABC,abstractmethod
2+
fromlogger_configimportget_logger
3+
4+
5+
classBaseParser(ABC):
6+
"""Base class for all CVE parsers"""
7+
8+
def__init__(self):
9+
self.logger=get_logger()
10+
11+
defparse(self,content):
12+
"""Parse content and return list of CVEs"""
13+
ifnotcontent:
14+
self.logger.warning("Empty content provided")
15+
return []
16+
returnself._parse(content)
17+
18+
@abstractmethod
19+
def_parse(self,content):
20+
"""Actual parsing implementation"""
21+
pass
22+
23+
@abstractmethod
24+
defget_name(self):
25+
"""Return parser name"""
26+
pass

‎server/parsers/manual_parser.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
importre
2+
from .base_parserimportBaseParser
3+
4+
5+
classManualParser(BaseParser):
6+
defget_name(self):
7+
return"Manual Input"
8+
9+
def_parse(self,content):
10+
"""Parse manual input text"""
11+
try:
12+
cve_pattern=r"CVE-(\d{4}-\d{4,7})"
13+
cve_matches=re.findall(cve_pattern,str(content),re.IGNORECASE)
14+
returnset(cve_matches)ifcve_matcheselse []
15+
exceptExceptionase:
16+
self.logger.error(f"Error parsing manual input:{str(e)}")
17+
return []

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp