CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/uso_trigger/MiniUsoClient.cpp
Views: 11766
1
2
#include "MiniUsoClient.h"
3
4
#pragma comment(lib, "rpcrt4.lib")
5
6
MiniUsoClient::MiniUsoClient()
7
{
8
HRESULT hResult;
9
10
hResult = CoInitializeEx(0, COINIT_MULTITHREADED);
11
if (FAILED(hResult))
12
{
13
//wprintf_s(L" |__ CoInitializeEx() failed. Error code = 0x%08X\n", hResult);
14
_ready = false;
15
}
16
else
17
{
18
_ready = true;
19
}
20
}
21
22
MiniUsoClient::~MiniUsoClient()
23
{
24
CoUninitialize();
25
}
26
27
void MiniUsoClient::ThrowOnError(HRESULT hResult)
28
{
29
if (hResult != 0)
30
{
31
throw _com_error(hResult);
32
}
33
}
34
35
36
bool MiniUsoClient::Run(UsoAction action)
37
{
38
HRESULT hResult;
39
40
if (this->_ready)
41
{
42
//wprintf_s(L" |__ Creating instance of 'UpdateSessionOrchestrator'... ");
43
44
GUID CLSID_UpdateSessionOrchestrator = { 0xb91d5831, 0xb1bd, 0x4608, { 0x81, 0x98, 0xd7, 0x2e, 0x15, 0x50, 0x20, 0xf7 } };
45
IUpdateSessionOrchestratorPtr updateSessionOrchestrator;
46
hResult = CoCreateInstance(CLSID_UpdateSessionOrchestrator, nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&updateSessionOrchestrator));
47
if (FAILED(hResult))
48
{
49
//wprintf_s(L"\n |__ CoCreateInstance() failed. Error code = 0x%08X\n", hResult);
50
CoUninitialize();
51
return false;
52
}
53
54
//wprintf_s(L"Done.\n");
55
56
/*
57
try
58
{
59
ThrowOnError(updateSessionOrchestrator->LogTaskRunning(L"StartScan"));
60
}
61
catch (const _com_error& error)
62
{
63
//wprintf(L" |__ LogTaskRunning() - Return code: 0x%08X (\"%s\")\n", error.Error(), error.ErrorMessage());
64
}
65
*/
66
67
IUsoSessionCommonPtr usoSessionCommon;
68
GUID IID_IUsoSessionCommon = { 0xfccc288d, 0xb47e, 0x41fa, { 0x97, 0x0c, 0x93, 0x5e, 0xc9, 0x52, 0xf4, 0xa4 } };
69
try
70
{
71
//wprintf_s(L" |__ Creating a new Update Session... ");
72
updateSessionOrchestrator->CreateUpdateSession(1, &IID_IUsoSessionCommon, &usoSessionCommon);
73
//wprintf_s(L"Done.\n");
74
75
//wprintf_s(L" |__ Calling 'CoSetProxyBlanket()'... ");
76
ThrowOnError(CoSetProxyBlanket(usoSessionCommon, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, NULL));
77
//wprintf_s(L"Done.\n");
78
79
switch (action)
80
{
81
case USO_STARTSCAN:
82
//wprintf(L" |__ Calling 'StartScan'... ");
83
ThrowOnError(usoSessionCommon->Proc21(0, 0, L"ScanTriggerUsoClient"));
84
//wprintf(L"Done.\n");
85
break;
86
case USO_STARTDOWNLOAD:
87
//wprintf(L" |__ Calling 'StartDownload'... ");
88
ThrowOnError(usoSessionCommon->Proc22(0));
89
//wprintf(L"Done.\n");
90
break;
91
case USO_STARTINTERACTIVESCAN:
92
//wprintf(L" |__ Calling 'StartInteractiveScan'... ");
93
ThrowOnError(usoSessionCommon->Proc21(-1, 0, L"ScanTriggerUsoClientInteractive"));
94
//wprintf(L"Done.\n");
95
break;
96
}
97
98
}
99
catch (const _com_error&)
100
{
101
return false;
102
}
103
}
104
else
105
{
106
return false;
107
}
108
109
return true;
110
}
111
112