<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yuvarajan on Medium]]></title>
        <description><![CDATA[Stories by Yuvarajan on Medium]]></description>
        <link>https://medium.com/@UVvirus?source=rss-5d667013e60f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*F-lSgxwjCleLzgR3WYBPMw.jpeg</url>
            <title>Stories by Yuvarajan on Medium</title>
            <link>https://medium.com/@UVvirus?source=rss-5d667013e60f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:49:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@UVvirus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Leak a $340B Secret: The Anthropic “Claude Code” Incident]]></title>
            <link>https://infosecwriteups.com/how-to-leak-a-340b-secret-the-anthropic-claude-code-incident-663b3d6e3bb4?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/663b3d6e3bb4</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Wed, 01 Apr 2026 16:50:53 GMT</pubDate>
            <atom:updated>2026-04-06T07:11:48.873Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ruqGwfHW5hs7C3_vI-u5Q.png" /></figure><p>I genuinely thought this was an April Fool’s prank. Every year, companies like Google pull some elaborate stunt, so when I saw the “Claude Code leak” trending on April 1st, I kept scrolling.</p><p>But out of curiosity, I checked the npm registry for @anthropic-ai/claude-code. The version everyone was talking about (<strong>v2.1.88</strong>)?</p><p><strong>Gone.</strong> Not deprecated. Not hidden. Just scrubbed from existence.</p><p>That’s when it stopped looking like a joke.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*w19AzjX_Q_e_bzUSaaGv7w.png" /><figcaption>where is v2.1.88?</figcaption></figure><h3>What Actually Happened</h3><p>This wasn’t a sophisticated zero-day or a database breach. It is just a bad release.</p><p>It was a perfect example of how modern software supply chains fail fast and fail publicly:</p><ul><li><strong>The Trigger:</strong> Anthropic pushed an update to npm.</li><li><strong>The Cargo:</strong> Inside the package was a <strong>59.8 MB</strong> debug artifact.</li><li><strong>The Payload:</strong> A .map file (cli.js.map) that didn&#39;t just map code—it contained the sourcesContent for the entire project.</li></ul><h3>The Timeline of Chaos</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SHNXEkyPf1pRaTVKgLaLAA.png" /></figure><ul><li><strong>T+0 mins:</strong> Version 2.1.88 hits npm.</li><li><strong>+23 mins:</strong> Security researcher <strong>Chaofan Shou</strong> notices the unusual file size and downloads the package.</li><li><strong>+45 mins:</strong> The source is extracted. It’s not just snippets; it’s <strong>1,900+ TypeScript files</strong> and <strong>512,000+ lines</strong> of proprietary logic.</li><li><strong>+2 hours:</strong> The GitHub mirrors start to appear, before the first DMCA notice can even be drafted.</li><li><strong>+6 hours:</strong> The “clean-room” rewrites begin. A Python port and a Rust rewrite (likely AI-assisted) exploded.</li></ul><h3>What is a Source Map actually?</h3><p>A source map is a JSON file that acts as a bridge between your “ Production Code” and your “Development Code.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D--Dyrgzuh1E_JWLGGV02w.png" /></figure><p><strong>Why this exists:</strong></p><p>Modern web development is a series of transformations:</p><ul><li><strong>TypeScript</strong> → Compiled to <strong>JavaScript</strong></li><li><strong>Modern JS</strong> → Transpiled for compatibility (Babel)</li><li><strong>Code</strong> → Bundled and Minified (Vite, Webpack, or in Anthropic’s case, <strong>Bun</strong>)</li></ul><p>The final code is a single-line mess. If an error happens in production, your stack trace looks like this: Error at a.js:1:98432. You are effectively blind.</p><p><strong>The Fix:</strong></p><p>A source map tells the browser: <em>“Line 1, column 98432 in bundle.js actually maps to line 42 in </em><em>AuthService.ts.&quot;</em></p><h3>How to Extract Code from .map Files</h3><p>If you’re a dev and you see a .map file in the wild, here is how you &quot;reverse&quot; it.</p><h4>Method 1: The DevTools Way</h4><ol><li>Open Chrome DevTools → <strong>Sources</strong> tab.</li><li>If the site has maps enabled, look for a folder usually named webpack:// or file://.</li><li>You can browse the original source tree, set breakpoints, and read comments exactly as the author wrote them.</li></ol><h4>The Billion-Dollar String: Why sourcesContent is a Security Nightmare</h4><p>If you open that .map file in a text editor instead of a browser, you’ll see why DevTools is able to show you the original code.</p><p>Most people don’t realize there are two ways a source map handles your files:</p><ol><li><strong>Reference Maps:</strong> They just point to paths (e.g., &quot;sources&quot;: [&quot;src/main.ts&quot;]). If a hacker downloads this, they get a list of your filenames, but the files are empty because they don&#39;t have access to your local machine&#39;s file system.</li><li><strong>Inline Maps (The “Anthropic” Way):</strong> These include the sourcesContent field. This is a massive array of strings containing the <strong>actual raw source code</strong> of every single file in your project.</li></ol><p><strong>This is what Anthropic did.</strong> They didn’t just point to the code; they bundled the entire repository <em>inside</em> the map file. When you have sourcesContent, DevTools doesn&#39;t need to look for your files on a server—it already has the full text sitting right there in the JSON. What We Learned (The “Undercover Mode” and more)</p><p>The leak revealed more than just code; it revealed Anthropic’s roadmap:</p><ul><li><strong>“Kairos”:</strong> An unreleased daemon mode that allows Claude to run as an always-on background agent.</li><li><strong>“Undercover Mode”:</strong> A feature that strips AI attribution from commits so devs can contribute to public repos “silently.”</li><li><strong>“Buddy”:</strong> A full-blown pet/Tamagotchi system (likely the intended April Fool’s release) with rarity tiers and “shiny” variants.</li></ul><h3>The Security Takeaway</h3><ul><li><strong>Your build pipeline is a bigger risk than hackers.</strong> A single misconfigured .npmignore or a missing files field in package.json can bypass all your firewalls.</li><li><strong>Deletion is an illusion.</strong> Anthropic nuked the package within hours, but by then, it was already mirrored in 40,000 places.</li><li><strong>Check your Bundler.</strong> Anthropic uses <strong>Bun</strong>. Bun (and Vite/Webpack) make it very easy to generate maps; you must be explicit about <em>where</em> those maps go.</li></ul><p><strong>Pro-tip:</strong> Use a tool like source-map-explorer As part of your CI/CD, visualize what you&#39;re actually shipping before it hits the registry.</p><h3>References:</h3><p><a href="https://github.com/chatgptprojects/clear-code/tree/642c7f944bbe5f7e57c05d756ab7fa7c9c5035cc?tab=readme-ov-file">https://github.com/chatgptprojects/clear-code/tree/642c7f944bbe5f7e57c05d756ab7fa7c9c5035cc?tab=readme-ov-file</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=663b3d6e3bb4" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/how-to-leak-a-340b-secret-the-anthropic-claude-code-incident-663b3d6e3bb4">How to Leak a $340B Secret: The Anthropic “Claude Code” Incident</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Asked My AI to Find Vulnerable AI. It Found 2,442]]></title>
            <link>https://infosecwriteups.com/i-asked-my-ai-to-find-vulnerable-ai-it-found-2-442-dd68ce522832?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd68ce522832</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Sat, 31 Jan 2026 16:07:10 GMT</pubDate>
            <atom:updated>2026-02-12T05:27:32.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuEgbVmrf6eJlsQoiM-W2A.png" /></figure><p>Hello Hackers!!! Ever wondered what happens when you set an AI assistant loose to hunt for security vulnerabilities in… other AI assistants? Today, I’m sharing something wild: I used my Clawdbot to scan the internet for exposed Clawdbot instances, and what we found is both fascinating and terrifying.</p><p><strong>TL;DR:</strong> 2,442 AI assistant instances are leaking sensitive information through misconfigured mDNS broadcasts. One of them? Completely open to the internet with ZERO authentication. Anyone could have taken full control.</p><p>This isn’t theoretical. This is happening right now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*UxWbPNiEnsUFNXK2ohq2Gg.png" /></figure><h3>The Setup: AI Hunting AI</h3><p>Clawdbot is a personal AI assistant that runs on your own infrastructure. It’s powerful — it can execute commands, read files, access your conversations, and integrate with platforms like WhatsApp, Telegram, and Slack.</p><p>I was curious: how many people are running Clawdbot in the wild? And more importantly, how many of them are doing it securely?</p><p>So I asked my Clawdbot: <strong>”Find other Clawdbot instances on the internet.”</strong></p><p>What happened next was… concerning.</p><h3>The Discovery: 2,442 Exposed Instances</h3><p>Using Shodan (a search engine for internet-connected devices), my AI assistant discovered <strong>2,442 Clawdbot instances</strong> actively broadcasting their presence on the internet.</p><p><strong>Geographic breakdown:</strong><br>- 🇩🇪 Germany (Hetzner): ~416 instances<br>- 🇺🇸 United States (DigitalOcean, Linode): ~760 instances<br>- 🇦🇪 UAE: ~319 instances<br>- 🇸🇬 🇭🇰 🇫🇷 🇬🇧: Multiple instances each</p><p>From hobbyists running personal AI assistants on home servers to businesses deploying them on cloud infrastructure, all are inadvertently exposing themselves.</p><p><strong>What’s going wrong?</strong> Let’s dig in.</p><h3>The Leak: mDNS Broadcasting Everything</h3><p>Clawdbot uses <strong>mDNS (Multicast DNS)</strong> for device discovery. It’s the same technology that lets your iPhone find your AirPods or your laptop discover printers on your local network.</p><p>The problem? <strong>mDNS doesn’t know the difference between “local network” and “the entire internet.”</strong></p><p>When you run Clawdbot on a VPS without proper firewall configuration, it broadcasts on port 5353:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwOiZ1T-gGj8_FRBaM6KnA.png" /></figure><h3>The Attack Vector: From Recon to Exploitation</h3><p>Let me walk you through how an attacker would exploit an exposed Clawdbot instance.</p><h4>Step 1: Find the Target</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8I1jcIB2FbKTUHL120hqQ.png" /></figure><p>Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qnX5LTwK89d5NZ59pG0nw.png" /></figure><h4>Step 2: Extract Information</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exdYAGspDU829Q8NlxkTWA.png" /></figure><h4>Step 3: Probe the Gateway</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*kvs_AQqYapsLWzFWttUvuw.png" /></figure><h4>Step 4: Attempt WebSocket Connection</h4><p>The Clawdbot gateway uses WebSocket for RPC (Remote Procedure Call) commands. Let’s try connecting:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1JdfR872JZ8401jqn2uBg.png" /></figure><p><strong>The gateway accepts WebSocket connections.</strong> If there’s no authentication challenge… you’re in.</p><h4>Step 5: Send RPC Commands</h4><p>Once connected via WebSocket, you can send JSON-RPC commands:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8RwfrL3BmHHPul6usPMdg.png" /></figure><p><strong>What can an attacker do with this access?</strong></p><h3>Case Study: The Unauthenticated Gateway</h3><p>Out of the 2,442 instances we found, one stood out. Let’s call it <strong>Instance X</strong></p><p><strong>Configuration:</strong><br>- Hosted on Google Cloud Platform<br>- Port 18789 publicly accessible<br>- WebSocket endpoint open<br>- <strong>Zero authentication required</strong></p><p><strong>The test:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*Da0EIBq2dmAIfQIVqdRBmQ.png" /></figure><p><strong>No authentication challenge. No login prompt. Just… access.</strong></p><p>Next, I tested the WebSocket upgrade:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlWAAcQ_qzPhsA4_P-ycxw.png" /></figure><p><strong>WebSocket connection established. No authentication required.</strong></p><h4>What This Means</h4><p>With unauthenticated WebSocket access, an attacker could:</p><p><strong>1. Read Everything</strong><br>- Session transcripts (all private conversations)<br>- Credentials (API keys, OAuth tokens, channel tokens)<br>- SSH keys<br>- Environment files<br>- Source code<br>- Personal documents</p><p><strong>2. Execute Anything</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvChNXjQ2rAaxQjO86w-SA.png" /></figure><p><strong>3. Control the AI</strong><br>- Send messages as the owner<br>- Access WhatsApp, Telegram, Slack accounts<br>- Manipulate conversations<br>- Impersonate the owner</p><p><strong>4. Pivot to Other Systems</strong><br>- Use as a launchpad for attacks on internal networks<br>- Steal cloud credentials (AWS, GCP, Azure)<br>- Scan for other vulnerable services</p><p><strong>5. Crypto-mine or Botnet</strong><br>- Use compute resources for cryptocurrency mining<br>- Enlist in a DDoS botnet<br>- Burn through expensive AI API credits</p><h4>The Scary Part</h4><p>This instance had been running for <strong>21+ hours</strong> (uptime: 78190 seconds) completely exposed.</p><p>How many people had already discovered it? How long had it been vulnerable? Had anyone already exploited it?</p><p><strong>We don’t know.</strong></p><p>— -</p><h4>The Exploit Code: AI Pentesting AI</h4><p>I created a proof-of-concept exploit script to test the vulnerability. My Clawdbot wrote code to compromise other Clawdbots. But I&#39;m not going to share it here.</p><p><strong>Meta-irony: An AI assistant writing exploit code for AI assistants.</strong></p><h4>Why Are People Vulnerable?</h4><p>After analyzing the 2,442 instances, common patterns emerged:</p><ol><li><strong>Default Configuration</strong><br>Many users run Clawdbot with default settings:<br>- mDNS enabled (mode: “full” instead of “minimal”)<br>- No firewall rules<br>- Gateway bound to `0.0.0.0` instead of `127.0.0.1`</li></ol><p><strong>2.</strong> <strong>“It’s Just a Personal Project.”</strong><br>Running on a VPS, thinking “no one will find my little server.”</p><p><strong>Wrong.</strong> Shodan scans the entire IPv4 address space regularly. Your server WILL be found.</p><p><strong>3. Skipping the Security Docs</strong><br>Clawdbot has excellent security documentation. Most people skip it.</p><p>From the docs:<br>&gt; “Treat inbound DMs as untrusted input.”<br>&gt; “Keep gateway.bind on loopback unless you have authentication configured.”<br>&gt; “Run clawdbot security audit regularly.”</p><p>How many actually do this? Based on our findings: <strong>not enough.</strong></p><p><strong>4. Cloud Defaults</strong><br>Cloud VPS providers (DigitalOcean, Hetzner, Linode) often:<br>- Have permissive default firewall rules<br>- Enable IPv6 by default (another attack surface)<br>- Allow all outbound connections</p><p>Users deploy Clawdbot, it works, they move on. Never realizing port 5353 and 18789 are wide open.</p><p><strong>5. Running as Root</strong><br>We found <strong>multiple instances</strong> with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*My_OkbrDVjg5nmYSbvJZBQ.png" /></figure><p>Running AI assistants with shell access as root? That’s a security nightmare.</p><p>— -</p><h4>The Bigger Picture: AI Security is Hard</h4><p>This isn’t just about Clawdbot. This is about a broader trend:</p><p><strong>AI assistants are becoming infrastructure.</strong></p><p>They have access to:<br>- Your private conversations<br>- Your files and code<br>- Your credentials and API keys<br>- Your cloud environments<br>- Your communication channels</p><p>When they’re compromised, <strong>everything</strong> is compromised.</p><p><strong>The New Threat Model</strong></p><p>Traditional security assumes:<br>- Humans make decisions<br>- Code is reviewed<br>- Access is controlled</p><p>AI assistants blur these lines:<br>- They make autonomous decisions<br>- They write and execute code on the fly<br>- They bridge multiple systems and accounts</p><p><strong>Prompt injection</strong> becomes <strong>remote code execution</strong>.<br><strong>Information disclosure</strong> becomes <strong>full system compromise</strong>.<br><strong>Misconfiguration</strong> becomes <strong>total infrastructure takeover</strong>.</p><h3>Lessons Learned: What This Taught Us</h3><h4>1. “Security Through Obscurity” Doesn’t Work</h4><p><strong>The myth:</strong> “My server is just one of millions. No one will find it.”</p><p><strong>The reality:</strong> Shodan found 2,442 instances. It took 30 seconds.</p><p>Your server is not hidden. It’s indexed, cataloged, and searchable.</p><h4>2. Default Configurations Are Dangerous</h4><p>Most security breaches happen because:<br>- People use default credentials<br>- Default ports are exposed<br>- Default services are running</p><p>Clawdbot’s defaults (mDNS enabled, no forced auth) prioritize usability. That’s understandable, but dangerous.</p><p><strong>Lesson:</strong> First-run wizards should include security setup, not just feature setup.</p><h4>3. Security Documentation Isn’t Enough</h4><p>Clawdbot has <strong>excellent</strong> security docs. But here’s what we learned from the 2,442 exposed instances:</p><p><strong>People don’t read the docs.</strong></p><p>Or they read them after deployment. Or they bookmark them “to read later.”</p><p><strong>Lesson:</strong> Security should be enforced by the tool, not just documented.</p><h4>4. The “Personal Project” Mentality</h4><p>Many exposed instances appeared to be:<br>- Personal hobby projects<br>- Development/staging environments<br>- Quick experiments</p><p>The thinking: “It’s not production, so security doesn’t matter.”</p><p><strong>Wrong.</strong> That “personal project” server still has:<br>- Your SSH keys<br>- Your cloud credentials<br>- Your private conversations<br>- Your API tokens</p><p><strong>Lesson:</strong> Treat every deployment like it’s production.</p><h4>5. AI Makes Attack Automation Trivial</h4><p>I spent <strong>maybe 2 hours total</strong> on this research:<br>- 15 minutes to ask my AI to search Shodan<br>- 30 minutes analyzing results<br>- 1 hour writing proof-of-concept exploit code (with AI help)</p><p><strong>Lesson:</strong> The attacker’s barrier to entry has collapsed. Defenses need to keep pace.</p><h4>6. Meta-Responsibility</h4><p>When you run an AI assistant with access to sensitive data:<br>- You’re responsible for securing it<br>- You’re responsible for what it can do<br>- You’re responsible for what happens if it’s compromised</p><p>It’s not just “your data at risk.” It’s every conversation, every credential, every system the AI touches.</p><p><strong>Lesson:</strong> AI infrastructure requires the same security rigor as production databases</p><h3>Conclusion: The Era of AI Security</h3><p>We’re entering an era where:<br>- AI tools have infrastructure-level access<br>- Misconfigurations are trivial to find<br>- Exploitation is automatable<br>- The blast radius is massive</p><p>This research took my AI assistant <strong>2 hours</strong>. A dedicated attacker could have automated:<br>- Finding all 2,442 instances<br>- Testing each for vulnerabilities<br>- Exploiting the weakest ones<br>- Exfiltrating credentials<br>- Moving laterally to other systems</p><p><strong>All automated. All in an afternoon.</strong></p><h4>The Irony</h4><p>I used an AI assistant to find vulnerable AI assistants. The same tool that empowers us to be more productive also empowers attackers to be more efficient.</p><h4>The Call to Action</h4><p><strong>If you’re running Clawdbot (or any AI infrastructure):</strong></p><p>1. Run `clawdbot security audit — deep — fix` <strong>right now</strong><br>2. Enable authentication<br>3. Bind to localhost or use Tailscale<br>4. Disable or minimize mDNS<br>5. Set up proper firewall rules</p><p><strong>If you’re building AI tools:</strong></p><p>1. Make security the default, not an option<br>2. Provide in-product security guidance<br>3. Audit on every startup<br>4. Educate your users<br>5. Build intrusion detection from day one</p><p><strong>If you’re using AI in production:</strong></p><p>1. Treat it like infrastructure (because it is)<br>2. Regular security audits<br>3. Principle of least privilege<br>4. Monitoring and alerting<br>5. Incident response planning</p><h3>Final Thought</h3><p>This wasn’t about exposing Clawdbot or attacking anyone. It was about showing:</p><p><strong>When powerful tools are easy to deploy, they’re also easy to misuse.</strong></p><p>The solution isn’t to make tools harder to use. It’s to make security <strong>impossible to skip</strong>.</p><p>Let’s build the AI future responsibly. Our AI assistants deserve better security. So do we.</p><p>— -</p><h4>References</h4><p>- [Clawdbot GitHub Repository](<a href="https://github.com/openclaw/openclaw.git">https://github.com/openclaw/openclaw.git</a>)<br>- [Clawdbot Security Documentation](<a href="https://docs.openclaw.ai/gateway/security">https://docs.openclaw.ai/gateway/security</a>)<br>- [Shodan Search Engine](<a href="https://www.shodan.io/">https://www.shodan.io/</a>)<br>- [mDNS Protocol (RFC 6762)](<a href="https://tools.ietf.org/html/rfc6762">https://tools.ietf.org/html/rfc6762</a>)<br>- [WebSocket Protocol (RFC 6455)](<a href="https://tools.ietf.org/html/rfc6455">https://tools.ietf.org/html/rfc6455</a>)</p><p>— -</p><p><strong>Got questions?</strong></p><p>- Follow me on Medium: [<a href="http://twitter.com/uvvirus">@uvvirus</a>](<a href="https://medium.com/@uvvirus">https://medium.com/@uvvirus</a>)<br>- My GitHub: [github.com/uvvirus]<br>- My X Handle: [<a href="https://x.com/UV_virus">https://x.com/UV_virus</a>]</p><p>Stay secure, Hackers. 🔒🦞</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd68ce522832" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/i-asked-my-ai-to-find-vulnerable-ai-it-found-2-442-dd68ce522832">I Asked My AI to Find Vulnerable AI. It Found 2,442</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gRPC for Beginners: What It Is and Why You Should Care]]></title>
            <link>https://medium.com/@UVvirus/grpc-for-beginners-what-it-is-and-why-you-should-care-ecb52e8e6dc5?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecb52e8e6dc5</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Sat, 11 Oct 2025 19:02:37 GMT</pubDate>
            <atom:updated>2025-10-11T19:02:37.117Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*q6A1Y0j6AMiDeNrMBhLkEg.png" /></figure><h3>Introduction: The Problem with REST at Scale</h3><p>If you’ve built APIs before, you’ve probably used REST. It’s simple, widely understood, and works great for most use cases. But as your application grows and you start building microservices that need to talk to each other constantly, REST can become a bottleneck.</p><p>JSON parsing, HTTP/1.1 overhead, and the lack of type safety start to add up. That’s where gRPC comes in.</p><h3>What is gRPC?</h3><p><strong>gRPC</strong> stands for <strong>Google Remote Procedure Call</strong>. It’s an open-source framework developed by Google for building high-performance APIs.</p><p>Here’s the key idea: instead of making HTTP requests to endpoints, you call functions on a remote server as if they were local functions. The complexity of network communication is abstracted away.</p><h3>Key Components</h3><ul><li><strong>Protocol Buffers (protobuf)</strong>: A binary serialization format (think JSON but binary and typed)</li><li><strong>HTTP/2</strong>: Modern protocol with multiplexing, streaming, and better performance</li><li><strong>Code Generation</strong>: Automatically generates client and server code in multiple languages</li></ul><h3>Who Uses gRPC?</h3><ul><li>Netflix (for internal microservices)</li><li>Square (payment processing)</li><li>Cisco (networking products)</li><li>Uber (real-time services)</li><li>And many more companies operating at scale</li></ul><h3>Why gRPC?</h3><p>Let’s break down the major benefits:</p><h3>1. Performance</h3><p>gRPC uses Protocol Buffers, which are binary and much smaller than JSON. This means:</p><ul><li>Faster serialization/deserialization</li><li>Less bandwidth usage</li><li>Lower latency</li></ul><p><strong>Real-world impact</strong>: 3–5x faster than REST in many benchmarks.</p><h3>2. Type Safety</h3><p>With REST, your API contract is often just documentation. With gRPC, you define your API in a .proto file with strict types. This catches errors at compile time, not runtime.</p><h3>3. Streaming Support</h3><p>gRPC supports four types of communication:</p><ol><li><strong>Unary</strong>: Traditional request-response (like REST)</li><li><strong>Server Streaming</strong>: Server sends multiple responses</li><li><strong>Client Streaming</strong>: Client sends multiple requests</li><li><strong>Bidirectional Streaming</strong>: Both sides stream data simultaneously</li></ol><p>This makes real-time features like chat, live updates, or IoT data streams much easier.</p><h3>4. Language Agnostic</h3><p>Write your server in Go, your mobile client in Swift, and your web backend in Python. gRPC handles the communication seamlessly.</p><h3>5. Auto Code Generation</h3><p>Define your API once in a .proto file, and gRPC generates all the boilerplate client and server code for you. Less code to write means fewer bugs.</p><h3>Use gRPC When:</h3><ul><li>Building microservices that communicate internally</li><li>Performance is critical</li><li>You need real-time bi-directional streaming</li><li>You want strong typing and code generation</li><li>You’re building polyglot systems (multiple languages)</li></ul><h3>Use REST When:</h3><ul><li>Building public APIs for third-party developers</li><li>Browser-based applications (without a proxy)</li><li>Simplicity and wide compatibility are priorities</li><li>You need human-readable debugging</li><li>Your team is already familiar with REST</li></ul><p><strong>Bottom line</strong>: For internal microservices, gRPC is often the better choice. For public-facing APIs, REST might still be king.</p><h3>Hands-On: Creating Your First Proto File</h3><p>Let’s build a simple User Service. This is where everything starts in gRPC — the .proto file.</p><h3>Step 1: Define the Service</h3><p>Create a file called user.proto:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X1SvL_2xKZzsSjVNz-JgBg.png" /></figure><h3>Step 2: Understanding the Proto Syntax</h3><ul><li>syntax = &quot;proto3&quot;: Specifies Protocol Buffers version 3</li><li>service UserService: Defines your API service</li><li>rpc GetUser(...): Defines a remote procedure call (method)</li><li>message GetUserRequest: Defines the data structure</li><li>Field numbers (= 1, = 2): Used for binary encoding (don&#39;t change once deployed!)</li><li>stream: Indicates streaming responses</li></ul><h3>Step 3: Generate Python Code</h3><p>Install the gRPC tools:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*qWJJtVwIUpvfrd-58fKKTQ.png" /></figure><p>Generate the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ldy95fJHxeivCmYFE2uuJQ.png" /></figure><p>This creates two files:</p><ul><li>user_pb2.py: Contains message classes</li><li>user_pb2_grpc.py: Contains service client and server classes</li></ul><h3>Step 4: Implement the Server (Python)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3LAXApbx8FyRYGdAg455w.png" /></figure><h3>Step 5: Create a Client</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*psm_ezFnYMVRyDGO9YyC9Q.png" /></figure><p>And that’s it! You’ve created your first gRPC service.</p><h3>Common Pitfalls to Avoid</h3><ol><li><strong>Forgetting to regenerate code</strong>: Always regenerate Python files after changing .proto files</li><li><strong>Not using TLS in production</strong>: The example uses insecure_channel - use proper SSL/TLS for production</li><li><strong>Ignoring error handling</strong>: Always handle RPC errors properly</li><li><strong>Changing field numbers</strong>: Once deployed, never change field numbers in proto files</li></ol><h3>Next Steps</h3><p>Now that you understand the basics:</p><ol><li><strong>Add authentication</strong>: Implement interceptors for auth</li><li><strong>Explore streaming</strong>: Try server and bidirectional streaming</li><li><strong>Add error handling</strong>: Use gRPC status codes properly</li><li><strong>Deploy it</strong>: Try containerizing your gRPC service</li><li><strong>Monitor it</strong>: Set up observability with metrics and tracing</li></ol><h3>Conclusion</h3><p>gRPC is a powerful tool for building high-performance, type-safe APIs. While it has a steeper learning curve than REST, the benefits for microservices and internal communication are substantial.</p><p>Start small, build a simple service, and gradually explore advanced features like streaming and interceptors. The investment in learning gRPC pays off quickly, especially as your systems grow.</p><p><strong>What will you build with gRPC?</strong></p><p><em>Building tools and breaking things in cybersecurity. Follow my journey at [</em><a href="https://x.com/UV_virus"><em>@UV_virus</em></a><em>]</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecb52e8e6dc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Developer’s Guide: Moving Files to iPhone Over an HTTP Server]]></title>
            <link>https://medium.com/@UVvirus/the-developers-guide-moving-files-to-iphone-over-an-http-server-1ff55450e893?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ff55450e893</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Wed, 01 Oct 2025 17:14:10 GMT</pubDate>
            <atom:updated>2025-10-01T18:14:22.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nl7_1k5yb93zwEfhGgYJdA.jpeg" /></figure><p>I recently tried moving my Android data to an iPhone, only to run into some quirks with Apple’s <em>Move to iOS</em> app.</p><p>Here’s the catch:</p><ul><li>The app works only during the <strong>initial setup</strong> of the iPhone.</li><li>If you forget to transfer some files, you can’t just add them later. The only option is to <strong>reset your iPhone</strong> and start over.</li></ul><h4>This becomes a problem if:</h4><ul><li>You already started using the iPhone and still have old files on your Android.</li><li>You want to clean up your old phone and transfer just the remaining files without resetting your iPhone.</li></ul><h4>Exploring Alternatives</h4><p>So, I started looking for other options.<br> ChatGPT suggested uploading the files to Google Drive and then downloading them on the iPhone. But with ~100GB of data to move and only 15GB of free Drive storage (already filled with photos and documents), that wasn’t really practical.</p><p>While digging around further, I came across the <strong>“Connect to Server”</strong> feature in the Files app. That’s when it clicked — what if I set up my Android phone as an HTTP server and transfer the files directly?</p><h3>The Plan</h3><p>Here’s the idea:</p><ul><li>Turn the Android phone into a server on the local network.</li><li>Connect the iPhone to the same Wi-Fi.</li><li>Access the server from the iPhone and download the files.</li></ul><p>To do this, the first step is installing a terminal app — I used <strong>Termux</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*In9VWtMJ5sVrNCdvutv5Qg.png" /></figure><p>Next, install Python in Termux:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*54XxbBl3EA829IfaQJlfRQ.png" /></figure><p>Give Termux permission to access your storage:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*-xQXxFJ6MuyFtKsbv37ZFg.png" /></figure><p>You’ll see a pop-up — grant the permissions. To verify that storage access is working, run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*6dxgN9pRU2AlvOjqYtCdEA.png" /></figure><p>You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wRvbBCXoh0HlA-_-UYSy8w.jpeg" /></figure><h3>Preparing the Files</h3><p>To transfer large batches of files over an HTTP server, it’s easier to <strong>zip them first</strong>. Otherwise, you’d need to download each file one by one.</p><p>So, install the zip package in Termux:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*lZaKcj7sk821LYQ3TEKIPA.png" /></figure><p>Then, locate your files and create a zip archive with the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*wm77KpVTwwmIkV1EYfuxOg.png" /></figure><p>You can also create the zip with any file manager you prefer. Just remember: the zip is mainly for <strong>grouping files together</strong> — it won’t actually make them smaller, especially if they’re photos or videos.</p><p>That’s because most media formats (like JPEG for images and MP4 for videos) are already compressed. Since they’re encoded with algorithms that remove redundancy, zipping them won’t shrink the size much further.</p><h4>Starting the Server</h4><p>Now, let’s start the Python HTTP server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*IxuUwfrcHKqYFl2vH54hew.png" /></figure><p>It should display output like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EK7upzyOOAf_k8D1ocS0Yw.jpeg" /></figure><p>In another Termux window, type the following command and copy the IP address shown under the <strong>inet</strong> section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*7DLyTg6rMul1W8P8ZtN9mQ.png" /></figure><p>Make sure your iPhone is connected to the same Wi-Fi as your Android. Open Safari or Chrome on the iPhone and enter the following address in the browser:</p><p>You should now see your files listed in the browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1q9Ba15_Ll4tPkaZCinrQ.png" /></figure><p>That’s it — just tap the file, and it will begin downloading to your iPhone.</p><p>And just like that, you’ve bypassed the Move to iOS limitation and transferred files <strong>the developer way</strong>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ff55450e893" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Art of Breaking Your SQL-Powered AI Chatbot (After Building It)]]></title>
            <link>https://infosecwriteups.com/the-art-of-breaking-your-sql-powered-ai-chatbot-after-building-it-2426da985813?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2426da985813</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 17:46:56 GMT</pubDate>
            <atom:updated>2025-01-02T17:42:36.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1jTYL-bazUc2n9IKfnAdg.png" /></figure><p>Hello Hackers!!!<strong> </strong>Ever wondered how AI chatbots with API and database access get compromised? Curious about what really happens under the hood? Let’s uncover the vulnerabilities that put these systems at risk — and learn how to defend against them.</p><p>But that’s not all — let’s explore this from <strong>both the developer’s perspective</strong> (how to build it) and <strong>the attacker’s perspective</strong> (how to break it).</p><h3>The Chatbot Design: Features &amp; Functionality</h3><p>In this blog post, we’ll build a chatbot that translates human language queries into SQL commands to fetch product details from a database. The chatbot supports conversational queries like:</p><ul><li><em>“Find smartphones under $800”</em></li><li><em>“List all laptops in stock.”</em></li></ul><p>This bot allows users to query databases conversationally, making complex data retrieval as easy as chatting with a friend. But as we’ll see, this design introduces vulnerabilities that attackers can exploit, and we’ll walk through how to identify and fix them.</p><h3>Tech Stack</h3><p>Here’s the tech stack we’ll be working with to bring this bot to life:</p><ul><li><strong>Anthropic’s Claude Haiku model</strong> — for its speed and conversational accuracy. (but you can use whichever model you want)</li><li><strong>SQLite</strong> — for lightweight database management.</li><li><strong>Chainlit</strong> — for quick prototyping of chatbot interfaces.(UI)</li></ul><h3>Architecture:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1yaYEGAekGoGRbh8eBvqCg.png" /></figure><p>Let’s begin by making the necessary imports, then create a class, and initialize the required variables.</p><p><strong>Filename: bot.py</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4vfzS3xAg90F9Sf-ZvsdA.png" /></figure><p><strong>Line 1–18:</strong> Imports and class creation</p><p><strong>Line 19–20:</strong> Getting the API key from the .env file and passing it to the Anthropic client</p><p><strong>Line 21–22:</strong> Setting the database name to <strong>“product_store.db”</strong> and Establishing a connection to the SQLite database.</p><p><strong>Line 23–24:</strong> Creating a cursor object to execute SQL commands and Calling the get_db_schema() method to fetch and store the database schema.</p><p>Next, we will create a function that will get the user input and convert it into a DB query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CRNSacBSr6OzM-1HFEzpHQ.png" /></figure><p>In this method, generate_sql_query(), we take a user&#39;s natural language query and convert it into an SQL query. Here&#39;s how it works:</p><ol><li><strong>Define the System Prompt</strong>: First, we create a prompt that describes the task. We explain that the AI will convert natural language into SQL queries for a product database. We also include the database schema and examples to guide the AI.</li><li><strong>Prepare the User Query</strong>: The user’s query (like “Show me all laptops under $1000”) is passed as a message to the AI, asking it to generate the corresponding SQL query.</li><li><strong>Send the Query to the AI</strong>: We send the user’s query along with the system prompt to the AI model (in this case, claude-3-5-haiku-20241022).</li><li><strong>Extract the SQL Query</strong>: Once the AI processes the request, it returns a response. We extract the SQL query from the response.</li></ol><p>Next we will create a function to execute the SQL query generated by AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*_saix33UDMor88EoSHTcZg.png" /></figure><p>We will pass the output generated by the previous function to this one. The execute_db_query() method runs the SQL query on the database using the cursor, fetches the results, and returns them. If an error occurs, it catches the exception and returns the error message.</p><p>Now that we have the results from the database, we can’t show the raw data directly to the user. Since this is a chatbot, we need to present the output in a conversational manner. To achieve this, we’ll create a function called generate_response().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6znzu1Q17za2hdXz1YeY8Q.png" /></figure><p>The generate_response() method takes the user query and database results as input, then uses an AI model to generate a friendly, conversational summary of the results. It summarizes product names, categories, and prices. If no results are found, it suggests related options. The final response is returned in natural language.</p><p>Thats it!!! we have completed the bot functionality. Now we need one more function to execute all these functions in a orderly manner. For that we will create function named process_query().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xz43YEEdBucp7qzGwkLOuQ.png" /></figure><p>The <strong>process_query()</strong> function will combine all the operations.</p><p>The function is marked as async because database queries and external API calls (like generating responses) can take time. Using async allows these tasks to run concurrently without blocking the rest of the application, improving performance and responsiveness.</p><p>Next, we need to create our SQLite database. For learning purposes, we will create three tables and insert some dummy data. Then, we’ll simulate an attack by attempting to extract that data from the bot.</p><p>create a file named db.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6KBqLmdQgfjhEdJ8QxcVmg.png" /></figure><p>Like the previous file(bot.py) , here also Import the required libraries, create a class and initialize the required values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UTCDalAKtRXhia_8NSroeA.png" /></figure><p>Next, we will create the product_info, user_info, and purchase_history tables. Although we won&#39;t use the purchase_history table in this example I am not going to show the implementation, but if you&#39;re interested in implementing it, I&#39;ll share the GitHub repository for this code.</p><p>The product_info_table() method creates a table named products if it doesn&#39;t already exist. The table includes columns for product details such as product_name, url, price, category, and description.</p><p>The user_info_table() method creates a users table if it doesn&#39;t already exist. This table stores user information, including username, password, email, and registration_date.</p><p>Next we will insert some dummy data to the db.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkT-LprfgZJ9n6o_DWPeRw.png" /></figure><p>The above function inserts data into the users and product_info tables. Now, execute this Python file, and it will create a database file named product_store.db. please check if the data has been properly inserted.</p><p>We have now completed the backend and database parts. The remaining task is to build the frontend. For the frontend, I used Chainlit, an open-source async Python framework that enables developers to create scalable Conversational AI or agentic applications. If you’re interested, please check the references section for the link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKvnuy5spQZdr6RTHFW-Uw.png" /></figure><p>Now go back to our bot.py file and add these import statements and main method.</p><p>Here, we create an instance of the UnsafeAI class using ai = UnsafeAI(). The @cl.on_message decorator listens for incoming messages. When a message is received, the main function processes the user&#39;s query asynchronously using ai.process_query(). The response is then sent back to the user through Chainlit.</p><p>Now, if you execute the following command in your terminal, the application will begin running.</p><blockquote>chainlit run your_filename.py</blockquote><p>When the application starts running, this is how the UI looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XtxgxvDYcjrgfqxzpyvNmA.png" /></figure><h3>The Attacker’s Approach</h3><p>Now lets get into the exploitation part. Now as an attacker,</p><p>Looking at the previous image, the response mentions <strong>“database results,”</strong> which strongly suggests that the chatbot queries the database directly and returns the results.</p><p>This behavior raises a crucial question — how secure is the interaction between the chatbot and the database? Could an attacker manipulate the input to exploit vulnerabilities like <strong>SQL injection</strong>?</p><p>Let’s test this assumption by crafting malicious queries and analyzing the chatbot’s behavior.</p><p>First lets test it by sending a simple SQL query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BWK9xX6KdaKGnSdixmRvjw.png" /></figure><p><strong>Great! It works!</strong> This confirms that the bot is accepting SQL queries.</p><p>Now, let’s analyze what’s happening here from an attacker’s perspective:</p><ol><li>First, the model is processing both SQL queries and natural language inputs. This indicates that no restrictions or input sanitization have been applied.</li><li>Second, the response is presented in a conversational format rather than displaying direct database results.</li><li>This suggests that some preprocessing is being performed by the developer before showing the output to the end user.</li></ol><p>Lets test it with some malicious input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDBnUDmb-AMdNMyJKmlPQA.png" /></figure><p>Unfortunately this didn’t worked. Its because of the built-in safety mechanism of claude prevents this input from executing.</p><p><strong>Let’s try something different this time.</strong> We’ll attempt to list all the tables in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Y7HXnq0ilRk6GMq8pmebg.png" /></figure><p><strong>Cool! It successfully listed all the tables from the database.</strong> Among these, the “users” table seems quite interesting, doesn’t it? <strong>Let’s try extracting information from this table.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HL2zzz_hVhcA2BGIJgXa-g.png" /></figure><p>From the above screenshot, we successfully extracted details about the admin user and other customers.</p><h3>How to Mitigate:</h3><ol><li>Use parameterized queries to avoid SQL injection attacks instead of directly concatenating user inputs.</li><li>Validate user inputs before processing them. Allow only predefined formats for queries instead of arbitrary strings.</li><li>Sanitize AI-generated SQL queries before execution.<br>Implement logic to reject unsafe queries containing operations like DROP, ALTER, or DELETE.</li><li>Restrict database permissions by assigning a read-only role to the chatbot, preventing destructive queries.</li><li>Avoid displaying database error messages to users, as these may leak implementation details.</li></ol><h3>References:</h3><ul><li><a href="https://github.com/Chainlit/chainlit">GitHub - Chainlit/chainlit: Build Conversational AI in minutes ⚡️</a></li><li><a href="https://github.com/UVvirus/unsafe_ai_blog">GitHub - UVvirus/unsafe_ai_blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2426da985813" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/the-art-of-breaking-your-sql-powered-ai-chatbot-after-building-it-2426da985813">The Art of Breaking Your SQL-Powered AI Chatbot (After Building It)</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Under the Hood: How Fuzzing Really Works]]></title>
            <link>https://infosecwriteups.com/under-the-hood-how-fuzzing-really-works-f16ee58be279?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f16ee58be279</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Tue, 26 Mar 2024 16:52:26 GMT</pubDate>
            <atom:updated>2024-03-29T04:57:01.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kKBKjRW_47mYdOLgKeS6LA.jpeg" /></figure><p>Hello Hackers!!! Ever found yourself curious about the mechanics behind fuzzing and fuzzers? Today, we’re diving deep into the realm of fuzzing, uncovering its mysteries, and mastering the art of crafting our very own fuzzer.</p><blockquote>What is Fuzzing?</blockquote><blockquote>What is mutation fuzzing?</blockquote><blockquote>How to write a mutation fuzzer?</blockquote><h4>What is Fuzzing?</h4><p>Fuzzing is an automated software testing technique that involves randomly injecting unexpected, invalid, and random data into the program. The goal of fuzz testing is to identify weaknesses in software that could lead to crashes, performance issues, security breaches, or other undesirable behavior.</p><p>On a High level, fuzzing needs two things.</p><ul><li>A function that needs to be fuzzed</li><li>A function that will generate random inputs(Fuzzer).</li></ul><p>Let’s proceed to create both components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pl-yJ1LORdZFv1eLM39oLg.png" /></figure><p>In the above function, it is expecting a URL(possibly a string) and it is checking whether the URL starts with HTTP or HTTPS. Since it accepts strings as input, we will create another function that will create some random strings that we pass to this function. we will try to fuzz this function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NH2Mr-Zlsuq89XxLrkX5rA.png" /></figure><p>In the fuzzer() function outlined above, we&#39;re generating input data intended for our target function. The input data is a combination of letters and numbers. When the fuzzer operates successfully, If the fuzzer runs successfully, this is how the output looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*txzPR4Kp_gJkUL8ZboJHYQ.png" /></figure><p>But here is a catch, it will throw an error(Below Image). Because our target function is expecting a string that starts with either HTTP or HTTPS. To generate an input like that, it will take a lot of iterations for our fuzzer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2HnDl5nfcFKbbd8Etat1A.png" /></figure><p>However Fuzzing does have some drawbacks like this,</p><ul><li>Fuzzing with random inputs can be computationally expensive, especially for complex or large programs. Generating and testing a large number of random inputs can consume significant CPU and memory resources, slowing down the testing process and potentially causing performance issues.</li><li>Randomly generated inputs may not effectively exercise all paths and conditions within the codebase. This can result in low code coverage, leaving some parts of the program untested and potentially hiding bugs.</li></ul><p>To overcome these challenges, the concept of mutation fuzzing is introduced.</p><h4>What is mutation fuzzing?</h4><p>Mutation fuzzing is a software testing technique used to discover bugs, vulnerabilities, and unexpected behaviors in programs by generating mutated versions of existing inputs.</p><p>Here’s how mutation fuzzing typically works:</p><ol><li><strong>Seed Inputs:</strong> Mutation fuzzing starts with one or more seed inputs, which are typically valid inputs to the program being tested. These seed inputs can be existing test cases, real-world inputs, or randomly generated data.</li><li><strong>Mutation:</strong> Mutated versions of the seed inputs are generated by applying various mutation techniques. These techniques include adding, deleting, flipping, or modifying characters, bytes, or other elements of the input data. Mutations are applied randomly or guided by heuristics to create diverse input variations.</li><li><strong>Input Execution: </strong>The mutated inputs are then provided as input to the program under test. The program’s behavior is observed during execution, including any crashes, errors, or unexpected outputs.</li><li><strong>Analysis and Feedback: </strong>If the program exhibits unexpected behavior or crashes, information about the input that triggered the behavior is recorded. This information, along with any error messages or stack traces, is analyzed to identify the root cause of the issue and provide feedback to the testing process.</li><li><strong>Iterative Process:</strong> Mutation fuzzing is often an iterative process, where mutations are continuously generated, applied, and tested against the program under test. The feedback obtained from each iteration is used to guide the mutation process, prioritize certain types of mutations, and improve the effectiveness of the testing.</li></ol><h4>How to write a mutation fuzzer?</h4><p>Let&#39;s say there is a program that accepts URLs as input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ddjlzYrbzfSKD7KxuL39Q.png" /></figure><p>In the above case, the program checks for specific conditions: whether the URL begins with HTTP or HTTPS and whether the hostname is empty. In this case, if we are passing random inputs, then it is a pure waste of computing resources.</p><p>As we understand the input format required, a more effective approach is to generate inputs adhering to this format and subsequently provide these valid inputs to the program, rather than supplying random, invalid input.</p><p>Let’s develop our fuzzer to initially generate valid inputs for this program.</p><p>The goal is to create a fuzzer that will generate valid inputs by applying various mutation techniques.</p><p>To do this we are going to create 3 functions</p><ul><li>delete_random_character()</li><li>insert_random_character()</li><li>flip_random_character()</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5kboS5BGWf0sTGmCifmGg.png" /></figure><p>This function randomly deletes a character from a given string input. It first checks if the input string is empty. If not, it selects a random position in the string and removes the character at that position. Finally, it returns the modified string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8yzHJHRYPgk0FRmyzvPGNg.png" /></figure><p>This function inserts a random printable ASCII character into a given string at a random position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFtjOIDfF4-rx_Raq9mudw.png" /></figure><p>This function randomly selects a character from the given input string and flips one of its bits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*WnJAK70a4HxKZVzGqerlOw.png" /></figure><p>The mutate function randomly selects one mutation operation from a list of mutation functions: deleting a random character, flipping a random character&#39;s bit, or inserting a random character into the input string. It stores the selected mutation function in the variable mutator. Then, it applies this mutation function to the input string and returns the result.</p><p>As you can see from the output above, each output only receives one modification. Let’s modify the logic to incorporate several mutations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*RHq1J6krRltIfHX_9Hi43g.png" /></figure><p>Here in the above multiple_mutation function mutates a URL multiple times within a specified range of trials. It checks the validity of each mutated URL and stores valid inputs in a set. Finally, it prints the set of valid inputs.</p><p>At this stage, we’ve compiled a set of valid inputs specifically tailored for the function under fuzzing. This illustrates the fundamental mechanism by which fuzzers generate valid input data.</p><p>Stay tuned for a deeper exploration of this concept in upcoming blog posts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f16ee58be279" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/under-the-hood-how-fuzzing-really-works-f16ee58be279">Under the Hood: How Fuzzing Really Works</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 5: Message Queue | Part 2 [PRACTICAL]]]></title>
            <link>https://medium.com/@UVvirus/day-5-message-queue-part-2-practical-32aba0057e47?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/32aba0057e47</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Mon, 07 Aug 2023 06:53:16 GMT</pubDate>
            <atom:updated>2023-08-07T06:53:16.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RVmtgWoAIxqv5kXq__AVMQ.jpeg" /></figure><p>Hello Hackers, this is Part 2 of the message queue, if you haven’t read the first part, please head over to the below link.</p><p><a href="https://medium.com/@UVvirus/day-4-load-balancers-message-queue-6303d02630fa">Day 4: Load Balancers &amp; Message Queue</a></p><p>In this blog, we will create a simple Python application and will use AWS SQS along with that. The simple Python application will scan for the given domain name&#39;s open ports. Let’s get started.</p><h4>The flow:</h4><p>The application will get input from the user -&gt; send the user input(domain name) to the SQS queue -&gt; SQS queue will receive the request and process the request -&gt; return the result.</p><p>The first step is to create a virtualenv for our project and install the required packages</p><pre>$ python3 -m venv venv_name<br>$ pip install flask[async]<br>$ pip install python-dotenv</pre><h4><strong>Step 1:</strong> Create your Python application</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWyOnR-gc_LQAcPNG0uusg.png" /></figure><p>Here in the above image we have created two methods namely <strong>get_user_input() and nmap_scan(), </strong>we are going to use that <strong>get_user_input()</strong> function with the API, that’s why it just returns the given input.</p><p>The next function <strong>nmap_scan()</strong> will do the scan for the given domain. The nmap_scan() function is performing a synchronous task. This means that while the Nmap scan is running, the application will be blocked, and it won’t be able to handle other tasks or requests.</p><p>If you want to make this function truly asynchronous and non-blocking, you can use the subprocess module with the asyncio library to run the Nmap command asynchronously.</p><p>And for the sake of example, we took a simple Nmap command</p><pre>$ nmap -p 80,443 {domain_name}</pre><p>The command will check whether ports 80 and 443 are open or closed for the given domain.</p><h4><strong>Step 2:</strong> Get the SQS queue URL</h4><p>In our last post, we already created our queue using the AWS console, Now we need to get that URL. Most of the SQS APIs require the <strong>QueueUrl</strong> so we will use the get_queue_url() method to retrieve the URL of the queue using the QueueName</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XW8FK_rPWKN6lbsYsmg-Dw.png" /></figure><p>In the above function, we just have to pass the name of the queue to the <strong>get_queue_url()</strong> function. The name can be found on our AWS console.</p><h4><strong>Step 3: </strong>Send the user input to the SQS queue</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHg2K9eCdL7VbN6xTAEvzA.png" /></figure><p>Now that we got our SQS queue URL, we need to send our messages or user requests to the queue, so that our server will process those requests in that order(FIFO).</p><p>To send the message to the queue, first, we need to make sure that our message is converted into JSON format or key &amp; value format. Then using the <strong>send_message()</strong> function, we can send our message.</p><p>The message sent will be converted into an MD5 hash.</p><h4>Step 4: Receive the message from the queue</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wKv9NGxqiiAHNkaEAniuJQ.png" /></figure><p>We will be using the receive_message() method from Boto3 to receive a message from the SQS queue. Some of the important parameters to keep in mind while using this method:</p><ul><li>QueueUrl: URL of the queue we want to receive a message from</li><li>MaxNumberOfMessages: The maximum number of messages to retrieve.</li><li>WaitTimeSeconds: Amount of time to wait for a message to arrive in the queue. Useful for long-polling of messages</li></ul><p>After receiving and processing the message, we need to delete the message from the queue, so that queue won’t pick up that message again. Basically, to avoid duplication and to save some processing power, we need to remove it.</p><h4>Step 5: Delete the message from the queue</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8uEKCPEwepxTSz-TfeCww.png" /></figure><p>It is important to keep in mind that receiving a message from the SQS queue doesn’t automatically delete it. Any other consumer can also retrieve the same message once the VisibilityTimeout period expires. To ensure, no other consumer retrieves the same message, it needs to be deleted within the VisibilityTimeout time period.</p><p>We will be using delete_message to delete the message from the SQS queue.</p><ul><li>We need to provide the ReceiptHandle as an argument to the delete_message method.</li></ul><p>That’s it, our SQS queue operation is ready, Now we need to integrate both our application and SQS operation file with the API.</p><p>To create API, I am going to use Flask today.</p><h4>Step 6: Create an API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8i2V_2SusTulpa3wRls_g.png" /></figure><p>The API is self-explanatory.</p><ul><li>First, we are getting user input using an HTML Form</li><li>And then sending it to the queue</li><li>Then receiving that message from the queue</li><li>Processing and rendering the scan results in a new HTML template.</li></ul><p>In order to get the user input via HTML form, first, we need to create the form class.</p><h4>Step 7: Create a Form class</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iERpt2CaYd3aFK0jcnP83g.png" /></figure><p>For this example, I took a simple text box(where the user will enter the input) and a submit button.</p><p>Now create an HTML template where the user input and result will be shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIwy_ij9CarDTH4EVoHsTQ.png" /></figure><p>HTML template to show the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsYUbKrU4KTbrhfqLvJf8A.png" /></figure><p>That’s it, Now run the API.py file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*XSIFIha1klO8uYHLqGwcpQ.png" /></figure><p>Sample results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*m-iWJTNlk4jkSrkGJw95qw.png" /></figure><p>This is how you implement the SQS queue in your application.</p><h4>Alright!!! Let’s explore a quick summary.</h4><ul><li>First, we created our application</li><li>Then we created SQS operations</li><li>Then integrated both files with our API</li><li>To get the user input we created a Form class</li><li>To show the results we created HTML templates</li><li>Finally, we scanned for a domain name and got the result.</li></ul><p>If you want the full code, you can find it here.</p><p><a href="https://github.com/UVvirus/aws_sqs_implementation">GitHub - UVvirus/aws_sqs_implementation</a></p><p><em>That’s it… signing off for today…will meet you soon with another great article.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32aba0057e47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 4: Load Balancers & Message Queue]]></title>
            <link>https://medium.com/@UVvirus/day-4-load-balancers-message-queue-6303d02630fa?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6303d02630fa</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 14:28:38 GMT</pubDate>
            <atom:updated>2023-08-07T06:55:36.664Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4YYi2wRYNFYpnBxa5mzS5Q.jpeg" /></figure><p>Hello Hackers!!! Today is Day 4 on our series of How to become a better software engineer. Let me introduce you to two tech superheroes: load balancers and message queues! 🦸‍♂️🦸‍♀️ Load balancers evenly distribute tasks among servers, while message queues keep things organized and running smoothly. 🚀 Get ready to dive into the fascinating world of these behind-the-scenes champions!</p><blockquote>What is Load balancing?</blockquote><blockquote>Why do we need Load balancers?</blockquote><blockquote>How do Load balancers effectively manage all this?</blockquote><blockquote>Round Robin:</blockquote><blockquote>Least Connection:</blockquote><blockquote>Weighted Least Connection:</blockquote><blockquote>Message Queues:</blockquote><blockquote>Why do we need message queues:</blockquote><blockquote>what was used before SQS?</blockquote><blockquote>How to create:</blockquote><p>We already covered a lot about load balancers in our previous blogs. If you haven’t read that yet please find the links below.</p><ul><li><a href="https://medium.com/@UVvirus/world-of-scaling-part-1-75a272a4391b">World of Scaling: PART 1</a></li><li><a href="https://medium.com/@UVvirus/day-2-three-ways-to-scale-an-application-part-2-55afad446646">Day 2: Three Ways to Scale an Application | PART 2</a></li></ul><h4>What is Load balancing?</h4><p>Load balancing is a technique to split or balance the load equally among the servers. Doing this won’t apply a heavy load to any of the servers. Thereby efficiency will be improved.</p><h4>Why do we need Load balancers?</h4><ul><li>To minimize server response time</li><li>Efficiency</li><li>scalable</li><li>A single point of failure can be avoided, if one server goes down, others can process that request.</li></ul><h4>How do Load balancers effectively manage all this?</h4><p>To manage all the load efficiently, load balancers use certain types of algorithms. They are</p><ul><li>Round Robin</li><li>Least connection</li><li>Weighted Least connection</li></ul><h4>Round Robin:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*U9fvtQVrq6HTrGGXWaJZxw.jpeg" /></figure><p>Round robin is a method in which the load will be distributed in a sequential manner. Let’s say there are six servers, then the Round robin method will distribute the first 6 requests to the six servers and then 7th request will be routed to 1 st server, likewise, this process continues.</p><h4>Least Connection:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*g0i0D3xQaMKZ_bWADwi1FQ.jpeg" /></figure><p>In this method, The server which is handling the very least amount of connections will be given the first priority by the load balancer, however, there is a problem with this approach, Not all the machines are going to have the same configuration, so it might be difficult for a machine to handle if something big has been received.</p><p>To solve this problem Weighted Least connection method has been introduced.</p><h4>Weighted Least Connection:</h4><p>In the weighted least connection method, servers will be categorized according to their processing capacity. So, if a large request has been received then the server with a large processing unit will handle that.</p><p><em>That’s all about load balancers, the next thing we are going to discuss is Message Queues.</em></p><h4>Message Queues:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*EBhsGCxNds6_8WTs5OBE6w.jpeg" /></figure><p>Let’s say you came to a bank to deposit your money in your account. But people already formed a queue at the cashier. Now you also joined the queue until the queue moves and the cashier gets your money.</p><p>In technical terms</p><p>A message queue is a temporary place where requests will be stored for a period of time before it is taken by the server to process. In our bank example, you are the “request” that joins the “queue” and moves to process your information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GdduOn_wdI0GUoIgv9414A.jpeg" /></figure><h4>Why do we need message queues:</h4><ul><li>Load balancing</li><li>Async communication</li><li>Scalability</li></ul><p>Today we are going to use AWS SQS(Simple Queue Service) as our Message Queue service.</p><p>SQS is nothing but a <strong>simple queue service</strong> offered by AWS.</p><h4>what was used before SQS?</h4><p>Before Amazon SQS and other cloud-based message queuing services, various traditional messaging systems and middleware were used to handle message queuing and communication between applications. Some of the commonly used alternatives to SQS include:</p><ul><li>IBM MQ (formerly known as WebSphere MQ)</li><li>Apache ActiveMQ, RabbitMQ</li><li>and Microsoft Message Queue (MSMQ)</li></ul><h4>How to create:</h4><p>To create SQS, head over to the AWS console</p><ol><li>Search for SQS on the search bar</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*QN19-ya_xM7tJcRmqEkt0A.png" /></figure><p>2. Create a new queue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*krPS_s_urVKH9Rc5s7T6zw.png" /></figure><p><em>You can ask when to use </em><strong><em>Standard</em></strong><em> and when to use </em><strong><em>FIFO.</em></strong></p><p><em>The answer is simple</em></p><ul><li><em>if your application has a large user base or if you want to process a large amount of data then use </em><strong><em>standard</em></strong></li><li><em>if you want to execute commands or something in an ordered way then use </em><strong><em>FIFO</em></strong></li></ul><p>Also, don&#39;t forget to include Dead-letter queues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*vYFxepCgIvZFTDeNzeAmDA.png" /></figure><p>Dead-letter queues allow you to handle failed or time-sensitive requests separately, ensuring they receive attention quickly.</p><p>That’s it, our queue is ready, Now we need to integrate this with our application.</p><p>That we’ll do in our next post. Since Queue is a very large topic, it is difficult to write it in a single post.</p><p>Here is the link for Part 2 of this post.</p><p><a href="https://medium.com/@UVvirus/day-5-message-queue-part-2-practical-32aba0057e47">Day 5: Message Queue | Part 2 [PRACTICAL]</a></p><p><em>That’s it… signing off for today…will meet you soon with another great article.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6303d02630fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 3: How to deploy your Python application on AWS]]></title>
            <link>https://medium.com/@UVvirus/day-3-how-to-deploy-your-python-application-on-aws-b4c98c81a088?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4c98c81a088</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 07:42:38 GMT</pubDate>
            <atom:updated>2023-07-28T07:42:38.907Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LvwI3k6clPGMw0hIzDLfCw.jpeg" /></figure><p>Hello Hackers!!! I totally get it — deployment might seem like a big deal, but trust me, it’s not that hard. Let’s keep it chill and walk through how to deploy your Python app on an AWS EC2 instance. It’s actually pretty straightforward, and I’ll be your guide through the whole thing. So, grab your favorite drink, and let’s get this show on the road! We’ll have your app up and running on AWS in no time, and you’ll see how easy it can be. Let’s rock and roll!</p><p><strong>Step: 1</strong> Login to your AWS console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ZV34ZxjfXctni1zX6IU1zw.png" /></figure><p><strong>Step 2:</strong> Create a new EC2 instance and configure it according to your needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*MxBm8Uk3KDbthrEQEEfczg.png" /></figure><p><strong>Step 3:</strong> Now log in to your instance using SSH</p><pre>$ ssh ubuntu@ip -i keyfile.pem</pre><p><strong>Step 4:</strong> Create a project directory</p><pre>$ sudo apt-get update<br>$ mkdir your_project_name <br>$ cd your_project_name</pre><p><strong>Step 5:</strong> Create a virtualenv and install the required packages</p><pre>$ python3 -m venv venv_name<br>$ source venv_name/bin/activate<br>$ pip install flask</pre><p><strong>Step 6:</strong> Create your application</p><pre>#Filename: example.py<br><br>import requests<br><br>  def get_request(url):<br>    response=requests.get(url)<br>    return response.text<br><br>if __name__ == &quot;__main__&quot;:<br>  url=&quot;https://google.com&quot;<br>  get_request(url)</pre><p><strong>Step 7:</strong> Create your API</p><pre>#Filename: api.py<br><br>from flask import Flask, Response<br>from example import get_request<br>import json<br><br>app=Flask(__name__)<br><br>@app.route(&quot;/request/&lt;string:url&gt;&quot;,methods=[&quot;GET&quot;])<br>def api_endpoint1(url):<br>  api_response=get_request(url)<br>  return Response(response=json.dumps(api_response))<br><br>if __name__ ==&quot;__main__&quot;:<br>  app.run(host=&#39;0.0.0.0&#39;,port=5000)</pre><blockquote>Always remember to keep the API layer and application layer separate.</blockquote><blockquote>The API should never be aware of the backend’s internal workings. Making changes to the application layer should have no impact on the API layer.</blockquote><blockquote>This approach ensures that future changes to the backend won’t affect the API, That is the good software development practice.</blockquote><p><strong>Step 8:</strong> Create requirements.txt file</p><pre>pip freeze &gt; requirements.txt</pre><p><strong>Step 9:</strong> Install docker on the instance and create a dockerfile</p><pre>$ sudo snap install docker<br>$ nano Dockerfile</pre><pre>#Filename: Dockerfile<br><br>FROM python:3.10<br>WORKDIR /app<br>COPY . /app<br>RUN pip install -r requirements.txt<br>EXPOSE 5000<br>CMD [&quot;python3&quot;, &quot;api.py&quot;]</pre><p>Here in the above file, we begin by specifying the base image as <strong>Python 3.10</strong>, creating a working directory for our application. Next, we <strong>copy</strong> all the necessary project files into this <strong>working directory</strong>. With the RUN command, we <strong>install the required packages</strong> from the requirements.txt file. By <strong>exposing port 5000</strong>, we allow our instance to communicate with the application running inside the container. Finally, we execute the Python script named api.py to run our application.</p><p>Before proceeding to the next step, create a <strong><em>.dockerignore</em></strong> file and add the <strong><em>venv_name</em></strong> file to it.</p><p><strong>Step 10:</strong> Now, build the docker image using the dockerfile and start the container</p><pre>$ sudo docker build -t flask_app . &lt;-- There is a dot here<br>$ sudo docker run -p 5000:5000 flask_app</pre><p>Now the application is running inside the container, However, to access it everywhere in the world we have to set up a <strong>Reverse-proxy.</strong></p><h4><strong>What is Reverse-proxy?</strong></h4><p>According to ChatGPT <em>“A reverse proxy is a server or software component that sits between client devices (such as web browsers) and backend servers. It acts as an intermediary, receiving requests from clients and forwarding them to the appropriate backend server, then forwarding the response back to the clients.”</em></p><p>Hmm… Difficult to understand right, Let me simplify it for you</p><p>Forward proxy forwards the request <strong>from the client(Browser) to the server</strong>, whereas Reverse proxy forwards the request <strong>from the server to the client</strong>.</p><p><strong>Step 11:</strong> Now install nginx</p><pre>$ sudo apt install nginx-core</pre><p>Nginx is a web server that is used for a variety of purposes such as reverse proxy, load balancer, etc. So we are going to use that to deploy our application.</p><p><strong>Step 12:</strong> Unlink the default configuration and create a new configuration</p><pre>$ sudo unlink /etc/nginx/sites-enabled/default <br>$ cd etc/nginx/sites-available/ <br>$ nano reverse-proxy.conf</pre><pre>server { <br><br>    listen 80; <br><br>    server_name &lt;server_ip&gt;; <br><br>    location / { <br><br>        proxy_pass http://127.0.0.1:5000; <br><br>    } <br><br>} </pre><p>What the above lines will do is, our server will listen on port 80 and forward all the incoming requests to the application running on localhost port 8000.</p><pre>$ sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf <br># ln -s: The ln command is used to create links (hard links or symbolic links) between files. <br># The -s option specifies that we want to create a symbolic link.<br>$ sudo systemctl status nginx <br>$ sudo systemctl restart nginx </pre><p><strong>Step 13:</strong> Now just stop the container that you created in Step 10</p><pre>$ sudo docker ps -a<br>$ sudo docker stop container_name<br>$ sudo docker rm container_name<br>$ sudo docker run -p 5000:5000 flask_app</pre><p>Now enter your server IP on your browser, and you can view your application.</p><p><strong><em>Note:-</em></strong></p><ul><li><em>If you shut down the ec2 instance and restart it, then IP will e changed for that instance. In that case, you have to repeat Steps 12 and 13.</em></li><li><em>If pasting the server IP on the browser didn&#39;t work, then try with ports(IP: port) and endpoints(IP/endpoint)</em></li></ul><p>That’s it your application has been deployed.</p><p><strong><em>To summarize what we did on this blog</em></strong></p><ul><li><strong><em>Logged in to the AWS console</em></strong></li><li><strong><em>Created an EC2 instance</em></strong></li><li><strong><em>Created our application</em></strong></li><li><strong><em>Created an API</em></strong></li><li><strong><em>Containerized our application using the docker</em></strong></li><li><strong><em>Created a reverse proxy using Nginx</em></strong></li><li><strong><em>Deployed our application in the docker container</em></strong></li></ul><p><em>That’s it… signing off for today…will meet you soon with another great article.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4c98c81a088" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 2: Three Ways to Scale an Application | PART 2]]></title>
            <link>https://medium.com/@UVvirus/day-2-three-ways-to-scale-an-application-part-2-55afad446646?source=rss-5d667013e60f------2</link>
            <guid isPermaLink="false">https://medium.com/p/55afad446646</guid>
            <dc:creator><![CDATA[Yuvarajan]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 14:54:08 GMT</pubDate>
            <atom:updated>2023-07-28T07:33:15.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nw9tA74t8b8LlcWR7IeWRw.jpeg" /></figure><p>Hello Hackers!!! This is a continuation of my previous blog, if you haven’t read that yet, I request you to read that first and then read this, otherwise it will be difficult for you to understand this. Here is the link.</p><p><a href="https://medium.com/@UVvirus/world-of-scaling-part-1-75a272a4391b">World of Scaling: PART 1</a></p><p>Ok!! Let’s get started</p><p>Today we are going to explore <strong>three different options to Scale</strong> our Application. The difficulty level would be Hard, Easy, Easiest.</p><p>You can ask that “If it is hard, why are you doing that? Instead, why don&#39;t you go to easy way?” I understand that, but <strong>the goal of this series is to understand How things work under the hood.</strong></p><blockquote>OPTION 1: Manually adding and configuring servers</blockquote><blockquote>OPTION 2: Autoscaling using AWS</blockquote><blockquote>OPTION 3: AWS Elastic BeanStalk</blockquote><h4><strong>OPTION 1: Manually adding and configuring servers</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T4TFaAuYumJnIOwNaD1_3A.png" /></figure><p>Option 1 will be similar to the above diagram, yes we are going to route traffic through different servers using nginx as a load balancer.</p><p><strong>Step 1:</strong> Log in to your AWS console</p><p><strong>Step 2:</strong> Create 3 new EC2 instances( Search EC2 -&gt; Instances -&gt; Launch Instance )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*DGY-tolLSMitTypp9QoQcg.png" /></figure><p>One instance will act as a load balancer(using nginx) and the other 2 instances will have our application running.</p><p><strong>Step 3:</strong> Login into any of your application servers using SSH.</p><pre>$ ssh ubuntu@ip -i keyname.pem<br>(if the above cmd gives any error, then check the permissions)<br>$ chmod 400 keyname.pem</pre><p><strong>Step 4: </strong>Once logged in. Create a project directory</p><pre>$ sudo apt-get update<br>$ mkdir your_project &amp;&amp; cd your_project</pre><p><strong>Step 5:</strong> Create a virtualenv and install the required packages</p><pre>$ python3 -m venv venv_name<br>$ source venv_name/bin/activate<br>$ pip install flask</pre><p><strong>Step 6:</strong> Create your application</p><pre>#applicaton_name.py<br>from flask import Flask, request<br><br>app = Flask(__name__)<br><br>@app.route(&#39;/input/&lt;user_input&gt;&#39;)<br>def process_input(user_input):<br>    return f&quot;Response from server 1: {user_input}&quot;<br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(&#39;0.0.0.0&#39;)</pre><p><strong>Step 7:</strong> Create requirements.txt file</p><pre>pip freeze &gt; requirements.txt</pre><p><strong>Step 8:</strong> Install docker on the instance and create a dockerfile</p><pre>$ sudo snap install docker<br>$ nano Dockerfile</pre><pre>#Filename: Dockerfile<br><br>FROM python:3.10<br>WORKDIR /app<br>COPY . /app<br>RUN pip install -r requirements.txt<br>EXPOSE 5000<br>CMD [&quot;python3&quot;, &quot;application_name.py&quot;]</pre><p>Here in the above file, we begin by specifying the base image as <strong>Python 3.10</strong>, creating a working directory for our application. Next, we <strong>copy</strong> all the necessary project files into this <strong>working directory</strong>. With the RUN command, we <strong>install the required packages</strong> from the requirements.txt file. By <strong>exposing port 5000</strong>, we allow our instance to communicate with the application running inside the container. Finally, we execute the Python script named application_name.py to run our application.</p><p>Before proceeding to the next step, create a <strong><em>.dockerignore</em></strong> file and add the <strong><em>venv_name</em></strong> file to it.</p><p><strong>Step 9:</strong> Now, build the docker image using the dockerfile and start the container</p><pre>$ sudo docker build -t flask_app . &lt;-- There is a dot here<br>$ sudo docker run -p 5000:5000 flask_app</pre><p><strong>Step 10:</strong> Now install nginx</p><pre>$ sudo apt install nginx-core</pre><p>By default, nginx will listen on port 80.</p><blockquote>Repeat the same above steps on Instance 2 as well</blockquote><blockquote><strong>NOW SWITCH TO NGINX INSTANCE</strong></blockquote><p><strong>Step 1.a:</strong> Login into the <strong>nginx instance</strong> using the ssh key</p><p>Then follow Steps 3 &amp; 4</p><p><strong>Step 2.a:</strong> Install docker and nginx</p><pre>$ sudo snap install docker<br>$ sudo snap install nginx-core</pre><p><strong>Step 3.a: </strong>Create an nginx config file <strong>#MAIN STEP</strong></p><pre>#nginx.conf<br><br>events{}<br><br>http{<br> upstream my_application {<br>  server flask_app_server:5000; <br>  server flask_app_server2:5000<br>}<br> server {<br>  listen 80;<br>  server_name nginx_ip;<br>  location / {<br>   proxy_pass http://my_application; &lt;-- dont replace this<br>} <br>}<br>}</pre><p>In the above file, the events{} block in the nginx.conf file is used to configure various settings related to how Nginx handles events, such as connections and requests. Then on the <strong>http{}</strong> block you will define the configuration.</p><p>The <strong>upstream block</strong> will have all the application servers that our Nginx load balancer routes to. Then On the <strong><em>server{}</em></strong> block, we have to define on which port our nginx server will listen, and what is the server name and <strong><em>proxy_pass</em></strong>. The request received on <strong><em>port 80</em></strong> will be forwarded to proxy_pass and proxy pass has the value <strong>my_application</strong>, so obviously it will route to our application servers.</p><p>Step 4.a: Now create a dockerfile</p><pre>#Dockerfile<br><br>FROM nginx<br>CMD [&quot;sudo&quot;, &quot;unlink&quot;,  &quot;/etc/nginx/sites-enabled/default&quot;]<br>COPY nginx.conf /etc/nginx/sites-enabled/nginx.conf<br>CMD [&quot;sudo&quot;, &quot;ln -s&quot;, &quot;/etc/nginx/sites-available/nginx.conf&quot;, &quot;/etc/nginx/sites-enabled/nginx.conf&quot;]<br>CMD [&quot;sudo&quot;, &quot;systemctl&quot;,&quot;restart&quot; , &quot;nginx&quot;]</pre><p>Step 5.a: Build and run the docker image</p><pre>$ sudo docker build -t flask_nginx .<br>$ sudo docker run -d -p 80:80 --name nginx_server flask_nginx<br><br># Explanation:<br># -d: This flag stands for &quot;detached mode,&quot; which means the container will run in the background (daemon mode). It allows you to continue using the terminal for other tasks while the container runs in the background.<br><br># -p 80:80: This flag maps port 80 from the host machine to port 80 of the container. It allows incoming traffic on port 80 of the host to be forwarded to port 80 of the running container.</pre><p>That’s it!!! now you can access your application using the nginx instance IP.</p><h4>OPTION 2: Autoscaling using AWS</h4><p>AWS Autoscaling allows you to automatically adjust the capacity of your AWS resources based on predefined conditions or metrics. It enables you to maintain the desired level of performance, availability, and cost efficiency for your applications without manual intervention.</p><p><strong>Step 1: </strong>Create a launch template</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1MlzRaIoPDMxM_RjmzMRg.png" /></figure><p>In the Launch template, we have to configure AMI, type of machine, security group, etc. With this configuration, a new instance will be created to scale the application.</p><p>To create a launch template Go to <strong>Ec2 -&gt; Launch templates -&gt; Create new template</strong></p><p><strong>Step 2:</strong> Setup an Auto-scaling group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*le3Pmj4zChsfSo6UTLYZIQ.png" /></figure><p>The auto-scaling group will utilize the launch template and will create the instance based on that configuration.</p><p>To create an Auto-scaling group Go to <strong>Ec2 -&gt; Auto-Scaling groups -&gt; Create Auto-Scaling group</strong></p><p><strong>Step 3:</strong> Verify whether a new instance has launched or not</p><p>Now that we have created a launch template and an Auto-scaling group, it will launch a new ec2 instance. To verify that head over to the <strong>Autoscaling Groups page.</strong></p><p>You can view the newly created instance on the instances page also.</p><p><strong>Disclaimer:- </strong>If you terminate the newly created instance, then aws will create another new instance, To avoid this you have to revert the changes, which you did on the above two steps.</p><h4>OPTION 3: AWS Elastic BeanStalk</h4><p>According to AWS <em>“Elastic Beanstalk is a service for deploying and scaling web applications and services. Upload your code and Elastic Beanstalk automatically handles the deployment — from capacity provisioning, load balancing, and auto-scaling to application health monitoring.”</em></p><p><strong>Step 1:</strong> Log in to the AWS console</p><p><strong>Step 2:</strong> Search for Elastic Beanstalk</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dXau54sAXFKOSc2kuRO0kA.png" /></figure><p><strong>Step 3:</strong> Configure the environment as per your need</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IEKSzaGtCzkAsmJiTjVrLA.png" /></figure><p>That’s it!!! AWS will take care of deploying and scaling your application.</p><p><em>That’s it… signing off for today…will meet you soon with another great article.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55afad446646" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>