<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>haymiz@kali:~/blog$</title>
    <description>A Diary of a Hacker</description>
    <link>https://haymiz.dev//</link>
    <atom:link href="https://haymiz.dev//feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Insecure CORS Configuration in Fiber Middleware Framework</title>
        <description>&lt;h2 id=&quot;-critical-security-advisory&quot;&gt;🚨 CRITICAL SECURITY ADVISORY&lt;/h2&gt;
&lt;h3 id=&quot;insecure-cors-configuration-in-gofiber-framework&quot;&gt;Insecure CORS Configuration in GoFiber Framework&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;CVE ID:&lt;/strong&gt; &lt;a href=&quot;https://github.com/gofiber/fiber/security/advisories/GHSA-fmg4-x8pw-hjhg&quot;&gt;GHSA-fmg4-x8pw-hjhg&lt;/a&gt;&lt;br /&gt;
&lt;strong&gt;Severity:&lt;/strong&gt; CRITICAL&lt;br /&gt;
&lt;strong&gt;Published:&lt;/strong&gt; February 21, 2024&lt;br /&gt;
&lt;strong&gt;Affected Package:&lt;/strong&gt; github.com/gofiber/fiber/v2&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;-vulnerability-overview&quot;&gt;📋 VULNERABILITY OVERVIEW&lt;/h3&gt;

&lt;p&gt;The GoFiber web framework contains a critical CORS (Cross-Origin Resource Sharing) middleware vulnerability that allows dangerous misconfigurations. The middleware permits setting wildcard origins (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*&lt;/code&gt;) while simultaneously enabling credentials sharing, creating a severe security breach that violates CORS security standards.&lt;/p&gt;

&lt;h3 id=&quot;-affected-versions&quot;&gt;🎯 AFFECTED VERSIONS&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Vulnerable:&lt;/strong&gt; All versions &amp;lt; 2.52.1&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Patched:&lt;/strong&gt; Versions &amp;gt;= 2.52.1&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Components:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;github.com/gofiber/fiber/v2&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;github.com/gofiber/fiber/v2/middleware/cors&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;️-security-impact&quot;&gt;⚠️ SECURITY IMPACT&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Risk Level:&lt;/strong&gt; HIGH to CRITICAL&lt;/p&gt;

&lt;p&gt;This misconfiguration exposes applications to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Unauthorized data access&lt;/strong&gt; from any origin&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Credential theft&lt;/strong&gt; through malicious websites&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Session hijacking&lt;/strong&gt; attacks&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cross-site request forgery (CSRF)&lt;/strong&gt; vulnerabilities&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Data exfiltration&lt;/strong&gt; from authenticated users&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any malicious website can now make credentialed requests to your application, bypassing the same-origin policy that protects users.&lt;/p&gt;

&lt;h3 id=&quot;-technical-details&quot;&gt;🔍 TECHNICAL DETAILS&lt;/h3&gt;

&lt;p&gt;The vulnerability exists in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cors.go&lt;/code&gt; where the middleware fails to validate the dangerous combination of:&lt;/p&gt;
&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;AllowOrigins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;AllowCredentials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This configuration violates RFC specifications and security best practices, as browsers should reject such configurations but the middleware doesn’t prevent developers from creating them.&lt;/p&gt;

&lt;h3 id=&quot;️-immediate-actions-required&quot;&gt;🛠️ IMMEDIATE ACTIONS REQUIRED&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. UPDATE IMMEDIATELY&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;go get github.com/gofiber/fiber/v2@latest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2. AUDIT YOUR CORS CONFIGURATION&lt;/strong&gt;
Review all CORS middleware implementations for:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Wildcard origins with credentials enabled&lt;/li&gt;
  &lt;li&gt;Overly permissive origin lists&lt;/li&gt;
  &lt;li&gt;Missing validation logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. TEMPORARY WORKAROUND&lt;/strong&gt; (if immediate update isn’t possible)
Manually validate CORS settings in your application:&lt;/p&gt;
&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cfg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AllowCredentials&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cfg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AllowOrigins&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;panic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;INSECURE CORS: Cannot use wildcard origin with credentials&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;-recommended-secure-configuration&quot;&gt;✅ RECOMMENDED SECURE CONFIGURATION&lt;/h3&gt;

&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;// SECURE - Specific origins with credentials&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;New&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;AllowOrigins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://yourdomain.com,https://app.yourdomain.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;AllowCredentials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}))&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;// SECURE - Wildcard without credentials&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;New&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;AllowOrigins&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;AllowCredentials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;-references--resources&quot;&gt;📚 REFERENCES &amp;amp; RESOURCES&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&quot;&gt;MDN CORS Documentation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://portswigger.net/web-security/cors&quot;&gt;PortSwigger CORS Exploitation Guide&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://fetch.spec.whatwg.org/#http-cors-protocol&quot;&gt;WHATWG CORS Specification&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/advisories/GHSA-fmg4-x8pw-hjhg&quot;&gt;GitHub Security Advisory&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;Thanks for reading!
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Disclaimer:&lt;/strong&gt; This material is for informational purposes only, and should not be construed as legal advice or opinion. For actual legal advice, you should consult with professional legal services.&lt;/p&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://giscus.app/client.js&quot; data-repo=&quot;haymizrachi/haymizrachi.github.io&quot; data-repo-id=&quot;R_kgDOLLvfpA&quot; data-category=&quot;Announcements&quot; data-category-id=&quot;DIC_kwDOLLvfpM4CpMZa&quot; data-mapping=&quot;pathname&quot; data-strict=&quot;0&quot; data-reactions-enabled=&quot;1&quot; data-emit-metadata=&quot;0&quot; data-input-position=&quot;top&quot; data-theme=&quot;light&quot; data-lang=&quot;en&quot; crossorigin=&quot;anonymous&quot; async=&quot;&quot;&gt;
&lt;/script&gt;

&lt;p&gt;💡 Prefer not to sign in here? You can comment directly on the related GitHub discussion.&lt;/p&gt;
</description>
        <pubDate>Fri, 23 May 2025 12:00:00 +0000</pubDate>
        <link>https://haymiz.dev//security/2025/05/23/go-middleware-cors/</link>
        <guid isPermaLink="true">https://haymiz.dev//security/2025/05/23/go-middleware-cors/</guid>
      </item>
    
      <item>
        <title>Hunting 12 Zero Days in Popular WooCommerce Plugins - A Research Journey</title>
        <description>&lt;p&gt;It all started with a simple question: How secure are the plugins running behind the scenes of WooCommerce-powered stores?
&lt;br /&gt;&lt;br /&gt;
In today’s post, we’ll deep dive into a comprehensive vulnerability research project I conducted back in December 2024. This was a personal initiative, carried out outside of my professional responsibilities, purely driven by my curiosity and interest in the WordPress ecosystem. My main goal was to better understand how WordPress plugins are developed and integrated into the platform.
&lt;br /&gt;&lt;br /&gt;
On December 21, 2024, I analyzed three WooCommerce-related plugins developed by WebToffee — a vendor responsible for several key administrative plugins used for tasks like order exports, customer data imports, and WooCommerce product management. Together, these three plugins are installed on over 240,000 active WordPress sites. Because they shared the same codebase, I discovered identical vulnerabilities across all of them.
&lt;br /&gt;
By the end of December, I submitted my findings, along with working Proof-of-Concept (PoC) exploits for each vulnerability, through the official Wordfence bug bounty program.&lt;/p&gt;

&lt;p&gt;In total, I discovered and reported 12 zero-day vulnerabilities, all of which were successfully validated by the Wordfence triage team. These vulnerabilities were later assigned official CVEs by the CNA in May 2025.&lt;/p&gt;

&lt;p&gt;However, since all of these vulnerabilities required Administrator or higher privileges, they fell outside the scope of Wordfence’s 2025 bug bounty policy. As a result, I was ineligible for any bounty rewards.&lt;/p&gt;

&lt;p&gt;To demonstrate the practical impact of these findings, I’ll be sharing Golang-based PoC code (I’ve recently started learning Go — it’s an incredibly fun language!) that shows how these vulnerabilities can be triggered and exploited.&lt;/p&gt;

&lt;p&gt;These vulnerabilities include PHP Insecure Deserialization, Server-Side Request Forgery (SSRF), and Directory Traversal (These flaws have remained exploitable from the feature’s launch to the latest version). While they require Administrator-level access to exploit, successful exploitation could allow attackers to escalate their attacks and further compromise affected WordPress sites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; WebToffee has since released security patches addressing all reported vulnerabilities, and the fixed versions are now publicly available.&lt;/p&gt;

&lt;p&gt;Full list of assigned CVEs:
&lt;br /&gt;
You can find the complete list of CVEs published via Wordfence here:
https://www.wordfence.com/threat-intel/vulnerabilities/researchers/haymiz&lt;/p&gt;

