Chapter 3: Bash and Python Scripting




Download 6,34 Mb.
Pdf ko'rish
bet127/203
Sana10.01.2024
Hajmi6,34 Mb.
#134102
1   ...   123   124   125   126   127   128   129   130   ...   203
Bog'liq
Linux This Book Includes 4 Manuscripts The Underground Bible

Chapter 3:
Bash and Python Scripting


Bash and Python scripting are the most popular automation programming
languages around the world. They have advantages and disadvantages
users should keep in mind. It can be difficult to choose which one to use.
To pick the right one, consider the task at hand, the context, and the ease or
complexity of the task. Bash is a Linux shell command language and is
wonderful for writing shell scripts that use CDL (Command Line Interface)
utilities.
Bash is preferred by many because it can use command-line commands the
way it is. Furthermore, it has better startup time compared to Python.
However, it has poor execution time performance. Bash is not compatible
with all shells such as zsh, and csh. It does not have good utilities and
debugging tools compared to Python. It also lacks various functions, multi-
threading, and data structures. On the other hand, Python performs general
functions than Bash. It can be used for any task and has simple syntax. It
has improved debugging tools than Bash. This makes it ideal for developing
complex software apps.
Many times, people prefer to use graphical based interfaces than those from
command lines. However, this is a wrong approach because the graphical
user interface tends to be for those who believe that the software does what
it is supposed to do, but that is not always the case.
It is far from the truth in the case of shell programming windows where
malware and viruses cause big issues. Therefore, those who use the
command-line interface think that what they are doing is correct. Other
times you are stuck, and the computer hangs because of a simple graphic
error. It is better to work on a command-line interface because it is fast, and
you know what you are dealing with.
However, not everyone likes writing programs and using shells. Apart from
writing programs, using some software would be worse than using a
graphic user interface. Shell scripting is elegant to use, and it allows you to
transfer the output of files. Shell scripting is fairly simple, but Python is
more powerful. Its strength lies in the sed or the Stream Text Editor. You
can combine shell and Python scripts to create and execute a chain of
commands. Some people argue that Python can replace Bash shell. Both


Bash and Python are for general language purposes, and they have strengths
and shortcomings.
Bash is a default terminal in Linux distributions and is faster regarding
performance. However, that does not mean that it can replace Python. It
gets complicated when dealing with large programs, but Python does not.
Moreover, Python can be employed as an object-oriented language, and it is
not a must to know the differences between the software. If you are
searching for an elegant scripting language, Python is the one. However,
this does not mean that Bash is less desirable. Bash is good at piping out
commands. Shell scripting is seamless when handling files and is good at
copying, storing file inputs, and cloning disks .
No matter how messy or cluttered your file system is, take delight in the
fact that your computer comes with an alternate reality found in the
command-line interface. It provides a direct way of interacting with your
computer and acts as a relief from dragging and clicking small boxes that
assume text-based commands. These commands tend to be mouse-agnostic
and hard to work with. We use several small utility applications in the
development of software. These applications lack graphical frontends and
are not important. Instead, command-line interfaces are used to interact
with these utilities. You can use utilities offered by the OS or a third party.
Y
ou should care about the functionality for a couple of reasons. For starters,
it gives insight into how the OS works. Furthermore, some routine tasks can
only be done using the command prompt. There are also vital utilities that
you can use in your everyday automation tasks. You need to install the Bash
shell to facilitate smooth hacking. Bash has gained popularity over the years
as a command line that is built into Linux and OSX.
It is currently offered as a built-in feature in Windows 10 versions. It is
alluring to think that a command-shell is part of your operating system.
Others believe that it is integrated into the computer without realizing that it
is just a program. The operation of the shell is made in such a way that
users enter commands from a set location and directs the OS on how to do
that. If you launch a program by clicking an icon, you will get similar
results. You can issue commands individually or through shell scripts. 


