FreeHackingLesson


SUBMITTED BY: ProffesorFaux

DATE: March 28, 2020, 2:24 p.m.

FORMAT: Text only

SIZE: 16.8 kB

HITS: 422

  1. Free Hacking Book.
  2. From: Manifestation
  3. Subject: Security holes manifest themselves in (broadly) four ways...
  4. Date: 11.10.93
  5. ( Please contribute by sending E-Mail to <scott@santafe.edu> ... )
  6. [quoting from the comp.security.unix FAQ]
  7. Security holes manifest themselves in (broadly) four ways:
  8. 1) Physical Security Holes.
  9. - Where the potential problem is caused by giving unauthorised persons
  10. physical access to the machine, where this might allow them to perform
  11. things that they shouldn't be able to do.
  12. A good example of this would be a public workstation room where it would
  13. be trivial for a user to reboot a machine into single-user mode and muck
  14. around with the workstation filestore, if precautions are not taken.
  15. Another example of this is the need to restrict access to confidential
  16. backup tapes, which may (otherwise) be read by any user with access to
  17. the tapes and a tape drive, whether they are meant to have permission or
  18. not.
  19. 2) Software Security Holes
  20. - Where the problem is caused by badly written items of "privledged"
  21. software (daemons, cronjobs) which can be compromised into doing things
  22. which they shouldn't oughta.
  23. The most famous example of this is the "sendmail debug" hole (see
  24. bibliography) which would enable a cracker to bootstrap a "root" shell.
  25. This could be used to delete your filestore, create a new account, copy
  26. your password file, anything.
  27. (Contrary to popular opinion, crack attacks via sendmail were not just
  28. restricted to the infamous "Internet Worm" - any cracker could do this
  29. by using "telnet" to port 25 on the target machine. The story behind a
  30. similar hole (this time in the EMACS "move-mail" software) is described
  31. in [Stoll].)
  32. New holes like this appear all the time, and your best hopes are to:
  33. a: try to structure your system so that as little software as possible
  34. runs with root/daemon/bin privileges, and that which does is known to
  35. be robust.
  36. b: subscribe to a mailing list which can get details of problems
  37. and/or fixes out to you as quickly as possible, and then ACT when you
  38. receive information.
  39. >From: Wes Morgan <morgan@edu.uky.ms>
  40. >
  41. > c: When installing/upgrading a given system, try to install/enable only
  42. > those software packages for which you have an immediate or foreseeable
  43. > need. Many packages include daemons or utilities which can reveal
  44. > information to outsiders. For instance, AT&T System V Unix' accounting
  45. > package includes acctcom(1), which will (by default) allow any user to
  46. > review the daily accounting data for any other user. Many TCP/IP packa-
  47. > ges automatically install/run programs such as rwhod, fingerd, and
  48. > <occasionally> tftpd, all of which can present security problems.
  49. >
  50. > Careful system administration is the solution. Most of these programs
  51. > are initialized/started at boot time; you may wish to modify your boot
  52. > scripts (usually in the /etc, /etc/rc, /etc/rcX.d directories) to pre-
  53. > vent their execution. You may wish to remove some utilities completely.
  54. > For some utilities, a simple chmod(1) can prevent access from unauthorized
  55. > users.
  56. >
  57. > In summary, DON'T TRUST INSTALLATION SCRIPTS/PROGRAMS! Such facilities
  58. > tend to install/run everything in the package without asking you. Most
  59. > installation documentation includes lists of "the programs included in
  60. > this package"; be sure to review it.
  61. 3) Incompatible Usage Security Holes
  62. - Where, through lack of experience, or no fault of his/her own, the
  63. System Manager assembles a combination of hardware and software which
  64. when used as a system is seriously flawed from a security point of view.
  65. It is the incompatibility of trying to do two unconnected but useful
  66. things which creates the security hole.
  67. Problems like this are a pain to find once a system is set up and
  68. running, so it is better to build your system with them in mind. It's
  69. never too late to have a rethink, though.
  70. Some examples are detailed below; let's not go into them here, it would
  71. only spoil the surprise.
  72. 4) Choosing a suitable security philosophy and maintaining it.
  73. >From: Gene Spafford <spaf@cs.purdue.edu>
  74. >The fourth kind of security problem is one of perception and
  75. >understanding. Perfect software, protected hardware, and compatible
  76. >components don't work unless you have selected an appropriate security
  77. >policy and turned on the parts of your system that enforce it. Having
  78. >the best password mechanism in the world is worthless if your users
  79. >think that their login name backwards is a good password! Security is
  80. >relative to a policy (or set of policies) and the operation of a system
  81. >in conformance with that policy.
  82. ---
  83. From: Hacking
  84. Subject: Hacking Ideas
  85. Date: 11/10/93
  86. ( Please contribute by sending E-Mail to <scott@santafe.edu> ... )
  87. [ Many ideas taken from: HaxNet - APG V1.3 : Guide to finding new holes]
  88. NOTE: I think this should be divided into general categories:
  89. 1) General principles
  90. 2) Looking for holes in src (most items here)
  91. 3) Looking in binary distributions
  92. 4) Looking in site specific configurations
  93. The following general classifications suggest themselves:
  94. 1) SUID/SGID
  95. 2) Return codes/error conditions
  96. 3) unexpected input
  97. 4) race conditions
  98. 5) authentication
  99. 6) implicit trust
  100. 7) parameters
  101. 8) permissions
  102. 9) interrupts
  103. 10) I/O
  104. 11) symbolic links
  105. 12) Daemons, particularly those taking user input.
  106. 13) Kernel race conditions
  107. 14) what else? - please add categories
  108. (Suggested splitting of above into main and sub-catagories)
  109. I: Suid binaries and scripts
  110. unexpected user interactions
  111. flawed liberary calls
  112. implicit assumptions of external conditions (sym links, loc. paths)
  113. race conditions
  114. II: daemons running with priviliged uid's
  115. race conditions
  116. poor file protectons
  117. implicit file protections
  118. trust
  119. authentication
  120. III: Kernel problems
  121. Kernel race conditions
  122. device driver code
  123. The following four step method was created by System Development
  124. Corporation, who report a 65% success rate on the flaw hypotheses
  125. generated. Doing a comprehensive search for operating system flaws
  126. requires four steps:
  127. Step 1) Knowledge of system control structure.
  128. ===============================================
  129. To find security holes, and identifying design weaknesses it is
  130. necessary to understand the system control structure, and layers.
  131. One should be able to list the:
  132. A) security objects: items to be protected. ie: a users file.
  133. B) control objects: items that protect security objects. ie: a i-node
  134. C) mutual objects : objects in both classes. ie: the password file
  135. With such a list, it is possible to graphically represent a control
  136. hierarchy and identify potential points of attack. Making flow charts
  137. to give a visual breakdown of relationships definitely helps.
  138. Reading the various users, operators, and administrators manuals should
  139. provide this information.
  140. (following para's should probably be moved to a "legal" section)
  141. Reading and greping source code should also prove valuable. For those
  142. without a source licence, I would suggest we use LINUX, NET2, and BSD386
  143. distributions in order to stay legal. At some future time we may be able
  144. to form a working contract between someone or a company with legal access
  145. to other distributions and members actively participating in this project.
  146. It appears that extracts of proprietary code may be used for academic
  147. study, so long as they are not reused in a commercial product - more
  148. checking is necessary though.
  149. Step 2) Generate an inventory of suspected flaws. (i.e. flaw hypotheses)
  150. ========================================================================
  151. In particular we want:
  152. Code history:
  153. What UNIX src does a particular flavor derive from? This is important
  154. for cross references (very often only one vendor patches certain code,
  155. which may get reused, in it's unpatched reincarnation by others)
  156. A solid cross reference:
  157. Who checked which bug in what OS and what version prevents us from
  158. duplicating work.
  159. A good start would be listing all the suid binaries on the various OS
  160. flavors/versions. Then try to work out why each program is suid. i.e.:
  161. rcp is suid root because it must use a privilaged port to do user
  162. name authentication.
  163. Often code that was never designed to be suid, is made suid, durring
  164. porting to solve file access problems.
  165. We need to develope a data base that will be able to look at pairs and
  166. triplets of data, specificly: program name, suid, sgid, object accessed
  167. (why prog is suid/sgid), OS flavor/version, and flav/vers geniology.
  168. Any sugestions on how to implement such a DB?
  169. Step 3) Confirm hypotheses. (test and exploit flaws)
  170. ====================================================
  171. Step 4) Make generalizations of the underlying system weaknesses, for
  172. which the flaw represents a specific instance.
  173. =====================================================================
  174. Tool Box:
  175. =========
  176. AGREP: I suggest everyone obtain, and install agrep from:
  177. ftp cs.arizona.edu /agrep/agrep.tar.Z
  178. Agrep supports "windowing" so it can look for routines, and subroutines.
  179. It also supports logical operators and is thus ideally suited to automating
  180. the search for many of the following flaws. i.e. <psudocode>
  181. agrep WINDOW {suid() NOT taintperl()} /usr/local/*.pl
  182. or agrep WINDOW {[suid() OR sgid()] AND [system() OR popen() OR execlp()
  183. OR execvp()]} /usr/local/src/*.c
  184. PERMUTATION PROGRAM: Another tool worth producing is a program to generate
  185. all possible permutations of command line flags/arguments in order to uncover
  186. undocumented features, and try to produce errors.
  187. TCOV:
  188. CRASH: Posted to USENET (what FTP archive?) (descrip?)
  189. PAPERS: There are several papers that discuss methods of finding flaws, and
  190. present test suites.
  191. 1) An Emphirical Study of the reliability of UNIX Utilities, by Barton P.
  192. Miller, Lars Fredriksen, and Bryan So, Comm ACM, v33 n12, pp32-44,
  193. Dec '90. Describes a test suite for testing random input strings.
  194. Results indicated that 25% of the programs hung, crashed, or misbehaved.
  195. In one case the OS crashed. An understanding of buffer and register
  196. layout on the environment in question, and the expected input is likely
  197. to produce the desired results.
  198. 2) The Mothra tools set, in Proceedings of the 22nd Hawaii International
  199. Conference on Systems and Software, pages 275-284, Kona, HI, January '89
  200. 3) Extending Mutation Testing to Find Environmental Bugs, by Eugene H.
  201. Spafford, Software Practice and Experience, 20(2):181-189, Feb '90
  202. 4) A paper by IBM was mentioned that was submitted to USENIX a few years
  203. ago. (Anyone have a citation?).
  204. Specific Flaws to Check For:
  205. ============================
  206. 1) Look for routines that don't do boundary checking, or verify input.
  207. ie: the gets() family of routines, where it is possible to overwrite
  208. buffer boundaries. ( sprintf()?, gets(), etc. )
  209. also: strcpy() which is why most src has:
  210. #define SCYPYN((a)(b)) strcpy(a, b, sizeof(a))
  211. 2) SUID/SGID routines written in one of the shells, instead of C or
  212. PERL.
  213. 3) SUID/SGID routines written in PERL that don't use the "taintperl"
  214. program.)
  215. 4) SUID/SGID routines that use the system(), popen(), execlp(), or
  216. execvp() calls to run something else.
  217. 5) Any program that uses relative path names inside the program.
  218. 6) The use of relative path names to specify dynamically linked libraries.
  219. (look in Makefile).
  220. 7) Routines that don't check error return codes from system calls. (ie:
  221. fork(2), suid(2), etc), setuid() rather, as in the famous rcp bug
  222. 8) Holes can often be found in code that:
  223. A) is ported to a new environment.
  224. B) receives unexpected input.
  225. C) interacts with other local software.
  226. D) accesses system files like passwd, L.sys, etc.
  227. E) reads input from a publicly writable file/directory.
  228. F) diagnostic programs which are typically not user-proofed.
  229. 9) Test code for unexpected input. Coverage, data flow, and mutation
  230. testing tools are available.
  231. 10) Look in man pages, and users guides for warnings against doing X, and
  232. try variations of X. Ditto for "bugs" section.
  233. 11) Look for seldom used, or unusual functions or commands - read backwards.
  234. In particular looking for undocumented flags/arguments may prove useful.
  235. Check flags that were in prior releases, or in other OS versions. Check
  236. for options that other programs might use. For instance telnet uses -h
  237. option to login ...
  238. right, as most login.c's I've seen have:
  239. if((getuid()) && hflag){
  240. syslog()
  241. exit()
  242. }
  243. 12) Look for race conditions.
  244. 13) Failure of software to authenticate that it is really communicating
  245. with the desired software or hardware module it wants to be accessing.
  246. 14) Lack or error detection to reset protection mechanisms following an
  247. error.
  248. 15) Poor implementation resulting in, for example, condition codes being
  249. improperly tested.
  250. 16) Implicit trust: Routine B assumes routine A's parameters are correct
  251. because routine A is a system process.
  252. 17) System stores it's data or references user parameters in the users
  253. address space.
  254. 18) Inter process communication: return conditions (passwd OK, illegal
  255. parameter, segment error, etc) can provide a significant wedge, esp.
  256. when combined with (17).
  257. 19) User parameters may not be adequately checked.
  258. 20) Addresses that overlap or refer to system areas.
  259. 21) Condition code checks may be omitted.
  260. 22) Failure to anticipate unusual or extraordinary parameters.
  261. 23) Look for system levels where the modules involved were written by
  262. different programmers, or groups of programmers - holes are likely
  263. to be found.
  264. 24) Registers that point to the location of a parameters value instead
  265. of passing the value itself.
  266. 25) Any program running with system privileges. (too many progs are given
  267. uid 0, to facilitate access to certain tables, etc.)
  268. 26) Group or world readable temporary files, buffers, etc.
  269. 27) Lack of threshold values, and lack of logging/notification once these
  270. have been triggered.
  271. 28) Changing parameters of critical system areas prior to their execution
  272. by a concurrent process. (race conditions)
  273. 29) Inadequate boundary checking at compile time, for example, a user
  274. may be able to execute machine code disguised as data in a data area.
  275. (if text and data areas are shared)
  276. 30) Improperly handling user generated asynchronous interrupts. Users
  277. interrupting a process, performing an operation, and either returning
  278. to continue the process or begin another will frequently leave the
  279. system in an unprotected state. Partially written files are left open,
  280. improper writing of protection infraction messages, improper setting
  281. of protection bits, etc often occur.
  282. 31) Code that uses fopen(3) without setting the umask. ( eg: at(1), etc. )
  283. In general, code that does not reset the real and effective uid before
  284. forking.
  285. 32) Trace is your friend (or truss in SVR4) for helping figure out what
  286. system calls a program is using.
  287. 33) Scan /usr/local fs's closely. Many admins will install software from
  288. the net. Often you'll find tcpdump, top, nfswatch, ... suid'd root for
  289. their ease of use.
  290. 34) Check suid programs to see if they are the ones originally put on the
  291. system. Admins will sometimes put in a passwd replacement which is less
  292. secure than the distributed version.
  293. 35) Look for programs that were there to install software or loadable
  294. kernel modules.
  295. 36) Dynamically linked programs in general. Remember LD_PRELOAD, I think
  296. that was the variable.
  297. 37) I/O channel programming is a prime target. Look for logical errors,
  298. inconsistencies, and omissions.
  299. 38) See if it's possible for a I/O channel program to modify itself, loop
  300. back, and then execute the newly modified code. (instruction pre-load
  301. may screw this up)
  302. 39) If I/O channels act as independent processors they may have unlimited
  303. access to memory, thus system code may be modified in memory prior to
  304. execution.
  305. 40) Look for bugs requiring flaws in multiple pieces of software, i.e. say
  306. program a can be used to change config file /etc/a now program b assumes
  307. the information in a to be correct and this leads to unexpected results
  308. (just look at how many programs trust /etc/utmp)
  309. 41) Any program, especially those suid/sgid, that allow shell escapes.

comments powered by Disqus