Skip to main content
Hardware security Fault injection Analog Digital Microcontroller KiCad Project repo

Building Glitchy: an open-source hardware hacking tool

Power glitching to bypass instruction flow and power monitoring to interrogate program branching. Or in other words, glitch it to bypass that password check or power monitor it to recover that password.

Key takeaways
  • Open source hardware and software project! Click the PROJECT REPO button at the top to see it. There’s also a Wiki to walk you through some beginning lessons.
  • Funded by and developed for a client to use with their internal red team and at hacking events.
  • Biggest tech challenge: making an ESP32 consistently produce 18 ns pulses
  • Designed as an introductory learning tool, and to be as cheap and simple as possible. We’re not competing with ChipWhisperer or any other professional tools here.
  • Uses real third-party hardware for targets, not special-built boards designed to be exploited.

So why Glitchy? There’s tools out there already that do this stuff and more. When I was approached by a friend about this project, they needed something that lowered the barrier to exploring hardware security exploitation. They wanted something that was cheap enough to hand out like badges at conferences and was geared toward beginners in the hardware hacking area. The vision was to use it with a client’s internal red team, experts in software attacks on CPU architectures, and help them explore the hardware aspect aka side channel attacks. We also agreed to open source this project so others could learn from it, which I was ecstatic about. Most of the work I do gets buried behind NDAs never to see the light of day, and I can actually share this one with you.

So where to start? I like looking at the trade space. There’s a thousand ways to make this thing, so how do we choose? Since it was open source, I wanted the hardware and software to be as accessible as possible — so that’s where I began.

PCB

What should I design the PCB in? I am good in Altium, but unless you are a professional, chances are you can’t afford that. So I built it in KiCad. It’s free and it’s what most hobbyists use. Honestly KiCad has gotten really good over the years and I enjoy using it over Altium for basic projects.

Full Glitchy schematic
Fig. 1 — The complete schematic (click to view full size). Functional blocks: USB-to-UART, the 3.3 V regulator, the ESP32-S3, the crowbar FET, and the analog front end for power analysis.

Glitchy PCB — copper trace routing
Fig. 2 — The routing.

Glitchy PCB — 3D render of the finished octagonal board
Fig. 3 — 3D Rendering of the board.

Glitchy PCB — 3D render of the back of the board
Fig. 4 — A bit of silkscreen art on the back.

The Brains

What should we run this on? I am a huge fan of Cypress PSoC chips (acquired by Infineon in 2019). The analog front end would have made this project SUPER easy. But beginners know Arduinos and ESP32s. So I took the challenge to see if I could get the performance out of an ESP32. It was cheap and it’s got Wi-Fi and can host basic webpages for control.

This turned into a whole journey I had no idea was coming. So many debugging hours and drilling down through datasheets. The ESP32 chips make this challenging for two reasons.

  • To do power glitching, we need to very quickly and very accurately toggle IO lines
  • To do power monitoring, we need low noise and decently fast analog to digital (ADC) functionality

Power Glitching

The concept of power glitching is surprisingly simple, while its execution is difficult to accomplish. In power glitching what you want to do is short the power supply to a chip just long enough that it misbehaves, but not so long it resets. That’s basically it. Do it just hard enough, just long enough, at just the right time, and that if statement that was supposed to come back and say “no you don’t have the right password” malfunctions and says “yup, you are good to go!”.

Source: Target_keypad.ino — the demo target’s password check, from the project repo (Code/Target Examples/Target_keypad/).

// g_was_the_right_key_pressed is declared volatile so the compiler can't
// optimize it away or assume its value. It is initialized false and never set
// true in normal execution, so this branch should never be taken -- until a
// glitch corrupts the check.
volatile bool g_was_the_right_key_pressed = false;

//Check to see if button is pressed and we should evaluate the password
if (!digitalRead(ENTER_KEY_PIN)) {
  Serial.println("Enter Key Pressed\n");
  if(g_was_the_right_key_pressed)
  {
    unlock_system();
  }
}
The branch we attack. Glitch the power at just the right instant and the core mis-evaluates that inner if, calling unlock_system() even when the wrong key was pressed.