Shell scripts are files with many commands organized in a manner that they
perform complex functions. The command that a shell recognizes makes
up a programming language, albeit narrow. Bash comprises of many
features that are underused. There are diverse environments and work
styles that affect hacking. One of the best things you can do to become a
good hacker is to learn how to use Bash history. Learning how to use Bash
history effectively is an effective trick that not many know or care about.
To increase chances of success, enable the histappend option to your shell. 
Enabling this option is easy by running this command: shopt -s histappend.
Doing this facilitates several terminal sessions to write to history quickly. 
You find that this option is not enabled in most environments which leads to
loss of histories when more than one Bash session is opened. Alternatively,
you can use sudo to repeat the last command. For instance, if you want to
create a new directory mkdir/etc/asp/ft.d, this command will fail if you are
not the root.
Many users press the up arrow, scroll down and hit the sudo command.
However, this is unnecessary work and there is an easy way of doing things.
Run the command by typing: Sudo!! and Bash will run it and previous
commands. It looks like this when you run the sequence: mkdir: cannot
create the directory/ect/asp/ permission denied. It can also look like this:
sudo mkdir -etc/asp/ft.d. when you key in !!, the full command is derived
from the terminal and informs you what was executed. Another trick is to
use the!* shortcut, which informs the Bash that you want to repeat the
arguments from the previous command to the current one. 
It comes in handy for commands with several arguments you want to
repeat. To make work easy, create some files and change the permission on
them. It is easy to change the permission on the files and becomes difficult
only in some instances. You can search your history by pressing ctrl + r, and
it will pop up. The good thing about Bash is that it does a reverse search on
your history and when results appear immediately you start typing.
When running a shell, keep in mind that it is running inside a predefined
destination in your file system. The system has a directory where the shell
starts out. If you get lost, run the ‘pwd’ command to check which folder
you are in. We use a ‘cd’ command to change directories, which is followed


by a valid destination directory. To run a program, type the name of the
program and press enter. It will open fast and make you think you clicked it
on the GUI.
Every hacker should make an effort to learn how to use a programming
language to improve their skills. While it is okay to use available resources,
you should grow and develop better tools to help you maneuver the web
world. Because you are the one who knows what you want, you are in a
position to get useful tools to help you reach your target. Technology has
changed the world in unimaginable ways. Every day there are new hacks
that are developed, and hackers are not slowing down. If you continue using
old hacking tools, you will never reach where you want to be. If you launch
malware on a machine that has improved its security system will not only
stop the attack, but it could be traced back to you.
Another trick for navigating the dark web is to use quality and updated
tools. The number of hackers has increased tremendously, and new tools are
developed every day. As a hacker, you must know the current tools and how
they are used. If you want to stay relevant in the hacking game and make
more gains, know tools that people are using to stay ahead. The Internet is
your friend, and there is no need to be caught off-guard. Moreover, some
people offer free or affordable training on how to use such tools. Hacking is
for people who understand the web works and staying informed. Do not
make the mistake of thinking that you know everything because that is the
beginning of the end. While you cannot trust just anyone, there are few
trustworthy people you can work with to improve your hacking game.
Aspiring hackers cannot go far without having basic scripting skills. Lack
of such skills will limit you to using tools developed by others, which
lowers your chances of success. Moreover, it increases the chances of
getting caught out by antivirus software. Companies know that hacking is
on the rise, and they have adopted safety measures to protect themselves.
There are intrusion detection systems that alert companies in case of
intrusion. This is why it is important to learn python scripting skills. Having
these skills elevates you to a professional hacker, increase chances of
success, and minimize risks.


In fact, it eliminates risks! Python has features that make it important for
hacking. It comes with built-in libraries with strong functionality. You
should consider adding python modules because they provide a wide range
of capabilities such as math modules, exception handling, and file handling.
They also offer cryptographic services. Despite the advantages that come
with having python, you still need to have third-party modules. There are
extensive third-party modules for python, and that is why hackers choose it
for scripting. In case you need to install a third-party module, you can
download, and uncompress it and then run the python install command.
After the download, you uncompress it using tar. For example, kali>tar-xf
python-nmap-0.2 tar gz. After this, change the directory to a new one.
Kali>cd python-nmap-03. You can install the new module by keying in:
kali>python setup.py install. Now that you are familiar with how to install
modules in Python, it is time to know basic terms and concepts.
Formatting is the first concept of Python, and it is important, unlike other
scripting languages. Formatting is used by a Python interpreter to know
how code is grouped. Consistency is more important than details. For
example, if you have a group of code to start with double indentation,
consistency matters for Python to know that the code belongs in the same
group. In other formatting languages, formatting is optional, but here it is a
must. Similar to any scripting and programming language, Python can add
comments. It is important to add comments to inform the viewer of what
you are talking about. Comments are sentences or words that explain the
purpose of the code. While they are not necessary, it helps when you come
back later and cannot recall what the script was talking about. The
interpreter does not see the comments and lines with comments are skipped
until it reaches a line of code. Similar to other languages, # is used at the
start of a line as a comment. Another important Python concept is modules.
Python allows users to group codes in modules. You must import a module
in case you want to use it. Modules are the important features that give
Python all its powers. They form the basis of the Python scripting language.
There are also literal constants which require users to take texts for their
literal values.
Ethical hackers have the habit of writing nifty scripts, and recently, many
have opted for Python as the language of choice for such tasks. Python is
used for ethical hacking for various reasons. Hacking started many years


