dsm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <assert.h>
  22. #include <unistd.h>
  23. #include <errno.h>
  24. #include <sys/socket.h>
  25. #include <netinet/in.h>
  26. #include <netinet/ip.h>
  27. #include <netinet/udp.h>
  28. #include <arpa/inet.h>
  29. #define NBT_UDP_PORT 138
  30. #define NBT_TCP_PORT 139
  31. #include "bdsm.h"
  32. #include "bdsm/netbios_utils.h"
  33. #include "bdsm/netbios_session.h"
  34. #include "bdsm/smb_session.h"
  35. #include "bdsm/smb_ntlm.h"
  36. #include "bdsm/smb_share.h"
  37. #include <openssl/md4.h>
  38. #include <openssl/md5.h>
  39. int main(int ac, char **av)
  40. {
  41. struct sockaddr_in addr;
  42. bdsm_context_t *ctx;
  43. ctx = bdsm_context_new();
  44. assert(ctx);
  45. addr.sin_addr.s_addr = netbios_ns_resolve(ctx->ns, av[1], NETBIOS_FILESERVER);
  46. printf("%s's IP address is : %s\n", av[1], inet_ntoa(addr.sin_addr));
  47. //netbios_ns_discover(ctx->ns);
  48. //exit(0);
  49. // netbios_session_t *session;
  50. // session = netbios_session_new(addr.sin_addr.s_addr);
  51. // if (netbios_session_connect(session, "Cerbere"))
  52. // printf("A NetBIOS session with %s has been established\n", av[1]);
  53. // else
  54. // {
  55. // printf("Unable to establish a NetBIOS session with %s\n", av[1]);
  56. // exit(21);
  57. // }
  58. // netbios_session_destroy(session);
  59. smb_session_t *session;
  60. session = smb_session_new();
  61. if (smb_session_connect(session, av[1], addr.sin_addr.s_addr))
  62. printf("Successfully connected to %s\n", av[1]);
  63. else
  64. {
  65. printf("Unable to connect to %s\n", av[1]);
  66. exit(42);
  67. }
  68. if (smb_negotiate(session))
  69. {
  70. fprintf(stderr, "Dialect/Security Mode negotation success.\n");
  71. fprintf(stderr, "Session key is 0x%x\n", session->srv.session_key);
  72. fprintf(stderr, "Challenge key is 0x%lx\n", session->srv.challenge);
  73. }
  74. else
  75. {
  76. printf("Unable to negotiate SMB Dialect\n");
  77. exit(42);
  78. }
  79. if (smb_authenticate(session, av[1], av[2], av[3]))
  80. {
  81. if (session->guest)
  82. printf("Login FAILED but we were logged in as GUEST \n");
  83. else
  84. printf("Successfully logged in as %s\\%s\n", av[1], av[2]);
  85. }
  86. else
  87. {
  88. printf("Authentication FAILURE.\n");
  89. exit(42);
  90. }
  91. smb_tid ipc = smb_tree_connect(session, "\\\\CERBERE\\IPC$");
  92. smb_tid test = smb_tree_connect(session, "\\\\CERBERE\\TEST");
  93. if (ipc == 0)
  94. {
  95. fprintf(stderr, "Unable to connect to IPC$ share\n");
  96. exit(42);
  97. }
  98. fprintf(stderr, "Connected to IPC$ share\n");
  99. smb_session_destroy(session);
  100. bdsm_context_destroy(ctx);
  101. return (0);
  102. }