UTCTF 2021

May 12-13th I competed in UTCTF, I decided to write up some of the challenges I thought were cool.

Small P Problems

This was a crypto problem. It was pretty easy, but I suck at crypto so this was the only one I solved from this category.

/assets/images/utctf21/Screenshot_from_2021-03-14_10-45-43.png

This is a Diffie-Hellman key exchange, we need to find the private keys a, and b:

# The given parameters:
p = 69691
g = 1001
A = 17016
B = 47643

# Calculate the shared key
def diffie_hellman_key_exchange(g, p, a, b):
	A = pow(g, a, p)
	B = pow(g, b, p)
	
	print("Alice sends: {}".format(A))
	print("Bob sends: {}".format(B))
	
	Ka = pow(B, a, p)
	Kb = pow(A, b, p)
	
	print("Alice calculates: {}".format(Ka))
	print("Bob calculates: {}".format(Kb))

# Find the private key a
for a1 in range(p):
	A1 = pow(g, a1, p)
	if A1 == A:
		a = a1
		break
# Find the private key b
for b1 in range(p):
	B1 = pow(g, b1, p)
	if B1 == B:
		b = b1
		break

print("Alice - private key a: {}".format(a))
print("Bob - private key b: {}".format(b))
diffie_hellman_key_exchange(g, p, a, b)

The output of the program is:

/assets/images/utctf21/Screenshot_from_2021-03-16_19-43-50.png

The shared secret is k = 53919. This is also the flag. FIN. 🥳

Hack Bob’s Box:

This was a networking problem. This is the first networking problem I have done, its an awesome category.

/assets/images/utctf21/Screenshot_from_2021-03-14_10-45-35.png

Scanning:

In the instructions it says we are only allowed to run nmap on [misc.utctf.live:8121](http://misc.utctf.live:8121) and [misc.utctf.live:8122](http://misc.utctf.live:8122) . Lets do it.

//I shouldn't have done these seperately:
nmap -p 8121 -sV misc.utctf.live
nmap -p 8122 -sV misc.utctf.live

/assets/images/utctf21/Screenshot_from_2021-03-12_22-08-16.png

We can see there is FTP, SSH service on these ports.

FTP:

Connect, and login to the ftp server as Anonymous:

ftp misc.utctf.live 8121

I couldn’t actually connect to it for some reason, but they posted the ftp files on the challenge server.

/assets/images/utctf21/Screenshot_from_2021-03-16_20-10-39.png

In the firefox folder there is places.sqlite

/assets/images/utctf21/Screenshot_from_2021-03-16_20-13-20.png

Open the file places.sqlite:

sqlite> .open places.sqlite
sqlite> .tables
moz_anno_attributes    moz_historyvisits      moz_meta             
moz_annos              moz_inputhistory       moz_origins          
moz_bookmarks          moz_items_annos        moz_places           
moz_bookmarks_deleted  moz_keywords         
sqlite> select * from moz_places;

In the table moz_places we find a password:

/assets/images/utctf21/Screenshot_from_2021-03-16_20-14-38.png

We now have a username, and password: bob:i-l0v3-d0lph1n5 so we can log into SSH

SSH Login:

We login to SSH with the credentials we found, and then use the find command to find the flag.

/assets/images/utctf21/Screenshot_from_2021-03-13_17-47-36.png

FIN. 🥳

Alright last one. 😐

Sandwiched

Sandwiched was a forensics challenge, I hadn’t done anything like it before, it took some work to solve.

/assets/images/utctf21/Screenshot_from_2021-03-14_10-45-26.png

secret.pdf contains the following:

/assets/images/utctf21/Screenshot_from_2021-03-16_20-26-21.png

We run foremost on the pdf to extract any files hidden in the pdf:

foremost secret.pdf

We find an image, but it has an unsupported marker type

/assets/images/utctf21/Screenshot_from_2021-03-16_20-33-25.png

When we open in hexdump we see that there are multiple PDFs inside the image:

/assets/images/utctf21/Screenshot_from_2021-03-16_20-34-28.png

If we remove these PDF from the image maybe we can fix the image. I guessed this but it worked 🙂

We write a script to do this.

The PDF start flag is %PDF , which indicates the beginning of a PDF this is 25504446 in hex. The PDF end flag is %%EOF , which indicates the end of a PDF, this is 2525454f46 in hex. We want to filter out everything between the start and end flag for all pdf in the image.

I am sorry for this code.

filtered_hex = ""

eof_flag = "2525454f46" # %%EOF
pdf_flag = "25504446"   # %PDF

lpf = len(pdf_flag)
ef = len(eof_flag)

hexdata = ""
start_pdf = False

# Open the image, and read it into a hexstring
with open('00000015.jpg', 'rb') as f:
    hexdata = f.read().hex()

i = 0
# loop through the data
while(i<len(hexdata)):
	# If we have found a pdf, we want to loop over it and don't write it to the filtered data buffer
	if hexdata[i:i+lpf] == pdf_flag:
		start_pdf = True
	# Write image data into the filtered data buffer if it is not part of a pdf
	if start_pdf is False:
		filtered_hex += hexdata[i]
	# we have reached the end of a pdf 
	elif start_pdf is True and hexdata[i:i+ef] == eof_flag:
		i += ef-1
		start_pdf = False
	i+=1
#write the filtered data buffer to a new image file
with open("flag1.jpg", "wb") as f:
	f.write(bytes.fromhex(filtered_hex))

We run it and we get:

/assets/images/utctf21/Screenshot_from_2021-03-16_21-04-06.png

FIN. 🥳

This CTF was fun but I still suck at pwn. 😑