Skip to content

Commit bc3ac1e

Browse files
committed
Correct private message format, update tests
1 parent 1500f33 commit bc3ac1e

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/rex/proto/ntp/modes.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,31 @@ class NTPPrivate < BitStruct
6666
# 0 1 2 3
6767
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
6868
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69-
# |R M| VN | 7 |A| Sequence |
69+
# |R M| VN | 7 |A| Sequence | Implementation| Req code |
7070
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71-
# | Implementation| request code |
72-
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73-
unsigned :response, 1, default: 0
74-
unsigned :more, 1, default: 0
71+
# | err | Number of data items | MBZ | Size of data item |
72+
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73+
unsigned :response, 1, default: 0
74+
unsigned :more, 1, default: 0
7575
unsigned :version, 3, default: 0
7676
unsigned :mode, 3, default: 7
7777
unsigned :auth, 1, default: 0
7878
unsigned :sequence, 7, default: 0
7979
unsigned :implementation, 8, default: 0
8080
unsigned :request_code, 8, default: 0
81+
unsigned :error, 4, default: 0
82+
unsigned :record_count, 12, default: 0
83+
unsigned :mbz, 4, default: 0
84+
unsigned :record_size, 12, default: 0
8185
rest :payload
86+
87+
def records
88+
records = []
89+
1.upto(record_count) do |record_num|
90+
records << payload[record_size*(record_num-1), record_size]
91+
end
92+
records
93+
end
8294
end
8395

8496
def self.ntp_control(version, operation, payload = nil)

spec/lib/rex/proto/ntp/modes_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@control_raw.should == @control.to_s
2828
end
2929

30-
it 'Parses private NTP messages correctly' do
30+
it 'Parses control NTP messages correctly' do
3131
parsed_raw = Rex::Proto::NTP::NTPControl.new(@control_raw)
3232
@control.should == parsed_raw
3333
end
@@ -50,15 +50,15 @@
5050
@generic_raw.should == @generic.to_s
5151
end
5252

53-
it 'Parses private NTP messages correctly' do
53+
it 'Parses generic NTP messages correctly' do
5454
parsed_raw = Rex::Proto::NTP::NTPGeneric.new(@generic_raw)
5555
@generic.should == parsed_raw
5656
end
5757
end
5858

5959
describe Rex::Proto::NTP::NTPPrivate do
6060
before do
61-
@private_raw = "\x1f\x5a\x01\x99" + @payload
61+
@private_raw = "\x1f\x5a\x01\x99\x00\x00\x00\x00" + @payload
6262
@private = Rex::Proto::NTP::NTPPrivate.new
6363
@private.response = 0
6464
@private.more = 0

0 commit comments

Comments
 (0)