티스토리 뷰

정보

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/

'정보' 카테고리의 다른 글

Ubuntu install pip  (0) 2017.04.20
linux 포트 닫는 법  (0) 2017.03.06
gcc canary , NX 해제 컴파일  (0) 2017.02.13
skeleton  (0) 2017.02.05
ubuntu 64bit 에서 32bit compile  (0) 2017.01.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함