In a CTF, a pdf compilation script [1] cn be use to compile latex document. The…
- User
In a CTF, a pdf compilation script [1] cn be use to compile latex document. The directory contains a setuid wrapper [2]. Craft a Latex document that allow us to inject a command to read the content of directory FALG. The setuid wrappers is : int main(int arc, char** arv) { char *argv[] = { "/bin/bash", "-p", "/challenge/app-script/ch24/ch24.sh", arv[1] , NULL }; setreuid(geteuid(), geteuid()); execve(argv[0], argv, NULL); return 0; } ANd the Latex compilation script [2] is : #!/usr/bin/env bash
if [[ $# -ne 1 ]]; then echo "Usage : ${0} TEX_FILE" fi if [[ -f "${1}" ]]; then TMP=$(mktemp -d) cp "${1}" "${TMP}/main.tex" # Compilation echo "[+] Compilation ..." timeout 5 /usr/bin/pdflatex \ -halt-on-error \ -output-format=pdf \ -output-directory "${TMP}" \ --shell-escape \ "${TMP}/main.tex" > /dev/null timeout 5 /usr/bin/pdflatex \ -halt-on-error \ -output-format=pdf \ -output-directory "${TMP}" \ --shell-escape \ "${TMP}/main.tex" > /dev/null chmod u+w "${TMP}/main.tex" rm "${TMP}/main.tex" chmod 750 -R "${TMP}" if [[ -f "${TMP}/main.pdf" ]]; then echo "[+] Output file : ${TMP}/main.pdf" else echo "[!] Compilation error, your logs : ${TMP}/main.log" fi else echo "[!] Can't access file ${1}" fi Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.