May the Shell Be With You - task automation unleashed in UNIX/Linux
In my previous post 9 Windows Command Prompt Hacks: the power of black and white, I've talked about Windows command line and how helpful it is for troubleshooting purposes.
In the meantime I went through two Linux classes (operating system and network administration), so I've become much more comfortable with UNIX/Linux Bash Shell, and I've started writing pentesting scripts in Bash and Python for me to automate tedious tasks. I've ultimately finalized my detachment from Windows, which now I use only when strictly needed.
In the meantime I went through two Linux classes (operating system and network administration), so I've become much more comfortable with UNIX/Linux Bash Shell, and I've started writing pentesting scripts in Bash and Python for me to automate tedious tasks. I've ultimately finalized my detachment from Windows, which now I use only when strictly needed.
In this post I want to show you how to unleash the full power of a UNIX/Linux shell. It is a very powerful tool, often overlooked.
You can automate repetitive tasks and be more productive with some simple Bash scripting.
(By the way, your shell doesn't have necessarily to be black and white, at least in OS X. From Shell/New Window, you can choose different settings. Below you can see a shell with Basic settings and one with Ocean settings).
Examples of task automation through Bash Shell scripting:
- Create and delete 100 identical files: With a for loop in Bash, I created 100 identical copies of an empty text file. Then, I could delete them instantly with a simple rm -rf command (remove recursively with a force option). Execution time: a fraction of a second in both cases.
- Automated people reconnaissance: One of the most boring phases of a pentest (and at the same time the most important) is reconnaissance, when you gather information on a company, its employees, its network, etc. I've created a set of scripts for automating these tedious tasks. One of my scripts allows to automatically search for a person's name in a certain number of specialized search engines without any need for you to open them and enter the search string manually. Execution time: a fraction of a second.
- Automatic YouTube search: I watch a bunch of YouTube tutorial, because in my industry what you know counts only if you can do something with it. I'm lazy, so I created a script that automatically returns the videos I want off YouTube. Execution time: a fraction of a second.
Wrap-up
This is only a brief overview of what you can do by using UNIX/Linux command line.
I'm barely scratching the surface with this post and, as to myself, I'm a work in progress and got a long way to go.
I will always remember what my Linux professor, prof. Hartmann, whom I consider a mentor, used to say when I was in his class: "Have your computer work for you, don't work for your computer".
He explained us the way we use our computers is lame: they sit there idle 90% of the times waiting for our inputs and, when we need to do something, we do stuff manually, wasting a bunch of time.
Instead, we should automate tasks and have our computer work for us while we do something else (enjoy a sunny day, learn more advanced programming, etc.), using our time better.
We only have that much time left in this world, so let's make the most out of it.
We only have that much time left in this world, so let's make the most out of it.
How would you go about creating (or deleting) 100 identical copies of a file, like I did in the video?
Would you do it manually? Really?
There's no way in hell I could waste my time for something that dumb.
UNIX/Linux command line works alright for me, and has a much simpler syntax than Powershell (though Powershell is a very powerful tool for pentesting and hacking, as well) and fewer quirks.
It can count on 47 years' history and community support.
UNIX/Linux command line works alright for me, and has a much simpler syntax than Powershell (though Powershell is a very powerful tool for pentesting and hacking, as well) and fewer quirks.
It can count on 47 years' history and community support.
Moreover, if you set a task to be automatically run on a UNIX/Linux system, you can rest assured it will, without unexpected reboots for you to install automatic updates.
Let's picture a common case: you've scheduled an automated task your Windows computer has run for 11 hours, then you go check it and guess what? It's waiting for your input, asking if you want to reboot it, for it to install a darn automated update. Outcome: wasted time (I'm citing my mentor here).
That's why I can't be productive on Windows.
Not that you can't, but it's comparatively so darn hard. Too many interferences and external distractions (chatty pop-ups, notifications, questions. It drives me up the wall; let me get my darn job done in peace!).
Of course, that's the way it works for me, I don't judge or criticize anyone who has a different opinion about this. Windows fanboys can cuss how much they want, and use what they like, as far as I'm concerned.
As of myself, that Linux class changed me and I'm moving to more and more complex stuff.
Linux has become my daily routine, alongside with OS X, because I installed it on my laptop and it feels so gooood to run it without having to use virtual machines or USB drives.
Linux has become my daily routine, alongside with OS X, because I installed it on my laptop and it feels so gooood to run it without having to use virtual machines or USB drives.
I'm no genius, so each step forward requires bloodshed, cusses and endless frustration hours.
Sadly, I don't know any other way for this.
Comments
Post a Comment