&lt;p&gt;Affected Plugins (by WebToffee):
&lt;br /&gt;
🔹 Order Export &amp;amp; Order Import for WooCommerce — 90,000+ active installs
&lt;br /&gt;
🔹 Export and Import Users and Customers — 60,000+ active installs
&lt;br /&gt;
🔹 Product Import Export for WooCommerce — 90,000+ active installs&lt;/p&gt;

&lt;p&gt;Assigned CVEs:
&lt;br /&gt;
📌 CVE-2025-1913 – PHP Object Injection via form_data parameter (High)
&lt;br /&gt;
📌 CVE-2025-1912 – Server-Side Request Forgery via validate_file() function (High)
&lt;br /&gt;
📌 CVE-2025-1911 – Directory Traversal to Limited Arbitrary File Deletion via admin_log_page() function (Low)
&lt;br /&gt;
📌 CVE-2024-13923 – Server-Side Request Forgery via validate_file() function (High)
&lt;br /&gt;
📌 CVE-2024-13922 – Directory Traversal to Limited Arbitrary File Deletion via admin_log_page() function (Low)
&lt;br /&gt;
📌 CVE-2024-13921 – PHP Object Injection via form_data parameter (High)
&lt;br /&gt;
📌 CVE-2024-13920 – Directory Traversal to Limited Arbitrary File Read via download_file() function (Medium)
&lt;br /&gt;
📌 CVE-2025-1970 – Server-Side Request Forgery via validate_file() function (High)
&lt;br /&gt;
📌 CVE-2025-1971 – PHP Object Injection via form_data parameter (High)
&lt;br /&gt;
📌 CVE-2025-1972 – Directory Traversal to Limited Arbitrary File Deletion via admin_log_page() function (Low)
&lt;br /&gt;
📌 CVE-2025-1973 – Directory Traversal to Limited Arbitrary File Read via download_file() function (Medium)
&lt;br /&gt;
📌 CVE-2025-1769 – Directory Traversal to Limited Arbitrary File Read via download_file() function (Medium)&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/wordpress_ssrf.png&quot; alt=&quot;wordpress_ssrf&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Server-Side Request Forgery via `validate_file()` function&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/wordpress_arbitrary_file_read.png&quot; alt=&quot;wordpress_arbitrary_file_read&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Directory Traversal to Limited Arbitrary File Read via `download_file()` function&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/wordpress_arbitrary_file_delete.png&quot; alt=&quot;wordpress_arbitrary_file_delete.png&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Directory Traversal to Limited Arbitrary File Deletion via `admin_log_page()` function&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/wordpress_read_and_delete_together.png&quot; alt=&quot;wordpress_read_and_delete_together&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Log Arbitrary File Read and Log Arbitrary File Deletion using `admin_log_page()` and `download_file()` functions&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/wordpress_deseralization.png&quot; alt=&quot;wordpress_deseralization&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;PHP Object Injection (Deserialization) via `form_data` parameter&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;XXXX&lt;/p&gt;

&lt;p&gt;Thanks for reading!
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Disclaimer:&lt;/strong&gt; This material is for informational purposes only, and should not be construed as legal advice or opinion. For actual legal advice, you should consult with professional legal services.&lt;/p&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://giscus.app/client.js&quot; data-repo=&quot;haymizrachi/haymizrachi.github.io&quot; data-repo-id=&quot;R_kgDOLLvfpA&quot; data-category=&quot;Announcements&quot; data-category-id=&quot;DIC_kwDOLLvfpM4CpMZa&quot; data-mapping=&quot;pathname&quot; data-strict=&quot;0&quot; data-reactions-enabled=&quot;1&quot; data-emit-metadata=&quot;0&quot; data-input-position=&quot;top&quot; data-theme=&quot;light&quot; data-lang=&quot;en&quot; crossorigin=&quot;anonymous&quot; async=&quot;&quot;&gt;
&lt;/script&gt;

&lt;p&gt;💡 Prefer not to sign in here? You can comment directly on the related GitHub discussion.&lt;/p&gt;
</description>
        <pubDate>Fri, 28 Mar 2025 12:00:00 +0000</pubDate>
        <link>https://haymiz.dev//security/2025/03/28/wordpress-vulnerability-plugins/</link>
        <guid isPermaLink="true">https://haymiz.dev//security/2025/03/28/wordpress-vulnerability-plugins/</guid>
      </item>
    
      <item>
        <title>From XSS Vulnerability to Full Admin Access</title>
        <description>&lt;p&gt;Welcome back, folks!
&lt;br /&gt;&lt;br /&gt;
In this post, I’ll walk you through a recent real-world engagement where I exploited a stored XSS vulnerability to gain admin access, even with cookie enabled 
protection by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPOnly&lt;/code&gt; flag. I’ll also demonstrate how I able to bypass this security measure to take over the administrative account.
&lt;br /&gt;&lt;br /&gt;
Stay Tuned!
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;A disclaimer before we begin:&lt;/strong&gt; The attack scenario was conducted with the formal approval of the customer.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/cookie_meme.jfif&quot; alt=&quot;cookie_meme&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
Let’s start with a brief explanation of what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPOnly&lt;/code&gt; protection is and how it helps developers prevent attackers from stealing account cookies.
&lt;br /&gt;&lt;br /&gt;
While we’re talking about Cookies, this mechanism is what authenticates a user and distinguishes each one based on their privileges in a web application. Cookies come with various security measures to enhance their safe usage and protect the end user.&lt;/p&gt;

&lt;p&gt;Some of the available Cookies attributes are:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/setcookie_attrs.png&quot; alt=&quot;setcookie_attrs&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;https://www.php.net/manual/en/function.setcookie.php&quot;&gt;setcookie entry on PHP.net documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPOnly&lt;/code&gt; explanation by PHP.net:
&lt;br /&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;When true the cookie will be made accessible only through the HTTP protocol. This means that the cookie won&apos;t be accessible by scripting languages, such as JavaScript.&lt;/code&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Oh, no!&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
What does it mean when, despite our injected XSS payload being part of the HTML DOM, we still can’t access the cookie value to impersonate the victim for an account takeover.
&lt;br /&gt;&lt;br /&gt;
We need to explore alternative pathways to exploit our XSS injection point:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/more_than_xss.jpg&quot; alt=&quot;more_than_xss&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
After a basic explanation of what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPOnly&lt;/code&gt; is, let’s dive deeper into our attack flow:&lt;/p&gt;

&lt;p&gt;Our engagement begins with a client who owns a social media platform featuring user-generated posts and a comments section for interactions from other users.
&lt;br /&gt;&lt;br /&gt;
The comments page of the application looks something like this:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/user_comments_section.png&quot; alt=&quot;user_comments_section&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;The first thing that immediately comes to my mind is injecting a test XSS payload to see if it’s reflected back (either temporarily or persistently) to the frontend of the application.
&lt;br /&gt;&lt;br /&gt;
Unfortunately, this was not the case here due to CloudFlare protection implemented by the admin during the application deployment:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/cf_headers.PNG&quot; alt=&quot;cf_headers&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;CloudFlare was recognized by its known HTTP headers&lt;/p&gt;

&lt;p&gt;This will require us to work much harder to bypass this protection and inject our malicious XSS payload.
&lt;br /&gt;&lt;br /&gt;
We can either try to peel off the CloudFlare Proxy protection and expose the underlying IP address of the web server using some Recon techniques, or find an HTML / JavaScript payload that will ‘fool’ CloudFlare into marking our payload as valid to be running on the frontend.&lt;/p&gt;

&lt;p&gt;This time, I chose to go with the latter option of the two.
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Spoiler Alert&lt;/strong&gt;: It’s going to hurt…&lt;/p&gt;

&lt;p&gt;After several attempts and trying to inject classic XSS payloads from the &lt;a href=&quot;https://github.com/Proviesec/xss-payload-list&quot;&gt;xss-payload-list&lt;/a&gt;, all of the XSS payloads I inserted were filtered out by the CloudFlare proxy and marked as non-executable.&lt;/p&gt;

&lt;p&gt;At this point, I realized I needed to try harder and find a dedicated payload &lt;strong&gt;specifically&lt;/strong&gt; designed to bypass CloudFlare protection.&lt;/p&gt;

&lt;p&gt;Finally, I came up with a working payload that was reflected back into the DOM of the HTML, which was:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/xss_cf_bypass.PNG&quot; alt=&quot;xss_cf_bypass&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;An hidden UI payload using display none css attribute&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
And we received a callback request to our temporary webhook from the XSS!&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/webhook.png&quot; alt=&quot;webhook&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; it’s important to mention that we’re dealing with a &lt;ins&gt;Stored XSS&lt;/ins&gt;, as the comments are saved in the application database and are extracted every time a user visits the relevant post’s comment section.&lt;/p&gt;

&lt;p&gt;Let’s continue on..&lt;/p&gt;

