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

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

Constant Summary collapse

Klass =
Rex::Proto::DRDA
Konst =
Rex::Proto::DRDA::Constants

Instance Method Summary collapse

Instance Method Details

#test_all_ddm_codepointsObject

Similarly, so should DDM Structs.



41
42
43
44
45
46
47
48
49
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 41

def test_all_ddm_codepoints
	ddms = Klass.constants.map {|x| x if x =~ /DDM$/}.compact
	assert_operator ddms.size, :>=, 4 # Allow for more later.
	ddms.each do |p|
		cp = p.split(/_DDM/).first
		next if cp == "BASIC"
		assert_kind_of Numeric, Konst.const_get(cp)
	end
end

#test_all_param_codepointsObject

All parameter names should have a corresponding codepoint, except “DDM_PARAM” (a generic parameter).



29
30
31
32
33
34
35
36
37
38
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 29

def test_all_param_codepoints
	params = Klass.constants.map {|x| x if x =~ /PARAM$/}.compact
	assert_operator params.size, :>=, 6 # Allow for more later.
	params.each do |p|
		cp = p.split(/_PARAM/).first
		next if cp == "DDM"
		assert Konst.const_defined? cp
		assert_kind_of Numeric, Konst.const_get(cp)
	end
end

#test_ddm_structObject

Make some similiar assertions about DDMs, though specific DDMs will have particular elements after the codepoint, usually more than one.



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 66

def test_ddm_struct
	ddms = Klass.constants.map {|x| x if x =~ /DDM$/}.compact
	ddms.each do |d|
		obj = Klass.const_get(d).new
		assert_operator obj.size, :>=, 7 
		assert_respond_to obj, :length
		assert_respond_to obj, :magic
		assert_respond_to obj, :format
		assert_respond_to obj, :correlid
		assert_respond_to obj, :length2
		assert_respond_to obj, :codepoint
	end
end

#test_mgrlvlls_paramObject

Test a sample param



14
15
16
17
18
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 14

def test_mgrlvlls_param
	p = Klass::MGRLVLLS_PARAM.new
	assert_kind_of(Struct, p)
	assert_equal(Konst::MGRLVLLS, p.codepoint)
end

#test_param_structObject

Ensure that all params have the same struct.



52
53
54
55
56
57
58
59
60
61
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 52

def test_param_struct
	params = Klass.constants.map {|x| x if x =~ /PARAM$/}.compact
	params.each do |p|
		obj = Klass.const_get(p).new
		assert_equal 3, obj.size
		assert_respond_to obj, :codepoint
		assert_respond_to obj, :length
		assert_respond_to obj, :payload
	end
end

#test_secchk_ddmObject

Test a sample ddm



21
22
23
24
25
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 21

def test_secchk_ddm
	d = Klass::SECCHK_DDM.new
	assert_kind_of Struct, d
	assert_equal Konst::SECCHK, d.codepoint
end

#test_server_packet_readObject

Exercise the SERVER_PACKET#read function with a sample packet.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 93

def test_server_packet_read
	pkt = "0015d0420001000f1219000611490000000511a4000050d0520002004a2201000611490000000c112ee2d8d3f0f8f0f2f4000d002fd8e3c4e2d8d3e7f8f6000a00350006119c033300062103022e00172135c3f0c1f8f6c1f0f14bc5c6f1f2070402195612008cd0030002008624080000000000303030303053514c303830323400ffffffff0200000000000000030000000000000000000000202020202020202020202000124d59444232444220202020202020202020200000003331ff383139ff4d59555345522020ff4d594442324442ff514442322f4c494e5558ff353538ff353538ff30ff31323038ff30ffff".scan(/../).map {|x| x.to_i(16).chr}.join
	s = Klass::SERVER_PACKET.new
	assert_equal 0, s.size
	s.read(pkt)
	assert_equal 3, s.size
	assert_equal Konst::SECCHKRM, s[0].codepoint
	assert_equal Konst::ACCRDBRM, s[1].codepoint
	assert_equal Konst::SQLCARD, s[2].codepoint
	assert_equal 0xd0, s[0].magic 
	assert_equal 0x52, s[1].format
	assert_equal 134, s[2].length2
	assert_equal 21+80+140, s.sz
end

#test_server_packet_structureObject

The server packet is special since it’s an Array of BASIC_DDM’s, and doesn’t have a particular, fixed struct. (It would be nice to build those up on the fly, but we’re not really interested in validating most server responses right now.



84
85
86
87
88
89
90
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 84

def test_server_packet_structure
	s = Klass::SERVER_PACKET.new
	assert_kind_of Array, s
	assert_respond_to s, :to_s
	assert_respond_to s, :sz
	assert_respond_to s, :read
end