The circuit for power glitching is also very simple. It’s a Field Effect Transistor (FET) that is connected between the power and ground rails of the target, and it’s turned on very quickly, for a brief moment. In the world of side channel attacks, this FET is often called the crowbar FET. Activate it too long and you just turn the chip completely off, resetting it, or trip the brown out detector and it resets it for you. Too short and nothing happens.

Crowbar FET section of the schematic
Fig. 5 — The crowbar: a single power FET (Q3) across the target’s supply, gated by GLITCH_TRIGGER. Rated 30 V / 160 A, in a through-hole I-Pak so it’s easy to replace.

Not only is it a fine balance to achieve — it also has to be done at exactly the right time. That means it often takes very short pulses on the order of nanoseconds, or 0.000000001 s, to drive the crowbar FET just enough to hit that balance point.

Boy did I set myself up for a challenge picking the ESP32 for this. I ran into the most frustrating random behavior trying to get repeatable glitching pulses. I started by doing a quick back of the napkin calculation to see what was theoretically possible with the chip. (Wrongly, it turns out.)

Breaking down the theory, I looked at the ESP32-S3-MINI-1-N8 module’s datasheet and saw it had a 240 MHz clock, and this processor typically can complete one simple instruction per clock cycle. I made a gross assumption that if I wrote optimized assembly, I could theoretically send two commands, IO high and IO low back to back. Optimistically that might be two clock cycles, so maybe 240 MHz / 2 = 120 MHz, or 1/120 MHz = 8.3 ns. That’s not bad! Knowing there were probably other practical limitations here, that number was enough for me to spend a couple bucks getting one to see what I could actually get from it.

However, after lots of code optimization, reading datasheets, controlling the IO registers directly, I discovered the best I could get from it was 40 MHz or 25 ns. And that was with hand optimized assembly, and it wasn’t consistent. I had missed that the IO bus runs on its own 80 MHz clock. But more than that, it was constantly being interrupted and even with interrupts off, I would get random pulses that were hundreds of ns and then jump back to 25 ns. Sometimes it would behave for hours and then the next day, I couldn’t get any pulses shorter than 100 ns. It was maddeningly inconsistent.

On top of that, the duration of the pulse isn’t the only thing to consider, you also have to trigger that pulse at an exact time. And there was so much jitter (variance) between the trigger and when the pulse happened, it was looking like this would never work.

Then I had a clever idea that solved everything! Like most microcontrollers the ESP32 has specialized hardware for communications lines. Things like serial, I2C, and SPI, and they often have their own clocks and dedicated logic so the CPU jitter doesn’t affect the communications. I knew pulses from these modules would be clean and repeatable and not prone to the CPU interrupts. But could I change the pulse lengths and reliably trigger them?

More digging I found the SPI module has clock scaling. Testing the module I was getting rock solid 18 ns pulses on the oscilloscope! It should have theoretically been 12.5 ns. I attributed the extra time to a combination of capacitive loading and internal shift register delays from the SPI module. So I wrote a function to adjust the timing by changing the clock scaling. Note the function below isn’t perfect, there are discrete time steps, it just tries to get as close to the requested time as possible. But it is stable, repeatable, and it works!

Source: glitching.cpp — the function that fires the pulse, from the project repo (Code/Glitchy/src/).

//Shortest time about 18ns, longest time about 10000ns
void execute_spi_driven_glitch(unsigned long time_ns)
{
  unsigned long drive_frequency = 1/(0.000000001 * time_ns);

  spi_fspi.beginTransaction(SPISettings(drive_frequency, MSBFIRST, SPI_MODE0));
  spi_fspi.transfer(0b00000001);
  spi_fspi.endTransaction();
}
Clocking a single SPI bit out of the hardware shift register produces one clean, repeatable pulse whose width is set by the SPI clock — no CPU loop, no jitter.

