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

test suite and workflows #51

Merged
merged 33 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dbbd877
adding workflow and stub test file
akielaries Dec 3, 2023
d30c625
Update README.md
akielaries Dec 3, 2023
f845a55
testing workflow
akielaries Dec 3, 2023
1d166a5
updating versions in workflow
akielaries Dec 3, 2023
742996d
testing build workflow
akielaries Dec 3, 2023
2bcf75a
updating workflows
akielaries Dec 3, 2023
2c496e2
Update README.md
akielaries Dec 3, 2023
45b85ba
changes to build and test workflow. should only run when changes to s…
akielaries Dec 3, 2023
9012886
testing trigger for workflows
akielaries Dec 3, 2023
ed7cc23
testing trigger for workflows
akielaries Dec 3, 2023
6b55ead
testing trigger for workflows
akielaries Dec 3, 2023
eb8438a
testing trigger for workflows
akielaries Dec 3, 2023
5f82990
updating unit tests for parser. fixes #50
akielaries Dec 3, 2023
7e6d33b
updating unit tests for parser. fixes #50
akielaries Dec 3, 2023
b239abb
adding some more tests for Parser class
akielaries Dec 3, 2023
f46ad3a
json files?
akielaries Dec 3, 2023
d19c6c6
Create tests and necessary object
cjb873 Dec 4, 2023
1c97cef
Create None checks and fix off-by-one error in get_lower_bound
cjb873 Dec 4, 2023
09c00b4
Remove references to get_images
cjb873 Dec 4, 2023
8acd64b
Reset json for testing
cjb873 Dec 4, 2023
8b5e1cb
Revert "Remove references to get_images"
cjb873 Dec 4, 2023
ca53232
Recreate
cjb873 Dec 4, 2023
96a95de
Merge pull request #52 from zeek/cjb873/unit_tests
cjb873 Dec 4, 2023
016d477
Update pytest.yml
cjb873 Dec 4, 2023
ce44265
Add tests to path
cjb873 Dec 4, 2023
4c7378a
Update test_search.py
cjb873 Dec 4, 2023
8d85193
Change file paths
cjb873 Dec 4, 2023
31c0f5d
Change file path to saved rankings
cjb873 Dec 4, 2023
46104a5
Changed equals to approximately equals for ranking test
cjb873 Dec 4, 2023
6114a46
Sort rankings
cjb873 Dec 4, 2023
1ce615e
Create for testing scraper
cjb873 Dec 5, 2023
cf7e9e0
Add test_scraper.py
cjb873 Dec 5, 2023
dbb0b9a
Update with checks for None
cjb873 Dec 5, 2023
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
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# BUILDS AND RUNS DOCKER IMAGE
name: Build

on:
push:
branches:
# any branch
- '**'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build Docker Image
run: docker build -t zeek_website . --no-cache

- name: Start Docker Service
run: docker-compose up -d

- name: Stop Docker Service
run: docker-compose down

31 changes: 31 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# RUNS TEST SUITE
name: Test Suite

