feat:更改代码分布,实现模块化添加功能
Some checks failed
Python application test / build (pull_request) Failing after 12m34s
Some checks failed
Python application test / build (pull_request) Failing after 12m34s
This commit is contained in:
37
detection/Regexdetection.py
Normal file
37
detection/Regexdetection.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import re
|
||||
from typing import Dict, List, Tuple
|
||||
from .utils import remove_comments
|
||||
|
||||
def find_dangerous_functions(
|
||||
file_content: str, file_extension: str
|
||||
) -> Dict[str, List[Tuple[int, str]]]:
|
||||
patterns = {
|
||||
".py": {
|
||||
r"\bsystem\(": "high",
|
||||
r"\bexec\(": "high",
|
||||
r"\bpopen\(": "medium",
|
||||
r"\beval\(": "high",
|
||||
r"\bsubprocess\.run\(": "medium",
|
||||
r"\b__getattribute__\(": "high",
|
||||
r"\bgetattr\(": "medium",
|
||||
r"\b__import__\(": "high",
|
||||
},
|
||||
".js": {
|
||||
r"\beval\(": "high",
|
||||
r"\bexec\(": "high",
|
||||
r"\bchild_process\.exec\(": "high",
|
||||
},
|
||||
".cpp": {
|
||||
r"\bsystem\(": "high",
|
||||
},
|
||||
}
|
||||
risk_patterns = patterns.get(file_extension, {})
|
||||
classified_results = {"high": [], "medium": [], "low": [], "none": []}
|
||||
for line_number, line in enumerate(file_content.split("\n"), start=1):
|
||||
clean_line = remove_comments(line, file_extension)
|
||||
if not clean_line:
|
||||
continue
|
||||
for pattern, risk_level in risk_patterns.items():
|
||||
if re.search(pattern, clean_line):
|
||||
classified_results[risk_level].append((line_number, clean_line))
|
||||
return classified_results
|
||||
Reference in New Issue
Block a user