&lt;p&gt;At this point, we have a verified injection point, but we don’t want to stop here. We want to find a way to fully exploit the potential impact of this vulnerability.
&lt;br /&gt;&lt;br /&gt;
Stealing the administrator’s cookie value is &lt;strong&gt;out&lt;/strong&gt; (remember the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPOnly&lt;/code&gt; flag in place?)
&lt;br /&gt;
So, I came to the realization that we could manipulate the HTML DOM directly instead.&lt;/p&gt;

&lt;p&gt;Getting back to the Recon stage..&lt;/p&gt;

&lt;p&gt;During the initial stage of discovering the web application, my Wappalyzer Chrome plugin identified that the web app was written in Python:
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/wappalyzer.PNG&quot; alt=&quot;wappalyzer&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;In the market today, there are a few popular Python frameworks for web development, such as Django and Flask.&lt;/p&gt;

&lt;p&gt;Digging into the HTML source code reveals the use of the Django framework in this case:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/django_framework.png&quot; alt=&quot;django_framework&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Javascript source code exposed Django technology&lt;/p&gt;

&lt;p&gt;This framework is typically managed through the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/admin&lt;/code&gt; path, with a page titled ‘Django Administration’:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/django_admin.png&quot; alt=&quot;django_admin&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;Of course at this point I didn’t have any administrative privileges and got rejected by a message of unauthorized access when attempting to access the page using my already logged-on cookie:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/django_admin_rejected.png&quot; alt=&quot;django_admin_rejected&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hold your breath… the best part is yet to come..&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
So, a brilliant idea came into my mind! We can send behind-the-scenes XHR/AJAX requests to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/admin&lt;/code&gt; path on behalf of the authenticated user (one with admin privileges of course).
&lt;br /&gt;&lt;br /&gt;
This would allow us to steal the HTML content of the Django Admin page, extract the CSRF nonce token, and then send GET/POST requests.
&lt;br /&gt;&lt;br /&gt;
Since we’re operating within the same domain origin, no any Same-origin policy violations occur in this scenario for the returned response content, enabling us to modify, delete, and alter client data, including resetting their personal passwords 😈&lt;/p&gt;

&lt;p&gt;And the jackpot is that &lt;ins&gt;no phishing campaign or any account referrals&lt;/ins&gt; to my XSS page were needed since the comment page is publicly accessible to everyone!&lt;/p&gt;

&lt;p&gt;The final payload attack used a double JavaScript &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt; functions call to first retrieve the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/admin&lt;/code&gt; page contents, and then send the response back to my webhook instance:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/fetch_xss_payload.jfif&quot; alt=&quot;fetch_xss_payload&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bingo!&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
The administrative Django content was captured under the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Raw Content&lt;/code&gt; section as below:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/webhook_django_content.png&quot; alt=&quot;webhook_django_content&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;And finally, the rendered HTML page of the crown jewels 🥳&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/final_django_admin_page.png&quot; alt=&quot;final_django_admin_page&quot; /&gt;
&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;This article demonstrated some unconventional uses of a simple XSS attack, even with strong protections like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPOnly&lt;/code&gt; in place.&lt;/p&gt;

&lt;p&gt;Never underestimate a simple vulnerability like XSS, even in today’s fast-paced, advanced technology-driven webapps. Your imagination can take you to a new heights - use it wisely!&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Thanks for reading!
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Disclaimer:&lt;/strong&gt; This material is for informational purposes only, and should not be construed as legal advice or opinion. For actual legal advice, you should consult with professional legal services.&lt;/p&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://giscus.app/client.js&quot; data-repo=&quot;haymizrachi/haymizrachi.github.io&quot; data-repo-id=&quot;R_kgDOLLvfpA&quot; data-category=&quot;Announcements&quot; data-category-id=&quot;DIC_kwDOLLvfpM4CpMZa&quot; data-mapping=&quot;pathname&quot; data-strict=&quot;0&quot; data-reactions-enabled=&quot;1&quot; data-emit-metadata=&quot;0&quot; data-input-position=&quot;top&quot; data-theme=&quot;light&quot; data-lang=&quot;en&quot; crossorigin=&quot;anonymous&quot; async=&quot;&quot;&gt;
&lt;/script&gt;

&lt;p&gt;💡 Prefer not to sign in here? You can comment directly on the related GitHub discussion.&lt;/p&gt;
</description>
        <pubDate>Mon, 25 Nov 2024 12:00:00 +0000</pubDate>
        <link>https://haymiz.dev//security/2024/11/25/stored-xss-takeover/</link>
        <guid isPermaLink="true">https://haymiz.dev//security/2024/11/25/stored-xss-takeover/</guid>
      </item>
    
      <item>
        <title>Exploring Deserialization Attacks and Their Effects</title>
        <description>&lt;p&gt;Cheers!
&lt;br /&gt;
I took a short break and returned with a new security post :relaxed:
&lt;br /&gt;&lt;br /&gt;
Let’s discuss today on what Deserialization is and give a demonstration example, as it can sometimes can lead to Remote Code Execution (RCE), Privilege Escalation and additional weaknesses with severe impacts on the entire application.
&lt;br /&gt;&lt;br /&gt;
This time, I was digging deep inside the Internet and discovered a cool Deseralization challenge from ‘&lt;a href=&quot;https://ctftime.org/event/119&quot;&gt;Plaid CTF 2014&lt;/a&gt;’ called ‘the kPOP challenge’ which will help us better understand this vulnerability in this blog post.
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Note:&lt;/strong&gt; This challenge can be solved using two different approaches to achieve the same outcome. In this post, we chose to present one of them.
&lt;br /&gt;&lt;br /&gt;
The CTF source code files can be downloaded directly from &lt;a href=&quot;https://github.com/pwning/plaidctf2014/tree/master/web/kPOP&quot;&gt;plaidctf2014 &lt;/a&gt; Github repo.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/i_dunno_what_to_choose.jpeg&quot; alt=&quot;i_dunno_what_to_choose&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Let’s get started –
&lt;br /&gt;&lt;br /&gt;
Applications, in general, often rely on handling serialized data to function correctly. It’s crucial to examine how this data is deserialized to ensure it’s done safely. As attackers or researchers, we focus on instances where data is deserialized without proper validation or where serialized input is directly trusted. These deserialization opportunities, known as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sinks&lt;/code&gt; can occur in a specific functions like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unserialize()&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;serialize()&lt;/code&gt; that depend on user-provided input.
&lt;br /&gt;&lt;br /&gt;
Once we understand what we’re looking for, let’s take a closer look at the application’s source code:
&lt;br /&gt;&lt;br /&gt;
The first step is to identify the PHP classes used within the application and examine their relationships and interactions. This can be easily done by using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CTRL+SHIFT+F&lt;/code&gt; shortcut in Visual Studio Code:
&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/vscode_classes_list.png&quot; alt=&quot;vscode_classes_list&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;In order to better understand the relationships between kPOP classes in a more visual way, we can create a UML diagram based on the above class properties using PlantUML Editor&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;. This diagram represents the system’s structure and design, illustrating the various classes and their relationships, including inheritance, associations, and dependencies:
&lt;br /&gt;&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/kpop_uml.png&quot; alt=&quot;kpop_uml&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;kPOP UML Diagram&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Once we have a basic understanding of the class relations, let’s focus on the relevant &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sinks&lt;/code&gt; that handle serialization based on user-supplied input.
&lt;br /&gt;
Using the same method in VSCode, let’s search for all occurrences of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unserialize&lt;/code&gt; function in the code:
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/unserialize_function.png&quot; alt=&quot;unserialize_function&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;The search results reveal three different occurrences, spread across two files:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;classes.php&lt;/li&gt;
  &lt;li&gt;import.php&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can see that some occurrences of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;serialize&lt;/code&gt; depend on SQL return results (e.g., $row[0]), which are not influenced by user input. However, the other instances appear to be more promising for us.
&lt;br /&gt;&lt;br /&gt;
We will focus on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import.php&lt;/code&gt; file:
&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/unserialize_import_php.png&quot; alt=&quot;unserialize_import_php&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;Which appears like this in the browser UI:&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/import_php_file.png&quot; alt=&quot;import_php_file&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;http://127.0.0.1/kPOP/import.php&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
Class objects are immediately get deserialized once an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unserialize&lt;/code&gt; call is triggered. We can exploit line 5 in the image above to inject our malicious class object, which will be demonstrated later in this article.
&lt;br /&gt;&lt;br /&gt;
At this stage, we have an injection entry point that depends on the provided &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$_POST[&apos;data&apos;]&lt;/code&gt; parameter and get serialized. Let’s now take a closer look at the class declarations themselves.&lt;/p&gt;

&lt;p&gt;When examining the code, the function that immediately caught my eye on is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;file_put_contents&lt;/code&gt; within the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;writeLog&lt;/code&gt; function, located in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogWriter_File&lt;/code&gt; class inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;classes.php&lt;/code&gt; file:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/logwriter_file_put_contents.png&quot; alt=&quot;logwriter_file_put_contents&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;LogWriter_File declaration&lt;/p&gt;

