<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:media="http://search.yahoo.com/mrss/">
  <channel>

    <title>CTFs on less on sec</title>
    <link>https://lessonsec.com/tags/ctfs/</link>
    <description>
      Recent content in CTFson less on sec
    </description>

    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Sun, 17 Apr 2022 14:08:32 &#43;0200</lastBuildDate>
    <atom:link href="https://lessonsec.com/tags/ctfs/index.xml" rel="self" type="application/rss&#43;xml" /><item>
        <title>Walkthrough: BLE CTF</title>
        <link>https://lessonsec.com/posts/walkthrough-ble-ctf/</link>
        <guid isPermaLink="true">https://lessonsec.com/posts/walkthrough-ble-ctf/</guid>
        <pubDate>Sun, 17 Apr 2022 14:08:32 &#43;0200</pubDate><description>This CTF has been in my todo list for a good while, finally I had the time to solve it and to publish a walkthrough article on it! The challenge is available at: https://github.</description>
	<content:encoded>&lt;p&gt;This CTF has been in my todo list for a good while, finally I had the time to solve it and to publish a walkthrough article on it!
The challenge is available at: &lt;a href=&#34;https://github.com/hackgnar/ble_ctf&#34;&gt;https://github.com/hackgnar/ble_ctf&lt;/a&gt; and is an awesome tool to learn about BLE and get your feet wet.&lt;/p&gt;
&lt;p&gt;To be fair I expected the CTF to be a bit more security oriented, but I learned way more than I expected, both on BLE technologies and on the tools used to interact with those.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
I&amp;rsquo;m not a fan of walkthrough articles that ignore the request of the creators not to post those.
The reasons I&amp;rsquo;m publishing this article are that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No request by the creator has been made not to post the solutions&lt;/li&gt;
&lt;li&gt;There are plenty of walkthrough articles on this CTF that don&amp;rsquo;t really teach anything and barely explain the solutions&lt;/li&gt;
&lt;li&gt;The CTF is self-hosted and is more of a teaching tool than a proper challenge&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Of course I strongly recommend trying to solve the challenges on your own before checking the solutions here!
Anyway I suggest reading the first part of the articles to gather some useful information about the technologies involved in the challenge.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Without further ado, let&amp;rsquo;s get started!&lt;/p&gt;
&lt;h2 id=&#34;how-does-this-ctf-works&#34;&gt;How does this CTF works?&lt;/h2&gt;
&lt;p&gt;The CTF is composed of a series of challenges hosted on an ESP32 board.
The software required to setup the challenge is in fact a firmware to be installed on the board. I won&amp;rsquo;t enter in details about the installation in this article, but you can find detailed instructions here: &lt;a href=&#34;https://github.com/hackgnar/ble_ctf/blob/master/docs/setup.md&#34;&gt;https://github.com/hackgnar/ble_ctf/blob/master/docs/setup.md&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When the firmware is installed, the ESP32 will host a GATT server with which we can interact to solve the challenges and gather the flags.&lt;/p&gt;
&lt;h3 id=&#34;whats-a-gatt-server&#34;&gt;What&amp;rsquo;s a GATT server&lt;/h3&gt;
&lt;p&gt;GATT is the name of a protocol that is used to exchange data between two Bluetooth Low Energy devices.
This is developed on top of the Attribute Protocol (ATT) and manages device interactions following the advertising and pairing processes.
A GATT Server is a device that stores attribute data locally and provides data access methods to a remote GATT Client paired via BLE.  A client, on the other hand, is a device that access data on a remote GATT Server. When two devices are paired, each can function as both a GATT Server and a GATT Client.&lt;/p&gt;
&lt;p&gt;GATT lists a device’s characteristics, descriptors, and services in a table as either 16 or 32-bits values.
A characteristic is a data value sent between the server and the client.&lt;/p&gt;
&lt;p&gt;These characteristics can have descriptors that provide additional information about them.
Characteristics are often grouped in services if they have purposes related to each other. Services can have several characteristics.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:center&#34;&gt;&lt;img src=&#34;https://lessonsec.com/images/BLE_CTF/gatt_server.jpg#center&#34; alt=&#34;GATT server layout&#34;&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:center&#34;&gt;GATT Server content layout &lt;br /&gt;Credits - Practical IoT Hacking: The Definitive Guide to Attacking the Internet of Things&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;attgatt-basics&#34;&gt;ATT/GATT basics&lt;/h3&gt;
&lt;p&gt;It is possible to interact with a GATT server, by interacting with each of the characteristics available.
It is possible to do that using handles, or UUID: handles define the address of a characteristic, while the UUID works as an identifier, but also gives the user some indication about the content of a characteristic. In general, handles are to be preferred to reference to a particular characteristic, this is because UUID can vary depending on the GATT implementation, while handles are expected to remain immutable for each device.&lt;/p&gt;
&lt;p&gt;As anticipated, UUID contain info about the service or characteristic. These are useful because they are defined by profiles: standards that use known UUID to serve specific information, profiles can be found here: &lt;a href=&#34;https://www.bluetooth.com/specifications/specs/&#34;&gt;https://www.bluetooth.com/specifications/specs/&lt;/a&gt;
While UUID vary depending on the device functionality some UUID remains the same, for example: 0x2800, around which service discovery is built. This UUID allows GATT servers to understand service boundaries without having to know the exact standard the device is following.&lt;/p&gt;
&lt;p&gt;Finally, there are characteristic properties. Properties indicate how to interact with a characteristic and what to expect from it.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:center&#34;&gt;&lt;img src=&#34;https://lessonsec.com/images/BLE_CTF/properties.jpg#center&#34; alt=&#34;properties&#34;&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:center&#34;&gt;GATT chatateristic proprieties  &lt;br /&gt;Credits - devzone.nordicsemi.com&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Properties are defined as an hex value and work as bitmasks, so using bitwise operations it is possible reveal the properties of a characteristic starting from its properties value.&lt;/p&gt;
&lt;p&gt;Properties need to be interpreted knowing Attribute Protocol Packets, these are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Commands         	    (Client -&amp;gt; Server, no response required)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Requests            	     (Client -&amp;gt; Server, response required)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Responses         	    (Server -&amp;gt; Client, it&amp;rsquo;s the response to a request)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Notifications      	    (Server -&amp;gt; Client, no response required - Signal the fact that a&lt;/p&gt;
&lt;p&gt;                 characteristic&amp;rsquo;s value has changed)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Indications        	     (Server -&amp;gt; Client, ACK response required by the client - Similar to&lt;/p&gt;
&lt;p&gt;                notifications)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Confirmations   	    (Client -&amp;gt; Server, it&amp;rsquo;s the response to an indication)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As indicated in the image, the &lt;code&gt;Read&lt;/code&gt; and &lt;code&gt;Write&lt;/code&gt; properties are like permissions, and allow the reading and writing of the characteristic if set.
The other properties are an indication of the behavior of a characteristic in response of an action by the client.&lt;/p&gt;
&lt;p&gt;Actions performed by the client are limited to read and write operations.
While read operations are requests by nature, write operations can either be commands or requests.&lt;/p&gt;
&lt;h2 id=&#34;ctf&#34;&gt;CTF&lt;/h2&gt;
&lt;p&gt;The tools that will be employed for this challenge are: gatttool and hcitool.
There are other tools that can be used, in particular bettercap, which is a bit more user friendly but lacks some functionalities, or libraries that implement GATT operations, that were avoided to allow familiarizing with the tools available on a standard linux system.
I think this &amp;ldquo;Living off the Land&amp;rdquo; approach helps better understanding GATT operations and also leads to a more generally employable approach to solve BLE related tasks. Of course you&amp;rsquo;re free to use the tools you prefer for this challenge.&lt;/p&gt;
&lt;p&gt;Before starting, I suggest familiarizing with the challenge page and to understand how to operate actions relative to the challenge, like reading the score and submitting a flag. The list of the flags at the bottom of the page is really useful, as understanding exactly what to do can be tricky.
There are also hints there, don&amp;rsquo;t be afraid to check those out. None of the hints gives away too much and in certain cases those are needed to understand the challenge and to get the flag.&lt;/p&gt;
&lt;p&gt;NOTE: the score is reset each time the ESP32 is powered off! Keep that in mind.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Let&amp;rsquo;s begin! First thing first, we need to retrieve the device BT MAC address and we can do that using hcitool:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ sudo hcitool lescan
LE Scan ...
78:21:84:80:A2:22 BLECTF
[...]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we know the address for my board is: &lt;code&gt;78:21:84:80:A2:22&lt;/code&gt;, it will vary on yours.&lt;/p&gt;
&lt;p&gt;Once we have the address we can start enumerating services on the GATT server.
The first thing to do is to connect to the board, we will do that using &lt;code&gt;gatttool&lt;/code&gt; and its interactive mode:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -I
[                 ][LE]&amp;gt; connect 78:21:84:80:A2:22
Attempting to connect to 78:21:84:80:A2:22
Connection successful
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we need to enumerate the services, we can do that using the &lt;code&gt;primary&lt;/code&gt; command or by reading the UUID 0x2800.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[78:21:84:80:A2:22][LE]&amp;gt; primary
attr handle: 0x0001, end grp handle: 0x0005 uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0014, end grp handle: 0x001c uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0028, end grp handle: 0xffff uuid: 000000ff-0000-1000-8000-00805f9b34fb
[78:21:84:80:A2:22][LE]&amp;gt; char-read-uuid 0x2800
handle: 0x0001 	 value: 01 18 
handle: 0x0014 	 value: 00 18 
handle: 0x0028 	 value: ff 00 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And in both cases we retrieve services boundaries. The first two services are standard, and contain info about the server itself, while the third is the one we want to work with.&lt;/p&gt;
&lt;p&gt;Now we can enumerate the characteristic of each service. This can be done using the command &lt;code&gt;characteristics&lt;/code&gt; and using the boundaries found as upper and lower limits:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[78:21:84:80:A2:22][LE]&amp;gt; characteristics 0x0001 0x0014
handle: 0x0002, char properties: 0x20, char value handle: 0x0003, uuid: 00002a05-0000-1000-8000-00805f9b34fb
[78:21:84:80:A2:22][LE]&amp;gt; characteristics 0x0014 0x0028
handle: 0x0015, char properties: 0x02, char value handle: 0x0016, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0017, char properties: 0x02, char value handle: 0x0018, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0019, char properties: 0x02, char value handle: 0x001a, uuid: 00002aa6-0000-1000-8000-00805f9b34fb
[78:21:84:80:A2:22][LE]&amp;gt; characteristics 0x0028 0x00ff
handle: 0x0029, char properties: 0x02, char value handle: 0x002a, uuid: 0000ff01-0000-1000-8000-00805f9b34fb
handle: 0x002b, char properties: 0x0a, char value handle: 0x002c, uuid: 0000ff02-0000-1000-8000-00805f9b34fb
handle: 0x002d, char properties: 0x02, char value handle: 0x002e, uuid: 0000ff03-0000-1000-8000-00805f9b34fb
handle: 0x002f, char properties: 0x02, char value handle: 0x0030, uuid: 0000ff04-0000-1000-8000-00805f9b34fb
handle: 0x0031, char properties: 0x0a, char value handle: 0x0032, uuid: 0000ff05-0000-1000-8000-00805f9b34fb
handle: 0x0033, char properties: 0x0a, char value handle: 0x0034, uuid: 0000ff06-0000-1000-8000-00805f9b34fb
handle: 0x0035, char properties: 0x0a, char value handle: 0x0036, uuid: 0000ff07-0000-1000-8000-00805f9b34fb
handle: 0x0037, char properties: 0x02, char value handle: 0x0038, uuid: 0000ff08-0000-1000-8000-00805f9b34fb
handle: 0x0039, char properties: 0x08, char value handle: 0x003a, uuid: 0000ff09-0000-1000-8000-00805f9b34fb
handle: 0x003b, char properties: 0x0a, char value handle: 0x003c, uuid: 0000ff0a-0000-1000-8000-00805f9b34fb
handle: 0x003d, char properties: 0x02, char value handle: 0x003e, uuid: 0000ff0b-0000-1000-8000-00805f9b34fb
handle: 0x003f, char properties: 0x1a, char value handle: 0x0040, uuid: 0000ff0c-0000-1000-8000-00805f9b34fb
handle: 0x0041, char properties: 0x02, char value handle: 0x0042, uuid: 0000ff0d-0000-1000-8000-00805f9b34fb
handle: 0x0043, char properties: 0x2a, char value handle: 0x0044, uuid: 0000ff0e-0000-1000-8000-00805f9b34fb
handle: 0x0045, char properties: 0x1a, char value handle: 0x0046, uuid: 0000ff0f-0000-1000-8000-00805f9b34fb
handle: 0x0047, char properties: 0x02, char value handle: 0x0048, uuid: 0000ff10-0000-1000-8000-00805f9b34fb
handle: 0x0049, char properties: 0x2a, char value handle: 0x004a, uuid: 0000ff11-0000-1000-8000-00805f9b34fb
handle: 0x004b, char properties: 0x02, char value handle: 0x004c, uuid: 0000ff12-0000-1000-8000-00805f9b34fb
handle: 0x004d, char properties: 0x02, char value handle: 0x004e, uuid: 0000ff13-0000-1000-8000-00805f9b34fb
handle: 0x004f, char properties: 0x0a, char value handle: 0x0050, uuid: 0000ff14-0000-1000-8000-00805f9b34fb
handle: 0x0051, char properties: 0x0a, char value handle: 0x0052, uuid: 0000ff15-0000-1000-8000-00805f9b34fb
handle: 0x0053, char properties: 0x9b, char value handle: 0x0054, uuid: 0000ff16-0000-1000-8000-00805f9b34fb
handle: 0x0055, char properties: 0x02, char value handle: 0x0056, uuid: 0000ff17-0000-1000-8000-00805f9b34fb
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And just like that we retrieved every characteristic available, their value and their properties.&lt;/p&gt;
&lt;p&gt;At this point it is useful to define utility functions to work with the handles:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;mac&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;78:21:84:80:A2:22&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;#change the value to match your board&amp;#39;s MAC&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# HEX encode&lt;/span&gt;
encode&lt;span style=&#34;color:#f92672&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
        echo -n $1 | xxd -ps;
