<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Özgün Kültekin on Medium]]></title>
        <description><![CDATA[Stories by Özgün Kültekin on Medium]]></description>
        <link>https://medium.com/@ozgunkultekin?source=rss-da182ca030a0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6A0xWZKeChNZpONlI2RBng.jpeg</url>
            <title>Stories by Özgün Kültekin on Medium</title>
            <link>https://medium.com/@ozgunkultekin?source=rss-da182ca030a0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 00:20:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ozgunkultekin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Phisher’s Playbook: Part 1 — Creating a 10/10 Phishing Mail]]></title>
            <link>https://ozgunkultekin.medium.com/the-phishers-playbook-part-1-creating-a-10-10-phishing-mail-3f7f99c8243?source=rss-da182ca030a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f7f99c8243</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[phishing]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[Özgün Kültekin]]></dc:creator>
            <pubDate>Sun, 16 Jul 2023 17:55:18 GMT</pubDate>
            <atom:updated>2023-12-24T11:18:18.718Z</atom:updated>
            <content:encoded><![CDATA[<h3>Phisher’s Playbook: Creating a 10/10 Phishing Mail</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*yLkwN-IixTxXE4Cg0dFQnw.png" /></figure><h3>Welcome to the Phisher’s Playbook</h3><p>In this thrilling series, we will discover the techniques behind crafting phishing emails, aiming to achieve a perfect<strong> 10/10</strong> score on mail score testers 💯.</p><p>With my current role as an Offensive Security Engineer, I’ve been actively involved in conducting Red Team Campaigns, continuously improving my skills and gaining valuable knowledge. Now, I’m excited to pass on my firsthand experiences to you as we begin to this adventure together.</p><p>Throughout this series, I’ll provide you with every detail and key point I’ve encountered while manipulating the complexities of email security. Our focus will be on using Postfix as the Mail Transfer Agent (MTA) -or basically as the SMTP Server-.</p><p>To ensure our success, we’ll put our crafted emails to the test using online mail score testers. These tools will help us evaluate the effectiveness of our techniques and provide valuable feedback to fine-tune our approaches. By the end of this series, you’ll have the knowledge and skills to send a phishing email that not only achieves a perfect 10/10 score but also manages to land in the inbox of even the most vigilant email providers like Gmail 📬.</p><p>So fasten your seat belts and get ready to deceive and outsmart even the most cautious recipients. Let’s dive in and master the art of creating a phishing email!</p><p>Note: The techniques and knowledge shared in this series are intended for educational purposes only. It is essential to understand the ethical implications of email phishing and to always abide by legal and responsible practices 🥷.</p><h3>1- Infrastructure details &amp; installing Postfix</h3><p>In this section, we’ll cover the essential elements of getting your email infrastructure up and running, beginning with the initial installation of Postfix.</p><p>For the purposes of this demonstration, we’ll be using Google Cloud Platform (GCP) with a virtual machine instance running Ubuntu 22.04 x86/64.</p><p>Moreover, ensure you have a domain name to serve as the sender for your emails. For the purpose of this article, I have chosen the domain <strong>ozgun.zip</strong> and managed it via Cloudflare.</p><p>And yes, we can even do all of these using <strong>.zip</strong> TLD. How? Here is the <a href="https://github.com/apache/spamassassin/blob/39ea11b27b55f99a945d2542779175d393d35334/rulesrc/sandbox/pds/20_ntld.cf">untrusted TLD</a>’s shared by widely used open-source anti-spam platform SpamAssassin. They still did not label <strong>.zip</strong> as untrusted 🤡</p><p>With your virtual machine up and running, you can proceed with the installation of Postfix. Open a terminal session on your Ubuntu instance and enter the following command to update the package repository &amp; install Postfix:</p><pre>sudo apt update &amp;&amp; sudo apt install -y postfix</pre><p>During the installation, you will be prompted to choose the type of mail server configuration. Select “Internet Site” and press Enter. Next, provide the fully qualified domain name (FQDN) for your email server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*Zcl2tA8XTVGq6lefmIoO4Q.png" /><figcaption>Postfix coniguration</figcaption></figure><p>Next, let’s update the /etc/postfix/main.cf file by setting the <strong>myhostname</strong> field to your fully-qualified domain name (FQDN). This field specifies the FQDN of the machine running the Postfix system.</p><blockquote>By default, the <strong>myhostname</strong> parameter is set to the local machine name. However, if your local machine name is not in fully-qualified domain name form or if Postfix is running on a virtual interface, you must specify the FQDN that the mail system should use.</blockquote><p>In our case, we can set the <strong>myhostname </strong>field as <strong>mail.ozgun.zip</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6SUsaJfFamH3HVtCP4zzhw.png" /><figcaption>myhostname field in main.cf</figcaption></figure><p>Secondly, open the /etc/hostname file with a text editor and set the hostname to match your Postfix configuration. You can just specify the hostname without the domain. Therefore, you should set the hostname in the /etc/hostname file as “<strong>mail”</strong> (without the “.ozgun.zip” domain).</p><blockquote>It ensures consistency between the system’s hostname and the hostname used by the mail server. When these values match, it avoids confusion and potential issues when sending and receiving emails. This consistency helps in smooth email delivery, reduces potential issues, and ensures the proper functioning of various services and protocols.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y8pWwr0V3QacLNlyc2bjbA.png" /><figcaption>hostname change</figcaption></figure><p>As it can be seen from the above screenshot, our hostname field still seems “phishersplaybook”. We need to restart the system after modifying the hostname to ensure that the new hostname is properly initialized and propagated throughout the system.</p><p>Adding the “<strong>mail.ozgun.zip</strong>” and “<strong>mail</strong>” values to your /etc/hosts file is an optional step that can provide benefits such as bypassing DNS lookups for local connections and aiding in local hostname resolution. Although not strictly required, it is considered a good practice. Doing this can potentially enhance performance and streamline local network communication.</p><p>By adding these values in /etc/hosts file -before the <strong>localhost</strong>-, we can send mails without explicitly stating sender.</p><p>After the reboot, we should observe that our hostname has been updated. At this stage, our objective should be reflected in the following file configurations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*YChHeIC5ffyMmAu76K8eOA.png" /><figcaption>config check</figcaption></figure><p>/etc/mailname part should already be changed automatically to the same domain provided in the Postfix installation.</p><h3>First mail -&gt; 1.3/10:</h3><p>It is time to send our very first email!</p><p>I will be using <a href="https://www.mail-tester.com/">https://www.mail-tester.com</a> to test our email score. But there are plenty of other cool alternatives out there if you want to mix it up a bit.</p><p>Just a heads up, the changes we’ve made so far won’t impact the score yet. Our Postfix server isn’t aware that we truly own <strong>ozgun.zip</strong> because we haven’t set up any DNS records. So, it is going to be a slightly dubious email experience.</p><p>We will simply use <strong>mailx</strong> for that purpose:</p><pre>sudo apt install -y mailutils</pre><p>Send an example mail:</p><pre>echo &quot;our first untrustworthy email&quot; | mailx -s &quot;no subject&quot; -r test@ozgun.zip &lt;code&gt;.mail-tester.com<br><br># You can change the &quot;From&quot; part via &quot;-r&quot; parameter.<br># -r &quot;ozgun@ozgun.ozgun&quot; will also work and get a nice 0 score :)</pre><p>And the perfect result!:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIa-FY8Cpe9Y8PY8NBpoeA.png" /><figcaption>1st mail test result</figcaption></figure><p>As it’s been said, our email may never see the light of an inbox.</p><h3>2- Setting initial DNS records</h3><p>Now it’s time to take things up a notch and boost our server’s reliability! We’ll do this by adding an <strong>A</strong> record and <strong>MX</strong> record.</p><p>This move also proves that we truly own the domain.</p><h4>A Record:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rLWvuU9LF57FxLbKiGezkw.png" /><figcaption>A record on CF</figcaption></figure><p>Our A mail server (<strong>mail.ozgun.zip</strong>) is now directing to our Postfix GCP instance.</p><h4>MX Record:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6dzKr4Aif9BLgqGEQ-lSng.png" /><figcaption>MX record on CF</figcaption></figure><p>By configuring this MX record, any emails sent from <strong>ozgun.zip</strong> will be seamlessly handled by our GCP instance, <strong>mail.ozgun.zip</strong>. That means, now we can send mails with specifying sender as &lt;username&gt;@ozgun.zip.</p><h3>Second mail -&gt; 5.8/10:</h3><p>This time, because we have <strong>MX</strong> record, we’ll make sure to explicitly specify the sender/return address for our email.</p><pre>echo &quot;our second untrustworthy email&quot; | mailx -s &quot;no subject 2&quot; -r &quot;test@ozgun.zip&quot; &lt;code&gt;@srv1.mail-tester.com</pre><p>And we are inching closer to perfection!:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFNwIssiiK1cNwcsrpgc4g.png" /><figcaption>2nd mail test result</figcaption></figure><p>We have increased our score by making the following fields ticked:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpP_jDIGz6bY7E1O8fDwXg.png" /><figcaption>mail score improvement</figcaption></figure><h3>3- Creating an SPF record:</h3><p>Firstly, why do we need that?</p><p>An SPF record on your Postfix server is like a reliability superhero for your emails. It acts as a defender, ensuring that only authorized servers can send messages on your behalf. By including an SPF record, you reduce the risk of email impersonation and make your messages more trustworthy. It’s like adding a secret code that tells the world, “Hey, this email is legit!”</p><p>And more importantly, many mailboxes and <strong>email security gateways</strong> of companies do perform SPF checks as part of their email filtering and security measures. When an email is received, the recipient’s mail server or security gateway may query the SPF record of the sender’s domain to verify if the originating server is authorized to send emails on behalf of that domain. If the SPF check fails or no SPF record is found, it could result in the email being flagged as suspicious or potentially rejected by the receiving system.</p><p>I suppose that drives the message home, doesn’t it?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F1pK9NBqJVjU7m%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F1pK9NBqJVjU7m%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F1pK9NBqJVjU7m%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="198" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0c31403ed79c15265f668707d8da354/href">https://medium.com/media/a0c31403ed79c15265f668707d8da354/href</a></iframe><p>Creating an SPF record is a breeze — simply add the following DNS record:</p><pre>TXT    @    v=spf1 mx ~all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3DsPRpCr5KcAihF-hcivLQ.png" /><figcaption>SPF TXT record</figcaption></figure><p><strong>v=spf1</strong> denotes the version of SPF.</p><p><strong>mx</strong> allows the domain’s MX records to be designated as authorized senders for the domain. We might want to use other server’s MX as <strong>include:_spf.example.com</strong></p><p>The “<strong>~all</strong>” qualifier specifies the policy for all other hosts that are not explicitly defined. In this case, it suggests a soft fail, which means the server should still accept the email but may flag it as potentially suspicious. Alternatives are “<strong>-all</strong>” (hard fail) and “<strong>+all</strong>” (allow all).</p><h4>(Optional) SPF policy daemon configuration:</h4><p>In that step, you can configure your Postfix server to check SPF on incoming emails and reject emails which are unauthorized.</p><p>However, in this particular scenario where we are the attackers, our objective is solely to send emails. We don’t expect to receive any emails in return. Therefore, if there are no plans to retrieve emails from the target you’ve phished, feel free to skip this part.</p><p>Install the Postfix policy daemon for SPF checking:</p><pre>sudo apt install postfix-policyd-spf-python</pre><p>Now it’s time to instruct Postfix to start the SPF policy daemon alongside the Postfix service itself. Add the following lines to <strong>/etc/postfix/master.cf:</strong></p><pre>policyd-spf  unix  -       n       n       -       0       spawn<br>    user=policyd-spf argv=/usr/bin/policyd-spf</pre><p>We will provide Postfix with instructions to perform SPF checks on incoming emails and reject any emails that are unauthorized. Add the following lines to <strong>/etc/postfix/main.cf</strong>:</p><pre>policyd-spf_time_limit = 3600<br>smtpd_recipient_restrictions =<br>   permit_mynetworks,<br>   permit_sasl_authenticated,<br>   reject_unauth_destination,<br>   check_policy_service unix:private/policyd-spf</pre><p><strong>policyd-spf_time_limit</strong> defines the time limit, in seconds, for the SPF policy daemon to process SPF checks for an email. If the SPF check takes longer than the specified time, it may result in a timeout.</p><p><strong>smtpd_recipient_restrictions</strong> defines the restrictions applied to incoming emails when the Postfix SMTP server receives them. No need to dive into details, they are the most common restrictions.</p><p>After all of these configurations, we need to restart the Postfix service:</p><pre>sudo systemctl restart postfix</pre><h3>Third mail -&gt; 8.6/10:</h3><p>Just like before, we sent an email from <strong>test@ozgun.zip</strong> and guess what? We received an impressive score of 8.6! Way to go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5NDYq5nUkh9hUrGlxHU-Gg.png" /><figcaption>3rd mail test result</figcaption></figure><h3>4- Creating a DKIM record:</h3><p>Let’s explain DKIM record with an example first:</p><p>DKIM (DomainKeys Identified Mail) is like a secret code that makes your emails more trustworthy and ensures they arrive at their destination intact. It’s a digital signature that you add to your outgoing emails to prove they’re legit.</p><p>Here’s how it works: Let’s say you send an email from <strong>test@ozgun.zip</strong> Before it’s sent, your email server signs it with a special key, creating a unique digital signature. This signature is then attached to the email.</p><p>When the recipient’s email server gets your email, it checks the DKIM record in the DNS for <strong>ozgun.zip</strong>. The DKIM record contains the public key needed to verify the signature.</p><p>Using the public key, the recipient’s server unlocks the digital signature and checks if it matches the content of the email. If it does, it knows the email is genuine, unaltered, and from a trusted source like you. Awesome, right?</p><p>DKIM helps protect against sneaky scammers trying to trick people with fake emails. Oh my goodness, who are these evil people! 👀</p><p>Unlike SPF, the level of DKIM record checking may not always be as strict. While DKIM provides an additional layer of email authentication, some email gateway solutions may not consistently perform DKIM checks. Nonetheless, configuring DKIM is recommended for optimal email security and delivery.</p><h4>DKIM installation &amp; configuration:</h4><p>To get started, let’s install the necessary tools for OpenDKIM:</p><pre>sudo apt install opendkim opendkim-tools</pre><p>By adding the postfix user to the opendkim group, you ensure that Postfix has the necessary privileges to access the OpenDKIM service and perform DKIM signing or verification of outgoing and incoming emails:</p><pre>sudo gpasswd -a postfix opendkim</pre><p>We need the following changes on <strong>/etc/opendkim.conf:</strong></p><pre># Add the following line under the -&gt; Syslog   yes<br>LogWhy   yes</pre><p>Enabling LogWhy yes helps with troubleshooting and understanding the DKIM verification process</p><pre># Uncomment the following lines and change Canonicalization as the following:<br>Canonicalization       relaxed/simple<br>Mode                   sv<br>SubDomains             no</pre><p>For canonicalization, “/’ separates the header/body part of the email. The relaxed canonicalization algorithm slightly modifies the email content and headers to ensure consistent DKIM signature generation, while the simple canonicalization algorithm preserves the original structure without modifications.</p><p>The “sv” mode stands for “signing and verifying.” This mode enables OpenDKIM to both sign outgoing emails with DKIM signatures and verify DKIM signatures of incoming emails.</p><p>SubDomains: The “no” setting indicates that DKIM signing and verification will not be automatically applied to subdomains of the signing domain.</p><pre># Add the following lines:<br>AutoRestart             yes<br>AutoRestartRate         10/1M<br>Background              yes<br>DNSTimeout              5<br>SignatureAlgorithm      rsa-sha256</pre><ol><li>AutoRestart: Enables automatic restart of OpenDKIM in case of issues or crashes.</li><li>AutoRestartRate: Specifies the rate at which OpenDKIM restarts.</li><li>Background: Allows OpenDKIM to run as a background process.</li><li>DNSTimeout: Sets the maximum time for DNS lookups in OpenDKIM.</li><li>SignatureAlgorithm: Defines the cryptographic algorithm used for DKIM signature generation.</li></ol><pre># Add the following lines at the end of the file, under the &quot;UserID&quot;:  <br>KeyTable                refile:/etc/opendkim/key.table<br>SigningTable            refile:/etc/opendkim/signing.table<br>ExternalIgnoreList      /etc/opendkim/trusted.hosts  <br>InternalHosts           /etc/opendkim/trusted.hosts</pre><p>In OpenDKIM configuration, the KeyTable specifies the location of the file containing DKIM keys, the SigningTable determines which domains to sign emails for, and the ExternalIgnoreList and InternalHosts files define trusted hosts for external and internal email sources, respectively.</p><p>Here’s how the opendkim.conf file should appear with our changes implemented (without comments):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3c30bbd1bde425035c7e81efc57c374/href">https://medium.com/media/f3c30bbd1bde425035c7e81efc57c374/href</a></iframe><h4>Creating necessary folders/files and configuring them:</h4><p>Create opendkim folders and set the necessary permissions:</p><pre># Create opendkim folders:<br>sudo mkdir /etc/opendkim<br>sudo mkdir /etc/opendkim/keys<br><br># Change owners &amp; permissions:<br>sudo chown -R opendkim:opendkim /etc/opendkim  <br>sudo chmod go-rw /etc/opendkim/keys</pre><p>Create the signing table and edit:</p><pre># Create the signing.table:<br>sudo touch /etc/opendkim/signing.table<br><br># Add the following lines to signing.table:<br>*@ozgun.zip       default._domainkey.ozgun.zip<br>*@*.ozgun.zip     default._domainkey.ozgun.zip</pre><p>First line signifies that all email addresses ending with @ozgun.zip should use the default DKIM selector default._domainkey.ozgun.zip for DKIM signing.</p><p>The second line indicates that any subdomain of ozgun.zip (e.g., subdomain.ozgun.zip) should also employ the same default DKIM selector for signing.</p><p>Create the key table and edit:</p><pre># Create the key.table:<br>sudo touch /etc/opendkim/key.table<br><br># Add the following line to key.table:<br>default._domainkey.ozgun.zip ozgun.zip:default:/etc/opendkim/keys/ozgun.zip/default.private</pre><p>This line associates the DKIM selector default._domainkey.ozgun.zip with the domain ozgun.zip and specifies the location of the corresponding private key file /etc/opendkim/keys/ozgun.zip/default.private. This key is used for signing outgoing emails from the ozgun.zip domain using the DKIM selector “default”.</p><p>Create the trusted.hosts and edit:</p><pre># Create the trusted.hosts:<br>sudo touch /etc/opendkim/trusted.hosts<br><br># Add the following lines to trusted.hosts:<br>127.0.0.1  <br>localhost<br><br>*.ozgun.zip</pre><p>The line *.ozgun.zip signifies that any subdomain under the ozgun.zip domain (e.g., subdomain.ozgun.zip) is also considered a trusted source exempt from DKIM verification. This allows emails from any subdomain of ozgun.zip to bypass DKIM checks.</p><h4>Generating private-public key pair:</h4><p>Create key’s folder:</p><pre>sudo mkdir /etc/opendkim/keys/ozgun.zip</pre><p>Generate keys using opendkim-genkey (default selector):</p><pre>sudo opendkim-genkey -b 2048 -d ozgun.zip -D /etc/opendkim/keys/ozgun.zip -s default -v</pre><p>This line generates a DKIM key pair for the domain ozgun.zip with a key size of 2048 bits, storing the keys in the specified directory (/etc/opendkim/keys/ozgun.zip) using the selector default for DKIM signing and verification.</p><p>Set ownerships &amp; permissions of generated keys:</p><pre>sudo chown opendkim:opendkim /etc/opendkim/keys/ozgun.zip/default.private<br>sudo chmod 600 /etc/opendkim/keys/ozgun.zip/default.private</pre><h4>Publishing the DKIM public key as a DNS record:</h4><p>Read the public key via:</p><pre>sudo cat /etc/opendkim/keys/ozgun.zip/default.txt</pre><p>Add the readed line, without spaces and quotes, as a TXT record with the value default._domainkey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y_0-yMFbjm4OQTovp6XSKA.png" /><figcaption>DKIM TXT record</figcaption></figure><h4>Testing the DKIM record:</h4><p>Now, it’s time to test if our DKIM record is correctly configured:</p><pre>sudo opendkim-testkey -d ozgun.zip -s default -vvv</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-czjAFH-8pQ8IONAqM6Pw.png" /><figcaption>DKIM test succeeded</figcaption></figure><p>key OK suggests that the key has passed the test and is considered valid, key not secure part is generally related to DNSSec configurations, which is not our main concern right now.</p><h4>Connecting the Postfix to OpenDKIM:</h4><p>Create opendkim socket files and set ownerships:</p><pre>sudo mkdir /var/spool/postfix/opendkim  <br>sudo chown opendkim:postfix /var/spool/postfix/opendkim</pre><p>Edit the <strong>/etc/opendkim.conf</strong>:</p><pre># Replace the Socket with the following line:<br>Socket local:/var/spool/postfix/opendkim/opendkim.sock</pre><p>Edit the <strong>/etc/default/opendkim:</strong></p><pre># Replace the Socket with the following line:<br>SOCKET=&quot;local:/var/spool/postfix/opendkim/opendkim.sock&quot;</pre><p>Lastly, edit the <strong>/etc/postfix/main.cf:</strong></p><pre># Add the following lines: <br>milter_default_action = accept  <br>milter_protocol = 6  <br>smtpd_milters = local:opendkim/opendkim.sock  <br>non_smtpd_milters = $smtpd_milters</pre><p>These lines configure Postfix to utilize OpenDKIM as a milter for both incoming SMTP connections and non-SMTP mail delivery, enabling the integration of DKIM signing and verification into the mail server’s processes.</p><p>Now it’s time to restart everything!</p><pre>sudo systemctl restart opendkim postfix</pre><h3>Fourth mail -&gt; 9.8/10:</h3><p>As we did previously, we sent an email from test@ozgun.zip and to our delight, we achieved a remarkable score of 9.8!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BohM6Q6xa04ztBrwxe7hUQ.png" /><figcaption>4th mail test result</figcaption></figure><p>Is… that enough? Hell no.</p><h3>5- The Secret Ingredient: Reverse DNS Records</h3><p>Now, for the final step, let’s introduce our secret ingredient: PTR (Pointer) records, also known as Reverse DNS. But before we dive in, let’s understand what PTR and Reverse DNS are all about and why they are crucial.</p><p>PTR (Pointer) records are a type of DNS record that maps an IP address to a domain name. In the context of Reverse DNS, it associates an IP address with its corresponding hostname. This reverse mapping helps establish trust and authenticity for email servers.</p><p>Reverse DNS is important because it verifies the identity of the sender’s IP address. When an email is received, the recipient’s server performs a reverse DNS lookup to match the IP address to a domain name. If the lookup fails or doesn’t match, it can raise suspicions and affect email deliverability.</p><p>Let’s take a look at how our mail server’s reverse DNS appears now, note that my current GCP instance’s ip is <strong>35.239.232.204</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_Pc3IJJW3L3zQ4jR_THMw.png" /><figcaption>nslookup on our GCP instance</figcaption></figure><p>DNS A records are associated with domain names, while DNS PTR records are linked to IP addresses in reverse format with the addition of “.in-addr.arpa”. For instance, for our IP address <strong>35.239.232.204</strong>, the corresponding PTR record would be stored under 204.232.239.35.in-addr.arpa.</p><p>Because my server is running on Google Cloud Provider, my mail server’s ip address resolves to the hostname 204.232.239.35.bc.googleusercontent.com.</p><p>When we send an email from <strong>test@ozgun.zip</strong>, the recipient server, thanks to MX records, identifies that our email is originating from <strong>mail.ozgun.zip</strong>. To validate this information, the recipient server performs a DNS lookup for <strong>mail.ozgun.zip</strong> and retrieves its corresponding IP address, which is <strong>35.239.232.204:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*g5pzfBk-dXKXEBOXWXYJ1Q.png" /><figcaption>DNS lookup for mail.ozgun.zip</figcaption></figure><p>However, when the recipient server attempts a reverse DNS lookup for <strong>35.239.232.204</strong>, it receives an inconsistent response of 204.232.239.35.bc.googleusercontent.com :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iohVZkK4f76ljE4llyFFTw.png" /><figcaption>Reverse DNS lookup for GCP ip</figcaption></figure><p>This inconsistency between the forward and reverse DNS lookups needs to be addressed. Ensuring consistent forward and reverse DNS lookups is crucial for establishing trust and maintaining proper email deliverability. Let’s take the necessary steps to resolve this inconsistency and align the reverse DNS lookup with our desired hostname.</p><p>It is worth noting that PTR records can be edited on various cloud providers, including AWS. However, for the purpose of this demonstration, I will showcase the process specifically on GCP.</p><p>Google Cloud has a <a href="https://cloud.google.com/compute/docs/instances/create-ptr-record">great documentation</a> to create a PR record for a VM instance. First and foremost, we must confirm our domain ownership: <strong>mail.ozgun.zip</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZxTeusK5-lz-beWDvshtg.png" /></figure><p>Domains can be verified from <a href="https://search.google.com/u/0/search-console/welcome">https://search.google.com/u/0/search-console/welcome</a>.</p><p>Following the <a href="https://cloud.google.com/compute/docs/instances/create-ptr-record">documentation</a>, Public DNS PTR Record can be set from the Network settings of the target instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*dEywWshBxK9GH09DliFA-A.png" /><figcaption>PTR Record change on GCP</figcaption></figure><p>As a result of these modifications, it is important to be aware that your instance’s IP address may have been changed. So don’t forget to update your <strong>A</strong> record with the new ip.</p><p>Reverse DNS lookup on my new ip: <strong>35.202.215.47</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clJf6JlpvGYh3fZnmc1UpA.png" /><figcaption>Reverse DNS lookup on new ip</figcaption></figure><p>This change can also be noticed by examining the <strong>Received</strong> header of the sent emails:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFJiBz72y-jjKsaCxSVJzg.png" /><figcaption>Received header</figcaption></figure><h3>Fifth mail -&gt; 10/10:</h3><p>Are you ready for the final email? Here we go:</p><pre>echo &quot;our trustworthy email&quot; | mailx -s &quot;Final mail&quot; -r &quot;final@ozgun.zip&quot; &lt;code&gt;@srv1.mail-tester.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COoqgls1B3SgrwRDvxgTXA.png" /><figcaption>5th mail test result</figcaption></figure><p>And voila! We can now send <strong>innocent 😇</strong> emails with a flawless 10/10 score on the mail tester!</p><h3>6- Gmail Test</h3><p>Now, let’s verify if we can successfully send emails to the target’s Gmail primary inbox.</p><pre>echo &quot;our trustworthy email&quot; | mailx -s &quot;Gmail Delivery Test&quot; -r &quot;support@ozgun.zip&quot; ozgunkultekin@gmail.com</pre><p>And guess what:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wpmzkDkaZzpaiVJ8m1o-A.png" /><figcaption>Successful gmail delivery test</figcaption></figure><p>Mail details:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*kzypYrhFKixOBkbCiVQqnw.png" /><figcaption>Mail details.</figcaption></figure><p>Yep! Now we can send signed/secure emails directly to the target’s primary inbox!</p><h3>7- In case of Outlook…</h3><p>But here’s the catch: when you try sending emails to Outlook, you’ll hit a roadblock! Outlook’s spam policy is like a tough bouncer, making it harder to get into the inbox. But fear not!</p><p>In my <strong>upcoming write-up</strong>, I’ll spill the beans on how to outsmart Outlook’s spam filters and successfully land your emails in those hardened Outlook inboxes. Get ready for some sneaky tricks and expert tips!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FMTbya3k32GED2EyPEX%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FMTbya3k32GED2EyPEX%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FMTbya3k32GED2EyPEX%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/fafb4e794617b78d4f192c288723d9b3/href">https://medium.com/media/fafb4e794617b78d4f192c288723d9b3/href</a></iframe><h3>8- Final Notes &amp; Resources:</h3><p>We’ve reached the end of the first part of the <strong>Phisher’s Playbook</strong> series. Thanks for reading! I’ll keep going with the series and share more about my adventures in offensive security. I’ve already hinted at what to expect in my upcoming writing 👀 📪.</p><p>Here are the files we created and edited during our journey. For those who may encounter any issues with them, I am sharing each file with their latest version that was used in this writing:</p><ul><li><strong>/etc/postfix/main.cf: </strong><a href="https://github.com/oz9un/phishers-playbook/blob/main/phisher&#39;s%20playbook%201/main.cf">https://github.com/oz9un/phishers-playbook/blob/main/phisher&#39;s%20playbook%201/main.cf</a></li><li><strong>/etc/postfix/master.cf:</strong><a href="https://github.com/oz9un/phishers-playbook/blob/main/phisher&#39;s%20playbook%201/master.cf">https://github.com/oz9un/phishers-playbook/blob/main/phisher&#39;s%20playbook%201/master.cf</a></li></ul><p>You can follow/reach me <strong>anytime </strong>from:</p><ul><li><a href="https://twitter.com/oz9un">twitter</a></li><li><a href="https://www.linkedin.com/in/oz9unkultekin/">linkedin</a></li></ul><p>Warning ⚠️ : Before concluding, it is crucial to emphasize the legal and ethical considerations surrounding the topic of creating phishing emails. While this article aimed to shed light on achieving a high mail tester score, it is imperative to utilize this knowledge responsibly. The techniques and information provided here should only be used for educational or security awareness purposes. Engaging in any illegal activities, such as sending deceptive phishing emails, is strictly prohibited and can result in severe legal consequences. It is essential to respect privacy, adhere to laws, and prioritize the well-being of others in all online activities. Let us all strive for a safer and more secure digital environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f7f99c8243" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SysmonForLinux — Logging File Create Events]]></title>
            <link>https://ozgunkultekin.medium.com/sysmonforlinux-logging-file-create-events-da082dd3f893?source=rss-da182ca030a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/da082dd3f893</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[sysmon]]></category>
            <category><![CDATA[logging]]></category>
            <dc:creator><![CDATA[Özgün Kültekin]]></dc:creator>
            <pubDate>Wed, 20 Oct 2021 15:49:33 GMT</pubDate>
            <atom:updated>2021-10-20T15:49:33.004Z</atom:updated>
            <content:encoded><![CDATA[<h3>SysmonForLinux — Logging File Create Events</h3><p>In this article, I will explain how to use SysmonForLinux for creating specific configurations to keep track of file creation events.</p><p>For further information about SysmonForLinux, events and configuration options; you can visit my GitHub repository: <a href="https://github.com/oz9un/SysmonForLinux-Manual"><strong>oz9un</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*RqcQecp3Ot502htmHOuZ8w.jpeg" /></figure><h3>Sysmon in a nutshell:</h3><p><strong>Sysmon </strong>(System Monitor) is a Windows system service that logs system activity to the Windows event log. Now, it is available for <strong>Linux </strong>too!</p><p>It was developed by Microsoft as an open source project. Even though it is doubtful to see such a contribution, I am very glad about it 🤭</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*bnYPwfP0WYvCtqqcpTOwSw.gif" /><figcaption>Microsoft ❤ Linux</figcaption></figure><h3>File Create event:</h3><p>As its name suggests, this event detects when a file is created on Linux systems.</p><blockquote>This event can be especially useful when tracking auto-startup folders and folders where everyone has a permission to create files. Because most of the time, they are the main targets of malicious users 👹.</blockquote><p>A normal file creation event log would looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*gDCfhzYZhOlgvd_MbTX_Xg.png" /><figcaption>Normal FILE CREATE Event</figcaption></figure><h3>Configuring File Create event:</h3><p>By default, <strong>SysmonForLinux </strong>logs every file creation events.</p><blockquote>But we are talking about Linux. Even if you connect to a server via SSH; that results in the creation of many tmp files.</blockquote><p>As a result, you can guess how chaotic the log file has become. This is why we don’t want to log everything, especially in case of file creation event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*PRw1PlTQr9cAJWtTzGU-nQ.gif" /><figcaption>/var/log/syslog be like</figcaption></figure><p>File Create event has 7 different description fields that we can use as filters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*It19oz52e-r_il54pETh_g.png" /><figcaption>Description Fields</figcaption></figure><blockquote>When creating a configuration file (xml) for <strong>SysmonForLinux</strong>, we can use above fields as a filter.</blockquote><p>You can view all description fields for each event on my <a href="https://github.com/oz9un/SysmonForLinux-Manual"><strong>GitHub </strong></a>page!</p><h3>Example scenario:</h3><p>Suppose you want to keep log of the every file creation event with the following properties:</p><ol><li>File should be created in <strong>/tmp </strong>or under <strong>/home/secret</strong> folder</li><li>File should be created in <strong>October 2021</strong>.</li><li>File shouldn’t be created with <strong>/usr/sbin/cups-browsed</strong> daemon (This printer daemon uses /tmp file quite often).</li></ol><h4>Desired configuration file should looks like that:</h4><pre>&lt;! — Event ID 11 == FileCreate. Log what we want! →<br>&lt;RuleGroup name=”” groupRelation=”and”&gt;<br> &lt;FileCreate onmatch=”include”&gt;<br> &lt;TargetFilename condition=”contains any”&gt;/home/secret/;/tmp/&lt;/TargetFilename&gt;<br> &lt;UtcTime condition=”contains”&gt;2021–10&lt;/UtcTime&gt;<br> &lt;/FileCreate&gt;</pre><pre>&lt;FileCreate onmatch=”exclude”&gt;<br> &lt;Image condition=”is”&gt;/usr/sbin/cups-browsed&lt;/Image&gt;<br> &lt;/FileCreate&gt;<br>&lt;/RuleGroup&gt;</pre><p>You can view the whole configuration file from: <a href="https://github.com/oz9un/SysmonForLinux-Manual/blob/main/Description%20Field%20Examples/FileCreate_ExampleScenario.xml"><strong>Example Scenario</strong></a><strong>.</strong></p><h3>Results:</h3><p>To activate our configuration file:</p><pre>sudo sysmon -c example_scenario.xml</pre><p>To view <strong>sysmon</strong>’s log file:</p><pre>tail -f /var/log/syslog | sudo /opt/sysmon/sysmonLogView -X</pre><h4>Output:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*HszPfA0v1gTGL7oOEAgekg.png" /><figcaption>Log output</figcaption></figure><p>As you can see, we successfully created a configuration file according to our properties and caught some malicious events already!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*0hbe6EdxsWN0Row7sAdYeQ.gif" /></figure><h3>End &amp; Contact:</h3><p>This is at the end of my first post about <strong>SysmonForLinux</strong>. I plan to write much more on this subject as I find time. I would be very happy if you can give a feedback. Stay in touch!</p><p>Github: <a href="https://github.com/oz9un">https://github.com/oz9un</a><br>Twitter: <a href="https://twitter.com/oz9un">https://twitter.com/oz9un</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*mXEvcs-fQfAcANFfYbILIg.gif" /><figcaption>bye!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da082dd3f893" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crypto Basics: Fixed XOR implementation [Python]]]></title>
            <link>https://medium.com/analytics-vidhya/crypto-basics-fixed-xor-implementation-python-9cfba54f4661?source=rss-da182ca030a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cfba54f4661</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[cryptology]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[cryptopals]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Özgün Kültekin]]></dc:creator>
            <pubDate>Tue, 26 Jan 2021 20:28:20 GMT</pubDate>
            <atom:updated>2021-10-12T18:41:57.789Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Crypto Basics: Fixed XOR implementation [Python][Cryptopals]</strong></h3><p>If you are a person who is constantly having trouble when making decisions like me, that means you use the word ‘OR’ a lot in your life.</p><p>In computer science, the ‘OR’ operator is fairly common, but probably not because computer scientists have trouble when making decisions.</p><p>And adding ‘<strong>exclusive</strong>’ to the beginning of a word always makes that word cooler. Right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*0aGgBl67Mvvk2_7f.png" /><figcaption>Rick Astley &gt; XOR &gt; OR &gt; AND (coolness ranking)</figcaption></figure><p>You can use this operator just because it’s super cool (I think it’s a pretty good reason). However, those dealing with cryptography have good reasons to use the ‘XOR’ operator. XOR allows you to easily encrypt and decrypt a string. You cannot do this with other logical operators:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4skurBRWKNpgFZPwaLUE8Q.png" /><figcaption>backward compatibility of XOR</figcaption></figure><p>In this article, we won’t start with inserting words into the XOR operator as above. With a more basic and fun challenge, we will see how we can do the Fixed XOR operation in Python.</p><p>And the purpose here is not to solve the challenge quickly and in the shortest way, but to fully understand the processes and the functions used. Thus, to use it effectively in different questions/challenges.</p><p>Spoiler: We’ll do that as in the<a href="https://medium.com/analytics-vidhya/crypto-basics-understand-create-your-own-base64-encoding-with-python-a1481686a35a"> <strong>base64 post</strong></a>, without importing any modules!</p><blockquote><strong>WARNING:</strong> Don’t be angry with me for not explaining what XOR is from the beginning, just believe it would be boring if I explained at length that <strong>it is just the sum of two bits in mod 2</strong>.</blockquote><h3>The challenge we’ll rock:</h3><p>We will solve Challenge 2 of Set 1 on the <a href="https://cryptopals.com/sets/1/challenges/2">cryptopals</a> : Fixed XOR.</p><blockquote>Cryptopals is a very well crafted site with lots of crypto challenges. Must be visited by beginners and those who want to improve themselves!</blockquote><p>First, let’s examine the challenge:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/0*YffPpSsW4v6ljSUR" /><figcaption>me when trying to figure out if I can solve the example</figcaption></figure><h4>Challenge:</h4><p>Write a function that takes two equal-length buffers and produces their XOR combination.</p><p>If your function works properly, then when you feed it the string:</p><pre>1c0111001f010100061a024b53535009181c</pre><p>… after hex decoding, and when XOR’d against:</p><pre>686974207468652062756c6c277320657965</pre><p>… should produce:</p><pre>746865206b696420646f6e277420706c6179</pre><h3>Battle time! (or coding):</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*P47Qza2u5uJqLAMf" /></figure><h4>1- Converting HEX to integer:</h4><p>Firstly, we need to convert hex to integer (I’ll also explain that we don’t actually need).</p><p>Python has a int() function, which takes 2 parameters:</p><blockquote><strong>int(α, base)</strong></blockquote><blockquote><strong>α</strong> = the number to be converted to an integer (It works with and without the 0x prefix)</blockquote><blockquote><strong>base </strong>= base of the α</blockquote><p>As we know, the “hex” system is a number system consisting of 16 symbols. That means “hex” is base 16.</p><p><strong>Example usage of int() function to convert hex to integer:</strong></p><pre>hex_value = &quot;CAFEBABE&quot; # or &quot;0xCAFEBABE&quot;<br>base = 16<br>result = int(hex_value<strong><em>,</em></strong> base)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*9hyTxr8RoWLO0TRwBQx7aQ.png" /><figcaption>more convenient for reading</figcaption></figure><h4>2- Converting integer to binary:</h4><p>Python has a bin() function, which takes 1 parameter.</p><blockquote><strong>bin(α)</strong></blockquote><blockquote><strong>α </strong>= any numeric value</blockquote><p>Any numeric value… That means you can:</p><pre>decimal = bin(3405691582)<br>hexadecimal = bin(0xCAFEBABE)<br>octal = bin(0o31277535276)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*cU6vhDzeW-cCIzqqrTvFnQ.png" /><figcaption>more convenient for reading</figcaption></figure><p>And they all give the same “binary string” output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wZRDzeNX7qodT11_aujGw.png" /></figure><p>I didn’t want to spoil the originality as the ‘0x’ prefix was not given in the challenge, so I first converted it to integer. If you wish, you can add the 0x prefix and use the bin() function directly.</p><h4>3- Converting binary to desired format:</h4><p>What is desired format?</p><p>To get the desired format, we have to solve the following 2 problems:</p><ol><li>Output of the bin() function always prefixed with ‘0b’.</li><li>The bin() function always tries to express the number in the shortest way.</li></ol><p>What I mean is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*mx_VNqkmPMTGFEjWEx2ssg.png" /><figcaption>problems of bin() function</figcaption></figure><p>It will be convenient for us to have equal length of outputs to do bit by bit <strong>XOR</strong> operation. But as seen above, the length of the output depends on the value of the input.</p><p>We can solve our 1st problem by excluding the first two values of our output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*JOsOI3QMl235LUaRJ0DmTA.png" /><figcaption>excluding the ‘0b’ part</figcaption></figure><p>To solve 2nd problem, how can we make both outputs equal?</p><p>Python has a zfill() function, which takes 1 parameter.</p><blockquote><strong>zfill(width)</strong></blockquote><blockquote><strong>width </strong>= desired length of output</blockquote><p>zfill() function basically adds 0 to the beginning of the output, bringing it to the desired length.</p><p>Therefore, we must first find out which of the two values we will XOR are long. Then we have to make the other output to that length:</p><pre># example hex values:<br>hex_1 = &quot;CAFEBABE&quot;<br>hex_2 = &quot;0A0A0A0A&quot;</pre><pre>bin_1 = bin(int(hex_1<strong><em>,</em></strong> 16))[2<strong><em>:</em></strong>]<br>bin_2 = bin(int(hex_2<strong><em>,</em></strong> 16))[2<strong><em>:</em></strong>]</pre><pre># find out length of the longer binary:<br>desired_length = len(bin_1) <strong>if</strong> len(bin_1) &gt; len(bin_2) <strong>else</strong> len(bin_2)</pre><pre># use zfill() to make equal lengths:<br>bin_1 = bin_1<strong><em>.</em></strong>zfill(desired_length) <br>bin_2 = bin_2<strong><em>.</em></strong>zfill(desired_length)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SA-yZ8gce4wbPe-a6wDgHg.png" /><figcaption>more convenient for reading</figcaption></figure><p>Finally, we have two binary values of the same length.</p><h4><strong>4- XOR:</strong></h4><p>We can aggregate two binary values with the zip() function and apply XOR operation bit by bit in one line:</p><pre>bin_1 = &quot;11001010111111101011101010111110&quot;<br>bin_2 = &quot;00001010000010100000101000001010&quot;</pre><pre>result = [int(bit1)<strong><em>^</em></strong>int(bit2) <strong>for</strong> bit1<strong><em>,</em></strong>bit2 <strong>in</strong> zip(bin_1<strong><em>,</em></strong>bin_2)]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLrjVk5LCT21jMSjYIBdeg.png" /><figcaption>more convenient for reading</figcaption></figure><p>The only problem there is, result returns “list”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9wHiILMFktOBEoI4Z-uCAA.png" /><figcaption>list output of result</figcaption></figure><p>We can easily convert this to a string value:</p><pre>string_result = &quot;&quot;<strong><em>.</em></strong>join([str(bits) <strong>for</strong> bits <strong>in</strong> result])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*nOJGT6_oBZ89LrcGi__7JA.png" /><figcaption>more convenient for reading</figcaption></figure><p>Now, we are ready for the last part!</p><h4>5- Binary to HEX:</h4><p>Python has a hex() function, which takes 1 parameter.</p><blockquote><strong>hex(α)</strong></blockquote><blockquote><strong>α </strong>= integer number</blockquote><p><strong>hex()</strong> function converts an integer number to its corresponding hexadecimal string with ‘0x’ prefix.</p><p>That’s good! But…We have binary number. Is that okay?</p><p>Yeah! At this point, we can use the <strong>int()</strong> function we learned at the beginning:</p><pre>hex(int(string_result<strong><em>,</em></strong>2))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*t3tEheRkmY3XcX4goypWgA.png" /><figcaption>we specified base 2 and got rid of ‘0x’ prefix</figcaption></figure><h4>Yayyyyyy, we made it!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*gnokDynKMRrffWVRWzDETA.png" /></figure><h3>FINAL:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*7-uEN5s1MsXhMntu.gif" /></figure><p>As I said before, the purpose here is not to solve the challenge quickly and in the shortest way, but to fully understand the processes and functions used. Now that we’ve revealed all the details, we can solve the real challenge:</p><pre># CRYPTOPALS SET 1 CHALLENGE 2 : FIXED XOR<br>hex_value1 = &quot;1c0111001f010100061a024b53535009181c&quot;<br>hex_value2 = &quot;686974207468652062756c6c277320657965&quot;</pre><pre>#step 1-2<br>bin_value1 = bin(int(hex_value1<strong><em>,</em></strong> 16))[2<strong><em>:</em></strong>]<br>bin_value2 = bin(int(hex_value2<strong><em>,</em></strong> 16))[2<strong><em>:</em></strong>]</pre><pre>#step 3<br>desired_length = len(bin_value1) <strong>if</strong> len(bin_value1) &gt; len(bin_value2) <strong>else</strong> len(bin_value2)</pre><pre>bin_value1 = bin_value1<strong><em>.</em></strong>zfill(desired_length)<br>bin_value2 = bin_value2<strong><em>.</em></strong>zfill(desired_length)</pre><pre>#step 4<br>result = [int(bit1) <strong><em>^</em></strong> int(bit2) <strong>for</strong> bit1<strong><em>,</em></strong>bit2 <strong>in</strong> zip(bin_value1<strong><em>,</em></strong>bin_value2)]</pre><pre>string_result = &quot;&quot;<strong><em>.</em></strong>join([str(bits) <strong>for</strong> bits <strong>in</strong> result])</pre><pre>#step 5<br>final_output = hex(int(string_result<strong><em>,</em></strong> 2))[2<strong><em>:</em></strong>]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWoXfyYWdhb5wZzvjy9kGw.png" /><figcaption>pretty clear one</figcaption></figure><p>If you’ve come this far, you either really interested and enjoyed it, or you just wanted to learn the answer. Both options look pretty good, thanks!</p><blockquote>Source code: <a href="https://github.com/oz9un/crypto_basics/blob/master/medium_writings/cryptopals12_medium.py">https://github.com/oz9un/crypto_basics/blob/master/medium_writings/cryptopals12_medium.py</a></blockquote><blockquote>I’m just one email away from you for any feedback / question:</blockquote><blockquote><strong>ozgunkultekin@gmail.com</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cfba54f4661" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/crypto-basics-fixed-xor-implementation-python-9cfba54f4661">Crypto Basics: Fixed XOR implementation [Python]</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crypto Basics: understand&create your own base64 encoding with Python]]></title>
            <link>https://medium.com/analytics-vidhya/crypto-basics-understand-create-your-own-base64-encoding-with-python-a1481686a35a?source=rss-da182ca030a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1481686a35a</guid>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[base64]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Özgün Kültekin]]></dc:creator>
            <pubDate>Sun, 23 Aug 2020 17:48:37 GMT</pubDate>
            <atom:updated>2020-08-31T05:39:13.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*sol4tSIMpXTU4KBxt7IgFA.png" /></figure><p>We encounter base64 encoding in most of our daily lives (yeah, nerds).</p><p>For example, we use base64 encoding to embed image data directly into HTML source code or to prevent the probability of binary data getting corrupt in its raw form when sending attachments over the Internet.</p><p>If you’re an active CTF player, you probably see it more than your family already.</p><h3>Let’s move on to <strong>how base64 works </strong>without further ado:</h3><blockquote>ASCII encoding and Base64 encoding are not interchangeable. Don’t fall for this common misunderstanding. They are used for different purposes.</blockquote><p>Base64 is a binary-to-text encoding scheme. Therefore, it can encrypt any binary data or non-ASCII character, and gives<strong><em> ASCII characters </em></strong>as a result.</p><blockquote><strong>Step 1:</strong> The Base64 encoding algorithm receives an input stream of 8-bit bytes.</blockquote><pre><strong>input</strong>: <br><strong>-&gt; </strong>oz9un<br><strong>Binary Represantation(8-bit sequences)</strong>:<br><strong>-&gt; </strong>01101111 01111010 00111001 01110101 01101110</pre><blockquote><strong>Step 2:</strong> Split the input into 6-bit chunks. Pad with ‘0’ bits at the end of the last group unless it is split into full 6-bit groups.</blockquote><pre><strong>Binary Represantation(6-bit sequences):<br>-&gt; </strong>011011 110111 101000 111001 011101 010110 1110<strong>00</strong></pre><blockquote><strong>Step 3:</strong> Now that we have 6-bit groups we need to convert them to ASCII characters. But how? By indexing 6-bit sequences into the Base64 index table.</blockquote><pre><strong>The 6-bit sequences above correspond to:<br>-&gt; </strong>27 55 40 57 29 22 56</pre><p>Let’s take a look at the base64 index table</p><figure><img alt="this table is taken from wikipedia" src="https://cdn-images-1.medium.com/max/881/1*yWJlXoyZcxMynLFuDMO4TQ.png" /><figcaption>this table is taken from <a href="https://en.wikipedia.org/wiki/Base64">wikipedia</a></figcaption></figure><p>As you can see, there are corresponding ASCII characters for 63 different numbers that 6-bit sequence can take.</p><h4>What the heck does that<strong> ‘Padding’ </strong>mean?</h4><p>Calm, it is for your health. As you may notice, we cut <strong>three </strong>8-bit chunks into <strong>four </strong>6-bit chunks (that was easy math, got it).</p><p>Remember what we did in <strong>Step 2</strong>. We simply added 0 bits to make sequence splitible into 6-bit chunks. We have two options when adding the ‘0’ bits. Either 2 or 4. And after converting 6-bit sequences into corresponding base64 characters, we should add <strong><em>(# of additional ‘0’ bytes)/2</em></strong> padding characters(=) at the end of the encoded version.</p><h4>Okay…Can I ask why we did that?</h4><p>Imm, I absolutely agree with you. That is unnecessary today. But base64 encoding is very old guy and in its days of youth, computers have limited CPUs/RAMs and writing software was not that easy. So, the decoder guys were thinking of easily splitting the input into 4 blocks and extracting 3 characters from each 4 blocks. And the padding process allowed them to do this without going through the end of the input.</p><p>Yeah, that was a sad story. But do not worry. We can code that without needing any padding characters too (we have rams larger than 10mb).</p><p>Now it’s time to convert these numbers to ASCII characters with the help of the base64 index table:</p><pre><strong>The 6-bit sequences above correspond to:<br>-&gt; </strong>27 55 40 57 29 22 56<br><strong>Corresponding ASCII characters:<br>-&gt; </strong>b3o5dW4=</pre><p>And now you definitely have an idea of where this equality sign came from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*J0CaNhTgI8TiarYbBaRP_A.png" /></figure><h4>Not yet, here we go:</h4><p>First of all, I can definitely say that we don’t need to import any modules, because we got the logic. That’s the cool part.</p><blockquote><strong>Code Step 1: </strong>We have to initialize a variable to keep the base64 index table.</blockquote><p><strong>[1]</strong> You can do that with importing <em>string </em>module. But of course we will not choose this way (code with no imports, thanks).</p><pre><em>import</em> string</pre><pre><strong>base64_table</strong> = (string.ascii_uppercase+string.ascii_lowercase+string.digits+&#39;+/&#39;)</pre><p><strong>[2] </strong>Easy to guess, writing your alphabet yourself will not tire your fingers. But I still leave it for you to copy.</p><pre><strong>ascii_lowercase</strong> = &#39;abcdefghijklmnopqrstuvwxyz&#39;<br><strong>ascii_uppercase</strong> = &#39;ABCDEFGHIJKLMNOPQRSTUVWXYZ&#39;<br><strong>digits</strong> = &#39;0123456789&#39;</pre><pre><strong>base64_alphabet</strong> = ascii_uppercase + ascii_lowercase + digits + &#39;+/&#39;</pre><blockquote><strong>Code Step 2: </strong>Let’s break down our input into 8-bit chunks. (But…We did not take any input. Yeah, take it then.)</blockquote><pre><strong>to_encode</strong> = input(&quot;base64 encoder -&gt;  &quot;)</pre><pre><strong>chunks_8bit</strong> = &#39;&#39;<strong><em>.</em></strong>join([format(bits<strong><em>,</em></strong>&#39;08b&#39;) <strong>for</strong> bits <strong>in</strong> to_encode<strong><em>.</em></strong>encode(&#39;utf8&#39;)])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMw-S06Nlw7PGrpgQKV_Wg.png" /><figcaption>In case you had trouble reading the above code snippet</figcaption></figure><p>We use <em>format(bits, ‘08b’) </em>to convert an integer to binary keep leading zeros.</p><p>With the <em>join, </em><strong>chunks_8bit</strong> output looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*Ms4XIWPAh7Ti3ecgQfhHmg.png" /></figure><blockquote><strong>Code Step 3: </strong>It’s time to convert 8-bit chunks to 6-bit chunks and add ‘0’ bits at the end of the string if needed.</blockquote><pre><strong>chunks_6bit</strong> = [chunks_8bit[bits<strong><em>:</em></strong>bits+6] <strong>for</strong> bits <strong>in</strong> range(0<strong><em>,</em></strong>len(chunks_8bit)<strong><em>,</em></strong>6)]</pre><pre><strong>padding_amount</strong> = ( 6 - len(chunks_6bit[len(chunks_6bit)-1]) )</pre><pre><strong>chunks_6bit[</strong>len(chunks_6bit)-1<strong>]</strong> += padding_amount * &#39;0&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGFRyagrPM1V9ImZ3X-c7g.png" /><figcaption>In case you had trouble reading the above code snippet</figcaption></figure><p>This code is all you need to convert 8-bit chunks to 6-bit chunks with ‘0’ padding if needed.</p><p>With the help of calculating <strong>padding_amount, </strong>we can add ‘=’ later.</p><p><strong>chunks_6bit</strong> output looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*xVQ10WnYeOKZDC8IHu-YwQ.png" /></figure><blockquote><strong>Code Step 4: </strong>The final step. All we have to do is map these 6-bit chunks value into our base64 alphabet.</blockquote><pre><strong>encoded</strong> = &#39;&#39;<strong><em>.</em></strong>join([base64_alphabet[int(bits<strong><em>,</em></strong>2)] <strong>for</strong> bits <strong>in</strong> chunks_6bit])</pre><pre><strong>encoded</strong> += int(padding_amount/2) * &#39;=&#39;</pre><pre>print(&#39;Base64 encoded version of <strong>{to_encode}</strong> is: <strong>{result}</strong>&#39;<strong><em>.</em></strong>format(<strong><em>to_encode</em></strong> = to_encode<strong><em>,</em></strong> <strong><em>result</em></strong> = encoded))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d13L3LN_oitilcxJBo34WQ.png" /><figcaption>In case you had trouble reading the above code snippet</figcaption></figure><p>We used <em>int(bits,2) </em>to convert binary to decimal. Every two additional ‘0’ bits corresponds to one padding character(‘=’). That is why we divided padding_amount by 2.</p><p>Then, we just print it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*gpgDKQdN4UcadY1d9qhBDg.png" /></figure><p>You can find the complete code here. As I write new writings, I will share their codes in this repository.</p><blockquote><a href="https://github.com/oz9un/crypto_basics/blob/master/base_world/base64_manually.py">https://github.com/oz9un/crypto_basics/blob/master/base_world/base64_manually.py</a></blockquote><h3>The end:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*YtGBFphYH6sEtnZ6E5iCmw.gif" /></figure><p>This is at the end of my first post about Crypto Basics. I plan to write much more on this subject as I find time. I would be very happy if you can give a feedback. Stay in touch!</p><h4>Contact me:</h4><blockquote><strong>Gmail:</strong> ozgunkultekin@gmail.com</blockquote><blockquote><strong>Github:</strong> <a href="https://github.com/oz9un/crypto_basics">https://github.com/oz9un</a></blockquote><blockquote><strong>Twitter: </strong><a href="https://twitter.com/oz9un">https://twitter.com/oz9un</a>(New here, but will be active).</blockquote><blockquote><strong>CTFtime: </strong>oz9un</blockquote><blockquote><strong>Linkedin: </strong><a href="https://www.linkedin.com/in/oz9unkultekin">https://www.linkedin.com/in/oz9unkultekin</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1481686a35a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/crypto-basics-understand-create-your-own-base64-encoding-with-python-a1481686a35a">Crypto Basics: understand&amp;create your own base64 encoding with Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>