Re: Medium Scale Scanning Best Practices

From: Gerardo Richarte (core.lists.pentest@core-sdi.com)
Date: Wed Jan 16 2002 - 16:13:41 PST

  • Next message: Perciaccante, Robert: "Extraction of user credentials from PWL files"

    "Erlend J. Leiknes" wrote:
    
    > You could program it in python using the telnet library.
    
        On this same line... and from the top of my head:
    
    import time
    import telnetlib               # this is not really needed if you are not going to connect to port 21
    
    ---- BannerGrabber.py
    import time
    import telnetlib               # this is not really needed if you are not going to connect to port 21
    
    class BannerGrabber:
        def __init__(self,host,port = None):
            self.host = host
            self.port = port
    
        def connect(self, port = None, host = None):
            if host: self.host = host
            if port: self.port = port
            self.telnet = telnetlib.Telnet()
    
            try:
                self.telnet.open(self.host, self.port)
            except:            # exception catching can be narrower here...
                return 0
    
            return 1
    
        def getBanner(self, timeout = 5):
            banner = ''
            while (timeout):
                time.sleep(1)
                timeout -= 1
                banner += self.telnet.read_very_eager()
    
            return banner
    
    
        def close(self):
            self.telnet.close()
    ---- banner.py
    #!/usr/bin/python2
    
    import BannerGrabber
    import sys
    
    if not sys.argv[2:]:
        print "use: banner.py host ports"
        sys.exit(1)
    
    b = BannerGrabber.BannerGrabber(sys.argv[1])
    
    for i in sys.argv[2:]:
        if b.connect(int(i)):
            try:
                print "Port %s: %s" % (i,b.getBanner())
                b.close()
            except Exception,e:
                print e
        else:
            print "Port %s: (closed)" % i
    ---------
    
        in python indentation is what defines what in C would be delimited by { and }
    
        this is simple, you can improve it i'm sure... ley me know if you have any problems with it.
    
        gera
    
    
    --- for a personal reply use: Gerardo Richarte <geraat_private>
    
    ----------------------------------------------------------------------------
    This list is provided by the SecurityFocus Security Intelligence Alert (SIA)
    Service. For more information on SecurityFocus' SIA service which
    automatically alerts you to the latest security vulnerabilities please see:
    https://alerts.securityfocus.com/
    



    This archive was generated by hypermail 2b30 : Thu Jan 17 2002 - 10:58:33 PST