&lt;p&gt;To better understand its usage, I referred to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PHP.net&lt;/code&gt; documentation page:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/file_put_contents_php.png&quot; alt=&quot;file_put_contents_php&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;PHP.net Manual&lt;/p&gt;

&lt;p&gt;This function can be our &lt;ins&gt;first primitive&lt;/ins&gt; for finding a way to write a malicious file on the web server’s filesystem, which could serve as a web shell backdoor for executing shell commands!
&lt;br /&gt;&lt;br /&gt;
So, if we can control the filename written to disk (e.g., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmd.php&lt;/code&gt;) and its contents, we can write PHP code such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;system()&lt;/code&gt; function to execute any command that we want.&lt;/p&gt;

&lt;p&gt;We need to keep this in mind as we piece together the relationships between all the other classes, much like solving a puzzle, to successfully navigate this path and create our final malicious class object 😈&lt;/p&gt;

&lt;p&gt;To put it in a nutshell, when a class object is injected, it begins executing what are called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Magic Methods.&lt;/code&gt; These methods follow a naming convention with double leading and trailing underscores, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__construct()&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__destruct()&lt;/code&gt;. We need to analyze these methods to identify which classes implement them, as they will trigger our object to execute.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Let’s continue on. In order to control the written filename, we need to identify which class holds this filename as a variable and gain control over it in our class object. This is illustrated in the following image:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/logwriter_file_filename.png&quot; alt=&quot;logwriter_file_filename&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Song class contains LogWriter_File object instance&lt;/p&gt;

&lt;p&gt;LogWriter_File is the relevant class. In the class declaration, we can see that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$filename&lt;/code&gt; variable is set to our desired file name within the LogWriter_File constructor (refer to the ‘LogWriter_File Declaration’ picture).&lt;/p&gt;

&lt;p&gt;In the same image, we can also see that the content of the file is stored in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$txt&lt;/code&gt; parameter within the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;writeLog&lt;/code&gt; function of the LogWriter_File class.
&lt;br /&gt;
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$txt&lt;/code&gt; content is controlled by executing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log()&lt;/code&gt; function within the Song class, which consists of a concatenation of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;group&lt;/code&gt; properties of the Song class.&lt;/p&gt;

&lt;p&gt;To control both the filename and content of the file using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;file_put_contents&lt;/code&gt; function, we need to follow the class calling orders and determine where and by whom the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;writeLog&lt;/code&gt; function is invoked.&lt;/p&gt;

&lt;p&gt;Let’s illustrate this in the following picture:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/flow_write_diagram.png&quot; alt=&quot;flow_write_diagram&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Classes calling order&lt;/p&gt;

&lt;p&gt;We can see that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Song&lt;/code&gt; class is the one that initiates the entire class calling sequence to our desired &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;file_put_contents&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;ins&gt;To summarize what we’ve covered so far:&lt;/ins&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;We need to exploit the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;file_put_contents&lt;/code&gt; functionality to write a webshell.&lt;/li&gt;
  &lt;li&gt;We need to initialize the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$filename&lt;/code&gt; variable under the LogWriter_File class with a value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmd.php&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;We need to insert our malicious PHP code as a content to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmd.php&lt;/code&gt; file triggered by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;writeLog&lt;/code&gt; function.&lt;/li&gt;
  &lt;li&gt;Finally, we need to invoke the correct sequence order of classes in our final payload, as shown above.&lt;/li&gt;
&lt;/ol&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/all_the_magic_happens.jpg&quot; alt=&quot;all_the_magic_happens&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;Let’s put all the pieces together to create the payload as a one big serialized object:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;O:6:&quot;Lyrics&quot;:2:{s:9:&quot;*lyrics&quot;;s:12:&quot;shell_lyrics&quot;;s:7:&quot;*song&quot;;O:4:&quot;Song&quot;:4:{s:9:&quot;*logger&quot;;O:6:&quot;Logger&quot;:1:{s:12:&quot;*logwriter&quot;;O:14:&quot;LogWriter_File&quot;:2:{s:11:&quot;*filename&quot;;s:7:&quot;cmd.php&quot;;s:9:&quot;*format&quot;;O:13:&quot;LogFileFormat&quot;:2:{s:10:&quot;*filters&quot;;a:1:{i:0;O:12:&quot;OutputFilter&quot;:2:{s:15:&quot;*matchPattern&quot;;s:19:&quot;/\[i\](.*)\[\/i\]/i&quot;;s:14:&quot;*replacement&quot;;s:9:&quot;&amp;lt;i&amp;gt;\1&amp;lt;/i&amp;gt;&quot;;}}s:7:&quot;*endl&quot;;s:1:&quot;
&quot;;}}}s:7:&quot;*name&quot;;s:35:&quot;&amp;lt;?php system(&apos;ls -l; cat flag&apos;); ?&amp;gt;&quot;;s:8:&quot;*group&quot;;s:11:&quot;shell_group&quot;;s:6:&quot;*url&quot;;s:19:&quot;https:\/\/shell.com&quot;;}}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Take note of the line &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s:11:&quot;*filename&quot;;s:7:&quot;cmd.php&quot;;&lt;/code&gt; which represents our malicious filename with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.php&lt;/code&gt; extension, and the line &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s:7:&quot;*name&quot;;s:35:&quot;&amp;lt;?php system(&apos;ls -l; cat flag&apos;); ?&amp;gt;&quot;;&lt;/code&gt; which represents our PHP &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;system()&lt;/code&gt; function to execute shell commands.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
The final serialized payload to be injected as a HTTP POST parameter in base64 format wil follow:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tzo2OiJMeXJpY3MiOjI6e3M6OToiACoAbHlyaWNzIjtzOjEyOiJzaGVsbF9seXJpY3MiO3M6&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NzoiACoAc29uZyI7Tzo0OiJTb25nIjo0OntzOjk6IgAqAGxvZ2dlciI7Tzo2OiJMb2dnZXIi&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OjE6e3M6MTI6IgAqAGxvZ3dyaXRlciI7TzoxNDoiTG9nV3JpdGVyX0ZpbGUiOjI6e3M6MTE6&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IgAqAGZpbGVuYW1lIjtzOjc6ImNtZC5waHAiO3M6OToiACoAZm9ybWF0IjtPOjEzOiJMb2dG&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aWxlRm9ybWF0IjoyOntzOjEwOiIAKgBmaWx0ZXJzIjthOjE6e2k6MDtPOjEyOiJPdXRwdXRG&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aWx0ZXIiOjI6e3M6MTU6IgAqAG1hdGNoUGF0dGVybiI7czoxOToiL1xbaVxdKC4qKVxbXC9p&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;XF0vaSI7czoxNDoiACoAcmVwbGFjZW1lbnQiO3M6OToiPGk+XDE8L2k+Ijt9fXM6NzoiACoA&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ZW5kbCI7czoxOiIKIjt9fX1zOjc6IgAqAG5hbWUiO3M6MzU6Ijw/cGhwIHN5c3RlbSgnbHMg&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LWw7IGNhdCBmbGFnJyk7ID8+IjtzOjg6IgAqAGdyb3VwIjtzOjExOiJzaGVsbF9ncm91cCI7&lt;/code&gt;
&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;czo2OiIAKgB1cmwiO3M6MTk6Imh0dHBzOlwvXC9zaGVsbC5jb20iO319&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can use the Online PHP Unserializer&lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; to visualize the encoded payload in a Class Object hierarchy:
&lt;br /&gt;&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/unserialize_poc.png&quot; alt=&quot;unserialize_poc&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;PHP Class Object representation&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
And finally, gentlemen, music please — it’s time to execute our malicious serialized payload on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import.php&lt;/code&gt; page!&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/import_final_payload.png&quot; alt=&quot;import_final_payload&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmd.php&lt;/code&gt; file was created, revealing the challenge flag and the execution of our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls -l&lt;/code&gt; command!&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/challenge_flag.png&quot; alt=&quot;challenge_flag&quot; /&gt;
&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;In this article, we presented a deserialization challenge that highlights how it can be exploited by malicious hackers to take over an entire application.&lt;/p&gt;

&lt;p&gt;Those attacks have quite high entry barrier and require strong programming and research skills, making them as one of the most difficult vulnerabilities to identify in web applications. However, they have the most impactful severities once discovered.&lt;/p&gt;

&lt;p&gt;Hope you’ve learned something new to add to your arsenal of vulnerabilities to look for during Code Review engagements.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Thanks for reading!&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;Disclaimer:&lt;/strong&gt; This material is for informational purposes only, and should not be construed as legal advice or opinion. For actual legal advice, you should consult with professional legal services.&lt;/p&gt;

&lt;hr /&gt;

