<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>ZERO</title>
        <link>https://blog.zero-trust.site/</link>
        <description>Cyber Sec Blog</description>
        <lastBuildDate>Sun, 01 Nov 2026 11:15:14 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en-US</language>
        <copyright>All rights reserved 2026, Kinabler</copyright>
        <item>
            <title><![CDATA[Application Patching]]></title>
            <link>https://blog.zero-trust.site/article/application-patching</link>
            <guid>https://blog.zero-trust.site/article/application-patching</guid>
            <pubDate>Thu, 29 Oct 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden  "><main class="notion light-mode notion-page notion-block-4030aff0a13e8026bb39e125cf02c184"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4070aff0a13e8050bbacc25f00a39728" data-id="4070aff0a13e8050bbacc25f00a39728"><span><div id="4070aff0a13e8050bbacc25f00a39728" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4070aff0a13e8050bbacc25f00a39728" title="Authentication Bypass"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Authentication Bypass</b></span></span></h2><hr class="notion-hr notion-block-4070aff0a13e80aca479d0b7cea30a81"/><div class="notion-text notion-block-4070aff0a13e807088c8ea83ee7d048f">Application patching có thể làm lộ các lỗ hổng tiềm ẩn và cung cấp cái nhìn về cách ứng dụng phản hồi khi các thành phần cụ thể bị thay đổi. Kỹ thuật này cho phép tester mô phỏng các cuộc tấn công bằng cách bypass một số chức năng, chẳng hạn như cơ chế xác thực. Trong số các kỹ thuật patching hiện có, phần này tập trung vào một phương pháp phổ biến: decompile file APK để kiểm tra và chỉnh sửa source code hoặc resource files bằng các công cụ như JADX và APKTool. </div><div class="notion-text notion-block-4080aff0a13e8050a986df21aade80bd">Trong ví dụ dưới đây, ta sẽ khảo sát một ứng dụng yêu cầu xác thực người dùng trước khi truy cập tính năng. Chúng ta sẽ cố bypass giới hạn này bằng application patching.</div><div class="notion-row notion-block-4080aff0a13e801d95a5cc0600c1e307"><div class="notion-column notion-block-4080aff0a13e8015b5e0dd4f14132bee" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80819c57fff4266a6b99"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:355.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A015b7b17-3e5e-4b62-a992-2ff2d454cca7%3Aimage.png?table=block&amp;id=4080aff0-a13e-8081-9c57-fff4266a6b99&amp;t=4080aff0-a13e-8081-9c57-fff4266a6b99" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4080aff0a13e80cb9c60f71e3702d19c" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4080aff0a13e80adb16dfb34a92730f9">Package name: <code class="notion-inline-code">com.hackthebox.myapp</code></div><div class="notion-text notion-block-4080aff0a13e80d08f3ecfd1af80794c">Khởi động ứng dụng và thử đăng nhập với credentials ngẫu nhiên <code class="notion-inline-code">test/test</code> sẽ hiển thị thông báo “<code class="notion-inline-code">Wrong username or password!</code>”</div><div class="notion-blank notion-block-4080aff0a13e809090d8d2e3d0054141"> </div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4080aff0a13e80cd9ea8f4edc0f523e2">Bây giờ, hãy dùng JADX để đọc source:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e8070acc9d82b542ba4b2"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A357e5ab0-23bc-4965-8d30-4e244a8fc8ad%3Aimage.png?table=block&amp;id=4080aff0-a13e-8070-acc9-d82b542ba4b2&amp;t=4080aff0-a13e-8070-acc9-d82b542ba4b2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80308ec1cfbe0e1c26e2">Đây là đoạn code sẽ kiểm tra Authentication: Đoạn code sẽ lấy user (entry) từ Database, nếu có user hợp lệ được trả về thì app sẽ call đến native method <code class="notion-inline-code">stringFromJNI()</code> để trả thông báo cho người dùng</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e802eb267f16558d80f1e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A8ec45ce0-24c2-4632-8cc1-83b79b0be598%3Aimage.png?table=block&amp;id=4080aff0-a13e-802e-b267-f16558d80f1e&amp;t=4080aff0-a13e-802e-b267-f16558d80f1e" alt="Return value của getUser()" loading="lazy" decoding="async"/><figcaption class="notion-asset-caption">Return value của <code class="notion-inline-code">getUser()</code></figcaption></div></figure><div class="notion-text notion-block-4080aff0a13e8017a628ee4613dd4719">Bây giờ ta sẽ patch chương trình thành luôn đúng ngay đoạn check <code class="notion-inline-code">null</code> của method <code class="notion-inline-code">onPostExecute()</code></div><div class="notion-text notion-block-4080aff0a13e80ad90add5f38a2c08f3">Để patch được, ta cần decompile file <code class="notion-inline-code">apk</code> bằng APKTool</div><div class="notion-text notion-block-4080aff0a13e800186ece3f3fffe1f8c">Các file smali sẽ nằm tại: <code class="notion-inline-code">.\myapp\smali\com\hackthebox\myapp\</code> và đây là dòng smali đã check true/false</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80188a0ada6aec3486c5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A72b13035-4767-47fe-a93e-dc73274dd072%3Aimage.png?table=block&amp;id=4080aff0-a13e-8018-8a0a-da6aec3486c5&amp;t=4080aff0-a13e-8018-8a0a-da6aec3486c5" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80f2b759c0238bd1fad8">Sẽ có 2 hướng:</div><ul class="notion-list notion-list-disc notion-block-4080aff0a13e80b980a3eb54a37f5eaf"><li>Một là: Xóa hẳn điều kiện này đi để điều kiện luôn đúng</li></ul><ul class="notion-list notion-list-disc notion-block-4080aff0a13e80d7a321d611b798bde7"><li>Hai là: Đảo ngược logic của nó (Login sai ⇒ Đúng / Login đúng ⇒ Sai)</li></ul><div class="notion-text notion-block-4080aff0a13e805688a2d2f9e25fa67b">Ta sẽ chọn hướng hai để code sau khi compile lại không bị thay đổi logic quá nhiều (tối thiểu thay đổi - giảm thiểu rủi ro hỏng file)</div><div class="notion-text notion-block-4080aff0a13e80d2b78eefae107d94cc"><code class="notion-inline-code">if-eqz p1, :cond_0</code> ⇒ <code class="notion-inline-code">if-nez p1, :cond_0</code></div><blockquote class="notion-quote notion-block-4080aff0a13e80eeb472cce8b6f67474"><div>Bạn có thể đọc thêm tại đây: <a class="notion-link" href="https://gist.github.com/AadilGillani/8c5690ebbaceda2914f9dc37197bd154" target="_blank" rel="noopener noreferrer">Smalli Cheat-Sheet</a></div></blockquote><div class="notion-text notion-block-4080aff0a13e80fea70fe8b3bcf01549">Sau khi thay đổi xong, bạn sẽ compile lại thành file <code class="notion-inline-code">apk</code> </div><div class="notion-text notion-block-4080aff0a13e809997f2c845713b7902">Sau đó ta sẽ sign lại app.</div><div class="notion-text notion-block-4080aff0a13e80909f16d981d5dc9419">Gỡ cài đặt app cũ và cài đặt app mới:</div><div class="notion-row notion-block-4080aff0a13e80f9b930cd318955ca06"><div class="notion-column notion-block-4080aff0a13e80a18733e4ed1e06ecc3" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.3125)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e806393fee8180639cebe"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:355.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A1de04648-2620-4b9a-8e06-265d0afaeafa%3Aimage.png?table=block&amp;id=4080aff0-a13e-8063-93fe-e8180639cebe&amp;t=4080aff0-a13e-8063-93fe-e8180639cebe" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4080aff0a13e8027a644fa0e1c1d0085" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.6875)"><div class="notion-text notion-block-4080aff0a13e80b68752e46c62534c55">Lúc này, ta không cần nhập gì cả, chỉ cần ấn nút Login luôn thì thông báo đăng nhập thành công sẽ hiện ra.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80e3b167dcbfcafda1da"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:150px"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A8be155a7-5f9c-4e04-ae77-29fadffdc7a6%3Aimage.png?table=block&amp;id=4080aff0-a13e-80e3-b167-dcbfcafda1da&amp;t=4080aff0-a13e-80e3-b167-dcbfcafda1da" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e8080bf03d210bf9a90f3">Logic code sau khi patching</div></div><div class="notion-spacer"></div></div><hr class="notion-hr notion-block-4080aff0a13e807ab52ae849f351bc54"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4080aff0a13e806d8b18c98af2f3e772" data-id="4080aff0a13e806d8b18c98af2f3e772"><span><div id="4080aff0a13e806d8b18c98af2f3e772" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4080aff0a13e806d8b18c98af2f3e772" title="Modifying Game Apps"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Modifying Game Apps</b></span></span></h2><div class="notion-row notion-block-4080aff0a13e8069b81fcc44184aab25"><div class="notion-column notion-block-4080aff0a13e8014b0cde9f1eeefbc87" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e800b86addbf0d86f52ad"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:750px"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ab6d8f824-cbdb-4f00-aa0d-e3c937d01b19%3Aimage.png?table=block&amp;id=4080aff0-a13e-800b-86ad-dbf0d86f52ad&amp;t=4080aff0-a13e-800b-86ad-dbf0d86f52ad" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4080aff0a13e800bb708eb14d3a3dc28" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80d8a14ef6e54dc8ad68"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:320.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ade7a741e-02af-4a57-bc1d-fc6193feca41%3Aimage.png?table=block&amp;id=4080aff0-a13e-80d8-a14e-f6e54dc8ad68&amp;t=4080aff0-a13e-80d8-a14e-f6e54dc8ad68" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4080aff0a13e802b8ec9fe72f1074479">Bạn đã hiểu App Patching sẽ làm gì trong tình huống này rồi chứ 😃 ?</div><div class="notion-text notion-block-4080aff0a13e805983c0f5d01034a80f">⇒ Bypass cái Daily check này hoặc giảm 50 coin xuống 40 coin hoặc đơn giản hơn nữa là không cần đủ coin vẫn mua được 😃 chứ sao nữa kkk</div><div class="notion-text notion-block-4080aff0a13e804eaf0cd4badba47841">Mở ứng dụng bằng JADX</div><div class="notion-text notion-block-4080aff0a13e8035a2d6d6fb48b2b13f">Đây là logic trong button “<code class="notion-inline-code">GO TO STORE</code>”</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e8012b62fc10a12635299"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A7cbcdda3-fa96-4939-96b5-c6f59da2327a%3Aimage.png?table=block&amp;id=4080aff0-a13e-8012-b62f-c10a12635299&amp;t=4080aff0-a13e-8012-b62f-c10a12635299" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e8023afc8ff22935084ff">Ta có thể thấy khi “Kiểm tra coins có đủ hay không” thì app call đến 1 native method <code class="notion-inline-code">getPrice()</code> để lấy giá sản phẩm. Đi sâu vào method <code class="notion-inline-code">purchaseItem()</code>, ta sẽ thấy coin sẽ được so sánh với cost đó để</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e8026994ec3d54daf073d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A9e6113bf-5af8-4128-b0ea-956399d65400%3Aimage.png?table=block&amp;id=4080aff0-a13e-8026-994e-c3d54daf073d&amp;t=4080aff0-a13e-8026-994e-c3d54daf073d" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80bda5f0f28029f85699">Ngay tại đây, ta có thể cho nó return <code class="notion-inline-code">True</code> thay vì <code class="notion-inline-code">False</code> </div><div class="notion-text notion-block-4080aff0a13e8057958acf29cea7e839">Tiếp tục đến với button “<code class="notion-inline-code">EARN COINS</code>” </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e803d8cb7cd8b7c8ad3b6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A89c4fcda-009c-4cea-9764-01adaba157e0%3Aimage.png?table=block&amp;id=4080aff0-a13e-803d-8cb7-cd8b7c8ad3b6&amp;t=4080aff0-a13e-803d-8cb7-cd8b7c8ad3b6" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e805f98efdf05ca0a5ad2">Đi sâu vào method addCoins(), để khám phá logic của nó</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e801fb4aad9e7f4b37431"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A6bb9fb26-e335-480d-983b-279a5e0471e9%3Aimage.png?table=block&amp;id=4080aff0-a13e-801f-b4aa-d9e7f4b37431&amp;t=4080aff0-a13e-801f-b4aa-d9e7f4b37431" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80229e81fb7a28c2ae00">Ta có thể thấy rằng <code class="notion-inline-code">earned_coins_key</code> và <code class="notion-inline-code">coins_key</code> được lấy từ <code class="notion-inline-code">SharedPreferences</code></div><div class="notion-text notion-block-4080aff0a13e80e98650e7a40a8adc5a">Sau đó kiểm tra xem earned_coins_key đã vượt qua hoặc bằng 40 chưa. Nếu rồi thì dừng không cộng thêm 10 coins nữa. Ngoài ra khi cộng, app không dùng operator <code class="notion-inline-code">+</code> đơn giản mà dùng method <code class="notion-inline-code">Math.min()</code>. Kể cả có cộng vượt qua 50 thì return value của method <code class="notion-inline-code">Math.min(50, 40)</code> vẫn sẽ là 40.</div><div class="notion-text notion-block-4080aff0a13e80188be6ced5c9d816c3">Sau khi cộng xong thì number of coin mới sẽ được lưu lại vào trong SharePreferences</div><div class="notion-text notion-block-4080aff0a13e809d9cfdcb43dd0fdd40">Sau khi overview toàn bộ, ta thấy việc Patching tại logic thứ 1 (Logic check <code class="notion-inline-code">coins enough</code>) là dễ dàng nhất (vì chỉ cần patching 1 lần duy nhất). Nói chung, khi bạn đã biết Patching rồi thì cứ thỏa sức sáng tạo thôi 😄</div><div class="notion-text notion-block-4080aff0a13e80108156e4aaf9f6152c">Như bài của HackTheBox, họ sẽ bám theo hằng số này:</div><div class="notion-text notion-block-4080aff0a13e8077a359cdb5f8e42e93">Có thể do sai sót khi decompile của JADX nên giá trị 40 mà ta thấy thực chất là value của hằng số này. Code gốc có thể truyền hằng số này thay vì giá trị 40</div><div class="notion-text notion-block-4080aff0a13e80a18394cd261793ae9d">Tôi sẽ thử thay đổi nó xem sao nhé 🙂. Trước tiên, xác định code smali tương ứng của hằng số đó, nó nằm trong đoạn sau</div><div class="notion-text notion-block-4080aff0a13e80cd9d53ce9986d53f11">Ta sẽ thay đổi <code class="notion-inline-code">0x28</code> (40) thành <code class="notion-inline-code">0x32</code> (50). Dùng apktool để decompile file apk</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e807eb681fc7f703bee42"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Acb4b8a25-6f3b-4c97-90d4-1e2ed48bb1bb%3Aimage.png?table=block&amp;id=4080aff0-a13e-807e-b681-fc7f703bee42&amp;t=4080aff0-a13e-807e-b681-fc7f703bee42" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80f1afcbca4ed26a380c">Sau đó tiếp tục dùng apktool để compile folder này thành file <code class="notion-inline-code">.apk</code> và sign nó (bằng script của riêng tôi). </div><div class="notion-text notion-block-4080aff0a13e80bca976df91442b0f0b">Kiểm tra lại phần đã Patch bằng JADX</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e8054985de05720eccefe"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A1ee7e0b7-e6e9-41e7-886a-2e0eacfbbdcc%3Aimage.png?table=block&amp;id=4080aff0-a13e-8054-985d-e05720eccefe&amp;t=4080aff0-a13e-8054-985d-e05720eccefe" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80c18c30e869aa71a08b">Ok, như vậy là nó không thay đổi gì cả, mất công Patch theo hướng này rồi thì ta sẽ cùng Patch nốt 2 giá trị <code class="notion-inline-code">40</code> còn lại :)) </div><div class="notion-text notion-block-4080aff0a13e8026be08fcfc135962dd">Ta chỉ cần pathc nốt dòng <code class="notion-inline-code">const/16 v3, 0x28</code> ⇒ <code class="notion-inline-code">const/16 v3, 0x32 </code>là xong rồi, vì thanh ghi <code class="notion-inline-code">v3</code> được sử dụng cho cả 2 giá trị <code class="notion-inline-code">40</code> mà bạn thấy trên JADX</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80c98b4cea4966263476"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A648c3c00-bdae-41ea-810d-434cbefb2a6a%3Aimage.png?table=block&amp;id=4080aff0-a13e-80c9-8b4c-ea4966263476&amp;t=4080aff0-a13e-80c9-8b4c-ea4966263476" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e8082a414ee0bc5c80fdd">Tiếp tục, compile và sign lại app, sau đó check file patched trên JADX để quan sát sự thay đổi</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e8055bebfdc8abe284181"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A24be8a0a-4212-42a1-8d9e-dc271703c99c%3Aimage.png?table=block&amp;id=4080aff0-a13e-8055-bebf-dc8abe284181&amp;t=4080aff0-a13e-8055-bebf-dc8abe284181" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80efba74cdf9e81ebdea">Như vậy cả 3 giá trị đều đã thay đổi, bây giờ khởi động lại app và thử claim 50 coins xem nào.</div><div class="notion-row notion-block-4080aff0a13e80a89ceed2699e7ba747"><div class="notion-column notion-block-4080aff0a13e80988ddaef2424ed42a4" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80ccb86dd5dce72483ff"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:356.9886169433594px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af36a568b-aa73-48f6-8bda-a339637d7a2d%3Aimage.png?table=block&amp;id=4080aff0-a13e-80cc-b86d-d5dce72483ff&amp;t=4080aff0-a13e-80cc-b86d-d5dce72483ff" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4080aff0a13e8040aa35d83b560f5415" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80c2b6eaeeae34b37588"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:350.9801025390625px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af681dc55-8d31-467b-8c97-b93e0fbfbac3%3Aimage.png?table=block&amp;id=4080aff0-a13e-80c2-b6ea-eeae34b37588&amp;t=4080aff0-a13e-80c2-b6ea-eeae34b37588" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4080aff0a13e8047965ae04af03acf81">Done rồi</div><hr class="notion-hr notion-block-4080aff0a13e802bb9fbf1efdceb8f2f"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4080aff0a13e80c6ba0ac627a3428134" data-id="4080aff0a13e80c6ba0ac627a3428134"><span><div id="4080aff0a13e80c6ba0ac627a3428134" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4080aff0a13e80c6ba0ac627a3428134" title="License Verification Bypass"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>License Verification Bypass</b></span></span></h2><div class="notion-text notion-block-4080aff0a13e80e7a1a5f62ee4182e7b">Ngoài ra, trong các tình huống application patching, một nơi cần chú ý là <code class="notion-inline-code"><b>quá trình license verification bypass</b></code>. Cơ chế này được thiết kế để đảm bảo người dùng hợp pháp hoặc được cấp quyền sử dụng ứng dụng và nó áp dụng cho các app trả phí hoặc app có in-app purchases. </div><div class="notion-text notion-block-4080aff0a13e8027babcd3d6ab3c0b48"><b>License Verification Bypass</b> là phương pháp mà các attacker có thể dùng để sử dụng các tính năng trả phí mà không thực sự mua license. Nhiều kỹ thuật có thể dùng để bypass các cơ chế như vậy, bao gồm application patching, dùng tool bên thứ ba để giả lập license hợp lệ hoặc can thiệp và thay đổi giao tiếp giữa ứng dụng và licensing server. Dưới đây là các bước cho thấy app được xác minh như thế nào:</div><table class="notion-simple-table notion-block-4080aff0a13e809fb8d0c0badf3552b5"><tbody><tr class="notion-simple-table-row notion-block-4080aff0a13e8063a129c8f563ad6906"><td class="" style="width:184.66192626953125px"><div class="notion-simple-table-cell">Bước</div></td><td class="" style="width:427.66192626953125px"><div class="notion-simple-table-cell">Mô tả</div></td></tr><tr class="notion-simple-table-row notion-block-4080aff0a13e8075a8d6ce0a23ac546b"><td class="" style="width:184.66192626953125px"><div class="notion-simple-table-cell">License Verification Library (LVL)</div></td><td class="" style="width:427.66192626953125px"><div class="notion-simple-table-cell">Android cung cấp License Verification Library (LVL) để tạo điều kiện giao tiếp giữa app và các licensing server của Google nhằm xác minh trạng thái license của app.</div></td></tr><tr class="notion-simple-table-row notion-block-4080aff0a13e807398b9db270aa01b6b"><td class="" style="width:184.66192626953125px"><div class="notion-simple-table-cell">Verification Process</div></td><td class="" style="width:427.66192626953125px"><div class="notion-simple-table-cell">Khi một app có license verification được khởi chạy, nó sẽ cố gắng liên hệ với các server của Google để xác nhận người dùng đã mua hợp pháp app hay một tính năng cụ thể.</div></td></tr><tr class="notion-simple-table-row notion-block-4080aff0a13e807f9a45feb03314f961"><td class="" style="width:184.66192626953125px"><div class="notion-simple-table-cell">Server Response</div></td><td class="" style="width:427.66192626953125px"><div class="notion-simple-table-cell">Server phản hồi với trạng thái licensing, và app dùng phản hồi này để quyết định cấp quyền truy cập đầy đủ hay giới hạn một số tính năng.</div></td></tr></tbody></table><div class="notion-text notion-block-4080aff0a13e8095a415d120d7811515">Mục đích chính của license verification là ngăn chặn <b>piracy</b> và việc sử dụng trái phép. <b>Piracy</b> trong các ứng dụng Android có thể xảy ra như sau: hình dung một premium application bị chỉnh sửa license verification và được phân phối lại qua các third-party app stores. Trong phiên bản sửa đổi này, các kiểm tra license nội bộ của app được patch để luôn trả về trạng thái hợp lệ, bất kể người dùng đã mua license hợp pháp hay chưa. Điều này cho phép người dùng tải app từ các store ngoài kia truy cập tính năng trả phí mà không cần thanh toán.</div><div class="notion-text notion-block-4080aff0a13e80a08b7ec752fd9ee04b">Trong bài tập này, chúng ta sẽ mô phỏng kịch bản piracy nói trên và cố bypass license verification của app.</div><div class="notion-row notion-block-4080aff0a13e80aaa455d09eb8a790b7"><div class="notion-column notion-block-4080aff0a13e8005842ef752b25d6e94" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e808db2e3c3bf051a8c89"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:355.9801025390625px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A129a5a6c-ae5d-4b93-baca-ac8271394857%3Aimage.png?table=block&amp;id=4080aff0-a13e-808d-b2e3-c3bf051a8c89&amp;t=4080aff0-a13e-808d-b2e3-c3bf051a8c89" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4080aff0a13e80a393d7e30acc8317df" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4080aff0a13e809fb747cebf4ebbb678">Package name: <code class="notion-inline-code">com.example.myapplication</code></div><div class="notion-text notion-block-4080aff0a13e80808093e3998ae635af">Ta đang ở trạng thái là một user thường (<code class="notion-inline-code">normal application</code>). Việc của ta sẽ là bypass thành <code class="notion-inline-code">premium application</code> </div><div class="notion-text notion-block-4080aff0a13e806da3e9d9e3fa2df7fc">Còn hiện tại Message cho biết để truy cập các premium features, ta cần mua license.</div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4080aff0a13e806da1f3cddaf75e410f">Mở file <code class="notion-inline-code">.apk</code> trên JADX.</div><div class="notion-text notion-block-4080aff0a13e806c94dac477cb8aaa6f">Ta sẽ thấy đây chính là method (<code class="notion-inline-code">checkAccess()</code>) kiểm tra License và nó thuộc Package <code class="notion-inline-code">com.google.android.vending.licensing</code>  với tham số truyền vào là <code class="notion-inline-code">mLicenseCheckerCallback</code></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e805aab83e3ea5d5ed0a6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A5f7e0195-e948-442c-81ee-549bddf451e9%3Aimage.png?table=block&amp;id=4080aff0-a13e-805a-ab83-e3ea5d5ed0a6&amp;t=4080aff0-a13e-805a-ab83-e3ea5d5ed0a6" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e8069b856fe8e6cebbbfa"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ae2e2d3d4-7a9e-4814-9508-ea9ec6357236%3Aimage.png?table=block&amp;id=4080aff0-a13e-8069-b856-fe8e6cebbbfa&amp;t=4080aff0-a13e-8069-b856-fe8e6cebbbfa" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80dca8fcf5d18a6d3b7a">Lần theo <code class="notion-inline-code">mLicenseCheckerCallback</code> ta thấy nó được khởi tạo từ class <code class="notion-inline-code">MyLicenseCheckerCallback</code>: 
