pushl %ebp - popl %ebp - ret (Returning seg fault)
- From: "skylazart" <spamtrap@xxxxxxxxxx>
- Date: 24 Mar 2006 18:54:42 -0800
Hi All,
I'm playing with sockets in assembly (using at&t sintax) for linux
systems.
I have created a simple echo server and Im wondering why the
application is finishing with segfault.
There is no problem to finish the application using exit (0); I.E. But
I want to get base pointer from stack and ret to bash$.
-- echo_server.s --
# Simple echo server
..include "defines.h"
..include "socket.h"
BIND_PORT = 0xfeff ## Port = 65534
..data
SOCK:
.long 0x0
LEN:
.long 0x10
SHELL:
.string "/bin/sh"
FD:
.long 0x0
..text
..globl _start
_start:
pushl %ebp
movl %esp, %ebp
subl $1060,%esp
## socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
movl $SYS_socketcall,%eax
movl $SYS_socketcall_socket,%ebx
movl $AF_INET,(%esp)
movl $SOCK_STREAM,0x4(%esp)
movl $IPPROTO_TCP,0x8(%esp)
movl %esp,%ecx
int $0x80
## save sockfd
movl %eax,SOCK
xorl %edx,%edx
## bind(%eax, %esp+0xc, 0x10);
movw $AF_INET,0xc(%esp)
movw $BIND_PORT,0xe(%esp)
movl %edx,0x10(%esp)
movl %eax,(%esp)
leal 0xc(%esp),%ebx
movl %ebx,0x4(%esp)
movl $0x10,0x8(%esp)
movl $SYS_socketcall,%eax
movl $SYS_socketcall_bind,%ebx
int $0x80
movl SOCK,%eax
## listen(%eax, 0x1);
movl %eax,(%esp)
movl $0x1,0x4(%esp)
movl $SYS_socketcall,%eax
movl $SYS_socketcall_listen,%ebx
int $0x80
movl SOCK,%eax
## accept(%eax, %esp+0xc, $LEN);
movl %eax,(%esp)
leal 0xc(%esp),%ebx
movl %ebx,0x4(%esp)
movl $LEN,0x8(%esp)
movl $SYS_socketcall,%eax
movl $SYS_socketcall_accept,%ebx
int $0x80
## Salvando o fd
movl %eax, FD
## Echo Server
echo_server:
leal -1024(%ebp), %ecx
movl $1024, %edx
movl $SYS_read, %eax
movl FD, %ebx
int $0x80
cmp $0, %eax
je close
# Echo'ng
movl %eax, %edx
movl $SYS_write, %eax
int $0x80
jmp echo_server
## Fechando o FD
close:
movl $SYS_close, %eax
movl FD, %ebx
int $0x80
## Trying to exit
addl $1060, %esp
popl %ebp
ret # <--- Here is the problem (Its crashing)
## _exit(0)
movl $SYS_exit,%eax
xorl %ebx, %ebx
int $0x80
ret
-- EOF --
Someone can tell me whats im doing wrong?
Thankz a lot and sorry my english.
.
- Follow-Ups:
- Re: pushl %ebp - popl %ebp - ret (Returning seg fault)
- From: Frank Kotler
- Re: pushl %ebp - popl %ebp - ret (Returning seg fault)
- Prev by Date: Re: LSS and MOV SS
- Next by Date: Re: pushl %ebp - popl %ebp - ret (Returning seg fault)
- Previous by thread: Recommendations for Self-Instruction?
- Next by thread: Re: pushl %ebp - popl %ebp - ret (Returning seg fault)
- Index(es):