#============================================================#
#                    Stegosploit tutorial                    #
#============================================================#

Here are a couple questions to answer, you should be able to 
answer them by looking over the slides. Do these before building
the Stegosploit inorder to have a basic understanding of what 
Stegosploit is doing. 
Hand-in the solutions at the end of the tutorial. 

1. How does Stegosploit use steganography and polyglots?

2. What is the key difference between <script src> and 
<img src>? 

3. What is the difference between the 7th Bit layer vs. the 
0th Bit Layer?

4. How does Stegosploit hide the exploit code in the image?

5. How many iterations should encoding a PNG take?

6. Why do we need to encode a JPG multiple times? What is 
the encoding called?

7. Why does Stegosploit care about HTML5 Canvas? 
    
8. Which header section do we edit to make more space?

9. Why is Stegosploit hard to use at this time?

10. What are the 3 best ways to stop a Stegosploit?

#============================================================#
#                  Let's build a Stegosploit                 #
#============================================================#

- Download the .zip from Arnold's website, you will need 
this throughout the tutorial.

- There is a folder and a pdf located in the zip. In order to get
the Stegosploit tools we need to use the PDF! Open the PDF and look
at the end of Stegosploit section to find the toolkit.
(Hint: The PDF is a Polyglot and you can find the command to extract 
Stegosploit tools from the PDF.)
(Hint 2: Try CRTL+F "stegosploit_tool.png" without the quotations)


- UPDATE: The link in the PDF Polyglot is outdated so we have actually included the tool
kit in the ZIP. 

- In order to use this toolkit, you must host a web server
controlled by you. cd into the "stego" directory inside the toolkit and 
Use the command:
    python -m SimpleHTTPServer port
    
- Go into your browser and type in:
    localhost:port
    
- You should see all the files in "stego" directory. 

- Now click on the "iterative_encoding.html" file in
your browser. 

- We are going to start with the steganography part of 
the Stegosploit first.

- Load up the monaLisa.png into the encoding tool

- Now, let's encode some _exploit_ on Bit Layer 7 and 
with a Grid of 2. You can make the exploit any javascript code you want,
but for simplicity lets make it: alert("Stegosploit got you!");

- Click process and then click iterate once the code 
is encoded into the image. This will be on the MSB Layer. It should be 
easy to see the exploit that has been encoded.

- Great, now you should have the encoded image downloaded as
"stego.PNG". Move this picture into the "stego" directory.

- Lets use the image_layer_analysis.html to see each Bit Layer 
of the image. Click on this tool and load up the image to see
the layers that make up the image. Try comparing the original to
the encoded image. 

- The encoded picture has the exploit in it but we need a way to decode it.
This is where the HTML5 Canvas Element and decoder code comes in.
The HTML5 Canvas will read the pixel data and our Javascript will decrypt the
exploit from that pixel data.

- Lets add our decoder code to the PNG header and make the image into a Polyglot
(Can be run as HTML and as a PNG file)

- Run the command (for PNG): ./imajs/html_in_png.pl exploits/decoder_cve_2014_0282.html ./stego.PNG polyglot.png

- Now, you have created the Stegosploit! To test it, you
must now run another server (which is provided). 
Use the command: python PythonServer.py

- Now go to localhost:8002, if the port is taken, edit
the PythonServer.py to a free port

- Click on the polyglot.png then click the image

- And now you have created the StegoSploit 

- You can view the code that has been inserted into the 
image by using the command:
    less polyglot.png
   

    
    