<?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"><channel><title><![CDATA[Rabindra's Blog]]></title><description><![CDATA[Rabindra's Blog]]></description><link>https://blog.rmb.info.np</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 19:42:52 GMT</lastBuildDate><atom:link href="https://blog.rmb.info.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[AWS Community Day CTF Writeups]]></title><description><![CDATA[Writeups for ctf held in AWS community day]]></description><link>https://blog.rmb.info.np/aws-community-day-ctf-writeups</link><guid isPermaLink="true">https://blog.rmb.info.np/aws-community-day-ctf-writeups</guid><category><![CDATA[AWS]]></category><category><![CDATA[CTF]]></category><dc:creator><![CDATA[Rabindra Man Bajracharya]]></dc:creator><pubDate>Mon, 30 Sep 2024 15:25:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1727709374939/c35a18d9-e703-4262-a258-ae88b2f7c7b3.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This Sunday, I had the opportunity to participate in <strong>AWS Community Day Nepal</strong>, and it was an amazing experience filled with engaging talks and events. One of the highlights was the <strong>Capture the Flag</strong> competition, where I participated and secured the <strong>first place</strong>. Below are some writeups of the challenges I tackled during the event.</p>
<h3 id="heading-escape-your-vessel">Escape your vessel</h3>
<p>The challenge description included a link. Upon opening it, I was greeted with a basic web interface. .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727619991916/3d87ffad-e360-438e-87bc-a4b0d8a75b7e.png" alt class="image--center mx-auto" /></p>
<p>Inspecting the source code and checking for common files or directories like <code>/admin</code> and <code>robots.txt</code> yielded no results. So, I decided to fuzz the web server for hidden endpoints.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727620178448/b354ceff-669c-4ef4-97e2-ed604e7b812b.png" alt class="image--center mx-auto" /></p>
<p>Using a common wordlist, I found two endpoints: <code>/health</code> and <code>/hi</code>.</p>
<ul>
<li><p><strong>/health</strong>: This endpoint returned a generic message stating "Site is up"—nothing particularly useful.</p>
</li>
<li><p><strong>/hi</strong>: This endpoint returned an interesting response—"Method not allowed."</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727620285871/1963ceac-a70c-4c75-85bd-8e8848281158.png" alt class="image--center mx-auto" /></p>
<p>After some investigation, I discovered that only <code>POST</code> and <code>OPTIONS</code> methods were accepted on the <code>hi</code> endpoint. I tried various POST parameters, but they all returned the following error. To narrow down the valid parameter, I decided to use fuzzing again. I leveraged a tool called <strong>Arjun</strong>, which scans for potential GET and POST parameters. After running Arjun, I got the breakthrough I needed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727620409237/32b77df4-f9cc-4ed3-b5ed-78780c3aaa6e.png" alt class="image--center mx-auto" /></p>
<p>To narrow down the valid parameter, I decided to use fuzzing again. I made useof a tool called <strong>Arjun</strong>, which scans for potential GET and POST parameters. After running Arjun, I got the parameter I was looking for <code>command</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727620499272/5ee4ee5c-cd80-4ef0-add4-21609e076c9b.png" alt class="image--center mx-auto" /></p>
<p>Due to the obvious name I tried running basic Linux commands and confirmed that we had command execution.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727620577108/74b002c0-2e6b-4619-bcf9-7272f2a527fb.png" alt class="image--center mx-auto" /></p>
<p>Looking around, I realized that I was inside a docker container.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727620669210/19f70c64-916f-4ea5-be02-37243fb61dc2.png" alt class="image--center mx-auto" /></p>
<p>Since the challenge was named <code>Escape your vessel</code> I figured that the flag was in the host machine rather than in the container. So I started to check for hints to access the host machine. First I thought we might get sensitive information by quering to the AWS meta data IP i.e. <a target="_blank" href="http://169.254.169.254/latest/meta-data/iam/">http://169.254.169.254/</a> but it did not lead to anywhere. Then I started to look if any volume has been mounted from our host machine. Looking around I found out that <code>/host</code> was mounted to <code>/</code> of host machine. That gave me access to the host’s filesystem.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621029518/00e01bc3-afe4-422b-b369-585ea3477c6f.png" alt class="image--center mx-auto" /></p>
<p>Once, I had access to the files of host machine, it was a matter of moment before I got the flag. For this, first I checked the <code>.bash_history</code> file of the users i.e <code>root</code> and <code>ubuntu</code> in our case. Looking at <code>ubuntu</code>'s history, I found some juicy information</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621275700/0663ec15-ce0a-4c55-b008-8eea2b29e216.png" alt class="image--center mx-auto" /></p>
<p>With the information found in the bash history, I read the file that was located at <code>/var/log/flag.txt</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621353176/4695d321-1b5e-4885-b7f1-0a5f264ffd8e.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-pwned-the-bucket">Pwned the Bucket</h3>
<p>The challenge description provided a URL <a target="_blank" href="http://ctf.csaju.com/"><code>http://ctf.csaju.com/</code></a> which showed the following:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621472551/6c0b0fba-9a4b-441f-9e00-c62b829ffb8a.png" alt class="image--center mx-auto" /></p>
<p>Initially, I assumed the S3 bucket might be named <a target="_blank" href="http://ctf.csaju.com"><code>ctf.csaju.com</code></a>, as AWS bucket names often follow domain-like structures which was wrong. To identify the correct bucket, I used <code>nslookup</code> to query the canonical name (CNAME) associated with <a target="_blank" href="http://ctf.csaju.com"><code>ctf.csaju.com</code></a>. The DNS resolution indicated that the domain was pointing to an AWS S3 bucket via a CNAME record, which revealed the actual bucket name: <code>awscommunitydayctf</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621609433/c5715769-1e1e-4143-97f2-7187422bc757.png" alt class="image--center mx-auto" /></p>
<p>Upon confirming that the bucket name, I proceeded to enumerate its contents using the AWS CLI. By running the command <code>aws s3 ls s3://awscommunitydayctf/</code>, I confirmed that the bucket was fully exposed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621687030/15accee6-c276-446d-b7bd-30b2e299790f.png" alt class="image--center mx-auto" /></p>
<p>So, I went ahead and downloaded all the content of the bucket to my machine.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621858061/88f3a592-b02b-4f19-8492-8d33748b7037.png" alt class="image--center mx-auto" /></p>
<p>Looking around I found the flag at <code>pdf/main.inc</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727621898423/4ff4dbff-11d6-4790-a885-0898a6a36684.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-mistaken-image">Mistaken Image</h3>
<p>In this challenge, a link to the Github repo was given which contained the text <code>r4s1p1w2/awscloudclubnepal</code> in the <code>README.md</code> file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727709518433/37545155-345c-43a7-b645-64feca843426.png" alt class="image--center mx-auto" /></p>
<p>The challenge hinted about ECR in its description. So I directly started to check if it was a publicly accessible ECR image. I navigated to <a target="_blank" href="http://gallery.ecr.aws"><code>gallery.ecr.aws</code></a> and checked for <code>awscloudclubnepal</code> as a public repository. And to no one’s surprise, it was indeed a publicly available image.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727622214519/643e7023-6846-41b6-b23b-d7dfad60245a.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727622262685/d2614f2f-d2ac-4fdf-822f-68ce9db01948.png" alt class="image--center mx-auto" /></p>
<p>Once I located the publicly available container,hen I pulled the docker image to my local machine</p>
<pre><code class="lang-plaintext">docker pull public.ecr.aws/r4s1p1w2/awscloudclubnepal:latest
</code></pre>
<p>After I pulled the image, it was fairly simple enough to get inside the docker container and grab the flag located at <code>/flag/flag.txt</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727622484602/91cb4ea6-7053-407a-954d-b5f757d09d99.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-balti">Balti</h3>
<p>The challenge description provied an Android app and hinted about reverse engineering the app to find something useful.</p>
<p>So, I downloaded the android apk provided in the challenge description and ran it through JADX decompiler. Poking and looking around, I stumbled accross this file at <code>com.example.oggybhai/aws.java</code> which seem to contain AWS access key and secret key.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727623300173/c61317cc-c15e-430b-9ef1-91c085a9fa06.png" alt class="image--center mx-auto" /></p>
<p>On my local machine I setup the AWS CLI with the found credentials and checked if the creds were working with the following command. This revealed that indeed, the credentials were working and the username of the account was <code>mobile</code></p>
<pre><code class="lang-plaintext">➜  awsctf aws sts get-caller-identity
{
    "UserId": "AIDAUGO4KMZB4PGSYXVZZ",
    "Account": "288761734723",
    "Arn": "arn:aws:iam::288761734723:user/mobile"
}
</code></pre>
<p>Since the challenge was named <code>Balti</code> which means bucket in Nepali, I looked if there were any buckets available.</p>
<pre><code class="lang-plaintext">➜  awsctf aws s3 ls
An error occurred (AccessDenied) when calling the ListBuckets operation: User: arn:aws:iam::288761734723:user/mobile is not authorized to perform: s3:ListAllMyBuckets because no identity-based policy allows the s3:ListAllMyBuckets action
</code></pre>
<p>Seeing that access to <code>list</code> bucket was not available, I checked what policies this account was attached to.</p>
<pre><code class="lang-plaintext">➜  awsctf aws iam list-attached-user-policies --user-name mobile
{
    "AttachedPolicies": [
        {
            "PolicyName": "oggy_bhai",
            "PolicyArn": "arn:aws:iam::288761734723:policy/oggy_bhai"
        },
        {
            "PolicyName": "IAMReadOnlyAccess",
            "PolicyArn": "arn:aws:iam::aws:policy/IAMReadOnlyAccess"
        }
    ]
}
</code></pre>
<p>The first policy seemed interesting. So I digged deeper to check the contents of the policy.</p>
<pre><code class="lang-plaintext"> ➜  aws iam get-policy-version --policy-arn arn:aws:iam::288761734723:policy/oggy_bhai --version-id v11
 {
    "PolicyVersion": {
        "Document": {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Sid": "AllowSpecificBucketActions",
                    "Effect": "Allow",
                    "Action": [
                        "s3:GetObject",
                        "s3:ListBucket"
                    ],
                    "Resource": [
                        "arn:aws:s3:::oggyandcockroachesbucket",
                        "arn:aws:s3:::oggyandcockroachesbucket/*"
                    ]
                },
                {
                    "Sid": "AllowIAMPolicyReadAccess",
                    "Effect": "Allow",
                    "Action": [
                        "iam:GetPolicy",
                        "iam:GetPolicyVersion"
                    ],
                    "Resource": "arn:aws:iam::288761734723:policy/oggy_bhai"
                }
            ]
        },
        "VersionId": "v11",
        "IsDefaultVersion": true,
        "CreateDate": "2024-09-27T11:11:45+00:00"
    }
}
</code></pre>
<p>Looking at the policy, I found out that the account <code>mobile</code> had permissions to view and download contents of the S3 bucket <code>oggyandcockroachesbucket</code>. So I checked the mentioned bucket contents and found a file <code>oggy.txt</code>. Wrapping the text in flag format, I submitted the flag successfully.</p>
<pre><code class="lang-plaintext">➜  aws s3 ls s3://oggyandcockroachesbucket
2024-09-19 15:15:14         17 oggy.txt
➜  aws s3 sync s3://oggyandcockroachesbucket .
download: s3://oggyandcockroachesbucket/oggy.txt to ./oggy.txt
➜  cat oggy.txt
tLgxjcbrlmkAoYdR
</code></pre>
<h3 id="heading-serverless">Serverless</h3>
<p>The following Github repository was linked in the challenge description</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727704474746/61022d74-221d-448a-8342-764ad563f189.png" alt class="image--center mx-auto" /></p>
<p>Checking the commit history of the repo, we find an interesting commit message</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727704509517/817246a6-37a4-4940-8679-ac074f159f37.png" alt class="image--center mx-auto" /></p>
<p>First I thought it was some base64 encoded text but on closer inspection I found it to be <code>access id</code> and <code>secret token</code> of an AWS ac. So I updated my AWS CLI credentials to include it and ran some commands to verify it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727704666993/610b2c0e-93f4-4cd6-ba42-ba4a01ee106d.png" alt class="image--center mx-auto" /></p>
<p>Once the credentials was setup, I directly started looking at lambda functions as the challenge was named <code>serverless</code>. Upon enumerating all the lambda functions available, I found flag in the environment variable section of description of Lambda function called <code>EnvBreaches</code></p>
<pre><code class="lang-plaintext">➜ aws lambda list-functions --region ap-south-1
{
    "Functions": [
        {
            "FunctionName": "EnvBreaches",
            "FunctionArn": "arn:aws:lambda:ap-south-1:288761734723:function:EnvBreaches",
            "Runtime": "python3.10",
            "Role": "arn:aws:iam::288761734723:role/service-role/EnvBreaches-role-9b68sucr",
            "Handler": "lambda_function.lambda_handler",
            "CodeSize": 420,
            "Description": "A starter AWS Lambda function.",
            "Timeout": 3,
            "MemorySize": 128,
            "LastModified": "2024-09-24T11:26:41.000+0000",
            "CodeSha256": "v1xwIoDXIUeuD0DlTfWkCCHYaQpg/RAtlvvfc1IfpV4=",
            "Version": "$LATEST",
            "Environment": {
                "Variables": {
                    "SECRET_KEY": "CTF{wow_congrats}"
                }
            },
            "TracingConfig": {
                "Mode": "PassThrough"
            },
</code></pre>
<h3 id="heading-exposed-volume">Exposed Volume</h3>
<p>The main event site was given in the challenge description i.e.<a target="_blank" href="https://awscloudclubnepal.com/robots.txt">https://awscloudclubnepal.com</a>. Checking the <code>robots.txt</code> in the main website, I found the following contents</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705338119/a1e10b86-4b79-4913-a988-b2332804d541.png" alt class="image--center mx-auto" /></p>
<p>What I found suspicious was the last entry i.e. <code>#backup: snap-0cfd61c21e57c8138</code>. This looked like a snapshot id of EBS volume. To confirm my suspicions, I opened my AWS account and started the search for the given snapshot id and my guess was correct. There was a valid snapshot with the given id.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705562394/58fbbf06-e1bc-4cdb-88c2-95aadc25d2e8.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705608795/61ad1614-40e3-4e07-9e32-8fc24b24eb27.png" alt class="image--center mx-auto" /></p>
<p>So the next step was to create a volume using the snapshot.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705669524/db72cee0-0f54-4255-9bd8-d25fbabbfa2e.png" alt class="image--center mx-auto" /></p>
<p>Once the volume was created, I thought of launching a new EC2 instance and attaching our new created volume to check its contents.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705735778/10d33d4c-05d9-46c3-87cb-d85be9fb6ea3.png" alt class="image--center mx-auto" /></p>
<p>So I very quickly created a ubuntu EC2 instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705823011/3509f67f-e74c-4ecb-ad6d-b9924c5dd7d3.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705981015/4873e8df-45b8-4a47-acf1-6f220eb81749.png" alt class="image--center mx-auto" /></p>
<p>Then I went and attached our volume we created using snapshot to the EC2 instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727705880443/5eaaefd4-a298-4a6c-b09d-4e4e2ee3ab6b.png" alt class="image--center mx-auto" /></p>
<p>After attaching the volume to our EC2 instance, I created a mount directory and mounted the volume. Looking at the contents inside the volume, I found a file called <code>flag.txt</code> which contained the flag.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727706198036/f4ab68a3-1b59-4a0f-8512-d88e87d436d1.png" alt class="image--center mx-auto" /></p>
<p>Overall, AWS Community Day Nepal was a fantastic experience that not only enhanced my technical skills but also allowed me to connect with like-minded individuals in the community. The Capture the Flag event was challenging and rewarding, and I'm looking forward to more such opportunities in the future. Kudos to everyone involved at the event.</p>
]]></content:encoded></item><item><title><![CDATA[NCA CTF Writeup]]></title><description><![CDATA[writeups of some challenges of nca ctf 2024]]></description><link>https://blog.rmb.info.np/nca-ctf-writeup</link><guid isPermaLink="true">https://blog.rmb.info.np/nca-ctf-writeup</guid><category><![CDATA[CTF Writeup]]></category><category><![CDATA[CTF]]></category><dc:creator><![CDATA[Rabindra Man Bajracharya]]></dc:creator><pubDate>Thu, 26 Sep 2024 09:28:53 GMT</pubDate><content:encoded><![CDATA[<p>We had a chance to participate in the NCA CTF last weekend in which we managed to secure the win. Following are some of the solutions to the CTF challenges that were present in the platform.</p>
<h2 id="heading-web-challenges">Web Challenges</h2>
<h3 id="heading-robotbase">RobotBase</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727067021002/c5c92d51-44e9-42aa-b71f-5542629e1bda.png" alt class="image--center mx-auto" /></p>
<p>Opening the link, we were greeted with a login button that lead to login panel which looked like</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727067803670/57194989-2d3e-48b2-b7b7-afcde9eb0ff9.png" alt class="image--center mx-auto" /></p>
<p>As the name of the challenge suggested, the first thing I checked was for <code>robots.txt</code></p>
<p>The following entries were present in it.</p>
<pre><code class="lang-plaintext">User-agent: *
Disallow: /robot-db/
</code></pre>
<p>Browsing <code>/robot-db</code> led to the download of file <code>w0_robotdb.db</code></p>
<p>Running <code>file</code> command, we get the following output</p>
<pre><code class="lang-plaintext">┌──(root💀adm-StomachUniverse)-[~/ctf/writeups]
└─# file w0_robotdb.db                              
w0_robotdb.db: SQLite 3.x database, last written using SQLite version 3046001, page size 8192, file counter 11, database pages 4, 1st free page 3, free pages 2, cookie 0x5, schema 4, UTF-8, version-valid-for 11
</code></pre>
<p>From the file output, it was clear that this was a SQLite database. So I quickly loaded the file on an online SQLite viewer. Looking through the rows present in the table, I stumbled across the most likely credentials which was stored without any encryption/hashing mechanism.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727067908237/30fd8a53-e24f-4285-b513-7eed4d62ef22.png" alt class="image--center mx-auto" /></p>
<p>Logging in with credentials <code>fl4g:asudfgr3456_g1v3_m3_th3_fl4g_x435naslkjf</code>, we successfully get the flag.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727067974926/0d01fe00-78f3-41c1-9006-e1991f4315bf.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-epic-glitch">Epic Glitch</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727068031556/35b55853-f69f-4bb8-a8bf-6a0bcc00408e.png" alt class="image--center mx-auto" /></p>
<p>The challenge had a file <code>Epic-Glitch.zip</code> attached to it. Upon inspecting, the zip file seem to contain the source of web application which was a basic Flask application.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727068154233/41cd3d5a-dc73-4634-b839-0575b83f0fcd.png" alt class="image--center mx-auto" /></p>
<p>The contents of the file <code>app.py</code> were</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask, render_template, request, redirect, url_for, session, make_response
<span class="hljs-keyword">import</span> sqlite3
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> base64

app = Flask(__name__)
app.secret_key = os.urandom(<span class="hljs-number">16</span>)

SECRET_KEY = <span class="hljs-string">b'REDACTED'</span> <span class="hljs-comment">## REDACTED, SHHHHHHHHHHHH IT'S SECRET</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">xor</span>(<span class="hljs-params">data, key</span>):</span>
    <span class="hljs-keyword">return</span> bytes(a ^ b <span class="hljs-keyword">for</span> a, b <span class="hljs-keyword">in</span> zip(data, key * (len(data) // len(key) + <span class="hljs-number">1</span>)))

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create_token</span>(<span class="hljs-params">username, uid</span>):</span>
    token_data = <span class="hljs-string">f'{{"username": "<span class="hljs-subst">{username}</span>", "uid": <span class="hljs-subst">{uid}</span>}}'</span>.encode()
    encrypted_token = xor(token_data, SECRET_KEY)
    <span class="hljs-keyword">return</span> base64.b64encode(encrypted_token).decode()

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">decode_token</span>(<span class="hljs-params">token</span>):</span>
    encrypted_token = base64.b64decode(token)
    decrypted_token = xor(encrypted_token, SECRET_KEY)
    <span class="hljs-keyword">return</span> decrypted_token.decode()

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_db_connection</span>():</span>
    conn = sqlite3.connect(<span class="hljs-string">'ctf.db'</span>)
    conn.row_factory = sqlite3.Row
    <span class="hljs-keyword">return</span> conn

<span class="hljs-meta">@app.route('/')</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span>():</span>
    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'dummy.html'</span>)

<span class="hljs-meta">@app.route('/register', methods=['GET', 'POST'])</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">register</span>():</span>
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">'POST'</span>:
        username = request.form[<span class="hljs-string">'username'</span>]
        password = request.form[<span class="hljs-string">'password'</span>]

        <span class="hljs-keyword">if</span> username == <span class="hljs-string">'admin'</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-string">"Username 'admin' is already taken."</span>, <span class="hljs-number">400</span>

        conn = get_db_connection()
        conn.execute(<span class="hljs-string">"INSERT INTO users (username, password, uid) VALUES (?, ?, ?)"</span>,
                     (username, password, <span class="hljs-number">1</span>))
        conn.commit()
        conn.close()

        <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">'login'</span>))

    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'register.html'</span>)

<span class="hljs-meta">@app.route('/login', methods=['GET', 'POST'])</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span>():</span>
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">'POST'</span>:
        username = request.form[<span class="hljs-string">'username'</span>]
        password = request.form[<span class="hljs-string">'password'</span>]

        conn = get_db_connection()
        user = conn.execute(<span class="hljs-string">'SELECT * FROM users WHERE username = ? AND password = ?'</span>, (username, password)).fetchone()
        conn.close()

        <span class="hljs-keyword">if</span> user:
            token = create_token(user[<span class="hljs-string">'username'</span>], user[<span class="hljs-string">'uid'</span>])
            response = make_response(redirect(url_for(<span class="hljs-string">'dashboard'</span>)))
            response.set_cookie(<span class="hljs-string">'auth_token'</span>, token)
            <span class="hljs-keyword">return</span> response
        <span class="hljs-keyword">else</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-string">"Invalid credentials"</span>, <span class="hljs-number">403</span>

    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">'login.html'</span>)

<span class="hljs-meta">@app.route('/dashboard')</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">dashboard</span>():</span>
    auth_token = request.cookies.get(<span class="hljs-string">'auth_token'</span>)

    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> auth_token:
        <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">'login'</span>))

    <span class="hljs-keyword">try</span>:
        user_info = decode_token(auth_token)
        <span class="hljs-comment"># the uid is 0 below</span>
        <span class="hljs-keyword">if</span> <span class="hljs-string">'"uid": 0'</span> <span class="hljs-keyword">in</span> user_info:
            <span class="hljs-keyword">return</span> <span class="hljs-string">"nca{f4k3_fl4g_f0r_t35t1ng}"</span>
        <span class="hljs-keyword">else</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-string">"What are you looking for? The flag? :D"</span>
    <span class="hljs-keyword">except</span> Exception:
        <span class="hljs-keyword">return</span> <span class="hljs-string">"Invalid token"</span>, <span class="hljs-number">400</span>

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    app.run(debug=<span class="hljs-literal">False</span>)
</code></pre>
<p>So in a nutshell, the file contained logic of different pages within the website like login, register, dashboard pages etc. Looking at the <code>dashboard()</code> function, we find out that if we have <code>auth-token</code> cookie in our request whose decoded value contains <code>uid</code> with value <code>0</code> we will get the flag. So with this, I started to look at the <code>register()</code> logic and I found out that all the default users were getting id of 1.</p>
<pre><code class="lang-python"> conn.execute(<span class="hljs-string">"INSERT INTO users (username, password, uid) VALUES (?, ?, ?)"</span>,
                     (username, password, <span class="hljs-number">1</span>))
</code></pre>
<p>Once the user was created, we could login using the credentials. The login function called <code>create_token()</code> function to create auth token using the user information recieved from database. Inspecting the <code>create_token()</code> function we see that, the user information was being <code>XORED</code> and then <code>base64</code> encoded.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create_token</span>(<span class="hljs-params">username, uid</span>):</span>
    token_data = <span class="hljs-string">f'{{"username": "<span class="hljs-subst">{username}</span>", "uid": <span class="hljs-subst">{uid}</span>}}'</span>.encode()
    encrypted_token = xor(token_data, SECRET_KEY)
    <span class="hljs-keyword">return</span> base64.b64encode(encrypted_token).decode()
</code></pre>
<p>So the plan here is simple, we need to create a new user and generate token. The token would be <strong>ciphertext</strong> while the <strong>plaintext</strong> would be `<code>{{"username": "{our_username}", "uid": {uid}}}</code> . Once we have the <strong>ciphertext</strong> and <strong>plaintext</strong> we can easily retrieve the key.</p>
<p>So I created a new user with username <code>nepal</code> and got this token</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727080100194/e2cd045a-e023-4db4-8606-36d5eb7ac9d6.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727080164784/23d4a080-7061-4616-aa01-6fc3058a8792.png" alt class="image--center mx-auto" /></p>
<p><code>C0cHABUXDRUEE0dKRVAdFRUCGEtaRVIQGxdSX0NFFA==</code> which is our ciphertext. Meanwhile, our plaintext now is <code>{{"username": "nepal", "uid": 1}</code>. To get the key, we can first base64 decode our token and <code>XOR</code> the result with our plaintext. Following script does the operation.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> base64

token = <span class="hljs-string">"C0cHABUXDRUEE0dKRVAdFRUCGEtaRVIQGxdSX0NFFA=="</span>
decoded_token = base64.b64decode(token)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">xor</span>(<span class="hljs-params">data, key</span>):</span>
    <span class="hljs-keyword">return</span> bytes(a ^ b <span class="hljs-keyword">for</span> a, b <span class="hljs-keyword">in</span> zip(data, key * (len(data) // len(key) + <span class="hljs-number">1</span>)))

plaintext_str = <span class="hljs-string">f'{{"username": "nepal", "uid": 1}}'</span>
plaintext = plaintext_str.encode()
key = xor(decoded_token, plaintext)
print(<span class="hljs-string">f": Key <span class="hljs-subst">{key}</span>"</span>)
</code></pre>
<p>Running the above script we, get result as : <code>Key b'perspectiveperspectiveperspecti'</code></p>
<p>Here’s a cyberchef <a target="_blank" href="https://gchq.github.io/CyberChef/#recipe=From_Base64\('A-Za-z0-9%2B/%3D',true,false\)XOR\(%7B'option':'UTF8','string':'%7B%22username%22:%20%22nepal%22,%20%22uid%22:%201%7D'%7D,'Standard',false\)&amp;input=QzBjSEFCVVhEUlVFRTBkS1JWQWRGUlVDR0V0YVJWSVFHeGRTWDBORkZBPT0">recipe</a> to do the same.</p>
<p>Thus our key is <code>perspective</code> Now using the key we can forge a new token with with <code>uid</code> 0 using our new found new found key. So simple we XOR <code>{"username": "nepal", "uid": 0}</code> with key perspective. Notice the uid has been changed to 0. Then we simply base64encode it. The cyberchef recipe to perform this operation is <a target="_blank" href="https://gchq.github.io/CyberChef/#recipe=XOR\(%7B'option':'UTF8','string':'perspective'%7D,'Standard',false\)To_Base64\('A-Za-z0-9%2B/%3D'\)&amp;input=eyJ1c2VybmFtZSI6ICJuZXBhbCIsICJ1aWQiOiAwfQ&amp;oeol=VT">here</a>.</p>
<p>Once we have forged the token, we can replace it in our <code>auth_token</code> to recieve the flag</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727080277655/dd58622b-1312-4369-97f0-c22e70176a3d.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-my-name-is-marie-biscuit-v2">My Name is Marie Biscuit V2</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727080348337/dfddca01-4338-427b-8870-4bfea803291e.png" alt class="image--center mx-auto" /></p>
<p>The link contained a simple login panel. Using the credentials provided in the description, I was able to login and got this screen.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727227686852/0f8ea305-3455-4eac-8447-56164393d816.png" alt class="image--center mx-auto" /></p>
<p>From the challenge name, it looked like a challenge related to cookie, so I started checking out the cookie. The cookie contained a <code>JWT</code> token.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727227769630/7cebc2d6-0650-43b9-917f-3cf94fe1dcde.png" alt class="image--center mx-auto" /></p>
<p>I double checked using the <code>jwt.io</code> to ensure it was a <code>JWT</code> token.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727227824101/60bb296f-0033-47db-a61e-90eee06486dd.png" alt class="image--center mx-auto" /></p>
<p>Looking at the payload field, I guessed that if we somehow managed forge a token with username <code>admin</code> we would probably get the flag. For this we needed the secret key that was used to sign the <code>JWT</code> token. So, I launched <code>JohnTheRipper</code> with the <code>rockyou.txt</code> wordlist and started bruteforcing. After few seconds, I got the following output.</p>
<pre><code class="lang-plaintext">┌──(root💀adm-StomachUniverse)-[~/ctf]
└─# john jwt.txt --wordlist=~/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (HMAC-SHA256 [password is key, SHA256 512/512 AVX512BW 16x])
Will run 32 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
cybernepal       (?)     
1g 0:00:00:04 DONE (2024-09-25 01:33) 0.2272g/s 2025Kp/s 2025Kc/s 2025KC/s dany12_..crompond
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
</code></pre>
<p>So the secret used to the sign the token was <code>cybernepal</code>. With this I created a new token with username <code>admin</code> on the payload field.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727228125139/fa9200a2-df50-4fe8-9a71-1793b6d54b4c.png" alt class="image--center mx-auto" /></p>
<p>Using the newly forged token on the cookie, I was able to get the flag.</p>
<pre><code class="lang-plaintext">┌──(root💀adm-StomachUniverse)-[~/ctf]
└─# curl -H "Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNzI3MjMxMjQzfQ.ssSTMaEIJYABTNX50wSSo2-XNHvzrZ4nOtnvBJHlGuw" http://147.79.67.234:2332/ | grep nca
        &lt;h3&gt;nca{m4rr13_b15cu1t_l0v3rs_h3r3_b0155}&lt;/h3&gt;
</code></pre>
<h3 id="heading-mero-kitab">Mero Kitab</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727228290697/71e541cc-3c15-401b-b42b-1ff8d447d69f.png" alt class="image--center mx-auto" /></p>
<p>Opening the link, we see the following prompt that asks to specify a username in base64 format.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727228393329/18121b3c-736d-4c41-afc7-d75cd47f0b4e.png" alt class="image--center mx-auto" /></p>
<p>Clicking on the example, a GET request is made to</p>
<p><a target="_blank" href="http://147.79.67.234:3223/?username=aGFyaWJhaGFkdXI="><code>http://147.79.67.234:3223/?username=aGFyaWJhaGFkdXI=</code></a></p>
<p>The username consisted the string <code>haribahadur</code> in base64 format and the output of page looked like.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727229470912/0253e81a-bbff-474a-9d6c-d6eabd3882f6.png" alt class="image--center mx-auto" /></p>
<p>I quickly base64 encoded <code>hello</code> and tested it.</p>
<p><a target="_blank" href="http://147.79.67.234:3223/?username=aGVsbG8="><code>http://147.79.67.234:3223/?username=aGVsbG8=</code></a> and got similar result like the previous one that said <code>No kitab available for you</code></p>
<p>Trying base64 encoded <code>admin</code> i.e. <code>YWRtaW4=</code> led to error which was pretty suprising. URL encoding the last character still led to error.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1727228709300/4131967d-f815-4d84-8a63-6087af8681ea.png" alt class="image--center mx-auto" /></p>
<p>I tried appending <code>’</code> to the encoded value thinking it could be some form of SQL Injection and suprisingly got the flag.</p>
<p><a target="_blank" href="http://147.79.67.234:3223/?username=YWRtaW4%3d--"><code>http://147.79.67.234:3223/?username=YWRtaW4='</code></a></p>
<p>At the time of writing this writeup I have noticed that, the vulnerability probably has nothing to do with SQL injection. As all of following payloads lead to the flag.</p>
<p><code>GET /?username=YWRtaW4%3d</code></p>
<p><code>GET /?username=YWRtaW4%</code></p>
<p>Another pattern I found was <code>admin</code> encoded in base64 + special character also led to flag. Examples:</p>
<p><code>GET /?username=YWRtaW4=$</code></p>
<p><code>GET /?username=YWRtaW4=@</code></p>
<p><code>GET /?username=YWRtaW4=.</code></p>
<p>My guess would it be adding the characters somehow bypassed the <code>admin</code> blacklisting.</p>
]]></content:encoded></item><item><title><![CDATA[Using Github Actions to track Daraz  ~ Part 1]]></title><description><![CDATA[Greetings, everyone. I hope you are doing well. This blog will be an introduction to using Github Actions and common Linux tools for automation and…]]></description><link>https://blog.rmb.info.np/using-github-actions-to-track-daraz-part-1</link><guid isPermaLink="true">https://blog.rmb.info.np/using-github-actions-to-track-daraz-part-1</guid><category><![CDATA[automation]]></category><category><![CDATA[Scraping]]></category><dc:creator><![CDATA[Rabindra Man Bajracharya]]></dc:creator><pubDate>Mon, 18 Mar 2024 17:25:20 GMT</pubDate><content:encoded><![CDATA[<p>Greetings, everyone. I hope you are doing well. This blog will be an introduction to using Github Actions and common Linux tools for automation and scraping in general. I have decided to demonstrate how to make a simple price tracker of Daraz that will notify the user on price reduction.</p>
<p>So let us begin with the scraping part. For the tutorial I have selected a random item with URL <a target="_blank" href="https://www.daraz.com.np/products/mi-xiaomi-router-ac1200-4-antenna-xiaomi-wifi-router-i120336993-s1032855436.html">https://www.daraz.com.np/products/mi-xiaomi-router-ac1200-4-antenna-xiaomi-wifi-router-i120336993-s1032855436.html</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710776892433/4cd4808c-7b41-4b7b-bbb5-199996de3d4d.png" alt class="image--center mx-auto" /></p>
<p>The price of the item is marked as 5499, so we need to check out the source code looking for it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710777159224/2352f8c0-9edd-4019-8eaa-db41672f3e40.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710777189488/54b7012e-9d7e-4797-9b9f-076326320c36.png" alt class="image--center mx-auto" /></p>
<p>So, apparently the price of the item is stored in key value pairs with keys being <code>value</code> and <code>priceNumber</code>. We shall proceed with priceNumber for the sake of simplicity in this tutorial. (Note:Here the remaning two hits are exact copies of <code>value</code> and <code>priceNumber</code> )</p>
<p>Let us cook up a simple regex that searches for word <code>priceNumber</code> and digits after it.</p>
<p>The regex I came up for this looks like <code>priceNumber":[0-9]+</code>. Now let's grep to check the pattern.</p>
<p>Explanation:</p>
<ul>
<li><p><code>priceNumber":</code> matches the literal string "priceNumber":</p>
</li>
<li><p><code>[0-9]+</code> matches one or more digits.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710778810461/e060c985-726a-4a78-acae-567608ce9544.png" alt class="image--center mx-auto" /></p>
<p>As we can see, the pattern is being matched but there are duplicate results. Simply using <code>sort -u</code> on the result fixes this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710778947229/692b3afd-b764-48e0-b0a3-2e7c50c5ff3a.png" alt class="image--center mx-auto" /></p>
<p>. Now we shall grab the price portion only from the result. This is pretty easy to do using <code>cut</code> command</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710779039711/6e46a5fc-21de-4bdb-8d91-32f03f0837ec.png" alt class="image--center mx-auto" /></p>
<p>Explanation</p>
<p><code>-d</code> is used to specify the delimiter used to split our string. It is <code>:</code> in our case.</p>
<p><code>-f</code> is used to select the second element of the splitted string. Here <code>priceNumber"</code> is the first element and the price is second element.</p>
<p>Alright, we are done with the scraping portion. Now let us use github actions to track the price daily and send us notification if the price reduces. So what is Github Actions? GitHub Actions is a feature of GitHub that allows you to automate workflows directly within your GitHub repository. With GitHub Actions, you can build, test, and deploy your code right from GitHub. It's essentially a CI/CD (Continuous Integration/Continuous Deployment) service that is tightly integrated with your repository. If you want to learn more about Github Actions, please check out <a target="_blank" href="https://docs.github.com/en/actions/learn-github-actions">this</a> official tutorial by Github.</p>
<p>An event triggers a workflow run. Events can be various GitHub activities, such as pushing code to a repository, creating a pull request, or releasing a new version. For our small monitoring project, we will be using the schedule event. The <code>schedule</code> event allows you to trigger a workflow at a scheduled time. The <code>schedule</code> can trigger a workflow to run at specific UTC times using cron syntax. Here's the basic syntax of schedule event:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">on:</span>
  <span class="hljs-attr">schedule:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-attr">cron:</span> <span class="hljs-string">'30 5 * * *'</span>
<span class="hljs-attr">jobs:</span>
<span class="hljs-string">//do</span> <span class="hljs-string">some</span> <span class="hljs-string">job</span>
</code></pre>
<p>I want the price to be fetched every day at 9am. The cron syntax for this would be</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710780420977/49ec0357-2e21-432f-beab-0d2f53778d86.png" alt class="image--center mx-auto" /></p>
<p>The issue here is that this is for UTC timing and not my local time i.e. (GMT +5:45). So the correct cron syntax would be <code>45 3 * * *</code></p>
<p>To get this to, you subtract the offset from GMT, which is +5 hours and 45 minutes.</p>
<p>9:00 AM minus 5 hours and 45 minutes equals 3:15 AM. So, the equivalent time in GMT is 3:15 AM, and the cron schedule becomes <code>45 3 * * *</code>.This schedule will run every day at 3:45 AM GMT, which is equivalent to 9:00 AM in my local time zone (GMT+5:45).</p>
<p>Now that we are done with the configuring schedule of the workflow, we shall create a job that uses our previously crafted scraping command. The job looks like</p>
<pre><code class="lang-yaml"><span class="hljs-attr">jobs:</span>
  <span class="hljs-attr">scrap-price:</span>
    <span class="hljs-attr">runs-on:</span> <span class="hljs-string">ubuntu-latest</span>
    <span class="hljs-attr">steps:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-attr">run:</span> <span class="hljs-string">curl</span> <span class="hljs-string">-s</span> <span class="hljs-string">"https://www.daraz.com.np/products/mi-xiaomi-router-ac1200-4-antenna-xiaomi-wifi-router-i120336993-s1032855436.html"</span> <span class="hljs-string">|</span>  <span class="hljs-string">grep</span> <span class="hljs-string">-oE</span> <span class="hljs-string">'priceNumber":[0-9]+'</span> <span class="hljs-string">|</span> <span class="hljs-string">sort</span> <span class="hljs-string">-u</span> <span class="hljs-string">|</span> <span class="hljs-string">cut</span> <span class="hljs-string">-d</span> <span class="hljs-string">":"</span> <span class="hljs-string">-f</span> <span class="hljs-number">2</span>
</code></pre>
<p>But all this job does is run the command. It doesn't store it or neither does it compares the price with anything. So let's simply use the power of bash scripting for this. First we store the output of command into a variabl</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710781711605/e6608eca-33c2-44c3-ba64-c48e6400a348.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710781720029/28a19e82-34b6-4fb9-a13e-d8fa5e0e8bff.png" alt class="image--center mx-auto" /></p>
<p>Now we will use a simple if-else statement to check if the price variable is less than our specified value</p>
<p><code>if [ "$price" -lte 5200 ]; then echo "Price has reduced" fi</code></p>
<p>We want us to be notified when the price has gone down to our budget. For this I will be sending message to my private telegram channel using the <a target="_blank" href="https://core.telegram.org/#getting-started">Telegram API</a>. The endpoint to send message looks like <a target="_blank" href="https://api.telegram.org/bot[ApiKey]/sendMessage?chat_id=[chatID]&amp;text=[message]"><code>https://api.telegram.org/bot[ApiKey]/sendMessage?chat_id=[chatID]&amp;text=[message]</code></a>. So let's insert this in our if condition.</p>
<p><code>if [ "$price" -lte 5200 ]; then curl -s "</code><a target="_blank" href="https://api.telegram.org/bot[ApiKey]/sendMessage?chat_id=[chatID]&amp;text=[message]"><code>https://api.telegram.org/bot[ApiKey]/sendMessage?chat_id=[chatID]&amp;text=[message]</code></a><code>" fi</code> . This should notify us in Telegram when the price of the item has reached 5200 or less. Now let's wrap this entire command in our github actions yaml file.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">on:</span>
  <span class="hljs-attr">schedule:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-attr">cron:</span> <span class="hljs-string">'45 3 * * *'</span>
<span class="hljs-attr">jobs:</span>
  <span class="hljs-attr">scrap-price:</span>
    <span class="hljs-attr">runs-on:</span> <span class="hljs-string">ubuntu-latest</span>
    <span class="hljs-attr">steps:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Scrap</span> <span class="hljs-string">and</span> <span class="hljs-string">compare</span> <span class="hljs-string">price</span>
      <span class="hljs-attr">run:</span> <span class="hljs-string">|
        price=$(curl -s "url" | grep -oE 'priceNumber":[0-9]+' | sort -u | cut -d ":" -f 2)
        if [ "$price" -le 5200 ]; then
          curl -s "https://api.telegram.org/bot[ApiKey]/sendMessage?chat_id=[chatID]&amp;text=Price is less than or equal to 5200"
        fi</span>
</code></pre>
<p>And with that we are done. With this configuration, the job named "scrap-price" will run every day at 3:45 AM UTC time (9 am in my local time). It will scrape the price from the specified URL and send a Telegram message if the price is less than or equal to 5200. This marks the end of part one of this blog. The part 2 will make more improvements on the tracker such as grabbing api from github secrets, comparing the value with previous day's value, setting up analytics of daily price etc. Stay tuned.</p>
]]></content:encoded></item><item><title><![CDATA[Hidden Backdoor in Digicom Router?]]></title><description><![CDATA[In this article, let us take a close look into the Digicom router DG-M342T. First, let us view the technical specifications of the router. It's a 2.4 GHz…]]></description><link>https://blog.rmb.info.np/hidden-backdoor-in-digicom-router</link><guid isPermaLink="true">https://blog.rmb.info.np/hidden-backdoor-in-digicom-router</guid><category><![CDATA[router]]></category><category><![CDATA[hacker]]></category><category><![CDATA[hacking]]></category><dc:creator><![CDATA[Rabindra Man Bajracharya]]></dc:creator><pubDate>Sat, 07 Oct 2023 15:23:03 GMT</pubDate><content:encoded><![CDATA[<p>In this article, let us take a close look into the Digicom router DG-M342T. First, let us view the technical specifications of the router. It's a 2.4 GHz router with 1 WAN Port and 4 LAN Port. Nothing fancy, but it's a decent router for use as a secondary Wi-Fi router.</p>
<p>The box of the router points to the official website i.e. digicom.com.hk. Upon opening the website, we are greeted with this maintenance screen.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696687389773/e18c1208-e786-4222-b672-f7153de90069.png" alt class="image--center mx-auto" /></p>
<p>Performing some background checks on the website via archive.org, it is found that the website has been in maintenance mode since 2016. So we are not off to a good start here.</p>
<p>Looking into the router setup page of the router, the pages are a close resemblance to that of dlink router. Initially, I thought that this router might be running modified firmware of dlink router. This claim was kind of verified when I found a javascript file "menu.js" on the page, the js code had a function openSupport() that opens D-Link's website.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696689074690/ce623388-e7d8-401d-834d-5339a9d7f5de.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696689119349/f0864e79-9cfe-457a-a473-b749c44308a2.png" alt class="image--center mx-auto" /></p>
<p>While checking the router page, I found an interesting page that was accessible without login i.e. "status.htm" which gave some basic information about the router.</p>
<p>Looking further and deeper into the router, I came across telnet enable/disable page of the router</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696689804843/bc6d6dfb-7c87-4345-9910-cdac41a1513a.png" alt class="image--center mx-auto" /></p>
<p>I enabled it and performed a quick port scan to verify that the port was open.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696689973177/7b618bb1-d2f3-43bc-8d66-b4bce2d79d47.png" alt class="image--center mx-auto" /></p>
<p>Then, I tried to connect to the telnet using the router credentials that I had set via the setup page. It worked and I was in.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696690103899/dd362a04-5d2c-4cdb-bfe1-3846590a51f3.png" alt class="image--center mx-auto" /></p>
<p>The list of available commands inside the telnet session was as follows:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696690173799/a3abf238-684d-4b0e-b2e0-d03915f37b72.png" alt class="image--center mx-auto" /></p>
<p>Most of the commands were for providing debug information. The particular command that piqued my interest was "login". Upon running the command I found out that, it accepted arguments.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696690387692/a3656986-2ea5-4f14-9a5d-e140cdd0ffe9.png" alt class="image--center mx-auto" /></p>
<p>I was interested in the show argument and I ran it. To my surprise, instead of it showing a single account detail I set on the router, it showed two accounts: one that I set and another one which probably is a backdoor account. What seems even more interesting is that the priority of the account is higher than that of my own.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696690687640/37fc3cb9-08cc-4e7f-b1d1-9a1579f19146.png" alt class="image--center mx-auto" /></p>
<p>I opened a new terminal and try to telnet to the router using the new credentials i.e. admin:3EF4airocon. The login was successful. Upon login, I immediately noticed that the list of commands this account could access was higher than that of a normal account.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696691024760/3bd8108c-04f3-4309-9e12-1355dd0f0bab.png" alt class="image--center mx-auto" /></p>
<p>I also tested the credentials on the router setup page.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696691142774/3f8adb39-8a97-488a-9749-7a4193581f67.png" alt class="image--center mx-auto" /></p>
<p>But instead of it working like a normal account, I landed on a 404 page.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696691196226/bcb130d8-175d-47d9-b734-389ad01e14f5.png" alt class="image--center mx-auto" /></p>
<p>Even the login page was no longer accessible</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696691256431/8667b612-e7df-49a2-ad96-ef9003202b52.png" alt class="image--center mx-auto" /></p>
<p>The page was inaccessible even via curl.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696691402912/4ae4ce3b-8130-49cf-86f2-cf76a82971f2.png" alt class="image--center mx-auto" /></p>
<p>With no other choice, I had to restart my router to restore it back to the previous working state.<br />In conclusion, the particular digicom router seems very suspicious and full of suprises. From the official website to the backdoor account, everything about the router seems pretty eccentric. With this blog, I hope to raise some awareness among the users of Digicom routers.</p>
]]></content:encoded></item></channel></rss>