Skip to main content

Creating password linux cracker with python (☞ ͡° ͜ʖ ͡°)☞ (day 21)



Ever since 2017, python programming language had a steady increased of popularity not just in the area of data analysis but in penetration testing. If you try to look into one of the famous websites for penetration testing, "exploit DB" you can sense that programming language that usually used to create ax exploit is either ruby, c or python.

So in this post, I'm going to show you how you can implement python into your pentesting project. We are going to create your own password Linux cracker with python.

Background:

Before we go to the actual coding, let me explain it to you about some fundamental concepts:

  • First, we need to know how Linux stored its password. Originally, Linux stored its own password in two different file one is located at "/etc/provides" which is contained the username (every user inside the operating system can see inside of the file ) and the other one which is located at "/etc/shadow" contained the actual password but it stored in sha512 hash. You can see the format of the Linux password below
 $ID$SALT$ENCRYPTED
    • The ID is for what type of encryption do you use:
      • $1 = MD5
      • $2a = blowfish 
      • $2 = blowfish
      • $5 = SHA-256
      • $6 = SHA-512 
    • The SALT random strings (8 <= n <= 16 char)
    • $ENCRYPTED, the encrypted string
  • For quick testing, you can use "I" utility from Linux to generate your own password

Getting your hand dirty:

we need to import some important libraries, crypt for doing the hashing process and sys to add some command line functionality in the program:

import crypt
import sys



Next is to create a function that will return the hash:

def crack_password(salt,plain_text):
        return crypt.crypt(plain_text,"$6$%s" % salt)

The functionality of the crypt library is almost the same as mkpasswd you need to provide three value, the id, the salt, and the plain text. The rest of the source code is like this:

file = open(sys.argv[1])
result = []

for x in file.readlines():
        temp = x.rstrip("\n")
        salt = temp.split("$")[2]
        dictionary = open(sys.argv[2])
        for y in dictionary.readlines():
                temp2 = y.rstrip("\n")
                if crack_password(salt,temp2) == temp:
                        result.append(temp2)
                else:
                        print "try:" + y.rstrip("\n")
print "----------------result----------------"
print result

file.close()
dictionary.close()

the program i create assume that the user provide two files, first is the file contain a string of Linux password that will be decrypted and the second file is the dictionary file that will use to match the hash (https://github.com/danielmiessler/SecLists/tree/master/Passwords)

that's why for usablity i use the sys function so all you have to do is to write the name of the two files in front of the program and it will automatically do the decryption.

example: python password_decryptor.py file_contain_linux_password file_contain_dictionary_list

the first loop deal with iterating through the encrypted word inside the file, don't forget to strip the "\n" at the end of every line

the second loop will try to match the result of the dictionary list with the encrypted word. Once the program got a match result it will append to the result variable.

Result:

The file contains Linux password(first file):


$6$nnghqtzilxdhtkfk$CD0wgI..IQSGKobZ/PNW8zxW.VYKdU700rk9rILxrOR.M9yBntu1PrYEzzxLsiDyyjsISlSm.mkhh239X2ROc0
$6$aevmjnyzbrnqrxkq$TUbMkd34Gvk87s5iiF5VBveNIDsy/MNPyGCMTAPyYZjEPI100RUdwbY6K.WV83oqPBq7B7wlWqaW2ZtZtbvW01
$6$ysuucnvahyhnutcg$8g8MHX.Uh2FGaig6lAFOijcM8zXf4.7Ui0zp9l04ECZeP.5OIeukp0JNPZSipDkDSCLrP4LfzUXSSVemNXDwJ/
$6$kunaekvqyhyouoqu$DClxoXyV8BmkaV0q8zd4otc5aUZDdPWVNlIRwqDWZ2MtM7Sya156CpD/vVqaIyjPeKCJmmFvsn5DNHyJWGzKl0

The file contains dictionary list(second file):





Run it:




 Yea we got the string, that's all have a great weekend guys











Comments

Popular posts from this blog

Having fun analyzing nginx log to find malicious attacker in the net (ง'̀-'́)ง (day 37)

  What makes you sleepless at night? is it because of a ghost or scary stories? is it because you have an important meeting tomorrow? or is it because you have an exam? For me, what keeps me up all night is that I keep thinking about what happens to a website that I just created, is it safe from an attacker (certainly not) or did I missing some security adjustments that lead to vulnerability? well I'm not the best secure programmer in the world, I'm still learning and there is a big possibility that I can make a mistake but for me, a mistake can be a valuable investment to myself or yourself to be better so from this idea, I want to know more about what attackers casually do when attacking a website. Here in this post, I'm going to show you how I analyzed attack to the website that I have permission to design and also some interesting findings that I could get from the analysis Background: All of this analysis comes from the traffic that is targeted to th...

Utilize Pwntools for crafting ROP chain :') (day 69)

who doesn't like pwntools? it is a very versatile tool and can be customized according to our need using the python script but did you need to know that pwntools itself can help us to automatically craft a rop chain for us? so in this post, I will show you how to make rop chain less painful and make pwntools do all the heavy lifting. To demonstrate this I will use the binary challenge callme 64 bit from ropemporium link: https://ropemporium.com/challenge/callme.html Crashing the app: Like any other exploitation process, we need to crash the program by generating a long string pattern to determine the offset. based on the information from the above figure we can see that we required to provide 40 bytes of offset Fun stuff: now this where the fun stuff began write the following python script: as in the guideline of the challenged said we need to chain the function call by first to call the callme_one function, callme_two function and then callme_three funct...

Why you should always cautious on your VPN: Study Case on Broken Cryptography of Android VPN (day 91) ಠ_ಠ

source: https://me.me/i/when-you-make-a-meme-in-europe-but-you-use-22778509 Disclaimer: This blog post is heavily based on https://www.youtube.com/watch?v=ofTts7jlC2Y&t=177s created by Lukas Stefanko. I strongly suggest you guys check his youtube videos it contain many great android security study cases that you can learn free Background: Who doesn't know VPN, right?! It is a wonderful program that lets us maintain the confidentiality of our identity and information while surfing the internet. It is fast and more importantly is "FREE!" there are tons of free VPN applications that you can download in play store and use it in a click of a button. The workflow is also not really that difficult to understand: Source: https://blog.sucuri.net/2020/03/vpn-secure-online-work-environment.html Pay attention to the above figure, this diagram explains the difference in our connection when using a VPN and not using VPN. When using a VPN before we connect to ...