From cc58b8f261a5dcbeddb3a53f3d3bf490a6729c6b Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sat, 16 Jul 2022 23:41:13 +0100 Subject: [PATCH 01/24] feat: add tests using impacket --- tests/Dockerfile | 9 ++ tests/tests/helpers.py | 68 ++++++++++++ tests/tests/test_options.py | 41 +++++++ tests/tests/test_output.py | 34 ++++++ tests/tests/test_smb_scans.py | 199 ++++++++++++++++++++++++++++++++++ tests/tests/test_tcp_scans.py | 61 +++++++++++ 6 files changed, 412 insertions(+) create mode 100644 tests/Dockerfile create mode 100644 tests/tests/helpers.py create mode 100644 tests/tests/test_options.py create mode 100644 tests/tests/test_output.py create mode 100644 tests/tests/test_smb_scans.py create mode 100644 tests/tests/test_tcp_scans.py diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..47c9cf2 --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,9 @@ +FROM punksecurity/smbeagle +RUN apt update && apt install python3 python3-pip -y +RUN pip install impacket pytest +RUN mkdir /empty_dir +WORKDIR /tests/ +COPY tests/* . +ENTRYPOINT [ "" ] +CMD ["pytest", "-v", "test_output.py"] +#CMD ["pytest", "-k", "not windows", "-rP"] \ No newline at end of file diff --git a/tests/tests/helpers.py b/tests/tests/helpers.py new file mode 100644 index 0000000..8540fca --- /dev/null +++ b/tests/tests/helpers.py @@ -0,0 +1,68 @@ +from impacket import smbserver +import multiprocessing +import os +import subprocess +from time import sleep +import csv +import shutil +import uuid + + +def __setupSMB(address, dir, SMB2 = True): + os.chdir("/empty_dir") + server = smbserver.SimpleSMBServer(listenAddress=address, listenPort=445) + server.addShare("share", dir, "") + server.addCredential("test", 1200, "9FD78381EC915F1AAAD3B435B51404EE", "25EDEDFF26CB970623DDA4733227A3F7") + server.setSMB2Support(SMB2) + server.start() + +def setupSMB(address, dir): + process = multiprocessing.Process(target=__setupSMB, args=[address, dir]) + process.start() + return process + +class SMB(object): + def __init__(self, address = "0.0.0.0", dir_structure = ["fileA", "fileB"]): + self.address = address + self.dir_structure = dir_structure + self.dir = f"/{uuid.uuid4().hex}" + def __enter__(self): + self.smb = setupSMB(self.address, self.dir) + os.mkdir(self.dir) + self.populate_dir(self.dir, self.dir_structure) + def populate_dir(self, dir, dir_structure): + for item in dir_structure: + if type(item) != type( () ) and type(item) != type(""): + raise ValueError("Directory should be list of strings and tuples") + if type(item) == type( () ): + #type tuple, so create folder and then parse that structure + os.mkdir(f"{dir}{os.sep}{item[0]}") + self.populate_dir(f"{dir}{os.sep}{item[0]}", item[1]) + else: + # type string, so make the file + open(f"{dir}{os.sep}{item}", 'a').close() + + def __exit__(self, *args, **kwargs): + self.smb.kill() + shutil.rmtree(self.dir) + #self.smb.close() + +def runSMBeagle(*args, print_out=True): + run = subprocess.run(["smbeagle",*args], stdout = subprocess.PIPE, universal_newlines=True) + if print_out: + print(run.stdout) + return run.stdout + +def runSMBeagleToCSV(*args): + return runSMBeagle("-c","out.csv",*args) + +def runSMBeagleToCSVWithAuth(*args): + return runSMBeagleToCSV("-u","test", "-p", "goose", *args) + +def runSMBeagleToCSVWithAuthAndReturnResults(*args): + print(runSMBeagleToCSVWithAuth(*args)) + with open('out.csv', newline='') as csvfile: + results = list(csv.DictReader(csvfile, delimiter=',', quotechar='"')) + for result in results: + print(result) + return results diff --git a/tests/tests/test_options.py b/tests/tests/test_options.py new file mode 100644 index 0000000..0dcb92d --- /dev/null +++ b/tests/tests/test_options.py @@ -0,0 +1,41 @@ +from helpers import * + +username_or_password_missing_error = "ERROR: Username and Password required on none Windows platforms" +def test_username_and_password_required_on_linux(): + assert username_or_password_missing_error in runSMBeagleToCSV() +def test_password_required_on_linux(): + assert username_or_password_missing_error in runSMBeagleToCSV("-p","goose") +def test_username_required_on_linux(): + assert username_or_password_missing_error in runSMBeagleToCSV("-u","goose") +def test_username_and_password_accepted(): + assert username_or_password_missing_error not in runSMBeagleToCSV("-u","goose", "-p", "goose") +def test_long_username_accepted(): + assert username_or_password_missing_error not in runSMBeagleToCSV("--username","goose", "-p", "goose") +def test_long_password_accepted(): + assert username_or_password_missing_error not in runSMBeagleToCSV("-u","goose", "--password", "goose") + +output_required_error = "At least one option from group 'output' (c, csv-file, e, elasticsearch-host)" +def test_csv_or_elasticsearch_required(): + assert output_required_error in runSMBeagle() +def test_short_csv_accepted(): + assert output_required_error not in runSMBeagle("-c","out.csv") +def test_long_csv_accepted(): + assert output_required_error not in runSMBeagle("--csv-file","out.csv") +def test_short_elasticsearch_accepted(): + assert output_required_error not in runSMBeagle("-e","elasticsearch") +def test_long_elasticsearch_accepted(): + assert output_required_error not in runSMBeagle("--elasticsearch-host","elasticsearch") + + +def test_manual_host_accepted(): + assert "127.0.0.2" in runSMBeagleToCSVWithAuth("-h", "127.0.0.2") +def test_multiple_manual_host_accepted(): + output = runSMBeagleToCSVWithAuth("-h", "127.0.0.2", "127.0.0.3") + assert "127.0.0.2" in output and "127.0.0.3" in output + +def test_manual_network_accepted(): + output = runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + assert "127.0.0.0/24" in output +def test_multiple_manual_network_accepted(): + output = runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24", "127.0.1.0/24") + assert "127.0.0.0/24" in output and "127.0.1.0/24" in output \ No newline at end of file diff --git a/tests/tests/test_output.py b/tests/tests/test_output.py new file mode 100644 index 0000000..723a56c --- /dev/null +++ b/tests/tests/test_output.py @@ -0,0 +1,34 @@ +from helpers import * + +def test_no_acl_mode_returns_false_perms(): + with SMB(dir_structure=["fileA","fileB","fileC"]): + for result in runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2", "-A"): + print(result) + # assert perms are all false + assert result["Readable"] == 'False' + assert result["Writeable"] == 'False' + assert result["Deletable"] == 'False' + +### test fast mode gives matching perms + +def test_csv_fields_exist(): + with SMB(dir_structure=["fileA"]): + fields = ['Name','Host', 'Extension', 'Username', 'Hostname', 'UNCDirectory', 'CreationTime', 'LastWriteTime', 'Readable', 'Writeable', 'Deletable', 'DirectoryType', 'Base'] + for result in runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2", "-A"): + for field in fields: + assert field in result.keys() + +def test_csv_fields_are_valid(): + with SMB(dir_structure=[("dirA",["fileA.txt"])]): + fields = ['Name','Host', 'Extension', 'Username', 'Hostname', 'UNCDirectory', 'CreationTime', 'LastWriteTime', 'Readable', 'Writeable', 'Deletable', 'DirectoryType', 'Base'] + for result in runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2"): + print(result) + assert result["Name"].lower() == "filea.txt" + assert result["Extension"].lower() == "txt" + assert result["Host"] == "127.0.0.2" + assert result["DirectoryType"] == "SMB" + assert result["UNCDirectory"].lower() == "\\\\127.0.0.2\\share\\dira" + assert result["Base"].lower() == "\\\\127.0.0.2\\share\\" + assert result["Readable"] == 'True' + assert result["Writeable"] == 'True' + assert result["Deletable"] == 'True' diff --git a/tests/tests/test_smb_scans.py b/tests/tests/test_smb_scans.py new file mode 100644 index 0000000..3cb84d4 --- /dev/null +++ b/tests/tests/test_smb_scans.py @@ -0,0 +1,199 @@ +from time import time +from helpers import * + +one_file = ["fileA"] +two_files = ["fileA", "fileB"] +no_files = [] +empty_dir = [("emptyDir", [])] +dir_with_one_file = [("dirA", one_file)] +dir_with_two_files = [("dirB", two_files)] +empty_dir_with_empty_dir = [("emptyDir", empty_dir)] +empty_dir_with_empty_dir_nested = [("emptyDir", empty_dir_with_empty_dir)] +two_files_in_two_nested_dirs = [("dirA", [("dirB", two_files)])] + +detected_share_message = r"Enumerating all subdirectories for '\\{host}\{share}\'" + +def test_detect_normal_share(): + with SMB(): + assert detected_share_message.format(host = "127.0.0.2", share = "share") in runSMBeagleToCSVWithAuth("-h","127.0.0.2") + +def test_detect_admin_share(): + with SMB(): + assert detected_share_message.format(host = "127.0.0.2", share = "ipc$") in runSMBeagleToCSVWithAuth("-h","127.0.0.2") + +def test_do_not_detect_admin_share(): + with SMB(): + assert detected_share_message.format(host = "127.0.0.2", share = "ipc$") not in runSMBeagleToCSVWithAuth("-h","127.0.0.2","-E") + +def test_do_not_detect_none_matching_share(): + with SMB(): + assert detected_share_message.format(host = "127.0.0.2", share = "share") not in runSMBeagleToCSVWithAuth("-h","127.0.0.2","-s","goose") + +def test_detect_matching_share(): + with SMB(): + assert detected_share_message.format(host = "127.0.0.2", share = "share") in runSMBeagleToCSVWithAuth("-h","127.0.0.2","-s","share") + +def test_detect_matching_share_from_multiple(): + with SMB(): + assert detected_share_message.format(host = "127.0.0.2", share = "share") in runSMBeagleToCSVWithAuth("-h","127.0.0.2","-s","goose","share") + +def test_one_host_no_files(): + with SMB(dir_structure=no_files): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 0 + +def test_one_host_empty_dir(): + with SMB(dir_structure=empty_dir): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 0 + +def test_one_host_empty_dir_nested(): + with SMB(dir_structure=empty_dir_with_empty_dir): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 0 + +def test_one_host_empty_dir_nested_twice(): + with SMB(dir_structure=empty_dir_with_empty_dir_nested): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 0 + +def test_one_host_one_file(): + with SMB(dir_structure=one_file): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 1 + +def test_one_host_two_files(): + with SMB(dir_structure=two_files): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 2 + +def test_one_host_empty_dir_and_two_files(): + with SMB(dir_structure=(empty_dir + two_files)): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 2 + +def test_one_host_one_dir_and_one_file(): + with SMB(dir_structure=dir_with_one_file): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 1 + +def test_one_host_one_dir_and_two_files(): + with SMB(dir_structure=dir_with_two_files): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 2 + +def test_one_host_one_dir_and_one_file_and_another_root_file(): + with SMB(dir_structure=dir_with_one_file + one_file): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 2 + +def test_one_host_two_dirs_with_three_files_and_another_root_file(): + with SMB(dir_structure=dir_with_one_file + dir_with_two_files + one_file): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 4 + +def test_one_host_two_dirs_with_three_files_and_another_two_root_files(): + with SMB(dir_structure=dir_with_one_file + dir_with_two_files + two_files): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 5 + +def test_one_host_two_dirs_with_three_files(): + with SMB(dir_structure=dir_with_one_file + dir_with_two_files): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 3 + +def test_one_host_two_files_in_nested_dirs(): + with SMB(dir_structure=two_files_in_two_nested_dirs): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == 2 + +def n_files(n): + return [f"a{x}" for x in range(0,n)] + +def smb_with_n_files(n): + with SMB(dir_structure=n_files(n)): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2")) == n + +def test_ten_files_in_the_root(): + smb_with_n_files(10) + +def test_fifty_files_in_the_root(): + smb_with_n_files(50) + +def test_one_hundred_files_in_the_root(): + smb_with_n_files(100) + +def test_five_hundred_files_in_the_root(): + smb_with_n_files(500) + +def test_nine_hundred_files_in_the_root(): + smb_with_n_files(900) + +# FAILS +#def test_one_thousand_files_in_the_root(): +# smb_with_n_files(1000) + +def n_files_in_n_dirs(files, dirs): + return [(f"dir{x}", n_files(files)) for x in range(0,dirs)] + +def smb_with_n_files_in_n_dirs(files, dirs): + with SMB(dir_structure=n_files_in_n_dirs(files, dirs)): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2", "-A")) == files * dirs + +def test_ten_files_in_two_folders(): + smb_with_n_files_in_n_dirs(10,2) + +def test_fifty_files_in_two_folders(): + smb_with_n_files_in_n_dirs(50,2) + +def test_one_hundred_files_in_two_folders(): + smb_with_n_files_in_n_dirs(100,2) + +def test_five_hundred_files_in_two_folders(): + smb_with_n_files_in_n_dirs(500,2) + +def test_ten_files_in_five_folders(): + smb_with_n_files_in_n_dirs(10,5) + +def test_fifty_files_in_five_folders(): + smb_with_n_files_in_n_dirs(50,5) + +def test_one_hundred_files_in_five_folders(): + smb_with_n_files_in_n_dirs(100,5) + +def test_five_hundred_files_in_five_folders(): + smb_with_n_files_in_n_dirs(500,5) + +def test_five_hundred_files_in_one_hundred_folders(): + smb_with_n_files_in_n_dirs(500,100) + +def test_fast_mode_is_faster(): + start = time() + with SMB(dir_structure=n_files_in_n_dirs(50, 5)): + runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2") + time_to_run_normal = time() - start + start = time() + with SMB(dir_structure=n_files_in_n_dirs(50, 5)): + runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2", "-f") + time_to_run_fast = time() - start + assert time_to_run_normal > time_to_run_fast + +def test_no_acl_mode_is_faster_than_fast(): + start = time() + with SMB(dir_structure=n_files_in_n_dirs(50, 5)): + runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2", "-f") + time_to_run_fast = time() - start + start = time() + with SMB(dir_structure=n_files_in_n_dirs(50, 5)): + runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2", "-A") + time_to_run_no_acl = time() - start + assert time_to_run_fast > time_to_run_no_acl + +def n_files_in_dir_n_deep(files, depth): + dir = [(f"dir", n_files(files))] + for x in range(0,depth): + dir = [(f"dir{x}", dir)] + return dir + +def smb_with_n_files_at_depth_n(n, depth): + with SMB(dir_structure=n_files_in_dir_n_deep(n, depth)): + assert len(runSMBeagleToCSVWithAuthAndReturnResults("-h", "127.0.0.2", "-A")) == n + +def test_ten_files_one_folders_deep(): + smb_with_n_files_at_depth_n(10,1) + +def test_ten_files_two_folders_deep(): + smb_with_n_files_at_depth_n(10,2) + +def test_ten_files_three_folders_deep(): + smb_with_n_files_at_depth_n(10,3) + +def test_ten_files_ten_folders_deep(): + smb_with_n_files_at_depth_n(10,10) + diff --git a/tests/tests/test_tcp_scans.py b/tests/tests/test_tcp_scans.py new file mode 100644 index 0000000..b46cfc9 --- /dev/null +++ b/tests/tests/test_tcp_scans.py @@ -0,0 +1,61 @@ +from helpers import * + +smb_reachable_message = "we have {} hosts with reachable SMB services" + +no_smb_service_discovered_message = smb_reachable_message.format(0) +one_smb_service_discovered_message = smb_reachable_message.format(1) +two_smb_service_discovered_message = smb_reachable_message.format(2) +three_smb_service_discovered_message = smb_reachable_message.format(3) +four_smb_service_discovered_message = smb_reachable_message.format(4) + +def test_one_manual_host_tcp_success(): + with SMB(): + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.2") + +def test_one_manual_host_tcp_fail_if_not_listening(): + with SMB("127.0.0.2"): + assert no_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.3") + +def test_two_manual_host_tcp_success(): + with SMB("127.0.0.2"): + with SMB("127.0.0.3"): + assert two_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.2", "127.0.0.3") + +def test_one_manual_host_tcp_success_and_not_two_if_second_not_listening(): + with SMB("127.0.0.2"): + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.2", "127.0.0.3") + +def test_one_discovered_host_tcp_success(): + with SMB("127.0.0.2"): + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + +def test_no_discovered_host_when_filtered(): + with SMB("127.0.0.2"): + assert no_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24","-H","127.0.0.2" ) + +def test_one_discovered_host_when_one_filtered(): + with SMB("127.0.0.2"): + with SMB("127.0.0.3"): + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24","-H","127.0.0.2" ) + +def test_two_discovered_host_tcp_success(): + with SMB("127.0.0.2"): + with SMB("127.0.0.3"): + assert two_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + +def test_three_discovered_host_tcp_success(): + with SMB("127.0.0.2"): + with SMB("127.0.0.3"): + with SMB("127.0.0.4"): + assert three_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + +def test_four_discovered_host_tcp_success(): + with SMB("127.0.0.2"): + with SMB("127.0.0.3"): + with SMB("127.0.0.4"): + with SMB("127.0.0.5"): + assert four_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + +def test_disable_network_discovery(): + no_networks_to_scan_message = "there are no networks or hosts to scan" + assert no_networks_to_scan_message in runSMBeagleToCSVWithAuth("-D") From d5b15aeddbb7f7cb6bbeda4c843b0a8730984f63 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 22:36:26 +0100 Subject: [PATCH 02/24] chore: remove dockerfile test changes --- tests/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Dockerfile b/tests/Dockerfile index 47c9cf2..25febd0 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -5,5 +5,4 @@ RUN mkdir /empty_dir WORKDIR /tests/ COPY tests/* . ENTRYPOINT [ "" ] -CMD ["pytest", "-v", "test_output.py"] -#CMD ["pytest", "-k", "not windows", "-rP"] \ No newline at end of file +CMD ["pytest", "-v"] \ No newline at end of file From 237ef56330cb24478589a87e1c9f704a739c1e58 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 22:36:44 +0100 Subject: [PATCH 03/24] feat: add PR action --- .github/workflows/build_preview.yml | 31 ++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 099b69a..a55621a 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -43,10 +43,9 @@ jobs: uses: actions/upload-artifact@v2 with: name: linux-arm - path: packages/linux/arm64/* + path: packages/linux/arm64/* build_windows: runs-on: windows-2019 - steps: - uses: actions/checkout@v2 - name: Setup .NET @@ -72,6 +71,28 @@ jobs: with: name: windows-x64 path: packages\windows/x64\* - - - + test_linux: + runs_on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build linux x64 + run: dotnet publish -c Release --self-contained -r linux-x64 -o packages/linux/amd64 -p:PublishSingleFile=true -p:PublishTrimmed=true -p:InvariantGlobalization=true -p:DebugType=None -p:DebugSymbols=false -p:VersionSuffix=pr$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }') + - name: install test dependencies + run: | + apt update && apt install python3 python3-pip -y + pip install impacket pytest + - run: | + cp packages/linux/amd64/SMBeagle /bin/smbeagle + chmod +x /bin/smbeagle + mkdir /empty_dir + - name: run pytest + run: | + cd tests + pytest -v From 3b13df71e4cdd548e0095b5be3bfb2c8bcb1ef7f Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 22:38:25 +0100 Subject: [PATCH 04/24] fix: invalid key --- .github/workflows/build_preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index a55621a..55241d9 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -71,8 +71,8 @@ jobs: with: name: windows-x64 path: packages\windows/x64\* - test_linux: - runs_on: ubuntu-latest + test_on_linux: + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 From a72d89becb18fc5bea443b1a0b3e143df2f76a78 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 22:41:24 +0100 Subject: [PATCH 05/24] fix: grant sudo --- .github/workflows/build_preview.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 55241d9..d45f5df 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -86,12 +86,11 @@ jobs: run: dotnet publish -c Release --self-contained -r linux-x64 -o packages/linux/amd64 -p:PublishSingleFile=true -p:PublishTrimmed=true -p:InvariantGlobalization=true -p:DebugType=None -p:DebugSymbols=false -p:VersionSuffix=pr$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }') - name: install test dependencies run: | - apt update && apt install python3 python3-pip -y pip install impacket pytest - run: | - cp packages/linux/amd64/SMBeagle /bin/smbeagle - chmod +x /bin/smbeagle - mkdir /empty_dir + sudo cp packages/linux/amd64/SMBeagle /bin/smbeagle + sudo chmod +x /bin/smbeagle + sudo mkdir /empty_dir - name: run pytest run: | cd tests From a2adfbcfb2d486ae82d2747dc52d1e7689d596ea Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 22:43:32 +0100 Subject: [PATCH 06/24] fix: sudo the test --- .github/workflows/build_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index d45f5df..f3de0a2 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -94,4 +94,4 @@ jobs: - name: run pytest run: | cd tests - pytest -v + sudo pytest -v From c181047f12194740c3b9f0c09a988e1452a4b013 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 22:45:29 +0100 Subject: [PATCH 07/24] fix: sudo pip --- .github/workflows/build_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index f3de0a2..586b57c 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -86,7 +86,7 @@ jobs: run: dotnet publish -c Release --self-contained -r linux-x64 -o packages/linux/amd64 -p:PublishSingleFile=true -p:PublishTrimmed=true -p:InvariantGlobalization=true -p:DebugType=None -p:DebugSymbols=false -p:VersionSuffix=pr$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }') - name: install test dependencies run: | - pip install impacket pytest + sudo pip install impacket pytest - run: | sudo cp packages/linux/amd64/SMBeagle /bin/smbeagle sudo chmod +x /bin/smbeagle From 4077784f0ee5ff3fc9c74a291743c6b5dcc09905 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 23:00:12 +0100 Subject: [PATCH 08/24] chore: rename files --- tests/Dockerfile | 2 +- tests/tests/{test_options.py => test_010_options.py} | 2 +- tests/tests/{test_tcp_scans.py => test_020_tcp_scans.py} | 0 tests/tests/{test_output.py => test_030_output.py} | 0 tests/tests/{test_smb_scans.py => test_040_smb_scans.py} | 1 - 5 files changed, 2 insertions(+), 3 deletions(-) rename tests/tests/{test_options.py => test_010_options.py} (99%) rename tests/tests/{test_tcp_scans.py => test_020_tcp_scans.py} (100%) rename tests/tests/{test_output.py => test_030_output.py} (100%) rename tests/tests/{test_smb_scans.py => test_040_smb_scans.py} (99%) diff --git a/tests/Dockerfile b/tests/Dockerfile index 25febd0..85a746c 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -5,4 +5,4 @@ RUN mkdir /empty_dir WORKDIR /tests/ COPY tests/* . ENTRYPOINT [ "" ] -CMD ["pytest", "-v"] \ No newline at end of file +CMD ["pytest", "-v"] diff --git a/tests/tests/test_options.py b/tests/tests/test_010_options.py similarity index 99% rename from tests/tests/test_options.py rename to tests/tests/test_010_options.py index 0dcb92d..8f90151 100644 --- a/tests/tests/test_options.py +++ b/tests/tests/test_010_options.py @@ -38,4 +38,4 @@ def test_manual_network_accepted(): assert "127.0.0.0/24" in output def test_multiple_manual_network_accepted(): output = runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24", "127.0.1.0/24") - assert "127.0.0.0/24" in output and "127.0.1.0/24" in output \ No newline at end of file + assert "127.0.0.0/24" in output and "127.0.1.0/24" in output diff --git a/tests/tests/test_tcp_scans.py b/tests/tests/test_020_tcp_scans.py similarity index 100% rename from tests/tests/test_tcp_scans.py rename to tests/tests/test_020_tcp_scans.py diff --git a/tests/tests/test_output.py b/tests/tests/test_030_output.py similarity index 100% rename from tests/tests/test_output.py rename to tests/tests/test_030_output.py diff --git a/tests/tests/test_smb_scans.py b/tests/tests/test_040_smb_scans.py similarity index 99% rename from tests/tests/test_smb_scans.py rename to tests/tests/test_040_smb_scans.py index 3cb84d4..e265d48 100644 --- a/tests/tests/test_smb_scans.py +++ b/tests/tests/test_040_smb_scans.py @@ -196,4 +196,3 @@ def test_ten_files_three_folders_deep(): def test_ten_files_ten_folders_deep(): smb_with_n_files_at_depth_n(10,10) - From fc0316f58a6ee5216fc1478e313e652346303fb1 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Sun, 17 Jul 2022 23:11:28 +0100 Subject: [PATCH 09/24] fix: add 1s sleep on smb kill --- tests/tests/helpers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tests/helpers.py b/tests/tests/helpers.py index 8540fca..390965a 100644 --- a/tests/tests/helpers.py +++ b/tests/tests/helpers.py @@ -44,6 +44,7 @@ def populate_dir(self, dir, dir_structure): def __exit__(self, *args, **kwargs): self.smb.kill() + sleep(1) shutil.rmtree(self.dir) #self.smb.close() From 83374bc48427a7a73c237910b69a9114e44aa940 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:02:42 +0100 Subject: [PATCH 10/24] feat: improve linux test dockerfile --- tests/Dockerfile.Linux | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/Dockerfile.Linux diff --git a/tests/Dockerfile.Linux b/tests/Dockerfile.Linux new file mode 100644 index 0000000..34eace2 --- /dev/null +++ b/tests/Dockerfile.Linux @@ -0,0 +1,9 @@ +FROM punksecurity/smbeagle +RUN apt update && apt install python3 python3-pip -y +RUN pip install impacket pytest +RUN mkdir /empty_dir +WORKDIR /tests/ +COPY tests/* . +ENTRYPOINT [ "" ] +ENV ROOTDIR "/" +CMD pytest -v -k 'not on_windows' From 5d78bb22c2a0e04047c8af7c43280b5566b1f1d1 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:03:45 +0100 Subject: [PATCH 11/24] feat: disable discovery for some tests --- tests/tests/test_010_options.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/tests/test_010_options.py b/tests/tests/test_010_options.py index 8f90151..8def4c4 100644 --- a/tests/tests/test_010_options.py +++ b/tests/tests/test_010_options.py @@ -2,40 +2,42 @@ username_or_password_missing_error = "ERROR: Username and Password required on none Windows platforms" def test_username_and_password_required_on_linux(): - assert username_or_password_missing_error in runSMBeagleToCSV() + assert username_or_password_missing_error in runSMBeagleQuick() def test_password_required_on_linux(): - assert username_or_password_missing_error in runSMBeagleToCSV("-p","goose") + assert username_or_password_missing_error in runSMBeagleQuick("-p","goose") def test_username_required_on_linux(): - assert username_or_password_missing_error in runSMBeagleToCSV("-u","goose") + assert username_or_password_missing_error in runSMBeagleQuick("-u","goose") +def test_username_and_password_not_required_on_windows(): + assert username_or_password_missing_error not in runSMBeagleQuick() def test_username_and_password_accepted(): - assert username_or_password_missing_error not in runSMBeagleToCSV("-u","goose", "-p", "goose") + assert username_or_password_missing_error not in runSMBeagleQuick("-u","goose", "-p", "goose") def test_long_username_accepted(): - assert username_or_password_missing_error not in runSMBeagleToCSV("--username","goose", "-p", "goose") + assert username_or_password_missing_error not in runSMBeagleQuick("--username","goose", "-p", "goose") def test_long_password_accepted(): - assert username_or_password_missing_error not in runSMBeagleToCSV("-u","goose", "--password", "goose") + assert username_or_password_missing_error not in runSMBeagleQuick("-u","goose", "--password", "goose") output_required_error = "At least one option from group 'output' (c, csv-file, e, elasticsearch-host)" def test_csv_or_elasticsearch_required(): assert output_required_error in runSMBeagle() def test_short_csv_accepted(): - assert output_required_error not in runSMBeagle("-c","out.csv") + assert output_required_error not in runSMBeagleQuick("-c","out.csv") def test_long_csv_accepted(): - assert output_required_error not in runSMBeagle("--csv-file","out.csv") + assert output_required_error not in runSMBeagleQuick("--csv-file","out.csv") def test_short_elasticsearch_accepted(): - assert output_required_error not in runSMBeagle("-e","elasticsearch") + assert output_required_error not in runSMBeagleQuick("-e","elasticsearch") def test_long_elasticsearch_accepted(): - assert output_required_error not in runSMBeagle("--elasticsearch-host","elasticsearch") + assert output_required_error not in runSMBeagleQuick("--elasticsearch-host","elasticsearch") def test_manual_host_accepted(): - assert "127.0.0.2" in runSMBeagleToCSVWithAuth("-h", "127.0.0.2") + assert "127.0.0.2" in runSMBeagleToCSVWithAuth("-D","-h", "127.0.0.2") def test_multiple_manual_host_accepted(): - output = runSMBeagleToCSVWithAuth("-h", "127.0.0.2", "127.0.0.3") + output = runSMBeagleToCSVWithAuth("-D","-h", "127.0.0.2", "127.0.0.3") assert "127.0.0.2" in output and "127.0.0.3" in output def test_manual_network_accepted(): - output = runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + output = runSMBeagleToCSVWithAuth("-D", "-n", "127.0.0.0/24") assert "127.0.0.0/24" in output def test_multiple_manual_network_accepted(): - output = runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24", "127.0.1.0/24") + output = runSMBeagleToCSVWithAuth("-D","-n", "127.0.0.0/24", "127.0.1.0/24") assert "127.0.0.0/24" in output and "127.0.1.0/24" in output From 8fa1cb34931889b5e61fe55960b0905462d2ab25 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:04:18 +0100 Subject: [PATCH 12/24] feat: allow selecting root dir --- tests/tests/helpers.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/tests/helpers.py b/tests/tests/helpers.py index 390965a..a71f60e 100644 --- a/tests/tests/helpers.py +++ b/tests/tests/helpers.py @@ -6,14 +6,16 @@ import csv import shutil import uuid +import platform def __setupSMB(address, dir, SMB2 = True): - os.chdir("/empty_dir") + os.chdir(f"{os.environ['ROOTDIR']}empty_dir") server = smbserver.SimpleSMBServer(listenAddress=address, listenPort=445) server.addShare("share", dir, "") server.addCredential("test", 1200, "9FD78381EC915F1AAAD3B435B51404EE", "25EDEDFF26CB970623DDA4733227A3F7") server.setSMB2Support(SMB2) + server.setLogFile('') server.start() def setupSMB(address, dir): @@ -25,7 +27,7 @@ class SMB(object): def __init__(self, address = "0.0.0.0", dir_structure = ["fileA", "fileB"]): self.address = address self.dir_structure = dir_structure - self.dir = f"/{uuid.uuid4().hex}" + self.dir = f"{os.environ['ROOTDIR']}{uuid.uuid4().hex}" def __enter__(self): self.smb = setupSMB(self.address, self.dir) os.mkdir(self.dir) @@ -57,8 +59,15 @@ def runSMBeagle(*args, print_out=True): def runSMBeagleToCSV(*args): return runSMBeagle("-c","out.csv",*args) +def runSMBeagleQuick(*args): + return runSMBeagleToCSV("-D",*args) + def runSMBeagleToCSVWithAuth(*args): - return runSMBeagleToCSV("-u","test", "-p", "goose", *args) + try: + os.environ["NATIVE_AUTH"] + return runSMBeagleToCSV(*args) + except: + return runSMBeagleToCSV("-u","test", "-p", "goose", *args) def runSMBeagleToCSVWithAuthAndReturnResults(*args): print(runSMBeagleToCSVWithAuth(*args)) From 76a426e627027182740aeeaabe4e12801e5c25cc Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:04:43 +0100 Subject: [PATCH 13/24] feat: add windows test dockerfile --- tests/Dockerfile | 8 -------- tests/Dockerfile.Windows | 23 +++++++++++++++++++++++ tests/windows_scripts/install_python.ps1 | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) delete mode 100644 tests/Dockerfile create mode 100644 tests/Dockerfile.Windows create mode 100644 tests/windows_scripts/install_python.ps1 diff --git a/tests/Dockerfile b/tests/Dockerfile deleted file mode 100644 index 85a746c..0000000 --- a/tests/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM punksecurity/smbeagle -RUN apt update && apt install python3 python3-pip -y -RUN pip install impacket pytest -RUN mkdir /empty_dir -WORKDIR /tests/ -COPY tests/* . -ENTRYPOINT [ "" ] -CMD ["pytest", "-v"] diff --git a/tests/Dockerfile.Windows b/tests/Dockerfile.Windows new file mode 100644 index 0000000..6217ac7 --- /dev/null +++ b/tests/Dockerfile.Windows @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/windows:20H2 +ENV PYTHON_VERSION 3.10.5 +ENV PYTHON_GET_PIP_URL https://bootstrap.pypa.io/get-pip.py + +COPY windows_scripts/* / +RUN "powershell -noprofile -executionpolicy bypass -file .\install_python.ps1" + +RUN "pip install impacket pytest" + +ENV ROOTDIR "C:\\" +WORKDIR "C:\\" +RUN mkdir empty_dir tests +COPY tests tests +COPY x64 "C:\\windows\\system32\\." +WORKDIR tests +CMD pytest -v -k "not on_linux" + +# Cant test native auth as windows auth broken in containers... tried this hacky fix but no good +#RUN net user /add test +#RUN net localgroup administrators test /add +#USER test +#ENV NATIVE_AUTH=1 +#RUN net user test goose; pytest -k test_fifty_files_in_the_root diff --git a/tests/windows_scripts/install_python.ps1 b/tests/windows_scripts/install_python.ps1 new file mode 100644 index 0000000..4ab3236 --- /dev/null +++ b/tests/windows_scripts/install_python.ps1 @@ -0,0 +1,16 @@ +$url = ('https://www.python.org/ftp/python/{0}/python-{0}-amd64.exe' -f $env:PYTHON_VERSION) +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +Invoke-WebRequest -Uri $url -OutFile 'python.exe'; +# https://docs.python.org/3.7/using/windows.html#installing-without-ui +Start-Process python.exe -Wait -ArgumentList @( + '/quiet', + 'InstallAllUsers=1', + 'TargetDir=C:\Python', + 'PrependPath=1', + 'Shortcuts=0', + 'Include_doc=0', + 'Include_pip=1', + 'Include_test=0' + ); +#the installer updated PATH, so we should refresh our local value +Remove-Item python.exe -Force From 8cd95866628a54c537d32647b8575e3f163b755b Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:04:57 +0100 Subject: [PATCH 14/24] feat: fix PR linux tests --- .github/workflows/build_preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 586b57c..be709a3 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -92,6 +92,8 @@ jobs: sudo chmod +x /bin/smbeagle sudo mkdir /empty_dir - name: run pytest + env: + ROOT_DIR: / run: | cd tests sudo pytest -v From f9aeb607c048fb41696109335d284533b3c16d2a Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:10:12 +0100 Subject: [PATCH 15/24] fix: rootdir not root_dir --- .github/workflows/build_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index be709a3..346b111 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -93,7 +93,7 @@ jobs: sudo mkdir /empty_dir - name: run pytest env: - ROOT_DIR: / + ROOTDIR: / run: | cd tests sudo pytest -v From e3c13f64a071ddec1ca404cf908cc256b733f311 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:14:37 +0100 Subject: [PATCH 16/24] fix: quote rootdir --- .github/workflows/build_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 346b111..4c0854f 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -93,7 +93,7 @@ jobs: sudo mkdir /empty_dir - name: run pytest env: - ROOTDIR: / + ROOTDIR: "/" run: | cd tests sudo pytest -v From 0279f2141754c7af4058e4af42787f64808fef87 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:21:29 +0100 Subject: [PATCH 17/24] fix: env not working with sudo --- .github/workflows/build_preview.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 4c0854f..5837148 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -92,8 +92,6 @@ jobs: sudo chmod +x /bin/smbeagle sudo mkdir /empty_dir - name: run pytest - env: - ROOTDIR: "/" run: | cd tests - sudo pytest -v + sudo ROOTDIR=/ pytest -v From 6a9a0992474816b76eb677b4d47d3b3d77bd4ecd Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:29:58 +0100 Subject: [PATCH 18/24] feat: dont run windows tests on linux --- .github/workflows/build_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 5837148..755b290 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -94,4 +94,4 @@ jobs: - name: run pytest run: | cd tests - sudo ROOTDIR=/ pytest -v + sudo ROOTDIR=/ pytest -v -k "not on_windows" From 3401b4369f5aff5ecf62542a93e34a047990eec5 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 14:54:20 +0100 Subject: [PATCH 19/24] feat: test on build --- .github/workflows/build_preview.yml | 36 ++++++++++------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 755b290..9414556 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -44,6 +44,18 @@ jobs: with: name: linux-arm path: packages/linux/arm64/* + - name: install test dependencies + run: | + sudo pip install impacket pytest + - name: copy beagle into path + run: | + sudo cp packages/linux/amd64/SMBeagle /bin/smbeagle + sudo chmod +x /bin/smbeagle + sudo mkdir /empty_dir + - name: run pytest + run: | + cd tests + sudo ROOTDIR=/ pytest -v -k "not on_windows" build_windows: runs-on: windows-2019 steps: @@ -71,27 +83,3 @@ jobs: with: name: windows-x64 path: packages\windows/x64\* - test_on_linux: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 5.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build linux x64 - run: dotnet publish -c Release --self-contained -r linux-x64 -o packages/linux/amd64 -p:PublishSingleFile=true -p:PublishTrimmed=true -p:InvariantGlobalization=true -p:DebugType=None -p:DebugSymbols=false -p:VersionSuffix=pr$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }') - - name: install test dependencies - run: | - sudo pip install impacket pytest - - run: | - sudo cp packages/linux/amd64/SMBeagle /bin/smbeagle - sudo chmod +x /bin/smbeagle - sudo mkdir /empty_dir - - name: run pytest - run: | - cd tests - sudo ROOTDIR=/ pytest -v -k "not on_windows" From 5d9b3023f24ef276046e637ca9798a33208dcc98 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 15:42:59 +0100 Subject: [PATCH 20/24] feat: add windows test --- .github/workflows/build_preview.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 9414556..6e2a835 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -83,3 +83,17 @@ jobs: with: name: windows-x64 path: packages\windows/x64\* + - name: Prep tests + env: + PYTHON_VERSION: 3.10.5 + run: | + powershell -noprofile -executionpolicy bypass -file tests\windows_scripts\install_python.ps1 + pip install impacket pytest + mkdir empty_dir + cp packages\windows\x64\* C:\windows\system32\ + - name: Run tests + env: + ROOTDIR: C:\ + run: | + cd tests + pytest -v -k "not on_linux" From a227d815aa52c0e210f55e021fb6cf130ed1b656 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 15:58:07 +0100 Subject: [PATCH 21/24] feat: fix tmpdir --- .github/workflows/build_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 6e2a835..d48e57e 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -89,7 +89,7 @@ jobs: run: | powershell -noprofile -executionpolicy bypass -file tests\windows_scripts\install_python.ps1 pip install impacket pytest - mkdir empty_dir + mkdir C:\empty_dir cp packages\windows\x64\* C:\windows\system32\ - name: Run tests env: From 40eee91f5be8696ae65b322a1436d76962f00649 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 16:21:41 +0100 Subject: [PATCH 22/24] feat: bump to w2022 --- .github/workflows/build_preview.yml | 2 +- tests/tests/test_020_tcp_scans.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index d48e57e..8ce86e2 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -57,7 +57,7 @@ jobs: cd tests sudo ROOTDIR=/ pytest -v -k "not on_windows" build_windows: - runs-on: windows-2019 + runs-on: windows-2022 steps: - uses: actions/checkout@v2 - name: Setup .NET diff --git a/tests/tests/test_020_tcp_scans.py b/tests/tests/test_020_tcp_scans.py index b46cfc9..496f639 100644 --- a/tests/tests/test_020_tcp_scans.py +++ b/tests/tests/test_020_tcp_scans.py @@ -10,51 +10,51 @@ def test_one_manual_host_tcp_success(): with SMB(): - assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.2") + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-h", "127.0.0.2") def test_one_manual_host_tcp_fail_if_not_listening(): with SMB("127.0.0.2"): - assert no_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.3") + assert no_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-h", "127.0.0.3") def test_two_manual_host_tcp_success(): with SMB("127.0.0.2"): with SMB("127.0.0.3"): - assert two_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.2", "127.0.0.3") + assert two_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-h", "127.0.0.2", "127.0.0.3") def test_one_manual_host_tcp_success_and_not_two_if_second_not_listening(): with SMB("127.0.0.2"): - assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-h", "127.0.0.2", "127.0.0.3") + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-h", "127.0.0.2", "127.0.0.3") def test_one_discovered_host_tcp_success(): with SMB("127.0.0.2"): - assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-n", "127.0.0.0/24") def test_no_discovered_host_when_filtered(): with SMB("127.0.0.2"): - assert no_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24","-H","127.0.0.2" ) + assert no_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-n", "127.0.0.0/24","-H","127.0.0.2" ) def test_one_discovered_host_when_one_filtered(): with SMB("127.0.0.2"): with SMB("127.0.0.3"): - assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24","-H","127.0.0.2" ) + assert one_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-n", "127.0.0.0/24","-H","127.0.0.2" ) def test_two_discovered_host_tcp_success(): with SMB("127.0.0.2"): with SMB("127.0.0.3"): - assert two_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + assert two_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-n", "127.0.0.0/24") def test_three_discovered_host_tcp_success(): with SMB("127.0.0.2"): with SMB("127.0.0.3"): with SMB("127.0.0.4"): - assert three_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + assert three_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-n", "127.0.0.0/24") def test_four_discovered_host_tcp_success(): with SMB("127.0.0.2"): with SMB("127.0.0.3"): with SMB("127.0.0.4"): with SMB("127.0.0.5"): - assert four_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-n", "127.0.0.0/24") + assert four_smb_service_discovered_message in runSMBeagleToCSVWithAuth("-D", "-n", "127.0.0.0/24") def test_disable_network_discovery(): no_networks_to_scan_message = "there are no networks or hosts to scan" From da5c09e3cde9917e825572137094e7f0fd68997c Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 16:36:14 +0100 Subject: [PATCH 23/24] fix: cant test windows because smb svc running --- .github/workflows/build_preview.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 8ce86e2..93bd857 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -83,17 +83,3 @@ jobs: with: name: windows-x64 path: packages\windows/x64\* - - name: Prep tests - env: - PYTHON_VERSION: 3.10.5 - run: | - powershell -noprofile -executionpolicy bypass -file tests\windows_scripts\install_python.ps1 - pip install impacket pytest - mkdir C:\empty_dir - cp packages\windows\x64\* C:\windows\system32\ - - name: Run tests - env: - ROOTDIR: C:\ - run: | - cd tests - pytest -v -k "not on_linux" From 7d8f65ac5b6e6b59ecbec67d7bd3d3a376413db7 Mon Sep 17 00:00:00 2001 From: Simon Gurney Date: Mon, 18 Jul 2022 16:40:10 +0100 Subject: [PATCH 24/24] chore: downgrade --- .github/workflows/build_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_preview.yml b/.github/workflows/build_preview.yml index 93bd857..9414556 100644 --- a/.github/workflows/build_preview.yml +++ b/.github/workflows/build_preview.yml @@ -57,7 +57,7 @@ jobs: cd tests sudo ROOTDIR=/ pytest -v -k "not on_windows" build_windows: - runs-on: windows-2022 + runs-on: windows-2019 steps: - uses: actions/checkout@v2 - name: Setup .NET