deardaniel/secdata-raw huggingface dataset:
OWASP Mobile Application Security Testing Guide: output

open(/var/mobile/Containers/Data/Application/976DB6BA-3AE8-483D-9CE7-0207049BB3B5/Documents/secret.json)
Backtrace:
0x19a8dfd68 Foundation!_NSOpenFileDescriptor_Protected
0x19a8cb884 Foundation!_NSWriteDataToFileWithExtendedAttributes
0x19a92336c Foundation!writeStringToURLOrPath
0x19abeb294 Foundation!StringProtocol.write(to:atomically:encoding:)
0x104ab0418 MASTestApp!specialized static MastgTest.mastgTest(completion:)
0x104ab122c MASTestApp!closure #1 in closure #1 in closure #1 in ContentView.body.getter
0x1a417e9e8 SwiftUI!0x7199e8 (0x18a8f29e8)
0x1a417ece8 SwiftUI!0x719ce8 (0x18a8f2ce8)

open(/var/mobile/Containers/Data/Application/976DB6BA-3AE8-483D-9CE7-0207049BB3B5/Library/secret.json)
Backtrace:
0x19a8dfd68 Foundation!_NSOpenFileDescriptor_Protected
0x19a8cb884 Foundation!_NSWriteDataToFileWithExtendedAttributes
0x19a92336c Foundation!writeStringToURLOrPath
0x19abeb294 Foundation!StringProtocol.write(to:atomically:encoding:)
0x104ab0418 MASTestApp!specialized static MastgTest.mastgTest(completion:)
0x104ab122c MASTestApp!closure #1 in closure #1 in closure #1 in ContentView.body.getter
0x1a417e9e8 SwiftUI!0x7199e8 (0x18a8f29e8)
0x1a417ece8 SwiftUI!0x719ce8 (0x18a8f2ce8)

open(/var/mobile/Containers/Data/Application/976DB6BA-3AE8-483D-9CE7-0207049BB3B5/Library/Application Support/secret.json)
Backtrace:
0x19a8dfd68 Foundation!_NSOpenFileDescriptor_Protected
0x19a8cb884 Foundation!_NSWriteDataToFileWithExtendedAttributes
0x19a92336c Foundation!writeStringToURLOrPath
0x19abeb294 Foundation!StringProtocol.write(to:atomically:encoding:)
0x104ab0418 MASTestApp!specialized static MastgTest.mastgTest(completion:)
0x104ab122c MASTestApp!closure #1 in closure #1 in closure #1 in ContentView.body.getter
0x1a417e9e8 SwiftUI!0x7199e8 (0x18a8f29e8)
0x1a417ece8 SwiftUI!0x719ce8 (0x18a8f2ce8)
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0067

---
platform: ios
title: Runtime Tracking of Files Eligible for Backup with Frida
id: MASTG-DEMO-0067
code: [swift]
test: MASTG-TEST-0298
---

## Sample

The code snippet below shows sample code that writes files to storage at different locations.

{{ MastgTest.swift }}

## Steps

1. Install the app on a device (@MASTG-TECH-0056)
2. Make sure you have @MASTG-TOOL-0039 installed on your machine and the frida-server running on the device
3. Run `run.sh` to spawn your app with Frida
4. Click the **Start** button
5. Stop the script by pressing `Ctrl+C`

