1

There is a file with the name **flag_999.tar.gz** which has been packed maybe 999 times is there any way of unpacking all of them or a bash script because nothing is working for me.

The name is the file goes as flag_999.tar.gz and inside the archive, there is flag_998.tar.gz and inside that there is flag_997.tar.gz. So here the "flag_" is constant and then the number goes descending I reached flag_967.tar.gz manually to check the file names inside.

I tried:

file=(*tar); while [[ -e $file ]]; do tar zxf "$file"; rm "$file"; file=(*tar); done

no output

awk -F'\0' '/[^\0]/{print $(NF)}' flag_999.tar.gz

output not readable

for i in {1000..1}; do tar -xf $i.tar; done

maybe this could work I don't know because I don't know how to use it.

Click here to see and download the file https://drive.google.com/file/d/1ycWVR0htwFyexCJRohTGHio4UFdvGuPW/view?usp=sharing

6
  • 1
    Does this answer your question? How to repeatedly un tar files that are within the tar itself
    – Panki
    Jun 21, 2021 at 12:43
  • You will have to use -xzf instead of -xf obviously
    – Panki
    Jun 21, 2021 at 12:44
  • no tried them all
    – farzan
    Jun 21, 2021 at 12:44
  • Unlikely, and even if you did, you should edit your question and provide the details of what you tried and how it failed
    – Panki
    Jun 21, 2021 at 12:45
  • What I flagged as dupe is the solution - you just need to do a little transfer exercise, because your files are named differently. Also, you should try to understand what it does, not blindly copy-paste and execute it.
    – Panki
    Jun 21, 2021 at 13:03

2 Answers 2

1

With the GNU implementation of tar, you could write an extract script like:

#! /bin/sh -
PROGNAME="$0" exec tar -zxvvf - --to-command='
  case "$TAR_FILENAME" in
    (*.tar.gz | *.tgz) exec "$PROGNAME";;
    (*) set -o noclobber
        mkdir -p -- "$(dirname -- "$TAR_FILENAME")" &&
          exec cat > "$TAR_FILENAME"
  esac' 3<&-

To be invoked as:

path/to/extract < flag_999.tar.gz

in your case.

That script will call itself recursively via tar's --to-command for each archive member whose name ends in .tar.gz or .tgz. It will extract files on the fly without storing the intermediate tar files on disk.

Note that it only extracts regular files and doesn't restore any file metadata.

6
  • Sorry I tried the above script but it didn't work.
    – farzan
    Jun 27, 2021 at 5:28
  • @farzan In which way did it not work? Jun 27, 2021 at 5:38
  • @farzan, FWIW, that script works for me (in that it eventually extracts the contents of flag.txt) on your file with GNU tar 1.34 on Debian GNU/Linux. Jun 27, 2021 at 6:36
  • ./script.sh: 2: exec: /home/rasiq/Downloads/flag_999.tar.gz: Permission denied Even after chmod +x
    – farzan
    Jun 29, 2021 at 5:31
  • @farzan, did you start it as ./script.sh < /home/rasiq/Downloads/flag_999.tar.gz? Though even if you didn't, I can't see how you could get that error message with this script as written. Jun 29, 2021 at 5:44
0

This weird file was a nice stress test for ratarmount. It basically works out of the box with the --recursive option but has the problem that the file path grows too long to something like mountpoint/flag_998.tar.gz/flag_997.tar.gz/flag_996.tar.gz/flag_995.tar.gz/flag_994.tar.gz/.... To avoid that, I added a more generic command line option to the existing --strip-recursive-tar-extension so that you can now transform the mount point of a recursive tar arbitrarily by using --transform-recursive-mount-point. This is currently not yet fully released but you can already try it out like this:

python3 -m pip install --user --force-reinstall 'git+https://github.com/mxmlnkn/ratarmount.git@develop#egginfo=ratarmountcore&subdirectory=core'
python3 -m pip install --user 'git+https://github.com/mxmlnkn/ratarmount.git@develop#egginfo=ratarmount'

ratarmount --recursive --transform-recursive-mount-point '.*/' '' flag_999.tar.gz mountpoint
ls -lA mountpoint
# drw-r--r-- 1 root root    146 May 24  2019 flag_0.tar.gz
# drw-r--r-- 1 root root  17331 May 24  2019 flag_100.tar.gz
# drw-r--r-- 1 root root  17490 May 24  2019 flag_101.tar.gz
# drw-r--r-- 1 root root  17652 May 24  2019 flag_102.tar.gz
ls -lA mountpoint/flag_0.tar.gz/
# -rw-r--r-- 1 root root 33 May 24  2019 flag.txt
cat mountpoint/flag_0.tar.gz/flag.txt

And there you have it. If everything works correctly, your original archive basically contains only some kind of hexadecimal hash inside a single file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.