Author: canutethegreat

  • Flipper Zero, part 2: why so many office badges are weaker than they look

    Flipper Zero, part 2: why so many office badges are weaker than they look

    Part 2 of 5 in the Flipper Zero series. Part 1: what it actually is and what it can’t do.

    Most buildings I have walked into run on one of four card technologies, and the reception desk usually cannot tell you which. That matters, because the four have wildly different security properties and they look identical in a wallet. This part is about the two badge radios on the Flipper Zero, 125 kHz and 13.56 MHz, and what they reveal when you point them at your own cards.

    Same rules as part 1: hardware and cards I own, and a defender’s goal. A work badge usually belongs to your employer, so get written permission before testing one, and do the same before auditing a site.

    Two radios, four families

    Comparison of four badge families (125 kHz proximity, MIFARE Classic, iCLASS Classic, DESFire/Seos) showing what each card sends, whether it can be copied, and a verdict, with Wiegand versus OSDP Secure Channel underneath

    The low frequency radio at 125 kHz reads old proximity cards. EM4100 and HID Prox are the common ones. The high frequency radio at 13.56 MHz covers ISO 14443 and the NFC family: MIFARE Classic, MIFARE Ultralight, DESFire and the rest. HID’s iCLASS also lives at 13.56 MHz, but it is based on ISO 15693 and Flipper handles it separately in its Picopass app. The Flipper’s main menu sorts the cards under “125 kHz RFID” and “NFC”, and its read screen tells you which family it found for most of them. That screen is the first step of the audit, not the whole of it.

    125 kHz: an ID, not a credential

    An EM4100 tag transmits a 40 bit value, over and over, to anything that powers it up. There is no key, no challenge and no secret. HID Prox is much the same idea wrapped in the 26 bit Wiegand format called H10301: one parity bit, an 8 bit facility code, a 16 bit card number and a closing parity bit.

    You can decode that yourself in a few lines:

    def parse_h10301(bits: str):
        assert len(bits) == 26
        facility = int(bits[1:9], 2)
        card = int(bits[9:25], 2)
        return facility, card
    
    print(parse_h10301("00000001100000000000011111"))  # (3, 15)

    Sixteen bits of card number means 65,536 possible values per facility code, and facility codes are 8 bits. Nothing in the card proves it is the original. Copying one to a blank tag takes seconds with a Flipper or a ten dollar reader. I have never seen a reason to defend this technology beyond “we have not got round to replacing it”.

    MIFARE Classic: encryption that did not hold

    MIFARE Classic is the long-lived 13.56 MHz card from NXP, and it shipped with a proprietary cipher called Crypto1 and 48 bit keys. In 2008 researchers at Radboud University Nijmegen (Garcia and colleagues) published “Dismantling MIFARE Classic” at ESORICS, after Karsten Nohl and Henryk Plötz had reverse engineered the cipher from the chip. In 2009 a nested attack from the same group (IEEE S&P) recovered every key on a card given one known key, and Courtois published a variant that needed none. In 2015 Meijer and Verdult’s “hardnested” attack handled the hardened cards that NXP issued after the first breaks.

    In practice the weak point is often not the cipher at all. Many deployments leave sectors on the factory default key, FFFFFFFFFFFF, and many readers only look at the 4 or 7 byte UID. A UID is not a secret, and there are “magic” cards sold with a rewritable UID block. If the reader only checks the UID, the cryptography never gets a say.

    You can see what you have without special tools. With libnfc and an ordinary USB reader:

    $ nfc-list
    ISO/IEC 14443A (106 kbps) target:
        ATQA (SENS_RES): 00  04
           UID (NFCID1): 04  a2  3b  1c
          SAK (SEL_RES): 08

    Those values are illustrative, not from a real card, but the SAK byte is real: 0x08 identifies a MIFARE Classic 1K, 0x18 a 4K. A DESFire card answers differently, with a SAK of 0x20 and ISO 14443-4 support. The Flipper shows the same information on its screen without any laptop.

    iCLASS: the shared key problem

    HID’s original iCLASS (now called iCLASS Classic) used a master key shared across the product line. Milosch Meriac extracted it in 2010, and the 2012 paper “Dismantling iClass and iClass Elite” went on to break the Elite key diversification as well. Once a master key is public, every site using the default configuration is exposed, whether it knows or not. HID’s replacements, iCLASS SE and the Seos credential, moved to modern cryptography.

    What good looks like

    The fix is a card that authenticates with a per-card key, using a standard algorithm, and a reader that actually checks. MIFARE DESFire EV2 and EV3 use AES with mutual authentication, and Seos does too. Whichever you choose, ask your vendor four questions:

    1. Does the card use AES, and are keys diversified per card?
    2. Does the reader verify the credential, or only read a UID?
    3. Is the reader-to-controller link OSDP with Secure Channel enabled and a unique key, not Wiegand or the default install key?
    4. Who holds the master keys, and where do they live?

    The third question is the one people forget. Wiegand sends the card number down a few wires in cleartext, so a tap on the cable behind the reader defeats the best card on the market. OSDP v2 adds an AES-128 secure channel and also lets you supervise the reader, so a pulled or replaced one raises an alarm. I would put reader wiring on the same priority list as the cards.

    One caveat, because I try to be straight about limits: even a strong card can be relayed. An attacker standing near the victim and near the door can pass the radio exchange along in real time, and the crypto still succeeds. Distance bounding is the research answer. Some cards, DESFire EV2 and EV3 among them, offer a proximity check feature, but I rarely see it switched on. Defend with a second factor at sensitive doors, or camera coverage, rather than assuming the card solves it.

    Migrating without a big bang

    Nobody swaps every card in a weekend. Dual technology readers that accept the old and new credential let you issue new cards gradually, with a cutoff date after which the legacy mode is disabled in the controller. Skipping that last step is the usual failure, so put it in the project plan with a name next to it. I have seen buildings run “temporary” legacy support for six years.

    Start with the audit. Tap your own badge on a reader that tells you what it is, write down the family, and compare it with the list above. If the answer is 125 kHz or MIFARE Classic, you have your project.

    Part 3 moves to Sub-GHz remotes, rolling codes and how gates should be built.

    Other parts of the Flipper Zero series: part 1, part 2, part 3, part 4, part 5.

  • Flipper Zero, part 1: what it actually is and what it can’t do

    Flipper Zero, part 1: what it actually is and what it can’t do

    Part 1 of 5 in the Flipper Zero series.

    I own a Flipper Zero, and the first thing that struck me was how ordinary the insides are. Some people treat it as a skeleton key, others wave it off as a toy. Both are wrong. If you are responsible for doors, badges or wireless gear, it helps to know which parts of the legend are true, because the bad habits it exposes are very old ones.

    This series covers it from the defender’s side, on hardware I own, and nothing here is a how-to for getting into other people’s property. Later parts cover access cards, Sub-GHz remotes, USB keystroke injection and the Wi-Fi dev board.

    A small computer with a lot of radios

    The Flipper Zero comes from Flipper Devices Inc. It was funded on Kickstarter in 2020, where it raised about $4.8 million, and the first units reached backers roughly 18 months later. The firmware runs on FreeRTOS and is open source under the GPL, and the schematics are published. An app store opened in July 2023.

    The brain is an STM32WB55RG: a 64 MHz Arm Cortex-M4 for the application and a separate 32 MHz Cortex-M0+ for the radio stack, sharing 1024 KB of flash and 256 KB of SRAM. The screen is a 1.4 inch monochrome LCD at 128×64, you drive it with a five-way D-pad, and a microSD card (not in the box) holds your data. The interface is a pixel-art dolphin whose mood depends on how you use the device. That was a deliberate choice, and it explains the toy-versus-weapon argument better than any spec does.

    The interfaces

    Each radio is a separate, fairly standard part:

    • Sub-1 GHz: a TI CC1101 transceiver covering 315, 433, 868 and 915 MHz depending on region. This is where garage doors, gates and simple sensors live.
    • NFC at 13.56 MHz: an ST25R3916 handling ISO 14443 A and B, so MIFARE Classic, Ultralight and DESFire, plus FeliCa, iClass (Picopass) and NFC Forum tags.
    • 125 kHz RFID for older proximity cards, with formats such as EM4100 and HID H10301.
    • Bluetooth LE 5.4, infrared transmit and receive, iButton contacts and 13 GPIO pins. Flipper’s tech specs list those as 3.3V logic with 5V tolerant inputs. I treat that as a limit rather than an invitation: if you wire anything to them, read the GPIO documentation first and never connect another device’s power rail to the header.
    • USB-C, over which it can present itself as a keyboard. That is the BadUSB feature.
    Block diagram of the Flipper Zero: its microcontroller connected to the Sub-GHz, NFC, 125 kHz RFID, infrared, iButton, GPIO and USB interfaces

    Each of these is a commodity part a hobbyist can buy as a separate module. Flipper Devices’ contribution was packing them into one pocketable case with a friendly interface.

    Myth versus reality

    “It cracks any card.” No. Reading a card and breaking it are two different things. A 125 kHz card announces a fixed ID to anyone who asks, so copying one is trivial, and that is a flaw in the card. A system using modern cards with proper cryptographic authentication is a different problem, and a handheld does not change that.

    “It does Wi-Fi attacks.” Not by itself. There is no Wi-Fi radio on the board. The Wi-Fi features come from a separate add-on board, which gets its own part.

    “It can open any car or garage.” It can record and replay Sub-GHz signals, which only works against a receiver that accepts the same code every time. Rolling codes are designed to stop exactly that, and I will go through how in part 3.

    “It’s a toy.” Also no, as the next section shows. So the fair summary: the Flipper makes known weaknesses easy to demonstrate. It doesn’t invent new ones.

    Why institutions got nervous anyway

    Amazon banned its sale on 7 April 2023, describing it as a card skimming device. Packages ordered in Brazil in 2023 were reported seized by the telecom regulator Anatel. In February 2024, Innovation, Science and Economic Development Canada announced an intention to ban devices that could be used to clone wireless signals for remote entry, in response to a rise in car theft. Whether those moves were proportionate is debatable. They do show that people are worried about cheap, easy-to-use radio tools, and banning one product won’t remove the underlying weaknesses.

    There is a milder example too. With third-party firmware or apps the device can send Bluetooth LE advertisements that pop up on nearby phones. That was disruptive enough that Android and Windows added detection for BLE spam.

    What a defender should do with this

    Treat it as a cheap way to audit your own estate, within your local radio rules. If it can read and replay your badges or remotes, so can many other devices that do not have a dolphin on the screen. Check which card technology your access system uses, whether your gate remotes use fixed codes, and whether your endpoints let any USB keyboard type into a logged-in session. If the answer is a fixed identifier, a protocol with known weaknesses or a remote with no rolling code, the gadget is the least of your worries, so plan the migration.

    Only point it at gear you own or have written permission to test. That’s the law in most places, and it’s also the line between an audit and a problem.

    Part 2 looks at RFID and NFC badges, and why so many office cards are weaker than people think.

    Other parts of the Flipper Zero series: part 1, part 2, part 3, part 4, part 5.

  • Zombie infrastructure: forgotten assets and attack surface management

    Zombie infrastructure: forgotten assets and attack surface management

    Every organisation I’ve worked with had infrastructure nobody remembered. A staging environment from a project that got cancelled. A marketing microsite from a 2019 campaign, still running a CMS that hasn’t been patched since. A DNS record pointing at a cloud resource someone deleted two years ago. A test tenant with a service account whose password hasn’t changed since it was created.

    None of it is in the asset inventory. If it were, someone would have switched it off years ago. That’s the danger: you can’t patch, monitor or decommission something you don’t know exists, and attackers are very good at finding exactly those things. It’s Halloween, so let’s talk about the undead.

    Why this keeps causing breaches

    Flow diagram: Certificate Transparency, subdomain enumeration, scans and DNS exports plus cloud inventory, IaC state and identity provider feed a reconcile step that outputs dangling DNS, unowned resources, shadow services and stale identities, each routed to assign an owner or disconnect then delete, on a scheduled loop

    Two incidents make the point better than any vendor slide deck.

    In the 2017 Equifax breach, attackers came in through CVE-2017-5638 in Apache Struts on an online dispute portal. The patch had been out since early March. Equifax had an internal alert about it and ran a scan, and the scan didn’t find the vulnerable system. Then, per the US House Oversight Committee’s report, an SSL certificate on a device that inspected outbound traffic had expired months earlier, so data left the network uninspected for weeks. The vulnerable app and the blind monitoring device were both things the organisation owned and had lost track of.

    In January 2024, Microsoft disclosed that the group it tracks as Midnight Blizzard had password-sprayed its way into a legacy, non-production test tenant account that didn’t have MFA. From there the attackers used a legacy test OAuth application with elevated access to reach corporate mailboxes, including senior leadership. Nothing clever was needed. It took one forgotten account in one forgotten tenant.

    In both cases the system everyone was watching was fine. The way in was the thing that was supposed to be temporary.

    The common kinds of zombie

    Forgotten hosts and services are the obvious ones: old VMs, test environments, a jump box someone built for a migration. They’re unpatched because no patching process knows about them, and they often have weaker auth because they were “only for testing”.

    Dangling DNS is subtler and, in my experience, more common. A CNAME for promo.example.com points at example-promo.s3-website-us-east-1.amazonaws.com, or an Azure App Service hostname, or a Heroku app. The cloud resource gets deleted, but the DNS record stays. If the provider lets anyone claim that name, an attacker registers it and now serves content on your subdomain, with your cookies in scope if they’re set on the parent domain. The community-maintained “can-i-take-over-xyz” project on GitHub tracks which services are vulnerable to this and how to fingerprint them.

    Released IP addresses are the same problem one layer down. An A record still points at an Elastic IP or public IP you released. The cloud provider hands that IP to another customer, and your hostname now resolves to their server.

    Then there are identities: service accounts, API keys, OAuth apps and test tenants that outlived their project. These don’t show up in a port scan, which is why they get forgotten even by teams that do external scanning well.

    Find what you have from the outside first

    Start where an attacker starts. That view doesn’t depend on your assumptions.

    Certificate Transparency (RFC 6962) logs every publicly trusted TLS certificate, and every hostname you ever got a certificate for is in there. That’s usually the single best source of forgotten subdomains:

    curl -s 'https://crt.sh/?q=%25.example.com&output=json' \
      | jq -r '.[].name_value' | tr 'A-Z' 'a-z' | sed 's/^\*\.//' | sort -u > ct-hosts.txt

    Passive DNS and enumeration tools such as subfinder or OWASP Amass add hostnames from other sources. Then check which of them resolve and answer:

    subfinder -d example.com -silent | sort -u > enum-hosts.txt
    sort -u ct-hosts.txt enum-hosts.txt | dnsx -silent -a -cname -resp > resolved.txt
    cut -d' ' -f1 resolved.txt | sort -u | httpx -silent -status-code -title -tech-detect > live.txt

    Only run active probing against domains and IP ranges you own or are authorised to test. CT logs will happily list hostnames that belong to a vendor or a former subsidiary.

    For dangling DNS specifically, look at every CNAME pointing at a cloud provider’s namespace and check whether the target still exists. An NXDOMAIN on the target, or a provider’s “no such bucket” or “app not found” page, is the signal:

    dig +short CNAME promo.example.com
    # example-promo.s3-website-us-east-1.amazonaws.com.
    curl -s http://promo.example.com/ | grep -o 'NoSuchBucket'

    Then compare against what you think you have

    The outside view tells you what’s exposed. The inside view tells you what you’re paying for. Pull both and reconcile them.

    Every cloud provider has an inventory API. On AWS, the resource groups tagging API or AWS Config lists resources across services, and Route 53 can export every record you host. On GCP, Cloud Asset Inventory does the same with gcloud asset search-all-resources, and Azure has Resource Graph. Run them across every account and subscription, including the ones in the “sandbox” OU nobody looks at.

    The reconciliation is where the value is:

    • Hostnames in DNS or CT with no matching cloud resource are dangling records or something hosted elsewhere you didn’t know about.
    • Cloud resources with no owner tag and no recent deploys are zombie candidates.
    • Public IPs and load balancers that answer on the internet but aren’t in any service catalogue are shadow services.
    • Identities with no sign-in or API use in 90 days are accounts to disable.

    Give everything an owner, or a death date

    Discovery without ownership just produces a spreadsheet that’s wrong next month. The policy that works is simple to state and annoying to enforce: every asset has an owning team, and anything without one is scheduled for shutdown.

    Enforce it at creation time. Require an owner tag through AWS Service Control Policies or tag policies, Azure Policy or GCP organisation policy constraints, so untagged resources can’t be created in the first place. Give temporary environments an expires tag and a job that deletes them when it passes. Delete DNS records in the same change that deletes the resource they point to. Infrastructure as code helps a lot here, because removing a resource from Terraform can remove its DNS record in the same apply.

    For decommissioning, I like a two-step approach. First, disconnect the asset: remove it from DNS, block inbound traffic, disable the account. Wait a couple of weeks. If nobody screams, delete it. If someone does, you’ve just found the owner.

    Make it continuous

    A one-time sweep finds a pile of zombies and then the pile slowly grows back. Run the external discovery on a schedule, diff the results against the previous run, and alert on new hostnames, new open ports and new dangling CNAMEs. Commercial attack surface management products do this with more sources and nicer dashboards, but the core loop of discover, diff, assign an owner and decommission works fine with open-source tools and a cron job.

    Try this: pick a random hostname from your CT log results and ask who owns it. If the answer takes more than a minute, you’ve got zombies.