-
Notifications
You must be signed in to change notification settings - Fork 0
/
rd.py
126 lines (100 loc) · 4.23 KB
/
rd.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import subprocess
import sys
RESET = "\033[0m" # Reset to default
BOLD = "\033[1m" # Bold text
RED = "\033[91m" # Red text
GREEN = "\033[92m" # Green text
YELLOW = "\033[93m" # Yellow text
BLUE = "\033[94m" # Blue text
WHITE = "\033[97m" # White text
def banner():
whale_art = f"""
{BLUE}.
{BLUE}":"{RESET}
___:____ |"\\/"|
,' `. \\ /
| O \\___/ |
~^~^~^~^~^~^~^~^~^~^~^~^~
"""
print(whale_art)
print(f" {RED}RED {BLUE}DOCK")
print(f" {YELLOW}by shellkraft{RESET}")
def start_container():
container_id = subprocess.check_output(["sudo", "docker", "ps", "-q", "-n", "1"]).decode("utf-8").strip()
container_id_stopped = subprocess.check_output(
["sudo", "docker", "ps", "-aq", "--filter", "status=exited", "--no-trunc"]).decode("utf-8").strip()
if container_id_stopped:
subprocess.run(["sudo", "docker", "start", container_id_stopped])
subprocess.run(["sudo", "docker", "attach", container_id_stopped])
elif container_id:
subprocess.run(["sudo", "docker", "attach", container_id])
else:
subprocess.run(
["sudo", "docker", "run", "--name", "kali", "--mount", "source=pentest,target=/vol", "--mount", "type=bind,source=/home/sysploit/,target=/mnt/sysploit", "-it", "--network", "host", "kali", "/bin/bash"])
def stop_container():
all_containers = subprocess.check_output(["sudo", "docker", "ps", "-qa"]).decode("utf-8").splitlines()
if not all_containers:
print(f"{YELLOW}Error: No containers are currently running.{RESET}")
else:
running_containers = subprocess.check_output(["sudo", "docker", "ps", "-q"]).decode("utf-8").splitlines()
for container_id in running_containers:
subprocess.run(["sudo", "docker", "kill", container_id])
subprocess.run(["sudo", "docker", "stop"] + all_containers)
subprocess.run(["sudo", "docker", "rm"] + all_containers)
def show_status():
subprocess.run(["sudo", "docker", "ps", "-a"])
def update_image():
container_id = subprocess.check_output(["sudo", "docker", "ps", "-q", "-n", "1"]).decode("utf-8").strip()
subprocess.run(["sudo", "docker", "commit", container_id, "kali"])
def get_next_container_name(base_name="kali"):
existing_containers = subprocess.check_output(["sudo", "docker", "ps", "--format", "{{.Names}}"]).decode(
"utf-8").splitlines()
index = 2
while True:
new_name = f"{base_name}{index}"
if new_name not in existing_containers:
return new_name
index += 1
def clone_container():
new_container_name = get_next_container_name()
subprocess.run(
["sudo", "docker", "run", "--name", new_container_name, "--mount", "source=pentest,target=/vol", "-it", "--network", "host", "kali",
"/bin/bash"])
def print_help_menu():
help_menu = f"""
{BOLD}{RED}RED {BLUE}DOCK{RESET} - A simple Docker management tool for Penetration Testing.
{BOLD}{GREEN}COMMANDS:{RESET}
{BOLD}start{RESET} {WHITE}Start the kali image.{RESET}
{BOLD}stop{RESET} {WHITE}Stop a running container.{RESET}
{BOLD}status{RESET} {WHITE}Check the container status.{RESET}
{BOLD}update{RESET} {WHITE}Update the Kali image.{RESET}
{BOLD}clone{RESET} {WHITE}Open another terminal.{RESET}
{BOLD}{GREEN}EXAMPLES:{RESET}
rd start
rd stop
rd status
rd update
rd clone
"""
print(help_menu)
def main():
if len(sys.argv) == 2 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
print_help_menu()
sys.exit()
if len(sys.argv) == 1 or sys.argv[1] not in ["start", "stop", "clone", "status", "update"]:
banner()
print(f"{RED}Error: Unknown command. Use -h for help.{RESET}")
sys.exit()
command = sys.argv[1]
if command == "start":
start_container()
elif command == "stop":
stop_container()
elif command == "clone":
clone_container()
elif command == "status":
show_status()
elif command == "update":
update_image()
if __name__ == "__main__":
main()