home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack1 / phrack25.005 < prev    next >
Encoding:
Text File  |  2003-06-11  |  14.1 KB  |  315 lines

  1.  
  2.  
  3.                                 ==Phrack Inc.==
  4.  
  5.                      Volume Three, Issue 25, File 5 of 11
  6.  
  7.        <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  8.         <><><><>                                            <><><><>
  9.         <><><>                Unix Cracking Tips              <><><>
  10.         <><>                                                    <><>
  11.         <>                     by Dark OverLord                   <>
  12.         <><>                                                    <><>
  13.         <><><>                  March 17, 1989                <><><>
  14.         <><><><>                                            <><><><>
  15.        <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  16.  
  17.  
  18. The purpose of this file is to present tips for budding Unix hackers.  The
  19. audience this is aimed at are those that are experienced at working with basic
  20. Unix, but not in the cracking aspects.
  21.  
  22. Most of the following material is based on actual experience with BSD boxes
  23. (with some help from my friends).  Many of the bugs here may not apply to your
  24. system; your mileage will vary.
  25.  
  26.  
  27. When Cracking A System Remember --
  28.  
  29.      o ALWAYS cover your tracks
  30.      o Don't get caught
  31.      o Don't get malicious
  32.      o Get off as soon as possible
  33.      o Keep a bottle of "Wild Turkey" near the terminal
  34. (IMPORTANT!)
  35.  
  36.  
  37. About Logging:  Remember that many systems use paper terminals so that if a
  38. warning message goes to the console, you can't erase it.
  39.  
  40. Hint:  If you know that you are going to be ringing a few bells, you may wish
  41.        to send a bunch of bogus messages to the console so it runs out of paper
  42.        before the important messages get there.
  43.  
  44.  
  45. After you gain superuser privileges and you wish to stay root, here are
  46. a few suggestions for installing backdoors:
  47.  
  48. - Disable checks for superuser in the kernel
  49. - Install new system calls
  50. - Patch a system binary to contain a backdoor
  51. - Leave /dev/mem readable
  52.  
  53.  
  54. An ancient method of extracting data from anything is to sort through its
  55. trash.  The same applies to Unix and newly allocated data.
  56. One trick is to look for old data in newly allocated data (eg: Allocate a
  57. large amount of memory and search through it for old [useful?] data).  Given
  58. enough time and an intelligent search algorithms, you could find quite a bit of
  59. information including people's passwords and other private stuff like
  60. mail, et al.
  61.  
  62.  
  63. If the device "/dev/kmem" is readable, you should be able to write a quick C
  64. program that intercepts the I/O to other terminals and catch other people's
  65. password etc.
  66.  
  67. If the device "/dev/kmem" is writeable, it is possible to change your userid by
  68. editing the user structure.
  69.  
  70.  
  71. A Common Trick:  When looking to gain more system privileges, one of the first
  72. things to investigate are other users' .rhost files since these can be used to
  73. grant access to other accounts without the use of a password.  See the Unix
  74. manual entry for rlogin for more information.
  75.  
  76.  
  77. Another thing to look for are writeable .profile, .cshrc or .logins (to name a
  78. few).  It these are left writeable, it is all too easy to install a Trojan
  79. horse.
  80.  
  81.  
  82. Look for readable .netrc files since these files may contain passwords to other
  83. accounts.
  84.  
  85.  
  86. If the man command is setuid, it might be possible to get a shell by typing
  87. "!/bin/csh" from within the pager.
  88.  
  89.  
  90. Some types of terminals can be "instructed" to issue commands using various
  91. escape sequences.  This makes it possible to mail someone a "letter bomb" that
  92. (when read) will send commands to the user's shell.
  93.  
  94.  
  95. It is possible to mail commands to a system.  This is a feature of the
  96. debugging mode of Unix's sendmail.  This trick was made fairly public through
  97. its use by the Internet Worm.  The way it is done is by connecting to the SMTP
  98. socket/port and turning on the debug mode.  The recipient that is mailed to is
  99. "| sed '1,/$/d' | /bin/sh ; exit 0" and then the commands for the shell are
  100. placed in the body of the letter/data section.
  101.  
  102.  
  103. Under Unix it is trivial to forge mail.  The easiest way this is done is by
  104. connecting to the SMTP port and pretending to be a foreign mailer program.
  105.  
  106.  
  107. Some systems will crash if you issue the command "eval `\!\!`" from within the
  108. C shell (/bin/csh).
  109.  
  110.  
  111. When searching for data, do not forget to look for possible un-mounted file
  112. systems.  [eg:  Look for disk partitions that are unaccounted for.]
  113.  
  114.  
  115. Other things to try are illegal system calls and system calls with
  116. illegal (strange?) arguments.  A good example is the fchown system call
  117. under 4.3-Tahoe Release from Berkeley.  If you give it a negative
  118. number for the group argument it grants permission for you to change
  119. the ownership of any file.  Another example (on many systems) is the
  120. "access" system call used by many, many programs.  Its problem is that
  121. is only checks permissions on the requested file and neglects to check
  122. the permissions of links and directories that lead to the file.  I have
  123. seen some systems that allow any user to use the chroot system call;
  124. this is VERY foolish since all I have to do in construct my own
  125. sub-environment (with my own configuration files) and execute certain
  126. commands from within it.
  127.  
  128.  
  129. Yet another thing to look for are system structures stored in user accessible
  130. memory.  These structures can be modified to suit your purposes.
  131.  
  132.  
  133. Look for sloppy permission/ownership on system directories and on system
  134. configuration files.  These can allow you to modify and/or control many aspects
  135. of system behavior.  Here are a few files to look out for:
  136. "/etc/rc",
  137. "/etc/passwd", "/etc/group", "/etc/profile",
  138. "/usr/lib/crontab" or
  139. "/usr/spool/cron/crontabs/*".
  140.  
  141. Hint:  AT&T 3b1 systems are notorious for this problem.
  142.  
  143.  
  144. If the system you are hacking has readable system logfiles and it logs failed
  145. login attempts, a possible leak might be if a user had accidentally typed their
  146. password at the login prompt.  You should scan through these logs looking to
  147. strange and nonexistent account names and use these as the password for users
  148. that logged in around that time (the command "last" will list the login time of
  149. users).
  150.  
  151.  
  152. Check to see if the system has source code on-line.  There is nothing more
  153. useful then having system source code on-line for browsing.
  154. Look for source code (normally found in the directory /usr/src) and scan it
  155. for programming errors (or download it so you spend less time on the
  156. system).
  157.  
  158.  
  159. Look for other people's back doors.  If you can find any, they can make your
  160. life a bit easier.
  161.  
  162.  
  163. Check to see if the system has a good auditing system.  If so, run it since it
  164. may find a few security problems for you.
  165.  
  166.  
  167. Look for setuid shell scripts that may be on the system.  There is no
  168. way way to secure a setuid shell script under the current release of
  169. BSDish Unixes in the current market.  The command "find / -perm -6000 -ls"
  170. will print out all setuid and setgid files on a system.  Look
  171. through this list for setuid shell scripts.  One way in defeating a
  172. setuid script is to make a link named "-i" to the file, then execute
  173. the link.  Another way is to send it a signal at the right moment
  174. during its start up.  The simplest way do this is to write a quick C program tha
  175.    t sets a block on the signal, then sends
  176. itself the signal, and then execs a setuid script. (Note: The signal
  177. will not be processed because of the block, thus leaving it for the
  178. setuid script).   Either of these bugs should give you an interactive
  179. shell running as the userid of the setuid script.
  180.  
  181.  
  182. If you are familiar with programming with assemblers/dissemblers, you can look
  183. for bugs and/or modify existing software to suit your needs since most
  184. installations do not strip debugging symbols from system binaries and leave the
  185. executables readable.  There is an enormous amount of hacking information that
  186. can be learned this way.
  187.  
  188.  
  189. Under UNIX-V7 & 4.1BSD, programs that were setgid were only a security problem
  190. because if you were able to get them to dump a core file, the core would be
  191. owned by you and setgid to the groupid of the program that generated it.  Since
  192. you owned this file, you could copy a shell of a command script into it and
  193. have it run as the groupid of the file.  This will allow you access to to any
  194. file that is owned by the group.
  195.  
  196.  
  197. If the system you are hacking supports bidirectional modems, it is possible to
  198. use them for stealing passwords.  This can be done by using tip to connect to
  199. the modem and then waiting for a user to call.  When a user calls in, you
  200. simply answer the phone and simulate the login process.  Once the user has
  201. surrendered their password, you simulate line noise and hang up.
  202.  
  203.  
  204. The Unix login program (the program that prompts you for the account name and
  205. password) is tricky in the way that the error message for bad accounts and bad
  206. passwords are the same.  This is to stop account/password guessing.  I guess it
  207. works if your only access to a system is either a terminal line or a modem
  208. connection.  If you have access through a LAN you can check account names with
  209. the finger command.  This neat little Unix goodie will give you all sorts of
  210. information about people's accounts.  If the finger utility is turned off,
  211. there is another way through a program called ftp.  The ftp (File Transfer
  212. Program) command can be used to confirm the existence of a user account/bad
  213. password selection.  I have also noted that the ftp command does not do as much
  214. logging, thus repeated bad password guesses not logged as much via ftp.
  215. [See next section also.]
  216.  
  217.  
  218. If the Unix system you wish to crack is networked via UUCP or TCP/IP, it should
  219. be fairly simple to extract the password file from the remote system using the
  220. ftp utility.  Once you have a copy of the password file, you can simply back
  221. away from the system (thus reducing the chances of getting caught!).
  222.  
  223.  
  224. See Phrack Inc. Issue 22, File 6 -- "Yet Another File On Hacking Unix by
  225. >Unknown User<" for a slow but effective password grinder.
  226.  
  227.  
  228. Another network based attack involves tapping in on the LAN (Local Area
  229. Network) and listening for people's passwords since most systems transmit them
  230. in clear text.
  231.  
  232.  
  233. On systems that disable account logins after N number of bad logins, it is
  234. sometimes useful to use the feature to lock out staff members from logging in
  235. thus giving you [the cracker] more time to clean up after yourself and escape.
  236.  
  237.  
  238. Here are a few bugs in the su (set userid) command that may come in handy:
  239.  
  240. The first was that the "-c" option did not check to see if the user being su'ed
  241. to had a valid shell.  The "-c" option is used to instruct the su command to
  242. run another command instead of a shell [eg:  "su davis -c foobar" tells su to
  243. run foobar instead of davis's default shell].  This comes in handy with
  244. accounts like "sync::0:1::/:/bin/sync" because you can execute any arbitrary
  245. command [eg: su sync -c /bin/csh].
  246.  
  247. Another bug in the su command exists in some System V ports where if su was
  248. unable to open the password file ("etc/passwd"), it would grant root access
  249. (without checking the reason for the failure).  I guess the programming can
  250. tell that something is wrong and grants access so someone can fix things.  The
  251. security problem occurs when when su is executed with a full file descriptor
  252. table; this will force su to fail its open request on the password file.
  253.  
  254.  
  255. Some Unix system's mkdir (MaKe DIRectory) command can be subverted into aiding
  256. you in gaining root.  This is done by exploiting a race condition that can
  257. occur between processes.  The following command script will eventually cause
  258. the error to occur and cause the password file to be owned by you:
  259.  
  260.     while : ; do
  261.         nice -10 (mkdir a;rm -fr a) &
  262.         (rm -fr a; ln /etc/passwd a) &
  263.     done
  264.  
  265. The race condition happens when the "ln" command runs while the mkdir command
  266. is in the middle of running.  This works because the mkdir does its job by
  267. doing the two system calls:  mknod and then chown.  If the now inode (allocated
  268. by mknod) is replaced with a link to the password file before the chown system
  269. call is made, then the password file is "chown"ed instead.  To become root from
  270. here, all you have to do is add a new entry into the password file.
  271.  
  272.  
  273. The print command ("lpr" or "lp") has an option to delete a file after it is
  274. printed.  This option will work (print & delete the file) even if you do not
  275. own the file.
  276.  
  277.  
  278. The mail command has the option to save your mail after you read to another
  279. file.  Some versions of this command will save (append) your mail to a file
  280. after it is read.  A bug exists where the mail program does not check to see if
  281. you have write permission to the file you are saving the mail to, thus allowing
  282. you to (for example) add new accounts to the password file.
  283.  
  284.  
  285. A quick word on the crypt command (and vi -x since it uses the crypt command):
  286. The algorithm used is not hard to break (it takes about twenty minutes to
  287. decrypt a file with the right tools).  See the "Bell Systems Technical
  288. journal," Vol. 63, 8, part 2 for more information.
  289.  
  290.  
  291. If the UUCP configuration files are readable [default on many systems], you can
  292. obtain the login names, passwords, and phone numbers to all of the mail links
  293. to and from the system you are hacking.  With the use of the a public domain
  294. program, "uupc", you can make the connections yourself and intercept and/or
  295. filter all incoming mail.
  296.  
  297. There are so many ways to crack Unix just through UUCP that I am not going to
  298. expand and list the many ways and their permutations.  Instead, I am going to
  299. save them for an article to be done at some random time in the future.
  300.  
  301.  
  302. If you are hacking on a system that supports sharable memory you may be able to
  303. access these memory segments.  On Sun systems, there is a command called ipcs.
  304. This command lists available sharable memory segments.  If this command does
  305. not exist (nor has a equivalent command available), you may have to either
  306. write one or use blind exploration.  Once you have identified these segments,
  307. you can gain control to the data contained therein and/or other programs
  308. utilizing the data contained within.
  309.  
  310.  
  311. If you are caught:  Grasp the bottle of "Wild Turkey" (the one near your
  312. terminal) and drink it.
  313.  
  314. ===============================================================
  315.