Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tunz
- # cwhan.tunz |at| gmail.com
- # 2013. 11. 27
- import os
- import sys
- if os.getuid() != 0:
- print "[-] You are not root"
- sys.exit(-1)
- if len(sys.argv) < 2:
- print "python attach.py [binary name] [script]"
- output = os.popen('ps aux | grep '+sys.argv[1]).read()
- outputs = output.split('\n')
- lastline = ""
- i=len(outputs)-2
- while i>= 0:
- try:
- pid = outputs[i].split(None)[1]
- except:
- i -= 1
- continue
- if int(pid) < os.getpid():
- lastline = outputs[i]
- break
- i -= 1
- pid = lastline.split(None)[1]
- print "[*] Attach to "+ ' '.join(lastline.split(None)[-2:]) +" ("+pid+")"
- if len(sys.argv) == 3:
- print "gdb -q --pid="+pid+" -x "+sys.argv[2]
- os.system("gdb -q --pid="+pid+" -x "+sys.argv[2])
- else:
- print "gdb -q --pid="+pid
- os.system("gdb -q --pid="+pid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement