lcrack-20040914/0000755000175000017500000000000011300514213012174 5ustar tiagotiagolcrack-20040914/COPYING0000644000175000017500000004310506355614616013260 0ustar tiagotiago GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. lcrack-20040914/regex.txt0000644000175000017500000000007510121654041014055 0ustar tiagotiago# regex spec admin = adm[*] lepton = [0-9]\x20[*][xyz] lcrack-20040914/mod_nt4.c0000644000175000017500000000130410115662577013726 0ustar tiagotiago/* NT (Unicode) MD4 implementation Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_method.h" #include #include extern void mdfour(unsigned char *out, unsigned char *in, int len); int xtn_nt4_init(void) { fprintf(stderr, "xtn: initialized 'NT md4/unicode' module\n"); return 16; } int xtn_nt4_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1) { return !memcmp(h0, h1, 16 * sizeof(BYTE)); } CODE_BLOCK_PTR xtn_nt4_crypt(char *passwd, int len, BYTE *CMAP) { static BYTE md4_buf[16]; BYTE aux[64]; int j; for(j = 0; j < len; j ++) { aux[2*j] = CMAP[(int)passwd[j]]; aux[2*j+1] = '\0'; } len *= 2; mdfour(md4_buf, aux, len); return md4_buf; } lcrack-20040914/README0000644000175000017500000003003010121653772013066 0ustar tiagotiago ** lcrack: Lepton's Crack ** /------------------------------------------------------------\ | Generic password hash cracker | | | | Copyright (C) Bernardo Reino (lepton@runbox.com) | | and Miguel Dilaj (nekromancer@eudoramail.com) | | | | 20021208 | \------------------------------------------------------------/ Credits/ -------/ To the es.comp.hackers newsgroup, especially to TyPhOoN, znôrt, PijusMagnificus, Chachini, CastleMan, user, and all the others whom I've forgotten to mention. The Lotus Domino HTTP hash implementation is based partially on code provided by Jeff Fay (jeff@sdii.com) The SHA-1 module has been contributed by Burcin Erocal (burcin@math.bilgi.edu.tr) To all our beta testers out there. Disclaimer/ ----------/ THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Introduction/ ------------/ Lepton's Crack is a generic password cracker, easily customizable with a simple plug-in system. It can perform a dictionary-based (wordlist) attack, as well as a brute-force (incremental) password scan. For the incremental scan, the user can provide a regex-like expression that will be enumerated, thus checking every possible combination. This powerful feature effectively combines `shoulder-surfing' with standard brute-forcing. By default it comes with the following modules: * md4 : standard MD4 hash * md5 : standard MD5 hash * nt4 : NT MD4/Unicode * dom : Lotus Domino HTTP password * sha1 : standard SHA-1 hash * null : trivial 1-byte hash (sample for plug-in developers :) Installation/ ------------/ The first thing to do is to run the 'configure' shell script (beware, it is not the standard 'autoconf' stuff.. :). This simple script will try to determine what compiler to use, which flags to set, and will generate the 'Makefile' and 'xtn_method.[ch]' depending on what modules are available (mod_*.[ch]). If you want to add or delete modules, the best procedure is to type 'make distclean', then copy or remove the module files as needed, and type './configure' again. Compilation/ -----------/ Use the 'Makefile' generated in the previous step. Make sure you check all the settings (compiler, flags, etc.) in the Makefile, and adjust as needed. Typing 'make' will generate the 'lcrack' executable file. Usage/ -----/ The command-line usage is as follows: usage: lcrack [-q | -v] -m [] .. -o : output password file -d : use word list from -t : use pre-computed word list from -s : use specified charset for incremental -s# : use charset from charset.txt file -l : use specified length-set for incremental -g : enumerate regex for incremental -g# : use regex from regex.txt file -x[+|-] : activate/deactivate specified mode mode = l : login mode mode = f : fast word list mode mode = s : smart word list mode mode = b : brute-force mode -stdin : stdin (external) mode -rand : randomized brute-force mode -h : display usage information and exit : hash algorithm, one of: { 'dom' 'md4' 'md5' 'nt4' 'null' 'sha1' } The '-m' option sets the hashing method, and should match with the algorithm that was used to create the input file(s). The '-d' option enables the dictionary-attack, using the dictionary provided. Multiple dictionaries can be specified, using multiple '-d ' options. The format of the dictionary file is very simple: one word per line :) The '-t' option enables the table-lookup attack. The given file is a sequence of (word, hash) pairs, where 'word' is padded to 16 bytes, and the hash is exactly 16 (binary) bytes. Obviously this is only useful for 16-byte hashes, but if that's the case (as it is with the Lotus Domino hash) the look-up will be extremely fast. To create such a table, use the include mktbl program. By default none of the modes will be active. You can activate or deactivate any mode at will, using the '-x' option. With the '-s' option you can specify the character set that will be used during the brute-force scan. The default set is 'a-z0-9'. You can use a simple compact form to specify the set, using the '-' character, which defines a range of characters. Using the '-s#' option followed by a name, lcrack will use the character set defined in the charset.txt (which will be searched in the current directory, your home directory, the directory where lcrack is running from, or /etc, in that order). The format of the file is like: --<-- charset.txt # charset spec alpha = a-zA-Z alpha-numeric = a-zA-Z0-9 alpha-numeric-symbol14 = a-zA-Z0-9!-/ alpha-space = a-zA-Z\x20 printable = \x20-~ all = \x00-\xff --<-- For example: -s 'A-M0-7aq-z' will 'expand' to the following: '01234567ABCDEFGHIJKLMaqrstuvwxyz' (yes, it's sorted). The '-l' option sets the password lengths that will be checked during the brute-force scan. The syntax is similar to that of the character set, but you must use ',' to separate groups. That is: -l '1,2,4-6,9' will expand to { 1, 2, 4, 5, 6, 9 } By default, the brute-forcing will try, in order, every possible password, using the specified character set and length set. If the '-rand' option is given, the search will try passwords in a random fashion, instead of sequentially. The number of possible passwords will be computed by the program before starting, so it knows how many random passwords it should try, *BUT* this mode will not guarantee that every password is found, because it might happen that some word gets repeated. Alternatively you can provide a regex-like expression, which will (hopefully) reduce the number of passwords to test. Lepton's Crack will enumerate the regular expression, testing each combination. For example: -g 'abc[0-9]z' would try passwords whose first letter is one of { a, b, c }, the second letter is a digit (0-9), and the third, and last[*] letter, is 'z'. You can also use wildcards '[*]', and lcrack will expand them to a combination of symbols taken from the defined character set. In order to use wildcards effectively, you must supply a length parameter (or range), using the '-l' option. The wildcards will expand and compress in a way that the total length is always one of the specified lengths. The enumeration will generate *every* possible combination (ie. nothing will be missed), and in a strictly increasing-length order. There is also support for a regex.txt file, similar to the charset.txt above, so that you can define your favorite regex's there. File format/ -----------/ Each password file (more than one can be specified) contains a user entry in each line. Each entry has the following format: Login:Hash[Comment] Where 'Login' will be the user-name (can be anything, it is not used by the program except in the 'login' mode). 'Hash' is the hexadecimal representation of the password hash. Whatever comes after the hash (':comment', for example) will be silently ignored. Cracking/ --------/ Now, suppose you have a file containing Lotus Domino HTTP password hashes, like this: --<<-- passwd.txt -- abc:24572fa0a43d8203f9b18f0fc3a38bb3:ABC root:0ae0a8c0c7e4761948a6c490cc651395:SECRET Mike:23B3D19CE5790E51457D7D1E36EDCB10:Nekromancer lepton:772a755d7020ed0bcafbc7b0088554b9:lepton1 piru:ae108c3142bac881d0575a372a4f4139:pirul juan:756944e56c60f6f3c7210b698cbf7026:juanjuan --<<-- (Note the use of the 'comment' field to store the actual password, just for convenience :) Now that everything is clear, here's the program output for this simple example: --<<-- $ ./lcrack -m dom -d words -xl+ -xf+ -xb+ -s a-z -l 1-8 passwd.txt xtn: initialized (domino HTTP hash) module loaded: CSET[26] = { abcdefghijklmnopqrstuvwxyz } loaded: LSET[8] = { 1 2 3 4 5 6 7 8 } dbg: loading 'test/dom.test' mode: null password, loaded 6 passwords mode: login single crack, loaded 6 passwords found: login(abc), passwd(ABC) found: login(juan), passwd(juanjuan) found: login(lepton), passwd(lepton1) mode: fast dictionary search, loaded 3 passwords found: login(Mike), passwd(Nekromancer) found: login(root), passwd(SECRET) mode: incremental, loaded 1 password Length = 1, Total = 26 Length = 2, Total = 676 Length = 3, Total = 17576 Length = 4, Total = 456976 Length = 5, Total = 11881376 found: login(piru), passwd(pirul) Lapse: 91.676s, Checked: 8060689, Found: 6/6, Speed: 87925 passwd/s --<<-- Some debugging output is printed on the screen, but technically it goes to 'stderr', so it is safe to redirect 'stdout' to a file to get all passwords there, while everything else (*and* the passwords found) will be displayed on 'stderr'. Performance/ -----------/ Lepton's Crack can check about 90000 Lotus Domino and about 700000 MD4/MD5/NT-MD4 passwords per second using a 850Mhz Pentium III. Notice that the program is written in plain-ANSI C[*], and hopefully coded with optimization in mind :), but that's entirely up to the compiler you use. [*] Not really, it uses gettimeofday(2) and strdup(3). The former is used only for printing the statistics line at the end, and the latter can be trivially implemented using malloc(3) and strcpy(3). Proactive password auditing/ ---------------------------/ Domino administrators will benefit from this program (at least that's what we expect), because they can simply audit their entire NAB in search for bad passwords (i.e. equal to the UserID, dictionary word, etc.) To make it easy to get all the hashes in a file to feed into lcrack, the following LotusScript agent has been contributed. (It has to be put into names.nsf, and will generate a 'hashes.txt' file with the structure " USERID:HASH ", and if something strange is found, for example new R5 hashes or unhashed passwords, they will go to the 'aliens.txt' file. I discovered some unhashed passwords in our names.nsf, and I'm still wondering what happened...) =============================================== Dim session As New notessession Dim db As NotesDatabase Dim view As NotesView Dim doc As NotesDocument Dim user, pass, total As String Dim fileNum As Integer Dim alienfileNum As Integer Dim fileName As String Dim alienfileName As String Set db = session.CurrentDatabase Set view = db.GetView("People") Set doc = view.GetFirstDocument fileNum% = Freefile() fileName$ = "hashes.txt" Open fileName$ For Output As fileNum% alienfileNum% = Freefile() alienfileName$ = "aliens.txt" Open alienfileName$ For Output As alienfileNum% While Not(doc Is Nothing) user = doc.ShortName(0) pass = doc.HTTPPassword(0) If pass = "" Goto siguiente If Len(pass) <> 32 Goto alien total = user & ":" & pass Write #fileNum%, total Goto siguiente alien: total = user & ":" & pass Write #alienfileNum%, total siguiente: Set doc = view.GetNextDocument(doc) Wend Close fileNum% Close alienfileNum% Print "Finished..." =============================================== NOTE: take into account that the program produces THIS: " USERID:PASSWORD " and you need THIS: USERID:PASSWORD so process the file with the filter of your preference ;-) lcrack-20040914/xtn_method.c.out0000644000175000017500000000003407574113224015333 0ustar tiagotiago { (char *)0, 0, 0, 0 } }; lcrack-20040914/regex.c0000644000175000017500000001437110121637655013500 0ustar tiagotiago/* Regular Expression Enumerator (part of Lepton's Crack) Copyright (C) Bernardo Reino (aka Lepton) (lepton@runbox.com) 20040901 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include "global.h" extern int LoadCharSet(const char *set); extern int LoadLenSet(const char *set); extern int LoadRegEx(const char *regex); unsigned long long EnumCount, PasswordCount; int verbose, ordered; /* * K_CHARSET = Vector of characters included in brute-force keyspace * K_CHARSET_LEN = Length of vector * * K_LENSET = Vector of password-lengths to try * K_LENSET_LEN = Length of vector */ BYTE *K_ACTIVE; BYTE K_ASCII[BYTE_MAX], K_CHARSET[BYTE_MAX], K_SYMBOL[BYTE_MAX]; BYTE K_LENSET[MAX_PASS_LEN]; int K_CHARSET_LEN, K_LENSET_LEN; struct regex_t *K_REGEX; int RXMinLength, RXWildCount; volatile int CtrlC; #ifdef __MINGW_H #include void gettimeofday(struct timeval* tp, void *null) { struct timeb tm; ftime(&tm); tp->tv_sec = tm.time; tp->tv_usec = tm.millitm * 1000; } #endif void sig_CtrlC(int q) { CtrlC = 1; /* next CTRL-C will work as usual */ signal(SIGINT, SIG_DFL); } /* * Display a password, where ith-letter is K_CHARSET[stream[i]] */ void print_key(FILE *f, BYTE *stream, unsigned int len) { while(len --) fprintf(f, "%c", K_ACTIVE[(int)*(stream ++)]); } static void rx_enum(int len, int avail, char *prefix, const struct regex_t *rx) { if(CtrlC) return; EnumCount ++; if(rx) { int j; if(rx->wild) { switch(avail) { case 0: /* ignore wildcard */ rx_enum(len, avail, prefix, rx->next); break; default: rx_enum(len, avail, prefix, rx->next); for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum(len + 1, avail - 1, prefix, rx); } } break; } } else { for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum(len + 1, avail, prefix, rx->next); } } } } else { print_key(stdout, prefix, len); printf("\n"); PasswordCount ++; } } static void rx_enum_ordered(int len, int avail, char *prefix, const struct regex_t *rx) { if(CtrlC) return; EnumCount ++; if(rx) { int j; if(rx->wild) { if(avail) { for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum_ordered(len + 1, avail - 1, prefix, rx); } } } rx_enum_ordered(len, avail, prefix, rx->next); } else { for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum_ordered(len + 1, avail, prefix, rx->next); } } } } else { /* rx == null */ if(len && (avail == 0)) { print_key(stdout, prefix, len); printf("\n"); PasswordCount ++; } } } void RegexCrack(void) { char check[MAX_PASS_LEN]; int len_idx, len; K_ACTIVE = K_ASCII; for(len = 0, len_idx = 0; len_idx < K_LENSET_LEN; len_idx ++) if(K_LENSET[len_idx] > len) len = K_LENSET[len_idx]; if(len < RXMinLength) { fprintf(stderr, "(dbg) Len = %d, must be greater than %d.. OK\n", len, RXMinLength); len = RXMinLength; } fprintf(stderr, "(dbg) rx_enum(len = %d)\n", len); if(ordered) { int x; for(x = 0; x <= len - RXMinLength; x ++) rx_enum_ordered(0, x, check, K_REGEX); } else rx_enum(0, len - RXMinLength, check, K_REGEX); } void BeginCrack(void) { struct timeval t0, t1; double lapse; signal(SIGINT, sig_CtrlC); gettimeofday(&t0, NULL); RegexCrack(); gettimeofday(&t1, NULL); lapse = (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec)/1000000.0; if(CtrlC) { fprintf(stderr, "\ngot Ctrl-C signal, exiting...\n"); } /* verbose? */ #ifdef __MINGW_H fprintf(stderr, "Lapse: %.5gs, Checked: %I64u, Enum: %I64u, Speed: %I64u passwd/s\n", lapse, PasswordCount, EnumCount, (unsigned long long)((double)PasswordCount / lapse)); #else fprintf(stderr, "Lapse: %.5gs, Checked: %llu, Enum: %llu, Speed: %llu passwd/s\n", lapse, PasswordCount, EnumCount, (unsigned long long)((double)PasswordCount / lapse)); #endif signal(SIGINT, SIG_DFL); } void usage(int e, char *prog) { FILE *f = e ? stderr : stdout; fprintf(f, "usage: %s [-q | -v] " "-s -g -l \n", prog); exit(e); } int main(int argc, char **argv) { char *default_set = "a-z0-9"; char *default_len = "1-8"; char *default_regex = NULL; int j; K_REGEX = NULL; CtrlC = 0; verbose = 1; ordered = 1; for(j = 1; j < argc; j ++) { if(!strcmp(argv[j], "-s")) { default_set = argv[++ j]; } else if(!strcmp(argv[j], "-l")) { default_len = argv[++ j]; } else if(!strcmp(argv[j], "-g")) { default_regex = argv[++ j]; } else if(!strcmp(argv[j], "-g#")) { default_regex = argv[++ j]; ordered = 0; } else if(!strcmp(argv[j], "-q")) { verbose = 0; } else if(!strcmp(argv[j], "-v")) { verbose = 1; } else if(!strcmp(argv[j], "-h")) { usage(0, argv[0]); } else { usage(1, argv[0]); } } if(LoadCharSet(default_set) == -1) exit(3); if(LoadLenSet(default_len) == -1) exit(4); if(default_regex) { if(LoadRegEx(default_regex) == -1) exit(5); } else usage(2, argv[0]); for(j = 0; j < sizeof(K_ASCII); j ++) K_ASCII[j] = j; BeginCrack(); return 0; } lcrack-20040914/mod_md4.h0000644000175000017500000000037210115662542013706 0ustar tiagotiago/* Standard MD4 implementation Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_def.h" int xtn_md4_init(void); int xtn_md4_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1); CODE_BLOCK_PTR xtn_md4_crypt(char *passwd, int len, BYTE *CMAP); lcrack-20040914/key.c0000644000175000017500000001107310121647441013144 0ustar tiagotiago/* * Cracking Engine * Copyright (C) Bernardo Reino (aka Lepton) (lepton@runbox.com) * 20021120 * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #include "global.h" #include #include #include #include void KEY_text(BYTE *stream, char *dst, unsigned int len) { while(len --) *(dst ++) = K_CHARSET[(int)*(stream ++)]; } /* * Check if Hash(K) matches a Hash from the Password List */ int KEY_find(char *K, int K_Len, CODE_BLOCK_PTR H) { PasswordElement *ptr; BYTE mod_index; unsigned int found; found = 0; PasswordCount ++; mod_index = H[0] & 0xff; for(ptr = PasswordList[mod_index].next; ptr; ptr = ptr->next) if(*ptr->login && xtn_cmp(H, ptr->data)) { if(verbose) { fprintf(stderr, "found: login(%s), passwd(", ptr->login); print_key(stderr, K, K_Len); fprintf(stderr, ")\n"); } if(pot_file || !verbose) { fprintf(pot, "%s:", ptr->login); print_key(pot, K, K_Len); fprintf(pot, "\n"); } ptr->login[0] = '\0'; /* mark login as cracked.. */ PasswordLeft --; found ++; //return 1; } return found; } void KEY_zero(BYTE *K, unsigned int Len) { while(Len --) *(K ++) = 0; } signed int KEY_next(BYTE *K, unsigned int Len) { signed int j = Len - 1; while(j >= 0) { if(++ K[j] >= K_CHARSET_LEN) { K[j --] = 0; } else break; } return j; } void KEY_rand(BYTE *K, unsigned int Len) { unsigned int j; for(j = 0; j < Len; j ++) { K[j] = rand() % K_CHARSET_LEN; } } /* * compute hash(passwd) and search in the list.. */ int KEY_cmp(char *passwd, int len) { CODE_BLOCK_PTR R; R = xtn_crypt(passwd, len, K_ACTIVE); return KEY_find(passwd, len, R); } int KEY_word(char *passwd, int len, int xtd) { static char sym_tbl[] = " 0123456789^!\"$%&/()=?'`+-*{}[]#.,;:_-~<>|@"; static int sym_len = sizeof(sym_tbl); char aux[MAX_PASS_LEN+1]; int j; strncpy(aux, passwd, MAX_PASS_LEN); aux[MAX_PASS_LEN] = '\0'; if(KEY_cmp(aux, len)) return 1; for(j = 0; j < len; j ++) aux[j] = tolower(aux[j]); if(KEY_cmp(aux, len)) return 1; aux[0] = toupper(aux[0]); if(KEY_cmp(aux, len)) return 1; for(j = 0; j < len; j ++) aux[j] = toupper(aux[j]); if(KEY_cmp(aux, len)) return 1; if((xtd) && (len < MAX_PASS_LEN - 1)) { int i; strncpy(aux, passwd, MAX_PASS_LEN); aux[MAX_PASS_LEN] = '\0'; /* prefix symbol */ aux[len + 1] = '\0'; for(i = 0; i < sym_len; i ++) { aux[len] = sym_tbl[i]; if(KEY_word(aux, len+1, 0)) /* recursive */ return 1; } /* suffix symbol */ memcpy(aux + 1, passwd, len); for(i = 0; i < sym_len; i ++) { aux[0] = sym_tbl[i]; if(KEY_word(aux, len+1, 0)) /* recursive */ return 1; } } return 0; } int KEY_login(char *passwd, int len, int xtd) { static char sym_tbl[] = "0123456789^!\"$%&/()=?'`+-*{}[]#.,;:_-~<>|@"; static int sym_len = sizeof(sym_tbl); char aux[MAX_PASS_LEN+1]; int j; strncpy(aux, passwd, MAX_PASS_LEN); aux[MAX_PASS_LEN] = '\0'; if(KEY_cmp(aux, len)) return 1; for(j = 0; j < len; j ++) aux[j] = tolower(aux[j]); if(KEY_cmp(aux, len)) return 1; aux[0] = toupper(aux[0]); if(KEY_cmp(aux, len)) return 1; for(j = 0; j < len; j ++) aux[j] = toupper(aux[j]); if(KEY_cmp(aux, len)) return 1; if((xtd) && (len < MAX_PASS_LEN - 1)) { int i; /* prefix symbol */ aux[len + 1] = '\0'; for(i = 0; i < sym_len; i ++) { aux[len] = sym_tbl[i]; if(KEY_login(aux, len+1, 0)) return 1; } /* suffix symbol */ memcpy(aux + 1, passwd, len); for(i = 0; i < sym_len; i ++) { aux[0] = sym_tbl[i]; if(KEY_login(aux, len+1, 0)) return 1; } } if((xtd) && (2*len < MAX_PASS_LEN - 1)) { /* double login */ strcpy(aux, passwd); strcat(aux, passwd); if(KEY_login(aux, 2*len, 0)) return 1; } return 0; } lcrack-20040914/charset.txt0000644000175000017500000000034010121642702014370 0ustar tiagotiago# charset spec alpha = a-zA-Z alpha-numeric = a-zA-Z0-9 alpha-numeric-symbol14 = a-zA-Z0-9!-/ alpha-space = a-zA-Z\x20 printable = \x20-~ all = \x00-\xff lcrack-20040914/xtn_def.h0000644000175000017500000000133510121637556014016 0ustar tiagotiago/* Cracking Engine Copyright (C) Bernardo Reino (aka Lepton) (lepton@runbox.com) 20021119 */ #ifndef __XTN_DEF__ #define __XTN_DEF__ /* * Maximum size for a hash/encrypted password */ #include #define MAX_CODE_LEN 64 #define MAX_PASS_LEN 16 typedef unsigned char BYTE; #define BYTE_MAX (2 << CHAR_BIT) typedef BYTE* CODE_BLOCK_PTR; typedef BYTE CODE_BLOCK; typedef CODE_BLOCK_PTR (*xtn_crypt_t)(char *, int, BYTE *); typedef int (*xtn_cmp_t)(CODE_BLOCK_PTR, CODE_BLOCK_PTR); extern xtn_crypt_t xtn_crypt; extern xtn_cmp_t xtn_cmp; struct xtn_module_t { char *xtn_text; int (*xtn_init)(void); xtn_cmp_t xtn_check; xtn_crypt_t xtn_function; }; extern struct xtn_module_t xtn_all[]; #endif lcrack-20040914/base64.c0000644000175000017500000000430607616237337013457 0ustar tiagotiago#include /* * Quick & dirty base64 handling stuff. Currently not used by any * of the modules, but provided if needed. * * NOTE: Not tested, seems to work, but might not handle weird * situations, so use only if you're really lazy to do it yourself :) * * Bernardo Reino (aka Lepton) * 20021120 * */ char tbl64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; int idx64(unsigned char x) { int i; if(x == '=') return 0; for(i = 0; i < sizeof(tbl64); i ++) if(tbl64[i] == x) return i; return 0xff; } char *base64_encode(unsigned char *s_in, unsigned long s_len) { unsigned long g24; unsigned long buf_len; unsigned char *buf64, *ptr64; buf_len = (4 * (s_len + 2)/3) + 1; ptr64 = buf64 = calloc(1, buf_len); while(s_len > 2) { g24 = (s_in[0] << 16) + (s_in[1] << 8) + s_in[2]; ptr64[0] = tbl64[(g24 >> 18) & 0x3f]; ptr64[1] = tbl64[(g24 >> 12) & 0x3f]; ptr64[2] = tbl64[(g24 >> 6) & 0x3f]; ptr64[3] = tbl64[(g24 & 0x3f)]; ptr64 += 4; s_in += 3; s_len -= 3; } switch(s_len) { case 2: g24 = (s_in[0] << 16) + (s_in[1] << 8); ptr64[0] = tbl64[(g24 >> 18) & 0x3f]; ptr64[1] = tbl64[(g24 >> 12) & 0x3f]; ptr64[2] = tbl64[(g24 >> 6) & 0x3f]; ptr64[3] = '='; ptr64 += 4; break; case 1: g24 = (s_in[0] << 16); ptr64[0] = tbl64[(g24 >> 18) & 0x3f]; ptr64[1] = tbl64[(g24 >> 12) & 0x3f]; ptr64[2] = '='; ptr64[3] = '='; ptr64 += 4; break; } *ptr64 = '\0'; return (char *)buf64; } char *base64_decode(char *s_in, int s_len, int *o_len) { unsigned int c0, c1, c2, c3; unsigned char *buf8, *ptr8, *s_idx; s_idx = calloc(1, s_len + 1); for(c0 = 0; c0 < s_len; c0 ++) { if((s_idx[c0] = idx64(s_in[c0])) == 0xff) return NULL; } *o_len = (s_len/4) * 3 + 1; ptr8 = buf8 = calloc(1, *o_len); while(s_len >= 4) { c0 = s_idx[0]; c1 = s_idx[1]; c2 = s_idx[2]; c3 = s_idx[3]; ptr8[0] = (c0 << 2) | (c1 >> 4); ptr8[1] = ((c1 & 0x0f) << 4) | (c2 >> 2); ptr8[2] = ((c2 & 0x3) << 6) | c3; ptr8 += 3; s_in += 4; s_len -= 4; } *ptr8 = '\0'; free(s_idx); return (char *)buf8; } lcrack-20040914/CHANGES0000644000175000017500000000425110121646660013205 0ustar tiagotiago20040914/ - Added support for any ASCII character (ie. also non-printable) in the charset and regex definition, via \0(octal), \x(hex), \(decimal) 20040912/ - Added support for a user-generated charset.txt and regex.txt file that can be used for storing common charsets and regex's. - Minor optimization to mod_dom.c (domino HTTP hash) 20040902/ - I'm back.. ;) - Regex's are now enumerated in order of increasing length, so that shorter passwords are found much faster, without having to 'zig-zag' through all the lenset (which is the 'natural' way for my algorithm..) - A separate program, called 'regex' enumerates passwords (using same syntax as lcrack, ie. -s, -g, -l) and prints them on stdout. This program can be used stand-alone, or in combination with lcrack's 'stdin' mode.. - Included 'mkword' utility, which will extract words form any given input (stdin). Useful for creating dictionaries.. 20030401/ - Regex's support variable-length wildcards, so things like [qwas][*][0-9] will try every password starting with one of { q w a s }, ending with a digit, and having anything else in the middle (based on whatever charset/lenset has been specified, of course..) - In case I didn't say it, there is a special mode, called 'stdin' (ie. lcrack -stdin ..) which will allow lcrack to be provided with passwords to try from an external program, via a pipe, eg. password_generator | lcrack -m nt4 -stdin hashes.txt This way lcrack's power can be extended arbitrarily without touching the code. 20030325/ - Added experimental support for regex enumeration (for use in brute-forcing, when you have partial knowledge of the key) Read README.devel.regex for more information 20030324/ - Added check for null passwords. It happens too often, so I had to account for that :) 20021231/ - Added SHA-1 module. Thanks to Burcin Erocal. - Hmm, and I wish everyone a happy new year! ;) 20021216/ - Minor optimization (~ 2%) of the Lotus Domino hash calculation. 20021215/ - Bug-fix. If a password was repeated in the input file, only one of them was found. 20021211/ - v1.0 is finished. - Support for Domino HTTP passwords (R4), MD4, MD5, and NT (MD4/Unicode). lcrack-20040914/engine.c0000644000175000017500000005127610121645104013624 0ustar tiagotiago/* Cracking Engine Copyright (C) Bernardo Reino (aka Lepton) (lepton@runbox.com) 20021120-20040902 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include "xtn_def.h" #include "xtn_method.h" #include "global.h" extern char *LoadExternalSpec(const char *me, const char *file, const char *spec); extern int LoadCharSet(const char *set); extern int LoadLenSet(const char *set); extern int LoadRegEx(const char *regex); xtn_cmp_t xtn_cmp; xtn_crypt_t xtn_crypt; /* * Linked List used for storing dictionary files (just the filename) */ typedef struct FileList_t { char *data; struct FileList_t *next; } FileList; /* * Linked List for storing pairs login/hash (read from input file) */ PasswordElement PasswordList[BYTE_MAX]; /* * PasswordCount = Number of passwords processed * PasswordTotal = Number of passwords to crack (input file) * PasswordLeft = Number of passwords not cracked */ unsigned long long PasswordCount; /* who knows? :) */ int PasswordTotal, PasswordLeft; FILE *pot; int pot_file, verbose; int do_login, do_fast, do_smart, do_scan; int rand_mode, stdin_mode; int rx_ordered; /* * K_CHARSET = Vector of characters included in brute-force keyspace * K_CHARSET_LEN = Length of vector * * K_LENSET = Vector of password-lengths to try * K_LENSET_LEN = Length of vector */ BYTE *K_ACTIVE; BYTE K_ASCII[BYTE_MAX], K_CHARSET[BYTE_MAX], K_SYMBOL[BYTE_MAX]; BYTE K_LENSET[MAX_PASS_LEN]; int K_CHARSET_LEN, K_LENSET_LEN; struct regex_t *K_REGEX; int RXMinLength, RXWildCount; volatile int CtrlC; #ifdef __MINGW_H #include void gettimeofday(struct timeval* tp, void *null) { struct timeb tm; ftime(&tm); tp->tv_sec = tm.time; tp->tv_usec = tm.millitm * 1000; } #endif void sig_CtrlC(int q) { CtrlC = 1; /* next CTRL-C will work as usual */ signal(SIGINT, SIG_DFL); } /* * Hexa display of 'stream', size = len. */ void print_hex(FILE *f, BYTE *stream, unsigned int len) { while(len --) fprintf(f, "%02x", *(stream ++)); } /* * Display a password, where ith-letter is K_CHARSET[stream[i]] */ void print_key(FILE *f, BYTE *stream, unsigned int len) { while(len --) { int ch = K_ACTIVE[(int)*(stream ++)]; if(isprint(ch)) fprintf(f, "%c", ch); else fprintf(f, "\\x%02x", ch); } } void LoginCrack(void) { PasswordElement *pwd; char *line; time_t t0, t1; int mod_index; K_ACTIVE = K_ASCII; t0 = 0; for(mod_index = 0; mod_index < BYTE_MAX; mod_index ++) { if(CtrlC || (PasswordLeft == 0)) break; for(pwd = PasswordList[mod_index].next; pwd; pwd = pwd->next) { if(CtrlC || (PasswordLeft == 0)) break; line = pwd->login; if(strlen(line) >= MAX_PASS_LEN) continue; if(verbose && ((t1 = time(NULL)) > t0)) { fprintf(stderr, " \r" "KEY: %s\r", line); fflush(stderr); t0 = t1; } KEY_login(line, strlen(line), 1); } } } void TableCrack(FileList *tbl) { struct elem { char word[16]; BYTE hash[16]; } next; time_t t0, t1; FileList *dptr; K_ACTIVE = K_ASCII; t0 = 0; dptr = tbl->next; for(dptr = tbl->next; (! CtrlC) && PasswordLeft && (dptr) && (dptr->data); dptr = dptr->next) { FILE *fp = fopen(dptr->data, "rb"); if(fp == NULL) { perror(dptr->data); continue; } while((! CtrlC) && PasswordLeft && fread(&next, sizeof(next), 1, fp)) { if(verbose && ((t1 = time(NULL)) > t0)) { fprintf(stderr, " \r" "KEY: %s\r", next.word); fflush(stderr); t0 = t1; } KEY_find(next.word, strlen(next.word), next.hash); } fclose(fp); } } void DictionaryCrack(FileList *dict, int round) { char line[128]; time_t t0, t1; FileList *dptr; K_ACTIVE = K_ASCII; t0 = 0; dptr = dict->next; for(dptr = dict->next; (! CtrlC) && PasswordLeft && (dptr) && (dptr->data); dptr = dptr->next) { FILE *fp = fopen(dptr->data, "rt"); if(fp == NULL) { perror(dptr->data); continue; } while((! CtrlC) && PasswordLeft && fgets(line, 128, fp)) { char *ptr; if((ptr = strrchr(line, '\n')) != NULL) *ptr = '\0'; if((ptr = strrchr(line, '\r')) != NULL) *ptr = '\0'; if(strlen(line) >= MAX_PASS_LEN) continue; if(verbose && ((t1 = time(NULL)) > t0)) { fprintf(stderr, " \r" "KEY: %s\r", line); fflush(stderr); t0 = t1; } KEY_word(line, strlen(line), round); } fclose(fp); } } void stdinCrack(void) { char line[128]; time_t t0, t1; int tty; K_ACTIVE = K_ASCII; t0 = 0; tty = isatty(0); while((! CtrlC) && PasswordLeft && fgets(line, 128, stdin)) { char *ptr; if((ptr = strrchr(line, '\n')) != NULL) *ptr = '\0'; if((ptr = strrchr(line, '\r')) != NULL) *ptr = '\0'; if(strlen(line) >= MAX_PASS_LEN) continue; if(verbose && !tty && ((t1 = time(NULL)) > t0)) { fprintf(stderr, " \r" "KEY: %s\r", line); fflush(stderr); t0 = t1; } KEY_word(line, strlen(line), 0); } } static void rx_enum(int len, int avail, char *prefix, const struct regex_t *rx, time_t *t0) { if(CtrlC || (PasswordLeft == 0)) return; if(rx) { int j; if(rx->wild) { switch(avail) { case 0: /* ignore wildcard */ rx_enum(len, avail, prefix, rx->next, t0); break; default: rx_enum(len, avail, prefix, rx->next, t0); for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum(len + 1, avail - 1, prefix, rx, t0); } } break; } } else { for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum(len + 1, avail, prefix, rx->next, t0); } } } } else { time_t t1; if(verbose && ((t1 = time(NULL)) > *t0)) { fprintf(stderr, "KEY: "); print_key(stderr, prefix, len); fprintf(stderr, "\r"); fflush(stderr); *t0 = t1; } KEY_cmp(prefix, len); } } static void rx_enum_ordered(int len, int avail, char *prefix, const struct regex_t *rx, time_t *t0) { if(CtrlC || (PasswordLeft == 0)) return; if(rx) { int j; if(rx->wild) { if(avail) { for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum_ordered(len + 1, avail - 1, prefix, rx, t0); } } } rx_enum_ordered(len, avail, prefix, rx->next, t0); } else { for(j = 0; j < BYTE_MAX; j ++) { if(rx->symbol[j] > 0) { prefix[len] = j; rx_enum_ordered(len + 1, avail, prefix, rx->next, t0); } } } } else if(len && (avail == 0)) { time_t t1; if(verbose && ((t1 = time(NULL)) > *t0)) { fprintf(stderr, "KEY: "); print_key(stderr, prefix, len); fprintf(stderr, "\r"); fflush(stderr); *t0 = t1; } KEY_cmp(prefix, len); } } void RegexCrack(void) { char check[MAX_PASS_LEN]; time_t t0; int len_idx, len; K_ACTIVE = K_ASCII; for(len = 0, len_idx = 0; len_idx < K_LENSET_LEN; len_idx ++) if(K_LENSET[len_idx] > len) len = K_LENSET[len_idx]; if(len < RXMinLength) { fprintf(stderr, "(dbg) Len = %d, must be greater than %d.. OK\n", len, RXMinLength); len = RXMinLength; } fprintf(stderr, "(dbg) rx_enum(len = %d)\n", len); t0 = time(NULL); if(rx_ordered) { int x; for(x = 0; x <= len - RXMinLength; x ++) rx_enum_ordered(0, x, check, K_REGEX, &t0); } else rx_enum(0, len - RXMinLength, check, K_REGEX, &t0); } void PasswordCrack(void) { BYTE check[MAX_PASS_LEN]; unsigned long long len_max; int len_idx, len; time_t t0, t1; K_ACTIVE = K_CHARSET; t0 = 0; for(len_idx = 0; (! CtrlC) && PasswordLeft && (len_idx < K_LENSET_LEN); len_idx ++) { len = K_LENSET[len_idx]; { unsigned int j; for(len_max = 1, j = 0; j < len; j ++) len_max *= K_CHARSET_LEN; } if(verbose) #ifdef __MINGW_H fprintf(stderr, "Length = %d, Total = %I64u\n", #else fprintf(stderr, "Length = %d, Total = %llu\n", #endif len, len_max); KEY_zero(check, len); while((! CtrlC) && PasswordLeft) { if(verbose && ((t1 = time(NULL)) > t0)) { fprintf(stderr, "KEY: "); print_key(stderr, check, len); #ifdef __MINGW_H fprintf(stderr, ", R = %I64u\r", len_max); #else fprintf(stderr, ", R = %llu\r", len_max); #endif fprintf(stderr, "\r"); fflush(stderr); t0 = t1; } KEY_cmp((char *)check, len); len_max --; if(KEY_next(check, len) < 0) break; } } } void RandomCrack(void) { BYTE check[MAX_PASS_LEN]; unsigned long long len_max; int len_idx, len; time_t t0, t1; K_ACTIVE = K_CHARSET; t0 = 0; for(len_idx = 0; (! CtrlC) && PasswordLeft && (len_idx < K_LENSET_LEN); len_idx ++) { len = K_LENSET[len_idx]; { unsigned int j; for(len_max = 1, j = 0; j < len; j ++) len_max *= K_CHARSET_LEN; } if(verbose) #ifdef __MINGW_H fprintf(stderr, "Length = %d, Total = %I64u\n", #else fprintf(stderr, "Length = %d, Total = %llu\n", #endif len, len_max); while((! CtrlC) && PasswordLeft && len_max) { KEY_rand(check, len); if(verbose && ((t1 = time(NULL)) > t0)) { fprintf(stderr, "KEY: "); print_key(stderr, check, len); #ifdef __MINGW_H fprintf(stderr, ", R = %I64u\r", len_max); #else fprintf(stderr, ", R = %llu\r", len_max); #endif fflush(stderr); t0 = t1; } KEY_cmp((char *)check, len); len_max --; } } } signed int hex(char x) { if((x >= '0') && (x <= '9')) return (x - '0'); else if((x >= 'A') && (x <= 'F')) return (x - 'A' + 10); else if((x >= 'a') && (x <= 'f')) return (x - 'a' + 10); return -1; } void LoadInput(FileList *pwd_file) { PasswordElement *ptrLinked[BYTE_MAX]; char line[1024]; int mod_index; for(mod_index = 0; mod_index < BYTE_MAX; mod_index ++) ptrLinked[mod_index] = &PasswordList[mod_index]; PasswordTotal = 0; while(pwd_file->next) { FILE *fp; pwd_file = pwd_file->next; fprintf(stderr, "dbg: loading '%s'\n", pwd_file->data); fp = fopen(pwd_file->data, "rt"); if(fp) { while(fgets(line, 1024, fp)) { int i, j, pwlen, len; char *user, *passwd, *ptr; BYTE hash8[MAX_CODE_LEN]; for(ptr = line; *ptr && isspace(*ptr); ptr ++) ; for(user = ptr ++; *ptr && *ptr != ':'; ptr ++) ; *(ptr ++) = '\0'; for(passwd = ptr; *ptr && isxdigit(*ptr); ptr ++) ; *(ptr ++) = '\0'; pwlen = strlen(passwd); for(len = 0, i = 0; i < pwlen; i += 2, len ++) { if((j = hex(passwd[i])) < 0) goto _format; hash8[len] = ((j & 0xf) << 4); if((j = hex(passwd[i+1])) < 0) goto _format; hash8[len] += (j & 0x0f); } goto _next; _format: fprintf(stderr, "%s: bad hexadecimal character\n", passwd); continue; _next: mod_index = hash8[0] & 0xff; ptrLinked[mod_index]->next = calloc(1, sizeof(PasswordElement)); ptrLinked[mod_index] = ptrLinked[mod_index]->next; ptrLinked[mod_index]->login = strdup(user); memcpy(ptrLinked[mod_index]->data, hash8, len); ptrLinked[mod_index]->next = NULL; PasswordTotal ++; } fclose(fp); } else perror(pwd_file->data); } } void BeginCrack(FileList *tbl, FileList *dict) { struct timeval t0, t1; double lapse; signal(SIGINT, sig_CtrlC); PasswordLeft = PasswordTotal; gettimeofday(&t0, NULL); if(!CtrlC && PasswordLeft) { if(verbose) fprintf(stderr, "mode: null password, loaded %d password%s\n", PasswordLeft, PasswordLeft > 1 ? "s" : ""); KEY_cmp("", 0); } if(do_login && !CtrlC && PasswordLeft) { if(verbose) fprintf(stderr, "mode: login single crack, loaded %d password%s\n", PasswordLeft, PasswordLeft > 1 ? "s" : ""); LoginCrack(); } if(stdin_mode) { if(verbose) fprintf(stderr, "mode: stdin search, loaded %d password%s\n", PasswordLeft, PasswordLeft > 1 ? "s" : ""); stdinCrack(); } if(do_fast && !CtrlC && PasswordLeft && tbl->next) { if(verbose) fprintf(stderr, "mode: fast pre-computed table, loaded %d password%s\n", PasswordLeft, PasswordLeft > 1 ? "s" : ""); TableCrack(tbl); } if(do_fast && !CtrlC && PasswordLeft && dict->next) { if(verbose) fprintf(stderr, "mode: fast dictionary search, loaded %d password%s\n", PasswordLeft, PasswordLeft > 1 ? "s" : ""); DictionaryCrack(dict, 0); } if(do_smart && !CtrlC && PasswordLeft && dict->next) { if(verbose) fprintf(stderr, "mode: smart dictionary search, loaded %d password%s\n", PasswordLeft, PasswordLeft > 1 ? "s" : ""); DictionaryCrack(dict, 1); } if(do_scan && !CtrlC && PasswordLeft) { if(verbose) fprintf(stderr, "mode: incremental%s, loaded %d password%s\n", K_REGEX ? (rx_ordered ? " (regex, ordered)" : " (regex)") : rand_mode ? " (random)" : "", PasswordLeft, PasswordLeft > 1 ? "s" : ""); if(K_REGEX) RegexCrack(); else if(rand_mode) RandomCrack(); else PasswordCrack(); } gettimeofday(&t1, NULL); lapse = (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec)/1000000.0; if(CtrlC) { fprintf(stderr, "\ngot Ctrl-C signal, exiting...\n"); } /* verbose? */ #ifdef __MINGW_H fprintf(stderr, "Lapse: %.5gs, Checked: %I64u, Found: %d/%d, Speed: %I64u passwd/s\n", lapse, PasswordCount, PasswordTotal - PasswordLeft, PasswordTotal, (unsigned long long)((double)PasswordCount / lapse)); #else fprintf(stderr, "Lapse: %.5gs, Checked: %llu, Found: %d/%d, Speed: %llu passwd/s\n", lapse, PasswordCount, PasswordTotal - PasswordLeft, PasswordTotal, (unsigned long long)((double)PasswordCount / lapse)); #endif signal(SIGINT, SIG_DFL); } void banner(void) { fprintf(stderr, "-= [ Lepton's Crack ] =- Password Cracker [%s]\n", __DATE__); fprintf(stderr, "(C) Bernardo Reino (aka Lepton) \n"); fprintf(stderr, " and Miguel Dilaj (aka Nekromancer) \n"); fprintf(stderr, "\n"); } void usage(int e, char *prog) { FILE *f = e ? stderr : stdout; struct xtn_module_t *xtn_ptr; fprintf(f, "usage: %s [-q | -v] -m [] ..\n", prog); fprintf(f, " -o : output password file\n"); fprintf(f, " -d : use word list from \n"); fprintf(f, " -t : use pre-computed word list from \n"); fprintf(f, " -s : use specified charset for incremental\n"); fprintf(f, " -s# : use charset from charset.txt file\n"); fprintf(f, " -l : use specified length-set for incremental\n"); fprintf(f, " -g : enumerate regex for incremental\n"); fprintf(f, " -g# : use regex from regex.txt file\n"); fprintf(f, " -x[+|-] : activate/deactivate specified mode\n"); fprintf(f, " mode = l : login mode\n"); fprintf(f, " mode = f : fast word list mode\n"); fprintf(f, " mode = s : smart word list mode\n"); fprintf(f, " mode = b : incremental (brute-force) mode\n"); fprintf(f, " -stdin : stdin (external) mode\n"); fprintf(f, " -rand : randomized brute-force mode\n"); fprintf(f, " -h : display usage information and exit\n"); fprintf(f, " : hash algorithm, one of:\n"); fprintf(f, " { "); for(xtn_ptr = &xtn_all[0]; xtn_ptr->xtn_text; xtn_ptr ++) { fprintf(f, "'%s' ", xtn_ptr->xtn_text); } fprintf(f, "}\n"); exit(e); } int main(int argc, char **argv) { char * default_cipher = NULL; char * default_set = "a-z0-9"; char * default_len = "1-8"; char * default_regex = NULL; char * external_set = NULL; char * external_regex = NULL; FileList *tbl_file, *tbl_ptr; FileList *dict_file, *dict_ptr; FileList *pwd_file, *pwd_ptr; struct xtn_module_t *xtn_ptr; int j, files = 0; banner(); srand((unsigned int)time(NULL)); tbl_ptr = tbl_file = calloc(1, sizeof(FileList)); dict_ptr = dict_file = calloc(1, sizeof(FileList)); pwd_ptr = pwd_file = calloc(1, sizeof(FileList)); K_REGEX = NULL; CtrlC = 0; pot = stdout; pot_file = 0; verbose = 1; xtn_crypt = NULL; xtn_cmp = NULL; do_login = 0; do_fast = 0; do_smart = 0; do_scan = 0; stdin_mode = 0; rx_ordered = 1; for(j = 1; j < argc; j ++) { if(!strcmp(argv[j], "-m")) { default_cipher = argv[++ j]; } else if(!strcmp(argv[j], "-stdin")) { stdin_mode = 1; } else if(!strcmp(argv[j], "-d")) { dict_ptr->next = calloc(1, sizeof(*dict_ptr)); dict_ptr = dict_ptr->next; dict_ptr->data = strdup(argv[++ j]); dict_ptr->next = NULL; } else if(!strcmp(argv[j], "-t")) { tbl_ptr->next = calloc(1, sizeof(*tbl_ptr)); tbl_ptr = tbl_ptr->next; tbl_ptr->data = strdup(argv[++ j]); tbl_ptr->next = NULL; } else if(!strcmp(argv[j], "-s")) { default_set = argv[++ j]; } else if(!strcmp(argv[j], "-s#")) { external_set = LoadExternalSpec(argv[0], "charset.txt", argv[++ j]); if(external_set) { default_set = external_set; } } else if(!strcmp(argv[j], "-l")) { default_len = argv[++ j]; } else if(!strcmp(argv[j], "-g")) { default_regex = argv[++ j]; rx_ordered = 1; } else if(!strcmp(argv[j], "-g#")) { external_regex = LoadExternalSpec(argv[0], "regex.txt", argv[++ j]); if(external_regex) { default_regex = external_regex; rx_ordered = 1; } } else if(!strcmp(argv[j], "-q")) { verbose = 0; } else if(!strcmp(argv[j], "-v")) { verbose = 1; } else if(!strcmp(argv[j], "-o")) { pot = fopen(argv[++ j], "at"); if(pot == NULL) { perror(argv[j]); exit(2); } else pot_file = 1; } else if(!strcmp(argv[j], "-h")) { usage(0, argv[0]); } else if(!strcmp(argv[j], "-rand")) { rand_mode = 1; } else if(!strncmp(argv[j], "-x", 2) && (strlen(argv[j]) > 3)) { int what = argv[j][2]; int mode = argv[j][3]; switch(mode) { case '+': mode = 1; break; case '-': mode = 0; break; default: usage(1, argv[0]); } switch(what) { case 'l': do_login = mode; break; case 'f': do_fast = mode; break; case 's': do_smart = mode; break; case 'b': do_scan = mode; break; default: usage(1, argv[0]); } } else if(argv[j][0] == '-') { usage(1, argv[0]); } else { pwd_ptr->next = calloc(1, sizeof(*pwd_ptr)); pwd_ptr = pwd_ptr->next; pwd_ptr->data = strdup(argv[j]); pwd_ptr->next = NULL; files ++; } } if((default_cipher == NULL) || (default_cipher[0] == '\0')) { fprintf(stderr, "%s: method must be specified (-m), exiting..\n", argv[0]); usage(1, argv[0]); } for(xtn_ptr = &xtn_all[0]; xtn_ptr->xtn_text; xtn_ptr ++) { if(!strcmp(default_cipher, xtn_ptr->xtn_text)) { xtn_ptr->xtn_init(); xtn_cmp = xtn_ptr->xtn_check; xtn_crypt = xtn_ptr->xtn_function; } } if(xtn_crypt == NULL) { fprintf(stderr, "%s: method '%s' not implemented, exiting..\n", argv[0], default_cipher); usage(3, argv[0]); } if(rand_mode && !do_scan) { fprintf(stderr, "%s: random mode set, but incremental not used, ignoring..\n", argv[0]); } if(LoadCharSet(default_set) == -1) exit(4); if(LoadLenSet(default_len) == -1) exit(5); if(default_regex) { if(LoadRegEx(default_regex) == -1) exit(6); } for(j = 0; j < sizeof(K_ASCII); j ++) K_ASCII[j] = j; if(files == 0) { fprintf(stderr, "%s: need at least one input file!\n", argv[0]); usage(1, argv[0]); } LoadInput(pwd_file); BeginCrack(tbl_file, dict_file); if(pot_file && pot) fclose(pot); if(external_set) free(external_set); if(external_regex) free(external_regex); return 0; } lcrack-20040914/configure0000755000175000017500000001345510121654113014117 0ustar tiagotiago#!/bin/sh Makefile=Makefile if [ -f $Makefile ]; then make clean rm -f $Makefile fi # detect compiler if [ -z "$CC" ]; then for COMPILER in gcc cc icc pgcc ; do AUX=`which $COMPILER 2>/dev/null` if [ $? -eq 0 -a -n "$AUX" ]; then CC=$COMPILER; break; fi done fi if [ -z "$CC" ]; then echo $0: compiler not found, please set the CC environment variable exit 1 fi AUX=`which $CC 2>/dev/null` echo dbg: $CC compiler found, at $AUX XFLAGS= case $CC in gcc*) VERSION=`$CC -v 2>&1 | tail -1 | cut -d" " -f3 2> /dev/null` case $VERSION in 3\.*) echo "dbg: GNU $VERSION compiler detected" if [ -z "$1" ]; then echo "Please select your CPU, one of {" echo " pentium, pentium-mmx, pentiumpro, pentium2, " echo " pentium3, pentium4, k6, k6-2, k6-3, athlon, " echo " athlon-tbird, athlon-4, athlon-xp, athlon-mp" echo -n "} = " read ARCH else ARCH=$1 fi ARCHOPT="-march=$ARCH" case $ARCH in pentium4) CPUFLAGS="-msse2";; pentium2|pentium3) CPUFLAGS="-msse";; pentiumpro) CPUFLAGS="-mmmx";; pentium-mmx) CPUFLAGS="-mmmx";; pentium) CPUFLAGS="";; athlon*) CPUFLAGS="-m3dnow";; k6*) CPUFLAGS="";; *) echo "don't know how to deal with that CPU, no problem.." CPUFLAGS= ARCHOPT= ;; esac XFLAGS="-O9 -Wall -fomit-frame-pointer -funroll-loops -minline-all-stringops -maccumulate-outgoing-args -finline-functions -fstrict-aliasing $ARCHOPT $CPUFLAGS" ;; 2\.*) echo "dbg: GNU $VERSION compiler detected" if [ -z "$1" ]; then echo "Please select your CPU, one of {" echo " i386, i486, i586 = pentium, i686 = pentiumII, k6" echo -n "} = " read ARCH else ARCH=$1 fi case $ARCH in i[3456]86) ;; pentium[234]) ARCH="i686";; pentium) ARCH="i586";; k6*) ARCH="k6";; *) echo "don't know how to deal with that CPU, no problem.." CPUFLAGS= ARCHOPT= ;; esac XFLAGS="-O3 -Wall -fomit-frame-pointer -funroll-loops -finline-functions -fstrict-aliasing -march=$ARCH" ;; esac ;; pgcc*) VERSION=`$CC -V 2> /dev/null | head -2 | tail -1 | cut -d" " -f2` case $VERSION in 4*) echo "dbg: Portland PGCC $VERSION compiler detected" if [ -z "$1" ]; then echo "Please select your CPU, one of {" echo " pentium, pentiumpro, pentium2, pentium3," echo " pentium4, athlon, athlon-xp, athlon-mp" echo -n "} = " read ARCH else ARCH=$1 fi case $ARCH in pentium4) CPUFLAGS="-tp p7 -fastsse";; pentium3) CPUFLAGS="-tp p6 -fastsse";; pentium2) CPUFLAGS="-tp p6 -fast";; pentiumpro) CPUFLAGS="-tp p6 -fast";; pentium) CPUFLAGS="-tp p5 -fast";; athlon) CPUFLAGS="-tp athlon -fast";; athlon*) CPUFLAGS="-tp athlonxp -fastsse";; *) echo "don't know how to deal with that CPU, no problem.." CPUFLAGS="-tp px -fast" ;; esac XFLAGS=$CPUFLAGS ;; esac ;; icc*) VERSION=`$CC -v 2>&1 | cut -d" " -f2` case $VERSION in 8*) echo "dbg: Intel ICC $VERSION compiler detected" if [ -z "$1" ]; then echo "Please select your CPU, one of {" echo " pentium, pentiumpro, pentium2, pentium3, pentium4" echo -n "} = " read ARCH else ARCH=$1 fi case $ARCH in pentium4) CPUFLAGS="-march=pentium4";; pentium3) CPUFLAGS="-march=pentiumiii";; pentium2) CPUFLAGS="-march=pentiumii";; pentiumpro) CPUFLAGS="-march=pentiumpro";; pentium) CPUFLAGS="-march=pentium";; *) echo "don't know how to deal with that CPU, no problem.." CPUFLAGS="" ;; esac XFLAGS="-fast $CPUFLAGS" ;; esac esac if [ -z "$XFLAGS" ]; then echo "dbg: unknown compiler version detected (please check Makefile)" CFLAGS="-O" else CFLAGS=$XFLAGS echo "dbg: CFLAGS=$CFLAGS" fi # generate the Makefile (cat < $Makefile # select name of executable program if [ "$TERM" = "cygwin" ]; then PROGRAM=lcrack.exe REGEX=regex.exe MKWORD=mkword.exe MKTBL=mktbl.exe else PROGRAM=lcrack REGEX=regex MKWORD=mkword MKTBL=mktbl fi (cat <> $Makefile # select modules to build echo dbg: generating plug-in section cp -f xtn_method.h.in xtn_method.h cp -f xtn_method.c.in xtn_method.c /bin/ls mod_*.h | while read MOD_HDR; do MOD=`echo $MOD_HDR | cut -d_ -f2 | cut -d. -f1` echo dbg: found \'$MOD\' plug-in at ${MOD_HDR}/${MOD_HDR%.h}.c echo "#include \"${MOD_HDR}\"" >> xtn_method.h echo " { \"$MOD\", &xtn_${MOD}_init, &xtn_${MOD}_cmp, &xtn_${MOD}_crypt }," >> xtn_method.c done cat xtn_method.c.out >> xtn_method.c (cat <> $Makefile cat Makefile.in >> $Makefile echo dbg: Makefile generated echo echo Please check that the auto-generated Makefile looks good. echo Then compile it typing \'make\' echo exit 0 lcrack-20040914/mod_md4.c0000644000175000017500000000122410115662530013673 0ustar tiagotiago/* Standard MD4 implementation Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_method.h" #include #include extern void mdfour(unsigned char *out, unsigned char *in, int n); int xtn_md4_init(void) { fprintf(stderr, "xtn: initialized 'md4' module\n"); return 16; } int xtn_md4_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1) { return !memcmp(h0, h1, 16 * sizeof(BYTE)); } CODE_BLOCK_PTR xtn_md4_crypt(char *passwd, int len, BYTE *CMAP) { static BYTE md4_buf[16]; BYTE pwd_buf[16]; int j; for(j = 0; j < len; j ++) pwd_buf[j] = CMAP[(int)passwd[j]]; mdfour(md4_buf, pwd_buf, len); return md4_buf; } lcrack-20040914/mod_null.c0000644000175000017500000000102410115662647014170 0ustar tiagotiago/* Null module implementation Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_method.h" #include #include int xtn_null_init(void) { fprintf(stderr, "xtn: initialized 'null' module\n"); return 1; } int xtn_null_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1) { return (h0[0] == h1[0]); } CODE_BLOCK_PTR xtn_null_crypt(char *passwd, int len, BYTE *CMAP) { static BYTE buf[1]; int j; for(buf[0] = 0xee, j = 0; j < len; j ++) { buf[0] ^= CMAP[(int)passwd[j]]; } return buf; } lcrack-20040914/Makefile.in0000644000175000017500000000122010115672023014243 0ustar tiagotiago# fixed Makefile part (not auto-generated) all: $(MAIN_BIN) $(REGEX_BIN) $(MKWORD_BIN) $(MKTBL_BIN) $(MAIN_BIN): $(MAIN_OBJ) $(XTN_OBJ) $(CC) -o $(MAIN_BIN) $(MAIN_OBJ) $(XTN_OBJ) $(LDFLAGS) $(MKTBL_BIN): $(MKTBL_OBJ) $(XTN_OBJ) $(CC) -o $(MKTBL_BIN) $(MKTBL_OBJ) $(XTN_OBJ) $(LDFLAGS) $(REGEX_BIN): $(REGEX_OBJ) $(CC) -o $(REGEX_BIN) $(REGEX_OBJ) $(LDFLAGS) $(MKWORD_BIN): $(MKWORD_OBJ) $(CC) -o $(MKWORD_BIN) $(MKWORD_OBJ) $(LDFLAGS) clean: rm -f $(MAIN_OBJ) $(MAIN_BIN) $(XTN_OBJ) rm -f $(MKTBL_OBJ) $(MKTBL_BIN) rm -f $(REGEX_OBJ) $(REGEX_BIN) rm -f $(MKWORD_OBJ) $(MKWORD_BIN) distclean: clean rm -f Makefile xtn_method.h xtn_method.c lcrack-20040914/AUTHORS0000644000175000017500000000022410121651726013255 0ustar tiagotiagoBernardo Reino (aka Lepton) Miguel Dilaj (aka Nekromancer) Piero Bruneti lcrack-20040914/md4.c0000644000175000017500000001071707571730653013061 0ustar tiagotiago/* Unix SMB/Netbios implementation. Version 1.9. a implementation of MD4 designed for use in the SMB authentication protocol Copyright (C) Andrew Tridgell 1997-1998. Modified by Steve French (sfrench@us.ibm.com) 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* NOTE: This code makes no attempt to be fast! It assumes that a int is at least 32 bits long */ /* added by Bernardo Reino, 20021110 */ #include /* memcpy() */ typedef unsigned int __u32; static __u32 A, B, C, D; static __u32 F(__u32 X, __u32 Y, __u32 Z) { return (X & Y) | ((~X) & Z); } static __u32 G(__u32 X, __u32 Y, __u32 Z) { return (X & Y) | (X & Z) | (Y & Z); } static __u32 H(__u32 X, __u32 Y, __u32 Z) { return X ^ Y ^ Z; } static __u32 lshift(__u32 x, int s) { x &= 0xFFFFFFFF; return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s)); } #define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s) #define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + (__u32)0x5A827999,s) #define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (__u32)0x6ED9EBA1,s) /* this applies md4 to 64 byte chunks */ static void mdfour64(__u32 * M) { int j; __u32 AA, BB, CC, DD; __u32 X[16]; for (j = 0; j < 16; j++) X[j] = M[j]; AA = A; BB = B; CC = C; DD = D; ROUND1(A, B, C, D, 0, 3); ROUND1(D, A, B, C, 1, 7); ROUND1(C, D, A, B, 2, 11); ROUND1(B, C, D, A, 3, 19); ROUND1(A, B, C, D, 4, 3); ROUND1(D, A, B, C, 5, 7); ROUND1(C, D, A, B, 6, 11); ROUND1(B, C, D, A, 7, 19); ROUND1(A, B, C, D, 8, 3); ROUND1(D, A, B, C, 9, 7); ROUND1(C, D, A, B, 10, 11); ROUND1(B, C, D, A, 11, 19); ROUND1(A, B, C, D, 12, 3); ROUND1(D, A, B, C, 13, 7); ROUND1(C, D, A, B, 14, 11); ROUND1(B, C, D, A, 15, 19); ROUND2(A, B, C, D, 0, 3); ROUND2(D, A, B, C, 4, 5); ROUND2(C, D, A, B, 8, 9); ROUND2(B, C, D, A, 12, 13); ROUND2(A, B, C, D, 1, 3); ROUND2(D, A, B, C, 5, 5); ROUND2(C, D, A, B, 9, 9); ROUND2(B, C, D, A, 13, 13); ROUND2(A, B, C, D, 2, 3); ROUND2(D, A, B, C, 6, 5); ROUND2(C, D, A, B, 10, 9); ROUND2(B, C, D, A, 14, 13); ROUND2(A, B, C, D, 3, 3); ROUND2(D, A, B, C, 7, 5); ROUND2(C, D, A, B, 11, 9); ROUND2(B, C, D, A, 15, 13); ROUND3(A, B, C, D, 0, 3); ROUND3(D, A, B, C, 8, 9); ROUND3(C, D, A, B, 4, 11); ROUND3(B, C, D, A, 12, 15); ROUND3(A, B, C, D, 2, 3); ROUND3(D, A, B, C, 10, 9); ROUND3(C, D, A, B, 6, 11); ROUND3(B, C, D, A, 14, 15); ROUND3(A, B, C, D, 1, 3); ROUND3(D, A, B, C, 9, 9); ROUND3(C, D, A, B, 5, 11); ROUND3(B, C, D, A, 13, 15); ROUND3(A, B, C, D, 3, 3); ROUND3(D, A, B, C, 11, 9); ROUND3(C, D, A, B, 7, 11); ROUND3(B, C, D, A, 15, 15); A += AA; B += BB; C += CC; D += DD; A &= 0xFFFFFFFF; B &= 0xFFFFFFFF; C &= 0xFFFFFFFF; D &= 0xFFFFFFFF; for (j = 0; j < 16; j++) X[j] = 0; } static void copy64(__u32 * M, unsigned char *in) { int i; for (i = 0; i < 16; i++) M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) | (in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0); } static void copy4(unsigned char *out, __u32 x) { out[0] = x & 0xFF; out[1] = (x >> 8) & 0xFF; out[2] = (x >> 16) & 0xFF; out[3] = (x >> 24) & 0xFF; } /* produce a md4 message digest from data of length n bytes */ void mdfour(unsigned char *out, unsigned char *in, int n) { unsigned char buf[128]; __u32 M[16]; __u32 b = n * 8; int i; A = 0x67452301; B = 0xefcdab89; C = 0x98badcfe; D = 0x10325476; while (n > 64) { copy64(M, in); mdfour64(M); in += 64; n -= 64; } for (i = 0; i < 128; i++) buf[i] = 0; memcpy(buf, in, n); buf[n] = 0x80; if (n <= 55) { copy4(buf + 56, b); copy64(M, buf); mdfour64(M); } else { copy4(buf + 120, b); copy64(M, buf); mdfour64(M); copy64(M, buf + 64); mdfour64(M); } for (i = 0; i < 128; i++) buf[i] = 0; copy64(M, buf); copy4(out, A); copy4(out + 4, B); copy4(out + 8, C); copy4(out + 12, D); A = B = C = D = 0; } lcrack-20040914/mod_sha1.c0000644000175000017500000000124410115662732014051 0ustar tiagotiago/* Standard SHA-1 implementation */ #include "xtn_method.h" #include #include #include "sha1.h" int xtn_sha1_init(void) { fprintf(stderr, "xtn: initialized 'sha1' module\n"); return 20; } int xtn_sha1_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1) { return !memcmp(h0, h1, 20 * sizeof(BYTE)); } CODE_BLOCK_PTR xtn_sha1_crypt(char *passwd, int len, BYTE *CMAP) { static BYTE sha1_buf[20]; BYTE pwd_buf[20]; int j; SHA1Context sha; for(j = 0; j < len; j ++) pwd_buf[j] = CMAP[(int)passwd[j]]; SHA1Reset(&sha); SHA1Input(&sha, (const unsigned char *) pwd_buf, len); SHA1Result(&sha, sha1_buf); return sha1_buf; } lcrack-20040914/mktbl.c0000644000175000017500000000407310121637704013470 0ustar tiagotiago/* * mktbl - generate pre-computed domino-hash table from a words file * * usage: cat words | ./mktbl -m * * output file = { { word[0..15], hash[0..15] } ... } * * Bernardo Reino, aka Lepton. * 20021127 */ #include #include #include #include "xtn_def.h" #include "xtn_method.h" #include "global.h" xtn_crypt_t xtn_crypt; struct elem { char word[16]; char hash[16]; }; BYTE K_ASCII[BYTE_MAX]; void mktbl(FILE *fp) { CODE_BLOCK_PTR R; struct elem next; while(1) { char *ptr; memset(next.word, '\0', 16); if(! fgets(next.word, 16, stdin)) break; if((ptr = strrchr(next.word, '\r')) != NULL) *ptr = '\0'; if((ptr = strrchr(next.word, '\n')) != NULL) *ptr = '\0'; R = xtn_crypt(next.word, strlen(next.word), K_ASCII); memcpy(next.hash, R, 16); fwrite(&next, sizeof(next), 1, fp); } } void usage(int e, char *me) { FILE *f = e ? stderr : stdout; struct xtn_module_t *xtn_ptr; fprintf(f, "usage: %s [-h] -m \n", me); fprintf(f, " = { "); for(xtn_ptr = &xtn_all[0]; xtn_ptr->xtn_text; xtn_ptr = xtn_ptr ++) { fprintf(f, "'%s' ", xtn_ptr->xtn_text); } fprintf(f, "}\n"); exit(e); } int main(int argc, char *argv[]) { char *alg = NULL; char *ofile = NULL; FILE *fp; struct xtn_module_t *xtn_ptr; int j; for(j = 1; j < argc; j ++) { if(!strcmp(argv[j], "-h")) { usage(0, argv[0]); } else if(!strcmp(argv[j], "-m")) { alg = argv[++ j]; } else if(ofile == NULL) { ofile = argv[j]; } else usage(1, argv[0]); } if(alg == NULL) usage(1, argv[0]); for(xtn_ptr = &xtn_all[0]; xtn_ptr->xtn_text; xtn_ptr = xtn_ptr ++) { if(!strcmp(alg, xtn_ptr->xtn_text)) { xtn_ptr->xtn_init(); xtn_crypt = xtn_ptr->xtn_function; } } if(xtn_crypt == NULL) usage(2, argv[0]); for(j = 0; j < sizeof(K_ASCII); j ++) K_ASCII[j] = j; fp = fopen(ofile, "wb"); if(fp) { mktbl(fp); fclose(fp); } else { perror(ofile); exit(3); } return 0; } lcrack-20040914/md5.c0000644000175000017500000001771610115721353013051 0ustar tiagotiago/* * This code implements the MD5 message-digest algorithm. * The algorithm is due to Ron Rivest. This code was * written by Colin Plumb in 1993, no copyright is claimed. * This code is in the public domain; do with it what you wish. * * Equivalent code is available from RSA Data Security, Inc. * This code has been tested against that, and is equivalent, * except that you don't need to include two pages of legalese * with every copy. * * To compute the message digest of a chunk of bytes, declare an * MD5Context structure, pass it to MD5Init, call MD5Update as * needed on buffers full of bytes, and then call MD5Final, which * will fill a supplied 16-byte array with the digest. */ #include #include /* for memcpy() */ #ifdef __MINGW_H typedef unsigned int u_int32_t; #endif struct MD5Context { u_int32_t buf[4]; u_int32_t bits[2]; unsigned char in[64]; }; void MD5Init(struct MD5Context *context); void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len); void MD5Final(unsigned char digest[16], struct MD5Context *context); void MD5Transform(u_int32_t buf[4], u_int32_t const in[16]); /* * This is needed to make RSAREF happy on some MS-DOS compilers. */ typedef struct MD5Context MD5_CTX; /* * Wrapper function for all-in-one MD5 * * Bernardo Reino, aka Lepton. * 20021120 */ void md5(unsigned char *digest, unsigned char *passwd, int len) { struct MD5Context K; MD5Init(&K); MD5Update(&K, passwd, len); MD5Final(digest, &K); } void MD5Init(struct MD5Context *ctx) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; ctx->buf[2] = 0x98badcfe; ctx->buf[3] = 0x10325476; ctx->bits[0] = 0; ctx->bits[1] = 0; } /* * Update context to reflect the concatenation of another buffer full * of bytes. */ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) { u_int32_t t; /* Update bitcount */ t = ctx->bits[0]; if ((ctx->bits[0] = t + ((u_int32_t) len << 3)) < t) ctx->bits[1]++; /* Carry from low to high */ ctx->bits[1] += len >> 29; t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ /* Handle any leading odd-sized chunks */ if (t) { unsigned char *p = (unsigned char *) ctx->in + t; t = 64 - t; if (len < t) { memcpy(p, buf, len); return; } memcpy(p, buf, t); MD5Transform(ctx->buf, (u_int32_t *) ctx->in); buf += t; len -= t; } /* Process data in 64-byte chunks */ while (len >= 64) { memcpy(ctx->in, buf, 64); MD5Transform(ctx->buf, (u_int32_t *) ctx->in); buf += 64; len -= 64; } /* Handle any remaining bytes of data. */ memcpy(ctx->in, buf, len); } /* * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ void MD5Final(unsigned char digest[16], struct MD5Context *ctx) { unsigned count; unsigned char *p; /* Compute number of bytes mod 64 */ count = (ctx->bits[0] >> 3) & 0x3F; /* Set the first char of padding to 0x80. This is safe since there is always at least one byte free */ p = ctx->in + count; *p++ = 0x80; /* Bytes of padding needed to make 64 bytes */ count = 64 - 1 - count; /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); MD5Transform(ctx->buf, (u_int32_t *) ctx->in); /* Now fill the next block with 56 bytes */ memset(ctx->in, 0, 56); } else { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } /* Append length in bits and transform */ ((u_int32_t *) ctx->in)[14] = ctx->bits[0]; ((u_int32_t *) ctx->in)[15] = ctx->bits[1]; MD5Transform(ctx->buf, (u_int32_t *) ctx->in); memcpy(digest, ctx->buf, 16); memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ } /* The four core functions - F1 is optimized somewhat */ /* #define F1(x, y, z) (x & y | ~x & z) */ #define F1(x, y, z) (z ^ (x & (y ^ z))) #define F2(x, y, z) F1(z, x, y) #define F3(x, y, z) (x ^ y ^ z) #define F4(x, y, z) (y ^ (x | ~z)) /* This is the central step in the MD5 algorithm. */ #define MD5STEP(f, w, x, y, z, data, s) \ ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) /* * The core of the MD5 algorithm, this alters an existing MD5 hash to * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ void MD5Transform(u_int32_t buf[4], u_int32_t const in[16]) { register u_int32_t a, b, c, d; a = buf[0]; b = buf[1]; c = buf[2]; d = buf[3]; MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); buf[0] += a; buf[1] += b; buf[2] += c; buf[3] += d; } lcrack-20040914/mod_nt4.h0000644000175000017500000000037610115662610013727 0ustar tiagotiago/* NT (unicode) MD4 implementation Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_def.h" int xtn_nt4_init(void); int xtn_nt4_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1); CODE_BLOCK_PTR xtn_nt4_crypt(char *passwd, int len, BYTE *CMAP); lcrack-20040914/sha1.h0000644000175000017500000000276710115710356013226 0ustar tiagotiago/* * sha1.h * * Description: * This is the header file for code which implements the Secure * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published * April 17, 1995. * * Many of the variable names in this code, especially the * single character names, were used because those were the names * used in the publication. * * Please read the file sha1.c for more information. * */ #ifndef _SHA1_H_ #define _SHA1_H_ #include #ifndef _SHA_enum_ #define _SHA_enum_ enum { shaSuccess = 0, shaNull, /* Null pointer parameter */ shaInputTooLong, /* input data too long */ shaStateError /* called Input after Result */ }; #endif #define SHA1HashSize 20 /* * This structure will hold context information for the SHA-1 * hashing operation */ typedef struct SHA1Context { uint32_t Intermediate_Hash[SHA1HashSize / 4]; /* Message Digest */ uint32_t Length_Low; /* Message length in bits */ uint32_t Length_High; /* Message length in bits */ /* Index into message block array */ int_least16_t Message_Block_Index; uint8_t Message_Block[64]; /* 512-bit message blocks */ int Computed; /* Is the digest computed? */ int Corrupted; /* Is the message digest corrupted? */ } SHA1Context; /* * Function Prototypes */ int SHA1Reset(SHA1Context *); int SHA1Input(SHA1Context *, const uint8_t *, unsigned int); int SHA1Result(SHA1Context *, uint8_t Message_Digest[SHA1HashSize]); #endif lcrack-20040914/mod_md5.h0000644000175000017500000000037210115662562013711 0ustar tiagotiago/* Standard MD5 implementation Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_def.h" int xtn_md5_init(void); int xtn_md5_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1); CODE_BLOCK_PTR xtn_md5_crypt(char *passwd, int len, BYTE *CMAP); lcrack-20040914/mod_dom.h0000644000175000017500000000057110115662513014000 0ustar tiagotiago/* Lotus HTTP Password Hash implementation Copyright (C) Bernardo Reino (lepton@runbox.com), and Miguel Dilaj (nekromancer@eudoramail.com) Based on code by Jeff Fay (jeff@sdii.com) */ #include "xtn_def.h" int xtn_dom_init(void); int xtn_dom_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1); CODE_BLOCK_PTR xtn_dom_crypt(char *passwd, int len, BYTE *CMAP); lcrack-20040914/mkword.c0000644000175000017500000000164210115665245013665 0ustar tiagotiago/* * grab words (as defined by isalnum()) from text files, * useful for generating cracking dictionaries. * * example: * * $ mkword *.txt | sort | uniq > words * * Bernardo Reino, aka Lepton. * 20021121 */ #include #include #include void parse(FILE *fp) { enum { SEEK, WORD } state; int ch; for(state = SEEK; (ch = fgetc(fp)) != EOF; ) { switch(state) { case SEEK: if(isalnum(ch)) { ungetc(ch, fp); state = WORD; } break; case WORD: if(!isalnum(ch)) { putchar('\n'); state = SEEK; } else { putchar(ch); } break; } } if(state == WORD) putchar('\n'); } int main(int argc, char **argv) { if(argc > 1) { int j; for(j = 1; j < argc; j ++) { FILE *fp = fopen(argv[j], "r"); if(fp) { parse(fp); fclose(fp); } else perror(argv[j]); } } else parse(stdin); return 0; } lcrack-20040914/global.h0000644000175000017500000000310710121637610013615 0ustar tiagotiago/* Cracking Engine Copyright (C) Bernardo Reino (aka Lepton) (lepton@runbox.com) 20021119 */ #ifndef __XTN_GLOBAL__ #define __XTN_GLOBAL__ #include #include #include "xtn_def.h" extern BYTE K_CHARSET[BYTE_MAX], *K_ACTIVE; extern BYTE K_LENSET[MAX_PASS_LEN]; /* used for regex enumeration (default character set, taken from K_CHARSET) */ extern BYTE K_SYMBOL[BYTE_MAX]; struct regex_t { struct regex_t *next; int wild; BYTE symbol[BYTE_MAX]; }; /* parsed regex, used for enumeration */ extern struct regex_t *K_REGEX; extern int RXMinLength, RXWildCount; extern int K_CHARSET_LEN, K_LENSET_LEN; extern int verbose; typedef struct _t_PasswordElement { char * login; CODE_BLOCK data[MAX_CODE_LEN]; struct _t_PasswordElement * next; } PasswordElement; extern PasswordElement PasswordList[BYTE_MAX]; extern unsigned long long PasswordCount; /* who knows? :) */ extern int PasswordLeft; extern FILE *pot; extern int pot_file, verbose; extern void print_key(FILE *f, BYTE *K, unsigned int K_Len); extern void KEY_text(BYTE *stream, char *dst, unsigned int len); extern int KEY_find(char *K, int K_Len, CODE_BLOCK_PTR H); extern int KEY_login(char *passwd, int Len, int xtd); extern int KEY_word(char *passwd, int Len, int xtd); extern int KEY_cmp(char *passwd, int Len); extern void KEY_zero(BYTE *K, unsigned int Len); extern signed int KEY_next(BYTE *K, unsigned int Len); extern void KEY_rand(BYTE *K, unsigned int Len); #ifdef __MINGW_H void gettimeofday(struct timeval* p, void* tz /* IGNORED */); #endif #endif lcrack-20040914/xtn_method.h.in0000644000175000017500000000013510115663143015134 0ustar tiagotiago/* Cracking Engine Copyright (C) Bernardo Reino (lepton@runbox.com) 20021122 */ lcrack-20040914/mod_dom.c0000644000175000017500000001131610121107544013765 0ustar tiagotiago/* Lotus HTTP Password Hash implementation Copyright (C) Bernardo Reino (aka Lepton) (lepton@runbox.com), and Miguel Dilaj (aka Nekromancer) (nekromancer@eudoramail.com) Based on code by Jeff Fay (jeff@sdii.com) */ #include "xtn_method.h" #include #include const BYTE S_BOX[] = { 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A, 0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0, 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B, 0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A, 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA, 0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36, 0x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8, 0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C, 0x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17, 0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60, 0x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72, 0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA, 0xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD, 0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E, 0xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B, 0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF, 0x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77, 0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6, 0xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3, 0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3, 0x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E, 0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C, 0xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D, 0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2, 0x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46, 0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5, 0x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97, 0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5, 0x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF, 0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F, 0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF, 0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, /* repeated to avoid & 0xff */ 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A, 0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0, 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B, 0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A, 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA, 0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36, 0x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8, 0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C, 0x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17, 0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60, 0x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72, 0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA, 0xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD, 0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E, 0xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B, 0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF, 0x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77, 0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6, 0xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3, 0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3, 0x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E, 0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C, 0xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D, 0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2, 0x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46, 0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5, 0x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97, 0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5, 0x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF, 0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F, 0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF, 0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB }; int xtn_dom_init(void) { fprintf(stderr, "xtn: initialized (domino HTTP hash) module\n"); return 16; } int xtn_dom_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1) { return !memcmp(h0, h1, 16 * sizeof(BYTE)); } CODE_BLOCK_PTR xtn_dom_crypt(char *passwd, int len, BYTE *CMAP) { static BYTE RC4_Block[48]; BYTE RC4_Key[16]; int j; for(j = 0; j < len; j ++) RC4_Block[16 + j] = CMAP[(int)passwd[j]]; for(; j < 16; j ++) RC4_Block[16 + j] = (16 - len); memcpy(RC4_Block + 32, RC4_Block + 16, 16); RC4_Key[0] = S_BOX[RC4_Block[16]]; for(j = 1; j < 16; j ++) RC4_Key[j] = S_BOX[RC4_Key[j - 1] ^ RC4_Block[16 + j]]; if(1) { /* RC4_MixTable1 */ register BYTE X; register const BYTE *S; register unsigned int i; S = &S_BOX[48]; for(X = 0, i = 0; i < 16; i ++, S --) { X = (RC4_Block[i] = S[X]); } for(i = 16; i < 48; i ++, S --) { X = (RC4_Block[i] ^= S[X]); } for(i = 17; i > 0; i --) { register int j; S = &S_BOX[48]; for(j = 0; j < 48; j ++, S --) { X = (RC4_Block[j] ^= S[X]); } } } if(1) { unsigned long long *K, *B; K = (unsigned long long *)RC4_Key; B = (unsigned long long *)RC4_Block; B[2] = K[0]; B[3] = K[1]; B[4] = B[0] ^ K[0]; B[5] = B[1] ^ K[1]; } if(1) { /* RC4_MixTable2 */ register BYTE X = 0; register const BYTE *S; register unsigned int i; for(i = 17; i > 0; i --) { register int j; S = &S_BOX[48]; for(j = 0; j < 48; j ++, S --) X = (RC4_Block[j] ^= S[X]); } S = &S_BOX[48]; for(i = 0; i < 16; i ++, S --) X = (RC4_Block[i] ^= S[X]); } return RC4_Block; } lcrack-20040914/mod_md5.c0000644000175000017500000000123010115662552013675 0ustar tiagotiago/* Standard MD5 implementation Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_method.h" #include #include extern void md5(unsigned char *digest, unsigned char *passwd, int len); int xtn_md5_init(void) { fprintf(stderr, "xtn: initialized 'md5' module\n"); return 16; } int xtn_md5_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1) { return !memcmp(h0, h1, 16 * sizeof(BYTE)); } CODE_BLOCK_PTR xtn_md5_crypt(char *passwd, int len, BYTE *CMAP) { static BYTE md5_buf[16]; BYTE pwd_buf[16]; int j; for(j = 0; j < len; j ++) pwd_buf[j] = CMAP[(int)passwd[j]]; md5(md5_buf, pwd_buf, len); return md5_buf; } lcrack-20040914/sha1.c0000644000175000017500000002255207604161726013225 0ustar tiagotiago/* * sha1.c * * Description: * This file implements the Secure Hashing Algorithm 1 as * defined in FIPS PUB 180-1 published April 17, 1995. * * The SHA-1, produces a 160-bit message digest for a given * data stream. It should take about 2**n steps to find a * message with the same digest as a given message and * 2**(n/2) to find any two messages with the same digest, * when n is the digest size in bits. Therefore, this * algorithm can serve as a means of providing a * "fingerprint" for a message. * * Portability Issues: * SHA-1 is defined in terms of 32-bit "words". This code * uses (included via "sha1.h" to define 32 and 8 * bit unsigned integer types. If your C compiler does not * support 32 bit unsigned integers, this code is not * appropriate. * * Caveats: * SHA-1 is designed to work with messages less than 2^64 bits * long. Although SHA-1 allows a message digest to be generated * for messages of any number of bits less than 2^64, this * implementation only works with messages with a length that is * a multiple of the size of an 8-bit character. * */ #include "sha1.h" /* * Define the SHA1 circular left shift macro */ #define SHA1CircularShift(bits,word) \ (((word) << (bits)) | ((word) >> (32-(bits)))) /* Local Function Prototyptes */ void SHA1PadMessage (SHA1Context *); void SHA1ProcessMessageBlock (SHA1Context *); /* * SHA1Reset * * Description: * This function will initialize the SHA1Context in preparation * for computing a new SHA1 message digest. * * Parameters: * context: [in/out] * The context to reset. * * Returns: * sha Error Code. * */ int SHA1Reset (SHA1Context * context) { if (!context) { return shaNull; } context->Length_Low = 0; context->Length_High = 0; context->Message_Block_Index = 0; context->Intermediate_Hash[0] = 0x67452301; context->Intermediate_Hash[1] = 0xEFCDAB89; context->Intermediate_Hash[2] = 0x98BADCFE; context->Intermediate_Hash[3] = 0x10325476; context->Intermediate_Hash[4] = 0xC3D2E1F0; context->Computed = 0; context->Corrupted = 0; return shaSuccess; } /* * SHA1Result * * Description: * This function will return the 160-bit message digest into the * Message_Digest array provided by the caller. * NOTE: The first octet of hash is stored in the 0th element, * the last octet of hash in the 19th element. * * Parameters: * context: [in/out] * The context to use to calculate the SHA-1 hash. * Message_Digest: [out] * Where the digest is returned. * * Returns: * sha Error Code. * */ int SHA1Result (SHA1Context * context, uint8_t Message_Digest[SHA1HashSize]) { int i; if (!context || !Message_Digest) { return shaNull; } if (context->Corrupted) { return context->Corrupted; } if (!context->Computed) { SHA1PadMessage (context); for (i = 0; i < 64; ++i) { /* message may be sensitive, clear it out */ context->Message_Block[i] = 0; } context->Length_Low = 0; /* and clear length */ context->Length_High = 0; context->Computed = 1; } for (i = 0; i < SHA1HashSize; ++i) { Message_Digest[i] = context->Intermediate_Hash[i >> 2] >> 8 * (3 - (i & 0x03)); } return shaSuccess; } /* * SHA1Input * * Description: * This function accepts an array of octets as the next portion * of the message. * * Parameters: * context: [in/out] * The SHA context to update * message_array: [in] * An array of characters representing the next portion of * the message. * length: [in] * The length of the message in message_array * * Returns: * sha Error Code. * */ int SHA1Input (SHA1Context * context, const uint8_t * message_array, unsigned length) { if (!length) { return shaSuccess; } if (!context || !message_array) { return shaNull; } if (context->Computed) { context->Corrupted = shaStateError; return shaStateError; } if (context->Corrupted) { return context->Corrupted; } while (length-- && !context->Corrupted) { context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); context->Length_Low += 8; if (context->Length_Low == 0) { context->Length_High++; if (context->Length_High == 0) { /* Message is too long */ context->Corrupted = 1; } } if (context->Message_Block_Index == 64) { SHA1ProcessMessageBlock (context); } message_array++; } return shaSuccess; } /* * SHA1ProcessMessageBlock * * Description: * This function will process the next 512 bits of the message * stored in the Message_Block array. * * Parameters: * None. * * Returns: * Nothing. * * Comments: * Many of the variable names in this code, especially the * single character names, were used because those were the * names used in the publication. * * */ void SHA1ProcessMessageBlock (SHA1Context * context) { const uint32_t K[] = { /* Constants defined in SHA-1 */ 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 }; int t; /* Loop counter */ uint32_t temp; /* Temporary word value */ uint32_t W[80]; /* Word sequence */ uint32_t A, B, C, D, E; /* Word buffers */ /* * Initialize the first 16 words in the array W */ for (t = 0; t < 16; t++) { W[t] = context->Message_Block[t * 4] << 24; W[t] |= context->Message_Block[t * 4 + 1] << 16; W[t] |= context->Message_Block[t * 4 + 2] << 8; W[t] |= context->Message_Block[t * 4 + 3]; } for (t = 16; t < 80; t++) { W[t] = SHA1CircularShift (1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]); } A = context->Intermediate_Hash[0]; B = context->Intermediate_Hash[1]; C = context->Intermediate_Hash[2]; D = context->Intermediate_Hash[3]; E = context->Intermediate_Hash[4]; for (t = 0; t < 20; t++) { temp = SHA1CircularShift (5, A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; E = D; D = C; C = SHA1CircularShift (30, B); B = A; A = temp; } for (t = 20; t < 40; t++) { temp = SHA1CircularShift (5, A) + (B ^ C ^ D) + E + W[t] + K[1]; E = D; D = C; C = SHA1CircularShift (30, B); B = A; A = temp; } for (t = 40; t < 60; t++) { temp = SHA1CircularShift (5, A) + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; E = D; D = C; C = SHA1CircularShift (30, B); B = A; A = temp; } for (t = 60; t < 80; t++) { temp = SHA1CircularShift (5, A) + (B ^ C ^ D) + E + W[t] + K[3]; E = D; D = C; C = SHA1CircularShift (30, B); B = A; A = temp; } context->Intermediate_Hash[0] += A; context->Intermediate_Hash[1] += B; context->Intermediate_Hash[2] += C; context->Intermediate_Hash[3] += D; context->Intermediate_Hash[4] += E; context->Message_Block_Index = 0; } /* * SHA1PadMessage * * Description: * According to the standard, the message must be padded to an even * 512 bits. The first padding bit must be a '1'. The last 64 * bits represent the length of the original message. All bits in * between should be 0. This function will pad the message * according to those rules by filling the Message_Block array * accordingly. It will also call the ProcessMessageBlock function * provided appropriately. When it returns, it can be assumed that * the message digest has been computed. * * Parameters: * context: [in/out] * The context to pad * ProcessMessageBlock: [in] * The appropriate SHA*ProcessMessageBlock function * Returns: * Nothing. * */ void SHA1PadMessage (SHA1Context * context) { /* * Check to see if the current message block is too small to hold * the initial padding bits and length. If so, we will pad the * block, process it, and then continue padding into a second * block. */ if (context->Message_Block_Index > 55) { context->Message_Block[context->Message_Block_Index++] = 0x80; while (context->Message_Block_Index < 64) { context->Message_Block[context->Message_Block_Index++] = 0; } SHA1ProcessMessageBlock (context); while (context->Message_Block_Index < 56) { context->Message_Block[context->Message_Block_Index++] = 0; } } else { context->Message_Block[context->Message_Block_Index++] = 0x80; while (context->Message_Block_Index < 56) { context->Message_Block[context->Message_Block_Index++] = 0; } } /* * Store the message length as the last 8 octets */ context->Message_Block[56] = context->Length_High >> 24; context->Message_Block[57] = context->Length_High >> 16; context->Message_Block[58] = context->Length_High >> 8; context->Message_Block[59] = context->Length_High; context->Message_Block[60] = context->Length_Low >> 24; context->Message_Block[61] = context->Length_Low >> 16; context->Message_Block[62] = context->Length_Low >> 8; context->Message_Block[63] = context->Length_Low; SHA1ProcessMessageBlock (context); } lcrack-20040914/xtn_method.c.in0000644000175000017500000000030310115663122015121 0ustar tiagotiago/* Plug-in definition (don't touch it :) Copyright (C) Bernardo Reino (lepton@runbox.com) 20021122 */ #include "xtn_def.h" #include "xtn_method.h" struct xtn_module_t xtn_all[] = { lcrack-20040914/mod_sha1.h0000644000175000017500000000032210115662737014057 0ustar tiagotiago/* Standard SHA-1 implementation */ #include "xtn_def.h" int xtn_sha1_init(void); int xtn_sha1_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1); CODE_BLOCK_PTR xtn_sha1_crypt(char *passwd, int len, BYTE *CMAP); lcrack-20040914/CREDITS0000640000175000017500000000174310121652261013223 0ustar tiagotiagoBernardo Reino is the main author of Lepton's Crack. Miguel Dilaj is the program mantainer, coordinator, and researcher. Jeff Fay provided a Lotus Domino HTTP hash implementation, which was used as a base for the implementation in Lepton's Crack. Burcin Erocal contributed a SHA-1 module. Piero Bruneti has made many contributions to the project (support for LM hash, password prefix & suffix, etc.) Matteo Bruneti ESPoRa joe joe Sergiusz Pawlowicz Stefan Bredow J.A. Gutierrez Scott Stevens lcrack-20040914/mod_null.h0000644000175000017500000000035510115662660014176 0ustar tiagotiago/* Null module Copyright (C) Lepton (lepton@runbox.com) */ #include "xtn_def.h" int xtn_null_init(void); int xtn_null_cmp(CODE_BLOCK_PTR h0, CODE_BLOCK_PTR h1); CODE_BLOCK_PTR xtn_null_crypt(char *passwd, int len, BYTE *CMAP); lcrack-20040914/set.c0000644000175000017500000003164010121644324013146 0ustar tiagotiago/* Cracking Engine, LoadExternalSpec() LoadCharSet() LoadLenSet() LoadRegEx() Copyright (C) Bernardo Reino (lepton@runbox.com) 20040912 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * K_CHARSET = Vector of characters included in brute-force keyspace * K_CHARSET_LEN = Length of vector * * K_LENSET = Vector of password-lengths to try * K_LENSET_LEN = Length of vector */ #include /* [f]printf() */ #include /* memset() */ #include /* strtoul() */ #include /* isspace() */ #include "global.h" static unsigned char *fix_expr(const unsigned char *expr, int *len) { enum { NORMAL, ESCAPE, OCTAL, DECIMAL, HEXA } state; const unsigned char *rptr; unsigned char *fixed, *wptr; int prefix; unsigned int val = 0; wptr = fixed = strdup(expr); /* may waste some space, but.. */ for(state = NORMAL, rptr = expr; *rptr; rptr ++) { int ch = *rptr; switch(state) { case NORMAL: if(ch == '\\') { /* escaped character */ state = ESCAPE; } else { *(wptr ++) = ch; } break; case ESCAPE: if(ch == '0') { /* octal */ prefix = ch; val = 0; state = OCTAL; } else if(isdigit(ch)) { /* decimal */ prefix = ch; val = 0; state = DECIMAL; rptr --; } else if((ch == 'x') || (ch == 'X')) { /* hexa */ prefix = ch; val = 0; state = HEXA; } else { /* nothing special (or a backslash) */ *(wptr ++) = ch; state = NORMAL; } break; case OCTAL: if((ch >= '0') || (ch <= '7')) { int nval; nval = (val * 8) + (unsigned int)(ch - '0'); if(nval < BYTE_MAX) val = nval; else goto end_octal; } else { /* end of octal */ end_octal: *(wptr ++) = (unsigned char)val; rptr --; state = NORMAL; } break; case DECIMAL: if(isdigit(ch)) { int nval; nval = (val * 10) + (unsigned int)(ch - '0'); if(nval < BYTE_MAX) val = nval; else goto end_decimal; } else { /* end of decimal */ end_decimal: *(wptr ++) = (unsigned char)val; rptr --; state = NORMAL; } break; case HEXA: if(isxdigit(ch)) { int nval; nval = val * 16; if((ch >= '0') && (ch <= '9')) nval += (ch - '0'); else if((ch >= 'A') && (ch <= 'F')) nval += (ch - 'A' + 10); else if((ch >= 'a') && (ch <= 'f')) nval += (ch - 'a' + 10); if(nval < BYTE_MAX) val = nval; else goto end_hexa; } else { /* end of decimal */ end_hexa: *(wptr ++) = (unsigned char)val; rptr --; state = NORMAL; } break; } } switch(state) { case NORMAL: /* OK */ break; case ESCAPE: /* expr ended with escape char.. */ if("add it anyway..") *(wptr ++) = '\\'; break; case OCTAL: case DECIMAL: case HEXA: /* don't forget me! :) */ *(wptr ++) = (unsigned char)val; break; } *wptr = '\0'; if(len) *len = (int)(wptr - fixed); return fixed; } static FILE *ExternalFile(const char *me, const char *default_filename) { char *file = NULL; char *where_am_i, *ptr; int do_bin = 0; FILE *fp; where_am_i = strdup(me); ptr = strrchr(where_am_i, '/'); if(ptr) { *ptr = '\0'; do_bin = 1; } file = strdup(default_filename); fp = fopen(file, "r"); if(fp == NULL) { free(file), file = NULL; if(do_bin) { file = malloc(strlen(where_am_i) + strlen(default_filename) + 2); sprintf(file, "%s/%s", where_am_i, default_filename); fp = fopen(file, "r"); } if(fp == NULL) { char *home = getenv("HOME"); if(file) free(file), file = NULL; if(home) { file = malloc(strlen(home) + strlen(default_filename) + 2); sprintf(file, "%s/%s", home, default_filename); fp = fopen(file, "r"); } if(fp == NULL) { if(file) free(file), file = NULL; file = malloc(strlen(default_filename) + 6); sprintf(file, "/etc/%s", default_filename); fp = fopen(file, "r"); } } } if(file) free(file); return fp; } unsigned char *LoadExternalSpec(const char *me, const char *file, const char *spec) { FILE *external; unsigned char *value = NULL; if((external = ExternalFile(me, file)) != NULL) { unsigned char line[1024]; while(fgets(line, 1024, external)) { unsigned char *ptr, *begin; ptr = strrchr(line, '\n'); if(ptr) *ptr = '\0'; ptr = strrchr(line, '\r'); if(ptr) *ptr = '\0'; for(begin = &line[0]; *begin && isspace(*begin); begin ++) ; if(*begin) { if(*begin == '#') continue; ptr = strstr(begin, " = "); if(ptr) { unsigned char *def; for(def = ptr + 3; *def && isspace(*def); def ++) ; while((ptr > begin) && isspace(*ptr)) *(ptr --) = '\0'; if(strcmp(spec, begin) == 0) { if(*def) { ptr = def + strlen(def) - 1; while((ptr > def) && isspace(*ptr)) ptr --; if(isspace(*ptr)) *ptr = '\0'; } value = strdup(def); } } else { /* ignore line.. */ } } } fclose(external); } else fprintf(stderr, "%s: no %s config file found..\n", me, file); /* fprintf(stderr, "(dbg) %s = '%s'\n", spec, value); */ return value; } int LoadCharSet(const unsigned char *set) { unsigned char *fixed_set; int cmap[BYTE_MAX], stored, stored_len, next; int fixed_len, ndx; enum { SEEK, NEXT, CSET } state; fixed_set = fix_expr(set, &fixed_len); memset(cmap, 0, sizeof(cmap)); stored = 0; for(state = SEEK, ndx = 0; ndx < fixed_len; ndx ++) { next = fixed_set[ndx]; switch(state) { case SEEK: stored = next; state = NEXT; break; case NEXT: if(next == '-') { state = CSET; } else { cmap[stored] ++; stored = next; } break; case CSET: if(next == '-') { /* double '-', weird.. */ fprintf(stderr, "alert: specified character set might not be " "what you are thinking of! :)\n"); cmap[stored] ++; stored = next; } else { int j; for(j = stored; j <= next; j ++) cmap[j] ++; state = SEEK; } break; } } free(fixed_set); /* not needed anymore.. */ switch(state) { case CSET: fprintf(stderr, "failed: character set not closed (%c-?)\n", stored); return -1; case NEXT: cmap[stored] ++; /* don't forget me! */ break; case SEEK: break; } for(stored_len = stored = next = 0; next < BYTE_MAX; next ++) { if(cmap[next] > 1) { fprintf(stderr, "alert: character '%c' repeated %d times in set, fixing..\n", next, cmap[next]); cmap[next] = 1; } if(cmap[next] > 0) { K_CHARSET[stored ++] = next; stored_len += isprint(next) ? 1 : 4; } K_SYMBOL[next] = (BYTE)cmap[next]; } K_CHARSET_LEN = stored; if(verbose) { int printed_len, one_line, limit; for(limit = stored_len; limit > 70; ) limit = (limit + 1)/2; fprintf(stderr, "loaded: CSET[%d] = {", K_CHARSET_LEN); if(stored_len < 50) { one_line = 1; fputc(' ', stderr); } else { one_line = 0; fputc('\n', stderr); } for(printed_len = next = 0; next < stored; next ++) { int ch; if((printed_len == 0) && !one_line) fprintf(stderr, " "); ch = K_CHARSET[next]; if(isprint(ch)) fputc(ch, stderr), printed_len ++; else fprintf(stderr, "\\x%02x", ch), printed_len += 4; if(printed_len > limit) fprintf(stderr, "\n"), printed_len = 0; } if(printed_len) fputc(one_line ? ' ' : '\n', stderr); fprintf(stderr, "}\n"); } return 0; } int LoadLenSet(const char *set) { int lmap[16]; int stored = 0, next; int in_set = 0, eol = 0; memset(lmap, 0, sizeof(lmap)); while((! eol) && *set) { char *endptr; size_t seg_len; seg_len = strspn(set, "x0123456789"); if(seg_len) { next = strtoul(set, &endptr, 0); if(endptr != (set + seg_len)) goto bad_format; if((next < 1) || (next > MAX_PASS_LEN)) { fprintf(stderr, "failed: size of password must be < %d\n", MAX_PASS_LEN); return -1; } set = endptr; switch(*set) { case '\0': case ',': if(in_set) { int j; for(j = stored; j <= next; j ++) lmap[j - 1] ++; in_set = 0; } else { lmap[next - 1] ++; } if(! *set) eol = 1; else set ++; break; case '-': if(in_set) goto bad_format; stored = next; in_set = 1; set ++; break; default: fprintf(stderr, "failed: invalid character ('%c') found in length-set\n", *set); return -1; } } else { bad_format: fprintf(stderr, "failed: bad length-set format\n"); return -1; } } for(stored = next = 0; next < 16; next ++) { if(lmap[next] > 1) { fprintf(stderr, "alert: length(%d) specified %u times\n", next, lmap[next]); } if(lmap[next]) K_LENSET[stored ++] = next + 1; } K_LENSET_LEN = stored; if(verbose) { fprintf(stderr, "loaded: LSET[%d] = { ", K_LENSET_LEN); for(next = 0; next < stored; next ++) { fprintf(stderr, "%d ", K_LENSET[next]); } fprintf(stderr, "}\n"); } return 0; } static struct regex_t *rx_add(struct regex_t *rx, int wild, const BYTE *symbol) { struct regex_t *tail; tail = malloc(sizeof(struct regex_t)); tail->next = NULL; tail->wild = wild; memcpy(tail->symbol, symbol, BYTE_MAX * sizeof(BYTE)); rx->next = tail; return tail; } static struct regex_t *rx_parse(const unsigned char *regex, int len) { static BYTE symbol[BYTE_MAX]; enum { SEEK, SYMBOL, SET, START, RANGE } state; struct regex_t *rx, *tail; unsigned char left = '\0'; int s_len = 0, wild = 0, ndx; rx = malloc(sizeof(struct regex_t)); rx->next = NULL; tail = rx; for(state = SEEK, ndx = 0; ndx < len; ) { switch(state) { case SEEK: memset(symbol, 0, sizeof(symbol)); switch(regex[ndx]) { case '[': state = SET; s_len = 0; ndx ++; break; default: state = SYMBOL; } break; case SYMBOL: symbol[(int) regex[ndx ++]] ++; RXMinLength ++; tail = rx_add(tail, 0, symbol); state = SEEK; break; case SET: switch(regex[ndx]) { case ']': if(s_len == 0) { /* use default character set */ memcpy(symbol, K_SYMBOL, sizeof(symbol)); RXMinLength ++; } else if((s_len == 1) && (left == '*')) { /* special case, [*] = variable-length wildcard */ memcpy(symbol, K_SYMBOL, sizeof(symbol)); RXWildCount ++; wild = 1; } tail = rx_add(tail, wild, symbol); wild = 0; state = SEEK; break; default: left = regex[ndx]; state = START; break; } ndx ++; break; case START: switch(regex[ndx]) { case ']': symbol[(int)left] ++; s_len ++; state = SET; break; case '-': state = RANGE; ndx ++; break; default: symbol[(int)left] ++; s_len ++; left = regex[ndx ++]; break; } break; case RANGE: if(left > regex[ndx]) { fprintf(stderr, "(dbg) empty set [%c-%c], will take it as '%c'\n", left, regex[ndx], left); symbol[(int)left] ++; s_len ++; } else { while(left <= regex[ndx]) { symbol[(int)(left ++)] ++; s_len ++; } } ndx ++; state = SET; break; } } switch(state) { case SEEK: /* OK */ break; case SYMBOL: case SET: case START: case RANGE: return NULL; } tail = rx->next; free(rx); return tail; } static void rx_dump(FILE *o, struct regex_t *rx) { while(rx) { int j; fprintf(o, "["); if(rx->wild) fputc('*', o); else { for(j = 0; j < BYTE_MAX; j ++) if(rx->symbol[j] > 0) { if(isprint(j)) fputc(j, o); else fprintf(o, "\\x%02x", j); } } fprintf(o, "]"); rx = rx->next; } } int LoadRegEx(const unsigned char *regex) { struct regex_t *rx; unsigned char *fixed; int fixed_len; if(verbose) { fprintf(stderr, "(dbg) regex '%s'\n", regex); } fixed = fix_expr(regex, &fixed_len); rx = rx_parse(fixed, fixed_len); free(fixed); if(rx == NULL) return -1; K_REGEX = rx; if(verbose) { fprintf(stderr, "loaded: REGEX = "); rx_dump(stderr, rx); fprintf(stderr, "\n"); } return 0; }