Introduction
It is common practice amongst ethical hackers to write nifty scripts and automate any structured process, ranging from small network scans to wide area network packet sniffing. In recent years, Python has become the language of choice for such tasks, and there are good reasons for this.
What is Ethical Hacking?
The term hacking goes a long way back. To be exact, it all started at the Railroad Club of MIT, where both the term 'hacking' and 'hacker' were first coined. It's been almost 50 years now, and hacking has evolved into a discipline in the current day and age.
With the increase in awareness regarding data protection and data privacy, hacking has been deemed as an illegal activity today. If caught, there's a good chance that you will be prosecuted for quite some time depending on the degree of harm caused.
None the less, to protect themselves from hackers of all sorts, employment of Ethical Hackers has become a common practice amongst organizations. Ethical hackers are given the responsibility of finding and fixing security flaws for a certain organization before black hat hackers find them.
What is Python?
Python is a general-purpose scripting language that has gained immense popularity amongst professionals and beginners for its simplicity and powerful libraries. Python is insanely versatile and can be used for almost any kind of programming.
From building small scale scripts that are meant to do banal tasks, to large scale system applications – Python can be used anywhere and everywhere. In fact, NASA actually uses Python for programming their equipment and space machinery.
Why use Python for Ethical Hacking?
Python has gained its popularity mostly because of its super powerful yet easy to use libraries. These libraries find uses in all sorts of domains:
- Nifty libraries like Pulsar, NAPALM, NetworkX make developing network tools a breeze
- Scripting language - Python being a scripting language provides amazing performance for small programs
- Huge community - Any doubt related to programming is quickly solved by the community
- Career opportunities - Learning Python opens doors to several career paths
Demo: Dictionary Attack using Python
Let me give you a small demonstration of how an ethical hacker may use Python in their day to day job. Here's a simple password cracker using the dictionary attack method:
python
Copy
1import hashlib 2 3flag = 0 4pass_hash = input("md5 hash: ") 5wordlist = input("File name: ") 6 7try: 8 pass_file = open(wordlist, "r") 9except:10 print("No file found :(")11 quit()1213for word in pass_file:14 enc_wrd = word.encode('utf-8')15 digest = hashlib.md5(enc_wrd.strip()).hexdigest()16 17 if digest.strip() == pass_hash.strip():18 print("Password found!")19 print("Password is " + word)20 flag = 121 break2223if flag == 0:24 print("Password not in list")
Conclusion
This is one of the many ways Python can be used in ethical hacking. The simplicity of the language combined with powerful libraries makes it the perfect choice for security professionals.