Latest / CyberCode Academy / Course 5 - Full Mobile Hacking | Episode 5: Exploiting Insecure Storage and Access Controls via Reverse Engineering and ADB
Transcript
- 0:00Speaker 1: Welcome to the deep dive. We're digging into the details
- 0:03Speaker 1: to bring you the essential insights fast. Today we're really
- 0:07Speaker 1: getting into mobile app security, specifically what happens after you
- 0:11Speaker 1: hit safe, you know, when you trust an app with
- 0:13Speaker 1: your data or it does something in the background exactly.
- 0:16Speaker 2: Our goal here is well, to put you in the
- 0:18Speaker 2: shoes of a security tester. We want to show how
- 0:21Speaker 2: developers maybe unintentionally leave doors open. We'll look at how
- 0:24Speaker 2: testers use pretty common tools like the Android debug Bridge
- 0:28Speaker 2: ADB and reverse engineering to find these weaknesses.
- 0:32Speaker 1: Right, and we've boiled it down to two main kinds
- 0:34Speaker 1: of problems we'll explore today. First, how things outside the
- 0:37Speaker 1: app can trigger functions inside it bypassing the normal flow.
- 0:41Speaker 1: That's an access control issue. And second, all the ways
- 0:44Speaker 1: data gets stored insecurely, you know, not checking input properly,
- 0:48Speaker 1: input validation, or just saving sensitive stuff in plain text.
- 0:52Speaker 1: That's data storage. Yeah.
- 0:53Speaker 2: Let's let's maybe define those a bit more clearly first,
- 0:56Speaker 2: because they're central to mobile security flaws. The first big
- 1:00Speaker 2: category is improper access control. Basically, this means some internal
- 1:05Speaker 2: part of the app, maybe an activity or a class
- 1:07Speaker 2: that should only run after you log in or click
- 1:09Speaker 2: something specific. Yeah, well, it can be started directly from
- 1:12Speaker 2: outside the app. It just skips all the intended checks, so.
- 1:15Speaker 1: It's not like guessing a password. It's more like finding
- 1:18Speaker 1: a hidden command line switch that just turns on a future.
- 1:21Speaker 2: That's a good way to put it. Yeah. The second
- 1:23Speaker 2: category is insecure data handling, and this really covers two
- 1:28Speaker 2: related problems. First, not properly checking the data someone types
- 1:32Speaker 2: in that's the input validation failure, and second just not
- 1:36Speaker 2: protecting the data once it's saved on the phone. That's
- 1:39Speaker 2: insecure data storage.
- 1:40Speaker 1: Okay, let's dive into that first one. Then method one
- 1:43Speaker 1: exploiting access control. How does a tester even find out
- 1:46Speaker 1: the name of that like secret internal function they shouldn't
- 1:49Speaker 1: be able to run.
- 1:50Speaker 2: Well, you start by watching what the phone itself is doing.
- 1:52Speaker 2: Let's say a user clicks a button in some app,
- 1:55Speaker 2: maybe it says view API credentials or something sensitive. When
- 1:58Speaker 2: that happens, the Android system actually logs it, and the
- 2:01Speaker 2: tool for seeing those logs is ADB logcat. Think of
- 2:05Speaker 2: logcat as like a running diary for the whole device.
- 2:08Speaker 2: It shows system messages, events, when app components start everything.
- 2:14Speaker 1: Ah, so the system itself is kind of tattling on
- 2:16Speaker 1: the app, telling you the internal path it used. What
- 2:19Speaker 1: exactly are you listening for in that long stream?
- 2:22Speaker 2: You're looking for a specific message from the activity manager.
- 2:24Speaker 2: It pops up right when that private part of the
- 2:26Speaker 2: app starts. So you run logcat. You perform the action
- 2:30Speaker 2: in the app, like clicking the button, and then you
- 2:32Speaker 2: scan the output. You'll find an entry maybe something like
- 2:34Speaker 2: ah activitymanager, dot start, you act dot cmp com, dot example,
- 2:39Speaker 2: dot app, dot secret activity.
- 2:41Speaker 1: Okay, so that comm dot example, dot app secret activity part.
- 2:44Speaker 1: That looks like technical jargon, but that's the key, that's
- 2:46Speaker 1: the address.
- 2:47Speaker 2: That's exactly it. Once you have that name, that specific
- 2:50Speaker 2: component path, you don't need the X buttons anymore. You
- 2:53Speaker 2: go to the ADB shell, which is like a command
- 2:55Speaker 2: line for the phone, and you type am start desh
- 2:58Speaker 2: en followed by that exact name like calm, dot example,
- 3:01Speaker 2: dot app, dot secret activity, and boom, the app is
- 3:05Speaker 2: forced to launch that specific screen or function directly. It
- 3:08Speaker 2: proves that something meant to be internal and secure can
- 3:11Speaker 2: be triggered externally, a classic access control vulnerability.
- 3:15Speaker 1: Wow, that's clever. You're basically mapping the apps hidden pathways
- 3:18Speaker 1: without guessing. Okay, okay, let's switch gears method two. Input
- 3:22Speaker 1: validation problems. Say there's a field in an app and
- 3:25Speaker 1: it's just supposed to take a website address, like my
- 3:27Speaker 1: website dot com. What's the danger if the app just
- 3:30Speaker 1: trusts whatever you type in there?
- 3:31Speaker 2: Oh, the danger is huge because mobile apps often have
- 3:35Speaker 2: really broad permissions to access storage on the device, internal storage,
- 3:38Speaker 2: the SD card, everything. If that input field is invalidated properly,
- 3:42Speaker 2: if the app doesn't strictly check is this really a URL,
- 3:45Speaker 2: then you can trick it. You can feed it a
- 3:46Speaker 2: filepath instead of a web address.
- 3:49Speaker 1: Right, so instead of HDP, you give it something like
- 3:51Speaker 1: data data. Tell me more about that path reversal. How
- 3:53Speaker 1: does that work?
- 3:54Speaker 2: Yeah, that's the idea path traversal. You could try to
- 3:57Speaker 2: read data the app, say for itself in its private area.
- 4:00Speaker 2: Inject a path starting with file dot data data, then
- 4:02Speaker 2: the app's unique package names, say comm dot beatup, and
- 4:06Speaker 2: then the filename like file dot data, data dot com,
- 4:08Speaker 2: dot bat up, file user prefs, dot xml. The app
- 4:12Speaker 2: thinks it's loading a resource, but because validation failed, it
- 4:15Speaker 2: actually displays the contents of that internal file.
- 4:18Speaker 1: And what if the juicy stuff isn't in the app's
- 4:20Speaker 1: private sandbox. What about like the sd card.
- 4:24Speaker 2: Same principle applies. If the app has permission to read
- 4:26Speaker 2: external storage, you might just feed it a simpler path,
- 4:29Speaker 2: maybe sd card, dot secrets, dot txt or something similar.
- 4:33Speaker 2: Because the app didn't sanitize the input, it essentially lets
- 4:35Speaker 2: an attacker use its own file access permissions to read
- 4:38Speaker 2: arbitrary files. It completely breaks data integrity.
- 4:41Speaker 1: So if you can inject a filepath where a URL
- 4:44Speaker 1: should be, the attacker has effectively hijacked the app's file
- 4:47Speaker 1: reading power. That's yeah, that's bad.
- 4:50Speaker 2: It really is, and it highlights why you absolutely must
- 4:53Speaker 2: check and clean up any data coming from outside the
- 4:55Speaker 2: app every single input field.
- 4:57Speaker 1: Okay, but let's say the developers are actually doing a
- 4:59Speaker 1: decent job blocking those kinds of direct attacks at runtime.
- 5:03Speaker 1: What's next for a tester? That brings us to method three? Right,
- 5:06Speaker 1: going deeper, looking at the actual code reverse engineering exactly.
- 5:09Speaker 2: Now, we're not interacting with the running apps so much
- 5:12Speaker 2: as we're dissecting the app package itself, the APK file.
- 5:16Speaker 2: The process is usually pretty standard. You take the APK file,
- 5:19Speaker 2: which is basically a zip archive with compiled code and resources.
- 5:22Speaker 2: You use a tool something like dtjdx to convert the
- 5:26Speaker 2: app's executable code into Java bytecode packaged in a jar file.
- 5:31Speaker 1: So DTG kind of translates the machine code back into
- 5:34Speaker 1: something more structured, closer to Java.
- 5:36Speaker 2: What then, then you use a decompiler. Jdgui is a
- 5:39Speaker 2: common one. You feed at the jr file and this
- 5:41Speaker 2: tool reconstructs the source code or something very close to it.
- 5:45Speaker 2: You can browse the classes the methods look for interesting names.
- 5:48Speaker 2: Maybe you see database helper dot java, or like in
- 5:51Speaker 2: one case, study school injection activity dot java.
- 5:54Speaker 1: Okay, now I'm a developer watching this, and I'm thinking,
- 5:56Speaker 1: what's the absolute worst thing someone could find just by
- 6:00Speaker 1: looking at my decompiled code.
- 6:02Speaker 2: Well, the really shocking discovery is often finding hard coded
- 6:05Speaker 2: secrets directly in the code. You look inside those classes,
- 6:09Speaker 2: maybe ones that set up the database for the first time,
- 6:11Speaker 2: and you find the actual SQL commands. And sometimes these
- 6:15Speaker 2: commands include default data. You might literally find lines setting
- 6:19Speaker 2: username admin or password equals password one, two, three, or
- 6:23Speaker 2: even fields for credit card number hard coded strings.
- 6:26Speaker 1: Wait, so the initial admin password, or maybe even the
- 6:29Speaker 1: structure of sensitive database tables is just written into the
- 6:33Speaker 1: app's code.
- 6:34Speaker 2: Itself precisely. That's the core of vulnerability here. If you
- 6:37Speaker 2: bake sensitive information, credentials, keys, database schemas directly into the
- 6:41Speaker 2: application binary, then anyone who can decompile the app, which
- 6:45Speaker 2: is relatively easy, gets all those secrets. It's a huge risk.
- 6:47Speaker 1: Okay, So method three reverse engineering give us the map
- 6:51Speaker 1: we know that database table names, that can fig file names,
- 6:54Speaker 1: maybe even default passwords. Now we combine that with method
- 6:56Speaker 1: four using ADB shell again, time to actually grab the
- 7:01Speaker 1: live data that the app is saved. How easy is
- 7:03Speaker 1: it to just pull that data out?
- 7:06Speaker 2: If you have shell access, especially root access, it's often
- 7:09Speaker 2: disturbingly easy. First you usually need to figure out the
- 7:12Speaker 2: app's specific data directory. You might use a command like
- 7:16Speaker 2: PM list packages rep app name to find the package name,
- 7:19Speaker 2: say commot Securecorp, dot Bank cap. Then you navigate into
- 7:23Speaker 2: its private data area CD data data comm dot Securecorp,
- 7:26Speaker 2: dot Bank cap. Once you're in there, you just look
- 7:28Speaker 2: around using ls.
- 7:29Speaker 1: It seems so fundamental, though, If this data is so
- 7:32Speaker 1: exposed with shell access, why isn't it just encrypted by default?
- 7:35Speaker 1: Why do developers keep saving things this way?
- 7:37Speaker 2: That's a great question. Often it comes down to well
- 7:41Speaker 2: ease of use and maybe performance. The standard ways Android
- 7:45Speaker 2: provides for saving simple data like shared preferences are super
- 7:49Speaker 2: easy for developers to use just a few lines of code,
- 7:52Speaker 2: but the default behavior is often unencrypted. Developers might prioritize
- 7:56Speaker 2: getting the future working quickly, or they might assume the
- 7:58Speaker 2: Android saandbox itself is enough protection, which as we're seeing
- 8:02Speaker 2: it isn't if someone gets shell access. So with that context,
- 8:06Speaker 2: let's look at the four commonplaces we found data stored insecurely.
- 8:10Speaker 2: First up, shared preferences. This is the standard Android way
- 8:14Speaker 2: to save small key value pairs like user settings. Inside
- 8:17Speaker 2: the app's data directory, there's usually a shared prefs folder.
- 8:20Speaker 2: Inside that you find XML files. You just use the
- 8:22Speaker 2: cat command on the XML file like cat user settings
- 8:25Speaker 2: dot xml and right there and plain text, you might
- 8:27Speaker 2: see string name user nam testing and string name password
- 8:29Speaker 2: testing wide open.
- 8:30Speaker 1: Unbelievable, just sitting there in a text file. Okay, what's next.
- 8:33Speaker 2: Second, quite databases. Apps use these for more structured data,
- 8:37Speaker 2: lots of it. Sometimes in the databases folder within the
- 8:40Speaker 2: app's data directory, you'll find these files. They might not
- 8:43Speaker 2: even have a dot dB extension, maybe just a name
- 8:46Speaker 2: like user store or eads too. But tools can identify them.
- 8:50Speaker 2: You open it using the squite three command line tool
- 8:53Speaker 2: squite three User Store. Then you can run seql commands.
- 8:56Speaker 2: Dot tables shows you the tables and select from users.
- 9:01Speaker 2: Dumps all the data again, typically usernames, passwords, everything stored unencrypted.
- 9:06Speaker 1: Right two for two on plaintext data. What about files
- 9:08Speaker 1: that are only supposed to be around for a little while?
- 9:10Speaker 2: Third temporary files. Yeah, apps create temporary files all the time,
- 9:14Speaker 2: maybe for caching or a session info. They might have
- 9:17Speaker 2: names ending in dot tmp or be in a cash directory.
- 9:20Speaker 2: Ideally these get deleted properly, but often they don't. They
- 9:23Speaker 2: just hang around in the app's main data folder cash folder.
- 9:26Speaker 2: You can spot them, maybe by timestamp. Use cat again
- 9:28Speaker 2: and find sensitive session details or credentials that we're supposed
- 9:31Speaker 2: to be temporary.
- 9:32Speaker 1: Okay, And the last one data saved outside the apps
- 9:34Speaker 1: supposedly secure area.
- 9:36Speaker 2: Fourth external storage. This is the sd card territory, whether
- 9:40Speaker 2: it's a physical card or emulated. If a developer uses
- 9:43Speaker 2: code that points to environment dot get external storage directory,
- 9:47Speaker 2: they're deliberately saving data outside the apps sandbox in a
- 9:50Speaker 2: place that's generally much easier to access. You just navigate
- 9:53Speaker 2: to secard in the ADB shell. Look around, maybe find
- 9:56Speaker 2: hidden files starting with a dot like dot myapp data
- 9:59Speaker 2: dot txt, and again use cat to read it. Secrets exposed.
- 10:03Speaker 1: This is quite a rundown. XML files, siecle databases, tem files,
- 10:07Speaker 1: as dcard files in almost every common storage method. The
- 10:10Speaker 1: examples show critical data just sitting there in plain text,
- 10:13Speaker 1: easy pickings for anyone who gets shell access. So thinking
- 10:15Speaker 1: about that, why don't the operating systems themselves, like Android
- 10:19Speaker 1: just force encryption on all this stuff by default make
- 10:21Speaker 1: it harder to make these basic mistakes?
- 10:23Speaker 2: That really is the million dollar question, isn't it. The
- 10:25Speaker 2: platforms Android and iOS do offer strong encryption tools absolutely,
- 10:30Speaker 2: but mandating it everywhere, well, there are complexities. Legacy app
- 10:34Speaker 2: compatibility is one factor. Performance on say, very low end
- 10:39Speaker 2: devices might be another concern. So the capability is there,
- 10:42Speaker 2: but the onus. The responsibility falls squarely on the application
- 10:46Speaker 2: developer to choose the secure storage methods and actively encrypt
- 10:50Speaker 2: sensitive data before writing it anywhere.
- 10:52Speaker 1: It's not automatic, right, So these examples really hammer home
- 10:55Speaker 1: that good app security has to be deliberate. It needs
- 10:57Speaker 1: that defensive mindset encoding, you know, properly checking inputs using encryption,
- 11:02Speaker 1: keeping sensitive data internal, not just throwing it onto the
- 11:05Speaker 1: SD card.
- 11:06Speaker 2: Absolutely understanding how these attacks work, these exploitation pads. It's
- 11:09Speaker 2: crucial whether you're building apps yourself or you're just trying
- 11:12Speaker 2: to understand the security promises of the apps you use
- 11:15Speaker 2: every single day.
- 11:16Speaker 1: Okay, that leads us perfectly into a final thought for you,
- 11:19Speaker 1: our listeners to chew on. We talked about four common
- 11:22Speaker 1: ways apps store data insecurely shared preferences in XML, squalid databases,
- 11:27Speaker 1: temporary files, and files on external storage or the SD card. Now,
- 11:32Speaker 1: imagine an attacker has gained roopshell access to a device.
- 11:35Speaker 1: Which of those four storage methods do you think poses
- 11:38Speaker 1: the biggest long term risk for exposing the most valuable
- 11:41Speaker 1: user data. Think about how easy it is to copy
- 11:44Speaker 1: the data off and how often it's stored in plain text.
- 11:47Speaker 1: Which one keeps the secrets the longest and most accessibly.
- 11:50Speaker 2: Yeah, consider which type tends to hold more structured, persistent,
- 11:54Speaker 2: valuable information rather than just temporary stuff. We really hope
- 11:57Speaker 2: this deep dive has given you some solid grounding and
- 11:59Speaker 2: maybe made you think a bit differently about mobile apps
- 12:01Speaker 2: security