<?xml version="1.0"?>
<!--Copyright Brian Starkey 2013-->
<page title="Can You Find It?" dir="misc/gchq" filename="gchq4" type="windowpage" 
    root="/xml_95" date="23rd October 2013">
<window title="GCHQ: Can You Find It? (4)">
	<menu>
		<menu-item name="File">
			<!--<pdf-subitem name="Get PDF"/>-->
			<home-subitem name="Home" href="{/page/@root}"/>
			<menu-subitem name="XML" href="gchq4.xml"/>
		</menu-item>
		<!--include common menu items (dynamically generated)-->
        <autogen type='category' category='all'/>
	</menu>
	<substance>
	<locations name="{/page/@title}">
            <folder name="Challenge 1" href="./1"/>
            <folder name="Challenge 2" href="./2"/>
            <folder name="Challenge 3" href="./3"/>
            <folder name="Challenge 4" href="./4">
                <!--<leaf class="pdfleaf" name="proj.pdf" href="proj.pdf" />-->
                <!-- img="/images/pdf_icon.gif" -->
                <leaf class="sectionleaf" name="Hiding in Plain Sight" 
                    href="#Hiding%20In%20Plain%20Sight"/>
                <leaf class="sectionleaf" name="The Solution" 
                    href="#The%20Solution"/>
            </folder>
            <folder name="Challenge 5" href="./5"/>
            <folder name="Files">
                <!--<leaf class="pdfleaf" name="proj.pdf" href="proj.pdf" />-->
                <!-- img="/images/pdf_icon.gif" -->
                <leaf class="codeleaf" name="challenge1.c" 
                    href="files/challenge1.c"/>
                <leaf class="otherleaf" name="comp1.key" 
                    href="files/comp1.key"/>
                <leaf class="codeleaf" name="challenge2" 
                    href="files/challenge2"/>
                <leaf class="codeleaf" name="challenge3" 
                    href="files/challenge3"/>
                <leaf class="codeleaf" name="rsa.py" 
                        href="files/rsa.py"/>
                <leaf class="codeleaf" name="challenge4" 
                    href="files/challenge4"/>
                <leaf class="imgleaf" name="comp3.jpg" 
                    href="files/comp3.jpg"/>
            </folder>
	</locations>
	<window-contents>
        <row>
	    <section-title name="Challenge 4"/>
            <image style="float: none; width: 80%; max-width: 650px;
                margin-left: auto; margin-right: auto;"
                src="images/challenge4.jpg">The fourth challenge</image>
            <section-content>
            <p>
            This picture is the fourth challenge, and is my favourite of the 
            lot. Straight away you might be able to guess the answer, but it
            will reveal itself in due time.
            </p>
            <sub-title name="Hiding in Plain Sight"/>
            <p>
            Hiding things in images is not a new thing, there are all sorts
            of presentations and white papers on it - in fact it's been shown
            to be a good attack vector for hacking computers.
            </p>
            <p>
            The easy thing to check is the <a href=
            "http://en.wikipedia.org/wiki/Exchangeable_image_file_format">
            EXIF</a> data attached to the image:
            <pre>
$ exiftool comp3.jpg 
ExifTool Version Number         : 9.13
File Name                       : comp3.jpg
Directory                       : .
File Size                       : 61 kB
File Modification Date/Time     : 2013:09:14 23:03:53+01:00
File Access Date/Time           : 2013:10:24 22:17:43+01:00
File Inode Change Date/Time     : 2013:09:14 23:03:53+01:00
File Permissions                : rw-rw-r--
File Type                       : JPEG
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : inches
X Resolution                    : 200
Y Resolution                    : 200
Image Width                     : 350
Image Height                    : 246
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:4:4 (1 1)
Image Size                      : 350x246
            </pre>
            </p>
            <p>
            That doesn't really tell us anything interesting. I guess that would
            be too easy. Next I checked the file for any obvious text strings
            hidden in it's binary code. Using <icode>hexdump</icode> and 
            <icode>grep</icode> (you do know how to use <icode>grep</icode>
            by now right? If not, <b>learn it!</b>) I didn't spot any obvious 
            long web-address like strings, but I did find something interesting.
            </p>
            <sub-title name="The Solution"/>
            <image style="float: none; width: 80%; max-width: 650px;
                margin-left: auto; margin-right: auto;"
                src="images/challenge4_hex.png">mmm, hex</image>
            <p>
            This command finds sequences of 4 capital letters - I have
            specifically used it here to illustrate the point with a minimum of
            noise. It wasn't the first thing I tried!
            </p>
            <p>
            Ignore the sections of the alphabet - they're just parts of the file
            which happen to contain sequential numbers corresponding to capital
            letters.
            </p>
            <p>
            Anyway, notice that on the
            first line we have "JFIF" and on the last-but-one line we have
            "JFIF" again...
            </p>
            <p>
            JFIF stands for <i><a href=
            "http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format">
            JPEG File Interchange Format</a></i>, and if you have a
            look at <a href=
            "http://en.wikipedia.org/wiki/JPEG#Syntax_and_structure">
            Wikipedia</a> it has a breakdown of the markers used in the 
            JPEG file format.
            A JPEG file always starts with 0xFFE0, then a 16 bit field, then
            JFIF - a sort of magic number the computer can look for to determine
            that the file is a JPEG.
            </p>
            <p>
            What's strange is, our picture seems to have a second one of these
            at the end of it? In fact, if you look a little closer, it comes
            immediately after 0xFFD9, which marks the end of the image, and the
            file terminates with another 0xFFD9. In short, the image we 
            downloaded from the website has a second image stuck on the end of 
            it!
            </p>
            <p>
            Most (all?) image viewers will read from the start of a file until
            they reach to 0xFFD9 marker and then stop, assuming that's the end
            of the file. So now we have to cut the second image off the end of
            the file and have a look at it
            </p>
            <p>
            I used <icode>dd</icode>, which is a generic binary stream copier.
            I basically told it to take all the bytes starting at the start of 
            the second image, and put them into a new file:
            </p>
            <pre>
$ dd ibs=1 skip=52180 count=10288 if=comp3.jpg of=comp4.jpg
            </pre>
            <p>
            The command basically says <i>"working one byte at a time, starting
            at position 52,180 in comp3.jpg, copy 10,288 bytes to comp4.jpg".
            </i>
            The offset 52,180 corresponds to the start of the second image, hex
            address 0xCBD4. 10,288 is all the bytes that are left - the file
            size is 62,468; (62,468 - 52,180) = 10,288.
            </p>
            <image style="float: none; width: 80%; max-width: 650px;
                margin-left: auto; margin-right: auto;"
                src="images/challenge4_ans.jpg">Ta-da! comp4.jpg</image>
            <p>
            So there we have it! This image was hidden at the end of the one we
            downloaded from the website and clearly contains our next clue,
            <a href="http://www.eveningstandard.co.uk/colossus">
            www.eveningstandard.co.uk/colossus</a>. The 4th answer is 
            <b><a href=
            "http://en.wikipedia.org/wiki/Colossus_computer">colossus</a></b>, 
            which is actually the computer in the first picture - it was used at
            Bletchley park during WWII to help crack the Lorenz cipher. 
            </p>
            <p>
            So that's that, probably the easiest challenge so far - let's take
            a look at <a href="./5">Challenge 5</a>.
            </p>
            <image style="float: none; width: 80%; max-width: 650px;
                margin-left: auto; margin-right: auto;"
                src="images/4down.png"/>
            </section-content>
        </row>
    <comments/>

	</window-contents>
	</substance>
</window>

</page>


