modules/auxiliary/scanner/bannergrab.rb
def negotiate_telnet(sock)
        response = sock.recv(1024)
        resp = ""
        index = 0
        (0..20).each do
            # If the response is IAC (Interpret as Command)
            index = response.index(IAC, index)
            break if not index
            # The option type is the character after IAC
            opttype = response[index+1]
            # The option is the character after that
            opt = response[index+2]
            # If the option type is WILL or WONT, we respond with DONT
            if [WILL, WONT].index(opttype)!=nil
                opttype = DONT
            # If the option type is DO or DONT, we respond with WONT
            elsif [DO, DONT].index(opttype)!=nil
                opttype = WONT
            end
            # Our response is [IAC] + [OPTION TYPE] + [OPTION]
            resp << IAC
            resp << opttype
            resp << opt
            index += 1
        end
        sock.put(resp)
        response += sock.recv(1024)
    end
# End stolen code
# Heavily based off of H. D. Moore's banner-plus.nse
End stolen code
Heavily based off of H. D.
End stolen code Heavily based off of H . D .
def negotiate_telnet(sock)
        response = sock.recv(1024)
        resp = ""
        index = 0
        (0..20).each do
            index = response.index(IAC, index)
            break if not index
            opttype = response[index+1]
            opt = response[index+2]
            if [WILL, WONT].index(opttype)!=nil
                opttype = DONT
            elsif [DO, DONT].index(opttype)!=nil
                opttype = WONT
            end
            resp << IAC
            resp << opttype
            resp << opt
            index += 1
        end
        sock.put(resp)
        response += sock.recv(1024)
    end
def negotiate_telnet ( sock ) response = sock . recv ( 1024 ) resp = "" index = 0 ( 0 .. 20 ) . each do index = response . index ( IAC , index ) break if not index opttype = response [ index + 1 ] opt = response [ index + 2 ] if [ WILL , WONT ] . index ( opttype ) != nil opttype = DONT elsif [ DO , DONT ] . index ( opttype ) != nil opttype = WONT end resp << IAC resp << opttype resp << opt index += 1 end sock . put ( resp ) response += sock . recv ( 1024 ) end
End stolen code
Heavily based off of H. D. Moore's banner-plus.nse
End stolen code Heavily based off of H . D . Moore ' s banner - plus . nse
# If the response is IAC (Interpret as Command) # The option type is the character after IAC # The option is the character after that # If the option type is WILL or WONT, we respond with DONT # If the option type is DO or DONT, we respond with WONT # Our response is [IAC] + [OPTION TYPE] + [OPTION]
sock