Skip to content

Commit 29d8697

Browse files
committed
Fix the ntp_nak_to_the_future module
1 parent 72c7f4a commit 29d8697

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

modules/auxiliary/scanner/ntp/ntp_nak_to_the_future.rb

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class MetasploitModule < Msf::Auxiliary
77
include Msf::Auxiliary::Report
88
include Msf::Auxiliary::Scanner
99
include Msf::Exploit::Remote::Udp
10-
include Msf::Auxiliary::NTP
10+
11+
SYMMETRIC_ACTIVE_MODE = Rex::Proto::NTP::Constants::Mode::SYMMETRIC_ACTIVE
12+
SYMMETRIC_PASSIVE_MODE = Rex::Proto::NTP::Constants::Mode::SYMMETRIC_PASSIVE
1113

1214
def initialize(info = {})
1315
super(
@@ -39,26 +41,16 @@ def initialize(info = {})
3941
]
4042
)
4143
)
42-
43-
register_options(
44-
[
45-
OptInt.new('OFFSET', [true, "Offset from local time, in seconds", 300])
46-
])
4744
end
4845

4946
def build_crypto_nak(time)
50-
probe = Rex::Proto::NTP::NTPSymmetric.new
47+
probe = Rex::Proto::NTP::Header::NTPHeader.new
48+
probe.version_number = 3
5149
probe.stratum = 1
5250
probe.poll = 10
53-
probe.mode = 1
51+
probe.mode = SYMMETRIC_ACTIVE_MODE
5452
unless time
55-
now = Time.now
56-
# compute the timestamp. NTP stores a timestamp as 64-bit unsigned
57-
# integer, the high 32-bits representing the number of seconds since era
58-
# epoch and the low 32-bits representing the fraction of a second. The era
59-
# epoch in this case is Jan 1 1900, so we must add the number of seconds
60-
# between then and the ruby era epoch, Jan 1 1970, which is 2208988800
61-
time = ((now.to_i + 2208988800 + datastore['OFFSET']) << 32) + now.nsec
53+
time = Time.now
6254
end
6355

6456
# TODO: use different values for each?
@@ -67,24 +59,24 @@ def build_crypto_nak(time)
6759
probe.receive_timestamp = time
6860
probe.transmit_timestamp = time
6961
# key-id 0
70-
probe.payload = "\x00\x00\x00\x00"
62+
probe.key_identifier = 0
7163
probe
7264
end
7365

7466
def check
7567
connect_udp
7668

7769
# pick a random 64-bit timestamp
78-
canary_timestamp = rand((2**32)..((2**64) - 1))
70+
canary_timestamp = Time.now.utc - (60 * 5)
7971
probe = build_crypto_nak(canary_timestamp)
80-
udp_sock.put(probe)
72+
udp_sock.put(probe.to_binary_s)
8173

82-
expected_length = probe.to_binary_s.length - probe.payload.length
74+
expected_length = probe.offset_of(probe.key_identifier)
8375
response = udp_sock.timed_read(expected_length)
8476
disconnect_udp
8577
if response.length == expected_length
86-
ntp_symmetric = Rex::Proto::NTP::NTPSymmetric.new.read(response)
87-
if ntp_symmetric.mode == 2 && ntp_symmetric.origin_timestamp == canary_timestamp
78+
ntp_symmetric = Rex::Proto::NTP::Header::NTPHeader.read(response)
79+
if ntp_symmetric.mode == SYMMETRIC_PASSIVE_MODE && ntp_symmetric.origin_timestamp == nil
8880
vprint_good("#{rhost}:#{rport} - NTP - VULNERABLE: Accepted a NTP symmetric active association")
8981
report_vuln(
9082
host: rhost,

0 commit comments

Comments
 (0)