&lt;!-- Giscus Comment Section --&gt;
&lt;script src=&quot;https://giscus.app/client.js&quot; data-repo=&quot;haymizrachi/haymizrachi.github.io&quot; data-repo-id=&quot;R_kgDOLLvfpA&quot; data-category=&quot;Announcements&quot; data-category-id=&quot;DIC_kwDOLLvfpM4CpMZa&quot; data-mapping=&quot;pathname&quot; data-strict=&quot;0&quot; data-reactions-enabled=&quot;1&quot; data-emit-metadata=&quot;0&quot; data-input-position=&quot;bottom&quot; data-theme=&quot;light&quot; data-lang=&quot;en&quot; crossorigin=&quot;anonymous&quot; async=&quot;&quot;&gt;
&lt;/script&gt;

&lt;p&gt;💡 Prefer not to sign in here? You can comment directly on the related GitHub discussion.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://www.plantuml.com/&quot;&gt;PlantUML Online Editor&lt;/a&gt; &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://www.unserialize.com/&quot;&gt;Online PHP Unserializer&lt;/a&gt; &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 07 Sep 2024 12:00:00 +0000</pubDate>
        <link>https://haymiz.dev//security/2024/09/07/deserialization-attacks/</link>
        <guid isPermaLink="true">https://haymiz.dev//security/2024/09/07/deserialization-attacks/</guid>
      </item>
    
      <item>
        <title>Type Juggling and Dangers of Loose Comparisons</title>
        <description>&lt;p&gt;Welcome back,
&lt;br /&gt;
It’s Hay here with another important topic.
&lt;br /&gt;&lt;br /&gt;
Today, I want to discuss about a vulnerability that is rarely talked and often stays under the hood, yet represents a significant security issue once it’s found - ‘Type Juggling’ Vulnerability:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/type_juggling_wtf.jpg&quot; alt=&quot;type_juggling_wtf&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;For a web application to function correctly, it needs to perform various comparison and calculation checks on the backend. These include authorizing users based on their relevant privileges, managing a password reset mechanism for users who have forgotten their passwords, validating sessions to authenticate users, and such on.&lt;/p&gt;

&lt;p&gt;All the examples mentioned above require the use of comparison statements to achieve their functionality properly. Attackers who understand this potential may attempt to bypass these mechanisms to lead to unexpected results.&lt;/p&gt;

&lt;h3 id=&quot;tldr&quot;&gt;TL;DR&lt;/h3&gt;

&lt;p&gt;Programming languages like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PHP&lt;/code&gt; support ‘loose comparison’ operators (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!=&lt;/code&gt;) that interpret equality differently in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt; statements. This can lead to security bypass issues and present risks to the entire application.&lt;/p&gt;

&lt;p&gt;Make sure to check and compare both the value and their type to ensure the comparison is based on strict (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;===&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!==&lt;/code&gt;) comparison.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In PHP versions newer than PHP 5, this issue has been resolved.&lt;/p&gt;

&lt;h3 id=&quot;what-loose-comparison-is-all-about&quot;&gt;What ‘Loose Comparison’ is all about?&lt;/h3&gt;
&lt;p&gt;In languages like PHP, JavaScript, and Ruby, comparison operations are based on the values of variables rather than their types, which is known as ‘loose’ comparison.
&lt;br /&gt;&lt;br /&gt;
This approach can lead to issues in certain cases, unlike ‘strict’ comparison where both value and type must be matched.&lt;/p&gt;

&lt;h3 id=&quot;php-comparision-table&quot;&gt;PHP Comparision Table:&lt;/h3&gt;
&lt;p&gt;To illustrate the differences between loose and strict comparison types, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PHP.net&lt;/code&gt; &lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; presents various use cases scenarios that highlight the importance of using the correct comparison operator to get the right outcomes:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/loose_compare_table.png&quot; alt=&quot;php_loose_comparison_table&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Loose comparisons table&lt;/p&gt;

&lt;p&gt;Versus:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/strict_compare_table.png&quot; alt=&quot;php_strict_comparison_table&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Strict comparisons table&lt;/p&gt;

&lt;p&gt;Some unexpected examples which yields &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;True&lt;/code&gt; in loose comparison, whereas it yields &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;False&lt;/code&gt; in strict comparison:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;php&quot; == 0&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;10 foxes on the tree&quot; == 10&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0e13466324543662017 == 0e5932847&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;wait-0e123456789012345--0e987654321012345-seriously&quot;&gt;Wait, 0e123456789012345 == 0e987654321012345, seriously??&lt;/h3&gt;
&lt;p&gt;Yes, you are not wrong 😃&lt;/p&gt;

&lt;p&gt;In ‘Type-Juggling’, strings that start with “0e” followed by digits (like “0e13466324543662017” or “0e5932847”) are considered equal to zero (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;) in ‘loose comparison’.&lt;/p&gt;

&lt;p&gt;Consider these examples:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;var_dump(“0e13466324543662017” == “0e5932847”); // bool(true)&lt;/li&gt;
  &lt;li&gt;var_dump(“0e13466324543662017” == 0); // bool(true)&lt;/li&gt;
  &lt;li&gt;var_dump(“0e5932847” == “0”); // bool(true)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This case study can play a significant role when we want to bypass comparison checks if we have control over the parameters in the equation.&lt;/p&gt;

&lt;h3 id=&quot;md5-attack-scenario&quot;&gt;MD5 Attack Scenario:&lt;/h3&gt;
&lt;p&gt;Let’s take a look at a code snippet responsible for validating the authenticated user’s cookie to grant them the appropriate privileges on the web application:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/vulnerable_cookie_validation.png&quot; alt=&quot;vulnerable_cookie_validation&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;From the attacker’s perspective, we can see that the function receives the cookie from the user’s side, which consists of three parts:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Username cookie&lt;/li&gt;
  &lt;li&gt;Token cookie&lt;/li&gt;
  &lt;li&gt;Date Expiration cookie&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We have control over the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;username&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expiration&lt;/code&gt; cookie values, while the token is pulled from the database. We do not know its value because we do not own the ‘Admin’ account.&lt;/p&gt;

&lt;p&gt;On line 14, we can see the ‘loose comparison’ operator (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;), which &lt;ins&gt;hints&lt;/ins&gt; at a Type-Juggling vulnerability. Let’s find a way to exploit this check to impersonate the ‘Admin’ account.&lt;/p&gt;

&lt;p&gt;So, if we follow the rule that “0e[0-9]{10}” == “0” (pay attention to the substr in the snippet code - we need only 10 first digits match), we can make our equation evaluate to TRUE and be authenticated.&lt;/p&gt;

&lt;h4 id=&quot;lets-examine-the-following-flow&quot;&gt;Let’s examine the following flow:&lt;/h4&gt;
&lt;p&gt;If we set “0” as the value for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$cookie_token&lt;/code&gt; cookie and control &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$final_token&lt;/code&gt; to return a string in the format of “0e..”, we’ll be successful. But how do we get &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$final_token&lt;/code&gt; to be starting with “0e” when we only control &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$cookie_expiration&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;&lt;ins&gt;The answer:&lt;/ins&gt; Brute force technique!&lt;/p&gt;

&lt;p&gt;The attack will require brute-forcing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$cookie_expiration&lt;/code&gt; values until the final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$final_token&lt;/code&gt; value begins with “0e” followed by only digits. Since we do not know the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$user_token&lt;/code&gt; value at this point, an ‘Online Brute Force’ attack is necessary here.&lt;/p&gt;

&lt;p&gt;I’ve developed a short Python PoC code to demonstrate that:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/brute_force_python_script.png&quot; alt=&quot;brute_force_python_script&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;The final HTTP request payload will look like this:
&lt;br /&gt;
cookie: username=admin; token=0; expiration=1858339652;&lt;/p&gt;

&lt;p&gt;Take into consideration that the expiration value will be different for each user depending on his &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$user_token&lt;/code&gt; value.&lt;/p&gt;

&lt;h3 id=&quot;null--0---oh-no-strikes-again&quot;&gt;NULL == 0 - Oh no, Strikes Again??&lt;/h3&gt;
&lt;p&gt;Let’s take another example, but this time we’ll focus on the ‘strcmp’ function, which compares two different strings to find a match between them:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/strcmp_scenario.png&quot; alt=&quot;strcmp_scenario&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;As you can see, the function ‘login’ is receiving the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pass&lt;/code&gt; arguments from the client side. It then pulls the password for the account directly from the database and compares the pulled password to the provided one using the ‘strcmp’ PHP built-in function.&lt;/p&gt;

&lt;p&gt;So, in order to bypass this check, we need to figure out the correct password for the ‘admin’ account that we want to impersonate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meanwhile, on PHP.net…&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While looking at the ‘strcmp’ documentation on PHP.net, we noticed some user comments warning against using this function due to its potential for ‘extremely unpredictable’ behavior caused by string comparison mismatches in certain circumstances:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/php_strcmp_comment.png&quot; alt=&quot;php_strcmp_comment&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
    &lt;a href=&quot;https://www.php.net/manual/en/function.strcmp.php#108563&quot;&gt;&apos;strcmp&apos; function comments from PHP.net&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;What we can understand from this comment is that strcmp(NULL, “Whatever_We_Put_In”) will always return ZERO, which leads to a successful string matching and will &lt;strong&gt;pass the check!!&lt;/strong&gt; 😈&lt;/p&gt;

