Today I've learned: Compression and Archiving

Search for a command to run...

No comments yet. Be the first to comment.
Intro IoT nowadays is everywhere. Now there’s about 20 billion IoT devices. In 2031 there will be around 35 billion IoT devices connected to the internet. Interesting information about IoT devices & other stuff When more network devices we have and m...

Intro When I was learning cybersecurity topics in the past year, I’ve grasped lots of different tools and techniques. Some of the most iconic for me were: CAN BUS (controller area network) Radio Frequency Cryptography I was lucky to have an oppo...

What is Enumeration? It is one of the most important parts of Penetration Testing process. It is identifying all of the ways we could attack a target. We must do our best in this phase. Long story short - enumeration is collecting as much information...

Transferring files During any penetration testing exercise, it is likely that we will need to transfer files to the remote server. There are few options for this: One method is running a Python HTTP server on our machine and then using wget or cUR...

Privilege Escalation Once we gain initial access to a box, we want to thoroughly enumerate the box to find any potential vulnerabilities we can exploit to achieve a higher privilege level. There are checklists for privilege escalation online. A goo...

Cyber Journey
41 posts
Pentesters/hackers often need to share files and scripts. Most of the time we need to send more than one file and sometimes those files can be BIG. That’s where the archiving and compression comes handy.
On Windows machines it’s common case to see .zip files. These are the archives.
Basically compression makes data smaller requiring less storage capacity and making the data easier to send.
There are two types of compression:
Lossy
Lossless
Lossy compression is very good when we need smaller file sizes. It’s efficient and effective, but it also has draw backs. Files lose integrity of the information.
Some of the most popular Lossy compression algorithms are -
.mp3
.mp4
.jpg
If we compare the sounds of .mp3 file and same sounds of .flac (uncompressed) file, we could hear the difference. Same with .nef (RAW) and .jpeg photos.
.nef (RAW) size would be ~40MB and .jpeg would compress the same photograph to around 11MB.
We cannot use lossy compression when dealing with software sending because data integrity is crucial.
There are several ways to compress files. They use different compression algorithms and have different compression ratios.
First thing that we need to do before compressing files is to combine them into one file.
For that we’ll use tar .
Tar stands for “tape archive”, because in the prehistoric days systems used tapes to store data
When we create single file with tar it is called archive, tar file, tarball.
Let’s create example files to combine them into one file:
echo "Example file 1" > example1
echo "Example file 2" > example2
echo "Example file 3" > example3
Let’s see the files that we’ve created (use long listing to see the file size):
└─# ls -l
total 12
-rw-r--r-- 1 root root 10 Dec 30 05:35 example1
-rw-r--r-- 1 root root 19 Dec 30 05:35 examaple2
-rw-r--r-- 1 root root 23 Dec 30 05:35 examaple3
Now we can combine the files into one file:
tar -cvf Example.tar example1 example2 example3
example1
example2
example3
c - stands for create
f - write to the following file
v - optional parameter which lists files that tar is dealing with
You can check the options using tar —help
Now when we long list our files we can see that there’s a new file called Example.tar:
ls -l
-rw-r--r-- 1 root root 10 Dec 30 05:35 example1
-rw-r--r-- 1 root root 15 Dec 30 05:46 example2
-rw-r--r-- 1 root root 15 Dec 30 05:46 example3
-rw-r--r-- 1 root root 10240 Dec 30 05:46 Example.tar
You can see that the size of tarball is way bigger than the files sizes combined. It becomes less significant with larger files.
We can see what files are inside the tarball without extraction by doing so:
tar -tvf Example.tar
-rw-r--r-- root/root 10 2024-12-30 05:35 example1
-rw-r--r-- root/root 15 2024-12-30 05:46 example2
-rw-r--r-- root/root 15 2024-12-30 05:46 example3
To extract files we can use x switch:
tar -xvf Example.tar
example1
example2
example3
Keep in mind that by default if an extracted file already exists, tar will replace it with extracted file.
gzip (GNU zip) - it uses the extension of .tar.gz or .tgz
bzip2 - it uses the extension of .tar.bz2
It works similarly to gzip but has better compression ratios which mean that compressed files will be smaller
To decompress use bunzip2
compress - it uses the extension of .tar.z
This is least commonly used tool, but it’s easy to remember.
To decompress use uncompress
You can also use gunzip do decompress files which were compressed using compress
Let’s compress our Example.tar using gzip
gzip Example.tar
ls -l
-rw-r--r-- 1 root root 10 Dec 30 05:35 example1
-rw-r--r-- 1 root root 15 Dec 30 05:46 example2
-rw-r--r-- 1 root root 15 Dec 30 05:46 example3
-rw-r--r-- 1 root root 199 Dec 30 05:46 Example.tar.gz
You can see that now our compressed file size is only 199. Before it was 10240!
Let’s decompress it:
gunzip Example.tar.gz
ls -l
-rw-r--r-- 1 root root 10 Dec 30 05:35 example1
-rw-r--r-- 1 root root 15 Dec 30 05:46 example2
-rw-r--r-- 1 root root 15 Dec 30 05:46 example3
-rw-r--r-- 1 root root 10240 Dec 30 05:46 Example.tar
As you can see our file size is same as before - 10240.
I’m learning using this book:
Linux Basics For Hackers by OCCUPYTHEWEB (MASTER OTP)