Class: Rex::Proto::DRDA::Utils::UnitTest

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

Constant Summary collapse

Klass =
Rex::Proto::DRDA

Instance Method Summary collapse

Instance Method Details

#test_client_authObject

Client auth requires a successful probe. This is a complete authentication sequence, culminating in info returning either true or false.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rex/proto/drda/utils.rb.ut.rb', line 56

def test_client_auth
	probe_pkt = Klass::Utils.client_probe('toolsdb')
	auth_pkt = Klass::Utils.client_auth(:dbname => 'toolsdb',
		:dbuser => $_REX_TEST_DRDA_USER.to_s,
		:dbpass => $_REX_TEST_DRDA_PASS.to_s
	)
	begin
		Timeout.timeout($_REX_TEST_TIMEOUT) do
			socket = Rex::Socket.create_tcp(
				'PeerHost' => $_REX_TEST_DRDA_HOST.to_s, 
				'PeerPort' => 50000
			)
			sent = socket.put probe_pkt
			probe_reply = socket.get_once
			sent = socket.put auth_pkt
			assert_equal(75, sent)
			auth_reply = socket.get_once
			parsed_auth_reply = Klass::SERVER_PACKET.new.read auth_reply
			info = Klass::Utils.server_packet_info(parsed_auth_reply)
			assert info[:db_login_success]
			socket.close
		end
	rescue Timeout::Error
		flunk("Timed out")
	end
end

#test_client_probeObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rex/proto/drda/utils.rb.ut.rb', line 31

def test_client_probe
	probe_pkt = Klass::Utils.client_probe('toolsdb')
	begin
		Timeout.timeout($_REX_TEST_TIMEOUT) do
			socket = Rex::Socket.create_tcp(
				'PeerHost' => $_REX_TEST_DRDA_HOST.to_s, 
				'PeerPort' => 50000
			)
			sent = socket.put probe_pkt
			assert_equal 76, sent
			probe_reply = socket.get_once
			assert_operator probe_reply.size, :>=, 10
			parsed_reply = Klass::SERVER_PACKET.new.read probe_reply
			assert_kind_of Array, parsed_reply
			assert_equal parsed_reply[0].codepoint, Klass::Constants::EXCSATRD
			socket.close
		end
	rescue Timeout::Error
		flunk("Timed out")
	end
end

#test_client_probe_createObject



26
27
28
29
# File 'lib/rex/proto/drda/utils.rb.ut.rb', line 26

def test_client_probe_create
	probe_pkt = Klass::Utils.client_probe
	assert_equal 54, probe_pkt.size
end

#test_socket_connectivityObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rex/proto/drda/utils.rb.ut.rb', line 13

def test_socket_connectivity
	assert_nothing_raised do
		socket = Rex::Socket.create_tcp(
			'PeerHost' => $_REX_TEST_DRDA_HOST.to_s, # PeerHost can be nil!
			'PeerPort' => 50000
		)
		assert_kind_of Socket, socket
		assert !socket.closed?
		socket.close
		assert socket.closed?
	end
end