-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (41 loc) · 1.43 KB
/
Copy pathmain.py
File metadata and controls
52 lines (41 loc) · 1.43 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
import logging
import time
from config import CONFIG, validate_config
from tunnel_strategies import get_strategy
from ssh_connector import connect_via_ws_and_start_socks
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger(__name__)
def main() -> None:
"""
1) Validate config.
2) Use the chosen strategy to do the WebSocket handshake.
3) Wrap the socket in Paramiko's SSH transport.
4) Expose a local SOCKS proxy on CONFIG['LOCAL_SOCKS_PORT'].
5) Block until the user kills the process.
"""
try:
validate_config(CONFIG)
strategy_cls = get_strategy(CONFIG["MODE"])
ws_sock = strategy_cls(CONFIG).establish()
ssh_connection = connect_via_ws_and_start_socks(
ws_socket=ws_sock,
ssh_user=CONFIG["SSH_USERNAME"],
ssh_password=CONFIG["SSH_PASSWORD"],
ssh_port=CONFIG["SSH_PORT"],
local_socks_port=CONFIG["LOCAL_SOCKS_PORT"],
)
logger.info(
"SOCKS proxy up on 127.0.0.1:%d – all traffic forwarded over SSH via WS tunnel.",
CONFIG["LOCAL_SOCKS_PORT"],
)
while True:
time.sleep(999999)
except KeyboardInterrupt:
logger.info("Shutting down (KeyboardInterrupt).")
except Exception as exc:
logger.error("Fatal error: %s", exc)
if __name__ == "__main__":
main()