정보

gdb 자동화

Oth 2017. 2. 19. 23:13
#!/usr/bin/python

from subprocess import Popen , PIPE from time import sleep # shellcode shellcode = "\x41" * 1000 + "\n" # opens gdb with parameter executable # you can also manage stdout and stderr here proc = Popen( ['gdb' , 'executable'] , bufsize=1 ,stdin=PIPE ) # sample breakpoint # notice the new line after each command proc.stdin.write('b *DEADBEEF\n') # half a second of sleep after each command sleep(0.5) # r or run to start debugging the program with GDB proc.stdin.write('r\n') sleep(0.5) # any other commands go here # this is a loop, will get every command and pass it to GDB # "leave" == quit GDB and terminate process # "dump" == paste shellcode while True: mycommand = raw_input() if (mycommand == "leave"): # quit gdb proc.stdin.write("quit\n") break # paste shellcode if (mycommand == "dump"): proc.stdin.write(shellcode) # more custom commands go here # not a custom command? send it as-is else: mycommand = mycommand + '\n' proc.stdin.write(mycommand) sleep(0.5) # close our pipe proc.stdin.close()


위의 코드에서 write 하는 값만 적절하게 넣어주면 gdb를 이용한 자동 디버깅이 가능하다. 


출처 : https://parsiya.net/blog/2014-05-25-pasting-shellcode-in-gdb-using-python/