Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Add challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
willbarkoff committed May 12, 2020
1 parent ffc3ccf commit de6730d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Generated image
nhb.out.png
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# HackDalton: Secret Agent

## Problem:

Agent, the fate of the world rests on you. Terrorists have taken control of a nuclear arsenal and now have control of a stockpile of nuclear weapons. They have locked themselves in the arsenal with a password, and when entered wrong or broken into, the nuclear missiles will automatically be launched and strike capital cities around the world. The terrorists are communicating the password between each other using [this](./nhb.out.png) image. The world is doomed unless you can crack the code, special agent.

## Hints
1. Look into least-significant-bit encoding.
2. Check out [this](https://github.com/auyer/steganography) library.

Look at the writeup [here](./WRITEUP.md).
10 changes: 10 additions & 0 deletions WRITEUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# HackDalton: Secret Agent (Writeup)

> Warning! There are spoilers ahead
The image is encoded with least significant bit encoding (LSB), a form of [steganography](https://en.wikipedia.org/wiki/Steganography)

From the wikipedia page for steganography:
> For example, a 24-bit bitmap uses 8 bits to represent each of the three color values (red, green, and blue) of each pixel. The blue alone has 28 different levels of blue intensity. The difference between 11111111 and 11111110 in the value for blue intensity is likely to be undetectable by the human eye. Therefore, the least significant bit can be used more or less undetectably for something else other than color information. If that is repeated for the green and the red elements of each pixel as well, it is possible to encode one letter of ASCII text for every three pixels.
A script to encode and decode images can be found at [main.go](./main.go).
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/HackDalton/secret-agent

go 1.13

require github.com/auyer/steganography v1.0.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/auyer/steganography v1.0.0 h1:0jty6tzmLff01Oe1Nz197XcutYV+LhgUhySCbfNQUrI=
github.com/auyer/steganography v1.0.0/go.mod h1:Q2qN+f1ixaXnKTCT4xkSDCZ/5NiOpUeTgOCLwQdJD+A=
52 changes: 52 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"bufio"
"bytes"
"fmt"
"image/png"
"os"

"github.com/auyer/steganography"
)

func check(err error) {
if err != nil {
panic(err)
}
}

func main() {
inFile, err := os.Open("nhb.in.png") // opening file
check(err)
reader := bufio.NewReader(inFile) // buffer reader
img, err := png.Decode(reader) // decoding to golang's image.Image
check(err)

w := new(bytes.Buffer) // buffer that will recieve the results
err = steganography.Encode(w, img, []byte("hackDalton{w3lc0m3_t0_l4ngl3y_kgLQq-1mHU}")) // Encode the message into the image
check(err)
outFile, err := os.Create("nhb.out.png") // create file
check(err)
_, err = w.WriteTo(outFile) // write buffer to it
check(err)
err = outFile.Close()
check(err)

fmt.Println(decodeFile("nhb.out.png"))
}

func decodeFile(file string) string {
inFile, err := os.Open(file) // opening file
check(err)
defer inFile.Close()

reader := bufio.NewReader(inFile) // buffer reader
img, err := png.Decode(reader) // decoding to golang's image.Image
check(err)

sizeOfMessage := steganography.GetMessageSizeFromImage(img) // retrieving message size to decode in the next line

msg := steganography.Decode(sizeOfMessage, img) // decoding the message from the file
return string(msg)
}
Binary file added nhb.in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de6730d

Please sign in to comment.