SEC261
SEC261
SEC261
Public
Speakers
The information in this presentation is confidential and proprietary to SAP and may not be disclosed without the permission of
SAP. Except for your obligation to protect confidential information, this presentation is not subject to your license agreement or
any other service or subscription agreement with SAP. SAP has no obligation to pursue any course of business outlined in this
presentation or any related document, or to develop or release any functionality mentioned therein.
This presentation, or any related document and SAP's strategy and possible future developments, products and or platforms
directions and functionality are all subject to change and may be changed by SAP at any time for any reason without notice.
The information in this presentation is not a commitment, promise or legal obligation to deliver any material, code or functionality.
This presentation is provided without a warranty of any kind, either express or implied, including but not limited to, the implied
warranties of merchantability, fitness for a particular purpose, or non-infringement. This presentation is for informational
purposes and may not be incorporated into a contract. SAP assumes no responsibility for errors or omissions in this
presentation, except if such damages were caused by SAPs intentional or gross negligence.
All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially
from expectations. Readers are cautioned not to place undue reliance on these forward-looking statements, which speak only
as of their dates, and they should not be relied upon in making purchasing decisions.
Introduction
Why is security a topic?
SAP NetWeaver Application Server, add-on for code vulnerability analysis
Toolset for application protection
Demo
Secure programming
Command injection
Directory traversal
XSS and XSRF
Recommendations
Public
Current software security vulnerability situation
The problem:
Each new technology brings with it the risk of new vulnerabilities.
Firewalls, intrusion detection systems, signatures and encryption alone cannot make
an application secure.
Automated Source
Automated Application
Code Analysis
Vulnerability Scanning
DAST SAST
Dynamic Application Security Testing Static Application Security Testing
Public
SAP security and GRC access governance portfolio
3rd Party
Systems Make sure that SAP SAP HANA Cloud SAP NetWeaver
Platform SAP HANA
solutions run securely Platform Application Server
Security
R R
ABAP Workbench
Code Inspector
Checks
ABAP Source
Code R
SLIN Security
Checks
What is it?
ATC is an ABAP check framework which allows running static checks and unit tests for
ABAP programs
ATC is fully integrated into the development environment and transport tools, along with
instant navigation, documentation and fix recommendation
ATC is the single point of entry for all static code check tools
ATC is fully integrated in the ABAP development workbench with a high usability for
developers and quality experts
ATC is not only a check tool but supports essential QA techniques like
Q-Gates or regression testing in a consolidation system
2016 SAP SE or an SAP affiliate company. All rights reserved. Public 13
Example: What does SAP NetWeaver AS, add-on for code
vulnerability analysis show within the ABAP Test Cockpit?
Plus a
detailed
explanation
about the
reason for
the finding
and
suggestions
how to fix the
problem
ABAP Test Cockpit and SAP NetWeaver Application Server, add-on for code vulnerability analysis
Public
SAP NetWeaver Application Server, add-on for code
vulnerability analysis
CVA ABAP
Stub
ATC Repository
Configuration of checks and administration of check runs takes place in the central check system
The stub can be installed through SAP note. No upgrade, no SP prerequisite in analyzed systems (planned)
Recommendation: Use the central check system for CVA only
No dependencies to other software components
You can easily implement support packages and upgrades
Easy consumption of new or enhanced security checks
Remote scenario
Public
Toolset for application protection
QUOTE( )
QUOTE_STR( )
ESCAPE_QUOTES( )
ESCAPE_QUOTES_STR( )
Note: The pure escaping (last two boxes) can also be achieved through the REPLACE statement.
2016 SAP SE or an SAP affiliate company. All rights reserved. Public 23
Sanitization by class CL_ABAP_DYN_PRG
Escaping methods for Web techniques (cross-site scripting, XSS)
ESCAPE_XSS_XML_HTML( )
ESCAPE_XSS_JAVASCRIPT( )
ESCAPE_XSS_CSS( )
ESCAPE_XSS_URL( )
Note: XSS escaping can also be achieved through the built-in function ESCAPE (SAP_BASIS >= 7.31).
2016 SAP SE or an SAP affiliate company. All rights reserved. Public 24
Sanitization by class CL_ABAP_DYN_PRG
Hints
Please use the following pattern when using check methods of CL_ABAP_DYN_PRG:
Use the returned value to proceed. This ensures that an invalid input cannot be used in a meaningful way.
Public
Operating system command injection
What is an OS command injection?
Context
Software invokes OS commands
Part of the OS command invocation contains external, user-provided input, e.g. dir user input
Attack / entry point
Attacker supplies malicious data in order to call:
Other, unintended OS commands (OS command injection)
The same command with manipulated parameters (OS command manipulation)
Typically aims at command chaining, i.e. the use of special OS-specific characters to execute additional
commands right after the execution of the intended command, e.g. dir foobar | format c:
Potential result
Injection and execution of unexpected, dangerous commands directly on the operating system (e.g., to
allow OS remote logons, change authorizations or configurations, etc.)
SAPXPG mechanism
Can be used to call OS commands on the application server
Enables customers to adapt commands to their needs
Abstracts differences between operating systems
Allows customers to define check modules per OS command, e.g., to implement a character whitelist
Comes with an authorization check
ADDITIONAL_PARAMETERS = userinput
FUNCTION SXPG_DUMMY_COMMAND_CHECK.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(PROGRAMNAME) LIKE SXPGCOLIST-OPCOMMAND
*" VALUE(PARAMETERS) LIKE SXPGCOLIST-PARAMETERS
*" VALUE(LONG_PARAMS) TYPE CHAR1024 OPTIONAL
*" EXCEPTIONS
*" NO_PERMISSION
*"----------------------------------------------------------------------
RAISE NO_PERMISSION.
ENDFUNCTION.
Public
Secure programming:
Directory traversal
Public
Directory traversal attack
What is the risk?
Directory traversal attacks ( also called path traversal attacks ) try to abuse insufficient sanitization and
validation when taking user input as (part of) file names.
Usual countermeasures include using FILE_GET_NAME to safely construct the file name and
FILE_VALIDATE_NAME to verify the file name.
The best approach is to not allow the user to define a file name but let the administrator decide. They
know their system best! If the user needs to be able to specify a complete file name including the path,
you need to make sure that the file ends up somewhere where it is supposed to be:
Use the function module FILE_GET_NAME to retrieve the definition from the administrator.
In case it is required to request the file name from the user validate the file name using the function
module FILE_VALIDATE_NAME.
Do not try to only rely on authorizations! You can circumvent these in some cases.
Retrieving a file name with FILE_GET_NAME without validation can enable the user to control
the file name!
The transaction FILE is being used to define properties related to file system operations when
using functions like FILE_GET_NAME and FILE_GET_NAME_AND_VALIDATE.
Logical paths allow to create platform independent path definitions. This is achieved as one
physical path per platform can be mapped to a logical path.
A logical path can be used in the definitions of logical file names to enable programs to retrieve
physical file names valid for the operating system, the application server is running on. The
definition contains:
The name to refer to the logical path
A description
One directory definition per syntax group
Logical file names are patterns defined in transaction FILE. These patterns are used to create
or verify file names for file system access. The definition of a logical file name includes
information about
The name to refer to the logical file name in the coding
The pattern for the file name
Optional: Data format (ASCII, Binary, Directory, ) for the file
Optional: Application area
Optional: Logical path required for validation!
File name patterns may include predefined patterns like date, time, OS or patterns based on
profile parameters and more.
2016 SAP SE or an SAP affiliate company. All rights reserved. Public 41
Directory traversal attack
Constructing the file name I
FILE_GET_NAME will take the information from the logical path, append the contents from the
logical file name and replace variable values by their actuals:
Result: D:\Files\orders-out\AMER\Exton_20161013-122409.txt
FILE_GET_NAME will take the information from the logical path, append the contents from the
logical file name and replace variable values by their actuals:
Result: D:\Files\orders-in\EMEA\Exton_20161013-122409.txt
However it will NOT validate the input!
2016 SAP SE or an SAP affiliate company. All rights reserved. Public 43
Directory traversal attack
How to use FILE_GET_NAME_AND_VALIDATE to retrieve file names
Public
Secure programming:
XSS and XSRF
Public
XSS Cross-site scripting
Introduction
Context: Web applications accept user input, which is used to create dynamic content in HTML pages
Weakness(es)
Insufficient input validation
Missing output filtering or encoding, when writing user input to HTML pages
Potential results
Stealing access credentials, DoS, Web page modifications, executing commands on the attacked users system
Types of XSS:
1. Reflected (the most common type): The server receives input data and uses it to build a result HTML page for the same
user, without properly sanitizing the input
2. Persistent: Input data from a given user is persisted by a server, and is included later in HTML pages returned to other
users, again without proper data sanitization
2016 SAP SE or an SAP affiliate company. All rights reserved. Public 47
XSS Cross-site scripting
Reflected XSS
Problem
Web applications accept user input, which is displayed on subsequent HTML pages (either immediately or some time after)
If user input is not parsed, malicious JavaScript can be injected into HTML pages (which are a mix of data and code)
Example
The search page echoes the search
string on the result page
1. Attacker sends malicious code as part of message GET Money for FREE !!!
<script> attack code </script>
Public
XSS Cross-site scripting
Countermeasures
General idea
Prevent the injection of executable code in the web page, i.e., address the problem that HTML pages
are a mixture of code and data
Find a harmless representation of user input
In BSP extensions (HTMLB, XHTMLB and PHTMLB), you may also use specific encode attribute
forceEncode on the HTMLB content-tag
Limitation: Protects HTMLB tags only
Set the attribute forceEncode to ENABLED
Result
Victim executes an action on behalf of the attacker, using an already authenticated session
Simply visiting a URL may have bad consequences
Public
XSRF Cross-site request forgery
Countermeasures
General idea
Ensure that URLs (requests) are not guessable by the attacker by including a random element (token)
in the request
However, an attacker can always trick users into starting an application
Recommendations
Applications must use the available anti-XSRF mechanism
For ABAP, in general, no manual efforts are required on code level
Mechanism can be enabled via checkbox in BSP/ITS
Mechanism is automatically used in WebDynpro ABAP
Developers must avoid sensitive actions (= state changes) at application start and in all automatically
reachable pages (= pages reachable without user interaction)
All other pages are protected by the anti-XSRF mechanism
Validate input
The entire (!) HTTP request must be considered as input, including HTTP headers, cookies, web forms
Client-side checks cannot be trusted; always (!) re-do the check on the server side
Follow advice given in the section on injection attacks (whitelist vs. blacklist, etc.)
Encode output
User input must not become executable; use the existing mechanisms for output encoding
Public
Recommendations
Public
Recommendations
SQL Injection
(Open SQL)
Directory
Call Injection
Traversal
OS Command
Injection
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://www.sap.com/corporate-en/about/legal/copyright/index.html for additional trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.