Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Http_banner get 2.0

Shulou Source: shulou.com Published: 2022-06-01 09:23:37 10月03日 Update

Update as follows

The port can be customized by default 80

Threads can be customized by default 10

Queues are used to store messages

#-*-coding=utf-8-*-# _ _ author__ = 'sanr'# _ email__ =' 5754190@qq.com'# _ _ url__ = 'http://0x007.blog.51cto.com/'# _ _ version__ =' 2.0'import requestsimport reimport sysfrom threading import Thread,Lockimport Queueimport chardetimport netaddrimport socketimport structimport optparseimport osimport timelock = Lock () Q = Queue.Queue () def ip2int (addr): return struct.unpack ("! I" Socket.inet_aton (addr) [0] def int2ip (addr): return socket.inet_ntoa (struct.pack ("! I") Addr)) def int_dec (pagehtml):''get the page code intelligently. The first step is to find charset. The second step is to use chardect intelligent matching.' 'charset = None if pagehtml! =': # print 'use charset dect' enc= chardet.detect (pagehtml) # print' enc=' Enc if enc ['encoding'] and enc [' confidence'] > 0.9: charset = enc ['encoding'] if charset = = None: charset_re = re.compile ("((^ | )\ s*charset\ test charset try =) ([^\ "] *)", re.M) charset=charset_re.search (pagehtml [: 1000]) charset=charset and charset.group (3) or None # test charset try: if charset: unicode ('test',charset Errors='replace') except Exception,e: print 'Exception',e charset= None # print' charset=', charset return charsetdef http_banner (): while True: try: if q.qsize () = 0: break Ip = q.get () url=' http://%s:%s'%(ip,port) url=requests.get (url Timeout=2) body = url.content charset = None if body! ='': charset = int_dec (body) if charset = = None or charset = = 'ascii': Charset = 'ISO-8859-1' if charset and charset! = 'ascii' and charset! =' unicode': try: body = unicode (body Charset,errors='replace') except Exception E: body =''# get status code Struts=url.status_code # get webserver information Server=url.headers ['server'] [0:13] # get title If Struts==200 or Struts==403 or Struts==401: title=re.findall (r "(. *)" Body) if len (title): title = title [0] .strip () else: title =''# output locking prevention On the second line, enter # apply for lock lock.acquire () print ('% s\ t% d\ t% Mutual 10s\ t% slots% (ip.lstrip ('http://'),) Struts,Server,title)) # release lock lock.release () except (requests.HTTPError,requests.RequestException,AttributeError,KeyError), e: passdef main (ips,threads=10): if'-'in ips: start End = ips.split ('-') startlong = ip2int (start) endlong = ip2int (end) ips = netaddr.IPRange (start) End) for ip in list (ips): q.put (str (ip)) elif'/'in ips: ips = netaddr.IPNetwork (ips) for ip in ips: q.put (str (ip)) ths = [ ] for i in xrange (threads): th = Thread (target=http_banner Name='thread'+str (I) th.start () ths.append (th) if _ _ name__ ='_ _ main__': parser = optparse.OptionParser ('usage:% prog [options] target') parser.add_option ('-paired,'--port', dest='port', default='80',type='string' Help='Port.default = 80') parser.add_option ('- tweak,'--threads', dest='threads_num',default=10, type='int',help='Number of threads. Default = 10') (options Args) = parser.parse_args () if len (args) < 1: parser.print_help () print 'usage: python% s 218.92.227.1-218.92.227.254'%os.path.basename (sys.argv [0]) print' usage: python% s 218.92.227.1 usage 24'% os.path.basename (sys.argv [0]) ) print 'usage: python% s 218.92.227.1 print 24-p 8080'%os.path.basename (sys.argv [0]) print' usage: python% s 218.92.227.1 Universe 24-t 100-p 8080'%os.path.basename (sys.argv [0]) sys.exit (0) ips=args [0] port=options.port Threads = options.threads_num main (ips Int (threads))

Tags: Intelligence information message status port thread encoding queue page update input output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Microsoft Shulou Information MariaDB