on:
push:
branches:
# any branch
- '**'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run Unit Tests
run: |
cd zeek-package-website && pytest -s --showlocals tests/test_parser.py tests/test_search.py tests/test_scraper.py

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Build](https://github.com/zeek/package-website/actions/workflows/build.yml/badge.svg)](https://github.com/zeek/package-website/actions/workflows/build.yml)
[![Test Suite](https://github.com/zeek/package-website/actions/workflows/pytest.yml/badge.svg)](https://github.com/zeek/package-website/actions/workflows/pytest.yml)
[![license](https://img.shields.io/github/license/zeek/package-website?color=23228B22)](https://github.com/zeek/package-website/blob/main/LICENSE)

# Zeek Package Website Repository
...

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ fastapi_utils
mistune
markdown
pytest
requests
Empty file.
53 changes: 26 additions & 27 deletions zeek-package-website/app/api/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,34 @@ def parse_data(self) -> dict:

# extract our desired fields
# TODO: pass in header + text to look for
self.author = self.get_line("credits", header)
self.description = self.get_line("description", header)
self.tags = self.get_line("tags", header)
self.version = self.get_line("version", header)
self.get_next("depends", header)
self.test_cmd = self.get_line("test_command", header)
self.build_cmd = self.get_line("build_command", header)
self.url = self.get_line("url", header)
self.summary = self.get_line("summary", header)
self.script_dir = self.get_line("script_dir", header)
self.plugin_dir = self.get_line("plugin_dir", header)
self.readme = self.get_readme()
self.author = self.get_line("credits", header)
self.description = self.get_line("description", header)
self.tags = self.get_line("tags", header)
self.version = self.get_line("version", header)
self.depends = self.get_next("depends", header)
self.test_cmd = self.get_line("test_command", header)
self.build_cmd = self.get_line("build_command", header)
self.url = self.get_line("url", header)
self.summary = self.get_line("summary", header)
self.script_dir = self.get_line("script_dir", header)
self.plugin_dir = self.get_line("plugin_dir", header)
self.readme = self.get_readme()

if self.readme is not None and self.url is not None:
self.get_images()

self.pkg_dict[self.section_header] = {
"description": self.description,
"tags": self.tags,
"version": self.version,
"depends": self.depends,
"test_cmd": self.test_cmd,
"build_cmd": self.build_cmd,
"url": self.url,
"summary": self.summary,
"script_dir": self.script_dir,
"plugin_dir": self.plugin_dir,
"readme": self.readme
"description" : self.description,
"tags" : self.tags,
"version" : self.version,
"depends" : self.depends,
"test_cmd" : self.test_cmd,
"build_cmd" : self.build_cmd,
"url" : self.url,
"summary" : self.summary,
"script_dir" : self.script_dir,
"plugin_dir" : self.plugin_dir,
"readme" : self.readme
}


Expand All @@ -95,8 +96,6 @@ def parse_data(self) -> dict:

return self.pkg_dict



def get_name(self) -> str:
"""
@brief Finds all section headers in the file contents.
Expand Down Expand Up @@ -148,8 +147,8 @@ def get_next(self, text, header) -> list:

if next_match:
next_line = next_match.group(1).strip().split('\n')
# remove tabs
next_line = [ln.replace('\t', '') for ln in next_line]
# remove tabs and leading spaces
next_line = [ln.replace('\t', '').lstrip() for ln in next_line]
else:
next_line = None

Expand Down
6 changes: 6 additions & 0 deletions zeek-package-website/app/api/readme_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def load_packages() -> []:
def find_missing(package: dict) -> []:
missing = []

if(package is None):
return None

for key in package.keys():
if package[key] is None and key in fields.keys():
missing.append(key)
Expand All @@ -42,6 +45,9 @@ def find_missing(package: dict) -> []:

def get_field(readme: str, field: str) -> str:

if readme is None or field is None:
return None

search_term = f"{fields[field]}"

field = re.search(f'(?<=# {search_term})(.*)(?=\n)', readme.lower())
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"description": "A package to detect CVE-2021-42292, a Microsoft Excel priviledge exploit.", "tags": null, "version": "v0.1.0", "depends": null, "test_cmd": "cd testing && btest -c btest.cfg", "build_cmd": null, "url": "https://github.com/corelight/CVE-2021-42292", "summary": "A package to detect CVE-2021-42292, a Microsoft Excel priviledge exploit.", "script_dir": "scripts", "plugin_dir": null, "readme": "## CVE-2021-42292\n\nThis package will detect exploits of [CVE-2021-42292](https://raw.githubusercontent.com/corelight/CVE-2021-42292/master/http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-42292), a Microsoft Excel local\nprivilege escalation vulnerability, and generate a notice in notice.log for it.\n\nhttps://corelight.com/blog/detecting-cve-2021-42292 \n\n#### Detection Method:\n\nThis package detects the vulnerability when the triggering Excel spreadsheet downloads a second spreadsheet.\nThe second spreadsheet is executed with elevated privileges. We can detect Microsoft Excel downloading\na Microsoft Excel file with this script. In our testing on some live networks we monitor,\nthis combination was extremely rare and we have not seen any false positives so far.\n\n#### Usage:\n\n```\n$ zeek -Cr excelsploit_1.pcap packages\n\n$ cat notice.log\n#separator \\x09\n#set_separator ,\n#empty_field (empty)\n#unset_field -\n#path notice\n#open 2021-11-10-10-56-50\n#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p fuid file_mime_type file_desc proto note msg sub src dst p n peer_descr actions email_dest suppress_for remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude\n#types time string addr port addr port string string string enum enum string string addr addr port count string set[enum] set[string] interval string string string double double\n1636433584.277654 CeV1DA2EM1pRTfgWkc 127.0.0.1 51543 127.0.0.1 80 - - - tcp CVE_2021_42292::CVE_2021_42292 127.0.0.1 may be compromised by CVE-2021-42292, MS Office Excel download using Office from 127.0.0.1 detected. See sub field for additional triage information host='127.0.0.1', method='HEAD', user_agent='Microsoft Office Excel 2014', CONTENT-TYPE='application/vnd.ms-excel', uri='/replica.xls' 127.0.0.1 127.0.0.1 80 - - Notice::ACTION_LOG (empty) 3600.000000 - - - - -\n1636433584.311236 CgKWSM1bhhl7K8B6n8 127.0.0.1 51545 127.0.0.1 80 - - - tcp CVE_2021_42292::CVE_2021_42292 127.0.0.1 may be compromised by CVE-2021-42292, MS Office Excel download using Office from 127.0.0.1 detected. See sub field for additional triage information host='127.0.0.1', method='GET', user_agent='Mozilla/4.0 (compatible; ms-office; MSOffice 16)', CONTENT-TYPE='application/vnd.ms-excel', uri='/replica.xls' 127.0.0.1 127.0.0.1 80 - - Notice::ACTION_LOG (empty) 3600.000000 - - - - -\n#close 2021-11-10-10-56-50\n```\n\nSuricata rules are also provided that mirror the detection methodology of the\nZeek package.\n\n#### Links:\n* Associated blog including walk through of code elements: \n * https://corelight.com/blog/detecting-cve-2021-42292 \n* MIME Types:\n * https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n* Excel User Agents:\n * https://developers.whatismybrowser.com/useragents/explore/software_name/excel/\n"}
{"description": "A package to detect CVE-2021-42292, a Microsoft Excel priviledge exploit.", "tags": null, "version": "v0.1.0", "depends": ["zeek >=3.0.0"], "test_cmd": "cd testing && btest -c btest.cfg", "build_cmd": null, "url": "https://github.com/corelight/CVE-2021-42292", "summary": "A package to detect CVE-2021-42292, a Microsoft Excel priviledge exploit.", "script_dir": "scripts", "plugin_dir": null, "readme": "## CVE-2021-42292\n\nThis package will detect exploits of [CVE-2021-42292](https://raw.githubusercontent.com/corelight/CVE-2021-42292/master/http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-42292), a Microsoft Excel local\nprivilege escalation vulnerability, and generate a notice in notice.log for it.\n\nhttps://corelight.com/blog/detecting-cve-2021-42292 \n\n#### Detection Method:\n\nThis package detects the vulnerability when the triggering Excel spreadsheet downloads a second spreadsheet.\nThe second spreadsheet is executed with elevated privileges. We can detect Microsoft Excel downloading\na Microsoft Excel file with this script. In our testing on some live networks we monitor,\nthis combination was extremely rare and we have not seen any false positives so far.\n\n#### Usage:\n\n```\n$ zeek -Cr excelsploit_1.pcap packages\n\n$ cat notice.log\n#separator \\x09\n#set_separator ,\n#empty_field (empty)\n#unset_field -\n#path notice\n#open 2021-11-10-10-56-50\n#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p fuid file_mime_type file_desc proto note msg sub src dst p n peer_descr actions email_dest suppress_for remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude\n#types time string addr port addr port string string string enum enum string string addr addr port count string set[enum] set[string] interval string string string double double\n1636433584.277654 CeV1DA2EM1pRTfgWkc 127.0.0.1 51543 127.0.0.1 80 - - - tcp CVE_2021_42292::CVE_2021_42292 127.0.0.1 may be compromised by CVE-2021-42292, MS Office Excel download using Office from 127.0.0.1 detected. See sub field for additional triage information host='127.0.0.1', method='HEAD', user_agent='Microsoft Office Excel 2014', CONTENT-TYPE='application/vnd.ms-excel', uri='/replica.xls' 127.0.0.1 127.0.0.1 80 - - Notice::ACTION_LOG (empty) 3600.000000 - - - - -\n1636433584.311236 CgKWSM1bhhl7K8B6n8 127.0.0.1 51545 127.0.0.1 80 - - - tcp CVE_2021_42292::CVE_2021_42292 127.0.0.1 may be compromised by CVE-2021-42292, MS Office Excel download using Office from 127.0.0.1 detected. See sub field for additional triage information host='127.0.0.1', method='GET', user_agent='Mozilla/4.0 (compatible; ms-office; MSOffice 16)', CONTENT-TYPE='application/vnd.ms-excel', uri='/replica.xls' 127.0.0.1 127.0.0.1 80 - - Notice::ACTION_LOG (empty) 3600.000000 - - - - -\n#close 2021-11-10-10-56-50\n```\n\nSuricata rules are also provided that mirror the detection methodology of the\nZeek package.\n\n#### Links:\n* Associated blog including walk through of code elements: \n * https://corelight.com/blog/detecting-cve-2021-42292 \n* MIME Types:\n * https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n* Excel User Agents:\n * https://developers.whatismybrowser.com/useragents/explore/software_name/excel/\n"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"description": "A package to detect CVE-2022-23270.", "tags": null, "version": "master", "depends": null, "test_cmd": "cd testing && btest -c btest.cfg", "build_cmd": null, "url": "https://github.com/corelight/CVE-2022-23270-PPTP", "summary": "A package to detect CVE-2022-23270.", "script_dir": "scripts", "plugin_dir": null, "readme": "# CVE-2022-23270\n\nA package to detect CVE-2022-23270, a vulnerability in Microsoft's PPTP implementation.\n\n## Example\n\nYou can run this logic on the included PCAP in the `testing\\traces` directory:\n\n```\n$ zeek -Cr CVE-2022-23270-exploited.pcap packages\n\n$ cat notice.log \n#separator \\x09\n#set_separator\t,\n#empty_field\t(empty)\n#unset_field\t-\n#path\tnotice\n#open\t2022-05-10-23-03-47\n#fields\tts\tuid\tid.orig_h\tid.orig_p\tid.resp_h\tid.resp_p\tfuid\tfile_mime_type\tfile_desc\tproto\tnote\tmsg\tsub\tsrc\tdst\tp\tn\tpeer_descr\tactions\temail_dest\tsuppress_for\tremote_location.country_code\tremote_location.region\tremote_location.city\tremote_location.latitude\tremote_location.longitude\n#types\ttime\tstring\taddr\tport\taddr\tport\tstring\tstring\tstring\tenum\tenum\tstring\tstring\taddr\taddr\tport\tcount\tstring\tset[enum]\tset[string]\tinterval\tstring\tstring\tstring\tdouble\tdouble\n1652212222.744235\tCHhAvVGS1DHFjwGM9\t192.168.88.166\t51143\t192.168.88.157\t1723\t-\t-\t-\ttcp\tCVE202223270::CVE_2022_23270_Attempt\tPotential PPTP CVE-2022-23270 exploit attempt: 192.168.88.166 attempted exploit against 192.168.88.157\t-\t192.168.88.166\t192.168.88.157\t1723\t-\t-\tNotice::ACTION_LOG\t(empty)\t3600.000000\t-\t-\t-\t-\t-\n1652212222.744235\tCHhAvVGS1DHFjwGM9\t192.168.88.166\t51143\t192.168.88.157\t1723\t-\t-\t-\ttcp\tCVE202223270::CVE_2022_23270_Success\tPPTP CVE-2022-23270 exploit success: 192.168.88.166 exploited 192.168.88.157\t-\t192.168.88.166\t192.168.88.157\t1723\t-\t-\tNotice::ACTION_LOG\t(empty)\t3600.000000\t-\t-\t-\t-\t-\n#close\t2022-05-10-23-03-47\n```\n\n## RFCs\n- https://datatracker.ietf.org/doc/html/rfc2637"}
{"description": "A package to detect CVE-2022-23270.", "tags": null, "version": "master", "depends": ["zeek >=4.0.0"], "test_cmd": "cd testing && btest -c btest.cfg", "build_cmd": null, "url": "https://github.com/corelight/CVE-2022-23270-PPTP", "summary": "A package to detect CVE-2022-23270.", "script_dir": "scripts", "plugin_dir": null, "readme": "# CVE-2022-23270\n\nA package to detect CVE-2022-23270, a vulnerability in Microsoft's PPTP implementation.\n\n## Example\n\nYou can run this logic on the included PCAP in the `testing\\traces` directory:\n\n```\n$ zeek -Cr CVE-2022-23270-exploited.pcap packages\n\n$ cat notice.log \n#separator \\x09\n#set_separator\t,\n#empty_field\t(empty)\n#unset_field\t-\n#path\tnotice\n#open\t2022-05-10-23-03-47\n#fields\tts\tuid\tid.orig_h\tid.orig_p\tid.resp_h\tid.resp_p\tfuid\tfile_mime_type\tfile_desc\tproto\tnote\tmsg\tsub\tsrc\tdst\tp\tn\tpeer_descr\tactions\temail_dest\tsuppress_for\tremote_location.country_code\tremote_location.region\tremote_location.city\tremote_location.latitude\tremote_location.longitude\n#types\ttime\tstring\taddr\tport\taddr\tport\tstring\tstring\tstring\tenum\tenum\tstring\tstring\taddr\taddr\tport\tcount\tstring\tset[enum]\tset[string]\tinterval\tstring\tstring\tstring\tdouble\tdouble\n1652212222.744235\tCHhAvVGS1DHFjwGM9\t192.168.88.166\t51143\t192.168.88.157\t1723\t-\t-\t-\ttcp\tCVE202223270::CVE_2022_23270_Attempt\tPotential PPTP CVE-2022-23270 exploit attempt: 192.168.88.166 attempted exploit against 192.168.88.157\t-\t192.168.88.166\t192.168.88.157\t1723\t-\t-\tNotice::ACTION_LOG\t(empty)\t3600.000000\t-\t-\t-\t-\t-\n1652212222.744235\tCHhAvVGS1DHFjwGM9\t192.168.88.166\t51143\t192.168.88.157\t1723\t-\t-\t-\ttcp\tCVE202223270::CVE_2022_23270_Success\tPPTP CVE-2022-23270 exploit success: 192.168.88.166 exploited 192.168.88.157\t-\t192.168.88.166\t192.168.88.157\t1723\t-\t-\tNotice::ACTION_LOG\t(empty)\t3600.000000\t-\t-\t-\t-\t-\n#close\t2022-05-10-23-03-47\n```\n\n## RFCs\n- https://datatracker.ietf.org/doc/html/rfc2637"}
Loading