While I don’t have any screenshots of the raw IO out, I can show you what a successful power glitch on an Arduino looks like. This is the VCC (Power) line to the Arduino.

Oscilloscope capture of a successful power glitch on the Arduino’s VCC line
Fig. 6 — A successful glitch on the Arduino’s VCC line.

Here we used a glitch pulse of about 0.93 µs, which crowbars the supply down from ~5.06 V to ~2.70 V. The goal is to disrupt a single instruction — though it’s not an exact science: internal capacitance, drain time, and other variables mean you may corrupt more than you intend. Either way, it’s short enough not to reset the chip. You can read more about the methodology and walk through the class lab in the wiki at the repo link at the top of this article. But basically, you trigger an event, and try several times at varying glitch pulse widths until you get the result you want.

This successfully bypassed the if check in the example code we included above, something that can only be done by glitching.

Power Monitoring

The other challenge going into this was knowing the ESP32’s analog-to-digital (ADC) conversion was very noisy internally. I had no idea if it would be up to the task of measuring minute power differences caused by different code execution flows in something like a small microcontroller.

I started by breadboarding some different basic filters and amp design. And when I say breadboarding I don’t mean protoboarding or prototyping. I mean grabbing a breadboard with through hole components building prototype circuits out there. You can quickly switch around components and change the topology. It’s like Legos with circuits.

Back to the ADC front end design. My thought was, if I make the signal large enough, and I drive the ADC with a solid amp, we should be able to overcome those limitations.

Schematic of the analog front end for power analysis
Fig. 7 — The analog front end.

The sense resistor

Fundamentally we want to be able to sense the current going to the target. One of the ways of doing this is putting what is called a shunt or sense resistor in line with the power supply to the target. However there is a tradeoff here with the value of the resistor.

The higher the resistor, the larger the voltage signal across it develops, and the easier to sense and process it. But that voltage drop across the resistor also takes away voltage to the target, and if you take too much away, the chip will brown out and not work at all.

Too low of a resistor, and the target is perfectly happy, but you can’t read the tiny voltage signal across that resistor and you just get noise.

And every target is different and has different current requirements. So the first part in the circuit is a configurable sense resistor. There is a resistor chain with dip switches that short out each resistor to bypass it, allowing you to configure how much resistance to use.

Sense-resistor bank and DIP switches on the board
Fig. 8 — The sense-resistor bank. Each DIP switch shorts out one resistor in the chain, so you can dial in how much resistance sits in line with the target’s supply.

Zoomed schematic of the sense-resistor bank: the R14–R21 chain and the SW1 DIP switch, outlined
Fig. 9 — The same bank in the schematic: the resistor chain (R14–R21), with each DIP switch on SW1 able to short out — and so bypass — its resistor.

Buffer Amp

One of the tradeoffs of this design for cost savings was using cheap single ended op-amps which means that the Glitchy board and the target board must share a ground. You will notice the buffer amp just has the one input to it, because it’s referencing that input to GND. Why have a buffer amp here? Put simply, op-amps in this configuration take very little current at their inputs, and use whatever power supply they’re hooked up to in order to produce a higher current mirror of the voltage signal they’re given. It’s worth noting there are MANY ways of using op-amps. What I am describing is the unity gain amplifier, or buffer amp you see here.

Buffer amp (U3A) highlighted in the analog front-end schematic
Fig. 10 — The input buffer (U3A) in the schematic: a unity-gain op-amp that reads the sense voltage without loading the circuit.

AC coupling

The job of the capacitor right after the buffer amp is to AC couple. Or in other words, we only want the CHANGE in voltage to be transmitted through, not the static DC bias. For example, say we have a 1 V steady DC voltage, and on that was riding a 1 kHz AC signal. If we only want that 1 kHz AC signal, we would AC couple it with a capacitor.

AC-coupling capacitor (C15) highlighted in the schematic
Fig. 11 — The AC-coupling capacitor (C15) in the schematic, sitting right after the buffer.

