应急响应靶机练习-Linux1

打印 上一主题 下一主题

主题 883|帖子 883|积分 2649

靶机来源: 知攻善防实验室公众号 https://mp.weixin.qq.com/s/gCWGnBiwbqSnafXU1apJCA
我是在另一台主机上通过ssh连接到靶机进行解题的,以下为解题记录。
背景

远景需要:小王急急忙地找到小张,小王说"李哥,我dev服务器被黑了",快救救我!!
挑战内容:
(1)黑客的IP地址
(2)遗留下的三个flag
解题

首先查察当前主机最近的用户登录情况,如何黑客乐成登录,那么可以查到乐成登录的记录。
  1. [root@localhost defend]# grep "Accepted " /var/log/secure* | awk '{print $1,$2,$3,$9,$11}'
  2. Mar 18 20:23:07 root 192.168.75.129
  3. Mar 20 14:28:21 defend 192.168.1.104
复制代码
此处可以看到3月18日,root用户进行了登录,IP地址为192.168.75.129,该IP大概就是黑客的IP地址。

IP正确,接着看看有没有黑客新增的用户。
  1. [root@localhost defend]# cat /etc/passwd
  2. root:x:0:0:root:/root:/bin/bash
  3. bin:x:1:1:bin:/bin:/sbin/nologin
  4. daemon:x:2:2:daemon:/sbin:/sbin/nologin
  5. adm:x:3:4:adm:/var/adm:/sbin/nologin
  6. lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
  7. sync:x:5:0:sync:/sbin:/bin/sync
  8. shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
  9. halt:x:7:0:halt:/sbin:/sbin/halt
  10. mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
  11. operator:x:11:0:operator:/root:/sbin/nologin
  12. games:x:12:100:games:/usr/games:/sbin/nologin
  13. ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
  14. nobody:x:99:99:Nobody:/:/sbin/nologin
  15. systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
  16. dbus:x:81:81:System message bus:/:/sbin/nologin
  17. polkitd:x:999:998:User for polkitd:/:/sbin/nologin
  18. libstoragemgmt:x:998:996:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
  19. colord:x:997:995:User for colord:/var/lib/colord:/sbin/nologin
  20. rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
  21. saned:x:996:993:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
  22. saslauth:x:995:76:Saslauthd user:/run/saslauthd:/sbin/nologin
  23. abrt:x:173:173::/etc/abrt:/sbin/nologin
  24. setroubleshoot:x:994:991::/var/lib/setroubleshoot:/sbin/nologin
  25. rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
  26. pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
  27. chrony:x:993:988::/var/lib/chrony:/sbin/nologin
  28. unbound:x:992:987:Unbound DNS resolver:/etc/unbound:/sbin/nologin
  29. radvd:x:75:75:radvd user:/:/sbin/nologin
  30. tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
  31. usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
  32. geoclue:x:991:985:User for geoclue:/var/lib/geoclue:/sbin/nologin
  33. qemu:x:107:107:qemu user:/:/sbin/nologin
  34. gluster:x:990:984:GlusterFS daemons:/run/gluster:/sbin/nologin
  35. gdm:x:42:42::/var/lib/gdm:/sbin/nologin
  36. rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
  37. nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
  38. gnome-initial-setup:x:989:983::/run/gnome-initial-setup/:/sbin/nologin
  39. sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
  40. avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
  41. postfix:x:89:89::/var/spool/postfix:/sbin/nologin
  42. ntp:x:38:38::/etc/ntp:/sbin/nologin
  43. tcpdump:x:72:72::/:/sbin/nologin
  44. defend:x:1000:1000:defend:/home/defend:/bin/bash
  45. redis:x:988:982:Redis Database Server:/var/lib/redis:/sbin/nologin
