enumwebclient.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include "enumwebclient.h"
  4. #include "beacon.h"
  5. //START TrustedSec BOF print code: https://github.com/trustedsec/CS-Situational-Awareness-BOF/blob/master/src/common/base.c
  6. #ifndef bufsize
  7. #define bufsize 8192
  8. #endif
  9. char *output = 0;
  10. WORD currentoutsize = 0;
  11. HANDLE trash = NULL;
  12. int bofstart();
  13. void internal_printf(const char* format, ...);
  14. void printoutput(BOOL done);
  15. int bofstart() {
  16. output = (char*)MSVCRT$calloc(bufsize, 1);
  17. currentoutsize = 0;
  18. return 1;
  19. }
  20. void internal_printf(const char* format, ...){
  21. int buffersize = 0;
  22. int transfersize = 0;
  23. char * curloc = NULL;
  24. char* intBuffer = NULL;
  25. va_list args;
  26. va_start(args, format);
  27. buffersize = MSVCRT$vsnprintf(NULL, 0, format, args);
  28. va_end(args);
  29. if (buffersize == -1) return;
  30. char* transferBuffer = (char*)KERNEL32$HeapAlloc(KERNEL32$GetProcessHeap(), HEAP_ZERO_MEMORY, bufsize);
  31. intBuffer = (char*)KERNEL32$HeapAlloc(KERNEL32$GetProcessHeap(), HEAP_ZERO_MEMORY, buffersize);
  32. va_start(args, format);
  33. MSVCRT$vsnprintf(intBuffer, buffersize, format, args);
  34. va_end(args);
  35. if(buffersize + currentoutsize < bufsize)
  36. {
  37. MSVCRT$memcpy(output+currentoutsize, intBuffer, buffersize);
  38. currentoutsize += buffersize;
  39. } else {
  40. curloc = intBuffer;
  41. while(buffersize > 0)
  42. {
  43. transfersize = bufsize - currentoutsize;
  44. if(buffersize < transfersize)
  45. {
  46. transfersize = buffersize;
  47. }
  48. MSVCRT$memcpy(output+currentoutsize, curloc, transfersize);
  49. currentoutsize += transfersize;
  50. if(currentoutsize == bufsize)
  51. {
  52. printoutput(FALSE);
  53. }
  54. MSVCRT$memset(transferBuffer, 0, transfersize);
  55. curloc += transfersize;
  56. buffersize -= transfersize;
  57. }
  58. }
  59. KERNEL32$HeapFree(KERNEL32$GetProcessHeap(), 0, intBuffer);
  60. KERNEL32$HeapFree(KERNEL32$GetProcessHeap(), 0, transferBuffer);
  61. }
  62. void printoutput(BOOL done) {
  63. char * msg = NULL;
  64. BeaconOutput(CALLBACK_OUTPUT, output, currentoutsize);
  65. currentoutsize = 0;
  66. MSVCRT$memset(output, 0, bufsize);
  67. if(done) {MSVCRT$free(output); output=NULL;}
  68. }
  69. //END TrustedSec BOF print code.
  70. int go(char *args, int len) {
  71. char* pipeNameHead = "\\\\";
  72. char* pipeNameTail = "\\pipe\\DAV RPC SERVICE";
  73. BOOL pipeStatus = 0;
  74. char* hostname;
  75. char* nextHostname;
  76. char* debug;
  77. int iBytesLen = 0;
  78. CHAR *hostFileBytes;
  79. datap parser;
  80. BeaconDataParse(&parser, args, len);
  81. hostFileBytes = BeaconDataExtract(&parser, &iBytesLen);
  82. debug = BeaconDataExtract(&parser, NULL);
  83. if(!bofstart()) return;
  84. if(iBytesLen != 0) {
  85. BeaconPrintf(CALLBACK_OUTPUT, "[*] Loaded file in memory with a size of %d bytes\n", iBytesLen);
  86. internal_printf("\nEnumeration results:\n");
  87. internal_printf("==============================================\n");
  88. hostname = MSVCRT$strtok(hostFileBytes, "\r\n");
  89. while (hostname != NULL) {
  90. nextHostname = MSVCRT$strtok(NULL, "\r\n");
  91. if (nextHostname == NULL) {
  92. break;
  93. }
  94. size_t len = MSVCRT$strlen(hostname);
  95. char* fullPipeName = (char*) MSVCRT$malloc(len + MSVCRT$strlen(pipeNameHead) + MSVCRT$strlen(pipeNameTail) + 1);
  96. MSVCRT$strcpy(fullPipeName, pipeNameHead);
  97. MSVCRT$strcat(fullPipeName, hostname);
  98. MSVCRT$strcat(fullPipeName, pipeNameTail);
  99. pipeStatus = KERNEL32$WaitNamedPipeA(fullPipeName, 3000);
  100. if (pipeStatus == 0 && (MSVCRT$strcmp(debug, "debug") == 0)) {
  101. internal_printf("[-] WebClient service not running on %s\n", hostname);
  102. } else if (pipeStatus == 0) {
  103. } else {
  104. internal_printf("[+] WebClient running on %s\n", hostname);
  105. }
  106. MSVCRT$free(fullPipeName);
  107. hostname = nextHostname;
  108. }
  109. printoutput(TRUE);
  110. } else {
  111. BeaconPrintf(CALLBACK_ERROR, "Couldn't load the host file from disk.\n");
  112. }
  113. return 0;
  114. }