chntpw-140201-port-to-gcrypt-debian.patch 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. diff -Naur chntpw-140201.orig/Makefile chntpw-140201/Makefile
  2. --- chntpw-140201.orig/Makefile 2014-02-01 17:54:37.000000000 +0100
  3. +++ chntpw-140201/Makefile 2021-04-04 19:25:52.517404000 +0200
  4. @@ -1,32 +1,14 @@
  5. #
  6. # Makefile for the Offline NT Password Editor
  7. #
  8. -#
  9. -# Change here to point to the needed OpenSSL libraries & .h files
  10. -# See INSTALL for more info.
  11. -#
  12. -
  13. -#SSLPATH=/usr/local/ssl
  14. -OSSLPATH=/usr
  15. -OSSLINC=$(OSSLPATH)/include
  16. CC=gcc
  17. +CFLAGS=-DUSELIBGCRYPT -g -I. $(shell libgcrypt-config --cflags) -Wall $(EXTRA_CFLAGS)
  18. -# Force 32 bit
  19. -CFLAGS= -DUSEOPENSSL -g -I. -I$(OSSLINC) -Wall -m32
  20. -OSSLLIB=$(OSSLPATH)/lib
  21. -
  22. -# 64 bit if default for compiler setup
  23. -#CFLAGS= -DUSEOPENSSL -g -I. -I$(OSSLINC) -Wall
  24. -#OSSLLIB=$(OSSLPATH)/lib64
  25. -
  26. -
  27. -# This is to link with whatever we have, SSL crypto lib we put in static
  28. -#LIBS=-L$(OSSLLIB) $(OSSLLIB)/libcrypto.a
  29. -LIBS=-L$(OSSLLIB)
  30. +LIBS=$(shell libgcrypt-config --libs)
  31. -all: chntpw chntpw.static cpnt reged reged.static samusrgrp samusrgrp.static sampasswd sampasswd.static
  32. +all: chntpw cpnt reged samusrgrp sampasswd
  33. chntpw: chntpw.o ntreg.o edlib.o libsam.o
  34. $(CC) $(CFLAGS) -o chntpw chntpw.o ntreg.o edlib.o libsam.o $(LIBS)
  35. diff -Naur chntpw-140201.orig/chntpw.c chntpw-140201/chntpw.c
  36. --- chntpw-140201.orig/chntpw.c 2014-02-01 17:54:37.000000000 +0100
  37. +++ chntpw-140201/chntpw.c 2021-04-04 19:24:37.185404000 +0200
  38. @@ -16,6 +16,7 @@
  39. * 2010-jun: Syskey not visible in menu, but is selectable (2)
  40. * 2010-apr: Interactive menu adapts to show most relevant
  41. * selections based on what is loaded
  42. + * 2008-may: port to libgcrypt to avoid GPL/OpenSSL incompatibility [Debian]
  43. * 2008-mar: Minor other tweaks
  44. * 2008-mar: Interactive reg ed moved out of this file, into edlib.c
  45. * 2008-mar: 64 bit compatible patch by Mike Doty, via Alon Bar-Lev
  46. @@ -79,8 +80,14 @@
  47. */
  48. #ifdef DOCRYPTO
  49. +#if defined(USEOPENSSL)
  50. #include <openssl/des.h>
  51. #include <openssl/md4.h>
  52. +#elif defined(USELIBGCRYPT)
  53. + #include <gcrypt.h>
  54. +#else
  55. + #error No DES encryption and MD4 hashing library found
  56. +#endif
  57. #endif
  58. #define uchar u_char
  59. @@ -155,7 +162,9 @@
  60. for (i=0;i<8;i++) {
  61. key[i] = (key[i]<<1);
  62. }
  63. +#if defined(USEOPENSSL)
  64. DES_set_odd_parity((des_cblock *)key);
  65. +#endif
  66. }
  67. /*
  68. @@ -200,6 +209,7 @@
  69. void E1(uchar *k, uchar *d, uchar *out)
  70. {
  71. +#if defined(USEOPENSSL)
  72. des_key_schedule ks;
  73. des_cblock deskey;
  74. @@ -210,6 +220,15 @@
  75. des_set_key((des_cblock *)deskey,ks);
  76. #endif /* __FreeBsd__ */
  77. des_ecb_encrypt((des_cblock *)d,(des_cblock *)out, ks, DES_ENCRYPT);
  78. +#elif defined(USELIBGCRYPT)
  79. + gcry_cipher_hd_t ks;
  80. + uchar deskey[8];
  81. + str_to_key(k,deskey);
  82. + gcry_cipher_open(&ks, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_ECB, 0);
  83. + gcry_cipher_setkey(ks, deskey, 8);
  84. + gcry_cipher_encrypt(ks, out, 8, d, 8);
  85. + gcry_cipher_close(ks);
  86. +#endif
  87. }
  88. #endif /* DOCRYPTO */
  89. @@ -343,9 +362,16 @@
  90. int i;
  91. char md4[32],lanman[32];
  92. char newunipw[34], despw[20], newlanpw[16], newlandes[20];
  93. +#ifdef USEOPENSSL
  94. des_key_schedule ks1, ks2;
  95. des_cblock deskey1, deskey2;
  96. MD4_CTX context;
  97. +#elif defined(USELIBGCRYPT)
  98. + gcry_cipher_hd_t ks1, ks2;
  99. + uchar deskey1[8], deskey2[8];
  100. + unsigned char *p;
  101. + gcry_md_hd_t context;
  102. +#endif
  103. unsigned char digest[16];
  104. uchar x1[] = {0x4B,0x47,0x53,0x21,0x40,0x23,0x24,0x25};
  105. #endif
  106. @@ -460,6 +486,7 @@
  107. }
  108. #ifdef DOCRYPTO
  109. +#if defined(USEOPENSSL)
  110. /* Get the two decrpt keys. */
  111. sid_to_key1(rid,(unsigned char *)deskey1);
  112. des_set_key((des_cblock *)deskey1,ks1);
  113. @@ -477,6 +504,25 @@
  114. (des_cblock *)lanman, ks1, DES_DECRYPT);
  115. des_ecb_encrypt((des_cblock *)(vp+lmpw_offs + 8),
  116. (des_cblock *)&lanman[8], ks2, DES_DECRYPT);
  117. +#elif defined(USELIBGCRYPT)
  118. + /* Start the keys */
  119. + gcry_cipher_open(&ks1, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_ECB, 0);
  120. + gcry_cipher_open(&ks2, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_ECB, 0);
  121. +
  122. + /* Get the two decrpt keys. */
  123. + sid_to_key1(rid,deskey1);
  124. + gcry_cipher_setkey(ks1, deskey1, 8);
  125. + sid_to_key2(rid,deskey2);
  126. + gcry_cipher_setkey(ks2, deskey2, 8);
  127. +
  128. + /* Decrypt the NT md4 password hash as two 8 byte blocks. */
  129. + gcry_cipher_decrypt(ks1, md4, 8, vp+ntpw_offs, 8);
  130. + gcry_cipher_decrypt(ks2, &md4[8], 8, vp+ntpw_offs+8, 8);
  131. +
  132. + /* Decrypt the lanman password hash as two 8 byte blocks. */
  133. + gcry_cipher_decrypt(ks1, lanman, 8, vp+lmpw_offs, 8);
  134. + gcry_cipher_decrypt(ks2, &lanman[8], 8, vp+lmpw_offs+8, 8);
  135. +#endif
  136. if (gverbose) {
  137. hexprnt("MD4 hash : ",(unsigned char *)md4,16);
  138. @@ -544,9 +590,17 @@
  139. /* printf("Ucase Lanman: %s\n",newlanpw); */
  140. +#if defined(USEOPENSSL)
  141. MD4Init (&context);
  142. MD4Update (&context, newunipw, pl<<1);
  143. MD4Final (digest, &context);
  144. +#elif defined(USELIBGCRYPT)
  145. + gcry_md_open(&context, GCRY_MD_MD4, 0);
  146. + gcry_md_write(context, newunipw, pl<<1);
  147. + p = gcry_md_read(context, GCRY_MD_MD4);
  148. + if(p) memcpy(digest, p, gcry_md_get_algo_dlen(GCRY_MD_MD4));
  149. + gcry_md_close(context);
  150. +#endif
  151. if (gverbose) hexprnt("\nNEW MD4 hash : ",digest,16);
  152. @@ -555,6 +609,7 @@
  153. if (gverbose) hexprnt("NEW LANMAN hash : ",(unsigned char *)lanman,16);
  154. +#if defined(USEOPENSSL)
  155. /* Encrypt the NT md4 password hash as two 8 byte blocks. */
  156. des_ecb_encrypt((des_cblock *)digest,
  157. (des_cblock *)despw, ks1, DES_ENCRYPT);
  158. @@ -565,6 +620,18 @@
  159. (des_cblock *)newlandes, ks1, DES_ENCRYPT);
  160. des_ecb_encrypt((des_cblock *)(lanman+8),
  161. (des_cblock *)&newlandes[8], ks2, DES_ENCRYPT);
  162. +#elif defined(USELIBGCRYPT)
  163. + /* Encrypt the NT md4 password hash as two 8 byte blocks. */
  164. + gcry_cipher_encrypt(ks1, despw, 8, digest, 8);
  165. + gcry_cipher_encrypt(ks2, &despw[8], 8, digest+8, 8);
  166. +
  167. + gcry_cipher_encrypt(ks1, newlandes, 8, lanman, 8);
  168. + gcry_cipher_encrypt(ks2, &newlandes[8], 8, lanman+8, 8);
  169. +
  170. + /* Close keys, not needed after this */
  171. + gcry_cipher_close(ks1);
  172. + gcry_cipher_close(ks2);
  173. +#endif
  174. if (gverbose) {
  175. hexprnt("NEW DES crypt : ",(unsigned char *)despw,16);