<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ information security - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ information security - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 05:06:28 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/information-security/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Strengthen Your Code: Essential Secure Design Principles for Developers ]]>
                </title>
                <description>
                    <![CDATA[ Secure design principles have long been the foundation for building secure systems. And they remain a crucial aspect of modern cybersecurity. Introduced in 1975 by Saltzer and Schroeder in their landmark paper The Protection of Information in Compute... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/essential-secure-design-principles-for-developers/</link>
                <guid isPermaLink="false">6706e4c64819d7266b88ad62</guid>
                
                    <category>
                        <![CDATA[ secure coding ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ softwaresecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ infosec ]]>
                    </category>
                
                    <category>
                        <![CDATA[ appsec ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Chama Jennane ]]>
                </dc:creator>
                <pubDate>Wed, 09 Oct 2024 20:17:10 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1728461315564/0ec07485-8537-475e-8b15-3ab653ababfc.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Secure design principles have long been the foundation for building secure systems. And they remain a crucial aspect of modern cybersecurity.</p>
<p>Introduced in 1975 by Saltzer and Schroeder in their landmark paper <em>The Protection of Information in Computer Systems</em>, these timeless principles continue to guide secure system design today.</p>
<p>Secure design principles are aimed at protecting computer-stored information from unauthorized access. In this article, we’ll discuss these principles in detail, emphasizing their ongoing relevance in preventing security vulnerabilities. You’ll see some real-world examples that highlight the importance of adhering to these principles for creating robust, secure systems. </p>
<p>Saltzer and Schroeder outlined eight core principles along with two additional ones. These additional principles, while initially considered to apply imperfectly to computer systems, have since proven essential. </p>
<p>Let's start by outlining these secure design principles before delving deeper into each one.</p>
<h2 id="heading-key-secure-design-principles">Key Secure Design Principles:</h2>
<ol>
<li><p>Economy of mechanism: Keep designs simple and minimal.  </p>
</li>
<li><p>Fail-safe defaults: Base access on permission, not exclusion.  </p>
</li>
<li><p>Complete mediation: Check every access request for authority.  </p>
</li>
<li><p>Open design: Secrets lie in data, not design.  </p>
</li>
<li><p>Separation of privilege: Require two parties for critical decisions, it is safer.  </p>
</li>
<li><p>Least privilege: Operate with the minimum necessary permissions.  </p>
</li>
<li><p>Least common mechanism: Limit shared subsystems between users.  </p>
</li>
<li><p>Psychological acceptability: Ensure usability for humans.  </p>
</li>
</ol>
<p>Additional principles:  </p>
<ol start="9">
<li><p>Work factor: Weigh the cost of breaching security against the attacker's resources.  </p>
</li>
<li><p>Compromise recording: Log breaches when they occur.  </p>
</li>
</ol>
<h2 id="heading-the-eight-main-secure-design-principles"><strong>The Eight Main Secure Design Principles</strong></h2>
<h3 id="heading-economy-of-mechanism"><strong>Economy of Mechanism</strong></h3>
<p>The first principle instructs that you should keep your design simple and compact to minimize unwanted access paths.</p>
<p>Errors often go unnoticed during normal use, making it crucial to have straightforward designs that are easier to inspect for vulnerabilities. A simpler codebase reduces the attack surface, offering fewer opportunities for exploitation and facilitating code verification.  </p>
<p>But remember that simplicity isn’t just a synonym for brevity. For instance, consider this C code:  </p>
<pre><code class="lang-c"><span class="hljs-comment">// Example A </span>
<span class="hljs-keyword">if</span> (a = b)  

<span class="hljs-comment">// Example B </span>
a = b;   
<span class="hljs-keyword">if</span> (a != <span class="hljs-number">0</span>)
</code></pre>
<p>Here, someone who looks at this code may think that the developer intended "==" instead of "=". The first example could lead to confusion, while the second clearly conveys the developer's intent. This may look trivial, but this confusion was key in an <a target="_blank" href="https://freedom-to-tinker.com/2013/10/09/the-linux-backdoor-attempt-of-2003/">attempt to backdoor the Linux kernel in 2003</a>! </p>
<p>Ultimately, it's tempting to write concise hacks that work, but they can become confusing, even to yourself in the future. Prioritize clean code and adhere to coding standards and best practices.  </p>
<h3 id="heading-fail-safe-defaults"><strong>Fail-Safe Defaults</strong></h3>
<p>You should base access decisions on permission rather than exclusion. Mistakes in permission-based systems typically result in accidental denials – that is, users being denied access to necessary information. These can be quickly identified.</p>
<p>On the other hand, errors in exclusion-based systems may lead to unauthorized access. These can often go unnoticed, as people rarely report having unnecessary permissions.  </p>
<p>In essence, you should prioritize allowlists over denylists – not just in access control, but also in input validation.</p>
<p>An allowlist (formerly known as a whitelist) specifies who can access what, denying everyone else by default. In contrast, a denylist (formerly known as a blacklist) allows all access except for specified exclusions. These are often implemented as rules, such as only allowing an integer value between 0 and 200, or a string that must match a regular expression before it can be accepted as an e-mail address. </p>
<h3 id="heading-complete-mediation"><strong>Complete Mediation</strong></h3>
<p>This principle states that every access to every object must undergo an authority check. It ensures a comprehensive view of access control, encompassing all system operations, from initialization to recovery, shutdown, and maintenance.</p>
<p>It requires a reliable method for identifying the source of every request, and any changes in authority must be promptly updated. This principle also applies to input validation. </p>
<p>Complete mediation emphasizes that no access should rely on previous checks or assumptions of validity, reflecting the defense-in-depth approach. Each access request must be validated in real-time to prevent vulnerabilities, such as time-of-check to time-of-use (TOCTTOU) attacks.  </p>
<p>Consider this scenario: You have two ATM cards linked to the same bank account. When you attempt to withdraw your funds at one ATM, it checks your balance and asks for confirmation. While waiting, you use the other ATM to withdraw the entire amount. If the first ATM didn't recheck your balance, you could exploit this to withdraw funds twice.</p>
<p>Fortunately, complete mediation ensures that the ATM verifies your balance again before dispensing cash, effectively preventing such exploitation.  </p>
<h3 id="heading-open-design"><strong>Open Design</strong></h3>
<p>Design transparency is crucial. Security should not rely on the ignorance of potential attackers, but instead on well-protected keys or passwords. Maintaining secrecy in widely distributed systems is unrealistic.  </p>
<p>The open design principle is grounded in <a target="_blank" href="https://petitcolas.net/kerckhoffs/index.html">Kerckhoff’s principle</a>, which asserts that a cryptographic system's security relies solely on the secrecy of its keys, while the algorithm itself should be public knowledge.  </p>
<p>In contrast, security by obscurity assumes safety through concealment, which is fundamentally flawed. Attackers can obtain design documents, reverse-engineer products, or exploit hidden vulnerabilities. Beyond that, keeping the implementation secret complicates security audits and reviews. Effective security design must never depend on keeping the implementation confidential.</p>
<h3 id="heading-separation-of-privilege"><strong>Separation of Privilege</strong></h3>
<p>Using a dual-key system is generally more secure and adaptable than relying on a single key for access. A key principle of secure design is to implement multiple layers of protection. The more checks in place, the tougher it becomes for attackers.  </p>
<p>But these checks should employ different mechanisms. For instance, in multi-factor authentication, combine knowledge-based methods (like a password) with either possession-based methods (like a token) or biometrics (like a fingerprint).</p>
<p>For added security, consider incorporating location data. If your credit card is used in London and then again in Moscow shortly after, your bank’s fraud detection will likely flag the second transaction. But it’s important to note that location data cannot substitute for any of the primary authentication factors.  </p>
<p>This principle also implies the necessity of creating users with specialized roles and privileges instead of relying on superusers who can access everything. </p>
<h3 id="heading-least-privilege"><strong>Least Privilege</strong></h3>
<p>Every program and user should have only the minimum privileges needed to perform their tasks. Identify the specific capabilities a program needs and provide only those permissions. This approach significantly reduces the impact of potential attacks.  </p>
<p>For instance, an image viewer shouldn’t require network access, and a bus timetable app shouldn’t access your call history or contacts. While implementing this can be challenging, the best strategy is to deny all permissions by default and grant them gradually as necessary.</p>
<h3 id="heading-least-common-mechanism"><strong>Least Common Mechanism</strong></h3>
<p>Minimize shared mechanisms among users, as each shared component, especially those involving common variables, can create security risks. Any dependence between components can lead to widespread consequences if one is compromised.  </p>
<p>Be cautious with shared code, as assumptions may change when the code interacts with different environments. For instance, the Ariane 5 rocket disaster resulted from reusing the Ariane 4 code without testing it with the new trajectory that had a much higher horizontal bias. This caused possibly the <a target="_blank" href="https://hownot2code.wordpress.com/2016/09/02/a-space-error-370-million-for-an-integer-overflow/">most expensive integer overflow in history</a>.</p>
<p>Shared data poses similar risks. If two processes access the same temporary files, a compromise of one of the processes can affect the other. Process separation and isolation as well as utilizing techniques like containers and virtualization can help prevent the domino effect. </p>
<h3 id="heading-psychological-acceptability"><strong>Psychological Acceptability</strong></h3>
<p>Design user interfaces for ease of use to ensure users apply security mechanisms correctly. When users' mental models align with the protection mechanisms, errors are minimized. If the authentication process is overly complicated, users may resist it or find ways around it.  </p>
<p>Balancing security and usability can be challenging, as increasing one often decreases the other. Aim for a compromise where security measures are effective but still allow for a positive user experience. </p>
<h2 id="heading-the-two-additional-principles"><strong>The Two Additional Principles</strong></h2>
<h3 id="heading-work-factor"><strong>Work Factor</strong></h3>
<p>Assess the cost of bypassing security mechanisms against an attacker's resources, known as the "work factor." While some work factors are straightforward to calculate, many computer security mechanisms defy easy assessment, making it challenging to gauge the risks accurately.</p>
<p>You should aim for a balance between security costs and potential losses, considering both the attacker’s motivations and the value of your assets.</p>
<p>For example, securing your car is usually sufficient if it’s harder to steal than your neighbor’s. But if your car is particularly desirable to thieves, you’ll need stronger security measures.  </p>
<p>For a practical example, password storage algorithms – such as Argon2, bcrypt, and scrypt – have a ‘work factor’ parameter that determines the amount of resources to use. This can be scaled to keep the algorithm fast enough for regular use, but prohibitively expensive to brute-force. </p>
<h3 id="heading-compromise-recording"><strong>Compromise Recording</strong></h3>
<p>This principle highlights the need for effective logging and evidence collection. If an attack goes unnoticed, the consequences can be severe, so detecting breaches promptly is vital for minimizing damage and facilitating incident response.  </p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>As Saltzer and Schroeder remind us, these principles serve as helpful warnings rather than strict rules. If you notice a principle being violated in your design, it’s a sign that something could be wrong and should be closely examined to ensure the issue is addressed or isn’t significant.  </p>
<p>Remember, even the best-designed systems can be vulnerable if a single bug slips through during implementation. That’s why secure design and implementation must work together – security is a comprehensive approach. Most exploitable weaknesses come from either the design phase or the implementation phase, and attackers don’t care which type they exploit – they just want to break in.  </p>
<p>The latest OWASP Top 10 emphasizes the critical role of design by <a target="_blank" href="https://owasp.org/Top10/A04_2021-Insecure_Design/">featuring "Insecure Design" for the first time</a>. To address this, it is essential for developer teams to understand best practices thoroughly.</p>
<p><a target="_blank" href="https://cydrill.com/">Cydrill</a>’s secure coding training program delves into these principles, offering real-world examples that demonstrate how neglecting them can lead to serious vulnerabilities. Check it out if you want to learn more.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ More Secure Authentication: From Passwords to Passkeys ]]>
                </title>
                <description>
                    <![CDATA[ In the ever-evolving world of cybersecurity, authentication remains a cornerstone. Traditional methods, like passwords and social logins, are increasingly vulnerable to attacks. Enter passkeys—a revolutionary approach promising enhanced security and ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/more-secure-authentication-from-passwords-to-passkeys/</link>
                <guid isPermaLink="false">66d039dddaf2a38a6b1e1d02</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Juan Cruz Martinez ]]>
                </dc:creator>
                <pubDate>Thu, 11 Jul 2024 13:38:21 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/07/passkeys-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In the ever-evolving world of cybersecurity, authentication remains a cornerstone. Traditional methods, like passwords and social logins, are increasingly vulnerable to attacks. Enter passkeys—a revolutionary approach promising enhanced security and user convenience. </p>
<p>This guide will explore the current state of authentication, delve into what passkeys are, how they work, and discuss the challenges and future of this technology.</p>
<h2 id="heading-the-current-state-of-authentication">The Current State of Authentication</h2>
<p>Authentication is a critical component of digital security, serving as the gateway to systems and data. Despite numerous advancements, traditional authentication methods, such as passwords and social logins, remain prevalent. But these methods are increasingly proving to be inadequate in addressing modern security challenges.</p>
<p>Passwords, once considered the gold standard, are now recognized as a significant weak link in cybersecurity. The rise in sophisticated cyberattacks, coupled with poor password practices, has highlighted the urgent need for more robust authentication mechanisms. </p>
<p>Passwords are susceptible to various attacks, including phishing, brute force, and credential stuffing. Many users also recycle passwords across multiple sites, exacerbating the risk. Managing multiple passwords can be cumbersome, leading to weak password practices and forgotten credentials.</p>
<p>Social logins, while convenient, bring their own set of issues, including privacy concerns and dependency on third-party platforms. Users are often wary of sharing their social media credentials with third-party sites, fearing data misuse. </p>
<p>Also, social logins tie users to specific platforms, which can be problematic if a user decides to leave a social network or if the platform experiences an outage.</p>
<p>Magic links, an alternative authentication method, also have their limitations. Magic links are sent via email, which is not always secure. If an email account is compromised, so is the authentication. </p>
<p>The process of checking email and clicking a link can be cumbersome, particularly for users on mobile devices or with poor internet connectivity. Emails can also be delayed, end up in spam folders, or fail to deliver, causing frustration and potential access issues for users.</p>
<p>As the digital landscape continues to evolve, the need for more secure, user-friendly, and scalable authentication solutions becomes paramount. This exploration of the inherent problems with passwords, social logins, and magic links sets the stage for understanding why passkeys are a vital innovation in the field of authentication.</p>
<h2 id="heading-what-are-passkeys">What are Passkeys?</h2>
<p>Passkeys represent a modern authentication solution designed to address the shortcomings of traditional methods. Essentially, passkeys eliminate the need for passwords by utilizing a pair of cryptographic keys to authenticate users securely.</p>
<p>At the core of passkeys is public-private key cryptography. Each user has a unique pair of keys: a public key, which is stored on the server, and a private key, which remains securely on the user's device. </p>
<p>When a user attempts to authenticate, they use a method like biometric verification (fingerprint or facial recognition) or a device-specific security feature to access their private key. </p>
<p>This private key generates a cryptographic signature that the server verifies using the corresponding public key, ensuring a secure and seamless authentication process.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/passkeys.png" alt="Image" width="600" height="400" loading="lazy">
<em>Diagram showing the passkey authentication process</em></p>
<p>Passkeys are built on the <a target="_blank" href="https://fidoalliance.org/fido2/">FIDO2 standard</a>, which promotes interoperability and security across different devices and platforms. Major tech companies, including Google, Microsoft, Okta, and Apple, support this standard, making it a robust and widely adopted solution.</p>
<p>The use of biometrics and device-based authentication enhances security by ensuring that the private key never leaves the user's device and is never exposed to potential attackers. </p>
<p>This approach significantly reduces the risk of phishing attacks, as there are no passwords to be stolen or guessed. Passkeys also help streamline the user experience by eliminating the need to remember and manage multiple passwords.</p>
<p>Implementing passkeys involves a few key steps:</p>
<ol>
<li><strong>Registration</strong>: During account creation or passkey setup, the user's device generates a new key pair. The public key is sent to the server and stored with the user's account information.</li>
<li><strong>Authentication</strong>: When the user logs in, they use their private key to generate a cryptographic signature. The server verifies this signature using the stored public key, ensuring that the user is who they claim to be.</li>
</ol>
<blockquote>
<p>Visit <a target="_blank" href="https://learnpasskeys.io/">learnpasskeys.io</a> to learn in detail how each of these processes work.</p>
</blockquote>
<p>By leveraging these principles, passkeys offer a secure, user-friendly, and scalable solution for modern authentication needs. As developers, understanding how passkeys work and how to implement them is crucial in staying ahead in the realm of digital security.</p>
<h2 id="heading-challenges-with-passkeys">Challenges with Passkeys</h2>
<p>While passkeys offer numerous advantages over traditional authentication methods, they are not without their challenges. Understanding these challenges is crucial for developers and organizations considering adopting this technology.</p>
<h3 id="heading-adoption-and-integration">Adoption and Integration</h3>
<p>One of the primary challenges with passkeys is the integration with existing systems. </p>
<p>Many organizations rely on legacy systems that are not compatible with passkey technology, requiring significant overhauls to implement. Migrating to a passkey-based system involves not only technical adjustments but also changes in infrastructure, which can be resource-intensive and time-consuming.</p>
<h3 id="heading-user-education-and-trust">User Education and Trust</h3>
<p>Introducing a new authentication method requires educating users about how it works and why it's beneficial. </p>
<p>Users need to understand and trust the new system, which can be a hurdle given the novelty of passkeys. Ensuring that users feel comfortable and secure with the transition from passwords to passkeys is essential for widespread adoption.</p>
<h3 id="heading-technical-considerations">Technical Considerations</h3>
<p>Passkeys rely heavily on device capabilities. Not all devices support biometric authentication or the FIDO2 standard, potentially limiting the adoption of passkeys. </p>
<p>Developers need to ensure that fallback mechanisms are in place for users with unsupported devices, which can complicate the implementation process.</p>
<h3 id="heading-compatibility-and-interoperability">Compatibility and Interoperability</h3>
<p>While the FIDO2 standard promotes interoperability, ensuring compatibility across different devices, operating systems, and browsers can still be challenging. Developers need to thoroughly test their implementations to ensure a seamless user experience across all platforms.</p>
<p>Despite these challenges, the benefits of passkeys in terms of security and user experience make them a compelling option for modern authentication. By addressing these challenges proactively, developers and organizations can pave the way for a more secure and user-friendly authentication future.</p>
<h2 id="heading-the-future-of-authentication">The Future of Authentication</h2>
<p>The evolution of authentication is a testament to our ongoing quest for balance between security and convenience. From the simplicity of passwords to the robust security of passkeys, each step forward has been driven by the need to protect our digital lives against increasingly sophisticated threats.</p>
<p>Passkeys represent a significant leap in this journey, offering a secure, user-friendly alternative to traditional methods. By leveraging cryptographic keys and biometric verification, passkeys address many of the vulnerabilities that plague passwords and social logins. </p>
<p>The path to widespread adoption is not without its challenges, though, from integration hurdles to user education. But despite these obstacles, the benefits of passkeys make them a compelling option for modern authentication. </p>
<p>As developers and organizations navigate these challenges, the future of authentication looks promising. By embracing innovations like passkeys, we can move towards a more secure, seamless digital experience for all users.</p>
<p>The story of authentication is ongoing, and as we continue to innovate, the lessons from our past and the potential of our future guide us towards a safer digital world. Stay ahead of the curve, keep learning, and together, we can build a more secure digital landscape.</p>
<p>Thanks for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Hash Passwords with bcrypt in Node.js ]]>
                </title>
                <description>
                    <![CDATA[ By Dennis Temoye Charity Security is critical in the field of web development, particularly when dealing with user credentials such as passwords. One security procedure that's critical in web development is password hashing.  Password hashing guarant... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-hash-passwords-with-bcrypt-in-nodejs/</link>
                <guid isPermaLink="false">66d45e01d14641365a05089a</guid>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 03 Apr 2024 22:01:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/How-to-Hash-Password-With-Bcrypt-In-Nodejs.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dennis Temoye Charity</p>
<p>Security is critical in the field of web development, particularly when dealing with user credentials such as passwords. One security procedure that's critical in web development is password hashing. </p>
<p>Password hashing guarantees that plaintext passwords are difficult for attackers to find, even in a situation where a database is compromised. But not all hashing methods are created equal, and this is where bcrypt stands out.</p>
<p>Node.js, a popular framework for developing web applications, provides a robust ecosystem for constructing secure authentication systems. In this article, we'll look at using bcrypt in Node.js to hash passwords. We'll look at how bcrypt may be smoothly incorporated into Node.js applications to improve security and safeguard user credentials effectively.</p>
<p>Whether you're an experienced Node.js developer looking to strengthen your authentication practices or a beginner looking to learn the best techniques for secure password management, this article will be helpful to you. Let's have a look at how you can use bcrypt to hash passwords in Node.js.</p>
<h3 id="heading-heres-what-well-cover">Here's what we'll cover:</h3>
<ol>
<li><a class="post-section-overview" href="#heading-what-is-hashing">What is Hashing?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-bcrypt">What is Bcrypt?</a></li>
<li><a class="post-section-overview" href="#heading-how-to-install-bcrypt-in-nodejs">How to Install Bcrypt in Nodejs</a></li>
<li><a class="post-section-overview" href="#heading-how-to-set-up-bcrypt-in-nodejs">How to Set Up Bcrypt in Node.js</a></li>
<li><a class="post-section-overview" href="#heading-how-to-hash-passwords-with-bcrypt">How to Hash Passwords With Bcrypt</a></li>
<li><a class="post-section-overview" href="#heading-how-to-verify-passwords-with-bcrypt">How to Verify Passwords With Bcryp</a>t</li>
<li><a class="post-section-overview" href="#heading-security-best-practices-with-bcrypt">Security Best Practices with Bcrypt</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ol>
<h2 id="heading-what-is-hashing">What is Hashing?</h2>
<p>Hashing involves converting a given key or string of characters into another value. This is typically represented by a shorter, fixed-length value or key that represents the original value and facilitates the retrieval.</p>
<h3 id="heading-what-is-password-hashing">What is Password Hashing?</h3>
<p>Password Hashing is a process of converting an input password into a fixed-length string of characters, typically for the purpose of securely storing and transmitting the password. </p>
<p>Password hash functions are designed to be one-way functions. This means it should not be computationally possible to reverse the process and get the original input password from the hashed value.</p>
<p>For example, suppose we want to hash a password like "password123". The password will be transformed into a fixed-length character string using a hash algorithm like bcrypt. And we'll get a hashed result once the hash function has processed our password. </p>
<p>The hashed output of "password123" using bcrypt, for instance, would look like this:</p>
<pre><code>e234dsdom3k2kmdl3l43iwes9vjro44223m3n32kn5n2ksdo4
</code></pre><p>Now that you understand the basics of how password hashing works, it's time to dive deeper into the practical application of hashing a password using the bcrypt algorithm. </p>
<p>But before we proceed with that, let's learn a bit more about bcrypt so you understand its workings and installation process, as well as how to integrate it into a Node.js project.</p>
<p>Firstly, let's gain insight into bcrypt – what it is, how it operates, and its significance in password security. Then we'll discuss how to install bcrypt and integrate it seamlessly within a Node.js environment. This will include a detailed walkthrough on setting up bcrypt within your project and leveraging its functionalities effectively.</p>
<p>By the end of this article, you'll have a comprehensive understanding of bcrypt, equipped with the knowledge to securely hash passwords in your Node.js applications. So, let's embark on this journey to enhance the security of our projects through bcrypt integration.</p>
<h2 id="heading-what-is-bcrypt">What is bcrypt?</h2>
<p>bcrypt is a type of cryptographic algorithm used to securely store passwords. It scrambles a user's password into a unique code. This way, even if a thief takes the database, they won't be able to recover the original passwords readily.</p>
<h3 id="heading-how-does-bcrypt-work">How Does bcrypt Work?</h3>
<p>bcrypt works by combining hashing and a technique known as salting, which is specifically developed to make stored passwords more safe. </p>
<p>Here's a breakdown of the procedure:</p>
<ol>
<li><strong>Hashing:</strong> Bcrypt processes a user's password using a sophisticated mathematical function. This function converts the password to a fixed-length string of characters that appear random and meaningless. The hashed value is what is kept in the database, not the original password. Because the hashing function is one-way, reversing the hash will not produce the original password.</li>
<li><strong>Salting:</strong> To improve security, bcrypt incorporates a random number called a salt. This salt is unique to each password and is attached to it before hashing. The combined value (password + salt) is then passed to the hashing function.</li>
</ol>
<h2 id="heading-how-to-install-bcrypt-in-nodejs">How to Install Bcrypt in Nodejs</h2>
<p>Before you install bcrypt, you'll need to have a Node.js project already set up. If you haven't created one yet, follow these steps to create a new Node.js project:</p>
<h3 id="heading-create-a-directory">Create a directory:</h3>
<p>This command creates a new directory (folder) where your Node.js project will reside. It's named <code>bcrypt-password-hash</code>.</p>
<pre><code>mkdir bcrypt-password-hash
</code></pre><ul>
<li><code>mkdir</code>: This command stands for "make directory." It's used to create a new directory.</li>
<li><code>bcrypt-password-hash</code>: This is the name of the directory you're creating. You can choose any name you prefer for your project directory.</li>
</ul>
<h3 id="heading-change-into-the-newly-created-directory">Change into the newly created directory:</h3>
<p>This command navigates you into the newly created directory so that you can start working on your project within it.</p>
<pre><code>cd bcrypt-password-hash
</code></pre><ul>
<li><code>cd</code>: This command stands for "change directory." It's used to move from one directory to another.</li>
<li><code>bcrypt-password-hash</code>: This is the name of the directory you want to navigate into.</li>
</ul>
<h3 id="heading-initialize-a-new-nodejs-project">Initialize a new Node.js project:</h3>
<p>This command initializes a new Node.js project within the directory you created. It creates a <code>package.json</code> file, which is used to manage dependencies and configuration for your Node.js project.</p>
<pre><code>npm init -y
</code></pre><ul>
<li><code>npm init</code>: This command initializes a new Node.js project using npm (Node Package Manager).</li>
<li><code>-y</code>: This flag automatically accepts all default values for the <code>package.json</code> file, so you don't have to manually provide input for each field.</li>
</ul>
<p>After running these commands, you should have a new directory (bcrypt-password-hash) with a package.json file, indicating that you successfully created a new Node.js project. You can now go ahead and install dependencies and write code.</p>
<h3 id="heading-create-a-file-named-indexjs-where-you-will-write-your-code">Create a file named <code>index.js</code> where you will write your code:</h3>
<p>To create a file named <code>index.js</code> where you will write your code, you can use the <code>touch</code> command in your terminal. Here's how to do it:</p>
<pre><code>touch index.js
</code></pre><ul>
<li><code>touch</code>: This command is used to create a new file. (Note that you must have already installed <code>touch</code> on your machine to use it. If<br>you haven't, you may run this command in your terminal to install<br>touch: <code>npm install touch-cli -g</code>.)</li>
<li><code>index.js</code>: This is the name of the file you want to create. In this case, you're creating a JavaScript file named <code>index.js</code>.</li>
</ul>
<p>After running this command, you'll have a new file named <code>index.js</code> in your project directory where you can write your Node.js code just like you can see in the image below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/Bcrypt.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now that we've correctly constructed a Node.js project, we can install bcrypt in our project.</p>
<h3 id="heading-install-the-required-dependencies-bcrypt">Install the required dependencies (bcrypt):</h3>
<p>To install bcrypt, you'll use npm, the Node.js package manager. Here's the command to install bcrypt:</p>
<pre><code>npm install bcrypt
</code></pre><ul>
<li><code>npm install</code>: This command is used to install packages from the npm registry.</li>
<li><code>bcrypt</code>: This is the name of the package you want to install. bcrypt is a popular package for hashing passwords securely in Node.js.</li>
</ul>
<p>When you run this command, npm will download and install the bcrypt package and its dependencies in the <code>node_modules</code> directory of your project. This directory will include all of the dependencies required for your project, including bcrypt.</p>
<h2 id="heading-how-to-set-up-bcrypt-in-nodejs">How to Set Up Bcrypt in Node.js</h2>
<p>Once Bcrypt is installed in your Node.js project, you can seamlessly integrate its functionality into your application. Here's how to proceed:</p>
<p>Firstly, after installing the bcrypt package using npm, make sure you import it into your Node.js application <code>index.js</code> file to utilize its features effectively. </p>
<p>Here's how to do it:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> bcrypt = <span class="hljs-built_in">require</span>(<span class="hljs-string">'bcrypt'</span>);
</code></pre>
<p>This line of code ensures that the bcrypt package is accessible within your application, allowing you to leverage its powerful capabilities for secure password hashing and verification. </p>
<p>With bcrypt integrated into your project, you can enhance the security of user authentication and data protection.</p>
<p>bcrypt provides two primary functions for password hashing and comparison:</p>
<ol>
<li><code>bcrypt.hash()</code>: This function is used to generate a hash of a plaintext password. It takes the plaintext password and a salt factor (optional) as input parameters and returns the hashed password asynchronously.</li>
<li><code>bcrypt.compare()</code>: This function is used to compare a plaintext password with its hashed counterpart. It takes the plaintext password and the hashed password as input parameters and returns a boolean value indicating whether the passwords match.</li>
</ol>
<h2 id="heading-how-to-hash-passwords-with-bcrypt">How to Hash Passwords With Bcrypt</h2>
<p>Having delved into the significance of password hashing, as well as the concepts of hash and salt, let's put theory into practice within our <code>index.js</code> file.</p>
<h3 id="heading-how-to-generate-a-salt-and-hash-the-password">How to Generate a Salt and Hash the Password</h3>
<p>As we've learned, a key aspect of secure password hashing involves incorporating a unique salt into the hashing process. bcrypt simplifies this by handling salt generation and password hashing seamlessly.</p>
<p>To begin, we require the bcrypt module in our Node.js application:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> bcrypt = <span class="hljs-built_in">require</span>(<span class="hljs-string">'bcrypt'</span>);
</code></pre>
<p>To ensure the strength of our password hashes, we determine the number of salt rounds. This value dictates the computational cost of hashing and, consequently, the level of security:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> saltRounds = <span class="hljs-number">10</span>; <span class="hljs-comment">// Typically a value between 10 and 12</span>
</code></pre>
<p>With our configuration established, we can generate a salt asynchronously using the <code>bcrypt.genSalt()</code> function. This salt will be unique for each password hash, enhancing security:</p>
<pre><code class="lang-javascript">bcrypt.genSalt(saltRounds, <span class="hljs-function">(<span class="hljs-params">err, salt</span>) =&gt;</span> {
<span class="hljs-keyword">if</span> (err) {
    <span class="hljs-comment">// Handle error</span>
    <span class="hljs-keyword">return</span>;
}

<span class="hljs-comment">// Salt generation successful, proceed to hash the password</span>
});
</code></pre>
<p>Once the salt is generated, we combine it with the user's password to compute the hash using the <code>bcrypt.hash()</code> function. This results in a securely hashed password ready for storage:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> userPassword = <span class="hljs-string">'user_password'</span>; <span class="hljs-comment">// Replace with the actual password</span>
bcrypt.hash(userPassword, salt, <span class="hljs-function">(<span class="hljs-params">err, hash</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (err) {
        <span class="hljs-comment">// Handle error</span>
        <span class="hljs-keyword">return</span>;
    }

<span class="hljs-comment">// Hashing successful, 'hash' contains the hashed password</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Hashed password:'</span>, hash);
});
</code></pre>
<p>By leveraging bcrypt for password hashing in our Node.js application, we ensure the robust security of user credentials. The incorporation of unique salts for each password hash, coupled with the computational complexity of bcrypt, fortifies our defense against unauthorized access and malicious attacks.</p>
<p>In the next section, we'll explore how to verify passwords and discuss best practices for securely managing hashed passwords.</p>
<h2 id="heading-how-to-verify-passwords-with-bcrypt">How to Verify Passwords With Bcrypt</h2>
<p>Now that we've covered the process of hashing passwords using bcrypt within our Node.js application, let's shift our focus to verifying passwords during user authentication. </p>
<p>In this section, we'll explore how bcrypt facilitates password verification, ensuring a secure and seamless authentication process.</p>
<h3 id="heading-how-to-retrieve-a-hashed-password-from-the-database">How to Retrieve a Hashed Password from the Database</h3>
<p>Before we can verify a user's password, we need to retrieve the hashed password associated with the user's account from the database. </p>
<p>Assuming you have a user authentication system in place, you'll typically query the database to fetch the hashed password based on the user's username or email.</p>
<p>Once you have retrieved the hashed password from the database, you're ready to proceed with the password verification process.</p>
<h3 id="heading-how-to-verify-passwords">How to Verify Passwords</h3>
<p>To verify a password using bcrypt, use the <code>bcrypt.compare()</code> function. This function compares a plaintext password provided by the user during login with the hashed password stored in the database.</p>
<p>Here's how you can implement password verification using bcrypt in your Node.js application:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> storedHashedPassword = <span class="hljs-string">'hashed_password_from_database'</span>;
<span class="hljs-keyword">const</span> userInputPassword = <span class="hljs-string">'password_attempt_from_user'</span>;

bcrypt.compare(userInputPassword, storedHashedPassword, <span class="hljs-function">(<span class="hljs-params">err, result</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (err) {
        <span class="hljs-comment">// Handle error</span>
        <span class="hljs-built_in">console</span>.error(<span class="hljs-string">'Error comparing passwords:'</span>, err);
        <span class="hljs-keyword">return</span>;
    }

<span class="hljs-keyword">if</span> (result) {
    <span class="hljs-comment">// Passwords match, authentication successful</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Passwords match! User authenticated.'</span>);
} <span class="hljs-keyword">else</span> {
    <span class="hljs-comment">// Passwords don't match, authentication failed</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Passwords do not match! Authentication failed.'</span>);
}
});
</code></pre>
<p>In this code snippet, <code>storedHashedPassword</code> represents the hashed password retrieved from the database, while <code>userInputPassword</code> is the plaintext password provided by the user during login. The <code>bcrypt.compare()</code> function compares these two passwords and returns a boolean value indicating whether they match.</p>
<p>In the next section, we'll discuss best practices for securely managing hashed passwords, including considerations for password storage and handling.</p>
<h2 id="heading-security-best-practices-with-bcrypt">Security Best Practices with bcrypt</h2>
<p>Now that we've discussed the principles of password hashing and verification with bcrypt, let's look at some important security best practices to ensure the integrity of our authentication system.</p>
<h3 id="heading-robust-password-guidelines">Robust Password Guidelines</h3>
<p>Encourage users to create strong and complex passwords that are resistant to dictionary attacks. Provide guidance on password length, the inclusion of alphanumeric characters, symbols, and the avoidance of common patterns.</p>
<h3 id="heading-salting">Salting</h3>
<p>Always use a unique salt for each password hash. This prevents attackers from using precomputed rainbow tables to crack passwords. bcrypt automatically handles salt generation, ensuring that each hash is unique.</p>
<h3 id="heading-adaptive-hashing">Adaptive Hashing</h3>
<p>bcrypt employs adaptive hashing, allowing developers to adjust the computational cost of hashing over time. Periodically increase the number of hashing rounds to keep pace with advancements in hardware and computational power.</p>
<h3 id="heading-secure-storage">Secure Storage</h3>
<p>Store hashed passwords securely in your database. Ensure that access controls are in place to prevent unauthorized access to user credentials. Avoid storing plaintext passwords or using reversible encryption algorithms.</p>
<h3 id="heading-error-handling">Error Handling</h3>
<p>Implement proper error handling mechanisms when working with bcrypt functions. Handle errors gracefully and avoid leaking sensitive information that could aid attackers in exploiting vulnerabilities.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In conclusion, we have explored the essential aspects of password security and the role of bcrypt in safeguarding user credentials within Node.js applications. From understanding the fundamentals of password hashing and salting to implementing secure authentication mechanisms, we have covered a wide array of topics aimed at enhancing the security posture of our applications.</p>
<p>By leveraging bcrypt for password hashing and verification, we ensure that sensitive user data remains protected against unauthorized access and malicious attacks. bcrypt's robust algorithm, combined with adaptive hashing and salt generation, provides a reliable defense mechanism against common password-based vulnerabilities.</p>
<p>We also discussed security best practices, including strong password policies, secure storage practices, and error handling. By adhering to these best practices and staying vigilant against evolving threats, we can create a secure authentication system that instills confidence in our users and upholds the integrity of our applications.</p>
<p>Let's continue to prioritize security and strive for excellence in our pursuit of building robust and trustworthy applications.</p>
<p>Thank you for joining me on this exploration of password security with bcrypt. Together, we can create a safer digital environment for all users.</p>
<p>Happy Coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Homomorphic Encryption Works – Explained in Plain English ]]>
                </title>
                <description>
                    <![CDATA[ As the fields of cryptography and cybersecurity advance, homomorphic encryption stands out as a groundbreaking technology.  It has the potential to reshape everything in data privacy and security. What really is homomorphic encryption? Why is it gett... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/homomorphic-encryption-in-plain-english/</link>
                <guid isPermaLink="false">66ba5320ba2ef92905bfa81d</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tiago Capelo Monteiro ]]>
                </dc:creator>
                <pubDate>Mon, 29 Jan 2024 18:33:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/07/vanna-phon-hRXIKdxoaPo-unsplash--1-.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As the fields of cryptography and cybersecurity advance, <a target="_blank" href="https://www.freecodecamp.org/news/introduction-to-homomorphic-encryption/">homomorphic encryption</a> stands out as a groundbreaking technology. </p>
<p>It has the potential to reshape everything in data privacy and security.</p>
<p>What really is homomorphic encryption? Why is it getting so much attention? How can it increase data privacy?</p>
<p>Essentially, with homomorphic encryption, we can process encrypted data without ever needing to decrypt it for computation.</p>
<p>This results in complete privacy everywhere the data is processed and stored.</p>
<p>In this article, you'll learn why this type of encryption will revolutionize the field of security. We'll tackle questions such as:</p>
<ul>
<li>What is homomorphic encryption?</li>
<li>How does homomorphic encryption work?</li>
<li>Homomorphic encryption vs traditional encryption – what's the difference?</li>
<li>What are the applications of homomorphic encryption?</li>
</ul>
<h2 id="heading-what-is-homomorphic-encryption">What is Homomorphic Encryption?</h2>
<p>Let's use an analogy to understand homomorphic encryption.</p>
<p>Imagine a locked treasure chest that has many valuable items inside.</p>
<p>To add or remove items, you need to unlock the chest. This could make it easier for thieves to steal the items when you open it.</p>
<p>In this analogy, this is what traditional encryption is.</p>
<p>Homomorphic encryption is like having a magical glove that allows you to add or remove items from the chest without ever unlocking it.</p>
<p>This way, you remove the risk of thieves ever getting the items inside the treasure chest.</p>
<p>This is essentially what Homomorphic encryption does with data: it allows us to perform operations on encrypted data without ever needing to decrypt it.</p>
<p>This is not possible with traditional encryption. In that case, we must process the data we need to decrypt, do whatever computations are necessary, and then encrypt the data again.</p>
<p>With homomorphic encryption, security is never compromised.</p>
<h2 id="heading-how-does-homomorphic-encryption-work">How Does Homomorphic Encryption Work?</h2>
<p>Homomorphic encryption allows computations to act on encrypted data – also called ciphertext.</p>
<p>This means the data is processed while encrypted.</p>
<p>Homomorphic encryption does computations on encrypted data (ciphertext). But computations done in ciphertext give encrypted results.</p>
<p>When these results are decrypted, they are similar to those that would've been obtained if the operations had been performed on the original, unencrypted data.</p>
<p>So basically, homomorphic encryption allows operations on encrypted data to give the same results as if performed on the original, decrypted data.</p>
<h3 id="heading-how-is-this-done">How is this done?</h3>
<p>Homomorphic encryption uses complex mathematical algorithms that:</p>
<ul>
<li>transform the numbers to obscure the original data, and </li>
<li>perform the same operations whether on the original or on this obscured data.</li>
</ul>
<p>Essentially, you're always working on the same data in the same way, but from different points of view.</p>
<p>So you can work with the data and get exactly the same results as if it were not encrypted. But since it actually is encrypted, the data is always protected!</p>
<p>This way, no one can see it and maybe steal it, which allows data privacy even in environments where trust is minimal.</p>
<h3 id="heading-python-code-example">Python code example</h3>
<p>We are going to use the Pyfhel library for this example, which you can read more about <a target="_blank" href="https://pypi.org/project/Pyfhel/3.1.1/">here</a>.</p>
<p>In this code, we are going to add two numbers in their encrypted form and see the results.</p>
<p>Here is the full code so you can truly understand how homomorphic encryption works:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> Pyfhel <span class="hljs-keyword">import</span> Pyfhel

HE = Pyfhel()
HE.contextGen(scheme=<span class="hljs-string">'bfv'</span>, n=<span class="hljs-number">2</span>**<span class="hljs-number">14</span>, t_bits=<span class="hljs-number">20</span>)
HE.keyGen()

integer1 = np.array([<span class="hljs-number">127</span>], dtype=np.int64)
integer2 = np.array([<span class="hljs-number">-57</span>], dtype=np.int64)

ctxt1 = HE.encryptInt(integer1)
ctxt2 = HE.encryptInt(integer2)

ctxtSum = ctxt1 + ctxt2
ctxtSub = ctxt1 - ctxt2
ctxtMul = ctxt1 * ctxt2

resSum = HE.decryptInt(ctxtSum) 
resSub = HE.decryptInt(ctxtSub)
resMul = HE.decryptInt(ctxtMul)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/ray-so-export.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now we are going to break it down line by line:</p>
<p>First, we need to import the necessary modules:</p>
<pre><code><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> Pyfhel <span class="hljs-keyword">import</span> Pyfhel
</code></pre><p>Here, we are just importing the necessary modules to make our calculations.</p>
<p>Next, we need to create a Pyfhel object and generate keys:</p>
<pre><code>HE = Pyfhel()
HE.contextGen(scheme=<span class="hljs-string">'bfv'</span>, n=<span class="hljs-number">2</span>**<span class="hljs-number">14</span>, t_bits=<span class="hljs-number">20</span>)
HE.keyGen()
</code></pre><p>In the first line we initialize a <code>Pyfhel</code> python object. In the second line we set encryption with certain parameters:</p>
<ul>
<li><code>scheme='bfv'</code>: We use the <a target="_blank" href="https://link.springer.com/chapter/10.1007/978-3-030-92078-4_21">BFV (Brakerski/Fan-Vercauteren)</a> homomorphic encryption scheme.</li>
<li><code>n=2**14</code>: Defines the degree of the polynomial modulus degree. The polynomial modulus degree balances the encryption security level with the computational efficiency. A bigger number gives better encryption but at the cost of more computational resources</li>
<li><code>t_bits=20</code>: Sets the bit size of the plaintext modulus. Bigger bit size values let you use larger numbers but make the encryption less clean</li>
<li>In the third line, we <a target="_blank" href="https://www.freecodecamp.org/news/encryption-explained-in-plain-english/">generate a public and private key</a></li>
</ul>
<p>Then, we get two numbers and encrypt them:</p>
<pre><code>integer1 = np.array([<span class="hljs-number">127</span>], dtype=np.int64)
integer2 = np.array([<span class="hljs-number">-57</span>], dtype=np.int64)

ctxt1 = HE.encryptInt(integer1)
ctxt2 = HE.encryptInt(integer2)
</code></pre><p>We represent the numbers in a array with just one number and encrypt them.</p>
<p>We represent these numbers in an array and not as if we are declaring variables.</p>
<p>We do this because the function <code>encryptInt()</code> only takes an array of integers with 64 bits as an argument. From the <a target="_blank" href="https://pyfhel.readthedocs.io/en/latest/_autosummary/Pyfhel.Pyfhel.html">documentation</a>:</p>
<pre><code class="lang-python">encryptInt(self, int64_t[:] arr, PyCtxt ctxt=<span class="hljs-literal">None</span>)
</code></pre>
<p>Now we'll perform the operations on the two numbers while encrypted:</p>
<pre><code>ctxtSum = ctxt1 + ctxt2
ctxtSub = ctxt1 - ctxt2
ctxtMul = ctxt1 * ctxt2
</code></pre><p>And then decrypt the numbers after the operation when they where encrypted:</p>
<pre><code>resSum = HE.decryptInt(ctxtSum) 
resSub = HE.decryptInt(ctxtSub)
resMul = HE.decryptInt(ctxtMul)
</code></pre><p>Which will output the following:</p>
<pre><code>&gt;&gt;&gt; [<span class="hljs-number">70</span>  <span class="hljs-number">0</span>  <span class="hljs-number">0</span> ...  <span class="hljs-number">0</span>  <span class="hljs-number">0</span>  <span class="hljs-number">0</span>]
&gt;&gt;&gt; [<span class="hljs-number">184</span>   <span class="hljs-number">0</span>   <span class="hljs-number">0</span> ...   <span class="hljs-number">0</span>   <span class="hljs-number">0</span>   <span class="hljs-number">0</span>]
&gt;&gt;&gt; [<span class="hljs-number">-7239</span>     <span class="hljs-number">0</span>     <span class="hljs-number">0</span> ...     <span class="hljs-number">0</span>     <span class="hljs-number">0</span>     <span class="hljs-number">0</span>]
</code></pre><p>And if we do the normal calculations without being encrypted, we see that the values match:</p>
<pre><code>integer1 = <span class="hljs-number">127</span>
integer2 = <span class="hljs-number">-57</span>

print(integer1+integer2)

print(integer1-integer2)

print(integer1*integer2)
</code></pre><p>Which gives the following:</p>
<pre><code>&gt;&gt;&gt; <span class="hljs-number">70</span>

&gt;&gt;&gt; <span class="hljs-number">184</span>

&gt;&gt;&gt; <span class="hljs-number">-7239</span>
</code></pre><p>As you can see, we get the same results if we perform the operations on the data while it's encrypted as we do when it's not encrypted.</p>
<h2 id="heading-homomorphic-encryption-vs-traditional-encryption-whats-the-difference">Homomorphic Encryption vs Traditional Encryption – What's the Difference?</h2>
<p>In traditional encryption methods, data needs to be decrypted before any kind of processing. </p>
<p>In homomorphic encryption, data is always used in its encrypted state.</p>
<p>Traditional encryption is like a secure envelope: contents must be taken out to be read or modified. </p>
<p>Homomorphic encryption is like a special envelope that allows content manipulation without ever needing to open it to be read or modified.</p>
<h2 id="heading-applications-of-homomorphic-encryption">Applications of Homomorphic Encryption</h2>
<p>There are many practical applications of homomorphic encryption.</p>
<p>In cloud computing, it allows users to process data in the cloud without ever exposing it to cloud service providers. This way, sensitive information always remains confidential.</p>
<p>In healthcare, it allows the analysis of encrypted medical records without compromising patient privacy. Patient health data always remains protected.</p>
<p>Another promising application of homomorphic encryption is in secure voting systems. Using this type of encryption, votes are counted in such a way that no one can see for whom each person voted. This would make the voting process safer and more private.</p>
<p>These examples represent just the tip of the iceberg. </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Homomorphic encryption is a paradigm shift in how we handle and process sensitive data. </p>
<p>This technology and its development are important as more and more data breaches are happening all the time.</p>
<p>Homomorphic encryption offers a path toward the simplification of data privacy regulations. </p>
<p>It also allows more innovation by making the protection of private data simpler, encouraging new security developments.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Defend Against Server-Side Request Forgery ]]>
                </title>
                <description>
                    <![CDATA[ Server-Side Request Forgery (SSRF) has been a consistent issue in application security and is among the OWASP Top 10 vulnerabilities. In this walkthrough, you'll first learn what Server-Side Request Forgery is and how it differs from Client-Side Requ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/defending-against-ssrf-attacks/</link>
                <guid isPermaLink="false">66c4c5321b22d2d8d9040ebb</guid>
                
                    <category>
                        <![CDATA[ Back end development  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hamdaan Ali ]]>
                </dc:creator>
                <pubDate>Fri, 05 Jan 2024 17:21:50 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1730833444910/4e483988-c1f3-4637-af6c-fcf2fbedbbb6.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Server-Side Request Forgery (SSRF) has been a consistent issue in application security and is among the OWASP Top 10 vulnerabilities.</p>
<p>In this walkthrough, you'll first learn what Server-Side Request Forgery is and how it differs from Client-Side Request Forgery. We will create a sample application to gain a better understanding of how Server-Side Request Forgery attacks work, and explore various methods to safeguard our application against SSRF vulnerabilities.</p>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-server-side-request-forgery">What is Server-Side Request Forgery?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-does-ssrf-differ-from-csrf">How Does SSRF Differ from CSRF?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-identifying-code-smells">Identifying Code Smells</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-understanding-the-pain-points">Understanding the Pain Points</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-project-setup">Project Setup</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-exploit-the-vulnerability">How to Exploit the Vulnerability</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-defend-against-ssrf-attacks">How to Defend Against SSRF Attacks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-wrapping-up">Wrapping Up</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ol>
<li><p><strong>Node and Express:</strong> We'll create a JavaScript sample application using the Express framework. A basic understanding of the framework would be helpful. You will need the <a target="_blank" href="https://nodejs.org/en/download/">Node Runtime Environment</a> to execute the scripts.</p>
</li>
<li><p><strong>Postman Client:</strong> To make an API request and to exploit the vulnerability, you will need a tool to make HTTP Requests. You may use your web browser's "Edit and Send" feature under the Networks tab, but since not all browsers allow this, it's best to use a tool like <a target="_blank" href="https://www.postman.com/downloads/">Postman</a> which provides a better UI to observe responses.</p>
</li>
</ol>
<h2 id="heading-what-is-server-side-request-forgery">What is Server-Side Request Forgery?</h2>
<p>Server-Side Request Forgery, or SSRF, is a security vulnerability that allows malicious actors to manipulate the server into making unintended requests on behalf of the server itself.</p>
<p>SSRF provides a window for such malicious actors to make requests "from" the server when they should be making requests "to" the server.</p>
<p>To appreciate what this means, let's look at a normal request execution using the sequence diagrams below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/12/image-104.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>UML Sequence Diagram for normal request execution</em></p>
<p>In a typical scenario, a server processes incoming requests from clients. Users or external systems initiate these requests, and the server responds accordingly. This is a standard client-server interaction where the server acts upon the requests it receives.</p>
<p>Now let's look at what SSRF looks like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/image-7.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>UML Sequence Diagram for SSRF attacks</em></p>
<p>In applications vulnerable to SSRF, attackers exploit the server's ability to make HTTP requests to resources that should not be directly accessible from the public internet. These resources may include internal protected resources, APIs, websites, or databases that can only be accessed from the server.</p>
<p>Attackers achieve this by tricking the server into making unintended requests to various destinations, including internal APIs, internal HTML pages, and internal databases.</p>
<h2 id="heading-how-does-ssrf-differ-from-csrf">How Does SSRF Differ from CSRF?</h2>
<p>SSRF is an attack where an attacker can make the server perform requests on their behalf. This involves manipulating the server to make requests to internal resources, which can result in unauthorized actions or information disclosure.</p>
<p>On the other hand, in CSRF, or Client-Side Request Forgery, the attacker tricks a user's browser into making unintended requests to a specific web application for which the user is already authenticated. This means that actions are performed on behalf of the user without their consent.</p>
<p>Backend Developers must be aware of SSRF to make secure applications. In contrast, front-end developers must be mindful of and implement client-side security measures to prevent CSRF attacks.</p>
<h2 id="heading-identifying-code-smells">Identifying Code Smells</h2>
<p>SSRF attacks often occur when web applications improperly mishandle user-controlled input, leading to network requests based on inadequately sanitized user input. Processing un-sanitized URLs in API requests is a common entry point for SSRF attacks.</p>
<p>Another common giveaway to identifying SSRF vulnerabilities in your applications is to check for instances where XML parsing occurs without adequate validation of external entities. Applications that fail to validate and secure their XML parsers properly may inadvertently expose themselves to SSRF risks.</p>
<p>In this walkthrough, you will make a server that takes a URL and uses it to make network requests without proper validation and sanitization. You will then see ways to mitigate this issue.</p>
<h2 id="heading-understanding-the-pain-points">Understanding the Pain Points</h2>
<p>To better understand the issue of SSRF attacks, lets create a sample application using Express and JavaScript. Below is a Mermaid Sequence Diagram where we explain what the code base does:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/12/image-169.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>UML Sequence Diagram for the sample application</em></p>
<p>We will create an Express app with two endpoints — <code>/fetch</code>, a <code>GET</code> request designed to fetch content from a specified URL, and <code>/admin</code>, another <code>GET</code> request, which is an internal API within the organization that accesses an internally protected resource.</p>
<p>We will discover a security vulnerability associated with Server-Side Request Forgery (SSRF) in implementing the first <code>GET</code> request.</p>
<p>We will also create another helper function at the <code>/uploads</code> endpoint to allow our clients to fetch and view their recently uploaded content.</p>
<h2 id="heading-project-setup">Project Setup</h2>
<p>To get started, let's quickly set up our repository and install all the required packages. In the root of your workspace, install Express and Axios using the following command:</p>
<pre><code class="lang-bash">npm init -y | npm i axios express
</code></pre>
<p>Executing this command will create a <code>package.json</code> file with default settings and install the specified packages.</p>
<p>To simulate the internal protected resource, let's create a <code>data.json</code> in the root of your workspace:</p>
<pre><code class="lang-json">{   
    <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Hamdaan Ali Quatil"</span>,
    <span class="hljs-attr">"password"</span>: <span class="hljs-string">"violinblackeye"</span>
}
</code></pre>
<p>Now, create a file called <code>app.js</code> in the root of your repository. Here, we will define all of our endpoints. Import all required packages like this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> axios = <span class="hljs-built_in">require</span>(<span class="hljs-string">'axios'</span>);
<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>).promises;
</code></pre>
<p>We use the <code>fs</code> (File System) module to interact with the local file system. Within the Express application, we use <code>fs.promises</code> to read the contents of a file. The <code>fetchPrivateResource</code> function asynchronously reads the contents of the <code>data.json</code> file, which is an internal resource.</p>
<p>Let's create an instance of the Express app to handle HTTP requests and define the <code>fetchPrivateResource</code> method. In the sample application, only the admin should be able to fetch this internal resource, but you will observe how a malicious actor can access this using an SSRF attack.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> app = express();
<span class="hljs-keyword">const</span> port = <span class="hljs-number">3000</span>;

<span class="hljs-comment">// Function to fetch private resource</span>
<span class="hljs-keyword">const</span> fetchPrivateResource = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> content = <span class="hljs-keyword">await</span> fs.readFile(<span class="hljs-string">'data.json'</span>, <span class="hljs-string">'utf-8'</span>);
    <span class="hljs-keyword">return</span> content;
  } <span class="hljs-keyword">catch</span> (error) {
    <span class="hljs-built_in">console</span>.error(<span class="hljs-string">'Error reading private resource:'</span>, error.message);
    <span class="hljs-keyword">throw</span> error;
  }
};
</code></pre>
<h3 id="heading-the-fetch-endpoint">The Fetch Endpoint</h3>
<p>Now, let's define our first endpoint, <code>/fetch</code> which expects a query parameter <code>url</code> containing the target URL. Upon receiving a request, the server uses the Axios library to make a GET request to the specified URL.</p>
<pre><code class="lang-js">app.get(<span class="hljs-string">"/fetch"</span>, <span class="hljs-keyword">async</span> (req, res) =&gt; {
  <span class="hljs-keyword">const</span> url = req.query.url;

  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> axios.get(url);
    <span class="hljs-keyword">const</span> responseData = <span class="hljs-built_in">JSON</span>.stringify(response.data);

    <span class="hljs-keyword">const</span> filename = path.basename(url);
    <span class="hljs-keyword">const</span> textFilePath = path.join(__dirname, <span class="hljs-string">"uploads"</span>, <span class="hljs-string">"upload-data.txt"</span>);

    <span class="hljs-keyword">await</span> fs.writeFile(textFilePath, responseData, <span class="hljs-string">"utf-8"</span>);

    res.send(<span class="hljs-string">"Upload Successful"</span>);
  } <span class="hljs-keyword">catch</span> (error) {
    <span class="hljs-built_in">console</span>.error(<span class="hljs-string">"Error:"</span>, error.message);
    res.status(<span class="hljs-number">500</span>).send(<span class="hljs-string">"Internal Server Error"</span>);
  }
});
</code></pre>
<p>The <code>axios.get</code> method is used to perform the HTTP GET request, and the response data is then converted to a JSON string. The resulting string is written to a text file named <code>upload-data.txt</code> in the <code>uploads</code> folder of the server. Finally, a success message or an error message is sent back to the client, depending on the outcome of the operation.</p>
<h3 id="heading-the-uploads-endpoint">The Uploads Endpoint</h3>
<p>With that done, let's create an endpoint to allow users to access and verify their uploaded files. The server will check if the requested file exists, and if so, it sends the file to the client. When a file cannot be found, the server returns a 404 error.</p>
<pre><code class="lang-js">app.get(<span class="hljs-string">"/uploads/:filename"</span>, <span class="hljs-keyword">async</span> (req, res) =&gt; {
  <span class="hljs-keyword">const</span> filename = req.params.filename;
  <span class="hljs-keyword">const</span> filePath = path.join(__dirname, <span class="hljs-string">"uploads"</span>, filename);
  <span class="hljs-built_in">console</span>.log(filePath);

  <span class="hljs-keyword">try</span> {
    <span class="hljs-comment">// Check if file exists</span>
    <span class="hljs-keyword">await</span> fs.access(filePath);

    <span class="hljs-comment">// If file exists, send it to the client</span>
    res.sendFile(filePath);

  } <span class="hljs-keyword">catch</span> (error) {
    res.status(<span class="hljs-number">404</span>).send(<span class="hljs-string">"File not found: "</span> + error);
  }
});
</code></pre>
<h3 id="heading-the-admin-endpoint">The Admin Endpoint</h3>
<p>Now, we need to make an internal API – the <code>/admin</code> route – which is intentionally shielded from public access. The objective is to ensure this API is only accessible from localhost or the local machine (127.0.0.1).</p>
<p>We can do this by implementing a middleware that acts as a protective barrier, permitting requests to proceed to the <code>/admin</code> route only if they originate from the local host.</p>
<p>The middleware checks whether the <code>req.hostname</code> property, which represents the hostname specified in the HTTP request, matches <code>localhost</code> or <code>127.0.0.1</code>. If the request is from a different host, the middleware responds with a <code>403</code> Forbidden status, thereby restricting access.</p>
<pre><code class="lang-js"><span class="hljs-comment">// middleware to protect admin API</span>
app.use(<span class="hljs-string">'/admin'</span>, <span class="hljs-keyword">async</span> (req, res, next) =&gt; {
  <span class="hljs-keyword">const</span> isLocalhost = req.hostname === <span class="hljs-string">'localhost'</span> || req.hostname === <span class="hljs-string">'127.0.0.1'</span>;

  <span class="hljs-keyword">if</span> (isLocalhost) {
    next();
  } <span class="hljs-keyword">else</span> {
    res.status(<span class="hljs-number">403</span>).send(<span class="hljs-string">'Forbidden'</span>);
  }
});

<span class="hljs-comment">// Route to access the admin API</span>
app.get(<span class="hljs-string">'/admin'</span>, <span class="hljs-keyword">async</span> (req, res) =&gt; {
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> content = <span class="hljs-keyword">await</span> fetchPrivateResource();
    res.send(content);
  } <span class="hljs-keyword">catch</span> (error) {
    res.status(<span class="hljs-number">500</span>).send(<span class="hljs-string">'Internal Server Error'</span>);
  }
});
</code></pre>
<p>Once all routes are configured, we start the server using the <code>app.listen</code> method, and it begins listening on port 3000 for incoming requests.</p>
<pre><code class="lang-js">app.listen(port, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Server is running on http://localhost:<span class="hljs-subst">${port}</span>`</span>);
});
</code></pre>
<p>With our <code>app.js</code> now set up to process incoming requests, let's run the sample application using <code>nodemon</code>:</p>
<pre><code class="lang-bash">npm i -D nodemon | nodemon app.js
</code></pre>
<p>The server has started on the port <code>3000</code>. Now, we are ready to test our sample application and look for code smells that may lead to SSRF attacks. You may find the complete code here — <a target="_blank" href="https://gist.github.com/HamdaanAliQuatil/c7db6f3dd0666bd9396a7f4e6ebe6665">GitHub Gist | HamdaanAliQuatil</a>.</p>
<h2 id="heading-how-to-exploit-the-vulnerability">How to Exploit the Vulnerability</h2>
<p>Let's try to make a <code>GET</code> request to the fetch API. We are simulating the process of uploading a text file using the URL to the file. In this demonstration, we will fetch the contents of an example file and save it on our servers. Here is the <a target="_blank" href="https://example-files.online-convert.com/document/txt/example.txt">link to the text file</a>.</p>
<p>Open your Postman Client and execute a <code>GET</code> request with the URL <code>http://localhost:3000/fetch?url=https://example-files.online-convert.com/document/txt/example.txt</code>. We are adding the link to the file as a Query Parameter in the <code>/fetch</code> endpoint. When you hit send, you will see a response <code>"Upload Successful"</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/image-3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Postman Client: Fetch Endpoint</em></p>
<p>You'll see that your repository now has a newly created file in the <code>uploads</code> directory. Clients can now access their uploaded information using the <code>/uploads</code> API endpoint to view their files.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/image-4.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Postman Client: Uploads Endpoint</em></p>
<p>Now, let's send a malicious request by changing our Query param to <code>http://120.0.07/admin</code> in the same request to the <code>/fetch</code> endpoint. The updated URL will now look like this: <code>http://localhost:3000/fetch?url=http://127.0.0.1:3000/admin</code>.</p>
<p>In the Query parameter, <code>127.0.0.1</code> is a Loopback Address. A loopback address is a reserved IP address used to establish network connections with the same host (the local machine) for testing and communication within the device.</p>
<p>The malicious actor is attempting is to make a request to the server's <code>/admin</code> route from the server itself using the loopback address. This simulates an internal resource access scenario.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/image-5.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Postman Client: Admin Endpoint</em></p>
<p>You'll notice that an <code>"Upload Successful"</code> message comes as a response to this request. Now try accessing your uploaded file again using the <code>GET</code> request at the <code>/upload</code> endpoint.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/01/image-6.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Postman Client: Uploads Endpoint</em></p>
<p>You'll see that the contents of the uploaded file have been altered. This alteration highlights a successful SSRF (Server-Side Request Forgery) attack, where a malicious actor took advantage of the server's capability to initiate internal requests.</p>
<p>The file, which initially contained specific data, has now been tampered with. This showcases the potential for unauthorized access and manipulation of sensitive information through SSRF exploits.</p>
<h2 id="heading-how-to-defend-against-ssrf-attacks">How to Defend Against SSRF Attacks</h2>
<p>Now, let’s see the ways in which we can fix our application's vulnerability to SSRF. The most intuitive solution that comes to your mind could be to never allow a client to enter a URL. This is certainly the most powerful defense. The server should create a URL it needs.</p>
<p>But many times, allowing URLs in your business logic becomes an absolute necessity. In such cases, our goal is to prevent the attack or at least reduce the risk if an attack occurs.</p>
<p>If you really must allow a URL as it is, here are some precautionary steps you can take:</p>
<h3 id="heading-sanitization-and-validation">Sanitization and Validation</h3>
<p>As with most vulnerabilities, a pain-point in SSRF attacks is the use of untrusted data. Always treat any data coming from the client side as untrusted.</p>
<p>Sanitizing and validating the client-supplied data should go a long way to defend against SSRF attacks. A very intuitive validation is to restrict any URL containing localhost or the loopback address.</p>
<p>Let's create a helper function <code>isValidUrl</code> and call it in the function for the <code>/fetch</code> endpoint.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isValidUrl</span>(<span class="hljs-params">url</span>) </span>{
  <span class="hljs-comment">// Restrict URLs to HTTP only. This blocks FTP and other protocols</span>
  <span class="hljs-keyword">const</span> validUrlRegex = <span class="hljs-regexp">/^http:\/\/\S+$/</span>;

  <span class="hljs-keyword">if</span> (!validUrlRegex.test(url)) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }

  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> parsedUrl = <span class="hljs-keyword">new</span> URL(url);

    <span class="hljs-comment">// Check if the host is localhost or a loopback IP address</span>
    <span class="hljs-keyword">const</span> isLocalhost = parsedUrl.hostname === <span class="hljs-string">'localhost'</span>;
    <span class="hljs-keyword">const</span> isLocalIP = <span class="hljs-regexp">/^127\.\d+\.\d+\.\d+$/g</span>.test(parsedUrl.hostname);

    <span class="hljs-keyword">return</span> !(isLocalhost || isLocalIP);
  } <span class="hljs-keyword">catch</span> (error) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }
}
</code></pre>
<p>Your updated function for <code>/fetch</code> endpoint should look like this:</p>
<pre><code class="lang-js">app.get(<span class="hljs-string">"/fetch"</span>, <span class="hljs-keyword">async</span> (req, res) =&gt; {
  <span class="hljs-keyword">const</span> url = req.query.url;

  <span class="hljs-keyword">if</span> (!isValidUrl(url)) {
    res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">"Loopback URLs are not allowed"</span>);
    <span class="hljs-keyword">return</span>;
  }

  <span class="hljs-keyword">try</span> {
    ...
    res.send(<span class="hljs-string">"Upload Successful"</span>);
  } <span class="hljs-keyword">catch</span> (error) {
    ...
  }
});
</code></pre>
<p>Now, go back to the Postman Client and resend the malicious request. You will observe that previously uploaded file is not tampered and you receive <code>"Loopback URLs are not allowed"</code> in the response.</p>
<h3 id="heading-whitelisting-via-an-allow-list">Whitelisting via an Allow List</h3>
<p>You may create a positive allow list to only allow certain trusted IP Addresses, URL Schema, and Port. Let's implement an allow list and improve our <code>isValidUrl</code> function:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> whitelist = [<span class="hljs-string">"boost.com"</span>, <span class="hljs-string">"boost.in"</span>, <span class="hljs-string">"trustedDomain3.com"</span>];
<span class="hljs-keyword">const</span> allowedPorts = [<span class="hljs-string">'80'</span>, <span class="hljs-string">'443'</span>];
</code></pre>
<p>Now use your declared <code>whitelist</code> in the <code>isValidUrl</code> function:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isValidUrl</span>(<span class="hljs-params">url</span>) </span>{
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> parsedUrl = <span class="hljs-keyword">new</span> URL(url);

    <span class="hljs-keyword">if</span> (!whitelist.includes(parsedUrl.hostname)) {
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">if</span> (!allowedPorts.includes(parsedUrl.port)) {
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  } <span class="hljs-keyword">catch</span> (error) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }
}
</code></pre>
<p>Notice how we've removed the need for regex. This brings us to another mitigation technique that you must avoid:</p>
<h3 id="heading-dont-use-a-deny-list">Don't Use a Deny List</h3>
<p>You must never mitigate SSRF vulnerabilities using a deny list or regex. Restricting the use of IP Addresses is not straightforward. To understand why we must avoid a deny list, look at the following example.</p>
<p>A Loopback Address is typically represented using <code>127.0.0.1</code> . Its quite easy to spot this address and reject it. But a problem arises when a malicious request is sent using any other forms of this Loopback address that also points to the local machine. For example, <code>127.1</code>, <code>::1</code>, <code>localhost</code> ,<code>::ffff:7f00:1</code> all point to the local machine.</p>
<p>A regular expression to spot all such variations is much more complex. Malicious actors can easily bypass a deny list by passing an octal representation of decimal encoding of the IP address.</p>
<h3 id="heading-enforce-a-url-scheme">Enforce a URL Scheme</h3>
<p>In absence of this measure, a client might send requests that use any protocols other than the intended ones. To replace our <code>validUrlRegex</code>, we will use a <code>allowedSchemes</code> list. We will restrict our application to only process requests when the protocols are either <code>https:</code> or <code>http</code>. Not allowing any requests with protocols <code>file:</code> and <code>ftp:</code> will safe-guard our sample application.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> allowedSchemes = [<span class="hljs-string">'http:'</span>, <span class="hljs-string">'https:'</span>];
</code></pre>
<p>The updated <code>isValidUrl</code> function will look like this:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isValidUrl</span>(<span class="hljs-params">url</span>) </span>{
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> parsedUrl = <span class="hljs-keyword">new</span> URL(url);

    <span class="hljs-keyword">if</span> (!whitelist.includes(parsedUrl.hostname)) {
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">if</span> (!allowedPorts.includes(parsedUrl.port)) {
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">if</span> (!allowedSchemes.includes(parsedUrl.protocol)) {
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  } <span class="hljs-keyword">catch</span> (error) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }
}
</code></pre>
<h3 id="heading-disable-redirects">Disable Redirects</h3>
<p>Redirects are a mechanism used by web applications to forward a user's browser from one URL to another. If a server follows redirects automatically, an attacker could exploit this behavior to make the server inadvertently access internal resources, leading to data exposure or unauthorized actions.</p>
<p>To restrict redirects in Axios, pass in an Axios Configuration object in the second parameter:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> axios.get(url, { <span class="hljs-attr">maxRedirects</span>: <span class="hljs-number">0</span> });
</code></pre>
<p>To learn more about Axios Config, check this guide: <a target="_blank" href="https://axios-http.com/docs/req_config">Axios | Request Config</a>.</p>
<h3 id="heading-send-filtered-data-to-the-client">Send Filtered Data to the Client</h3>
<p>Avoid sending raw response bodies directly from your server to the client. Ensure that the responses reaching the client are carefully curated and conform to expected formats.</p>
<p>By implementing this practice, you shield your application from potential security vulnerabilities associated with exposing unfiltered or sensitive information. Always validate, filter, and format responses to align with your application's anticipated data structures.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>And there you have it: by implementing a few well-established methodologies and best practices, you can effectively detect and mitigate SSRF attacks in your applications and create secure APIs as developers.</p>
<p>Find the complete code snippets here — <a target="_blank" href="https://gist.github.com/HamdaanAliQuatil/c7db6f3dd0666bd9396a7f4e6ebe6665">GitHub Gist | HamdaanAliQuatil</a>.<br>You may find me on X (formerly Twitter) - <a target="_blank" href="https://twitter.com/violinblackeye">Hamdaan Ali Quatil</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Cybersecurity Forensics? The Art of Being a Digital Detective ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever wondered how experts catch cybercriminals and solve digital mysteries? Well, in this article, you'll learn about the fascinating techniques that help investigators unravel online crimes and protect our privacy. In today’s digital world,... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-cybersecurity-forensics/</link>
                <guid isPermaLink="false">66d0362eec0a2e1087e8242f</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Mon, 04 Sep 2023 05:20:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/09/cyber-forensics.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever wondered how experts catch cybercriminals and solve digital mysteries? Well, in this article, you'll learn about the fascinating techniques that help investigators unravel online crimes and protect our privacy.</p>
<p>In today’s digital world, where we rely on computers, smartphones, and the internet for almost everything, the importance of cybersecurity cannot be overstated. </p>
<p>While you might be familiar with the term “cyberattack,” there’s a lesser-known but equally crucial field that operates in the shadows — cybersecurity forensics. This is where the art and science of investigating digital crimes and breaches come into play.</p>
<h2 id="heading-what-is-cybersecurity-forensics">What is Cybersecurity Forensics?</h2>
<p>Cybersecurity forensics, in simple terms, is like being a digital detective. It involves the careful and systematic process of collecting, analyzing, and preserving digital evidence to uncover what happened in a cybercrime or security breach.</p>
<p>Imagine a digital crime scene where there are no physical fingerprints or footprints. Instead, there are digital footprints left behind on computers, smartphones, servers, and networks.</p>
<p>These footprints can be tricky to spot, but they are crucial in solving digital mysteries.</p>
<h2 id="heading-types-of-digital-evidence">Types of Digital Evidence</h2>
<p>Digital evidence comes in various forms, much like pieces of a puzzle. It includes things like compromised passwords, malware artefacts and network logs. </p>
<h3 id="heading-compromised-passwords">Compromised Passwords</h3>
<p>When an unauthorized individual attempts to gain access to your account by guessing your password or through hacking techniques, it is known as a compromised password. Such attempts often leave behind evidence that can be scrutinized for increased security. </p>
<p>It includes multiple failed login attempts from unfamiliar locations or devices, changes made to the account settings, or even unauthorized transactions. </p>
<p>By looking for these signs, you can take immediate action, such as updating your password or enabling two-factor authentication, to secure your account and minimize potential damage.</p>
<h3 id="heading-malware-artifacts">Malware Artifacts</h3>
<p>Malware, including viruses and malicious software, pose a significant risk to your computer system. </p>
<p>When a system is infected, malware often leaves behind traces known as artifacts. These artifacts include unusual files, changes in system settings, or the installation of new, unfamiliar software. </p>
<p>Recognizing these artifacts is important for removing the existing malware and improving the system's defence against future attacks. Specialized software tools can help identify and eliminate these threats, and help restore the system to a secure state.</p>
<h3 id="heading-network-logs">Network Logs</h3>
<p>Networks, whether they belong to an organization or an individual, maintain logs that record various activities occurring on the network. </p>
<p>These logs help in identifying suspicious activities, such as multiple login attempts from foreign IP addresses, the transfer of unusually large amounts of data, or unauthorized attempts to access private areas of the network. </p>
<p>By regularly reviewing and monitoring network logs, you can spot anomalies and take preemptive measures to counter any potential security threats.</p>
<p>The tricky part about digital evidence is that it can be easily tampered with or deleted, just like erasing a message from your phone. Preserving the integrity of this evidence is a top priority in cybersecurity forensics.</p>
<h2 id="heading-the-digital-detectives-toolkit">The Digital Detective’s Toolkit</h2>
<p>To solve digital mysteries, cybersecurity forensic experts use a range of tools and techniques.</p>
<h3 id="heading-forensic-software">Forensic Software</h3>
<p>In cybersecurity forensics, specialized software plays an important role in collecting and analyzing digital evidence. The use of such software helps to acquire and analyze data without causing any alterations.</p>
<p>This is crucial for maintaining the integrity of an investigation, especially if the findings are to be used in legal proceedings. By using forensic software, experts can carry out complex tasks such as data recovery, malware analysis, and encrypted file examinations.</p>
<h3 id="heading-data-acquisition">Data Acquisition</h3>
<p>Data acquisition involves creating an exact copy of the digital data in question. The importance of this process is its ability to preserve the integrity of the original data while providing investigators with a duplicate set for analysis. </p>
<p>This ensures that the original evidence remains untouched, thereby maintaining its credibility and usability in legal contexts. Methods like <a target="_blank" href="https://www.cardwave.com/knowledge-hub/why-we-use-bit-by-bit-duplication/">bit-by-bit</a> copying are used to make sure that the duplicate is an exact replica, capturing not just files but also hidden or deleted information. It provides a comprehensive dataset for investigators to analyze while keeping the original data intact.</p>
<h3 id="heading-chain-of-custody">Chain of Custody</h3>
<p>The concept of the chain of custody is equally important in cybersecurity investigations as it is in traditional detective work. It serves as a systematic documentation process that tracks how evidence is collected, stored, transferred, and eventually presented in court or other official settings.</p>
<p>Every individual who interacts with the evidence is identified, and their actions are carefully documented to prevent tampering or mishandling. This careful management ensures that the evidence remains reliable. </p>
<p>Maintaining an unbroken chain of custody is critical for upholding the integrity of the investigation and making sure that its findings are both credible and actionable.</p>
<h2 id="heading-the-investigative-process">The Investigative Process</h2>
<p>Cybersecurity forensics investigations follow a structured process, just like detective work in the physical world. Here are the key steps:</p>
<ul>
<li><strong>Data Collection:</strong> Experts collect digital evidence from various sources, such as computers, smartphones, or servers.</li>
<li><strong>Data Analysis:</strong> The collected evidence is carefully examined to understand what happened and who might be responsible.</li>
<li><strong>Reporting:</strong> Findings are documented in detailed reports, which can be used in legal proceedings if necessary.</li>
<li><strong>Presentation:</strong> Experts may need to present their findings to explain what they’ve discovered and how they reached their conclusions.</li>
<li><strong>Legal Considerations:</strong> Throughout the process, legal rules and standards must be followed to ensure the evidence is admissible in court.</li>
</ul>
<h2 id="heading-the-future-of-cybersecurity-forensics"><strong>The Future of Cybersecurity Forensics</strong></h2>
<p>The world of cybersecurity is constantly evolving, and so is the field of cybersecurity forensics. Here are some trends and challenges.</p>
<h3 id="heading-ai-and-machine-learning">AI and Machine Learning</h3>
<p>Artificial Intelligence (AI) and Machine Learning technologies are increasingly becoming valuable tools in the field of cybersecurity. They allow for the rapid detection and analysis of cyber threats, making it easier to identify vulnerabilities or potential attacks much faster than traditional methods. </p>
<p>By using algorithms that can learn from data, these technologies adapt and evolve, becoming more effective over time at identifying normal network behaviour from potentially harmful anomalies.</p>
<p>This heightened capacity for quick and accurate threat detection saves valuable time and resources, thus strengthening overall cybersecurity measures.</p>
<h3 id="heading-encryption-challenges">Encryption Challenges</h3>
<p>As encryption technologies advance, they offer stronger protection for data, making it difficult for unauthorized users to access sensitive information. </p>
<p>This also presents challenges in cybersecurity forensics. Strong encryption can act as a barrier that makes it difficult for experts to uncover digital evidence during their investigations. </p>
<p>For example, if data is encrypted to a high standard, it could prevent the timely identification of malware or other cybersecurity threats. While encryption is essential for securing data, it also creates the need for more advanced tools and methodologies for cybersecurity professionals to penetrate these 'walls' and access the information they need to maintain security.</p>
<h3 id="heading-emerging-cyber-threats">Emerging Cyber Threats</h3>
<p>The cybersecurity landscape is continually evolving, with new types of threats appearing on a regular basis. This constant emergence of new threats presents a challenge for cybersecurity forensics experts, requiring them to stay updated and adapt their skills and tools continually. </p>
<p>From ransomware attacks that lock users out of their own systems to increasingly complicated phishing scams, these threats necessitate ongoing education and vigilance. By staying one step ahead, cybersecurity professionals can develop proactive measures and response strategies to neutralize these threats before they can inflict significant damage.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In a world where our lives have become increasingly digital, the work of cybersecurity forensics experts is more crucial than ever. They are the digital detectives who tirelessly investigate cybercrimes and breaches, ensuring that justice is served in the complex and rapidly changing world of cyberspace. </p>
<p>The art and science of cybersecurity forensics is essential in safeguarding our online lives and maintaining the trust and security of the digital realm.</p>
<p>If you found this article useful, visit <a target="_blank" href="https://blog.stealthsecurity.io/">Stealth Security</a> to read more articles on ethical hacking. You can also <a target="_blank" href="https://www.linkedin.com/in/manishmshiva/">connect with me on LinkedIn</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Web Security in Django – How to Build a Secure Web Application ]]>
                </title>
                <description>
                    <![CDATA[ By Jacob Isah  Web security is an important aspect of the web application development process. Especially as more data is stored, managed, and shared.  As a web developer, it's essential to prioritize security measures to protect your company’s users... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-secure-django-web-app/</link>
                <guid isPermaLink="false">66d45f3347a8245f78752a4a</guid>
                
                    <category>
                        <![CDATA[ Django ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 31 Aug 2023 18:52:53 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/08/Web-Security-in-Django---How-to-Build-a-Secure-Web-Application.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Jacob Isah </p>
<p>Web security is an important aspect of the web application development process. Especially as more data is stored, managed, and shared. </p>
<p>As a web developer, it's essential to prioritize security measures to protect your company’s users and data from potential threats.   </p>
<p>In this article, I will demonstrate web security best practices by building a secure web application using Django, a powerful Python web framework. I'll cover password hashing, secure session management, authentication, authorization, and other key security considerations with accompanying code examples.  </p>
<p>Before continuing with this article, keep in mind that this isn't intended for absolute beginners. You should have a good understanding of Python to get the most out of this guide. </p>
<p>If you need to brush up on your basic programming skills in Python and Django before continuing, here are a couple resources to help you out:</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/python-for-everybody/">Python for Everybody</a> from Dr. Chuck</li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/django-for-everybody-learn-the-popular-python-framework-from-dr-chuck/">Django for Everybody</a>, also from Dr. Chuck</li>
</ul>
<p>You will get access to the code at the end of the article.</p>
<h2 id="heading-set-up-your-file-structure">Set Up Your File Structure</h2>
<p>Let's say that we want to store our project on the desktop. The first thing do is to set up our file structure. Let's start by creating a root directory for our project on the desktop (<code>WebSec</code> in this case).</p>
<pre><code class="lang-python">mkdir WebSec
cd WebSec
</code></pre>
<h3 id="heading-create-a-virtual-environment-and-activate-it">Create a Virtual Environment and Activate It</h3>
<p>On Linux (Ubuntu):</p>
<pre><code class="lang-python">python3 -m venv my_env

Source my_env/bin/activate
</code></pre>
<p>And on Windows:</p>
<pre><code class="lang-python">python -m venv my_env

my_env\Scripts\activate.bat
</code></pre>
<h2 id="heading-how-to-create-the-django-project">How to Create the Django Project</h2>
<p>First, if you don't already have it, you'll need to install Django using the following command:</p>
<pre><code class="lang-python">python -m pip install Django
</code></pre>
<p>Then you can use this command to create the project:</p>
<pre><code class="lang-python">django-admin startproject web_sec_project .
</code></pre>
<p>And finally, use this command to create the app:</p>
<pre><code class="lang-python">django-admin startapp web_sec_app
</code></pre>
<p>Your file structure should look like this at the end:</p>
<pre><code class="lang-python">WebSec
    my_env/
    web_sec_app/
        __pycache__/
        migrations/
        templates/
        admin.py
        apps.py
        forms.py
        models.py
        tests.py
        urls.py
        views.py
    web_sec_project/
        __pycache__/
        __init__.py
        asgi.py
        settings.py
        urls.py
        wsgi.py
    db.sqlite3
    manage.py
</code></pre>
<h3 id="heading-run-your-server">Run Your Server</h3>
<p>On your IDE terminal run the following command and test if your project is working. If so, you are good to go.</p>
<pre><code class="lang-python">python manage.py runserver
</code></pre>
<p>Ensure that you add your app to your project:</p>
<p><img src="https://lh4.googleusercontent.com/5KMFSFkkzM4T-YPujI0_9tm6FdnoTQRfJ8FbfVAZfChJfnkLRjvOSnyfq3PzIiLLWr-h-r5_mw9OOk55yJtXJ4OOjhu0wIwKiTiX5T_-7TN-oHt4elagFQ_st3mAxFHU-bWlR3JCcpcdn6b1BGgVSg" alt="Image" width="600" height="400" loading="lazy">
<em>Check that your app is added</em></p>
<p>Now let’s start building and implementing web security.</p>
<h2 id="heading-password-hashing">Password Hashing</h2>
<p>The first line of defense when implementing web security is ensuring that user passwords are properly protected. And instead of storing passwords in plaintext, it's a good idea to hash them. We'll use cryptographic hashing to safeguard sensitive user information. </p>
<p>Cryptographic hashing, also known as hash functions or hash algorithms, is a fundamental concept in cryptography and computer security. It involves taking an input (or "message") and transforming it into a fixed-size string of characters, which is typically a sequence of numbers and letters. This output is called the "hash value" or "hash code."</p>
<p>Django provides a secure password hashing mechanism by default, using the <strong>PBKDF2</strong> algorithm with a <strong>SHA-256</strong> hash. </p>
<p>Django uses a robust and secure password hashing mechanism to protect user passwords. This mechanism helps ensure that even if the database is compromised, attackers cannot easily retrieve users' plaintext passwords. Django's password hashing mechanism consists of <strong>PBKDF2.</strong></p>
<p><strong>PBKDF2</strong> is a simple cryptographic key derivation function that is resistant to <a target="_blank" href="https://en.wikipedia.org/wiki/Dictionary_attack">dictionary attacks</a> and <a target="_blank" href="https://en.wikipedia.org/wiki/Rainbow_table">rainbow table attacks</a>. It is based on iteratively deriving <strong>HMAC</strong> many times with some padding. This ensures that even if the database is compromised, the passwords remain unreadable.</p>
<p>To demonstrate this, we are going to create a new user with a hashed password and save the user with their hashed password in the database.</p>
<p>First, we import the <code>User</code>  from the User model. Then, we import <code>make_password</code>. Here's the code to do that:</p>
<pre><code class="lang-python"><span class="hljs-comment">#web_sec_app/views.py</span>

<span class="hljs-keyword">from</span> django.contrib.auth.hashers <span class="hljs-keyword">import</span> make_password
<span class="hljs-keyword">from</span> django.contrib.auth.models <span class="hljs-keyword">import</span> User

<span class="hljs-comment"># Create User views here.</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">UserView</span>(<span class="hljs-params">request</span>):</span>
    users = User.objects.all()
    password = <span class="hljs-string">'password'</span>
    hashed_password = make_password(password)
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'create_user.html'</span>, 
                {<span class="hljs-string">'users'</span>: users, <span class="hljs-string">'hashed_password'</span>: hashed_password})
</code></pre>
<h2 id="heading-secure-session-management">Secure Session Management</h2>
<p>Session management is key to maintaining user state across multiple requests. Django comes with a built-in session management system that stores session data on the server-side. We'll ensure that the session data is encrypted and the session ID is secure to prevent session hijacking attacks.</p>
<p>To achieve secure session management, we will make sure we have a secure session cookie, which will require HTTPS. We are also going to prevent <code>JavaScript</code> access to the session cookie. The session expires when the browser is closed.</p>
<pre><code class="lang-python">SESSION_COOKIE_SECURE = <span class="hljs-literal">True</span>
</code></pre>
<p>This setting tells Django to only send the session cookie over HTTPS connections. When set to <code>True</code>, the session cookie will not be sent over unencrypted HTTP connections. This is important for protecting sensitive session data, such as user authentication tokens, from being intercepted by malicious actors on insecure networks.</p>
<pre><code class="lang-python">SESSION_COOKIE_HTTPONLY = <span class="hljs-literal">True</span>
</code></pre>
<p>Setting <code>SESSION_COOKIE_HTTPONLY</code> to <code>True</code> adds an extra layer of security. When this is enabled, the session cookie cannot be accessed by JavaScript code running on the client's browser. This helps mitigate certain types of cross-site scripting (XSS) attacks, where an attacker tries to steal session data using malicious scripts.</p>
<pre><code class="lang-python">SESSION_EXPIRE_AT_BROWSER_CLOSE = <span class="hljs-literal">True</span>
</code></pre>
<p>When <code>SESSION_EXPIRE_AT_BROWSER_CLOSE</code> is set to <code>True</code>, the session will expire and be deleted once the user closes their web browser. This provides a mechanism for creating short-lived sessions that automatically end when the user finishes their browsing session. It's useful for scenarios where you want to ensure that users are logged out when they close their browser, enhancing security for shared or public computers.</p>
<p>Your <code>settings.py</code> file should contain the following:</p>
<pre><code class="lang-python">SESSION_COOKIE_SECURE = <span class="hljs-literal">True</span> 
SESSION_COOKIE_HTTPONLY = <span class="hljs-literal">True</span>
SESSION_EXPIRE_AT_BROWSER_CLOSE = <span class="hljs-literal">True</span>
</code></pre>
<h2 id="heading-authentication-and-authorization">Authentication and Authorization</h2>
<p>Proper authentication and authorization procedures are important for limiting access to certain parts of the web application.</p>
<p>In this section, I'll demonstrate how to implement user login and authentication using Django's authentication framework. I'll also define access control based on user roles to ensure that only authorized users can access certain views and features.</p>
<pre><code class="lang-python"><span class="hljs-meta">@user_passes_test(lambda u: u.is_superuser)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">admin</span>(<span class="hljs-params">request</span>):</span>
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'admin.html'</span>, {<span class="hljs-string">'username'</span>: request.user.username})
</code></pre>
<p>The code above is used to restrict access to the admin view based on whether the user is a superuser (admin) or not. </p>
<p>If the user is a superuser, they are allowed to access the view, and the template <code>admin.html</code> is rendered with their username displayed. If the user is not a superuser, they will be redirected to a default unauthorized view, unless additional handling is implemented. </p>
<p>This ensures that only authorized users with admin privileges can access the 'admin.html' page.</p>
<h2 id="heading-cross-site-scripting-xss-protection">Cross-Site Scripting (XSS) Protection</h2>
<p>Cross-Site Scripting (XSS) is a common vulnerability that allows hackers to inject malicious scripts into web pages viewed by other users. </p>
<p>In this section, we'll explore how to implement Content Security Policy (CSP) headers to prevent unauthorized script execution and protect our application against XSS attacks.</p>
<p>CSP headers work by creating a set of rules that define which content sources are allowed and which are blocked. This significantly reduces the attack surface for XSS vulnerabilities, making it much harder for attackers to execute unauthorized scripts on your application. </p>
<p>It's important to carefully configure CSP policies to strike a balance between security and functionality, as overly restrictive policies could potentially break legitimate functionality in your application.</p>
<pre><code class="lang-python">CSP_DEFAULT_SRC = (<span class="hljs-string">"'self'"</span>,)
</code></pre>
<h2 id="heading-cross-site-request-forgery-csrf-protection">Cross-Site Request Forgery (CSRF) Protection</h2>
<p>CSRF attacks occur when malicious websites trick users into taking unauthorized actions on other sites where they are authenticated. Django offers built-in protection against CSRF attacks using CSRF tokens.</p>
<p>It is one of the most common methods used for preventing CSRF attacks using CSRF tokens. </p>
<p>When a user loads a web page that requires user interaction, the server generates a unique token and includes it in the form or the request data. This token is typically associated with the user's session. When the user submits the form or initiates an action, the server checks if the submitted token matches the one associated with the user's session. If they don't match, the request is rejected, as it might be an attempt to perform a CSRF attack. </p>
<p>I'll show you how to include these tokens in forms to prevent unauthorized requests.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>Create Account<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"{% url 'create_user' %}"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"post"</span>&gt;</span>
   {% csrf_token %}
   <span class="hljs-tag">&lt;<span class="hljs-name">input</span> 
      <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> 
      <span class="hljs-attr">id</span>=<span class="hljs-string">"userName"</span> 
      <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span>
      <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control input-sm chat-input"</span> 
      <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"username"</span> 
    /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<h2 id="heading-sql-injection-prevention">SQL Injection Prevention</h2>
<p>SQL injection is a serious vulnerability that occurs when attackers manipulate user inputs to execute malicious SQL queries on the database. I'll demonstrate how Django's ORM (Object-Relational Mapping) automatically sanitizes user inputs and protects against SQL injection attacks.</p>
<p>It is important to note that even though Django's ORM offers robust defense against the majority of SQL injection attacks, developers must still adhere to best security practices, such as input validation and authorization checks, to guarantee the overall security of their web applications. </p>
<p>It's also a good idea to update Django and its dependencies frequently to take advantage of any security updates or other improvements that may be released in the future.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">search</span>(<span class="hljs-params">request</span>):</span>
    query = request.GET.get(<span class="hljs-string">'q'</span>)
    <span class="hljs-keyword">if</span> query <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
        results = Search.objects.filter(Q(name__icontains=query) | Q(description__icontains=query))
    <span class="hljs-keyword">else</span>:
        results = []
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'search.html'</span>, {<span class="hljs-string">'results'</span>: results})
</code></pre>
<p>The code above defines a Django view function that handles search functionality by extracting a query from the request's <code>GET</code> parameters, using that query to perform a search in the Search model using the Django ORM's filter method, and then rendering a template with the search results. </p>
<p>The search is performed based on the '<strong>name</strong>' and '<strong>description</strong>' fields of the model, and the results are case-insensitive partial matches.</p>
<p>By relying on Django's ORM and its built-in features, you're leveraging a higher level of abstraction that inherently helps prevent common SQL injection vulnerabilities. </p>
<p>This code's structure and usage patterns align with best practices for writing secure queries in Django, making it less susceptible to SQL injection attacks. But it's still important to ensure that the rest of your codebase follows security best practices and that you keep your Django version and dependencies up to date to benefit from the latest security patches.</p>
<h2 id="heading-file-upload-security">File Upload Security</h2>
<p>Handling file uploads requires special attention to prevent attackers from uploading malicious files. We'll see how to validate and restrict file uploads to ensure the security of our web application.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">upload_file</span>(<span class="hljs-params">request</span>):</span>
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">'POST'</span>:
        uploaded_file = request.FILES.get(<span class="hljs-string">'file'</span>)
        <span class="hljs-keyword">if</span> uploaded_file:
            <span class="hljs-keyword">if</span> uploaded_file.content_type <span class="hljs-keyword">in</span> ALLOWED_FILE_EXTENSIONS:
                <span class="hljs-keyword">try</span>:
                    <span class="hljs-keyword">with</span> open(<span class="hljs-string">'uploads/'</span> + uploaded_file.name, <span class="hljs-string">'wb+'</span>) <span class="hljs-keyword">as</span> destination:
                        <span class="hljs-keyword">for</span> chunk <span class="hljs-keyword">in</span> uploaded_file.chunks():
                            destination.write(chunk)
                    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'success.html'</span>)
                <span class="hljs-keyword">except</span> ValidationError <span class="hljs-keyword">as</span> e:
                    error_message = str(e)
                    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'fileUpload.html'</span>, {<span class="hljs-string">'error_message'</span>: error_message})
            <span class="hljs-keyword">else</span>:
                error_message = <span class="hljs-string">"Invalid file type."</span>
                <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'fileUpload.html'</span>, {<span class="hljs-string">'error_message'</span>: error_message})
        <span class="hljs-keyword">else</span>:
            error_message = <span class="hljs-string">"No file selected."</span>
            <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'fileUpload.html'</span>, {<span class="hljs-string">'error_message'</span>: error_message})
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'fileUpload.html'</span>)
</code></pre>
<p>The code snippet above defines a function called <code>upload_file</code> This function takes a request object as its argument and handles file uploads.</p>
<p>The function first checks if the request method is <code>POST</code>. If it is, then the function gets the file uploaded by the user using the <code>request.FILES.get('file')</code> method.</p>
<p>If the file is not empty, then the function checks if the file extension is in the <code>ALLOWED_FILE_EXTENSIONS</code> list. This list contains the file types that are allowed to be uploaded. If the file extension is not in the list, then the function displays an error message.</p>
<p>If the file extension is in the list, then the function tries to save the file to a directory called <code>uploads</code>. function uses the <code>with open()</code> statement to open the file in binary write mode. The file is then saved in chunks using the <code>for chunk in file.chunks()</code> loop.</p>
<p>If the file is saved successfully, then the function redirects the user to a success page. Otherwise, an error message is displayed.</p>
<p>The <code>ALLOWED_FILE_EXTENSIONS</code> list is a security measure that prevents users from uploading malicious files, such as executables or scripts. The maximum file size limit is another security measure that prevents users from uploading large files that could cause a denial-of-service attack. Storing the uploaded file in a separate directory isolates the file from the rest of the application and makes it more difficult for attackers to access it.</p>
<h2 id="heading-wrapping-up">Wrapping-up</h2>
<p>Building a secure web application is a continuous process that requires vigilance and implementing best practices. </p>
<p>In this article, I demonstrated various web security measures with code examples while building a web application using Django. </p>
<p>By implementing password hashing, secure session management, authentication, authorization, and protection against common web vulnerabilities like XSS and CSRF, I've taken important steps towards creating a robust and secure web application. </p>
<p>But web security is a vast and ever-evolving field, and it's crucial to stay updated with the latest security trends and practices to ensure your web application remains safe from potential threats. Always perform thorough security testing and regularly update your application and libraries to maintain a strong defense against potential attacks. </p>
<p>With the right security measures in place, you can confidently provide your users with a safe and secure web experience.</p>
<p>You can have access to the code <a target="_blank" href="https://github.com/Enecode/secure-web-application.git">here</a>. Thanks for reading!  </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Photo Encryption App using Steganography ]]>
                </title>
                <description>
                    <![CDATA[ In this digital age, data flows freely across networks and devices. So protecting sensitive information from unauthorized access is crucial. That's where encryption comes in.  Encryption involves converting plain, readable data into an incomprehensib... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-a-photo-encryption-app/</link>
                <guid isPermaLink="false">66c5a25d3d77fae9eb82a46c</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Houssein Badra ]]>
                </dc:creator>
                <pubDate>Wed, 23 Aug 2023 21:06:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--122-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this digital age, data flows freely across networks and devices. So protecting sensitive information from unauthorized access is crucial. That's where encryption comes in. </p>
