Open In App

Ethical Hacking with Python

As a Computer Science Engineer who encrypts the world, one should know how Hacking activities are done. And we must stand front in protecting our world from cybercriminals.

Being able to gain access to a system that you’re not supposed to have access to is known as Hacking. For example, login into an email account without authorization is considered hacking that account. Gaining access to a remote computer without authorization is hacking that computer. So you can see that there are a large number of ways to hack into a system and the word hacking can refer to a number of things but the main concept is the same. Gaining access or being able to do things that you’re not supposed to be able to do, is considered hacking.



Ethical hacking: 
To crack passwords or to steal data? No, it is much more than that. Ethical hacking is to scan vulnerabilities and to find potential threats on a computer or networks. An ethical hacker finds the weak points or loopholes in a computer, web applications or network and reports them to the organization. So, let’s explore more about Ethical Hacking step-by-step.

These are various types of hackers



Note: To know more about types of hackers click here.

Why Python Programming For Hacking

Python is a widely used general-purpose, high-level programming language. Python is a very simple language yet powerful scripting language, it’s open-source and object-oriented and it has great libraries that can be used for both for hacking and for writing very useful normal programs other than hacking programs. In the future and present era python is very popular and it’s easy to learn, learning to hack with python will be fun and you will learn python programming in the best way. There is a great demand for python developers in the market.
Note: To know more about python click here.
 

How Password Are Hacked

Everyone knows that passwords are not stored a plain text in the website’s database. Now we are going to see how to hack a plain text password when you find a password that is in hashed(md5) format. So we take the input_hash(hashed password in the database) and try to compare it with md5 hash of every plain text password which is in a password file(pass_doc) and when the hashes are matched we simply display the plain text password which is in the password file(pass_doc). If the password is not present in the input password file it will say password is not found, this happens only if buffer overflow doesn’t occur. This type of attack can be considered as a dictionary attack.

Below is the implementation. Let’s suppose the text file containing list of password is password.txt.




import hashlib
print("**************PASSWORD CRACKER ******************")
        
# To check if the password
# found or not.
pass_found = 0                                     
 
input_hash = input("Enter the hashed password:")
 
pass_doc = input("\nEnter passwords filename including path(root / home/):")
  
try:
    # trying to open the password file.
    pass_file = open(pass_doc, 'r')             
except:
    print("Error:")
    print(pass_doc, "is not found.\nPlease give the path of file correctly.")
    quit()
 
 
# comparing the input_hash with the hashes
# of the words in password file,
# and finding password.
 
for word in pass_file:
    # encoding the word into utf-8 format
    enc_word = word.encode('utf-8'
             
    # Hashing a word into md5 hash
    hash_word = hashlib.md5(enc_word.strip())  
  
    # digesting that hash into a hexa decimal value    
    digest = hash_word.hexdigest()        
      
    if digest == input_hash:
        # comparing hashes
        print("Password found.\nThe password is:", word)  
        pass_found = 1
        break
 
# if password is not found.
if not pass_found:
    print("Password is not found in the", pass_doc, "file")  
    print('\n')
print("*****************  Thank you  **********************")

Input: 

Enter the hashed password :  061a01a98f80f415b1431236b62bb10b 
Enter passwords filename including path(root/home/) : password.txt

Output: 

Password found.
The password is : vivek 

Input:  

Enter the hashed password :  aae039d6aa239cfc121357a825210fa3 
Enter passwords filename including path(root/home/) : password.txt

Output  

Password found.
The password is : jessica 

 


Article Tags :