Exploiting SAP - CYBSEC
Exploiting SAP - CYBSEC
Agenda
• SAP Connectivity
• SAP RFC Interface
• The RFC Library
• Security Review of the RFC Interface Implementation
• Advanced Attacks
• Tool Release: sapyto
• Conclusions
• Questions & Answers
2
Attacking the Giants: Exploiting SAP Internals
© 2007
SAP Connectivity
3
Attacking the Giants: Exploiting SAP Internals
SAP Connectivity © 2007
SAP Connectivity
4
Attacking the Giants: Exploiting SAP Internals
© 2007
SAP RFC
Interface
5
Attacking the Giants: Exploiting SAP Internals
SAP RFC Interface © 2007
A Bit of History...
6
Attacking the Giants: Exploiting SAP Internals
SAP RFC Interface © 2007
7
Attacking the Giants: Exploiting SAP Internals
SAP RFC Interface © 2007
...
CALL FUNCTION ‘ZCUST_GETMONEY’ DESTINATION ‘PROD2’
EXPORTING
ZCUST_ID = 100
IMPORTING
MONEY = cust_money
TABLES
TABINFO = table1
EXCEPTIONS
CUST_NOT_FOUND = 0
TABLE_EMPTY = 1
... 8
Attacking the Giants: Exploiting SAP Internals
SAP RFC Interface © 2007
9
Attacking the Giants: Exploiting SAP Internals
SAP RFC Interface © 2007
Gateway Server
Gateway
Gateway Reader Gateway Monitor
Work Process
TCP/IP LU 6.2
10
Attacking the Giants: Exploiting SAP Internals
SAP RFC Interface © 2007
External System SAP R/3 System SAP R/3 System External System
E E
W W Server Function 2
Result A A
result
Y Y
11
Attacking the Giants: Exploiting SAP Internals
SAP RFC Interface © 2007
13
Attacking the Giants: Exploiting SAP Internals
The RFC Library © 2007
14
Attacking the Giants: Exploiting SAP Internals
The RFC Library © 2007
RfcInstallFunction(RFC_FUNCTIONNAME functionname,
RFC_ONCALL f_ptr,
rfc_char_t *docu);
Security Review
of the RFC
Interface
Implementation
16
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
Traffic Analysis
17
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
Traffic Analysis
...
01a0 00 00 00 00 00 00 06 05 14 00 10 5f 22 ea 45 5e ..........._".E^
01b0 22 c5 10 e1 00 00 00 c0 a8 02 8b 05 14 01 30 00 ".............0.
01c0 0a 72 66 63 5f 73 65 72 76 65 72 01 30 01 11 00 .rfc_server.0...
01d0 06 42 43 55 53 45 52 01 11 01 17 00 0b 81 bb 89 .BCUSER.........
01e0 62 fc b5 3e 70 07 6e 79 01 17 01 14 00 03 30 30 b..?w.oy......00
01f0 30 01 14 01 15 00 01 45 01 15 05 01 00 01 01 05 0......E........
0200 01 05 02 00 00 05 02 00 0b 00 03 36 34 30 00 0b ...........640..
0210 01 02 00 0e 5a 43 55 53 54 5f 47 45 54 4d 4f 4e ....ZCUST_GETMON
0220 45 59 01 02 05 14 00 10 5f 22 ea 45 5e 22 c5 10 EY......_".E^"..
0230 e1 00 00 00 c0 a8 02 8b 05 14 02 01 00 09 43 4c ..............CL
0240 49 45 4e 54 5f 49 44 02 01 02 03 00 08 43 55 53 IENT_ID......CUS
0250 54 30 30 31 00 02 03 ff ff 00 00 ff ff 00 00 01 T001............
0260 c7 00 00 3e 80 ...>.
18
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
• You said that data is clear-text... but I can’t see a single password!
• Reason: Password is obfuscated.
19
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
20
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
• A RFC ping
• Connects to the target system, analyzing its availability.
• No need for valid logon data.
• Available in External Systems and R/3.
21
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
• RFC_TRUSTED_SYSTEM_SECURITY
• RFC_SET_REG_SERVER_PROPERTY
• RFC_START_GUI
• SYSTEM_CREATE_INSTANCE
• RFC_START_PROGRAM
Impact:
This function can be used to check existence of users and groups in
an External system, its domain and trusted domains.
24
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
Impact:
Calling this function with a special parameter would render an
External Registered Server unavailable to other clients (Denial of
Service).
25
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
Impact:
Calling this function with a specially crafted parameter would result
in the ability to run remote arbitrary commands over the External
Server system.
26
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
Impact:
Calling this function with a specially crafted parameter would result
in the ability to run remote arbitrary commands over the External
Server system.
27
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
28
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
Impact:
Calling the functions with specially crafted parameters would allow
an attacker to:
• Obtain information about configuration of the remote server.
• Execute remote arbitrary commands, exploiting a buffer
overflow vulnerability.
29
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
30
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
RFCEXEC
31
Attacking the Giants: Exploiting SAP Internals
Security Review of the RFC Interface... © 2007
SAPXPG
32
Attacking the Giants: Exploiting SAP Internals
© 2007
Advanced
Attacks
33
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
Attacks Setup
• Scenario:
35
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
Evil Twin
• External Servers can register several times with the same Program ID.
• ANY External Server can register with that ID!
• Attack:
G1
D =RE
I
External RFC
Server
SAP GW
SAP R/3
37
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
SAP GW
SAP R/3
38
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
RCF Call
Server
SAP GW
SAP R/3
39
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
SAP GW
SAP R/3
G1
D =RE
I
External RFC
Server
SAP GW ID=
RE
G1
SAP R/3
41
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
RCF Call
SAP GW ID=
RE
G1
SAP R/3
• Proof of Concept.
• Attack:
G1
D =RE
I
RESPONSE
External RFC
Server
SAP GW
SAP R/3
44
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
SAP GW
Modified
SAP R/3 RESPONSE
45
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
SAP GW ID=
RE
G1
Modified
SAP R/3 RESPONSE
G1
D =RE
I
External RFC
Server
RCF Call
SAP GW ID=
RE
G1
SAP R/3
47
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
RCF Modified External RFC
Call
Server
SAP GW ID=
RE
G1
SAP R/3
48
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
RFC Call
Client
Function 1
Send data
Send result
49
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
50
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
RESPONSE I
External RFC
Server
SAP GW
SAP R/3
- Yes, again the same scenario: the valid client, the valid
External RFC Server, the SAP R/3 Server and the SAP Gateway
51
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
SAP GW ID=
RE
G1
SAP R/3
52
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
RCF Call
SAP GW ID=
RE
G1
SAP R/3
53
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Poisoned
RCF Callback Server
SAP GW ID=
RE
G1
SAP R/3
54
Attacking the Giants: Exploiting SAP Internals
Advanced Attacks © 2007
G1
D =RE
I
External RFC
Server
SAP GW ID=
RE
G1
SAP R/3
55
Attacking the Giants: Exploiting SAP Internals
© 2007
Tool Release:
sapyto
56
Attacking the Giants: Exploiting SAP Internals
Tool Release: sapyto © 2007
sapyto
• First public framework for performing SAP Penetration Tests.
• Core dependencies: SAP RFC Library and saprfc module.
• Plugin based.
• Audit & Attack Plugins.
• Shipped with plugins for exploiting RFC vulnerabilities, auditing SAP
R/3 configuration, launching described attacks, etc..
• Developed in Python and C.
57
Attacking the Giants: Exploiting SAP Internals
Tool Release: sapyto © 2007
58
Attacking the Giants: Exploiting SAP Internals
Tool Release: sapyto © 2007
• Tools:
• RFC Password Obfuscator / De-obfuscator.
59
Attacking the Giants: Exploiting SAP Internals
Tool Release: sapyto © 2007
sapyto Demonstration
60
Attacking the Giants: Exploiting SAP Internals
© 2007
61
Attacking the Giants: Exploiting SAP Internals
© 2007
Coming soon...
soon...
• Attacking SAP clients.
• SAP Backdoors.
• ABAP Worms.
• Exploiting Trusted Systems.
• RFC Fuzzer.
• ...
Stay tunned!
tunned!
62
Attacking the Giants: Exploiting SAP Internals
© 2007
Questions?
63
Attacking the Giants: Exploiting SAP Internals
© 2007
Thank you!
www.cybsec.com
64