<code class="notion-inline-code">this.mLicenseCheckerCallback = new MyLicenseCheckerCallback();</code></div><div class="notion-text notion-block-4080aff0a13e809e895ac5198db5ec06">Class đó chứa các điều kiện để kiểm tra tính hợp lệ của license hay nói cách khác là kiểm tra xem bạn có được phép truy cập vào ứng dụng hay không:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80b6ad83e7fa2f28fd9c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aaf34066e-38da-4a80-93d1-ed0d31009ed7%3Aimage.png?table=block&amp;id=4080aff0-a13e-80b6-ad83-e7fa2f28fd9c&amp;t=4080aff0-a13e-80b6-ad83-e7fa2f28fd9c" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80f19015df8241e8d407">Ta thấy method <code class="notion-inline-code">allow()</code> chính là mục tiêu và nó được gọi trong <code class="notion-inline-code">checkAccess()</code> với đoạn code cos thể viết gọn lại như sau</div><div class="notion-text notion-block-4080aff0a13e80c6ae5ffa4f259861ed">Như bạn có thể thấy, nó đang dùng nhiều <code class="notion-inline-code">IF</code> operator để cố gắng connect đến license service nếu không tồn tại <code class="notion-inline-code">cached license response</code>.</div><div class="notion-text notion-block-4080aff0a13e80348d73e37e8ad9a191">⇒ Vậy, để ta có thể bypass được license check này, ta cần làm cho điều kiện <code class="notion-inline-code">this.mPolicy.allowAccess()</code> này luôn đúng và khi đó <code class="notion-inline-code">allow()</code> sẽ luôn được gọi.</div><div class="notion-text notion-block-4080aff0a13e80fd8a3af72d297013f0">Cách đơn giản nhất là ta sẽ đảo ngược logic check là được. Ngay tại đây.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e803ea560f703f8290c04"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ad992a2ec-17e9-4207-a37d-09b3ece7c403%3Aimage.png?table=block&amp;id=4080aff0-a13e-803e-a560-f703f8290c04&amp;t=4080aff0-a13e-803e-a560-f703f8290c04" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e80a2aefcc6d29a44db66">File mà ta cần patch sẽ nằm tại: <code class="notion-inline-code">.\myapp\smali\com\google\android\vending\licensing\</code></div><div class="notion-text notion-block-4080aff0a13e80b2b848c43b49636850">Mở lại file apk mới bằng JADX để kiểm tra lại logic xem</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e8010b979e68ef16b88d8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A7852f356-0ba4-43df-82a6-bccadd694a22%3Aimage.png?table=block&amp;id=4080aff0-a13e-8010-b979-e68ef16b88d8&amp;t=4080aff0-a13e-8010-b979-e68ef16b88d8" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4080aff0a13e807a8da2ef963030ba19">Logic được đảo ngược thành công, bây giờ thử sử dụng app trên AVD để xem kết quả</div><div class="notion-row notion-block-4080aff0a13e807ab9aaef0d4ea34688"><div class="notion-column notion-block-4080aff0a13e806b8b40e4d789fe5b0d" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4080aff0a13e80508ba6e981e4c550e5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:356.9886169433594px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af29fb468-8560-4834-9c3d-57b3c2ac8bf7%3Aimage.png?table=block&amp;id=4080aff0-a13e-8050-8ba6-e981e4c550e5&amp;t=4080aff0-a13e-8050-8ba6-e981e4c550e5" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4080aff0a13e80de895acdef1892e178" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-4080aff0a13e806f916afcab2e7002a5">⇒ Như vậy, ta có thể truy cập các tính năng Premium free rồi.</div><div class="notion-text notion-block-4080aff0a13e80daad18d3587f6aafb5">Ngoài việc đổi từ eqz → nez thì bạn cũng có thể đáp nguyên cái điều kiện <code class="notion-inline-code">if-nez v0, :cond_16</code> ra đằng sau <code class="notion-inline-code">invoke-interface {p1, v0}, Lcom/google/android/vending/licensing/LicenseCheckerCallback;-&gt;allow(I)V</code> để đỡ bị cản bước bởi điều kiện nào 😃</div><div class="notion-blank notion-block-4080aff0a13e80b2bcc5c04236900987"> </div></div><div class="notion-spacer"></div></div><hr class="notion-hr notion-block-4080aff0a13e8027aa0eee836503154a"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4080aff0a13e803f912dd8a43c7145f8" data-id="4080aff0a13e803f912dd8a43c7145f8"><span><div id="4080aff0a13e803f912dd8a43c7145f8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4080aff0a13e803f912dd8a43c7145f8" title="Root Detection Bypass"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Root Detection Bypass</b></span></span></h2><div class="notion-text notion-block-4090aff0a13e8009abf8f8341fd47911">Root detection trong các ứng dụng Android là một biện pháp bảo mật phổ biến mà các lập trình viên sử dụng để bảo toàn tính toàn vẹn của ứng dụng.</div><div class="notion-text notion-block-4090aff0a13e8036a03debdfb19c83b5">Có nhiều phương pháp mà lập trình viên có thể dùng để triển khai kiểm tra root detection trong ứng dụng, bao gồm tìm kiếm các ứng dụng root phổ biến, tìm sự hiện diện của binary su, kiểm tra các thư viện open-source phổ biến, v.v. 
Khi một ứng dụng phát hiện thiết bị đã root, nó có thể chặn truy cập, giới hạn một số tính năng, hoặc hiển thị thông báo cảnh báo cho người dùng. Nếu một ứng dụng chặn sử dụng trên thiết bị đã root, người dùng có thể muốn vượt qua giới hạn này để giữ cả chức năng lẫn lợi ích của việc root. Trong section này, chúng ta sẽ tìm hiểu cách vượt qua root detection bằng cách patch ứng dụng.</div><div class="notion-text notion-block-4090aff0a13e8096bb45f888620755b8">Đối với bài thực hành này, khuyên bạn dùng một emulator AVD</div><div class="notion-row notion-block-4090aff0a13e804eae38d37f874822b1"><div class="notion-column notion-block-4090aff0a13e80f5bb7bdbd52be60a74" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.3125)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80f289e1c2b418c7eeb5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:353.991455078125px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A1a4e8ac5-a0e8-469b-9cdc-671bd2b58a3d%3Aimage.png?table=block&amp;id=4090aff0-a13e-80f2-89e1-c2b418c7eeb5&amp;t=4090aff0-a13e-80f2-89e1-c2b418c7eeb5" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4090aff0a13e808b8e32d4e39b98c5bb" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.6875)"><div class="notion-text notion-block-4090aff0a13e80e19fcbd372100f4b8f">Package name: <code class="notion-inline-code">com.hackthebox.myapp</code></div><div class="notion-text notion-block-4090aff0a13e80188cb1c3cd0007fc55">Ứng dụng ngân hàng đã phát hiện thiết bị đã root và hiển thị thông báo Rooted device detected.</div></div><div class="notion-spacer"></div></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4090aff0a13e80e48cb0d8239ef40244" data-id="4090aff0a13e80e48cb0d8239ef40244"><span><div id="4090aff0a13e80e48cb0d8239ef40244" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4090aff0a13e80e48cb0d8239ef40244" title="Third-Party Libraries"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Third-Party Libraries</span></span></h3><div class="notion-text notion-block-4090aff0a13e8038a7e0dcecff7ae6f5">Kiểm tra ứng dụng bằng JADX</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80a082fbcf25081cdbaf"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A2141702d-474f-4d0c-98a2-67381dace5a3%3Aimage.png?table=block&amp;id=4090aff0-a13e-80a0-82fb-cf25081cdbaf&amp;t=4090aff0-a13e-80a0-82fb-cf25081cdbaf" alt="Tôi đã thay đổi tên method một chút để trông dễ hiểu code hơn" loading="lazy" decoding="async"/><figcaption class="notion-asset-caption">Tôi đã thay đổi tên method một chút để trông dễ hiểu code hơn</figcaption></div></figure><div class="notion-text notion-block-4090aff0a13e80fdb4e1e0c8c27a728d">Đoạn code trên cho thấy method <code class="notion-inline-code">d16r45()</code>, trong đó có dòng <code class="notion-inline-code">if (this.rootBeer.isRooted())</code>. Nếu method <code class="notion-inline-code">isRooted()</code> trả về true, chuỗi trả về từ method <code class="notion-inline-code">hd87et()</code> sẽ được hiển thị. Package được <code class="notion-inline-code">import com.scottyab.rootbeer.RootBeer</code> cho biết ứng dụng đang dùng một thư viện tên là <code class="notion-inline-code">rootbeer</code> để kiểm tra thiết bị đã root hay chưa. Dùng APKTool, ta có thể chỉnh sửa code Smali và vượt qua kiểm tra root detection bằng cách đảo ngược điều kiện <code class="notion-inline-code">if</code>, như đã trình bày ở section trước.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e8014b315d65ac254b1ab"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A51af4bdc-c44e-4535-a611-041575d573ad%3Aimage.png?table=block&amp;id=4090aff0-a13e-8014-b315-d65ac254b1ab&amp;t=4090aff0-a13e-8014-b315-d65ac254b1ab" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e8064a442e42e0f3e12c6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A308262ed-ed8a-496d-917b-5cfcad7a9b26%3Aimage.png?table=block&amp;id=4090aff0-a13e-8064-a442-e42e0f3e12c6&amp;t=4090aff0-a13e-8064-a442-e42e0f3e12c6" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4090aff0a13e80b08f4ef167df1d1f4b" data-id="4090aff0a13e80b08f4ef167df1d1f4b"><span><div id="4090aff0a13e80b08f4ef167df1d1f4b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4090aff0a13e80b08f4ef167df1d1f4b" title="Build Tags"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Build Tags</span></span></h3><div class="notion-text notion-block-4090aff0a13e800b8d16d30b391e953c">Trong ví dụ này, root detection được triển khai bằng cách kiểm tra build tags của hệ điều hành thiết bị. Build tags là một phần của build properties hệ thống, cho biết cách hệ điều hành được biên dịch. Trên thiết bị chưa root, build tag thường được đặt thành giá trị dạng <code class="notion-inline-code">release-keys</code>, trong khi thiết bị đã root (hoặc chạy custom ROM) thường dùng các tag như <code class="notion-inline-code">test-keys</code> hay <code class="notion-inline-code">dev-keys</code>. </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80df9d65e92730167bb9"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:524.9573974609375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A0c21843b-3552-49a4-8909-c131ae2d1a61%3Aimage.png?table=block&amp;id=4090aff0-a13e-80df-9d65-e92730167bb9&amp;t=4090aff0-a13e-80df-9d65-e92730167bb9" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e80478deecdd83f5e86a6">Đoạn code cho thấy một method khác tên <code class="notion-inline-code">v55n21()</code>. Dòng <code class="notion-inline-code">String str = Build.TAGS;</code> lưu chuỗi trả về từ field <code class="notion-inline-code">Build.TAGS</code> vào biến <code class="notion-inline-code">str</code>. Nếu chuỗi con <code class="notion-inline-code">test-keys</code> được tìm thấy trong chuỗi này, ứng dụng coi thiết bị là đã root. Để vượt qua kiểm tra này, ta có thể sửa code Smali bằng APKTool bằng cách thay đổi điều kiện <code class="notion-inline-code">if (str != null &amp;&amp; str.contains(&quot;test-keys&quot;))</code>.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e806ea481c117c2bde78a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A24154063-f1d5-408a-84ab-b64b849af3b3%3Aimage.png?table=block&amp;id=4090aff0-a13e-806e-a481-c117c2bde78a&amp;t=4090aff0-a13e-806e-a481-c117c2bde78a" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80c2ac2ff076e1edd655"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af8897c61-bff7-45e1-997c-f9f0f17f9112%3Aimage.png?table=block&amp;id=4090aff0-a13e-80c2-ac2f-f076e1edd655&amp;t=4090aff0-a13e-80c2-ac2f-f076e1edd655" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4090aff0a13e807da492e46376c4e78b" data-id="4090aff0a13e807da492e46376c4e78b"><span><div id="4090aff0a13e807da492e46376c4e78b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4090aff0a13e807da492e46376c4e78b" title="Root Management Apps"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Root Management Apps</span></span></h3><div class="notion-text notion-block-4090aff0a13e8020a9f6e067aeb39a5c">Trong tình huống này, các ứng dụng quản lý root được cài đặt trên thiết bị. Các ứng dụng này cho phép người dùng quản lý quyền root trên hệ thống Android đã root, kiểm soát ứng dụng nào được cấp quyền <code class="notion-inline-code">superuser</code>.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e806ea837eaf372f03a01"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:604.9715576171875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ad1e986e9-914a-4323-a4ee-78204099d6d4%3Aimage.png?table=block&amp;id=4090aff0-a13e-806e-a837-eaf372f03a01&amp;t=4090aff0-a13e-806e-a837-eaf372f03a01" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e80898f13c3e64cdb1371">Method <code class="notion-inline-code">h27n99()</code> kiểm tra xem điều kiện <code class="notion-inline-code">if (this.apn.isRootManagementAppInstalled(getPackageManager()))</code> có trả về <code class="notion-inline-code">true</code> hay không. Để hiểu cách kiểm tra này được thực hiện, hãy double-click vào <code class="notion-inline-code">isRootManagementAppInstalled()</code> để xem nội dung của nó.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80edbeafcc84a31036ef"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aa2ce6e05-835a-447d-a034-e0706d2fddff%3Aimage.png?table=block&amp;id=4090aff0-a13e-80ed-beaf-cc84a31036ef&amp;t=4090aff0-a13e-80ed-beaf-cc84a31036ef" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e800d962bd72e516856a7">Điều này cho thấy class <code class="notion-inline-code">AppPackageNames</code> và method <code class="notion-inline-code">isRootManagementAppInstalled()</code>. Method liệt kê tên package của các ứng dụng đã cài đặt thông qua method <code class="notion-inline-code">getInstalledPackages()</code>, rồi kiểm tra mảng <code class="notion-inline-code">strArr</code> xem có tồn tại &quot;<code class="notion-inline-code">com.noshufou.android.su</code>&quot;, &quot;<code class="notion-inline-code">eu.chainfire.supersu</code>&quot;, &quot;<code class="notion-inline-code">com.topjohnwu.magisk</code>&quot;, và &quot;<code class="notion-inline-code">com.hackthebox.rootmanagerapp</code>&quot; hay không. Đây là tên package của một số ứng dụng quản lý root. Sau đó, ta có thể dùng APKTool để xóa chúng khỏi mảng và xem liệu bypass có thành công hay không.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e8004a1a9e67f35123edc"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A7b663b43-a85e-43b9-8599-8676deb50e7e%3Aimage.png?table=block&amp;id=4090aff0-a13e-8004-a1a9-e67f35123edc&amp;t=4090aff0-a13e-8004-a1a9-e67f35123edc" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e8018ba02d0d87d04b2fe"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A8bc797e3-5ff4-4021-b739-b4725dd72bb3%3Aimage.png?table=block&amp;id=4090aff0-a13e-8018-ba02-d0d87d04b2fe&amp;t=4090aff0-a13e-8018-ba02-d0d87d04b2fe" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e8037bccafe1100c3e0a6">Đến đây, ta sẵn sàng compile lại, sign ứng dụng và kiểm tra.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80b2b763cc2e79b8df5a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:353.991455078125px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A93bdbfd1-dd69-40a3-9391-31ded828e9b9%3Aimage.png?table=block&amp;id=4090aff0-a13e-80b2-b763-cc2e79b8df5a&amp;t=4090aff0-a13e-80b2-b763-cc2e79b8df5a" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e80f28808f5c3c486fdb8">Dòng Rooted device detected vẫn còn nguyên nên ta cần kiểm tra nốt hàm cuối cùng trong method <code class="notion-inline-code">onCreate()</code> </div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4090aff0a13e8048bee5f8016202baaf" data-id="4090aff0a13e8048bee5f8016202baaf"><span><div id="4090aff0a13e8048bee5f8016202baaf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4090aff0a13e8048bee5f8016202baaf" title="Within Native Code"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Within Native Code</span></span></h3><div class="notion-text notion-block-4090aff0a13e80aa855cd0af4efbb22a">Triển khai root detection trong code native làm tăng đáng kể độ khó của việc bypass, vì thư viện native khó dịch ngược hơn code Java. Ví dụ sau đây là một ứng dụng thực hiện kiểm tra root trong code native. Ta sẽ bắt đầu bằng việc phân tích source bằng JADX:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80189867dda94b989e42"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A981d0742-27ef-47eb-98fe-ee2c476e72f0%3Aimage.png?table=block&amp;id=4090aff0-a13e-8018-9867-dda94b989e42&amp;t=4090aff0-a13e-8018-9867-dda94b989e42" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e8037afdbf41b52cb5663">Đọc nội dung method <code class="notion-inline-code">onCreate()</code> cho thấy method <code class="notion-inline-code">f1474h()</code>. Phân tích sâu hơn class <code class="notion-inline-code">MainActivity</code> xác nhận rằng đây là một native method nằm trong thư viện myapp.</div><div class="notion-text notion-block-4090aff0a13e80f9a6d8e90050067807">Đọc thư viện này với Ghidra để hiểu logic hoạt động. File lib này nằm tại: <code class="notion-inline-code">.\myapp\lib\x86_64\</code> </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e802db633fb5835930458"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A59c5ece3-3050-47f1-8f3f-a8f2f54309e8%3Aimage.png?table=block&amp;id=4090aff0-a13e-802d-b633-fb5835930458&amp;t=4090aff0-a13e-802d-b633-fb5835930458" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e806a93b3f06eb0f71a65">Nó sẽ kiểm tra sự tồn tại của các binary sau trên AVD</div><div class="notion-text notion-block-4090aff0a13e8003a190f7901f0f52cb"> Vì hàm này chỉ đảm nhiệm duy nhất root detection, ta có thể vượt qua nó bằng cách xóa dòng gọi <code class="notion-inline-code">f1474h()</code> khỏi method <code class="notion-inline-code">onCreate()</code> trong code Smali.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80728e9beb22cedf8fe8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af3df1bb8-f05b-4bd8-9ab1-bfaa98f5f5dd%3Aimage.png?table=block&amp;id=4090aff0-a13e-8072-8e9b-eb22cedf8fe8&amp;t=4090aff0-a13e-8072-8e9b-eb22cedf8fe8" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4090aff0a13e803b8417eec7120e2dd0">Sau đó build - sign và test lại xem</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80448419eff622956fac"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:432.9829406738281px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A3ba14120-599e-449a-904f-29e047b8b931%3Aimage.png?table=block&amp;id=4090aff0-a13e-8044-8419-eff622956fac&amp;t=4090aff0-a13e-8044-8419-eff622956fac" alt="3 party library" loading="lazy" decoding="async"/><figcaption class="notion-asset-caption">3 party library</figcaption></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e803a86b3c50d3224a3ee"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:542.9545288085938px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af21d6ddb-a60e-4a60-9850-fa91eed1f8f9%3Aimage.png?table=block&amp;id=4090aff0-a13e-803a-86b3-c50d3224a3ee&amp;t=4090aff0-a13e-803a-86b3-c50d3224a3ee" alt="Build.TAGS (đoạn này compile lại trông khác với code ban đầu nhưng nếu bạn đọc kĩ logic thì nó đã hoạt động đúng như mong đợi rồi)" loading="lazy" decoding="async"/><figcaption class="notion-asset-caption">Build.TAGS (đoạn này compile lại trông khác với code ban đầu nhưng nếu bạn đọc kĩ logic thì nó đã hoạt động đúng như mong đợi rồi)</figcaption></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e805082f9d7de484083c4"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A744508b9-8eee-44e6-9976-3da77b054465%3Aimage.png?table=block&amp;id=4090aff0-a13e-8050-82f9-d7de484083c4&amp;t=4090aff0-a13e-8050-82f9-d7de484083c4" alt="Root Management Apps (BuildConfig.FLAVOR chính là chuỗi rỗng “” )" loading="lazy" decoding="async"/><figcaption class="notion-asset-caption">Root Management Apps (<code class="notion-inline-code">BuildConfig.FLAVOR</code> chính là chuỗi rỗng <code class="notion-inline-code">“”</code> )</figcaption></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e80ee9959d6699d1fe38a"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:528.9772338867188px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A412e4333-adbd-4cbc-ac72-f9bf31325b5f%3Aimage.png?table=block&amp;id=4090aff0-a13e-80ee-9959-d6699d1fe38a&amp;t=4090aff0-a13e-80ee-9959-d6699d1fe38a" alt="Native Code. (Ta đã xóa calling đến hàm đó rồi, bây giờ chỉ còn logic gán biến this.tvRessults thôi)" loading="lazy" decoding="async"/><figcaption class="notion-asset-caption">Native Code. (Ta đã xóa calling đến hàm đó rồi, bây giờ chỉ còn logic gán biến <code class="notion-inline-code">this.tvRessults</code> thôi)</figcaption></div></figure><div class="notion-row notion-block-4090aff0a13e807f8dfbe805bd034018"><div class="notion-column notion-block-4090aff0a13e806ea7bde3d4171ae05f" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e8072927adc6a2b62f43c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:352.9829406738281px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aa359afeb-7de3-4fe9-8302-be2ff4f50b24%3Aimage.png?table=block&amp;id=4090aff0-a13e-8072-927a-dc6a2b62f43c&amp;t=4090aff0-a13e-8072-927a-dc6a2b62f43c" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4090aff0a13e80588a83eab89b5120be" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4090aff0a13e804eb725de836db53904">Như vậy là ta đã bypass tất cả các Root Detection trên ứng dụng này. Và thông báo mà ta mong đợi đã hiện ra</div></div><div class="notion-spacer"></div></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Analyzing Native Libraries]]></title>
            <link>https://blog.zero-trust.site/article/analyze-native-libraries</link>
            <guid>https://blog.zero-trust.site/article/analyze-native-libraries</guid>
            <pubDate>Wed, 28 Oct 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden  "><main class="notion light-mode notion-page notion-block-4030aff0a13e80ff99b4d4bfb9d20da9"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4070aff0a13e806da5ade98098718b7f" data-id="4070aff0a13e806da5ade98098718b7f"><span><div id="4070aff0a13e806da5ade98098718b7f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4070aff0a13e806da5ade98098718b7f" title="Reversing Shared Objects"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Reversing Shared Objects</b></span></span></h2><hr class="notion-hr notion-block-4070aff0a13e808b9913fe4aa0d54c03"/><div class="notion-text notion-block-4070aff0a13e805ab4e4f1aa33fd559f">Các ứng dụng Android đôi khi bao gồm native C++ code, thường được tích hợp thông qua <b>Native Development Kit</b> (NDK). Developers có thể dùng native code để cải thiện hiệu năng, giảm độ trễ, hoặc thêm một lớp phức tạp khiến reverse engineering khó khăn hơn. Khi ứng dụng được biên dịch, mọi native code được đóng gói vào các shared object (<code class="notion-inline-code">.so</code>) file bên trong APK. Phân tích <code class="notion-inline-code">.so</code> files là một phần quan trọng của quá trình reverse engineering nói chung và đóng vai trò then chốt trong phân tích app nâng cao và nghiên cứu malware.</div><div class="notion-text notion-block-4070aff0a13e80798549fc842816739d">Trong khi JADX thường được dùng để phân tích Java code của ứng dụng, các công cụ như <b>Ghidra</b>, <b>IDA Pro</b> và <b>RADARE2</b> được ưa chuộng hơn để phân tích shared objects. Trong ví dụ dưới, ta sẽ dùng <b>Ghidra</b> để phân tích native code.</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4070aff0a13e8020b454f1cc02fa5345" data-id="4070aff0a13e8020b454f1cc02fa5345"><span><div id="4070aff0a13e8020b454f1cc02fa5345" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4070aff0a13e8020b454f1cc02fa5345" title="Reading Strings Directly from SO Files"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Strings Directly from SO Files</span></span></h3><div class="notion-text notion-block-4070aff0a13e8044b858f177fc34013f">Ví dụ sau là một weather forecast app dùng một private API key để lấy dữ liệu từ xa và hiển thị locally. </div><div class="notion-row notion-block-4070aff0a13e80238bdfd6c796f5b9b7"><div class="notion-column notion-block-4070aff0a13e8004b0f8fb6c75bdd503" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80c2a671ef171014a5c8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:352.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A010ed3f2-eea2-4825-bef1-b5ada9a86bad%3Aimage.png?table=block&amp;id=4070aff0-a13e-80c2-a671-ef171014a5c8&amp;t=4070aff0-a13e-80c2-a671-ef171014a5c8" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4070aff0a13e809fb2dccf5b96cd1542" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4070aff0a13e80b991e3e34e72741477">Package name: <code class="notion-inline-code">com.hackthebox.myapp</code></div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4070aff0a13e802985afc09d11175bfc">Code decompiled trong JADX cho thấy như sau:</div><div class="notion-text notion-block-4070aff0a13e808ba827c00cd3e83220">Đọc Java code của app, ta hiểu rằng shared library tên <code class="notion-inline-code">myapp</code> được sử dụng, và native method <code class="notion-inline-code">getAPIKey()</code> được khởi tạo. Vài dòng phía dưới, ta thấy có một HTTP request tới URL <code class="notion-inline-code">http://api.weather.org/data/2.5/weather</code> dùng giá trị lấy từ native method <code class="notion-inline-code">getAPIKey()</code>:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80aeb2fefc00ddec4721"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A39961866-f9e4-435b-86a5-b59e4eb7029d%3Aimage.png?table=block&amp;id=4070aff0-a13e-80ae-b2fe-fc00ddec4721&amp;t=4070aff0-a13e-80ae-b2fe-fc00ddec4721" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e808f8292d351597dc83b">Kiểm tra xem có lấy được API key từ shared library không. Đầu tiên, ta extract các file từ APK bằng APKTool sau đó tìm file shared library</div><div class="notion-text notion-block-4070aff0a13e8013b29dcc936982f2e5">Tại đây, ta có thể dùng strings để đọc các chuỗi trong shared library được rồi. Nhưng ta sẽ không làm như vậy. Ta sẽ dùng Ghidra.</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4070aff0a13e8069886af81d786b851e" data-id="4070aff0a13e8069886af81d786b851e"><span><div id="4070aff0a13e8069886af81d786b851e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4070aff0a13e8069886af81d786b851e" title="Reading Hardcoded Strings With Ghidra"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Hardcoded Strings With Ghidra</span></span></h3><div class="notion-text notion-block-4070aff0a13e80069272ea1867c282f3">Bạn có thể search google để biết cách cài Ghidra trên hệ điều hành tương ứng.</div><div class="notion-text notion-block-4070aff0a13e802db0a5d721bc9a3a73">Khi Ghidra khởi động xong, click <code class="notion-inline-code">File</code> -&gt; <code class="notion-inline-code">New Project</code> -&gt; <code class="notion-inline-code">Non-Shared Project</code> -&gt; <code class="notion-inline-code">Next</code>. Sau đó đặt Project Name và click <code class="notion-inline-code">Next</code> lần nữa. Khi project đã được tạo, click <code class="notion-inline-code">File</code> -&gt; <code class="notion-inline-code">Import File</code>, điều hướng tới file <code class="notion-inline-code">libmyapp.so</code>, click <code class="notion-inline-code">Select File To Import</code> và click <code class="notion-inline-code">OK</code> cho các popup tiếp theo. Tiếp theo, double-click vào file đã import, click <code class="notion-inline-code">Yes</code> rồi <code class="notion-inline-code">Analyze</code> ở popup kế tiếp. Ảnh dưới đây là layout của Ghidra sau khi load xong shared library:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e802b9357c36932f76e1c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A4f993331-82fb-4475-8339-063e3712ac92%3Aimage.png?table=block&amp;id=4070aff0-a13e-802b-9357-c36932f76e1c&amp;t=4070aff0-a13e-802b-9357-c36932f76e1c" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e80959b6adb5c8830df9e">Dưới đây là tổng quan nhanh các pane cơ bản sẽ dùng khi reverse shared libraries trong Ghidra:</div><table class="notion-simple-table notion-block-4070aff0a13e806296d5ef76fe5716ac"><tbody><tr class="notion-simple-table-row notion-block-4070aff0a13e808bb05fdcee073a6b24"><td class="" style="width:114.65625px"><div class="notion-simple-table-cell">Pane</div></td><td class="" style="width:587.65625px"><div class="notion-simple-table-cell">Mô tả</div></td></tr><tr class="notion-simple-table-row notion-block-4070aff0a13e80b1ae89fdd294ef3978"><td class="" style="width:114.65625px"><div class="notion-simple-table-cell">Symbol Tree</div></td><td class="" style="width:587.65625px"><div class="notion-simple-table-cell">Nằm bên trái cửa sổ, hiển thị các symbols trong binary đang phân tích theo cấu trúc phân cấp. Symbols đại diện cho các thực thể của chương trình: <code class="notion-inline-code">functions</code>, <code class="notion-inline-code">variables</code>, <code class="notion-inline-code">labels</code>, v.v. Giúp điều hướng nhanh và xác định các phần đáng chú ý của binary.</div></td></tr><tr class="notion-simple-table-row notion-block-4070aff0a13e80b58a4cf7ba1bfd78a8"><td class="" style="width:114.65625px"><div class="notion-simple-table-cell">Listing</div></td><td class="" style="width:587.65625px"><div class="notion-simple-table-cell">Hiển thị disassembled code của binary bằng cách biểu diễn các low-level machine instruction dưới dạng assembly dễ đọc hơn. Bên cạnh code còn có addresses, byte values của instructions và các comment/annotation khác. Pane này cung cấp cái nhìn chi tiết (granular) hoạt động của chương trình ở cấp độ instruction.</div></td></tr><tr class="notion-simple-table-row notion-block-4070aff0a13e80f68ec2c3ed2fbd05e7"><td class="" style="width:114.65625px"><div class="notion-simple-table-cell">Decompiler</div></td><td class="" style="width:587.65625px"><div class="notion-simple-table-cell">Một trong những công cụ mạnh nhất của Ghidra, dịch assembly code từ pane Listing thành biểu diễn cấp cao hơn, giúp người dùng đọc và hiểu dễ hơn.</div></td></tr></tbody></table><div class="notion-text notion-block-4070aff0a13e80129988e6f006b31882">Kiểm tra các functions được dùng trong file này dưới <b>Symbol Tree</b> bên trái cửa sổ cho thấy function <code class="notion-inline-code">Java_com_hackthebox_myapp_MainActivity_getAPIKey</code>:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e8047ad0eda89b95387f6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ac16753f2-fe65-4e0c-b8b7-9fdb9d629e4a%3Aimage.png?table=block&amp;id=4070aff0-a13e-8047-ad0e-da89b95387f6&amp;t=4070aff0-a13e-8047-ad0e-da89b95387f6" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e805ba4b3cd894637f554">Đọc pseudocode trên, ta có thể tạo 1 script decode các kí tự trên (lưu ý là để convert từ hex ở Ghidra sang string ⇒ Bạn cần convert nó theo dạng Little Endian (chiều từ phải sang trái)) </div><div class="notion-text notion-block-4070aff0a13e80f4b55bf1ec67daefca">Chạy script</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80c29232d298cad308bd"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:553.96875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A861daf3a-8f14-4155-8356-61525f878b2e%3Aimage.png?table=block&amp;id=4070aff0-a13e-80c2-9232-d298cad308bd&amp;t=4070aff0-a13e-80c2-9232-d298cad308bd" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e80d28cccc4a33001fdb1">Hoặc cũng có thể dùng Cyber Chef như sau</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80c3aafeee8424d2a50b"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A5be112ce-5f6a-4811-ac4d-476b6dfade3a%3Aimage.png?table=block&amp;id=4070aff0-a13e-80c3-aafe-ee8424d2a50b&amp;t=4070aff0-a13e-80c3-aafe-ee8424d2a50b" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e804a83fdce08625c586a">Sau đó ta thay thế các kí tự (từ các hàm strncpy) vào trong chuỗi là ta sẽ nhận được chuỗi <code class="notion-inline-code">API_Key</code></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4070aff0a13e804b9bdef19b42f98fa2" data-id="4070aff0a13e804b9bdef19b42f98fa2"><span><div id="4070aff0a13e804b9bdef19b42f98fa2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4070aff0a13e804b9bdef19b42f98fa2" title="Reading Code With Ghidra"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Reading Code With Ghidra</b></span></span></h3><div class="notion-text notion-block-4070aff0a13e807491e9daa14d6c0514">Trong ví dụ trước, ta đã thấy cách lấy hardcoded strings từ shared library bằng Ghidra. Trong ví dụ sau, ta sẽ cố đọc và hiểu code để lấy ra API key. Nhìn pane Symbol Tree dưới Functions, ta có thể thấy các functions <code class="notion-inline-code">Java_com_hackthebox_myapp_MainActivity_getAPIKey</code> và <code class="notion-inline-code">deobfuscate</code>:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80c9b385d9efd2627980"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ac7011ea1-cee3-4c55-b3b5-aae61b691f41%3Aimage.png?table=block&amp;id=4070aff0-a13e-80c9-b385-d9efd2627980&amp;t=4070aff0-a13e-80c9-b385-d9efd2627980" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e802b9167d9f85f778d2a">Snippet trên là biểu diễn cấp cao của assembly code của shared object. Như có thể thấy, nhiều <b>local variables</b> và memory allocations được thiết lập cho việc thực thi. 