&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# HEX decode&lt;/span&gt;
decode&lt;span style=&#34;color:#f92672&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
        echo $1 | tr -d &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; | xxd -r -p; echo
&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# Write flag to handle 0x002c&lt;/span&gt;
submit_flag&lt;span style=&#34;color:#f92672&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
        gatttool -b $mac --char-write-req -a 0x002c -n &lt;span style=&#34;color:#e6db74&#34;&gt;`&lt;/span&gt;encode &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$1&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;`&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# Read handle 0x002a to get the score&lt;/span&gt;
get_score&lt;span style=&#34;color:#f92672&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
        read_hnd 0x002a
&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# Read values from handle and decode it&lt;/span&gt;
read_hnd&lt;span style=&#34;color:#f92672&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
        decode &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;`gatttool -b &lt;/span&gt;$mac&lt;span style=&#34;color:#e6db74&#34;&gt; --char-read -a &lt;/span&gt;$1&lt;span style=&#34;color:#e6db74&#34;&gt; | awk -F&amp;#39;:&amp;#39; &amp;#39;{print &lt;/span&gt;$2&lt;span style=&#34;color:#e6db74&#34;&gt;}&amp;#39;`&amp;#34;&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# List properties from hex property value&lt;/span&gt;
get_properties&lt;span style=&#34;color:#f92672&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
		&lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x1&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x1 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Broadcast&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x2&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x2 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Read&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x4&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x4 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Write without response&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x8&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x8 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Write&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x10&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x10 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Notify&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x20&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x20 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Indicate&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x40&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x40 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Authenticated Signed Writes&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;((&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;$1 &amp;amp; 0x80&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; 0x80 &lt;span style=&#34;color:#f92672&#34;&gt;))&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Extended Properties&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;NOTE: properties for each characteristic of interest are listed in the challenge description, so the &lt;code&gt;get_properties&lt;/code&gt; function won&amp;rsquo;t be used explicitly.&lt;/p&gt;
&lt;hr&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Flag #1&lt;/strong&gt;
To get this flag we need to use the &lt;a href=&#34;https://github.com/hackgnar/ble_ctf/blob/master/docs/hints/flag1.md&#34;&gt;hint&lt;/a&gt;!&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req -a 0x002c -n $(echo -n &amp;quot;12345678901234567890&amp;quot;|xxd -ps)
Characteristic value was written successfully
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, reading the handle 0x002a confirms we got the first flag.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ get_score
Score:1 /20
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x002e&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To get this flag we simply need to read the handle 0x002e.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x002e
d205303e099ceff44835
less@machine:~$ submit_flag d205303e099ceff44835
less@machine:~$ get_score
Score:2 /20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0030&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;MD5 of Device Name&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So for this flag we need to submit the MD5 of the Device Name.
Note: the MD5 hash needs to be truncated to 20 characters as suggested in the README of the CTF project.&lt;/p&gt;
&lt;p&gt;We already know the device name as we encountered it connecting to the device:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ sudo hcitool lescan
LE Scan ...
78:21:84:80:A2:22 BLECTF
[...]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we only need to get the MD5 digest of the name, cut and submit it:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ echo -n &amp;quot;BLECTF&amp;quot; | md5sum | cut -c 1-20
5cd56d74049ae40f442e
less@machine:~$ submit_flag 5cd56d74049ae40f442e
Characteristic value was written successfully
less@machine:~$ get_score 
Score:3 /20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0016&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is a particular challenge, the hint says:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Bluetooth GATT services provide some extra device attributes.  Try finding the value of the Generic Access -&amp;gt; Device Name.&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But the name of the challenge is &amp;ldquo;Flag 0x0016&amp;rdquo;, so it gives it away!&lt;/p&gt;
&lt;p&gt;Reading the handle we get the flag:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x0016
2b00042f7481c7b056c4b410d28f33cf
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Of course we need to cut it before submitting it (as it is a name and the README clearly states that names and digests need to be cut to the 20th character):&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ echo 2b00042f7481c7b056c4b410d28f33cf | cut -c 1-20
2b00042f7481c7b056c4
less@machine:~$  submit_flag 2b00042f7481c7b056c4
Characteristic value was written successfully
less@machine:~$  get_score 
Score:4 /20
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But it is important to understand the reason why this flag is there.
We already talked about profiles and standard UUID, these include an UUID that corresponds to the Device Name, this UUID is: 0x2A00.&lt;/p&gt;
&lt;p&gt;Using &lt;code&gt;gatttool&lt;/code&gt;, we can read the UUID and note that the handle is indeed 0x0016:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-read -u 0x2A00
handle: 0x0016 	 value: 32 62 30 30 30 34 32 66 37 34 38 31 63 37 62 30 35 36 63 
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0032&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Write anything here&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To get the flag we need to write &amp;ldquo;anything&amp;rdquo; to the 0x0032 handle.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req -a 0x0032 -n `encode &amp;quot;anything&amp;quot;`
Characteristic value was written successfully
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, we can read the handle a second time and it will reveal the flag&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x0032
3873c0270763568cf7aa
less@machine:~$ submit_flag 3873c0270763568cf7aa
Characteristic value was written successfully
less@machine:~$ get_score 
Score:5 /20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0034&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Write the ascii value &amp;ldquo;yo&amp;rdquo; here&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The task is similar to the last one, but this time we don&amp;rsquo;t have to hex encode the string&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req -a 0x0034 -n `encode &amp;quot;yo&amp;quot;`
Characteristic value was written successfully
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, we can get the flag reading the handle again&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x0034
c55c6314b3db0a6128af
less@machine:~$ submit_flag c55c6314b3db0a6128af
Characteristic value was written successfully
less@machine:~$ get_score 
Score:6 /20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0036&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Write the hex value 0x07 here&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This task is not different from the previous ones, but since the default encoding used in BLE communications is hex, and the value is to be sent in hex, no encoding needs to be used&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req -a 0x0036 -n 07
Characteristic value was written successfully
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the flag should be available at the same handle&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x0036
1179080b29f8da16ad66
less@machine:~$ submit_flag 1179080b29f8da16ad66
Characteristic value was written successfully
less@machine:~$ get_score 
Score:7 /20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0038&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Write 0xC9 to handle 58&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read
Handle 58 properties: Write&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;First off we need to convert 58 in hex to get the hex value for the handle, &lt;code&gt;hex(58)&lt;/code&gt; is 0x3A.
Now we need to write the hex value 0xC9 to the handle, this can be done exactly like we did for the last challenge:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req -a 0x003A -n C9
Characteristic value was written successfully
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now reading the handle 0x0038 again reveals the flag&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x0038
f8b136d937fad6a2be9f
less@machine:~$ submit_flag f8b136d937fad6a2be9f
Characteristic value was written successfully
less@machine:~$ get_score 
Score:8 /20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x003C&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Brute force my value 00 to ff&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This can be achieved in multiple ways, but for consistency &lt;code&gt;gatttool&lt;/code&gt; and a bit of bash scripting will be used.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ for i in {0..255};
&amp;gt; do gatttool -b 78:21:84:80:A2:22 --char-write-req -a 0x003c -n $(printf &#39;%02x\n&#39; $i) &amp;gt; /dev/null;
&amp;gt; done;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This script iterates through every value from 0 to 255 (which is FF in hex) and writes such value in the handle 0x003C. The &lt;code&gt;$(printf &#39;%02x\n&#39; $i);&lt;/code&gt; command converts the value to write from decimal to hex.&lt;/p&gt;
&lt;p&gt;Once the script has finished, it&amp;rsquo;s possible to read the handle 0x003C again to get the flag&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x003c
933c1fcfa8ed52d2ec05
less@machine:~$ submit_flag 933c1fcfa8ed52d2ec05
Characteristic value was written successfully
less@machine:~$ get_score 
Score:9 /20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x003E&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Read me 1000 times&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This can be done simply modifying the script used in the previous challenge&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ for i in {0..1000}; 
&amp;gt; do gatttool -b 78:21:84:80:A2:22 --char-read -a 0x003e;
&amp;gt; done;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This command will print out the content of the reads, and after a while you&amp;rsquo;ll notice that the output changes like in the example here:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[...]
Characteristic value/descriptor: 52 65 61 64 20 6d 65 20 31 30 30 30 20 74 69 6d 65 73 
Characteristic value/descriptor: 52 65 61 64 20 6d 65 20 31 30 30 30 20 74 69 6d 65 73 
Characteristic value/descriptor: 52 65 61 64 20 6d 65 20 31 30 30 30 20 74 69 6d 65 73 
Characteristic value/descriptor: 36 66 66 63 64 32 31 34 66 66 65 62 64 63 30 64 30 36 39 65 
Characteristic value/descriptor: 36 66 66 63 64 32 31 34 66 66 65 62 64 63 30 64 30 36 39 65 
Characteristic value/descriptor: 36 66 66 63 64 32 31 34 66 66 65 62 64 63 30 64 30 36 39 65 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The values printed after the variation represent the flag!&lt;/p&gt;
&lt;p&gt;So we just need to submit it to complete this challenge&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ decode &amp;quot;36 66 66 63 64 32 31 34 66 66 65 62 64 63 30 64 30 36 39 65&amp;quot;
6ffcd214ffebdc0d069e
less@machine:~$ submit_flag 6ffcd214ffebdc0d069e
Characteristic value was written successfully
less@machine:~$ get_score 
Score:10/20 
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0040&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Listen to me for a single notification&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write, Notify&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To listen for a notification, we first need to send a write request, but we will have to listen to the notification, this can be achieved with the following command:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req --handle=0x0040 --value=dummy --listen
Characteristic value was written successfully
Notification handle = 0x0040 value: 35 65 63 33 37 37 32 62 63 64 30 30 63 66 30 36 64 38 65 62 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The notification value is the flag!&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ decode &amp;quot;35 65 63 33 37 37 32 62 63 64 30 30 63 66 30 36 64 38 65 62&amp;quot;
5ec3772bcd00cf06d8eb
less@machine:~$ submit_flag 5ec3772bcd00cf06d8eb
Characteristic value was written successfully
less@machine:~$ get_score 
Score:11/20 
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0042&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Listen to handle 0x0044 for a single indication&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;p&gt;Handle 0x0044 Properties: Read, Write, Indicate&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This flag can be obtained just like the last one:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req --handle=0x0044 --value=ffff --listen
Characteristic value was written successfully
Indication   handle = 0x0044 value: 63 37 62 38 36 64 64 31 32 31 38 34 38 63 37 37 63 31 31 33 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Once the notification value is retrieved we can decode and submit it:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ decode &amp;quot;63 37 62 38 36 64 64 31 32 31 38 34 38 63 37 37 63 31 31 33&amp;quot;
c7b86dd121848c77c113
less@machine:~$ submit_flag c7b86dd121848c77c113
Characteristic value was written successfully
less@machine:~$ get_score 
Score:12/20 
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0046&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Listen to me for multi notifications&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write, Notify&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And with the same command we can get this flag too!&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req --handle=0x0046 --value=ffff --listen
Characteristic value was written successfully
Notification handle = 0x0046 value: 55 20 6e 6f 20 77 61 6e 74 20 74 68 69 73 20 6d 73 67 00 00 
Notification handle = 0x0046 value: 63 39 34 35 37 64 65 35 66 64 38 63 61 66 65 33 34 39 66 64 
Notification handle = 0x0046 value: 63 39 34 35 37 64 65 35 66 64 38 63 61 66 65 33 34 39 66 64 
Notification handle = 0x0046 value: 63 39 34 35 37 64 65 35 66 64 38 63 61 66 65 33 34 39 66 64 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After the first notification, we get the content of the flag! (The decoded content of the first notification is &amp;ldquo;U no want this msg&amp;rdquo;).&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ decode &amp;quot;63 39 34 35 37 64 65 35 66 64 38 63 61 66 65 33 34 39 66 64&amp;quot;
c9457de5fd8cafe349fd
less@machine:~$ submit_flag c9457de5fd8cafe349fd
Characteristic value was written successfully
less@machine:~$ get_score 
Score:13/20 
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0048&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Listen to handle 0x004a for multi indications&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;p&gt;Handle 0x004a Properties: Read, Write, Indicate&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Once again the same command is the key to the flag!&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req --handle=0x004a --value=ffff --listen
Characteristic value was written successfully
Indication   handle = 0x004a value: 55 20 6e 6f 20 77 61 6e 74 20 74 68 69 73 20 6d 73 67 00 00 
Indication   handle = 0x004a value: 62 36 66 33 61 34 37 66 32 30 37 64 33 38 65 31 36 66 66 61 
Indication   handle = 0x004a value: 62 36 66 33 61 34 37 66 32 30 37 64 33 38 65 31 36 66 66 61 
Indication   handle = 0x004a value: 62 36 66 33 61 34 37 66 32 30 37 64 33 38 65 31 36 66 66 61 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we can decode and submit the flag like always.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ decode &amp;quot;62 36 66 33 61 34 37 66 32 30 37 64 33 38 65 31 36 66 66 61&amp;quot;
b6f3a47f207d38e16ffa
less@machine:~$ submit_flag b6f3a47f207d38e16ffa
Characteristic value was written successfully
less@machine:~$ get_score 
Score:14/20 
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x004c&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Connect with BT MAC address 11:22:33:44:55:66&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now, this challenge depends on the BT card you&amp;rsquo;re using. I&amp;rsquo;m using a raspberry pi 3b+ and I could solve the challenge in the following way:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ sudo hcitool cmd 0x3f 0x001 0x66 0x55 0x44 0x33 0x22 0x11
&amp;lt; HCI Command: ogf 0x3f, ocf 0x0001, plen 6
  66 55 44 33 22 11 
&amp;gt; HCI Event: 0x0e plen 4
  01 01 FC 00 
less@machine:~$ sudo hciconfig hci0 reset
less@machine:~$ systemctl restart bluetooth.service
Authentication is required to restart &#39;bluetooth.service&#39;.
Authenticating as: ,,, (less)
Password: 
==== AUTHENTICATION COMPLETE ===
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At this point we can confirm our BT MAC address executing &lt;code&gt;hciconfig&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ hciconfig
hci0:	Type: Primary  Bus: UART
	BD Address: 11:22:33:44:55:66  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING 
	RX bytes:13820 acl:117 sco:0 events:824 errors:0
	TX bytes:16604 acl:108 sco:0 commands:606 errors:0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And of course now, reading the handle gives us the flag:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x004c
aca16920583e42bdcf5f
less@machine:~$ submit_flag aca16920583e42bdcf5f
Characteristic value was written successfully
less@machine:~$ get_score 
Score:15/20
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Check out these resources for more info on this solution:
&lt;a href=&#34;https://www.lisha.ufsc.br/teaching/shi/ine5346-2003-1/work/bluetooth/hci_commands.html&#34;&gt;https://www.lisha.ufsc.br/teaching/shi/ine5346-2003-1/work/bluetooth/hci_commands.html&lt;/a&gt; and &lt;a href=&#34;https://raspberrypi.stackexchange.com/a/124117&#34;&gt;https://raspberrypi.stackexchange.com/a/124117&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x004e&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Set your connection MTU to 444&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Even if there is the option to do that (-m), I can&amp;rsquo;t seem to get the flag without using the interactive mode of gatttools, so my solution to this flag is:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -I
[                 ][LE]&amp;gt; connect 78:21:84:80:A2:22
Attempting to connect to 78:21:84:80:A2:22
Connection successful
[78:21:84:80:A2:22][LE]&amp;gt; mtu 444
MTU was exchanged successfully: 444
[78:21:84:80:A2:22][LE]&amp;gt; char-read-hnd 0x004e
Characteristic value/descriptor: 62 31 65 34 30 39 65 35 61 34 65 61 66 39 66 65 35 31 35 38 
[78:21:84:80:A2:22][LE]&amp;gt; exit
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And just like that we got the flag&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ decode &amp;quot;62 31 65 34 30 39 65 35 61 34 65 61 66 39 66 65 35 31 35 38 &amp;quot;
b1e409e5a4eaf9fe5158
less@machine:~$ submit_flag b1e409e5a4eaf9fe5158
Characteristic value was written successfully
less@machine:~$ get_score 
Score:16/20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0050&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;Write+resp &amp;lsquo;hello&amp;rsquo; &amp;quot;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I suggest checking the hint for this challenge! The key is in correctly handling the ACK response from the write instruction, this is the reason&lt;/p&gt;
&lt;p&gt;&lt;code&gt;--char-write-req&lt;/code&gt; needs to be used.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req --handle=0x0050 --value=`encode hello`
Characteristic value was written successfully
less@machine:~$ read_hnd 0x0050
d41d8cd98f00b204e980
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we only need to submit the flag.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ submit_flag d41d8cd98f00b204e980
Characteristic value was written successfully
less@machine:~$ get_score 
Score:17/20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0052&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;No notifications here! really?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Read, Write&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In fact even if there is no notification property set&amp;hellip;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req --handle=0x0052 --value=`encode hello` --listen
Characteristic value was written successfully
Notification handle = 0x0052 value: 66 63 39 32 30 63 36 38 62 36 30 30 36 31 36 39 34 37 37 62 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The flag is revealed through a notification!
Now we can decode and submit it.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ decode &amp;quot;66 63 39 32 30 63 36 38 62 36 30 30 36 31 36 39 34 37 37 62&amp;quot;
fc920c68b6006169477b
less@machine:~$ submit_flag fc920c68b6006169477b
Characteristic value was written successfully
less@machine:~$ get_score 
Score:18/20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0054&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;So many properties!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Properties: Broadcast, Read, Write, Notify, Extended properties&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;hellip;and to be fair this handle has &amp;ldquo;Broadcast, Read, Write, Notify, Extended properties&amp;rdquo; properties. It&amp;rsquo;s a bit of a mess!&lt;/p&gt;
&lt;p&gt;But getting the flag is fairly simple. The first half can be retrieved simply listening for a notification:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ gatttool -b 78:21:84:80:A2:22 --char-write-req --handle=0x0054 --value=ffff --listen
Characteristic value was written successfully
Notification handle = 0x0054 value: 30 37 65 34 61 30 63 63 34 38 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For the second half we need to read the handle once more:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ read_hnd 0x0054
fbb966958f
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we just need to put the two halves together and submit the flag (the second half of the flag goes first!):&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ submit_flag fbb966958f07e4a0cc48
Characteristic value was written successfully
less@machine:~$ get_score 
Score:19/20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flag 0x0056&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The content of the handle is: &amp;ldquo;md5 of author&amp;rsquo;s twitter handle&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Properties: Read&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So we need to do a bit of OSINT to solve this challenge!&lt;/p&gt;
&lt;p&gt;The starting point is the github page of the challenge: &lt;a href=&#34;https://github.com/hackgnar/ble_ctf&#34;&gt;https://github.com/hackgnar/ble_ctf&lt;/a&gt;
Luckily in the README.md file we can find a twitter follow button, this leads us to: &lt;a href=&#34;https://twitter.com/hackgnar&#34;&gt;https://twitter.com/hackgnar&lt;/a&gt;
And now we know the handle is: @hackgnar&lt;/p&gt;
&lt;p&gt;Now we can get the MD5 digest of the handle and cut it to 20 chars:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ echo -n &amp;quot;@hackgnar&amp;quot; | md5sum | cut -c 1-20
d953bfb9846acc2e15ee
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can now submit it as a flag&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;less@machine:~$ submit_flag d953bfb9846acc2e15ee
Characteristic value was written successfully
less@machine:~$ get_score 
Score:20/20
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;conclusions&#34;&gt;Conclusions&lt;/h2&gt;
&lt;p&gt;Hope this article is useful to anyone who&amp;rsquo;s stuck on one of these challenges or to anyone who&amp;rsquo;s trying to learn about BLE technologies.
Writing this article has helped me formalizing most of the things I learned solving these challenges and my main takeaways are an improved understanding of BLE, GATT and ATT, but also the ability to use the tools needed to work with these technologies.&lt;/p&gt;
&lt;p&gt;In future I&amp;rsquo;ll try working with GATT libraries to programmatically interact with GATT servers!&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://epxx.co/artigos/bluetooth_gatt.html&#34;&gt;https://epxx.co/artigos/bluetooth_gatt.html&lt;/a&gt; (ATT/GATT basics)&lt;/li&gt;
&lt;li&gt;Practical IoT Hacking: The Definitive Guide to Attacking the Internet of Things (General BLE introduction)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://axodyne.com/2020/08/ble-uuids/&#34;&gt;https://axodyne.com/2020/08/ble-uuids/&lt;/a&gt;  (Explanation on standard UUIDS)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt&#34;&gt;https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt&lt;/a&gt; (Profiles and services)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://devzone.nordicsemi.com/guides/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial&#34;&gt;https://devzone.nordicsemi.com/guides/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial&lt;/a&gt; (Properties)&lt;/li&gt;
&lt;/ul&gt;
</content:encoded>

      </item><item>
        <title>Walkthrough: CryptoHack CTF</title>
        <link>https://lessonsec.com/posts/walkthrough-cryptohack-ctf/</link>
        <guid isPermaLink="true">https://lessonsec.com/posts/walkthrough-cryptohack-ctf/</guid>
        <pubDate>Sun, 03 Oct 2021 12:41:44 &#43;0200</pubDate><description>Recently I&amp;rsquo;ve been meaning to get into cryptography more seriously, and to be honest I&amp;rsquo;ve also been postponing it for a while too, so I figured it was time I wrote this article to get motivated!</description>
	<content:encoded>&lt;p&gt;Recently I&amp;rsquo;ve been meaning to get into cryptography more seriously, and to be honest I&amp;rsquo;ve also been postponing it for a while too, so I figured it was time I wrote this article to get motivated!&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m approaching this cryptography deep dive with &lt;a href=&#34;https://cryptohack.org/&#34;&gt;https://cryptohack.org/&lt;/a&gt;.
Cryptohack it&amp;rsquo;s website offering CTF style challenges to understand and try to break modern cryptography. I really like this gamified approach so I decided to give it a shot.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You always need to be extra careful when sharing CTFs solutions online. That&amp;rsquo;s the reason why I&amp;rsquo;m strictly following cryptohack&amp;rsquo;s guidelines.
As requested in the website&amp;rsquo;s &lt;a href=&#34;https://cryptohack.org/faq/#solutions&#34;&gt;FAQ&lt;/a&gt; I&amp;rsquo;m only sharing solutions for challenges worth 10 points or less.
These challenges are pretty basic, but I felt like it would be useful to have this kind of content published for those who are not familiar with basic cryptography or with the coding tools and technologies needed to solve the challenges. Each challenge solution will be explained but no flag will be available in this article.&lt;/p&gt;
&lt;p&gt;Cryptohack also has a functionality to share the solution once you get the flag for the challenge. Solutions to more complex challenges are to be shared exclusively there. The solutions are however only available for the solvers of the relative challenge.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Make sure to download the python notebook with the code snippets from this article &lt;a href=&#34;https://lessonsec.com/resources/cryptohack_walkthrough/cryptohack_walkthrough.ipynb&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;page-index&#34;&gt;Page index&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#setup&#34;&gt;Setup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#introduction-challenges&#34;&gt;Introduction Challenges&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#finding-flags-2-pts&#34;&gt;Finding Flags&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#great-snakes-3-pts&#34;&gt;Great Snakes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#network-attacks-5-pts&#34;&gt;Network Attacks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#general-challenges&#34;&gt;General Challenges&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#ascii-5-pts&#34;&gt;ASCII&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#hex-5-pts&#34;&gt;Hex&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#base64-10-pts&#34;&gt;Base64&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#bytes-and-big-integers-10-pts&#34;&gt;Bytes and Big Integers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#xor-starter-10-pts&#34;&gt;XOR Starter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#mathematics&#34;&gt;Mathematics&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#vectors-10-pts&#34;&gt;Vectors&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#symmetric-ciphers&#34;&gt;Symmetric Ciphers&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#keyed-permutations-5-pts&#34;&gt;Keyed Permutations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#resisting-bruteforce-10-pts&#34;&gt;Resisting Bruteforce&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#rsa&#34;&gt;RSA&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#rsa-starter-1-10-pts&#34;&gt;RSA Starter 1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#diffie-hellman&#34;&gt;Diffie-Hellman&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#diffie-hellman-starter-1-10-pts&#34;&gt;Diffie-Hellman Starter 1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#crypto-on-the-web&#34;&gt;Crypto On The Web&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#token-appreciation-5-pts&#34;&gt;Token Appreciation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#jwt-sessions-10-pts&#34;&gt;JWT Sessions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lessonsec.com/posts/walkthrough-cryptohack-ctf/#conclusions&#34;&gt;Conclusions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;setup&#34;&gt;Setup&lt;/h2&gt;
&lt;p&gt;Before starting I suggest getting the official docker image provided in the FAQs.
You simply need to pull &lt;code&gt;hyperreality/cryptohack:latest&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To run the container simply run the provided command: &lt;code&gt;docker run -p 127.0.0.1:8888:8888 -it hyperreality/cryptohack:latest&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This will start a Jupyter Notebook server reachable at &lt;code&gt;localhost:8888&lt;/code&gt;.
If you don&amp;rsquo;t want to use notebooks to solve the challenges but still want to use the container because of dependencies, you can overwrite the entrypoint of the image with the following command: &lt;code&gt;docker run -it --entrypoint /bin/bash -p 127.0.0.1:8888:8888 -v hyperreality/cryptohack:latest&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Once the docker situation is under control, we can start working on the challenges.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction-challenges&#34;&gt;Introduction Challenges&lt;/h2&gt;
&lt;p&gt;These challenges are basically tutorials to get familiar with how the challenges on this website works.
They show the flag format, how to work with the challenge scripts and how to approach the network based attacks.&lt;/p&gt;
&lt;h4 id=&#34;finding-flags-2-pts&#34;&gt;Finding Flags (2 pts.)&lt;/h4&gt;
&lt;p&gt;Simply follow the instructions and copy-paste the flag in the text field.&lt;/p&gt;
&lt;h4 id=&#34;great-snakes-3-pts&#34;&gt;Great Snakes (3 pts.)&lt;/h4&gt;
&lt;p&gt;For this one you need to execute the provided python script, that will print out the flag.&lt;/p&gt;
&lt;h4 id=&#34;network-attacks-5-pts&#34;&gt;Network Attacks (5 pts.)&lt;/h4&gt;
&lt;p&gt;We need to interact with a TCP server using JSON messages.
The website suggests using python and &lt;code&gt;telnetlib&lt;/code&gt; to do so. It also provides an example showing how to interact with the server of this challenge.&lt;/p&gt;
&lt;p&gt;What we need to do to get the flag is to play around a little bit with the server and find the correct request to &lt;em&gt;buy&lt;/em&gt; a &lt;em&gt;flag&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# import the libraries needed for the challenge&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; telnetlib
&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; json

HOST &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;socket.cryptohack.org&amp;#34;&lt;/span&gt;
PORT &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11112&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# initialize the connection&lt;/span&gt;
tn &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; telnetlib&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Telnet(HOST, PORT)

&lt;span style=&#34;color:#75715e&#34;&gt;# define functions to receive and send JSON payloads over TCP&lt;/span&gt;
&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;readline&lt;/span&gt;():
    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; tn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;read_until(&lt;span style=&#34;color:#e6db74&#34;&gt;b&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;)

&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;json_recv&lt;/span&gt;():
    line &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; readline()
    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; json&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;loads(line&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;decode())

&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;json_send&lt;/span&gt;(hsh):
    request &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; json&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;dumps(hsh)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encode()
    tn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;write(request)
  
&lt;span style=&#34;color:#75715e&#34;&gt;# reads the banner printed by the server&lt;/span&gt;
print(readline())
print(readline())
print(readline())
print(readline())

&lt;span style=&#34;color:#75715e&#34;&gt;# ------ Request example ------&lt;/span&gt;
&lt;span style=&#34;color:#75715e&#34;&gt;# Compose a request for the server&lt;/span&gt;
request &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; {&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;buy&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;clothes&amp;#34;&lt;/span&gt;}

&lt;span style=&#34;color:#75715e&#34;&gt;# Sends the request&lt;/span&gt;
json_send(request)

&lt;span style=&#34;color:#75715e&#34;&gt;# Gets the response&lt;/span&gt;
response &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; json_recv()

print(response) &lt;span style=&#34;color:#75715e&#34;&gt;# {&amp;#39;error&amp;#39;: &amp;#39;Sorry! All we have to sell are flags.&amp;#39;}&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# ------ Real request ------&lt;/span&gt;
&lt;span style=&#34;color:#75715e&#34;&gt;# mhhh flags you say?&lt;/span&gt;
request &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; {&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;buy&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;}

&lt;span style=&#34;color:#75715e&#34;&gt;# Sends the request&lt;/span&gt;
json_send(request)

&lt;span style=&#34;color:#75715e&#34;&gt;# Gets the response&lt;/span&gt;
response &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; json_recv()

print(response)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;general-challenges&#34;&gt;General Challenges&lt;/h2&gt;
&lt;h3 id=&#34;uencodingu&#34;&gt;&lt;u&gt;Encoding&lt;/u&gt;&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;For these challenges it&amp;rsquo;s not really necessary to write any code. While writing your own scripts can help getting familiar with tools and techniques, a deeper understanding of encodings can be obtained solving the challenges in different ways.&lt;/p&gt;
&lt;p&gt;A super-versatile and commonly used tool for this kind of task is &lt;a href=&#34;https://gchq.github.io/CyberChef/&#34;&gt;CyberChef&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&#34;ascii-5-pts&#34;&gt;ASCII (5 pts.)&lt;/h4&gt;
&lt;p&gt;We are given a 7-bit ASCII encoded string and we need to decode it to get the flag.
The challenge hint suggests that we use the python &lt;code&gt;chr()&lt;/code&gt; function to do to.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# ASCII values to decode&lt;/span&gt;
values &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;99&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;114&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;121&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;112&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;116&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;111&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;123&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;65&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;83&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;67&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;73&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;73&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;95&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;112&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;114&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;49&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;110&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;116&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;52&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;98&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;108&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;51&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;125&lt;/span&gt;]

solution &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;
&lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; v &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; values:
    solution &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; chr(v)
    
print(solution)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;hex-5-pts&#34;&gt;Hex (5 pts.)&lt;/h4&gt;
&lt;p&gt;In this challenge we are provided with an hex encoded string we need to decode.
This time the challenge hint suggests using the &lt;code&gt;bytes.fromhex()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# HEX values to decode&lt;/span&gt;
values &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d&amp;#34;&lt;/span&gt;

solution &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; bytes&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;fromhex(values)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;decode(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;utf-8&amp;#39;&lt;/span&gt;)

print(solution)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;base64-10-pts&#34;&gt;Base64 (10 pts.)&lt;/h4&gt;
&lt;p&gt;For this challenge we are given an hex encoded string, to be decoded and then encoded in base64 to be used as flag.
In this case we will be using the &lt;code&gt;base64&lt;/code&gt; python module, in particular the &lt;code&gt;base64.b64encode()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; base64

&lt;span style=&#34;color:#75715e&#34;&gt;# HEX values to decode&lt;/span&gt;
values &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf&amp;#34;&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;# Decoded values&lt;/span&gt;
tmp &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; bytes&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;fromhex(values)
&lt;span style=&#34;color:#75715e&#34;&gt;# print(tmp)&lt;/span&gt;
solution &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; base64&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;b64encode(tmp)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;decode(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;utf-8&amp;#39;&lt;/span&gt;)

print(solution)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;bytes-and-big-integers-10-pts&#34;&gt;Bytes and Big Integers (10 pts.)&lt;/h4&gt;
&lt;p&gt;Some cryptosystems like RSA work only when applied to numbers. We need to encode our messages as numbers in order to work with these cryptosystems.
One method to do so is to represent the data as bytes and convert these in a base-16 or base-10 number.&lt;/p&gt;
&lt;p&gt;In this challenge we are provided with a message encoded in this way and we need to get the original message out.&lt;/p&gt;
&lt;p&gt;For this challenge the PyCryptodome library it needed, we can work with this encoding using the functions: &lt;code&gt;Crypto.Util.number.bytes_to_long()&lt;/code&gt; and &lt;code&gt;Crypto.Util.number.long_to_bytes()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; Crypto.Util.number &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; long_to_bytes

&lt;span style=&#34;color:#75715e&#34;&gt;# Message encoded as number&lt;/span&gt;
values &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11515195063862318899931685488813747395775516287289682636499965282714637259206269&lt;/span&gt;

solution &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; long_to_bytes(values)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;decode(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;utf-8&amp;#39;&lt;/span&gt;)

print(solution)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h3 id=&#34;uxoru&#34;&gt;&lt;u&gt;XOR&lt;/u&gt;&lt;/h3&gt;
&lt;h4 id=&#34;xor-starter-10-pts&#34;&gt;XOR Starter (10 pts.)&lt;/h4&gt;
&lt;p&gt;In this challenge we need to XOR the value 13 to each character of the provided string, then we need to put the result in the cyber{flag} format.
The hint suggests that it&amp;rsquo;s possible to use the &lt;code&gt;xor()&lt;/code&gt; function from &lt;code&gt;pwntools&lt;/code&gt; but it&amp;rsquo;s just as easy to do the same in pure python.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Provided string&lt;/span&gt;
values &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;label&amp;#34;&lt;/span&gt;

solution &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;
&lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; v &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; values:
    solution &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; chr(ord(v) &lt;span style=&#34;color:#f92672&#34;&gt;^&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;13&lt;/span&gt;)
    
&lt;span style=&#34;color:#75715e&#34;&gt;# The {{{var}}} syntax is needed to excape curly braces in python f-strings&lt;/span&gt;
print(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;crypto&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;{{&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;solution&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;}}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;mathematics&#34;&gt;Mathematics&lt;/h2&gt;
&lt;h3 id=&#34;ulatticesu&#34;&gt;&lt;u&gt;Lattices&lt;/u&gt;&lt;/h3&gt;
&lt;h4 id=&#34;vectors-10-pts&#34;&gt;Vectors (10 pts.)&lt;/h4&gt;
&lt;p&gt;In this challenge we are asked to perform operations on a three dimensional vector space.
If this sounds new to you make sure to carefully read the challenge description and check the suggested materials.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;v &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;)
w &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;)
u &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;)

&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;vector_minus&lt;/span&gt;(a, b):
   &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; [x &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; y &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; x, y &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; zip(a,b)]

&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;vector_dot&lt;/span&gt;(a,b):
    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; sum([x &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; y &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; x, y &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; zip(a,b)])
    
&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;scalar_times&lt;/span&gt;(a, times):
    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; list(map( &lt;span style=&#34;color:#66d9ef&#34;&gt;lambda&lt;/span&gt; x: x &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; times , a))

&lt;span style=&#34;color:#75715e&#34;&gt;# calculate 3*(2*v - w) ∙ 2*u&lt;/span&gt;
vector_dot(scalar_times(vector_minus(scalar_times(v, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;), w), &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;), scalar_times(u, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;symmetric-ciphers&#34;&gt;Symmetric Ciphers&lt;/h2&gt;
&lt;p&gt;&lt;u&gt;&lt;strong&gt;How AES Works&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;
&lt;h4 id=&#34;keyed-permutations-5-pts&#34;&gt;Keyed Permutations (5 pts.)&lt;/h4&gt;
&lt;p&gt;In this challenge we are asked to answer a question: &lt;em&gt;What is the mathematical term for a one-to-one correspondence?&lt;/em&gt;
Google is your friend for this one!&lt;/p&gt;
&lt;h4 id=&#34;resisting-bruteforce-10-pts&#34;&gt;Resisting Bruteforce (10 pts.)&lt;/h4&gt;
&lt;p&gt;This time we are asked: &lt;em&gt;What is the name for the best single-key attack against AES?&lt;/em&gt;                &lt;br&gt;
Just make sure you carefully read the challenge description and you&amp;rsquo;re good to go!&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;rsa&#34;&gt;RSA&lt;/h2&gt;
&lt;p&gt;&lt;u&gt;&lt;strong&gt;Starter&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;
&lt;h4 id=&#34;rsa-starter-1-10-pts&#34;&gt;RSA Starter 1 (10 pts.)&lt;/h4&gt;
&lt;p&gt;The basis of RSA encryption is modular exponentiation. In this challenge we are asked to use such technique to create a &amp;ldquo;trapdoor function&amp;rdquo; (a function easy to calculate but hard to reverse).
This can be done using the &lt;code&gt;pow()&lt;/code&gt; function that python provides.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Calculate 101^17 mod 22663&lt;/span&gt;
pow(&lt;span style=&#34;color:#ae81ff&#34;&gt;101&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;17&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;22663&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;diffie-hellman&#34;&gt;Diffie-Hellman&lt;/h2&gt;
&lt;p&gt;&lt;u&gt;&lt;strong&gt;Starter&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;
&lt;h4 id=&#34;diffie-hellman-starter-1-10-pts&#34;&gt;Diffie-Hellman Starter 1 (10 pts.)&lt;/h4&gt;
&lt;p&gt;The Diffie-Hellman algorithm works with finite fields and modular exponentiation to allow to parties to exchange a shared secret.
If you&amp;rsquo;re not familiar with this algorithm or with the math behind it I would suggest to check out the &lt;a href=&#34;https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#Cryptographic_explanation&#34;&gt;Wikipedia page&lt;/a&gt; to get started.&lt;/p&gt;
&lt;p&gt;In this challenge we are asked to find an inverse element given the prime number and the modulo.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution&lt;/u&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;g &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;209&lt;/span&gt;
p &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;991&lt;/span&gt;
fc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;

&lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; x &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;, p):    
    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (g &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; x) &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt; p &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; fc:         
        print(x)        
        &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;crypto-on-the-web&#34;&gt;Crypto On The Web&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;JSON web tokens&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&#34;token-appreciation-5-pts&#34;&gt;Token Appreciation (5 pts.)&lt;/h4&gt;
&lt;p&gt;&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7519&#34;&gt;JWTs or JSON Web Tokens&lt;/a&gt; are a standard method to safely represent claims between two parties.
This kind of token is not encrypted by default, and this is the reason why it&amp;rsquo;s possible to reverse the encoding and extract the original message.&lt;/p&gt;
&lt;p&gt;We are given the token:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmbGFnIjoiY3J5cHRve2p3dF9jb250ZW50c19j&lt;/code&gt;
&lt;code&gt;YW5fYmVfZWFzaWx5X3ZpZXdlZH0iLCJ1c2VyIjoiQ3J5cHRvIE1jSGFjayIsImV4cCI6MjAwNT&lt;/code&gt;
&lt;code&gt;AzMzQ5M30.shKSmZfgGVvd2OSB2CGezzJ3N6WAULo3w9zCl_T47K&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now, there are a few ways to solve this challenge, the suggested one is to use Python&amp;rsquo;s &lt;a href=&#34;https://pyjwt.readthedocs.io/en/stable/&#34;&gt;PyJWT&lt;/a&gt; library, but since it&amp;rsquo;s not installed in the docker container we are using, it&amp;rsquo;s easier to use an online tool like &lt;a href=&#34;https://gchq.github.io/CyberChef&#34;&gt;CyberChef&lt;/a&gt; or &lt;a href=&#34;https://jwt.io/&#34;&gt;jwt.io&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;jwt-sessions-10-pts&#34;&gt;JWT Sessions (10 pts.)&lt;/h4&gt;
&lt;p&gt;In this challenge we are given some information about the use of JWT tokens, now we are asked the &lt;em&gt;HTTP header used by the browser to send JWTs to the server&lt;/em&gt;. Once again Google is your friend!&lt;/p&gt;
&lt;p&gt;If you want to solve this challenge on your own, take out the developer tools in your browser, go to the network tab and start looking around for HTTP headers that could refer to the use of JWT tokens. You&amp;rsquo;re &lt;em&gt;authorized&lt;/em&gt; to do that!&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;conclusions&#34;&gt;Conclusions&lt;/h2&gt;
&lt;p&gt;Hope this article is useful to anyone who&amp;rsquo;s meaning to get into cryptography or CTFs in general.
Writing this article allowed me to go back and review my knowledge of basic cryptography as well as exploring a bit out of my comfort zone (when it came to more complex challenges not included in the writeup).&lt;/p&gt;
</content:encoded>

      </item>

  </channel>
</rss>
