在x86汇编代码、NASM和Linux中操作字符串
我一直在尝试操作.s文件中的字符串 我希望将包含“/bin/bash”的变量“pa”转换为“/bin/sh”,然后调用执行“/bin/sh”的系统 我已经编写了一个打印机制,以确保“pa”具有“/bin/bash” 我试过这么做在x86汇编代码、NASM和Linux中操作字符串,x86,intel,nasm,X86,Intel,Nasm,我一直在尝试操作.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]; /
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的新手
请帮帮我
下面是完整的代码片段
`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
'
我已经有一段时间没有和ASM合作了,我对NASM不是很熟悉,所以我可能错了。但你可能想尝试一下 问题是你不能这样做一个内存对内存的移动 试试这个:
mov bx,[eax+7]
mov [eax],bx
mov byte [eax+7], 0
将来,如果您让我们知道您得到的是汇编程序错误而不是不正确的输出,这将非常有用。我不熟悉Linux上的ASM,但我注意到您将
palen
作为长度传递,即使您传递的命令短了两个字符。您是否应该通过palen-2
?这只是为了打印它。如果你能帮助我在mov eax,pa指令后寻址eax寄存器的方式,我可以试着把它弄对,因为据我所知,我在这方面犯了一个错误addressinghitesh@hitesh-Studio-XPS-1340:~$nasm-f elf示例。s示例。s:12:错误:操作码和操作数的组合无效示例。s:13:错误:操作码和操作数的组合无效示例。s:14:错误:操作码和操作数的组合无效hitesh@hitesh-Studio-XPS-1340:~$nasm-f elfsample.s sample.s:12:错误:操作码和操作数的组合无效