尝试在Windows 8中写入.myText段时NASM中的访问冲突错误

时间:2014-08-24 16:35:23

标签: windows nasm shellcode

当我尝试使用NASM弹出我的Windows 32位系统中的shellcode程序时,我得到错误。

section .myText progbits alloc exec write align=16
    global  _WinMain@16
_WinMain@16:
    xor eax, eax
    xor ebx, ebx
    xor ecx, ecx
    xor edx, edx

    jmp short GetLibrary
LibraryReturn:
    pop ecx
    mov BYTE [ecx+10], dl
    mov ebx, 0x76d62fe4
    push ecx
    call ebx

    jmp short FunctionName

FunctionReturn:
    pop ecx
    xor edx, edx
    mov BYTE [ecx+11], dl
    push ecx        
    push eax        ; handle to the module user32.dll
    mov ebx, 0x76d616b9    ; GetProcAddress
    call ebx
        ; now eax has the procAddress of 'MessageBoxA'
    jmp short Message

MessageReturn:    

    pop ecx
    xor edx, edx
    mov BYTE [ecx+16] , dl
    push edx
    push ecx
    push ecx 
    push edx
    call eax        ;MessageBoxA(windowhandle,msg,title,type)

ender:
    xor edx,edx
    push eax            
    mov eax, 0x76d63176        ;exitprocess(exitcode);
    call eax

Message:
    call MessageReturn
    db 'hello am melvin!'

FunctionName:
    call FunctionReturn
    db 'MessageBoxAN'    

GetLibrary:
    call LibraryReturn
    db 'user32.dllN'

我编译了

C:\SHELL>nasm -f win32 -o msgbox.o msgbox.asm

C:\SHELL>ld -o msgbox.exe msgbox.o

它没有显示任何错误,但是当我运行它时, "我得到Windows调试窗口 - 并显示一条消息:' messagebox.exe'已停止工作' "

我的代码中有什么问题。如何在没有错误的情况下在Windows中执行NASM代码。?

现在我禁用了ASLR。我发现这是问题所在 Sample.exe中0x00404003处的未处理异常:0xC0000005:Access 违规写入位置0x00404019。 00404003 C6 41 05 00 mov byte ptr [ecx+10],0
那怎么能摆脱AV。我编辑了bcdedit.exe。但是没有用

在我尝试这个时,在Linux中

section .myText progbits alloc exec write align=16

它工作但是在Windows中,没有。

1 个答案:

答案 0 :(得分:0)

最后我自己找到答案.....:yeye :: yeye :: yeye ::

我们只能改变,

“部分”

section .myText progbits alloc exec write align=16

使用“elf32”而不是“win32”

进行编译
nasm -f elf32 -o MessageBox.o MessageBox.asm
gcc -o MessageBox.exe MessageBox.o

多数民众赞成,它会正常工作....:blackhat: 并且不要忘记禁用ASLR

注意:elf允许您在SECTION指令行上指定其他信息,以控制您声明的部分的类型和属性。