【发布时间】:2011-09-26 19:09:01
【问题描述】:
我一直在尝试操作 .s 文件中的字符串 我希望将包含“/bin/bash”的变量“pa”转换为“/bin/sh”,然后我想调用执行“/bin/sh”的系统 我写了一个打印机制来确保“pa”有“/bin/bash”
我已经尝试过这样做
mov eax,pa
mov [eax+5],[eax+7]; /bin/bash becomes /bin/sash\0
mov [eax+6],[eax+8]; /bin/sash becomes /bin/shsh\0
mov [eax+7],[eax+9]; /bin/shsh becomes /bin/sh\0
但我想这不是它的工作方式 我是 NASM 的新手
请帮帮我
整个代码sn-p在下面
`section .data
%defstr path %!SHELL
pa db path,10
palen equ $-pa
section .text
global _start
_start:
mov eax,pa
mov [eax+5],[eax+7] ; /bin/bash becomes /bin/sash\0
mov [eax+6],[eax+8] ; /bin/sash becomes /bin/shsh\0
mov [eax+7],[eax+9] ; /bin/shsh becomes /bin/sh\0
mov eax,4 ; The system call for write (sys_write)
mov ebx,1 ; File descriptor 1 - standard output
mov ecx,pa
mov edx,palen
int 80h
mov eax,1 ; The system call for exit (sys_exit)
mov ebx,0 ; Exit with return code of 0 (no error)
int 80h
'
【问题讨论】:
-
我不熟悉 Linux 上的 ASM,但我注意到您将
palen作为长度传递,即使您传递的命令短了两个字符。你应该改为传递palen - 2吗? -
那只是为了打印它。如果你能帮助我在 mov eax,pa 指令之后对 eax 寄存器寻址的方式,我可以尝试把它弄好,因为据我所知,我在寻址方面犯了一个错误
-
hitesh@hitesh-Studio-XPS-1340:~$ nasm -f elf sample.s sample.s:12: 错误:操作码和操作数组合无效 sample.s:13: 错误:无效操作码和操作数的组合 sample.s:14: 错误:操作码和操作数的组合无效