<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Heavens</title>
    <description>The latest articles on DEV Community by Heavens (@hi_heavens).</description>
    <link>https://dev.to/hi_heavens</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F786226%2Fc8ac53bd-c066-49b0-850b-f6d1471057af.png</url>
      <title>DEV Community: Heavens</title>
      <link>https://dev.to/hi_heavens</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hi_heavens"/>
    <language>en</language>
    <item>
      <title>A Simple Cracked P*$$w*rd</title>
      <dc:creator>Heavens</dc:creator>
      <pubDate>Tue, 29 Mar 2022 06:52:18 +0000</pubDate>
      <link>https://dev.to/hi_heavens/a-simple-cracked-pwrd-1ckg</link>
      <guid>https://dev.to/hi_heavens/a-simple-cracked-pwrd-1ckg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;What is a passworded file without a "possward"?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With the advancement of the digital age; digital security is becoming much more important for safety. And with attackers getting so skilled, the need for an improvement for stronger security begs for exploration and implementation. &lt;/p&gt;

&lt;p&gt;Anyhoo, I am not here for that. I'm here to show how a simple password file that is coded in C programming language can be hacked in a simple way. I will be running this on my Ubuntu machine.&lt;/p&gt;

&lt;p&gt;You can access the file &lt;a href="https://github.com/holbertonschool/0x06.c" rel="noopener noreferrer"&gt;crackme2&lt;/a&gt; here.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You may need to install the &lt;code&gt;openssl&lt;/code&gt; library to run the &lt;code&gt;crakme2&lt;/code&gt; program: &lt;code&gt;sudo apt install libssl-dev&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Edit the source list &lt;code&gt;sudo nano /etc/apt/sources.list&lt;/code&gt; to add the following line: &lt;code&gt;deb http://security.ubuntu.com/ubuntu xenial-security main&lt;/code&gt; Then &lt;code&gt;sudo apt update&lt;/code&gt; and &lt;code&gt;sudo apt install libssl1.0.0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us run the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ./crackme2
&amp;gt;&amp;gt;&amp;gt; bash: ./crackme2: Permission denied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you encountered the above, it means the user does not have executable permission to the file. Run the below to add executable permission for the user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ chmod 744 crackme2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ chmod u+x crackme2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Trying running the executable file again&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ./crackme2
&amp;gt;&amp;gt;&amp;gt; Access Denied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OMG! Access denied?! This shows the file has some type of access that you don't have and/or a password attached to it. And you don't even know where to write this password to gain access even if you know it.&lt;/p&gt;

&lt;p&gt;So, first thing first! We need to check if this file is stripped or not. &lt;a href="https://unix.stackexchange.com/questions/2969/what-are-stripped-and-not-stripped-executables-in-unix#:~:text=If%20you%20compile,of%20the%20executable." rel="noopener noreferrer"&gt;Why?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use the &lt;a href="https://www.geeksforgeeks.org/file-command-in-linux-with-examples/?ref=gcse" rel="noopener noreferrer"&gt;file&lt;/a&gt; command to determine the type of your file. The command tests each argument in an attempt to categorize it based on the below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;filesystem test&lt;/li&gt;
&lt;li&gt;magic test&lt;/li&gt;
&lt;li&gt;language test
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ file crackme2
&amp;gt;&amp;gt;&amp;gt; crackme2: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=e707426293fb8df389849d6d43665deb4e0229c2, not stripped
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's not stripped; indicating the file contains some information and symbols.&lt;/p&gt;

