Latest / CyberCode Academy / Course 42 - Mobile Malware Analysis Fundamentals | Episode 10: The Essentials of Dynamic Analysis
Transcript
- 0:00Speaker 1: Imagine for a second that you are a bomb disposal expert.
- 0:04Speaker 2: Okay, I'm with you.
- 0:05Speaker 1: But instead of you know, sweating over a ticking device
- 0:10Speaker 1: in a crowded city square, like gently trying to figure
- 0:13Speaker 1: out whether to cut the red wire or the blue wire,
- 0:15Speaker 1: you use a completely different strategy.
- 0:17Speaker 2: A safer one, hopefully exactly. Yeah.
- 0:19Speaker 1: You take the explosive device, you lock it inside a
- 0:22Speaker 1: heavily reinforced steel vault, You step back behind like three
- 0:26Speaker 1: feet of blast glass, and you just detonate it.
- 0:28Speaker 2: You just blow it up.
- 0:29Speaker 1: You blow it up on purpose, just to watch exactly
- 0:32Speaker 1: how the explosion works. I mean, you want to see
- 0:34Speaker 1: what triggers first, how big the blast radius is, what
- 0:37Speaker 1: kind of shrapnel flies out.
- 0:38Speaker 2: It's such a vivid image, and honestly, it really perfectly
- 0:42Speaker 2: captures the essence of dynamic malware analysis, right because you
- 0:46Speaker 2: aren't trying to diffuse the malicious code by gently picking
- 0:50Speaker 2: it apart in the dark. You are giving it a safe, contained,
- 0:54Speaker 2: you heavily monitored space to just do its absolute worst.
- 0:58Speaker 1: Also, you can observe exactly what it's programmed to do exactly,
- 1:01Speaker 1: and that is our mission for today's deep dive. We're
- 1:04Speaker 1: going to walk you through the practical, step by step
- 1:08Speaker 1: scientific process of dynamic.
- 1:10Speaker 2: Analysis, specifically looking at the iOS environment so Apple devices.
- 1:15Speaker 1: Yeah, we want to uncover the true functionality of a
- 1:18Speaker 1: suspicious application by letting it run and carefully recording the results.
- 1:23Speaker 1: So we're talking about tracking network connections, device modifications, hidden.
- 1:27Speaker 2: Behaviors, everything that happens while the app is alive and breathing,
- 1:30Speaker 2: basically right.
- 1:31Speaker 1: So to connect this to the broader picture of how
- 1:34Speaker 1: we analyze malware, maybe we should contrast it with static analysis.
- 1:37Speaker 2: First. Yeah, that's a good idea because if you've ever
- 1:40Speaker 2: looked at static analysis, well, let me see if I
- 1:42Speaker 2: can unpack that within an analogy.
- 1:44Speaker 1: So if static analysis is like studying the blueprints of
- 1:47Speaker 1: a house, like looking at the architectural drawings to see
- 1:49Speaker 1: where the doors and windows are supposed to be, right,
- 1:51Speaker 1: then dynamic analysis is letting the construction crew actually build
- 1:55Speaker 1: the house while you sit across the street with a
- 1:57Speaker 1: pair of binoculars to see if they install this secret
- 2:00Speaker 1: trapdoor that definitely wasn't on those original blueprints.
- 2:03Speaker 2: That is a great way to look at it because
- 2:06Speaker 2: blueprints can lie or well, they can be deliberately confusing Oh,
- 2:09Speaker 2: for sure. Malware authors are incredibly skilled at obfuscating their code,
- 2:15Speaker 2: you know, hiding their true intentions so that your static
- 2:18Speaker 2: analysis just hits a brick wall. But eventually the malware
- 2:21Speaker 2: has to run. I mean, it has to execute its
- 2:24Speaker 2: instructions to steal data or compromise the system.
- 2:27Speaker 1: It has to do the thing it was built to
- 2:29Speaker 1: do exactly, and.
- 2:30Speaker 2: When it does, it steps out of the shadows and
- 2:32Speaker 2: reveals its true nature.
- 2:34Speaker 1: Okay, So if we're going to detonate this digital bomb,
- 2:37Speaker 1: we need to build that reinforced steel vault first, which
- 2:41Speaker 1: brings up an immediate problem.
- 2:43Speaker 2: Where do we run it?
- 2:44Speaker 1: Yeah? Where do we safely run iOS malware? Because I
- 2:47Speaker 1: am definitely not installing a suspicious file on my personal.
- 2:50Speaker 2: Phone, absolutely not. No. You need an isolated environment, and
- 2:53Speaker 2: typically you have three main avenues for creating one.
- 2:56Speaker 1: Okay, what are they?
- 2:57Speaker 2: The first avenue is using online sandboxes. These are quick
- 3:00Speaker 2: web based tools where you basically just upload the file
- 3:02Speaker 2: and their servers run it in a virtual environment for you.
- 3:05Speaker 1: Sounds easy enough, it is.
- 3:07Speaker 2: The second avenue involves third party framework so open source
- 3:11Speaker 2: tools created by the community, and the third avenue is
- 3:14Speaker 2: building a custom lab yourself, which gives you total granular
- 3:18Speaker 2: control over every aspect of the device.
- 3:21Speaker 1: But when we talk about building a custom labs or
- 3:24Speaker 1: iOS specifically, there's a massive hurdle here, right, because Apple's
- 3:29Speaker 1: ecosystem is samously a walled garden.
- 3:32Speaker 2: Oh, it is extremely locked down. I mean, the biggest
- 3:35Speaker 2: challenge for anyone beginning iOS dynamic analysis is just the
- 3:39Speaker 2: sheer time commitment.
- 3:40Speaker 1: And the knowledge required, right, Yeah, the.
- 3:42Speaker 2: Deep knowledge of operating system internals you need just to
- 3:45Speaker 2: set up a custom lab because Apple designs iOS specifically
- 3:48Speaker 2: to prevent the kind of deep root level system access
- 3:52Speaker 2: that a malware analyst actually needs to do their job, right.
- 3:55Speaker 1: Because everything is sandboxed, everything needs cryptographic signatures exactly.
- 3:59Speaker 2: So building a lab where you can bypass those protections,
- 4:02Speaker 2: install specific monitoring software, and control every single variable, it's
- 4:06Speaker 2: a very steep learning curve.
- 4:08Speaker 1: Okay, I have to push back here, though, go for it.
- 4:10Speaker 1: If it takes weeks of time and highly specialized knowledge
- 4:14Speaker 1: to build a custom lab that basically has to fight
- 4:17Speaker 1: against Apple's architecture, why do it? That's a fair question,
- 4:21Speaker 1: like why reinvent the wheel? If I could just use
- 4:23Speaker 1: one of those online sandboxes you mentioned earlier they run
- 4:26Speaker 1: the file for me. Isn't that enough?
- 4:28Speaker 2: It's a really good point. And sandboxes are great for
- 4:30Speaker 2: quick wins, and we absolutely do use them. But here's
- 4:33Speaker 2: the problem. Deep artifacts, like the really sneaky behaviors of
- 4:38Speaker 2: advanced malware. They are often hidden.
- 4:41Speaker 1: Hidden how well.
- 4:42Speaker 2: First off, an online sandbox might only give you top
- 4:44Speaker 2: level reporting unless you pay for a really expensive premium subscription, right.
- 4:49Speaker 2: But more importantly, modern malware is smart.
- 4:51Speaker 1: Smart how like it knows it's being.
- 4:53Speaker 2: Watched exactly that. Sometimes malware actually checks its environment before
- 4:58Speaker 2: it dendates. It looks for specif hardware markers, or it
- 5:01Speaker 2: checks if certain standard user files exist like photos or contacts.
- 5:05Speaker 1: Wow, okay yeah, And if it.
- 5:07Speaker 2: Detects that it's sitting inside a generic automated web sand box,
- 5:10Speaker 2: it might just stay dormant. It just plays dead.
- 5:12Speaker 1: Ah. So the now where checks the vault, realizes it's
- 5:16Speaker 1: a sterile vault with blast glass all around it, and
- 5:19Speaker 1: decides not to explode.
- 5:21Speaker 2: Precisely. That is why having the skills to build a
- 5:24Speaker 2: custom lab is eventually completely necessary. To trigger those hidden behaviors,
- 5:29Speaker 2: you often need a bespoke environment that tricks the malware
- 5:32Speaker 2: into thinking it's on a real vulnerable device being used
- 5:35Speaker 2: by a real human.
- 5:36Speaker 1: Okay, I get it now.
- 5:37Speaker 2: However, because building that lab takes so much time, a
- 5:41Speaker 2: practical everyday workflow usually does start with those quick wins. Right.
- 5:44Speaker 1: So, if I'm sitting at my desk today and I've
- 5:46Speaker 1: got a suspicious file, I'm not going to spend a
- 5:48Speaker 1: whole week building a custom lab just to get a
- 5:50Speaker 1: preliminary read. Where do I go right now to gather
- 5:52Speaker 1: initial intelligence?
- 5:53Speaker 2: The very first step you take is grabbing your iOS
- 5:56Speaker 2: application file and uploading it to a reputable online sand Now,
- 6:00Speaker 2: an iOS app file is called an IPA file.
- 6:03Speaker 1: Wait, let's defind that for a second. What actually is
- 6:05Speaker 1: an IPA file?
- 6:06Speaker 2: Good point. So IPA stands for iOS App Store Package.
- 6:10Speaker 2: When you download an app to your phone, you are
- 6:12Speaker 2: downloading an IPA. Under the hood, it is essentially just
- 6:16Speaker 2: a specialized ZP archive. It contains the app's binary code,
- 6:21Speaker 2: its graphics, its audio files, and its configuration documents. So
- 6:25Speaker 2: you take this IPA file and you upload it to
- 6:27Speaker 2: a sandbox service, something like virus Total or Joe Sandbox.
- 6:32Speaker 1: Okay, so I literally drag and drop this suspicious IPA
- 6:35Speaker 1: file into my web browser. The sandbox spins up a
- 6:38Speaker 1: virtual device on their end and runs all its automated checks. Right,
- 6:41Speaker 1: what am I specifically looking for when the results pop
- 6:44Speaker 1: up on my screen?
- 6:45Speaker 2: You're looking for a few very specific indicators. First, you
- 6:49Speaker 2: want to extract strings of text embedded in the code.
- 6:52Speaker 1: Look what kind of strings?
- 6:53Speaker 2: Things like error messages or maybe URLs or even hard
- 6:57Speaker 2: coded passwords if the developer was sloppy. Second, you are
- 7:00Speaker 2: looking for any network connections the app tries to make
- 7:03Speaker 2: the very moment it wakes up. Okay, And third, you
- 7:05Speaker 2: want a list of the external libraries or frameworks the
- 7:08Speaker 2: app relies on to function.
- 7:09Speaker 1: Let's make that real for a second. Let's say I
- 7:11Speaker 1: upload a simple flashlight app. I look at the sandbox results,
- 7:15Speaker 1: and it tells me this flashlight app is trying to
- 7:17Speaker 1: make a network connection to an unknown server in a
- 7:21Speaker 1: foreign country, and it's using a software library specifically designed
- 7:26Speaker 1: to access the device's microphone.
- 7:29Speaker 2: Which is a massive red flag. I mean, a flashlight
- 7:32Speaker 2: does not need Internet access, and it certainly does not
- 7:35Speaker 2: need to listen to your microphone. Definitely not so the
- 7:37Speaker 2: goal of this initial step is to quickly confirm the
- 7:40Speaker 2: hypotheses you might have formed earlier. It gives you the
- 7:43Speaker 2: immediate context you need before you invest hours into deep
- 7:47Speaker 2: manual analysis.
- 7:48Speaker 1: But as we discussed, those sandboxes only go so far, right,
- 7:52Speaker 1: because there are automated web tools, they can't realistically mimic
- 7:56Speaker 1: a real user swiping around, entering passwords or triggering complex
- 8:00Speaker 1: application states. So to really poke and prod the app
- 8:03Speaker 1: and reverce it to reveal its deepest secrets, we have
- 8:06Speaker 1: to interact with it while it is running on a
- 8:08Speaker 1: physical device that we control.
- 8:09Speaker 2: That's right, we have to move from the web to
- 8:11Speaker 2: the laboratory.
- 8:12Speaker 1: But I'm guessing before we can manipulate the app, we
- 8:15Speaker 1: have to actually understand its biological makeup. I mean, how
- 8:18Speaker 1: does an iOS app actually boot up?
- 8:20Speaker 2: Yeah, this is a really crucial concept. If you don't
- 8:23Speaker 2: understand the normal execution flow of an application, you won't
- 8:27Speaker 2: know where to insert your monitoring tools. You'd just be guessing.
- 8:30Speaker 1: Okay, so let's break this down step by step. I'm
- 8:32Speaker 1: holding my phone, I tap a suspicious app icon on
- 8:36Speaker 1: my home screen. What actually happens underneath the glass?
- 8:40Speaker 2: First, we need a tiny bit of context on the
- 8:42Speaker 2: programming language itself. Traditionally, iOS apps have been built using
- 8:46Speaker 2: objective C. Okay, And what's important to know is that
- 8:49Speaker 2: objective C is a superset of the C programming language.
- 8:52Speaker 1: Why does that matter to us as analysts though?
- 8:54Speaker 2: Because it gives the language this kind of dual nature.
- 8:57Speaker 2: It has the high level organized structure of object oriented programming, sure,
- 9:02Speaker 2: but because it sits on top of C, it also
- 9:04Speaker 2: allows for a very low level direct manipulation of the
- 9:08Speaker 2: device's memory. Oh icy, and that low level memory access
- 9:12Speaker 2: is exactly what we're going to exploit later. So keeping
- 9:15Speaker 2: that in mind, when you tap the app icon, the
- 9:18Speaker 2: application begins with what is called the main function. Every
- 9:21Speaker 2: single C based program starts at.
- 9:24Speaker 1: Main Okay, so maine is the starting line.
- 9:26Speaker 2: Right, But in an iOS app, the main function really
- 9:29Speaker 2: only has one single job. It delegates it immediately calls
- 9:33Speaker 2: a method called UI application.
- 9:35Speaker 1: Main UI Application main and what does that do.
- 9:38Speaker 2: It creates a UI application object. Think of this object
- 9:42Speaker 2: as the high level manager of the app. It handles
- 9:44Speaker 2: the main event loop, so it's constantly listening for touch inputs, screenswipes,
- 9:48Speaker 2: or system notifications. Okay, the manager, but this UI application
- 9:52Speaker 2: object doesn't actually handle the custom logic of the app. Itself. Instead,
- 9:56Speaker 2: it immediately starts talking to another critical component called the
- 9:59Speaker 2: app do delegate.
- 10:00Speaker 1: The app delegate, I feel like i've heard this term.
- 10:02Speaker 1: Who is this character in the system.
- 10:04Speaker 2: The app delegate is a custom object created by the
- 10:07Speaker 2: developer of the app. Its primary purpose is to manage
- 10:10Speaker 2: the application's states states like what well, there are typically
- 10:14Speaker 2: five different states and app can be in like whether
- 10:16Speaker 2: it's active on your screen, running silently in the background,
- 10:20Speaker 2: or maybe suspended entirely. The UI Application object notifies the
- 10:24Speaker 2: app delegate whenever these state changes happen, and the app
- 10:27Speaker 2: delegate decides how the app should react.
- 10:30Speaker 1: Okay, let me see if I can visualize this execution flow.
- 10:33Speaker 1: Let's compare it to going to a restaurant.
- 10:35Speaker 2: Okay, let's hear it.
- 10:36Speaker 1: So, tapping the app icon is like walking through the
- 10:39Speaker 1: front door of the restaurant. The main function is the
- 10:42Speaker 1: host at the greeting stand. Right. The host doesn't cook
- 10:45Speaker 1: your food or take your order. Their only job is
- 10:48Speaker 1: to point you to the manager. That manager is UI
- 10:51Speaker 1: Application main. The manager runs the whole floor, making sure
- 10:54Speaker 1: the lights are on, the tables are clean, everything is running.
- 10:57Speaker 1: I'm tracking, but when it's time to actually deal with
- 10:59Speaker 1: your your specific needs. Like when your state changes from
- 11:03Speaker 1: waiting to ready to order, the manager hands you off
- 11:06Speaker 1: to a specific waiter. That waiter is the app delegate.
- 11:10Speaker 1: The waiter actually takes your order and handles your specific requests.
- 11:15Speaker 2: I like that a lot. That really works. And just
- 11:17Speaker 2: to finish the analogy, once the waiter has your order,
- 11:21Speaker 2: the kitchen starts cooking. So in our app, a method
- 11:24Speaker 2: called application did finish launching is returned. At that exact moment,
- 11:29Speaker 2: the application window launches on your screen, and from that
- 11:32Speaker 2: point on, a continuous cycle called the run loop takes over.
- 11:36Speaker 2: The kitchen is constantly churning, checking for new orders or,
- 11:39Speaker 2: in the app's case, checking for new user taps or
- 11:42Speaker 2: system updates.
- 11:43Speaker 1: Why did Apple designed it this way, though, Like why
- 11:45Speaker 1: separate the manager from the waiter.
- 11:47Speaker 2: It's mostly about stability and security. By separating the high
- 11:51Speaker 2: level touch events from the custom logic of the app,
- 11:54Speaker 2: Apple basically ensures that if a developer writes really bad
- 11:57Speaker 2: code in the app delegate, it might crash the app. Yep, sure,
- 12:00Speaker 2: but it won't crash the entire operating system's touch interface.
- 12:04Speaker 1: Oh that makes total sense and for an analyst, I
- 12:06Speaker 1: guess It means we have a reliable, standardized starting point, Like,
- 12:10Speaker 1: no matter what restaurant we walk into, we know the
- 12:12Speaker 1: host is at the door, the manager runs the floor,
- 12:15Speaker 1: and the waiter takes the order. We don't have to
- 12:17Speaker 1: guess how the app boots up, which means we know
- 12:20Speaker 1: exactly where to set our traps.
- 12:21Speaker 2: Yeah, you nailed it, which brings us to actually preparing
- 12:25Speaker 2: the physical hardware for our lab. We know how the
- 12:29Speaker 2: app functions internally. Now we need a physical device that
- 12:32Speaker 2: will let us intercept those functions.
- 12:34Speaker 1: And this requires a jailbroken iOS device, right it does.
- 12:37Speaker 2: Yeah, Without a jailbroken device, dynamic analysis on iOS is
- 12:41Speaker 2: virtually impossible.
- 12:43Speaker 1: Let's clarify what jail breaking actually means technically for those
- 12:46Speaker 1: who might just think of it as hacking a phone.
- 12:49Speaker 2: Sure, remember how we talked about Apple's walled garden. Normally,
- 12:53Speaker 2: apps are locked in user partitions. They can't access the
- 12:55Speaker 2: core system files at all. Jail breaking is the process
- 12:59Speaker 2: of exploiting vultunderabilities in iOS to remove those software restrictions.
- 13:03Speaker 1: It breaks in that of the sandbox exactly.
- 13:05Speaker 2: It escapes the sandbox and gives us root access the
- 13:07Speaker 2: ultimate administrative privileges. It lets us see and modify the
- 13:11Speaker 2: entire file system from the ground up.
- 13:13Speaker 1: And obviously this should be a dedicated test device, right like,
- 13:16Speaker 1: never your personal phone that has your actual banking apps
- 13:19Speaker 1: and emails on it.
- 13:21Speaker 2: Never ever, your personal phone. Once you have your jail
- 13:24Speaker 2: broken test device, you need to install a specific toolkit. First,
- 13:28Speaker 2: you'll need an alternative app store like Citia, which usually
- 13:31Speaker 2: just comes installed with the jail break itself anyway, Okay, Next,
- 13:34Speaker 2: you'll need Darwin CC tools.
- 13:36Speaker 1: Hold on, Darwin CC tools. What is Darwin?
- 13:39Speaker 2: Ah? So, Darwin is the open source Unix like core
- 13:43Speaker 2: operating system that iOS and macOS are actually built on
- 13:47Speaker 2: top of.
- 13:47Speaker 1: Oh I didn't know that.
- 13:48Speaker 2: Yeah, and the CC tools are basically the foundational compilers
- 13:52Speaker 2: and utilities that allow your custom software to talk directly
- 13:55Speaker 2: to that underlying operating system.
- 13:57Speaker 1: Okay, got it. What else is in the toolkit?
- 14:00Speaker 2: Open Ssh? And finally, you'll need a command line JavaScript framework.
- 14:04Speaker 2: For our purposes today, we'll just refer to it broadly
- 14:06Speaker 2: as the script framework.
- 14:08Speaker 1: I want to pause on open ssh for a second,
- 14:10Speaker 1: because I know SSH is used for remote access, but
- 14:14Speaker 1: if my test phone is literally sitting on the desk
- 14:17Speaker 1: right in front of me plugged into my laptop via USB.
- 14:20Speaker 1: Why do I need to remotely log into it?
- 14:22Speaker 2: Because you really do not want to be trying to
- 14:25Speaker 2: type complex multi line code injections using a tiny, little
- 14:29Speaker 2: touchscreen keyboard on a phone.
- 14:31Speaker 1: Oh right, yeah, that sounds like a nightmare. It is.
- 14:33Speaker 2: Open Ssh allows you to open terminal windows on your
- 14:36Speaker 2: large computer monitor and type commands using a full normal keyboard,
- 14:40Speaker 2: securely executing them on the phone in real time.
- 14:42Speaker 1: Okay, that makes total sense. It's just a workflow thing,
- 14:45Speaker 1: it is.
- 14:45Speaker 2: But there is a massive crucial security step you absolutely
- 14:49Speaker 2: must take the exact moment you install open ssh.
- 14:52Speaker 1: Uh oh what is it?
- 14:54Speaker 2: Well, by default, every single iOS device ships with the
- 14:57Speaker 2: exact same underlying root password.
- 14:59Speaker 1: I guess it's something incredibly basic.
- 15:01Speaker 2: It is a legacy Unix default. The root password is
- 15:04Speaker 2: Alpine alpi n E.
- 15:06Speaker 1: Wow.
- 15:06Speaker 2: Yeah. So if you gel break a device, gain root access,
- 15:10Speaker 2: install open ssh, and do not change that default password,
- 15:13Speaker 2: your phone is now broadcasting remote access to anyone.
- 15:17Speaker 1: That's bad.
- 15:18Speaker 2: Your custom malware lab is just wide open to anyone
- 15:21Speaker 2: else on your network who wants to log in and
- 15:23Speaker 2: take control of it.
- 15:24Speaker 1: You basically built a reinforced steel vault, put a live
- 15:27Speaker 1: bomb inside, and then left the combination lock set to one, two.
- 15:31Speaker 2: Three, four exactly. And it happens way more often than
- 15:34Speaker 2: you'd think, so you have to change that password immediately.
- 15:37Speaker 2: Once that's secure, you want to set up your workflow
- 15:40Speaker 2: on your computer screen. The most efficient way to do
- 15:43Speaker 2: this is to open two separate shell windows side by side.
- 15:46Speaker 1: Why two.
- 15:47Speaker 2: You use one shell window to navigate the device's file system,
- 15:51Speaker 2: so moving files around, checking directories, seeing what the malware
- 15:54Speaker 2: is writing to the disc right, and you use the
- 15:56Speaker 2: second shell window to run your script framework commands simultaneously.
- 16:00Speaker 2: This lets you observe the environment in one window while
- 16:03Speaker 2: you fire off live commands in the other.
- 16:05Speaker 1: Okay, so the device is prepped, the tools are loaded,
- 16:08Speaker 1: the default password has changed. My two shehell windows are
- 16:11Speaker 1: open on my monitor. It's time for the main event.
- 16:15Speaker 1: We are finally going to inject our tools directly into
- 16:17Speaker 1: the beating heart of the running application.
- 16:19Speaker 2: Yes, first we have to pick our target. If you
- 16:23Speaker 2: just want to practice these techniques. Default system applications like
- 16:26Speaker 2: the iOS springboard, which manages the home screen, they're actually unencrypted.
- 16:31Speaker 2: They are fantastic easy targets for beginners to learn how
- 16:34Speaker 2: hooking marks.
- 16:35Speaker 1: But what if I want to analyze a suspicious app
- 16:37Speaker 1: I found, or maybe even a legitimate app from the
- 16:40Speaker 1: app Store, just to see how it handles my privacy.
- 16:43Speaker 2: That's where you hit another layer of Apple security. Any
- 16:47Speaker 2: app downloaded directly from the official app store is encrypted
- 16:50Speaker 2: using Apple's fair Play digital rights management.
- 16:52Speaker 1: Of course it is.
- 16:53Speaker 2: Yeah, So to analyze those directly on the device, you
- 16:56Speaker 2: would theoretically have to run the app, dump the decrypted
- 16:59Speaker 2: code from the active memory, pull those files over to
- 17:02Speaker 2: your Mac, analyze them, and push them back. It's a
- 17:04Speaker 2: very tedious, time consuming process.
- 17:07Speaker 1: Is there a workaround for that? Because pulling memory dumps
- 17:09Speaker 1: back and forth sounds like it completely breaks the flow
- 17:12Speaker 1: of dynamic analysis.
- 17:13Speaker 2: There is a workaround, thankfully. You can sideload unencrypted third
- 17:17Speaker 2: party IPA files directly onto your jail broken device using
- 17:21Speaker 2: tools like citia Impactor or app sync.
- 17:23Speaker 1: Oh nice.
- 17:24Speaker 2: Yeah, you just connect your phone via USB, point your
- 17:26Speaker 2: computer at the unencrypted IPA file, and it forcefully installs
- 17:29Speaker 2: it just bypassing the app stores encryption checks entirely perfect.
- 17:34Speaker 1: Okay, so we have our unencrypted target app running on
- 17:36Speaker 1: the screen of our jail broken phone. I'm looking at
- 17:39Speaker 1: my two shell windows. What is the actual action I take?
- 17:43Speaker 2: You use your JavaScript script framework to hook into the
- 17:46Speaker 2: applications process ID. Whenever an app runs, the operating system
- 17:50Speaker 2: assigns it a unique ID number. Our framework basically latches
- 17:54Speaker 2: onto that ID, essentially merging our command line terminal directly
- 17:58Speaker 2: with the app's internal memory space.
- 18:00Speaker 1: And this brings us to the absolute climax of the
- 18:02Speaker 1: whole process. A concept with a very funny name but
- 18:05Speaker 1: incredibly powerful implications. Method swizzling.
- 18:09Speaker 2: Yes, method swizzling is brilliant. It leverages that low level
- 18:12Speaker 2: memory access we talked about earlier with objective C. Using
- 18:16Speaker 2: a combination of JavaScript and objective C commands. Through our framework,
- 18:19Speaker 2: we can interact with and physically change the methods of
- 18:22Speaker 2: a specific object while the application is actively running.
- 18:26Speaker 1: Hold on, let me just make sure I understand this.
- 18:28Speaker 1: Are we literally rewriting the app source code live on
- 18:31Speaker 1: the fly, because that sounds impossible.
- 18:34Speaker 2: We aren't rewriting the source code. No, we are manipulating
- 18:38Speaker 2: memory pointers. So think of every function in an app
- 18:41Speaker 2: as a house with a specific address in the device's memory.
- 18:44Speaker 1: Okay, I'm picturing it.
- 18:45Speaker 2: When the app needs to check something it sends our
- 18:48Speaker 2: request to that specific address. Method swizzling allows our script
- 18:52Speaker 2: framework to act like a malicious traffic cop. Okay, when
- 18:55Speaker 2: the app asks for the directions to a specific function,
- 18:58Speaker 2: our framework in accepts that request and points the app
- 19:02Speaker 2: to a completely different address and memory and address that
- 19:05Speaker 2: we control.
- 19:06Speaker 1: That is wild, But how do we even know what
- 19:08Speaker 1: addresses to redirect? Like? How do you know what to swizzle?
- 19:11Speaker 2: This is exactly where your previous static analysis pays off.
- 19:14Speaker 2: Remember the blueprints. During static analysis, you mapped out the
- 19:18Speaker 2: app structure. You know that somewhere in the code there
- 19:21Speaker 2: is a method called, for example, check the user is premium,
- 19:25Speaker 2: and normally for a free user, it just returns false.
- 19:28Speaker 1: Oh, I see, because I read the blueprints, I know
- 19:30Speaker 1: exactly what the method is named.
- 19:32Speaker 2: Exactly. You use your script framework to hook the app
- 19:35Speaker 2: target the check of users a premium method, and you
- 19:38Speaker 2: swizzle it. You tell the traffic cop to redirect any
- 19:41Speaker 2: request for that method to a new block of code
- 19:44Speaker 2: that simply always returns true. You just modified the app's
- 19:47Speaker 2: behavior at runtime without changing the underlying file.
- 19:51Speaker 1: Wow.
- 19:51Speaker 2: Now apply that to malware, right if.
- 19:53Speaker 1: The malware has a method called I don't know detect
- 19:56Speaker 1: sandbox and hide you swizzle it to always return fall.
- 20:00Speaker 1: The malware asks the system, am I in a sandbox,
- 20:04Speaker 1: and your traffic cop forces the system to say, Nope,
- 20:07Speaker 1: You're totally safe.
- 20:08Speaker 2: Exactly. You just force the malware to reveal its malicious
- 20:11Speaker 2: payload right there in your vault.
- 20:13Speaker 1: That is an incredible aha moment. You are literally forcing
- 20:16Speaker 1: the bomb to detonate by hot wiring its own circuitry
- 20:20Speaker 1: while it's ticking.
- 20:21Speaker 2: It is the ultimate level of control over a piece
- 20:23Speaker 2: of software. It really allows you to peel back every
- 20:26Speaker 2: single layer of evasion a malware author tries to throw
- 20:29Speaker 2: at you.
- 20:30Speaker 1: So let's summarize this incredible Johnny we've just been on.
- 20:33Speaker 1: We started by safely uploading our IPA file to a
- 20:35Speaker 1: web sandbox to grab quick strings and network data. Right
- 20:39Speaker 1: then we dug into the execution flow, learning how the
- 20:42Speaker 1: main function delegates to the UI application manager and the
- 20:46Speaker 1: app delegate waiter. We prepped our physical lab by jailbreaking
- 20:49Speaker 1: a device, setting up our Darwin tools and SSH, and
- 20:53Speaker 1: changing that incredibly dangerous default password Yes. And finally, we
- 20:57Speaker 1: used a script framework to hook the live process and
- 21:00Speaker 1: perform method swizzlnk, acting as a traffic cop to redirect
- 21:04Speaker 1: memory on the fly.
- 21:05Speaker 2: That is the complete practical life cycle of a dynamic
- 21:08Speaker 2: analysis session. And since our goal here is that you
- 21:10Speaker 2: deeply understand and can actually apply this knowledge, I want
- 21:13Speaker 2: to pose a quick review question for you, the listener,
- 21:16Speaker 2: just to test your grasp on that iOS architecture we discussed.
- 21:19Speaker 1: Ooh, pop quiz, I love it. Let's hear it.
- 21:21Speaker 2: Think back to the execution flow of an iOS app.
- 21:24Speaker 2: If you were analyzing a piece of malware and you
- 21:27Speaker 2: specifically wanted to observe what the malware does when the
- 21:30Speaker 2: application is pushed to the background. So say, when the
- 21:33Speaker 2: user switches to another app, which object would you focus
- 21:37Speaker 2: on inspecting? Would you huck the UI application object or
- 21:40Speaker 2: the app delegate.
- 21:42Speaker 1: I'll give every one a second to think about it.
- 21:43Speaker 1: Take your time, okay, If I remember my restaurant analogy correctly,
- 21:47Speaker 1: the UI application is the general manager running the floor,
- 21:50Speaker 1: but the app delegate is the specific waiter that handles
- 21:54Speaker 1: the custom state changes like going from active to background
- 21:58Speaker 1: spot on.
- 21:58Speaker 2: You would want to inspect the delegate because it is
- 22:01Speaker 2: uniquely responsible for managing those state transitions, including moving to
- 22:05Speaker 2: the background.
- 22:05Speaker 1: Awesome, this has been a truly eye opening deep dive.
- 22:09Speaker 1: But before we wrap up, we always like to leave
- 22:10Speaker 1: you with a lingering question something that you.
- 22:13Speaker 2: On Yeah, and this reads is a very important question
- 22:16Speaker 2: about the nature of these tools in general. We've just
- 22:19Speaker 2: spent this entire time talking about how security analysts use
- 22:22Speaker 2: jailbroken phones, powerful frameworks, and method swizzling to hook into
- 22:27Speaker 2: an app and modify its behavior at runtime for good
- 22:31Speaker 2: to expose malware and understand threats.
- 22:34Speaker 1: Right, we are using the tools to build.
- 22:35Speaker 2: A safe fault, but the technology itself is completely neutral.
- 22:39Speaker 2: Memory pointers don't care who is redirecting them. So if
- 22:41Speaker 2: we can do this, what is stopping malicious actors from
- 22:45Speaker 2: using these exact same run time injection and method swizzling
- 22:48Speaker 2: techniques to manipulate legitimate applications like your banking app or
- 22:52Speaker 2: your secure messaging app on a compromised device.
- 22:55Speaker 1: Man, that is a terrifying thought. The idea that the
- 22:57Speaker 1: very tools we use to study the bomb could actually
- 23:00Speaker 1: be used to turn a perfectly safe app into a
- 23:02Speaker 1: weapon without rewriting a single line of its original code
- 23:05Speaker 1: definitely something to ponder the next time you tap an
- 23:07Speaker 1: app icon. Thanks for joining us on this deep dive.