Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@rvrsh3ll
Forked fromklezVirus/EtwStartWebClient.cs
CreatedJanuary 13, 2023 15:18
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist

    Select an option

    Save rvrsh3ll/fa6825664378e9d2226c61b3dd628e37 to your computer and use it in GitHub Desktop.
    A PoC in C# to enable WebClient Programmatically
    usingSystem.Runtime.InteropServices;
    usingSystem;
    /*
    * Simple C# PoC to enable WebClient Service Programmatically
    * Based on the C++ version from @tirannido (James Forshaw)
    * Twitter: https://twitter.com/tiraniddo
    * URL: https://www.tiraniddo.dev/2015/03/starting-webclient-service.html
    *
    * Compile with:
    * - 32-bit: C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe .\EtwStartWebClient.cs /unsafe
    * - 64-bit: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe .\EtwStartWebClient.cs /unsafe
    */
    namespaceEtwStartWebClient
    {
    classEtwStartWebClient
    {
    staticvoidMain(string[]args)
    {
    if(StartWebClientService()){
    Console.WriteLine("[+] WebClient Service started successfully");
    }
    else{
    Console.WriteLine("[-] Failed to start WebClient Service");
    }
    }
    staticboolStartWebClientService()
    {
    Guid_MS_Windows_WebClntLookupServiceTrigger_Provider=newGuid(0x22B6D684,0xFA63,0x4578,0x87,0xC9,0xEF,0xFC,0xBE,0x66,0x43,0xC7);
    Win32.EVENT_DESCRIPTOReventDescriptor=newWin32.EVENT_DESCRIPTOR();
    ulongregHandle=0;
    Win32.WINERRORwinError=Win32.EventRegister(
    ref_MS_Windows_WebClntLookupServiceTrigger_Provider,
    IntPtr.Zero,
    IntPtr.Zero,
    refregHandle
    );
    if(winError==((ulong)Win32.WINERROR.ERROR_SUCCESS))
    {
    unsafe{
    if(Win32.EventWrite(
    regHandle,
    refeventDescriptor,
    0,
    null
    )==Win32.WINERROR.ERROR_SUCCESS){
    Win32.EventUnregister(regHandle);
    returntrue;
    }
    }
    }
    returnfalse;
    }
    }
    classWin32
    {
    publicenumWINERROR:ulong{
    ERROR_SUCCESS=0x0,
    ERROR_INVALID_PARAMETER=0x57,
    ERROR_INVALID_HANDLE=0x6,
    ERROR_ARITHMETIC_OVERFLOW=0x216,
    ERROR_MORE_DATA=0xEA,
    ERROR_NOT_ENOUGH_MEMORY=0x8,
    STATUS_LOG_FILE_FULL=0xC0000188,
    }
    [StructLayout(LayoutKind.Explicit,Size=16)]
    publicclassEVENT_DESCRIPTOR
    {
    [FieldOffset(0)]ushortId=1;
    [FieldOffset(2)]byteVersion=0;
    [FieldOffset(3)]byteChannel=0;
    [FieldOffset(4)]byteLevel=4;
    [FieldOffset(5)]byteOpcode=0;
    [FieldOffset(6)]ushortTask=0;
    [FieldOffset(8)]longKeyword=0;
    }
    [StructLayout(LayoutKind.Explicit,Size=16)]
    publicstructEVENT_DATA_DESCRIPTOR
    {
    [FieldOffset(0)]
    internalUInt64DataPointer;
    [FieldOffset(8)]
    internaluintSize;
    [FieldOffset(12)]
    internalintReserved;
    }
    [DllImport("Advapi32.dll",SetLastError=true)]
    publicstaticexternWINERROREventRegister(refGuidguid,[Optional]IntPtrEnableCallback,[Optional]IntPtrCallbackContext,[In][Out]refulongRegHandle);
    [DllImport("Advapi32.dll",SetLastError=true)]
    publicstaticexternunsafeWINERROREventWrite(ulongRegHandle,refEVENT_DESCRIPTOREventDescriptor,uintUserDataCount,EVENT_DATA_DESCRIPTOR*UserData);
    [DllImport("Advapi32.dll",SetLastError=true)]
    publicstaticexternWINERROREventUnregister(ulongRegHandle);
    }
    }
    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp