<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Posts on Hands On Cybersecurity Learning Blog</title>
    <link>https://rnayaksec.github.io/posts/</link>
    <description>Recent content in Posts on Hands On Cybersecurity Learning Blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <copyright>© Rohit Nayak</copyright>
    <lastBuildDate>Thu, 05 Dec 2024 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://rnayaksec.github.io/posts/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Crypto Lab 4- Key Exchange</title>
      <link>https://rnayaksec.github.io/posts/keyexchange/</link>
      <pubDate>Thu, 05 Dec 2024 00:00:00 +0000</pubDate>
      <guid>https://rnayaksec.github.io/posts/keyexchange/</guid>
      <description>&lt;p&gt;Diffie-Hellman key exchange is a method that allows two parties to establish a shared secret over an insecure channel. Here&amp;rsquo;s how you can perform a basic Diffie-Hellman key exchange using OpenSSL on Linux:&lt;/p&gt;&#xA;&lt;h3 id=&#34;step-by-step-demo&#34;&gt;Step-by-Step Demo&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Generate Diffie-Hellman Parameters&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;openssl dhparam -out dhparam.pem &lt;span style=&#34;color:#ae81ff&#34;&gt;2048&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;2&#34;&gt;&#xA;&lt;li&gt;&lt;strong&gt;Generate Private Keys for Both Parties&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;For Party A&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;openssl genpkey -paramfile dhparam.pem -out privateA.pem&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;For Party B&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;openssl genpkey -paramfile dhparam.pem -out privateB.pem&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Extract Public Keys from the Private Keys&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;For Party A&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;openssl pkey -in privateA.pem -pubout -out publicA.pem&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;For Party B&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  openssl pkey -in privateB.pem -pubout -out publicB.pem&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Generate the Shared Secret&lt;/strong&gt;:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;For Party A (using Party B&amp;rsquo;s public key)&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;openssl pkeyutl -derive -inkey privateA.pem -peerkey publicB.pem -out shared_secret_A.bin&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;For Party B (using Party A&amp;rsquo;s public key)&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     openssl pkeyutl -derive -inkey privateB.pem -peerkey publicA.pem -out shared_secret_B.bin&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&#34;2&#34;&gt;&#xA;&lt;li&gt;&lt;strong&gt;Verify the Shared Secrets Match&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   diff shared_secret_A.bin shared_secret_B.bin &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Shared secrets match!&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;||&lt;/span&gt; echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Shared secrets do not match!&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;explanation&#34;&gt;Explanation&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Generates Diffie-Hellman parameters (a shared foundation) which both parties use.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Each party generates their private keys using the shared parameters.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Extracts public keys from the private keys to be shared with the other party.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Each party generates a shared secret using their private key and the other party&amp;rsquo;s public key.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Verifies that both parties have derived the same shared secret.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;This demonstration helps you understand the process of establishing a shared secret securely. If you have more questions or need further details, feel free to ask!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Crypto Lab 3 - Using Digital Signatures</title>
      <link>https://rnayaksec.github.io/posts/digisign/</link>
      <pubDate>Wed, 04 Dec 2024 00:00:00 +0000</pubDate>
      <guid>https://rnayaksec.github.io/posts/digisign/</guid>
      <description>&lt;p&gt;Digital signatures provide an electronic counterpart to physical signatures, using asymmetric cryptography to achieve the following&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Authenticati&lt;/strong&gt;on**: The person owning the public key used to sign the message is the one who signed it.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Integrity&lt;/strong&gt;: The message was not altered after being signed.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Non-repudiation&lt;/strong&gt;: The sender can prove these facts to a third party if necessary.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Behind the scenes, digital signatures depend on two things:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A collision-resistant &lt;strong&gt;hash function&lt;/strong&gt; that ensures no two inputs produce the same output.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Asymmetric key pair&lt;/strong&gt;: Anything encrypted with one key can only be decrypted with the other key from the pair.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Let’s walk through an example of using digital signatures on the Linux command line involving two users, mikey and bart, using &lt;code&gt;gpg&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Crypto Lab 2 - Using Asymmetric keys</title>
      <link>https://rnayaksec.github.io/posts/asymmetric/</link>
      <pubDate>Tue, 03 Dec 2024 00:00:00 +0000</pubDate>
      <guid>https://rnayaksec.github.io/posts/asymmetric/</guid>
      <description>&lt;p&gt;Asymmetric encryption, also known as public key cryptography, uses a pair of keys: a public key for encryption and a private key for decryption. Each user has a key pair, and anything encrypted with one key can be decrypted with the other key from the same pair.&lt;/p&gt;&#xA;&lt;p&gt;Please refer to &lt;a href=&#34;https://rnayaksec.github.io/posts/linux_prereq_crypto.md&#34;&gt;pre-requisite&lt;/a&gt; for this blog to ensure that you have two users setup on Linux.&lt;/p&gt;&#xA;&lt;h3 id=&#34;scenario&#34;&gt;Scenario&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;mikey wants to send an encrypted file to bart.&lt;/li&gt;&#xA;&lt;li&gt;mikey uses bart’s public key to encrypt the file.&lt;/li&gt;&#xA;&lt;li&gt;bart uses his private key to decrypt the file.&lt;/li&gt;&#xA;&lt;li&gt;The file to be encrypted is &lt;code&gt;turing_bio&lt;/code&gt; stored at &lt;code&gt;/srv/shared&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;barts-side-generating-the-keys&#34;&gt;bart’s Side (Generating the keys)&lt;/h3&gt;&#xA;&lt;p&gt;bart generates a key pair (public and private keys):&lt;/p&gt;</description>
    </item>
    <item>
      <title>Crypto Lab 1 - Using Symmetric keys</title>
      <link>https://rnayaksec.github.io/posts/symmetric/</link>
      <pubDate>Mon, 02 Dec 2024 00:00:00 +0000</pubDate>
      <guid>https://rnayaksec.github.io/posts/symmetric/</guid>
      <description>&lt;p&gt;Symmetric encryption, also known as shared secret encryption, uses the same key for both encryption and decryption. If one user encrypts a message with a secret key, the recipient must use the same key to decrypt it.&lt;/p&gt;&#xA;&lt;p&gt;Let’s walk through an example of symmetric key encryption on the Linux command line involving two users, mikey and bart, using gpg . In this case the shared key is the passphrase used to encrypt and decrypt.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Linux Basics - Adding users and groups</title>
      <link>https://rnayaksec.github.io/posts/linux_prereq_crypto/</link>
      <pubDate>Sun, 01 Dec 2024 00:00:00 +0000</pubDate>
      <guid>https://rnayaksec.github.io/posts/linux_prereq_crypto/</guid>
      <description>&lt;p&gt;This short introductory post will walk you through adding a user, creating a group, adding the user to the group and sudoers, and setting up a shared folder with proper permissions on Ubuntu Linux.&lt;/p&gt;&#xA;&lt;p&gt;The end goal is to end up with two user who can play the role of Alice and Bob as is typically the case for lot of cryptographic operations.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;[! IMPORTANT]&#xA;This blog assumes you already are logged into Ubuntu Linux with one user and all we are doing here is creating a second one. Alternately you can reuse the same script and create two distinct users if you wish to do so.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
