diff --git a/nix/devshell.nix b/nix/devshell.nix index 903f728cc..b8be483c2 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -64,7 +64,6 @@ in gdb parallel qemu - netcat-openbsd zig_0_13 # version match setup-dev.sh go diff --git a/setup-dev.sh b/setup-dev.sh index 96cf777fb..be73a1b46 100755 --- a/setup-dev.sh +++ b/setup-dev.sh @@ -140,7 +140,6 @@ install_apt() { gdb \ gdb-multiarch \ parallel \ - netcat-openbsd \ iproute2 \ qemu-system-x86 \ qemu-system-arm \ @@ -204,11 +203,6 @@ EOF gdb \ parallel - # check if netcat exists first, as it might it may be installed from some other netcat packages - if [ ! -f /usr/bin/nc ]; then - sudo pacman -S --needed --noconfirm gnu-netcat - fi - command -v go &> /dev/null || sudo pacman -S --noconfirm go download_zig_binary diff --git a/tests/gdb-tests/tests/test_command_procinfo.py b/tests/gdb-tests/tests/test_command_procinfo.py index 36f25e41b..c876de497 100644 --- a/tests/gdb-tests/tests/test_command_procinfo.py +++ b/tests/gdb-tests/tests/test_command_procinfo.py @@ -1,9 +1,8 @@ from __future__ import annotations -import os -import shutil -import signal -import subprocess +import socket +import threading +import time import gdb @@ -13,21 +12,30 @@ import tests REFERENCE_BINARY_NET = tests.binaries.get("reference-binary-net.out") +class TCPServerThread(threading.Thread): + def __init__(self): + super().__init__(daemon=True) + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.bind(("127.0.0.1", 31337)) + self.port = self.sock.getsockname()[1] + self.sock.listen(1) + + def run(self): + try: + # Accept one conn and sleep + conn, addr = self.sock.accept() + while True: + time.sleep(1) + except OSError: + pass # Socket closed + + def test_command_procinfo(start_binary): start_binary(REFERENCE_BINARY_NET) - # Check if netcat exists - nc_path = shutil.which("nc") - assert nc_path is not None, "netcat is not installed" - - # Spawn netcat - netcat_process = subprocess.Popen( - [nc_path, "-l", "-p", "31337"], - stdin=subprocess.DEVNULL, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - start_new_session=True, - ) + # Listen tcp server + server = TCPServerThread() + server.start() bin_path = pwndbg.aglib.proc.exe pid = str(pwndbg.aglib.proc.pid) @@ -40,10 +48,10 @@ def test_command_procinfo(start_binary): assert bin_path in res_list[0] assert pid in res_list[3] - assert "127.0.0.1:31337" in result + assert f"127.0.0.1:{server.port}" in result - # Close netcat - os.killpg(os.getpgid(netcat_process.pid), signal.SIGTERM) + # Close tcp server + server.sock.close() def test_command_procinfo_before_binary_start():