&lt;p&gt;So, if we able to find a way to pass a NULL value instead of the secret password, we won.&lt;/p&gt;

&lt;p&gt;Based on the PHP.net user comments above, we can infer the following flow:
&lt;br /&gt;
strcmp(“foo”, array()) =&amp;gt; NULL &amp;lt;=&amp;gt; NULL == 0
&lt;br /&gt;&lt;br /&gt;
&lt;ins&gt;Note:&lt;/ins&gt; PHP treats NULL as 0.&lt;/p&gt;

&lt;p&gt;If we send an array as the password parameter, PHP will treat it as an empty array, confirming the conclusion above:
&lt;br /&gt;
&lt;a href=&quot;https://localhost/login.php?username=admin&amp;amp;password[]=&apos;&apos;&quot;&gt;https://192.168.1.100/login.php?username=admin&amp;amp;password[]=’’&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is ‘Type-Juggling’ attack, requires some creativity, yet it can result in devastating impact!&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;This article aims to present high risk vulnerability that we can sometimes find in the wild once we have access to the application’s source code, and may potentially risking the entire application.&lt;/p&gt;

&lt;p&gt;This vulnerability is not new, but not many people have heard about it, and discovering it can be a game-changer for the attacker.&lt;/p&gt;

&lt;p&gt;For additional information and materials, I highly recommend referring to ‘PayloadsAllTheThings / Type Juggling’ &lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; resource.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Thanks for reading!&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;Disclaimer:&lt;/strong&gt; This material is for informational purposes only, and should not be construed as legal advice or opinion. For actual legal advice, you should consult with professional legal services.&lt;/p&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://giscus.app/client.js&quot; data-repo=&quot;haymizrachi/haymizrachi.github.io&quot; data-repo-id=&quot;R_kgDOLLvfpA&quot; data-category=&quot;Announcements&quot; data-category-id=&quot;DIC_kwDOLLvfpM4CpMZa&quot; data-mapping=&quot;pathname&quot; data-strict=&quot;0&quot; data-reactions-enabled=&quot;1&quot; data-emit-metadata=&quot;0&quot; data-input-position=&quot;top&quot; data-theme=&quot;light&quot; data-lang=&quot;en&quot; crossorigin=&quot;anonymous&quot; async=&quot;&quot;&gt;
&lt;/script&gt;

&lt;p&gt;💡 Prefer not to sign in here? You can comment directly on the related GitHub discussion.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://www.php.net/manual/en/types.comparisons.php&quot;&gt;PHP Type Comparison Table&lt;/a&gt; &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Type%20Juggling/README.md&quot;&gt;PayloadsAllTheThings GitHub&lt;/a&gt; &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Thu, 13 Jun 2024 12:00:00 +0000</pubDate>
        <link>https://haymiz.dev//security/2024/06/13/type-juggling-vulnerability/</link>
        <guid isPermaLink="true">https://haymiz.dev//security/2024/06/13/type-juggling-vulnerability/</guid>
      </item>
    
      <item>
        <title>Automating API Vulnerability Testing Using Postman Workflows</title>
        <description>&lt;p&gt;Hello there, Hay is here.
&lt;br /&gt;
It’s been quite a while since I wrote my last post, so let’s begin!
&lt;br /&gt;&lt;br /&gt;
Today, I’m excited to introduce you a new cool feature by Postman platform that I’ve recently discovered which has the potential to save you time and enhance your efforts on demonstrating API vulnerabilities.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/omg_yes_please.jpg&quot; alt=&quot;omg_yes_please&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;When we discuss on providing API PoC vulnerabilities for Bug Hunting programs or customer reports, the classic method involves providing a short Python script to demonstrate the full impact (Dana Epp’s done a good job on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;&lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; - Thank you man!).&lt;/p&gt;

&lt;p&gt;In the following article, I’ll introduce a new alternative approach that can also be effective in certain cases which focusing on the GUI approach, and doesn’t even require any programming skills !&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For demostartion purposes, all the presented examples will be showed on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OWASP crAPI&lt;/code&gt;&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; project that serves as a vulnerable API’s platform for new beginners who want to start their hacking learning process.
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;what-is-postman-platform&quot;&gt;What is Postman Platform?&lt;/h3&gt;

&lt;p&gt;Postman is an API tool development platform that simplify the process of building, testing, and managing API’s under a group of HTTP requests that called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This tool offers a wide range of built-in capabilities for interacting with API requests, for example:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Load &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OpenAPI&lt;/code&gt; specifications as API documentation&lt;/li&gt;
  &lt;li&gt;Execute a sequence of HTTP requests using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection Runner&lt;/code&gt; feature&lt;/li&gt;
  &lt;li&gt;Interact with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GraphQL&lt;/code&gt; API instances&lt;/li&gt;
  &lt;li&gt;Visualizing outcomes using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Postman Visualizer&lt;/code&gt; tool&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And finally the crown jewels: the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Postman Workflows&lt;/code&gt; feature.&lt;/p&gt;

&lt;p&gt;So,&lt;/p&gt;

&lt;h3 id=&quot;what-postman-workflows-is-all-about&quot;&gt;What Postman Workflows is all about?&lt;/h3&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/postman_flows_demonstration.gif&quot; alt=&quot;postman_flows_demonstration&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
    &lt;a href=&quot;https://learning.postman.com/docs/postman-flows/gs/flows-overview/&quot;&gt;Demonstration by Animation&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;Postman Workflows is based on a &lt;ins&gt;sequence of HTTP requests&lt;/ins&gt; that need to occur in a certain flow to achieve its goal. For example, combining a series of dependent requests (passing some parameters between them) to achieve a BOLA (Broken Object-Level Authorization) vulnerability, iterating over a list of API requests that implement a pagination feature to pull out all of it data, you got the idea :smiley:
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;bola-demonstration-using-workflow&quot;&gt;BOLA Demonstration using Workflow&lt;/h3&gt;

&lt;p&gt;For our workflow creation, let’s demonstrate it using the first crAPI challenge: accessing details of another user’s vehicle location as a &lt;a href=&quot;https://github.com/OWASP/crAPI/blob/develop/docs/challenges.md&quot;&gt;BOLA vulnerability&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After signing up on the crAPI platform and adding my own vehicle under my profile, there is a blue button called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Refresh Location&lt;/code&gt;. Clicking this button will trigger a background API GET request including my vehicle’s unique UUID as a parameter, providing us with the vehicle’s real-time location:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/my_vehicle_request.png&quot; alt=&quot;my_vehicle_request&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Getting my vehicle location by passing vehicle&apos;s UUID paramter&lt;/p&gt;

&lt;p&gt;The response of the request will provide us with the vehicle location using the carId as a UUID parameter. If we can change the carId to a different UUID belonging to another user and receive their vehicle location, we have found a BOLA vulnerability. All we need to do is find a way to obtain the UUIDs of other victims and exploit them in this request:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/my_vehicle_response.png&quot; alt=&quot;my_vehicle_response&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Returned latitude and longitude vehicle data&lt;/p&gt;

&lt;p&gt;By using the community page of the crAPI platform, we can obtain all victims data, including their vehicleId, which represents their car’s UUID parameter to be provided in the above request. With this information, we can iterate over each vehicleId and send a request to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/identity/api/v2/vehicle/UUID_PARAMETER/location&lt;/code&gt; endpoint to receive their vehicle’s location and achieve our malicious goal:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/community_vehicle_id_exposure.png&quot; alt=&quot;community_vehicle_id_exposure&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Community page exposed all victims personal information&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
So, let’s summarize this into one flow:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Retrieve all victims personal information from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/community/api/v2/community/posts/recent&lt;/code&gt; endpoint.&lt;/li&gt;
  &lt;li&gt;Iterate through each result in the list and extract the vehicleId associated with each victim.&lt;/li&gt;
  &lt;li&gt;For each vehicleId, use it as a UUID parameter and send an HTTP GET request to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/identity/api/v2/vehicle/UUID_PARAMETER/location&lt;/code&gt; endpoint.&lt;/li&gt;
  &lt;li&gt;Print out the results.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;br /&gt;