&lt;p&gt;Next, let us do a ltrace on the file.&lt;br&gt;
&lt;a href="https://man7.org/linux/man-pages/man1/ltrace.1.html#:~:text=ltrace%20is%20a,by%20the%20program." rel="noopener noreferrer"&gt;ltrace is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls executed by the program.&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ltrace ./crackme2
&amp;gt;&amp;gt;&amp;gt; __libc_start_main(0x400876, 1, 0x7ffed3761ee8, 0x400a60 &amp;lt;unfinished ...&amp;gt;
strncmp("HOSTNAME=28baaff6813f", "jennieandjayloveasm=", 20)                              = -34
strncmp("LANGUAGE=en_US:en", "jennieandjayloveasm=", 20)                                  = -30
strncmp("PWD=/root/alx-low_level_programm"..., "jennieandjayloveasm=", 20)                = -26
strncmp("TZ=America/Los_Angeles", "jennieandjayloveasm=", 20)                             = -22
strncmp("HOME=/root", "jennieandjayloveasm=", 20)                                         = -34
strncmp("LANG=en_US.UTF-8", "jennieandjayloveasm=", 20)                                   = -30
strncmp("LS_COLORS=rs=0:di=01;34:ln=01;36"..., "jennieandjayloveasm=", 20)                = -30
strncmp("LESSCLOSE=/usr/bin/lesspipe %s %"..., "jennieandjayloveasm=", 20)                = -30
strncmp("TERM=xterm", "jennieandjayloveasm=", 20)                                         = -22
strncmp("LESSOPEN=| /usr/bin/lesspipe %s", "jennieandjayloveasm=", 20)                    = -30
strncmp("SHLVL=1", "jennieandjayloveasm=", 20)                                            = -23
strncmp("LC_ALL=en_US.UTF-8", "jennieandjayloveasm=", 20)                                 = -30
strncmp("PATH=/usr/local/sbin:/usr/local/"..., "jennieandjayloveasm=", 20)                = -26
strncmp("OLDPWD=/etc", "jennieandjayloveasm=", 20)                                        = -27
strncmp("_=/usr/bin/ltrace", "jennieandjayloveasm=", 20)                                  = -11
puts("Access Denied"Access Denied
)                                                                     = 14
+++ exited (status 1) +++
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gotcha!!! From the look of the above trace, you could observe that this program is accessing the environment variables like &lt;strong&gt;PATH&lt;/strong&gt;, &lt;strong&gt;HOSTNAME&lt;/strong&gt;, &lt;strong&gt;HOME&lt;/strong&gt;, &lt;strong&gt;LANG&lt;/strong&gt;, et al. Using the strncmp function in C language, it is comparing the first 20 characters with &lt;strong&gt;jennieandjayloveasm=&lt;/strong&gt;. It is searching the environment variable for a name with jennieandjayloveasm.&lt;br&gt;
Let us give this program what it is looking for by creating a variable with that name with any value of choice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ export jennieandjayloveasm=alvicci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us confirm that the variable was created successfully&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo $jennieandjayloveasm
&amp;gt;&amp;gt;&amp;gt; alvicci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let us re-run the ltrace on the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ltrace ./crackme2
&amp;gt;&amp;gt;&amp;gt; __libc_start_main(0x400876, 1, 0x7fffd90db8d8, 0x400a60 &amp;lt;unfinished ...&amp;gt;
strncmp("HOSTNAME=28baaff6813f", "jennieandjayloveasm=", 20)                              = -34
strncmp("LANGUAGE=en_US:en", "jennieandjayloveasm=", 20)                                  = -30
strncmp("PWD=/root/alx-low_level_programm"..., "jennieandjayloveasm=", 20)                = -26
strncmp("TZ=America/Los_Angeles", "jennieandjayloveasm=", 20)                             = -22
strncmp("HOME=/root", "jennieandjayloveasm=", 20)                                         = -34
strncmp("LANG=en_US.UTF-8", "jennieandjayloveasm=", 20)                                   = -30
strncmp("LS_COLORS=rs=0:di=01;34:ln=01;36"..., "jennieandjayloveasm=", 20)                = -30
strncmp("jennieandjayloveasm=alvicci", "jennieandjayloveasm=", 20)                        = 0
MD5_Init(0x7fffd90db740, 0x400af6, 20, 61)                                                = 1
strlen("alvicci")                                                                         = 7
MD5_Update(0x7fffd90db740, 0x7fffd90ddf20, 7, 0x7fffd90ddf20)                             = 1
MD5_Final(0x7fffd90db7a0, 0x7fffd90db740, 0x7fffd90db740, 0x69636369)                     = 1
sprintf("ab", "%02x", 0xab)                                                               = 2
sprintf("11", "%02x", 0x11)                                                               = 2
sprintf("4a", "%02x", 0x4a)                                                               = 2
sprintf("86", "%02x", 0x86)                                                               = 2
sprintf("d9", "%02x", 0xd9)                                                               = 2
sprintf("a0", "%02x", 0xa0)                                                               = 2
sprintf("af", "%02x", 0xaf)                                                               = 2
sprintf("b8", "%02x", 0xb8)                                                               = 2
sprintf("da", "%02x", 0xda)                                                               = 2
sprintf("d6", "%02x", 0xd6)                                                               = 2
sprintf("36", "%02x", 0x36)                                                               = 2
sprintf("8c", "%02x", 0x8c)                                                               = 2
sprintf("bd", "%02x", 0xbd)                                                               = 2
sprintf("53", "%02x", 0x53)                                                               = 2
sprintf("7a", "%02x", 0x7a)                                                               = 2
sprintf("c1", "%02x", 0xc1)                                                               = 2
strcmp("e99a18c428cb38d5f260853678922e03"..., "ab114a86d9a0afb8dad6368cbd537ac1"...)      = 4
puts("Access Denied"Access Denied
)                                                                     = 14
+++ exited (status 1) +++
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nice! It went farther than the initial trial that we did. So, it checked the environment variable for the file and after locating it, it checked the length of the value using the strlen function.&lt;br&gt;
From the look of it, it seems it calculate the MD5 hash of the environment variable value and compare it to a predefined MD5 in the program itself using the strcmp function.&lt;/p&gt;

&lt;p&gt;It is comparing the hash value of the environment variable with a predefined MD5 hash value e99a18c428cb38d5f260853678922e03 in the program using the strcmp function.&lt;/p&gt;

&lt;p&gt;To confirm the actual password, you should try decrypting the MD5 hash value to the string. You can use &lt;a href="https://www.md5online.org/md5-decrypt.html" rel="noopener noreferrer"&gt;md5online&lt;/a&gt; website for this.&lt;/p&gt;

&lt;p&gt;After converting, the result is "abc123".&lt;br&gt;
To confirm if the password is correct, let us replace the value of the environment variable jennieandjayloveasm with abc123.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ export jennieandjayloveasm=abc123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, let us run your executable file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ./crackme2
&amp;gt;&amp;gt;&amp;gt; Access Granted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wheeeeeeew! &lt;br&gt;
You have the password to the file.&lt;br&gt;
You now have access to the file.&lt;/p&gt;

&lt;p&gt;Are you still here?&lt;br&gt;
I love you more! 💕 &lt;/p&gt;

&lt;p&gt;How did I come about this? I am currently enrolled in the &lt;a href="https://www.alxafrica.com/software-engineering-2022" rel="noopener noreferrer"&gt;ALX software engineering programme&lt;/a&gt;. And in one of the projects, we were asked to create a file that contains the password to an executable file.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7uqehgd6jgs5s61ii5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7uqehgd6jgs5s61ii5l.png" alt="snap of the task on ALX"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;image: &lt;a href="https://www.gettyimages.com/photos/password-lock" rel="noopener noreferrer"&gt;from gettyimages&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading. This was a long read and I hope it's helpful.&lt;/p&gt;

&lt;p&gt;Signing out: Your friendly beginner ❤&lt;/p&gt;

</description>
      <category>programming</category>
      <category>cpp</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Print vs Return in Python</title>
      <dc:creator>Heavens</dc:creator>
      <pubDate>Sun, 20 Mar 2022 04:47:32 +0000</pubDate>
      <link>https://dev.to/hi_heavens/print-vs-return-in-python-3ppd</link>
      <guid>https://dev.to/hi_heavens/print-vs-return-in-python-3ppd</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zUMP7Iso--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647713583456/YZCTM1WKu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zUMP7Iso--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647713583456/YZCTM1WKu.jpg" alt="print vs return.jpg" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I pondered on what my first post will be, like the luck of the genie, someone asked the below question and I jumped on it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Please, what's the difference in using return or print in a function for python?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me paint a really "long in a short story" here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Return - Come back&lt;/li&gt;
&lt;li&gt;Print - Shout or do something&lt;/li&gt;
&lt;li&gt;Function_name - Your errand boy&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, you sent your guy to buy something for you. Let us say, Chicken Republic's burger (my fav ❤) with the Monster drink and gave him your ATM card and PIN (hope you trust this friend though - &lt;em&gt;I won't be held accountable. Lol&lt;/em&gt; 😁).&lt;br&gt;
You told him on getting to the location, he should drop a flash on your mobile phone number.&lt;br&gt;
When he's done with the purchase and paid successfully, he should bring the items to you.&lt;/p&gt;

&lt;p&gt;Now, when he brings the items, you have unlimited options of things to do with them.&lt;br&gt;
You can either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;eat it&lt;/li&gt;
&lt;li&gt;drink it&lt;/li&gt;
&lt;li&gt;give to a friend&lt;/li&gt;
&lt;li&gt;keep it&lt;/li&gt;
&lt;li&gt;throw it away ...et al&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using the above, the &lt;strong&gt;print&lt;/strong&gt; in a function is like the dropped-flash that you asked your friend to give to you when he's at the location. When you call a function, you should do something.&lt;br&gt;
However, when you &lt;strong&gt;return&lt;/strong&gt; a value, just like when you asked your guy to come back with the items, you are instructing the function to &lt;strong&gt;come back&lt;/strong&gt; with something. &lt;br&gt;
This something can be used in any way that you like. Store in a variable, do nothing, used in an expression, et al.&lt;/p&gt;

&lt;p&gt;Now, let me add the samples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def say_name():
    name = 'alvicci'
    print("My name is {:s}".format(name))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you call the function, it will print the next line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;say_name()
My name is alvicci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, let us use the same function, but this time instead of using print, let us use the return keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def say_name():
    name = 'alvicci'
    return("My name is {:s}".format(name))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you call the above function, nothing happens. You didn't tell it to do something but to return something.&lt;br&gt;
What do we do to things that we receive? Lord and master, over to you, lordship. 😎&lt;br&gt;
Let me use what was returned to do something:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("What is your name? ")
print(say_name())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We called the function in the print function. So, it will evaluate the function, &lt;strong&gt;say_name()&lt;/strong&gt; first and give the return value to the print function.&lt;br&gt;
Now, you have given the print function something. And the print function always displays to the console what it was given.&lt;br&gt;
The output will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is your name? 
My name is alvicci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my first attempt ✍ and I hope you find this helpful. However, I'm still learning and growing!&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>devjournal</category>
    </item>
  </channel>
</rss>
