Parent

Class/Module Index [+]

Quicksearch

ConnectionTest

Public Instance Methods

client_auth(pw) click to toggle source
# File lib/rex/proto/ntlm.rb.ut.rb, line 39
def client_auth(pw)
        msg_1 = Rex::Proto::NTLM::Message::Type1.new
        get_req = http_message(msg_1)
        socket = Rex::Socket.create_tcp(
                'PeerHost' => @host,
                'PeerPort' => 80
        )
        socket.put get_req
        res = socket.get(3)
        assert res =~ /WWW-Authenticate: NTLM TlRM/
                res_ntlm = res.match(/WWW-Authenticate: NTLM ([A-Z0-9\x2b\x2f=]+)/)[1]
        assert_operator res_ntlm.size, :>=, 24
        msg_2 = Rex::Proto::NTLM::Message.decode64(res_ntlm)
        assert msg_2
        msg_3 = msg_2.response({:user => @user, :password => pw}, {:ntlmv2 => true})
        assert msg_3
        auth_req = http_message(msg_3)
        socket.put auth_req
        auth_res = socket.get(3)
        socket.close
        return auth_res
end
http_message(msg) click to toggle source
# File lib/rex/proto/ntlm.rb.ut.rb, line 29
def http_message(msg)
        get_req = "GET / HTTP/1.1\r\n"
        get_req += "Host: #{@host}\r\n"
        get_req += "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
        get_req += "Authorization: NTLM #{msg.encode64}\r\n"
        get_req += "Content-type: application/x-www-form-urlencoded\r\n"
        get_req += "Content-Length: 0\r\n"
        get_req += "\r\n"
end
setup() click to toggle source
# File lib/rex/proto/ntlm.rb.ut.rb, line 9
def setup
        @user = "admin"
        @pass = "1234"
        @domain = ""
        @host = "192.168.145.161"
end
test_client_auth_fail() click to toggle source
# File lib/rex/proto/ntlm.rb.ut.rb, line 66
def test_client_auth_fail
        assert_not_equal client_auth("badpass")[0,12], "HTTP/1.1 200"
        assert_equal client_auth("badpass")[0,12], "HTTP/1.1 401"
end
test_client_auth_success() click to toggle source
# File lib/rex/proto/ntlm.rb.ut.rb, line 62
def test_client_auth_success
        assert_equal client_auth(@pass)[0,12], "HTTP/1.1 200"
end
test_socket_connectivity() click to toggle source
# File lib/rex/proto/ntlm.rb.ut.rb, line 16
def test_socket_connectivity
        assert_nothing_raised do
                socket = Rex::Socket.create_tcp(
                        'PeerHost' => @host,
                        'PeerPort' => 80
                )
                assert_kind_of Socket, socket
                assert !socket.closed?
                socket.close
                assert socket.closed?
        end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.