Skip to main content

Solve the iGoat Exercise

This tutorial will show you how Ocular can help you solve the exercises and challenges presented in the iGoat. Per OAWSP, iGoat is a "learning tool for iOS app pentesting and security."


For this tutorial, we will assume that you're running iGoat on an iOS Simulator, which will allow you to try out the following examples. Therefore, you should have an iOS simulator installed and ready to use.

Downloading and Configuring iGoat

To fetch the source files and open the project in Xcode, run:

git clone
cd igoat/iGoat/
open iGoat.xcodeproj/

Change your build settings to enable Link Time Optimization before you build iGoat (this gets you the LLVM bitcode that you can then load into Ocular).

You will also need to add -flto to Other C Flags and Other Linker Flags. You should have something like this in the end:

LTO Build Settings

Finally, to simplify setup, go to File > Project Settings and change Derived Data to Project-Relative Location:

Project Settings

At this point, build the app and run it using any iOS simulator.

Loading iGoat into Ocular

Once you build the iGoat application, you can load its LLVM bitcode into Ocular. To do this, you'll need to

  1. Navigate to the object directory and obtain the build files
  2. Convert the build artifacts into a Code Property Graph (CPG)

You can run the following in your Terminal to navigate to the object directory:

cd DerivedData/iGoat/Build/Intermediates.noindex/

There are several object files, each of which is an LLVM bitcode file:

$ file BrokenCryptographyExerciseViewController.o
BrokenCryptographyExerciseViewController.o: LLVM bitcode, wrapper x86_64

You can convert these files into a CPG using the following:

<path-to-Ocular -installation>/ --output=/tmp/ *.o

After processing, you will see something like this:

[2020-03-27 11:55:27.097] [llvm2cpg] [info] Serializing CPG
[2020-03-27 11:55:27.907] [llvm2cpg] [info] Saving CPG on disk
[2020-03-27 11:55:42.170] [llvm2cpg] [info] CPG is successfully saved on disk: /tmp/
[2020-03-27 11:55:44.992] [llvm2cpg] [info] Shutting down

Now, run Ocular:

sl ocular

Load the CPG:

ocular> importCpg("/tmp/")

Yap Storage

Let's start with the Yap Storage exercise.

In the iGoat app running in the simulator, go to Data Protection (Rest) -> Yap Storage and click Start.

Yap Storage Exercise

This challenge is to log in using a username/password combination. Try a few combinations to ensure that the authentication mechanism is in place.

At this point, you can assume that the Yap database is somehow involved here since the challenge is called Yap Storage. To validate (or invalidate) this assumption, check if the YapDatabase class exists in the CPG:

ocular> cpg.typeDecl.nameExact("YapDatabase").p

List[String] = List(

You can see from the results that YapDatabase exists.

The next thing to do is to find a valid username/password combination that you can use to log in. Assume that the credentials are hardcoded and written to the database during the app lifecycle.

Run the following to look at the available Yap database classes:


List[String] = List(

Note: You could have used .*, but doing so includes all types, including function pointers, ObjC metaclasses, etc., which may make the results difficult to parse.

Ocular returns are a few classes, but the one you would be interested in is YapDatabaseReadWriteTransaction. Let's look at the available methods:

ocular> cpg.typeDecl.nameExact("YapDatabaseReadWriteTransaction")

List[String] = List(

As you can see, there are a few methods related to data storage. These three should be of particular interest to you:


Let's see if the application calls any of these methods:


List[String] = List(

Ocular shows that there are several calls to these methods, so let's narrow the results of interest by checking to see where they're called from:

>"setObject:forKey:inCollection:.*").map(c => + " -> " +

List[String] = List(
"/tmp/igoat/iGoat/iGoat/YAP Data Storage/YAPExcersizeViewController.m -> setObject:forKey:inCollection:",
"/tmp/igoat/iGoat/iGoat/YAP Data Storage/YAPExcersizeViewController.m -> setObject:forKey:inCollection:",
"/tmp/igoat/iGoat/iGoat/ThirdParty/YapDatabase/YapDatabaseTransaction.m -> setObject:forKey:inCollection:withMetadata:serializedObject:serializedMetadata:",
"/tmp/igoat/iGoat/iGoat/ThirdParty/YapDatabase/YapDatabaseTransaction.m -> setObject:forKey:inCollection:withMetadata:serializedObject:serializedMetadata:"

From the results, you can see that setObject:forKey:inCollection:withMetadata:serializedObject:serializedMetadata:, which is called by YapDatabaseTransaction.m and must be some type of Yap database internals. Furthermore, setObject:forKey:inCollection: which is called from YAPExcersizeViewController.m seems to be what we're looking for as well.

Let's see if there any string arguments passed to the setObject:forKey:inCollection:

ocular>"setObject:forKey:inCollection:") => l.order + ":" + l.code).p

List[String] = List(

Bingo! At this point, you can map the following arguments to the method parameters:

  • Argument 2 is the implicit method name (ObjC selector)
  • Arguments 3, 4, and 5 map to the key, object, and collection, respectively.

Let's make the output easier to read:

ocular>"setObject:forKey:inCollection:").map(c => c.start.argument.order(4).code.head + " = " + c.start.argument.order(3).code.head).p

List[String] = List("YapKeyPassword = TheUnknown", "YapKeyEmail =")

Now, you can check to see if this email/password combination works. Return to the iOS simulator and provide the credentials.

Yap Storage Exercise Success

Yes, it works!