A few months passed since my last post – so it's about time for new one! 💡
User name as a code condition
The system field SY-UNAME contains the name of the currently logged-on user and is quite frequently used by developers to facilitate tests by adding special conditions to their code. The block of code that is executed depending on the current user's name is usually only intended for the developer him-/herself.
Although developer guidelines almost always include the obligation to make use of AUTHORITY-CHECKs, these checks might interfere with functional tests – and people might want to circumvent them (just for the tests, of course). No matter what the intention was, this approach leads to programs that do authorization checks for all users – except for the developer of the code... bad thing!
The following code snippet is probably one of the most prominent examples:
IF sy-uname <> 'DEVELOPER'. AUTHORITY-CHECK ... ENDIF.
Right after the successful test phase, the code is transported to production and the conditional code might never be made universal...
If we consider malicious behavior, such code is called a backdoor and/or hidden function and this means that there is a need for action (at least to protect your developer colleagues)!
How to detect it
To find affected code, the SAP standard report RS_ABAP_SOURCE_SCAN is of great help — you can use it to search for plain strings or expressions in reports, classes, etc.
Since we're interested in IF conditions that check the value of SY-UNAME, I'd suggest to search using "IF .*sy-uname" as the expression and tick the checkbox "String is standard expression".
In the sample below, I limited the code to search in to programs with name Z*, but you might probably want to adjust this according to your needs (e.g. your registered namespaces).
The result shows two different conditions that use SY-UNAME in a possibly evil way:
The search expression above is rather straight forward...
Unfortunately, it can be tricked easily by a developer, who knows it:
DATA: foobar TYPE syuname. foobar = sy-uname. * Obfuscated condition IF foobar <> 'MYSELF'. AUTHORITY-CHECK ... ENDIF.
So – when you establish controls to prevent the usage of user-based conditions, this is something to keep in mind.
Humans are usually better at detecting fuzzy patterns that computers are... 😎
Code that is bypassed based on the value of SY-UNAME should never be used!
➡ All instances of hard-coded user names in customer code used on productive systems should be corrected.
➡ Controls should be established to prevent such code from being transported.
You might want to integrate the use of the SAP code inspector into your transport process.
After a relaxing summer holiday, it's time to fulfill the promise I made in my last post and provide the evaluation report for our log of RFC calls.
If you don't know what I'm talking about, please read the first part of this article.
This report basically parses the RFC log and shows the function groups that would've been required to execute the called modules.
In addition, it finds out, whether the respective users currently have the required S_RFC authorization — therefore, it allows you to focus on those entries, where the authorization is missing.
- Create a new program in SE38 and copy-paste this source code.
- Set a program authorization group in the attributes section.
- Activate the program & execute it.
The selection screen should be rather self-explanatory:
There is only one noteworthy feature: the "Client" field is pre-filled with all clients, for which no RFC connection could be determined automatically. The report checks the logical systems for all local SAP clients and tries to reach them via the assigned RFC connection (that should normally work in a well-configured system :wink:). If this attempt fails, the respective client is excluded from the evaluation. Just log on to the excluded client(s) and run the report locally – this will always work!
The screenshot below shows an exemplary result. All lines with function groups, for which authorizations exist, are hidden per default; to unhide them, just remove the filter (marked in red below).
The icons in the "Auth. check" column have the following meaning:
» User has the required authorization — filtered out per default
» S_RFC authorization is missing — this is what we're interested in
» User is locked
» User does not currently exist
In this article, I'll show you a handy way of identifying the S_RFC authorizations your users need; this method helped me a lot recently.
Generally, you might be interested in this topic, because…
- … you were asked to raise the value of profile parameter
auth/rfc_authority_check from zero to a greater value
- … you need a practical approach to improve your S_RFC authorizations
- … you updated your SAP kernel to a patch level ≥ 7.20-400
or ≥ 7.21-041 (see SAP Note 1785761)
The authorization object S_RFC consists of three fields, but only one of them is of interest for us: RFC_NAME – which is checked against the called function module's group (the other two fields have only one possible value each, so we'll ignore them here).
I opted for a heuristic approach to determine values for that field… so first we'll collect a list of function module calls that occur on a productive system. In part 2 of this series, we'll use that list to determine the affected function groups and derive the required S_RFC values from that.
Unfortunately, this approach assumes that all required RFC calls succeed – so during the analysis phase, S_RFC authorizations have to be (or stay?) oversized to ensure no authorization problems distort the result. I'll leave it to you, how you deal with that…, but you might want to think about setting the profile parameter auth/rfc_authority_check to zero… Danger, Will Robinson! → this has security implementations! 😕
Obtaining a list of called function modules per user is possible in various ways:
- the Security Audit Log (tcode SM19/20 » audit class "RFC call")
- the Business Transaction Analysis (tcode STAD)
- … if you have another good idea, please leave a comment …
Using the Security Audit Log would imply some nasty problems: the log size per day is limited (parameters rsau/max_diskspace/*); all logs generated after that limitation is reached are lost.
The functionality of tcode STAD on the contrary quite exactly matches what we need. Furthermore, there is no need to configure anything, as the statistics are recorded anyway (in fact the profile parameter stat/level has to be set to 1… but that's the system default). The structure which is used to record the statistics contains a field that holds the called function modules — so another benefit of the latter method is that we don't have to split a text string (like the one stored in an Audit Log message text, e.g. "Successful RFC Call RFCPING (Function Group = SYST)").
I chose the second solution — evaluating statistics from STAD —, because it seems to be smarter, more reliable… and gives me the opportunity to code a bit! 😉
The next step is to create a new report called ZS_STAD_EXTRACT_RFC_CALLS and copy-paste this source code.
Then you need to set up two new customer tables that hold the data we want to collect.
Go to SE11 and create the tables ZSSTAD_RFC_DATA and ZSSTAD_LASTRUN.
I'd suggest using the following settings in the subsequent steps:
- Delivery class "A" = application table,
- Data class "APPL1" = transaction data, transparent tables (in: Technical settings),
- Size category "0" = up to 100.000 entries (in: Technical settings) and
- Enhancement category "Can be enhanced (deep)" (menu: Extras → Enhancement category)
The field definitions can be found in the top comment of the report source code; use them as shown below:
Then please repeat these steps for the second table.
Last but not least you should schedule the report to run every hour — that's a good value because the runtime of the report stays rather short and there's no danger of losing data (the retention period for STAD data is usually 48 hours, because the statistics files are written every hour and the parameter stat/max_files determines the number of files kept – 48 per default).
You also might want to increase the profile parameter stat/rfcrec, which determines the maximum number of RFC calls in a session that will be recorded in STAD. The default value of 5 is probably not sufficient for all cases!
Please check SAP Note 1964997 for information on the parameters stat/rfc/distinct and stat/rfc/distinct_depth, which are also relevant. Thanks to Christian Wippermann for pointing me to this!
So what does it do?
The report reads all statistics records since the time it was last started (which is saved in table ZSSTAD_LASTRUN) or — if that table contains no values — the ones since one hour ago. The records are filtered for RFC calls (all other record types are discarded) and the called function modules' groups are determined.
As the last step, this information is saved to table ZSSTAD_RFC_DATA.
- the date (DATUM),
- SAP client (MANDT),
- calling user (UNAME),
- called function module (FUMOD),
- the respective function group (FUGRP) and
- the number of calls (NCALL) per line.
In the below example, the user SAPJSF called RFCPING 22 times on the 4th of May 2013 in client 000:
The information in this table will later be used to determine the values for S_RFC.
In part 2 of this series, I'll post a nice evaluation report for the above log…
See you then!
In my article about Sniffing SAP GUI passwords in Nov. 2012, I took a look at several state-of-the-art sniffing tools for capturing SAP GUI passwords.
One of those tools was a Wireshark plugin by Martin Gallo of CoreLabs — unfortunately it refused to compile over and over again, which is why I never tested it… but meanwhile Martin released an improved version.
Fortunately, I took the time to try it, because it turned out to be a real gem — a bit hard to obtain, but pretty useful once you got it. 😉
The nice part: Usage
In contrast to the other Wireshark plugin by Positive Research, this one does not only decompress, but also dissect almost all parts of the traffic and shows the respective fields and values (below you can see a DDIC login with the password in plain text).
Another invaluable advantage is of course its availability as source code!
The nasty part: Compilation
The following script does the trick, although you'll probably want to adjust it to the build environment, the Wireshark version and your needs…
(It assumes to be run from the directory, where the plugin tarball is located.)
#!/bin/bash -ex rm -rf wireshark svn co http://anonsvn.wireshark.org/wireshark/trunk wireshark mkdir wireshark/plugins/sap tar -C wireshark/plugins/sap -xzf sap-wireshark-plugin-0.1.3.tar.gz cd wireshark ./autogen.sh patch -p0 < plugins/sap/wireshark.patch test -x /usr/bin/python2 && export PYTHON=/usr/bin/python2 ./configure --prefix="$PWD" --disable-warnings-as-errors make make install bin/wireshark
See you soon!
This time I'd like to present a hot new SAP feature to you: Security policies!
( Available starting from ERP 6.0 EHP6. )
The system behavior regarding password rules and logon restrictions is controlled by profile parameters, e.g. "login/min_password_lng" for the minimum password length. These parameters are valid system-wide and could not be overridden by any means.
With the new security policies, it is now possible to define different sets of password rules, password change policies and logon restrictions and assign these policies to users.
This provides the flexibility to segregate users and assign an appropriate policy to each of those groups of users!
For instance, you can enforce strict rules on the global level (= profile parameters) and loosen them on user level via a security policy (e.g. increased validity period of unused initial password for users, who use SAP less frequently).
For users with a security policy assignment, the attributes defined therein
override replace the profile parameters – for users without a SecPol the parameters stay relevant.
The administration of security policies can be performed via the new tcode SECPOL, which is secured by two brand-new authorization objects: S_SECPOL is checked during the maintenance of the policies themselves, while S_SECPOL_A is used to define the values that may be assigned to the security policy attributes.
First of all, let's create a new policy:
… then mark it and switch to the attribute maintenance screen by double-clicking on "Attributes".
The following attributes are available:
|Password rules||CHECK_PASSWORD_BLACKLIST||( none )||Check the password blacklist|
|MIN_PASSWORD_DIGITS||login/min_password_digits||Minimum number of digits|
|MIN_PASSWORD_LENGTH||login/min_password_lng||Minimum password length|
|MIN_PASSWORD_LETTERS||login/min_password_letters||Minimum number of letters|
|MIN_PASSWORD_LOWERCASE||login/min_password_lowercase||Minimum number of lowercase letters|
|MIN_PASSWORD_SPECIALS||login/min_password_specials||Minimum number of special characters|
|MIN_PASSWORD_UPPERCASE||login/min_password_uppercase||Minimum number of uppercase letters|
|MIN_PASSWORD_CHANGE_WAITTIME||login/password_change_waittime||Minimum wait time for password change|
|MIN_PASSWORD_DIFFERENCE||login/min_password_diff||No. of different characters when changing|
|PASSWORD_CHANGE_FOR_SSO||login/password_change_for_SSO||Password change requirement for SSO logons|
|PASSWORD_CHANGE_INTERVAL||login/password_expiration_time||Interval for regular password changes|
|PASSWORD_COMPLIANCE_TO_CURRENT_POLICY||login/password_compliance_to_current_policy||Password change after rule tightening|
|PASSWORD_HISTORY_SIZE||login/password_history_size||Size of the password history|
|Disable password logon|
|DISABLE_TICKET_LOGON||( none )||Disable ticket logon|
|MAX_FAILED_PASSWORD_LOGON_ATTEMPTS||login/fails_to_user_lock||Maximum number of failed attempts|
|MAX_PASSWORD_IDLE_INITIAL||login/password_max_idle_initial||Validity of unused initial passwords|
|MAX_PASSWORD_IDLE_PRODUCTIVE||login/password_max_idle_productive||Validity of unused productive passwords|
|PASSWORD_LOCK_EXPIRATION||login/failed_user_auto_unlock||Automatic expiration of password lock|
The button "Effective…" shows the relation of the policy values to the default ones (=, ≠ or not set), while the "Superfluous Entries" button identifies unnecessary entries (i.e. identical to the default ones).
To assign the newly created security policy, just edit a user in SU01, switch to the "Logon Data" tab and enter the SecPol name in the "Security Policy" field:
Mass-assignments via SU10 are of course possible, too!
To be able to assign a SecPol, you'll need the authorization object "S_SECPOL", which behaves similar to S_USER_AGR – i.e. activity 22 (assign) and the policy's name are checked.
If you want to select users by their security policy assignment, you can simply use the User Information System:
SUIM » User » by Logon Date and Password Change
Central user administration
The security policy ↔ user assignment is supported by the CUA and its distribution can be configured via SCUM as usual.
See you next time!