@@ -7,7 +7,9 @@ class MetasploitModule < Msf::Auxiliary
7
7
include Msf ::Auxiliary ::Report
8
8
include Msf ::Auxiliary ::Scanner
9
9
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
11
13
12
14
def initialize ( info = { } )
13
15
super (
@@ -39,26 +41,16 @@ def initialize(info = {})
39
41
]
40
42
)
41
43
)
42
-
43
- register_options (
44
- [
45
- OptInt . new ( 'OFFSET' , [ true , "Offset from local time, in seconds" , 300 ] )
46
- ] )
47
44
end
48
45
49
46
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
51
49
probe . stratum = 1
52
50
probe . poll = 10
53
- probe . mode = 1
51
+ probe . mode = SYMMETRIC_ACTIVE_MODE
54
52
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
62
54
end
63
55
64
56
# TODO: use different values for each?
@@ -67,24 +59,24 @@ def build_crypto_nak(time)
67
59
probe . receive_timestamp = time
68
60
probe . transmit_timestamp = time
69
61
# key-id 0
70
- probe . payload = " \x00 \x00 \x00 \x00 "
62
+ probe . key_identifier = 0
71
63
probe
72
64
end
73
65
74
66
def check
75
67
connect_udp
76
68
77
69
# pick a random 64-bit timestamp
78
- canary_timestamp = rand ( ( 2 ** 32 ) .. ( ( 2 ** 64 ) - 1 ) )
70
+ canary_timestamp = Time . now . utc - ( 60 * 5 )
79
71
probe = build_crypto_nak ( canary_timestamp )
80
- udp_sock . put ( probe )
72
+ udp_sock . put ( probe . to_binary_s )
81
73
82
- expected_length = probe . to_binary_s . length - probe . payload . length
74
+ expected_length = probe . offset_of ( probe . key_identifier )
83
75
response = udp_sock . timed_read ( expected_length )
84
76
disconnect_udp
85
77
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
88
80
vprint_good ( "#{ rhost } :#{ rport } - NTP - VULNERABLE: Accepted a NTP symmetric active association" )
89
81
report_vuln (
90
82
host : rhost ,
0 commit comments