Skip to content

About

Steganography Workshop #7 workshop.ivancyber.uk

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

BCUCompSoc Cyber Workshop 07 – StegoLab: Hidden in Plain Sight

Date: TBC · Time: 2 hours · Room: TBC · Host: Ivan Khan (Head of Cybersecurity) Level: Beginner-friendly · Language: Python · Needs: Python 3.10+, Pillow, Git, VS Code

Part of the BCUCompSoc cybersecurity series. Semester 1 was about networks (recon scanning, PCAP analysis). This workshop opens the digital forensics block: finding evidence hidden inside files.


The scenario

The night before the CyberSecurity CTF Hackathon, four memes appeared in a public channel. They look harmless. But the committee suspects that someone used them to leak the challenge answers.

You are the forensic analyst. Your job:

  1. Build StegoLab, a small Python tool that can hide data inside images and detect it.
  2. Use it to examine the four suspect images in evidence/.
  3. Decide which images carry hidden data, where it is hidden, recover it, and back every claim with evidence.

Fictional scenario. The images in this repo were generated by code for this workshop. No real people, accounts or answers are involved.


What is steganography?

Cryptography hides what a message says. Steganography hides that a message exists at all. A file looks completely normal, but carries a secret.

It matters in cybersecurity because:

  • Malware hides commands or code inside images (it has been used to slip past filters).
  • Insiders smuggle data out of organisations inside innocent-looking files.
  • CTFs love it: steganography challenges appear in almost every competition.
  • Forensic analysts must know where data can hide in order to find it.

Three places data can hide in an image

Where How it works How an analyst finds it
After the end of the file Image viewers stop reading at the end marker (IEND in PNG, FF D9 in JPEG). Anything after it is ignored, but still there. Look for bytes after the end marker.
Metadata Images carry hidden text fields: camera details, software, comments. Viewers rarely show them. Read the PNG text chunks and EXIF fields.
The pixels themselves (LSB) Each colour value (0–255) is changed by at most 1 to store one bit. The eye cannot see it. Extract the least significant bits, inspect their statistics and look at the "bit plane".

How LSB hiding works

Every pixel has three colour values: Red, Green, Blue. Each is a number from 0 to 255, stored as 8 bits.

Red value 200 = 1 1 0 0 1 0 0 0
                              ^ least significant bit (LSB)

Hide a 1  ->  201 = 1 1 0 0 1 0 0 1   (a change of 1 out of 255: invisible)

Three hidden bits fit in every pixel. A 480 × 320 image can hide about 57,000 characters.

StegoLab puts a small header in front of the message so it can recognise its own data:

"BCU7" (4 bytes)  +  message length (4 bytes)  +  message (UTF-8)

Why PNG and not JPEG?

PNG is lossless: every pixel is saved exactly. JPEG is lossy: it slightly changes pixel values to save space, which destroys the hidden bits. Try it in the challenge section.


What you will build

StegoLab/
├── main.py              # Prebuilt: command-line interface (hide / reveal / analyse)
├── stegolab/
│   ├── encoder.py       # TASK 1: text <-> bits, header
│   ├── embed.py         # TASK 2: hide and reveal bits in pixels
│   ├── detect.py        # TASK 3: forensic checks
│   └── report.py        # Prebuilt: prints the forensic report
├── tests/               # One test file per task
├── samples/cover.png    # Practise hiding your own messages here
├── evidence/            # The four suspect images (the case)
├── AI_PROMPTS.md        # Prompts for using AI as a tutor
└── PORTFOLIO_README.md  # Template: describe YOUR work for your GitHub

How the parts fit together:

hide:     message -> encoder.py (bits + header) -> embed.py (write LSBs) -> stego.png
reveal:   stego.png -> embed.py (read LSBs) -> encoder.py (parse header, bits -> text) -> message
analyse:  suspect.png -> detect.py (end marker, metadata, LSBs) -> report.py -> forensic report

Before you arrive

Follow SETUP.md. It takes about 5 minutes: install Python, Pillow and Git, then fork and clone this repo.

Agenda

