How to Resolve ERROR_NOACCESS (0x3E6) When Injecting Assembly Code into a PE File Using CreateThread

I encountered an issue when injecting my assembly program asm.txt into a portable executable file to run a keylogger using CreateThread. CreateThread was failing with the error code 0x3E6 (ERROR_NOACCESS). I've been suspecting it could be stack issues, memory protection issue, or me passing the wrong parameters to CreateThread, but I haven't been able to pinpoint the exact cause. Where is the error in my assembly code? How can I resolve the ERROR_NOACCESS error and successfully create the thread to run my keylogger in the injected PE file?
attachment 0
attachment 1
attachment 2
5 Replies
Renuel Roberts
Renuel Roberts2mo ago
@Marvee Amasi The ERROR_NOACCESS (0x3E6) error in your CreateThread call is likely due to memory access or parameter issues. Ensure the memory where your injected code resides has proper permissions using VirtualProtect (PAGE_EXECUTE_READWRITE). Also, verify that the stack is 16-byte aligned before calling CreateThread, and re-check that the parameters you're passing are correct. If you're injecting code into another process, make sure it allows execution of injected threads, and consider security features like DEP and ASLR that may need to be addressed.
Marvee Amasi
Marvee Amasi2mo ago
I guess I am even complicating things the more . I need to calm down, and take my time to verify , altho I am under pressure doing this task
Renuel Roberts
Renuel Roberts2mo ago
Yea coding might be more tasking at times and even cause severe headaches, that's y u never 4get ur coffee ☕
Marvee Amasi
Marvee Amasi2mo ago
So after further debugging, I found that I hadn't correctly initialized the stack. Once I added the following initialization to the code, the keylogger started working correctly:
mov qword[rsp+20h], 0
lea rbx, [ThreadId]
mov qword[rsp+28h], rbx
lea r9, [Par]
lea r8, [KL]
xor rdx, rdx
lea rcx, [SECURITY_ATTRIBUTES_]
call rax
mov qword[rsp+20h], 0
lea rbx, [ThreadId]
mov qword[rsp+28h], rbx
lea r9, [Par]
lea r8, [KL]
xor rdx, rdx
lea rcx, [SECURITY_ATTRIBUTES_]
call rax
With this fix, the keylogger now works perfectly. Thanks for the help @Renuel Roberts

Did you find this page helpful?