[3주] 04장 - 프로세스 스냅샷

Posted by dw0rdptr
2015. 1. 26. 06:02 Study/파이썬 해킹 프로그래밍

스냅샷은 대상 프로세스의 어떤 특정 시점을 저장한다.

스냅샷을 만든 이후에는 언제든지 프로세스의 상태를 스냅샷 생성 시점으로 되돌릴 수 있다.



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#snapshot.py
#-*- coding: utf-8 -*-
from pydbg import *
from pydbg.defines import *
 
import threading
import time
import sys
 
class snapshotter(object):
 
    def __init__(self,exe_path):
 
        self.exe_path = exe_path
        self.pid      = None
        self.dbg      = None
        self.running  = True
 
        #디버거 스레드시작, 대상 프로세스의 PID가 설정될 떄까지 루프돔
        pydbg_thread = threading.Thread(target = self.start_debugger)
        pydbg_thread.setDaemon(0)
        pydbg_thread.start()
 
        while self.pid == None:
            time.sleep(1)
 
        #현재 PID가 설정된 상태이고 대상 프로세스가 실행중.
        #스냅샷을 위한 두 번째 스레드 실행
        monitor_thread = threading.Thread(target=self.monitor_debugger)
        monitor_thread.setDaemon(0)
        monitor_thread.start()
 
 
    #스냅샷을 만들것인지 복원할것인지 종료할것인지 명령입력
    def monitor_debugger(self):
        while self.running == True:
            input = raw_input("Enter: 'snap', 'restore' or 'quit' :")
            input = input.lower().strip()
 
            if input == "quit":
                print "[*] Exiting the snapshotter."
                self.running = False
                self.dbg.terminate_process()
 
            elif input == "snap":
                print "[*] Suspending all threads."
                self.dbg.suspend_all_threads()
 
                print "[*] Obtaining snapshot"
                self.dbg.process_snapshot()
 
                print "[*] Resuming operation."
                self.dbg.resume_all_threads()
 
            elif input == "restore":
                print "[*] Suspending all threads."
                self.dbg.suspend_all_threads()
 
                print "[*] Restoring snapshot."
                self.dbg.process_restore()
 
                print "[*] Resuming operation."
                self.dbg.resume_all_threads()
 
    def start_debugger(self):
        self.dbg = pydbg()
        pid = self.dbg.load(self.exe_path)
        self.pid = self.dbg.pid
 
        self.dbg.run()
 
exe_path = "C:\\Windows\\System32\\calc.exe"
snapshotter(exe_path)
 
 
 
cs

#계산기로 프로세스 스냅샷 기능이 동작하는 것을 확인 가능