CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/ntp/modes_spec.rb
Views: 1904
1
# -*- coding: binary -*-
2
#
3
4
RSpec.describe "Rex::Proto::NTP mode message handling" do
5
before do
6
@payload = 'R7' * 7
7
end
8
9
describe Rex::Proto::NTP::NTPControl do
10
before do
11
@control_raw = "\x1e\x05\x12\x34\x12\x34\x12\x34\x00\x00\x00\x0e" + @payload
12
@control = Rex::Proto::NTP::NTPControl.new
13
@control.version = 3
14
@control.response = 0
15
@control.more = 0
16
@control.operation = 5
17
@control.sequence = 0x1234
18
@control.association_id = 0x1234
19
@control.status = 0x1234
20
@control.payload_offset = 0
21
@control.payload_size = 14
22
@control.payload = @payload
23
end
24
25
it 'Generates control NTP messages correctly' do
26
expect(@control_raw).to eq @control.to_binary_s
27
end
28
29
it 'Parses control NTP messages correctly' do
30
parsed_raw = Rex::Proto::NTP::NTPControl.new.read(@control_raw)
31
expect(@control).to eq parsed_raw
32
end
33
end
34
35
describe Rex::Proto::NTP::NTPGeneric do
36
before do
37
@generic_raw = "\xcc\x12\x34\x56" + @payload
38
@generic = Rex::Proto::NTP::NTPGeneric.new
39
@generic.li = 3
40
@generic.version = 1
41
@generic.mode = 4
42
@generic.stratum = 0x12
43
@generic.poll = 0x34
44
@generic.precision = 0x56
45
@generic.payload = @payload
46
end
47
48
it 'Generates generic NTP messages correctly' do
49
expect(@generic_raw).to eq @generic.to_binary_s
50
end
51
52
it 'Parses generic NTP messages correctly' do
53
parsed_raw = Rex::Proto::NTP::NTPGeneric.new.read(@generic_raw)
54
expect(@generic).to eq parsed_raw
55
end
56
end
57
58
describe Rex::Proto::NTP::NTPPrivate do
59
before do
60
@private_raw = "\x1f\x5a\x01\x99\x00\x00\x00\x00" + @payload
61
@private = Rex::Proto::NTP::NTPPrivate.new
62
@private.response = 0
63
@private.more = 0
64
@private.version = 3
65
@private.mode = 7
66
@private.auth = 0
67
@private.sequence = 90
68
@private.implementation = 1
69
@private.request_code = 153
70
@private.payload = @payload
71
end
72
73
it 'Generates private NTP messages correctly' do
74
expect(@private_raw).to eq @private.to_binary_s
75
end
76
77
it 'Parses private NTP messages correctly' do
78
parsed_raw = Rex::Proto::NTP::NTPPrivate.new.read(@private_raw)
79
expect(@private).to eq parsed_raw
80
end
81
end
82
end
83
84