Hi all,
the problem is that my program produces a segmentation fault but I don't know why, but the strange thing is that when I use gdb and I set a breakpoint to a specific line of the code, the program terminates correctly!
Here's the code:
global main
main:
lea esi,[sh]
xor eax,eax ;syscall execve("/bin/sh")
mov byte[esi+7],$0
mov [esi+8],esi
mov [esi+0xc],eax
lea edx,[esi+0xc]
lea ecx,[esi+0x8]
mov ebx,esi
mov al,0xb
;1° breakpoint (If i set a break here the program terminates normally)
int 0x80
xor eax, eax ;syscall exit(0)
xor ebx, ebx
inc eax
int 0x80
.data
sh db '/bin/sh';
As you can see, this code issues an execve("/bin/sh"..) syscall which spawns a shell, but it produces a segmentation fault at run-time.
Debugging with gdb I got this error, that looks like eip is overwritten by something (eip points to 0x40000bb0 but it shouldn't!!):
Program received signal SIGTRAP, Trace/breakpoint trap.
0x40000bb0 in ?? ()
But when I set a breakpoint in the 1° point the program terminates correctly!?!?
(gdb) run
Breakpoint 1, main () at a.asm:16
16 int 0x80
(gdb) continue
Continuing.
sh-2.05b$ exit ;<--------execve("/bin/sh"...)
exit
Program exited normally.
(gdb)
How come if I set the breakpoint it terminates fine?
Is there something wrong in the code?
Any help is really appreciated!!
the problem is that my program produces a segmentation fault but I don't know why, but the strange thing is that when I use gdb and I set a breakpoint to a specific line of the code, the program terminates correctly!
Here's the code:
global main
main:
lea esi,[sh]
xor eax,eax ;syscall execve("/bin/sh")
mov byte[esi+7],$0
mov [esi+8],esi
mov [esi+0xc],eax
lea edx,[esi+0xc]
lea ecx,[esi+0x8]
mov ebx,esi
mov al,0xb
;1° breakpoint (If i set a break here the program terminates normally)
int 0x80
xor eax, eax ;syscall exit(0)
xor ebx, ebx
inc eax
int 0x80
.data
sh db '/bin/sh';
As you can see, this code issues an execve("/bin/sh"..) syscall which spawns a shell, but it produces a segmentation fault at run-time.
Debugging with gdb I got this error, that looks like eip is overwritten by something (eip points to 0x40000bb0 but it shouldn't!!):
Program received signal SIGTRAP, Trace/breakpoint trap.
0x40000bb0 in ?? ()
But when I set a breakpoint in the 1° point the program terminates correctly!?!?
(gdb) run
Breakpoint 1, main () at a.asm:16
16 int 0x80
(gdb) continue
Continuing.
sh-2.05b$ exit ;<--------execve("/bin/sh"...)
exit
Program exited normally.
(gdb)
How come if I set the breakpoint it terminates fine?
Is there something wrong in the code?
Any help is really appreciated!!