靶机下载地址:应急响应靶机-Linux(1)
1. 背景
前景需要:小王急匆匆地找到小张,小王说"李哥,我dev服务器被黑了",快救救我!!
挑战内容:
(1)黑客的IP地址
(2)遗留下的三个flag
登录密码:defend/defend ; root/defend
2. 查看登录记录
- 查看成功登录记录:使用 last 命令或搜索 /var/log/secure 或 /var/log/auth.log 文件。
- 查看失败登录记录:搜索 /var/log/secure 或 /var/log/auth.log 文件中的“Failed”关键字。
- 查看最后一次登录记录:使用 lastlog 命令。
2.1 last
[defend@localhost log]$ last
defend pts/0 :0 Thu Mar 13 22:37 still logged in
defend pts/0 :0 Thu Mar 13 22:32 - 22:35 (00:02)
defend :0 :0 Thu Mar 13 22:32 still logged in
reboot system boot 3.10.0-1160.el7. Thu Mar 13 22:29 - 22:38 (00:09)
defend pts/1 :0 Tue Mar 19 10:17 - crash (359+12:11)
defend pts/1 :0 Mon Mar 18 20:25 - 20:26 (00:01)
root pts/1 192.168.75.129 Mon Mar 18 20:23 - 20:25 (00:02)
defend pts/0 :0 Tue Mar 19 03:16 - crash (359+19:13)
defend :0 :0 Tue Mar 19 03:15 - crash (359+19:13)
reboot system boot 3.10.0-1160.el7. Tue Mar 19 03:14 - 22:38 (359+19:24)
结果分析:
可疑IP192.168.75.129于3月18号 20:23分成功通过root用户以伪终端登录。
1. 记录格式解析
每行记录的格式通常为:
<用户名> <终端类型> <登录来源> <登录时间> <登出时间> <持续时间>
(1)用户名
表示登录的用户。例如:defend、root。
(2)终端类型
pts/0、pts/1:表示伪终端(pseudo-terminal),通常用于 SSH 或终端模拟器登录。
:0:表示图形界面登录(X11 会话)。
system boot:表示系统启动。
(3)登录来源
表示登录的来源。例如:
:0:本地图形界面登录。
192.168.75.129:远程 IP 地址。
:0(重复):本地登录。
(4)登录时间
表示用户登录的时间。
(5)登出时间
表示用户登出的时间。如果是 still logged in,表示用户当前仍然登录。
(6)持续时间
表示登录会话的持续时间。例如:00:02 表示持续了 2 分钟,359+12:11 表示持续了 359 天 12 小时 11 分钟。
例子:
root pts/1 192.168.75.129 Mon Mar 18 20:23 - 20:25 (00:02)
用户 root 于 3 月 18 日 20:23 从远程 IP 地址 192.168.75.129 登录,20:25 登出,持续了 2 分钟。
2.2 lastlog
结果分析:
还是可疑IP192.168.75.129
[defend@localhost log]$ lastlog
用户名 端口 来自 最后登陆时间
root pts/1 192.168.75.129 一 3月 18 20:23:07 +0800 2024
bin **从未登录过**
daemon **从未登录过**
adm **从未登录过**
lp **从未登录过**
sync **从未登录过**
shutdown **从未登录过**
halt **从未登录过**
mail **从未登录过**
operator **从未登录过**
games **从未登录过**
ftp **从未登录过**
nobody **从未登录过**
systemd-network **从未登录过**
dbus **从未登录过**
polkitd **从未登录过**
libstoragemgmt **从未登录过**
colord **从未登录过**
rpc **从未登录过**
saned **从未登录过**
saslauth **从未登录过**
abrt **从未登录过**
setroubleshoot **从未登录过**
rtkit **从未登录过**
pulse **从未登录过**
chrony **从未登录过**
unbound **从未登录过**
radvd **从未登录过**
tss **从未登录过**
usbmuxd **从未登录过**
geoclue **从未登录过**
qemu **从未登录过**
gluster **从未登录过**
gdm :0 四 3月 13 22:29:19 +0800 2025
rpcuser **从未登录过**
nfsnobody **从未登录过**
gnome-initial-setup **从未登录过**
sshd **从未登录过**
avahi **从未登录过**
postfix **从未登录过**
ntp **从未登录过**
tcpdump **从未登录过**
defend :0 四 3月 13 22:32:15 +0800 2025
redis **从未登录过**
2.3 grep "Failed" /var/log/secure*
结果分析:
3月18号19:29分左右,在短时间内,可疑IP192.168.75.129多次尝试SSH登录,存在暴力破解嫌疑
[root@localhost ~]# grep "Failed" /var/log/secure*
Mar 18 19:29:20 localhost sshd[11621]: Failed password for root from 192.168.75.129 port 55904 ssh2
Mar 18 19:29:43 localhost sshd[11634]: Failed password for root from 192.168.75.129 port 40066 ssh2
Mar 18 19:29:43 localhost sshd[11646]: Failed password for root from 192.168.75.129 port 40188 ssh2
Mar 18 19:29:43 localhost sshd[11644]: Failed password for root from 192.168.75.129 port 40160 ssh2
Mar 18 19:29:43 localhost sshd[11647]: Failed password for root from 192.168.75.129 port 40204 ssh2
#####下面还有很多失败的记录,就不放出来了
2.4 grep "Accepted " /var/log/secure*
结果分析:
3月18号20:23分,SSH 服务接受了一个基于公钥的认证请求,目标用户是 root,来源IP为192.168.75.129
[root@localhost ~]# grep "Accepted " /var/log/secure*
Mar 18 20:23:07 localhost sshd[13285]: Accepted publickey for root from 192.168.75.129 port 42162 ssh2: RSA SHA256:CntyDg/6Rprau//z63898uxnuJxK3XooqdUZJfQmlUo
2.5 history
结果分析:
/etc/rc.d/rc.local
是一个传统的 Linux 启动脚本文件,用于在系统启动时执行一些自定义的命令或脚本。历史命令中看到了曾修改过该文件的权限,同时发现第一个flag。
[root@localhost ~]# history
1 ls
2 chmod +x /etc/rc.d/rc.local
3 cat /etc/rc.d/rc.local
4 vim /etc/rc.d/rc.local
5 echo flag{thisismybaby}
6 exit
7 grep "Failed" /var/log/secure*
8 grep "Accepted " /var/log/secure*
9 ps -aux
10 history
2.6 cat /etc/rc.d/rc.local
结果分析:
ps:现代的 Linux 系统(如使用 systemd 的系统)已经不推荐使用 rc.local
,而是建议使用 systemd 服务或 udev 规则来实现启动时的脚本执行。创建一个 systemd 服务文件 /etc/systemd/system/myscript.service.
发现第二个flag。
[root@localhost ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
# flag{kfcvme50}
touch /var/lock/subsys/local
2.7 netstat -tunlp
结果分析:
没有发现异常
[root@localhost ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 739/rpcbind
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1537/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1085/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1086/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1408/master
tcp6 0 0 :::111 :::* LISTEN 739/rpcbind
tcp6 0 0 :::22 :::* LISTEN 1085/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1086/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1408/master
udp 0 0 0.0.0.0:5353 0.0.0.0:* 800/avahi-daemon: r
udp 0 0 192.168.122.1:53 0.0.0.0:* 1537/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1537/dnsmasq
udp 0 0 0.0.0.0:111 0.0.0.0:* 739/rpcbind
udp 0 0 127.0.0.1:323 0.0.0.0:* 753/chronyd
udp 0 0 0.0.0.0:912 0.0.0.0:* 739/rpcbind
udp 0 0 0.0.0.0:39837 0.0.0.0:* 800/avahi-daemon: r
udp6 0 0 :::111 :::* 739/rpcbind
udp6 0 0 ::1:323 :::* 753/chronyd
udp6 0 0 :::912 :::* 739/rpcbind
2.8 cat /var/log/redis/redis.log
结果分析:
之所以查看redis日志,是因为在lastlog中发现存在redis用户,再结合ssh公钥登录,很有可能是redis未授权漏洞。
发现可疑IP192.168.75.129,多次连接来自同一个 IP 地址,表明该 IP 地址的客户端与 Redis 服务进行了多次交互
[root@localhost redis]# cat redis.log | grep "Accepted"
11111:M 18 Mar 19:27:54.895 - Accepted 127.0.0.1:41590
11595:M 18 Mar 19:27:57.321 - Accepted 192.168.75.129:54766
11595:M 18 Mar 19:39:31.996 - Accepted 192.168.75.129:53104
11595:M 18 Mar 19:39:34.052 - Accepted 192.168.75.129:57672
11595:M 18 Mar 19:44:53.399 - Accepted 127.0.0.1:41594
12234:M 18 Mar 19:47:02.153 - Accepted 192.168.75.129:45240
12234:M 18 Mar 19:47:03.612 - Accepted 192.168.75.129:53124
12234:M 18 Mar 19:53:40.994 - Accepted 127.0.0.1:41596
12559:M 18 Mar 19:53:45.397 - Accepted 192.168.75.129:44572
12559:M 18 Mar 19:53:46.807 - Accepted 192.168.75.129:44582
12559:M 18 Mar 20:20:57.221 - Accepted 127.0.0.1:41598
13274:M 18 Mar 20:21:56.411 - Accepted 192.168.75.129:54826
13274:M 18 Mar 20:21:58.333 - Accepted 192.168.75.129:54836
2.9 cat /root/.ssh/authorized_keys
结果分析:
发现含有redis字符的ssh公钥,可以判定攻击者利用redis未授权漏洞进行ssh公钥写入,再进行ssh远程连接
[root@localhost redis]# cd /root/.ssh
[root@localhost .ssh]# ls
authorized_keys
[root@localhost .ssh]# cat authorized_keys
REDIS0007� redis-ver3.2.12�
redis-bits�@�ctime�2�eused-mem��h
��TJB=
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDAWLnUKcX0Wpd0/BDBwd6CKVb3MP9PmUwpnyIxRP3HbB7peiimjN1p6pmSHGU0NOszENTgCUGvesgwzNeG3yA/hTJOTWbHvV9Yp3ZsVPAC1JnptEWhNLbPjQjHyp/4o3H1aaFavtqrcOkFnd0/RxCYBZm8ZSEBEIV2QnN2c3ovrTYzKWDNCVJ/XM8db4i33sSpCVUJeZtBw0j3exSIpyJrxplYVDOlpY38UKuWptbAU5BdDDXPcaBLLK3TuXk2OUCBU+A6oTj9AOWgKkLfREYFavTWrifbrTrZ3nfL+YjHXS9IHoi4JKKUXoI/9yKXIIf2c7O6zoPy992nKV00wfe0TP7xEyKrrQVEitMkEAdyfyiMQ5wf9whl5xNPYrDwqO1fIzz1cUtf0UwPJ3hD6QT48PHxu9+L4heLd1J7YnwOn5l15/5CtIwkNDn035ZQq22PkhO7w02lrSBYWcT5XB2J8k/RrWwOu5u4Yi+fEPyQchXsoitcuDHMX/iPxnJOQO0= chinaran@kali
�nh����
2.10 rpm -Vf /usr/bin/*
结果分析:
发现redis.conf配置文件被修改
rpm -Vf /usr/bin/* 是一个非常有用的命令,用于验证 /usr/bin 目录下的所有文件是否与它们对应的 RPM 包安装时的状态一致。这个命令可以帮助你检查文件是否被修改、替换或损坏,从而发现潜在的安全问题或配置错误。
1. 命令解析
rpm:RPM 包管理工具,用于安装、查询、验证和管理 RPM 包。
-V(或 --verify):验证文件的状态。它会检查文件的大小、权限、所有者、校验和等属性是否与 RPM 数据库中记录的一致。
-f(或 --file):指定要验证的文件路径。在这里,/usr/bin/* 表示验证 /usr/bin 目录下的所有文件。
2. 命令的作用
当你运行 rpm -Vf /usr/bin/* 时,RPM 会检查 /usr/bin 目录下的每个文件,并将其当前状态与 RPM 数据库中记录的状态进行比较。如果发现任何不一致(例如文件被修改、权限被更改等),RPM 会输出相关信息。
3. 输出结果的含义
如果文件的状态与 RPM 数据库中的记录一致,命令不会输出任何内容。如果发现不一致,RPM 会输出类似以下的内容:
S.5....T c /usr/bin/example
解释:
S:文件大小发生了变化。
.:文件的权限没有变化。
5:文件的 MD5 校验和发生了变化。
.:文件的链接状态没有变化。
.:文件的所有者没有变化。
.:文件的组没有变化。
T:文件的修改时间发生了变化。
c:表示这是一个配置文件(config)。
/usr/bin/example:受影响的文件路径。
例:
S.5....T. c /etc/redis.conf
[root@localhost .ssh]# rpm -Vf /usr/bin/*
文件 /usr/bin/alt-java 不属于任何软件包
SM5....T. c /etc/rc.d/rc.local
SM5....T. c /etc/rc.d/rc.local
文件 /usr/bin/ControlPanel 不属于任何软件包
SM5....T. c /etc/rc.d/rc.local
SM5....T. c /etc/rc.d/rc.local
文件 /usr/bin/itweb-settings 不属于任何软件包
文件 /usr/bin/java 不属于任何软件包
文件 /usr/bin/javaws 不属于任何软件包
SM5....T. c /etc/rc.d/rc.local
SM5....T. c /etc/rc.d/rc.local
文件 /usr/bin/keytool 不属于任何软件包
SM5....T. c /etc/rc.d/rc.local
SM5....T. c /etc/rc.d/rc.local
SM5....T. c /etc/rc.d/rc.local
文件 /usr/bin/orbd 不属于任何软件包
文件 /usr/bin/pack200 不属于任何软件包
文件 /usr/bin/policyeditor 不属于任何软件包
文件 /usr/bin/policytool 不属于任何软件包
遗漏 /var/run/pulse
文件 /usr/bin/readcd 不属于任何软件包
S.5....T. c /etc/redis.conf
S.5....T. c /etc/redis.conf
S.5....T. c /etc/redis.conf
S.5....T. c /etc/redis.conf
S.5....T. c /etc/redis.conf
S.5....T. c /etc/redis.conf
2.11 cat /etc/redis.conf
结果分析:
发现第三个flag。
在配置文件中发现redis监听0.0.0.0,并且没有密码要求(requirepass被注释了),这就是redis未授权访问漏洞的根源。
[root@localhost .ssh]# cat /etc/redis.conf
# flag{P@ssW0rd_redis}
# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.
################################## INCLUDES ###################################
# Include one or more other config files here. This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
提交答案脚本在桌面