<p>Encryption involves converting plain, readable data into an incomprehensible form. It's also essential to have a way to convert the data back into a readable form – otherwise the whole process makes no sense and isn't useful.</p>
<p>There are various popular encryption algorithms, each with its strengths and weaknesses. Understanding how these algorithms work is essential for programmers, as they need to choose the most appropriate one for their applications. </p>
<p>In this article, we will be build an application where users can encrypt images, and also revert the process using HTML, CSS, and JavaScript. </p>
<p>You will learn about working with images and how to encrypt them. The approach we will be using involves hiding one image inside another one, which is called <strong>Steganography.</strong> You will also practice some basic web development skills. It will be fun for sure!</p>
<h3 id="heading-heres-what-well-cover">Here's what we'll cover:</h3>
<ul>
<li>How images are represented on your computer</li>
<li>How to create the encryption algorithm </li>
<li>How to create the decryption algorithm</li>
<li>Photo encryption app code</li>
</ul>
<h2 id="heading-how-images-are-represented-on-your-computer">How Images Are Represented on Your Computer</h2>
<p>Understanding the way images are stored is critical before diving into encrypting them. </p>
<p>Images are represented on computers using a combination of pixels. A pixel is the smallest unit of an image and serves as the building block for displaying visuals on digital screens. </p>
<p>In memory, an image is an array of pixels. But now you're probably wondering, what is a pixel?</p>
<p>A pixel is assigned a specific color value which determines its appearance. The color values are typically represented using a combination of three primary colors: red, green, and blue – commonly known as RGB. </p>
<p>Each color channel is represented by a number value, ranging from 0 to 255, which determines the intensity of that color in the pixel. </p>
<p>For example:</p>
<ul>
<li>(0, 0, 0) represents black (absence of all colors)</li>
<li>(255, 255, 255) represents white (maximum intensity of all colors)</li>
<li>(255, 0, 0) represents pure red (maximum intensity of red, absence of green and blue)</li>
<li>(0, 255, 0) represents pure green (maximum intensity of green, absence of red and blue)</li>
<li>(0, 0, 255) represents pure blue (maximum intensity of blue, absence of red and green)</li>
</ul>
<p>By combining different intensities of red, green, and blue, we can represent a wide range of colors. This color information for each pixel is stored in memory, forming a digital image. For example to get yellow, we can combine red and green – (255, 255, 0) represents a yellow pixel.</p>
<h2 id="heading-how-to-use-the-encryption-algorithm">How to Use the Encryption Algorithm</h2>
<p>The key idea behind the algorithm we're going to use is that it uses 2 images: the image we want to encrypt and an image that will play the role of mask used to hide the image we want to encrypt. So we're going to combine these two images in a way that hides our main image and allows its extraction.</p>
<p>Since an image is made of pixels, what works for a single pixel works for an entire image. We will discuss how we will be combining 2 pixels in a way that hides one and allows reverting the process.</p>
<p>Now for the interesting part: if we look at numbers from 0 to 255, they all can be written as follows: a <em> 16 + b. For example 241 can be written as 15 </em> 16 + 1. But why we are doing this? </p>
<p>We will be using this to divide each pixel into two parts: first the a * 16 part and second b. The first part holds way more information than the second, since when a color degree goes up its intensity goes up. For example a (245, 137, 200) pixel can be split into (240, 128, 192) and (5, 9, 8). </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--114-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image splitting</em></p>
<p>Now by comparing the high value pixel and the original one, you can see clearly that using the higher value pixel instead of the original one isn't going to change much of the information the original pixel holds.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--115-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Comparing a higher value pixel and an original pixel's values</em></p>
<p>Now we will be using two pixels – one we're going to encrypt (the target pixel), and one we're going to hide the target pixel within (the encryption pixel), which can be random as we will see later. </p>
<p>First we will get the high value pixel from our target and encryption pixels. Then for the pixel we're trying to encrypt, we'll divide each number degree by 16. </p>
<p>For example if the original target pixel was (245, 137, 200) then the high value pixel will be (240, 128, 192) which will become (15, 8, 12) after applying a division by 16. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--121-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Getting initial values and applying division</em></p>
<p>Now we have two new pixels: the high value pixel of the encryption pixel, and our target pixel high value pixel that got divided by 16. </p>
<p>Finally, to get an encrypted pixel, we'll sum up the values of these two pixels to get what we're looking for. </p>
<p>Take, for example, (26, 98, 234) and (245, 137, 200) as our encryption and target pixels, respectively. Let's first get the high value pixels. We will have (16, 96, 224) and (240, 128, 192), respectively. </p>
<p>Now divide the target pixel high value pixel by 16 and you'll have (15, 8, 12). Now add these two up and you'll be left with (31, 104, 236). And that's our encrypted pixel. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--118-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Encrypted image</em></p>
<p>Now you know how to encrypt a pixel. By applying this to all the pixels of an image we will get an encrypted image. </p>
<p>To make this clearer, we will be hiding an image of Quincy Larson playing guitar within the freeCodeCamp logo 😂.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--126-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image showing how we were able to hide Quincy Larson image in the freeCodeCamp logo</em></p>
<p>So to make this work we need two images: the one we need to encrypt and a random image to use as the encryption image. Also the two images should have the same dimensions to get the same number of pixels. </p>
<p>The reason we're using a random image to hide our image is to make it look like a very random image that will make no one suspicious.</p>
<h2 id="heading-how-to-use-the-decryption-algorithm">How to Use the Decryption Algorithm</h2>
<p>Now we need a way to revert the process, so to extract the target pixel from an encrypted pixel. Then we will have accomplished our goal.</p>
<p>Like we did earlier by combining 2 pixels to get an encrypted pixel, we will split back the encrypted pixel to get our target.</p>
<p>Every pixel can be split into two parts – the high value part (a * 16) and the low value part (b). Now we care about the b part since it comes from our target pixel. So we need to extract the b part from an encrypted pixel.</p>
<p>We can do this easily by mapping each number with its corresponding remainder of division by 16. We can do this using the modulo operator <strong>%</strong> which is a mathematical operator to get the remainder of the division of a number by another. For example 241 % 16 is 1 since since 241 is equal to 15 * 16 + 1.</p>
<p>By taking (31, 104, 236) and applying the modulo, we will be left with (15, 8, 12). As discussed earlier an encrypted pixel is the sum of the high value pixel of our encryption pixel or the mask pixel and the high value pixel of our target divided by 16. After the modulo is applied, the left value is the high value pixel of our target divided by 16.</p>
<p>Now multiply each number by 16 and you'll get exactly (240, 128, 192) which is the high value pixel of our target pixel.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Screenshot--117-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Decryption</em></p>
<p>Now as you can see, <strong>Steganography</strong> involves a small loss of each target pixel's information – but it's ok as you can see that it doesn't matter much in how the final image looks.</p>
<h2 id="heading-photo-encryption-app-code">Photo Encryption App Code</h2>
<p>And now since our toolkit is ready, let's code this image encryption application. All the code is available in this <a target="_blank" href="https://github.com/HousseinBadra/image-Encryption.git">GitHub repo</a>. The code itself is very straightforward. </p>
<p>First, create three files: an HTML file, a CSS file, and a JavaScript file. </p>
<p>For the HTML file we just need a canvas where we can see the resulting image. We also need two inputs of type file so we can upload our target and encryption images. And finally we need a button to save our encrypted image. </p>
<p>Also we will be using a small library to manage images created by Duke University, so we will have to include a script tag in the end of the body for this.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Image encryption app<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"index.css"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-container"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Target"</span>&gt;</span>Upload target image<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"file"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"target"</span> <span class="hljs-attr">mltiple</span>=<span class="hljs-string">'false'</span> <span class="hljs-attr">accept</span>=<span class="hljs-string">'image/*'</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-container"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Encryption"</span>&gt;</span>Upload encryption image<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"file"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"encryption"</span> <span class="hljs-attr">multiple</span>=<span class="hljs-string">'false'</span> <span class="hljs-attr">accept</span>=<span class="hljs-string">'image/*'</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Save image<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">'https://www.dukelearntoprogram.com/course1/common/js/image/SimpleImage.js'</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The CSS is simple too. We will give the div wrapping the canvas a width and height of 300px, the canvas a width and height of 100%, and it'll have a black border. Now the div tags wrapping our inputs will get a slight margin of 10px on the top, and that's it.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
  <span class="hljs-attribute">width</span>:<span class="hljs-number">300px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}

<span class="hljs-selector-tag">canvas</span>{
  <span class="hljs-attribute">width</span>:<span class="hljs-number">100%</span>;
  <span class="hljs-attribute">height</span>:<span class="hljs-number">100%</span>;
  <span class="hljs-attribute">border</span>:<span class="hljs-number">1px</span> solid black;
}

<span class="hljs-selector-class">.input-container</span>{
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p>Now for the JavaScript file. We will first select the two inputs, the canvas and the save button, and store them in four different variables. Then we will set the canvas width and height to 300px with JavaScript to avoid any future problems. And finally we'll set two variables, target and encryption, to store our encryption and target images.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> canvas = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"canvas"</span>);
<span class="hljs-keyword">const</span> targetInput = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#target"</span>);
<span class="hljs-keyword">const</span> encryptionInput = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#encryption"</span>);
<span class="hljs-keyword">const</span> saveButton = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"button"</span>);
<span class="hljs-keyword">let</span> target;
<span class="hljs-keyword">let</span> encryption;

canvas.width = <span class="hljs-number">300</span>;
canvas.height = <span class="hljs-number">300</span>;
</code></pre>
<p>Now we need to store the encryption and target images on user upload in the two variables we created earlier. Also set the <strong>onClick</strong> event of our save button to a function called <strong>save</strong> that we will create next. Finally, we'll create a function that takes a number as an argument and returns its high value as discussed in the encryption algorithm section.  </p>
<pre><code class="lang-js">targetInput.onchange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> SimpleImage(targetInput);
  img.setSize(<span class="hljs-number">300</span>, <span class="hljs-number">300</span>);
  target = img;
};

encryptionInput.onchange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> SimpleImage(encryptionInput);
  img.setSize(<span class="hljs-number">300</span>, <span class="hljs-number">300</span>);
  encryption = img;
};

saveButton.onclick = save;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getValue</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">return</span> x - (x % <span class="hljs-number">16</span>);
}
</code></pre>
<p>All that's left is to create the save function. First we will create a new image object with dimensions of 300 * 300. An image with these dimensions will have 90000 pixels. All of them have x and y coordinates from 0-299, since indexing starts from 0 in arrays. Looping from 0 to 300 twice will allow us to get all possible coordinates which means all pixels.</p>
<p>Now for each coordinate we will use the corresponding pixel of our encryption, target, and newly created image. Now we can set each pixel of our newly created image to the sum of the high value pixel of the encryption pixel and the high value pixel of our target divided by 16.</p>
<p>Now we will draw the newly created pixel on the canvas. And we'll need to get the URL of the image drawn into the canvas. We will be applying a small modification to the URL otherwise it will not work because we will get blocked by the browser for security reasons.</p>
<p>Finally, navigate to this URL by setting the window location to that URL. Then the encrypted image will be downloaded.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">save</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> img = <span class="hljs-keyword">new</span> SimpleImage(<span class="hljs-number">300</span>, <span class="hljs-number">300</span>);
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">300</span>; i++) {
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j &lt; <span class="hljs-number">300</span>; j++) {
      <span class="hljs-keyword">const</span> targetPixel = target.getPixel(i, j);
      <span class="hljs-keyword">const</span> encryptionPixel = encryption.getPixel(i, j);
      <span class="hljs-keyword">const</span> pixel = img.getPixel(i, j);
      pixel.setRed(
        getValue(targetPixel.getRed()) / <span class="hljs-number">16</span> + getValue(encryptionPixel.getRed())
      );
      pixel.setGreen(
        getValue(targetPixel.getGreen()) / <span class="hljs-number">16</span> +
          getValue(encryptionPixel.getGreen())
      );
      pixel.setBlue(
        getValue(targetPixel.getBlue()) / <span class="hljs-number">16</span> +
          getValue(encryptionPixel.getBlue())
      );
    }
  }
  img.drawTo(canvas);
  <span class="hljs-keyword">let</span> url = canvas
    .toDataURL(<span class="hljs-string">"image/png"</span>)
    .replace(<span class="hljs-string">"image/png"</span>, <span class="hljs-string">"image/octet-stream"</span>);
  <span class="hljs-built_in">window</span>.location.href = url;
}
</code></pre>
<p>And that's it for the code 😇.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we've learned a simple algorithm for image encryption. Modern algorithms are way more robust, as they use techniques like matrix multiplication to get solid hashing algorithms but they are very complex and require way more time and math knowledge than this one. </p>
<p>If you find this content enjoyable, <a target="_blank" href="https://www.linkedin.com/in/houssein-badra-943879214/">follow me on LinkedIn</a> as I post great content there 😉.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Hackers Attack Social Media Accounts – And How to Defend Against Them ]]>
                </title>
                <description>
                    <![CDATA[ Hey everyone, and welcome to the world of Social Media 📲. In this article, we will explore the famous (or infamous) sphere of social media, why it is critical to both you and hackers, and how you can avoid having your social media accounts attacked.... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-protect-social-media-accounts-from-attackers/</link>
                <guid isPermaLink="false">66bb9015a5fd14123a8b4a1e</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ social media ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Daniel Iwugo ]]>
                </dc:creator>
                <pubDate>Tue, 06 Jun 2023 16:42:11 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/06/aman-pal-15r9RAOy38Q-unsplash-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hey everyone, and welcome to the world of Social Media 📲.</p>
