From bb106cd4b9eb66eba3ad950bf2f3a5213a68d1ae Mon Sep 17 00:00:00 2001 From: csandker Date: Sun, 21 Feb 2021 15:39:06 +0100 Subject: [PATCH] Added CPP-RPC-Client-Server --- .../CPP-RPC-Client-Server.sln | 34 - .../RPC-Client/RPC-Client.cpp | 83 -- .../RPC-Client/RPC-Client.vcxproj | 164 ---- .../RPC-Client/RPC-Client.vcxproj.filters | 25 - .../RPC-Client/RPC-Client.vcxproj.user | 4 - .../RPC-Client1-Explicit-Auth-NoQOS.cpp | 55 +- .../RPC-Client1-Explicit-Auth-QOS.cpp | 52 +- .../RPC-Client1-Explicit.cpp | 51 +- .../RPC-Client1-Implicit.cpp | 48 +- .../RPC-Interface1/Example1.idl | 29 - .../RPC-Interface1/Example1_c.c | 511 ------------ .../RPC-Interface1/Example1_h.h | 77 -- .../RPC-Interface1/Example1_s.c | 506 ------------ .../RPC-Interface1/RPC-Interface1.vcxproj | 1 - .../RPC-Interface1.vcxproj.filters | 3 - .../RPC-Server/RPC-Server.cpp | 110 --- .../RPC-Server/RPC-Server.vcxproj | 190 ----- .../RPC-Server/RPC-Server.vcxproj.filters | 25 - .../RPC-Server/RPC-Server.vcxproj.user | 4 - .../RPC-Server-Explicit-NoSecurity.cpp | 48 +- ...-Server-Explicit-SecurityCallback-Auth.cpp | 733 ++---------------- ...er1-Explicit-SecurityCallback-Auth.vcxproj | 2 +- ...erver-Explicit-SecurityCallback-NoAuth.cpp | 6 +- .../RPC-Server-Implicit-NoSecurity.cpp | 48 +- RPC/CPP-RPC-Client-Server/RPC-Util/Access.cpp | 74 -- .../RPC-Util/Command.cpp | 307 ++++++++ .../RPC-Util/RPC-Util.vcxproj | 3 +- .../RPC-Util/RPC-Util.vcxproj.filters | 5 +- RPC/CPP-RPC-Client-Server/RPC-Util/Token.cpp | 130 ---- 29 files changed, 504 insertions(+), 2824 deletions(-) delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.cpp delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.filters delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.user delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1.idl delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_c.c delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_h.h delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_s.c delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.cpp delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.filters delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.user create mode 100644 RPC/CPP-RPC-Client-Server/RPC-Util/Command.cpp delete mode 100644 RPC/CPP-RPC-Client-Server/RPC-Util/Token.cpp diff --git a/RPC/CPP-RPC-Client-Server/CPP-RPC-Client-Server.sln b/RPC/CPP-RPC-Client-Server/CPP-RPC-Client-Server.sln index 489e77c..ba9988d 100644 --- a/RPC/CPP-RPC-Client-Server/CPP-RPC-Client-Server.sln +++ b/RPC/CPP-RPC-Client-Server/CPP-RPC-Client-Server.sln @@ -3,16 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30907.101 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RPC-Server", "RPC-Server\RPC-Server.vcxproj", "{C990E686-372D-4BC6-BADE-6B6E5C9A65FA}" - ProjectSection(ProjectDependencies) = postProject - {423C961C-29AD-432A-86C3-72DAAA407D9C} = {423C961C-29AD-432A-86C3-72DAAA407D9C} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RPC-Client", "RPC-Client\RPC-Client.vcxproj", "{2A2515C4-97EF-420E-B302-0A442332E7E2}" - ProjectSection(ProjectDependencies) = postProject - {423C961C-29AD-432A-86C3-72DAAA407D9C} = {423C961C-29AD-432A-86C3-72DAAA407D9C} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RPC-Interface1", "RPC-Interface1\RPC-Interface1.vcxproj", "{423C961C-29AD-432A-86C3-72DAAA407D9C}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RPC-Server1-Implicit-NoSecurity", "RPC-Server1-Implicit-NoSecurity\RPC-Server1-Implicit-NoSecurity.vcxproj", "{58A9F403-9EDA-4CD1-B6D3-6C737CCC1CEB}" @@ -67,30 +57,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Debug|Win32.ActiveCfg = Debug|Win32 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Debug|Win32.Build.0 = Debug|Win32 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Debug|x64.ActiveCfg = Debug|x64 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Debug|x64.Build.0 = Debug|x64 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Debug|x86.ActiveCfg = Debug|Win32 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Debug|x86.Build.0 = Debug|Win32 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Release|Win32.ActiveCfg = Release|Win32 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Release|Win32.Build.0 = Release|Win32 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Release|x64.ActiveCfg = Release|x64 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Release|x64.Build.0 = Release|x64 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Release|x86.ActiveCfg = Release|Win32 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA}.Release|x86.Build.0 = Release|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Debug|Win32.ActiveCfg = Debug|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Debug|Win32.Build.0 = Debug|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Debug|x64.ActiveCfg = Debug|x64 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Debug|x64.Build.0 = Debug|x64 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Debug|x86.ActiveCfg = Debug|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Debug|x86.Build.0 = Debug|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Release|Win32.ActiveCfg = Release|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Release|Win32.Build.0 = Release|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Release|x64.ActiveCfg = Release|x64 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Release|x64.Build.0 = Release|x64 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Release|x86.ActiveCfg = Release|Win32 - {2A2515C4-97EF-420E-B302-0A442332E7E2}.Release|x86.Build.0 = Release|Win32 {423C961C-29AD-432A-86C3-72DAAA407D9C}.Debug|Win32.ActiveCfg = Debug|Win32 {423C961C-29AD-432A-86C3-72DAAA407D9C}.Debug|Win32.Build.0 = Debug|Win32 {423C961C-29AD-432A-86C3-72DAAA407D9C}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.cpp b/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.cpp deleted file mode 100644 index 85f25ca..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// File Example1Client.cpp -#include -#include "..\RPC-Interface1\Example1_h.h" - -int main() -{ - RPC_STATUS status; - RPC_WSTR szStringBinding = NULL; - RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); - RPC_WSTR pszTCPHost = (RPC_WSTR)L"localhost"; //reinterpret_cast(L"localhost"); - RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; //reinterpret_cast(L"8989"); - - // Creates a string binding handle. - // Connection is not done here. - status = RpcStringBindingCompose( - NULL, // UUID to bind to. - pszProtSeq, // Use TCP/IP protocol. - pszTCPHost, // TCP/IP network address to use. - pszTCPPort, // TCP/IP port to use. - NULL, // Protocol dependent network options to use. - &szStringBinding); // String binding output. - - if (status) - exit(status); - - handle_t hBinding = NULL; - // Create a valid binding handle from String - status = RpcBindingFromStringBinding( - szStringBinding, // The string binding to validate. - &hBinding // Put the result in the implicit binding - ); // handle defined in the IDL file. - - if (status) - exit(status); - - RpcTryExcept - { - // Calls the RPC function. The hExample1Binding binding handle - // is used implicitly (as defined in the Interface IDL file). - // Connection is done here. - int ret = Output(hBinding, "Hello From Client!"); - ret = Output(hBinding, "Triggering Remote Shutdown now..."); - std::cout << "Return value was: " << ret << std::endl; - Shutdown(hBinding); - } - RpcExcept(1) - { - std::cerr << "Runtime reported exception " << RpcExceptionCode() - << std::endl; - } - RpcEndExcept - - // Free the memory allocated by a string. - status = RpcStringFree( - &szStringBinding); // String to be freed. - - if (status) - exit(status); - - // Releases binding handle resources and disconnects from the server. - status = RpcBindingFree( - &hBinding); // Frees the implicit binding handle defined in the IDL file. - - if (status) - exit(status); -} - - -/******************************************************/ -/* MIDL allocate and free */ -/* The runtime uses these two functions for */ -/* allocating / deallocating */ -/******************************************************/ - -void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) -{ - return(malloc(len)); -} - -void __RPC_USER midl_user_free(void __RPC_FAR * ptr) -{ - free(ptr); -} \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj b/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj deleted file mode 100644 index 059bade..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj +++ /dev/null @@ -1,164 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {2A2515C4-97EF-420E-B302-0A442332E7E2} - Win32Proj - RPCClient - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - - - Level4 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - rpcrt4.lib;%(AdditionalDependencies) - - - - - - - Level4 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - rpcrt4.lib;%(AdditionalDependencies) - - - - - - - Level4 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - rpcrt4.lib;%(AdditionalDependencies) - - - - - - - Level4 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - rpcrt4.lib;%(AdditionalDependencies) - - - - - - - - - - \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.filters b/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.filters deleted file mode 100644 index b52e97f..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.user b/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.user deleted file mode 100644 index 6e2aec7..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Client/RPC-Client.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-NoQOS/RPC-Client1-Explicit-Auth-NoQOS.cpp b/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-NoQOS/RPC-Client1-Explicit-Auth-NoQOS.cpp index 98dd5d1..38ef9d7 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-NoQOS/RPC-Client1-Explicit-Auth-NoQOS.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-NoQOS/RPC-Client1-Explicit-Auth-NoQOS.cpp @@ -4,17 +4,17 @@ int main() { - RPC_STATUS status; + RPC_STATUS rpcStatus; RPC_WSTR szStringBinding = NULL; RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); - RPC_WSTR pszTCPHost = (RPC_WSTR)L"Spaceland-SRV-1"; //reinterpret_cast(L"localhost"); - RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; //reinterpret_cast(L"8989"); - RPC_WSTR pszHostSPN = (RPC_WSTR)L"Host/SPACELAND-SRV-1"; //reinterpret_cast(L"8989"); + RPC_WSTR pszTCPHost = (RPC_WSTR)L"GSrv1.SafeAlliance.local"; + RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; + RPC_WSTR pszHostSPN = (RPC_WSTR)L"Host/GSRV1"; // Creates a string binding handle. // Connection is not done here. wprintf(L"Create string binding to '%s:%s' using RpcStringBindingCompose()\n", pszTCPHost, pszTCPPort); - status = RpcStringBindingCompose( + rpcStatus = RpcStringBindingCompose( NULL, // UUID to bind to. pszProtSeq, // Use TCP/IP protocol. pszTCPHost, // TCP/IP network address to use. @@ -22,18 +22,20 @@ int main() NULL, // Protocol dependent network options to use. &szStringBinding); // String binding output. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } handle_t hExplicitBinding = NULL; // Create a valid binding handle from String - status = RpcBindingFromStringBinding( + rpcStatus = RpcBindingFromStringBinding( szStringBinding, // The string binding to validate. &hExplicitBinding // Put the result in the implicit binding ); // handle defined in the IDL file. wprintf(L"Set Binding authentication info to SPN '%s'...", pszHostSPN); - status = RpcBindingSetAuthInfo( + rpcStatus = RpcBindingSetAuthInfo( hExplicitBinding, // the client's binding handle pszHostSPN, // the server's service principale name (SPN) RPC_C_AUTHN_LEVEL_PKT, // authentication level as defined at https://docs.microsoft.com/en-us/windows/win32/rpc/authentication-level-constants @@ -41,9 +43,9 @@ int main() NULL, // use current thread credentials RPC_C_AUTHZ_NAME // authorization based on the provided SPN as defined at https://docs.microsoft.com/en-us/windows/win32/com/com-authorization-constants ); - if (status) { - wprintf(L"Failed. Error: %s\n", status); - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); } else wprintf(L"Success.\n"); @@ -53,31 +55,32 @@ int main() // Calls the RPC function. The hExample1Binding binding handle // is used implicitly (as defined in the Interface IDL file). // Connection is done here. - int ret = Output(hExplicitBinding, "Hello From Client!"); - ret = Output(hExplicitBinding, "Triggering Remote Shutdown now..."); - std::cout << "Return value was: " << ret << std::endl; + int retValue = Output(hExplicitBinding, "Hello From Client!"); + //ret = Output(hExplicitBinding, "Triggering Remote Shutdown now..."); + wprintf(L"[+] Value returned from Server is: %d\n", retValue); Shutdown(hExplicitBinding); } RpcExcept(1) { - std::cerr << "Runtime reported exception " << RpcExceptionCode() - << std::endl; + wprintf(L"Runtime reported exception: %d.\n", RpcExceptionCode()); } RpcEndExcept - // Free the memory allocated by a string. - status = RpcStringFree( - &szStringBinding); // String to be freed. + // Free the memory allocated by a string. + rpcStatus = RpcStringFree(&szStringBinding); - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } // Releases binding handle resources and disconnects from the server. - status = RpcBindingFree( - &hExplicitBinding); // Frees the implicit binding handle defined in the IDL file. + rpcStatus = RpcBindingFree(&hExplicitBinding); // Frees the implicit binding handle defined in the IDL file. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } } diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-QOS/RPC-Client1-Explicit-Auth-QOS.cpp b/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-QOS/RPC-Client1-Explicit-Auth-QOS.cpp index 810a77e..b6cc018 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-QOS/RPC-Client1-Explicit-Auth-QOS.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit-Auth-QOS/RPC-Client1-Explicit-Auth-QOS.cpp @@ -11,14 +11,14 @@ typedef enum _csENDPOINTTYPE { int main() { wprintf(L"[*] Starting RPC Client!\n"); - RPC_STATUS status; + RPC_STATUS rpcStatus; BOOL bSetBindingAuth = TRUE; RPC_WSTR szStringBinding = NULL; RPC_WSTR pszProtSeq; RPC_WSTR pszTCPPort; - RPC_WSTR pszTCPHost = (RPC_WSTR)L"localhost";//(RPC_WSTR)L"Spaceland-SRV-1"; //L"WIN10-Client-2"; //reinterpret_cast(L"localhost"); - RPC_WSTR pszHostSPN = (RPC_WSTR)L"Host/LONLEYPLANET-WI";//(RPC_WSTR)L"Host/SPACELAND-SRV-1"; //L"Host/WIN10-CLIENT-2";// - CSENDPOINTTYPE pwsEndpointType = LRPC; + RPC_WSTR pszTCPHost = (RPC_WSTR)L"GSrv1.SafeAlliance.local";//(RPC_WSTR)L"Spaceland-SRV-1"; //L"WIN10-Client-2"; //reinterpret_cast(L"localhost"); + RPC_WSTR pszHostSPN = (RPC_WSTR)L"Host/GSRV1";//(RPC_WSTR)L"Host/SPACELAND-SRV-1"; //L"Host/WIN10-CLIENT-2";// + CSENDPOINTTYPE pwsEndpointType = NamedPipe; switch (pwsEndpointType) { @@ -55,7 +55,7 @@ int main() // Creates a string binding handle. // Connection is not done here. wprintf(L"[*] Create string binding to '%s:%s' using protocol '%s'.\n", pszTCPHost, pszTCPPort, pszProtSeq); - status = RpcStringBindingCompose( + rpcStatus = RpcStringBindingCompose( NULL, // UUID to bind to. pszProtSeq, // Use TCP/IP protocol. pszTCPHost, // TCP/IPww network address to use. @@ -63,25 +63,25 @@ int main() NULL, // Protocol dependent network options to use. &szStringBinding); // String binding output. - if (status != RPC_S_OK) { - wprintf(L"[-] RpcStringBindingCompose() failed with status: %d.\n", status); - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcStringBindingCompose() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); } handle_t hExplicitBinding = NULL; // Create a valid binding handle from String - status = RpcBindingFromStringBinding( + rpcStatus = RpcBindingFromStringBinding( szStringBinding, // The string binding to validate. &hExplicitBinding // Put the result in the implicit binding ); // handle defined in the IDL file. - if (status != RPC_S_OK) { - wprintf(L"[-] RpcBindingFromStringBinding() failed with status: %d.\n", status); - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingFromStringBinding() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); } if (bSetBindingAuth) { wprintf(L"[*] Set Binding authentication info to SPN '%s' with an ImpersonationType of '%d'.\n", pszHostSPN, secQos.ImpersonationType); - status = RpcBindingSetAuthInfoEx( + rpcStatus = RpcBindingSetAuthInfoEx( hExplicitBinding, // the client's binding handle pszHostSPN, // the server's service principale name (SPN) RPC_C_AUTHN_LEVEL_PKT, // authentication level as defined at https://docs.microsoft.com/en-us/windows/win32/rpc/authentication-level-constants @@ -91,9 +91,9 @@ int main() &secQos // Quality of Service structure ); - if (status != RPC_S_OK) { - wprintf(L"[-] RpcBindingSetAuthInfoEx() failed with status: %d.\n", status); - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingSetAuthInfoEx() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); } } @@ -104,8 +104,8 @@ int main() int retValue = Output(hExplicitBinding, "Hello From Client!"); //ret = Output(hExplicitBinding, "Triggering Remote Shutdown now..."); wprintf(L"[+] Value returned from Server is: %d\n", retValue); - wprintf(L"[*] Trigger remote Shutdown now...\n"); - Shutdown(hExplicitBinding); + //wprintf(L"[*] Trigger remote Shutdown now...\n"); + //Shutdown(hExplicitBinding); } RpcExcept(1) { @@ -115,17 +115,17 @@ int main() wprintf(L"[*] Shuting down client...\n"); // Free the memory allocated by a string. - status = RpcStringFree(&szStringBinding); - if (status != RPC_S_OK) { - wprintf(L"[-] RpcStringFree() failed with status: %d.\n", status); - exit(status); + rpcStatus = RpcStringFree(&szStringBinding); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcStringFree() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); } // Releases binding handle resources and disconnects from the server. - status = RpcBindingFree(&hExplicitBinding); - if (status != RPC_S_OK) { - wprintf(L"[-] RpcBindingFree() failed with status: %d.\n", status); - exit(status); + rpcStatus = RpcBindingFree(&hExplicitBinding); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingFree() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); } // exit successfully diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit/RPC-Client1-Explicit.cpp b/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit/RPC-Client1-Explicit.cpp index a5e38f4..0650a82 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit/RPC-Client1-Explicit.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Client1-Explicit/RPC-Client1-Explicit.cpp @@ -4,16 +4,16 @@ int main() { - RPC_STATUS status; + RPC_STATUS rpcStatus; RPC_WSTR szStringBinding = NULL; RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); - RPC_WSTR pszTCPHost = (RPC_WSTR)L"Spaceland-SRV-1"; //reinterpret_cast(L"localhost"); - RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; //reinterpret_cast(L"8989"); + RPC_WSTR pszTCPHost = (RPC_WSTR)L"GSrv1.SafeAlliance.local"; + RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; // Creates a string binding handle. // Connection is not done here. wprintf(L"Create string binding to '%s:%s' using protocol '%s' at '%s' \n", pszTCPHost, pszTCPPort, pszProtSeq, pszTCPPort); - status = RpcStringBindingCompose( + rpcStatus = RpcStringBindingCompose( NULL, // UUID to bind to. pszProtSeq, // Use TCP/IP protocol. pszTCPHost, // TCP/IP network address to use. @@ -21,49 +21,54 @@ int main() NULL, // Protocol dependent network options to use. &szStringBinding); // String binding output. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed. Error: %d.\n", rpcStatus); + exit(rpcStatus); + } handle_t hExplicitBinding = NULL; // Create a valid binding handle from String - status = RpcBindingFromStringBinding( + rpcStatus = RpcBindingFromStringBinding( szStringBinding, // The string binding to validate. &hExplicitBinding // Put the result in the implicit binding ); // handle defined in the IDL file. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed. Error: %d.\n", rpcStatus); + exit(rpcStatus); + } RpcTryExcept { // Calls the RPC function. The hExample1Binding binding handle // is used implicitly (as defined in the Interface IDL file). // Connection is done here. - int ret = Output(hExplicitBinding, "Hello From Client!"); - ret = Output(hExplicitBinding, "Triggering Remote Shutdown now..."); - std::cout << "Return value was: " << ret << std::endl; + int retValue = Output(hExplicitBinding, "Hello From Client!"); + //ret = Output(hExplicitBinding, "Triggering Remote Shutdown now..."); + wprintf(L"[+] Value returned from Server is: %d\n", retValue); Shutdown(hExplicitBinding); } RpcExcept(1) { - std::cerr << "Runtime reported exception " << RpcExceptionCode() - << std::endl; + wprintf(L"Runtime reported exception: %d.\n", RpcExceptionCode()); } RpcEndExcept - // Free the memory allocated by a string. - status = RpcStringFree( - &szStringBinding); // String to be freed. + // Free the memory allocated by a string. + rpcStatus = RpcStringFree(&szStringBinding); - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed. Error: %d.\n", rpcStatus); + exit(rpcStatus); + }; // Releases binding handle resources and disconnects from the server. - status = RpcBindingFree( - &hExplicitBinding); // Frees the implicit binding handle defined in the IDL file. + rpcStatus = RpcBindingFree(&hExplicitBinding); // Frees the binding handle defined in the IDL file. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed. Error: %d.\n", rpcStatus); + exit(rpcStatus); + }; } diff --git a/RPC/CPP-RPC-Client-Server/RPC-Client1-Implicit/RPC-Client1-Implicit.cpp b/RPC/CPP-RPC-Client-Server/RPC-Client1-Implicit/RPC-Client1-Implicit.cpp index 292e284..d45f971 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Client1-Implicit/RPC-Client1-Implicit.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Client1-Implicit/RPC-Client1-Implicit.cpp @@ -4,7 +4,7 @@ int main() { - RPC_STATUS status; + RPC_STATUS rpcStatus; RPC_WSTR szStringBinding = NULL; RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); RPC_WSTR pszTCPHost = (RPC_WSTR)L"Spaceland-SRV-1"; //reinterpret_cast(L"localhost"); @@ -13,7 +13,7 @@ int main() // Creates a string binding handle. // Connection is not done here. wprintf(L"Create string binding to '%s:%s' using protocol '%s' at '%s' \n", pszTCPHost, pszTCPPort, pszProtSeq, pszTCPPort); - status = RpcStringBindingCompose( + rpcStatus = RpcStringBindingCompose( NULL, // UUID to bind to. pszProtSeq, // Use TCP/IP protocol. pszTCPHost, // TCP/IP network address to use. @@ -21,49 +21,53 @@ int main() NULL, // Protocol dependent network options to use. &szStringBinding); // String binding output. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } // Create a valid binding handle from String - status = RpcBindingFromStringBinding( + rpcStatus = RpcBindingFromStringBinding( szStringBinding, // The string binding to validate. &hImplicitBinding // Put the result in the implicit binding ); // handle defined in the IDL file. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } RpcTryExcept { // Calls the RPC function. The hExample1Binding binding handle // is used implicitly (as defined in the Interface IDL file). // Connection is done here. - int ret = Output("Hello From Client!"); - ret = Output("Triggering Remote Shutdown now..."); - std::cout << "Return value was: " << ret << std::endl; + int retValue = Output("Hello From Client!"); + //ret = Output("Triggering Remote Shutdown now..."); + wprintf(L"[+] Value returned from Server is: %d\n", retValue); Shutdown(); } RpcExcept(1) { - unsigned long errCode = RpcExceptionCode(); - std::cerr << "Runtime reported exception. Error Code: " << errCode - << std::endl; + wprintf(L"Runtime reported exception: %d.\n", RpcExceptionCode()); } RpcEndExcept - // Free the memory allocated by a string. - status = RpcStringFree( - &szStringBinding); // String to be freed. + // Free the memory allocated by a string. + rpcStatus = RpcStringFree(&szStringBinding); - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } // Releases binding handle resources and disconnects from the server. - status = RpcBindingFree( - &hImplicitBinding); // Frees the implicit binding handle defined in the IDL file. + rpcStatus = RpcBindingFree(&hImplicitBinding); // Frees the implicit binding handle defined in the IDL file. - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] Failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } } diff --git a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1.idl b/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1.idl deleted file mode 100644 index 28fb616..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1.idl +++ /dev/null @@ -1,29 +0,0 @@ -[ - // UUID: A unique identifier that distinguishes this - // interface from other interfaces. - uuid(9a4e95b2-8fee-46ab-8cd7-b8b1050f1c1a), - - // This is version 1.0 of this interface. - version(1.0), - - /* - In this example we're using an explicit binding handle. - Within an (optional) .acf file we could specify the keyword "explicit_handle". - An Explicit handle is not specifed with an extra keyword in the IDL file, but - by adding a handle parameter to all interface function. See "[in] handle_t hBinding" parameter below.. - - If we would use an implicit handle here, we could define one named hExample1Binding as below: - implicit_handle(handle_t hExample1Binding) - */ -] -interface Example1 // The interface is named Example1 -{ - // A function that takes a zero-terminated string. - int Output( - [in] handle_t hBinding, - [in, string] const char* pszOutput); - //[out, string] const char* szReturn); - - void Shutdown( - [in] handle_t hBinding); -} \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_c.c b/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_c.c deleted file mode 100644 index 6b35863..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_c.c +++ /dev/null @@ -1,511 +0,0 @@ - - -/* this ALWAYS GENERATED file contains the RPC client stubs */ - - - /* File created by MIDL compiler version 8.01.0622 */ -/* at Tue Jan 19 03:14:07 2038 - */ -/* Compiler settings for Example1.idl: - Oicf, W3, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 - protocol : all , ms_ext, app_config, c_ext, robust - error checks: allocation ref bounds_check enum stub_data - VC __declspec() decoration level: - __declspec(uuid()), __declspec(selectany), __declspec(novtable) - DECLSPEC_UUID(), MIDL_INTERFACE() -*/ -/* @@MIDL_FILE_HEADING( ) */ - -#if defined(_M_AMD64) - - -#if _MSC_VER >= 1200 -#pragma warning(push) -#endif - -#pragma warning( disable: 4211 ) /* redefine extern to static */ -#pragma warning( disable: 4232 ) /* dllimport identity*/ -#pragma warning( disable: 4024 ) /* array to pointer mapping*/ - -#include - -#include "Example1_h.h" - -#define TYPE_FORMAT_STRING_SIZE 7 -#define PROC_FORMAT_STRING_SIZE 73 -#define EXPR_FORMAT_STRING_SIZE 1 -#define TRANSMIT_AS_TABLE_SIZE 0 -#define WIRE_MARSHAL_TABLE_SIZE 0 - -typedef struct _Example1_MIDL_TYPE_FORMAT_STRING - { - short Pad; - unsigned char Format[ TYPE_FORMAT_STRING_SIZE ]; - } Example1_MIDL_TYPE_FORMAT_STRING; - -typedef struct _Example1_MIDL_PROC_FORMAT_STRING - { - short Pad; - unsigned char Format[ PROC_FORMAT_STRING_SIZE ]; - } Example1_MIDL_PROC_FORMAT_STRING; - -typedef struct _Example1_MIDL_EXPR_FORMAT_STRING - { - long Pad; - unsigned char Format[ EXPR_FORMAT_STRING_SIZE ]; - } Example1_MIDL_EXPR_FORMAT_STRING; - - -static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax = -{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}; - -static const RPC_SYNTAX_IDENTIFIER _NDR64_RpcTransferSyntax = -{{0x71710533,0xbeba,0x4937,{0x83,0x19,0xb5,0xdb,0xef,0x9c,0xcc,0x36}},{1,0}}; - - - -extern const Example1_MIDL_TYPE_FORMAT_STRING Example1__MIDL_TypeFormatString; -extern const Example1_MIDL_PROC_FORMAT_STRING Example1__MIDL_ProcFormatString; -extern const Example1_MIDL_EXPR_FORMAT_STRING Example1__MIDL_ExprFormatString; - -#define GENERIC_BINDING_TABLE_SIZE 0 - - -/* Standard interface: Example1, ver. 1.0, - GUID={0x9a4e95b2,0x8fee,0x46ab,{0x8c,0xd7,0xb8,0xb1,0x05,0x0f,0x1c,0x1a}} */ - - extern const MIDL_STUBLESS_PROXY_INFO Example1_ProxyInfo; - - -static const RPC_CLIENT_INTERFACE Example1___RpcClientInterface = - { - sizeof(RPC_CLIENT_INTERFACE), - {{0x9a4e95b2,0x8fee,0x46ab,{0x8c,0xd7,0xb8,0xb1,0x05,0x0f,0x1c,0x1a}},{1,0}}, - {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, - 0, - 0, - 0, - 0, - &Example1_ProxyInfo, - 0x02000000 - }; -RPC_IF_HANDLE Example1_v1_0_c_ifspec = (RPC_IF_HANDLE)& Example1___RpcClientInterface; - -extern const MIDL_STUB_DESC Example1_StubDesc; - -static RPC_BINDING_HANDLE Example1__MIDL_AutoBindHandle; - - -int Output( - /* [in] */ handle_t hBinding, - /* [string][in] */ const char *pszOutput) -{ - - CLIENT_CALL_RETURN _RetVal; - - _RetVal = NdrClientCall3( - ( PMIDL_STUBLESS_PROXY_INFO )&Example1_ProxyInfo, - 0, - 0, - hBinding, - pszOutput); - return ( int )_RetVal.Simple; - -} - - -void Shutdown( - /* [in] */ handle_t hBinding) -{ - - NdrClientCall3( - ( PMIDL_STUBLESS_PROXY_INFO )&Example1_ProxyInfo, - 1, - 0, - hBinding); - -} - - -#if !defined(__RPC_WIN64__) -#error Invalid build platform for this stub. -#endif - -static const Example1_MIDL_PROC_FORMAT_STRING Example1__MIDL_ProcFormatString = - { - 0, - { - - /* Procedure Output */ - - 0x0, /* 0 */ - 0x48, /* Old Flags: */ -/* 2 */ NdrFcLong( 0x0 ), /* 0 */ -/* 6 */ NdrFcShort( 0x0 ), /* 0 */ -/* 8 */ NdrFcShort( 0x18 ), /* X64 Stack size/offset = 24 */ -/* 10 */ 0x32, /* FC_BIND_PRIMITIVE */ - 0x0, /* 0 */ -/* 12 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ -/* 14 */ NdrFcShort( 0x0 ), /* 0 */ -/* 16 */ NdrFcShort( 0x8 ), /* 8 */ -/* 18 */ 0x46, /* Oi2 Flags: clt must size, has return, has ext, */ - 0x2, /* 2 */ -/* 20 */ 0xa, /* 10 */ - 0x1, /* Ext Flags: new corr desc, */ -/* 22 */ NdrFcShort( 0x0 ), /* 0 */ -/* 24 */ NdrFcShort( 0x0 ), /* 0 */ -/* 26 */ NdrFcShort( 0x0 ), /* 0 */ -/* 28 */ NdrFcShort( 0x0 ), /* 0 */ - - /* Parameter pszOutput */ - -/* 30 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */ -/* 32 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ -/* 34 */ NdrFcShort( 0x4 ), /* Type Offset=4 */ - - /* Return value */ - -/* 36 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */ -/* 38 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ -/* 40 */ 0x8, /* FC_LONG */ - 0x0, /* 0 */ - - /* Procedure Shutdown */ - -/* 42 */ 0x0, /* 0 */ - 0x48, /* Old Flags: */ -/* 44 */ NdrFcLong( 0x0 ), /* 0 */ -/* 48 */ NdrFcShort( 0x1 ), /* 1 */ -/* 50 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ -/* 52 */ 0x32, /* FC_BIND_PRIMITIVE */ - 0x0, /* 0 */ -/* 54 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ -/* 56 */ NdrFcShort( 0x0 ), /* 0 */ -/* 58 */ NdrFcShort( 0x0 ), /* 0 */ -/* 60 */ 0x40, /* Oi2 Flags: has ext, */ - 0x0, /* 0 */ -/* 62 */ 0xa, /* 10 */ - 0x1, /* Ext Flags: new corr desc, */ -/* 64 */ NdrFcShort( 0x0 ), /* 0 */ -/* 66 */ NdrFcShort( 0x0 ), /* 0 */ -/* 68 */ NdrFcShort( 0x0 ), /* 0 */ -/* 70 */ NdrFcShort( 0x0 ), /* 0 */ - - 0x0 - } - }; - -static const Example1_MIDL_TYPE_FORMAT_STRING Example1__MIDL_TypeFormatString = - { - 0, - { - NdrFcShort( 0x0 ), /* 0 */ -/* 2 */ - 0x11, 0x8, /* FC_RP [simple_pointer] */ -/* 4 */ - 0x22, /* FC_C_CSTRING */ - 0x5c, /* FC_PAD */ - - 0x0 - } - }; - -static const unsigned short Example1_FormatStringOffsetTable[] = - { - 0, - 42 - }; - - - -#endif /* defined(_M_AMD64)*/ - - - -/* this ALWAYS GENERATED file contains the RPC client stubs */ - - - /* File created by MIDL compiler version 8.01.0622 */ -/* at Tue Jan 19 03:14:07 2038 - */ -/* Compiler settings for Example1.idl: - Oicf, W3, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 - protocol : all , ms_ext, app_config, c_ext, robust - error checks: allocation ref bounds_check enum stub_data - VC __declspec() decoration level: - __declspec(uuid()), __declspec(selectany), __declspec(novtable) - DECLSPEC_UUID(), MIDL_INTERFACE() -*/ -/* @@MIDL_FILE_HEADING( ) */ - -#if defined(_M_AMD64) - - - - -#if !defined(__RPC_WIN64__) -#error Invalid build platform for this stub. -#endif - - -#include "ndr64types.h" -#include "pshpack8.h" - - -typedef -struct -{ - struct _NDR64_PROC_FORMAT frag1; - struct _NDR64_BIND_AND_NOTIFY_EXTENSION frag2; -} -__midl_frag6_t; -extern const __midl_frag6_t __midl_frag6; - -typedef -NDR64_FORMAT_CHAR -__midl_frag5_t; -extern const __midl_frag5_t __midl_frag5; - -typedef -struct _NDR64_CONFORMANT_STRING_FORMAT -__midl_frag4_t; -extern const __midl_frag4_t __midl_frag4; - -typedef -struct _NDR64_POINTER_FORMAT -__midl_frag3_t; -extern const __midl_frag3_t __midl_frag3; - -typedef -struct -{ - struct _NDR64_PROC_FORMAT frag1; - struct _NDR64_BIND_AND_NOTIFY_EXTENSION frag2; - struct _NDR64_PARAM_FORMAT frag3; - struct _NDR64_PARAM_FORMAT frag4; -} -__midl_frag2_t; -extern const __midl_frag2_t __midl_frag2; - -typedef -NDR64_FORMAT_UINT32 -__midl_frag1_t; -extern const __midl_frag1_t __midl_frag1; - -static const __midl_frag6_t __midl_frag6 = -{ -/* Shutdown */ - { - /* Shutdown */ /* procedure Shutdown */ - (NDR64_UINT32) 16777280 /* 0x1000040 */, /* explicit handle */ /* IsIntrepreted, HasExtensions */ - (NDR64_UINT32) 8 /* 0x8 */ , /* Stack size */ - (NDR64_UINT32) 0 /* 0x0 */, - (NDR64_UINT32) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 8 /* 0x8 */ - }, - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - 0x72, /* FC64_BIND_PRIMITIVE */ - (NDR64_UINT8) 0 /* 0x0 */, - 0 /* 0x0 */, /* Stack offset */ - (NDR64_UINT8) 0 /* 0x0 */, - (NDR64_UINT8) 0 /* 0x0 */ - }, - (NDR64_UINT16) 0 /* 0x0 */ /* Notify index */ - } -}; - -static const __midl_frag5_t __midl_frag5 = -0x5 /* FC64_INT32 */; - -static const __midl_frag4_t __midl_frag4 = -{ -/* *char */ - { - /* *char */ - 0x63, /* FC64_CONF_CHAR_STRING */ - { - /* *char */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - }, - (NDR64_UINT16) 1 /* 0x1 */ - } -}; - -static const __midl_frag3_t __midl_frag3 = -{ -/* *char */ - 0x20, /* FC64_RP */ - (NDR64_UINT8) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - &__midl_frag4 -}; - -static const __midl_frag2_t __midl_frag2 = -{ -/* Output */ - { - /* Output */ /* procedure Output */ - (NDR64_UINT32) 17563712 /* 0x10c0040 */, /* explicit handle */ /* IsIntrepreted, ClientMustSize, HasReturn, HasExtensions */ - (NDR64_UINT32) 24 /* 0x18 */ , /* Stack size */ - (NDR64_UINT32) 0 /* 0x0 */, - (NDR64_UINT32) 8 /* 0x8 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 2 /* 0x2 */, - (NDR64_UINT16) 8 /* 0x8 */ - }, - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - 0x72, /* FC64_BIND_PRIMITIVE */ - (NDR64_UINT8) 0 /* 0x0 */, - 0 /* 0x0 */, /* Stack offset */ - (NDR64_UINT8) 0 /* 0x0 */, - (NDR64_UINT8) 0 /* 0x0 */ - }, - (NDR64_UINT16) 0 /* 0x0 */ /* Notify index */ - }, - { - /* pszOutput */ /* parameter pszOutput */ - &__midl_frag4, - { - /* pszOutput */ - 1, - 1, - 0, - 1, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - (NDR64_UINT16) 0 /* 0x0 */, - 0 - }, /* MustSize, MustFree, [in], SimpleRef */ - (NDR64_UINT16) 0 /* 0x0 */, - 8 /* 0x8 */, /* Stack offset */ - }, - { - /* int */ /* parameter int */ - &__midl_frag5, - { - /* int */ - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - (NDR64_UINT16) 0 /* 0x0 */, - 0 - }, /* [out], IsReturn, Basetype, ByValue */ - (NDR64_UINT16) 0 /* 0x0 */, - 16 /* 0x10 */, /* Stack offset */ - } -}; - -static const __midl_frag1_t __midl_frag1 = -(NDR64_UINT32) 0 /* 0x0 */; - - -#include "poppack.h" - - -static const FormatInfoRef Example1_Ndr64ProcTable[] = - { - &__midl_frag2, - &__midl_frag6 - }; - - -static const MIDL_STUB_DESC Example1_StubDesc = - { - (void *)& Example1___RpcClientInterface, - MIDL_user_allocate, - MIDL_user_free, - &Example1__MIDL_AutoBindHandle, - 0, - 0, - 0, - 0, - Example1__MIDL_TypeFormatString.Format, - 1, /* -error bounds_check flag */ - 0x60001, /* Ndr library version */ - 0, - 0x801026e, /* MIDL Version 8.1.622 */ - 0, - 0, - 0, /* notify & notify_flag routine table */ - 0x2000001, /* MIDL flag */ - 0, /* cs routines */ - (void *)& Example1_ProxyInfo, /* proxy/server info */ - 0 - }; - -static const MIDL_SYNTAX_INFO Example1_SyntaxInfo [ 2 ] = - { - { - {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, - 0, - Example1__MIDL_ProcFormatString.Format, - Example1_FormatStringOffsetTable, - Example1__MIDL_TypeFormatString.Format, - 0, - 0, - 0 - } - ,{ - {{0x71710533,0xbeba,0x4937,{0x83,0x19,0xb5,0xdb,0xef,0x9c,0xcc,0x36}},{1,0}}, - 0, - 0 , - (unsigned short *) Example1_Ndr64ProcTable, - 0, - 0, - 0, - 0 - } - }; - -static const MIDL_STUBLESS_PROXY_INFO Example1_ProxyInfo = - { - &Example1_StubDesc, - Example1__MIDL_ProcFormatString.Format, - Example1_FormatStringOffsetTable, - (RPC_SYNTAX_IDENTIFIER*)&_RpcTransferSyntax, - 2, - (MIDL_SYNTAX_INFO*)Example1_SyntaxInfo - - }; - -#if _MSC_VER >= 1200 -#pragma warning(pop) -#endif - - -#endif /* defined(_M_AMD64)*/ - diff --git a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_h.h b/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_h.h deleted file mode 100644 index 33eaee4..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_h.h +++ /dev/null @@ -1,77 +0,0 @@ - - -/* this ALWAYS GENERATED file contains the definitions for the interfaces */ - - - /* File created by MIDL compiler version 8.01.0622 */ -/* at Tue Jan 19 03:14:07 2038 - */ -/* Compiler settings for Example1.idl: - Oicf, W3, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 - protocol : all , ms_ext, app_config, c_ext, robust - error checks: allocation ref bounds_check enum stub_data - VC __declspec() decoration level: - __declspec(uuid()), __declspec(selectany), __declspec(novtable) - DECLSPEC_UUID(), MIDL_INTERFACE() -*/ -/* @@MIDL_FILE_HEADING( ) */ - - - -/* verify that the version is high enough to compile this file*/ -#ifndef __REQUIRED_RPCNDR_H_VERSION__ -#define __REQUIRED_RPCNDR_H_VERSION__ 500 -#endif - -#include "rpc.h" -#include "rpcndr.h" - -#ifndef __RPCNDR_H_VERSION__ -#error this stub requires an updated version of -#endif /* __RPCNDR_H_VERSION__ */ - - -#ifndef __Example1_h_h__ -#define __Example1_h_h__ - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -#pragma once -#endif - -/* Forward Declarations */ - -#ifdef __cplusplus -extern "C"{ -#endif - - -#ifndef __Example1_INTERFACE_DEFINED__ -#define __Example1_INTERFACE_DEFINED__ - -/* interface Example1 */ -/* [version][uuid] */ - -int Output( - /* [in] */ handle_t hBinding, - /* [string][in] */ const char *pszOutput); - -void Shutdown( - /* [in] */ handle_t hBinding); - - - -extern RPC_IF_HANDLE Example1_v1_0_c_ifspec; -extern RPC_IF_HANDLE Example1_v1_0_s_ifspec; -#endif /* __Example1_INTERFACE_DEFINED__ */ - -/* Additional Prototypes for ALL interfaces */ - -/* end of Additional Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif - - diff --git a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_s.c b/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_s.c deleted file mode 100644 index c271ef6..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Interface1/Example1_s.c +++ /dev/null @@ -1,506 +0,0 @@ - - -/* this ALWAYS GENERATED file contains the RPC server stubs */ - - - /* File created by MIDL compiler version 8.01.0622 */ -/* at Tue Jan 19 03:14:07 2038 - */ -/* Compiler settings for Example1.idl: - Oicf, W3, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 - protocol : all , ms_ext, app_config, c_ext, robust - error checks: allocation ref bounds_check enum stub_data - VC __declspec() decoration level: - __declspec(uuid()), __declspec(selectany), __declspec(novtable) - DECLSPEC_UUID(), MIDL_INTERFACE() -*/ -/* @@MIDL_FILE_HEADING( ) */ - -#if defined(_M_AMD64) - - -#if _MSC_VER >= 1200 -#pragma warning(push) -#endif - -#pragma warning( disable: 4211 ) /* redefine extern to static */ -#pragma warning( disable: 4232 ) /* dllimport identity*/ -#pragma warning( disable: 4024 ) /* array to pointer mapping*/ - -#include -#include "Example1_h.h" - -#define TYPE_FORMAT_STRING_SIZE 7 -#define PROC_FORMAT_STRING_SIZE 73 -#define EXPR_FORMAT_STRING_SIZE 1 -#define TRANSMIT_AS_TABLE_SIZE 0 -#define WIRE_MARSHAL_TABLE_SIZE 0 - -typedef struct _Example1_MIDL_TYPE_FORMAT_STRING - { - short Pad; - unsigned char Format[ TYPE_FORMAT_STRING_SIZE ]; - } Example1_MIDL_TYPE_FORMAT_STRING; - -typedef struct _Example1_MIDL_PROC_FORMAT_STRING - { - short Pad; - unsigned char Format[ PROC_FORMAT_STRING_SIZE ]; - } Example1_MIDL_PROC_FORMAT_STRING; - -typedef struct _Example1_MIDL_EXPR_FORMAT_STRING - { - long Pad; - unsigned char Format[ EXPR_FORMAT_STRING_SIZE ]; - } Example1_MIDL_EXPR_FORMAT_STRING; - - -static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax = -{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}; - -static const RPC_SYNTAX_IDENTIFIER _NDR64_RpcTransferSyntax = -{{0x71710533,0xbeba,0x4937,{0x83,0x19,0xb5,0xdb,0xef,0x9c,0xcc,0x36}},{1,0}}; - - -extern const Example1_MIDL_TYPE_FORMAT_STRING Example1__MIDL_TypeFormatString; -extern const Example1_MIDL_PROC_FORMAT_STRING Example1__MIDL_ProcFormatString; -extern const Example1_MIDL_EXPR_FORMAT_STRING Example1__MIDL_ExprFormatString; - -/* Standard interface: Example1, ver. 1.0, - GUID={0x9a4e95b2,0x8fee,0x46ab,{0x8c,0xd7,0xb8,0xb1,0x05,0x0f,0x1c,0x1a}} */ - - -extern const MIDL_SERVER_INFO Example1_ServerInfo; - -extern const RPC_DISPATCH_TABLE Example1_v1_0_DispatchTable; - -static const RPC_SERVER_INTERFACE Example1___RpcServerInterface = - { - sizeof(RPC_SERVER_INTERFACE), - {{0x9a4e95b2,0x8fee,0x46ab,{0x8c,0xd7,0xb8,0xb1,0x05,0x0f,0x1c,0x1a}},{1,0}}, - {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, - (RPC_DISPATCH_TABLE*)&Example1_v1_0_DispatchTable, - 0, - 0, - 0, - &Example1_ServerInfo, - 0x06000000 - }; -RPC_IF_HANDLE Example1_v1_0_s_ifspec = (RPC_IF_HANDLE)& Example1___RpcServerInterface; - -extern const MIDL_STUB_DESC Example1_StubDesc; - - -#if !defined(__RPC_WIN64__) -#error Invalid build platform for this stub. -#endif - -static const Example1_MIDL_PROC_FORMAT_STRING Example1__MIDL_ProcFormatString = - { - 0, - { - - /* Procedure Output */ - - 0x0, /* 0 */ - 0x48, /* Old Flags: */ -/* 2 */ NdrFcLong( 0x0 ), /* 0 */ -/* 6 */ NdrFcShort( 0x0 ), /* 0 */ -/* 8 */ NdrFcShort( 0x18 ), /* X64 Stack size/offset = 24 */ -/* 10 */ 0x32, /* FC_BIND_PRIMITIVE */ - 0x0, /* 0 */ -/* 12 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ -/* 14 */ NdrFcShort( 0x0 ), /* 0 */ -/* 16 */ NdrFcShort( 0x8 ), /* 8 */ -/* 18 */ 0x46, /* Oi2 Flags: clt must size, has return, has ext, */ - 0x2, /* 2 */ -/* 20 */ 0xa, /* 10 */ - 0x1, /* Ext Flags: new corr desc, */ -/* 22 */ NdrFcShort( 0x0 ), /* 0 */ -/* 24 */ NdrFcShort( 0x0 ), /* 0 */ -/* 26 */ NdrFcShort( 0x0 ), /* 0 */ -/* 28 */ NdrFcShort( 0x0 ), /* 0 */ - - /* Parameter pszOutput */ - -/* 30 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */ -/* 32 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ -/* 34 */ NdrFcShort( 0x4 ), /* Type Offset=4 */ - - /* Return value */ - -/* 36 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */ -/* 38 */ NdrFcShort( 0x10 ), /* X64 Stack size/offset = 16 */ -/* 40 */ 0x8, /* FC_LONG */ - 0x0, /* 0 */ - - /* Procedure Shutdown */ - -/* 42 */ 0x0, /* 0 */ - 0x48, /* Old Flags: */ -/* 44 */ NdrFcLong( 0x0 ), /* 0 */ -/* 48 */ NdrFcShort( 0x1 ), /* 1 */ -/* 50 */ NdrFcShort( 0x8 ), /* X64 Stack size/offset = 8 */ -/* 52 */ 0x32, /* FC_BIND_PRIMITIVE */ - 0x0, /* 0 */ -/* 54 */ NdrFcShort( 0x0 ), /* X64 Stack size/offset = 0 */ -/* 56 */ NdrFcShort( 0x0 ), /* 0 */ -/* 58 */ NdrFcShort( 0x0 ), /* 0 */ -/* 60 */ 0x40, /* Oi2 Flags: has ext, */ - 0x0, /* 0 */ -/* 62 */ 0xa, /* 10 */ - 0x1, /* Ext Flags: new corr desc, */ -/* 64 */ NdrFcShort( 0x0 ), /* 0 */ -/* 66 */ NdrFcShort( 0x0 ), /* 0 */ -/* 68 */ NdrFcShort( 0x0 ), /* 0 */ -/* 70 */ NdrFcShort( 0x0 ), /* 0 */ - - 0x0 - } - }; - -static const Example1_MIDL_TYPE_FORMAT_STRING Example1__MIDL_TypeFormatString = - { - 0, - { - NdrFcShort( 0x0 ), /* 0 */ -/* 2 */ - 0x11, 0x8, /* FC_RP [simple_pointer] */ -/* 4 */ - 0x22, /* FC_C_CSTRING */ - 0x5c, /* FC_PAD */ - - 0x0 - } - }; - -static const unsigned short Example1_FormatStringOffsetTable[] = - { - 0, - 42 - }; - - -static const RPC_DISPATCH_FUNCTION Example1_table[] = - { - NdrServerCall2, - NdrServerCall2, - 0 - }; -static const RPC_DISPATCH_TABLE Example1_v1_0_DispatchTable = - { - 2, - (RPC_DISPATCH_FUNCTION*)Example1_table - }; - - -#endif /* defined(_M_AMD64)*/ - - - -/* this ALWAYS GENERATED file contains the RPC server stubs */ - - - /* File created by MIDL compiler version 8.01.0622 */ -/* at Tue Jan 19 03:14:07 2038 - */ -/* Compiler settings for Example1.idl: - Oicf, W3, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0622 - protocol : all , ms_ext, app_config, c_ext, robust - error checks: allocation ref bounds_check enum stub_data - VC __declspec() decoration level: - __declspec(uuid()), __declspec(selectany), __declspec(novtable) - DECLSPEC_UUID(), MIDL_INTERFACE() -*/ -/* @@MIDL_FILE_HEADING( ) */ - -#if defined(_M_AMD64) - - - - -#if !defined(__RPC_WIN64__) -#error Invalid build platform for this stub. -#endif - - -#include "ndr64types.h" -#include "pshpack8.h" - - -typedef -struct -{ - struct _NDR64_PROC_FORMAT frag1; - struct _NDR64_BIND_AND_NOTIFY_EXTENSION frag2; -} -__midl_frag6_t; -extern const __midl_frag6_t __midl_frag6; - -typedef -NDR64_FORMAT_CHAR -__midl_frag5_t; -extern const __midl_frag5_t __midl_frag5; - -typedef -struct _NDR64_CONFORMANT_STRING_FORMAT -__midl_frag4_t; -extern const __midl_frag4_t __midl_frag4; - -typedef -struct _NDR64_POINTER_FORMAT -__midl_frag3_t; -extern const __midl_frag3_t __midl_frag3; - -typedef -struct -{ - struct _NDR64_PROC_FORMAT frag1; - struct _NDR64_BIND_AND_NOTIFY_EXTENSION frag2; - struct _NDR64_PARAM_FORMAT frag3; - struct _NDR64_PARAM_FORMAT frag4; -} -__midl_frag2_t; -extern const __midl_frag2_t __midl_frag2; - -typedef -NDR64_FORMAT_UINT32 -__midl_frag1_t; -extern const __midl_frag1_t __midl_frag1; - -static const __midl_frag6_t __midl_frag6 = -{ -/* Shutdown */ - { - /* Shutdown */ /* procedure Shutdown */ - (NDR64_UINT32) 16777280 /* 0x1000040 */, /* explicit handle */ /* IsIntrepreted, HasExtensions */ - (NDR64_UINT32) 8 /* 0x8 */ , /* Stack size */ - (NDR64_UINT32) 0 /* 0x0 */, - (NDR64_UINT32) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 8 /* 0x8 */ - }, - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - 0x72, /* FC64_BIND_PRIMITIVE */ - (NDR64_UINT8) 0 /* 0x0 */, - 0 /* 0x0 */, /* Stack offset */ - (NDR64_UINT8) 0 /* 0x0 */, - (NDR64_UINT8) 0 /* 0x0 */ - }, - (NDR64_UINT16) 0 /* 0x0 */ /* Notify index */ - } -}; - -static const __midl_frag5_t __midl_frag5 = -0x5 /* FC64_INT32 */; - -static const __midl_frag4_t __midl_frag4 = -{ -/* *char */ - { - /* *char */ - 0x63, /* FC64_CONF_CHAR_STRING */ - { - /* *char */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - }, - (NDR64_UINT16) 1 /* 0x1 */ - } -}; - -static const __midl_frag3_t __midl_frag3 = -{ -/* *char */ - 0x20, /* FC64_RP */ - (NDR64_UINT8) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - &__midl_frag4 -}; - -static const __midl_frag2_t __midl_frag2 = -{ -/* Output */ - { - /* Output */ /* procedure Output */ - (NDR64_UINT32) 17563712 /* 0x10c0040 */, /* explicit handle */ /* IsIntrepreted, ClientMustSize, HasReturn, HasExtensions */ - (NDR64_UINT32) 24 /* 0x18 */ , /* Stack size */ - (NDR64_UINT32) 0 /* 0x0 */, - (NDR64_UINT32) 8 /* 0x8 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 0 /* 0x0 */, - (NDR64_UINT16) 2 /* 0x2 */, - (NDR64_UINT16) 8 /* 0x8 */ - }, - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - { - /* struct _NDR64_BIND_AND_NOTIFY_EXTENSION */ - 0x72, /* FC64_BIND_PRIMITIVE */ - (NDR64_UINT8) 0 /* 0x0 */, - 0 /* 0x0 */, /* Stack offset */ - (NDR64_UINT8) 0 /* 0x0 */, - (NDR64_UINT8) 0 /* 0x0 */ - }, - (NDR64_UINT16) 0 /* 0x0 */ /* Notify index */ - }, - { - /* pszOutput */ /* parameter pszOutput */ - &__midl_frag4, - { - /* pszOutput */ - 1, - 1, - 0, - 1, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - (NDR64_UINT16) 0 /* 0x0 */, - 0 - }, /* MustSize, MustFree, [in], SimpleRef */ - (NDR64_UINT16) 0 /* 0x0 */, - 8 /* 0x8 */, /* Stack offset */ - }, - { - /* int */ /* parameter int */ - &__midl_frag5, - { - /* int */ - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - (NDR64_UINT16) 0 /* 0x0 */, - 0 - }, /* [out], IsReturn, Basetype, ByValue */ - (NDR64_UINT16) 0 /* 0x0 */, - 16 /* 0x10 */, /* Stack offset */ - } -}; - -static const __midl_frag1_t __midl_frag1 = -(NDR64_UINT32) 0 /* 0x0 */; - - -#include "poppack.h" - - -static const FormatInfoRef Example1_Ndr64ProcTable[] = - { - &__midl_frag2, - &__midl_frag6 - }; - - -static const MIDL_STUB_DESC Example1_StubDesc = - { - (void *)& Example1___RpcServerInterface, - MIDL_user_allocate, - MIDL_user_free, - 0, - 0, - 0, - 0, - 0, - Example1__MIDL_TypeFormatString.Format, - 1, /* -error bounds_check flag */ - 0x60001, /* Ndr library version */ - 0, - 0x801026e, /* MIDL Version 8.1.622 */ - 0, - 0, - 0, /* notify & notify_flag routine table */ - 0x2000001, /* MIDL flag */ - 0, /* cs routines */ - (void *)& Example1_ServerInfo, /* proxy/server info */ - 0 - }; - -static const RPC_DISPATCH_FUNCTION Example1_NDR64__table[] = - { - NdrServerCallAll, - NdrServerCallAll, - 0 - }; -static const RPC_DISPATCH_TABLE Example1_NDR64__v1_0_DispatchTable = - { - 2, - (RPC_DISPATCH_FUNCTION*)Example1_NDR64__table - }; - -static const MIDL_SYNTAX_INFO Example1_SyntaxInfo [ 2 ] = - { - { - {{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}}, - (RPC_DISPATCH_TABLE*)&Example1_v1_0_DispatchTable, - Example1__MIDL_ProcFormatString.Format, - Example1_FormatStringOffsetTable, - Example1__MIDL_TypeFormatString.Format, - 0, - 0, - 0 - } - ,{ - {{0x71710533,0xbeba,0x4937,{0x83,0x19,0xb5,0xdb,0xef,0x9c,0xcc,0x36}},{1,0}}, - (RPC_DISPATCH_TABLE*)&Example1_NDR64__v1_0_DispatchTable, - 0 , - (unsigned short *) Example1_Ndr64ProcTable, - 0, - 0, - 0, - 0 - } - }; - - -static const SERVER_ROUTINE Example1_ServerRoutineTable[] = - { - (SERVER_ROUTINE)Output, - (SERVER_ROUTINE)Shutdown - }; - -static const MIDL_SERVER_INFO Example1_ServerInfo = - { - &Example1_StubDesc, - Example1_ServerRoutineTable, - Example1__MIDL_ProcFormatString.Format, - (unsigned short *) Example1_FormatStringOffsetTable, - 0, - (RPC_SYNTAX_IDENTIFIER*)&_NDR64_RpcTransferSyntax, - 2, - (MIDL_SYNTAX_INFO*)Example1_SyntaxInfo - }; -#if _MSC_VER >= 1200 -#pragma warning(pop) -#endif - - -#endif /* defined(_M_AMD64)*/ - diff --git a/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj b/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj index 5e5ad08..7edf74f 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj +++ b/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj @@ -19,7 +19,6 @@ - diff --git a/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj.filters b/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj.filters index 93d16dc..8199222 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj.filters +++ b/RPC/CPP-RPC-Client-Server/RPC-Interface1/RPC-Interface1.vcxproj.filters @@ -15,9 +15,6 @@ - - Source Files - Source Files diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.cpp b/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.cpp deleted file mode 100644 index c0303df..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.cpp +++ /dev/null @@ -1,110 +0,0 @@ - -#include -#include "..\RPC-Interface1\Example1_h.h" - -// Naive security callback. -RPC_STATUS CALLBACK SecurityCallback(RPC_IF_HANDLE hInterface, void* pBindingHandle) -{ - Output(pBindingHandle, "Inside Security Callback"); - return RPC_S_OK; // Always allow anyone. -} - -// Future server function. -int Output( - /* [in] */ handle_t hBinding, - /* [string][in] */ const char* pszOutput) -{ - std::cout << pszOutput << std::endl; - //szReturn = "Your Output was: "; - return 5; -} - - -void Shutdown( - /* [in] */ handle_t hBinding) -{ - Output(hBinding, "Calling: RpcMgmtStopServerListening ..."); - RPC_STATUS status; - status = RpcMgmtStopServerListening(NULL); // NULL indicates that we want to stop our own server, instead of a remote server - - if (status) - exit(status); - - Output(hBinding, "Calling: RpcServerUnregisterIf..."); - status = RpcServerUnregisterIf( - NULL, // NULL indicates that we want to unregister all interfaces - NULL, // NULL indicates that we want to remove interfaces for all UUIDs previously specfied with our s_ifspec - FALSE // FALSE indicates that we want to remove the interface from the registry immediatly - ); - - if (status) - exit(status); -} - - -int main() -{ - handle_t hBinding = NULL; - Output(hBinding , "Hello From RPC Server!"); - - RPC_STATUS rpcStatus; - RPC_WSTR pszProtSeq = (RPC_WSTR) L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); - RPC_WSTR pszTCPPort = (RPC_WSTR) L"8989"; //reinterpret_cast(L"8989"); - - // Create Binding information - Output(hBinding, "Creating Binding Information."); - rpcStatus = RpcServerUseProtseqEp( - pszProtSeq, // Use TCP/IP protocol. - RPC_C_PROTSEQ_MAX_REQS_DEFAULT, // Backlog queue length for TCP/IP. - pszTCPPort, // TCP/IP port to use. - NULL // No Secuirty Descriptor - ); - - if (rpcStatus) - exit(rpcStatus); - - // Registers the Example1 interface. - Output(hBinding, "Registering Server interface."); - rpcStatus = RpcServerRegisterIf2( - Example1_v1_0_s_ifspec, // Interface to register. - NULL, // Use the MIDL generated entry-point vector. - NULL, // Use the MIDL generated entry-point vector. - RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, // Forces use of security callback. - RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls. - (unsigned)-1, // Infinite max size of incoming data blocks. - SecurityCallback); // Naive security callback. - - if (rpcStatus) - exit(rpcStatus); - - // Start to listen for remote procedure - // calls for all registered interfaces. - // This call will not return until - // RpcMgmtStopServerListening is called. - Output(hBinding, "Listening for client connection."); - rpcStatus = RpcServerListen( - 1, // Recommended minimum number of threads. - RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Recommended maximum number of threads. - FALSE); // Start listening now. - - if (rpcStatus) - exit(rpcStatus); - - Output(hBinding, "RPC Server stopped, executing now..."); -} - -/******************************************************/ -/* MIDL allocate and free */ -/* The runtime uses these two functions for */ -/* allocating / deallocating */ -/******************************************************/ - -void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) -{ - return(malloc(len)); -} - -void __RPC_USER midl_user_free(void __RPC_FAR * ptr) -{ - free(ptr); -} \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj b/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj deleted file mode 100644 index 55bb8cd..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj +++ /dev/null @@ -1,190 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {C990E686-372D-4BC6-BADE-6B6E5C9A65FA} - Win32Proj - RPCServer - 10.0 - RPC-Server - - - - Application - true - v142 - Unicode - Static - - - Application - false - v142 - true - Unicode - Static - - - Application - true - v142 - Unicode - Static - - - Application - false - v142 - true - Unicode - Static - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - NotUsing - Level4 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - false - true - false - false - EnableFastChecks - - - Console - true - rpcrt4.lib;%(AdditionalDependencies) - - - true - /prefix %(AdditionalOptions) - - - - - NotUsing - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - rpcrt4.lib;%(AdditionalDependencies) - - - true - /prefix %(AdditionalOptions) - - - - - NotUsing - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - Rpcrt4.lib;%(AdditionalDependencies) - - - true - /prefix %(AdditionalOptions) - - - - - NotUsing - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - Rpcrt4.lib;%(AdditionalDependencies) - - - true - /prefix %(AdditionalOptions) - - - - - - - - - {423c961c-29ad-432a-86c3-72daaa407d9c} - - - - - - \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.filters b/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.filters deleted file mode 100644 index 6858e92..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.user b/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.user deleted file mode 100644 index 6e2aec7..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Server/RPC-Server.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-NoSecurity/RPC-Server-Explicit-NoSecurity.cpp b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-NoSecurity/RPC-Server-Explicit-NoSecurity.cpp index 3da8ba0..11fc6d5 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-NoSecurity/RPC-Server-Explicit-NoSecurity.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-NoSecurity/RPC-Server-Explicit-NoSecurity.cpp @@ -39,15 +39,12 @@ void Shutdown( int main() { - handle_t hBinding = NULL; - BOOL bAuthBinding = FALSE; wprintf(L"[*] RPC Server started.\n"); + handle_t hBinding = NULL; RPC_STATUS rpcStatus; RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); - RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; //reinterpret_cast(L"8989"); - //RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_np"; //reinterpret_cast(L"ncacn_ip_tcp"); - //RPC_WSTR pszTCPPort = (RPC_WSTR)L"\\pipe\\RPCServer1ESCA"; //reinterpret_cast(L"8989"); + RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; // Create Binding information wprintf(L"[*] Create Binding Information using protocol '%s' at '%s'...", pszTCPPort, pszProtSeq, pszTCPPort); @@ -67,7 +64,7 @@ int main() wprintf(L"[*] Registering Server interface without registration Flags or SecurityCallback..."); rpcStatus = RpcServerRegisterIf2( Example1_v1_0_s_ifspec, // Interface to register. - NULL, // Use the MIDL generated entry-point vector. + NULL, // NULL GUID NULL, // Use the MIDL generated entry-point vector. 0, // No flags. RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls. @@ -78,45 +75,6 @@ int main() wprintf(L"Failed. Error: %s\n", rpcStatus); exit(rpcStatus); } else wprintf(L"Success.\n"); - - if (bAuthBinding) { - // Obtain SPN for host - DWORD cSPN; - TCHAR** ppFoundSPNs; - DWORD spnStatus; - RPC_WSTR pszSpn; - wprintf(L"[*] Getting host SPN..."); - spnStatus = DsGetSpn( - DS_SPN_NB_HOST, // SPN format ServiceClass/ InstanceName: InstancePort - L"Host", // SPN class - NULL, // DNS name of SPN, not required therefor NULL - 0, // SPN instance port, 0 to specfiy that SPN does not include port - 0, // number additional instance names - NULL, // no additional instance names - NULL, // no additional instance ports - &cSPN, // pointer to DWORD containing the number of SPNs found - &ppFoundSPNs // Pointer to a variable that receives a pointer to an array of SPNs - ); - if (spnStatus != ERROR_SUCCESS) { - wprintf(L"Failed. Error: %s\n", rpcStatus); - exit(spnStatus); - } - else wprintf(L"Success.\n"); - pszSpn = (RPC_WSTR)ppFoundSPNs; - // Register authentication info - wprintf(L"[*] Registering Auth info with SPN '%s'...", *ppFoundSPNs); - rpcStatus = RpcServerRegisterAuthInfo( - pszSpn, // Server principal name - RPC_C_AUTHN_WINNT, // using NTLM as authentication service provider as defined at https://docs.microsoft.com/en-us/windows/win32/rpc/authentication-service-constants - NULL, // Use default key function, is ignored for NTLM SSP as per https://docs.microsoft.com/en-us/windows/win32/api/rpcdce/nf-rpcdce-rpcserverregisterauthinfo - NULL); // No arg for key function - - if (rpcStatus) { - wprintf(L"Failed. Error: %s\n", rpcStatus); - exit(rpcStatus); - } - else wprintf(L"Success.\n"); - } // Start to listen for remote procedure // calls for all registered interfaces. diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server-Explicit-SecurityCallback-Auth.cpp b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server-Explicit-SecurityCallback-Auth.cpp index 0c72ac0..2608553 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server-Explicit-SecurityCallback-Auth.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server-Explicit-SecurityCallback-Auth.cpp @@ -6,225 +6,15 @@ #include // For Window Security #include "..\RPC-Interface1\Interface1-Explicit_h.h" -#include "..\RPC-Util\Access.cpp" -#include "..\RPC-Util\Token.cpp" +#include "..\RPC-Util\Command.cpp" -//typedef struct _csTOKEN { -// LPWSTR pwsUSERSID; -// TOKEN_TYPE TokenType; -// LPWSTR pwsTokenType; -// LPWSTR pwsTokenImpersonationLevel; -//} CSTOKEN, *PCSTOKEN; -// -//typedef enum _csENDPOINTTYPE { -// TCP_IP, -// NamedPipe, -// LRPC -//} CSENDPOINTTYPE; -// -//BOOL EnablePriv(HANDLE hToken, LPCTSTR priv) -//{ -// TOKEN_PRIVILEGES tp; -// LUID luid; -// -// if (!LookupPrivilegeValue(NULL, priv, &luid)) -// { -// printf("Priv Lookup FALSE\n"); -// return FALSE; -// } -// -// tp.PrivilegeCount = 1; -// tp.Privileges[0].Luid = luid; -// tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; -// if (!AdjustTokenPrivileges( -// hToken, -// FALSE, -// &tp, -// sizeof(TOKEN_PRIVILEGES), -// (PTOKEN_PRIVILEGES)NULL, -// (PDWORD)NULL)) -// { -// printf("Priv Adjust FALSE\n"); -// return FALSE; -// } -// -// return TRUE; -//} - -//BOOL printTokenType(HANDLE hToken, PCSTOKEN pCSToken) { -// PTOKEN_TYPE ptt = NULL; -// DWORD dwSize = 0; -// pCSToken->pwsTokenType = (LPWSTR)L""; -// if (!GetTokenInformation(hToken, TokenType, NULL, 0, &dwSize) -// && ERROR_INSUFFICIENT_BUFFER != GetLastError()) -// { -// return FALSE; -// } -// if (NULL != (ptt = (PTOKEN_TYPE)LocalAlloc(LPTR, dwSize))) -// { -// if (!GetTokenInformation(hToken, TokenType, ptt, dwSize, &dwSize)) -// { -// LocalFree((HLOCAL)ptt); -// return FALSE; -// } -// pCSToken->TokenType = (TOKEN_TYPE)*ptt; -// switch (pCSToken->TokenType) -// { -// case TokenImpersonation: -// pCSToken->pwsTokenType = (LPWSTR)L"ImpersonationToken"; -// return TRUE; -// case TokenPrimary: -// pCSToken->pwsTokenType = (LPWSTR)L"PrimaryToken"; -// return TRUE; -// default: -// wprintf(L"[-] Undefined Token Type. \n"); -// return FALSE; -// } -// -// LocalFree((HLOCAL)ptt); -// } -// return FALSE; -//} -// -//BOOL printTokenImpersonationLeven(HANDLE hToken, PCSTOKEN pCSToken) { -// PSECURITY_IMPERSONATION_LEVEL psil = NULL; -// DWORD dwSize = 0; -// pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L""; -// if (!GetTokenInformation(hToken, TokenImpersonationLevel, NULL, 0, &dwSize) -// && ERROR_INSUFFICIENT_BUFFER != GetLastError()) -// { -// return FALSE; -// } -// if (NULL != (psil = (PSECURITY_IMPERSONATION_LEVEL)LocalAlloc(LPTR, dwSize))) -// { -// if (!GetTokenInformation(hToken, TokenImpersonationLevel, psil, dwSize, &dwSize)) -// { -// LocalFree((HLOCAL)psil); -// return FALSE; -// } -// switch (*psil) -// { -// case SecurityAnonymous: -// pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityAnonymous"; -// return TRUE; -// case SecurityIdentification: -// pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityIdentification"; -// return TRUE; -// case SecurityImpersonation: -// pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityImpersonation"; -// return TRUE; -// case SecurityDelegation: -// pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityDelegation"; -// return TRUE; -// default: -// wprintf(L"[-] Undefined Impersonation Level. \n"); -// return FALSE; -// } -// LocalFree((HLOCAL)psil); -// } -// return FALSE; -//} -// -//BOOL printTokenUserSid(HANDLE hToken, PCSTOKEN pCSToken) -//{ -// PTOKEN_USER ptu = NULL; -// DWORD dwSize = 0; -// pCSToken->pwsUSERSID = (LPWSTR)L""; -// if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize) -// && ERROR_INSUFFICIENT_BUFFER != GetLastError()) -// { -// return FALSE; -// } -// if (NULL != (ptu = (PTOKEN_USER)LocalAlloc(LPTR, dwSize))) -// { -// LPTSTR StringSid = NULL; -// if (!GetTokenInformation(hToken, TokenUser, ptu, dwSize, &dwSize)) -// { -// LocalFree((HLOCAL)ptu); -// return FALSE; -// } -// if (ConvertSidToStringSid(ptu->User.Sid, &StringSid)) -// { -// pCSToken->pwsUSERSID = StringSid; -// LocalFree((HLOCAL)StringSid); -// LocalFree((HLOCAL)ptu); -// return TRUE; -// } -// else { -// wprintf(L"[-] Failed to resolve SID to string.\n"); -// return FALSE; -// } -// LocalFree((HLOCAL)ptu); -// } -// return FALSE; -//} -// -// -//void ExtractTokenInformation(HANDLE hToken) { -// BOOL result; -// PCSTOKEN pCSToken = new CSTOKEN; -// // Get UserSID -// result = printTokenUserSid(hToken, pCSToken); -// if (!result) wprintf(L" [-]... failed to get Token SID\n"); -// else wprintf(L" [+] UserSID: %s\n", pCSToken->pwsUSERSID); -// // GET TokenType -// result = printTokenType(hToken, pCSToken); -// if (!result) wprintf(L" [-]... failed to get Token Type\n"); -// else wprintf(L" [+] TokenType: %s\n", pCSToken->pwsTokenType); -// if (pCSToken->TokenType == TokenImpersonation) { -// // GET TokenImpersonationLevel -// result = printTokenImpersonationLeven(hToken, pCSToken); -// if (!result) wprintf(L" [-]... failed to get Token Type\n"); -// else wprintf(L" [+] ImpersonationLevel: %s\n", pCSToken->pwsTokenImpersonationLevel); -// } -// -//} - -void LaunchPrg(HANDLE hClientToken) { - // open cmd.exe as client - STARTUPINFO si = {}; - PROCESS_INFORMATION pi = {}; - DWORD gle = 0; - HANDLE duped_token; - wchar_t command[] = L"C:\\Windows\\system32\\calc.exe"; - wprintf(L"Launching cmd.exe as impersonated client..."); - - try { - // create impersonation token - BOOL result = DuplicateTokenEx(hClientToken, - TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID | TOKEN_IMPERSONATE, - NULL, - SecurityImpersonation, - TokenImpersonation, - &duped_token); - - if (!result) { - printf("[-] DuplicateTokenEx failed: %d\n", GetLastError()); - } - - if (CreateProcessWithTokenW(duped_token, LOGON_WITH_PROFILE, NULL, - command, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { - wprintf(L"Success?...Waiting 10 secs\n"); - - Sleep(10); - } - else { - wprintf(L"Failed\n"); - gle = GetLastError(); - wprintf(L"Error code: %s\n", gle); - } - } - catch (...) { - gle = GetLastError(); - wprintf(L"Error code: %s\n", gle); - } - CloseHandle(hClientToken); -} +// global param +int g_bImpersonateClient = TRUE; // Naive security callback. RPC_STATUS CALLBACK SecurityCallback(RPC_IF_HANDLE hInterface, void* pBindingHandle) { - wprintf(L"Inside Security Callback"); + wprintf(L"[*] Inside Security Callback\n"); return RPC_S_OK; // Always allow anyone. } @@ -233,475 +23,24 @@ int Output( /* [in] */ handle_t hBinding, /* [string][in] */ const char* pszOutput) { - HANDLE hGClientToken; - HANDLE hGDuppedToken; - - printf("\n[~] Client Message: %s\n", pszOutput); - if (true) { - setWindowAccess(); - setDesktopAccess(); + BOOL bSuccess; + printf("[~] Client Message: %s\n", pszOutput); + if (g_bImpersonateClient) { // Try to impersonate client - wprintf(L"Trying to impersonate client..."); + wprintf(L"[*] Trying to impersonate client..."); RPC_STATUS status = RpcImpersonateClient(hBinding); if (status != RPC_S_OK) { - printf("failed.Status: %d\n", status); - //Shutdown(hBinding); - return 10; + printf("failed (Error: %d)\n", status); + return 10; // arbitrary chosen, this function could return void or anything else. This is just a PoC } - else printf("Success!\n"); - // Get thread token - printf("Trying to get current thread token..."); - BOOL bThrTokenOpened = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &hGClientToken); - if (!bThrTokenOpened) { - printf("Failed.\n"); + else { + printf("Success!\n"); + // Execute Window command (cause cmd.exe will spawn a new GUI window) + wchar_t command[] = L"C:\\Windows\\System32\\cmd.exe"; + bSuccess = execImpersonatedWindowCommand(hBinding, command); } - else printf("Succeded.\n"); - ExtractTokenInformation(hGClientToken); - // Duplicate Token - wprintf(L"Trying to duplicate impersonated token..."); - BOOL res5 = DuplicateTokenEx(hGClientToken, - TOKEN_ALL_ACCESS, - NULL, - SecurityImpersonation, - TokenPrimary, - &hGDuppedToken); - if (res5) wprintf(L"Success!\n"); - else wprintf(L"Failure\n"); - // revert back to server thread identity - printf("Reverting back to self..."); - RPC_STATUS rpcStatus = RpcRevertToSelfEx(hBinding); - if (rpcStatus) - { - wprintf(L"Failed to revert back from RPC client impersonation to server identity. Error 0x%x.\n", rpcStatus); - //exit(rpcStatus); - } - else printf("Success.\n"); - // -- Execute Process - printf("Trying to launch cmd.exe with CreateProcessWithTokenW... "); - PROCESS_INFORMATION pi; - STARTUPINFO si; - wchar_t command[] = L"C:\\Windows\\System32\\cmd.exe"; - //SECURITY_ATTRIBUTES sa; - ZeroMemory(&si, sizeof(STARTUPINFO)); - ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); - //memset(&pi, 0x00, sizeof(PROCESS_INFORMATION)); - si.cb = sizeof(STARTUPINFO); - BOOL bSucc = CreateProcessWithTokenW( - hGDuppedToken, - 0, - command, - NULL, - CREATE_NEW_CONSOLE, - NULL, - NULL, - &si, - &pi - ); - if (!bSucc) printf("failed. Error: %d\n", GetLastError()); - else wprintf(L"Success.\n"); - // -- Close Handles - CloseHandle(hGDuppedToken); - CloseHandle(hGClientToken); } - // -- Return value - return 5; - - /* - wprintf(L"\nGet Current Session ID..."); - DWORD sessionID = 12; - BOOL bRes = ProcessIdToSessionId(GetCurrentProcessId(), &sessionID); - if (bRes) wprintf(L"SessionID: %d\n", sessionID); - else wprintf(L"Failed. Error: %d\n", GetLastError()); - */ - - DWORD error; - wprintf(L"Gettinng current process Window..."); - HWINSTA hWinSta = GetProcessWindowStation(); - if (hWinSta) { - wprintf(L"Success.\n"); - wprintf(L"Setting Security of current Proccess Window..."); - error = SetSecurityInfo(hWinSta, - SE_WINDOW_OBJECT, - DACL_SECURITY_INFORMATION, - NULL, // don't set the ownerSID - NULL, // don't set the primary GROUP - NULL, // DACL pointer, NULL=> full access to everyone - NULL // no setting SACL - ); - if (error == ERROR_SUCCESS) wprintf(L"Success.\n"); - else wprintf(L"Error: %d.\n", error); - } - else wprintf(L"Error: %d.\n", GetLastError()); - - wprintf(L"Getting current Desktop.."); - HDESK hDesk = GetThreadDesktop(GetCurrentThreadId()); - if (hDesk) { - wprintf(L"Success\n"); - wprintf(L"Setting Security of current Desktop..."); - error = SetSecurityInfo(hDesk, - SE_WINDOW_OBJECT, - DACL_SECURITY_INFORMATION, - NULL, // don't set the ownerSID - NULL, // don't set the primary GROUP - NULL, // DACL pointer, NULL=> full access to everyone - NULL // no setting SACL - ); - if (error == ERROR_SUCCESS) wprintf(L"Success\n"); - else wprintf(L"Error: %d\n", error); - } - else wprintf(L"Error: %d\n", GetLastError()); - - /* - HANDLE hGServerToken; - wprintf(L"\nGet Server's thread access token..."); - BOOL hGSrvAccess = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hGServerToken); - if (!hGSrvAccess) { - printf("Error: %s\n", GetLastError()); - } - else printf("Succeded.\n"); - */ - - //szReturn = "Your Output was: "; - - /* - wprintf(L"Trying calling with own token..."); - HANDLE hServerToken2; - BOOL bThrTokenOpened2 = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hServerToken2); - if (!bThrTokenOpened2) { - DWORD eii = GetLastError(); - wprintf(L"Error OpenThreadToken: %d\n", eii); - } - ExtractTokenInformation(hServerToken2); - - PROCESS_INFORMATION pi2; - STARTUPINFO si2; - //SECURITY_ATTRIBUTES sa; - ZeroMemory(&si2, sizeof(STARTUPINFO)); - ZeroMemory(&pi2, sizeof(PROCESS_INFORMATION)); - memset(&pi2, 0x00, sizeof(PROCESS_INFORMATION)); - si2.cb = sizeof(STARTUPINFO); - BOOL ret8 = TRUE;//CreateProcessWithTokenW(hServerToken2, LOGON_NETCREDENTIALS_ONLY, L"C:\\Windows\\System32\\cmd.exe", NULL, CREATE_NEW_CONSOLE, NULL, NULL, &si2, &pi2); - if (!ret8) { - DWORD klqoo = GetLastError(); - wprintf(L"Error %d\n", klqoo); - } - else printf("Successy!!\n"); - */ - - // Try to impersonate client - wprintf(L"Trying to impersonate client..."); - RPC_STATUS status = RpcImpersonateClient(hBinding); - if (status != RPC_S_OK) { - printf("failed.Status: %d\n", status); - //Shutdown(hBinding); - return 10; - } - else printf("Success!\n"); - - - /* - // WORKING SPAWNING cmd.exe with server user (not impersonating) - - printf("Trying to launch cmd.exe with CreateProcess..."); - PROCESS_INFORMATION processInformation = { 0 }; - STARTUPINFO startupInfo = { 0 }; - startupInfo.cb = sizeof(startupInfo); - - printf("Creating process cmd.exe ..."); - // Create the process - wchar_t command[] = L"C:\\Windows\\system32\\cmd.exe"; - BOOL result = CreateProcess(NULL, command, - NULL, NULL, FALSE, - CREATE_NEW_CONSOLE, - NULL, NULL, &startupInfo, &processInformation); - if (!result) { - printf("Failed.\n"); - return 1; - } - else printf("Success.\n"); - // Successfully created the process. Wait for it to finish. - WaitForSingleObject(processInformation.hProcess, INFINITE); - //CloseHandle(processInformation.hProcess); - //CloseHandle(processInformation.hThread); - - // WORKING --END - - */ - - // Get token from current thread - //HANDLE hClientToken; - printf("Trying to get current thread token..."); - BOOL bThrTokenOpened = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &hGClientToken); - if (!bThrTokenOpened) { - printf("Failed.\n"); - } - else printf("Succeded.\n"); - ExtractTokenInformation(hGClientToken); - - - - - - /* - PSID ppUserSid; - PSID ppGroupSid; - wchar_t* foo[500] = {0}; - //HRESULT res = GetTokenSids(hClientToken, &ppUserSid, &ppGroupSid); - BOOL res3 = GetUserSid(hClientToken, &ppUserSid); - printf("Result: %d \n", res3); - BOOL res4 = ConvertSidToStringSid(ppUserSid, foo); - if (!res4) printf("Failed to resovle SID to String\n"); - else { - printf("Success to resolve SID...\n"); - printf("SID: %s", foo); - } - int a = 4; - //printf("User SIDs: %s", *ppUserSid->pSid) - */ - - // Duplicate Token - //HANDLE duped_token; - wprintf(L"Trying to duplicate impersonated token..."); - BOOL res5 = DuplicateTokenEx(hGClientToken, - TOKEN_ALL_ACCESS, - NULL, - SecurityImpersonation, - TokenPrimary, - &hGDuppedToken); - if (res5) wprintf(L"Success!\n"); - else wprintf(L"Failure\n"); - - - - //enable privileges - //BOOL bPrivsEn; - /* - HANDLE currenThreadToken; - printf("Open current Thread token..."); - BOOL bThrTokenOpened2 = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, ¤ThreadToken); - if (!bThrTokenOpened2) { - printf("Error: %d\n", GetLastError()); - } - else printf("Succeded.\n"); - */ - /* - printf("Enabling Privs with the user:\n"); - ExtractTokenInformation(hGDuppedToken); - printf("\n"); - wprintf(L"Enable Privilege: SE_IMPERSONATE_NAME...."); - bPrivsEn = EnablePriv(hGDuppedToken, SE_IMPERSONATE_NAME); - if (bPrivsEn) wprintf(L"Success.\n"); - else wprintf(L"failed.\n"); - wprintf(L"Enable Privilege: SE_ASSIGNPRIMARYTOKEN_NAME...."); - bPrivsEn = EnablePriv(hGDuppedToken, SE_ASSIGNPRIMARYTOKEN_NAME); - if (bPrivsEn) wprintf(L"Success.\n"); - else wprintf(L"failed.\n"); - wprintf(L"Enable Privilege: SE_INCREASE_QUOTA_NAME...."); - bPrivsEn = EnablePriv(hGDuppedToken, SE_INCREASE_QUOTA_NAME); - if (bPrivsEn) wprintf(L"Success.\n"); - else wprintf(L"failed.\n"); - */ - - printf("Reverting back to self..."); - // revert back to server thread identity - RPC_STATUS rpcStatus = RpcRevertToSelfEx(hBinding); - if (rpcStatus) - { - wprintf(L"Failed to revert back from RPC client impersonation to server identity. Error 0x%x.\n", rpcStatus); - //exit(rpcStatus); - } - else printf("Success.\n"); - - /* - printf("Enabling Privs with the user:\n"); - ExtractTokenInformation(hGServerToken); - LPCWSTR pwsPrivileges[6] = { SE_IMPERSONATE_NAME, SE_ASSIGNPRIMARYTOKEN_NAME, - SE_INCREASE_QUOTA_NAME, SE_DELEGATE_SESSION_USER_IMPERSONATE_NAME, - SE_ENABLE_DELEGATION_NAME, - SE_DELEGATE_SESSION_USER_IMPERSONATE_NAME, - }; - for (LPCWSTR pwsPrivilege : pwsPrivileges) - { - wprintf(L"Enable Privilege: %s ....", pwsPrivilege); - bPrivsEn = EnablePriv(hGServerToken, pwsPrivilege); - if (bPrivsEn) wprintf(L"Success.\n"); - else wprintf(L"failed. Error: %d\n", GetLastError()); - } - */ - - - // TEST - // TRY number #1 - - printf("Trying to launch cmd.exe with CreateProcessWithTokenW... "); - //PROCESS_INFORMATION processInformation2 = { 0 }; - //STARTUPINFO startupInfo2 = { 0 }; - //BOOL res = CreateProcessWithTokenW(hClientToken, LOGON_WITH_PROFILE, command1, command1, - // CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo2, &processInformation2); - PROCESS_INFORMATION pi; - STARTUPINFO si; - wchar_t command[] = L"C:\\Windows\\System32\\cmd.exe"; - //SECURITY_ATTRIBUTES sa; - ZeroMemory(&si, sizeof(STARTUPINFO)); - ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); - //memset(&pi, 0x00, sizeof(PROCESS_INFORMATION)); - si.cb = sizeof(STARTUPINFO); - BOOL bSucc = CreateProcessWithTokenW( - hGDuppedToken, - 0, - command, - NULL, - CREATE_NEW_CONSOLE, - NULL, - NULL, - &si, - &pi - ); - if (!bSucc) printf("failed. Error: %d\n", GetLastError()); - else wprintf(L"Success.\n"); - //ExtractTokenInformation(hGDuppedToken); - //WaitForSingleObject(pi.hProcess, INFINITE); // use this if you want to wait for the proccess to complete - - - - /* - wprintf(L"Try Number #2..."); - BOOL res = CreateProcessWithTokenW( - hGDuppedToken, // Duplicated Client token - 0, // No logon Flags (we don't want to set the logon registy) - L"C:\\Windows\\System32\\cmd.exe", // let's not use the lpApplicationName, but only the lpCommandLine - NULL, // lpCommandLine to execute - CREATE_NEW_CONSOLE, // get a new fresh console, not inheriting the parent's console - NULL, // no environment block needed - L"C:\\", // inherit the current directory from this calling proccess - &si, // startup information struct - &pi); // proccess informaiton struct - - if (!res) { - DWORD gle = GetLastError(); - printf("Error from next CreateProcessWithTokenW: %d\n", gle); - } - else printf("Success. \n"); - */ - - - /* - // Try 3 - wprintf(L"Try number #3 ..."); - PROCESS_INFORMATION pi3; - STARTUPINFO si3; - //SECURITY_ATTRIBUTES sa; - //sa.bInheritHandle = false; - //sa.nLength = sizeof(sa); - //sa.lpSecurityDescriptor = nullptr; - - ZeroMemory(&si3, sizeof(STARTUPINFO)); - ZeroMemory(&pi3, sizeof(PROCESS_INFORMATION)); - //memset(&pi3, 0x00, sizeof(PROCESS_INFORMATION)); - si3.cb = sizeof(STARTUPINFO); - //si3.lpDesktop = (LPWSTR)L"winsta0\\default"; - si3.wShowWindow = SW_SHOWNORMAL; - si3.dwFlags = STARTF_USESHOWWINDOW; - wchar_t command3[] = L"C:\\Windows\\System32\\notepad.exe"; - wchar_t command4[] = L"cmd.exe"; - BOOL res6 = CreateProcessAsUser( - hGDuppedToken, // duplicated primary token - NULL, // appName - command3, // cmdLine - NULL, // no security descriptor for proccess - NULL, // no security descriptor for thread - FALSE, // don't inherit handles from the calling process - CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, // creation flags - nullptr, // inherit environment from the calling process - L"C:\\", // spawn in the directory of the calling process - &si3, - &pi3 - ); - if (res6) { - WaitForSingleObject(pi3.hProcess, INFINITE); - - Sleep(5); - wprintf(L"Success. PID: %d \n", pi3.dwProcessId); - } - else { - DWORD gle2 = GetLastError(); - wprintf(L"nope: %d\n", gle2); - } - */ - - // Try number #4 - assign primary token - //SetThreadToken - - CloseHandle(hGDuppedToken); - CloseHandle(hGClientToken); - - // TEST --END - - //Shutdown(hBinding); - /*** - if (bThrTokenOpened) { - try - { - wprintf(L"Trying to extract token information\n"); - //ExtractTokenInformation(hClientToken); - //std::string foo = sid_from_token_info(hClientToken); - //wprintf(L"SID IS: %s", foo); - } - catch (...) - { - wprintf(L"Error while trying to extract token information\n"); - } - LaunchPrg(hClientToken); - - / - // open cmd.exe as client - STARTUPINFO si = {}; - PROCESS_INFORMATION pi = {}; - DWORD gle = 0; - HANDLE duped_token; - wchar_t command[] = L"C:\\Windows\\system32\\calc.exe"; - wprintf(L"Launching cmd.exe as impersonated client..."); - - try { - // create impersonation token - BOOL result = DuplicateTokenEx(hClientToken, - TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID | TOKEN_IMPERSONATE, - NULL, - SecurityImpersonation, - TokenImpersonation, - &duped_token); - - if (!result) { - printf("[-] DuplicateTokenEx failed: %d\n", GetLastError()); - } - - if (CreateProcessWithTokenW(duped_token, LOGON_WITH_PROFILE, L"C:\\Windows\\system32\\calc.exe", - NULL, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { - wprintf(L"Success?...Waiting 10 secs\n"); - - Sleep(10); - } - else { - wprintf(L"Failed\n"); - gle = GetLastError(); - wprintf(L"Error code: %s\n", gle); - } - } - catch (...) { - gle = GetLastError(); - wprintf(L"Error code: %s\n", gle); - } - CloseHandle(hClientToken); - / - } - else { - DWORD gle = GetLastError(); - wprintf(L"Failed to open thread token for impersonated RPC client. Error 0x%x.\n", gle); - return HRESULT_FROM_WIN32(gle); - } - - ***/ - + // -- Return value, arbitrary chosen return 5; } @@ -709,14 +48,14 @@ int Output( void Shutdown( /* [in] */ handle_t hBinding) { - wprintf(L"Calling: RpcMgmtStopServerListening ...\n"); + wprintf(L"[*] Calling: RpcMgmtStopServerListening ...\n"); RPC_STATUS status; status = RpcMgmtStopServerListening(NULL); // NULL indicates that we want to stop our own server, instead of a remote server if (status) exit(status); - wprintf(L"Calling: RpcServerUnregisterIf...\n"); + wprintf(L"[*] Calling: RpcServerUnregisterIf...\n"); status = RpcServerUnregisterIf( NULL, // NULL indicates that we want to unregister all interfaces NULL, // NULL indicates that we want to remove interfaces for all UUIDs previously specfied with our s_ifspec @@ -731,6 +70,7 @@ int main() { wprintf(L"[*] Starting RPC Server!\n"); handle_t hBinding = NULL; + BOOL bRpcEpRegister = TRUE; // SPN vars DWORD spnStatus; DWORD serverSPNLen = MAX_PATH; @@ -742,7 +82,7 @@ int main() RPC_WSTR pszSpn; RPC_WSTR pszProtSeq; RPC_WSTR pszTCPPort; - CSENDPOINTTYPE pwsEndpointType = LRPC; + CSENDPOINTTYPE pwsEndpointType = NamedPipe; switch (pwsEndpointType) { case TCP_IP: @@ -819,10 +159,10 @@ int main() } // Registers the Example1 interface. - wprintf(L"[*] Registering Server interface.\n"); + wprintf(L"[*] Registering Server interface:.\n"); rpcStatus = RpcServerRegisterIf2( Example1_v1_0_s_ifspec, // Interface to register. - NULL, // Use the MIDL generated entry-point vector. + NULL, // Nil-type UUID NULL, // Use the MIDL generated entry-point vector. RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, // Forces use of security callback. RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls. @@ -846,6 +186,33 @@ int main() wprintf(L"[-] RpcServerRegisterIf2() failed with status: %d.\n", rpcStatus); exit(rpcStatus); } + + if ( bRpcEpRegister ) { + // This server uses Well-known endpoints + // Therefore the server doesn't has to report its interfaces to the RPC Endpoint Mapper in + // Order for the clients to be able to connect + // We can do this nevertheless just so that we can find this server when quering the Endpoint Mapper + wprintf(L"[*] RpcServerInqBindings...\n"); + RPC_BINDING_VECTOR* pbindingVector = 0; + rpcStatus = RpcServerInqBindings(&pbindingVector); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcServerInqBindings() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } + wprintf(L"[*] RpcEpRegister...\n"); + rpcStatus = RpcEpRegister( + Example1_v1_0_s_ifspec, + pbindingVector, + 0, + (RPC_WSTR)L"TEST?" + ); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcEpRegister() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } + } + + // Start to listen for remote procedure // calls for all registered interfaces. // This call will not return until @@ -861,7 +228,7 @@ int main() exit(rpcStatus); } - wprintf(L"RPC Server stopped, executing now...\n"); + wprintf(L"[*] RPC Server stopped, exiting now...\n"); } /******************************************************/ diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server1-Explicit-SecurityCallback-Auth.vcxproj b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server1-Explicit-SecurityCallback-Auth.vcxproj index 520cf60..c0451d2 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server1-Explicit-SecurityCallback-Auth.vcxproj +++ b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-Auth/RPC-Server1-Explicit-SecurityCallback-Auth.vcxproj @@ -83,7 +83,7 @@ Console - rpcrt4.lib;Ntdsapi.lib;Advapi32.lib;User32.lib;%(AdditionalDependencies) + rpcrt4.lib;Ntdsapi.lib;Advapi32.lib;User32.lib;Ole32.lib;%(AdditionalDependencies) diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-NoAuth/RPC-Server-Explicit-SecurityCallback-NoAuth.cpp b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-NoAuth/RPC-Server-Explicit-SecurityCallback-NoAuth.cpp index 1d2ad5d..cc2282f 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-NoAuth/RPC-Server-Explicit-SecurityCallback-NoAuth.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Server1-Explicit-SecurityCallback-NoAuth/RPC-Server-Explicit-SecurityCallback-NoAuth.cpp @@ -45,9 +45,9 @@ void Shutdown( int main() { - handle_t hBinding = NULL; wprintf(L"[*] RPC Server started.\n"); + handle_t hBinding = NULL; RPC_STATUS rpcStatus; RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; //reinterpret_cast(L"8989"); @@ -70,9 +70,9 @@ int main() wprintf(L"[*] Registering Server interface ..."); rpcStatus = RpcServerRegisterIf2( Example1_v1_0_s_ifspec, // Interface to register. + NULL, // NULL GUID NULL, // Use the MIDL generated entry-point vector. - NULL, // Use the MIDL generated entry-point vector. - 0, // Forces use of security callback. + 0, // No Flags RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls. (unsigned)-1, // Infinite max size of incoming data blocks. SecurityCallback); // Naive security callback. diff --git a/RPC/CPP-RPC-Client-Server/RPC-Server1-Implicit-NoSecurity/RPC-Server-Implicit-NoSecurity.cpp b/RPC/CPP-RPC-Client-Server/RPC-Server1-Implicit-NoSecurity/RPC-Server-Implicit-NoSecurity.cpp index 1108efd..c774a83 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Server1-Implicit-NoSecurity/RPC-Server-Implicit-NoSecurity.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Server1-Implicit-NoSecurity/RPC-Server-Implicit-NoSecurity.cpp @@ -14,36 +14,40 @@ int Output( void Shutdown() { - Output("Calling: RpcMgmtStopServerListening ..."); - RPC_STATUS status; - status = RpcMgmtStopServerListening(NULL); // NULL indicates that we want to stop our own server, instead of a remote server + wprintf(L"Calling: RpcMgmtStopServerListening ..."); + RPC_STATUS rpcStatus; + rpcStatus = RpcMgmtStopServerListening(NULL); // NULL indicates that we want to stop our own server, instead of a remote server - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingSetAuthInfoEx() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } - Output("Calling: RpcServerUnregisterIf..."); - status = RpcServerUnregisterIf( + wprintf(L"Calling: RpcServerUnregisterIf..."); + rpcStatus = RpcServerUnregisterIf( NULL, // NULL indicates that we want to unregister all interfaces NULL, // NULL indicates that we want to remove interfaces for all UUIDs previously specfied with our s_ifspec FALSE // FALSE indicates that we want to remove the interface from the registry immediatly ); - if (status) - exit(status); + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingSetAuthInfoEx() failed with status: %d.\n", rpcStatus); + exit(rpcStatus); + } } int main() { - handle_t hBinding = NULL; - Output("Hello From RPC Server!"); + wprintf(L"Hello From RPC Server!"); + handle_t hBinding = NULL; RPC_STATUS rpcStatus; RPC_WSTR pszProtSeq = (RPC_WSTR)L"ncacn_ip_tcp"; //reinterpret_cast(L"ncacn_ip_tcp"); RPC_WSTR pszTCPPort = (RPC_WSTR)L"8989"; //reinterpret_cast(L"8989"); // Create Binding information - Output("Creating Binding Information."); + wprintf(L"Creating Binding Information."); rpcStatus = RpcServerUseProtseqEp( pszProtSeq, // Use TCP/IP protocol. RPC_C_PROTSEQ_MAX_REQS_DEFAULT, // Backlog queue length for TCP/IP. @@ -51,37 +55,43 @@ int main() NULL // No Secuirty Descriptor ); - if (rpcStatus) + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingSetAuthInfoEx() failed with status: %d.\n", rpcStatus); exit(rpcStatus); + } // Registers the Example1 interface. - Output("Registering Server interface."); + wprintf(L"Registering Server interface."); rpcStatus = RpcServerRegisterIf2( Example1_v1_0_s_ifspec, // Interface to register. - NULL, // Use the MIDL generated entry-point vector. + NULL, // NULL GUID NULL, // Use the MIDL generated entry-point vector. 0, // No Flags. RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls. (unsigned)-1, // Infinite max size of incoming data blocks. NULL); // No security callback. - if (rpcStatus) + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingSetAuthInfoEx() failed with status: %d.\n", rpcStatus); exit(rpcStatus); + } // Start to listen for remote procedure // calls for all registered interfaces. // This call will not return until // RpcMgmtStopServerListening is called. - Output("Listening for client connection."); + wprintf(L"Listening for client connection."); rpcStatus = RpcServerListen( 1, // Recommended minimum number of threads. RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Recommended maximum number of threads. FALSE); // Start listening now. - if (rpcStatus) + if (rpcStatus != RPC_S_OK) { + wprintf(L"[-] RpcBindingSetAuthInfoEx() failed with status: %d.\n", rpcStatus); exit(rpcStatus); + } - Output("RPC Server stopped, executing now..."); + wprintf(L"RPC Server stopped, executing now..."); } /******************************************************/ diff --git a/RPC/CPP-RPC-Client-Server/RPC-Util/Access.cpp b/RPC/CPP-RPC-Client-Server/RPC-Util/Access.cpp index 65d98c2..d3f5a12 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Util/Access.cpp +++ b/RPC/CPP-RPC-Client-Server/RPC-Util/Access.cpp @@ -1,75 +1 @@ -#include "RPC-Util.h" -#include -#include -BOOL EnablePriv(HANDLE hToken, LPCTSTR priv) -{ - TOKEN_PRIVILEGES tp; - LUID luid; - - if (!LookupPrivilegeValue(NULL, priv, &luid)) - { - printf("Priv Lookup FALSE\n"); - return FALSE; - } - - tp.PrivilegeCount = 1; - tp.Privileges[0].Luid = luid; - tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - if (!AdjustTokenPrivileges( - hToken, - FALSE, - &tp, - sizeof(TOKEN_PRIVILEGES), - (PTOKEN_PRIVILEGES)NULL, - (PDWORD)NULL)) - { - printf("Priv Adjust FALSE\n"); - return FALSE; - } - - return TRUE; -} - -void setWindowAccess() { - DWORD error; - wprintf(L"Gettinng current process Window..."); - HWINSTA hWinSta = GetProcessWindowStation(); - if (hWinSta) { - wprintf(L"Success.\n"); - wprintf(L"Setting Security of current Proccess Window..."); - error = SetSecurityInfo(hWinSta, - SE_WINDOW_OBJECT, - DACL_SECURITY_INFORMATION, - NULL, // don't set the ownerSID - NULL, // don't set the primary GROUP - NULL, // DACL pointer, NULL=> full access to everyone - NULL // no setting SACL - ); - if (error == ERROR_SUCCESS) wprintf(L"Success.\n"); - else wprintf(L"Error: %d.\n", error); - } - else wprintf(L"Error: %d.\n", GetLastError()); -} - -void setDesktopAccess() { - DWORD error; - wprintf(L"Getting current Desktop.."); - HDESK hDesk = GetThreadDesktop(GetCurrentThreadId()); - if (hDesk) { - wprintf(L"Success\n"); - wprintf(L"Setting Security of current Desktop..."); - error = SetSecurityInfo( - hDesk, - SE_WINDOW_OBJECT, - DACL_SECURITY_INFORMATION, - NULL, // don't set the ownerSID - NULL, // don't set the primary GROUP - NULL, // DACL pointer, NULL=> full access to everyone - NULL // no setting SACL - ); - if (error == ERROR_SUCCESS) wprintf(L"Success\n"); - else wprintf(L"Error: %d\n", error); - } - else wprintf(L"Error: %d\n", GetLastError()); -} \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Util/Command.cpp b/RPC/CPP-RPC-Client-Server/RPC-Util/Command.cpp new file mode 100644 index 0000000..f121060 --- /dev/null +++ b/RPC/CPP-RPC-Client-Server/RPC-Util/Command.cpp @@ -0,0 +1,307 @@ +#include "RPC-Util.h" +#include +#include + +/* + TOKEN API + +*/ + +BOOL printTokenType(HANDLE hToken, PCSTOKEN pCSToken) { + PTOKEN_TYPE ptt = NULL; + DWORD dwSize = 0; + pCSToken->pwsTokenType = (LPWSTR)L""; + if (!GetTokenInformation(hToken, TokenType, NULL, 0, &dwSize) + && ERROR_INSUFFICIENT_BUFFER != GetLastError()) + { + return FALSE; + } + if (NULL != (ptt = (PTOKEN_TYPE)LocalAlloc(LPTR, dwSize))) + { + if (!GetTokenInformation(hToken, TokenType, ptt, dwSize, &dwSize)) + { + LocalFree((HLOCAL)ptt); + return FALSE; + } + pCSToken->TokenType = (TOKEN_TYPE)*ptt; + switch (pCSToken->TokenType) + { + case TokenImpersonation: + pCSToken->pwsTokenType = (LPWSTR)L"ImpersonationToken"; + return TRUE; + case TokenPrimary: + pCSToken->pwsTokenType = (LPWSTR)L"PrimaryToken"; + return TRUE; + default: + wprintf(L"[-] Undefined Token Type. \n"); + return FALSE; + } + + LocalFree((HLOCAL)ptt); + } + return FALSE; +} + +BOOL printTokenImpersonationLeven(HANDLE hToken, PCSTOKEN pCSToken) { + PSECURITY_IMPERSONATION_LEVEL psil = NULL; + DWORD dwSize = 0; + pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L""; + if (!GetTokenInformation(hToken, TokenImpersonationLevel, NULL, 0, &dwSize) + && ERROR_INSUFFICIENT_BUFFER != GetLastError()) + { + return FALSE; + } + if (NULL != (psil = (PSECURITY_IMPERSONATION_LEVEL)LocalAlloc(LPTR, dwSize))) + { + if (!GetTokenInformation(hToken, TokenImpersonationLevel, psil, dwSize, &dwSize)) + { + LocalFree((HLOCAL)psil); + return FALSE; + } + switch (*psil) + { + case SecurityAnonymous: + pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityAnonymous"; + return TRUE; + case SecurityIdentification: + pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityIdentification"; + return TRUE; + case SecurityImpersonation: + pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityImpersonation"; + return TRUE; + case SecurityDelegation: + pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityDelegation"; + return TRUE; + default: + wprintf(L"[-] Undefined Impersonation Level. \n"); + return FALSE; + } + LocalFree((HLOCAL)psil); + } + return FALSE; +} + +BOOL printTokenUserSid(HANDLE hToken, PCSTOKEN pCSToken) +{ + PTOKEN_USER ptu = NULL; + DWORD dwSize = 0; + pCSToken->pwsUSERSID = (LPWSTR)L""; + if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize) + && ERROR_INSUFFICIENT_BUFFER != GetLastError()) + { + return FALSE; + } + if (NULL != (ptu = (PTOKEN_USER)LocalAlloc(LPTR, dwSize))) + { + LPTSTR StringSid = NULL; + if (!GetTokenInformation(hToken, TokenUser, ptu, dwSize, &dwSize)) + { + LocalFree((HLOCAL)ptu); + return FALSE; + } + if (ConvertSidToStringSid(ptu->User.Sid, &StringSid)) + { + pCSToken->pwsUSERSID = StringSid; + LocalFree((HLOCAL)StringSid); + LocalFree((HLOCAL)ptu); + return TRUE; + } + else { + wprintf(L"[-] Failed to resolve SID to string.\n"); + return FALSE; + } + LocalFree((HLOCAL)ptu); + } + return FALSE; +} + +void ExtractTokenInformation(HANDLE hToken) { + BOOL result; + PCSTOKEN pCSToken = new CSTOKEN; + // Get UserSID + result = printTokenUserSid(hToken, pCSToken); + if (!result) wprintf(L" [-]... failed to get Token SID\n"); + else wprintf(L" [+] UserSID: %s\n", pCSToken->pwsUSERSID); + // GET TokenType + result = printTokenType(hToken, pCSToken); + if (!result) wprintf(L" [-]... failed to get Token Type\n"); + else wprintf(L" [+] TokenType: %s\n", pCSToken->pwsTokenType); + if (pCSToken->TokenType == TokenImpersonation) { + // GET TokenImpersonationLevel + result = printTokenImpersonationLeven(hToken, pCSToken); + if (!result) wprintf(L" [-]... failed to get Token Type\n"); + else wprintf(L" [+] ImpersonationLevel: %s\n", pCSToken->pwsTokenImpersonationLevel); + } + +} + +BOOL EnablePriv(HANDLE hToken, LPCTSTR priv) +{ + TOKEN_PRIVILEGES tp; + LUID luid; + + if (!LookupPrivilegeValue(NULL, priv, &luid)) + { + printf("Priv Lookup FALSE\n"); + return FALSE; + } + + tp.PrivilegeCount = 1; + tp.Privileges[0].Luid = luid; + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + if (!AdjustTokenPrivileges( + hToken, + FALSE, + &tp, + sizeof(TOKEN_PRIVILEGES), + (PTOKEN_PRIVILEGES)NULL, + (PDWORD)NULL)) + { + printf("Priv Adjust FALSE\n"); + return FALSE; + } + + return TRUE; +} + +// TOKEN API -- END +// + +/* + ACCESS API + +*/ + +void setWindowAccess() { + DWORD error; + wprintf(L"Gettinng current process Window..."); + HWINSTA hWinSta = GetProcessWindowStation(); + if (hWinSta) { + wprintf(L"Success.\n"); + wprintf(L"Setting Security of current Proccess Window..."); + error = SetSecurityInfo(hWinSta, + SE_WINDOW_OBJECT, + DACL_SECURITY_INFORMATION, + NULL, // don't set the ownerSID + NULL, // don't set the primary GROUP + NULL, // DACL pointer, NULL=> full access to everyone + NULL // no setting SACL + ); + if (error == ERROR_SUCCESS) wprintf(L"Success.\n"); + else wprintf(L"Error: %d.\n", error); + } + else wprintf(L"Error: %d.\n", GetLastError()); +} + +void setDesktopAccess() { + DWORD error; + wprintf(L"Getting current Desktop.."); + HDESK hDesk = GetThreadDesktop(GetCurrentThreadId()); + if (hDesk) { + wprintf(L"Success\n"); + wprintf(L"Setting Security of current Desktop..."); + error = SetSecurityInfo( + hDesk, + SE_WINDOW_OBJECT, + DACL_SECURITY_INFORMATION, + NULL, // don't set the ownerSID + NULL, // don't set the primary GROUP + NULL, // DACL pointer, NULL=> full access to everyone + NULL // no setting SACL + ); + if (error == ERROR_SUCCESS) wprintf(L"Success\n"); + else wprintf(L"Error: %d\n", error); + } + else wprintf(L"Error: %d\n", GetLastError()); +} + +// ACCESS API -- END +// + +/* + COMMAND API + +*/ + +BOOL execCommand(HANDLE hDuppedToken, LPCWSTR command) { + // -- Execute Process + BOOL bSuccess; + PROCESS_INFORMATION pi; + STARTUPINFO si; + //SECURITY_ATTRIBUTES sa; + ZeroMemory(&si, sizeof(STARTUPINFO)); + ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); + //memset(&pi, 0x00, sizeof(PROCESS_INFORMATION)); + si.cb = sizeof(STARTUPINFO); + wprintf(L"Trying to launch '%s' with CreateProcessWithTokenW... ", command); + bSuccess = CreateProcessWithTokenW( + hDuppedToken, + 0, + command, + NULL, + CREATE_NEW_CONSOLE, + NULL, + NULL, + &si, + &pi + ); + if (!bSuccess) { + wprintf(L"failed (Error: %d).\n", GetLastError()); + } + else wprintf(L"Success.\n"); + return bSuccess; +} + +BOOL execImpersonatedWindowCommand(HANDLE hBinding, LPCWSTR command) { + BOOL bSuccess; + HANDLE hClientToken, hDuppedToken; + wprintf(L"### Exec Command as Impersonated User ###\n\n"); + // -- Set Window & Desktop access rights + // This is a dummy implementation and should not be used in production + setWindowAccess(); + setDesktopAccess(); + + // -- Get thread token + wprintf(L"Trying to get current thread token..."); + bSuccess = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &hClientToken); + if (!bSuccess) { + wprintf(L"Failed (Error: %d).\n", GetLastError()); + } + else wprintf(L"Succeded.\n"); + ExtractTokenInformation(hClientToken); + + // -- Duplicate Token + wprintf(L"Trying to duplicate impersonated token..."); + bSuccess = DuplicateTokenEx(hClientToken, + TOKEN_ALL_ACCESS, + NULL, + SecurityImpersonation, + TokenPrimary, + &hDuppedToken); + if (!bSuccess) { + wprintf(L"Failed (Error: %d).\n", GetLastError()); + } + else wprintf(L"Success!\n"); + + // -- Revert back to original thread identity + wprintf(L"Reverting back to self..."); + RPC_STATUS rpcStatus = RpcRevertToSelfEx(hBinding); + if (rpcStatus != RPC_S_OK) + { + wprintf(L"Failed to revert back from RPC client impersonation to server identity. Error 0x%x.\n", rpcStatus); + //exit(rpcStatus); + } + else printf("Success.\n"); + + // -- Exec command + bSuccess = execCommand(hDuppedToken, command); + + // -- Close Handles + CloseHandle(hDuppedToken); + CloseHandle(hClientToken); + wprintf(L"\n\n### DONE ###\n"); + return bSuccess; +} + +// COMMAND API -- END +// \ No newline at end of file diff --git a/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj b/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj index 8a81655..665d7c1 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj +++ b/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj @@ -142,8 +142,7 @@ - - + diff --git a/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj.filters b/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj.filters index 427e86f..5764eee 100644 --- a/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj.filters +++ b/RPC/CPP-RPC-Client-Server/RPC-Util/RPC-Util.vcxproj.filters @@ -20,10 +20,7 @@ - - Source Files - - + Source Files diff --git a/RPC/CPP-RPC-Client-Server/RPC-Util/Token.cpp b/RPC/CPP-RPC-Client-Server/RPC-Util/Token.cpp deleted file mode 100644 index fc35aaf..0000000 --- a/RPC/CPP-RPC-Client-Server/RPC-Util/Token.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "RPC-Util.h" - -BOOL printTokenType(HANDLE hToken, PCSTOKEN pCSToken) { - PTOKEN_TYPE ptt = NULL; - DWORD dwSize = 0; - pCSToken->pwsTokenType = (LPWSTR)L""; - if (!GetTokenInformation(hToken, TokenType, NULL, 0, &dwSize) - && ERROR_INSUFFICIENT_BUFFER != GetLastError()) - { - return FALSE; - } - if (NULL != (ptt = (PTOKEN_TYPE)LocalAlloc(LPTR, dwSize))) - { - if (!GetTokenInformation(hToken, TokenType, ptt, dwSize, &dwSize)) - { - LocalFree((HLOCAL)ptt); - return FALSE; - } - pCSToken->TokenType = (TOKEN_TYPE)*ptt; - switch (pCSToken->TokenType) - { - case TokenImpersonation: - pCSToken->pwsTokenType = (LPWSTR)L"ImpersonationToken"; - return TRUE; - case TokenPrimary: - pCSToken->pwsTokenType = (LPWSTR)L"PrimaryToken"; - return TRUE; - default: - wprintf(L"[-] Undefined Token Type. \n"); - return FALSE; - } - - LocalFree((HLOCAL)ptt); - } - return FALSE; -} - -BOOL printTokenImpersonationLeven(HANDLE hToken, PCSTOKEN pCSToken) { - PSECURITY_IMPERSONATION_LEVEL psil = NULL; - DWORD dwSize = 0; - pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L""; - if (!GetTokenInformation(hToken, TokenImpersonationLevel, NULL, 0, &dwSize) - && ERROR_INSUFFICIENT_BUFFER != GetLastError()) - { - return FALSE; - } - if (NULL != (psil = (PSECURITY_IMPERSONATION_LEVEL)LocalAlloc(LPTR, dwSize))) - { - if (!GetTokenInformation(hToken, TokenImpersonationLevel, psil, dwSize, &dwSize)) - { - LocalFree((HLOCAL)psil); - return FALSE; - } - switch (*psil) - { - case SecurityAnonymous: - pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityAnonymous"; - return TRUE; - case SecurityIdentification: - pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityIdentification"; - return TRUE; - case SecurityImpersonation: - pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityImpersonation"; - return TRUE; - case SecurityDelegation: - pCSToken->pwsTokenImpersonationLevel = (LPWSTR)L"SecurityDelegation"; - return TRUE; - default: - wprintf(L"[-] Undefined Impersonation Level. \n"); - return FALSE; - } - LocalFree((HLOCAL)psil); - } - return FALSE; -} - -BOOL printTokenUserSid(HANDLE hToken, PCSTOKEN pCSToken) -{ - PTOKEN_USER ptu = NULL; - DWORD dwSize = 0; - pCSToken->pwsUSERSID = (LPWSTR)L""; - if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize) - && ERROR_INSUFFICIENT_BUFFER != GetLastError()) - { - return FALSE; - } - if (NULL != (ptu = (PTOKEN_USER)LocalAlloc(LPTR, dwSize))) - { - LPTSTR StringSid = NULL; - if (!GetTokenInformation(hToken, TokenUser, ptu, dwSize, &dwSize)) - { - LocalFree((HLOCAL)ptu); - return FALSE; - } - if (ConvertSidToStringSid(ptu->User.Sid, &StringSid)) - { - pCSToken->pwsUSERSID = StringSid; - LocalFree((HLOCAL)StringSid); - LocalFree((HLOCAL)ptu); - return TRUE; - } - else { - wprintf(L"[-] Failed to resolve SID to string.\n"); - return FALSE; - } - LocalFree((HLOCAL)ptu); - } - return FALSE; -} - - -void ExtractTokenInformation(HANDLE hToken) { - BOOL result; - PCSTOKEN pCSToken = new CSTOKEN; - // Get UserSID - result = printTokenUserSid(hToken, pCSToken); - if (!result) wprintf(L" [-]... failed to get Token SID\n"); - else wprintf(L" [+] UserSID: %s\n", pCSToken->pwsUSERSID); - // GET TokenType - result = printTokenType(hToken, pCSToken); - if (!result) wprintf(L" [-]... failed to get Token Type\n"); - else wprintf(L" [+] TokenType: %s\n", pCSToken->pwsTokenType); - if (pCSToken->TokenType == TokenImpersonation) { - // GET TokenImpersonationLevel - result = printTokenImpersonationLeven(hToken, pCSToken); - if (!result) wprintf(L" [-]... failed to get Token Type\n"); - else wprintf(L" [+] ImpersonationLevel: %s\n", pCSToken->pwsTokenImpersonationLevel); - } - -} \ No newline at end of file