Class: ConnectionTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- ConnectionTest
- Defined in:
- lib/rex/proto/ntlm.rb.ut.rb
Instance Method Summary collapse
- #client_auth(pw) ⇒ Object
- #http_message(msg) ⇒ Object
- #setup ⇒ Object
- #test_client_auth_fail ⇒ Object
- #test_client_auth_success ⇒ Object
- #test_socket_connectivity ⇒ Object
Instance Method Details
#client_auth(pw) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 37 def client_auth(pw) msg_1 = Rex::Proto::NTLM::Message::Type1.new get_req = (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=]+)/i)[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 = (msg_3) socket.put auth_req auth_res = socket.get(3) socket.close return auth_res end |
#http_message(msg) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 27 def (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 ⇒ Object
7 8 9 10 11 12 |
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 7 def setup @user = "admin" @pass = "1234" @domain = "" @host = "192.168.145.161" end |
#test_client_auth_fail ⇒ Object
64 65 66 67 |
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 64 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 ⇒ Object
60 61 62 |
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 60 def test_client_auth_success assert_equal client_auth(@pass)[0,12], "HTTP/1.1 200" end |
#test_socket_connectivity ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 14 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 |