Hãy phân tích chúng để hiểu rõ hơn điều gì đang xảy ra: <code class="notion-inline-code">local_18</code> được cấp phát động <code class="notion-inline-code">0x30</code> (48) bytes bộ nhớ, được điền một số giá trị hex, nhiều khả năng là API key đã obfuscate. 
Function <code class="notion-inline-code">deobfuscate();</code> được gọi với địa chỉ của <code class="notion-inline-code">local_40</code> làm tham số. Mặc dù không có kết nối trực tiếp nào giữa <code class="notion-inline-code">local_18</code> và <code class="notion-inline-code">deobfuscate()</code>, ta vẫn có thể giả định rằng giá trị được truyền về sau cùng chính là các giá trị hex chứa trong biến <code class="notion-inline-code">local_18</code>. Do thiếu sót trong quá trình reverse, có thể có một function đổ dữ liệu từ <code class="notion-inline-code">local_18</code> vào <code class="notion-inline-code">local_40</code> trước khi <code class="notion-inline-code">deobfuscate()</code> được gọi, nhưng không được hiển thị. 
Hãy double-click vào <code class="notion-inline-code">deobfuscate()</code> để xem kỹ hơn chức năng của nó:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80219018c3a7eadad6d2"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A347a835d-de9e-4e71-aa8f-e7aba678bc2d%3Aimage.png?table=block&amp;id=4070aff0-a13e-8021-9018-c3a7eadad6d2&amp;t=4070aff0-a13e-8021-9018-c3a7eadad6d2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e8071abd1df17b2c016a7">Bên trong function <code class="notion-inline-code">deobfuscate()</code>, có thể thấy biến <code class="notion-inline-code">in_RSI</code> được kiểm tra. Ta có thể giả định đây là API key đã obfuscate, vì trong nhiều calling conventions, register <code class="notion-inline-code">RSI</code> được dùng để truyền tham số thứ hai của function. Nếu least significant bit (bit cuối cùng) của nó là 0</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80ad80b2c8a8bb965286"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:524.953125px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A5a633c10-235e-499a-a029-e67136d267b8%3Aimage.png?table=block&amp;id=4070aff0-a13e-80ad-80b2-c8a8bb965286&amp;t=4070aff0-a13e-80ad-80b2-c8a8bb965286" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e805bbe7ede4ae797bc3e">Thì chuỗi đó <b>ngắn</b> và được lưu <b>inline</b>; ngược lại, chuỗi <b>dài</b> và được lưu trong bộ nhớ cấp phát động. Function sau đó duyệt từng ký tự của chuỗi và lưu <b>bitwise negation</b> của nó vào <code class="notion-inline-code">param_1</code>. Nói đơn giản: nó lật bit của từng ký tự. 
Đây là một phương pháp obfuscation rất đơn giản, không nên dùng trong production. Giá trị <code class="notion-inline-code">param_1</code> sau đó được trả về cho function <code class="notion-inline-code">Java_com_hackthebox_myapp_MainActivity_getAPIKey()</code>.</div><div class="notion-text notion-block-4070aff0a13e804dbcf8f948ef29007a">Bây giờ đã hiểu chức năng của code trong shared library, ta có thể thử lấy lại API key ban đầu. Để tạo lại chuỗi đã obfuscate, ta cần lấy các giá trị hex được lưu trong biến <code class="notion-inline-code">local_18</code> và sắp xếp chúng theo đúng thứ tự. Trước khi bắt đầu, cần nhớ rằng kiến trúc <code class="notion-inline-code">x86-64</code> dùng định dạng <code class="notion-inline-code">little-endian</code>. Điều này có nghĩa, ví dụ, giá trị <code class="notion-inline-code">0xaf959287</code> sẽ trở thành <code class="notion-inline-code">0x879295af</code>. Đọc nội dung function <code class="notion-inline-code">Java_com_hackthebox_myapp_MainActivity_getAPIKey()</code> cho thấy các giá trị hex sau:</div><div class="notion-text notion-block-4070aff0a13e806fb359ee4b459cbbc4">Ta có thể dùng CyberChef với các operator sau để deobfuscate API_KEY</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80d795f2fac08720e47e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af3997a3e-95a7-437c-a93f-0e4ce7345eb2%3Aimage.png?table=block&amp;id=4070aff0-a13e-80d7-95f2-fac08720e47e&amp;t=4070aff0-a13e-80d7-95f2-fac08720e47e" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e80039a54ef19fd3bf9c3">Như có thể thấy, API key <code class="notion-inline-code">L6gQdvcj2N8yZa5RkthB0UMWFozp4XsS</code> đã hiện ra. May mắn cho chúng ta, chỉ mất vài bước để lấy thành công. 
Tuy nhiên, các phương pháp obfuscation phức tạp hơn có thể được dùng để làm cho việc đọc source code khó khăn hơn nữa, ta sẽ thấy các ví dụ như vậy ở phần sau của module.</div><hr class="notion-hr notion-block-4070aff0a13e803d9367fb40bb41491a"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4070aff0a13e804faf17c0216a7afcb7" data-id="4070aff0a13e804faf17c0216a7afcb7"><span><div id="4070aff0a13e804faf17c0216a7afcb7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4070aff0a13e804faf17c0216a7afcb7" title="Reversing DLL Files"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Reversing DLL Files</b></span></span></h2><div class="notion-text notion-block-4070aff0a13e80e09f42c685484b6a17">Khác với các ứng dụng build bằng <b>Android Studio</b> thường dùng Java hoặc Kotlin, <b>Xamarin</b> cho phép developers tạo ứng dụng bằng <b>.NET</b> framework và <b>C#</b>. 
Trong các dự án Xamarin, code C# đầu tiên được biên dịch thành <b>Intermediate Language</b> (<code class="notion-inline-code">IL</code>) bởi .NET compiler, sau đó được dịch sang code riêng cho từng nền tảng. Giống như native C++ code được đóng gói vào shared libraries (<code class="notion-inline-code">.so</code>) bên trong file APK, các ứng dụng Xamarin đóng gói code đã biên dịch vào Dynamically Linked Libraries (<code class="notion-inline-code">.dll</code>), được lưu gộp lại trong một file tên <code class="notion-inline-code">assemblies.blob</code>.</div><div class="notion-text notion-block-4070aff0a13e80479700d5c61b2bd592">Một số dev cho rằng việc đặt code vào DLL tạo ra một mức obfuscation nào đó. Tuy nhiên, giống như các shared objects đã phân tích trước đó, những libraries này chứa compiled code, khiến chúng không đọc được bằng các công cụ như JADX hay APKTool.  Ta sẽ khám phá cách extract và reverse một file DLL để kiểm tra source code của nó.</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4070aff0a13e800cb81ffa19e88d0605" data-id="4070aff0a13e800cb81ffa19e88d0605"><span><div id="4070aff0a13e800cb81ffa19e88d0605" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4070aff0a13e800cb81ffa19e88d0605" title="Locating Assemblies Inside APKs"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Locating Assemblies Inside APKs</span></span></h3><div class="notion-text notion-block-4070aff0a13e80afb826d2b1900d6de0">Ứng dụng dưới đây có một tính năng xác nhận password bạn đã đặt có đúng hay không:</div><div class="notion-row notion-block-4070aff0a13e80789d2de5e5d7bdf317"><div class="notion-column notion-block-4070aff0a13e80e39f6ac16cd2b195d2" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e802b9011d09e45759d69"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:356.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ad17be503-5124-47d1-8a90-43ba726a1254%3Aimage.png?table=block&amp;id=4070aff0-a13e-802b-9011-d09e45759d69&amp;t=4070aff0-a13e-802b-9011-d09e45759d69" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4070aff0a13e8083b753d89367d2a4d2" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4070aff0a13e8016a3a4df838ec65e3f">Package name: <code class="notion-inline-code">com.hackthebox.myapp</code></div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4070aff0a13e80b7b3c1c9c13dae8586">Hãy dùng APKTool để decode và extract các file từ APK:</div><div class="notion-text notion-block-4070aff0a13e807fae40fcfc6d1c9a67">Liệt kê nội dung thư mục <code class="notion-inline-code">myapp/smali</code> cho thấy như sau:</div><div class="notion-text notion-block-4070aff0a13e80a88843f54eb1039d7d">Thư mục xamarin cho thấy ứng dụng được tạo bằng <b>Xamarin</b>. Ta biết các ứng dụng Xamarin lưu code của chúng trong <b>dynamically linked libraries</b> (file <code class="notion-inline-code">DLL</code>). Hãy liệt kê thư mục đã extract <code class="notion-inline-code">myapp/unknown/assemblies/</code>:</div><div class="notion-text notion-block-4070aff0a13e803e91b0df0209f77e40">Ta sẽ dùng <a class="notion-link" href="https://github.com/jakev/pyxamstore" target="_blank" rel="noopener noreferrer">pyxamstore</a> để unpack ra các file <code class="notion-inline-code">.dll</code> từ file <code class="notion-inline-code">assemblies.blob</code></div><div class="notion-text notion-block-4070aff0a13e8047adf8e54bb1363d19">Thư mục này chứa các .NET assemblies (file DLL) được ứng dụng sử dụng. Vì tên app là myapp, ta có thể thử đọc nội dung file <code class="notion-inline-code">MyApp.dll</code> , check file type:</div><div class="notion-text notion-block-4070aff0a13e806b81f6db17440eb8f0">Ta sẽ cần sử dụng 1 công cụ chuyên để đọc file executable <b>.NET assembly</b> , đó chính là <b><a class="notion-link" href="https://github.com/icsharpcode/ILSpy" target="_blank" rel="noopener noreferrer">ILSPY</a></b> hoặc <b><a class="notion-link" href="https://www.jetbrains.com/decompiler/" target="_blank" rel="noopener noreferrer">DotPeak</a></b>. Ở đây, tôi sẽ dùng ILSPY (Lưu ý là bạn cần cài cả <a class="notion-link" href="https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-10.0.14-windows-x64-installer?cid=getdotnetcore" target="_blank" rel="noopener noreferrer">môi trường .NET</a> để có thể sử dụng 2 tool trên). Sau khi mở file trên Tool, giao diện trông sẽ như sau:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e800486e2d50eed7571b3"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A89f63351-748e-4a59-a018-debb4f3f8e0f%3Aimage.png?table=block&amp;id=4070aff0-a13e-8004-86e2-d50eed7571b3&amp;t=4070aff0-a13e-8004-86e2-d50eed7571b3" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e8016b9b9d32b0cb87978">Function này gọi <code class="notion-inline-code">InitializeComponent()</code>. Hãy click vào nó để xem source code:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e800e92e9ddbfae3c9540"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:596.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A8713992b-848e-4b04-bf24-9fda0e8c9c9c%3Aimage.png?table=block&amp;id=4070aff0-a13e-800e-92e9-ddbfae3c9540&amp;t=4070aff0-a13e-800e-92e9-ddbfae3c9540" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e8019a45ec7887df7d8db"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A4b8e468c-81a8-482a-b6fa-5458527f04fe%3Aimage.png?table=block&amp;id=4070aff0-a13e-8019-a45e-c7887df7d8db&amp;t=4070aff0-a13e-8019-a45e-c7887df7d8db" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e8089b51af3051137f3b9">Ở cuối function này, ta thấy dòng <code class="notion-inline-code">button.Clicked += mainPage.Master_Override_Passphrase;</code>  - đây là handler của nút Check. Hãy click vào cả function này:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80a5acd0e6bdfd4879d5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ab6dd3ad6-33a8-4f2c-873d-26a8e8c2163b%3Aimage.png?table=block&amp;id=4070aff0-a13e-80a5-acd0-e6bdfd4879d5&amp;t=4070aff0-a13e-80a5-acd0-e6bdfd4879d5" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e8017ae5bedf2d16fdeab">Như vậy bạn có thể thấy Password đi qua lớp AES encryption với key và iv hardcoded ngay trên source. Nên ta sẽ dùng <b>CyberChef</b> để decrypt</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e806894d6e6c6ce4fe414"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A230efaf1-e96d-480d-8533-4d2c9b1001c2%3Aimage.png?table=block&amp;id=4070aff0-a13e-8068-94d6-e6c6ce4fe414&amp;t=4070aff0-a13e-8068-94d6-e6c6ce4fe414" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e809ea5e6fd65305149fa">Như vậy là bạn đã giải mã ra mật khẩu nằm trong app Xamarin.</div><div class="notion-blank notion-block-4070aff0a13e802cbe8bdfa33182a156"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing Application’s Source Code]]></title>
            <link>https://blog.zero-trust.site/article/analyze-application-source-code</link>
            <guid>https://blog.zero-trust.site/article/analyze-application-source-code</guid>
            <pubDate>Sun, 25 Oct 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden notion-page-font-mono " style="font-family:iawriter-mono, Nitti, ui-monospace, SFMono-Regular, Menlo, Consolas, &#x27;Liberation Mono&#x27;, Courier, monospace"><main class="notion light-mode notion-page notion-block-4030aff0a13e80de9281de4cd7cf607e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4040aff0a13e80eab557e5e99ebfe83e" data-id="4040aff0a13e80eab557e5e99ebfe83e"><span><div id="4040aff0a13e80eab557e5e99ebfe83e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4040aff0a13e80eab557e5e99ebfe83e" title="Reading Hardcoded Strings"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Hardcoded Strings</span></span></h2><hr class="notion-hr notion-block-4040aff0a13e80158f04dd987414bb86"/><div class="notion-text notion-block-4040aff0a13e805790ecd752e037d222">Thông tin nhạy cảm có thể bị lưu một cách vô tình hoặc không đúng cách trong ứng dụng Android bao gồm nhiều loại dữ liệu đa dạng. Trong quá trình pentest, việc kiểm tra ứng dụng để tìm bất kỳ dấu hiệu nào cho thấy dữ liệu như vậy có thể đang được lưu hay truyền đi một cách không an toàn là điều hết sức quan trọng. Dưới đây là các ví dụ phổ biến về chuỗi nhạy cảm có thể được phát hiện trong một ứng dụng Android:</div><table class="notion-simple-table notion-block-4040aff0a13e8081ad9bd2cc1f3e6424"><tbody><tr class="notion-simple-table-row notion-block-4040aff0a13e801ba0e4c12a2cc398a4"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">Title</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Description</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80a487b3ee3d6d0aa6c8"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">API keys</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Thường dùng để xác thực các request của client app tới server. Nếu lưu không an toàn, API keys có thể bị đánh cắp và lạm dụng bởi kẻ xấu.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80ab8369ca89af85fbda"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">Database credentials</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Nếu ứng dụng tương tác với một database, nó có thể cần username và password. Những thông tin này tuyệt đối không được lưu dưới dạng plain text.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80d7a260e7322a2a917d"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">OAuth tokens</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Dùng cho giao tiếp có xác thực giữa app và các dịch vụ như Google, Facebook, Twitter, v.v. Một kẻ xấu có được các token này có thể impersonate app hoặc người dùng.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e8025b2a9ea6c9b772697"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">Cryptographic keys</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Dùng để mã hóa và giải mã dữ liệu nhạy cảm. Nếu key được lưu không an toàn, kẻ tấn công có thể giải mã được thông tin nhạy cảm.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80e1977cdc042367f4e3"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">Hardcoded passwords or passphrases</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Có thể được dùng để truy cập các phần bị giới hạn của ứng dụng hoặc kích hoạt các chức năng debug còn sót lại trong bản build production.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e8073b9a1d48c8d743c4d"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">Personally identifiable information (PII)</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Bao gồm dữ liệu như họ tên, địa chỉ email, số an sinh xã hội, và thông tin thẻ tín dụng. Loại dữ liệu này phải được xử lý với các biện pháp bảo mật nghiêm ngặt.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80d1a2f7ceaaa20f24d4"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">Sensitive URLs or IP addresses</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Có thể tiết lộ thông tin về các backend server hay dịch vụ mà ứng dụng tương tác, tiềm năng hỗ trợ cho các cuộc tấn công có nhắm mục tiêu.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e8077849df5bd2b16cf9b"><td class="" style="width:181.65625px"><div class="notion-simple-table-cell">Debugging information</div></td><td class="" style="width:503.65625px"><div class="notion-simple-table-cell">Có thể bao gồm thông báo lỗi chi tiết (verbose), stack traces, hay chi tiết triển khai nội bộ có thể giúp kẻ tấn công hiểu hoặc khai thác app.</div></td></tr></tbody></table><div class="notion-text notion-block-4040aff0a13e803ea0fdfbbdf56a41e4">Khi thực hiện pentest, ta nên luôn tìm kiếm các mẩu thông tin nhạy cảm này.</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4040aff0a13e8045bae8f3c20a1989e3" data-id="4040aff0a13e8045bae8f3c20a1989e3"><span><div id="4040aff0a13e8045bae8f3c20a1989e3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4040aff0a13e8045bae8f3c20a1989e3" title="Analyzing with JADX and APKTool"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Analyzing with JADX and APKTool</span></span></h3><div class="notion-text notion-block-4040aff0a13e80f18948e8f306e52868">JADX (Java Decompiler for Android) là một công cụ open-source phổ biến dùng để decompile ứng dụng Android. Nó nhận APK và chuyển ngược chúng thành mã nguồn Java đọc được. JADX có một số tính năng chính hỗ trợ static analysis hiệu quả, bao gồm:</div><table class="notion-simple-table notion-block-4040aff0a13e808395a9ccd825e29053"><tbody><tr class="notion-simple-table-row notion-block-4040aff0a13e806daa9fcd7213449dd7"><td class="" style="width:155.65625px"><div class="notion-simple-table-cell">Feature</div></td><td class="" style="width:537.65625px"><div class="notion-simple-table-cell">Description</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e8011a0a2f4a799d22e00"><td class="" style="width:155.65625px"><div class="notion-simple-table-cell">File Formats</div></td><td class="" style="width:537.65625px"><div class="notion-simple-table-cell">Decompile Dalvik bytecode thành các java classes từ các file APK, dex, aar, aab, và zip.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e809d9f8ef277f4e2b6e2"><td class="" style="width:155.65625px"><div class="notion-simple-table-cell">GUI and CLI</div></td><td class="" style="width:537.65625px"><div class="notion-simple-table-cell">Cung cấp cả bản GUI (jadx-gui) cho trải nghiệm trực quan hơn và bản CLI (jadx) cho việc scripting và automation.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80edaa66c3770c1a61ad"><td class="" style="width:155.65625px"><div class="notion-simple-table-cell">Decoding Files</div></td><td class="" style="width:537.65625px"><div class="notion-simple-table-cell">Decode AndroidManifest.xml và các tài nguyên khác từ resources.arsc</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80da8fa5cf7c8a856377"><td class="" style="width:155.65625px"><div class="notion-simple-table-cell">Deobfuscation</div></td><td class="" style="width:537.65625px"><div class="notion-simple-table-cell">Đổi tên các phương thức và biến đã bị obfuscate thành các tên có ý nghĩa để mã dễ đọc hơn.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e8043ab06c88b02d1707e"><td class="" style="width:155.65625px"><div class="notion-simple-table-cell">Smali</div></td><td class="" style="width:537.65625px"><div class="notion-simple-table-cell">Hỗ trợ biểu diễn Smali và debugging qua ADB.</div></td></tr><tr class="notion-simple-table-row notion-block-4040aff0a13e80cab52ce3a31791c5c7"><td class="" style="width:155.65625px"><div class="notion-simple-table-cell">Other Functionalities</div></td><td class="" style="width:537.65625px"><div class="notion-simple-table-cell">full-text search, tô sáng cú pháp, jump to declaration, Annotation.</div></td></tr></tbody></table><div class="notion-callout notion-gray_background_co notion-block-4040aff0a13e809f9617ca44235cb366"><div class="notion-page-icon-inline notion-page-icon-span"><img class="notion-page-icon" src="https://www.notion.so/icons/info-alternate_yellow.svg?mode=light" alt="page icon" loading="lazy" decoding="async"/></div><div class="notion-callout-text"><div class="notion-text notion-block-4040aff0a13e8061a6c0d0819615f644">JADX không cho phép chỉnh sửa code và build lại (recompilation).</div></div></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4040aff0a13e8000972cfaf6c0d79e73" data-id="4040aff0a13e8000972cfaf6c0d79e73"><span><div id="4040aff0a13e8000972cfaf6c0d79e73" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4040aff0a13e8000972cfaf6c0d79e73" title="Reading Strings from Source Code"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Strings from Source Code</span></span></h4><div class="notion-text notion-block-4040aff0a13e80c786e3eee4c328ecfe">Các thư mục <code class="notion-inline-code">res</code>, <code class="notion-inline-code">smali</code> và <code class="notion-inline-code">libs</code> thường chứa các file có chuỗi hardcoded, khiến chúng có thể trở thành điểm xuất phát cho việc kiểm thử. Các thư mục phổ biến này có thể được phân tích bằng công cụ như <b>JADX</b> và <b>APKTool</b>.</div><div class="notion-text notion-block-4040aff0a13e805a9c35ef6429a0b7bd">Trước hết, đáp file vào JADX, và ta sẽ nhận được giao diện sau. Nhấn vào biểu tượng ngôi nhà trên tool bar, bạn sẽ được dẫn đến MainActivity như dưới đây:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4040aff0a13e80bfaf12d294a0df575f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ac869a34b-d9c8-4c60-aaaf-f62b04815377%3Aimage.png?table=block&amp;id=4040aff0-a13e-80bf-af12-d294a0df575f&amp;t=4040aff0-a13e-80bf-af12-d294a0df575f" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4040aff0a13e80f9a58bf9cc80b87298">Trong hình, ta thấy dòng 45 chứa 1 Debug password:
<code class="notion-inline-code">Log.i(&quot;LoginApp&quot;, &quot;Login Successful: &quot; + responseExecute.body().string() + &quot;. Debug password: tempDebuggingPassword&quot;);</code></div><div class="notion-text notion-block-4040aff0a13e8023bbc8d908bda192c1">Ngoài ra, ta cũng có thể tìm nó bằng APKTool</div><div class="notion-text notion-block-4040aff0a13e80dd9e8fedfd2777555e">Tương tự, ta có thể áp dụng với <code class="notion-inline-code">api_key</code></div><div class="notion-text notion-block-4040aff0a13e80c49f63fc98e55744b8">Ngoài các thông tin, ta cũng thể khám phá thêm các thông tin khác.</div><div class="notion-text notion-block-4040aff0a13e800e92a3d1ec1775cb14">Ví dụ, ta thấy url được lấy từ <code class="notion-inline-code">R.string.login_url</code> thì bạn có thể tìm kiếm <code class="notion-inline-code">login_url</code> nằm trong <code class="notion-inline-code">./evil_bank/res/values/String.xml</code> hoặc thao tác như sau trong JADX</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4040aff0a13e805587c1fd5259486e15"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A0d62d7c4-e0e6-498d-a15b-6f4c090e2756%3Aimage.png?table=block&amp;id=4040aff0-a13e-8055-87c1-fd5259486e15&amp;t=4040aff0-a13e-8055-87c1-fd5259486e15" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4040aff0a13e80da9693de7dead487be" data-id="4040aff0a13e80da9693de7dead487be"><span><div id="4040aff0a13e80da9693de7dead487be" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4040aff0a13e80da9693de7dead487be" title="Reading Strings from network_security_config.xml"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Strings from network_security_config.xml</span></span></h4><div class="notion-text notion-block-4040aff0a13e8031a7fceb537b8a9dec">Chuyển sang kiểm tra thư mục <code class="notion-inline-code">xml</code>. File <code class="notion-inline-code">res/xml/network_security_config.xml</code> sẽ cho ta bức tranh tốt về các kết nối của app với các API endpoint tiềm năng. Do đó, file này sẽ tiết lộ ít nhất một Domain Name hoặc một IP.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4040aff0a13e80aeaa19e4596208654e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ab2c8ed1c-75b7-47b9-8035-6659faffc886%3Aimage.png?table=block&amp;id=4040aff0-a13e-80ae-aa19-e4596208654e&amp;t=4040aff0-a13e-80ae-aa19-e4596208654e" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4040aff0a13e809a851df35918e09d1b">Đọc nội dung file này cho thấy app không cho phép giao tiếp HTTP, ngoại trừ việc giao tiếp với URL <code class="notion-inline-code">192.168.1.8</code>. Có được một IP cùng chi tiết rằng một kết nối không mã hóa đang được sử dụng, attacking surface đang rộng hơn.</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4040aff0a13e80de924dd4b8db097dcd" data-id="4040aff0a13e80de924dd4b8db097dcd"><span><div id="4040aff0a13e80de924dd4b8db097dcd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4040aff0a13e80de924dd4b8db097dcd" title="Reading Strings from Shared Libraries"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Strings from Shared Libraries</span></span></h4><div class="notion-text notion-block-4040aff0a13e80e8b303f4a24d2e253d">Các ứng dụng lưu native C++ code của chúng trong thư mục <code class="notion-inline-code">./myapp/lib/x86_64/</code>. Trong ví dụ này, code nằm bên trong <code class="notion-inline-code">libmyapplication.so</code>, và mặc dù nội dung file này đã được biên dịch, các chuỗi hardcoded vẫn có thể được extract. Dùng <b>JADX</b> để đọc nội dung file này sẽ không thành công vì nó không hoạt động với native shared libraries. Ta có thể đọc bằng <code class="notion-inline-code">vim</code> hoặc <code class="notion-inline-code">strings</code> (không khuyến khích lắm) hãy mở lib bằng <b>IDA</b> để đọc clear hơn.</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4040aff0a13e80d0b197f52a3f9f3b7d" data-id="4040aff0a13e80d0b197f52a3f9f3b7d"><span><div id="4040aff0a13e80d0b197f52a3f9f3b7d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4040aff0a13e80d0b197f52a3f9f3b7d" title="Reading Strings from JS"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Strings from JS</span></span></h4><div class="notion-text notion-block-4040aff0a13e80b4989fea6f82a2fc71">Đọc các chuỗi hardcoded từ một ứng dụng Android dạng web-based có thể thực hiện bằng cả JADX và APKTool. Web-based apps lưu code của chúng bên trong các file <code class="notion-inline-code">.js</code> dưới thư mục <code class="notion-inline-code">assets</code>. Ví dụ:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4040aff0a13e8040b3b6f5b6db7015d3"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aaf7fdbb4-8bc7-419f-a242-ae9dae883b82%3Aimage.png?table=block&amp;id=4040aff0-a13e-8040-b3b6-f5b6db7015d3&amp;t=4040aff0-a13e-8040-b3b6-f5b6db7015d3" alt="notion image" loading="lazy" decoding="async"/></div></figure><hr class="notion-hr notion-block-4050aff0a13e80c69249d2338bc27e2c"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4040aff0a13e8008a0d1f614e6709e87" data-id="4040aff0a13e8008a0d1f614e6709e87"><span><div id="4040aff0a13e8008a0d1f614e6709e87" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4040aff0a13e8008a0d1f614e6709e87" title="Bad Cryptography Implementation"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Bad Cryptography Implementation</span></span></h2><div class="notion-text notion-block-4050aff0a13e80cb8b27d7444e04ad3a">Đảm bảo tính bảo mật và quyền riêng tư cho dữ liệu người dùng trong các ứng dụng Android hiện đại là điều tối quan trọng. Một khía cạnh then chốt của bảo mật là triển khai cryptography đúng cách. Triển khai cryptography sai có thể dẫn đến nhiều lỗ hổng, mở đường cho kẻ tấn công khai thác hệ thống và xâm phạm dữ liệu nhạy cảm. Trong các ứng dụng Android, điều này có thể biểu hiện theo nhiều cách, bao gồm việc sử dụng:</div><ul class="notion-list notion-list-disc notion-block-4050aff0a13e80df84ffebb0b01ab0f4"><li>Outdated cryptographic algorithms.</li></ul><ul class="notion-list notion-list-disc notion-block-4050aff0a13e8047ab34d8824082a04b"><li>Hardcoding keys.</li></ul><ul class="notion-list notion-list-disc notion-block-4050aff0a13e80a0ac46f7a1e77d19db"><li>Improper storage of keys. (Lưu trữ key không đúng cách.)</li></ul><ul class="notion-list notion-list-disc notion-block-4050aff0a13e8010bc42de8691c2f7fc"><li>Not utilizing secure random number generators.</li></ul><div class="notion-text notion-block-4050aff0a13e800d8349dc0da774698f">Developers nên dùng các thư viện cryptography, tránh hardcoded các cryptographic key, và lưu key một cách an toàn bằng các hardware-backed keystores có sẵn trong Android.</div><div class="notion-text notion-block-4050aff0a13e803bb0fac6105bc591cc">Trong ví dụ sau, ta sẽ đi qua quy trình xác định và khai thác một cách implement mật mã sai của một ứng dụng Android.</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4050aff0a13e808b9a35d4623b1ddf66" data-id="4050aff0a13e808b9a35d4623b1ddf66"><span><div id="4050aff0a13e808b9a35d4623b1ddf66" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4050aff0a13e808b9a35d4623b1ddf66" title="Exploiting Bad Cryptography Implementation"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Exploiting Bad Cryptography Implementation</span></span></h3><div class="notion-row notion-block-4050aff0a13e805789e6df9c431d5692"><div class="notion-column notion-block-4050aff0a13e806abf8ef8dcbe6d9aa4" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e8024a7adfa283bcd3f50"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:355.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A35635a1d-cfa4-4280-ba36-d35ffd06d50c%3Aimage.png?table=block&amp;id=4050aff0-a13e-8024-a7ad-fa283bcd3f50&amp;t=4050aff0-a13e-8024-a7ad-fa283bcd3f50" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4050aff0a13e8057b8f6e414573fd2ea" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4050aff0a13e802c94a1c67a840943fc">Ứng dụng sau đây là một chat application nơi người dùng có thể gửi và nhận tin nhắn. Đoạn chat được mã hóa end-to-end, nghĩa là không ai khác có thể đọc được nó.</div><div class="notion-text notion-block-4050aff0a13e801193bfe9ebcd2acf4c">Package name: <code class="notion-inline-code">com.hackthebox.chatapp</code></div><div class="notion-blank notion-block-4050aff0a13e80c1ab11ee96def5d829"> </div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4050aff0a13e80eab5f3d311484444c9">Ta có thể mở ứng dụng này với JADX bằng cách cung cấp đường dẫn đầy đủ đến file APK:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e80a3a287e6da459039d8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A75a0d816-5e92-4fc3-aeeb-5fa2ff020f93%3Aimage.png?table=block&amp;id=4050aff0-a13e-80a3-a287-e6da459039d8&amp;t=4050aff0-a13e-80a3-a287-e6da459039d8" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4050aff0a13e80049821e2f4f7cc6879">Tại MainActivity class, ta có thể thấy app có 2 hàm <code class="notion-inline-code">encrypt()</code> và <code class="notion-inline-code">decrypt()</code> được dùng để mã hóa tin nhắn. Cả 2 đều dùng thuật toán AES với Key và IV được lưu ngay trong <code class="notion-inline-code">res/values/Strings.xml</code> với key là “<code class="notion-inline-code">secret_key</code>” và “<code class="notion-inline-code">initialization_vector</code>” </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e802f9c2ec626399be836"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:624.96875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ad86725b9-9f33-4bd9-aebf-8cdd22fe7901%3Aimage.png?table=block&amp;id=4050aff0-a13e-802f-9c2e-c626399be836&amp;t=4050aff0-a13e-802f-9c2e-c626399be836" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e80e3982ef06d3eee1e95"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:602.921875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ad6090834-f475-425f-9d7b-f97ec0e93c8c%3Aimage.png?table=block&amp;id=4050aff0-a13e-80e3-982e-f06d3eee1e95&amp;t=4050aff0-a13e-80e3-982e-f06d3eee1e95" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4050aff0a13e80c88a05dc8e33685ba9">Như vậy, ta sẽ dùng 2 giá trị này để đọc tin nhắn được lưu trong Database</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e80b6aa85d507d9b1d952"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ae0474311-7210-4189-a95b-0e7b452475a4%3Aimage.png?table=block&amp;id=4050aff0-a13e-80b6-aa85-d507d9b1d952&amp;t=4050aff0-a13e-80b6-aa85-d507d9b1d952" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4050aff0a13e8019b2a7cc6d8f0cf8a8">Trong đó:</div><ul class="notion-list notion-list-disc notion-block-4050aff0a13e8063b0a1d8a27bfc97c9"><li><code class="notion-inline-code">INCOMING</code> là tin nhắn đến</li></ul><ul class="notion-list notion-list-disc notion-block-4050aff0a13e80c0830fd3d6b7bfe7fb"><li><code class="notion-inline-code">OUTCOMING</code> là tin nhắn đi</li></ul><div class="notion-text notion-block-4050aff0a13e80c6940bc4c9f869c823">Lấy bất kì một tin nhắn đến để mang đi decode ta sẽ thu được flag (<em>if you lucky</em>)</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e80d59153ead7d05391a4"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A545481d0-e343-498a-b834-532e4760a1ff%3Aimage.png?table=block&amp;id=4050aff0-a13e-80d5-9153-ead7d05391a4&amp;t=4050aff0-a13e-80d5-9153-ead7d05391a4" alt="notion image" loading="lazy" decoding="async"/></div></figure><hr class="notion-hr notion-block-4050aff0a13e80599ddfeadcb9781b0b"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4050aff0a13e80a2b2d0fa623e2561f3" data-id="4050aff0a13e80a2b2d0fa623e2561f3"><span><div id="4050aff0a13e80a2b2d0fa623e2561f3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4050aff0a13e80a2b2d0fa623e2561f3" title="Reversing Hybrid Apps"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Reversing Hybrid Apps</b></span></span></h2><div class="notion-text notion-block-4050aff0a13e809c9ab5d0ff42b873c5">Ứng dụng Android có thể được phân thành <b>ba</b> loại chính: </div><ul class="notion-list notion-list-disc notion-block-4050aff0a13e8018b6c3fd42c2da33b8"><li><b>Native apps</b>: được xây dựng bằng các ngôn ngữ riêng của nền tảng như Java hay Kotlin</li></ul><ul class="notion-list notion-list-disc notion-block-4050aff0a13e80b79264ce4f25e38cbd"><li><b>Web apps</b>: chạy trong trình duyệt và thường được xây dựng bằng HTML, CSS, và JavaScript</li></ul><ul class="notion-list notion-list-disc notion-block-4050aff0a13e80608f77e964e8893efa"><li><b>Hybrid apps</b>: kết hợp các yếu tố của cả hai và thường sử dụng <code class="notion-inline-code">WebViews</code> để hiển thị nội dung web bên trong một native container. Hybrid apps thường được dev bằng HTML, CSS, và JavaScript thông qua các framework tận dụng <code class="notion-inline-code">WebViews</code>. </li></ul><div class="notion-text notion-block-4050aff0a13e805da5cac8ab4c51d972">Trong ví dụ dưới đây, ta sẽ tập trung vào các ứng dụng được xây dựng bằng React Native, một framework open-source được phát triển bởi Facebook. React Native cho phép dev xây dựng các ứng dụng di động đa nền tảng (cross-platform) bằng JavaScript và React, giúp họ <b>duy trì một codebase</b> duy nhất cho cả hai nền tảng Android và iOS.Sử dụng JADX để phân tích hybrid apps là chưa đủ. JADX có thể decompile Java bytecode và tạo ra pseudocode giống Java, nhưng không thể xử lý các file JavaScript có trong Hybrid apps.
Hơn nữa, React Native developers có thể sử dụng JavaScript obfuscator để bảo vệ cho app khỏi reverse engineering. Ngoài ra, khi sử dụng <b>Hermes engine</b>, mã JavaScript được chuyển thành <b>Hermes bytecode</b>, một định dạng gọn hơn và được tối ưu hơn khi bổ sung thêm một lớp obfuscation. 
Trong các ứng dụng React Native, mã JavaScript thường được đóng gói (bundle) vào một file có tên <code class="notion-inline-code">index.android.bundle</code>, và file này là trọng tâm phân tích chính của phần này.</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4050aff0a13e80a596c5c76b031af57e" data-id="4050aff0a13e80a596c5c76b031af57e"><span><div id="4050aff0a13e80a596c5c76b031af57e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4050aff0a13e80a596c5c76b031af57e" title="Reading Minified JS Code"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Minified JS Code</span></span></h3><div class="notion-row notion-block-4050aff0a13e8018aeabce399ba7afb1"><div class="notion-column notion-block-4050aff0a13e807d8002f5629bca27f3" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e80ff95b0c6b6113c12dc"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:320.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Adef74a59-27f3-411a-b327-48a3e914295f%3Aimage.png?table=block&amp;id=4050aff0-a13e-80ff-95b0-c6b6113c12dc&amp;t=4050aff0-a13e-80ff-95b0-c6b6113c12dc" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4050aff0a13e80efaccfdd135e9140c4" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-4050aff0a13e80b5a5b2cecfb8e9da43">Ứng dụng sau đây được tạo bằng React Native, và khi khởi động, người dùng sẽ thấy một màn hình đăng nhập:</div><div class="notion-text notion-block-4050aff0a13e80599825d360df6144fd">Package name: <code class="notion-inline-code">com.awesomeproject</code></div><div class="notion-blank notion-block-4050aff0a13e806a832bf93b596ac18f"> </div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4050aff0a13e804cb518d27186a552fd">Hãy decompile APK và đọc mã nguồn của ứng dụng:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e804ea0e7dde2d91ed106"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A72b530f1-db24-4884-9644-996f7c36d31f%3Aimage.png?table=block&amp;id=4050aff0-a13e-804e-a0e7-dde2d91ed106&amp;t=4050aff0-a13e-804e-a0e7-dde2d91ed106" alt="notion image" loading="lazy" decoding="async"/></div></figure><blockquote class="notion-quote notion-block-4050aff0a13e80dabdcff755fffa62a0"><div>Các lớp <code class="notion-inline-code">MainActivity</code> và <code class="notion-inline-code">MainApplication</code> trong các dự án React Native đóng vai trò cầu nối giữa môi trường <b>Android native</b> và <b>JavaScript runtime</b>. Chúng chịu trách nhiệm khởi tạo và cấu hình các thiết lập và thành phần thiết yếu để framework React Native hoạt động đúng cách bên trong ứng dụng Android. </div></blockquote><div class="notion-text notion-block-4050aff0a13e807385aae232a3b25536">Bằng cách chuyển đến <code class="notion-inline-code">Source code</code> -&gt; <code class="notion-inline-code">Resources</code> -&gt; <code class="notion-inline-code">assets</code> -&gt; <code class="notion-inline-code">index.android.bundle</code>, ta có thể truy cập mã JavaScript đã được bundle, như hiển thị dưới đây:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e807b8e64ef143f84c297"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A7675320a-ff84-4888-bbb5-3f3568e0a86a%3Aimage.png?table=block&amp;id=4050aff0-a13e-807b-8e64-ef143f84c297&amp;t=4050aff0-a13e-807b-8e64-ef143f84c297" alt="notion image" loading="lazy" decoding="async"/></div></figure><blockquote class="notion-quote notion-block-4050aff0a13e8032ba13c4b32e2ddb32"><div>Khi React Native build ứng dụng, mã JavaScript trải qua quá trình minification để giảm kích thước. Quá trình này bao gồm việc loại bỏ whitespace, đổi tên biến thành các tên ngắn hơn, và thực hiện các tối ưu hóa khác để giảm kích thước file. Mặc dù ta có thể tìm kiếm các chuỗi hardcoded, việc đọc source của ứng dụng vẫn khá mất công. </div></blockquote><div class="notion-text notion-block-4050aff0a13e8000affbf463649a5776">Để chuyển mã đã minify về dạng dễ đọc hơn, ta cần sử dụng các công cụ gọi là <code class="notion-inline-code">beautifiers</code>. Các công cụ này có thể tìm trực tuyến, như <code class="notion-inline-code">JSBeautifier</code> và <code class="notion-inline-code">Pretty Print</code>. Tuy nhiên, <code class="notion-inline-code">index.android.bundle</code> thường là một file lớn, và trình duyệt web có thể gặp khó khăn khi hiển thị hiệu quả toàn bộ nội dung này. Ngược lại, các công cụ dòng lệnh như <code class="notion-inline-code">js-beautify</code> có thể hoạt động hiệu quả hơn. Hãy cài đặt công cụ này và thử đọc nội dung file <code class="notion-inline-code">index.android.bundle</code>:</div><div class="notion-text notion-block-4050aff0a13e80168ea1d18e34fa57e1">Sau đó dump file này ra khỏi file <code class="notion-inline-code">.apk</code></div><div class="notion-text notion-block-4050aff0a13e80aeb81ad29c101748ab">Sau đó dùng <code class="notion-inline-code">js-beautify</code> để làm beautiful content of minified JS code:</div><div class="notion-text notion-block-4050aff0a13e80bda920f199cb15a00b">Ngay cả sau khi beautify, file vẫn chứa cả code được <b>bundle</b> từ <b>tất cả</b> các <code class="notion-inline-code">node_modules</code> sử dụng trong dự án, chứ không phải chỉ có code ứng dụng do developer viết. May mắn trong hầu hết các trường hợp, code do developer viết thường nằm về cuối file. Kiểm tra nội dung bundle đã trích xuất cho thấy đoạn snippet sau:</div><div class="notion-blank notion-block-4050aff0a13e801db54bdfc3271f1833"> </div><div class="notion-text notion-block-4050aff0a13e80dea231f3ed550146f1">Đoạn snippet trên cho thấy đây là một hàm authentication và làm lộ password debug được hardcoded: <code class="notion-inline-code">565dc04237f69c88</code>.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4050aff0a13e80b1beace84e3e1c8a31"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:642.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ab9ddf546-197e-474e-b59a-a2af509c6dfa%3Aimage.png?table=block&amp;id=4050aff0-a13e-80b1-beac-e84e3e1c8a31&amp;t=4050aff0-a13e-80b1-beac-e84e3e1c8a31" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4050aff0a13e80a786bad4f1ec070076" data-id="4050aff0a13e80a786bad4f1ec070076"><span><div id="4050aff0a13e80a786bad4f1ec070076" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4050aff0a13e80a786bad4f1ec070076" title="Reading Compiled JS Code"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reading Compiled JS Code</span></span></h3><div class="notion-text notion-block-4060aff0a13e8032955adcc249a3db73">Như đã đề cập, các ứng dụng React Native được build với <b>Hermes engine</b> được xem là có thêm một lớp bảo mật. <b>Hermes engine</b> có thể được bật hoặc tắt bằng cách đặt giá trị <code class="notion-inline-code">hermesEnabled</code> thành <code class="notion-inline-code">true</code> hoặc <code class="notion-inline-code">false</code> tương ứng trong file <code class="notion-inline-code">gradle.properties</code> của dự án Android:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80c995f0f48ebda077f7"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A0910570d-669b-4270-95e6-29aa38fb6651%3Aimage.png?table=block&amp;id=4060aff0-a13e-80c9-95f0-f48ebda077f7&amp;t=4060aff0-a13e-80c9-95f0-f48ebda077f7" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e8069af19e58eb2e79b0d">Việc đọc nội dung file <code class="notion-inline-code">index.android.bundle</code> bằng JADX hoặc APKTool là không thể:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80719ee5f6d7bb0fc583"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A266cfa88-463a-4781-a0a1-728dd377db69%3Aimage.png?table=block&amp;id=4060aff0-a13e-8071-9ee5-f6d7bb0fc583&amp;t=4060aff0-a13e-8071-9ee5-f6d7bb0fc583" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e8065b244c80b896228d7">Toàn bộ đều là các byte rác (các byte không thể hiển thị)</div><div class="notion-text notion-block-4060aff0a13e8030be56cd74f131f446">Decompile file APK bằng APKTool và chạy lệnh <code class="notion-inline-code">file</code> trên <code class="notion-inline-code">index.android.bundle</code> cho thấy kết quả sau:</div><div class="notion-text notion-block-4060aff0a13e80359630e551337cd4a7">Điều này cho biết nội dung file là <b>Hermes JavaScript bytecode</b> — tức mã đã biên dịch, không thể đọc bởi con người — trong khi file trước đó chỉ chứa mã minify sẽ trả về ASCII text. May mắn thay, một số công cụ có thể disassemble các file được biên dịch thành Hermes VM bytecode. Trong ví dụ này, ta sẽ dùng <code class="notion-inline-code"><b>hermes-dec</b></code>. Hãy cài đặt nó và thử decompile file <code class="notion-inline-code"><b>index.android.bundle</b></code>:</div><div class="notion-text notion-block-4060aff0a13e807ebb54cca59afc4870">File đã được decompile thành công. Hãy đọc nội dung của nó:</div><div class="notion-row notion-block-4060aff0a13e80cdac38e56868f8125c"><div class="notion-column notion-block-4060aff0a13e800088f0f26563a26a63" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e801da86afb9b3519fa81"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A9a2ff532-1e9b-48b3-bfcf-0b4dd7a63863%3Aimage.png?table=block&amp;id=4060aff0-a13e-801d-a86a-fb9b3519fa81&amp;t=4060aff0-a13e-801d-a86a-fb9b3519fa81" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4060aff0a13e805db800ece89560f969" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80fe8286cf9d9ba4e197"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Accaa51f5-261f-4315-84a8-dd43fe66619f%3Aimage.png?table=block&amp;id=4060aff0-a13e-80fe-8286-cf9d9ba4e197&amp;t=4060aff0-a13e-80fe-8286-cf9d9ba4e197" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4060aff0a13e80348fe2d6b54a820f4d">Kiểm tra đoạn code gần cuối file cho thấy một POST request tới server <code class="notion-inline-code">http://</code> tại endpoint <code class="notion-inline-code">/login</code> (pseudo-code do <code class="notion-inline-code">hermes-dec</code> sinh ra)
Đọc thêm vài dòng phía dưới sẽ thấy một cặp key-value hardcoded <code class="notion-inline-code">debug_key: 1308bd3e299d42f4</code> để xác thực người dùng</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80d49d86e4180f2acc0f"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:661.96875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aaedd99c1-39a8-4474-94ad-6270bed4cbcf%3Aimage.png?table=block&amp;id=4060aff0-a13e-80d4-9d86-e4180f2acc0f&amp;t=4060aff0-a13e-80d4-9d86-e4180f2acc0f" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e8010ac40d26f84d9c43b">Với debug key chính xác đã được xác định trong mã nguồn, ta đã xác thực thành công và có được quyền truy cập vào ứng dụng.</div><hr class="notion-hr notion-block-4060aff0a13e80b183b6f13df3ea40b2"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4060aff0a13e8007b324cdc1a6b2222c" data-id="4060aff0a13e8007b324cdc1a6b2222c"><span><div id="4060aff0a13e8007b324cdc1a6b2222c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4060aff0a13e8007b324cdc1a6b2222c" title="Reading Obfuscated Code"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Reading Obfuscated Code</b></span></span></h2><div class="notion-text notion-block-4060aff0a13e80cb8fc3d948b2862ffb">Obfuscation là quá trình biến đổi executable code và assets của app thành một định dạng khó hiểu khi bị reverse engineering. App sau khi obfuscate vẫn hoạt động giống hệt bản gốc về mặt chức năng, nhưng cấu trúc bên dưới, tên biến, tên method, và các yếu tố nhận diện khác được thay đổi để tăng cường tính bảo mật của ứng dụng. Lý do phổ biến nhất khi sử dụng obfuscation là:</div><ul class="notion-list notion-list-disc notion-block-4060aff0a13e80f6bde5fcc518194289"><li>Protect Intellectual Property (Bảo vệ tài sản trí tuệ)</li></ul><ul class="notion-list notion-list-disc notion-block-4060aff0a13e803989eec034e2c0f780"><li>Enhance Security</li></ul><ul class="notion-list notion-list-disc notion-block-4060aff0a13e8054be6ed84d0fddd16a"><li>Reduce Binary Size</li></ul><div class="notion-text notion-block-4060aff0a13e809cb385ce6c83809b64">Mặc dù code obfuscation có thể gây ra các vấn đề về khả năng bảo trì (maintainability) và đôi khi giảm hiệu năng, nó vẫn là một giải pháp được ưa chuộng để tăng cường bảo mật ứng dụng. Có nhiều công cụ thương mại và open-source cung cấp code obfuscation, dưới đây là một số kỹ thuật phổ biến nhất được sử dụng:</div><ul class="notion-list notion-list-disc notion-block-4060aff0a13e8067a54dd5fecb5771d7"><li>Name Obfuscation: Đây là kỹ thuật phổ biến nhất. Các tên class, method, và variable mang tính mô tả được thay
bằng tên ngắn, vô nghĩa, khiến code khó đọc và khó hiểu hơn.</li></ul><ul class="notion-list notion-list-disc notion-block-4060aff0a13e802bacfbc45274a17900"><li>Control Flow Obfuscation: Thay đổi control flow của app bằng cách đưa vào các fake loops, switch statement giả, và unreachable code.</li></ul><ul class="notion-list notion-list-disc notion-block-4060aff0a13e80c79442f859af0706f3"><li>Repackaging: Thay đổi package của một class. Điều này phá vỡ tổ chức logic mà các package cung cấp. Bằng cách sắp xếp lại các class hiện có vào các cấu trúc package khác nhau hoặc hoàn toàn mới, ngữ cảnh vốn có từ tên package bị mất, khiến việc hiểu tổ chức và chức năng tổng thể của decompiled code trở nên khó khăn hơn.</li></ul><ul class="notion-list notion-list-disc notion-block-4060aff0a13e80f18eb4dd6c36fa132e"><li>String Encryption: Mã hóa các string constants được dùng trong app. Các chuỗi này được giải mã tại runtime, khiến static analysis khó khăn hơn.</li></ul><ul class="notion-list notion-list-disc notion-block-4060aff0a13e80bd8035e684eb756fec"><li>Class Encryption: Mã hóa một số class hoặc method nhất định, chỉ giải mã khi chúng được cần đến tại runtime.</li></ul><ul class="notion-list notion-list-disc notion-block-4060aff0a13e80ce9971f4975a468455"><li>Dummy Code Insertion: Đưa vào các đoạn code (không ảnh hưởng đến chức năng của app) gây nhiễu cho decompilers và các reverse engineer.</li></ul><div class="notion-text notion-block-4060aff0a13e809eb9bef1f3f4674778">Hệ sinh thái Android cung cấp một số công cụ obfuscation, được dùng rộng rãi nhất là <code class="notion-inline-code">R8</code> (giới thiệu năm 2018) và <code class="notion-inline-code">ProGuard</code> (tiền nhiệm của R8). Cả hai đều được tích hợp sẵn trong Android Studio, và để bật code obfuscation, giá trị <code class="notion-inline-code">minifyEnabled</code> phải là <code class="notion-inline-code">true</code> trong file <code class="notion-inline-code">Gradle Scripts</code> -&gt; <code class="notion-inline-code">build.gradle</code>:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80c797d8f26ffe6d5ecd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Abfacf8ae-7518-428e-8c1d-c53d2f1488df%3Aimage.png?table=block&amp;id=4060aff0-a13e-80c7-97d8-f26ffe6d5ecd&amp;t=4060aff0-a13e-80c7-97d8-f26ffe6d5ecd" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e80f88cfac58449de9406">Trong phần <code class="notion-inline-code">Gradle Scripts</code>, file <code class="notion-inline-code">proguard-rules.pro</code> cho phép bạn chỉ định các rules để thêm hoặc loại bỏ một số hành động trong quá trình build.</div><div class="notion-text notion-block-4060aff0a13e800c9679ff01dcaeee31">Trong ví dụ dưới đây, R8 được sử dụng. Theo mặc định, R8 thực hiện cả code shrinking (thu gọn mã — xóa code không dùng/không cần thiết) và obfuscation (làm code khó reverse hơn). Các rules điều khiển cách shrinking và obfuscation diễn ra được định nghĩa trong file <code class="notion-inline-code">proguard-rules.pro</code>:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4060aff0a13e80d9a154f94c221f9192" data-id="4060aff0a13e80d9a154f94c221f9192"><span><div id="4060aff0a13e80d9a154f94c221f9192" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4060aff0a13e80d9a154f94c221f9192" title="Following the Control Flow of an Obfuscated App"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Following the Control Flow of an Obfuscated App</span></span></h3><div class="notion-text notion-block-4060aff0a13e80989738d6d367fe57e6">Trong ví dụ sau, ta sẽ kiểm tra một ứng dụng được tạo bằng Android Studio với R8 code shrinker tích hợp sẵn. Trong khi đọc obfuscated code, ta sẽ cố gắng hiểu và lần theo luồng gọi method trong app để xem có thể tìm thấy bất kỳ thông tin hữu ích hoặc nhạy cảm nào không. Với ví dụ này, ta cũng sẽ so sánh pseudocode do JADX cung cấp với source code gốc của app trong Android Studio</div><div class="notion-row notion-block-4060aff0a13e805ea98ec326287bc969"><div class="notion-column notion-block-4060aff0a13e80cc810ae57caef18cae" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e807f9ec6e1bb73495c53"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:352.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A9496853d-b700-4698-912b-ed833ae3ad7a%3Aimage.png?table=block&amp;id=4060aff0-a13e-807f-9ec6-e1bb73495c53&amp;t=4060aff0-a13e-807f-9ec6-e1bb73495c53" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4060aff0a13e80b5b07ad40576613ad8" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4060aff0a13e80c2bc79fa1d041dbd4f">Package name: <code class="notion-inline-code">com.hackthebox.myapp</code></div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4060aff0a13e80b99cfee34641f812ff">Khi vào JADX để xem source code, bạn sẽ thấy các kí tự chữ được thay thế cho tên class</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80ee8361de68f8810b1d"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aeb8f8ae7-46ad-46cb-912c-b66117a8c6c7%3Aimage.png?table=block&amp;id=4060aff0-a13e-80ee-8361-de68f8810b1d&amp;t=4060aff0-a13e-80ee-8361-de68f8810b1d" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e80f68fb4c3643a78ca89">Đọc source code của class <code class="notion-inline-code">MainActivity</code> - method <code class="notion-inline-code">onClick(View view)</code>, đây nhiều khả năng là nút purchase product. Ngoài ra, nội dung của nó có vẻ gọi method <code class="notion-inline-code">a()</code> của class/object <code class="notion-inline-code">d()</code> tại dòng <code class="notion-inline-code">new d(mainActivity, mainActivity.M).a();</code>. Nhìn vào source code gốc của app, ta thấy method <code class="notion-inline-code">onClick()</code> sẽ tạo object <code class="notion-inline-code">UserActionHandler</code> (nhận hai tham số) rồi gọi method <code class="notion-inline-code">handleUserAction()</code>:</div><div class="notion-text notion-block-4060aff0a13e80e1855dfc1fd1b96722">Khả năng rất cao method <code class="notion-inline-code">d(mainActivity, mainActivity.M).a();</code> được lộ ra trong JADX và method <code class="notion-inline-code">actionHandler.handleUserAction();</code> trong source code gốc là một. Hãy double-click vào method <code class="notion-inline-code">a()</code> trong JADX để xem method này được tạo ở đâu trong code:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80aebff1cd16821aa1ff"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:484.953125px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A9b65b5d4-f586-4570-b81d-cf0affab393d%3Aimage.png?table=block&amp;id=4060aff0-a13e-80ae-bff1-cd16821aa1ff&amp;t=4060aff0-a13e-80ae-bff1-cd16821aa1ff" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e80319dbcc6d7c7f8b212">Điều này dẫn ta đến class <code class="notion-inline-code">d{}</code>, cho thấy method <code class="notion-inline-code">a()</code> ở cuối file. Lần theo luồng trong Android Studio bằng cách giữ alt và click vào method <code class="notion-inline-code">handleUserAction()</code> cũng cho thấy đoạn snippet sau:</div><div class="notion-text notion-block-4060aff0a13e80379654f17db1aa17fa">Điều này lần lượt gọi method <code class="notion-inline-code">productManager.fetchProductFromAPI(context, new ProductManager.ProductFetch...)</code>. Tương tự, code trong JADX cũng có vẻ gọi method <code class="notion-inline-code">b.a(this.f1816a, new a())</code>. Hãy lần theo lời gọi method lần nữa bằng cách double-click vào method <code class="notion-inline-code">a()</code>:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80d7b2c9e0c96efe1a7c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af95a5d92-c98b-43f6-b724-834c57647efe%3Aimage.png?table=block&amp;id=4060aff0-a13e-80d7-b2c9-e0c96efe1a7c&amp;t=4060aff0-a13e-80d7-b2c9-e0c96efe1a7c" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e8016a503c5cb7b2ff51d">Điều này dẫn ta đến method <code class="notion-inline-code">a()</code> của class <code class="notion-inline-code">a{}</code>, có vẻ như nó tạo một request tới URL <code class="notion-inline-code">https://10.10.10.10/products/1</code>. URL này được pass cho method <code class="notion-inline-code">c()</code>, và double-click vào nó sẽ dẫn ta đến đoạn code sau trong cùng class:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80b1a4b0d92e86e3f2d6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:550.96875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A0e88d039-4776-4d58-bd30-d07dd1ba89f1%3Aimage.png?table=block&amp;id=4060aff0-a13e-80b1-a4b0-d92e86e3f2d6&amp;t=4060aff0-a13e-80b1-a4b0-d92e86e3f2d6" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e80469819f841499de49d">Trong method <code class="notion-inline-code">c()</code> ở trên, ta có thể thấy một giá trị có tên <code class="notion-inline-code">api_key</code> cũng được đưa vào một object <code class="notion-inline-code">HashMap</code>, cùng với các giá trị khác. Quay lại JADX, giá trị này được trả về bởi method <code class="notion-inline-code">j1.a()</code>. Nhìn nhanh vào source code gốc của app, ta có thể xác nhận rằng đang lần theo đúng luồng dự kiến của app:</div><div class="notion-text notion-block-4060aff0a13e80c7a5bdd337b4c1f94e">Method tương đương với <code class="notion-inline-code">j1.a(&quot;api_key&quot;)</code> có vẻ là <code class="notion-inline-code">ActionCoordinator.authGet(&quot;api_key&quot;)</code>. Double-click vào <code class="notion-inline-code">j1.a()</code> sẽ dẫn ta đến instance của method này:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80c1a2b2fed2a1c7a492"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:589.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af62a9da2-ff16-4198-83a2-08ff7f697c06%3Aimage.png?table=block&amp;id=4060aff0-a13e-80c1-a2b2-fed2a1c7a492&amp;t=4060aff0-a13e-80c1-a2b2-fed2a1c7a492" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e807397d3f76ab7963d6c">Cuối cùng, có thể kết luận rằng một phép so sánh chuỗi diễn ra, so sánh <code class="notion-inline-code">api_key</code> với return value từ method <code class="notion-inline-code">f190a.a()</code>. Hãy double-click lần nữa vào method <code class="notion-inline-code">a()</code> và kiểm tra xem có thể đọc được bất kỳ cặp key-value tiềm năng nào không:</div><div class="notion-text notion-block-4060aff0a13e80af9489caba78cb2624">Cuối cùng, method <code class="notion-inline-code">z5.a()</code> đã làm lộ ra key <code class="notion-inline-code">xmjPceil0E5ekn6QisfF1XLVSxq3n7HkfK9duVJxaqLPxZ4eB9EiYacvgswubvKZ</code>.</div><hr class="notion-hr notion-block-4060aff0a13e8093879bf74d1aeb8d74"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4060aff0a13e8002857de0d3d34b40f9" data-id="4060aff0a13e8002857de0d3d34b40f9"><span><div id="4060aff0a13e8002857de0d3d34b40f9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4060aff0a13e8002857de0d3d34b40f9" title="Deobfuscating Code"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Deobfuscating Code</b></span></span></h2><div class="notion-text notion-block-4060aff0a13e808fb901cf4ba4734027">Ta đã khám phá cách phân tích thủ công obfuscated code bằng cách lần theo các method và control flow để hiểu rõ hơn hành vi của ứng dụng và phát hiện các vấn đề bảo mật tiềm ẩn. Mặc dù obfuscation có thể che giấu tên biến, cấu trúc method và logic, nó không làm code trở nên hoàn toàn không thể đọc được. Với thời gian và công sức, thường có thể tái dựng chức năng của chương trình — ngay cả với những app bị obfuscate nặng.</div><div class="notion-text notion-block-4060aff0a13e80169f99e5c50e36e7a3">Trong phần này, ta chuyển trọng tâm sang deobfuscation — quá trình đảo ngược obfuscated code để làm cho nó dễ đọc hơn. Thay vì kiểm tra thủ công từng dòng, ta sẽ sử dụng các công cụ và kỹ thuật tự động hóa một phần quá trình này, đặc biệt là đảo ngược string obfuscation. Những phương pháp này có thể giảm đáng kể thời gian và độ phức tạp khi phân tích các ứng dụng được bảo vệ, đặc biệt là những app dùng thư viện open-source để obfuscate code.</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4060aff0a13e80709c48ceab21b26af3" data-id="4060aff0a13e80709c48ceab21b26af3"><span><div id="4060aff0a13e80709c48ceab21b26af3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4060aff0a13e80709c48ceab21b26af3" title="Deobfuscating With Tools"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Deobfuscating With Tools</span></span></h3><div class="notion-text notion-block-4060aff0a13e80a8b66fdce200a53e8a">Trong ví dụ này, ta sẽ phân tích code của một ứng dụng đã bị obfuscate bằng một thư viện open-source để che giấu các chuỗi hardcoded.</div><div class="notion-row notion-block-4060aff0a13e80518cdbd4e67a6f63e9"><div class="notion-column notion-block-4060aff0a13e80b4b09fd0ec5f9a13eb" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e8007af83ea4752a16222"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:356.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aa78b33c3-4ea3-4e18-8b35-ef3c86e0aaa6%3Aimage.png?table=block&amp;id=4060aff0-a13e-8007-af83-ea4752a16222&amp;t=4060aff0-a13e-8007-af83-ea4752a16222" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4060aff0a13e809badb6c7b783fda8bc" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4060aff0a13e8077b8f7ecad36bdb663">Package name: <code class="notion-inline-code">com.hackthebox.myapp</code></div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4060aff0a13e803bbde6d3a2e5e7c293">Hãy dùng JADX để decompile ứng dụng:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80738e9ee13c43db4b42"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A39ccf9a8-9906-4b39-a806-438614bc29f9%3Aimage.png?table=block&amp;id=4060aff0-a13e-8073-8e9e-e13c43db4b42&amp;t=4060aff0-a13e-8073-8e9e-e13c43db4b42" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e802a812bdc59d9819e4a">Đọc nội dung <code class="notion-inline-code">MainActivity</code> cho thấy nút <code class="notion-inline-code">R.id.purchaseButton</code>. Double-click vào method <code class="notion-inline-code">UserActionHandler</code> bên trong <code class="notion-inline-code">onClick()</code> cho thấy class <code class="notion-inline-code">UserActionHandler</code>. Tiếp tục lần theo code như trong ví dụ trước sẽ dẫn ta đến class <code class="notion-inline-code">Authenticator</code>:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e80b2b2c8e787463df9c5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A8eaea08c-7ce3-4337-8808-49df747db65f%3Aimage.png?table=block&amp;id=4060aff0-a13e-80b2-b2c8-e787463df9c5&amp;t=4060aff0-a13e-80b2-b2c8-e787463df9c5" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e805eb261d8bb6f9935c6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A0927bfb4-7b27-4582-be45-d90d66d3f0db%3Aimage.png?table=block&amp;id=4060aff0-a13e-805e-b261-d8bb6f9935c6&amp;t=4060aff0-a13e-805e-b261-d8bb6f9935c6" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e806aaafbd57c33ea536f"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:569.984375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A7ed09b57-68d4-4a8a-808c-5584937c4ffd%3Aimage.png?table=block&amp;id=4060aff0-a13e-806a-aafb-d57c33ea536f&amp;t=4060aff0-a13e-806a-aafb-d57c33ea536f" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e8078a894cb902092a661"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A5f3057fb-4dd9-4c51-934c-0142ac77a0b5%3Aimage.png?table=block&amp;id=4060aff0-a13e-8078-a894-cb902092a661&amp;t=4060aff0-a13e-8078-a894-cb902092a661" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e80cf940dfce1e70a5a46">Biến <code class="notion-inline-code">API_KEY</code> cho thấy app dùng một API key để kết nối với remote server. Ta thấy giá trị của API không đọc được (do obfuscate). Method <code class="notion-inline-code">Deobfuscator$myapp$app.getString()</code> có vẻ trả về giá trị gốc của chuỗi đã obfuscate, và dòng <code class="notion-inline-code">import org.lsposed.lsparanoid.Deobfuscator$myapp$app;</code> ở đầu class cho biết thư viện obfuscation đã dùng. Tìm kiếm <code class="notion-inline-code">org.lsposed.lsparanoid</code> cho kết quả đầu tiên như sau:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e8067a3e0d8a205377409"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:669.9375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ad2383775-e44f-45e3-9918-84fee9e29768%3Aimage.png?table=block&amp;id=4060aff0-a13e-8067-a3e0-d8a205377409&amp;t=4060aff0-a13e-8067-a3e0-d8a205377409" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e80b2b6cde00e911a58ae">Theo mô tả project, đây là một string obfuscator cho ứng dụng Android có tên <a class="notion-link" href="https://github.com/LSPosed/LSParanoid" target="_blank" rel="noopener noreferrer">LSParanoid</a>. Tìm kiếm một công cụ deobfuscate các string của app cho kết quả như sau:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4060aff0a13e8008ad89ca62cab063ff"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:652.96875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A9e86a0a8-9ebf-4824-87cf-ababbc2f5ad7%3Aimage.png?table=block&amp;id=4060aff0-a13e-8008-ad89-ca62cab063ff&amp;t=4060aff0-a13e-8008-ad89-ca62cab063ff" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4060aff0a13e808b8913f604eeeffa85">Kết quả đầu tiên là một GitHub project tên <a class="notion-link" href="https://github.com/giacomoferretti/paranoid-deobfuscator" target="_blank" rel="noopener noreferrer">paranoid-deobfuscator</a>. Nhưng tại thời điểm tôi sử dụng, công cụ bị lỗi nên tôi sẽ dùng script sau</div><div class="notion-text notion-block-4060aff0a13e80a889efd02eb73037fa">Sau khi cài đặt xong, ta decompile app bằng APKTool:</div><div class="notion-text notion-block-4060aff0a13e8087b970e748691b5972">Bây giờ, hãy thử deobfuscate source code bằng cách chạy script trên:</div><div class="notion-text notion-block-4060aff0a13e80ee9dcbfe9a8a220f60">Như vậy là ta đã deobfuscate api_key thành công và giá trị của nó là:
<code class="notion-inline-code">kF6gV9zQ3sXpE2lW8rTnJyM0cD4hB7iUoZaO5YqxC1wLeSbPfIuGvHjRAkNmFt5x</code></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4060aff0a13e8010b8e2d3974b7f2b85" data-id="4060aff0a13e8010b8e2d3974b7f2b85"><span><div id="4060aff0a13e8010b8e2d3974b7f2b85" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4060aff0a13e8010b8e2d3974b7f2b85" title="Deobfuscating Manually"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Deobfuscating Manually</b></span></span></h3><div class="notion-text notion-block-4070aff0a13e808abf9df0ad7236a0a5">Dựa vào công cụ để deobfuscate code của một ứng dụng không phải lúc nào cũng khả thi. Do đó, học cách làm thủ công sẽ tăng cơ hội thành công của bạn. Trong ví dụ sau, ta sẽ phân tích source code của một ứng dụng Android để hiểu kỹ thuật obfuscation đang được sử dụng và tự xây dựng một script deobfuscation. Chức năng của app này tương tự ví dụ trước.</div><div class="notion-text notion-block-4070aff0a13e8057b99bd73f9b728043">Xét class <code class="notion-inline-code">Authenticator</code> cho thấy dòng <code class="notion-inline-code">private static final String API_KEY = Deobfuscator$myapp$app.getString(1198238974187119737L);</code>, đã xuất hiện trong ảnh trước đó. Điều này cho biết API key được lấy qua return value của method <code class="notion-inline-code">getString(1198238974187119737L)</code> nằm trong class <code class="notion-inline-code">Deobfuscator$myapp$app</code>. Để điều tra sâu hơn, hãy double-click vào method <code class="notion-inline-code">getString()</code> để xem implementation của nó:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e809fbbcfe67bc71f346e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A563660a0-1b64-4b2f-906f-c71a5bafbc95%3Aimage.png?table=block&amp;id=4070aff0-a13e-809f-bbcf-e67bc71f346e&amp;t=4070aff0-a13e-809f-bbcf-e67bc71f346e" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e8031adabe6cd2c979953">Class <code class="notion-inline-code">Deobfuscator$myapp$app</code> chứa method <code class="notion-inline-code">getString()</code> nhận một tham số <code class="notion-inline-code">long j</code>. Đây chính là giá trị <code class="notion-inline-code">1198238974187119737L</code> được truyền vào khi method được gọi, có thể đại diện cho một định danh (identifier) hoặc key. Bên trong method này, ta thấy một method khác: <code class="notion-inline-code">DeobfuscatorHelper.getString(j, chunks)</code>. Các giá trị được truyền vào khi gọi method này là <code class="notion-inline-code">j</code>. Hãy double-click vào method <code class="notion-inline-code">getString(j, chunks)</code> để xem class <code class="notion-inline-code">DeobfuscatorHelper</code>:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e805eaf5efea08f079881"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A60d8cdfc-0a14-457c-9abb-4b4981f3a18a%3Aimage.png?table=block&amp;id=4070aff0-a13e-805e-af5e-fea08f079881&amp;t=4070aff0-a13e-805e-af5e-fea08f079881" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e80659ca9d6833312cefd">Class này chứa method <code class="notion-inline-code">getString(long j, String[] strArr)</code>, nhận giá trị <code class="notion-inline-code">1198238974187119737L</code> và chuỗi đã obfuscate (<code class="notion-inline-code">chunks</code>) làm tham số. Bên trong method, chúng ta để ý hai dòng sau:</div><div class="notion-text notion-block-4070aff0a13e8074a48bcab59a4f5236">Các dòng này dùng một helper class <code class="notion-inline-code">RandomHelper</code> để sinh các giá trị random dựa trên <code class="notion-inline-code">j</code>. Đọc phần còn lại của method, có thể thấy nó được thiết kế để giải mã chuỗi từ mảng các chuỗi đã obfuscate (<code class="notion-inline-code">strArr</code>) và cuối cùng trả về chuỗi gốc dựa trên định danh. Hãy xem thêm class <code class="notion-inline-code">RandomHelper</code> bằng cách double-click vào nó:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e80dd849dc67c7c8ccaa0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aa98870fb-fd94-44ba-b189-2571a02b6d23%3Aimage.png?table=block&amp;id=4070aff0-a13e-80dd-849d-c67c7c8ccaa0&amp;t=4070aff0-a13e-80dd-849d-c67c7c8ccaa0" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e8093a3dadd26c4141189">Bây giờ, khi đã biết cơ chế deobfuscation hoạt động như thế nào, chúng ta có thể viết một script bằng Java để deobfuscate API key. Một cách tiếp cận là copy-paste code của các class <code class="notion-inline-code">Deobfuscator$myapp$app</code> và <code class="notion-inline-code">DeobfuscatorHelper</code> từ JADX về máy. Nếu cách này không hoạt động, ta có thể lấy các class này trực tiếp từ GitHub repository chính thức. Với ví dụ này, chúng ta sẽ đi theo cách thứ hai. Dưới đây là class <code class="notion-inline-code">DeobfuscatorHelper</code>:</div><div class="notion-text notion-block-4070aff0a13e8087821ae079301a3454">Class <code class="notion-inline-code">RandomHelper</code></div><div class="notion-text notion-block-4070aff0a13e809485c1cb7cbc2a8ba0">Cuối cùng, tạo class Main.java để khởi tạo các giá trị cần thiết:</div><div class="notion-text notion-block-4070aff0a13e80b6a26bd9d8e92ecd9f">Trong đoạn snippet trên, giá trị từ dòng <code class="notion-inline-code">long key = 1198238974187119737L</code> được lấy từ JADX  <code class="notion-inline-code">Deobfuscator$myapp$app.getString(1198238974187119737L)</code>.</div><div class="notion-text notion-block-4070aff0a13e8024ab7dfbc5bc128fcb">Biến có tên <code class="notion-inline-code">chunks</code> chứa chính chuỗi đã obfuscate, và vì các ký tự của nó không hiển thị ở chế độ code trong JADX, ta phải chuyển sang chế độ smali để lấy các Java unicode escape sequence.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4070aff0a13e8002a519e91ec5723883"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A81f1e857-bef3-486e-891a-ee7dc988fcc9%3Aimage.png?table=block&amp;id=4070aff0-a13e-8002-a519-e91ec5723883&amp;t=4070aff0-a13e-8002-a519-e91ec5723883" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4070aff0a13e80feafc2eb3694c52248">Khi script đã sẵn sàng, chạy lệnh sau để compile và thực thi:</div><div class="notion-text notion-block-4070aff0a13e80a29409d5181017a853">Và <code class="notion-inline-code">API_KEY</code> đã được deobfuscate thành công.</div><div class="notion-blank notion-block-4070aff0a13e800286dccbc896ee06e1"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extracting and Enumerating APK Files]]></title>
            <link>https://blog.zero-trust.site/article/extract-and-enumerate-apk-files</link>
            <guid>https://blog.zero-trust.site/article/extract-and-enumerate-apk-files</guid>
            <pubDate>Sat, 24 Oct 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden notion-page-font-mono " style="font-family:iawriter-mono, Nitti, ui-monospace, SFMono-Regular, Menlo, Consolas, &#x27;Liberation Mono&#x27;, Courier, monospace"><main class="notion light-mode notion-page notion-block-4030aff0a13e807e8241d357f871385a"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4030aff0a13e80e89e71fb13c56ab204" data-id="4030aff0a13e80e89e71fb13c56ab204"><span><div id="4030aff0a13e80e89e71fb13c56ab204" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80e89e71fb13c56ab204" title="Introduction"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Introduction</span></span></h2><hr class="notion-hr notion-block-4030aff0a13e8074bf84c0b88af05db1"/><div class="notion-text notion-block-4030aff0a13e8063affcf1c4720ccd4a">Static analysis là một kỹ thuật dùng để đánh giá tính bảo mật của một ứng dụng bằng cách kiểm tra mã nguồn mà không cần running nó. 