Time Block Checkpoint
00–10 Welcome, the case, safe use Repo cloned, python main.py --help runs
10–25 How images store data: pixels, bits, file structure, metadata Explain the LSB in your own words
25–35 Live demo: hide a message, compare the images, show the bit plane Spot the difference (you can't!)
35–60 Task 1 + Task 2 (core): encoder and embedding Hide and reveal your own message
60–65 Break
65–90 Task 3: forensic checks All tests pass
90–105 The case: analyse the evidence, recover what is hidden Findings with evidence
105–120 Push to GitHub, portfolio README, feedback Repo pushed

The timings are a guide. Understanding matters more than speed.


Tasks

Run all tests at any time:

python -m unittest discover -s tests -t . -v

Each function you need to write has numbered TODO hints and raises NotImplementedError until you replace it.

Core: everyone

Task 1 – stegolab/encoder.py: turn text into bits and back. bytes_to_bits, bits_to_bytes, build_payload, parse_header You are done when: python -m unittest tests.test_task1_encoder -v passes.

Task 2 – stegolab/embed.py: hide bits in pixels and read them back. set_lsb, hide_message, read_lsbs, reveal_message You are done when: python -m unittest tests.test_task2_embed -v passes, and this works:

python main.py hide samples/cover.png "my first secret" my_secret.png
python main.py reveal my_secret.png

Open samples/cover.png and my_secret.png side by side. Can you see any difference?

Task 3 – stegolab/detect.py: the forensic checks. find_appended_data and read_metadata are core. lsb_ratios and make_lsb_plane are stretch. You are done when: python -m unittest tests.test_task3_detect -v passes.

The case

python main.py analyse evidence/meme_01.png --plane meme_01_plane.png

Run it on all four images. For each one, answer:

  1. Is something hidden? Where: after the end of the file, in the metadata, or in the pixels?
  2. What does it say? Some data may need one more decoding step. (Does a string ending in = look familiar?)
  3. What is your evidence? Quote the report output and the bit plane.
  4. How confident are you? "No indicators found" does not prove an image is clean.

Open the _plane.png images. Smooth areas of a normal image make neat stripes. What does hidden data look like?

Stretch: if you finish early

  • Complete lsb_ratios and make_lsb_plane (Task 3.3 and 3.4).
  • Add a --password option that XOR-encrypts the message before hiding it, so finding the bits is not enough.
  • Spread the bits across random pixels chosen from a seed (the password), instead of starting at the first pixel.
  • Support hiding a whole file, not just text.

Challenge: break it

  • Save your stego image as a JPEG with Pillow, then try to reveal the message. What happens and why?
  • Hide a message in a noisy photo you took yourself. Does the bit plane still give it away?
  • Research the chi-square attack on LSB steganography and implement it as a new check in detect.py.
  • Compare your tool with professional ones: exiftool (metadata), binwalk (appended and embedded files) and zsteg (LSB). What do they find that StegoLab misses?

Writing up your findings

Add a FINDINGS.md to your repo, with one section per image:

Field Example
File meme_0X.png
Verdict Hidden data found / No indicators found
Location After IEND / Metadata field Comment / Pixel LSBs
Evidence The exact report line, a screenshot of the bit plane
Recovered content What it says, and any decoding steps you used
Confidence High / Medium / Low, and why

Finish with two sentences: what would you recommend the society does to stop this kind of leak?


Safe and responsible use

  • Only analyse files you are allowed to analyse: the workshop evidence, or images you created.
  • Steganography has legitimate uses (watermarking, privacy) and harmful ones (malware, data theft). This workshop is about detection and understanding.
  • Do not use these techniques to bypass your employer's, the university's or anyone else's security controls.
  • Do not upload private photos to the internet to test this. Metadata can reveal where and when a photo was taken. Check your own photos' EXIF data before you post them.

Using AI as a tutor

You may use ChatGPT, Claude or Gemini to explain concepts, debug errors and review your code. See AI_PROMPTS.md.

The workshop rule: do not commit code you cannot explain. For every function, you should be able to say what goes in, what comes out, and why.

Make it your portfolio piece

  1. Fill in PORTFOLIO_README.md with your work, then rename it to README.md (keep this guide as WORKSHOP_GUIDE.md).
  2. Add FINDINGS.md and a screenshot of a bit plane.
  3. Commit in small steps with clear messages, for example:
    • Implement bit encoder and header
    • Add LSB embedding and extraction
    • Add forensic checks for appended data and metadata
    • Document case findings
  4. Push to GitHub.

Further learning


BCUCompSoc · Cybersecurity Workshops · Don't just build something that works. Understand why it works.

About

Steganography Workshop #7 workshop.ivancyber.uk

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages