VMware vCenter ESXI中经常会装一些非常重要的业务虚拟服务器,Linux一般都是登录状态的,但是Windows机器锁屏较多,想要获取服务器权限,一般需要把vmem文件下载下来,用内存分析工具进行hashdump等,以突破其锁屏获取服务器权限。笔者在对volatility工具进行了解后,对分析vmem文件的手法进行了一定优化,可以提升解决锁屏问题的效率。
在了解了volatility内存取证工具后,想到了几种办法:
python3版本
python2版本:
最一开始对项目了解的不够深入,没注意到项目团队已经把volatility2制作成了可执行文件,导致前期一直在死磕打包volatility3,后来在小伙伴的提醒下,发现3gstudent师傅研究了利用volatility2进行Windows锁屏问题解决,在此先膜拜下师傅。
不过官方团队并没有打包volatility3的可执行程序,原因写的是打包出来的packages会被识别为恶意软件,解决了这个问题就会出可执行程序了。
Linux环境下的esxi,这个思考很快就被证明不太可行了,volatility3需要多个系统库和pip库:
yum install zlib &&\
yum install zlib-devel &&\
yum install bzip2-devel &&\
yum install ncurses-devel &&\
yum install sqlite-devel &&\
yum install readline-devel &&\
yum install gcc &&\
yum install libffi &&\
yum install libffi-devel &&\
yum install gcc-c++\
yum install openssl-devel\
yum install tk-devel
需要pip3
yum install xz-devel
yum install epel-release
yum install python35-devel
需要n多个系统依赖以及n多个pip依赖
pip3 install pefile==2018.8.8 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install backports.lzma -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install pycryptodome
pip install importlib-metadata==0.6
CentOS 7.9跟exsi的GLIBC库版本一致,自带python3.6,比较合适。
安装编译后续可能会用到的依赖::
yum install zlib &&\
yum install zlib-devel &&\
yum install bzip2-devel &&\
yum install ncurses-devel &&\
yum install sqlite-devel &&\
yum install readline-devel &&\
yum install gcc &&\
yum install libffi &&\
yum install libffi-devel &&\
yum install gcc-c++ &&\
yum install openssl-devel &&\
yum install tk-devel
GitHub地址:https://github.com/volatilityfoundation/volatility3
正常安装到yara的时候应该会报错,需要安装python-dev库才行
CentOS系统:
# 安装EPEL源
yum install epel-release -y
# 默认安装python3.6开发包
yum install python3-devel -y
Ubuntu系统:
apt-get install python3-dev
装好python-dev之后,安装依赖即可。
pip3 install -r requirements.txt
也可以这么安装
pip3 install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
需要先更新下setuptools不然等下安装编译 Python的相关包安装会报错:
pip3 install --upgrade setuptools
安装Volatility3
python3 setup.py install
完成安装后,测试是否能正常使用
python3 vol.py
查看运行是否有异常提示:
python3 vol.py -vv
测试功能是否正常
python3 vol.py -f xxx.vmem windows.info
python3 vol.py -f xxx.vmem windows.hashdump
pip3 install pyinstaller==3.6
修改spec,默认只有vol.py,增加了hashdump和yarascan;还增加了vol_coll使打包出来的是一个文件夹。
# This file is Copyright 2019 Volatility Foundation and licensed under the Volatility Software License 1.0
# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0
#
import os
import sys
from PyInstaller.building.api import PYZ, EXE,COLLECT
from PyInstaller.building.build_main import Analysis
from PyInstaller.utils.hooks import collect_submodules, collect_data_files, collect_dynamic_libs
block_cipher = None
binaries = []
try:
import capstone
binaries = collect_dynamic_libs('capstone')
except ImportError:
pass
# Volatility must be findable in sys.path in order for collect_submodules to work
# This adds the current working directory, which should usually do the trick
sys.path.append(os.path.dirname(os.path.abspath(SPEC)))
vol_analysis = Analysis(['vol.py',
'volatility3/framework/plugins/windows/hashdump.py',
'volatility3/framework/plugins/yarascan.py'],
pathex = [],
binaries = binaries,
datas = collect_data_files('volatility3.framework') + \
collect_data_files('volatility3.framework.automagic', include_py_files = True) + \
collect_data_files('volatility3.framework.plugins', include_py_files = True) + \
collect_data_files('volatility3.framework.layers', include_py_files = True) + \
collect_data_files('volatility3.schemas') + \
collect_data_files('volatility3.plugins', include_py_files = True),
hiddenimports = collect_submodules('volatility3.framework.automagic') + \
collect_submodules('volatility3.framework.plugins') + \
collect_submodules('volatility3.framework.symbols'),
hookspath = [],
runtime_hooks = [],
excludes = [],
win_no_prefer_redirects = False,
win_private_assemblies = False,
cipher = block_cipher,
noarchive = False)
vol_pyz = PYZ(vol_analysis.pure, vol_analysis.zipped_data,
cipher = block_cipher)
vol_exe = EXE(vol_pyz,
vol_analysis.scripts,
[('u', None, 'OPTION')],
exclude_binaries=True,
name = 'vol',
icon = os.path.join('doc', 'source', '_static', 'favicon.ico'),
debug = False,
bootloader_ignore_signals = False,
strip = False,
upx = True,
runtime_tmpdir = None,
console = True)
vol_coll = COLLECT(vol_exe,
vol_analysis.binaries,
vol_analysis.zipfiles,
vol_analysis.datas,
strip=False,
upx=True,
upx_exclude=[],
name = 'vol')
打包,默认是放在dist目录下。
pyinstaller vol-new.spec
需要把打包完成的vol文件夹中base_library.zip解压一下,解压至当前目录即可。
从CentOS7中把vol压缩下,搞到目标esxi服务器上解压,给好权限应该就能用了。
PS:Volatility3做Windows内存文件分析时,需要联网到微软网站那边下一个字符库,所以需要目标esxi能出网。
使用Ubuntu16及kali之类的系统,打包出来的vol在exsi中无法运行
查看esxi的GLIBC版本,发现为2.17:
尝试将高版本的so文件拷贝到esxi系统中,尝试将libc-2.27.so修改为libc.2.17.so,系统立马就GG了,还好mobax的sftp还能用:
需要找GLIBC版本一致,或更低版本的系统,打包vol才可以运行:
centos6.6服务器的glibc默认版本为2.12
centos7系统的默认glibc版本已经升级2.17
其中vultr中默认的CentOS7版本就可以:
strings /usr/lib64/libc.so.6 | grep GLIBC
以及centos7.9版本也是可以的
在esxi中运行打包好的vol会提示No module named 'encodings'
解决办法,把base_library.zip解压出来即可,注意需要解压到当前目录,不能解压到base_library文件夹里。
左边是打包为单一文件,右边是打包为一个文件夹
解决方法:
其实就是作者写vol.spec的时候,有些pip库没有打包上,增加上hashdump和yarascan就行了。
vol_analysis = Analysis(['vol.py',
'volatility3/framework/plugins/windows/hashdump.py',
'volatility3/framework/plugins/yarascan.py'],
在esxi中直接运行打包好的Volatility,在联网的情况下,已经可以完成hashdump。但是在无法联网的时候,无法下载到symbols文件,也就是pdb(program
database)文件,且该文件无法直接通过浏览器下载到。通过对项目的深入了解,发现作者有提供了下载pdb文件的解决办法。
作者并没有在readme中写明下载pdb文件的方法,在断网状态下调试脚本运行过程的时候,才发现作者留的小惊喜:
(venv) PS D:\PythonDev\project\volatility3-develop> python vol.py -vv -f "F:\Attck\Win10-TH-2.0\Windows 10 x64-490103e9.vmem" windows.hashdump Volatility 3 Framework 2.4.1 INFO volatility3.cli: Volatility plugins path: ['D:\\PythonDev\\project\\volatility3-develop\\volatility3\\plugins', 'D:\\PythonDev\\project\\volatility3-develop\\volatility3\\framework\\plugins'] INFO volatility3.cli: Volatility symbols path: ['D:\\PythonDev\\project\\volatility3-develop\\volatility3\\symbols', 'D:\\PythonDev\\project\\volatility3-develop\\volatility3\\framework\\symbols'] INFO volatility3.framework.automagic: Detected a windows category plugin INFO volatility3.framework.automagic: Running automagic: ConstructionMagic INFO volatility3.framework.automagic: Running automagic: SymbolCacheMagic INFO volatility3.framework.automagic: Running automagic: LayerStacker DEBUG volatility3.framework.automagic.windows: Detecting Self-referential pointer for recent windows DEBUG volatility3.framework.automagic.windows: DtbSelfRef64bit test succeeded at 0x1ad000 DEBUG volatility3.framework.symbols.windows.pdbconv: Failed with <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。> DEBUG volatility3.framework.symbols.windows.pdbconv: Attempting to retrieve http://msdl.microsoft.com/download/symbols/ntkrnlmp.pdb/118018959D8D7CA5AAB45B75AED5A9761/ntkrnlmp.pd_ DEBUG volatility3.framework.symbols.windows.pdbconv: Failed with <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。> WARNING volatility3.framework.symbols.windows.pdbutil: Symbol file could not be downloaded from remote server DEBUG volatility3.framework.symbols.windows.pdbutil: Required symbol library path not found: ntkrnlmp.pdb\118018959D8D7CA5AAB45B75AED5A976-1 INFO volatility3.framework.symbols.windows.pdbutil: The symbols can be downloaded later using pdbconv.py -p ntkrnlmp.pdb -g 118018959D8D7CA5AAB45B75AED5A9761 INFO volatility3.framework.automagic: Running automagic: SymbolFinder INFO volatility3.framework.automagic: Running automagic: KernelModule
上述调试信息中,关键点是:
Symbol file could not be downloaded from remote server
Required symbol library path not found: ntkrnlmp.pdb\118018959D8D7CA5AAB45B75AED5A976-1
The symbols can be downloaded later using pdbconv.py -p ntkrnlmp.pdb -g 118018959D8D7CA5AAB45B75AED5A9761
也就是说用pdbconv.py可以下载到所需的pdb文件:
将下载好的symbols文件放入以下目录,重新运行vol.py进行hashdump即可:
/tmp/vol/volatility3/framework/symbols/windows/ntkrnlmp.pdb/
这里遇到了个小问题就是pycharm可以正常运行该脚本进行下载,但是本地命令行运行脚本会提示No module named 'volatility3',网上搜了下说是环境变量的问题,加上打印环境变量的语句,pycharm和命令行分别运行了下,确实是pycharm多了些路径:
print("当前工作目录:",os.getcwd())
print("python搜索模块的路径集合:",sys.path)
定位到问题后,根据网上的解决办法,在pdbconv.py中加上缺少的路径即可正常使用该脚本:
sys.path.append("D:\\PythonDev\\project\\volatility3-develop")
sys.path.append("D:\\Program\\PyCharm\\PyCharm 2022.2.3\\plugins\\python\\helpers\\pycharm_display")
sys.path.append("D:\\Program\\PyCharm\\PyCharm 2022.2.3\\plugins\\python\\helpers\\pycharm_matplotlib_backend")
目前不出网状态解一个windows的hash大概需要3-7分钟,如果优化这个工具确实有很高实用价值,后续会继续进行优化,争取能3分钟解决战斗。
发现问题,解决问题,总结经验,分享方法,共同进步。
Linux环境下测试也是一样的结果:
估计是不ok的