Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit regex to exclude comments (to avoid false positives) #860

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"hostRequirements": {
"cpus": 4
},
"waitFor": "onCreateCommand",
"updateContentCommand": "python3 -m pip install -r requirements.txt",
"postCreateCommand": "",
"customizations": {
"codespaces": {
"openFiles": []
},
"vscode": {
"extensions": [
"EditorConfig.EditorConfig",
"ms-python.python"
]
}
}
}
8 changes: 4 additions & 4 deletions oletools/olevba.py
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,7 @@ def detect_autoexec(vba_code, obfuscation=None):
for keyword in keywords:
#TODO: if keyword is already a compiled regex, use it as-is
# search using regex to detect word boundaries:
match = re.search(r'(?i)\b' + re.escape(keyword) + r'\b', vba_code)
match = re.search(r'(?i)^(?:[^\']|\b).*\b' + re.escape(keyword) + r'\b', vba_code)
if match:
found_keyword = match.group()
results.append((found_keyword, description + obf_text))
Expand All @@ -2192,7 +2192,7 @@ def detect_autoexec(vba_code, obfuscation=None):
for keyword in keywords:
#TODO: if keyword is already a compiled regex, use it as-is
# search using regex to detect word boundaries:
match = re.search(r'(?i)\b' + keyword + r'\b', vba_code)
match = re.search(r'(?i)^(?:[^\']|\b).*\b' + keyword + r'\b', vba_code)
if match:
found_keyword = match.group()
results.append((found_keyword, description + obf_text))
Expand All @@ -2218,15 +2218,15 @@ def detect_suspicious(vba_code, obfuscation=None):
for keyword in keywords:
# search using regex to detect word boundaries:
# note: each keyword must be escaped if it contains special chars such as '\'
match = re.search(r'(?i)\b' + re.escape(keyword) + r'\b', vba_code)
match = re.search(r'(?i)^(?:[^\']|\b).*\b' + re.escape(keyword) + r'\b', vba_code)
if match:
found_keyword = match.group()
results.append((found_keyword, description + obf_text))
for description, keywords in SUSPICIOUS_KEYWORDS_REGEX.items():
for keyword in keywords:
# search using regex to detect word boundaries:
# note: each keyword must NOT be escaped because it is an actual regex
match = re.search(r'(?i)\b' + keyword + r'\b', vba_code)
match = re.search(r'(?i)^(?:[^\']|\b).*\b' + keyword + r'\b', vba_code)
if match:
found_keyword = match.group()
results.append((found_keyword, description + obf_text))
Expand Down
Loading