Static analysis giúp xác định các lỗ hổng tiềm ẩn, lỗi lập trình bằng cách phân tích nội dung APK, mã Smali, hoặc mã Java đã được decompile. Kỹ thuật này thường được dùng như một phần của quy trình đánh giá bảo mật nhằm phát hiện vấn đề sớm trong vòng đời phát triển hoặc đánh giá.</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e80b28f06f90695f20f17" data-id="4030aff0a13e80b28f06f90695f20f17"><span><div id="4030aff0a13e80b28f06f90695f20f17" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80b28f06f90695f20f17" title="How it Works"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">How it Works</span></span></h4><div class="notion-text notion-block-4030aff0a13e80b29a16e3bb6c6aa781">Các công cụ static analysis phân tích mã của ứng dụng và đánh giá nó dựa trên một tập quy tắc hoặc pattern được định nghĩa sẵn để xác định các vấn đề tiềm ẩn. 
Các công cụ này sử dụng những kỹ thuật như data flow analysis, control flow analysis, và semantic analysis (phân tích ngữ nghĩa) để hiểu hành vi của code. Static analysis cho ứng dụng Android thường bao gồm việc kiểm tra mã nguồn Java, các file DEX (Dalvik Executable) đã biên dịch, native libraries, và các file cấu hình như Android Manifest (nơi chứa thông tin thiết yếu về app, chẳng hạn như permissions và các thành phần được khai báo).</div><div class="notion-text notion-block-4030aff0a13e80528d68d5bb2ff9ad9c">Types of Vulnerabilities that Static Analysis Can Detect</div><table class="notion-simple-table notion-block-4030aff0a13e807e9e0fd29c44ba79e9"><tbody><tr class="notion-simple-table-row notion-block-4030aff0a13e803e93dfd4a6d6f57b49"><td class="" style="width:238.6328125px"><div class="notion-simple-table-cell">Type</div></td><td class="" style="width:425.6484375px"><div class="notion-simple-table-cell">Description</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e804abd07e7ade06af66f"><td class="" style="width:238.6328125px"><div class="notion-simple-table-cell">Insecure Storage</div></td><td class="" style="width:425.6484375px"><div class="notion-simple-table-cell">Dữ liệu được lưu ở những vị trí mà app hoặc người dùng khác có thể truy cập.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e803b8c64dc914598fbd0"><td class="" style="width:238.6328125px"><div class="notion-simple-table-cell">Hard-Coded Sensitive Information</div></td><td class="" style="width:425.6484375px"><div class="notion-simple-table-cell">Thông tin nhạy cảm như mật khẩu và API key được nhúng trực tiếp vào code.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e807facddcfdea8bf6c52"><td class="" style="width:238.6328125px"><div class="notion-simple-table-cell">Insecure Communication</div></td><td class="" style="width:425.6484375px"><div class="notion-simple-table-cell">Giao tiếp không mã hóa hoặc mã hóa kém, có thể bị intercept và đọc.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8027a8f8d6c1bc6f0900"><td class="" style="width:238.6328125px"><div class="notion-simple-table-cell">Insufficient Cryptography</div></td><td class="" style="width:425.6484375px"><div class="notion-simple-table-cell">Việc sử dụng thuật toán mã hóa yếu hoặc đã bị loại bỏ (deprecated).</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8047be7dcfed50bfb96d"><td class="" style="width:238.6328125px"><div class="notion-simple-table-cell">Insecure Permissions</div></td><td class="" style="width:425.6484375px"><div class="notion-simple-table-cell">Yêu cầu nhiều quyền hơn mức cần thiết, cho phép app truy cập dữ liệu nhạy cảm.</div></td></tr></tbody></table><hr class="notion-hr notion-block-4030aff0a13e805d9904cc8b2100ce52"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4030aff0a13e80d9ba30d998042f392d" data-id="4030aff0a13e80d9ba30d998042f392d"><span><div id="4030aff0a13e80d9ba30d998042f392d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80d9ba30d998042f392d" title="APK Extraction"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">APK Extraction</span></span></h3><div class="notion-text notion-block-4030aff0a13e800f938ccb29ff005536">Cách phổ biến nhất để cài ứng dụng Android lên thiết bị là thông qua các app store. 
Tuy nhiên, mục đích static analysis cần ta truy cập trực tiếp vào file APK của app chứ không chỉ một bản cài đặt hoạt động. Ta sẽ tìm hiểu và khám phá ba loại app store và giải thích cách trích xuất file APK để phân tích, thay vì chỉ đơn thuần cài ứng dụng lên thiết bị.</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4030aff0a13e80bb9d63c93e18bc8c03" data-id="4030aff0a13e80bb9d63c93e18bc8c03"><span><div id="4030aff0a13e80bb9d63c93e18bc8c03" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80bb9d63c93e18bc8c03" title="Google Play Store"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Google Play Store</span></span></h4><div class="notion-text notion-block-4030aff0a13e80748fc3f3fdfefd685e">Phần lớn ứng dụng Android được phân phối qua Google Play Store (app store chính thức do Google phát triển). Mặc dù cho phép người dùng cài app trực tiếp lên thiết bị, nó không cung cấp quyền truy cập vào các file APK gốc (raw) cần cho static analysis.</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4030aff0a13e80c69e7ec16254328836" data-id="4030aff0a13e80c69e7ec16254328836"><span><div id="4030aff0a13e80c69e7ec16254328836" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80c69e7ec16254328836" title="Manufacturer App Stores"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Manufacturer App Stores</span></span></h4><div class="notion-text notion-block-4030aff0a13e80d8bc3afea8f6a259e2">Các nhà sản xuất đóng gói thiết bị với phiên bản Android tùy chỉnh có thể không tích hợp sẵn Google Play Store. Vì vậy, họ thường cung cấp app store riêng của mình làm phương án thay thế, như:</div><ul class="notion-list notion-list-disc notion-block-4030aff0a13e80f9b154ca3d57f58408"><li>Samsung Galaxy Store </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e8097bb62dea85425bb3e"><li>Amazon Appstore </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e80749f1bffb585ad08db"><li>Huawei AppGallery </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e8023a89bf0cc0daff34a"><li>Xiaomi Mi GetApps </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e8015be47d1f87a6df852"><li>OPPO App Market </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e802fa0face70b956e2e3"><li>VIVO App Store</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4030aff0a13e80339afdded7d36bfb4f" data-id="4030aff0a13e80339afdded7d36bfb4f"><span><div id="4030aff0a13e80339afdded7d36bfb4f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80339afdded7d36bfb4f" title="Third-Party App Stores"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Third-Party App Stores</span></span></h4><div class="notion-text notion-block-4030aff0a13e8054a67bcda227d4b435">Third-party app store là nguồn tải ứng dụng Android thay thế, không được tích hợp sẵn hay cài đặt sẵn trên hầu hết thiết bị. Các nền tảng này thường cho phép người dùng tải trực tiếp file APK, giúp việc cài đặt thủ công và phân tích trở nên khả thi. Chúng cũng có thể cung cấp các phiên bản cũ hơn của app hoặc các app bị giới hạn/không có trên Google Play Store. Một số third-party app store nổi tiếng:</div><ul class="notion-list notion-list-disc notion-block-4030aff0a13e80288384d3c3679f9e39"><li>Amazon Appstore </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e800083a8f3562121f453"><li>APKMirror </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e80bbbe99c8a1a87338c2"><li>APKPure </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e80ecae56db18bcd1f8ed"><li>APKCombo </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e808b9609e6efb8105c0c"><li>Aptoide </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e807e825be052a7328ca0"><li>F-Droid</li></ul><div class="notion-text notion-block-4030aff0a13e807cbdc0c067a773960a">Việc cài app từ Third-Party App Store yêu cầu bật tùy chọn <code class="notion-inline-code">Unknown Sources</code> trên thiết bị. </div><div class="notion-row notion-block-4030aff0a13e80b8b079c235e96feab9"><div class="notion-column notion-block-4030aff0a13e806e800ee3d9b424b3c5" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e80029a8bc9c20518615e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:354.00390625px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A060b4e5c-13ca-4b16-9de5-4a0f70dea37f%3Aimage.png?table=block&amp;id=4030aff0-a13e-8002-9a8b-c9c20518615e&amp;t=4030aff0-a13e-8002-9a8b-c9c20518615e" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4030aff0a13e8098bbb4c94535cfebb0" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e80c9a99de38f2db89ea8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:320.99609375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A7c607dad-cb5c-4bb9-a37c-3a9bcb31f4ff%3Aimage.png?table=block&amp;id=4030aff0-a13e-80c9-a99d-e38f2db89ea8&amp;t=4030aff0-a13e-80c9-a99d-e38f2db89ea8" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4030aff0a13e8026ab05d407a08a59ad">Ngoài ra, khi ta nhấn vào một file APK để cài, một hộp thoại sẽ xuất hiện thông báo rằng cài đặt hiện tại không cho phép cài đặt từ nguồn này. Từ hộp thoại đó, ta có thể mở phần cài đặt bảo mật tương ứng và bật công tắc để cho phép cài đặt từ nguồn cụ thể này.</div><div class="notion-text notion-block-4030aff0a13e8081a1bbff64a61efcce">Như đã đề cập, để bắt đầu static analysis ứng dụng, ta cần có file APK. Hãy xem xét ba cách khác nhau để trích xuất file APK từ một app.</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4030aff0a13e80e281f5e1472c6c445b" data-id="4030aff0a13e80e281f5e1472c6c445b"><span><div id="4030aff0a13e80e281f5e1472c6c445b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80e281f5e1472c6c445b" title="Finding APK Online"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Finding APK Online</span></span></h4><div class="notion-text notion-block-4030aff0a13e8016ba6ef69c5bf689a0">Trong cách tiếp cận này, ta sẽ tìm và tải file APK từ Third-Party App Stores. Hãy truy cập F-Droid và tìm kiếm ứng dụng muốn phân tích. Ở đây ta tìm thử 1 app bất kì.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e8071a96ff1a5898743c6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A92257271-c122-46cc-86e4-0f0241a8315e%3Aimage.png?table=block&amp;id=4030aff0-a13e-8071-a96f-f1a5898743c6&amp;t=4030aff0-a13e-8071-a96f-f1a5898743c6" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e805fac15f3ba0f733544"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Abf51686c-29c3-4b9c-a4bf-81c829cf38bd%3Aimage.png?table=block&amp;id=4030aff0-a13e-805f-ac15-f3ba0f733544&amp;t=4030aff0-a13e-805f-ac15-f3ba0f733544" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e804081d7e5832a87a8d3"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:274.00390625px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A15341598-44b4-4eb6-88c6-fdedce4f22c3%3Aimage.png?table=block&amp;id=4030aff0-a13e-8040-81d7-e5832a87a8d3&amp;t=4030aff0-a13e-8040-81d7-e5832a87a8d3" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4030aff0a13e800eba7fe756661145e7">Như vậy là sau khi cài đặt lên thiết bị, ta có thể phân tích luôn file này.</div><div class="notion-text notion-block-4030aff0a13e80fb9dc2fdf1b201a80c">Nếu bạn tải APK trực tiếp trên thiết bị di động bằng trình duyệt, bạn sẽ tìm thấy nó trong thư mục Downloads qua file manager. Chỉ cần nhấn vào file để cài.</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4030aff0a13e80bc96b5cc07af77f9ad" data-id="4030aff0a13e80bc96b5cc07af77f9ad"><span><div id="4030aff0a13e80bc96b5cc07af77f9ad" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80bc96b5cc07af77f9ad" title="Extracting the APK using Third-Party Tools"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Extracting the APK using Third-Party Tools</span></span></h4><div class="notion-text notion-block-4030aff0a13e8020bf06e5d087384d4c">Một phương pháp khác để có được file APK là dùng các công cụ third-party được thiết kế cho mục đích này. Đó là APK Export, một ứng dụng tự động trích xuất file APK của bất kỳ app nào đã cài trên thiết bị và lưu nó tại máy.</div><div class="notion-row notion-block-4030aff0a13e809ab988cd324335605c"><div class="notion-column notion-block-4030aff0a13e8076b2aee1eb28d6bb51" style="width:calc((100% - (2 * min(32px, 4vw))) * 0.33333333333333337)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e80dca6d5c5ef229f1f69"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:356.9921875px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A7b91037b-5823-436b-8e3a-3338745266e4%3Aimage.png?table=block&amp;id=4030aff0-a13e-80dc-a6d5-c5ef229f1f69&amp;t=4030aff0-a13e-80dc-a6d5-c5ef229f1f69" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4030aff0a13e80beb11df8dd8c163350" style="width:calc((100% - (2 * min(32px, 4vw))) * 0.33333333333333337)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e80138412cd4e495ffca7"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:320.99609375px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A504f82ff-dfff-43b0-b8e1-456a0c0ab5a2%3Aimage.png?table=block&amp;id=4030aff0-a13e-8013-8412-cd4e495ffca7&amp;t=4030aff0-a13e-8013-8412-cd4e495ffca7" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4030aff0a13e80129e94fd2dc154e293" style="width:calc((100% - (2 * min(32px, 4vw))) * 0.3333333333333333)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e80209a16e029c98faf83"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:749px"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A40378cd6-aa8d-4346-acc2-596a20224824%3Aimage.png?table=block&amp;id=4030aff0-a13e-8020-9a16-e029c98faf83&amp;t=4030aff0-a13e-8020-9a16-e029c98faf83" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div></div><blockquote class="notion-quote notion-block-4030aff0a13e8066a9e0cf21a870b20e"><div>Giao diện khá dễ dùng nên bạn tự khám phá thêm</div></blockquote><div class="notion-row notion-block-4030aff0a13e8094a0e1debb5944fed2"><div class="notion-column notion-block-4030aff0a13e80689c0fc1bedb82e24b" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e80ae8776deda2f981471"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:355px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A665625ff-fa17-4324-a6d3-ddf9669fb1ff%3Aimage.png?table=block&amp;id=4030aff0-a13e-80ae-8776-deda2f981471&amp;t=4030aff0-a13e-80ae-8776-deda2f981471" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4030aff0a13e8047a165e55fb8d6f428" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.5)"><div class="notion-text notion-block-4030aff0a13e809ebf54cbdd573906a9">Nhưng mà khổ cái là muốn Save App thì phải mua premium nên tôi sẽ bỏ cách này đi (cần thiết lắm thì dùng thôi 🙂)</div></div><div class="notion-spacer"></div></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-4030aff0a13e806da545eefd78912e6c" data-id="4030aff0a13e806da545eefd78912e6c"><span><div id="4030aff0a13e806da545eefd78912e6c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e806da545eefd78912e6c" title="Extracting The APK From The Device"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Extracting The APK From The Device</span></span></h4><div class="notion-text notion-block-4030aff0a13e807aa3f8d98c869278f3">Một cách thủ công hơn để trích xuất APK là lấy trực tiếp file APK của một app đã cài từ thiết bị. APK thường nằm trong thư mục <code class="notion-inline-code">/data/app/&lt;package-name&gt;-1/base.apk</code>. Ví dụ, nếu package name là <code class="notion-inline-code">com.example.myapp</code>, đường dẫn nhiều khả năng sẽ là <code class="notion-inline-code">/data/app/com.example.myapp-1/base.apk</code>.</div><blockquote class="notion-quote notion-block-4030aff0a13e80559260dc56074b01a3"><div>Lưu ý: Hậu tố (-1) có thể khác nhau - có thể là số thứ tự hoặc một chuỗi ngẫu nhiên tùy thuộc vào phiên bản Android</div></blockquote><div class="notion-text notion-block-4030aff0a13e80daae40c0dd801cfd1c">Quyền truy cập vào thư mục <code class="notion-inline-code">/data/app/</code> bị hạn chế đối với người dùng chưa root, khiến việc khám phá hay đoán đường dẫn package đầy đủ trở nên khó khăn. Có 2 trường hợp:</div><ul class="notion-list notion-list-disc notion-block-4030aff0a13e801ca6c8c084c2cdc089"><li>Một là đã biết package name, ta có thể xác định chính xác đường dẫn bằng ADB.</li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e8088a977c0d7b5df6a1c"><li>Hai là chưa biết package name</li></ul><div class="notion-text notion-block-4030aff0a13e809a8556c886697f2966">Sau khi đã xác định đúng package, ta có thể pull file base.apk từ thiết bị về máy cục bộ bằng lệnh sau:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4030aff0a13e8037959cdc992246b2e3" data-id="4030aff0a13e8037959cdc992246b2e3"><span><div id="4030aff0a13e8037959cdc992246b2e3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e8037959cdc992246b2e3" title="Mini Homework"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Mini Homework</span></span></h3><div class="notion-row notion-block-4030aff0a13e80638594fb32c22b9c93"><div class="notion-column notion-block-4030aff0a13e80089fa3e2a15df6bfd9" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.375)"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e80a8ac19f12b40fd57af"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:356.015625px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A92c6f016-26b0-409e-9fae-fc482283bb32%3Aimage.png?table=block&amp;id=4030aff0-a13e-80a8-ac19-f12b40fd57af&amp;t=4030aff0-a13e-80a8-ac19-f12b40fd57af" alt="notion image" loading="lazy" decoding="async"/></div></figure></div><div class="notion-spacer"></div><div class="notion-column notion-block-4030aff0a13e8055a3f1ef56a497747f" style="width:calc((100% - (1 * min(32px, 4vw))) * 0.625)"><div class="notion-text notion-block-4030aff0a13e80a187f2d381d93e314b">Package name: <code class="notion-inline-code">com.hackthebox.myapp</code></div><div class="notion-text notion-block-4030aff0a13e800b95e9fea3df769b8b">Sau khi installed 1 app thì công việc của ta sẽ là tìm hash của app vừa install đó.</div><div class="notion-text notion-block-4030aff0a13e80149e05f5436a578e43">App vừa tải về có package name là: <code class="notion-inline-code">com.hackthebox.extractme</code> </div><div class="notion-text notion-block-4030aff0a13e808db87ceb26509d6df1">Sau đó là tìm path:</div></div><div class="notion-spacer"></div></div><div class="notion-text notion-block-4030aff0a13e804392bef6fcb02721e6">Pull về sau đó check hash của nó là xong</div><hr class="notion-hr notion-block-4030aff0a13e801593c1f935e096b663"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4030aff0a13e80979c19d71c7d37ef4d" data-id="4030aff0a13e80979c19d71c7d37ef4d"><span><div id="4030aff0a13e80979c19d71c7d37ef4d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80979c19d71c7d37ef4d" title="Disassembling the APK"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Disassembling the APK</span></span></h2><div class="notion-text notion-block-4030aff0a13e809fb8a0ceb89060fd28">File APK là file archive chứa mã nguồn, assets, và các file tài nguyên cần thiết để app chạy. Ta sẽ phân tích nội dung của một file APK bằng cách dùng công cụ để decompile mã nguồn của app về ngôn ngữ dễ đọc hơn với con người, sau đó decode assets và tài nguyên để đọc các file cấu hình.</div><div class="notion-text notion-block-4030aff0a13e80ee8dc2d4bcb737dd0d">Để thực hiện phân tích này, ta sẽ dùng <a class="notion-link" href="https://apktool.org/docs/install/" target="_blank" rel="noopener noreferrer">APKTool</a>. </div><div class="notion-text notion-block-4030aff0a13e800693e7d11218cbdc6f">Thư mục <code class="notion-inline-code">myapp</code> chứa nội dung đã được decode của APK. Một file quan trọng là <code class="notion-inline-code">AndroidManifest.xml</code> (file này được encoded bên trong APK và không thể đọc bằng cách giải nén APK). May mắn là, <b>APKTool </b>đã decode nó, và giờ ta có thể xem nội dung của file này.</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e804982ccc621d161dd2b" data-id="4030aff0a13e804982ccc621d161dd2b"><span><div id="4030aff0a13e804982ccc621d161dd2b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e804982ccc621d161dd2b" title="Package Name"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Package Name</span></span></h4><div class="notion-text notion-block-4030aff0a13e80879dd9d78f3985f19f">Thẻ <code class="notion-inline-code">&lt;manifest&gt;</code> chứa nhiều thuộc tính quan trọng. Một trong những thứ đầu tiên cần xem là package name (thứ nhận diện ứng dụng là duy nhất):</div><div class="notion-text notion-block-4030aff0a13e802ea4c9fa3856faab4f">Package name (<code class="notion-inline-code">com.disass.myapp</code>) rất cần thiết cho cả static lẫn dynamic analysis. Từ chính đoạn snippet trên, ta còn thấy target SDK version là <code class="notion-inline-code">34</code> (các phiên bản Android SDK khác nhau có thể kéo theo các cách thức bảo mật khác nhau).</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e80798087c645625a4761" data-id="4030aff0a13e80798087c645625a4761"><span><div id="4030aff0a13e80798087c645625a4761" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80798087c645625a4761" title="Permissions"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Permissions</span></span></h4><div class="notion-text notion-block-4030aff0a13e80b1b828ccda55493bb4">Đôi khi app sẽ yêu cầu quyền từ người dùng trong khi chạy, nhằm truy cập vào nhiều chức năng khác nhau. Đoạn snippet sau hiển thị các quyền này được khai báo trong manifest:</div><div class="notion-text notion-block-4030aff0a13e80b7ad60fbd1ff98932b">Các app lỏng lẻo về quyền hoặc có bảo mật kém có thể yêu cầu nhiều quyền hơn mức cần thiết, điều này có thể đưa rủi ro vào hệ thống. 
Ví dụ, việc lưu dữ liệu nhạy cảm trong external storage có thể cho phép các app khác truy cập dữ liệu đó nếu chúng cũng có quyền Read. Dưới đây là bảng tổng hợp một số quyền mà pentester cần đánh giá cẩn thận:</div><table class="notion-simple-table notion-block-4030aff0a13e806daaafde7a82cf7484"><tbody><tr class="notion-simple-table-row notion-block-4030aff0a13e80e6acb2e659acba6a15"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell"><b>Permissions</b></div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell"><b>Description</b></div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80c4b6aae6eba9c94763"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">READ_SMS, SEND_SMS, RECEIVE_SMS</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cấp cho app khả năng đọc, gửi và nhận tin nhắn SMS. Có thể bị khai thác để intercept OTP dùng trong two-factor authentication hoặc gửi tin nhắn trái phép.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8005884bccd61c7ae106"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">READ_CALL_LOG, WRITE_CALL_LOG</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cho phép app truy cập và sửa đổi lịch sử cuộc gọi của thiết bị. Điều này có thể làm lộ metadata nhạy cảm về hành vi liên lạc của người dùng hoặc được dùng để che giấu các cuộc gọi độc hại.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e807880d7f579bfa9a69b"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">READ_CONTACTS, WRITE_CONTACTS</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cấp quyền truy cập danh bạ của thiết bị và khả năng thay đổi nó. Một app độc hại có thể exfiltrate dữ liệu liên hệ hoặc chèn các mục giả mạo nhằm mục đích social engineering hoặc spam.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8089aeeff839f5b3f68f"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cho phép app truy cập vị trí của thiết bị. Điều này có thể tạo điều kiện theo dõi di chuyển real-time của người dùng mà không có sự đồng ý.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8044b95dc25c6915c351"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE </div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cho phép app truy cập và sửa đổi các file lưu trên external storage. Thông tin nhạy cảm có thể bị lộ hoặc bị thay đổi, đặc biệt khi không được app hay người dùng bảo vệ đúng cách.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8042bf9ad8b6453b704a"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">GET_ACCOUNTS </div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cho phép app truy vấn danh sách tài khoản đã đăng ký trên thiết bị. Thông tin này có thể bị lạm dụng để nhắm mục tiêu vào các tài khoản cụ thể hoặc thu thập dữ liệu cho các cuộc tấn công phishing.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e803386ffe6055e2d9d30"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">CAMERA</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cấp cho app quyền truy cập phần cứng camera của thiết bị. Nếu bị lạm dụng, có thể cho phép chụp ảnh hay quay video ngầm mà người dùng không hề hay biết.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e803e9b84eb6e9722f41a"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">RECORD_AUDIO</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cấp cho app quyền ghi âm qua micro của thiết bị. Có thể bị khai thác để nghe lén các cuộc hội thoại trong nền.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80809254c2d38311cdbb"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">INSTALL_PACKAGES, REQUEST_INSTALL_PACKAGES</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cho phép app kích hoạt cài đặt package thông qua trình cài đặt hệ thống. Nếu bị lạm dụng, có thể dẫn đến việc silent installation các app độc hại bổ sung.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80be8561f9a4610b9b28"><td class="" style="width:220.6484375px"><div class="notion-simple-table-cell">SYSTEM_ALERT_WINDOW</div></td><td class="" style="width:531.6484375px"><div class="notion-simple-table-cell">Cho phép app vẽ các lớp overlay đè lên các app khác. Có thể bị tận dụng để tạo các lớp phishing UI thực hiện hành vi ngoài ý muốn (ví dụ: nhấn &quot;Allow&quot; thay vì &quot;Deny&quot;).</div></td></tr></tbody></table><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e807cb780f07dc08cbf77" data-id="4030aff0a13e807cb780f07dc08cbf77"><span><div id="4030aff0a13e807cb780f07dc08cbf77" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e807cb780f07dc08cbf77" title="Application Class"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Application Class</span></span></h4><div class="notion-text notion-block-4030aff0a13e80b2a242d773b74ccf6d">Phần tử tiếp theo ta thấy là <code class="notion-inline-code">&lt;application&gt;</code>, vốn chứa nhiều thuộc tính:</div><div class="notion-text notion-block-4030aff0a13e804290eefdef5609775e">Một thuộc tính thú vị trong manifest này là <code class="notion-inline-code">android:name=&quot;com.disass.myapp.Update”</code>. Thuộc tính này được dùng để chỉ định một class trong Application. 
Class Application và bất kỳ subclass nào của nó, như <code class="notion-inline-code">Update</code> trong ví dụ này, đều được khởi tạo trước bất kỳ class nào khác khi ứng dụng được tạo. Điều này có nghĩa là class <code class="notion-inline-code">Update</code> sẽ chạy ngay lập tức khi app khởi động và trước khi người dùng tương tác. </div><blockquote class="notion-quote notion-block-4030aff0a13e80d69055e6c6f17ca3e8"><div>Developers thường dùng nó cho việc khởi tạo, nhưng pentester nên chú ý đến các class như vậy, chúng thường được dùng cho các third-party libraries yêu cầu khởi tạo trước khi thư viện đó được chạy. Nếu các thư viện này có vulnerabilities hoặc được cấu hình không an toàn, chúng có thể đưa rủi ro bảo mật vào app.</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e80689461e2d7dd45b87f" data-id="4030aff0a13e80689461e2d7dd45b87f"><span><div id="4030aff0a13e80689461e2d7dd45b87f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80689461e2d7dd45b87f" title="Network Security Configurations (Add-ons)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Network Security Configurations (Add-ons)</span></span></h4><div class="notion-text notion-block-4030aff0a13e80a7804fc15308f0b2aa"><b>Không trong manifest này </b>- nhưng ta còn có một thuộc tính đáng chú ý khác cần biết đó là <code class="notion-inline-code">android:networkSecurityConfig=&quot;@xml/network_security_config&quot;</code>. Thuộc tính này trỏ tới một file chứa các cấu hình bảo mật mạng của app, nơi ta có thể chỉ định các custom <b>Certificate Authority (CA)</b>, allow hoặc intercept lưu lượng cleartext (HTTP), cùng các thiết lập liên quan đến mạng khác. File thường có nội dung như sau:</div><div class="notion-text notion-block-4030aff0a13e8036b44dcfb0754208d9">Thuộc tính <code class="notion-inline-code">cleartextTrafficPermitted=&quot;false&quot;</code> cho biết chỉ được phép kết nối bảo mật (HTTPS) khi giao tiếp với domain <code class="notion-inline-code">192.168.1.20</code>. Ngoài ra, phần tử <code class="notion-inline-code">&lt;certificates src=&quot;@raw/certificate&quot; /&gt;</code> trỏ tới custom certificate mà app tin tưởng cho kết nối bảo mật này. File certificate của app nằm trong thư mục <code class="notion-inline-code">myapp/res/raw</code></div><div class="notion-text notion-block-4030aff0a13e80648145f3ef006c1a82">Đoạn snippet sau minh họa một ví dụ khác nữa của file <code class="notion-inline-code">network_security_config.xml</code>. Nó ngụ ý việc triển khai một kỹ thuật gọi là <b>Certificate Pinning</b>, bổ sung một lớp bảo mật nữa cho app:</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e80469c52d3e19290e0ec" data-id="4030aff0a13e80469c52d3e19290e0ec"><span><div id="4030aff0a13e80469c52d3e19290e0ec" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80469c52d3e19290e0ec" title="Components"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Components</span></span></h4><div class="notion-text notion-block-4030aff0a13e80189d67c6ae71e9c4b8">Đoạn snippet tiếp theo của manifest hiển thị các activity của ứng dụng:</div><div class="notion-text notion-block-4030aff0a13e804f920ae52440aebe90">Snippet trên khai báo một activity có thể được truy cập từ các component khác của app, các app khác, hoặc hệ thống. Trong snippet trên, phần tử <code class="notion-inline-code">&lt;activity&gt;</code> bao gồm các thuộc tính <code class="notion-inline-code">android:exported=&quot;true&quot;</code> và <code class="notion-inline-code">android:name=&quot;com.disass.myapp.MainActivity&quot;</code>. Thuộc tính <code class="notion-inline-code">android:name</code> cho biết tên của Activity (ở đây là <code class="notion-inline-code">MainActivity</code>). Còn <code class="notion-inline-code">android:exported=&quot;true&quot;</code> cho biết activity này có thể truy cập từ bên ngoài app, nó có thể được khởi chạy bởi các app bên ngoài hoặc các component hệ thống. 
Chính vì vậy, activity này cũng có thể được kích hoạt bởi ADB.</div><div class="notion-text notion-block-4030aff0a13e80879cf8ea6648cce2e0">Một thuộc tính khác là <code class="notion-inline-code">&lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;</code> nằm trong phần tử <code class="notion-inline-code">&lt;intent-filter&gt;</code>. Thuộc tính này chỉ định activity là <b>main entry point</b> của ứng dụng (màn hình đầu tiên được khởi chạy khi người dùng chạm vào biểu tượng app). 
⇒ Chỉ một activity duy nhất trong app nên khai báo action này.</div><div class="notion-text notion-block-4030aff0a13e80aeb8b1ece8e0b5b80d">Trong snippet dưới đây, ta thấy app có một Content Provider và một Receiver:</div><div class="notion-callout notion-gray_background_co notion-block-4030aff0a13e8004a618ed069d707ec4"><div class="notion-page-icon-inline notion-page-icon-span"><img class="notion-page-icon" src="https://www.notion.so/icons/info-alternate_yellow.svg?mode=light" alt="page icon" loading="lazy" decoding="async"/></div><div class="notion-callout-text"><div class="notion-text notion-block-4030aff0a13e8046aeebf9573b34b596">Tất cả các khai báo thành phần nêu trên đều có giá trị với pentester</div></div></div><div class="notion-callout notion-gray_background_co notion-block-4030aff0a13e8001a8f7eb211982a44c"><div class="notion-page-icon-inline notion-page-icon-span"><img class="notion-page-icon" src="https://www.notion.so/icons/info-alternate_yellow.svg?mode=light" alt="page icon" loading="lazy" decoding="async"/></div><div class="notion-callout-text"><div class="notion-text notion-block-4030aff0a13e8094bccff8e4ba958a40">Thuộc tính <code class="notion-inline-code">android:exported=&quot;true&quot;</code> của một Activity rất quan trọng, vì nó cho biết component này có thể bị truy cập bởi các app khác. Cần cẩn thận khi thông tin nhạy cảm có thể lộ lọt từ đây.</div></div></div><div class="notion-text notion-block-4030aff0a13e806ba5caf3d83034e023">Với một snippet ví dụ của file manifest khác. Đoạn snippet này cho thấy một Deep Link được sử dụng bởi Menu</div><div class="notion-text notion-block-4030aff0a13e803bad03f780225933bc">Bốn phần tử bên trong <code class="notion-inline-code">&lt;intent-filter&gt;</code> này cho biết Activity sử dụng một Deep Link. 
Lập trình sơ sài với Deep Links có thể dẫn đến các vấn đề bảo mật và cần được kiểm tra kỹ lưỡng. (sẽ được thảo luận sau)</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e806ab72ffacb31d5e394" data-id="4030aff0a13e806ab72ffacb31d5e394"><span><div id="4030aff0a13e806ab72ffacb31d5e394" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e806ab72ffacb31d5e394" title="Application Resources"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Application Resources</span></span></h4><div class="notion-text notion-block-4030aff0a13e80e2ba4bcd208a0341ea">Khi xem xét các file được extract từ APK này bằng APKTool, ta còn thấy các thư mục <b>lib</b>, <b>res</b> và <b>smali</b>. </div><ul class="notion-list notion-list-disc notion-block-4030aff0a13e8025827eff0fc68bd798"><li>Thư mục <code class="notion-inline-code"><b>lib</b></code> chứa các <b>file shared library</b> (.SO) tách biệt được tạo cho các kiến trúc khác nhau, chứa Native Code của ứng dụng. Những file này cũng có thể được lấy ra và kiểm tra bằng cách giải nén file APK bằng công cụ như unzip. </li></ul><ul class="notion-list notion-list-disc notion-block-4030aff0a13e8070a3dcfef8b8cb4050"><li>Thư mục <code class="notion-inline-code">res</code> chứa tài nguyên như layout của app, chuỗi UI (UI strings), hình ảnh, và các static file khác. Trong số các thư mục khác, ta cũng thấy thư mục <code class="notion-inline-code">values</code> bên trong thư mục res. Thư mục này chứa các file XML với chuỗi và số nguyên được hardcoded, chẳng hạn như <code class="notion-inline-code">Strings.xml</code> (file này lưu các chuỗi UI dưới dạng <b>key-value pairs</b>). 
File này có thể expose các entry point tấn công tiềm năng, API key, secret token, database credentials, encrypt key. </li></ul><div class="notion-text notion-block-4030aff0a13e80c0b8bce6121829c571">Dưới đây là ví dụ về file <code class="notion-inline-code">strings.xml</code>:</div><div class="notion-text notion-block-4030aff0a13e80f4ba95c36453fe1dff">Ngoài ra, trong thư mục <code class="notion-inline-code">res</code>, ta có thể thấy các thư mục <code class="notion-inline-code">drawable</code> và <code class="notion-inline-code">layout</code> chứa hình ảnh và các file XML định nghĩa giao diện người dùng. Một thư mục hữu ích khác đáng kiểm tra trong quá trình pentest là <code class="notion-inline-code">xml</code>. Thư mục này có thể chứa các file network config, tiết lộ IP address của các API endpoint tiềm năng mà app giao tiếp. 
Các file như vậy cũng có thể cho biết app có được cấu hình để tin tưởng các kết nối không mã hóa hay không. Thư mục này cũng có thể bao gồm thư mục con <code class="notion-inline-code">raw</code>, vốn chứa các file tùy ý được lưu ở raw form, như certificate và key do developer đặt vào đó.</div><div class="notion-text notion-block-4030aff0a13e803aa79fcf12df6d7a8b">Một thư mục thú vị khác xuất hiện sau khi extract file từ APK bằng APKTool là thư mục <code class="notion-inline-code">smali</code>, chứa các file <code class="notion-inline-code">Smali</code>. </div><blockquote class="notion-quote notion-block-4030aff0a13e8011b218daa5be69aacf"><div><em>Smali là biểu diễn ở dạng human-readable của Dalvik bytecode</em> (ta cũng sẽ tìm hiểu sau)</div></blockquote><hr class="notion-hr notion-block-4030aff0a13e8073a655f9dfc3422545"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4030aff0a13e8004921ff126a507da18" data-id="4030aff0a13e8004921ff126a507da18"><span><div id="4030aff0a13e8004921ff126a507da18" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e8004921ff126a507da18" title="Understanding Smali"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Understanding Smali</b></span></span></h2><div class="notion-text notion-block-4030aff0a13e802d8ae7dba5dfb2f11f">Khi một ứng dụng Android được biên dịch, Java compiler (<code class="notion-inline-code">javac</code>) biên dịch các file <code class="notion-inline-code">.java</code> thành Java bytecode (các file <code class="notion-inline-code">.class</code>). 
Tương tự, các file Kotlin được biên dịch thành các file <code class="notion-inline-code">.class</code> bởi Kotlin compiler (<code class="notion-inline-code">kotlinc</code>). 
Sau đó chúng được dịch sang <b>Dalvik bytecode</b>, và kết quả đầu ra được đóng gói vào các file <code class="notion-inline-code">.dex</code> (Dalvik Executable). Tiếp đó, Android Asset Packaging Tool (<code class="notion-inline-code">aapt</code>) đóng gói mã đã biên dịch, tài nguyên, và manifest vào một archive duy nhất gọi là file <b>APK</b>. Khi extract và decode nội dung của một APK bằng APKTool, ngoài việc giải nén tài nguyên, một tiện ích tên là baksmali được dùng để disassemble Dalvik bytecode thành một định dạng con người đọc được gọi là <b>Smali</b>.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e800ba986f0f40a179387"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A4f0da350-0b97-4e2b-b06f-f8f61058182e%3Aimage.png?table=block&amp;id=4030aff0-a13e-800b-a986-f0f40a179387&amp;t=4030aff0-a13e-800b-a986-f0f40a179387" alt="notion image" loading="lazy" decoding="async"/></div></figure><blockquote class="notion-quote notion-block-4030aff0a13e80209a45fd19e7fb7ebc"><div>Smali là low-level language, giống assembly, được sử dụng bởi <b>Dalvik Virtual Machine</b> và <b>Android Runtime</b> (ART). Nó biểu diễn một cách tượng trưng (symbolically) cấu trúc và hành vi của ứng dụng Android. Có được mã nguồn disassembled ở định dạng Smali cho phép pentester phân tích chức năng và thậm chí có thể sửa đổi logic của ứng dụng (gọi là Application Patching). Ví dụ, các cơ chế bảo mật như root detection hay license verification có thể bị bypass bằng cách chỉnh sửa mã Smali.</div></blockquote><details class="notion-toggle notion-block-4030aff0a13e8077bf43f1a12a9ac038"><summary>Làm quen với Smali</summary><div><div class="notion-text notion-block-4030aff0a13e8020b7aaf08e9b6ffed5">Để làm quen với Smali, hãy xem một ví dụ đơn giản. Dưới đây là mã Java gốc của một class có tên <code class="notion-inline-code">Calculate</code>:</div><div class="notion-text notion-block-4030aff0a13e80bb87abee6bf3b7d38a">Biểu diễn Smali của đoạn code trên được hiển thị dưới đây:</div><div class="notion-text notion-block-4030aff0a13e80c1b34acc4f746adfc0">Phân tích chi tiết syntax</div><table class="notion-simple-table notion-block-4030aff0a13e80ef9cc8fda119f42ebb"><tbody><tr class="notion-simple-table-row notion-block-4030aff0a13e80999052cfb3fc8da553"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell">Instruction</div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Description</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80d18a15c49f4f7bd0b9"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell"><code class="notion-inline-code">.class public Lcom/hackthebox/myapp/calculate;</code></div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Khai báo class public <code class="notion-inline-code">calculate</code> trong package được chỉ định.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80b9a5b7ccdbd12b3457"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell"><code class="notion-inline-code">.method public constructor &lt;init&gt;()V</code></div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Khai báo method constructor mặc định của class.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8068a514fcc3a605a97e"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell"><code class="notion-inline-code">.method public static add(II)I</code></div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Khai báo một static method <code class="notion-inline-code">add</code> nhận hai tham số nguyên (I, I) và trả về một số nguyên (I).</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80d58a4cf3071bc0ff7f"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell"><code class="notion-inline-code">.locals 0</code></div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Chỉ định rằng method này không sử dụng register cục bộ nào (không phải tham số).</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80fd8d35d3a249f8cfff"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell"><code class="notion-inline-code">invoke-direct {p0}, Ljava/lang/Object;-&gt;&lt;init&gt;()V</code></div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Gọi constructor của superclass (<code class="notion-inline-code">Object</code>) trên đối tượng hiện tại (<code class="notion-inline-code">p0</code>).</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e807ebe4acfca4703be74"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell"><code class="notion-inline-code">add-int/2addr p0, p1</code></div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Cộng số nguyên trong register <code class="notion-inline-code">p1</code> vào số nguyên trong <code class="notion-inline-code">p0</code>, lưu kết quả vào <code class="notion-inline-code">p0</code>.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8020b4b9fa3d1144f0bf"><td class="" style="width:214.33333333333334px"><div class="notion-simple-table-cell"><code class="notion-inline-code">return p0</code></div></td><td class="" style="width:421.328125px"><div class="notion-simple-table-cell">Trả về giá trị trong <code class="notion-inline-code">p0</code> làm kết quả của method <code class="notion-inline-code">add</code>.</div></td></tr></tbody></table></div></details><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e8097a2ccd70afbe0aff6" data-id="4030aff0a13e8097a2ccd70afbe0aff6"><span><div id="4030aff0a13e8097a2ccd70afbe0aff6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e8097a2ccd70afbe0aff6" title="Data Types"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Data Types</span></span></h4><div class="notion-text notion-block-4030aff0a13e80ff93b5f2f6a34d1fc5">Smali dùng các cách viết tắt cụ thể cho các kiểu dữ liệu, được gọi là primitive types. Các kiểu này có thể được lưu trong registers hoặc truyền vào làm tham số của method. Dưới đây là tóm tắt các kiểu thường dùng:</div><table class="notion-simple-table notion-block-4030aff0a13e808aa44dc369ada21d78"><tbody><tr class="notion-simple-table-row notion-block-4030aff0a13e808a806fc6f2ab229d96"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">Type</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Description</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80d79350d22e41db1256"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">V</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu <code class="notion-inline-code">void</code>. Dùng cho các phương thức không trả về giá trị.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80eebffde06e855e7132"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">Z</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu boolean. Chỉ giữ một trong hai giá trị: <code class="notion-inline-code">true</code> hoặc <code class="notion-inline-code">false</code>.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8057ab09da89b9a131ec"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">B</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu <code class="notion-inline-code">byte</code>, một số nguyên <b>8-bit</b>.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e800eb255c9e7a8885b5f"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">S</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu <code class="notion-inline-code">short</code>, một số nguyên <b>16-bit</b>.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e807aabcbc64ea91b8ff2"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">C</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu <code class="notion-inline-code">char</code>, một ký tự Unicode <b>16-bit</b> đơn lẻ.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80958371fc641f37eaf6"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">I</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu <code class="notion-inline-code">int</code>, một số nguyên <b>32-bit</b>.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80568c7de0f8edf36a48"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">J</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu <code class="notion-inline-code">long</code>, một số nguyên <b>64-bit</b>.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80ab80abd5ec2063b679"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">F</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Biểu diễn kiểu <code class="notion-inline-code">float</code>, một số <b>32-bit</b>.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80a3aa50c906e5316c69"><td class="" style="width:58.65625px"><div class="notion-simple-table-cell">D</div></td><td class="" style="width:634.65625px"><div class="notion-simple-table-cell">Viết tắt của <code class="notion-inline-code">double</code>, một số <b>64-bit</b>.</div></td></tr></tbody></table><div class="notion-text notion-block-4030aff0a13e800c9e1bdf034818ccbc">Ngoài các primitive types, Smali còn hỗ trợ reference types cho objects và arrays:</div><table class="notion-simple-table notion-block-4030aff0a13e807c92c6f7b9cd305cbc"><tbody><tr class="notion-simple-table-row notion-block-4030aff0a13e80beb87ecca3beb8ee1d"><td class="" style="width:65.65625px"><div class="notion-simple-table-cell">Type</div></td><td class="" style="width:629.65625px"><div class="notion-simple-table-cell">Description</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e805a9b45c566489cca77"><td class="" style="width:65.65625px"><div class="notion-simple-table-cell">L</div></td><td class="" style="width:629.65625px"><div class="notion-simple-table-cell">Biểu diễn một object của một lớp cụ thể. Ví dụ, <code class="notion-inline-code">Ljava/lang/String;</code> trỏ tới một object</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8072a42ec05c81675692"><td class="" style="width:65.65625px"><div class="notion-simple-table-cell">[</div></td><td class="" style="width:629.65625px"><div class="notion-simple-table-cell">Biểu diễn một array. Dùng kết hợp với các kiểu khác. Ví dụ, <code class="notion-inline-code">[I</code> là mảng các số nguyên,</div></td></tr></tbody></table><div class="notion-text notion-block-4030aff0a13e807e9d8ec8d9895987f1">Đây là các kiểu dữ liệu chính trong Smali. Đáng chú ý là kiểu <code class="notion-inline-code">J</code> (long) và <code class="notion-inline-code">D</code> (double) mỗi loại chiếm hai registers vì chúng là kiểu dữ liệu 64-bit, trong khi tất cả các kiểu khác chỉ chiếm một register.</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e8068b585dd25a6f85198" data-id="4030aff0a13e8068b585dd25a6f85198"><span><div id="4030aff0a13e8068b585dd25a6f85198" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e8068b585dd25a6f85198" title="Methods and Fields"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Methods and Fields</span></span></h4><div class="notion-text notion-block-4030aff0a13e80c88796d0786675ad94">Các method được định nghĩa bằng directive <code class="notion-inline-code">.method</code>, theo sau là một chuỗi modifiers, tên method, cùng tham số và kiểu trả về của method. Đoạn Smali sau định nghĩa một <b>public static</b> method tên <code class="notion-inline-code">add</code> nhận hai số nguyên làm tham số và trả về một số nguyên:</div><div class="notion-text notion-block-4030aff0a13e8028b462c78e89086e73"><code class="notion-inline-code">.method public static add(II)I</code></div><div class="notion-text notion-block-4030aff0a13e8050b4f7cff0e31683aa">Các method được gọi bằng các lệnh <code class="notion-inline-code">invoke-</code>, chẳng hạn như <code class="notion-inline-code">invoke-virtual</code>, <code class="notion-inline-code">invoke-super</code>, <code class="notion-inline-code">invoke-direct</code>, <code class="notion-inline-code">invoke-static</code>, và <code class="notion-inline-code">invoke-interface</code>. Các lệnh này được theo sau bởi các registers chứa argument cần truyền vào method, cũng như tham chiếu đến chính method đó. Tham chiếu này được tạo nên từ package name (<code class="notion-inline-code">Lpackage/name/</code>), tên class (<code class="notion-inline-code">MyClass</code>), và cuối cùng là method signature (<code class="notion-inline-code">add(II)I</code>):</div><div class="notion-text notion-block-4030aff0a13e800f8232ddcbc843b68a">Trong Smali, các biến thuộc về một class được gọi là fields. Một khai báo field trong Smali gồm các phần sau:</div><table class="notion-simple-table notion-block-4030aff0a13e80a287cfea5be9fbc227"><tbody><tr class="notion-simple-table-row notion-block-4030aff0a13e8086b627d05908b4aa8b"><td class="" style="width:152.65625px"><div class="notion-simple-table-cell">Field Part</div></td><td class="" style="width:560.65625px"><div class="notion-simple-table-cell">Description</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80d0b59bf3863fce5b2e"><td class="" style="width:152.65625px"><div class="notion-simple-table-cell">Class Type</div></td><td class="" style="width:560.65625px"><div class="notion-simple-table-cell">Kiểu của class mà field thuộc về.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e80a5ba04ea35be72e8d9"><td class="" style="width:152.65625px"><div class="notion-simple-table-cell">Field Name</div></td><td class="" style="width:560.65625px"><div class="notion-simple-table-cell">Định danh (identifier) dùng để truy cập field trong class.</div></td></tr><tr class="notion-simple-table-row notion-block-4030aff0a13e8084abc9c2dd2c50f066"><td class="" style="width:152.65625px"><div class="notion-simple-table-cell">Field Type</div></td><td class="" style="width:560.65625px"><div class="notion-simple-table-cell">Kiểu dữ liệu của field. Nó xác định loại dữ liệu field sẽ lưu, chẳng hạn int, float, String, v.v.</div></td></tr></tbody></table><div class="notion-text notion-block-4030aff0a13e804b89bcea55e4708a62">Một tham chiếu field đầy đủ (fully qualified) trông như sau:</div><div class="notion-text notion-block-4030aff0a13e80afa250f2b1d64a41d3"><code class="notion-inline-code">Lpackage/name/ObjectName;-&gt;FieldName:Ljava/lang/String;</code></div><div class="notion-text notion-block-4030aff0a13e80fa8214fffea33c0f4f">Snippet dưới đây định nghĩa một public field tên <code class="notion-inline-code">myString</code> thuộc kiểu <code class="notion-inline-code">String</code>:</div><div class="notion-text notion-block-4030aff0a13e800ea859ce3fb3f2ab2c"><code class="notion-inline-code">.field public myString:Ljava/lang/String;</code></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e80d2885dd32aa8893cd8" data-id="4030aff0a13e80d2885dd32aa8893cd8"><span><div id="4030aff0a13e80d2885dd32aa8893cd8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80d2885dd32aa8893cd8" title="Registers"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Registers</span></span></h4><div class="notion-text notion-block-4030aff0a13e80e7a5d3d87a8d137f93">Trong Smali, giống như nhiều low-level language khác, ta làm việc trực tiếp với các registers để thực hiện thao tác. 
Dalvik bytecode dùng registers thay vì stack để lưu biến và kết quả trung gian. </div><div class="notion-text notion-block-4030aff0a13e80fd9078d81c39d01518">⇒ Hiểu cách các registers này hoạt động là điều then chốt để hiểu mã Smali. Mỗi register trong Dalvik Virtual Machine (DVM) có kích thước <b>32 bits</b> và có thể giữ bất kỳ giá trị nào vừa trong 32 bits đó. Bao gồm các kiểu dữ liệu <b>integer</b>, <b>boolean</b>, <b>floa</b>t, cũng như các <b>tham chiếu đến</b> <b>objects</b> hay <b>arrays</b>. Ví dụ, xét mã Smali sau:</div><div class="notion-text notion-block-4030aff0a13e8071af15dc53b75ac61b"><code class="notion-inline-code">const v0, 10</code></div><div class="notion-text notion-block-4030aff0a13e80d5a738d1032fb430f0">Trong trường hợp này, <code class="notion-inline-code">v0</code> là một register, và giá trị <code class="notion-inline-code">10</code> được lưu vào đó. Với các kiểu dữ liệu cần <b>64 bits</b>, như <b>Long</b> và <b>Double</b>, Dalvik dùng một cặp registers (32 bit thấp của giá trị lưu vào register đầu tiên, và 32 bit cao vào register thứ hai). Ví dụ:</div><div class="notion-text notion-block-4030aff0a13e8095a702e2132afb52cc"><code class="notion-inline-code">const-wide v0, 0x100000000L</code></div><div class="notion-text notion-block-4030aff0a13e80e1aac0ebcfd1e3e615">Ở đây, số 64-bit <code class="notion-inline-code">0x100000000L</code> được lưu trải qua hai registers, <code class="notion-inline-code">v0</code> và <code class="notion-inline-code">v1</code>. Đặc điểm này rất quan trọng cần nhớ khi xử lý các method’s param.</div><div class="notion-text notion-block-4030aff0a13e8086bd12fb7bf7c59aa0">Hãy xét một non-static method: <code class="notion-inline-code">LMyObject;-&gt;MyMethod(IJZ)V</code>. Phương thức này nhận ba tham số: một integer (I), một long (J) và một boolean (Z). Thêm nữa, vì nó là non-static method, có một tham số ngầm định đầu tiên tham chiếu đến instance của chính object đó (<code class="notion-inline-code">LMyObject;</code>). Tổng cộng, phương thức này cần năm registers để giữ tất cả tham số (1-int, 1-boolean, 2-long và 1-cho tham chiếu đến instance của chính Object)</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4030aff0a13e803eab1acc4323d3e87f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A6768e740-0675-4918-a5fb-8f6f63db3f62%3Aimage.png?table=block&amp;id=4030aff0-a13e-803e-ab1a-cc4323d3e87f&amp;t=4030aff0-a13e-803e-ab1a-cc4323d3e87f" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-4030aff0a13e80d39c8ed389fcc90f16" data-id="4030aff0a13e80d39c8ed389fcc90f16"><span><div id="4030aff0a13e80d39c8ed389fcc90f16" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4030aff0a13e80d39c8ed389fcc90f16" title="Method Invocation and Registers"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Method Invocation and Registers</span></span></h4><div class="notion-text notion-block-4030aff0a13e80fba714f072354b5f8f">Trong Smali, <code class="notion-inline-code">p</code> và <code class="notion-inline-code">v</code> biểu diễn hai bộ registers khác nhau (parameter registers và local registers). Các registers <code class="notion-inline-code">p</code> được dùng cho param của method. Việc đánh số của <code class="notion-inline-code">p</code> registers bắt đầu với <code class="notion-inline-code">p0</code>, <code class="notion-inline-code">p1</code>, <code class="notion-inline-code">p2</code>, v.v. Trong các non-static methods, <code class="notion-inline-code">p0</code> là object mà method được gọi trên nó (tương tự this trong Java). Với static methods, <code class="notion-inline-code">p0</code> là param đầu tiên của method. Các registers <code class="notion-inline-code">v</code> được dùng cho biến cục bộ và các tính toán tạm thời bên trong method. Việc đánh số bắt đầu với <code class="notion-inline-code">v0</code>, <code class="notion-inline-code">v1</code>, <code class="notion-inline-code">v2</code>, v.v. Khi gọi một method, các param được truyền qua registers. Các registers <code class="notion-inline-code">p0</code>, <code class="notion-inline-code">p1</code>, <code class="notion-inline-code">p2</code>, <code class="notion-inline-code">pn</code> trỏ đến các param của method. Ví dụ:</div><div class="notion-text notion-block-4030aff0a13e80dfa514d5203687d492"><code class="notion-inline-code">invoke-virtual {p0, v0}, Lcom/example/MyClass;-&gt;myMethod(I)V</code></div><div class="notion-text notion-block-4030aff0a13e80f7bccdd3f18a4719df">Ở đây, <code class="notion-inline-code">p0</code> thường là object instance mà <code class="notion-inline-code">myMethod</code> được gọi trên đó (tương tự this của Java) và <code class="notion-inline-code">v0</code> là tham số nguyên được truyền vào method. Ta cũng thấy rằng tham số nguyên của method là <code class="notion-inline-code">v0</code> chứ không phải <code class="notion-inline-code">p1</code>. Điều này xảy ra vì Dalvik bytecode coi các registers <code class="notion-inline-code">p</code> và <code class="notion-inline-code">v</code> như một phần của cùng một tập hợp. Tham số có thể được gọi bằng tên <code class="notion-inline-code">p</code> hoặc <code class="notion-inline-code">v</code>, vì các phân biệt này chủ yếu được thiết kế để mã Smali dễ đọc hơn.</div><div class="notion-text notion-block-4030aff0a13e80659c45ebaf369d6bd6">Số lượng registers khả dụng được khai báo ở đầu method bằng directive <code class="notion-inline-code">.registers</code>. 
Ví dụ, <code class="notion-inline-code">.registers 5</code> khai báo rằng phương thức dùng <b>5</b> registers — bao gồm cả registers <code class="notion-inline-code">p</code> (tham số) và <code class="notion-inline-code">v</code> (biến cục bộ):</div><div class="notion-text notion-block-4030aff0a13e809ba3f4fd996e2423f7">Directive thay thế <code class="notion-inline-code">.locals</code> chỉ định số lượng registers không phải tham số (non-parameter) trong method:</div><div class="notion-text notion-block-4030aff0a13e80efa623e1a7605cc951">Nếu một non-static method với một tham số khai báo <code class="notion-inline-code">.registers 5</code>, thì <code class="notion-inline-code">p0</code> sẽ là this, <code class="notion-inline-code">p1</code> sẽ là tham số, và <code class="notion-inline-code">v0</code>, <code class="notion-inline-code">v1</code>, <code class="notion-inline-code">v2</code> sẽ khả dụng cho biến cục bộ. Tuy nhiên, về nội bộ, <code class="notion-inline-code">p0</code> cũng chính là <code class="notion-inline-code">v4</code>, <code class="notion-inline-code">p1</code> là <code class="notion-inline-code">v3</code>, <code class="notion-inline-code">v0</code> là <code class="notion-inline-code">v2</code>, <code class="notion-inline-code">v1</code> là <code class="notion-inline-code">v1</code>, và <code class="notion-inline-code">v2</code> là <code class="notion-inline-code">v0</code> (việc mapping được thực hiện theo thứ tự <b>ngược</b>, bắt đầu từ tổng số registers trừ một tính từ p0/this)</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skills Assessment]]></title>
            <link>https://blog.zero-trust.site/article/skills</link>
            <guid>https://blog.zero-trust.site/article/skills</guid>
            <pubDate>Fri, 23 Oct 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[Bài viết tổng hợp toàn bộ các bài thi Skills Assessment của HackTheBox mà tôi đã hoàn thành]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden notion-page-font-mono " style="font-family:iawriter-mono, Nitti, ui-monospace, SFMono-Regular, Menlo, Consolas, &#x27;Liberation Mono&#x27;, Courier, monospace"><main class="notion light-mode notion-page notion-block-4010aff0a13e8047a8a7cf3b27a0efb3"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4020aff0a13e80a495acf5283be9657f"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:432px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ae7d7d708-243b-4afa-baa0-f2ad42c4ca6c%3Aimage.png?table=block&amp;id=4020aff0-a13e-80a4-95ac-f5283be9657f&amp;t=4020aff0-a13e-80a4-95ac-f5283be9657f" alt="notion image" loading="lazy" decoding="async"/></div></figure><a class="notion-page-link notion-block-4010aff0a13e8024a965d41e99c50354" href="/4010aff0a13e8024a965d41e99c50354"><span class="notion-page-title"><div class="notion-page-icon-inline notion-page-icon-span"><img class="notion-page-title-icon notion-page-icon" src="https://www.notion.so/icons/phone_brown.svg?mode=light" alt="Android Application Dynamic Analysis" loading="lazy" decoding="async"/></div><span class="notion-page-title-text"><b>Android Application Dynamic Analysis</b></span></span></a><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4090aff0a13e808c9441ca697f2745fc"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:432px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ac1eb614e-efd1-48ed-bb30-cba0c3658a14%3Aimage.png?table=block&amp;id=4090aff0-a13e-808c-9441-ca697f2745fc&amp;t=4090aff0-a13e-808c-9441-ca697f2745fc" alt="notion image" loading="lazy" decoding="async"/></div></figure><a class="notion-page-link notion-block-4090aff0a13e80d59711e186d1b776b7" href="/4090aff0a13e80d59711e186d1b776b7"><span class="notion-page-title"><div class="notion-page-icon-inline notion-page-icon-span"><img class="notion-page-title-icon notion-page-icon" src="https://www.notion.so/icons/phone_brown.svg?mode=light" alt="Android Application Static Analysis" loading="lazy" decoding="async"/></div><span class="notion-page-title-text">Android Application Static Analysis</span></span></a></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intercepting HTTP/HTTPs Requests]]></title>
            <link>https://blog.zero-trust.site/article/intercept-http-requests</link>
            <guid>https://blog.zero-trust.site/article/intercept-http-requests</guid>
            <pubDate>Sun, 11 Oct 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden notion-page-font-mono " style="font-family:iawriter-mono, Nitti, ui-monospace, SFMono-Regular, Menlo, Consolas, &#x27;Liberation Mono&#x27;, Courier, monospace"><main class="notion light-mode notion-page notion-block-3f20aff0a13e8028b468f78d12dca074"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-3f70aff0a13e80c78b75c2c317dfee6f">Đầu tiên, ta sẽ đến với kĩ thuật <b>Intercept API calls</b></div><a class="notion-page-link notion-block-3f70aff0a13e8039b636cb30ef7399bf" href="/3f70aff0a13e8039b636cb30ef7399bf"><span class="notion-page-title"><div class="notion-page-icon-inline notion-page-icon-image"><svg class="notion-page-title-icon notion-page-icon" alt="Intercepting API Calls" viewBox="0 0 30 30" width="16"><path d="M16,1H4v28h22V11L16,1z M16,3.828L23.172,11H16V3.828z M24,27H6V3h8v10h10V27z M8,17h14v-2H8V17z M8,21h14v-2H8V21z M8,25h14v-2H8V25z"></path></svg></div><span class="notion-page-title-text">Intercepting API Calls</span></span></a><div class="notion-text notion-block-3f70aff0a13e80cd8f2bfb1256b5d123">Lỗ hổng IDOR</div><a class="notion-page-link notion-block-3f70aff0a13e8050a38ef9350552b286" href="/3f70aff0a13e8050a38ef9350552b286"><span class="notion-page-title"><div class="notion-page-icon-inline notion-page-icon-image"><svg class="notion-page-title-icon notion-page-icon" alt="IDOR Attack" viewBox="0 0 30 30" width="16"><path d="M16,1H4v28h22V11L16,1z M16,3.828L23.172,11H16V3.828z M24,27H6V3h8v10h10V27z M8,17h14v-2H8V17z M8,21h14v-2H8V21z M8,25h14v-2H8V25z"></path></svg></div><span class="notion-page-title-text"><b>IDOR Attack</b></span></span></a><div class="notion-text notion-block-4010aff0a13e80b99ae2cb95e8d471eb">Cuối cùng là SSL/TLS Certificate Pinning Bypass</div><a class="notion-page-link notion-block-4010aff0a13e809fa2c0c4300964c550" href="/4010aff0a13e809fa2c0c4300964c550"><span class="notion-page-title"><div class="notion-page-icon-inline notion-page-icon-image"><svg class="notion-page-title-icon notion-page-icon" alt="SSL/TLS Certificate Pinning Bypass" viewBox="0 0 30 30" width="16"><path d="M16,1H4v28h22V11L16,1z M16,3.828L23.172,11H16V3.828z M24,27H6V3h8v10h10V27z M8,17h14v-2H8V17z M8,21h14v-2H8V21z M8,25h14v-2H8V25z"></path></svg></div><span class="notion-page-title-text"><b>SSL/TLS Certificate Pinning Bypass</b></span></span></a></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>