6
6
##
7
7
8
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 -
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
11
# http://www.onapsis.com/research-free-solutions.php.
12
- # Mariano Nuñez (the author of the Bizploit framework) helped me in my efforts
12
+ # Mariano Nunez (the author of the Bizploit framework) helped me in my efforts
13
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
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
16
# provided excellent feedback. Some people just seem to enjoy hacking SAP :)
17
17
##
18
18
@@ -27,28 +27,28 @@ class Metasploit4 < Msf::Auxiliary
27
27
def initialize
28
28
super (
29
29
'Name' => 'SAP RFC RFC_READ_TABLE' ,
30
- 'Version' => '$Revision: $0.1' ,
31
30
'Description' => %q{
32
- This module makes use of the RFC_READ_TABLE Remote Function Call (via SOAP) to read data from tables.
31
+ This module makes use of the RFC_READ_TABLE Remote Function Call (via SOAP) to read
32
+ data from tables.
33
33
} ,
34
- 'References' => [ [ 'URL' , 'http://labs.mwrinfosecurity.com' ] ] ,
34
+ 'References' => [ [ 'URL' , 'http://labs.mwrinfosecurity.com/tools/2012/04/27/sap-metasploit-modules/ ' ] ] ,
35
35
'Author' => [ 'Agnivesh Sathasivam' , 'nmonkee' ] ,
36
36
'License' => BSD_LICENSE
37
37
)
38
-
38
+
39
39
register_options (
40
40
[
41
41
OptString . new ( 'CLIENT' , [ true , 'Client' , nil ] ) ,
42
42
OptString . new ( 'USERNAME' , [ true , 'Username' , nil ] ) ,
43
43
OptString . new ( 'PASSWORD' , [ true , 'Password' , nil ] ) ,
44
44
OptString . new ( 'TABLE' , [ true , 'Table to read' , nil ] ) ,
45
- OptString . new ( 'FIELDS' , [ true , 'Fields to read' , '*' ] ) ,
45
+ OptString . new ( 'FIELDS' , [ true , 'Fields to read' , '*' ] )
46
46
] , self . class )
47
47
end
48
-
48
+
49
49
def run_host ( ip )
50
50
columns = [ ]
51
- columns . push ( '*' ) if datastore [ 'FIELDS' ] . nil?
51
+ columns << '*' if datastore [ 'FIELDS' ] . nil?
52
52
if datastore [ 'FIELDS' ]
53
53
columns . push ( datastore [ 'FIELDS' ] ) if datastore [ 'FIELDS' ] =~ /^\w ?/
54
54
columns = datastore [ 'FIELDS' ] . split ( ',' ) if datastore [ 'FIELDS' ] =~ /\w *,\w */
@@ -59,7 +59,7 @@ def run_host(ip)
59
59
end
60
60
exec ( ip , fields )
61
61
end
62
-
62
+
63
63
def exec ( ip , fields )
64
64
data = '<?xml version="1.0" encoding="utf-8" ?>'
65
65
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">'
@@ -88,27 +88,27 @@ def exec(ip,fields)
88
88
'SOAPAction' => 'urn:sap-com:document:sap:rfc:functions' ,
89
89
'Cookie' => 'sap-usercontext=sap-language=EN&sap-client=' + datastore [ 'CLIENT' ] ,
90
90
'Authorization' => 'Basic ' + user_pass ,
91
- 'Content-Type' => 'text/xml; charset=UTF-8' ,
91
+ 'Content-Type' => 'text/xml; charset=UTF-8'
92
92
}
93
93
} , 45 )
94
- if ( res and res . code != 500 and res . code != 200 )
94
+ if res and res . code ! 500 and res . code != 200
95
95
# to do - implement error handlers for each status code, 404, 301, etc.
96
96
if res . body =~ /<h1>Logon failed<\/ h1>/
97
97
print_error ( "[SAP] #{ ip } :#{ rport } - login failed!" )
98
98
else
99
99
print_error ( "[SAP] #{ ip } :#{ rport } - something went wrong!" )
100
100
end
101
101
return
102
- elsif res . body =~ /Exception/
102
+ elsif res and res . body =~ /Exception/
103
103
response = res . body
104
104
error = response . scan ( %r{<faultstring>(.*?)</faultstring>} )
105
105
success = false
106
106
return
107
107
else
108
- response = res . body
108
+ response = res . body if res
109
109
success = true
110
110
end
111
- if success == true
111
+ if success
112
112
output = response . scan ( %r{<WA>([^<]+)</WA>} ) . flatten
113
113
print_status ( "[SAP] #{ ip } :#{ rport } - got response" )
114
114
saptbl = Msf ::Ui ::Console ::Table . new (
@@ -117,21 +117,21 @@ def exec(ip,fields)
117
117
'Prefix' => "\n " ,
118
118
'Postfix' => "\n " ,
119
119
'Indent' => 1 ,
120
- 'Columns' => [ "Returned Data" ] ,
120
+ 'Columns' => [ "Returned Data" ]
121
121
)
122
- for i in 0 .. output . length -1
122
+ 0 . upto ( output . length -1 ) do | i |
123
123
saptbl << [ output [ i ] ]
124
124
end
125
125
print ( saptbl . to_s )
126
126
end
127
- if success == false
128
- for i in 0 .. error . length -1
127
+ if ! success
128
+ 0 . upto ( error . length -1 ) do | i |
129
129
print_error ( "[SAP] #{ ip } :#{ rport } - error #{ error [ i ] } " )
130
130
end
131
131
end
132
- rescue ::Rex ::ConnectionError
133
- print_error ( "[SAP] #{ ip } :#{ rport } - Unable to connect" )
134
- return
135
- end
132
+ rescue ::Rex ::ConnectionError
133
+ print_error ( "[SAP] #{ ip } :#{ rport } - Unable to connect" )
134
+ return false
136
135
end
137
- end
136
+ end
137
+ end
0 commit comments