samdump2-1.1.1/0000755000175000001440000000000010721277533012421 5ustar cedricuserssamdump2-1.1.1/AUTHORS0000644000175000001440000000014110563066432013463 0ustar cedricusersNicola Cuomo Cedric Tissieres samdump2-1.1.1/ChangeLog0000644000175000001440000000251610721032342014162 0ustar cedricusers2007-11-21 Cedric Tissieres * Version 1.1.1 * Fix the detection of LM hash We get LM and NT hashes offset and size directly 2007-02-16 Cedric Tissieres * Version 1.1.0 * Code is (should be) portable * Link againt OpenSSL instead of libdes * Fix bugs * Add support for Windows Vista * Code cleaning + debugging * Fix wrong permissions in files * Fix Makefile * Changes to LICENSE 2006-10-15 Adam Cécile (Le_Vert) * Fix wrong permissions in Makefile (777 instead of 755). 2006-10-14 Adam Cécile (Le_Vert) * Bump to version 1.0.0 ! * Update to libdes 4.04b. * Re-write Makefile. * Write a man page. * Move gpl.txt to COPYING. * Add a ChangeLog. * Add a README file containing "syskey.txt" This document describe the obfuscation algorithm used by Windows 2k/NT/XP Syskey and the steps required to remove its encryption from the password hashes * Add Nicola Cuomo copyright in sources files headers. * Write LICENSE file that summarize different copyright and licenses used in this software. * Add an exception to the GPL license to fit with the OpenSSL-like licenses used by Eric Young. 2006-10-13 Nicola Cuomo * Switch to GNU General Public License version 2. samdump2-1.1.1/COPYING0000644000175000001440000004310310563066407013455 0ustar cedricusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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) 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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) year 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 Lesser General Public License instead of this License. samdump2-1.1.1/hive.c0000644000175000001440000002075210721005256013515 0ustar cedricusers/* Hive.c Hive file access, pretty lame and bugged but do the work O_o Thanks to B.D. for file structure info 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. Copyright (C) 2004-2006 Nicola Cuomo Improvments and some bugs fixes by Objectif Securité */ #include #include "hive.h" #ifdef BYTE_ORDER #if BYTE_ORDER == LITTLE_ENDIAN #elif BYTE_ORDER == BIG_ENDIAN #include #else #warning "Doesn't define a standard ENDIAN type" #endif #else #warning "Doesn't define BYTE_ORDER" #endif nk_hdr* read_nk(nk_hdr *nk, struct hive *h, int offset ) { memcpy(nk, h->base+offset+4, sizeof(nk_hdr)); nk->key_name = (h->base+offset+4+76); #if BYTE_ORDER == LITTLE_ENDIAN #elif BYTE_ORDER == BIG_ENDIAN nk->id = __bswap_16(nk->id); nk->type = __bswap_16(nk->type); nk->name_len = __bswap_16(nk->name_len); nk->classname_len = __bswap_16(nk->classname_len); nk->classname_off = __bswap_32(nk->classname_off); nk->unk2 = __bswap_32(nk->unk2); nk->lf_off = __bswap_32(nk->lf_off); nk->value_cnt = __bswap_32(nk->value_cnt); nk->value_off = __bswap_32(nk->value_off); nk->subkey_num = __bswap_32(nk->subkey_num); #endif return nk; } lf_hdr* read_lf(lf_hdr *lf, struct hive *h, int offset ) { memcpy(lf, h->base+offset+4, sizeof(lf_hdr)); lf->hr = (h->base+offset+4+4); #if BYTE_ORDER == LITTLE_ENDIAN #elif BYTE_ORDER == BIG_ENDIAN lf->id = __bswap_16(lf->id); lf->key_num = __bswap_16(lf->key_num); #endif return lf; } vk_hdr* read_vk(vk_hdr *vk, struct hive *h, int offset ) { memcpy(vk, h->base+offset+4, sizeof(vk_hdr)); vk->value_name = (h->base+offset+4+20); #if BYTE_ORDER == LITTLE_ENDIAN #elif BYTE_ORDER == BIG_ENDIAN vk->id = __bswap_16(vk->id); vk->name_len = __bswap_16(vk->name_len); vk->flag = __bswap_16(vk->flag); vk->data_len = __bswap_32(vk->data_len); vk->data_off = __bswap_32(vk->data_off); vk->data_type = __bswap_32(vk->data_type); #endif return vk; } int* read_valuelist(int *value, struct hive *h, int offset, int size ){ int i =0; memcpy(value, h->base+offset+4, size*sizeof(int)); #if BYTE_ORDER == LITTLE_ENDIAN #elif BYTE_ORDER == BIG_ENDIAN for (i=0; ink_offset = __bswap_32(hr->nk_offset); #endif return hr; } unsigned char* read_data(struct hive *h, int offset ) { return ( (unsigned char*) (h->base + offset + 4) ); } void _RegCloseHive( struct hive *h ) { if( h->base != NULL ) free( h->base ); return; } void _InitHive( struct hive *h ) { h->base = NULL; return; } int _RegOpenHive( char *filename, struct hive *h ) { FILE *hiveh; unsigned long hsize; /* Prova ad aprire l'hive */ if( ( hiveh = fopen( filename, "rb" ) ) != NULL ) { if( fseek( hiveh, 0, SEEK_END ) == 0 ) { hsize = ftell( hiveh ); /* Legge il file in memoria */ /* MMF ??? -_- */ h->base = (unsigned char *) malloc( hsize ); fseek( hiveh, 0, SEEK_SET ); if( fread( (void *) h->base, hsize, 1, hiveh ) == 1 ){ #if BYTE_ORDER == LITTLE_ENDIAN if( *((int*)h->base) == 0x66676572 ) { fclose( hiveh ); return 0; } #elif BYTE_ORDER == BIG_ENDIAN if( *((int*)h->base) == __bswap_32( 0x66676572)) { fclose( hiveh ); return 0; } #endif } } fclose( hiveh ); } return -1; } long parself( struct hive *h, char *t, unsigned long off ) { nk_hdr *n; lf_hdr *l; hashrecord *hr; long res; int i; hr = (hashrecord*) malloc(sizeof(hashrecord)); n = (nk_hdr*) malloc(sizeof(nk_hdr)); l = (lf_hdr*) malloc(sizeof(lf_hdr)); l = read_lf(l, h, off ); #ifdef DEBUG printf("off = %x, key_num = %d ", off, l->key_num); #endif for( i = 0; i < l->key_num; i++ ){ hr = read_hr(hr, l->hr, i); n = read_nk(n, h, hr->nk_offset + 0x1000 ); #ifdef DEBUG printf("/ i=%d/%d, keyname = %x, nk_offset = %x\n", i, l->key_num, hr->keyname, hr->nk_offset); printf("//t = %s, keyname = %s, len = %d\n", t, strndup(n->key_name, n->name_len), n->name_len); #endif if( !memcmp( t, n->key_name, n->name_len ) && (strlen(t) == n->name_len)) { res = hr->nk_offset; free(n); free(l); return res; } } free(n); free(l); return -1; } int _RegGetRootKey(struct hive *h, char **root_key) { nk_hdr *n; n = (nk_hdr*) malloc(sizeof(nk_hdr)); n = read_nk(n, h, 0x1020); #ifdef DEBUG printf("id = %x type = %x name_len = %d\n", n->id, n->type, n->name_len); #endif if ( n->id == NK_ID && n->type == NK_ROOT ) { *root_key = (char *)malloc(n->name_len+1); strncpy(*root_key, n->key_name, n->name_len); (*root_key)[n->name_len] = 0; free(n); return 0; } free(n); return -1; } int _RegOpenKey( struct hive *h, char *path, nk_hdr **nr ) { nk_hdr *n; char *t, *tpath; unsigned long noff; n = (nk_hdr*) malloc(sizeof(nk_hdr)); n = read_nk(n, h, 0x1020 ); #ifdef DEBUG printf("id = %x type = %x\n", n->id, n->type); #endif if( n->id == NK_ID && n->type == NK_ROOT ) { tpath = strdup( path ); t = strtok( tpath, "\\" ); #ifdef DEBUG printf("1 %s\n", t); #endif if( !memcmp( t, n->key_name, n->name_len ) ) { t = strtok( NULL, "\\" ); #ifdef DEBUG printf("2 %s %x %x\n", t, n->unk2, n->lf_off); #endif while( t != NULL ) { if( ( noff = parself( h, t, n->lf_off + 0x1000 ) ) == -1 ){ free(n); return -1; } n = read_nk(n, h, noff + 0x1000 ); t = strtok( NULL, "\\" ); #ifdef DEBUG printf("t = %s, noff = %x\n", t, noff); #endif } memcpy(*nr, n, sizeof(nk_hdr)); free(n); return 0; } free( tpath ); } free(n); return -1; } int _RegQueryValue( struct hive *h, char *name, nk_hdr *nr, unsigned char **buff, int *len ) { vk_hdr *v; unsigned int i,j; int *l; v = (vk_hdr*) malloc(sizeof(vk_hdr)); l = (int*) malloc(sizeof(int)*nr->value_cnt); l = read_valuelist(l, h, nr->value_off + 0x1000, nr->value_cnt); *len = 0; for( i = 0; i < nr->value_cnt; i++ ) { v = read_vk(v, h, l[i] + 0x1000 ); if( !memcmp( name, v->value_name, strlen( name ) ) || (name == NULL && ( v->flag & 1 ) == 0 ) ) { #ifdef DEBUG printf("%s len=%x &off=%x off=%x type=%x\n", v->value_name, v->data_len&0x0000FFFF, &(v->data_off), v->data_off, v->data_type); #endif *len = v->data_len & 0x0000FFFF; if (*buff!=NULL) free(*buff); *buff = (unsigned char*)malloc((*len)); if ((*len)< 5 ) { memcpy (*buff, &(v->data_off), (*len)); } else memcpy (*buff, read_data( h, v->data_off + 0x1000),(*len)); #ifdef DEBUG printf("buff = ", (*len)); for (j=0; j<(*len); j++) printf("%.2x", (*buff)[j]); printf("\n"); #endif free(v); return 0; } } free(v); return -1; } int _RegEnumKey( struct hive *h, nk_hdr *nr, int index, char *name, int *namelen ) { lf_hdr *lf; nk_hdr *nk; hashrecord *hr; lf = (lf_hdr*) malloc(sizeof(lf_hdr)); nk = (nk_hdr*) malloc(sizeof(nk_hdr)); hr = (hashrecord*) malloc(sizeof(hashrecord)); #if DEBUG printf("subkey_num = %d\n", nr->subkey_num); #endif if( index < nr->subkey_num ) { lf = read_lf(lf, h, nr->lf_off + 0x1000 ); hr = read_hr(hr, lf->hr, index); nk = read_nk(nk, h, hr->nk_offset + 0x1000 ); memcpy( name, nk->key_name, min( *namelen, nk->name_len ) ); name[ min( *namelen, nk->name_len ) ] = 0; *namelen = nk->name_len; free(lf); return ( (index + 1) < nr->subkey_num ) ? (index + 1) : -1; } free(lf); return -1; } samdump2-1.1.1/hive.h0000644000175000001440000000574310565265366013545 0ustar cedricusers/* Hive.h Hive file access, pretty lame and bugged but do the work O_o Thanks to B.D. for file structure info 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. Copyright (C) 2004-2006 Nicola Cuomo Improvments and some bugs fixes by Objectif Securité */ #ifndef HIVE_H #define HIVE_H #ifdef WIN32 #define BYTE_ORDER LITTLE_ENDIAN #endif #include #include #include #define min(a, b) (((a) < (b)) ? (a) : (b)) struct hive { unsigned char *base; }; typedef struct _nk_hdr { short int id; short int type; int t1, t2; int unk1; int parent_off; int subkey_num; int unk2; int lf_off; int unk3; int value_cnt; int value_off; int sk_off; int classname_off; int unk4[4]; int unk5; short int name_len; short int classname_len; unsigned char *key_name; } nk_hdr; typedef struct _hashrecord { int nk_offset; char keyname[4]; } hashrecord; typedef struct _lf_hdr { short int id; short int key_num; unsigned char *hr; } lf_hdr; typedef struct _vk_hdr { short int id; short int name_len; int data_len; int data_off; int data_type; short int flag; short int unk1; unsigned char *value_name; } vk_hdr; #define NK_ID 0x6B6E #define NK_ROOT 0x2c #define LF_ID 0x666C nk_hdr* read_nk(nk_hdr *nk, struct hive *h, int offset ); lf_hdr* read_lf(lf_hdr *lf, struct hive *h, int offset ); vk_hdr* read_vk(vk_hdr *vk, struct hive *h, int offset ); hashrecord* read_hr(hashrecord *hr, unsigned char *pos, int index ); int* read_valuelist(int *value, struct hive *h, int offset, int size); unsigned char* read_data(struct hive *h, int offset ); void _RegCloseHive( struct hive *h ); void _InitHive( struct hive *h ); int _RegOpenHive( char *filename, struct hive *h ); long parself( struct hive *h, char *t, unsigned long off ); int _RegGetRootKey(struct hive *h, char **root_key); int _RegOpenKey( struct hive *h, char *path, nk_hdr **nr ); int _RegQueryValue( struct hive *h, char *name, nk_hdr *nr, unsigned char **buff, int *len ); int _RegEnumKey( struct hive *h, nk_hdr *nr, int index, char *name, int *namelen ); #endif samdump2-1.1.1/LICENSE0000644000175000001440000001715710563066764013447 0ustar cedricusersSamdump2 is distributed under terms of GNU General Public License : Copyright (C) 2004-2006 Nicola Cuomo 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 package 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 package; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library. You must obey the GNU General Public License in all respects for all of the code used other than OpenSSL. If you modify file(s) with this exception, you may extend this exception to your version of the file(s), but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. If you delete this exception statement from all source files in the program, then also delete it here. The complete text of the GNU General Public License can be found in 'COPYING' file. LICENSE ISSUES ============== The OpenSSL toolkit stays under a dual license, i.e. both the conditions of the OpenSSL License and the original SSLeay license apply to the toolkit. See below for the actual license texts. Actually both licenses are BSD-style Open Source licenses. In case of any license issues related to OpenSSL please contact openssl-core@openssl.org. OpenSSL License --------------- /* ==================================================================== * Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * openssl-core@openssl.org. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.openssl.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED 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 OpenSSL PROJECT OR * ITS 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. * ==================================================================== * * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com). * */ Original SSLeay License ----------------------- /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */ samdump2-1.1.1/Makefile0000644000175000001440000000423710721031745014060 0ustar cedricusers# Copyright (C) 2006, Adam Cécile (Le_Vert) # # 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 # 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-13, USA # General variables DESTDIR = PREFIX = /usr/local/ BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/share/man/man1 INSTALL = $(shell which install) CC = $(shell which gcc) CFLAGS = LIBS = -lssl # Default target all: build # Show some informations infos: @echo "" @echo "###############################################################" @echo "Samdump2 1.0.0 : Dump Windows 2k/NT/XP password hashes" @echo "" @echo "Copyright (C) 2004-2006 Nicola Cuomo " @echo "Distributed under terms of GNU General Public License version 2" @echo "###############################################################" @echo "" # Build target build: infos samdump2 samdump2: hive.o samdump2.o @echo "Building binary..." $(CC) -o $@ $^ $(CFLAGS) $(LIBS) @echo "" # Clean target clean: @echo "Cleaning sources..." rm -f *.o samdump2 *~ @echo "" # Install target install: build infos @echo "Creating directories..." $(INSTALL) -d -m 755 -o root -g root $(DESTDIR)$(BINDIR) $(INSTALL) -d -m 755 -o root -g root $(DESTDIR)$(MANDIR) @echo "Copying binary..." $(INSTALL) samdump2 -m 755 -o root -g root $(DESTDIR)$(BINDIR) @echo "Installing man page..." $(INSTALL) samdump2.1 -m 644 -o root -g root $(DESTDIR)$(MANDIR) @echo "" # Uninstall target uninstall: infos @echo "Deleting binary and manpages..." rm -f $(DESTDIR)$(BINDIR)/samdump2 rm -f $(DESTDIR)$(MANDIR)/samdump2.1 @echo "" samdump2-1.1.1/Makefile.win320000644000175000001440000000434610721277517015033 0ustar cedricusers# Copyright (C) 2006, Adam Cécile (Le_Vert) # # 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 # 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-13, USA # General variables DESTDIR = PREFIX = /usr/local/ BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/share/man/man1 INSTALL = $(shell which install) CC = $(shell which gcc) CFLAGS = -mno-cygwin -DBYTE_ORDER=LITTLE_ENDIAN LFLAGS = -static -mno-cygwin LIBS = -lcrypto # Default target all: build # Show some informations infos: @echo "" @echo "###############################################################" @echo "Samdump2 1.0.0 : Dump Windows 2k/NT/XP password hashes" @echo "" @echo "Copyright (C) 2004-2006 Nicola Cuomo " @echo "Distributed under terms of GNU General Public License version 2" @echo "###############################################################" @echo "" # Build target build: infos samdump2 samdump2: hive.o samdump2.o @echo "Building binary..." $(CC) -o $@ $^ $(LFLAGS) $(LIBS) @echo "" # Clean target clean: @echo "Cleaning sources..." rm -f *.o samdump2 *~ @echo "" # Install target install: build infos @echo "Creating directories..." $(INSTALL) -d -m 755 -o root -g root $(DESTDIR)$(BINDIR) $(INSTALL) -d -m 755 -o root -g root $(DESTDIR)$(MANDIR) @echo "Copying binary..." $(INSTALL) samdump2 -m 755 -o root -g root $(DESTDIR)$(BINDIR) @echo "Installing man page..." $(INSTALL) samdump2.1 -m 644 -o root -g root $(DESTDIR)$(MANDIR) @echo "" # Uninstall target uninstall: infos @echo "Deleting binary and manpages..." rm -f $(DESTDIR)$(BINDIR)/samdump2 rm -f $(DESTDIR)$(MANDIR)/samdump2.1 @echo "" samdump2-1.1.1/README0000644000175000001440000001320510563066407013302 0ustar cedricusersWindows 2k/NT/XP's syskey encryption Syskey is a Windows feature that adds an additional encryption layer to the password hashes stored in the SAM database. The main purpose of this feature is to deter 'offline' attack. In fact one of the most common ways to gather passwords is to copy the system SAM database and then use one of the many good password crackers[1] to "recover" the passwords; of course physical access is almost always required. So with syskey the attacker needs to remove the additional encryption layer to get the password hashes (this is not entirely true as some tools can crack even syskeyed hashes while losing some performance). The key used by Syskey to encrypt the password hashes (called bootkey or system key) can be generated and stored in three ways. The method to use is selected when running syskey.exe on the host. 1) Using a user supplied passphrase(actually the MD5 hash of it). The system will prompt for the passphrase during startup. 2) Using a system generated key stored on a floppy. The system will ask for the boot floppy during startup. 3) Using a system generated key stored on the "the local system using a complex obfuscation algorithm" (citing Microsoft site[2]). This is the default method used. In the first two cases generally nothing can be done. If you cannot get the passphrase or the boot floppy you are compelled to crack the syskeyed hashes. The last case is different. This document describe the "complex obfuscation algorithm" and the steps required to restore the password hashes from their syskeyed equivalent. Some tools are also presented to automate the process. From now on we will talk about the case when the bootkey is stored on the system. During Windows boot phase before user are allowed to logon to the system, the main thread of Smss (Session Manager) starts the Winlogon process. Winlogon is the process required to load the Local Security Subsystem (Lsass) which in turn loads the Security Accounts Manager (SAM) service (the interface to the SAM database). The registry is accessed by the above-mentioned processes. In particular the following keys are accessed: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\JD HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Skew1 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Data HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\GBG The same keys are also accessed during the bootkey generation phase by the Syskey.exe tool. A more in depth analysis of the code accessing these keys uncover that the "complex obfuscation algorithm" is no more than a permutation of the class name of the above-mentioned keys. Is almost trivial to develop a tool to recover the syskey obfuscated bootkey from the registry. To make things simpler on pre SP4 system the ACL on the above keys allows 'Users' read access so a "normal" user can retrieve the registry stored bootkey. The tool developed to make this operation is called Bkreg. On SP4+ system it is still possible to recover the syskey bootkey. The ACLs on the keys only allow Administrator access, so Bkreg can recover the bootkey on SP4 system only if executed by the Administrator. But there is another way to access the registry keys. An attacker can steal (maybe at the same time of the SAM database) the system hive and access from there the above mentioned keys to recover the syskey bootkey. The tool developed to make this operation is called Bkhive. Now we have the bootkey, conveniently stored in a file, and the SAM hive; we need to know how to remove the syskey encryption. The process that decrypts the password hashes (using the bootkey) is Samss. The steps required to do so are: 1) The value 'F' of the registry key SAM\SAM\Domains\Account is accessed. The contents of that value is of binary type. 16 byte (starting at offset 0x70) from the F value are hashed (MD5) with the bootkey and some constant. The result is used as the key to decrypt (RC4) the 32 byte of the F value (starting from 0x80). The first 16 byte of the result are used later in the algorithm. I call them hbootkey. 2) For each rid subkey in SAM\SAM\Domains\Account\Users. The value 'V' of the key is accessed. The content of that value is of binary type and contain the syskey encrypted password hashes. The hbootkey (computed in step 1), the user rid and a constant string( different if decoding NT or lanman password) are hashed (MD5). The result is used as the key to decrypt (RC4) the syskeyed password hashes. So syskey encrypts the password hashes with the RC4 algorithm using as key "something" derived (through MD5) from the syskey bootkey. I've developed a tool to automate the above steps and include the features of SAMDUMP. The tool is called SAMDUMP2; SAMDUMP2 can, when given a SAM hive and a bootkey file (generated by Bkreg or Bkhive), output the password hashes in SAMDUMP/PWDUMP format. So an attacker with physical access can: 0) Boot using another OS (maybe Linux or DOS) 1) Steal the SAM and SYSTEM hive (from %WINDIR%\System32\config) 2) Recover the syskey bootkey from the SYSTEM hive using Bkhive (or Bkreg on pre Sp4 system) 3) Dump the password hashes using SAMDUMP2 4) Crack them offline using his favorite cracking tool References [1] http://www.atstake.com/products/lc/ http://www.oxid.it/cain.html http://www.openwall.com/john/ http://www.openwall.com/passwords/nt.shtml [2] http://support.microsoft.com/support/kb/articles/q143/4/75.asp Nicola Cuomo ncuomo(at)studenti.unina.it Many thanks to Jason R. DePriest for 'patching' my english ^_^ samdump2-1.1.1/samdump2.10000644000175000001440000000131010721032064014212 0ustar cedricusers.TH SAMDUMP2 1 "November 2007" "Version 1.1.1" .SH NAME .B samdump2 dumps Windows 2k/NT/XP/Vista password hashes. .SH SYNOPSIS samdump2 .SH EXAMPLE samdump2 /mnt/ntfs/WINDOWS/system32/config/sam out .SH AUTHOR This manual page was written by Adam Cecile for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B bkhive(1) .br .B ophcrack(1) samdump2-1.1.1/samdump2.c0000644000175000001440000002656710721032543014323 0ustar cedricusers/* Samdump2 Dump nt/lanman password hashes from a sam hive with Syskey enabled Thank to Dmitry Andrianov for the program name ^_^ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This program is released under the GPL with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. Copyright (C) 2004-2006 Nicola Cuomo Improvments and some bugs fixes by Objectif Securité */ #include #include #include #include #include #include "hive.h" #ifdef BYTE_ORDER #if BYTE_ORDER == LITTLE_ENDIAN #elif BYTE_ORDER == BIG_ENDIAN #include #else #warning "Doesn't define a standard ENDIAN type" #endif #else #warning "Doesn't define BYTE_ORDER" #endif /* Cut&Paste from pwdump source code */ /* * Convert a 7 byte array into an 8 byte des key with odd parity. */ void str_to_key(unsigned char *str,unsigned char *key) { // void des_set_odd_parity(des_cblock *); int i; key[0] = str[0]>>1; key[1] = ((str[0]&0x01)<<6) | (str[1]>>2); key[2] = ((str[1]&0x03)<<5) | (str[2]>>3); key[3] = ((str[2]&0x07)<<4) | (str[3]>>4); key[4] = ((str[3]&0x0F)<<3) | (str[4]>>5); key[5] = ((str[4]&0x1F)<<2) | (str[5]>>6); key[6] = ((str[5]&0x3F)<<1) | (str[6]>>7); key[7] = str[6]&0x7F; for (i=0;i<8;i++) { key[i] = (key[i]<<1); } des_set_odd_parity((des_cblock *)key); } /* * Function to convert the RID to the first decrypt key. */ void sid_to_key1(unsigned long sid,unsigned char deskey[8]) { unsigned char s[7]; s[0] = (unsigned char)(sid & 0xFF); s[1] = (unsigned char)((sid>>8) & 0xFF); s[2] = (unsigned char)((sid>>16) & 0xFF); s[3] = (unsigned char)((sid>>24) & 0xFF); s[4] = s[0]; s[5] = s[1]; s[6] = s[2]; str_to_key(s,deskey); } /* * Function to convert the RID to the second decrypt key. */ void sid_to_key2(unsigned long sid,unsigned char deskey[8]) { unsigned char s[7]; s[0] = (unsigned char)((sid>>24) & 0xFF); s[1] = (unsigned char)(sid & 0xFF); s[2] = (unsigned char)((sid>>8) & 0xFF); s[3] = (unsigned char)((sid>>16) & 0xFF); s[4] = s[0]; s[5] = s[1]; s[6] = s[2]; str_to_key(s,deskey); } //--- int main( int argc, char **argv ) { FILE *f; unsigned char bootkey[] = { 0x15, 0xbd, 0x18, 0x82, 0xfa, 0x6e, 0xf7, 0xe3, 0x87, 0x90, 0x67, 0x62, 0xd3, 0xfd, 0x5b, 0x03 }; /* const */ char *regaccountkey, *reguserskey; unsigned char aqwerty[] = "!@#$%^&*()qwertyUIOPAzxcvbnmQQQQQQQQQQQQ)(*@&%"; unsigned char anum[] = "0123456789012345678901234567890123456789"; unsigned char antpassword[] = "NTPASSWORD"; unsigned char almpassword[] = "LMPASSWORD"; char *root_key; /* hive */ struct hive h; nk_hdr *n = NULL; /* hive buffer */ unsigned char *b = NULL; int blen; unsigned char regkeyname[50]; int regkeynamelen; char *keyname; /* md5 contex, hash, rc4 key, hashed bootkey */ MD5_CTX md5c; unsigned char md5hash[0x10]; RC4_KEY rc4k; unsigned char hbootkey[0x20]; /* Des */ des_key_schedule ks1, ks2; des_cblock deskey1, deskey2; int i, j, z; char *username; int rid; int usernameoffset, usernamelen; int lm_hashesoffset, nt_hashesoffset; int lm_size, nt_size; unsigned char obfkey[0x10]; unsigned char fb[0x10]; fprintf(stderr, "samdump2 1.1.1 by Objectif Securite\nhttp://www.objectif-securite.ch\noriginal author: ncuomo@studenti.unina.it\n\n" ); if( argc != 3 ) { printf( "Usage:\nsamdump2 samhive keyfile\n" ); return -1; } /* Open bootkey file */ if( ( f = fopen( argv[2], "rb" ) ) != NULL ) { fread( &bootkey, 1, 16, f ); fclose( f ); } else { fprintf( stderr, "Error reading from %s\n", argv[2] ); return -1; } /* Initialize registry access function */ _InitHive( &h ); /* Open sam hive */ if( _RegOpenHive( argv[1], &h ) ) { fprintf( stderr, "Error opening sam hive or not valid file(\"%s\")\n", argv[1] ); return -1; } /* Get Root key name SAM for 2k/XP, CMI-CreateHive{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx} for Vista */ if( _RegGetRootKey( &h, &root_key)) { fprintf( stderr, "Error reading hive root key\n"); return -1; } fprintf(stderr, "Root Key : %s\n", root_key); regaccountkey = (char *) malloc(strlen(root_key)+30); reguserskey = (char *) malloc(strlen(root_key)+30); sprintf(regaccountkey, "%s\\SAM\\Domains\\Account", root_key); sprintf(reguserskey, "%s\\SAM\\Domains\\Account\\Users", root_key); n = (nk_hdr*) malloc(sizeof(nk_hdr)); /* Open SAM\\SAM\\Domains\\Account key*/ if( _RegOpenKey( &h, regaccountkey, &n ) ) { _RegCloseHive( &h ); fprintf( stderr, "%s key!\n", regaccountkey ); return -1; } if( _RegQueryValue( &h, "F", n, &b, &blen ) ) { _RegCloseHive( &h ); fprintf( stderr, "No F!\n" ); return -1; } /* hash the bootkey */ MD5_Init( &md5c ); MD5_Update( &md5c, &b[0x70], 0x10 ); MD5_Update( &md5c, aqwerty, 0x2f ); MD5_Update( &md5c, bootkey, 0x10 ); MD5_Update( &md5c, anum, 0x29 ); MD5_Final( md5hash, &md5c ); RC4_set_key( &rc4k, 0x10, md5hash ); RC4( &rc4k, 0x20, &b[0x80], hbootkey ); j = 0; /* Enumerate user */ while( j != -1 ) { /* Open SAM\\SAM\\Domains\\Account\\Users */ if( _RegOpenKey( &h, reguserskey, &n ) ) { _RegCloseHive( &h ); fprintf( stderr, "No Users key!\n" ); return -1; } regkeynamelen = sizeof( regkeyname ); j = _RegEnumKey( &h, n, j, (char*)regkeyname, ®keynamelen ); #if DEBUG printf("******************** %d ********************\n", j); #endif /* Skip Names key */ if( !memcmp( regkeyname, "Names", regkeynamelen ) ) continue; keyname = (char*) malloc( strlen( reguserskey ) + regkeynamelen + 2 ); /* Open SAM\\SAM\\Domains\\Account\\Users\\userrid */ strcpy( keyname, reguserskey ); strcat( keyname, "\\" ) ; strcat( keyname, (char*)regkeyname ) ; if( _RegOpenKey( &h, keyname, &n ) ) { _RegCloseHive( &h ); fprintf( stderr, "Asd -_- _RegEnumKey fail!\n" ); return -1; } if( _RegQueryValue( &h, "V", n, &b, &blen ) ) { _RegCloseHive( &h ); fprintf( stderr, "No V value!\n" ); return -1; } /* rid */ rid = strtoul( (char*)regkeyname, NULL, 16 ); /* get the username */ /* 0x10 username size 0xc username offset */ #if BYTE_ORDER == LITTLE_ENDIAN usernamelen = *(int*)(b + 0x10) >> 1; #elif BYTE_ORDER == BIG_ENDIAN usernamelen = __bswap_32(*(int*)(b + 0x10) >> 1); #endif usernameoffset = b[0xc] + 0xcc; #ifdef DEBUG printf("\nusername len=%d, off=%x\n", usernamelen, usernameoffset); #endif username = (char *) malloc( usernamelen + 1 ); // Quick hack for unicode -> ascii translation for( z = 0; z < usernamelen; z++) username[z] = b[usernameoffset + z*2]; username[ usernamelen ] = 0; #if BYTE_ORDER == LITTLE_ENDIAN lm_hashesoffset = *(int *)(b + 0x9c ) + 0xcc; lm_size = *(int *)(b + 0xa0 ); nt_hashesoffset = *(int *)(b + 0xa8 ) + 0xcc; nt_size = *(int *)(b + 0xac ); #elif BYTE_ORDER == BIG_ENDIAN lm_hashesoffset = __bswap_32(*(int *)(b + 0x9c )) + 0xcc; lm_size = __bswap_32(*(int *)(b + 0xa0 )); nt_hashesoffset = __bswap_32(*(int *)(b + 0xa8 )) + 0xcc; nt_size = __bswap_32(*(int *)(b + 0xac )); #endif #ifdef DEBUG printf("lm_hashoffset = %x, lm_size = %x\n", lm_hashesoffset, lm_size); printf("nt_hashoffset = %x, nt_size = %x\n", nt_hashesoffset, nt_size); #endif /* Print the user hash */ printf( "%s:%d:", username, rid ); if( lm_size == 0x14 ) { #ifdef DEBUG printf("\n"); for( i = 0; i < 0x10; i++ ) printf( "%.2x", b[lm_hashesoffset+4+i] ); #endif /* LANMAN */ /* hash the hbootkey and decode lanman password hashes */ MD5_Init( &md5c ); MD5_Update( &md5c, hbootkey, 0x10 ); #if BYTE_ORDER == LITTLE_ENDIAN MD5_Update( &md5c, &rid, 0x4 ); #elif BYTE_ORDER == BIG_ENDIAN rid = __bswap_32(rid); MD5_Update( &md5c, &rid, 0x4 ); rid = __bswap_32(rid); #endif MD5_Update( &md5c, almpassword, 0xb ); MD5_Final( md5hash, &md5c ); RC4_set_key( &rc4k, 0x10, md5hash ); RC4( &rc4k, 0x10, &b[ lm_hashesoffset + 4 ], obfkey ); #ifdef DEBUG printf("\nobfkey: "); for( i = 0; i < 0x10; i++ ) printf( "%.2x", (unsigned char)obfkey[i] ); printf("\n"); #endif /* From Pwdump */ /* Get the two decrpt keys. */ sid_to_key1(rid,(unsigned char *)deskey1); des_set_key_checked((des_cblock *)deskey1,ks1); sid_to_key2(rid,(unsigned char *)deskey2); des_set_key_unchecked((des_cblock *)deskey2,ks2); /* Decrypt the lanman password hash as two 8 byte blocks. */ des_ecb_encrypt((des_cblock *)obfkey, (des_cblock *)fb, ks1, DES_DECRYPT); des_ecb_encrypt((des_cblock *)(obfkey + 8), (des_cblock *)&fb[8], ks2, DES_DECRYPT); // sf25( obfkey, (int*)&rid, fb ); for( i = 0; i < 0x10; i++ ) printf( "%.2x", fb[i] ); } else { printf( "aad3b435b51404eeaad3b435b51404ee" ); } printf( ":" ); if( nt_size == 0x14 ) { #ifdef DEBUG printf("\n"); for( i = 0; i < 0x10; i++ ) printf( "%.2x", b[nt_hashesoffset+4+i] ); printf("\n"); #endif /* NT */ /* hash the hbootkey and decode the nt password hashes */ MD5_Init( &md5c ); MD5_Update( &md5c, hbootkey, 0x10 ); #if BYTE_ORDER == LITTLE_ENDIAN MD5_Update( &md5c, &rid, 0x4 ); #elif BYTE_ORDER == BIG_ENDIAN rid = __bswap_32(rid); MD5_Update( &md5c, &rid, 0x4 ); rid = __bswap_32(rid); #endif MD5_Update( &md5c, antpassword, 0xb ); MD5_Final( md5hash, &md5c ); RC4_set_key( &rc4k, 0x10, md5hash ); RC4( &rc4k, 0x10, &b[ nt_hashesoffset + 4], obfkey ); if (lm_size != 0x14) { /* Get the two decrpt keys. */ sid_to_key1(rid,(unsigned char *)deskey1); des_set_key((des_cblock *)deskey1,ks1); sid_to_key2(rid,(unsigned char *)deskey2); des_set_key((des_cblock *)deskey2,ks2); } /* Decrypt the NT md4 password hash as two 8 byte blocks. */ des_ecb_encrypt((des_cblock *)obfkey, (des_cblock *)fb, ks1, DES_DECRYPT); des_ecb_encrypt((des_cblock *)(obfkey + 8), (des_cblock *)&fb[8], ks2, DES_DECRYPT); /* sf27 wrap to sf25 */ //sf27( obfkey, (int*)&rid, fb ); for( i = 0; i < 0x10; i++ ) printf( "%.2x", fb[i] ); } else { printf("31d6cfe0d16ae931b73c59d7e0c089c0"); } printf( ":::\n" ); free( username ); free( keyname ); } _RegCloseHive( &h ); free(n); free(b); return 0; }