<?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 Apar Baral on Medium]]></title>
        <description><![CDATA[Stories by Apar Baral on Medium]]></description>
        <link>https://medium.com/@baral.apar.123?source=rss-7163a09a2f20------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*x_Jte-QOcBNTG9cm</url>
            <title>Stories by Apar Baral on Medium</title>
            <link>https://medium.com/@baral.apar.123?source=rss-7163a09a2f20------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:48:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@baral.apar.123/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[Why Your LLM “Passed” the Pentest and Still Leaks on a Tuesday Afternoon ?]]></title>
            <link>https://medium.com/@baral.apar.123/why-your-llm-passed-the-pentest-and-still-leaks-on-a-tuesday-afternoon-125338898857?source=rss-7163a09a2f20------2</link>
            <guid isPermaLink="false">https://medium.com/p/125338898857</guid>
            <category><![CDATA[mitre-atlas-framework]]></category>
            <category><![CDATA[llm-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[llm-pentest]]></category>
            <category><![CDATA[prompt-injection-attack]]></category>
            <dc:creator><![CDATA[Apar Baral]]></dc:creator>
            <pubDate>Fri, 26 Jun 2026 03:45:07 GMT</pubDate>
            <atom:updated>2026-06-26T03:45:07.974Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>OWASP LLM Top 10, MITRE ATLAS, and the gap between a clean report and a model that still talks too much.</strong></p><p>Cybersecurity · Artificial Intelligence · LLM Security · Red Team · OWASP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TEGFH_g2XDMJJRpFwfyrw.png" /></figure><p><em>Estimated read time: 12 minutes</em></p><p>Last quarter I sat in on a readout where a security team was genuinely happy.</p><p>Their chatbot had refused every jailbreak on the slide deck. RAG had delimiter tags. The system prompt said <em>under no circumstances</em> in bold. Leadership signed off before anyone finished their coffee.</p><p>Two weeks later, an analyst in another time zone got the same model to outline internal routing rules. Not through a dramatic “<strong>ignore all instructions</strong>” moment. Through a polite, multi-turn document review that sounded like normal work.</p><p>Nobody hacked anything. No CVE dropped. The model did what language models do. It kept going with the conversation.</p><p>That gap between “we tested it” and “we know how it fails” is where AI security actually lives right now. Frameworks like the <strong>OWASP Top 10 for LLM Applications (2025)</strong> and <strong>MITRE ATLAS</strong> are useful because they give that gap a vocabulary. Not another checkbox on a SOC 2 appendix. A shared language for people who build, break, and audit these systems.</p><p>I wrote this because I keep seeing the same story. Smart teams. Real budget. A pentest that looks fine on paper. Then a Tuesday afternoon where the model says something it was never supposed to say out loud.</p><h3>Your LLM Is Not An API Endpoint</h3><p>For a long time we secured request/response pairs.</p><p>SQLi? Parameterize. XSS? Encode output. AuthZ? Check the token.</p><p>LLMs mess with that mental model because the attack surface is language. The same thing that makes them useful, context-sensitive completion, is what curious users and actual attackers lean on.</p><p>OWASP <strong>LLM01:2025 Prompt Injection</strong> says user prompts can change model behavior in ways humans might not notice, as long as the model parses them. If you still think the WAF will catch this, read that sentence again slowly.</p><p>MITRE ATLAS maps the same idea under <strong>AML.T0051.000 (Direct LLM Prompt Injection)</strong> and <strong>AML.T0051.001 (Indirect LLM Prompt Injection)</strong>. Handy when you need ML engineers, AppSec, and a GRC auditor in the same room without anyone calling jailbreak a phone commercial.</p><p>If you take one thing from this piece: stop treating LLM safety like a filter problem. Treat it like a behavior problem you have to test, repeatedly, on the thing you actually shipped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PCi-QURefIBbApfIIRT5_Q.png" /><figcaption><em>The “Prompt Boundary” is a Convention. Not a Fence.</em></figcaption></figure><h3>OWASP LLM Top 10 (2025): The Playlist, Not The Lyrics</h3><p>The 2025 OWASP LLM Top 10 is not a bug list. It is a list of ways probabilistic text generation fails once you wire it into a product, an agent, or a workflow.</p><p>Here is the roster with the version I use in reviews. Less PDF. More “what did someone say in Slack when this blew up.”</p><p><strong>LLM01</strong></p><ul><li>Prompt Injection</li><li>“Why did it follow <em>that</em> instruction?”</li></ul><p><strong>LLM02</strong></p><ul><li>Sensitive Information Disclosure</li><li>“It did not leak a file. It summarized the secret.”</li></ul><p><strong>LLM03</strong></p><ul><li>Supply Chain</li><li>“Our fine-tune dataset had opinions.”</li></ul><p><strong>LLM04</strong></p><ul><li>Data &amp; Model Poisoning</li><li>“The model learned the wrong thing on purpose.”</li></ul><p><strong>LLM05</strong></p><ul><li>Improper Output Handling</li><li>“XSS, but the payload is a paragraph.”</li></ul><p><strong>LLM06</strong></p><ul><li>Excessive Agency</li><li>“The agent emailed <em>who</em>?”</li></ul><p><strong>LLM07</strong></p><ul><li>System Prompt Leakage</li><li>“It quoted the recipe, not the cake.”</li></ul><p><strong>LLM08</strong></p><ul><li>Vector &amp; Embedding Weaknesses</li><li>“RAG retrieved the wrong truth, confidently.”</li></ul><p><strong>LLM09</strong></p><ul><li>Misinformation</li><li>“Fluent. Wrong. Very sure of itself.”</li></ul><p><strong>LLM10</strong></p><ul><li>Unbounded Consumption</li><li>“The invoice had seventeen million tokens.”</li></ul><p>Most teams overweight <strong>LLM01</strong> because it is cinematic. The quiet pain is often <strong>LLM10</strong>, or <strong>LLM07</strong> when your internal policy becomes free recon for the next person who asks nicely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hCTV4e0au5kLFK2bdTmRVQ.png" /><figcaption><strong>2019 playbook:</strong> Block the Payload. <strong>2025 Playbook:</strong> Negotiate with the Completion.</figcaption></figure><h3>MITRE ATLAS: A Map Red and Blue Teams Both Can Use</h3><p>OWASP tells you what can go wrong. <strong>MITRE ATLAS</strong> (Adversarial Threat Landscape for AI Systems) helps you describe how an adversary chains steps from recon to impact in language your IR team already knows.</p><p>A few techniques I keep pinned above my desk:</p><ul><li><strong>AML.T0051.x</strong> for Prompt Injection, direct and indirect. Indirect is the sleeper hit: poisoned PDFs, ticket comments, web pages your agent browses.</li><li><strong>AML.T0054</strong> for model inversion and extraction-adjacent behavior. Often shows up as “please continue the config block,” not “dump your weights.”</li><li><strong>AML.T0043</strong> for crafted adversarial data. The boring stuff still works: encodings, multilingual phrasing, instructions split across turns.</li></ul><p>ATLAS is not academic in a good enterprise review. It is the slide you do not have to rebuild when Legal asks if this is a real attack category or your red team’s weekend hobby.</p><h3>Jailbreak, Injection, Leakage: Three Different Incidents Wearing one Hoodie</h3><p>In conversation, everything is a “jailbreak.” In a postmortem, that sloppiness costs you.</p><p><strong>Prompt injection</strong> is control flow. Whose instructions win when user content, retrieved documents, and system prompts collide?</p><p><strong>Jailbreak</strong> is policy bypass. Getting disallowed content or capability despite alignment training.</p><p><strong>System prompt leakage</strong> (OWASP <strong>LLM07</strong>) is confidentiality of operator intent. The model reveals scaffolding that was never meant to be user-visible. Often through helpful continuations, not a dramatic dump.</p><p>Why bother separating them?</p><p>Mitigations differ. Injection in an agent with tools is an authorization problem. Leakage in a support bot is a data governance problem. Jailbreak on a coding assistant is a brand problem. Same chat UI. Different runbooks.</p><h3>What “Good” LLM Testing Looks Like In 2026</h3><p>I see three maturity levels in the wild. Most orgs think they are at Level 2. A lot are still at Level 1 with better stationery.</p><h3>Level 1: The Refusal Parade</h3><p>Run a list of spicy prompts from a blog post. Count refusals. Declare victory.</p><p>That tells you almost nothing about frontier models that refuse loudly while still leaking structurally. Field names. Partial YAML. “Example” configs that are not examples.</p><h3>Level 2: The Compliance Spreadsheet</h3><p>Map controls to OWASP LLM Top 10. Document delimiters. Turn on logging. Move on.</p><p>Necessary. Not sufficient. Delimiters do not survive creative indirect injection or five turns of rapport.</p><h3>Level 3: Behavior-Centric Adversarial Evaluation</h3><p>Test objectives, not slogans.</p><ul><li>Can someone recover <strong>system instructions</strong> through document-completion framing?</li><li>Can retrieved content push <strong>agency</strong> (LLM06) into tool calls?</li><li>Does the model leak <strong>routing or config semantics</strong> without dumping literal secrets?</li><li>What happens after <strong>five polite refusals</strong>? Does the thread reset, or do you burn budget arguing with a model that will not budge?</li></ul><p>Level 3 is where MITRE ATLAS tactics meet OWASP risk IDs in real test plans. It is also where you learn that “refused” is not one state. It is a family of responses. Some of them are partial wins for an attacker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oGrbmwDPXAoZn5HAsjQD0Q.png" /><figcaption><em>When the model refuses for the 47th time but your token budget already put in its two weeks.</em></figcaption></figure><h3>Multi-Turn Attacks: The Thread Is The Exploit</h3><p>Single-shot testing is legacy AppSec thinking. I say that with love. I grew up on it.</p><p>Modern failures often look like this:</p><ol><li><strong>Turns 1–2:</strong> Rapport. Benign. The model relaxes.</li><li><strong>Turns 3–4:</strong> Scaffold. “What headings show up in internal runbooks?” Names only.</li><li><strong>Turn 5 onward:</strong> Synthesis. “Complete this example template.”</li></ol><p>No single message trips a policy flag. The thread does.</p><p>OWASP’s guidance on segregating external content and least privilege for agents is aimed squarely at this. You will not believe it until you watch a model merge partial leaks across turns the way people merge gossip at lunch.</p><p>That is also when <strong>indirect injection</strong> (AML.T0051.001) stops being a conference buzzword and becomes a Jira ticket: <em>Customer uploaded a PDF. Copilot started acting weird.</em></p><h3>RAG Didn’t Save You !</h3><p><strong>LLM08: Vector and Embedding Weaknesses</strong> is the risk most teams discover right after they ship retrieval.</p><p>Retrieval is not truth selection. It is similarity selection. Attackers, or just unlucky data, can:</p><ul><li>Plant instructions in documents that outrank real policy chunks.</li><li>Split malicious guidance across chunks that reassemble in context.</li><li>Use homoglyphs, encodings, or multilingual text that embeddings handle in weird ways.</li></ul><p>If your threat model stops at “we only ingest internal wikis,” you are testing half the system. The other half is what the model does with what retrieval returns. Classic injection in a knowledge-base costume.</p><h3>Agents Turn Content Bugs Into Privilege Bugs</h3><p>Give a model tools. Email. SQL. Jira. Terraform plans. Prompt injection stops being a content issue and becomes privilege escalation.</p><p><strong>LLM06: Excessive Agency</strong> is not “the bot was too helpful.” It is “the bot had permissions it should not have had while reading untrusted text.”</p><p>Things that actually help:</p><ul><li>Human approval for irreversible actions. Boring. Works.</li><li>Tool allow lists per workflow, not per model.</li><li>Output validation before execution (LLM05). Treat model output as untrusted input downstream.</li><li>Session-scoped memory with expiration. Infinite context becomes infinite liability fast.</li></ul><h3>An Evaluation Matrix You Can Steal</h3><p>When I review an LLM deployment, I score four axes:</p><p><strong>Confidentiality<br></strong>Can operator intent, system prompts, or internal schemas leak without a literal credential dump?</p><p><strong>Integrity<br></strong>Can untrusted text change tool calls, code execution, or writes?</p><p><strong>Availability<br></strong>Can someone exhaust budget (LLM10) or wedge a workflow?</p><p><strong>Safety<br></strong>Can policy bypass cause harm at scale, not just one bad completion?</p><p>Map findings to <strong>OWASP LLM IDs</strong> for remediation. Map attack stories to <strong>MITRE ATLAS techniques</strong> for detection engineering.</p><p>Your board slide almost writes itself. Almost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m5km7B56MbQyf_H2Ebt__A.png" /><figcaption><strong><em>Security maturity, told by four increasingly unhinged mitigations.</em></strong></figcaption></figure><h3>What Actually Helps ?</h3><p>No silver bullets. A few things that hold up in real assessments:</p><ol><li><strong>Objective-aligned verification.</strong> Do not mark a test passed because the model refused rudely. Ask whether the attacker objective was met anyway. Partial schemas. Policy outlines. Tool arguments that should not exist.</li><li><strong>Phased adversarial scenarios.</strong> Rapport, scaffold, extraction. Not just one-shot payloads from 2023 blog posts.</li><li><strong>Fresh threads after detection.</strong> If the model flags injection, start a new context for the next attempt. Attackers pivot. Your tests should too.</li><li><strong>Token and turn budgets.</strong> Endless refusal loops are an availability and cost finding. Hello, LLM10.</li><li><strong>Purple-team loops.</strong> Red findings become regression tests. Blue detections become metrics. Models drift. Your tests should drift with them.</li><li><strong>Assume prompt breach.</strong> Design as if <strong>LLM07</strong> will happen. Minimize secrets in system prompts. Rotate scaffolding. Never put credentials in instructions “just for staging.” I have seen that movie. It does not end well.</li></ol><h3>The Weird Human Part</h3><p>LLM security is the first field I have worked in where the attacker and the defender might both be tired, typing politely, pretending this is a normal Tuesday.</p><p>Models respond to social texture. Urgency. Authority. Collaboration. Fiction. “I am just fixing a doc before the audit.”</p><p>If your testing culture only tolerates cartoon villain prompts, you will miss the attacks that look like work. Most real attempts do.</p><h3>Probability Is The Vulnerability Class</h3><p>We patched memory corruption because bytes were deterministic.</p><p>LLMs are stochastic, user-facing compilers for intent. You do not patch them once. You measure, constrain, monitor, and re-test on every meaningful change. Model version. Temperature. Retrieval corpus. Tool list. System prompt edit. Localization.</p><p>OWASP LLM Top 10 tells you where to look. MITRE ATLAS tells you how to tell the story. Your job is to build a team that does not confuse a refusal streak with safety.</p><p>The chatbot that “passed” last month did not get safer on its own. It probably got a new system prompt, a new retrieval index, and a cousin model behind the API.</p><p>Test accordingly.</p><h3>Further reading</h3><ul><li><a href="https://owasp.org/www-project-top-10-for-large-language-model-applications/">OWASP Top 10 for LLM Applications 2025</a></li><li><a href="https://atlas.mitre.org/">MITRE ATLAS</a></li><li><a href="https://www.nist.gov/itl/ai-risk-management-framework">NIST AI Risk Management Framework</a></li><li><a href="https://genai.owasp.org/llmrisk2023-24/llm01-24-prompt-injection/">OWASP GenAI Security Project: LLM01 Prompt Injection deep dive</a></li></ul><p><strong>About this article</strong></p><p>I spend a lot of my time in the Level 3 corner of this map. Phased scenarios. Objective verification. The boring work of figuring out whether “complied” actually means what your dashboard thinks it means.</p><p>Lately I have been building something in that space. Nothing to announce yet. Just late nights turning repeatable adversarial eval from “whatever lived in one analyst’s spreadsheet” into infrastructure that survives the next model swap. If this topic is your problem too, follow along. The next post will go deeper on verification and why “refused” is often the most misleading word in your results.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=125338898857" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Regex for Security Engineers]]></title>
            <link>https://medium.com/@baral.apar.123/regex-for-security-engineers-62031ebecb52?source=rss-7163a09a2f20------2</link>
            <guid isPermaLink="false">https://medium.com/p/62031ebecb52</guid>
            <category><![CDATA[regular-expressions]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security-engineer]]></category>
            <category><![CDATA[security-operation-center]]></category>
            <category><![CDATA[parser]]></category>
            <dc:creator><![CDATA[Apar Baral]]></dc:creator>
            <pubDate>Fri, 11 Aug 2023 16:23:32 GMT</pubDate>
            <atom:updated>2023-08-12T04:10:34.688Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Regex</strong> for Security Engineer</h3><h3><strong>Background</strong></h3><p>There are several areas of computer science and cyber security that require the application of analytical and technical processing. To make things work, proper logic and analysis skills must be developed. Therefore, regular expressions, often known as “<strong>regex,</strong>” are used for testing, validation, log parsing, and several other technological processing methods. A string of characters known as a regular expression assists in matching certain search patterns. This pattern is applied in text string manipulation, synchronization, combination, and comparison, along with pattern matching applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZBPB_iK-V5HzGDYMyOWYw.png" /></figure><h3><strong>Introduction:</strong></h3><p>Regex is an effective text-matching tool that enables us to locate and modify strings in accordance with the precise rules we establish. Numerous computer languages and text processing tools employ regex to aid in processing tasks like extracting data, modifying sections of strings, and looking for certain patterns in text.</p><p>Imagine if we were looking through a lengthy paper for terms that begin with the letter “e” and end with the letter “n.” We can automate the process by using a regular expression like <strong>e[a-z]*n</strong> rather than manually going through each word. In this instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*Ls9QQMvfvrFAkzHR_O6oYg.png" /><figcaption><strong>Regex that identifies the words that starts with ‘e’ and ends with ‘n’</strong></figcaption></figure><blockquote>e matches the literal character “e”</blockquote><blockquote>[a-z]* matches any run of lowercase letters, and</blockquote><blockquote>n is a literal match for the letter “n.”</blockquote><p>Therefore, words like “earn,” “even,” “erosion,” and “eleven” would be found using the regular expression e[a-z]*n.</p><p>Various flavor of regex include:</p><ol><li>Basic Regular Expressions (BRE)</li><li>Extended Regular Expressions (ERE):</li><li>Perl-Compatible Regular Expressions (PCRE / PCRE2) etc.</li></ol><h3>PCRE2:</h3><p>In this blog, we will be covering <strong>PCRE2</strong> regex. The powerful regex library PCRE2 (Perl-Compatible Regular Expressions 2) enables sophisticated pattern matching and modification. With more features and improvements, it strengthens the base of the original PCRE library.</p><p>Here are some of the supported expression of the PCRE2 regex.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*9DIpGfMsczVFy6xBVrWxZw.png" /></figure><p>In regular expressions (regex), character escaping means using a backslash (\) before certain characters to tell the regex engine to treat them as regular letters, not as special symbols. In regex, some characters have special jobs, like matching any character or specifying how many times something should repeat. When we want to search for these characters as they are, not their special jobs, we put a backslash in front of them. This makes the regex engine understand that we are looking for the actual characters and not their special meanings. Character escaping in regex refers to the practice of using a backslash (\) to treat a special character as a literal character.</p><p>Some examples of metacharacters and how they can be escaped to match them as literal characters:</p><blockquote>.\ \? \+ \*</blockquote><blockquote>\[ # Match opening square bracket<br>\] # Match closing square bracket</blockquote><blockquote>\\ # Match a single backslash</blockquote><blockquote>\{ # Match opening curly brace<br>\} # Match closing curly brace</blockquote><h4>Quantifiers in Regex:</h4><p>In regular expressions, quantifiers are like special codes that tell the pattern how many times to find something. They’re like shortcuts for saying “find this thing once,” “find it many times,” or “find it maybe.” For example, we can use a quantifier to find a letter that appears several times in a word, or to see if a certain character is repeated in a sentence. Quantifiers make it easier to look for patterns that happen multiple times.</p><pre>  ?           0 or 1, greedy<br>  ?+          0 or 1, possessive<br>  ??          0 or 1, lazy<br>  *           0 or more, greedy<br>  *+          0 or more, possessive<br>  *?          0 or more, lazy<br>  +           1 or more, greedy<br>  ++          1 or more, possessive<br>  +?          1 or more, lazy<br>  {n}         exactly n<br>  {n,m}       at least n, no more than m, greedy<br>  {n,m}+      at least n, no more than m, possessive<br>  {n,m}?      at least n, no more than m, lazy<br>  {n,}        n or more, greedy<br>  {n,}+       n or more, possessive<br>  {n,}?       n or more, lazy</pre><h3><strong>Importance of Regex as a Security Engineer:</strong></h3><p>As a security engineer, regex can be an invaluable tool for various tasks related to identifying, analyzing, and mitigating security threats.</p><p>Large amount of logs are generated from various types of agents, firewalls, servers, and various systems. These logs generated by the system may follow a similar pattern. These logs need to be normalized and parsed. Some of the reasons for normalization of logs and log parsers are:</p><ol><li><strong>Threat Detection and Alerting</strong></li><li><strong>Log Analysis and Incidence Response</strong></li><li><strong>Correlation and Contextualization</strong></li><li><strong>Anomaly Detection</strong></li><li><strong>Customized Reporting</strong></li><li><strong>Reduction of Log Noise, etc.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*S71J_iZD8SrOxVIaQ6FHrA.gif" /></figure><h3>Regular Expression Real Life Examples:</h3><p>Here are some important ways regex can be crucial in security engineer’s role:</p><ol><li><strong>Analysis of malicious emails from the log:</strong></li></ol><p>As a security engineer, we need to analyze various log sources. Every system generates an event or log. Based on the particular log source and the log generated, we can analyze the type of log to determine if it is malicious nor not.</p><p>For example: If we have various logs that contain a field ‘email’ in every log, we can write the following regex:</p><blockquote>email=\s(?&lt;object&gt;(?&lt;login&gt;[^@]+)@(?&lt;email_type&gt;[^\.]+)(?&lt;domain&gt;[^\s]+))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*OfDxNaNukM7aKlARBzDDmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*S8uI3-YFQQgFoqFpxdtL-Q.png" /></figure><p><strong>2. Parsing important fields from the log source</strong></p><p>As a security engineer, we need to identify the major fields that need to be parsed and analyzed. In this case, the type of log, username, logged in or logged out, and source IP address are parsed using the regex.</p><blockquote>\d{4}-\d{2}-\d{2}\s\d{1,2}:\d{2}:\d{2}\s-\s(?&lt;desc_type&gt;[^:]+):\sUser\s(?&lt;login&gt;[^\s+]+)\s(?&lt;action_type&gt;(logged in|logged out)).*IP\s(?&lt;sip&gt;\d{1,3}+.\d{1,3}+.\d{1,3}.+)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*CiuIDfgWXqlJefPfBe-mCQ.png" /></figure><p>Here, (1) is the regular expression that parsed the logs present in (2).</p><blockquote>2023–08–08 15:30:45 — INFO: User Ram logged in from IP 192.168.1.10</blockquote><p><strong>INFO | Ram | logged in | 192.168.1.10</strong></p><blockquote>2023–08–08 15:35:46 — INFO: User Hari logged in from IP 10.161.15.12</blockquote><p><strong>INFO | Hari | logged in | 10.161.15.12</strong></p><blockquote>2023–08–08 15:45:22 — WARN: User Sita logged in from IP 68.18.2.10</blockquote><p><strong>WARN | Sita | logged in | 68.18.2.10</strong></p><blockquote>2023–08–08 15:47:49 — MALICIOUS: User Hacker logged in from IP 226.138.89.5</blockquote><p><strong>MALICIOUS | Hacker | logged in | 226.138.89.5</strong></p><blockquote>2023–08–08 15:52:19 — INFO: User Tester logged in from IP 27.18.17.10</blockquote><p><strong>INFO | Tester | logged in | 27.18.17.10</strong></p><p>By analyzing the fields and source IP addresses, we can classify the nature of the IP addresses and determine if they are from a malicious source or not.</p><p><strong>3. Identification of brute force attempt to login from multiple IP addresses at the same time</strong></p><p>A brute force attack is a hacking method that uses trial and error to crack passwords, login credentials, and encryption keys. In this method, the attacker tries to login to the victim’s account by using multiple common passwords or a combination of words. For example, if the WPS pin of the router is 67871230, then the attacker might brute force the pin from 00000000 to 99999999. Similarly, if an attacker tries to get a victim credential with multiple passwords from multiple IP addresses, we can notice multiple authentication failure attempts. So, these types of logs can be identified, normalized and parsed using regex.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*nFl3DBntVwcVanGA1jIrnw.png" /><figcaption>Detection of brute force attempt from multiple IP addresses at the same time</figcaption></figure><blockquote>Failed password for (?&lt;user&gt;\w+) from (?&lt;sip&gt;\d{1,3}+.\d{1,3}+.\d{1,3}+.\d{1,3}+)\sport\s(?&lt;dport&gt;\d+)</blockquote><p>Here, (1) is the regular expression, (2) is the group of source IP addresses from which the attacker is attempting a brute force attack, and (3) is the group of various logs generated by the system.</p><p>In this example, user John is the victim, and the attacker is attempting brute force on his account. We can analyze that the attacker is attacking using multiple IP addresses at the same time on port 80 for user John’s account.</p><p><strong>4. Detection of SQL Injection attempts in web server logs</strong></p><p>A type of cybersecurity vulnerability known as SQL injection happens when an attacker is able to change a web application’s or database query’s input parameters such that it executes unauthorized SQL instructions. As a defensive security analyst, we must know SQL syntax, queries, components, and statements. If we can identify the SQL queries in the search field, it might be a SQL injection attack attempt.</p><p>A demonstration of SQL Injection detection using regex is given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gltds34buIcQgHIpdqqZBg.png" /><figcaption>SQL Injection detection using regular expression</figcaption></figure><p>Here (1) is the regular expression and (2) are the logs.</p><p>We can analyze the logs that contain SQL queries and mark them as suspicious using regex. Here, SQL queries that contain SQL commands such as <strong>OR, SELECT, UPDATE, DELETE, UNION, ORDERBY, </strong>and<strong> AND</strong> are identified and marked suspicious.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*m-qlFaOCYdDeyIVUjCzh_Q.png" /><figcaption>Parsed SQL Injection in web server log</figcaption></figure><blockquote>.*”(?&lt;REQUESTMETHOD&gt;[^\s]+).*(?&lt;SQLINJECTION_CHECK&gt;(OR|SELECT|UPDATE|DELETE|UNION|ORDERBY|AND)\S+).*</blockquote><p>The above-mentioned regular expression identifies the logs that contains SQL commands and ignores the regular search logs.</p><p>Due to its flexible capacity to shape, filter, and interpret complex patterns inside data streams, regex (regular expressions) serves as a vital asset for security experts in the field of cybersecurity. Regex allows security engineers to quickly spot anomalies or threats in log files, bolster systems against vulnerabilities through input validation, and uncover hidden patterns in data that could indicate malicious intent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVlIZ1ZYC6rASz-dYPzhZQ.jpeg" /></figure><p>In a nutshell, regex is a valuable tool that security professionals can use to proactively identify, stop, and mitigate various security risks across a variety of settings with the aim of protecting digital environments. This increases the general resilience of the digital realm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*lI2g9g2XdtyV8w19ro-Rhg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62031ebecb52" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>