{{ run.sh # script.js }}

## Observation

{{ output.txt }}

The output contains all calls to `open` including the paths of the files being accessed and backtraces. In this case the app is writing a file named `secret.json` to multiple locations.

## Evaluation

The test fails because the `secret.json` file exists in multiple directories that are eligible for backup:

```txt
open(.../Documents/secret.json)
open(.../Library/secret.json)
open(.../Library/Application Support/secret.json)
```
OWASP Mobile Application Security Testing Guide: output

Uses of CommonCrypto hash function:
0x1000071a8    1     12 sym.imp.CC_MD5
0x1000071b4    1     12 sym.imp.CC_SHA1

xrefs to CC_MD5:
(nofunc) 0x1000048c4 [CALL:--x] bl sym.imp.CC_MD5
xrefs to CC_SHA1:
(nofunc) 0x10000456c [CALL:--x] bl sym.imp.CC_SHA1

Use of MD5:
            0x1000048b0      ffe301f8       stur xzr, [sp, 0x1e]
            0x1000048b4      ff0f00f9       str xzr, [sp, 0x18]
            0x1000048b8      e01b00f9       str x0, [sp, 0x30]
            0x1000048bc      e0630091       add x0, sp, 0x18
            0x1000048c0      01008052       mov w1, 0
            ; CODE XREF from sym.func.100004728 @ +0xf0(x)
            0x1000048c4      390a0094       bl sym.imp.CC_MD5
            0x1000048c8      e00316aa       mov x0, x22
            0x1000048cc      e10314aa       mov x1, x20
            0x1000048d0      7d000094       bl sym.func.100004ac4
            ; CODE XREF from sym.func.100004728 @ +0x184(x)
            0x1000048d4      e00316aa       mov x0, x22

Use of SHA1:
            0x100004558      ffe301f8       stur xzr, [sp, 0x1e]
            0x10000455c      ff0f00f9       str xzr, [sp, 0x18]
            0x100004560      e01b00f9       str x0, [sp, 0x30]
            0x100004564      e0630091       add x0, sp, 0x18
            0x100004568      01008052       mov w1, 0
            ; CODE XREF from sym.func.1000043cc @ +0xf4(x)
            0x10000456c      120b0094       bl sym.imp.CC_SHA1
            0x100004570      e00316aa       mov x0, x22
            0x100004574      e10314aa       mov x1, x20
            0x100004578      53010094       bl sym.func.100004ac4
            ; CODE XREF from sym.func.1000043cc @ +0x188(x)
            0x10000457c      e00316aa       mov x0, x22
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0015

---
platform: ios
title: Uses of Broken Hashing Algorithms in CommonCrypto with r2
code: [swift]
id: MASTG-DEMO-0015
test: MASTG-TEST-0211
---

## Sample

{{ MastgTest.swift }}

## Steps

1. Unzip the app package and locate the main binary file (@MASTG-TECH-0058), which in this case is `./Payload/MASTestApp.app/MASTestApp`.
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.

{{ cchash.r2 }}

{{ run.sh }}

## Observation

The output contains all uses of CommonCrypto hash functions in the binary, the xrefs for `CC_MD5` and `CC_SHA1` and the disassembled code of the region where each of these functions is called.

{{ output.txt }}

## Evaluation

The test fails because the MD5 and SHA1 algorithms were found in the code.

Remember that the context is important when evaluating the use of these algorithms. In some cases, the use of MD5 or SHA1 may be acceptable, for example, when the algorithm is used for checksums or non-cryptographic purposes. In order to determine that you should further analyze the reverse-engineered code and try to learn more about the context in which these algorithms are used.
OWASP Mobile Application Security Testing Guide: evaluation

│           0x1000040c0      00008052       mov w0, 0           -> kCCEncrypt (0 for encryption)
│           0x1000040c4      41008052       mov w1, 2           -> kCCAlgorithm3DES (2 for 3DES)
│           0x1000040c8      22008052       mov w2, 1           -> kCCOptionPKCS7Padding (1 for PKCS7 padding)
│           0x1000040cc      e30317aa       mov x3, x23         -> key (pointer to the encryption key)
│           0x1000040d0      04038052       mov w4, 0x18        -> keyLength (0x18 or 24 bytes for 3DES)
│           0x1000040d4      050080d2       mov x5, 0           -> iv (0 or NULL, implying no initialization vector)
│           0x1000040d8      e60316aa       mov x6, x22         -> dataIn (pointer to the input data to be encrypted)
│           0x1000040dc      e70319aa       mov x7, x25         -> dataOut (pointer to the output buffer where encrypted data will be stored)
│           0x1000040e0      790d0094       bl sym.imp.CCCrypt  -> Call to CCCrypt function
OWASP Mobile Application Security Testing Guide: output

Uses of CryptoKit.Insecure functions:
0x100007274    1     12 sym.imp.CryptoKit.Insecure.SHA1Digest.
0x100007280    1     12 sym.imp.CryptoKit.Insecure.MD5.
0x10000728c    1     12 sym.imp.CryptoKit.Insecure.SHA1.
0x100007298    1     12 sym.imp.CryptoKit.Insecure.MD5Digest.

xrefs to CryptoKit.Insecure.MD5:
sym.func.10000469c 0x1000046d8 [CALL:--x] bl sym.imp.CryptoKit.Insecure.MD5.

xrefs to CryptoKit.Insecure.SHA1:
sym.func.1000041d8 0x100004214 [CALL:--x] bl sym.imp.CryptoKit.Insecure.SHA1.

Use of MD5:
│           0x1000046c4      48000090       adrp x8, reloc.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______ ; 0x10000c000
│           0x1000046c8      08d141f9       ldr x8, reloc.__stack_chk_guard ; 0x10000c3a0
│           0x1000046cc      080140f9       ldr x8, [x8]
│           0x1000046d0      a8831af8       stur x8, [x29, -0x58]
│           0x1000046d4      000080d2       mov x0, 0
│           0x1000046d8      ea0a0094       bl sym CryptoKit.Insecure.MD5. ; sym.imp.CryptoKit.Insecure.MD5.
│           0x1000046dc      f70300aa       mov x23, x0
│           0x1000046e0      54000090       adrp x20, reloc.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______ ; 0x10000c000
│           0x1000046e4      947241f9       ldr x20, reloc.CryptoKit.Insecure.MD5. ; 0x10000c2e0
│           0x1000046e8      16805ff8       ldur x22, [x0, -8]

Use of SHA1:
│           0x100004200      48000090       adrp x8, reloc.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______ ; 0x10000c000
│           0x100004204      08d141f9       ldr x8, reloc.__stack_chk_guard ; 0x10000c3a0
│           0x100004208      080140f9       ldr x8, [x8]
│           0x10000420c      a8831af8       stur x8, [x29, -0x58]
│           0x100004210      000080d2       mov x0, 0
│           0x100004214      1e0c0094       bl sym CryptoKit.Insecure.SHA1. ; sym.imp.CryptoKit.Insecure.SHA1.
│           0x100004218      f70300aa       mov x23, x0
│           0x10000421c      54000090       adrp x20, reloc.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______ ; 0x10000c000
│           0x100004220      947a41f9       ldr x20, reloc.CryptoKit.Insecure.SHA1. ; 0x10000c2f0
│           0x100004224      16805ff8       ldur x22, [x0, -8]
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0016

---
platform: ios
title: Uses of Broken Hashing Algorithms in CryptoKit with r2
code: [swift]
id: MASTG-DEMO-0016
test: MASTG-TEST-0211
---

## Sample

{{ MastgTest.swift }}

## Steps

1. Unzip the app package and locate the main binary file (@MASTG-TECH-0058), which in this case is `./Payload/MASTestApp.app/MASTestApp`.
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.

{{ cryptokit_hash.r2 }}

{{ run.sh }}

## Observation

The output contains all uses of `CryptoKit.Insecure` functions in the binary, the xrefs for `Insecure.MD5` and `Insecure.SHA1` and the disassembled code of the region where each of these functions is called.

{{ output.txt }}

## Evaluation

The test fails because the MD5 and SHA1 algorithms were found in the code.

Remember that the context is important when evaluating the use of these algorithms. In some cases, the use of MD5 or SHA1 may be acceptable, for example, when the algorithm is used for checksums or non-cryptographic purposes. In order to determine that you should further analyze the reverse-engineered code and try to learn more about the context in which these algorithms are used.
OWASP Mobile Application Security Testing Guide: output

  2959 ms  srand(seed=0x691a0327)
  2959 ms  rand()
           ... x 16
  2959 ms  $ss17FixedWidthIntegerPsE6random2inxSNyxG_tFZ()
  2959 ms     | arc4random_buf(buf=0x16ef965a8, nbytes=0x8)
           ... x 16
  2959 ms  open(path="/dev/random", oflag=0x0, ...)
  2960 ms  arc4random_uniform(upper_bound=0x100)
           ... x 16
  2960 ms  arc4random()
           ... x 16
  2960 ms  $ss27SystemRandomNumberGeneratorVABycfC()
  2960 ms  $ss17FixedWidthIntegerPsE6random2in5usingxSNyxG_qd__ztSGRd__lFZ()
  2960 ms     | $ss17FixedWidthIntegerPsE7_random5usingxqd__z_tSGRd__lFZ()
  2960 ms     |    | arc4random_buf(buf=0x16ef964d8, nbytes=0x8)
           ... x 16
  2960 ms  drand48()
           ... x 16
  2960 ms  CCRandomGenerateBytes()
  2960 ms  SecRandomCopyBytes()
  2960 ms     | CCRandomCopyBytes()
  2960 ms     |    | CCRandomGenerateBytes()
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0074

---
platform: ios
title: Uses of Insecure Random Number Generation with frida-trace
code: [swift]
id: MASTG-DEMO-0074
test: MASTG-TEST-0311
---

## Sample

This demo uses the same sample code as in @MASTG-DEMO-0073. It demonstrates the use of insecure random number generation using various APIs.

{{ ../MASTG-DEMO-0073/MastgTest.swift }}

## Steps

1. Install the app on a device (@MASTG-TECH-0056)
2. Make sure you have @MASTG-TOOL-0039 installed on your machine and the frida-server running on the device
3. Run `run.sh` to spawn your app with Frida
4. Click the **Start** button
5. Stop the script by pressing `Ctrl+C`

{{ run.sh }}

## Observation

{{ output.txt }}

This output contains both insecure and secure APIs. For this test case the interesting calls are:

- `rand` and `srand`, which expose the insecure libc PRNG.
- `drand48`, which also uses an insecure linear congruential generator.

## Evaluation

The test fails because insecure PRNGs are used in a security relevant context. See the evaluation section in @MASTG-DEMO-0073 for more details.

The same output also shows calls to secure sources such as `SecRandomCopyBytes`, `CCRandomGenerateBytes`, `SystemRandomNumberGenerator`, and the Swift standard library's `FixedWidthInteger.random` implementation. These are present in the sample for contrast, but they are not the reason the test fails.
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0013

---
platform: ios
title: Use of Hardcoded RSA Private Key in SecKeyCreateWithData with r2
code: [swift]
id: MASTG-DEMO-0013
test: MASTG-TEST-0213
---

## Sample

{{ MastgTest.swift # function.asm # decompiled-o1-review.swift }}

## Steps

1. Unzip the app package and locate the main binary file (@MASTG-TECH-0058), which in this case is `./Payload/MASTestApp.app/MASTestApp`.
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.

{{ sec_hardcoded_rsa.r2 }}

{{ run.sh }}

## Observation

The output reveals a call to `SecKeyCreateWithData` as well as the hardcoded RSA private key within the DATA section of the binary.

{{ output.asm # key.asm }}

## Evaluation

The test fails because a hardcoded RSA private key was found in the code.

!!! note
    Using artificial intelligence we're able to decompile the disassembled code and review it. The output is a human-readable version of the assembly code. The AI decompiled code may not perfect and might contain errors but, in this case, it clearly shows the use of `SecKeyCreateWithData` and the associated private key.
OWASP Mobile Application Security Testing Guide: evaluation

0x1000047b4      adrp x0, segment.__DATA    ; 0x100010000   -> This instruction loads the base address of the `.data` segment into register `x0`.
0x1000047b8      add x0, x0, 0xe8           ; int64_t arg1  -> This adds an offset to the base address, pointing to a specific memory location within the `.data` segment, possibly where the hardcoded key or related data is stored.
0x1000047bc      bl sym.func.100004e0c                      -> A function is called, with `x0` as an argument, likely using the data at the computed address (which could be the key) for further operations.
0x1000047c0      ldur x8, [x0, -8]                          -> This loads data from the memory location computed earlier (potentially part of the key) into register `x8`.
0x1000047c4      ldr x8, [x8, 0x40]                         -> Further data manipulation, loading another piece of data related to the earlier load. This could be part of the key processing.
0x1000047f0      bl sym CryptoKit.P256.Signing.PrivateKey.  -> This calls the `PrivateKey` initializer, which may use the previously loaded data (potentially a hardcoded key) in its process of key creation.
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0014

---
platform: ios
title: Use of Hardcoded ECDSA Private Key in CryptoKit with r2
code: [swift]
id: MASTG-DEMO-0014
test: MASTG-TEST-0213
---

## Sample

{{ MastgTest.swift # function.asm # decompiled-o1-review.swift }}

## Steps

1. Unzip the app package and locate the main binary file (@MASTG-TECH-0058), which in this case is `./Payload/MASTestApp.app/MASTestApp`.
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.

{{ cryptokit_hardcoded_ecdsa.r2 }}

{{ run.sh }}

## Observation

The output reveals the different uses of `CryptoKit.P256.Signing.PrivateKey` functions, especially `sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation` which is used to extract the raw representation of the private key. The output also reveals the hardcoded ECDSA private key within the binary's DATA section.

{{ output.asm # key.asm }}

## Evaluation

The test fails because a hardcoded ECDSA private key was found in the code.

!!! note
    Using artificial intelligence we're able to decompile the disassembled code and review it. The output is a human-readable version of the assembly code. The AI decompiled code may not perfect and might contain errors but, in this case, it clearly shows the use of `CryptoKit.P256.Signing.PrivateKey` and the associated private key.
OWASP Mobile Application Security Testing Guide: evaluation

│       │   0x10000484c      080942f9       ldr x8, reloc.kSecAttrKeySizeInBits ; 0x10000c410   ->  Load the address of kSecAttrKeySizeInBits into x8
│       │   0x100004850      000140f9       ldr x0, [x8]
│       │   0x100004854      e30b0094       bl fcn.1000077e0
│       │   0x100004858      800605a9       stp x0, x1, [x20, 0x50]
│       │   0x10000485c      48000090       adrp x8, reloc.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______ ; 0x10000c000
│       │   0x100004860      089d41f9       ldr x8, reloc.Swift.Int    ; 0x10000c338
│       │   0x100004864      883e00f9       str x8, [x20, 0x78]
│       │   0x100004868      08808052       mov w8, 0x400                                       ->  Move 0x400 (1024 in decimal) into w8, the lower 32 bits of x8
│       │   0x10000486c      883200f9       str x8, [x20, 0x60]                                 ->  Store the final value (1024-bit key size) into memory
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0011

---
platform: ios
title: Uses of Insufficient Key Size in SecKeyCreateRandomKey with r2
code: [swift]
id: MASTG-DEMO-0011
test: MASTG-TEST-0209
---

## Sample

The following sample demonstrates the use of `SecKeyCreateRandomKey` to generate an RSA key pair with a 1024-bit key size. The key pair is then used to sign and verify a message.

{{ MastgTest.swift }}

## Steps

When calling [`SecKeyCreateRandomKey`](https://developer.apple.com/documentation/security/1823694-seckeycreaterandomkey) the key size is specified in the [`kSecAttrKeySizeInBits`](https://developer.apple.com/documentation/security/ksecattrkeysizeinbits) attribute within the `parameters` dictionary. See [Key Generation Attributes](https://developer.apple.com/documentation/security/certificate_key_and_trust_services/keys/key_generation_attributes) for details.

1. Unzip the app package and locate the main binary file (@MASTG-TECH-0058), which in this case is `./Payload/MASTestApp.app/MASTestApp`.
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.

{{ security_keysize.r2 }}

{{ run.sh }}

## Observation

The output contains the disassembled code of the function using `SecKeyCreateRandomKey`.

{{ output.txt }}

This function is pretty big so we just included the relevant part of the code that's right before the call to `SecKeyCreateRandomKey`. Note that we can see attributes being set in the `parameters` dictionary such as `kSecAttrKeySizeInBits` as `reloc.kSecAttrKeySizeInBits`. In radare2, this means that the symbol `kSecAttrKeySizeInBits` is not directly referenced by an absolute address but rather through a relocation entry. This entry will be resolved by the dynamic linker at runtime to the actual address where `kSecAttrKeySizeInBits` is located in memory.

## Evaluation

In the output we can see how the `kSecAttrKeySizeInBits` attribute is set to `1024` bits (0x400 in hexadecimal) using the `x8` register. This is later used to call `SecKeyCreateRandomKey`.

{{ evaluation.txt }}

The test fails because the key size is set to `1024` bits, which is considered insufficient for RSA encryption. The key size should be increased to `2048` bits or higher to provide adequate security against modern cryptographic attacks.
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0021

---
platform: ios
title: Uses of Jailbreak Detection Techniques with r2
code: [swift]
id: MASTG-DEMO-0021
test: MASTG-TEST-0240
---

## Sample

The code snippet below shows sample code that performs jailbreak detection checks on the device.

{{ MastgTest.swift }}

## Steps

1. Unzip the app package and locate the main binary file (@MASTG-TECH-0058), which in this case is `./Payload/MASTestApp.app/MASTestApp`.
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.

{{ jailbreak_detection.r2 }}

{{ run.sh }}

## Observation

The output reveals the use of file permissions, protocol handlers and file directories in the app.

{{ output.asm }}

## Evaluation

The test passes because jailbreak detection checks are implemented in the app.
OWASP Mobile Application Security Testing Guide: output

LAContext.canEvaluatePolicy(0x2) called with .deviceOwnerAuthentication (0x2)


Backtrace:
0x100f58110 MASTestApp.debug.dylib!static MastgTest.devicePasscodeSet()
0x100f5802c MASTestApp.debug.dylib!static MastgTest.mastgTest(completion:)
0x100f599d4 MASTestApp.debug.dylib!$s10MASTestApp11ContentViewV4bodyQrvg7SwiftUI05TupleD0VyAE0D0PAEE7paddingyQrAE4EdgeO3SetV_12CoreGraphics7CGFloatVSgtFQOyAE6HStackVyAGyAE4TextV_AE6SpacerVAiEEAJyQrAN_ARtFQOyAiEE12cornerRadius_11antialiasedQrAQ_SbtFQOyAiEE10background_9alignmentQrqd___AE9AlignmentVtAeHRd__lFQOyAE6ButtonVyAiEE4fontyQrAE4FontVSgFQOyAiEEAJyQrAN_ARtFQOyAiEEAJyQrAN_ARtFQOyAV_Qo__Qo__Qo_G_AE14LinearGradientVQo__Qo__Qo_tGG_Qo__AiEEAJyQrAN_ARtFQOyAiEEAY_AZQrAQ_SbtFQOyAiEEA__A0_Qrqd___A2_tAeHRd__lFQOyAiEE5frame8minWidth10idealWidth8maxWidth9minHeight11idealHeight9maxHeightA0_QrAR_A5RA2_tFQOyAE06ScrollD0VyAiEEAJyQrAN_ARtFQOyAiEEA21_A22_A23_A24_A25_A26_A27_A0_QrAR_A5RA2_tFQOyAV_Qo__Qo_G_Qo__AE5ColorVQo__Qo__Qo_tGyXEfU_A18_yXEfU_yyScMYccfU_
0x19afc6e30 SwiftUI!partial apply for implicit closure #2 in implicit closure #1 in WrappedButtonStyle.Body.body.getter
0x19b2ddf28 SwiftUI!closure #1 in PressableGestureCallbacks.dispatch(phase:state:)
0x19b047b98 SwiftUI!thunk for @escaping @callee_guaranteed () -> ()
0x19b047bc0 SwiftUI!thunk for @escaping @callee_guaranteed () -> (@out ())
0x19b047b98 SwiftUI!thunk for @escaping @callee_guaranteed () -> ()
OWASP Mobile Application Security Testing Guide: MASTG DEMO 0026

---
platform: ios
title: Runtime Use of LAContext.canEvaluatePolicy with Frida
id: MASTG-DEMO-0026
code: [swift]
test: MASTG-TEST-0246
---

## Sample

The following sample checks whether the device has a set passcode.

{{ MastgTest.swift }}

## Steps

1. Install the app on a device (@MASTG-TECH-0056)
2. Make sure you have @MASTG-TOOL-0039 installed on your machine and the frida-server running on the device
3. Run `run.sh` to spawn your app with Frida
4. Click the **Start** button
5. Stop the script by pressing `Ctrl+C`

{{ run.sh # script.js }}

## Observation

{{ output.txt }}

The output reveals the use of `LAcontext.canEvaluatePolicy(0x2)` in the app. Policy `0x2` is [`.deviceOwnerAuthentication`](https://developer.apple.com/documentation/localauthentication/lapolicy/deviceownerauthentication).

## Evaluation

The test passes because the output shows the runtime use of `LAcontext.canEvaluatePolicy(.deviceOwnerAuthentication)` which verifies whether the device has passcode set.