Diagram: AC coupling passes only the changing part of a signal
Fig. 12 — AC coupling.

The mechanism for how this works and why and the selection of the capacitor value and type are beyond the scope of this article. I might do a series on Electrical Engineering 101 at some point that would dive deeper into that. For now you can accept the ideal case that we are getting the signal changes through.

Bias Point

The next section is a resistor divider connected to a variable resistor, called a potentiometer. Remember how I mentioned a single ended amp setup? A single ended amp can only output positive voltage within whatever its power rails are. Adding a negative voltage rail here would have cost more and made this more complex. An alternative is you can bring the signal up so any negative signal gets shifted up into a readable range.

Bias divider (R25 and the bias potentiometer) highlighted in the schematic
Fig. 13 — The bias network in the schematic: R25 and the divider that set the DC level the signal rides on.

Diagram: shifting the AC-coupled signal onto a DC bias
Fig. 14 — Re-biasing.

You might be asking yourself, why did we go through the trouble of removing the DC bias just to add it again? The answer here is, we get to control the DC bias, and we need to make sure it’s in a range that the ADC on our chip can actually read. It has limits on what we can put into it without damaging it, it also has performance considerations on where it operates well at. Here we get to tune that point.

You will also see the first Do Not Populate (DNP) also called Do Not Install (DNI) symbol. On the delivered board I left these as potentiometers to allow for adjustment. But it’s just as easy to DNP the potentiometers and select static resistor values if you want to constrain the tool to one current range and make it simpler for the user.

The second amp

This last op-amp performs two tasks. First, it acts as a current buffer again so whatever we connect the output of this circuit to, doesn’t affect our resistor bias point. The same job as our input buffer. Second, it has variable gain. It lets us magnify the signal coming in so that the ESP32’s ADC input can hear the signal better.

Second amplifier stage (U3B) with its gain network highlighted in the schematic
Fig. 15 — The second stage (U3B) in the schematic: a variable-gain amp that boosts the signal to fill the ADC window.

Diagram: amplifying the biased signal to fill the ADC input window
Fig. 16 — Adding gain.

This flow lets us measure very small changes in a target’s current consumption.

The protection diode

The final part in this section of the circuit. It’s likely that people, especially people learning, are going to just turn dials and see what happens. And because we are powering the op-amps with 5 V, it’s possible to crank the gain up and exceed the ESP32’s input range, damaging the chip. So I have placed a protection diode at the output here. This is a Zener diode. Its role is to start conducting and short the signal if the voltage peaks too high, and thus protecting the ESP32.

Protection Zener (D5) at the ADC input, highlighted in the schematic
Fig. 17 — The protection Zener (D5) at the output, clamping the signal before it can exceed the ESP32’s input range.

Putting it all together

All this allows us to monitor the changes in a test program on the Arduino. The demo uses three keys, one of which runs a different code path. As you press each one, it looks at the current profile right after each button press. You can clearly see which key looks different in this screenshot.

Glitchy power-analysis screen: current traces for three keys, one clearly separating from the other two
Fig. 18 — The power-analysis view: current traces captured for three different keys. Key 3 (blue) takes a clearly different path from the other two.

In embedded systems it is very common to check each digit of a password as it is fed into the microcontroller from a keypad. This is a vulnerability, because you are able to test each key on the first digit of the password, figure that out, then move on to the next digit, and eventually decode the combination or password. It looks like this:

Phase 1 · pin down the first digit
  1. Reset the chip so you are on the first digit
  2. Send the number 1, capture the current
  3. Reset again so you are on the first digit
  4. Send the number 2, capture the current
  5. Rinse and repeat until you have tried all combinations for the first digit
  6. Figure out which one of the keypresses stands out for the first digit of the combination
Phase 2 · move to the next digit
  1. Reset the board, put in the first digit of the combination
  2. Send the number 1, capture the current
  3. Reset the board, put in the first digit of the combination
  4. Send the number 2, capture the current
  5. Rinse and repeat until you have done all the numbers and captured all the traces again
  6. Determine the second digit of the combo.

