Intro
This is probably the challenge I was proudest of completing since I don’t have a background in computer engineering. Out of Time was an easy-rated hardware challenge in this year’s Hack The Box University CTF. We’re given a python script to talk to the hardware running on the other side, and everytime we submit a password, we’re given a NumPy array of the power trace. We can leverage this to “brute-force” the password, by means of a power analysis, observing irregular spikes when we input something correct.
Description
Quick we need to get access to the bunker and we are running out of time! The door is using an advanced steam-powered door locking mechanism which we cannot breach. One of our scientists managed to make a tool that measures the mechanical stress of the pipes moving steam during the verification of the password and created a power consumption model but it looks like just random signals. Can you find anything useful in the data?
Initial Observations
When we open the downloadable component, we’re given a python scipt called socket_interface.py
.
This basically simplifies the process of accessing what’s on the other side; it’s just some basic socket programming to send a password, and then receive the power trace. I’ll add a line to print out the numpy array and see what happens on an initial connection.
What does this mean? I see numbers, but they don’t really mean much. The base64 is just another representation of the array, so that doesn’t help. At this point in time, I turned back to the description.
“The door is using an advanced steam-powered door locking mechanism which we cannot breach […] during the verification of the password and created a power consumption model but it looks like just random signals […]”
In the code, this “power consumption model” is referred to as “power_trace”. There must be something to do with this.
Research
Google FTW
My favorite thing about “easy” hardware challenges is that the research is not obscure and really interesting to read through. In this case, I began my search looking for “power consumption model and power trace” on Google.
I saw a lot of things related to “power analysis”, and that paper that had to do with cryptography was a nice indicator that I might be on the right track. I didn’t read the paper (out of sheer laziness). I then searched for “power analysis hardware” and found this.
Naturally, I went to videos and found the following videos, which guided me through this challenge.
- LiveOverflow - Breaking AES with ChipWhisperer
- Collin O’Flynn - Introduction to Side-Channel Power Analysis
- Collin O’Flynn - 0x501 Power Analysis Attacks
I found the LiveOverflow video first, which introduced me to the idea of Side Channel Analysis, but the lectures I found next solidified the process. So let’s talk about some theory.
No Security Without Physical Security
For the completely uninitiated, meaning absolutely no knowledge on how circuits work, I’ll give a quick run down. It’s not fully necessary to understand this part, but I think it helps demystify some stuff.
The above diagram can be broken down like so:
- The red box highlights the battery/power supply along with its voltage
- The yellow highlights the current flowing through the circuit
- The purple highlights the resistor, which “slows down” the current, which is an oversimplification, but I don’t want to dive too deep.
Simply put, when a current travels through a resistor, there is a drop in voltage. Power is calculated using voltage, so the two values are related. I’m not a computer/embedded systems engineer, so I don’t know the specifics about how something using a password is constructed, but we can imagine it. If a correct password is submitted, the voltages will probably drop one way (buttons, lightbulbs, and any device connected to a circuit acts as a resistor), but if something incorrect happens, the voltage goes another way.
When we measure what’s going on in the machine with an oscilloscope, we can get a power trace. If it’s not very secure, we will visibly be able to see a noticably different jump in the trace, allowing to conclude if something is correct or incorrect simply on a character to character basis.
Credit: Collin O’Flynn
ChipWhisperer
Collin O’Flynn actually has worked on a project, ChipWhisperer, that helps to perform these kinds of attacks. If you have a physical device that you’re trying to do this on, it’s probably a solid library to work from. However, we’re already recieving data as a numpy array, so we really only care about the process.
Luckily, he’s actually posted a step-by-step tutorial on performing the attack at this link. And it turns out it works perfectly for this challenge.
Grabbing the Flag
I’m not going to go step by step through the tutorial here because half of it is just exploring the concept using matplotlib, so I’ll just walk through my final script, which I ran out of a Jupyter Notebook (because I wanted to see the matplotlib stuff).
So what’s going on? The attack goes as follows:
- I go through each ASCII character in the range of 33 to 125 checking how the power trace responds
- I take the difference between this power trace, and the trace of when I just send a null byte at the end, and add up the absolute values of the entries in the resulting array
- If this value is above a predetermined threshold (I concluded mine to be 100 empirically), we add this to our guessed password and repeat. We know this is the correct character because the correct character will always show up as an outlier compared to the rest of the possible options.
The character that is correct will always cause a spike in the power trace, that is how we distinguish the right from the wrong. I have my loop run forever because I didn’t know how long the password was.
Once we run our program, we get the following output and can submit the flag.
HTB{c
HTB{c4
HTB{c4n
HTB{c4n7
HTB{c4n7_
HTB{c4n7_h
HTB{c4n7_h1
HTB{c4n7_h1d
HTB{c4n7_h1d3
HTB{c4n7_h1d3_
HTB{c4n7_h1d3_f
HTB{c4n7_h1d3_f2
HTB{c4n7_h1d3_f20
HTB{c4n7_h1d3_f20m
HTB{c4n7_h1d3_f20m_
HTB{c4n7_h1d3_f20m_7
HTB{c4n7_h1d3_f20m_71
HTB{c4n7_h1d3_f20m_71m
HTB{c4n7_h1d3_f20m_71m3
HTB{c4n7_h1d3_f20m_71m3}