본문 바로가기

reversing/reversing

gdbserver script

SMALL
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
 
import subprocess
import re
import sys
import os
#gdbserver --attach :55555 1299
 
def execute(cmd) :
    fd = subprocess.Popen(cmd, shell=True,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
    return fd
 
 
def get_pid(proc):
    fd = execute("/bin/ps -x")
    pslist= fd.stdout.read()
    arr = re.findall("\d+.+?"+proc+"\n",pslist)
    pid = ""
    for ps in arr:
        if "python" not in ps:
            pid = ps
    pid = re.findall("(\d+)",pid)[0]
    return pid
 
def kill_gdbserver():
    fd = execute("/bin/ps -x")
    pslist = fd.stdout.read()
 
    arr = re.findall("(\d+).+?gdbserver --attach.+?\n",pslist)
 
    if len(arr)!=0:
        for i in arr:
            os.system("kill "+str(i))
 
 
 
def main():
 
    if(len(sys.argv)!=3):
        print "Usage : python gdbsrv.py [proc name] [port]"
        sys.exit()
    kill_gdbserver()
    pid = get_pid(sys.argv[1])
    port = sys.argv[2]
    cmd = "gdbserver --attach :"+str(port)+" "+str(pid)
    execute(cmd)
 
if __name__ == "__main__":
    main()
 
cs

GDB server script 저장

서버 죽였다 켰다 하기 힘들어



LIST

'reversing > reversing' 카테고리의 다른 글

GO 언어 리버싱  (0) 2018.06.12
python gdb 백업  (0) 2018.04.01
C++ 리버싱 연습 [2] -이론  (0) 2018.03.10
SMT - z3[sudoku]  (0) 2018.01.24
inline function hooking  (0) 2017.05.12