Hardcore Sap Penetration Testing
August 27, 2022 | Author: Anonymous | Category: N/A
Short Description
Download Hardcore Sap Penetration Testing...
Description
Disclaimer According to the partnership agreement between ERPScan and SAP, our company is not entled to publish any specic and detailed informaon about detected vulnerabilies before SAP releases an appropriate appropriat e patch. This white paper only includes the details of those vulnerabilies that we have the right to publish as of the release date. However, However, you can see addional examples of exploitaon, which prove the existence of the vulnerabilies by following us during the conferences as well as at ERPScan. com.
The research was conducted by ERPScan as a part of contribuon to the EAS-SEC non-prot organizaon organizaon that is focused on Enterprise Applicaon Security awareness. This document or any of its fragments cannot be reproduced or distributed in whole or in part without prior wrien consent of EAS-SEC. SAP SE is neither the author nor the publisher of this whitepaper and is not responsible for its content. EAS-SEC and ERPScan are not responsible for any damage that can be incurred by aempng to test the vulnerabilies described in this document. This publicaon contains references refer ences to SAP SE products. SAP NetWeaver and other SAP products and services menoned herein are trademarks or registered trademarks of SAP SE. Our SAP security surveys go beyond this whitepaper. You can nd the latest stascs reports related to SAP services on the Internet and other endeavors of the ERPScan Research on on ERPScan ocial blog and on EAS-SEC project’s website.
2
Contents Disclaimer ............................................................................................................. ................................................................................................................................................ ................................... 2
Introducon................................................................................................................................. ............................................................................................................................................. ............ 4 What is SAP pentest? .................................... ............................................................................................................................ ........................................................................................4 4 SAP Pentest vs. SAP Security Audit .......................................................................................................5 Threat Modelling .................................................................................................................. ..................................................................................................................................... ................... 6
Analyzing Risks for Manufacturing Industry .................................................................................... ......................................................................................... ...... 6 Idenfying the most important assets in SAP landscape . ...................................................................... .....................................................................7 7 Uncovering SAP Plaorms for the most crical assets .......................................................................... .........................................................................7 7 How vulnerable are SAP plaorms? ...................................................................................................... .....................................................................................................8 8 Aack Scenario ........................................................................................................ ..................................................................................................................................... .............................. 10 Informaon gathering ................................... ......................................................................................................................... ......................................................................................10 10 Vulnerability exploitaon ................................. .................................................................................................................... ...................................................................................11 11 Privilege escalaon .............................................................................................................................13 Business Risk demonstra demonstraon on ..............................................................................................................13 The Scope of the Search .............................. ................................................................................................. .......................................................................................... ....................... 15 SAP Informaon disclosure ................................................................................................................17 SAP SQL injecon ....................................... ................................................................................................................................ .........................................................................................18 18 Crypto issue ........................................... ........................................................................................................................................ .............................................................................................24 24 Hardcore SAP Pentesng - Exploitaon ..............................................................................................31 Automaon ............................................ ......................................................................................................................................... .............................................................................................33 33 Privilege escalaon, remote command execuon ........ .............................................................................. ......................................................................36 36 Conclusion ......................................... ............................................................................................................. .................................................................................................... ................................ 39 Contacts ..................................................................................................................................... ................................................................................................................................................. ............ 40
3
Introduction Pentest, or penetraon tesng, stands for a range of processes that simulate an aacker's acons to idenfy security weaknesses. Usually, a company engages third-party security experts in conducng penetraon tesng and provides them with the address(es) of the server(s) they should examine. Pentestss are oen divided into two types: Pentest • white-box pentest - a pentest, in which experts are provided with background system information; • black-box pentest - a pentest in which background system data is unknown to a pentest executor.
The pentesng process of the rst model, when pentesters are outside the internal network and have no privileges, includes the following steps: 1. Acquiring information about a company, systems, and users. 2. Exploitation of vulnerabilities to access the system with minimal user privileges. 3. Exploitation of vulnerabilities and escalation of privileges to access a database and critical business information. 4. Acquiring administrative administrative access to an OS.
During a white-box pentesng, a client company informs a pentester about the infrastructure, gives a computer network diagram, explains specic features of protecng mechanisms, and somemes provides access to the source code. Both types of pentests may include manual and automac works. For example, examining source code for vulnerabilies is simplied by using ready-made pentesng tools (available on the Internet) or custom programs wrien on their own. Numerous tools can come in handy during pentesng, such as those that automate system analysis and exploitaon of SQL injecon, XSS, or RCE vulnerabilies. Nonetheless, it is impossible to conduct a successful penetraon tesng with automated programs only because every company has its own specic features, and pentesters have to modify programs adapng to each individual client.
► What is SAP pentest? Why do you need to access an SAP system security? The rst reason is rather obvious and simple: an SAP aon System is a tempng target hackersprocesses. because it stores and manages the lifeblood of any organizaon organiz – crical c rical informaon andfor business However, that is not it. Imagine a certain SAP module liable for industrial technologies, for example, one that controls oil exploitaon or transportaon. No need to say it has vital importance when it comes to producon lifecycle. How to ensure that the SAP system is not vulnerable and perpetrators are not able to interf interfere ere in any process? SAP Penetraon tesng perfectly serves the purpose here. A typical black-box SAP penetraon tesng looks like this: 1. Penetration testers scan SAP systems in their scope trying to reveal as much system information as possible. 2. According to the information obtained from the first step, the pentesters recognize what database, SAP version, and particular SAP modules are implemented. Then, they search for vulnerabilities a
version is susceptible to. By exploiting these vulnerabilities, pentesters pentesters gain minimal access rights to the system (e.g., as a guest user).
4
3. By exploiting vulnerabilities, pentesters escalate privileges and get administrative access to a system.
SAP soware is unique, and its specic nature should be taken into account while conducng an SAP Penetraon tesng. For example, by default, an administrator password, a password to a database, and a scheme for connecng an SAP server to a database are encrypted and stored in the SecStore. properes le, and the decrypon key is kept in the SecStore.key le. Therefore, in case of a poorly congured system, the exploitaon of a vulnerability, like Directory Traversal or XXE, is enough to read les from a server. Since a vendor now focuses on the security of its products and new protecng mechanisms are implemented, SAP system compromise compromise is more of a challenge to accomplish. Likewise, SAP security hits the radar of organizaons' security teams. So, these days it is unlikely that one can compromise the whole SAP system by exploing a single vulnerability vulnerability.. Thus a pentester has to exploit a chain of security issues to achieve the nal results.
► SAP Pentest vs. SAP Security Audit Another opon to assess SAP system security is SAP security Audit. If during pentesng a security expert does not succeed in hacking a system for a certain period of me (for example, 2 weeks), it does not mean that this system is secure and hackers cannot break into it. It simply means that if aackers have more me, they will succeed. The security audit process lies in the fact that a group of experts is provided with full access to a syst system, em, source code, and internal network so that they can analyze its security more eecvely and discover more vulnerabilies than during black-box or white-box pentests.
5
Threat Modelling A penetraon test is a pracce of aacking an IT infrastructure to evaluate evaluate its security and determine whether malicious acons are possible. Although it is a common task, the nature and methodology of a penetraon test dier according to the scope, aims, a client-compan client-company's y's specics, and many other factors. Once the ERPScan team was conducng a penetraon test in a large manufacturing organizaon. organizaon. The task was not so ordinary and easy because the number of syst systems ems in the scope was huge and lile me was alloed. That is why it was absolutely necessary to perform Threat Modelling before diving into the process of hacking. Threat Modelling is the rst step of every successful penetraon tesng. tesng. At this stage, a cybersecurity expert gets the picture of business processes of a typical manufacturing company, company, idenes the most crical assets and associated risks. The gathered informaon helps a penetraon tester tester to decide what to focus on.
► Analyzing Risks for Manufacturing Industry Manufacturing companies are aracve targets for dierent kinds of cybercriminals, i.e., state-sponsored hackers, hackvists, terrorists, malicious insiders). Such companies are responsible for a great part of some countries' economy. Any interference in their work can stop processes and, as a result, deprive the company and the country of revenue. Just to give some background informaon, in 2015 the United States exported app. 2.6 million vehicles valued at $65 billion. The manufacturing industry is indeed on the radar of cybercriminals. For example, the cyberaack cyberaack against a steel mill in Germany hit the headlines in 2015, as it has caused conrmed physical damage. In case of a cyberaack, a manufacturing company may face the following consequences: • Plant Sabotage/Shut Sabotage/Shutdown down • Equipment damage • Production Disruption (Stop or pause production) • Product Quality (Quality degradation) • Compliance violation (Such as pollution) • Safety violation (Death or injury)
Aer we have idened the most important risks for the manufacturing industry, the next step is to nd out whether it is possible to cause these risks by accessing acce ssing SAP systems and that exactly exactly an aacker should exploit to cause them. SAP systems are widely used in the Manufacturing industry, industry, and there are even specic SAP modules for Manufacturing. Cyberaacks Cyberaacks on SAP systems (regardless (regardless of the industry) are crical, as they can lead to espionage, sabotage or fraud. However, However, they can be even more lethal for the Manufacturing because of trust connecons in SAP syst systems ems that are responsible for asset management and technology networks (e.g., plant oor).
6
► Identifying the most important assets in SAP
landscape
A typical manufacturing company's infrastructure consists of mulple business applicaons and industry-specic modules. Here is an incomplete list of the applicaons which common for the majority of manufacturing enterprises: • Enterprise Resource Planning (ERP) • • • •
Manufacturing Execution System (MES) Asset Lifecycle Management (ALM) Manufacturing Integration (xMII) Other standard systems: HR, CRM, PLM, SRM, BI/BW, SCM
Some of these systems such as xMII or ALM can be connected with Industrial Control Control Systems or plant oor, so a single vulnerability in them may pose a risk for the enre company.
► Uncovering SAP Platforms Platforms for the
most critical assets
SAP systems can be based on dierent plaorms: ABAP, Java, or HANA. The main SAP plaorm is SAP NetWeaver, the enabling foundaon for SAP and non-SAP applicaons. The rst version of SAP NetWeaver came out in 2004. Aer that, SAP has introduced several versions of the plaorm and new modules to extend its funconality. As of today, the latest version is SAP NetWeaver NetWea ver 7.5 (the rst release was in October 2015). One of the main parts of SAP NetWeaver is SAP NetWeaver Applicaon Server (AS). SAP NetWeaver NetWeaver AS includes the applicaon server ABAP and Java. As its name implies, the main programming language for SAP NetWeaver AS ABAP plaorm is ABAP and, correspondingly, for SAP NetWeaver AS Java is Java. Returning to our case, the most crical applicaon linked to the producon network is SAP xMII (SAP xApp Manufacturing Integraon and Intelligence) based on the Java plaorm. SAP xMII is oen used in industrial enterprises to manage and automate their processes. This module extends the funconality of SAP NetWea NetWeaver ver AS Java to use it in producon. SAP xMII provides a direct connecon between shop-oor systems and business It enterprise ensures that all dataand related to manufacturing is visible in real me. SAP customers can operaons. also link their processes master data to manufacturing processes to run their business based on a single version. Vulnerabilies in SAP xMII are parcularly hazardous, because this soluon is a kind of a bridge between ERP (Enterprise Resource Planning), other enterprise applicaons and plant oor as well as OT (Operaonal Technology) Technology) devices. Any vulnerability aecng SAP xMII can be used as a starng point of a mul-stage aack aiming to get control over plant devices and manufacturing systems. A brief look at public sources indicates that there is a couple of notable vulnerabilies in the SAP xMII component (e.g., Reected XSS vulnerability, directory traversal vulnerability). Sounds great, now we know what the risks are, which systems are the most important and what plaorm we need to analyze in terms of security rst of all.
7
The nal preparaon step is to nd out the most important vulnerabilies in this plaorm, how common they are, and what versions are the most widespread. All these factors inuence chances of successfully performing a penetraon test. Such analysis will show us if we need to add addional resources to the team such as researchers who will look for 0-day vulnerabilies in the plaorms in case if informaon about those SAP systems is not available (this situaon is rather common when we deal with SAP Pentesng).
► How vulnerable are SAP
platforms?
According to the latest SAP Cybersecurity in Figures report, 3662 vulnerabilies in dierent SAP products were xed in total (as for mid-2016). 548 of them aect Java stack and 2585 ABAP. We have scanned the enre range of IP addresses on the Internet and revealed that an overwhelming number of SAP servers available on the Internet have version 7.3 (7.3 – 626, 7.3 EHP 1 – 851) and 7.4. In other words, we will likely come across these versions while conducng penetraon tesng. tesng. They are more secure and contain no security issues specic to the 7.2 version. Thus, we will need to nd 0-day vulnerabilies. Since the necessity to nd new vulnerabilies is evident, let us look at the most common types of issues patched in SAP NetWeaver Java plaorm (see Chart 1). This informaon as well as other interesng details are available in our latest SAP Cybersecurity Threat report.
7.3 21%
7.2
7.1 EHP1
7.1
1%
6%
1%
7.5 2%
7.4 41%
7.3 EHP1 28%
Chart 1. SAP NetWeaver AS JAVA versions From the Chart 1., it is clear that the most common vulnerability type is XSS, but we rarely exploit them during pentests. Apparently, Apparently, we will need to nd informaon disclosure or conguraon issue to break into the system (see Chart 2)
8
Other 8%
Denial of Service 3% XML external enty 2%
Cross-site scripn scripng g 29%
SQL injecon 2% Verb tampering 4% Directory traversal 5%
Cross-site request forgery 7% Missing Authorizaon 10%
Informaon disclosure 17% Configuraon issues 13%
Chart 2. Vulnerabilities in Java platform Theorecally, such a large number of the vulnerabilies in Java plaorm allows considering that penetraon tesng will pose no diculty. In most cases, it is so indeed. Usually, it does not take much me to break into an SAP system as companies do not even implement patches for 3-year-old vulnerabilies. Not this me, however however.. During our pentest, we faced some dicules and uncommon tasks.
9
Attack Scenario The exploitaon of 3 vulnerabilies enables an aacker to hijack an SAP administr administrator ator account without any access to an SAP system by using the black-box method. A typical pentest involves the following steps: 1. Information gathering 2. Vulnerability exploitation 3. Vulnera Privilegebility escalation 4. Business Risk demonstra demonstration tion
► Information
gathering
Informaon gathering gathering is the basis of every penetraon tesng. Some informaon about a syst system em can be collected without using a single vulnerability. vulnerability. For example, by scanning a network for parcular SAP services or a web server for available web applicaons to understand if there are any applicaons or services with security issues. This step also includes exploitaon of a specic vulnerability type - “Informaon disclosure.” Usually, there is a plethora of these low-risk vulnerabilies detected at the Informaon Gathering stage. What is more dangerous, they are oen le unpatched since administrators have to put all the available resources to cope with more crical issues. However, However, with the help of this vulnerability vulnerability,, an aacker can obtain valuable informaon about the operang system system installed, SAP version, private IP to a user list and user passwords. Although a typical SAP installaon is abundant in Informaon Disclosure vulnerabilies, during our pentesng the system system was so securely sec urely congured that we had to search for 0-days. Eventually,, we found mulple Informaon disclosure vulnerabilies. For instance, using vulnerabilies Eventually ERPSCAN-16-010 and ERPSCAN-16-016 an authencated aacker can get an SAP user's name, surname, privileges, and logins remotely. remotely. An example of vulnerabilies exploitaon is provided below (see Fig. 1.)
10
Fig. 1. Vulnerabi Vulnerability lity exploitation The exploitaon of this vulnerability is quite an easy task. An aacker needs to anonymously open an available webdynpro applicaon uniform resource idener (URI) and press the “Select” buon. Nevertheless, an aacker cannot log into the SAP system with only usernames; passwords for SAP accounts are also required. Here comes the second step of our plan – Vulnerability exploitaon. exploitaon.
► Vulnerability
exploitation
This step is straighorward. straighorward. Aer we gure out which services and web applicaons are available, we can nd out if these services have a vulnerability for us to exploit. As long as the SAP NetWeaver NetWeaver J2EE applicaon server is considered, there are mulple loopholes (from Verb Tampering vulnerability in the CTC web service and Invoker servlet to P4 Authencaon bypass, mulple XXEs, and SSRF issues in K2EE web services) idened years ago. All of them sll exist in almost every SAP Implementaon. Nonetheless, some clients do take care of SAP Security and have eliminated so-called "low-hanging fruits." It is the thing that disnguishes true pentesters from a “script-kiddie” “script-kiddie” or a vulnerability scanner. scanner. Real pentesters tries to nd new vulnerabilies even if there is no obvious way to do it. In doing so, they consider what is needed. Actually, pentesters pentesters already have some informaon about a system – usernames. Therefore, by laying their hands on at least a password hash pentesters ensure their victory.
11
How can they do this? Certain vulnerabilies may give access to it, and they are SQL Injecons. SQL injecons are common for tradional applicaons, but they are a rare occurrence in SAP (see Table 1). This type of vulnerabilies allows aackers to inject their own malicious SQL commands. These command legimate a request and paves the way for accessing crical data stored in a database (e.g., business data, user passwords, and bank account informaon). By using SQL injecons, aackers try to get credit cards dates, user passwords, social cards informaon, etc. Vulnerability type
Place in stascs
global CWE-ID
Place in SANS 25
Place in OWASP TOP 10
XSS
2
CWE-79
2
3
Missing Authorizaon Checks
5
CWE-862
3
7
Directory Traversal 6
CWE-22
10
4
Conguraon Issues
N/A
N/A
5
4
CWE-89
4
1
3
CWE-200
12
8
Disclosure Cross-Site Request 7 Forgery
CWE-352
8
6
Overows (DoS, RCE)
CWE-120
?
N/A
CWE-94
7
1
CWE-308
7
2
SQL Injecons Informaon
1
Conde Injecon Hardcoded Credenals
N/A
Table 1. Comparison of Top 10 SAP Vulnerabilies, World stasc, SANS 25, and OWASP TOP 10 In the scope of our pentest, we detected an anonymous SQL injecon vulnerability in SAP NetWea NetWeaver ver (later it was assigned the ERPSCAN-16-011 idener). It is the SAP UDDI (Universal Descripon, Discovery and Integraon) component, the most widespread one, that contains the vulnerability vulnerability.. Thus, the SAP NetWeaver versions 7.11 – 7.50 are suscepble to the threat. To exploit the vulnerability, an aacker can merely send an HTTP query of the following type: POST /UDDISecurityService/UDDISecurityImplBean HTTP/1.1 Content-Type: Content-Typ e: text/xml 5
x' x' AND 1=(SELECT COUNT(*) FROM BC_UDV3_EL8EM_KEY) BC_UDV3_EL8E M_KEY) or '1'='1
12
The vulnerability is contained in permissionId that can keep any SQL command. When SAP gets this code, it executes it. For example, an SAP server will execute this SQL command and return a count of rows from the BC_UDV3_EL8EM_KEY table. SELECT COUNT(*) FROM BC_UDV3_EL8EM_KEY
thi s vulnerability, By exploing this vulnerabili ty, aackers can obtain the hash of user passwords password s from the UME_STRINGS table. Aer that, they will need to get passwords from the hash. There are two ways to do this: 1. Use bruteforce attack 2. Find another vulnerability in password crypto algorithm
► Privilege escalation Aer exploitaon, we may have access to the system but the access is restricted to parcular acons. In other words, we need to escalate our privileges by using a chain of vulnerabilies. The rst part of the pentest has provided us with some valuable informaon, but it is not enough in our case. We have usernames and password hashes, but sll, do not have passwords. While nishing the project we we came across a vulnerability in the password encrypon funconality in SAP NetWeaver (ERPSCAN-16-003). When a user with a password is created in an SAP syst system, em, the password is secured with encrypon. e ncrypon. The funcon that makes it possible is HashWithIteraons stored in PasswordHash.class. PasswordHash.class. SAP SE has made a mistake during the realizaon of the encrypon algorithm, and as a result, the password is stored in its database as base64 which is not encrypon algorithm but an encoding one.
► Business Risk demonstra demonstration tion The great news is that now we have access to the system even though it may have seemed impossible in the beginning because all the known vulnerabilies were patched. Usually, a tradional pentest pentest ends here. However, However, to make a perfect pentest, it is not enough only to show access – it is also essenal to demonstrate demonstra te business risks. So, we have got an administr administrator ator account on the SAP syst system, em, for example, the one of the Manufacturing vercal. These companies use a wide range of SAP products and can manage technologic processes using the SAP MII module. SAP MII (SAP Manufacturing Integraon and Intelligence) is an applicaon for synchronizing manufacturing operaons with back-oce business processes and standar standardize dize data. Between SAP MII and technologic controllers, there is also SAP PCo. When SAP PCo receives all the control data from SAP MII, it changes the data and sends it to controllers. As we have SAP NetWeaver administrator user, we can get access to SAP MII and manage controllers are responsible for oil producon. Our research team idened several vulnerabilies in SAP xMII . These can be used as part of a mulstage mulstag e aack, starng from one of the numerous business applicaons exposed to the internet with the ulmate aim of geng control over the shop oor oor.. Industry control systems were designed without basic security measures implemented. Once cybercriminals breach a network, they gain unfeered access to all the controllers and their conguraons. Here, the result depends on perpetrators' goals and are limited only by their skills and imaginaon. For example, an aacker can change the melng 13
temperature so that products become more fragile. Another aack vector is a slight modicaon of the temperature instrucon of a welding seam. Both acons can lead to dire consequences if they are made during car producon or high-tech equipment manufacturing.
14
The Scope of the Search Quite oen a tradional approach does not work. If SAP pentesters know only a limited number of SAP vulnerabilies and downloaded free tools from the Internet, they will not be able to hack a system since some companies have installed the latest patches. In other words, it will be impossible to exploit the most common cybersecurity issues (e.g., Gatewa Gatewayy bypass, Verb Tampering, or Default Passwords). Passwords). For example, during one of the assessments, we understood that no exisng exploits worked: worked: all default passwords were changed, and pentetrang into those SAP syst systems ems seemed inconceivable. We will consider the following points which can help to perform a hardcore SAP pentesng: 1. SAP servlets and applications that should be viewed as a matter of priority to find 0-day vulnerabilities; 2. the rights for applications existing in an SAP system; 3. the features of a blind SQL injection in an SAP syst system; em; 4. the options of privilege escalation; 5. the way to execute arbitrary code from the application access level and gain full access to OS.
If there is no public vulnerability, 0-days should be looked for. To search for vulnerabilies in SAP systems, syst ems, it is necessary necessary,, to idenfy the types of apps exisng in an SAP system. There are several types of web applicaons that are installed and run together with the system: • • • • •
servlet; webdynpro; portal apps; service; extensions, core lib's, interfaces, but they will not be taken into account.
In SAP Servlets, apps webdynpro and portal applicaons are installed in the following folder:
C:\usr\sap\%SID%\J00\j2ee\ C:\usr\sap\%S ID%\J00\j2ee\cluster\apps cluster\apps the directory of service applicaons is: C:\usr\sap\%S C:\usr\sap\%SID%\J00\j2ee\ ID%\J00\j2ee\cluster\bin\ cluster\bin\ services; where %SID% is the SID of an SAP system. In our case, the SID is DM0. Each applicaon has privileges that are predened by developers. A user can use an applicaon with these privileges only. By default, SAP NetWeaver AS Java has four types of rights: 1. no safety - an application is available to all users and does not require authorization; 2. low safety - an application is available to authenticated users; 3. medium safety - an application is available to content admin user or admin system; 4. high safety - a medium application is available to content admin user or admin system.
All access rights to the applicaons are described in the webdynpro.xml, web.xml conguraon les, and for portal apps, it is portalapp.xml.
15
As menoned above, we are interested in the applicaons that do not require authencaon. To To nd them, we need to get the list of applicaons using a simple le search. The applicaons that sasfy the search condion are found in a few minutes, and one of them is the component tc~rtc~coll.appl.rtc~wd_chat . Its conguraon le is located by the following address:
C:\usr\sap\%SID%\J00\j2ee\cluster\apps\ C:\usr\sap\%SID%\J00\j2ee\ cluster\apps\sap.com\tc~rtc sap.com\tc~rtc~coll.appl.rt~coll.appl.rtc~wd_chat\servlet_jsp\webd c~wd_chat\ser vlet_jsp\webdynpro\resourc ynpro\resources\sap.com\tc~ es\sap.com\tc~rtc~coll.appl rtc~coll.appl. . rtc~wd_chat\root\WEB-INF\w rtc~wd_chat\r oot\WEB-INF\webdynpro.xml ebdynpro.xml and has the following code (see Fig. 2):
Fig. 2. Cong le code As seen from the descripon, this component has two applicaons that can be called from a browser: Chat and Messages. Accordingly,, the applicaons will be available at the addresses: Accordingly 1. http:/SAP_IP:SA http:/SAP_IP:SAP_PORT/webdynpr P_PORT/webdynpro/resources/s o/resources/sap.com/tc~rtc~coll.appl.rt ap.com/tc~rtc~coll.appl.rtc~wd_chat/Chat# c~wd_chat/Chat# http:/SAP_IP:SAP_PORT/webdynpro/resources/sa /webdynpro/resources/sap.com/tc~rtc~coll.appl.rtc~wd_chat/ p.com/tc~rtc~coll.appl.rtc~wd_chat/ 2. http:/SAP_IP:SAP_PORT Messages#
16
► SAP Information disclosure Let us open the Chat app and see what funconality it has (Fig. 3).
Fig. 3. Chat app funconality Aer following the address, an anonymous servlet with message wring funconality is opened. If we click the "Add parcipant" buon, a window that allows adding users to the Chat will be opened (see Fig. 4).
1 2
3
Fig. 4. Adding parcipant to the Chat If we select a user user,, it will be clear that we can get a list of all users and, consequently, consequently, their logins (see Fig. 5).
17
Fig. 5. Geng the list of users and their logins So, we have found an anonymous service and received the login of an administrator administrator named John. Then all we need is to know its account password. password.
► SAP SQL injection Proceeding with our search for vulnerabilies in anonymous servlets, we come across one funconal component tc~uddi. There are three services in it (see Fig. 6).
Fig. 6. Services in the tc~uddi component The most interesng among them is C:\usr\sap\DM0 C:\usr\sap\DM0\J00\j2ee\clu \J00\j2ee\cluster\apps\sap ster\apps\sap. . com\tc~uddi\servlet_jsp\UD com\tc~uddi\s ervlet_jsp\UDDISecuritySer DISecurityService vice If we open the congura conguraon on le at C:\usr\sap\DM C:\usr\sap\DM0\J00\j2ee\clu 0\J00\j2ee\cluster\apps\sap ster\apps\sap.com\ .com\ tc~uddi\servlet_jsp\UDDISe tc~uddi\servl et_jsp\UDDISecurityService curityService\root\WEB-INF\ \root\WEB-INF\web.xml web.xml we will see the content (see Fig. 7).
18
Fig. 7. The content of UDDISecurityService The "servlet-class" eld indicates that this servlet uses the SOAP methods to transfer and receive data, The name of the servlet is UDDISecurityImplBean. Aertheaddress http://nw74:50000/UDDISecurityService/UDDISecurityImplBean is opened in the browser, browser, the following message is displayed (see Fig. 8):
Fig. 8. Error Report message The UDDISecurityImplBean servlet does not accept GET requests. To understand understand which POST requests to send, it is sucient to add the "?wsdl" key to the URL . Here we got wsdl descripon of the UDDI Security Service (see Fig. 9).
19
Fig. 9. wsdl descripon To convert a wsdl le into soap requests, we can use burp with the wsdler extension (see Fig. 10).
Fig. 10. Operang wsdler extension
20
When an SOAP request is sent to the SAP server and then the deletePermissionById funcon is called with the permissionId parameter, parameter, the server sends a request and responds with the 200 code (see Fig. 11).
Fig. 11. Server requests and response It means that the server has processed the request successfully. successfully. Nevertheless, to understand what logic is built into the program, we need to nd the source code on the server server.. The root directory of the component C:\usr\sap\DM0\J00\j2ee\cluster\apps\sap.com\tc~uddi looks like this (see Fig. 12):
Fig. 12. Root directory of the component The EJBContainer folder oen stores JAR les used in the context of the component. This me, the server has a JAR le with the following path: C:\usr\sap\D C:\usr\sap\DM0\J00\j2ee\c M0\J00\j2ee\cluster\apps\ luster\apps\ sap.com\tc~uddi\EJBContainer\applicationjars\tc~esi~uddi~server~ejb~ejbm.jar To get the source code for Java programs, we can use JD-GUI Decompiler. Once this jar le is opened, the classes that are implemented in this program are displayed (see Fig. 13).
21
Fig. 13. The classes implemented into the program It is quite evident there are the UDDISecurityBean, AppluPermission and DeletePermissionById classes in the program. Let us analyze the UDDISecurityBean class (see Fig. 14).
Fig. 14. The UDDOSecurityBean class
22
Here, it says that the implementaon of the deletePermissionById and applyPermission funcons is described in the PermissionsDao class (see Fig. 15).
Fig. 15. The PermissionsDao class Here is a typical SQL injecon that does not require authencaon for its exploitaon. Let us send our favorite favorit e quotaon mark in the SOAP request and see what we will get in response (see Fig. 16).
Fig. 16. SOAP request and response to it So, there is no error in response, and now we need to see what is in the logs database and what is its last entry (see Fig. 17).
By default, all logs of the SAP program are stored in C:\usr\sap\DM0\J00\j2ee\cluster\ server0\log And a log le of the database is located in: C:\usr\sap\DM0\J00\j2ee\cluster\server0\log\system\ database_00.0.log
23
Fig. 17. Database log Everything is conrmed. Now we have an SQL injecon in SAP NetWeaver AS Java. Thus, to compromise compromise an SAP system, it is necessary to obtain an administr administrator ator password hash or even a password hash of any user from the database. Proceeding with our pentesng, we should answer a simple queson: "Even if we have a password hash, how can we decrypt it?"
► Crypto issue In order to obtain the password using SQL injecon, rst, we need to know which table stores passwords. To connect to the data stored stored in the database, we can apply the standard isql ulity as our database is Sybase ASE. To connect to the database in the console mode, we open a command line window and run the following commands:
Fig. 18. Connecng to the database
24
Here, we have SAP server with DM0 SID. We will use the DM0 database (see Fig. 19).
Fig. 19. DM0 database According to the SAP documentaon, SAP AS Java user passwords are stored in the User Management Engine (UME) in the UME_STRINGS table. There are two main elds in the UME_STRINGS table: PID and VAL. The PID eld keeps the Administrator ID, and VAL stores the password in an encrypted form with SHA as a prex. The request is as follows: SELECT PID, VAL FROM SAPSR3DB.UME_STRINGS WHERE PID LIKE '%Administrator%' and VAL LIKE '%SHA%' Here is the result of the program operaon (see Fig. 20):
Fig. 20. The result of the program operaon PID is UACC.PRIVATE_DATASOURCE.un:Administrator VAL is {SHA-512, 10000, 24}MTIzUVdFYXNk88FxuYamodVV2ycvIqBU80lPPUD8twAOhZ/ AUSezf4Reou4uFpqth9lDpefHZ1JOuzfILlHY AUSezf4Reou4uFpqt h9lDpefHZ1JOuzfILlHYQv4LhheyzoQMAng5pOkvHz5bZXJ+SGps Qv4LhheyzoQMAng5pOkvHz5bZXJ+SGpsyrju3UtBkmRQ== yrju3UtBkmRQ== It is evident enough that the SHA-512 hash is used which is calculated 10.000 mes. One may say it hinder those who tries to bruteforce the hash, but not in this case. This is what we got by decoding base64 (see Fig. 21).
25
Fig. 21. Decoding base64 It turns out that SAP made a mistake and the password is stored insecurely in base64. However, how could it fail to noce this error in such a crical place? Aer a couple of hours of researching, we have nally idened the funcon responsible for the encrypon and password storage. This JAR le encrypts and checks the password validity:
C:\usr\sap\DM0\J00\j2ee\cluster\bin\ext\com.sap.security.core.sda\ lib\private\sap.com~tc~sec lib\private\s ap.com~tc~sec~ume~core~imp ~ume~core~impl.jar l.jar To nd the necessary nec essary class in this le, it is enough to look for magic data, "SHA-512", in JD-GUI (see FIg. 22).
Fig. 22. SHA-512 in JD-GUI Done. PasswordHash.class PasswordHash.class is found. In the class, there is exactly what we need (see Fig. 23).
26
26
Fig. 23. The Passwor PasswordHash dHash class is found The main funcon of the class may come in handy to understand understand how the hash funcon works (see Fig. 24).
Fig. 24. The Hash funcon in opearaon First of all, it is the inializaon of the PasswordHash class (see Fig. 25)
Fig. 25. The inializaon of the PasswordHash PasswordHash class
27
Aer that, the getHash(); funcon is called (see Fig. 26).
Fig. 26. Calling the getHash(); funcon The lines from 87 to 113 show the variables are currently being checked and inializing, and the line 114 indicates a call of the createHashWithIteraons funcon that takes a data set of 24-character length. To demonstrate this feature, feature, we will write a wrapper for it in the debugger and see which data is sent. Below, is the full code of the class that is responsible for hashing the password in SAP. Let us run it and see how it works (see Fig. 27).
28
Fig. 27. The code of the class in operaon We chose the asdQWE123 combinaon as a password. It is worth menoning that the inializaon of two special parameters carries out in the createHashWithIteracons funcon. They are "output" and "pass_n_salt" transferred to the nal hash funcon - hashWithIteracons (see Fig. 28).
29
Fig. 28. output and pass_n_salt in operaon More details on the hashWithIteracons funcon are provided below (see Fig. 29)
Fig. 29. The hashWithIteracons funcon All the work the key has performed related to hashing is presented in the lines 40-45. The block diagram illustrates illustra tes the work of these lines (see Fig. 30). NO
YES i
View more...
Comments