ago and was the term was coined at the Railway Club of MIT. Hacking has
evolved over the years to include sophisticated tools and tricks to maneuver
the dark web world. Since many people are aware of data privacy and data
protection, it has become a bit tricky to hack into systems .
Only those who are really professional at hacking and have been doing it
for some time will be able to sneak onto a network without being noticed.
Hacking is an illegal activity, and anyone found engaging in the practice
risks a jail term, depending on the harm caused. Companies have embraced
several measures to protect themselves from outside intrusion. Ethical
hacking is now a norm in several companies. Ethical hackers have the duty
of detecting and fixing security issues for companies before outside hackers
spot them. Python is used in ethical hacking because it is easy to understand
and use. Moreover, it is powerful and assures you of great results. It also
has nifty Python libraries including NAPALM and Pulsar, which make the
development of network tools easy. Most ethical hackers prefer developing
small scripts and Python offers amazing performance. What is amazing
about Python is that you get more than you bargained for. Learning Python
opens doors for other opportunities you could not have known.
There are tips you can use to become a good hacker using Kali Linux.
Hacking is just like any other activity, whether it is ethical and unethical.
That said, you need to have certain skills to be an excellent hacker. You
must be willing to learn new things continuously. A person who is a know it
all or is rigid cannot be a good hacker. You cannot excel with Kali Linux if
you are not open to learning different ways of doing things. It is okay to
believe in your skills, but that does not mean that you brush off everything
you hear .
Apart from having a learning attitude, you should have a good
understanding of at least one of the coding languages. It is not a must for
you to know every aspect of the coding language, but have a rough idea of
what it entails is important. You need to learn how to code, understand the
basic concepts of OS, markup many technologies, and fundamentals of
security and network. It has been said without a number that you can only
succeed using Bash and Python scripting if you understand what they entail.
You also need to know the platform you will code in. This is very important
because it gives a rough idea of what to expect and how to execute plans.


You should learn Python because it is popular owing to its portability. To
become an expert at hacking, understand the operating system level of
operations of a particular language you are using.
You also need to manage your expectations. There are many people who set
high expectations the first day they start hacking and end up disappointed.
They put unnecessary pressure on themselves, which hinders them from
enjoying the process. Make things easy by managing your expectations and
accepting the outcome. You might not manage to hack into a system right
away, but appreciating the milestones you have made makes it easy to move
on. It also gives you the motivation to try another time. Stay motivated for
what will come next instead of stressing over what went wrong. Everyone
has heard that they should never underestimate the power of system
administrators and networks. They have the ability to make you a slave in
the hacking world .
An application that resembles a free hoodie is not appealing. Any hacker
wants to use an application that boosts their confidence and gives them the
zeal to hack into systems. Let no one cheat you that how an application
looks are not important because that is far from the truth. The truth is what
you see is what you get. When an application is not pleasant to look at, the
chances are that it is not that great to use. Hence, don’t let anyone cheat you
into using just any application, especially those that you are not sure of. 
Applications are similar to clothes; how they look determines whether you
will buy them or not. There is a lot of different software that offers fancy
and glitzy experiences, but all of us know that there is more to it than what
meets the eye. 
There are layers that users will never see. For example, TechOps must start
the server and confirm that it is working properly. You may have a hoodie
that is a universal cover and can be worn anytime. Similarly, the Bash shell
is what keeps several software tools together. Apart from being universal, it
is a recurring TechOps problem. The syntax may be obscure in some cases,
and users get used to it. However, this does not make it okay. The aim of
bash-bashing is to minimize the use of the shell. Since shell comes is now
common, some examples can be given on how to translate shell scripts into
Python. The shell can be used for many things such as reading
configuration files, performing date arithmetic, managing files, and running


applications. They are also known to manage network resources with ease,
hence their popularity. It allows remote access of resources using wget and
curl. Managing network resources is easy using these programs.
Moreover, the script has vital steps that should be followed to increase the
chances of success. It kills the process by reading the file to get process ID
and then kill the commands. It also creates a directory to be used in the
next steps. The shell script runs an analytic application and copies the
output file in another location. Bash and Python Scripting play a big role in
hacking with Kali Linux, and users must understand how they work, how
and when to use them.

Download 6,34 Mb.
1   ...   123   124   125   126   127   128   129   130   ...   203




Download 6,34 Mb.
Pdf ko'rish