Workflows come into play to help us automate this entire process. The final workflow will look like this:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/crapi_vehicle_postman_workflow.png&quot; alt=&quot;crapi_vehicle_postman_workflow&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;BOLA Flow (&lt;a href=&quot;https://haymiz.dev//images/crapi_vehicle_postman_workflow.png&quot;&gt;Click here for higher picture resolution&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Now, let’s break down each part of the graph:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/workflow_explain_1.png&quot; alt=&quot;workflow_explain_1&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;First part of the Workflow&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The workflow starts running from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Start&lt;/code&gt; orange label, serving as the entry point of the flow.&lt;/li&gt;
  &lt;li&gt;Immediately after that, the first HTTP request is executed to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/community/api/v2/community/posts/recent&lt;/code&gt; endpoint. (This endpoint was previously saved as an HTTP request in my Postman &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt; section)&lt;/li&gt;
  &lt;li&gt;This block is then divided into two separate parts:
    &lt;ul&gt;
      &lt;li&gt;Handling the request when it’s considered a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Success&lt;/code&gt; (i.e., when a 200 HTTP Status Code is returned).&lt;/li&gt;
      &lt;li&gt;Handling the request when it’s considered a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Fail&lt;/code&gt; (i.e., when a 400/500 HTTP Status Code is returned).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;In this case, we only want to handle the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Success&lt;/code&gt; part. Therefore, at this step, we extract the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTP Body&lt;/code&gt; of the response, which contains the victims’ data.&lt;/li&gt;
  &lt;li&gt;Next, we iterate over each victim’s data returned. To accomplish this, we use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;For&lt;/code&gt; block loop, which functions similarly to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt; loop in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Python&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;From each of the returned victim JSON lists, our focus is on extracting the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vehicleId&lt;/code&gt;, which will be sent to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/identity/api/v2/vehicle/UUID_PARAMETER/location&lt;/code&gt; endpoint.&lt;/li&gt;
&lt;/ol&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/workflow_explain_2.png&quot; alt=&quot;workflow_explain_2&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Second part of the Workflow&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The flow continues by passing the vehicleId from the previous response as a Postman pre-defined &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VEHICLE_ID&lt;/code&gt; variable and adding additional &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Send Request&lt;/code&gt; block to trigger the BOLA API request with this parameter.&lt;/li&gt;
  &lt;li&gt;Once again, we extract the data directly from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTP Body&lt;/code&gt; section of the returned response.&lt;/li&gt;
  &lt;li&gt;To merge all of the returned victims’ data from the BOLA request into one comprehensive output, we utilize the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collect&lt;/code&gt; block.&lt;/li&gt;
  &lt;li&gt;Finally, we display the victims’ real-time vehicle locations using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Output&lt;/code&gt; block.
&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;summarizing-up&quot;&gt;Summarizing Up&lt;/h3&gt;

&lt;p&gt;In the end, Postman Workflows can enhance your automation and presentation skills by allowing you to easily build drag-and-drop flows with just a click of a button.&lt;/p&gt;

&lt;p&gt;For more coverage on this topic, I’m providing you a link to a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Youtube Playlist&lt;/code&gt;&lt;sup id=&quot;fnref:4&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:4&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; of a short series presenting additional workflow features. You can learn from and use these for your demonstrations, both for fun and profit.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;Disclaimer:&lt;/strong&gt; This material is for informational purposes only, and should not be construed as legal advice or opinion. For actual legal advice, you should consult with professional legal services.&lt;/p&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://giscus.app/client.js&quot; data-repo=&quot;haymizrachi/haymizrachi.github.io&quot; data-repo-id=&quot;R_kgDOLLvfpA&quot; data-category=&quot;Announcements&quot; data-category-id=&quot;DIC_kwDOLLvfpM4CpMZa&quot; data-mapping=&quot;pathname&quot; data-strict=&quot;0&quot; data-reactions-enabled=&quot;1&quot; data-emit-metadata=&quot;0&quot; data-input-position=&quot;top&quot; data-theme=&quot;light&quot; data-lang=&quot;en&quot; crossorigin=&quot;anonymous&quot; async=&quot;&quot;&gt;
&lt;/script&gt;

&lt;p&gt;💡 Prefer not to sign in here? You can comment directly on the related GitHub discussion.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://danaepp.com/writing-api-exploits-in-python&quot;&gt;Writing API exploits in Python by DANA Epp&lt;/a&gt; &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://github.com/OWASP/crAPI&quot;&gt;OWASP crAPI&lt;/a&gt; &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:4&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://youtube.com/playlist?list=PLM-7VG-sgbtCWIWHJSXdJPbahXb_QWWEC&amp;amp;si=kidlwrwYo0boUEK5&quot;&gt;Postman Flows Playlist by Postman&lt;/a&gt; &lt;a href=&quot;#fnref:4&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 27 Apr 2024 12:00:00 +0000</pubDate>
        <link>https://haymiz.dev//security/2024/04/27/automating-apis-with-postman-workflows/</link>
        <guid isPermaLink="true">https://haymiz.dev//security/2024/04/27/automating-apis-with-postman-workflows/</guid>
      </item>
    
      <item>
        <title>Code Review Like a Pro</title>
        <description>&lt;p&gt;Hello everyone!
&lt;br /&gt;
Welcome to my first blog post! I’m excited to be here :smile:&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Today, I’m going to share with you my own research methodology for analyzing and reviewing source code applications to identify vulnerabilities on Whitebox engagements.&lt;/p&gt;

&lt;p&gt;Whitebox assessments refer to a specific security testing scenario where the attacker/tester &lt;strong&gt;has prior access&lt;/strong&gt; to the internal workings of the application, including its architecture, schemas or source code files. This access enables them to identify vulnerabilities more quickly and efficiently compared to the blackbox approach, which is what this article will be talking about.&lt;/p&gt;

&lt;p&gt;The following article will focus on source code files that we are able to obtain or find using some Recon techniques (which will be explore in a future blog posts).&lt;/p&gt;

&lt;p&gt;The skill of finding bugs and weaknesses inside a code that you don’t familiar with and getting into the developer mind’s required to be experienced with code reading - &lt;strong&gt;and a lot of it&lt;/strong&gt;, but I can promise to you, it will &lt;ins&gt;get much easier over time&lt;/ins&gt; as long as you practice and deal with code on your daily basis.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/code_review_meme.jpg&quot; alt=&quot;shut_up_please&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;So let’s get started…&lt;/p&gt;

&lt;h3 id=&quot;approaches-to-perform-code-review&quot;&gt;Approaches to perform Code Review:&lt;/h3&gt;

&lt;p&gt;There are numerous different ways to investigate code, which are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Covering code line by line&lt;/li&gt;
  &lt;li&gt;Focusing on low-hanging fruit functions such as Login, Registration, and Password Reset mechanisms&lt;/li&gt;
  &lt;li&gt;Greping regex keywords for quick-wins&lt;/li&gt;
  &lt;li&gt;Following user input using bottom-up and top-down approaches&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s break those things up:&lt;/p&gt;

&lt;h4 id=&quot;covering-line-by-line&quot;&gt;Covering line by line:&lt;/h4&gt;
&lt;p&gt;In cases where the project we are checking is considered large, this approach will consume a significant amount of time to cover end to end. Therefore, it is more suitable for projects with a small number of code files to cover.&lt;/p&gt;

&lt;h4 id=&quot;focus-on-low-hanging-fruit-functions&quot;&gt;Focus on Low-hanging fruit functions:&lt;/h4&gt;
&lt;p&gt;This approach involves prioritizing web application mechanisms where the severity of identifying weaknesses and vulnerabilities is higher due to the complexity of requirements, such as validations, checks, and dependencies on other internal functions, thus we will focus on functions such as Login, Register, Forgot Password, Upload Files, and more.&lt;/p&gt;

&lt;h4 id=&quot;greping-regex-keywords-for-quick-wins&quot;&gt;Greping regex keywords for quick-wins:&lt;/h4&gt;
&lt;p&gt;One of the fastest and quickest ways to achieve success in finding vulnerabilities is by looking after a list of keywords and dangerous functions that could potentially lead to weaknesses. Examples include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;username&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;password&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;token&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;system&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shell_exec&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;move_uploaded_file&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;file_get_contents&lt;/code&gt;, and other equivalent functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Don’t forget to adapt your keyword vocabulary to the programming language you’re researching.&lt;/p&gt;

&lt;h4 id=&quot;following-user-input-using-bottom-up-and-top-down-approaches&quot;&gt;Following user input using bottom-up and top-down approaches:&lt;/h4&gt;
&lt;p&gt;This strategy is based on the functionality of web applications, which rely on user input and are controlled by it in order to work appropriately. For example, variables like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$_GET&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$_POST&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$_COOKIE&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$_REQUEST&lt;/code&gt; are commonly used.&lt;/p&gt;

&lt;p&gt;The bottom-up and top-down approaches is based on the concepts of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sink&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source&lt;/code&gt; terms. The former refer to any part of the program that may be influenced by external data, while the latter refer any input or external data that enters a system.
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;the-power-of-tools&quot;&gt;The Power of Tools&lt;/h3&gt;

&lt;p&gt;A Security Researcher without his tools is like a baker without his mixer gentlemens, so we need to discuss on some tools that can save us a lot of time during our research and automate our efforts.&lt;/p&gt;

&lt;p&gt;One of the main thoughts that need to be in your head is - ‘How can I save time to make the process more efficient and more focused to achieving better results than the manual process?’&lt;/p&gt;

&lt;p&gt;As discussed earlier, the process of covering line by line, code by code is  very time-consuming process that we want to avoid. Therefore, we seek to apply the best fit approach presented above to the specific code project we are handle with.&lt;/p&gt;

&lt;p&gt;Let’s explore some awesome tools:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;cloc&lt;/li&gt;
  &lt;li&gt;graudit&lt;/li&gt;
  &lt;li&gt;TruffleHog&lt;/li&gt;
  &lt;li&gt;Driftwood&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cloc&quot;&gt;cloc:&lt;/h3&gt;
&lt;p&gt;A cool tool that I’ve discovered recently called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cloc&lt;/code&gt;&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; (‘Count Lines of Code’) that quickly assess the files content - such as comments, blank lines, and the actual code count.
This tool can give us some first imperssions on the material before we get our hands dirty with the code:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/cloc.png&quot; alt=&quot;cloc_output&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;cloc categorized the code content by its counts&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The ‘cloc –show-lang’ command will shows us the code languages that supported by this tool:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;ABAP                       (abap)&lt;br /&gt;
ActionScript               (as)&lt;br /&gt;
Ada                        (ada, adb, ads, pad)&lt;br /&gt;
ADSO/IDSM                  (adso)&lt;br /&gt;
Agda                       (agda, lagda)&lt;br /&gt;
AMPLE                      (ample, dofile, startup)&lt;br /&gt;
Ant                        (build.xml, build.xml)&lt;br /&gt;
ANTLR Grammar              (g, g4)&lt;br /&gt;
Apex Class                 (cls)&lt;br /&gt;
Apex Trigger               (trigger)&lt;br /&gt;
APL                        (apl, apla, aplc, aplf, apli, apln, aplo, dyalog, dyapp, mipage)&lt;br /&gt;
Arduino Sketch             (ino, pde)&lt;br /&gt;
AsciiDoc                   (adoc, asciidoc)&lt;br /&gt;
ASP                        (asa, ashx, asp, axd)
&lt;br /&gt;
..&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;graudit&quot;&gt;graudit:&lt;/h3&gt;
&lt;p&gt;Another tool that can save us time during our research is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;graudit&lt;/code&gt;&lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; (‘grep rough audit’) tool. This tool is signature-based that utilizes a large dataset of popular programming codes. Behind the scenes, it runs predefined keywords using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grep&lt;/code&gt; utility with severity to identify vulnerabilities in a code section:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/graudit.png&quot; alt=&quot;graudit_output&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;graudit detected some potential vulnerable code requiring further examination&lt;/p&gt;

&lt;p&gt;An output results of this tool could be a  line focus on a function that depends on user input or an SQL statement executed without passing through a sanitation check before, or &lt;strong&gt;for god’s sake&lt;/strong&gt; - existence of command execution functions that controlled by the end user:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/rce_born.png&quot; alt=&quot;how_rce_are_born&quot; /&gt;
&lt;/p&gt;

&lt;h3 id=&quot;trufflehog&quot;&gt;TruffleHog&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TruffleHog&lt;/code&gt;&lt;sup id=&quot;fnref:3&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:3&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; is a powerful open-source tool designed to detect secrets and leaked credentials that might be accidentally or intentionally left behind within Git repositories or raw filesystems. It achieves this by scanning all commit histories to identify high-entropy strings, which may indicate the presence of API keys, passwords, and other types of credentials.&lt;/p&gt;

&lt;p&gt;As discussed previously, our goal is to identify the quickest wins and expose the crown jewel assets, and this tool comes to help us achieving this.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/crown_jewel.jpg&quot; alt=&quot;crown_jewel_pic&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;In the picture below, while running the tool against a GitHub repo, we can see the tool is able to find an exposed SSH private key, an API key of the PagerDuty asset, and even a MongoDB database connection string:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/trufflehog_secrets.png&quot; alt=&quot;trufflehog_secrets_output&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;By the way, there is also a cool TruffleHog extension specifically built for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Google Chrome&lt;/code&gt;&lt;sup id=&quot;fnref:4&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:4&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt; that monitors API keys and credentials on websites we visit. Once the extension found one, it immediately alerts with a popup on the screen:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/trufflehog_chrome_ext.png&quot; alt=&quot;trufflehog_chrome_plugin&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Secrets revealed without the need to dig into the source code&lt;/p&gt;

&lt;h3 id=&quot;driftwood&quot;&gt;Driftwood&lt;/h3&gt;

&lt;p&gt;Additional tool from the same open-source creators is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Driftwood&lt;/code&gt;&lt;sup id=&quot;fnref:5&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:5&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;5&lt;/a&gt;&lt;/sup&gt;, which continues the process of TruffleHog’s tool output once a private key is found.&lt;/p&gt;

&lt;p&gt;Many times, we come a across hard-coded private SSH/TLS keys, and we’re not always certain about which asset they belong to. Private keys have a small number of use cases that typically used for TLS and SSH protocols.&lt;/p&gt;

&lt;p&gt;So, the purpose of this tool is to take a given Private Key, derive its Public Key component, and then perform lookups on a large database set of known exposed public keys in order to determine its belonging asset:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://haymiz.dev//images/driftwood_output.png&quot; alt=&quot;driftwood_output_poc&quot; /&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;Found 2 matches of TLS certificates to a given Private Key&lt;/p&gt;

&lt;p&gt;You can read more about &lt;a href=&quot;https://trufflesecurity.com/blog/driftwood-know-if-private-keys-are-sensitive/&quot;&gt;here&lt;/a&gt; to figure out how it really works behind the scenes.
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;wrapping-up&quot;&gt;Wrapping Up&lt;/h3&gt;

&lt;p&gt;The ideas and techniques presented in this article are just the tip of the iceberg in becoming a Code Reviewer master. I hope you learned one or two things you didn’t knew before.&lt;/p&gt;

&lt;p&gt;For those who want to take this a step further, I highly recommend the OSWE&lt;sup id=&quot;fnref:6&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:6&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;6&lt;/a&gt;&lt;/sup&gt; course by Offensive Security to gain additional hands-on practice covering all the necessary knowledge and techniques to achive this goal.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
Thank you for reading!&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;Disclaimer:&lt;/strong&gt; This material is for informational purposes only, and should not be construed as legal advice or opinion. For actual legal advice, you should consult with professional legal services.&lt;/p&gt;

&lt;hr /&gt;

&lt;script src=&quot;https://giscus.app/client.js&quot; data-repo=&quot;haymizrachi/haymizrachi.github.io&quot; data-repo-id=&quot;R_kgDOLLvfpA&quot; data-category=&quot;Announcements&quot; data-category-id=&quot;DIC_kwDOLLvfpM4CpMZa&quot; data-mapping=&quot;pathname&quot; data-strict=&quot;0&quot; data-reactions-enabled=&quot;1&quot; data-emit-metadata=&quot;0&quot; data-input-position=&quot;top&quot; data-theme=&quot;light&quot; data-lang=&quot;en&quot; crossorigin=&quot;anonymous&quot; async=&quot;&quot;&gt;
&lt;/script&gt;

&lt;p&gt;💡 Prefer not to sign in here? You can comment directly on the related GitHub discussion.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;cloc - &lt;a href=&quot;https://github.com/AlDanial/cloc&quot;&gt;https://github.com/AlDanial/cloc&lt;/a&gt;. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;graudit - &lt;a href=&quot;https://github.com/wireghoul/graudit&quot;&gt;https://github.com/wireghoul/graudit&lt;/a&gt;. &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:3&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;TruffleHog - &lt;a href=&quot;https://github.com/trufflesecurity/trufflehog&quot;&gt;https://github.com/trufflesecurity/trufflehog&lt;/a&gt;. &lt;a href=&quot;#fnref:3&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:4&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;TruffleHog for Chrome - &lt;a href=&quot;https://chromewebstore.google.com/detail/trufflehog/bafhdnhjnlcdbjcdcnafhdcphhnfnhjc&quot;&gt;https://chromewebstore.google.com/detail/trufflehog/&lt;/a&gt;. &lt;a href=&quot;#fnref:4&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:5&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Driftwood - &lt;a href=&quot;https://github.com/trufflesecurity/driftwood&quot;&gt;https://github.com/trufflesecurity/driftwood&lt;/a&gt;. &lt;a href=&quot;#fnref:5&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:6&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;WEB-300 - &lt;a href=&quot;https://www.offsec.com/courses/web-300/&quot;&gt;https://www.offsec.com/courses/web-300/&lt;/a&gt;. &lt;a href=&quot;#fnref:6&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Mon, 19 Feb 2024 12:00:00 +0000</pubDate>
        <link>https://haymiz.dev//security/2024/02/19/code-review-like-a-pro/</link>
        <guid isPermaLink="true">https://haymiz.dev//security/2024/02/19/code-review-like-a-pro/</guid>
      </item>
    
  </channel>
</rss>