And so on…

And pretty soon you have the full combo to an electronic lock or something similar!

The demo program in the repo is pretty basic to demonstrate this point, but this is a very real vulnerability, and the same technique is also used to extract encryption keys through stochastic analysis.

The Target

Here was another point that I was adamant about. A lot of kits, even the ChipWhisperer which is arguably the leader in this area, uses special boards they designed for you to glitch and test with. It always felt to me underwhelming and disconnected from the point I want to get across.

Of course the hardware you designed is going to glitch or exploit the board you specifically designed to be glitched and exploited. Are the techniques going to work in the real world? I wanted the target for Glitchy to be something cheap that everyone is familiar with. That’s why I picked the Arduino Uno.

Below are some pictures of soldering on wires to the ATMEGA’s power bypass capacitor that feeds the chip its power.

Tinning wires before soldering to the Arduino
Fig. 19 — Tinning the wires before attaching them to the target.

Locating the bypass capacitor that feeds the ATMEGA
Fig. 20 — The bypass capacitor on the Arduino that feeds the ATMEGA its power — where we tap in.

Wires soldered to the target, close up
Fig. 21 — Wires soldered on, close up.

On most targets you tend to want to remove those bypass capacitors, as their job is to specifically help the chip stay up when there are power fluctuations. However, the crowbar on the Glitchy is so strong that at least for the Arduino Uno it didn’t matter so it’s easier to just leave it on.

Note we are not trying to short out the power to the Uno’s input power port before we even hit the regulator. Glitching there would be fighting all the regulator circuitry and capacitance. It would be impossible to bring the power on the microcontroller down the way we need to from that point. So we solder on as close to the target as possible. Also on real systems, we don’t want to glitch all the supporting hardware around the chip, just the target chip.

Again, there are a couple step by step lessons in the project repo with some vulnerable Arduino demo code.

Control Interface

This project runs a web interface to control the parameters and initiate the glitching. The first version of the web interface I wrote from scratch and it was very rough. This was 2024, before the current boom in AI capability. Otherwise I’d have leaned on an agent to help improve the look and review my code and design along the way. But alas this wasn’t an option, so I did the next best thing. I hired a good friend of mine that is much better at web design than I am to improve the web interface.

Glitchy web interface — welcome screen
Fig. 22 — The web interface landing screen: everything runs from the browser over Wi-Fi, no desktop software to install.

Glitchy web interface — power-glitching tab showing a successful run
Fig. 23 — The glitching tab: set the pulse-width sweep, fire, and it reports back when a glitch lands.

Glitchy web interface — power-analysis setup tab
Fig. 24 — The power-analysis setup tab, where you arm the capture before running a sweep.

The repo for the web interface is also open source and is also linked in the project repo.

There is an additional benefit to having a wireless control interface. Things get complicated and noisy fast doing power analysis when multiple grounds and power sources are added. Being wireless means the computer doing the control is completely isolated from the target. So much improved noise profile, and you avoid ground loop issues that can completely kill your signal.

Board cost estimation

Roughly what it costs to build one, using current LCSC parts and JLCPCB for the 2-layer board. In hobby quantities the parts run about $10 a board — the ESP32-S3 module alone is nearly half of that — dropping toward $7–8 at a hundred units.

QtyParts + bare PCB (you hand-solder)+ turnkey SMT assembly
5~$11–12~$22
30~$8.5~$10
100~$7.8~$8.5

Prices are ballpark and exclude shipping and tax. Turnkey assembly only starts to pay off past a few dozen boards, since it carries around $50 in one-time setup and part-loading fees.

Wrapping up

So there we have it, an open-source, open-hardware gadget you can use to exploit real hardware and learn about side-channel attacks. All packed into a low cost board with some neat tricks to make the ESP32 do things it was clearly never scoped to do. My hope is that others will take this, hack on it, and learn along the way. I am very open to collaborators if anyone wants to submit a pull request.

Interested in hiring someone to do this for you? → See what I offer