<?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 Dan Ong Chew Seng on Medium]]></title>
        <description><![CDATA[Stories by Dan Ong Chew Seng on Medium]]></description>
        <link>https://medium.com/@danongchewseng?source=rss-cc46d54f1914------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eMxzYeI6w5msaJpM</url>
            <title>Stories by Dan Ong Chew Seng on Medium</title>
            <link>https://medium.com/@danongchewseng?source=rss-cc46d54f1914------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:41:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danongchewseng/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[What exactly is an Agent Harness?]]></title>
            <link>https://danongchewseng.medium.com/what-exactly-is-an-agent-harness-841ffab01e47?source=rss-cc46d54f1914------2</link>
            <guid isPermaLink="false">https://medium.com/p/841ffab01e47</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Dan Ong Chew Seng]]></dc:creator>
            <pubDate>Fri, 22 May 2026 13:43:56 GMT</pubDate>
            <atom:updated>2026-05-22T13:54:19.378Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>And what is “harness engineering,” and how do I build one — explained for people who already know how to build software</strong></h4><p><strong>A note before we start</strong></p><p>If you’ve used Claude Code or Cursor, you’ve used a harness without necessarily noticing it. But the harness is <em>not</em> the coding assistant. The coding assistant is one product built on one harness. The harness is the more general thing — the scaffolding any agent runs inside, whether that agent is writing code, discovering vulnerabilities, triaging tickets, or running a multi-step research workflow.</p><p>This article is for engineers who already understand systems, APIs, and control flow, but who haven’t yet had to <em>build </em>the layer that turns a language model into an agent. The goal is to give you (a) a precise mental model, (b) the vocabulary to reason about and evaluate a harness, and (c) enough of a build path that you could sketch one yourself.</p><p>I’ll lean on analogies to traditional software throughout, because the fastest way to understand a harness is to notice what it rhymes with in systems you already know.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lu_3GTbN3T07SQxLrxmv3w.png" /><figcaption>Agent Harness Engineering</figcaption></figure><h3>Act I — What is a harness?</h3><p><strong>The one-sentence definition</strong></p><blockquote>A harness is the loop that calls the model, supplies it with context and tools, and routes the model’s outputs back into the world, over and over, until a task is done.</blockquote><p>That’s it. A model on its own is a function: text in, text out, no memory, no side effects, no ability to <em>do</em> anything. The harness is everything around that function that turns “predict the next token” into “accomplish a task.”</p><p><strong>The mental model for a traditional SWE</strong></p><p>A raw LLM is like a <strong>CPU that is extraordinarily capable but has no operating system</strong>. It can compute, but it can’t:</p><ul><li>remember anything between calls — no persistent state,</li><li>read or write files — no I/O,</li><li>call other systems or APIs,</li><li>or even decide when it’s finished — no scheduler.</li></ul><p>The harness is the <strong>runtime / OS / scheduler</strong> wrapped around that CPU. It owns the event loop, manages memory (context), exposes I/O (tools), persists state (the session), and decides when to halt. If the model is the brain, the harness is the nervous system and the hands.</p><h4>The anatomy: the agent loop</h4><p>Strip away the product polish and almost every harness is the same loop:</p><p>1. Assemble context (system prompt + history + task + tool definitions)</p><p>2. Call the model</p><p>3. Did the model emit a tool call?</p><p>→ yes: execute the tool, capture the result, append to history, go to 1</p><p>→ no: the model produced a final answer → stop</p><p>4. (Guard against running forever)</p><p><strong>Seeing the loop in something you’ve probably used: Claude Code</strong></p><p>The fastest way to make the loop concrete is to point at one you already use. <strong>Claude Code</strong> is a harness, and you can watch it walk the exact steps from above:</p><p>Assemble context (step 1) — when you give Claude Code a request, it doesn’t just send your sentence to the model. It assembles a context: your prompt, the relevant file contents, what’s happened earlier in the session, and the list of tools available (read file, edit file, run shell, search). That assembly is the harness’s job, not the model’s.</p><p>Call the model (step 2) — it sends that whole package to the model and gets back a response. The model itself is stateless here; it only knows what step 1 just handed it.</p><p>Tool call or done? (step 3) — the response is either “here’s the final answer” or “I want to edit this file” / “I want to run this command.” Claude Code inspects which one it is. When it “edits a file,” the model didn’t touch your disk — it emitted a tool call, and the harness is what validated and executed it.</p><p>Execute and loop back (step 3 → 1) — the harness runs the tool, captures the result (the command output, the new file state, an error message), appends it to the running session, and loops back to step 1 with that new information in context. This is why it can chain edits: each result feeds the next decision.</p><p>Guard against running forever (step 4) — Claude Code won’t loop endlessly. It stops when the task is done, when you interrupt it, or when it hits limits on how long it can run and how much it can consume.</p><p>Everything that makes Claude Code feel like an agent rather than a chatbot lives in this loop (the harness) — not in the model. Strip the harness away and you have a model that can describe how to fix your bug but can’t open the file, run the test, or see that the test failed. The loop is what turns “predict the next token” into “get the task done.”</p><p>The lesson for an engineer: <strong>the harness, not the model, is where you encode the shape of the workflow.</strong> Choosing one-broad-agent vs. many-narrow-agents is a harness design decision, the same way choosing monolith vs. microservices is an architecture decision. The model is a component; the harness is the architecture, and it’s the engineer’s job to design, solution and build it.</p><h3>Act II — What is harness engineering?</h3><p><strong><em>And what’s actually involved?</em></strong></p><blockquote><em>A harness encodes assumptions about what the model can’t do on its own. Harness engineering is the craft of managing those assumptions, and accepting that they decay as models improve.</em></blockquote><p>A traditional codebase encodes assumptions about a problem domain, and those assumptions are stable: gravity @ ~9.81m/s² never changes, your income tax rate changes slowly. In harness engineering, <strong>the substrate (LLMs) you’re building on top of gets better (or changes) every few months</strong>, and improvements in the model can silently turn your hard-won scaffolding into dead weight.</p><p>Sharing a story that I’ve read that illustrates this perfectly.</p><p>Anthropic’s engineering team hit this directly. Claude Sonnet 4.5 had a habit of wrapping up tasks prematurely as it sensed its context window filling up, a behaviour they nicknamed “context anxiety.” So they engineered around it: they added <strong>context resets</strong> to the harness to give the model room to keep working.</p><p>Then they ran the <em>same harness</em> on Claude Opus 4.5. The behaviour was gone. The model no longer panicked near its context limit, and the context-reset machinery they’d built was now <strong>dead weight</strong>, solving a problem that no longer existed.</p><p><strong>Source:</strong> <em>Harness design for long-running application development — Anthropic (</em><a href="https://www.anthropic.com/engineering/harness-design-long-running-apps"><em>https://www.anthropic.com/engineering/harness-design-long-running-apps</em></a><em>)</em></p><p>Another example, closer to home, from our own work. When models were more rudimentary, one of the patterns we leaned on was a critique-refine loop: we’d build explicit steps for the model to critique its own output, then revise itself based on that critique, all in service of squeezing out better quality. It worked because the models of the day genuinely needed the second pass. Today, models (even open-source ones) are capable enough that for straightforward tasks they produce better results in a single shot than our critique-refine scaffold used to coax out of them. The loop we were proud of became overhead: extra latency, extra tokens, extra complexity, solving a problem the model had quietly outgrown.</p><p>This is the core tension of the discipline:</p><ul><li>Every clever thing you build into a harness is a <strong>patch over a current model limitation</strong>.</li><li>The better the underlying model gets, the more of your patches become <strong>obsolete</strong> — and sometimes actively harmful, because they add complexity and constrain a model that no longer needs constraining.</li><li>So the job is never “done.” Harness engineering is <strong>continuously re-asking which of your assumptions are still true.</strong></li></ul><p>A traditional-SWE analogy: it’s like writing polyfills for a browser feature. The polyfill is essential right up until the day the browser ships the feature natively, after which the polyfill is just risk and bloat you have to remember to delete. Now imagine the browser ships new native features every quarter, unannounced. That’s the cadence you’re engineering against.</p><h3>The components every real harness has</h3><p>A toy harness is just the loop from Act I. A production harness adds these concerns. For each, I’ve noted the traditional-software cousin:</p><p><strong>1. Context management</strong> <em>(≈ memory management / caching)</em> The context window is finite and is your most precious resource. You decide what goes in: system prompt, relevant history, retrieved documents, tool definitions. As a task runs long, you must <strong>compact</strong>; summarize old turns, drop stale tool output, retrieve-on-demand instead of holding everything. Get this wrong and you either blow the budget or starve the model of what it needs.</p><p><strong>2. Tool dispatch</strong> <em>(≈ a syscall interface / RPC router)</em> You define the tools the model may call, validate the arguments it produces (it <em>will</em> sometimes produce malformed ones), execute them, and feed results back. This is the model’s only way to affect the world, so it’s also your primary <strong>safety boundary</strong>.</p><p><strong>3. Session / state</strong> <em>(≈ an append-only event log / write-ahead log)</em> The durable record of everything that happened: every model output, every tool call, every result. Treating it as append-only gives you replayability, debuggability, and the ability to resume long-running work. If you’ve built event-sourced systems, this is the same instinct.</p><p><strong>4. Sandbox</strong> <em>(≈ a container / VM)</em> Where the agent’s generated code execution and file edits actually happen, isolated from everything you care about. Same threat model as running untrusted code, because, given prompt injection attacks, that’s effectively what you’re doing.</p><p><strong>5. Error recovery</strong> <em>(≈ retry middleware / circuit breakers)</em> The model will hallucinate a tool, a tool will fail, an output won’t parse. The harness has to catch, feed the error back to the model (it’s often surprisingly good at self-correcting), and bound the retries so it can’t spin forever.</p><p><strong>6. Termination &amp; budgets</strong> <em>(≈ a scheduler with timeouts / quotas)</em> Deciding when the agent is done, or when to stop it regardless: max steps, max tokens, time limits, cost ceilings. Non-negotiable, because a stochastic loop without a hard stop is an unbounded loop.</p><p><strong>Security aside worth flagging for any internal build:</strong> because the model acts on whatever text enters its context, <em>content it reads is a potential instruction source</em> — this is prompt injection. Treat tool outputs, fetched web pages, and file contents as <strong>untrusted input</strong>, exactly as you’d treat user input in a web app. The sandbox and the tool-dispatch validation layer are where you contain the blast radius.</p><h3>Act III — How do I build one?</h3><p>Let’s build up a harness conceptually, smallest-useful-thing first, then add the production concerns. I’ll keep this language-agnostic; the shape matters more than the syntax.</p><p><strong>Step 0 — the minimum viable harness</strong></p><pre>def run_agent(task, tools, model):<br>    history = [system_prompt(), user_message(task)]<br>    for step in range(MAX_STEPS):              # termination budget<br>        response = model.call(history, tools)  # call the brain<br>        history.append(response)<br>        if response.tool_calls:                # did it want to act?<br>            for call in response.tool_calls:<br>                result = dispatch(call, tools)  # use the hands<br>                history.append(result)<br>            continue                            # loop back with new info<br>        return response.text                    # no tool call → done<br>    raise StoppedError(&quot;hit step budget&quot;)       # hard stop</pre><p>This is genuinely almost all of it. If you read that and thought “this is just a while loop with an API call in the middle”. Yes, that’s the honest truth of it, and it’s worth saying out loud to a skeptical audience. The model provider’s SDK handles the actual model call and tool-calling protocol; <strong>you own the loop, the tools, and the policy.</strong></p><p><strong>Step 1 — make the tools real and safe</strong></p><p>dispatch() is where most of your engineering actually goes:</p><ul><li><strong>Validate</strong> the arguments the model produced against a schema before executing. Assume adversarial-by-accident input.</li><li><strong>Sandbox</strong> anything that runs code or touches the filesystem.</li><li><strong>Return errors as data</strong>, not exceptions — hand the failure back to the model as a tool result so it can adapt, rather than crashing the loop.</li></ul><p><strong>Step 2 — manage context before it manages you</strong></p><p>The naive loop appends forever and eventually overflows the window. Add a compaction policy that triggers as you approach the budget, summarize the oldest turns into a compact note, drop verbose tool outputs you no longer need, and retrieve detail on demand.</p><p><strong>Step 3 — decide your topology: one broad agent or many narrow ones</strong></p><p>This is the architectural fork from Act I, now as a build decision:</p><ul><li><strong>Single agent, broad tools</strong> — simplest, best for interactive and open-ended work (e.g. the coding-assistant pattern). Start here unless you have a reason not to.</li><li><strong>Multiple specialized sub-agents</strong> — when the task decomposes into narrow, parallelizable pieces, or when one context can’t hold the whole job (e.g. Anthropic’s Mythos vuln. discovery). More powerful, but you’ve now signed up for orchestration, inter-agent communication, and result aggregation, i.e. you’re building a distributed system, with all that implies.</li></ul><p>Don’t reach for the multi-agent pattern just because it sounds sophisticated. Reach for it when a single context genuinely can’t do the job, the same way you’d resist splitting a monolith until you actually feel the pain.</p><p><strong>A pragmatic build order</strong></p><p>If you’re starting from zero internally, this sequence gets you started:</p><ol><li>Minimal loop + 2–3 real tools + a hard step budget.</li><li>Sandbox and input validation before you let it touch anything real.</li><li>Context compaction once, and only once, you actually hit the limit.</li><li>Multi-agent topology only if a single agent provably can’t do the job.</li></ol><h3>Act IV — What does this look like in a real system?</h3><p>The simple case: agentic RAG.</p><p>Classic RAG is a pipeline — embed the query, retrieve top-k chunks, stuff them into the prompt, generate. There’s no harness worth speaking of; it’s a deterministic data-flow with one model call at the end.</p><p><em>Agentic</em> RAG is where a harness appears. Now the model decides <em>whether</em> to retrieve, <em>what</em> to search for (often reformulating the query), <em>whether the results are good enough</em>, and <em>whether to search again</em> before answering. That decide–act–observe–repeat is the agent loop, and everything around it is harness work: the retrieval tools and their schemas (tool dispatch), how much retrieved content you keep in the window versus discard (context management), capping how many search rounds it’s allowed before it must answer (termination/budgets), and treating retrieved documents as untrusted input (a real prompt-injection surface, since you’re feeding external text straight into the model). The model got “smarter” about retrieval, but every one of those new behaviours had to be <em>built into the harness.</em></p><p><strong>[Redacted org. contextualized example]</strong></p><h3>Closing</h3><p>Notice that across both examples, the simplest agentic RAG and [redacted], the model is the part we <em>didn’t</em> build and don’t control. What we build, in every case, is the harness: the loop, the tools we expose, the limits we set, the assumptions we encode about what the model can’t yet do on its own. <strong>That’s where our engineering judgment actually lives.</strong></p><p>The takeaways worth carrying out of this: designing a harness <em>is</em> doing system architecture. The same calls we already make well, are exactly the calls a harness demands. The model may be new, but it’s the easy part to swap in; the parts that decide whether an agentic system actually holds up in production are the unglamorous ones we already know how to build: how state is persisted, how tools fail safely, where the budgets sit, what the agent is allowed to touch.</p><p>As agentic solutions show up across more of what we build, that’s where the real engineering will live, and it’s a muscle worth developing now, on small and legible systems, before the stakes get higher (more complex monsters).</p><p><em>Post is written with AI’s assistance on structure, grammar and wording.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=841ffab01e47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A recommended resilient and scalable Elasticsearch data indexing architecture — Part 2]]></title>
            <link>https://danongchewseng.medium.com/a-recommended-resilient-and-scalable-elasticsearch-data-indexing-architecture-part-2-bfa05162614a?source=rss-cc46d54f1914------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfa05162614a</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[search]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[indexing]]></category>
            <category><![CDATA[full-text-search]]></category>
            <dc:creator><![CDATA[Dan Ong Chew Seng]]></dc:creator>
            <pubDate>Wed, 12 Jan 2022 11:03:14 GMT</pubDate>
            <atom:updated>2022-01-12T11:03:14.120Z</atom:updated>
            <content:encoded><![CDATA[<h3>A recommended resilient and scalable Elasticsearch data indexing architecture — Part 2</h3><p>In the first part of this 2-part series on an architecture for your Elasticsearch data indexing pipeline, I gave a short background and introduction. If you’ve not read part 1, you can do so <a href="https://danongchewseng.medium.com/a-recommended-resilient-and-scalable-elasticsearch-data-indexing-architecture-part-1-be17bd1cc32a">here</a>.</p><p>As a continuation, we’ll be discussing the proposed architecture in detail, the benefits and complication in part 2.</p><h3>Outline</h3><p>A recap of the outline of this 2-part series.</p><h4>Part 1</h4><ol><li>What is Data Indexing? And why do I need to index?</li><li>Open-source Search Engines — Elasticsearch</li><li>Message queue/brokers — RabbitMQ</li><li>Conventional data indexing flow</li></ol><h4>Part 2</h4><ol><li>Problems with conventional data indexing flow</li><li>Introduction to Extract-Transform-Load (ETL) indexing architecture</li><li>Benefits of proposed architecture</li><li>Complication of horizontal scaling</li></ol><h3>Problems with conventional data indexing flow</h3><p>In the <a href="https://danongchewseng.medium.com/a-recommended-resilient-and-scalable-elasticsearch-data-indexing-architecture-part-1-be17bd1cc32a">first part</a> of this series, we discussed a conventional flow of how a system can index data into Elasticsearch. A recap:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ROaFfMf2qaJwd2gq.png" /><figcaption>Diagram of a conventional data indexing flow</figcaption></figure><p>I like to call this the microservice “push” model, because the microservice is pushing data directly into both the primary data store (could be SQL, MongoDB, etc) and Elasticsearch. One problem in this model is that there is a larger transaction boundary.</p><h4>Transaction Boundary</h4><p>A transaction is an atomic unit of work that must be completed as a whole. It usually consists of one or more operation.</p><p>Here’s a straightforward example: when you transfer money to your friend, the bank deducts money from your bank account and adds it to your friend’s account balance. This is a “2-operation” transaction that <strong>MUST </strong>be executed to the end together. Imagine if the bank deducts your money, but it fails to add to your friend’s account. In that case, the entire transaction must be cancelled, that is, to reverse the deduction from your account, otherwise, the money will be lost.</p><p>Therefore, a transaction boundary is where a transaction starts and ends (being committed or rolled-back).</p><h4>Impact of a larger transaction boundary</h4><p>In our Elasticsearch scenario, it means that if the index operation in Elasticsearch fails for whatever reason, we need to rollback changes to the primary data store. Otherwise, there would be data inconsistency, i.e. data is actually in primary store but cannot be searched.</p><p>Ultimately, it means that we need to write code to cater for the rollback logic.</p><h3>Proposed Architecture</h3><p>A better way to implement data indexing to Elasticsearch could be as follows. One that uses a message queue and a separate indexer module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*qJH_Y8bCanEqWTytkPgu7Q.png" /><figcaption>Diagram of Proposed Architecture</figcaption></figure><p>Similar to the conventional flow, the application will push data changes to the primary data store first, then a copy of the data will be sent to the message queue (e.g. RabbitMQ). Next, an indexer module will subscribe to the queue and grab jobs from the queue to index into Elasticsearch.</p><h3>Benefits of Proposed Architecture</h3><h4><strong>Scalable</strong></h4><p>This architecture can be easily scaled up to meet higher demand. For instance, the number of indexer instances can be increased if there are more documents to process. The size of the RabbitMQ message queue can also be increased easily to support more or larger document sizes.</p><h4><strong>Resilient</strong></h4><p>Resiliency is also another benefit of this architecture. When data is sent to the queue, it will persist until it has been successfully processed and acknowledged by a subscriber. This basically guarantees eventual consistency; any changes made is guaranteed to be indexed into Elasticsearch without any data loss from transient failures.</p><h4><strong>Modular — Separation of Concerns (SoC)</strong></h4><p>SoC is one of the most important design principle, and it states that a computer program should be separated into distinct sections that serves one and only one function.</p><p>And one of the major benefits of this architecture is that the indexing operation is separated out into its individual module, creating modular components, namely the app and indexer. This also enable easier tech refresh by the individual components.</p><h3>Complication of Horizontal Scaling</h3><p>However, there’s a complication that arise from this architecture when it is scaled up, it is something that will need to be taken care of.</p><p>In a multi-indexer instance environment, if one of the instance fails after retrieving a message but didn’t finish processing it, the message may become out-of-order after retry by another instance. This may result in outdated versions of document being indexed.</p><p>This complication is illustrated in the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*bo4I2ya4XtNYaZ5cUbOR0A.png" /><figcaption>Diagram of horizontal scaling complication</figcaption></figure><p>In the example above, v1 is retrieved by indexer 1 and v2 is retrieved by indexer 2. Now let’s assume indexer 2 successfully acknowledged processing the document, but indexer 1 fails for some reason and didn’t successfully acknowledge. In that case, v1 will be retried and sent to another instance that is available, indexer 3. After which, it will be processed and acknowledged.</p><p>Now, since v1 is processed after v2, it will replace v2 in the Elasticsearch index, which is the oudated document.</p><h3>Mitigation</h3><p>To mitigate this issue, we need to have each indexer instance verify if the current document is oudated before indexing in Elasticsearch.</p><p>We do this by comparing the version of the document with the current one in ES.</p><ol><li>If the version in ES is <strong>before </strong>the current doc. version, we can <strong>proceed </strong>to index it.</li><li>If the version in ES is <strong>after </strong>the current doc. version, we can safely <strong>discard </strong>it.</li></ol><h3>Conclusion</h3><p>The benefits of this architecture is quite clear, and it can fit projects of various scale. However, if your project is simpler and more straightforward, it may be an overkill to implement such an architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfa05162614a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTX Investigators’ Challenge (HTXIC) CTF Write-Up]]></title>
            <link>https://danongchewseng.medium.com/htx-investigators-challenge-htxic-ctf-write-up-e4687b2857a7?source=rss-cc46d54f1914------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4687b2857a7</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[capture-the-flag]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Dan Ong Chew Seng]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 03:03:07 GMT</pubDate>
            <atom:updated>2022-01-03T04:02:13.585Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vMMyPciyR0T7zUD_.jpg" /></figure><p>HTX Investigators’ Challenge (HTXIC) is a Capture-The-Flag (CTF) competition organised by the Home Team Science and Technology Agency (HTX). The premise of the challenge involves having challengers play detectives for a day to investigate and stop a terrorist attack targeting the F1 Grand Prix in Singapore. The challenges involve different challenges from different domains such as Chemical, Biological, Radiological Nuclear and Explosive (CBRNE), forensics, robotics, biometric and profiling while immersed in a fully gamified 3D virtual reality environment.</p><h3>Pre-requisites</h3><p>The challenge was open to teams of 3 to 5 with members who are either full-time students in JC, ITE, Polytechnics or University, or are fresh graduates (within 2 years) from any of these Institutes of Higher Learning.</p><p>Being fresh graduates within 2 years, my team and I narrowly falls into the second category.</p><h3>Final Results</h3><p>Out of 120 teams, we managed to reach the top 15 leaderboards at the very last second (more about this later, it got pretty exciting).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*F8eM2RYA-ll9YFRM1VrIkQ.png" /><figcaption>HTXIC Final Leaderboard</figcaption></figure><p>It’s nothing impressive, but being relatively new to CTF and being up against teams with more than 30 past CTF experience, we were pretty happy with our results.</p><h3>Introduction</h3><p>The challenge was held on 20th Dec 2021 for a full 12 hours, 8am to 8pm. It was quite intensive and we were fully focused on the challenge for the entire 12 hours, only taking a break for lunch, by the end of it, I was so mentally drained it’s not a joke.</p><p>In this write-up, I will focus more on the cybersecurity, steganography and cryptography challenges. There were a few CBRNE challenges that we solved, but I’ll not be discussing them since it doesn’t fall in my field of expertise.</p><p>Without further ado, let’s get started.</p><h3>Physical Challenge — Fingerprinting</h3><p>Despite being a fully virtual challenge, there were a few physical challenges. One of them being a fingerprinting challenge, where we were given a drone propeller with the supposed perpetrator’s fingerprint, and we had to find, identify and lift the prints off the evidence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mDAjZKJs_MCAuIFjPDMirA.png" /><figcaption>Photo Credits: HTX</figcaption></figure><p>It’s a shame I don’t have any actual photo of us doing this challenge.</p><p>In the first part of the challenge, we’re supposed to use the provided black powder and brush to dust the propeller and count the number of fingerprints on it.</p><p>We didn’t manage to complete this part of the challenge, we used up both attempts. The thing is, there were a lot of partial prints on the evidence (intentional or not, we don’t know), and we weren’t sure if we were supposed to count them or not, so we had to try the different answers. Unfortunately, we didn’t get it right.</p><p>In the second part of the challenge, we were given 5 reference prints and their names, and an unknown fingerprint that we’re supposed to compare to the reference prints and identify it.</p><p>This part was quite straightforward and we got it done pretty quickly and submitted the answer on the game client.</p><h3>A06 — Break The Gate</h3><p>In this challenge, an extension-less file, “<em>BreakTheGate</em>” was given.</p><p>A simple hexdump of the file</p><pre>hexdump -R BreakTheGate &gt; hex.txt</pre><p>reveals the file header to be a ELF (Executable and Linkable Format) format for Linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*Tq_MfQIgGBIJGNRt4dOROw.png" /><figcaption>Hexdump of BreakTheGate file</figcaption></figure><p>Running the executable on a Linux machine gives us the following message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*7k8oE-IbLCc-edfgxGIsXQ.png" /><figcaption>Output of BreakTheGate file</figcaption></figure><p>We’re gonna need a username and password. A further look at the hexdump reveals the username and password in plaintext.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*SCRU7B1iN5jkfrxa1k_F3w.png" /><figcaption>Hexdump of BreakTheGate file</figcaption></figure><p>However, entering the password into the executable shows that it is invalid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*_wPPUp6jAYMkTkg5OkZHbg.png" /></figure><p>This was when I happened to notice the password seemed to be reversed. Reversing it back gives us “<em>Br3aking_in</em>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*1Nbj3Voseg0n44nJXRZzSA.png" /><figcaption>Bingo! Flag found.</figcaption></figure><p>Bingo! We have our flag, “<em>htx{Br3aking_in}</em>”.</p><h3>A15 — Find Revo Force’s Hideout</h3><p>In this challenge, we’re given a 72 images that supposedly contains information to where the bad guys’ hideout is located. And these are all pictures of cats, here’s one for your enjoyment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*GPAGMzt9wOIDhLFuKk-cQA.jpeg" /><figcaption>One of the cat image provided. Meow.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*oVXBbpxGQc0LXdQNn68hEQ.png" /><figcaption>List of 72 images provided</figcaption></figure><p>It is mentioned in the challenge information that these images contain location EXIF data. And the most common location is the hideout, and that the flag is in the form of latitude and longitude, separated by a comma e.g. x.xxxxxx, yyy.yyyyyy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*FLU2zIE6W63Kyc89FMOK-g.png" /><figcaption>File Properties of Image</figcaption></figure><p>Now, there’s 72 images, so it wouldn’t be wise to go through each of them manually trying to find which one is the most common.</p><p>So I wrote a short Python script and used <a href="https://pillow.readthedocs.io/en/stable">Pillow</a> library to extract the EXIF data wholesale.</p><pre>from PIL import Image<br>from PIL.ExifTags import TAGS<br>from os import listdir<br>from os.path import isfile, join</pre><pre>path = &quot;C:/Users/innov/Desktop/HTX/A15&quot;<br>files = [f for f in listdir(path) if isfile(join(path, f))]</pre><pre>for file in files:<br>    # load image<br>    my_image = Image.open(path + &quot;/&quot; + file)</pre><pre># get EXIF Data of the image<br>    img_exif_data = my_image.getexif()<br>    print(&quot;Lat: &quot; + str(img_exif_data.get(34853).get(2)))<br>    print(&quot;Lon: &quot; + str(img_exif_data.get(34853).get(4)))<br>    print()</pre><p>From the output, we can easily tell which location is the most common.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*pvm85xYSgJtK00PnQNizyg.png" /><figcaption>Output of the Python script</figcaption></figure><p>Given the DMS (Degrees Minutes Seconds), we convert it to Lat/Lon as required by the challenge. That gives us: 1.340885, 103.644482.</p><p>And that’s our flag.</p><h3>A23 — Reversing 101</h3><p>This challenge took up the most of my time, but it was the most satisfying to complete.</p><p>We were given an executable file, TicTacToe.exe. Running it shows the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*fIuKGqW27MFXpO-TNAXVxA.png" /><figcaption>TicTacToe Application</figcaption></figure><p>Playing the game yields nothing, winning or losing. We need to dig deeper.</p><p>Using PE Explorer, I noticed <em>mscoree.dll</em> to be one of its dependencies, which means that it’s a .NET application.</p><p>We can then use Telerik’s JustDecompile to decompile the executable into C# source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k_-g5bXCulXHv9ltkYPf2w.png" /><figcaption>Telerik JustDecompile — TicTacToe.exe Source</figcaption></figure><p>Unfortunately, the source code is obfuscated by <a href="https://mkaring.github.io/ConfuserEx/">ConfuserEx</a>, which renames symbols into weird characters (and in this case, some weird RTL unicode characters) to make it much harder to inspect and analyse the source code.</p><p>Looking back, I should have used a deobfuscator to make my life much easier. But I proceeded to analyse the source code in the obfuscated state, which contributed to the amount of time it took.</p><p>Combing through the source code, I found a piece of interesting snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pj349UhnjL22nU5xdY7ONA.png" /><figcaption>Code snippet</figcaption></figure><p>A MessageBox that shows a Base64 encoded message.</p><pre>WW91IGhhdmUgYWNjZXNzZWQgdGhlIGhpZGRlbiBsb2NrZXIsIGNhbiB5b3UgdW5sb2NrIGl0Pw==</pre><p>Decoding the base64 message gives us the following message:</p><pre>You have accessed the hidden locker, can you unlock it?</pre><p>And the only part of the source codes that call this function is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*uITEHm7nsnSONoxBI4zQgQ.png" /><figcaption>Code snippet</figcaption></figure><p>Which hints that the score has to be 3:2 for it to trigger something to happen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*DjSZYRhhLOdVuzOm0hAzbw.png" /><figcaption>Hidden locker discovered</figcaption></figure><p>After that, a numbered keypad appears, seemingly needing some PIN input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*VIiZxmxQ38Oq74ODKhFCOg.png" /><figcaption>Numbered keypad input</figcaption></figure><p>Looking through the source code again, I discovered this code snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*7gx43zR5hSq2NrCAhv1e1w.png" /><figcaption>Code snippet</figcaption></figure><p>Which seemingly checks for a 9 digit (<em>num0 </em>to <em>num8</em>) PIN. Basically, the 9 digit PIN needs to <strong>NOT</strong> satisfy (because satisfying any of the condition will return an error) all the conditions to be valid:</p><pre>num % num8 != 0<br>num8 * 3 != num1<br>num1 * 3 != num3<br>num4 % num1 != 2<br>num5 * 4 != num4<br>num1 % num3 != num2<br>num1 - num5 != num<br>num6 % num2 != num<br>num6 / 2 != num5<br>num7 % num1 != num8 ? true : num7 % num6 != num1</pre><p>Using some maths, logic and lots of time, it is determined that 133982471 is the valid PIN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*oQxehVhBa9lBYmzLT2Qh0w.png" /><figcaption>Flag obtained</figcaption></figure><p>There we go! Flag captured.</p><h3>c0deD ME5sages</h3><p>This was the last challenge that we worked on together as a team. We started about 30 mins before cut-off time, and submitted the flag literally seconds before the challenge ended, and it got us into the top 15 leaderboard. The adrenaline was rushing so much, exciting times.</p><p>In this challenge, we were given a long string, nothing else.</p><pre>%109y69&amp;o1#01U11_6(v32%E1,&amp;01^b88E1@05e-1$1!6n32\T1#16!R10%4i&amp;114!c69.K_1!01~e*@d</pre><p>Looking at the string, it doesn’t seem to fit the URL encoding scheme, ASCII or whatever. We even tried different ciphers like ROT13, Caesar or Affine cipher.</p><p>It took us awhile, but we noticed that if we remove the special symbols and numbers, it yields us</p><pre>yoUvEbEenTRicKed</pre><p>Well, okay. Tried that as a flag, didn’t work.</p><p>Then we noticed that if we removed special characters and alphabets instead, we’d get</p><pre>109 69 101 116 32 101 88 105 116 32 116 104 114 69 101</pre><p>which look awfully like ASCII. This translates to:</p><pre>mEet eXit thrEe</pre><p>Which is the flag to this challenge.</p><h3>Conclusion</h3><p>That’s all for this write-up, I can’t go into every single challenge that we’ve completed. Maybe if I have time, I can do a part 2 to share more.</p><p>Overall, I had a lot of fun doing this challenge. Thank you for taking time to read my write-up :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4687b2857a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A recommended resilient and scalable Elasticsearch data indexing architecture — Part 1]]></title>
            <link>https://danongchewseng.medium.com/a-recommended-resilient-and-scalable-elasticsearch-data-indexing-architecture-part-1-be17bd1cc32a?source=rss-cc46d54f1914------2</link>
            <guid isPermaLink="false">https://medium.com/p/be17bd1cc32a</guid>
            <category><![CDATA[indexing]]></category>
            <category><![CDATA[search]]></category>
            <category><![CDATA[full-text-search]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Dan Ong Chew Seng]]></dc:creator>
            <pubDate>Fri, 26 Nov 2021 15:31:00 GMT</pubDate>
            <atom:updated>2021-11-26T15:31:00.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>A recommended resilient and scalable Elasticsearch data indexing architecture — Part 1</h3><p>In this 2-part story, I’ll be introducing an architecture for your Elasticsearch data indexing pipeline. This architecture will be especially useful if you need some kind of full-text search on your data and would like to leverage on specialised full-text search engines like Elasticsearch.</p><h3>Outline</h3><p>This post is written with the assumption that you don’t have any background knowledge on the technology that we’re going to talk about, so I’ll be giving a short background and introduction in part 1. Some technical &amp; coding knowledge is definitely required to understand majority of it.</p><p>We’ll discuss the architecture in detail, the benefits and complications of it in the 2nd part of this series.</p><h4><strong>Part 1</strong></h4><ol><li>What is Data Indexing? And why do I need to index?</li><li>Open-source Search Engines — Elasticsearch</li><li>Message queue/brokers — RabbitMQ</li><li>Conventional data indexing flow</li></ol><h4><strong>Part 2</strong></h4><ol><li>Problems with conventional data indexing flow</li><li>Introduction to Extract-Transform-Load (ETL) indexing architecture</li><li>Benefits of proposed architecture</li><li>Complication of horizontal scaling</li></ol><h3>What is Data Indexing? And why do I need to index?</h3><p>If you’re reading this with the knowledge of relational databases and their indexes, it’ll be very easy to grasp whatever I’m about to say, as it’s basically the same concept. We index data to allow for <strong>efficient </strong>search and retrieval of data from the database.</p><p>Imagine you have a list of 2,000,000 names, and you want to find a specific name on the list, how long would that take? You’ll have to practically scan through the list until you find it. Worst case scenario, the name you’re looking for is the last item, you’d have looked through 2,000,000 names to find the one you’re looking for.</p><p>Now imagine you have a mapping of the name keywords to their position on the list. Now if you want to find “John Doe”, you simply lookup the position in the mapping and seek directly to the data instead of having to scan through the entire list.</p><p>Data indexing is basically the process of creating this “mapping” of keywords or data to some kind of “position” where the data is situated. This allows for very efficient search/retrieval of data given a particular search query.</p><h3>Open-source Search Engines — Elasticsearch</h3><p>Now, you may be wondering.. “How does data indexing apply to me and my projects?”</p><p>Most, if not all applications require some sort of search capability. Be it to pull out a customer’s order from your database, or customers searching for a product on your online store. Conventionally, if you store your data in a relational database like MySQL, or even a NoSQL database like MongoDB, “searching” for data would involve crafting some kind of query to instruct the database engine to match whatever you’re looking for to fields in the DB, and return the results.</p><p><strong>Example SQL query:</strong></p><pre>SELECT * FROM Product WHERE name LIKE &#39;%badminton%&#39;<br>OR description LIKE &#39;%badminton%&#39;<br>OR category LIKE &#39;%badminton%&#39;</pre><p>If we want to search into every single field available, you can imagine how long the query can get, not to mention the performance impact.</p><p>Furthermore, if we want to search into the normalized one-to-many or one-to-one data, the query will be a nightmare to build. <strong>E.g.</strong> a product can have multiple tags, which will be represented by one-to-many relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*aIoq_gr-o6mXwgc1v37w5A.png" /><figcaption>ERD of our sample Product-Tags scenario</figcaption></figure><p>Ergo, <a href="https://www.elastic.co/">Elasticsearch</a> to the rescue!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*_-UHjQBIGgo877TvN-1-hw.png" /></figure><p>Elasticsearch (ES) is an open-source full-text search engine that provides scalable search and near real-time search. It comes packed full with features and tools like Logstash and Kibana (<em>more popularly known as ELK stack</em>) for data processing and visualisation.</p><p>The concept of ES is very simple, we save documents into an ES index (similar to a database in RDBMS), and ES provides us with full-text search and other cool search functionalities right out of the box.</p><p>We’re not going to go into the detailed functionality and benefits of using Elasticsearch, that’s way out of the scope. If you’re interested to dive deeper into it, there’s a lot of resources available.</p><h4><strong>“BUT… most RDBMS have their own full-text search functionality!”</strong></h4><p>Yes, that’s true. I’m not going to go into a whole debate of RDBMS full-text search vs specialised search engines like Elasticsearch. But specialised search engines come with advanced feature-set and can scale much more easily.</p><p>To quote someone from <a href="https://www.reddit.com/r/devops/comments/av704k/comment/ehdc47x">Reddit</a>,</p><blockquote>MySQL does nothing well, but everything well enough. It’s a general, flexible relational database. It’s a Toyota Camry.</blockquote><blockquote>Elastic(search) is powerful but complex, and is well suited to its particular domain (search). It’s an F1 car. — htom3heb, Reddit</blockquote><p>Of course, if you’re doing a simple title or name search, stick with your RDBMS query. You don’t need an F1 car for your daily drive to work. But if you want to build your system to scale, and possibly more advanced search, you’ll need something more sophiscated.</p><h3>Message queue/brokers — RabbitMQ</h3><p>It may not be immediately obvious why we’re talking about a message broker and how it fits into the picture, but hear me out first. I’ll get to how we use a message broker in part 2 of this series.</p><p><a href="https://www.rabbitmq.com/">RabbitMQ</a> is a popular open-source message broker that implements the Advanced Message Queuing Protocol (AMQP). It enables inter-application communication in a reliable and interoperable manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*5nrUnyVnqXFvuP2N3uTXlw.png" /><figcaption>Image from <a href="https://www.cloudamqp.com/blog/part1-rabbitmq-for-beginners-what-is-rabbitmq.html">CloudAMQP blog</a></figcaption></figure><h4><strong>Basic Definition</strong></h4><p>The basic concept of a message queue/broker is simple.</p><p>Suppose 2 applications want to communicate with each other. They do so by sending messages through the message queue. 1 of the application will enqueue the message, and the receiving party will dequeue it for processing.</p><p>And as the name suggests, messages are processed in a first-in-first-out basis (i.e. messages enqueued first will be dequeued and processed first).</p><h4><strong>Publish-Subscribe Pattern</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*o3hjnA7wCpuE_AElaYFxMw.png" /><figcaption>Image from <a href="https://www.cloudamqp.com/blog/index.html">CloudAMQP blog</a></figcaption></figure><p>RabbitMQ works on a publish-subscribe pattern. The application publishing messages to the queue is called the <strong>Producer</strong>, and the application(s) consuming the messages are aptly called, the <strong>Consumer</strong>.</p><p>You can have as many consumers as you’d like to subscribe to messages. The message queue manager will handle distribution, as well as acknowledgement of messages after a consumer successfully processed the message.</p><h4>RabbitMQ Topic Exchange</h4><p>How do producers and consumers know where to send/receive the messages to/from? Introducing the Topic Exchange, which forward the messages according to the <em>routing key</em> provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVkQt033gbBYXzRC3-tO6w.png" /><figcaption>Topic Exchange forwarding messages by the routing key</figcaption></figure><p>For example, you can have 3 different routing keys bound to separate queues:</p><ol><li><em>product.create</em></li><li><em>product.modify</em></li><li><em>product.delete</em></li></ol><p>to represent the Create, Update and Delete operation of products in your system. Every time a product is created, updated or deleted, a message can be published into the respective queue using their corresponding routing key. These messages will then be consumed by the consumers who have subscribed to the queue(s) using the routing key.</p><h4><strong>Reliability of published messages</strong></h4><p>One of the main benefits of using a message broker like RabbitMQ is the reliable delivery of data. Once a message is published to a queue, it is persisted on the server’s hard drive until the broker receives an acknowledgement that the message is successfully processed by a consumer. This guarantees a message will always be processed and won’t be lost even in the event of an error or server failure.</p><p>In the event of an application error on the consumer-side while processing the message, a negative acknowledge (nack) can be sent to the broker to requeue the message so it can automatically be consumed again. Essentially a retry mechanism.</p><h3>Conventional data indexing flow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*9G-4T1V95ROkfJSnO-QIYw.png" /></figure><p>The diagram above shows how a system conventionally integrates with Elasticsearch to provide a search functionality. Whenever a C_UD (Create/Update/Delete) operation happens, the data will first be saved/modified in the primary data store (e.g. MySQL), then the same piece of data is pushed into Elasticsearch to be indexed for search purposes. With this flow, every new creation, or modification, will reflect immediately when users search for it.</p><p>However, there are a few problems with this model, which we’ll discuss in part 2 of this series. I’ll also be proposing a more resilient and scalable architecture to index data for search purposes.</p><p><em>Continue reading on part 2 — to be updated</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be17bd1cc32a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hovering on links to see where it leads? It’s not as safe as you think.]]></title>
            <link>https://danongchewseng.medium.com/hovering-on-links-to-see-where-it-leads-its-not-as-safe-as-you-think-a92853a7d4fc?source=rss-cc46d54f1914------2</link>
            <guid isPermaLink="false">https://medium.com/p/a92853a7d4fc</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[phishing]]></category>
            <category><![CDATA[clickjacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Dan Ong Chew Seng]]></dc:creator>
            <pubDate>Tue, 23 Nov 2021 09:02:47 GMT</pubDate>
            <atom:updated>2021-11-23T09:02:47.912Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5aPeDA1U1UZekxcj" /><figcaption>Photo by JJ Ying on Unsplash</figcaption></figure><p>It’s the dreadful Monday again, you pull yourself to your computer and open your email. Ding, comes a new email from what appears to be from your bank, telling you your account is compromised and requires your immediate attention. But you’ve been through enough scam awareness webinars to be wary, you know to look out for obvious signs like poor english, typos or even weird links like <em>www.my-dbs-online.net</em>.</p><p>However, as you hover your cursor over the link in the email, it appears to be legit, linking you directly to <em>https://www.dbs.com.sg</em>. Thinking it’s probably safe, you click on the link and log into your account. The very next day, you realized your bank balance is wiped clean. You’ve fallen victim to what I like to call a “distant-cousin” of clickjacking attack.</p><p>Such a scenario seem improbable, and it is. Modern email clients are sophiscated enough to prevent such attacks. But this technique can be used on any website to disguise a malicious link as a legit one (think a phishing page link disguised as your bank).</p><h3><strong>Mechanism of Attack</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*TxsDznvHM9FmM-4GXpDdAw.gif" /><figcaption>Screen capture of the demo of the Clickjacking attack</figcaption></figure><p>This kind of attack is made possible by intercepting the Javascript <em>onClick </em>event on the Anchor link, and calling:</p><pre>event.preventDefault();</pre><p>to cancel the default behavior of clicking on a link (i.e. redirecting the user to the location stated in <em>href </em>which is what you saw in the browser link preview). Subsequently, Javascript can be used to redirect the user to the malicious link.</p><pre>window.location.replace(&quot;http://www.evil.com&quot;);</pre><p>If the user is not paying attention, he/she may not notice the difference in the URL of the resulting page that loads.</p><h3><strong>Sample Code</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8034d619eca5b723ddcf7a1cc93c0f6/href">https://medium.com/media/e8034d619eca5b723ddcf7a1cc93c0f6/href</a></iframe><h3><strong>Caveat</strong></h3><p>As mentioned in the introduction, this technique won’t work on most modern email clients including your iPhone mail app, Gmail, Outlook, etc. It requires Javascript to work, which is not supported on almost all clients, with the exception of <a href="https://en.wikipedia.org/wiki/Comparison_of_email_clients#Templates,_scripts_and_programming_languages">a few of them</a>.</p><p>Of course, this technique can and is actually used for legitimate purposes. In one of my projects, I use it to capture clicks on a search result page for historical/usage statistics but still allow users to see the original URL when hovered instead of having them see a long proxy url like:</p><pre>https://my-search.com/proxy?link=www.original.com&amp;page=2&amp;rank=4</pre><h3><strong>Potential Mitigations</strong></h3><h4><strong>Check, check, and check.</strong></h4><p>The most obvious way you can prevent falling victim to such an attack will be to always double and triple check the URL of the resulting page after clicking on a link, to make sure that you’re actually in the right place. Additionally, also look out for the green <em>[since 2018, major browsers had been </em><a href="https://www.cnet.com/tech/services-and-software/say-good-bye-to-that-green-secure-lock-on-google-chrome"><em>phasing out</em></a><em> the bright green icon and defaulted to a less prominent color]</em> lock icon that signifies that your connection is secure and authentic, not spoofed by someone else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*GNv6zpcJFxBoLezvv1E8Yg.png" /><figcaption>Check that you’re in the right place, and the connection is secure.</figcaption></figure><h4><strong>Anti-phishing browser extensions</strong></h4><p>Another way you can keep yourself safe, is to install browser extensions that monitors your activity and warn you of any dangerous sites with a big, red warning sign that you can never miss. So even if you’re redirected to a malicious site, you will know for sure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*_q2NIAmlgNctx-olVPFCKg.png" /><figcaption>Big, red WOT warning screen</figcaption></figure><p>One such browser extension is WOT (Web of Trust), that is available for both <a href="https://chrome.google.com/webstore/detail/wot-website-security-brow/bhmmomiinigofkjcapegjjndpbikblnp">Google Chrome</a> and <a href="https://addons.mozilla.org/en-US/firefox/addon/wot-safe-browsing-tool">Firefox</a>.</p><h4><strong>Disable Javascript</strong></h4><p>Last but not least, the most extreme measure will be to disable Javascript on your browser or install an extension like <a href="https://chrome.google.com/webstore/detail/noscript/doojmbjmlfjjnbmnoijecmcbfeoakpjm">NoScript</a> to prevent script execution on some sites. But in the modern Web 2.0 world, disabling Javascript is a definite no-go as that will completely break most sites you visit on a daily basis.</p><h3><strong>Conclusion</strong></h3><p>It may sound like a stretch and implausible, but gullible and people who are less tech-savvy may end up falling victim. It is always good to have awareness of such techniques, be it to counter malicious actors, or if you’re a developer, to employ it in your next project (legitimately, of course).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a92853a7d4fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>