<p>In this article, we will explore the famous (or infamous) sphere of social media, why it is critical to both you and hackers, and how you can avoid having your social media accounts attacked.</p>
<p><strong>Disclaimer:</strong> Hacking is a tool with the potential for both good and bad. Under no circumstances should the knowledge in this article be used for any harmful or illegal purposes. Doing so could lead to a long time in a jail cell 💀.</p>
<p>And with that, let’s jump in 🙃.</p>
<h2 id="heading-what-well-cover">What We’ll Cover</h2>
<ol>
<li><p>Overview of Social Media Platforms</p>
</li>
<li><p>Attack Techniques</p>
</li>
<li><p>Defense Tips</p>
</li>
</ol>
<h2 id="heading-overview-of-social-media-platforms">Overview of Social Media Platforms</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/anledry-cobos-D-CYZ9ZaMqs-unsplash.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Media is Everything ¦ Credit:</em> <a target="_blank" href="https://unsplash.com/@anledry"><em>Anledry Cobos</em></a></p>
<p>Meta (formerly Facebook) remains one of the biggest companies on the planet.</p>
<p>Starting off in 2004, it redefined the way we interact with, share, and engage with the world around us. With roughly <a target="_blank" href="https://www.statista.com/statistics/264810/number-of-monthly-active-facebook-users-worldwide/">2.98 billion monthly active users</a>, Facebook has become an integral part of modern society, bridging gaps and fostering virtual communities.</p>
<p>The platform was among the pioneers of the social media craze which introduced the world to more apps such Instagram, Snapchat, Reddit, WhatsApp, YouTube, TikTok, Telegram and most notoriously, Twitter 🐦. Each and every single one of these apps have a different feel and taste to them with one underlying purpose: Connections.</p>
<p>Connections to people, places and products have been the centre of it all. These platforms allow you to interact with friends, as well as strangers. They also help you see the world around you in ways no one thought was possible many years ago. And if you’re a business person or content creator like I am, it allows you to show people what you have to offer.</p>
<p>If an attacker compromises your credentials, they have access to your connections. They could use your data to impersonate you, post illegal and harmful things, damage your reputation, spread malware, and social engineer your friends and followers on the platform in order to steal money and compromise their accounts.</p>
<p><a target="_blank" href="https://blog.gitnux.com/social-media-hacking-statistics/">According to Gitnux</a>, there are about 1.4 billion attacks on social media platforms monthly – quite a lot isn’t it?</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-85.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Giga Chad ¦ Credit: The Hacker Community</em></p>
<p>Many companies take the cybersecurity of their infrastructure quite seriously (most times anyway 😶). But as a consumer, you are your own last line of defense or your own greatest vulnerability.</p>
<p>In this article, we will take a look at some ways attackers can convert your ‘connections’ into profit and how you can defend against them. Now let’s find out how hackers can compromise your account.</p>
<h2 id="heading-social-media-account-attack-techniques">Social Media Account Attack Techniques</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/greg-bulla-KItSIXhXFDY-unsplash.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>A ‘Like’ signboard on 1 Hacker Way ¦ Credit: [Greg Bulla](https://unsplash.com/@gregbulla?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener noreferrer)</em></p>
<h3 id="heading-physical-access">Physical Access</h3>
<p>This may seem obvious, but people still make this mistake a lot. An attacker could install scripts or software that would let them get the passwords of your social media accounts if they have your phone or laptop in their hand.</p>
<p>Software like those from Passrevelator make it easy to get passwords and other credentials from devices on different platforms.</p>
<h3 id="heading-phishing-links-emails-and-sites">Phishing links, emails, and sites</h3>
<p>Phishing is a cyberattack in which the attacker tricks the victim into giving sensitive or critical information through fraudulent websites, forms, links or other means.</p>
<p>It’s pretty easy for anyone to make a Facebook clone with React Native. Tools like <a target="_blank" href="https://github.com/jaykali/maskphish.git">Zphisher</a> and <a target="_blank" href="https://github.com/KasRoudra/PyPhisher">PyPhisher</a> make it even easier for an attacker by setting up a phishing page and creating links to it, too.</p>
<p>As you can see, PyPhisher comes with a wide array of options for some major mayhem.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-86.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The Phyphisher Interface ¦ Credit: Mercury</em></p>
<p>More seasoned criminals can send links in spoofed emails to make them look like they are from official organisations and can register lookalike domains to trick users.</p>
<h3 id="heading-password-spraying-and-bruteforcing">Password Spraying and Bruteforcing</h3>
<p>Passwords are a big security concern, and for good reason. They are often repetitive and easy to guess. Spraying is the process of trying out common passwords while Bruteforcing is the process of trying out all possible combinations to gain access.</p>
<p>Attackers can get the passwords they use in password spraying from common <strong>wordlists</strong>. Wordlists are a list of passwords usually gotten from data breaches. The larger the wordlist, the higher the chances of compromising any account.</p>
<p>Below is a screenshot of the infamous rockyou.txt wordlist from the RockYou hack of 2009.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/rockyou-wordlist.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The rockyou.txt wordlist ¦ Credit Mercury</em></p>
<p>Bruteforcing, on the other hand, involves the attacker generating a custom wordlist alongside usernames or emails on different platforms. This is more effective if the attacker has a specified target.</p>
<p>As you can see, attackers can use a tool known as <strong>crunch</strong> to generate a wordlist, and it has a lot of options.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/Crunch-Wordlist.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Crunch in action ¦ Mercury</em></p>
<p>If an attacker uses these techniques on a login page, this has great potential to be an entry point, especially if the site has poor security.</p>
<h3 id="heading-keyloggers">Keyloggers</h3>
<p>A Keylogger is a piece of riskware that keeps track of what a person types on their device. Think of it like your keyboard having a memory card and sending what it stores to an attacker.</p>
<p>Note that keyloggers aren’t inherently bad, as they can also be used for organisational monitoring and parental control. But an attacker does not have authorization to monitor your keystrokes, which makes its use illegitimate.</p>
<p>An attacker could install a keylogger and monitor the victim's keystrokes. All they have to do is wait and read the logs for a peculiar sequence, usually one with an email, followed by a string of characters before the ‘return’ keystroke.</p>
<p>It would usually look something like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-88.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>A slightly modified Keylogger log ¦ Credit: Mercury</em></p>
<p>Usually, the entire log will be monochrome but for this example I made a few modifications. The red highlight indicates an email account, which is what an attacker would be looking for. Close behind is the password in blue.</p>
<h3 id="heading-network-sniffing">Network Sniffing</h3>
<p>Also known as packet sniffing, this is the practice of intercepting and analysing network packets in order to find out what kind of information is shared within the network.</p>
<p>If connections are not properly encrypted, an attacker could easily obtain sensitive information about the sites visited and the messages and passwords that are sent and inputted in them, respectively. WireShark is one of the most common tools for this kind of attack.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/image-89.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The Wireshark Interface ¦ Credit: Mercury</em></p>
<h3 id="heading-data-breaches">Data Breaches</h3>
<p>Data breaches are unintentional leaks of sensitive or confidential information. These are usually more devastating to users than organisations and could have far-reaching consequences.</p>
<p>Passwords and login credentials from data leaks can be sold and purchased on the dark web. They are then used to gain unauthorised access to the account and the rest is history.</p>
<h2 id="heading-how-to-defend-against-social-media-attacks">How to Defend Against Social Media Attacks</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/pexels-prateek-katyal-2694434.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>A Neon Instagram Heart ¦ Credit: [Prateek Katyal](https://www.pexels.com/@prateekkatyal/" rel="noopener noreferrer)</em></p>
<p>As you can see, there are many ways to obtain Social Media account credentials. Below are some ways to ensure you are not a victim.</p>
<h3 id="heading-check-the-url">Check the URL</h3>
<p>Always double check any links sent to you via messaging platforms or email. This is a simple but very effective measure against phishing links and sites, as the likelihood of clicking on the wrong link is much lower.</p>
<p>For example, www.facebook.com and www.facebok.com are not the same. As you can observe in the screenshots below, the former is legitimate while an antivirus warns me that the later is a phishing site.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/2023-06-06-16_21_22-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>facebook.com ¦ Credit: Mercury</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/2023-06-06-16_16_05-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>facebok.com ¦ Credit: Mercury</em></p>
<h3 id="heading-use-strong-passwordspassphrases">Use strong passwords/passphrases</h3>
<p>Make sure you use strong passwords and don’t use similar passwords for different accounts (not even variants 👀). You can also use passphrases rather than passwords as they are easier to remember but harder to guess or bruteforce.</p>
<p>An example of a password is 'dictionary'. An example of a passphrase is 'mydictionaryisthelargest'. The password is weak and could be guessed or found easily in a wordlist. The passphrase isn't the strongest but it is quite lengthy and would be almost impossible to find in a wordlist or to be guessed.</p>
<h3 id="heading-use-antivirus-software-and-firewalls">Use Antivirus Software and Firewalls</h3>
<p>An Antivirus is a software solution that protects systems against both internal and external threats based on the vendor. A Firewall, on the other hand, protects systems against external threats based on your preferences and settings.</p>
<p>The use of one or both of these products can go a long way in protecting both individuals and organisations from information stealing malware.</p>
<h3 id="heading-vpns">VPNs</h3>
<p>A Virtual Private Network is a secure network connection that connects you to the internet privately and anonymously. This is done by encrypting the connection and routing it through remote servers.</p>
<p>VPNs are a great option to avoid packet sniffers because packets analysed are encrypted. This means it’s going to be quite difficult for an attacker to get passwords from technical gibberish.</p>
<h3 id="heading-tracking-breaches">Tracking Breaches</h3>
<p>Tracking breaches can be done at an individual or enterprise level. It’s effectiveness, however, usually depends on how much you are willing to pay for it.</p>
<p>Individuals can use sites like <a target="_blank" href="http://haveibeenpwned.com/">haveibeenpwned.com</a> to check if their data has been compromised in any breaches and Enterprises can setup security units with the role of constantly monitoring the Internet for breaches related to them.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/pexels-visual-tag-mx-5361087.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Social Media in Scrabble ¦ Credit: [Visual Tag Mx](https://www.pexels.com/@visual-tag-mx-1321732/" rel="noopener noreferrer)</em></p>
<p>Getting credentials is pretty easy with some determination and a touch of mischievousness. But companies have gotten better at defense in recent years and attackers have had to get more creative.</p>
<p>As an individual, you are your last and dare I say best line of defense. Ensure your shields are always up in the online jungle. Stay safe and Happy Hacking 🙃.</p>
<h3 id="heading-acknowledgements">Acknowledgements</h3>
<p>Thanks to <a target="_blank" href="https://twitter.com/Anuoluwap__o">Anuoluwapo Victor</a>, <a target="_blank" href="https://www.linkedin.com/in/chinaza-nwukwa-22a256230/">Chinaza Nwukwa</a>, <a target="_blank" href="https://www.linkedin.com/in/mercy-holumidey-88a542232/">Holumidey Mercy</a>, <a target="_blank" href="https://www.linkedin.com/in/favour-ojo-906883199/">Favour Ojo</a>, <a target="_blank" href="https://www.linkedin.com/in/georgina-awani-254974233/">Georgina Awani</a>, and my family for the inspiration, support and knowledge used to put this together. You’re the best.</p>
<h3 id="heading-resources">Resources</h3>
<ol>
<li><p><a target="_blank" href="https://blog.gitnux.com/social-media-hacking-statistics/">Social Media Attack Statistics</a></p>
</li>
<li><p><a target="_blank" href="https://www.passwordrevelator.net">GUI tools for physical access hacking</a></p>
</li>
</ol>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Amazon EC2 – Understanding and Addressing the Security Problem ]]>
                </title>
                <description>
                    <![CDATA[ Hi there. Great to have you here. But I'm afraid I'm going to have to start off with some bad news.  Before you can really improve the security of your Amazon EC2 instances, you'll need to get a handle on all the stuff that can go wrong. And I'll ]]>
                </description>
                <link>https://www.freecodecamp.org/news/amazon-ec2-understanding-the-security-problem/</link>
                <guid isPermaLink="false">66b9959abe5923657131acb3</guid>
                
                    <category>
                        <![CDATA[ AWS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Thu, 18 May 2023 19:07:42 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/pexels-pixabay-277574.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hi there. Great to have you here. But I'm afraid I'm going to have to start off with some bad news. </p>
<p>Before you can really improve the security of your Amazon EC2 instances, you'll need to get a handle on all the stuff that can go wrong. And I'll give you a bit of a "hall of shame" rundown in just a minute. </p>
<h2 id="heading-whats-the-problem">What's the Problem?</h2>
<p>But first, by way of introduction, I want to tell you a really scary story. So scary, that you should perhaps prepare by turning on all the lights in your room and grabbing a soft blanket for comfort.</p>
<p>Here goes. Based on my own past experiences, I just conducted a brief experiment. I launched an EC2 instance running Ubuntu into one of my AWS accounts. The instance wasn't running anything more than whatever Ubuntu gave me by default and it wasn't associated with any DNS addresses. </p>
<p>Its only connection with the outside world was through the public IP address AWS assigned it. In fact, the only difference between this instance and one that you or I might normally run is that I opened up its security group to permit all incoming traffic. </p>
<p>Since Ubuntu, by default, doesn't run an active firewall, there would therefore be nothing standing between the instance and the big bad internet.</p>
<p>This article comes from my <a target="_blank" href="https://www.udemy.com/course/securing-amazon-ec2-instances/?referralCode=E3ACB9DC5E3B77853E63">Securing Your AWS EC2 Instances course</a>. If you'd like, you can follow the video version of this section here:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/femqe6OIJGk" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>So what happened? Well, the <code>auth.log</code> entries on the host were astounding. According to those logs, the system came up for the first time at around 14:56. Here's a little of what I saw just 35 minutes later:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/ec2_security1-f004258.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Someone was trying to log in to my system via SSH using the user name <code>root</code>. Now, of course, by default, root login is disabled - and you should leave it that way. But that didn't stop this individual from trying. </p>
<p>Note how they didn't just use the standard SSH port 22, but played around with alternative port numbers (including <code>51912</code> as well). That suggests that this attempt was part of an automated script that tests various combinations of usernames, passwords, and ports:</p>
<pre><code>Aug <span class="hljs-number">10</span> <span class="hljs-number">15</span>:<span class="hljs-number">31</span>:<span class="hljs-number">17</span> ip<span class="hljs-number">-172</span><span class="hljs-number">-30</span><span class="hljs-number">-1</span><span class="hljs-number">-186</span> sshd[<span class="hljs-number">2777</span>]: error: maximum authentication attempts exceeded <span class="hljs-keyword">for</span> root <span class="hljs-keyword">from</span> <span class="hljs-number">20.210</span><span class="hljs-number">.53</span><span class="hljs-number">.189</span> port <span class="hljs-number">51912</span> ssh2 [preauth]
</code></pre><p>But they weren't done. Over the next 75 seconds, 30 more login attempts came from this same IP address. They pointed to different ports in the 50,000 range, and used different usernames like, admin, oracle, test, test1, test2, ftpuser, and pi. </p>
<p>The fact that they tried <code>pi</code> tells me that they didn't realize that this was a cloud instance but that, for all they knew, it could have been a Raspberry Pi running in someone's home lab.</p>
<p>I don't know about you, but I find this really frightening. Sure, which admin would purposely open up a security group to all incoming traffic? But the real point is that there are so many scripts out there constantly scanning for live IP addresses and then trying to brute force system logins, that any random IP address can expect hits within minutes. </p>
<p>And, again, this isn't the first time I've seen this in action, nor is SSH the only public-facing service that attracts such attacks. At the very least, we should take this as a warning to tighten up our SSH configurations - which is something I will discuss later.</p>
<p>But here's the thing. It <em>is</em> possible to achieve perfect security - it really is - but that would involve completely locking your servers down and blocking all access from the outside world. What's the point of running servers like that? The goal is to find the best possible balance between application functionality and infrastructure security. </p>
<p>Establishing that balance might include incorporating all the general IT security basics like system hardening and monitoring, alongside the intelligent use of key AWS security features like IAM roles, security groups, appropriate VPC architectures and, where appropriate, the use of VPNs.</p>
<p>So just what's out there waiting to dig its claws into your AWS operations? Well there are hackers' tools for getting into your system, exploits for taking over and misusing your resources, and methodologies for bringing down your services by force. Let's look at these one at a time.</p>
<h2 id="heading-access-acquisition">Access Acquisition</h2>
<p>As you might have noticed from the <code>maximum authentication attempts exceeded</code> content of those log entries I showed you earlier, the hacker tried entering multiple passwords for each login name. </p>
<p>That's known as a brute force attack, where hackers rotate through a dictionary of common passwords, hoping that one will turn out to be correct. </p>
<p>The reason my system cut those attempts off completely is because the official EC2 Linux images have a default SSH configuration setting - <code>MaxAuthTries</code> - set to six. Even if you did permit password logins for SSH - and even if you did irresponsibly use a weak password - the odds against a hacker getting it right within six tries are pretty slim.</p>
<p>If you'd like, you can follow the video version of the second part of the article here:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/Ajwoe9sSjuo" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>Of course, if a hacker can get hold of <em>real, active</em> credentials, then they won't need to guess. That's why you should be aware of phishing attacks where hackers use social manipulation to get victims to unknowingly reveal their login information. </p>
<p>They can similarly take advantage of communications that take place using compromised devices or that are sent over unencrypted connections to sniff your credentials as you use them.</p>
<p>In <em>cloud</em> terms, just imagine how much fun someone could have once they get hold of your AWS account credentials. That would allow them to quickly run up hundreds of thousands of dollars worth of bills on your credit card, by deploying nearly endless AWS resources in service of their own criminal needs. Besides having to cover those bills, you might also get blamed for any crimes committed with those resources.</p>
<h2 id="heading-exploits">Exploits</h2>
<p>Once hackers have gained access to your system, things can only get worse. Whether they do something nasty right away or hang around for months planning something particularly nefarious, if you don't catch them at it, eventually they'll install their malware. </p>
<p>That might take the shape of keyboard trackers that record every character you and your colleagues enter in a shell session. It'll only be a matter of time before those trackers capture credentials that'll let them elevate their own permissions.</p>
<p>The malware could also take the form of cryptocurrency mining operations that make heavy - and expensive - use of your system resources so the hackers can profit. Or - and this is the most frightening - they might decide to encrypt key data on your drives and demand large payments before they'll let you decrypt and regain access. </p>
<p>This, of course, is known as ransomware, and it's currently the biggest problem facing enterprise-level systems. It costs governments and companies billions of dollars each year.</p>
<h2 id="heading-service-disruption">Service Disruption</h2>
<p>Even if they don't get <em>into</em> your system, the bad guys can still do a lot of damage from the outside. If, for instance, they detect misconfigurations on your servers - like unnecessarily open network listening ports, poorly written database endpoints, or outdated software like FTP or telnet, they can cause you plenty of problems.</p>
<p>And, for those criminals with access to networks of hijacked zombie servers, they could overrun your network capacity with distributed denial of service attacks - preventing your legitimate users from accessing your services. </p>
<p>Fortunately, AWS provides some serious protection from DDoS out of the box, so that's not likely to be a big concern for you as an admin.</p>
<p>Speaking of AWS engineering, now's probably a good time to discuss their <a target="_blank" href="https://aws.amazon.com/compliance/shared-responsibility-model/">Shared Responsibility Model</a>. The way the company phrases it, AWS is responsible for the security <em>of the cloud</em> while their customers - that would be you and me - are responsible for the security of whatever you put <em>in the cloud</em>.</p>
<p>Practically, that means you don't need to worry about terrible things happening to the physical servers and storage devices used by your EC2 instances. AWS will protect their warehouses and networking hardware from unauthenticated intrusion and harm. They'll also take responsibility for the software powering any of their managed services - like the API and dashboards you use to configure account activity.</p>
<p>But you're responsible for everything else. That includes the data your instances might generate and the operating systems themselves. So you're on the hook for keeping your operating system and application software patched, and for making appropriate backups of all the data and configuration files you generate.</p>
<p>You're also responsible for making the right AWS-level configuration choices, like getting your security group and network settings right. Depending on the industry and national jurisdiction within which you operate, you might also be expected to meet one or more regulatory compliance standards. </p>
<p>AWS provides documentation laying out which standards each service meets. If you open the web page shown below, you could expand the Payment Card Industry - PCI - section, for instance, and then search for EC2. You'll see that EC2 infrastructure is, indeed, PCI-compliant;</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/services_in_scope.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We've seen how vulnerable your EC2 instances are when they're left without adequate protection. But we've also seen some industry best-practices for keeping them secure. You know what your next step is.</p>
<p><em>This article comes from my <a target="_blank" href="https://www.udemy.com/course/securing-amazon-ec2-instances/?referralCode=E3ACB9DC5E3B77853E63">Securing Your AWS EC2 Instances course</a>. And there's much more technology goodness available at <a target="_blank" href="https://bootstrap-it.com/">bootstrap-it.com</a></em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Digital Intruders – Top Ways Hackers Can Breach Your Smartphone’s Security ]]>
                </title>
                <description>
                    <![CDATA[ Smartphones are integral to our lives, making them prime targets for hackers. In this article, we will go through 7 ways hackers can gain access to your smartphone and how to protect against these attacks. Smartphones have become an essential part of... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-hackers-can-breach-your-smartphones-security/</link>
                <guid isPermaLink="false">66d035d164be048ac359a300</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Fri, 28 Apr 2023 14:16:33 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/0_oX7oKDWxr6bwRgXd.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Smartphones are integral to our lives, making them prime targets for hackers. In this article, we will go through 7 ways hackers can gain access to your smartphone and how to protect against these attacks.</p>
<p>Smartphones have become an essential part of our daily lives with instant access to information at the touch of a button. Whether we’re checking our social media feeds or responding to work emails, they are always within arm’s reach. It's no wonder that these devices offer a wide range of functions, from GPS navigation to streaming music.</p>
<blockquote>
<p>In 2023, the number of <a target="_blank" href="https://www.oberlo.in/statistics/how-many-people-have-smartphones#:~:text=In%202023%2C%20the%20number%20of,2016%2C%20just%20seven%20years%20ago.">smartphone users worldwide is projected to reach 6.8 billion</a>, a growth rate of 4.2% per year.</p>
</blockquote>
<p>As we all depend more and more on our smartphones, the importance of securing them is at an all-time high. Cybercriminals can target your device using malicious apps, phishing, and even more sophisticated attacks.</p>
<p>As almost every aspect of our lives is now connected to our smartphones, a hacker gaining access to your device can be a nightmare scenario. Being the victim of a smartphone hack can be a distressing experience that can leave you feeling exposed and violated.</p>
<p>They can steal your personal information, bank account details, or social media passwords. The repercussions can be severe, ranging from financial loss to reputational damage.</p>
<p>I have outlined the 7 most common ways hackers can reach your smartphone. We will also see tips on how to protect your device from cyberattacks.</p>
<p>Keep reading to learn how you can keep your smartphone and data safe from those who try to exploit it.</p>
<h2 id="heading-smishing-attacks">Smishing Attacks</h2>
<p>Smishing is a type of phishing attack that hackers use to get access to sensitive information through text messages. An attacker will send you a link to click through a text message making it appear from a legitimate source.</p>
<p>Due to the limited display of URLs in mobile browsers, Smishing can be difficult to detect on mobile devices. This makes Smishing as effective as email phishing.</p>
<p>Knowing the source of text messages is crucial. This applies to messaging platforms like WhatsApp as well. Always be wary of clicking links or responding to messages from unknown numbers.</p>
<blockquote>
<p>According to the FBI’s 2020 Internet Crime Report, <a target="_blank" href="https://increditools.com/smishing-statistics/#:~:text=is%20smishing%3F%E2%80%9D.-,Only%2029%25%20of%20surveyed%20people%20across%2015%20countries%20understand%20smishing,over%20%2454.2%20million%20in%202019.">Smishing accounted for nearly a half-billion dollars in losses in 2019.</a></p>
</blockquote>
<h2 id="heading-breaking-in-via-bluetooth">Breaking in via Bluetooth</h2>
<p>Bluetooth is another easy way with which hackers target smartphones. Smartphones are vulnerable to Bluetooth hacking due to weak security protocols.</p>
<p>Hackers can gain access to calls, texts, and authentication codes via Bluetooth. It becomes easier for hackers to break into your device if you leave your Bluetooth connection unregulated. Luckily, physical proximity to the device is important for Bluetooth hacking.</p>
<p>Attackers can exploit weak wireless connections in public spaces. The automatic pairing of devices with visible Bluetooth signals makes it easy for attackers to exploit. To ensure safety, you must turn off your Bluetooth unless necessary and disable auto-pairing.</p>
<h2 id="heading-malware-attacks">Malware Attacks</h2>
<p>Malware is any software designed to harm computers, networks, or mobile devices. It can come in various forms such as viruses, spyware, adware, or Trojans.</p>
<p>Hackers can use malware to steal your account credentials, check your online activity, or even take control of your device. To avoid malware, ensure that your device’s software is up-to-date.</p>
<p>Install apps only from the app store or play store and never install them directly from third-party websites. Consider using antivirus or anti-malware software to protect your smartphone.</p>
<blockquote>
<p>In the first half of 2020, <a target="_blank" href="https://dataprot.net/statistics/malware-statistics/#:~:text=560%2C000%20new%20pieces%20of%20malware,58%25%20of%20all%20computer%20malware.">more than 3.2 billion malware attacks</a> have been registered by SonicWall.</p>
</blockquote>
<h2 id="heading-malvertising">Malvertising</h2>
<p>Malvertising is another popular tactic used by hackers to target smartphones. It involves using malicious advertisements to spread malware or spyware on various devices.</p>
<p>Malvertising works by delivering malicious ads via online advertising networks. These malvertisements are often found in illegal or pornographic websites.</p>
<p>Installation of malware or spyware on your device leads to instant compromise of your device. To protect your smartphone, avoid clicking on unknown ads or visiting suspicious websites.</p>
<blockquote>
<p>The annual malvertising revenue on <a target="_blank" href="https://proprivacy.com/blog/malvertising-facts-statistics-2022-protect-youreself-from-malvertising#:~:text=One%20in%20every%20100%20ads,malicious%20content%20are%20not%20surprising.">pirating websites is projected to be $1.34 billion</a>.</p>
</blockquote>
<h2 id="heading-social-engineering">Social engineering</h2>
<p>Social engineering is another popular attack vector used by hackers to access confidential data. It involves tricking users into providing sensitive information. This information could be your email, password, or even credit card information.</p>
<p>To protect your device from social engineering attacks, you should be wary of suspicious emails, messages, and phone calls. If a message or call requests personal information, double-check and make sure it is a legitimate source.</p>
<p>Social engineering attacks are also common in the workplace. If someone from your company is requesting suspicious information, check and make sure the request is from them via alternate communication channels.</p>
<blockquote>
<p><a target="_blank" href="https://eftsure.com/statistics/social-engineering-statistics/">23% of social engineering breaches</a> resulted in the confirmed disclosure of data to an unauthorized party.</p>
</blockquote>
<h2 id="heading-pretexting">Pretexting</h2>
<p>Pretexting is another technique used by hackers to gain access to confidential data. It involves creating a false pretext or story to convince an individual to reveal sensitive information.</p>
<p>Cybercriminals use pretexting attacks to steal passwords, credit card numbers, and personal details.</p>
<p>Never give out any personal information unless you are certain of the recipient’s identity. If you receive any suspicious messages via email or text messages, ignore them or report them to your organization’s security team.</p>
<blockquote>
<p><a target="_blank" href="https://www.proofpoint.com/us/security-awareness/post/phishing-pretexting-and-data-breaches-verizons-2018-dbir#:~:text=Taken%20together%2C%20phishing%20and%20pretexting,some%20useful%20distinctions%20between%20them.">Phishing and pretexting accounted for nearly all of the social breaches</a> with 93% of the incidents. Email was the most utilized attack vector (96%).</p>
</blockquote>
<h2 id="heading-man-in-the-middle-wi-fi-attacks">Man-in-the-middle Wi-Fi Attacks</h2>
<p>One of the most common ways hackers can target your smartphone is through man-in-the-middle Wi-Fi attacks. These attacks happen when you connect to public Wi-Fi or an unsecured network.</p>
<p>The hacker intercepts communication using tools like Wireshark and obtains information. Hackers can also access and manipulate data through hacked routers, which can lead to devastating consequences.</p>
<p>It’s important to note that these types of attacks do not need the hacker to take control of the user’s device, which makes them particularly dangerous. Wireless networks are vulnerable to a variety of attacks, so always be cautious when connecting to public Wi-Fi networks. Additionally, use a VPN to mask your network traffic.</p>
<blockquote>
<p>I<a target="_blank" href="https://snyk.io/learn/man-in-the-middle-attack/">n 2019, 35% of attacks were attempts at exploitation through MITM attacks.</a></p>
</blockquote>
<h2 id="heading-how-to-protect-yourself-from-smartphone-attacks">How to Protect Yourself from Smartphone Attacks</h2>
<p>Now that we have seen 7 ways hackers can target your smartphone, let me summarize the key points to protect yourself.</p>
<h3 id="heading-1-download-apps-from-trusted-sources-amp-install-mobile-antivirus-software">1. Download apps from trusted sources &amp; install mobile antivirus software:</h3>
<p>Always download apps from legitimate stores like the Apple app store or Google Play Store. Never download third-party apps or .apk files to your device. Ensure to use mobile antivirus software to protect your device from malware attacks.</p>
<h3 id="heading-2-beware-of-phishing-emails-amp-use-strong-passwords">2. Beware of phishing emails &amp; use strong passwords:</h3>
<p>Be wary of any emails that ask you to click on a link or enter personal information. Always use unique, complex passwords for your online accounts. Also, try to use two-factor authentication when possible.</p>
<h3 id="heading-3-stay-up-to-date-with-security-patches">3. Stay up-to-date with security patches:</h3>
<p>Ensure to update your operating system and apps with the latest security patches on a regular basis. Most software updates include security patches, and these vulnerabilities will be publicly disclosed. So, if you don’t update your device, you become an easy target for attackers.</p>
<h3 id="heading-4-use-a-vpn-virtual-private-network">4. Use a VPN (Virtual Private Network):</h3>
<p>When connected to public Wi-Fi networks or other unsecured networks, use a VPN to protect your data from hackers. This prevents unwanted snooping by malicious actors by using tools like <a target="_blank" href="https://blog.stealthsecurity.io/wireshark-a-walkthrough-of-the-best-packet-analyzer-in-the-world-9af0358ed9a1">Wireshark</a>.</p>
<h3 id="heading-5-disable-bluetooth-amp-gps-services-when-not-in-use">5. Disable Bluetooth &amp; GPS services when not in use:</h3>
<p>Ensure that your Bluetooth and GPS services are not active when they are not required. This will further reduce attack vectors for malicious actors.</p>
<h2 id="heading-summary">Summary</h2>
<p>Smartphone hacking is an unfortunate reality. It can leave users vulnerable to identity theft and financial loss. </p>
<p>To keep your smartphone device secure, do not give out personal information to untrusted sources. Stay vigilant and use the above-recommended security practices to ensure the safety of your smartphone.</p>
<p><em>If you found this article useful, join the</em> <a target="_blank" href="https://stealthsecurity.io/"><em>Stealth Security newsletter</em></a> <em>to get an email every Friday. We will include our articles, videos and the latest news from the world of Cybersecurity.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Symmetric and Asymmetric Key Encryption – Explained in Plain English ]]>
                </title>
                <description>
                    <![CDATA[ Encryption is a way of scrambling data so that it can only be read by the intended recipient. Encryption is an integral part of our daily lives – whether you are sending messages to friends on WhatsApp, visiting a website and your browser is making s... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/encryption-explained-in-plain-english/</link>
                <guid isPermaLink="false">66d45e0e3dce891ac3a967dc</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Daniel Adetunji ]]>
                </dc:creator>
                <pubDate>Wed, 05 Apr 2023 20:09:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/cover.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Encryption is a way of scrambling data so that it can only be read by the intended recipient.</p>
<p>Encryption is an integral part of our daily lives – whether you are sending messages to friends on WhatsApp, visiting a website and your browser is making sure it's legitimate, or entering your bank details when buying something online. Encryption protects your data from potentially malicious and prying eyes.</p>
<p>This article will cover:</p>
<ul>
<li><p>Encryption algorithms and keys</p>
</li>
<li><p>Symmetric and asymmetric key encryption</p>
</li>
<li><p>How TLS/SSL uses both symmetric and asymmetric encryption</p>
</li>
</ul>
<h2 id="heading-encryption-algorithms-and-keys">Encryption Algorithms and Keys</h2>
<p>At the start of this article, I described encryption as a way of scrambling data so that it can only be read by the intended recipient. Let’s break down what this means.</p>
<p>Let's say you want to write a letter to your friend and want to ensure that only the friend can read its contents. How would you prevent the prying eyes of all the intermediaries the letter could pass through before it gets to your friend? That is, how do you prevent the postman, the concierge in their building, or one of their friends from reading the letter?</p>
<p>You start with an unscrambled letter that anyone can read. This is called <strong>plaintext</strong>. To scramble the contents of the message, you need an <strong>encryption algorithm</strong> and a <strong>key</strong>. The encryption algorithm uses the key to scramble the contents of the message. This encrypted message is called <strong>ciphertext</strong>.</p>
<p>The process of encryption is shown in the image below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-9.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>When your friend gets the message, they will need to descramble it using the <strong>algorithm</strong> and the <strong>key</strong>. This is illustrated below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-10.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The two key ingredients needed to send a message to your friend that only they can read is an <strong>encryption algorithm</strong> and a <strong>key</strong>.</p>
<p>The encryption algorithm is simply a mathematical formula designed to scramble data, while the key is used as part of the formula. The encryption algorithm is generic, but the key, used as an input to the algorithm, is what ensures the uniqueness of the scrambled data.</p>
<p>Let’s look at one of the simplest encryption algorithms, called the Caesar Cipher. In its simplest form, this algorithm simply replaces each letter by the next letter in the alphabet. So A becomes B, and B becomes C and so on.</p>
<p>With this algorithm, the text ‘Birthday Surprise’ becomes ‘Cjsuiebz Tvsqsjtf’, indistinguishable from gibberish to the untrained eye.</p>
<p>With the Caesar Cipher example, the <strong>algorithm</strong> is the formula used to replace each letter of the alphabet with another. The <strong>key</strong> is the number of shifts made between each letter. With a key of 0, A is A, an obviously poor choice of key as the data is unscrambled. With a key of 1, A becomes B. With a key of 10, A becomes K.</p>
<p>The Caesar Cipher is a relatively poor encryption algorithm. Why? Since there are only 26 letters in the English language, you can only produce a maximum of 25 possible ciphertexts. If you don’t have the key, you only need to shift each letter up to 25 times until you see coherent words and sentences, at which point you know that you have successfully decrypted the message.</p>
<p>A bad encryption algorithm is one that is easily decrypted by using a small amount of brute force (that is, trying every possible permutation) – and 25 possible ciphertexts is an objectively small number of possible options to go through.</p>
<p>Modern encryption algorithms like AES-256 used by AWS, GCP, and Azure for encrypting data are considerably more complicated and secure than the Caesar Cipher. Based on current computing capability, it would take trillions and trillions of years for the most advanced supercomputer to use brute force to decrypt data encrypted using AES-256 [<a target="_blank" href="https://scrambox.com/article/brute-force-aes/">1</a>]. Even the universe is not that old.</p>
<h2 id="heading-symmetric-and-asymmetric-key-encryption">Symmetric and Asymmetric Key Encryption</h2>
<p>The core of any encryption process is the encryption algorithm and the key. There are many types of encryption algorithms. But there are, broadly speaking, two types of keys – symmetric and asymmetric keys.</p>
<p>In symmetric key encryption, the same key used to encrypt the data is used to decrypt the data. In asymmetric key encryption, one key is used to only encrypt the data (the public key) and another key is used to decrypt (the private key).</p>
<h3 id="heading-asymmetric-key-encryption">Asymmetric key encryption</h3>
<p>First, let’s look at asymmetric key encryption with a simple analogy.</p>
<p>Imagine you wanted to send something to your friend, but it was absolutely essential that nobody else, except your friend, could have access to that object. So, your friend buys an indestructible box, fabricated from the strongest metal on the planet, and sends it to you so that you can place the object in it. Your friend also sends you the key that can only be used to lock the box.</p>
<p>Now, this box has one more special property. It has two keyholes. One keyhole to open the box, another to lock the box.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-11.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Naturally, this box will also need two keys – one to open and another to lock it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-12.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Both keys are similar, but not identical. As you can see in the image above, for example, the key used to open the box has two prongs while the key used to lock the box has three prongs.</p>
<p>As the sender of the object, all you have is the box to place the object in and a key to lock the box. Only your friend has the key that can unlock the box.</p>
<p>The key used to lock the box is called the public key, and cannot be used to open it, as that requires the private key. If anyone intercepted the package and made a copy of the public key, it could not be used to open the box, only to lock it. Only the person who holds the private key can open the box.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-13.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Asymmetric key encryption is used when there are two or more parties involved in the transfer of data. This type of encryption is used for encrypting data in transit, that is encrypting data being sent between two or more systems. The most popular example of asymmetric key encryption is <a target="_blank" href="https://nordvpn.com/blog/rsa-encryption/">RSA</a>.</p>
<h3 id="heading-symmetric-key-encryption">Symmetric key encryption</h3>
<p>Symmetric key encryption uses the same key for encryption and decryption. This makes sharing the key difficult, as anyone who intercepts the message and sees the key can then decrypt your data.</p>
<p>This is why symmetric key encryption is generally used for encrypting data at rest. AES-256 is the most popular symmetric key encryption algorithm. It is used by AWS for encrypting data stored in hard disks (EBS volumes) and S3 buckets. GCP and Azure also use it for encrypting data at rest.</p>
<h2 id="heading-how-tlsssl-uses-both-symmetric-and-asymmetric-encryption">How TLS/SSL Uses Both Symmetric and Asymmetric Encryption</h2>
<p>The main strength of symmetric key encryption is that it is computationally easier and faster to encrypt and decrypt data using a single key, just as it is easier to build a box with a single lock and key.</p>
<p>The weakness of symmetric key encryption is that if the key is exposed, your data is no longer securely encrypted. So, if you needed to share the key with an external party, there is a risk that the key could be exposed, leaving your data at risk of being decrypted.</p>
<p>Symmetric key encryption is ideal for encrypting data at rest, where you do not need to share the key with another system.</p>
<p>With asymmetric encryption, this is not a problem since two separate keys are used – the public key to encrypt data and the private key to decrypt data.</p>
<p>The public key can be easily shared with anyone and poses no risk to your data being decrypted, since the private key is needed for decryption.</p>
<p>The drawback of asymmetric key encryption is that the encryption and decryption process is slower and more complicated. Asymmetric key encryption is ideal for encrypting data in transit, where you need to share the key with another system.</p>
<p>What if there was a way of getting the speed and computational simplicity of symmetric encryption without increasing the risk of exposing your keys?</p>
<p>TLS/SSL encryption use both symmetric and asymmetric keys to encrypt data in transit, and is used with the HTTP protocol for secure communications over a computer network.</p>
<h3 id="heading-tlsssl-encryption-explained">TLS/SSL Encryption Explained</h3>
<p>TSL (Transport Layer Security) and SSL (Secure Sockets Layer) are often used interchangeably to mean the same thing. But when people say SSL, they often mean TLS.</p>
<p>TLS is generally considered more secure than SSL due to several improvements made to the protocol, such as stronger cryptographic algorithms. Due to security concerns with SSL, most modern web browsers and applications have dropped support for SSL and only support TLS. As a result, TLS has become the standard for secure communication over the internet.</p>
<h3 id="heading-how-to-use-symmetric-and-asymmetric-encryption-at-the-same-time">How to Use Symmetric and Asymmetric Encryption at the Same Time</h3>
<p>Let's say you want to securely send a parcel to your friend. But you don’t want to keep using the special indestructible box that has two keyholes and two locks. It is expensive, heavy and impractical to use for frequent communications. You still want to use an indestructible box, but one that is simpler, with a single lock and key.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-14.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>However, if you are using a box with only a single lock and key, you now need to figure out how to securely share the key for that simpler box with your friend.</p>
<p>Since the same key is used to both open and lock it, you cant just send the key to your friend without somehow protecting it first. If the key is intercepted and a copy is taken by someone, they can now open your box and take what is inside.</p>
<p>How can you securely share this key with your friend so that you can use this simpler box for future communication?</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/04/image-15.png" alt="Image" width="600" height="400" loading="lazy"></p>
<ol>
<li><p>First, your friend sends the box with the two locks plus the public key used to lock it. But you don’t want to keep using this box. You will only use this box once – to transfer the key for another simpler box that you will use for future exchanges.</p>
</li>
<li><p>You place the master key that will be used in future exchanges inside this box and lock it with the public key sent by your friend.</p>
</li>
<li><p>You send the locked box which contains a copy of the master key inside back to your friend.</p>
</li>
<li><p>Your friend uses his private key to open the box. Now you both have the master key and can be sure no one else has it since it was sent in a secure box</p>
</li>
<li><p>All future items are then placed in this simpler box with a single lock and key which can be opened and locked using the master key you just sent to your friend.</p>
</li>
</ol>
<h3 id="heading-tlsssl-encryption-sequence">TLS/SSL Encryption Sequence</h3>
<p>The analogy in the previous section neatly maps to how TLS/SSL encryption actually works. But there are some prerequisite steps which I ignored in this analogy, like creating a TCP connection and the server sending its certificate (Steps 1 and 2 below).</p>
<p>Also, Step 6 is a simplification of the process. In reality, the master key is used to generate a further set of keys that the client and server will use to encrypt and decrypt messages and also to authenticate that the messages were indeed sent by the client and server.</p>
<p>To read more about the low level detail, I’d recommend Chapter 8 of "<a target="_blank" href="https://www.amazon.co.uk/Computer-Networking-Global-James-Kurose/dp/1292405465/ref=sr_1_1?keywords=computer+networking+a+top-down+approach&amp;qid=1680219419&amp;sprefix=computer+netw%2Caps%2C168&amp;sr=8-1">Computer Networking</a>" by Kurose &amp; Ross.</p>
<p>But, at a high level, the sequence is as follows:</p>
<ol>
<li><p>Client establishes TCP connection with the server</p>
</li>
<li><p>Client verifies that the server is who it says it is – server sends certificate which has the public key. The accompanying private key remains with the server.</p>
</li>
<li><p>Client creates a master secret key and uses the server's public key to encrypt it. This master secret key is a symmetric key so the same key is used for encryption and decryption.</p>
</li>
<li><p>Client sends the encrypted master secret key to the server.</p>
</li>
<li><p>Server decrypts the encrypted master key using its private key.</p>
</li>
<li><p>All future messages between client and server now use the symmetric master key to encrypt and decrypt messages.</p>
</li>
</ol>
<h2 id="heading-best-of-both-worlds">Best of Both Worlds</h2>
<p>Using both symmetric and asymmetric key encryption gives you the speed of symmetric key encryption without compromising on the extra security provided by asymmetric key encryption.</p>
<p>But nothing comes for free, of course. With TLS, there is an added layer of complexity since you need to first use asymmetric keys to establish a secure connection before exchanging the symmetric key for future communication.</p>
<p>So by using both symmetric and asymmetric encryption, TLS/SSL gets the best of both worlds with limited downsides.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Google Dorking for Penetration Testers — A Practical Tutorial ]]>
                </title>
                <description>
                    <![CDATA[ Every day, Google processes over 8.5 billion searches. We know how much we use Google daily. With the crawling capabilities of Google, it can also be a powerful tool for pen testers. Google can help us find exposed files, scripts and other critical r... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/google-dorking-for-pentesters-a-practical-tutorial/</link>
                <guid isPermaLink="false">66d035c7ba54db009200dc85</guid>
                
                    <category>
                        <![CDATA[ Google ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ penetration testing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Tue, 04 Apr 2023 21:10:01 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/dorks.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Every day, Google processes over 8.5 billion searches. We know how much we use Google daily.</p>
<p>With the crawling capabilities of Google, it can also be a powerful tool for pen testers. Google can help us find exposed files, scripts and other critical resources in web applications.</p>
<p>To find this type of sensitive information, hackers use specific search terms in Google. We call them Google Dorks.</p>
<p>Google Dorks are special search terms that help locate information which is not found through regular web searches.</p>
<p>In this article, we will look at what Google Dorks are and how they can help us in penetration testing.</p>
<h1 id="heading-what-are-google-dorks">What are Google Dorks?</h1>
<p>A Google Dork is a special search term. These terms, when used with regular search keywords, can help us discover hidden resources crawled by Google.</p>
<p>These resources include sensitive information such as usernames, passwords, credit card numbers, email addresses, shell scripts, user accounts, and so on.</p>
<p>These Dorks are not limited to Google. We can also use them with search engines like Bing and Yahoo. The results might vary, but they still serve the same purpose.</p>
<p>To harness the full potential of Google Dorking, we’ll need to master some specialized search operators. These operators will fine-tune our search results and help us find exactly what we are looking for.</p>
<p>Let’s try a few Google dorks.</p>
<h1 id="heading-common-google-dorks">Common Google Dorks</h1>
<p>Some of the common query operators in Google Dorking include search modifiers. These search modifiers allow us to find specific information that may not be accessible through traditional search methods.</p>
<p>Here are some of the most common operators used in Google Dorking.</p>
<h2 id="heading-intitle-operator">Intitle operator</h2>
<p>The “<strong>intitle</strong>” operator searches for web pages with specific words or phrases in the title tag. For instance, if you’re looking for pages that contain the phrase “password” and have “index of” in the title, you would use the search term:intitle:”index of” password.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/0*aGu8XsaRGj-LCmD9.png" alt="Image" width="600" height="400" loading="lazy">
<em>In title. Image by the author.</em></p>
<h2 id="heading-inurl-operator">Inurl operator</h2>
<p>The “<strong>inurl</strong>” operator searches for web pages that contain specific words or phrases in the URL. For example, if you’re looking for pages that contain “admin.php” in the URL, you would use the search term:inurl:admin.php.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/0*eQJJKQ2WwakLmMWC.png" alt="Image" width="600" height="400" loading="lazy">
<em>In url. Image by the author.</em></p>
<h2 id="heading-site-operator">Site operator</h2>
<p>The “<strong>site</strong>” operator allows you to search within a specific website or domain. For instance, if you’re looking for pages on the example.com domain that contain the word “Steganography”, you would use the search term:site:yeahhub.com “Steganography”</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/0*jvy2mkw49lQryy_r.png" alt="Image" width="600" height="400" loading="lazy">
<em>In site. Image by the author.</em></p>
<h2 id="heading-filetype-operator">Filetype operator</h2>
<p>The “<strong>filetype</strong>” operator allows you to search for specific file types, such as PDFs or Word documents. For example, if you’re looking for PDF files that contain the phrase “confidential report”, you would use the search term:filetype:pdf "Advanced Network Security"</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/0*oXNyJ4L02zdEXCqP.png" alt="Image" width="600" height="400" loading="lazy">
<em>Filetype. Image by the author.</em></p>
<h2 id="heading-intext-operator">Intext operator</h2>
<p>The “<strong>intext</strong>” operator searches for pages that contain specific words or phrases within the body of the page. For instance, if you’re looking for pages that contain both the words “login” and “password” within the body of the page, you would use the search term:intext:"about" contact.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/0*cLXuxHYh-XiwJSuC.png" alt="Image" width="600" height="400" loading="lazy">
<em>In text. Image by the author.</em></p>
<h2 id="heading-link-operator">Link operator</h2>
<p>The “<strong>link</strong>” operator searches for web pages that link to a specific URL. For example, if you’re looking for web pages that link to the example.com domain, you would use the search term:link:”example.com”</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/0*DYGNbQTE2DYRbmAM.png" alt="Image" width="600" height="400" loading="lazy">
<em>Link operator. Image by the author.</em></p>
<h2 id="heading-cache-operator">Cache operator</h2>
<p>The “<strong>cache</strong>” operator is used to retrieve the cached version of a web page. When you search for a website using Google, Google creates a cached version of that page in its system. This version can be useful if the original website is temporarily down or if you want to view an older version of the website.</p>
<p>Here is the syntax to find the cached version of yahoo.com.cache:https://www.yahoo.com</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/1*pJ888Ha57t-qrlF2ipSy4w.png" alt="Image" width="600" height="400" loading="lazy">
<em>Cached version of yahoo.com. Image by author.</em></p>
<h2 id="heading-related-operator">Related operator</h2>
<p>The “<strong>related</strong>” operator is used to find web pages that are related to a specific URL. Here is the syntax to use the “related” operator to find sites similar to yahoo.com.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/1*A1S-BCae_XJXYWpfz50eUA.png" alt="Image" width="600" height="400" loading="lazy">
<em>Related operator. Image by author.</em></p>
<p>By combining these operators in creative ways, you can find specific types of information on the web that can be useful for penetration testing and other purposes.</p>
<h1 id="heading-structure-of-query-operators">Structure of Query Operators</h1>
<p>Google Dorking query operators have a structure similar to regular Google search query operators. This technique involves using advanced operators and search queries to uncover information that is not typically available through regular searches.</p>
<p>The general structure of query operators in Google Dorking includes three elements:</p>
<ol>
<li><strong>Operator</strong>: A specific keyword or symbol that instructs Google what to search for. For instance, the “<strong>inurl</strong>” operator searches for pages that contain a particular keyword in their URL.</li>
<li><strong>Keyword:</strong> The search term or phrase that you want to find. If you are looking for a specific password file, then “password” is your keyword.</li>
<li><strong>Modifier:</strong> An additional search parameter that you can use to further refine your search. For example, the “<strong>filetype</strong>” modifier searches for a specific file type, such as a PDF.</li>
</ol>
<p>Here’s an example of a query operator structure in Google Dorking: intitle: “index of” site:example.com password filetype:pdf</p>
<p>This query uses the “<strong>intitle</strong>” operator to search for pages with “index of” in their title, the “site” operator to search within the example.com domain, the keyword “password,” and the “filetype” modifier to search for PDF files.</p>
<p>By utilizing query operators in Google Dorking, we can find useful and often vulnerable information that might not be accessible through regular searches.</p>
<h1 id="heading-google-hacking-database-ghdb">Google Hacking Database (GHDB)</h1>
<p><a target="_blank" href="https://www.exploit-db.com/google-hacking-database">The Google Hacking Database (GHDB)</a> is a compilation of search queries and query operators that help us in Google Dorking.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1050/1*ghTqBQgmfsmjgnl3T5QeKQ.png" alt="Image" width="600" height="400" loading="lazy">
<em>Google hacking database. Image generated by author.</em></p>
<p>Johnny Long, a well-known security researcher and author, established the GHDB. It has since become a valuable resource for security engineers like you and me.</p>
<p>The GHDB has several search queries and operators that can uncover numerous sensitive files, vulnerable web servers, and applications. It can also discover default login pages and credentials, as well as network and security devices that may be prone to attack.</p>
<p>GHDB is arranged into categories such as “Files containing passwords” “Vulnerable servers” “Footholds” and “Error Messages”. Each category contains several search queries and operators crafted to reveal specific information about a target.</p>
<p>Please note that search queries and operators in the GHDB might produce false positives or outdated information. Always verify the information obtained through these search operators.</p>
<h1 id="heading-a-dorking-scenario">A Dorking Scenario</h1>
<p>Let’s assume you have to conduct a pentesting audit for a client. Here is a sample dorking scenario.</p>
<ol>
<li>Use the <strong>“site”</strong> operator to limit your search to the company’s website: site:example.com. This returns all pages on the example.com website.</li>
<li>Use the <strong>“intitle”</strong> operator to search for pages containing specific keywords in the title: intitle:”login” site:example.com. This helps identify potential login pages vulnerable to attack.</li>
<li>Use the <strong>“filetype”</strong> operator to search for specific file types: filetype:pdf site:example.com. This helps identify potential documents or reports containing sensitive information.</li>
<li>Use the <strong>“inurl”</strong> operator to search for specific URLs: inurl:”admin” site:example.com. This helps identify potential administrative pages vulnerable to attack.</li>
<li>Use the <strong>“cache”</strong> operator to view the cached version of a webpage Google has indexed: cache:example.com/login.php. This provides access to the page contents even if the original page is removed or no longer accessible.</li>
<li>Use the <strong>“related”</strong> operator to find similar websites: related:example.com. This helps identify potential partners or third-party vendors with access to the company’s network.</li>
</ol>
<h1 id="heading-summary">Summary</h1>
<p>Google Dorking is a powerful technique that allows us to perform advanced searches on Google. We can use Google Dorks to find specific information and publicly exposed vulnerabilities. It is an essential tool in a pentester’s toolkit.</p>
<p>Google Hacking Database (GHDB) provides a collection of pre-defined Google Dorks. Given the harm that someone can cause using dorking, it is important to use it ethically and with permission. Ensure that you have permission and follow ethical guidelines when using dorking for security audits.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Encryption at Rest? Explained for Security Beginners ]]>
                </title>
                <description>
                    <![CDATA[ Encryption is a technique for secure communication that converts plain text into a coded form that can only be deciphered with a secret key. Let's explore some of encryption's fun bits. Encryption works by using an algorithm to convert plaintext into... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/encryption-at-rest/</link>
                <guid isPermaLink="false">66b995d8a3099de4654e61b0</guid>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Tue, 04 Apr 2023 15:49:01 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/pexels-cottonbro-studio-7319078.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Encryption is a technique for secure communication that converts plain text into a coded form that can only be deciphered with a secret key. Let's explore some of encryption's fun bits.</p>
<p>Encryption works by using an algorithm to convert plaintext into ciphertext, which is unreadable without a corresponding decryption key. </p>
<p>This article comes from <a target="_blank" href="https://www.udemy.com/course/complete-lpi-security-essentials-exam-study-guide/?referralCode=C2B6802EDB99578238B5">The Complete LPI Security Essentials Exam Study Guide</a>. You can also follow along with this video:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/kWBLfhf8eto" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>The encryption process takes the original data, and transforms it in a way that only someone with the correct decryption key can reverse the process and read the original data. This helps ensure that sensitive information is protected from unauthorized access or interception during transmission or storage.</p>
<h2 id="heading-understanding-encryption-tools">Understanding Encryption Tools</h2>
<p>Encryption at rest refers to the practice of protecting data that is stored on a device, such as a hard drive or a smartphone, by encoding it using encryption algorithms. The encrypted data can only be decrypted with the appropriate key, and this helps ensure that sensitive information remains confidential even if the device is lost or stolen. </p>
<p>This is a common security measure used to protect sensitive information such as credit card numbers, personal data, and confidential business information.</p>
<p>Password hashing is a technique for storing passwords in a secure manner by converting them into a cryptographic representation called a hash. The hash is created using a one-way function that transforms the password into a fixed-length string of characters that cannot be easily reversed to reveal the original password.</p>
<pre><code>$ echo -n mySecretPassword | sha256sum
<span class="hljs-number">2250e74</span>c6f823de9d70c2222802cd059dc970f56ed8d41d5d22d1a6d4a2ab66f  -
</code></pre><p>Salting is a security measure added to password hashing to increase its resilience against attacks. A salt is a random value that is generated for each password and combined with the password before it is hashed. </p>
<pre><code>$ openssl passwd -salt <span class="hljs-number">29</span> mytext
$<span class="hljs-number">1</span>$<span class="hljs-number">29</span>$WKQPJOxDf2nJLoPwT6cnz1
</code></pre><p>This results in a unique hash for each password, even if multiple users have the same password, making it much more difficult for an attacker to use pre-computed tables of hashes (such as rainbow tables) to crack the passwords. </p>
<p>When verifying a password, the salt is used to regenerate the hash, which is then compared to the stored hash to determine if the password is correct.</p>
<h2 id="heading-password-attack-tools">Password Attack Tools</h2>
<p>A rainbow table is a pre-computed table of hashes used to crack passwords by searching for a matching hash value. It is an optimization of a brute force attack that reduces the number of hashes that need to be calculated by reusing hashes computed for previous password guesses.</p>
<p>A Directory attack is a method of cracking passwords by using a large dictionary of words, phrases, and commonly used passwords to generate hashes and compare them to the target hashes. This type of attack is effective against weak passwords that are easily guessable.</p>
<p>A brute force attack is a way of cracking passwords by trying all possible combinations of characters until a match is found. It is a slow and resource-intensive method of cracking passwords, but it is effective against strong passwords that cannot be easily guessed. </p>
<p>Brute force attacks can be mitigated by using strong passwords, rate-limiting login attempts, and using encryption and hashing to store passwords securely.</p>
<h2 id="heading-symmetric-and-asymmetric-encryption">Symmetric and Asymmetric Encryption</h2>
<p>Symmetric cryptography, also known as shared-secret cryptography, is a type of encryption where the same key is used for both encryption and decryption of data. This means that both the sender and receiver of the data must have the same key and must keep it confidential. </p>
<p>Symmetric cryptography is fast and efficient but can be vulnerable if the key is compromised.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/slide-09.png" alt="Image" width="600" height="400" loading="lazy">
<em>Diagram showing how symmetric encryption works</em></p>
<p>Asymmetric cryptography, also known as public-key cryptography, uses a pair of keys, one for encryption and another for decryption. The encryption key, known as the public key, can be widely distributed, while the decryption key, known as the private key, is kept confidential. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/slide-10.png" alt="Image" width="600" height="400" loading="lazy">
<em>Diagram showing how asymmetric encryption works</em></p>
<p>Asymmetric cryptography is used for tasks such as digital signatures, key exchange, and data encryption, and is considered more secure than symmetric cryptography because the private key never needs to be transmitted or shared.</p>
<p>Hybrid cryptography is a combination of both symmetric and asymmetric cryptography. </p>
<p>In a typical hybrid encryption scheme, the data is encrypted using a symmetric algorithm, and the symmetric key is then encrypted using an asymmetric algorithm and sent to the recipient along with the encrypted data. The recipient uses their private key to decrypt the symmetric key, and then uses the symmetric key to decrypt the data. </p>
<p>Hybrid cryptography provides the security benefits of both symmetric and asymmetric cryptography, making it a commonly used encryption method.</p>
<h2 id="heading-public-key-infrastructure-pki">Public Key Infrastructure (PKI)</h2>
<p>PKI is a system for secure communication that uses a combination of public key cryptography, digital certificates, and certificate authorities (CAs) to authenticate the identity of parties involved in a communication and secure their communications.</p>
<p>Certificate Authorities (CAs) are organizations or entities that issue digital certificates, which are used to validate the identity of parties involved in a communication. </p>
<p>CAs act as trusted third parties that verify the identity of parties and issue certificates attesting to that identity. The certificate includes information such as the identity of the owner, the public key of the owner, and the digital signature of the CA.</p>
<p>Trusted Root-CAs are the highest level CAs in the PKI hierarchy. They are responsible for issuing certificates for intermediate CAs, who in turn issue certificates for end entities, such as individuals or organizations. </p>
<p>The trustworthiness of the entire PKI system is based on the trust in the root CAs. A trusted root CA is one that is widely recognized and trusted by users, systems, and applications. </p>
<p>The trusted root CA's certificate is usually pre-installed in software and devices, such as web browsers, to facilitate secure communication and verify the authenticity of digital certificates issued by other CAs.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>With what you've learned here, you're now ready to use encryption tools like <a target="_blank" href="https://www.veracrypt.fr/en/Home.html">VeraCrypt</a> and <a target="_blank" href="https://gnupg.org/">GnuPG</a> to protect the data you store on your local machines. You'll be able to properly assess the safety and integrity of the online and cloud storage platforms where you store data remotely.</p>
<p>This article and the accompanying video are excerpted from <a target="_blank" href="https://www.udemy.com/course/complete-lpi-security-essentials-exam-study-guide/?referralCode=C2B6802EDB99578238B5">my Complete LPI Security Essentials Exam Study Guide course</a>. And there's much more technology goodness available at <a target="_blank" href="https://bootstrap-it.com/">bootstrap-it.com</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Developers Can Prevent Fraud and Stop Scammers ]]>
                </title>
                <description>
                    <![CDATA[ By Dmitry Dragilev Online frauds and scams have shot past projections in the last decade, and no one seems to be immune to them—including developers.  The shift to serverless cloud management has opened doors for hackers to try new attack surfaces an... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-developers-can-prevent-fraud-and-stop-scammers/</link>
                <guid isPermaLink="false">66d45e3c36c45a88f96b7cd5</guid>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 20 Mar 2023 22:32:41 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/48332996261_4f1a1657fc_b.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dmitry Dragilev</p>
<p>Online frauds and scams have shot past projections in the last decade, and no one seems to be immune to them—including developers. </p>
<p>The shift to serverless cloud management has opened doors for hackers to try new attack surfaces and the impact is right in front of us. <a target="_blank" href="https://www.freecodecamp.org/news/what-is-devsecops/https://www.freecodecamp.org/news/what-is-devsecops/">90% of web applications are vulnerable to cybercriminals</a>, and a majority of these vulnerabilities can be traced back to direct dependencies.</p>
<p>Thanks to cloud migrations, DevOps teams can roll out product iterations faster and improve customer management KPIs. But this also means they lose control over custom code infrastructure and servers. Companies that have traded custom security for cloud efficiency are more susceptible to cybercriminals today.</p>
<p>In this article, we'll look into the most common scams faced by developers, how they work, and what developers can do to mitigate the risks.</p>
<h2 id="heading-what-is-a-fraud-or-scam">What is a Fraud or Scam?</h2>
<p>Fraud is the illegal attempt to deceive a person, entity, or organization to gain access to confidential assets. </p>
<p>Scams are the smaller steps that help criminals commit fraud and they almost always involve money. </p>
<p>If you have been scammed there's a good chance you've lost money. Frauds, however, may not always lead to financial ruin as the impact can be much larger than that.</p>
<p>DevOps teams are increasingly vulnerable to fraud and scams because these are built on deception and social engineering. Since access management is a major security pitfall of modern IT development, fraudsters look to access developers’ credentials to compromise systems and steal money and information.</p>
<h2 id="heading-four-common-scams-and-how-they-work">Four Common Scams and How They Work</h2>
<p>Hackers today use precise strategies to create the biggest impact. They have gone from “tried and tested” to highly targeted and innovative attacks that end up fooling even the most security-aware victims such as developers.</p>
<p>To better understand how these work here are a few examples:</p>
<h3 id="heading-1-ddos-attacks">1. DDos Attacks</h3>
<p>Distributed denial-of-service (DDoS) attacks are one of the most common types of cyberattacks that plague developers today. With a DDoS attack, criminals try to overwhelm a network or web application by sending a huge amount of access requests, effectively shutting it down. </p>
<p>Since most businesses today rely on their digital infrastructure to operate, an offline website or application at crucial moments can lead to massive loss—both financial and reputational.</p>
<p><a target="_blank" href="https://www.bigcommerce.com/blog/denial-of-service-attack/">DDoS attacks</a> use compromised machines and IoT devices as zombies (or bots) to send millions of pings within a short amount of time. Attackers can target the server architecture by spoofing SYN data packets, stress the software resources by using HTTP flood, or dump huge traffic on the website with DNS amplification.</p>
<p>Since it's difficult to detect botnet requests from authentic requests, victims often have a hard time separating the two. On top of that, the distributed nature of the attack means blocking off one IP address won't solve the issue.</p>
<p><img src="https://lh5.googleusercontent.com/JWZmINyPOstdWofeQ078TRQ8xDhYUzskB9-3RJpuSpyhhMpw-6JCMgucZ-3e1pC5pVTaThM7A6Kw-IgVToxVWCVEyGrcu-yJjvTYG4vDAZzsVxm9yjgpsVYdiYSA2wP80H6LB3eXzr6DJwFf1puTXeQ" alt="Image" width="1119" height="446" loading="lazy">
<em>Weird TTL responses with odd values which obviously tell you they did not come from the original server, but rather some intermediate device. <a target="_blank" href="https://blog.erratasec.com/2015/04/pin-pointing-chinas-attack-against.html">Source</a></em></p>
<p>One of the most famous examples of DDoS attacks was the 2015 attack on GitHub by Chinese attackers. It started with injecting browsers used to visit Baidu and Baidu analytics-enabled websites with JavaScript code run by a telecom company called China Unicom. </p>
<p>The malicious code created a botnet of affected browsers and triggered the browsers to send a massive amount of HTTP requests to specific GitHub pages. The attack lasted for five days and many parts of GitHub were inaccessible. </p>
<h3 id="heading-2-credit-card-scams">2. Credit Card Scams</h3>
<p>DevOps teams often have a lax attitude towards financial compliance, making them a gateway to credit card scams. These types of scams either look to get ahold of employee credit cards or gather enough data to carry out card-not-present (CNP) frauds.</p>
<p><a target="_blank" href="https://www.aura.com/learn/credit-card-scams">Credit card scams can happen in several ways</a> and attackers are still trying new methods to deceive victims. </p>
<p>It can start with simple shoulder surfing where an attacker monitors you entering the PIN or showing card details to advanced keyloggers and card skimmers placed at shady ATMs. Fake charities and rewards are also popular ways to get hold of credit card details. </p>
<p>On top of that, criminals can use personally identifiable information (PII) to apply for a new credit card or request updates to your old card and block it. They can go as far as intercepting cards from the mail or assaulting victims to steal credit cards.</p>
<p>Even if they don't get ahold of your card, CNP frauds allow them to make huge transactions online, which might ruin the victim’s credit score and put their finances in a tough spot.</p>
<h3 id="heading-3-sip-trunking-fraud">3. SIP Trunking Fraud</h3>
<p>Modern business communication relies on <a target="_blank" href="https://www.nextiva.com/products/voip-phone-system.html">VoIP phone systems</a> to reach customers, vendors, and stakeholders and uses omnichannel flexibility to improve productivity. It all sounds great on paper but VoIP used by small businesses often falls victim to SIP trunking fraud.</p>
<p>Session initiation protocol (SIP) trunk is the technology that connects a company's existing phone system or PBX with the cloud, allowing VoIP to work across the globe. It's a crucial piece of technology that is often exploited by hackers. Here's how it usually goes down:</p>
<ul>
<li>Cybercriminals use IP scanners to look for vulnerable phone systems to gain access to the SIP trunks</li>
<li>They either steal passwords or use brute force attacks on weak systems</li>
<li>Once they have the access, attackers often spoof caller IDs to extract sensitive data such as credit card and login details or eavesdrop on texts and calls on public IP connections.</li>
<li>Apart from this, attackers might commit toll fraud by rerouting calls to <a target="_blank" href="https://www.nextiva.com/blog/what-is-a-virtual-phone-number.html">virtual phone numbers</a> in premium domestic and international territories and stealing the revenue earned from those calls.</li>
</ul>
<p><img src="https://lh3.googleusercontent.com/qmcSLLBIb_MXtMDC-ajfsAKdfJ8bBkmJYHsQ3a3EoVXBLUy6dZZI7t4MivBQR01BoLZbxtp8WzHL82qHSP8iokj-8i28GGWj4mRpyerRL1ij1x0hZIexF-e0pDU6TpEBEuDORP2CoapU1FLQP0_4PY0" alt="Image" width="1024" height="476" loading="lazy">
<em>Twilio is flagging fraudulent calls by using their 3rd party anti-fraud database. <a target="_blank" href="https://www.twilio.com/blog/2018/03/how-to-protect-your-account-from-toll-fraud-with-voice-dialing-geo-permissions.html">Source</a></em></p>
<p>If SIP trunking fraud is left unchecked, a business can lose thousands of dollars within a few hours.</p>
<h3 id="heading-4-sim-swapping">4. SIM Swapping</h3>
<p>SIM swapping can happen to anyone and developers have no additional security against these types of scams. SIM swapping is convincing your network provider to transfer your SIM to their device, effectively taking over your phone number and everything tied to it.</p>
<p><a target="_blank" href="https://www.aura.com/learn/how-to-prevent-sim-swapping">SIM swapping doesn't happen in a vacuum</a>—it requires long-term planning and social engineering. Here's how it works:</p>
<ul>
<li>A scammer calls your SIM provider and requests to transfer the phone number because they claim the device is destroyed or stolen.</li>
<li>Now the representative asks for ID proof to authenticate the transfer and it usually requires personal information such as an address, email ID, IMEI, or last four digits of the credit card.</li>
<li>If the scammer can prove your identity to fool the operator, they can activate a new SIM in their phone.</li>
</ul>
<p>This is where long-term strategies come into play. Before executing a SIM swap, attackers use phishing emails, malware, and data breaches to collect snippets of personal data and piece them together to convince the SIM provider.</p>
<p><img src="https://lh6.googleusercontent.com/q6I7_Md5LIl7ladti5IWTOGlMD8nj2cHmBGOpH-Hcbm9LQm_QXTjIlgy5x1WqDZvBYM0n75XXqQiQB2BQccskFFAyGP16cn7-jcDkKx0mGJkAqcMSvI6NNTrHMHuIbqQmVSDIkTphkzgHOobLhi7VOs" alt="Image" width="1112" height="581" loading="lazy">
_Example of a SIM Swapping scam text message. <a target="_blank" href="https://www.phonearena.com/news/Cops-bust-gang-that-used-stolen-SIM-cards-to-access-bank-accounts_id107701">Source</a>_</p>
<p>A few years ago, a disgruntled T-Mobile employee exposed customer data to hackers who would swap out SIM and take over accounts.</p>
<p>Once the attackers have your SIM, they can bypass two-factor authentication (2FA) for all transactions, and get hold of your bank details, SSN, and personal media. SIM swap opens the floodgates to all kinds of crimes that require your phone number in the first place.</p>
<h2 id="heading-how-devops-can-prevent-fraud-and-scams">How DevOps Can Prevent Fraud and Scams</h2>
<p>Security risks come in abundance but developers are familiar with the concepts. By following a few steps you can detect, address, and mitigate most of these scams.</p>
<h3 id="heading-how-to-prevent-ddos-attacks">How to Prevent DDoS Attacks</h3>
<p>DDoS attacks are hard to distinguish without harming real traffic, which makes mitigation a difficult job. But you still try a few methods.</p>
<h4 id="heading-1-detect-signs-of-a-ddos-attack">1. Detect signs of a DDos attack</h4>
<p>Know the symptoms of DDoS to detect attacks early on. If an online asset is suddenly slow or unresponsive, you might have to look for DDoS signs. These include:</p>
<ul>
<li>an unusually high volume of traffic at odd hours of the day</li>
<li>hordes of requests coming from the same IP address, location, device, or browser, and targeting a specific page or part of the application.</li>
</ul>
<p>You can react quickly if you have monitored and documented the usual traffic patterns of your company.</p>
<h4 id="heading-2-deploy-anti-ddos-measures">2. Deploy anti-DDoS measures.</h4>
<p>Start by using hardware and applications that are built to prevent DDoS attempts and restore assets, <a target="_blank" href="https://www.freecodecamp.org/news/how-to-manage-data-storage/">decentralizing data centers and servers</a>, using a web application firewall (WAF), and migrating to the cloud to increase bandwidth. </p>
<p>AWS Shield Advanced is an easy-to-configure managed DDoS protection service that can detect and mitigate large-scale and complicated attacks. </p>
<p>Apart from using anti-DDoS tools, you should also close <a target="_blank" href="https://www.algosec.com/resources/security-policy/">security loopholes in your network</a> and practice cyber hygiene daily.</p>
<p><img src="https://lh3.googleusercontent.com/KEsXtxDCDaRlXcQkDNq8AKHzcnIqvZfiHkKS2Sq0iXgmZ-myJ4aob6FLYf_lDWj3X_NhTsZKVC28wiXsF4Y26VSdpMJ4pc4gjPDP4VC9Xt7fdSnHkDEi5EQuSz7UbH-PbmER46qo-0AepFMsOnqK-rU" alt="Image" width="1600" height="1017" loading="lazy">
<em>Example of AWS configuration for DDoS mitigation. <a target="_blank" href="https://www.youtube.com/watch?v=hyGuV2e8SDw">Source</a></em></p>
<h4 id="heading-3-have-a-ddos-response-plan-in-place-to-prevent-further-damage">3. Have a DDoS response plan in place to prevent further damage.</h4>
<p>This should include documented steps, a well-prepared team, and clear communication channels for internal and external stakeholders. </p>
<p>Modern multi-factor DDoS attacks combine multiple pathways so the more complex and thorough your plans are the better you can protect the company.</p>
<h3 id="heading-how-to-prevent-sip-trunking-scams">How to Prevent SIP Trunking Scams</h3>
<p>SIP trunking is a common method of phone fraud, but you have some weapons in your armory to prevent these.</p>
<h4 id="heading-1-set-up-a-maximum-default-rate-for-outbound-calls-to-prevent-toll-fraud">1. Set up a maximum default rate for outbound calls to prevent toll fraud.</h4>
<p>When you set a limit for the number of calls, you'll be notified if your business crosses that threshold—allowing you to monitor calls made by hackers.</p>
<p>On top of that, use a solid <a target="_blank" href="https://www.nextiva.com/solutions/small-business-phone-service.html">VoIP service</a> to identify outbound and inbound calls and log as much information as possible. Hackers will call to and from random numbers so it becomes easier for you to set up call barring for suspicious numbers.</p>
<p><img src="https://lh5.googleusercontent.com/49d4N6OJbwXWHNYsTiVUDk4WynrVv0O7tN3kD6aGB5B_-67KAaDnj2ODAQYzNQcXOX881MO0mbNPDh2vbDh819n4_KTI57AfkkiXTnrUsokQYH19ued4tTSNtHPVSxX4SU9-Kv2VO7ctjd2JWxXQkFA" alt="Image" width="1230" height="744" loading="lazy">
<em>VOIP vendor settings to disallow inbound calls which have characterists of robocalls. <a target="_blank" href="https://telnyx.com/resources/add-rate-limits-outbound-profiles">Source</a></em></p>
<h4 id="heading-2-activate-ip-based-authentication-to-manage-network-access">2. Activate IP-based authentication to manage network access.</h4>
<p>With this enabled, users would need to be part of your network to make and receive calls. Even though IP addresses are not completely hidden, you'll be notified of any effort to breach your network. By mandating a static IP address, you can easily set up IP-based authentication and monitor calls.</p>
<h4 id="heading-3-reinforce-pbx-security">3. Reinforce PBX security.</h4>
<p>You can protect your phone system by using new and complex passwords, regularly changing and storing them safely, properly installing SBC configuration, and using TLS and SRTP for superior encryptions. On top of that, you should also restrict access to hardware to prevent data breaches.</p>
<h3 id="heading-how-to-prevent-credit-card-scams">How to Prevent Credit Card Scams</h3>
<p>Credit card scams can open Pandora's box and as a developer, you should be wary of the consequences. Here are some steps you can take to prevent credit card scams:</p>
<h4 id="heading-1-employees-using-company-credit-cards-are-the-easiest-victims-of-scams">1. Employees using company credit cards are the easiest victims of scams.</h4>
<p>You can help them mitigate the risks with training. A series of training modules and frequent seminars should include identifying ways credit card details can be stolen (as discussed above) and quickly acting in case of theft. </p>
<p>These should also encourage employees to access only HTTPS websites, use VPNs every time they use personal devices or public WiFi, and help them identify malware and phishing attempts. </p>
<p>On top of that, you should use an <a target="_blank" href="https://www.aura.com/learn/how-much-does-identity-theft-protection-cost">identity theft protection service</a> to limit the consequences of credit card scams.</p>
<h4 id="heading-2-as-a-developer-youre-bound-by-compliance-standards-and-ethics-to-secure-the-credit-card-details-of-employees-and-customers">2. As a developer, you're bound by compliance standards (and ethics) to secure the credit card details of employees and customers.</h4>
<p>While writing code for software meant to process and store credit cards, you should distribute duties to protect yourself and the business. Not many developers follow the PCI DSS guidelines regarding this and trap themselves in compliance red tape.</p>
<p><a target="_blank" href="https://www.pcisecuritystandards.org/resources-overview/">PCI DSS</a> sections 6,7 and 8 clearly lays out third-party code review rules along with role and access management. Following compliance standards and leaving access keys to admin are best practices to mitigate potential credit card scams.</p>
<h3 id="heading-how-to-prevent-sim-swapping">How to Prevent SIM Swapping</h3>
<p>SIM swapping starts long before convincing SIM providers to activate a new SIM which is why you have to take several measures:</p>
<h4 id="heading-1-phishing-and-other-social-engineering-methods-are-used-to-mimic-you-so-be-wary-of-these-crimes">1. Phishing and other social engineering methods are used to mimic you, so be wary of these crimes.</h4>
<p>Be on the lookout for <a target="_blank" href="https://www.freecodecamp.org/news/how-to-recognize-phishing-email/">phishing emails</a> and SMSs, malware injections, compromised websites, and fake calls that coax you into sharing personal details such as birthdays, physical and email addresses, and SSNs. Scammers use this information while calling your operator. </p>
<p>Another way you can prevent this is by limiting how much personal data you share online in the first place. Here’s an example of a nicely crafted phishing email impersonating PayPal. All you have to do is check the sender’s address to find the scam</p>
<p><img src="https://lh6.googleusercontent.com/loP48E4iNW0LGxX73HUtt-sA_Wzx2Fxq2WzYSY0BQW_m1mhZF6Li2SGfvgsbeIzafSiHzoldzX7CXhq_Vuup9hq4inQdgOJ1VGYfZj5oV8RuKQ1tkaFt1pQEHvvMONjt92FynXRpm4QyvtqQbIRwQck" alt="Image" width="1423" height="1600" loading="lazy">
<em>Example of a Paypal Scam. <a target="_blank" href="https://www.pickr.com.au/how-to/2021/how-to-spot-a-paypal-phishing-email/">Source</a></em></p>
<h4 id="heading-2-dont-make-your-phone-number-the-central-part-of-your-security">2. Don't make your phone number the central part of your security.</h4>
<p>Since SMS is not a secure mode of 2FA in case of device theft and SIM swapping, use biometrics such as fingerprint or face IDs and authentication apps such as Authy to <a target="_blank" href="https://www.freecodecamp.org/news/user-authentication-methods-explained/">protect 2FAs</a>. </p>
<p>Speaking of third-party apps, you should also use a password manager to create and maintain unique, complex, and 14-character-long alphanumeric passwords to make sure attackers cannot use your personal information to guesstimate logins.</p>
<h4 id="heading-3-activate-alerts-so-that-banks-can-monitor-when-your-sim-is-reactivated-on-an-unknown-device">3. Activate alerts so that banks can monitor when your SIM is reactivated on an unknown device.</h4>
<p>Work with businesses that use callbacks to verify identities for transactions and don't forget to activate the PIN lock by the carrier to prevent unauthorized porting.</p>
<h2 id="heading-final-word">Final Word</h2>
<p>Cybercrimes and social engineering tactics have grown by leaps and bounds and developers working on critical projects must make sure they don't become a security liability. </p>
<p>By following the above steps you can protect your employer, colleagues, and yourself from nasty surprises.   </p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
