home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersguides-&-software / usefulunix.txt < prev    next >
Text File  |  1996-04-14  |  24KB  |  657 lines

  1.  
  2.  
  3.                        *** A List Of Some OF The Most Useful UNIX **
  4.      *** Hacking Commands, and Some Hints On Their Usage ***
  5.        
  6. ---------------------------------------------------------------
  7.  
  8.      It is fun and often usefull to create a file that is owned 
  9. by someone else.  On most systems with slack security ie 99% of 
  10. all UNIX systems, this is quite easily done.  The chown command 
  11. will change any of your files to make someone else the owner. 
  12. Format is as follows:
  13.  
  14. chown ownername filelist
  15.  
  16.  Where ownername is the new owner, and filelist is the list of 
  17. files to change.  You must own the file which your are goin to 
  18. change, unless you are a superuser....then u can change ANYTHING!
  19.      chgrp is a similar command which will change the group 
  20. ownership on a file.  If you are going to do both a chown and a 
  21. chgrp on a file, then make sure you do the chgrp first!  Once the 
  22. file is owned by someone else, you cant change nything about it!
  23.  
  24. ---------------------------------------------------------------
  25.  
  26.      Sometimes just seeing who is on the system is a challenge in 
  27. itself.  The best way is to write your own version of who in C, 
  28. but if you can't do that then this may be of some help to you:
  29.  
  30.      who   followed by on or more of the following flags:
  31.  
  32.           -b Displays time sys as last booted.
  33.           -H Precedes output with header.
  34.           -l Lists lines waiting for users to logon.
  35.           -q displays number of users logged on.
  36.           -t displays time sys clock was last changed.
  37.           -T displays the state field (a + indicates it is 
  38. possible to send to terminal, a - means u cannot)
  39.           -u Give a complete listing of those logged on.
  40.  
  41.    **who -HTu is about the best choice for the average user**
  42.  
  43. ##by the way, the list of users logged on is kept in the file 
  44. /etc/utmp.  If you want to write your own personalised version of 
  45. who in C, you now know where to look!###
  46.  
  47. --------------------------------------------------------------- 
  48.  
  49.      When a users state field (see -T flag option for who 
  50. command) says that a user has their message function on, this 
  51. actually means that it is possible to get stuff onto their 
  52. screen.
  53.      Basically, every terminal on the system has a file 
  54. corresponding to it.  These files can be found in the /dev 
  55. directory.  You can to anything to these files, so long as you 
  56. have access -eg you can read them, and write to them, but you 
  57. will notice that they never change in size.  They are called 
  58. character specific files, and are really the link between the 
  59. system and the terminals.  Whatever you put in these files will 
  60. go staright to the terminal it corresponds to.
  61.      Unfortunately, on most systems, when the user logs in, the 
  62. "mesg n" command is issued which turns off write access to that 
  63. terminal, BUT- if you can start cating to that terminal before 
  64. system issues the mesg n command, then you will continue to be 
  65. able to get stuff up on that terminal! This has many varied uses.
  66.  
  67.      Check out the terminal, or terminal software being used.  
  68. Often you will be able to remotely program another users 
  69. terminal, simply by 'cating' a string to a users screen.  You 
  70. might be able to set up a buffer, capturing all that is typed, or 
  71. you may be able to send the terminal into a frenzy- (sometimes a 
  72. user will walk away without realizing that they are sill 
  73. effectively logged on, leaving you with access to their 
  74. account!).  Some terminal types also have this great command 
  75. called transmit screen. It transmits everything on the screen, 
  76. just as if the user had typed it !
  77.      So just say I wanted to log off a user, then I would send a 
  78. clear screen command (usually ctrl l), followed by "exit" 
  79. followed by a carriage return, followed by the transmit screen 
  80. code.  Using ths technique you can wipe peoples directories or 
  81. anything.  My favourite is to set open access on all their files 
  82. and directories so I can peruse them for deletion etc at my own 
  83. leisure).            
  84.  
  85. ---------------------------------------------------------------
  86.  
  87.      If you ever briefly get access to another persons account 
  88. eg. they leave the room to go to toilet or whatever, then simply 
  89. type the following:
  90.  
  91. chmod 777 $HOME
  92. chmod 777 $MAIL
  93.  
  94.      Then clear the screen so they dont see what you just typed.
  95.  
  96.      Now you can go look at their directory, and their mail, and 
  97. you can even put mail in their mail file. (just use the same 
  98. format as any mail that is already there!). Next time they log in 
  99. the system will automatically inform them they have new mail!
  100.  
  101. ---------------------------------------------------------------
  102.  
  103.      Another way to send fake mail to people is to use the mail 
  104. server.  This method produces mail that is slightly different to 
  105. normal, so anyone who uses UNIX a bit may be suspiscious when 
  106. they receive it, but it will fool the average  user!
  107.  
  108. type telnet
  109.  
  110. the following prompt will appear:
  111.  
  112. telnet>
  113.  
  114. now type :
  115.  
  116. open localhost 25
  117.  
  118. some crap will come up about the mail server..now type:
  119.  
  120. mail from: xxxxxx     Put any name you want.
  121.  
  122. some more bullshit will come up. Now type:
  123.  
  124. rcpt to: xxxxxx  Put the name of the person to receive mail here.
  125.  
  126. now type:
  127.  
  128. data
  129.  
  130. now you can type the letter...end it with a "."
  131. type quit to exit once you are done.
  132.  
  133. -------------------------------------------------------------
  134.  
  135.      Heres one for any experimenters out there...
  136. It is possible to create files which simply cannot be deleted 
  137. from the standard shell.  To do this you will have to physically 
  138. CREATE THE FILE USING A C PROGRAM or SCRIPT FILE, and you will 
  139. have to use a sequence of control characters which cannot be 
  140. typed from the shell.  Try things like Ctrl-h (this is the 
  141. code for the delete key).  Just a file with the name Ctrl-h would 
  142. not be deleteable from the shell, unless you used wildcards. So, 
  143. make it a nice long series of characters, so that to delete the 
  144. file, the user has no choice but to individually copy all his 
  145. files elsewhere, then delete everything in his directory, and 
  146. then copy all his files back.....this is one of my 
  147. favourites..gets em every time!
  148.      
  149.      The following script file is an example which will create a 
  150. file with the name Ctrl-h.  You MUST tyoe this file in using the 
  151. vi editor or similar.
  152. *****If you are not very good with vi, type "man vi" and print the 
  153. help file...it even contains stuff that I find useful now and 
  154. then.*****
  155.  
  156. type the following in vi...
  157.  
  158. echo'' > 'a^h'
  159.  
  160.   ***NOTE...to get the ^h (this really means ctrl-h) from vi type:
  161.  
  162. Ctrl v
  163. Ctrl h 
  164.  
  165.   The Ctrl v instrcts vi to take the next character as a ascii 
  166. character, and not to interpret it.
  167.      change the access on the file you just created and now 
  168. execute it.  It will create a file which looks like it is called 
  169. a, but try to delete it !..use wildcards if you really want to 
  170. delete it. 
  171.  
  172. *> Title:   Tutorial on hacking through a UNIX system
  173.  
  174.  
  175. ** 
  176.  
  177. In the following file, all references made to the name Unix, may also be 
  178. substituted to the Xenix operating system. 
  179.  
  180. Brief history:  Back in the early sixties, during the development of 
  181. third generation computers at MIT, a group of programmers studying the 
  182. potential of computers, discovered their ability of performing two or 
  183. more tasks simultaneously.  Bell Labs, taking notice of this discovery, 
  184. provided funds for their developmental scientists to investigate into this 
  185. new frontier.  After about 2 years of developmental research, they produced 
  186. an operating system they called "Unix".  
  187. Sixties to Current:  During this time Bell Systems installed the Unix system 
  188. to provide their computer operators with the ability to multitask so that 
  189. they could become more productive, and efficient.  One of the systems they
  190. put on the Unix system was called "Elmos". Through Elmos many tasks (i.e.
  191. billing,and installation records) could be done by many people using the same 
  192. mainframe. 
  193.  
  194. Note: Cosmos is accessed through the Elmos system. 
  195.  
  196. Current:  Today, with the development of micro computers, such multitasking 
  197. can be achieved by a scaled down version of Unix (but just as 
  198. powerful).  Microsoft,seeing this development, opted to develop their own 
  199. Unix like system for the IBM line of PC/XT's.  Their result they called 
  200. Xenix (pronounced zee-nicks).  Both Unix and Xenix can be easily installed 
  201. on IBM PC's and offer the same function (just 2 different vendors). 
  202.  
  203. Note: Due to the many different versions of Unix (Berkley Unix, 
  204. Bell System III, and System V the most popular) many commands 
  205. following may/may not work. I have written them in System V routines. 
  206. Unix/Xenix operating systems will be considered identical systems below. 
  207.  
  208. How to tell if/if not you are on a Unix system:  Unix systems are quite 
  209. common systems across the country. Their security appears as such: 
  210.  
  211. Login;     (or login;) 
  212. password: 
  213.  
  214. When hacking on a Unix system it is best to use lowercase because the Unix 
  215. system commands are all done in lower- case. Login; is a 1-8 character field. It is 
  216. usually the name (i.e. joe or fred) of the user, or initials (i.e. j.jones 
  217. or f.wilson).  Hints for login names can be found trashing the location of 
  218. the dial-up (use your CN/A to find where the computer is). Password: is a 1-8 character password assigned by the sysop or chosen by the user. 
  219.    
  220.    Common default logins 
  221.    -------------------------- 
  222.    login;       Password: 
  223.    root         root,system,etc.. 
  224.    sys          sys,system 
  225.    daemon       daemon 
  226.    uucp         uucp 
  227.    tty          tty 
  228.    test         test 
  229.    unix         unix 
  230.    bin          bin 
  231.    adm          adm 
  232.    who          who 
  233.    learn        learn 
  234.    uuhost       uuhost 
  235.    nuucp        nuucp 
  236.  
  237. If you guess a login name and you are not asked for a password, and have 
  238. accessed to the system, then you have what is known as a non-gifted account. 
  239. If you guess a correct login and pass- word, then you have a user account. 
  240. And, if you get the root p/w you have a "super-user" account. 
  241. All Unix systems have the following installed to their system: 
  242. root, sys, bin, daemon, uucp, adm Once you are in the system, you will 
  243. get a prompt. Common prompts are: 
  244.  
  245.  
  246. But can be just about anything the sysop or user wants it to be. 
  247.  
  248. Things to do when you are in: Some of the commands that you may want to 
  249. try follow below: 
  250.  
  251. who is on  (shows who is currently logged on the system.) 
  252. write name (name is the person you wish to chat with) 
  253. To exit chat mode try ctrl-D. 
  254. EOT=End of Transfer. 
  255. ls -a      (list all files in current   directory.) 
  256. du -a      (checks amount of memory  your files use;disk usage) 
  257. cd\name    (name is the name of the sub-directory you choose) 
  258. cd\        (brings your home directory  to current use) 
  259. cat name   (name is a filename either  a program or documentation  your username has written) 
  260.  Most Unix programs are written  in the C language or Pascal 
  261.  since Unix is a programmers'  environment. One of the first things done on the 
  262. system is print up or capture (in a buffer) the file containing all user names and accounts. This can be done by doing the following command: 
  263.  
  264. cat /etc/passwd 
  265.  
  266. If you are successful you will see a list of all accounts on the system.  It 
  267. should look like this:  
  268. root:hvnsdcf:0:0:root dir:/: joe:majdnfd:1:1:Joe Cool:/bin:/bin/joe hal::1:2:Hal Smith:/bin:/bin/hal 
  269.  
  270. The "root" line tells the following info : 
  271. login name=root 
  272. hvnsdcf   = encrypted password 
  273. 0         = user group number 
  274. 0         = user number 
  275. root dir  = name of user 
  276. /         = root directory 
  277.  
  278. In the Joe login, the last part "/bin/joe " tells us which directory 
  279. is his home directory (joe) is. In the "hal" example the login name is 
  280. followed by 2 colons, that means that there is no password needed to get in 
  281. using his name. 
  282.  
  283. Conclusion:  I hope that this file will help other novice Unix hackers 
  284. obtain access to the Unix/Xenix systems that they may find.
  285.  
  286.  
  287.  
  288.               On the Security of UNIX
  289.  
  290.               =-=-=-=-=-=-=-=-=-=-=-=
  291.  
  292. Recently there has been much interest in the security aspects of operating
  293.  
  294. systems and software.At issue is the ability to prevent undesired disclosure of
  295.  
  296. information, destruction of information,and harm to the functioning of the
  297.  
  298. system.This paper discusses the degree of security which can be provided under
  299.  
  300. the system and offers a number of hints on how to improve security.The first
  301.  
  302. fact to face is that UNIX was not developed with security,in any realistic
  303.  
  304. sense,in mind;this fact alone guarantees a vast number of holes.(Actually the
  305.  
  306. same statement can be made with respect to most systems.)
  307.  
  308.  
  309.  
  310. The area of security in which is theoretically weakest is in protecting against
  311.  
  312. crashing or at least crippling the operation of the system.The problem here is
  313.  
  314. not mainly in uncritical acceptance of bad parameters to system calls (there
  315.  
  316. may be bugs in this area, but none are known)but rather in lack of checks for
  317.  
  318. excessive consumption of resources.
  319.  
  320.  
  321.  
  322. Most notably, there is no limit on the amount of disk storage used, either in
  323.  
  324. total space allocated or in the number of files or directories.Here is a
  325.  
  326. particularly ghastly shell sequence guaranteed to stop the system:
  327.  
  328.  
  329.  
  330.  
  331.  
  332. while : ; do
  333.  
  334.     mkdir x
  335.  
  336.     cd x
  337.  
  338. done
  339.  
  340.  
  341.  
  342. Either a panic will occur because all the i-nodes on the device are used up,
  343.  
  344. or all the disk blocks will be consumed, thus preventing anyone from writing
  345.  
  346. files on the device.In this version of the system,users are prevented from
  347.  
  348. creating more than a set number of processes simultaneously,so unless users
  349.  
  350. are in collusion it is unlikely that any one can stop the system altogether.
  351.  
  352.  
  353.  
  354. However, creation of 20 or so CPU or disk-bound jobs leaves few resources
  355.  
  356. available for others.Also, if many large jobs are run simultaneously,swap space
  357.  
  358. may run out, causing a panic.  It should be evident that excessive consumption
  359.  
  360. of diskspace, files, swap space and processes can easily occur accidentally in
  361.  
  362. malfunctioning programs as well as at command level.In fact UNIX is essentially
  363.  
  364. defenseless against this kind of abuse,nor is there any easy fix.The best that
  365.  
  366. can be said is that it is generally fairly easy to detect what has happened
  367.  
  368. when disaster strikes ,to identify the user responsible, and take appropriate
  369.  
  370. action.In practice,we have found that difficulties in this area are rather
  371.  
  372. rare,but we have not been faced with malicious users,and enjoy a fairly
  373.  
  374. generous supply of resources which have served to cushion us against accidental
  375.  
  376. overconsumption.
  377.  
  378.  
  379.  
  380. The picture is considerably brighter in the area of protection of information
  381.  
  382. from unauthorized perusal and destruction.Here the degree of security seems
  383.  
  384. (almost) adequate theoretically, and the problems lie more in the necessity for
  385.  
  386. care in the actual use of the system.Each UNIX file has associated with it
  387.  
  388. eleven bits of protection information together with a user identification
  389.  
  390. number and a user-group identification number (UID and GID).
  391.  
  392.  
  393.  
  394. Nine of the protection bits are used to specify independently permission to
  395.  
  396. read, to write, and to execute the file to the user himself, to members of the
  397.  
  398. user's group, and to all other users.Each process generated by or for a user
  399.  
  400. has associated with it an effective UID and a real UID, and an effective and
  401.  
  402. real GID.When an attempt is made to access the file for reading, writing, or
  403.  
  404. executing UID for the process is changed to the UID associated with the file;
  405.  
  406. the change persists until the process terminates or until the UID changed again
  407.  
  408. by another execution of a set-UID file.Similarly the effective group ID of a
  409.  
  410. process is changed to the GID associated with a file when that file is executed
  411.  
  412. and has the set-GID bit set.The real UID and GID of a process do not change
  413.  
  414. when any file is executed,but only as the result of a privileged system
  415.  
  416. call.The basic notion of the set-UID and set-GID bits is that one may write a
  417.  
  418. program which is executableby others and which maintains files accessible to
  419.  
  420. others only by that program.
  421.  
  422.  
  423.  
  424. The classical example is the game-playing program which maintains records of
  425.  
  426. the scores of its players.The program itself has to read and write the score
  427.  
  428. file,but no one but the game's sponsor can be allowed unrestricted access to
  429.  
  430. the file lest they manipulate the game to their own advantage.
  431.  
  432.  
  433.  
  434. The solution is to turn on the set-UID bit of the game program.  When, and only
  435.  
  436. when,it is invoked by players of the game,it may update the score file but
  437.  
  438. ordinary programs executed by others cannot access the score.  There are a
  439.  
  440. number of special cases involved in determining access permissions.  Since
  441.  
  442. executing a directory as a program is a meaningless operation,the
  443.  
  444. execute-permission bit, for directories, is taken instead to mean permission to
  445.  
  446. search the directory for a given file during the scanning of a path name; thus
  447.  
  448. if a directory has execute permission but no read permission for a given user,
  449.  
  450. he may access files with known names in the directory,but may not read (list)
  451.  
  452. the entire contents of the directory.
  453.  
  454.  
  455.  
  456. Write permission on a directory is interpreted to mean that the user may create
  457.  
  458. and delete files in that directory;it is impossible for any user to write
  459.  
  460. directly into any directory..Another, and from the point of view of security,
  461.  
  462. much more serious special case is that there is a ``super user'' who is able to
  463.  
  464. read any file and write any non-directory.The super-user is also able to change
  465.  
  466. the protection mode and the owner UID and GID of any file and to invoke
  467.  
  468. privileged system calls.It must be recognized that the mere notion of a
  469.  
  470. super-user is a theoretical, and usually practical, blemish on any protection
  471.  
  472. scheme.
  473.  
  474.  
  475.  
  476. The first necessity for a secure system is of course arranging that all files
  477.  
  478. and directories have the proper protection modes.Traditionally, UNIX software
  479.  
  480. has been exceedingly permissive in this regard;essentially all commands create
  481.  
  482. files readable and writable by everyone.In the current version,this policy may
  483.  
  484. be easily adjusted to suit the needs ofthe installation or the individual user.
  485.  
  486.  
  487.  
  488. Associated with each process and its descendants is a mask, which is in effect
  489.  
  490. anded with the mode of every file and directory created by that process.  In
  491.  
  492. this way, users can arrange that, by default,all their files are no more
  493.  
  494. accessible than they wish.The standard mask, set by login,allows all permiss-
  495.  
  496. ions to the user himself and to his group,but disallows writing by others.
  497.  
  498.  
  499.  
  500. To maintain both data privacy and data integrity,it is necessary, and largely
  501.  
  502. sufficient,to make one's files inaccessible to others.  The lack of sufficiency
  503.  
  504. could follow from the existence of set-UID programs created by the user and the
  505.  
  506. possibility of total breach of system security in one of the ways discussed
  507.  
  508. below(or one of the ways not discussed below).
  509.  
  510.  
  511.  
  512. For greater protection,an encryption scheme is available.Since the editor is
  513.  
  514. able to create encrypted documents, and the crypt command can be used to pipe
  515.  
  516. such documents into the other text-processing programs,the length of time
  517.  
  518. during which clear text versions need be available is strictly limited.The
  519.  
  520. encryption scheme used is not one of the strongest known, but it is judged
  521.  
  522. adequate, in the sense that cryptanalysisis likely to require considerably more
  523.  
  524. effort than more direct methods of reading the encrypted files.For example, a
  525.  
  526. user who stores data that he regards as truly secret should be aware that he is
  527.  
  528. implicitly trusting the system administrator not to install a version of the
  529.  
  530. crypt command that stores every typed password in a file.  Needless to say, the
  531.  
  532. system administrators must be at least as careful as their most demanding user
  533.  
  534. to place the correct protection mode on the files under their control.
  535.  
  536.  
  537.  
  538. In particular,it is necessary that special files be protected from writing, and
  539.  
  540. probably reading, by ordinary users when they store sensitive files belonging
  541.  
  542. to otherusers.It is easy to write programs that examine and change files by
  543.  
  544. accessing the device on which the files live.
  545.  
  546.  
  547.  
  548. On the issue of password security,UNIX is probably better than most systems.
  549.  
  550. Passwords are stored in an encrypted form which, in the absence of serious
  551.  
  552. attention from specialists in the field,appears reasonably secure, provided its
  553.  
  554. limitations are understood.In the current version, it is based on a slightl y
  555.  
  556. defective version of the Federal DES;it is purposely defective so that
  557.  
  558. easily-available hardware is useless for attempts at exhaustive
  559.  
  560. key-search.Since both the encryption algorithm and the encrypted passwords are
  561.  
  562. available,exhaustive enumeration of potential passwords is still feasible up to
  563.  
  564. a point.We have observed that users choose passwords that are easy to
  565.  
  566. guess:they are short, or from a limited alphabet, or in a dictionary.
  567.  
  568. Passwords should be at least six characters long and randomly chosen from an
  569.  
  570. alphabet which includes digits and special characters.
  571.  
  572.  
  573.  
  574. Of course there also exist feasible non-cryptanalytic ways of finding out
  575.  
  576. passwords.For example:    write a program which types out ``login:''on the
  577.  
  578. typewriter and copies whatever is typed to a file of your own.    Then invoke the
  579.  
  580. command and go away until the victim arrives..The set-UID (set-GID)notion must
  581.  
  582. be used carefully if any security is to be maintained.    The first thing to keep
  583.  
  584. in mind is that a writable set-UID file can have another program copied onto
  585.  
  586. it.
  587.  
  588.  
  589.  
  590. For example, if the super-user command is writable,anyone can copy the shell
  591.  
  592. onto it and get a password-free version of Shell Unix.A more subtle problem can
  593.  
  594. come from set-UID programs which are not sufficiently careful of what is fed
  595.  
  596. into them.To take an obsolete example,the previous version of the mail command
  597.  
  598. was set-UID and owned by the super-user.This version sent mail to the r
  599.  
  600. ecipient's own directory.The notion was that one should be able to send mail to
  601.  
  602. anyone even if they want to protecttheir directories from writing.  The trouble
  603.  
  604. was that mailwas rather dumb:anyone could mail someone else's priva te file to
  605.  
  606. himself.Much more seriousis the following scenario:  make a file with a line
  607.  
  608. like one in the password filewhich allows one to log in as the super-user.Then
  609.  
  610. make a link named ``.mail'' to the password file in some writable directory on
  611.  
  612. the same device as the password file (say /tmp).  Finally mail the bogus login
  613.  
  614. line to /tmp/.mail;You can then login as the superuser,clean up the
  615.  
  616. incriminating evidence,and have your will.
  617.  
  618.  
  619.  
  620. The fact that users can mount their own disks and tapes as file systems can be
  621.  
  622. another way of gaining super-user status.Once a disk pack is mounted, the
  623.  
  624. system believes what is on it.Thus one can take a blank disk pack,put on it
  625.  
  626. anything desired,and mount it.There are obvious and unfortunate consequences.
  627.  
  628. For example:a mounted disk with garbage on it will crash the system;one of the
  629.  
  630. files on the mounted disk can easily be a password-free version of Shell Unix;
  631.  
  632. other files can be unprotected entries for special files.  The only easy fix
  633.  
  634. for this problem is to forbid the use of mount to unpriv- ileged users.A
  635.  
  636. partial solution, not so restrictive,would be to have the mount command examine
  637.  
  638. the special file for bad data,set-UID programs owned by others ,and accessible
  639.  
  640. special files,and balk at unprivileged invokers.
  641.  
  642.  
  643.  
  644.  
  645.  
  646. Scott Walters   London, CANADA
  647. walterss@julian.uwo.ca  <CarbonBoy>
  648. PGP 31 03 1B E1 C7 6E 3A EC  97 32 01 BA 5B 05 5D FB
  649. finger me for public key block
  650. MIME-mail welcome
  651.  
  652. 'Beware the fury of a patient man.'
  653.  
  654.