> For the complete documentation index, see [llms.txt](https://va9ab0nd.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://va9ab0nd.gitbook.io/notes/forensics/steganography-ctf.md).

# Steganography - CTF

Steganography is the practice of concealing a message, file, or information within another non-secret data or medium, such as an image, audio file, or text, in a way that the existence of the hidden.

In CTF setting we try to find a text called as "flag" that's deliberately hidden in the given IMAGE ,AUDIO,ZIP or PDF file.Below are the few Techniques and tools used to solve the challenges.I will be updating the below notes as i learn.

Note - The Below notes are collected from Different Sources and Articles.

## Image Steganography

### Automated Analysis

<https://www.aperisolve.com/>

### Image Properties

After you receive the image ,the first thing to do is to find the Image type, property, metadata, comments,strings in the image file.

```bash
#File type
> file image_file

#Metadata and commments
> exiftool image_file (or) exiv2 file

#strings in image
> strings image_file

#view image
> eog image_file
```

***

### Binwalk

Binwalk is a powerful tool used for analyzing and extracting hidden data within binary files, including images or any File type \[firmware,audio,data ...].

```bash
> sudo apt install binwalk     # Insllation
> binwalk file                 # Displays the embedded data in the given file
> binwalk -e file              # Displays and extracts some files from the given file
> binwalk --dd ".*" file       # Displays and extracts all files from the given file
```

### Foremost

Another common tool to find hidden files is **foremost**.Foremost is a digital forensic tool used for file recovery and analysis. It is particularly useful for extracting files from disk images and other types of binary data

```bash
> sudo apt-get install foremost
> foremost -v -i file.img -o output
> foremost image_file

#Discovered files will appear inside the folder "output"
```

***

### Bulk Extractor

This tool can scan an image and will **extract pcaps** inside it, **network information (URLs, domains, IPs, MACs, mails)** and more **files**. You only have to do:

```bash
# install
> sudo apt install bulk_extractor

# usage
> bulk_extractor file.img -o out_folder
```

***

### Steghide

Steghide is a popular tool used for hiding data within various file formats, such as images and audio files.Steghide supports JPEG, BMP, WAV,GIF and AU file formats. File formats like PNG are not supported with this tool.&#x20;

```bash
# Installation :
> sudo apt-get install steghide

# Image Info :
> steghide info image

# Embed the cipher text in normal file :
    Use the -p option to specify a passphrase.
    Use the -Z option to enable compression.
    Use the -e option to specify an encryption algorithm.   
> steghide embed -ef <data_file> -cf <cover_file>
> steghide embed -ef <data_file> -cf <cover_file> -p MySecretPassphrase
> steghide embed -ef <data_file> -cf <cover_file> -z 8 # steghide has 9 level (1 to 9) for compression
> steghide --encinfo  # list all encryption methods supported
> steghide embed -ef secret.txt -cf car.jpeg -z 8 -e rc2  # encryption algoritham

# Extract the cipher text
> steghide extract -sf <stego_file>
enter passphrase       #password

# Audio Steganography: 
AU and WAV audio formats are supported by steghide.Command and process is same as image steganography
> steghide info voice.wav
> steghide embed -ef secret.txt -cf voice.wav
> steghide extract -sf voice.wav 
```

**simple python code to brute force steghide**

```python
for passphrase in $(cat $2); do
  response=$(steghide extract -sf $1 -p "$passphrase" 2>&1);
  if [[ ! $response == *"could not extract"* ]]; then
    printf "%s\\n\\n" "$response";
    exit
  fi
done
```

***

### Stegseek

stegseek is an actively maintained and well-supported tool. To set up easily, we need to download .deb file [from the release page](https://github.com/RickdeJager/stegseek/releases). Usage is well documented in that page.

```bash
# installation 
>sudo apt install stegseek

# embed 
> stegseek --embed secret.txt car.jpg 

# extract
> stegseek image.jpg <wordlist>

# seed - It will try to crack the code with every embedding pattern possible
> stegseek --seed image.jpg output.txt
```

***

### Stegcracker

This is actually a python package to brute-force stego password.&#x20;

```bash
# installation
> sudo apt install stegcracker 

# cracking
> stegcracker <file> <wordlist>
```

***

### Jsteg

JSteg is a package for hiding data inside JPEG files using a technique known as JPEG steganography.

```bash
> sudo wget -O /usr/bin/jsteg <https://github.com/lukechampine/jsteg/releases/download/v0.1.0/jsteg-linux-amd64>
> sudo chmod +x /usr/bin/jsteg
> sudo wget -O /usr/bin/slink <https://github.com/lukechampine/jsteg/releases/download/v0.2.0/slink-linux-amd64>
> chmod +x /usr/bin/slink

#hide 
> jsteg hide <in.jpg> <secret_file_name> <out.jpg>

#decode
> jsteg reveal <in.jpg> <output_file_name>
```

***

### Pngcheck

A tool to test PNG image files for corruption, display size, type, compression info.

Pngcheck is the official PNG tester and debugger. Originally designed simply to test the CRCs within a PNG image file (e.g., to check for ASCII rather than binary transfer), it has been extended to check and optionally print almost all the information about a PNG image and to verify that it conforms to the PNG specification. It also includes partial support for MNG animations.

```bash
> sudo apt install pngcheck

# Basic Information
> pngcheck -v image.png

# check for corruption and verify the integrity of a PNG image
> pngcheck -t image.png

# compression Information
> pngcheck -c image.png

> wine tweakpng.exe
```

***

### Zsteg

zsteg supports various techniques to extract all data from PNG and BMP files.

**Detects:**

1. **LSB (Least Significant Bit) Steganography**: `zsteg` can detect and analyze LSB steganography, which involves hiding data in the least significant bits of image pixels.&#x20;
2. **MSB (Most Significant Bit) Steganography**: `zsteg` can also detect and analyze MSB steganography, where data is hidden in the most significant bits of image pixels.
3. **Zlib-compressed Data**: `zsteg` is capable of detecting and extracting data that has been compressed using the zlib compression algorithm. This technique involves compressing the hidden data before embedding it into the image.
4. **Color Channel Steganography**: `zsteg` can analyze steganography techniques that involve hiding data within specific color channels of the image, such as Red, Green, or Blue channels.
5. **Various Payload Types**: `zsteg` supports extracting various payload types, including bitmaps (`b1`, `bgr`, etc.), LSB (`lsb`), and coordinates (`xy`), allowing you to analyze different types of hidden data within the image.

```bash
# installation 
> sudo gem install zsteg

# Analyze an image for all possible types of hidden data
> zsteg <image_file>

# Analyzing LSB (Least Significant Bit) Steganography
> zsteg -a image.png  
> zsteg -lsb image.png 

# Analyzing MSB (Most Significant Bit) Steganography
> zsteg -m <image_file> 
> zsteg -msb image.png   

# Extracting Specific Payloads
#Replace <payload> with the desired payload type (e.g., b1, bgr, lsb, xy).         
> zsteg <image_file> -e <payload>

# extract based on regex
> zsteg <image_file> -E '<regex>'
> zsteg lsb image.pnf | grep -oE "ctf{.*?}" --color none
```

***

### Stegnow

*Stegsnow* is a tool for concealing messages in text files by appending tabs and whitespaces at the end of lines.The encoding used by snow relies on the fact that whitespaces and new lines won't be displayed in text editors.

```bash
> sudo apt install stegsnow

> stegsnow -C -m "Attack At Dawn" -p "hail-hydra" NewColossus.txt NewColossusMod.txt

> stegsnow -C -p "hail-hydra" NewColossusMod.t
```

***

### Stegoveritas

Stegoveritas has other features as well such as color correcting images

```bash
# installation 
> pip3 install stegoveritas

# Analyzing Images
> stegoveritas <image_file>

# Extracting Hidden Data
> stegoveritas <image_file> --extract <output_directory>
```

***

### Stegsolve.jar

It is used to analyze images in different planes by taking off bits of the image.Stegsolve enables you to manipulate individual bits of the image, such as flipping or inverting them. This feature can be useful for revealing hidden data encoded in the least significant bits of the image.Providing features for viewing images in different color planes and manipulating individual bits.

```bash
# installation 
> wget <http://www.caesum.com/handbook/Stegsolve.jar> -O stegsolve.jar
> chmod +x stegsolve.jar
> mkdir bin
> mv stegsolve.jar bin/

# usage
> java -jar stegsolve.jar

```

***

### Tesseract

Tesseract is an optical character recognition (OCR) tool used to extract text from images.Use tesseract to scan text in image and convert it to .txt file.

<pre class="language-bash"><code class="lang-bash"># Installation 
> sudo apt-get install tesseract-ocr
> sudo apt-get install tesseract-ocr-eng  # for English language support

<strong># usage
</strong><strong>> tesseract &#x3C;input_image> &#x3C;output_text>
</strong>
# perform OCR on the image
> tesseract image.jpg output.txt -l eng --psm 3

</code></pre>

***

### Xbarimg

It is a tool used to scan and decode QR codes from image files

```bash
# Installation
> sudo apt-get install zbar-tools

# Usage
> zbarimg <file-name>
# Note: Zbar can also decode QR code by webcam, for this install the following tool,

> sudo apt-get install zbarcam
```

***

## Zip file \[decompress,bruteforce]&#x20;

<pre class="language-bash"><code class="lang-bash"># zip file info 
zipdetails -v
<strong>zipinfo 
</strong>
# unzip 
> unzip example.zip
> unzip example.zip -d myfolder

# unzip a zlib 
> zlib-flate -uncompress &#x3C; input.zlib > output.txt

# unzip a gzip
> gunzip filename.gz
> gzip -d filename.gz

# repair Corrupted Zip file 
> zip -FF input.zip --out output.zip

# Bruteforce a Zip password
fcrackzip -D -u -p rockyou.txt filename.zip

# crack 7z 
> 7z2hashcat32-1.3.exe filename.7z. 
> john --wordlist=/usr/share/wordlists/rockyou.txt hash

# crack using john
sudo apt install john-the-ripper
> zip2john file.zip
> zip2john flag.zip >> hash.txt
> cat hash.txt

# fcrackzip
> sudo apt install fcrackzip
> fcrackzip -v -b -u &#x3C;file_name.zip>
dictonary attack 
> fcrackzip -v -u -D -p &#x3C;path_to_wordlist_file> &#x3C;file_name.zip>
</code></pre>

***

## Audio file

1. Use `binwalk` first. They may embedded something in the file
2. Use **Audacity**.

   Using [Audacity](https://www.audacityteam.org/) we can see if it has 2 channels.We can suppress one of the channels,This can be done by moving the slider(on the left hand side) in the Audacity window to the left or right.
3. Use **Sonic Visualizer**. Look at spectogram and other few Pane.
4. Use **Deepsound**.
5. Use **SilentEye**.
6. Some of online stegano decoder for music:-<https://steganosaur.us/dissertation/tools/audio>

***

## Text

Use <http://www.spammimic.com/> that can decode hide message in spam text.

***

## Pdf

#### peepdf

```bash
Peepdf is a Python to find out if the file can be harmful or not.
> ./peepdf.py -i pdffile.pdf

> pdfcrack --wordlist=rockyou.txt pdf_file
> pdfcrack -f <file_name> -w <location_of_wordlist_file>
```

Here are more tools for pdf cracking ,you can learn more on your own.

```
qpdf 
PDFStreamdumper 
pdfinfo 
pdfcrack 
pdfimages 
pdfdetach
pdf-parser.py -v <file> 
pdftotext 
pdfid
```

***

## **File Recovery**&#x20;

**File Recovery**: In CTF sometimes we need to repair or recover the seemingly corrupted file to reveal the hidden data. This could involve repairing damaged file headers, reconstructing missing or corrupted sections, or using specialized tools designed for file recovery.

```bash
file <filename>
>>> file: data

> binwalk -e image_file
> foremost -i image_file

# Display file Signature 
> xxd -l8 <filename> 
> xxd -b ./littleschoolbus.bmp | head -n 20
```

**Python code for decoding**

```bash
binary_data = open("littleschoolbus.bmp","rb") # Open the file binary mode
binary_data.seek(54)  #seek to 54 bytes these bytes does not contain any data
data = binary_data.read() # read the binary data
l = []
for i in data:
    l.append(bin(i)[-1])  #make a list of LSB bit
for i in range(0,500,8):
    print(chr(int(''.join(l[i:i+8]),2)),end='') # print the character
```

If the headers are messed up you can look for similar kind of headers of [wikipedia](https://en.wikipedia.org/wiki/List_of_file_signatures) or [filesignature.net](https://www.filesignatures.net/) and try fixing it.

<pre class="language-bash"><code class="lang-bash">Say we are given an image called hack.png,now we use xxd

> xxd -l8 hack.png
45 65 4E 47 0D 0A 1A 0A
#These aren't any valid headers but if you replace the 45 with 89 and replace the 65 with 50 i.e the headers become

89 50 4E 47 0D 0A 1A 0A
#That would make it a valid PNG file and then you can see what's in it.
---------------------------------------------------------------------------

# ghex - view and edit the hex data or hex dump of an image.
> sudo apt install ghex
<strong>> ghex image.jpg
</strong><strong>
</strong><strong>change the first 8 octects to the valid image signature
</strong></code></pre>

***

## GPG

GNU Privacy Guard (GnuPG or GPG),replacement of PGP(Pretty Good Privacy) a free-software tool used to bring out encryption, it features a versatile key management system.

```bash
# Installation
> sudo apt install gnupg

# Usage
---------
# TO CREATE PUBLIC AND PRIVATE KEYS
> gpg --gen-key`

# LIST KEY
> gpg --fingerprint ibaydan

# REGISTER TO KEY SERVER
> gpg --keyserver gpg.mit.edu --send-keys 003D114F

# EXPORT PUBLIC KEY IN ASCII FORMATS
> gpg --armor --output pubkey.txt --export 'ibaydan'

# ENCRYPT A FILE
> gpg --encrypt --recipient 'ibayadan' --output ServerPass.txt.enc ServerPass.txt

# DECRYPT A FILE
> gpg --output foo.txt --decrypt ServerPass.txt.enc

# LIST INSTALLED KEYS
> gpg --list-keys

# DELETE KEY
> gpg --delete-key ibayadan

# DELETE KEY WITH SECRET KEYS
gpg --delete-secret-keys '[[email protected]]
```

***

### Doc Analysis

```
sudo pip3 install -U oletools
olevba -c /path/to/document #Extract macros
```

{% embed url="<https://intezer.com/blog/malware-analysis/analyze-malicious-microsoft-office-files/>" %}
