@@ -47,18 +47,13 @@ def initialize(info = {})
47
47
end
48
48
49
49
def build_crypto_nak ( time )
50
- probe = Rex ::Proto ::NTP ::NTPSymmetric . new
50
+ probe = NTPHeader . new
51
+ probe . version_number = 3
51
52
probe . stratum = 1
52
53
probe . poll = 10
53
54
probe . mode = 1
54
55
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
56
+ time = Time . now
62
57
end
63
58
64
59
# TODO: use different values for each?
@@ -67,24 +62,24 @@ def build_crypto_nak(time)
67
62
probe . receive_timestamp = time
68
63
probe . transmit_timestamp = time
69
64
# key-id 0
70
- probe . payload = " \x00 \x00 \x00 \x00 "
65
+ probe . key_identifier = 0
71
66
probe
72
67
end
73
68
74
69
def check
75
70
connect_udp
76
71
77
72
# pick a random 64-bit timestamp
78
- canary_timestamp = rand ( ( 2 ** 32 ) .. ( ( 2 ** 64 ) - 1 ) )
73
+ canary_timestamp = Time . now . utc - ( 60 * 5 )
79
74
probe = build_crypto_nak ( canary_timestamp )
80
- udp_sock . put ( probe )
75
+ udp_sock . put ( probe . to_binary_s )
81
76
82
- expected_length = probe . to_binary_s . length - probe . payload . length
77
+ expected_length = probe . offset_of ( probe . key_identifier )
83
78
response = udp_sock . timed_read ( expected_length )
84
79
disconnect_udp
85
80
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
81
+ ntp_symmetric = NTPHeader . read ( response )
82
+ if ntp_symmetric . mode == 2 && ntp_symmetric . origin_timestamp == nil
88
83
vprint_good ( "#{ rhost } :#{ rport } - NTP - VULNERABLE: Accepted a NTP symmetric active association" )
89
84
report_vuln (
90
85
host : rhost ,
0 commit comments