【问题标题】:Manipulating Strings in x86 assembly code , NASM, Linux在 x86 汇编代码、NASM、Linux 中操作字符串
【发布时间】: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: 错误:操作码和操作数的组合无效

标签: x86 intel nasm


【解决方案1】:

自从我使用 ASM 以来已经有一段时间了,而且我对 NASM 并不是很熟悉,所以我在这里可能是错的。但你可能想试一试。 . .

问题是你不能像那样进行内存到内存的移动。

试试这个:

mov bx,[eax+7]
mov [eax],bx
mov byte [eax+7], 0

将来,如果您让我们知道您遇到的是汇编错误而不是错误的输出,将会很有帮助。

【讨论】:

  • 它仍然显示 hitesh@hitesh-Studio-XPS-1340:~$ nasm -f elf sample.s sample.s:12: 错误:操作码和操作数的组合无效
猜你喜欢
  • 1970-01-01
  • 2017-03-31
  • 2022-11-24
  • 2016-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多