ntlm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //---------------------------------------------------------------------------
  2. // __________________ _________ _____ _____ .__ ._.
  3. // \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. // | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. // | | \| ` \/ / Y \ / | | \ ___/ \|
  6. // |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. // \/ \/ \/ \/ )/ \/ \/ \/
  8. //
  9. // This file is part of libdsm. Copyright © 2014 VideoLabs SAS
  10. //
  11. // Author: Julien 'Lta' BALLET <contact@lta.io>
  12. //
  13. // This program is free software. It comes without any warranty, to the extent
  14. // permitted by applicable law. You can redistribute it and/or modify it under
  15. // the terms of the Do What The Fuck You Want To Public License, Version 2, as
  16. // published by Sam Hocevar. See the COPYING file for more details.
  17. //----------------------------------------------------------------------------
  18. #define _BSD_SOURCE /* See feature_test_macros(7) */
  19. #include <endian.h>
  20. #include <assert.h>
  21. #include <ctype.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include "mdx/md4.h"
  25. #include "rc4/rc4.h"
  26. #include "bdsm/debug.h"
  27. #include "bdsm/smb_ntlm.h"
  28. int hexprint(const char *name, const char *data, size_t data_sz)
  29. {
  30. printf("%s =", name);
  31. for(size_t i = 0; i < data_sz; i++)
  32. {
  33. if (i % 16 == 0)
  34. {
  35. printf("\n0x");
  36. }
  37. printf("%0.2hhx", *(data + i));
  38. }
  39. printf("\n");
  40. }
  41. int main(int argc, char const *argv[])
  42. {
  43. // const char *user = "lta";//"BDSM";
  44. // const char *password = "lta";//"qweasd42";
  45. // const char *domain = "MACBOOKPRO-F13E";//"CERBERE";
  46. const char *user = "BDSM";
  47. const char *password = "qweasd";
  48. const char *domain = "STELLAR";
  49. const char *computer = "COMPUTER";
  50. //const char *session_key = "UUUUUUUUUUUUUUUU";
  51. //uint64_t srv_challenge = htobe64(0xe4de7b5beb9ed434);
  52. //uint64_t usr_challenge = htobe64(0x536843b23b75eb7f);
  53. uint64_t srv_challenge = htobe64(0x80206d74ea232d2c);
  54. uint64_t usr_challenge = htobe64(0x9a12f85759053d89);
  55. uint64_t srv_ts = htobe64(0x80b0dda51669cf01);
  56. uint64_t srv_ts2 = htobe64(0x34fd56df1669cf01);
  57. char *lm2, *ntlm2;
  58. smb_ntlm_blob *blob;
  59. size_t blob_sz;
  60. smb_ntlmh hashv1, hashv2, xkey, xkey_crypt;
  61. smb_ntlm_hash(password, hashv1);
  62. smb_ntlm2_hash(user, password, domain, hashv2);
  63. lm2 = smb_lm2_response(hashv2, srv_challenge, usr_challenge);
  64. blob_sz = 16;//smb_ntlm_make_blob(&blob, srv_ts, usr_challenge, domain, domain, srv_ts2);
  65. ntlm2 = smb_ntlm2_response(&hashv2, srv_challenge, lm2, blob_sz);
  66. //smb_ntlm2_session_key(&hashv2, ntlm2, &session_key);
  67. smb_ntlm_generate_xkey(xkey);
  68. smb_ntlm2_session_key(&hashv2, ntlm2, xkey, xkey_crypt);
  69. // MD4_CTX ctx;
  70. // MD4_Init(&ctx);
  71. // MD4_Update(&ctx, hashv1, 16);
  72. // MD4_Final(session_key, &ctx);
  73. hexprint("Srv Challenge", &srv_challenge, 8);
  74. hexprint("Usr Challenge", &usr_challenge, 8);
  75. //printf("Server challenge = %.8lx\n", srv_challenge);
  76. //printf("User challenge = %.8lx\n", usr_challenge);
  77. printf("Timestamp = %.8lx\n", srv_ts);
  78. printf("-------------------------------------\n");
  79. hexprint("NT# v1", hashv1, 16);
  80. hexprint("NT# v2", hashv2, 16);
  81. hexprint("LMv2 Response", lm2, 24);
  82. hexprint("NTLMv2 Response", ntlm2, blob_sz + 16);
  83. hexprint("Session Key", xkey_crypt, 16);
  84. return 0;
  85. }