Latest / CyberCode Academy / Course 42 - Mobile Malware Analysis Fundamentals | Episode 3: iOS Application Architecture and Jailbreaking Fundamentals
Transcript
- 0:00Speaker 1: Imagine buying this massive, you know, seemingly impenetrable digital fortress. Right,
- 0:06Speaker 1: you lock all your most valuable data inside your banking details,
- 0:10Speaker 1: private messages, your location history, and then intentionally you just
- 0:15Speaker 1: hand a master key to a teenager with a laptop.
- 0:17Speaker 2: I mean, yeah, that is essentially what you're doing when
- 0:19Speaker 2: you jail break a smartphone exactly.
- 0:21Speaker 1: Every time you pull that sleek piece of glass out
- 0:23Speaker 1: of your pocket and swipe through that like frictionless interface,
- 0:26Speaker 1: you are gliding over one of the most aggressively guarded
- 0:30Speaker 1: software environments on the planet.
- 0:31Speaker 2: Oh. Absolutely, it's wild to think about.
- 0:34Speaker 1: So today on this deep dive, we are tearing up
- 0:36Speaker 1: the floorboards. We're going to explore the underlying architecture of iOS,
- 0:40Speaker 1: figure out how these apps are actually constructed and isolated,
- 0:44Speaker 1: and then look at how hackers actively break out of
- 0:46Speaker 1: Apple's walled garden.
- 0:47Speaker 2: Yeah, we're basically looking at a masterclass in modern security engineering.
- 0:51Speaker 2: But it's also a case study and how no system
- 0:54Speaker 2: is completely bulletproof because the philosophy behind iOS is just
- 0:58Speaker 2: absolute control, maintains strict oversight over what gets built, how
- 1:04Speaker 2: it runs, what it can access.
- 1:06Speaker 1: So to really understand how someone breaks out of that environment.
- 1:09Speaker 1: You have to understand how it's built from the ground
- 1:11Speaker 1: up exactly.
- 1:12Speaker 2: You have to start at the foundation, which.
- 1:14Speaker 1: Brings us to well, the kitchen if x code is
- 1:17Speaker 1: the kitchen where developers build everything, the raw ingredients. For
- 1:21Speaker 1: the longest time, we're written in this language called objective C.
- 1:25Speaker 2: Oh yeah, objective C.
- 1:27Speaker 1: Wait, objective C is practically ancient in tech years, right,
- 1:30Speaker 1: I mean, it dates back to the nineteen eighties, the eighties.
- 1:33Speaker 1: It's an object oriented language based on Standard C, but
- 1:36Speaker 1: it bolted on this highly specific message passing syntax. Okay,
- 1:40Speaker 1: let's unpack this. Why did Apple feel the need to
- 1:43Speaker 1: invent a completely new language like Swift in twenty fourteen
- 1:47Speaker 1: instead of just updating objective C.
- 1:48Speaker 2: Well, it comes down to legacy, debt and ecosystem lock in.
- 1:53Speaker 2: Apple actually inherited objective C from next to Step.
- 1:56Speaker 1: That was Steve Jobs's company before he returned to Apple.
- 1:59Speaker 2: Right, right, exactly, and it was powerful. But you're right,
- 2:02Speaker 2: the syntax was just incredibly clunky by modern standards.
- 2:06Speaker 1: So for a long time, if you wanted to build
- 2:08Speaker 1: an iPhone app, you just had to suffer through this
- 2:11Speaker 1: steep learning curve.
- 2:12Speaker 2: You did, but that creates a massive bottleneck. I mean,
- 2:15Speaker 2: if your entire business model relies on the App Store
- 2:18Speaker 2: just exploding with millions of apps, you can't force every
- 2:23Speaker 2: new programmer to learn an archaic language.
- 2:25Speaker 1: You'd scare them away.
- 2:26Speaker 2: Yeah, exactly, so they rolled out Swift. It wasn't just
- 2:29Speaker 2: about speed. It was about lowering the barrier to entry.
- 2:32Speaker 1: I've actually looked at some Swift code and it reads
- 2:35Speaker 1: so much closer to plane English.
- 2:37Speaker 2: It really does.
- 2:38Speaker 1: It handles memory management more safely, and it dumps a
- 2:41Speaker 1: lot of those intimidating brackets. They basically rebuilt the kitchen
- 2:45Speaker 1: to attract.
- 2:45Speaker 2: More chefs, and those chefs use an integrated development environment,
- 2:50Speaker 2: you know, an ID called xcode. That is where they
- 2:53Speaker 2: write the Swift code, design the interfaces, and hook into
- 2:56Speaker 2: Apple's frameworks like.
- 2:58Speaker 1: Coco Touch for processing screenswat.
- 3:00Speaker 2: Right, or the underlying media layers for audio and video.
- 3:03Speaker 2: But writing the code is really only half the.
- 3:06Speaker 1: Battle here, because then the strict health inspector steps.
- 3:08Speaker 2: In exactly once the app is finished, xcode bundles it up,
- 3:12Speaker 2: signs it with a cryptographic certificate, and sends it off
- 3:15Speaker 2: for review. If it tries to access private APIs, Apple
- 3:19Speaker 2: just rejects it.
- 3:20Speaker 1: So let's assume the app passes inspection, you download it,
- 3:23Speaker 1: and it lands on your home screen. Yeah, this is
- 3:25Speaker 1: where Apple's paranoia and I mean that affectionately really kicks in. Yeah,
- 3:30Speaker 1: how does this system ensure that a random game you
- 3:32Speaker 1: just downloaded can't like silently read your email app in
- 3:36Speaker 1: the background.
- 3:37Speaker 2: Well, if we connect this to the bigger picture, it's
- 3:39Speaker 2: all done through an architecture called the sandbox.
- 3:41Speaker 1: The sandbox, right, it.
- 3:43Speaker 2: Is one of the most critical security mitigations in the
- 3:46Speaker 2: whole os The core philosophy is isolation and damage control.
- 3:51Speaker 1: So an application becomes compromised or it turns out to
- 3:53Speaker 1: be malicious. The sandbox contains the blast radius exactly. Conceptually,
- 3:58Speaker 1: it totally makes sense. It's literally like a sandbox at
- 4:00Speaker 1: a playground. Each app is a kid playing in their
- 4:03Speaker 1: own box. They can build whatever sand castles they want
- 4:05Speaker 1: in their own box, but they are strictly forbidden from
- 4:08Speaker 1: throwing sand into another kid's box.
- 4:10Speaker 2: That is a perfect analogy, and mechanically, if you look
- 4:13Speaker 2: at the file system, you see a highly compartmentalized hierarchy.
- 4:17Speaker 2: Every single app gets its own isolated directory structure.
- 4:20Speaker 1: And it's cryptographically barred from reaching outside of it. Yep.
- 4:24Speaker 2: Inside that specific sandbox, you have several distinct containers. First
- 4:28Speaker 2: is the app bundle, which has the executable code and
- 4:31Speaker 2: static resources like.
- 4:33Speaker 1: Icons, And because that's signed by Apple, the system constantly
- 4:36Speaker 1: checks to make sure the bundle hasn't been altered, right right.
- 4:39Speaker 2: Then, totally separate from that code, you have the user data.
- 4:43Speaker 2: There's a documents directory for files the user creates.
- 4:47Speaker 1: So the interactive content.
- 4:48Speaker 2: Yeah, a data directory for the app's internal organization, a
- 4:52Speaker 2: hidden library directory for system canfig files, and.
- 4:55Speaker 1: Temp folder, and that temfolda just gets wiped out between launches.
- 4:58Speaker 2: Exactly. By separating code from the user data, it's significantly
- 5:02Speaker 2: harder for an attacker to inject bad instructions into the
- 5:05Speaker 2: core files and all of.
- 5:06Speaker 1: These directories, the code, the icons, They arrive on your
- 5:09Speaker 1: device wrapped in a file with an IPA extension.
- 5:12Speaker 2: Yeah, the iOS app store package.
- 5:14Speaker 1: But and this is the open secret. An IPA file
- 5:18Speaker 1: isn't some mystical hyper encrypted Apple vault. It is literally
- 5:22Speaker 1: just a standard ZIP archive wearing a fake mustache.
- 5:25Speaker 2: It really is. It relies on standard compression. The security
- 5:28Speaker 2: doesn't come from the IPA wrapper itself.
- 5:30Speaker 1: It comes from the sandbox on the device, right.
- 5:32Speaker 2: And the digital signature is on the files inside.
- 5:34Speaker 1: Okay, which means if we have that IPA file sitting
- 5:37Speaker 1: on our desktop computer, we can just rip it open.
- 5:40Speaker 2: Yeah, we can.
- 5:41Speaker 1: This gets us into static analysis. Let's say I'm a
- 5:43Speaker 1: security researcher. I've downloaded the IPA. My immediate impulse is
- 5:46Speaker 1: just double click it and see what falls out.
- 5:48Speaker 2: See that would be a massive mistake in any forensic context.
- 5:52Speaker 1: Wait, really, why The absolute.
- 5:54Speaker 2: First thing you must do before you unzip or interact
- 5:58Speaker 2: with the file is generate a cryptograph cash Usually you
- 6:01Speaker 2: drop into the command line and run an MT five
- 6:04Speaker 2: sum or a SAHA two fifty six command.
- 6:07Speaker 1: So what does this all mean? If I just downloaded
- 6:10Speaker 1: the file from a banking server, why on earth do
- 6:12Speaker 1: I need to run a complex MD five hash check?
- 6:15Speaker 1: Can I just crust it?
- 6:17Speaker 2: Do you really trust it? Though? In cybersecurity, assumptions are vulnerabilities.
- 6:21Speaker 1: I guess that's true.
- 6:22Speaker 2: You cannot trust the network or the server or a
- 6:25Speaker 2: file and transit supply chain attacks happen all the time.
- 6:28Speaker 2: Man in the middle attacks happen.
- 6:30Speaker 1: Right, So a hash is basically a unique digital fingerprint
- 6:33Speaker 1: of that file's.
- 6:34Speaker 2: Exact state exactly. If a bad actor intercepted your download
- 6:38Speaker 2: and flipped a single bit of code to hide a
- 6:40Speaker 2: back door, the file looks identical, but the MD five
- 6:44Speaker 2: hash will be radically different.
- 6:46Speaker 1: So generating that hash is your only mathematical guarantee that
- 6:50Speaker 1: you are analyzing the authentic file precisely.
- 6:52Speaker 2: You have to ensure forensic integrity.
- 6:54Speaker 1: Okay, I get it. We run the hash, the fingerprint matches.
- 6:57Speaker 1: Now we can finally drop the disguise because it's just
- 7:00Speaker 1: a zip archive. We run a standard unzip command right
- 7:03Speaker 1: in the terminal YEP, and the IPA structure unpacks.
- 7:06Speaker 2: A very specific folder spills out called the payload directory.
- 7:09Speaker 1: And nested inside that payload directory is the app bundle
- 7:12Speaker 1: we discussed earlier.
- 7:13Speaker 2: Right, this is where static analysis gets really fascinating. You
- 7:16Speaker 2: strip away the polished user interface and you are looking
- 7:19Speaker 2: at the raw mechanical parts.
- 7:22Speaker 1: Among all the image files in there, two things stand out. First,
- 7:25Speaker 1: there's an info dot plist file.
- 7:27Speaker 2: The property list. It's a binary encoded XML file that
- 7:31Speaker 2: acts as the app's ID card. It tells iOS the
- 7:34Speaker 2: app's name, version, and crucially what permissions.
- 7:38Speaker 1: It needs, like camera access, or location tracking exactly. And
- 7:42Speaker 1: right next to that ID card is the main event,
- 7:45Speaker 1: the Maco sixty four bit executable. That is the actual
- 7:50Speaker 1: compiled Swift or objective C code, the engine of the app.
- 7:54Speaker 2: Right. But here is the massive limitation of static analysis.
- 7:57Speaker 2: It's static.
- 7:58Speaker 1: We are dissecting a lifeless binary on a desktop computer.
- 8:02Speaker 1: We can see the code, but we can't see how
- 8:04Speaker 1: it behaves when the engine is running.
- 8:05Speaker 2: And that is exactly why the sandbox is so frustrating
- 8:08Speaker 2: for security researchers.
- 8:09Speaker 1: Because it blocks you.
- 8:11Speaker 2: Yeah, if you want to know what an app is
- 8:13Speaker 2: truly doing, say you suspect it's secretly scraping your clipboard,
- 8:16Speaker 2: you have to perform dynamic analysis. You need to attach
- 8:19Speaker 2: a debugger, watch its memory, and monitor network traffic while
- 8:22Speaker 2: it runs on the device.
- 8:23Speaker 1: But Apple sandbox actively restricts all those debugging tools.
- 8:26Speaker 2: It completely blocks you from peering into another app's container.
- 8:29Speaker 1: So to do your job as a researcher, you have
- 8:32Speaker 1: to break the operating system. You have to escape the
- 8:34Speaker 1: sandbox entirely, which is the whole point.
- 8:36Speaker 2: Of jail breaking exactly.
- 8:38Speaker 1: Here's where it gets really interesting, though. If jail breaking
- 8:41Speaker 1: ruins all the beautiful security Apple Build. Why do people bother?
- 8:46Speaker 1: Is it just to pirate apps?
- 8:47Speaker 2: This raises an important question. I mean, sure some people pirate,
- 8:51Speaker 2: but for researchers, it's about achieving root access.
- 8:55Speaker 1: Total unrestricted administrative control over the device.
- 8:58Speaker 2: Yes, so you can actually see what these apps are
- 9:01Speaker 2: doing in the dark. But to run unapproved, unsigned code,
- 9:05Speaker 2: you have to systematically dismantle Apple's security mechanisms.
- 9:09Speaker 1: By exploiting vulnerabilities in the hardware or the software. But
- 9:13Speaker 1: how do you pick a digital lock engineered by a
- 9:16Speaker 1: multi trillion dollar company.
- 9:17Speaker 2: Well, it all starts the millisecond you press the power button.
- 9:20Speaker 2: The boot sequence works like a rigid chain of trust.
- 9:23Speaker 1: The boot sequence is basically a high stakes relay race.
- 9:26Speaker 1: Apple security relies on every runner passing the baton perfectly.
- 9:29Speaker 2: That's a great way to put it. Each guard must
- 9:32Speaker 2: verify the identity of the next guard before letting them
- 9:35Speaker 2: take over. And the very first guard is the bootROM.
- 9:38Speaker 1: And the bootROM is basically untouchable. Right. It's not software
- 9:41Speaker 1: you can just rewrite.
- 9:42Speaker 2: It is read only memory, literally masked into the silicon
- 9:46Speaker 2: of the processor during manufacturing. When the device powers on,
- 9:50Speaker 2: its job is to cryptographically verify the low level bootloader, and.
- 9:55Speaker 1: If the signature is valid, it passes the baton. The
- 9:58Speaker 1: bootloader then verifies iBoot, which verifies and loads the iOS kernel.
- 10:03Speaker 1: So if hackers can trip up that very first runner
- 10:06Speaker 1: the boot rom, the entire rest of the race is compromised.
- 10:09Speaker 1: Everything downstream trusts the corrupted upstream.
- 10:12Speaker 2: Which is why hardware exploits are incredibly attractive to hackers.
- 10:16Speaker 2: These are called tethered or semi untethered jail breaks. Because
- 10:19Speaker 2: the flaw is physical, Apple absolutely cannot patch it with
- 10:22Speaker 2: a software update wow.
- 10:23Speaker 1: So once an exploit is known, it works forever on
- 10:26Speaker 1: that device forever.
- 10:27Speaker 2: But hardware flaws are rare. Most of the time, hackers
- 10:31Speaker 2: attack the software later in the sequence, specifically the iOS kernel.
- 10:34Speaker 1: These are the untethered or semi tethered jail breaks. And
- 10:38Speaker 1: this is the ultimate cat and mouse game, right Because
- 10:41Speaker 1: it's software. Apple can fight back.
- 10:43Speaker 2: Oh, they fight back hard. They introduced a mitigation called
- 10:47Speaker 2: Kernel Patch Protection or KPP. It acts as a watchdog
- 10:51Speaker 2: that constantly scans the kernel's memory.
- 10:53Speaker 1: So if a jailbreak tool tries to modify the kernal
- 10:55Speaker 1: to disable the sandbox, KPP detects it.
- 10:58Speaker 2: Right, it assumes the system is under attack and instantly
- 11:01Speaker 2: triggers a kernel panic, crashing and rebooting the device.
- 11:03Speaker 1: Plus Apple stops digitally signing older iOS versions. If a
- 11:07Speaker 1: hacker finds a vulnerability in iOS fourteen, Apple patches it
- 11:11Speaker 1: in fourteen point one and refuses to sign the old version,
- 11:14Speaker 1: so you can't downgrade.
- 11:15Speaker 2: The window of opportunity just slam shut.
- 11:17Speaker 1: Okay, so let's put you the listener, in the shoes
- 11:19Speaker 1: of someone actually doing this. We're going to execute a
- 11:22Speaker 1: kernel level jailbreak on a test device, let's say an
- 11:25Speaker 1: iPhone five S on an older iOS version.
- 11:28Speaker 2: Prepare for frustration. The process is incredibly finicky. Modern exploits
- 11:32Speaker 2: rely on manipulating exact memory conditions. It is not a
- 11:36Speaker 2: clean Hollywood style hack where you.
- 11:38Speaker 1: Just hit enter right, So we have to make the
- 11:40Speaker 1: environment utterly sterile. We set the phone up as a
- 11:43Speaker 1: new device, disabled touch ID, remove the pass code, turn
- 11:47Speaker 1: off SERI location services Wi Fi, put it in airplane mode.
- 11:51Speaker 2: You have to.
- 11:52Speaker 1: It's so ironic. We're basically turning this ultra smart smartphone
- 11:56Speaker 1: into a temporary dumb brick just to make it vulnerable
- 11:59Speaker 1: enough to have Why is that set up so rigid?
- 12:03Speaker 2: Because of memory management. An exploit needs the memory arranged
- 12:06Speaker 2: in a highly specific pattern. If WiFi is on or
- 12:09Speaker 2: Siri pings a server in the background, it shifts the
- 12:12Speaker 2: system memory.
- 12:12Speaker 1: And if the memory shifts right as your exploit runs.
- 12:15Speaker 2: You miss your target. The kernel panics and the device
- 12:18Speaker 2: crashes all.
- 12:19Speaker 1: Right, so the phone is digitally comatose. In airplane mode.
- 12:22Speaker 1: We use a third party app installer to download an
- 12:24Speaker 1: exploit tool like the unquavert jailbray.
- 12:26Speaker 2: We tap the icon and iOS immediately blocks you. The
- 12:29Speaker 2: walled garden is still functioning. It checks the signature and
- 12:33Speaker 2: refuses to run the app.
- 12:34Speaker 1: So we have to go into settings, navigate to profiles
- 12:36Speaker 1: and device management and manually tell the OS to trust
- 12:40Speaker 1: the developer profile. We override the health inspector exactly.
- 12:43Speaker 2: Then you open the app, hit the jail brake button
- 12:46Speaker 2: and the app attempts to patch.
- 12:47Speaker 1: The kernel, and usually it fails. Right the device unexpectedly restarts.
- 12:52Speaker 2: Often multiple times. You have to clear caches, ensure airplane
- 12:55Speaker 2: mode is on, and try again.
- 12:57Speaker 1: But eventually the memory lignes, the payload executes, the kernel
- 13:02Speaker 1: is patched, and the device resprings and.
- 13:04Speaker 2: When the screen lights up you see it visual confirmation.
- 13:08Speaker 2: An app called Citia appears on the home.
- 13:10Speaker 1: Screen, Cydia being the jailbroken alternative app store.
- 13:14Speaker 2: Right the sandbox walls are down, but.
- 13:16Speaker 1: We want ultimate verification. Because Citya installs open ssh in
- 13:21Speaker 1: the background, we can connect the phone to Wi Fi,
- 13:23Speaker 1: find its IP address, and use a computer terminal to
- 13:26Speaker 1: SSH directly into the phone's root file system.
- 13:29Speaker 2: You're initiating a connection targeting the root user account, and
- 13:33Speaker 2: it asks for a.
- 13:34Speaker 1: Password, and this is crazy to me. The notorious default
- 13:37Speaker 1: password for this back door across every iOS device is
- 13:40Speaker 1: just Alpine Alpi. You type it in and boom, you
- 13:43Speaker 1: have a root command prompt inside the iPhone.
- 13:45Speaker 2: It's an incredible amount of power. You can browse the
- 13:48Speaker 2: entire unrestricted file system. But it's also a massive liability.
- 13:53Speaker 2: If you leave that SSH port open with a default password,
- 13:56Speaker 2: anyone on the network can take over your phone.
- 13:58Speaker 1: You've completely dismandled the fortress. It is a wild journey
- 14:03Speaker 1: to wrap up. We went from writing clean swift code
- 14:06Speaker 1: and x code, to packaging it in a disguise ZIP sandbox,
- 14:09Speaker 1: to forcefully tearing down those walls with a kernel exploit.
- 14:13Speaker 2: The tension between securing a system and human curiosity to
- 14:16Speaker 2: break it is just relentless.
- 14:19Speaker 1: So before we sign off, a quick interactive review exercise
- 14:22Speaker 1: for you listening. Imagine you've just been handed a mysterious
- 14:25Speaker 1: IPA file. Based on our deep dive, what is the
- 14:28Speaker 1: absolute first command line tool you should use to check
- 14:31Speaker 1: its integrity before you do anything else?
- 14:33Speaker 2: On on zip it yet?
- 14:34Speaker 1: Right? If you said the mt five sum command, you nailed.
- 14:36Speaker 2: It, which is so crucial. And you know we mentioned
- 14:39Speaker 2: earlier that hardware level bootROM vulnerabilities can't be patched by
- 14:43Speaker 2: a software update.
- 14:44Speaker 1: Oh right, the physical flaws.
- 14:45Speaker 2: Yeah, this means there are millions of older Apple devices
- 14:49Speaker 2: sitting in drawers around the world that will always be
- 14:52Speaker 2: vulnerable to anyone who physically holds them. It begs the question,
- 14:56Speaker 2: as our device's age out of software support, does true
- 14:59Speaker 2: DIVI security eventually come with an expiration date?
- 15:02Speaker 1: That is a fascinating thought to leave on. Definitely something
- 15:05Speaker 1: to chew on until next time. Keep looking beneath the surface.