【发布时间】:2017-06-22 02:33:57
【问题描述】:
我正在尝试编写一个 64 位 shellcode 来读取一个名为“/proc/flag”的文件。但是,我在编译程序集时遇到了一些随机错误,不知道为什么会发生。
这是我的汇编文件readflag.S:
.intel_syntax noprefix
.global _start
.type _start, @function
_start:
mov dword [rsp], '/pro' /* build filename on stack */
mov dword [rsp+4], 'c/fl'
push 'ag'
pop rcx
mov [rsp+8], ecx
lea rdi, [rsp] /* rdi now points to filename '/proc/flag' */
xor rsi, rsi /* rsi contains O_RDONLY, the mode with which we'll open the file */
xor rax, rax
inc rax
inc rax /* syscall open = 2 */
syscall
mov rbx, rax /* filehandle of opened file */
lea rsi, [rsp] /* rsi is the buffer to which we'll read the file */
mov rdi, rbx /* rbx was the filehandle */
push byte 0x7f /* read 127 bytes. if we stay below this value, the generated opcode will not contain null bytes */
pop rdx
xor rax, rax /* syscall read = 0 */
syscall
lea rsi, [rsp] /* the contents of the file were on the stack */
xor rdi, rdi
inc rdi /* filehandle; stdout! */
mov rdx, rax /* sys_read() returns number of bytes read in rax, so we move it to rdx */
xor rax, rax
inc rax
syscall /* syscall write = 1 */
push byte 60 /* some bytes left... */
pop rax /* exit cleanly */
syscall
这些是我在编译程序集时遇到的错误:
readflag.S: Assembler messages:
readflag.S:7: Error: junk `pro10mov dword [rsp+4]' after expression
readflag.S:21: Error: junk `0x7f' after expression
readflag.S:33: Error: junk `60' after expression
objcopy: 'readflag.o': No such file
我认为push byte 60 被认为是英特尔语法中的有效指令。我不确定错误来自哪里。将不胜感激。
【问题讨论】:
-
您正在尝试使用 GNU 汇编器不支持的 NASM 语法。 Intel 语法是 MASM 使用的语法。
-
@AjayBrahmakshatriya 问题是它不能使用 NASM 语法。
-
我认为 X86_64 不允许推送单个字节的真正问题。您只需要推送一个 qword 和 qword。
-
@RossRidge 我的错!名字不太好。
-
@AjayBrahmakshatriya NASM 与 MASM 语法相似,但有区别。 MASM 使用
DWORD PTR,而 NASM 使用DWORD。 MASM 使用7fh形式的十六进制数字,其中 NASM 支持 MASM 和 C 样式 (0x7f) 十六进制数字。
标签: assembly x86 gnu-assembler intel-syntax