复制代码
这里好像没有看到可疑用户,接着看看有没有可疑的历程
  1. [root@localhost defend]# ps -aux
  2. USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  3. root          1  0.3  0.1 193824  7000 ?        Ss   14:25   0:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
  4. root          2  0.0  0.0      0     0 ?        S    14:25   0:00 [kthreadd]
  5. root          4  0.0  0.0      0     0 ?        S<   14:25   0:00 [kworker/0:0H]
  6. root          6  0.0  0.0      0     0 ?        S    14:25   0:00 [ksoftirqd/0]
  7. root          7  0.0  0.0      0     0 ?        S    14:25   0:00 [migration/0]
  8. root          8  0.0  0.0      0     0 ?        S    14:25   0:00 [rcu_bh]
  9. root          9  0.0  0.0      0     0 ?        S    14:25   0:00 [rcu_sched]
  10. root         10  0.0  0.0      0     0 ?        S<   14:25   0:00 [lru-add-drain]
  11. root         11  0.0  0.0      0     0 ?        S    14:25   0:00 [watchdog/0]
  12. root         12  0.0  0.0      0     0 ?        S    14:25   0:00 [watchdog/1]
  13. root         13  0.0  0.0      0     0 ?        S    14:25   0:00 [migration/1]
  14. root         14  0.3  0.0      0     0 ?        S    14:25   0:03 [ksoftirqd/1]
  15. root         15  0.0  0.0      0     0 ?        S    14:25   0:00 [kworker/1:0]
  16. root         16  0.0  0.0      0     0 ?        S<   14:25   0:00 [kworker/1:0H]
  17. root         17  0.0  0.0      0     0 ?        S    14:25   0:00 [watchdog/2]
  18. root         18  0.0  0.0      0     0 ?        S    14:25   0:00 [migration/2]
  19. root         19  0.0  0.0      0     0 ?        S    14:25   0:00 [ksoftirqd/2]
  20. ......
  21. ......
  22. ......
  23. defend     3164  0.0  0.0 160988  2520 ?        S    14:28   0:00 sshd: defend@pts/0
  24. defend     3174  0.0  0.0 116328  2848 pts/0    Ss   14:28   0:00 -bash
  25. root       3300  0.0  0.1 231952  3928 pts/0    S    14:28   0:00 su
  26. root       3319  0.0  0.0 116324  2880 pts/0    S    14:28   0:00 bash
  27. root       3717  0.0  0.0      0     0 ?        S    14:30   0:00 [kworker/2:0]
  28. root       3830  0.0  0.0      0     0 ?        S    14:31   0:00 [kworker/0:0]
  29. defend     3919  0.2  0.8 697416 31464 ?        Sl   14:31   0:00 /usr/libexec/gnome-terminal-server
  30. defend     3925  0.0  0.0   8536   724 ?        S    14:31   0:00 gnome-pty-helper
  31. defend     3926  0.0  0.0 116444  2932 pts/1    Ss   14:31   0:00 bash
  32. defend     4011  0.0  0.0 116444  1916 pts/1    S+   14:31   0:00 bash
  33. root       4094  0.0  0.0      0     0 ?        S    14:35   0:00 [kworker/2:2]
  34. root       4104  0.0  0.0      0     0 ?        S    14:36   0:00 [kworker/0:1]
  35. root       4133  0.0  0.0 108052   352 ?        S    14:38   0:00 sleep 60
  36. root       4134  0.0  0.0 157532  1900 pts/0    R+   14:39   0:00 ps -aux
复制代码
也没有看到可疑的历程,那就看看黑客登录乐成之后都执行过什么命令
  1. [root@localhost defend]# history
  2.     1  ls
  3.     2  chmod +x /etc/rc.d/rc.local
  4.     3  cat /etc/rc.d/rc.local
  5.     4  vim /etc/rc.d/rc.local
  6.     5  echo flag{thisismybaby}
  7.     6  exit
  8.     7  grep "Accepted " /var/log/secure* | awk '{print $1,$2,$3,$9,$11}'
  9.     8  cat /etc/passwd
  10.     9  netstat -anltup
  11.    10  ps -aux
  12.    11  history
复制代码
这里直接发现了第一个flag:flag{thisismybaby}

除此之外,还发现黑客编辑了开机启动文件rc.local,查察一下这个文件
  1. [root@localhost defend]# cat /etc/rc.d/rc.local
  2. #!/bin/bash
  3. # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
  4. #
  5. # It is highly advisable to create own systemd services or udev rules
  6. # to run scripts during boot instead of using this file.
  7. #
  8. # In contrast to previous versions due to parallel execution during boot
  9. # this script will NOT be run after all other services.
  10. #
  11. # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
  12. # that this script will be executed during boot.
  13. # flag{kfcvme50}
  14. touch /var/lock/subsys/local
复制代码
在该文件中发现了第二个flag:flag{kfcvme50}

