mirror of
https://github.com/jtesta/ssh-audit.git
synced 2026-06-24 05:19:41 +02:00
f369689cd1
* Add --socks argument for scanning via SOCKS5 proxy Implement SOCKS5 proxy support without external dependencies: - Add socks_proxy field to AuditConf - Add --socks host:port CLI argument with input validation - Implement SOCKS5 handshake (no-auth, domain-name addressing) in SSH_Socket._connect_via_socks5() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Michał Majchrowicz <sectroyer@gmail.com> * Add SOCKS proxy regression tests --------- Signed-off-by: Michał Majchrowicz <sectroyer@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
import pytest
|
|
|
|
from ssh_audit.outputbuffer import OutputBuffer
|
|
from ssh_audit.ssh_socket import SSH_Socket
|
|
|
|
|
|
# pylint: disable=attribute-defined-outside-init
|
|
class TestSocket:
|
|
@pytest.fixture(autouse=True)
|
|
def init(self, ssh_audit):
|
|
self.OutputBuffer = OutputBuffer
|
|
self.ssh_socket = SSH_Socket
|
|
|
|
def test_invalid_host(self, virtual_socket):
|
|
with pytest.raises(ValueError):
|
|
self.ssh_socket(self.OutputBuffer(), None, 22)
|
|
|
|
def test_invalid_port(self, virtual_socket):
|
|
with pytest.raises(ValueError):
|
|
self.ssh_socket(self.OutputBuffer(), 'localhost', 'abc')
|
|
with pytest.raises(ValueError):
|
|
self.ssh_socket(self.OutputBuffer(), 'localhost', -1)
|
|
with pytest.raises(ValueError):
|
|
self.ssh_socket(self.OutputBuffer(), 'localhost', 0)
|
|
with pytest.raises(ValueError):
|
|
self.ssh_socket(self.OutputBuffer(), 'localhost', 65536)
|
|
|
|
def test_not_connected_socket(self, virtual_socket):
|
|
sock = self.ssh_socket(self.OutputBuffer(), 'localhost', 22)
|
|
banner, header, err = sock.get_banner()
|
|
assert banner is None
|
|
assert len(header) == 0
|
|
assert err == 'not connected'
|
|
s, e = sock.recv()
|
|
assert s == -1
|
|
assert e == 'not connected'
|
|
s, e = sock.send('nothing')
|
|
assert s == -1
|
|
assert e == 'not connected'
|
|
s, e = sock.send_packet()
|
|
assert s == -1
|
|
assert e == 'not connected'
|
|
|
|
def test_socks_proxy_rejected_for_unix_socket_targets(self, virtual_socket):
|
|
sock = self.ssh_socket(self.OutputBuffer(), 'unix:///tmp/test.sock', 22, socks_proxy='127.0.0.1:1080')
|
|
err = sock.connect()
|
|
assert err == '[exception] cannot use a SOCKS5 proxy with UNIX socket targets'
|