-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathtest_reverseshell.py
More file actions
50 lines (43 loc) · 1.67 KB
/
Copy pathtest_reverseshell.py
File metadata and controls
50 lines (43 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from unittest import mock
# Simulate a minimal, testable version of findshell logic
def simulate_findshell(inputs, config):
import builtins
original_input = builtins.input
input_iter = iter(inputs)
builtins.input = lambda _: next(input_iter)
try:
shelltype = input("#> ")
rhost = config['DEFAULT']['rhost']
lhost = config['DEFAULT']['lhost']
check = input("[y\\n] ")
if check != "y":
return None, None
shell_map = {
"1": "bash", "2": "php", "3": "netcat", "4": "telnet",
"5": "perl", "6": "perl windows", "7": "ruby", "8": "java",
"9": "python", "10": "gawk", "11": "powershell windows"
}
shell = shell_map.get(shelltype)
if shell is None:
return None, None
return shell, lhost
finally:
builtins.input = original_input
# Test case: valid selection
def test_valid_shell_selection():
config = {"DEFAULT": {"rhost": "192.168.1.10", "lhost": "10.0.0.5"}}
shell, lhost = simulate_findshell(["1", "y"], config)
assert shell == "bash"
assert lhost == "10.0.0.5"
# Test case: invalid selection
def test_invalid_shell_selection():
config = {"DEFAULT": {"rhost": "192.168.1.10", "lhost": "10.0.0.5"}}
shell, lhost = simulate_findshell(["15", "y"], config)
assert shell is None
assert lhost is None
# Test case: user declines confirmation
def test_shell_selection_declined():
config = {"DEFAULT": {"rhost": "127.0.0.1", "lhost": "127.0.0.1"}}
shell, lhost = simulate_findshell(["1", "n"], config)
assert shell is None
assert lhost is None