我是汇编语言的新手,我已经在Linux上进行了大约2周的编码,并且能够在Linux下在终端上输出某些信息。但是,今天当我开始在Windows下进行编码时,遇到了一个问题,我无法修改作为参数传递给函数的字符串中的字节。我在OllyDbg中调试了程序,它告诉我在写入[地址]时存在访问冲突-使用Shift F7 / F8 / F9将异常传递给程序。由于程序中没有异常处理程序,因此无法将异常传递给程序。修改传递给过程的字符串中的字符是否非法?我已经在下面发布了代码。
section .bss
var resb 6
section .text
global _start
_start:
xor eax, eax ; empty all registers
xor ebx, ebx
xor ecx, ecx
xor edx, edx
jmp short get_library
get_lib_addr: ; get_lib_addr(char *name)
mov ecx, [esp+8] ; get the first parameter
xor edx, edx ; zero out register
mov byte [ecx+6], dl ; add null terminating character to string
jmp short fin ; go to end
get_library:
xor ecx, ecx
mov ebx, var ; start address of var
jmp start_loop ; start looping
start_loop:
cmp ecx, 5
jge end_loop
mov byte [ebx+ecx], 'h'
inc ecx
jmp start_loop
end_loop:
push dword var ; at this point - var = "hhhhh"
call get_lib_addr ; call get_lib_addr("hhhhh")
fin:
xor eax, eax
mov ebx, 0x750b4b80 ; ExitProcess
push eax ; eax = 0
call ebx ; ExitProcess(0)
以及OllyDbg中调试的屏幕截图。
第二种情况
来自Vivid Machines Shellcoding for Linux & Windows的部分代码复制如下。当我尝试使用此语法传递参数时(假设正在发生这种情况),在尝试编辑字符串并添加空终止符代替N
时遇到访问冲突。我肯定会传递字符串,并且ecx
将获得正确的字符串。任何原因都不起作用?
LibraryReturn:
pop ecx ;get the library string
mov [ecx + 10], dl ;insert NULL - ***Access violation here***
;the N at the end of each string signifies the location of the NULL
;character that needs to be inserted
GetLibrary:
call LibraryReturn
db 'user32.dllN'
第二种情况下调试信息的屏幕快照,显示N确实是正在编辑的值。