# PicoCTF - like1000
###### tags: `PicoCTF` `CTF` `Misc`
Challenge: [like1000]()
## Background
[How to extract nested tar.gz files easily?](https://stackoverflow.com/questions/2778153/how-to-extract-nested-tar-gz-files-easily)
[Shell Script - While](https://ithelp.ithome.com.tw/articles/10132603)
## Exploit - Untar 1000 times
* For untar folders
```bash!
#! /bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
file_name=1000
for next in ${file_name}.tar
while [ $file_name > 1 ]
do
echo "Untaring - $file_name"
tar -xvf ${file_name}.tar #-C ./
file_name=$(($file_name-1))
mkdir ./$file_name
mv ${file_name}.tar ./$file_name
cd ./${file_name}
done
```
* For getting flag
```bash!
#! /bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
file_name=999
while [ "$file_name" > "0" ]
do
cd ./${file_name}
file_name=$(($file_name-1))
if [ "$file_name" == "0" ]
then ls -al
cat filler.txt
mv flag.png ~/CTF/PicoCTF/Misc/like1000
fi
done
exit 0
```
## Reference
[Shell Script 變數相加](https://shengyu7697.github.io/shell-script-arithmetic/)
[How to solve gzip: stdin: not in gzip format error](https://linuxhint.com/solve-gzip-stdin-not-gzip-format-error/)
[解压缩报错tar: Error is not recoverable: exiting now](https://blog.csdn.net/cp_panda_5/article/details/79192688)
[In a bash script, using the conditional "or" in an "if" statement](https://unix.stackexchange.com/questions/47584/in-a-bash-script-using-the-conditional-or-in-an-if-statement)