pydbg测试实例(三)进程快照的获取和恢复

转自《python灰帽子》第4章

目标:获取进程快照和恢复进程

思路:开启两个线程,第一线程创建一个pydbg调试器对象,并用它加载一个可执行程序;第二线程通过pydbg的方法process_snapshot()和process_restore()来获取进程快照和恢复,在获取快照或恢复的时候都要暂停进程的所有线程

snapshot.py

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
	
        # open debugger thread waiting for pid to be set
        pydbg_thread = threading.Thread(target=self.start_debugger)
        pydbg_thread.setDaemon(0)
        pydbg_thread.start()
            
        while self.pid == None:
            time.sleep(1)
        
        # open second thread to snapshot the process
        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"
snap = snapshotter(exe_path)
测试:

只在xp下可以成功,输入restore后,计算器窗口并没变化,要最小化后再打开就可以看到效果

另外,对计算器记忆功能如MS的恢复不起作用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值