按照黑客的攻击思绪,此时黑客已经拿到了root用户权限而且可以实现权限维持。那么第三个flag应该不会在筹划任务中,而是在黑客打进来的地方。
那么黑客是怎么打进来的?
此时,想到了刚才查察passwd文件时,最后一个用户是redis用户,阐明该机器上存在redis服务,于是查察网络连接,看看6379端口是否开放。
  1. [root@localhost defend]# netstat -anltup
  2. Active Internet connections (servers and established)
  3. Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
  4. tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1291/master         
  5. tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      761/rpcbind         
  6. tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1703/dnsmasq        
  7. tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1089/sshd           
  8. tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1092/cupsd         
  9. tcp        0      0 192.168.1.105:22        192.168.1.104:59096     ESTABLISHED 3160/sshd: defend [
  10. tcp6       0      0 ::1:25                  :::*                    LISTEN      1291/master         
  11. tcp6       0      0 :::111                  :::*                    LISTEN      761/rpcbind         
  12. tcp6       0      0 :::22                   :::*                    LISTEN      1089/sshd           
  13. tcp6       0      0 ::1:631                 :::*                    LISTEN      1092/cupsd         
  14. udp        0      0 192.168.122.1:53        0.0.0.0:*                           1703/dnsmasq        
  15. udp        0      0 0.0.0.0:67              0.0.0.0:*                           1703/dnsmasq        
  16. udp        0      0 0.0.0.0:68              0.0.0.0:*                           3052/dhclient      
  17. udp        0      0 0.0.0.0:111             0.0.0.0:*                           761/rpcbind         
  18. udp        0      0 127.0.0.1:323           0.0.0.0:*                           821/chronyd         
  19. udp        0      0 0.0.0.0:914             0.0.0.0:*                           761/rpcbind         
  20. udp        0      0 0.0.0.0:56315           0.0.0.0:*                           802/avahi-daemon: r
  21. udp        0      0 0.0.0.0:5353            0.0.0.0:*                           802/avahi-daemon: r
  22. udp6       0      0 :::111                  :::*                                761/rpcbind         
  23. udp6       0      0 ::1:323                 :::*                                821/chronyd         
  24. udp6       0      0 :::914                  :::*                                761/rpcbind
复制代码
没有发现6379端口,那么先运行该服务。
  1. [root@localhost defend]# redis-server
  2. 4368:C 20 Mar 14:55:04.305 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
  3. 4368:M 20 Mar 14:55:04.306 * Increased maximum number of open files to 10032 (it was originally set to 1024).
  4.                 _._                                                  
  5.            _.-``__ ''-._                                             
  6.       _.-``    `.  `_.  ''-._           Redis 3.2.12 (00000000/0) 64 bit
  7.   .-`` .-```.  ```\/    _.,_ ''-._                                   
  8. (    '      ,       .-`  | `,    )     Running in standalone mode
  9. |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
  10. |    `-._   `._    /     _.-'    |     PID: 4368
  11.   `-._    `-._  `-./  _.-'    _.-'                                   
  12. |`-._`-._    `-.__.-'    _.-'_.-'|                                 
  13. |    `-._`-._        _.-'_.-'    |           http://redis.io        
  14.   `-._    `-._`-.__.-'_.-'    _.-'                                   
  15. |`-._`-._    `-.__.-'    _.-'_.-'|                                 
  16. |    `-._`-._        _.-'_.-'    |                                 
  17.   `-._    `-._`-.__.-'_.-'    _.-'                                   
  18.       `-._    `-.__.-'    _.-'                                       
  19.           `-._        _.-'                                          
  20.               `-.__.-'                                               
  21. 4368:M 20 Mar 14:55:04.309 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  22. 4368:M 20 Mar 14:55:04.309 # Server started, Redis version 3.2.12
  23. 4368:M 20 Mar 14:55:04.309 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
  24. 4368:M 20 Mar 14:55:04.309 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
  25. 4368:M 20 Mar 14:55:04.310 * DB loaded from disk: 0.001 seconds
  26. 4368:M 20 Mar 14:55:04.310 * The server is now ready to accept connections on port 6379
复制代码
redis运行起来之后,需要进行登录,但是不知道密码,那就先尝试一下redis未授权。
  1. [root@localhost defend]# redis-cli -h 127.0.0.1
  2. 127.0.0.1:6379>
复制代码
直接登录乐成,那么黑客应该是通过redis未授权打进来的,看看/root/.ssh下有没有被写入ssh密钥
  1. [root@localhost .ssh]# pwd
  2. /root/.ssh
  3. [root@localhost .ssh]# ls -liah
  4. total 4.0K
  5. 51847075 drwxr-xr-x. 2 root root  29 Mar 18 20:22 .
  6. 33582977 dr-xr-x---. 7 root root 265 Mar 18 20:25 ..
  7. 51847076 -rw-r--r--. 1 root root 661 Mar 18 20:22 authorized_keys
  8. [root@localhost .ssh]# cat authorized_keys
  9. REDIS0007�      redis-ver3.2.12�
  10. redis-bits�@�ctime�2�eused-mem��h
  11.                                  ��TJB=
  12. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDAWLnUKcX0Wpd0/BDBwd6CKVb3MP9PmUwpnyIxRP3HbB7peiimjN1p6pmSHGU0NOszENTgCUGvesgwzNeG3yA/hTJOTWbHvV9Yp3ZsVPAC1JnptEWhNLbPjQjHyp/4o3H1aaFavtqrcOkFnd0/RxCYBZm8ZSEBEIV2QnN2c3ovrTYzKWDNCVJ/XM8db4i33sSpCVUJeZtBw0j3exSIpyJrxplYVDOlpY38UKuWptbAU5BdDDXPcaBLLK3TuXk2OUCBU+A6oTj9AOWgKkLfREYFavTWrifbrTrZ3nfL+YjHXS9IHoi4JKKUXoI/9yKXIIf2c7O6zoPy992nKV00wfe0TP7xEyKrrQVEitMkEAdyfyiMQ5wf9whl5xNPYrDwqO1fIzz1cUtf0UwPJ3hD6QT48PHxu9+L4heLd1J7YnwOn5l15/5CtIwkNDn035ZQq22PkhO7w02lrSBYWcT5XB2J8k/RrWwOu5u4Yi+fEPyQchXsoitcuDHMX/iPxnJOQO0= chinaran@kali
  13. �nh����[root@localhost .ssh]#
复制代码
到此,推测黑客是通过redis未授权写入ssh密钥进行登录,然后通过写入开机启动文件进行权限维持。
接着来寻找第三个flag。到此,由于我比较菜就没啥思绪了,于是就看看有哪些文件被修改过。
  1. [root@localhost .ssh]# rpm -Vf /usr/bin/*
  2. file /usr/bin/alt-java is not owned by any package
  3. SM5....T.  c /etc/rc.d/rc.local
  4. SM5....T.  c /etc/rc.d/rc.local
  5. file /usr/bin/ControlPanel is not owned by any package
  6. SM5....T.  c /etc/rc.d/rc.local
  7. SM5....T.  c /etc/rc.d/rc.local
  8. file /usr/bin/itweb-settings is not owned by any package
  9. file /usr/bin/java is not owned by any package
  10. file /usr/bin/javaws is not owned by any package
  11. SM5....T.  c /etc/rc.d/rc.local
  12. SM5....T.  c /etc/rc.d/rc.local
  13. file /usr/bin/keytool is not owned by any package
  14. SM5....T.  c /etc/rc.d/rc.local
  15. SM5....T.  c /etc/rc.d/rc.local
  16. SM5....T.  c /etc/rc.d/rc.local
  17. file /usr/bin/orbd is not owned by any package
  18. file /usr/bin/pack200 is not owned by any package
  19. file /usr/bin/policyeditor is not owned by any package
  20. file /usr/bin/policytool is not owned by any package
  21. missing     /var/run/pulse
  22. file /usr/bin/readcd is not owned by any package
  23. S.5....T.  c /etc/redis.conf
  24. S.5....T.  c /etc/redis.conf
  25. S.5....T.  c /etc/redis.conf
  26. S.5....T.  c /etc/redis.conf
  27. S.5....T.  c /etc/redis.conf
  28. S.5....T.  c /etc/redis.conf
  29. file /usr/bin/rmid is not owned by any package
  30. file /usr/bin/rmiregistry is not owned by any package
  31. file /usr/bin/servertool is not owned by any package
  32. SM5....T.  c /etc/rc.d/rc.local
复制代码
从上面看到redis的配置文件/etc/redis.conf被修改过,打开看看
  1. [root@localhost defend]# cat /etc/redis.conf
  2. # flag{P@ssW0rd_redis}
  3. # Redis configuration file example.
  4. #
  5. # Note that in order to read the configuration file, Redis must be
  6. # started with the file path as first argument:
  7. #
  8. # ./redis-server /path/to/redis.conf
  9. # Note on units: when memory size is needed, it is possible to specify
  10. # it in the usual form of 1k 5GB 4M and so forth:
  11. #
  12. # 1k => 1000 bytes
  13. # 1kb => 1024 bytes
  14. # 1m => 1000000 bytes
  15. # 1mb => 1024*1024 bytes
  16. # 1g => 1000000000 bytes
  17. # 1gb => 1024*1024*1024 bytes
  18. #
  19. # units are case insensitive so 1GB 1Gb 1gB are all the same.
复制代码
直接在第一行看到了第三个flag:flag{P@ssW0rd_redis}

至此,就拿到了三个flag。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

河曲智叟

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表