Class: ConnectionTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rex/proto/ntlm.rb.ut.rb

Instance Method Summary collapse

Instance Method Details

#client_auth(pw) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 41

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=]+)/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 = http_message(msg_3)
	socket.put auth_req
	auth_res = socket.get(3)
	socket.close
	return auth_res
end

#http_message(msg) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 31

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

#setupObject



11
12
13
14
15
16
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 11

def setup
	@user = "admin"
	@pass = "1234"
	@domain = ""
	@host = "192.168.145.161"
end

#test_client_auth_failObject



68
69
70
71
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 68

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_successObject



64
65
66
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 64

def test_client_auth_success
	assert_equal client_auth(@pass)[0,12], "HTTP/1.1 200"
end

#test_socket_connectivityObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rex/proto/ntlm.rb.ut.rb', line 18

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