In my previous article here i showed how to begin ethical hacking with Python, despite being a very minimal overview it still gave a realistic view on how Python is used in the domain of ethical hacking and penetration testing
So I’ve always been fascinated by hacking scenes in movies and tv shows with those nerds abusing the heck out of their keyboard then be like “I’m in” and those crazy looking output screens in green text so i thought to myself “hmmmmm since Python is so great like that can i find packages to create cool console interfaces?” and the answer is HECK YES cuz it’s Python
So if you wanna seem cool for your friends or someone you like and look like a shady hacker with a crazy terminal gibberish in green text rather than the lame tree
command, then this tutorial is for you
Preparing For The Realest Fake Hack Ever
Firstly we need to download two libraries that will make up this tutorial and they are :
- Pyfiglet :
pip install pyfiglet
This library allows us to generate really neat ascii art inside our console just like what the cool kids do with their hacking tools and it’ll help us design a simple banner for our fake tool
2. Rich : pip install rich
This is probably the queen of console when it comes to styling your console application, rich helps us render an amazingly formatted rich texts and tables and prompts and just about anything and we’ll need it for tons of tasks for our tool like prompts and colors for the outputs
What Are We Doing With Those Two ?
In this tutorial we’re gonna be building a fake hacking tool called Cypher, of course after the cyber terrorist from Fast N Furious 8 and this tool will allow us to “hypothetically of course” hack anything from web apps to wifi access points to cell phones, etc
Now open up your favorite text editor and activate your virtual environment if you use any of those and let’s get to coding
Firstly as usual , we import our required libraries so
import pyfiglet
from rich.console import Console
from os import walk
Then we initialize a Console
object that will act as a way for us to print to the console but with a style
con = Console()
Just for demo purposes, let’s print something simple to the console
con.print("Hello world",style="bold green")
refer to the links above where i explained installing them to understand more about rich styling
Now creating the banner for Cypher
banner = pyfiglet.figlet_format("Cypher",font="banner3-D")# then printing that out with rich console and a little introcon.print(banner,"modern hacking framework to hack any possible device in the whole entire world",style="bold green")
So far we have the following output if we ran the program
Sounds scary doesn’t it :D, now let’s view the possible hacks in our super secret hacking framework and we’re gonna do this with rich
So rich provides us with a very nice way to organize our components inside panels to view them in more organized way and in this case we’re going to be offering only 5 types of hacks just for demo purposes and you’ll figure out how to add more on your own
from rich.console import Consolefrom rich.console import RenderGroupfrom rich.panel import Panelcon = Console()stuff = RenderGroup( Panel("Web App Hacking"), Panel("Phishing Attack"), Panel("Social Engineering Kit"), Panel("MITM Attack"), Panel("WIFI Hacking"),)con.print(Panel(stuff),style="bold green")
Now we run our program one and more time and should see such output on our console
Looking neat now !
Now let’s ask the user to pick any of those listed above using a dedicated class that rich provides that allows us to ask the user for an integer answer, which is in our case to pick from number 1–5 selecting a category
from rich.prompt import IntPromptanswer = IntPrompt.ask("Which one do you pick? ",choices=['1','2','3','4','5'])
Now we have stored what the user entered in the answer
variable, let’s add a little logic to our program
As a personal preference I’m going to set up some logic for the web app hacking choice and gonna show you how to create pretty progress bars so we look like we’re doing some magic
So back to the script, let’s add this part
from rich.progress import Progress,track
from os import walk def web_hacking(): for x in track(range(25),"Initializing..."): sleep(0.1) url = Prompt.ask("Enter the website's url") for i in track(range(100),f"Gathering information on {url}"): sleep(0.1) with Progress(transient=True) as prog : exploiting = prog.add_task("Exploiting the website",total=500) decoding = prog.add_task("Cracking the passwords hashes",total=300) dumping = prog.add_task("Dumping plain text passwords",total=900) while not prog.finished: prog.update(exploiting,advance=0.9) prog.update(decoding,advance=0.1) prog.update(dumping,advance=0.2) sleep(0.1) for x in walk("/"): con.print(x,style="bold green")
Now to invoke the function we need to specify that when the user picks the option ‘1’ we run this function so :
if answer == 2:
web_hacking()
Now when we run this program we should see those neat progress bars and a prompt to ask us to type in the website url, then the crazy os.walk()
output
This sums it up for the tutorial but there are other things YOU can add to both make this look cooler and to also learn more about rich
- Add more logic to other portions of the program just like how we did for the web hacking part
- Add more portions to it even like a fuzzer or an insta hacker
- Use
Markdown
class fromrich.markdown
to organize the code more in terms of the intro part of it so you can put some introduction stuff about your work and that sort of stuff in a separate.md
file then do something likemd = Markdown(open(my_markdown).read)
thencon.print(md,style="bold green")
And just like that you’ve learned how to look like a hacker and also learned about rich and how amazing it is for styling your depressing looking console
If you’ve made it this far, i really appreciate your time and interest and hoping to write what interests you in my next articles