Hacking With Python - Beginner's Guide PDF
Hacking With Python - Beginner's Guide PDF
Python
Your Guide to
Ethical Hacking,
Basic Security,
Penetration Testing,
and Python Hacking
Hacking Made Easy
Evan Lane
Copyright 2017 – Evan Lane. All rights
reserved.
Printed in the USA
The information in this book represents
only the view of the author. As of the
date of publication, this book is
presented strictly for informational
purposes only. Every attempt to
verifying the information in this book has
been done and the author assumes no
responsibility for errors, omissions, or
inaccuracies.
In no way is it legal to reproduce,
duplicate, or transmit any part of this
document in either electronic means or
in printed format. Recording of this
publication is strictly prohibited and any
storage of this document is not allowed
unless with written permission from the
publisher. All rights reserved.
Respective authors own all copyrights
not held by the publisher.
The information herein is offered for
informational purposes solely, and is
universal as so. The presentation of the
information is without contract or any
type of guarantee assurance.
The trademarks that are used are without
any consent, and the publication of the
trademark is without permission or
backing by the trademark owner. All
trademarks and brands within this book
are for clarifying purposes only and are
the owned by the owners themselves, not
affiliated with this document.
Contents
Introduction
Chapter 1 Some of the Basics of Hacking
Chapter 2 How to Map Out Your Hacks
Chapter 3 Cracking the Password
Chapter 4 Spoofing Attacks to Fool Your
Target
Chapter 5 Hacking into a Network
Connection
Chapter 6 Hiding and Finding Your IP
Address
Chapter 7 Mobile Hacking
Chapter 8 Hacking Tools That Make
Your Hack Easier
Chapter 9 Tips to Keep Your Network
Safe
Other Books by Author
Introduction
address]
address]
exploit
this is going to provide you with
Spoofing
When we talk about spoofing, we are
talking about a technique of deception
that a hacker can use to pretend to be
another person or organization, a piece
of software or website, so that they can
get past any security protocols that keeps
them from getting ahold of the
information that they want. There are
many different spoofing techniques that
you can use including:
IP Spoofing
With this method, the hacker is going to
mask their IP address, usually the one on
the computer that they are using, so that
it can fool the network into thinking that
they should be the one the target is
communicating with. The network will
assume that this computer is supposed to
be there and will start sending the
communication through the hacker's
computer. This is going to be done by
imitation of the IP range or IP address so
that the hackers’ computer meets all the
criteria that the network administrator
sets.
DNS Spoofing
For this one, the hacker is going to work
with the IP address of a website in order
to send a user over to a website that is
malicious. Here, the hacker is then able
to get ahold of confidential and private
information or the user credentials. This
is another type of man in the middle
attack that will allow you to
communicate directly with the user
because they believe that they are
visiting a real and genuine website that
they typed into the search bar. This will
allow the hacker the ability to gain
access to a lot of information entered by
the users.
To make this one work, both the user and
the hacker should be on the same LAN
and to gain access to the LAN of the
user, the hacker can simply run some
searches for the weak passwords that
are connected to the LAN. All of this can
be done remotely. Once the hacker finds
what they want and gets the user over to
a fake website, they can start to monitor
all the activity that occurs.
Email Spoofing
This is a very common and efficient
form of spoofing that you can use. When
your email address has been spoofed,
the service of the email will see that any
email that the hacker sends is real and it
won’t be sent over to the spam inbox.
This will make it easier for the hacker to
send over emails that are malicious and
with lots of bad attachments right over to
the target. If the target opens one because
they assume that it is safe since it didn’t
go into the spam folder, there could be
some trouble and the hacker can easily
get on the system.
Phone number spoofing
With this option, the hacker is going to
use fake area codes or phone numbers to
mask their location and their identity.
This makes it easier for the hacker to tap
into your messages on the phone, to send
out text messages using the spoofed
number, and to falsify where their phone
calls are coming for. This can be really
effective for the hacker who wants to do
a social engineering attack.
Spoofing attacks, when they are done
properly, can cause a lot of damage
because the network administrator is
often not going to be able to detect that it
is going on. The security protocols that
are in place for protecting against this
kind of thing is actually what is letting
the hackers communicate through the
network. Often these spoofing attacks
are just the beginning and many hackers
move on to doing man in the middle
attacks as well.
Man in the Middle Attacks
After the hacker can get onto the system,
it is likely that they will perform a main
in the middle attack. Some hackers are
happy to just get onto a system and get
access to the data and to eavesdrop on
the company, some will want to turn to
an attack that is more active so that they
can control what goes on. These are
known as man in the middle attacks.
A man in the middle attack is possible
when the hacker does ARP spoofing.
This is basically when the hacker sends
over false ARP messages to the network
that they hacked. When these are
successful, these messages will allow
the hacker to link the MAC address of
their computer over to the IP address of
someone who is allowed to be on the
network. Once these are linked, it is now
possible for the hacker to receive any
and all of the data that is sent by users
over their IP address. Since the hacker
has access to the data on this network, as
well as any information that is received,
there are now a few things that they are
able to do including:
Session hijack: the hacker will be able
to use their false ARP to steal the ID of
the session so that they are able to use
these credentials later on to get into the
system.
DoS attack: this can be done right at the
same time as the ARP spoofing. It is
going to link the name of the networks IP
address over to the MAC address of the
hacker. All the data that the network is
sending over to the other IP addresses
will now be rerouted to this one device
and will cause a data overload.
Man in the middle attack: the hacker
basically becomes part of the network,
but no one else can see that they are
there. They can modify or intercept the
information that goes on between the
targets. Then the information can be sent
back through the system without either
party knowing that the hacker was there.
So now that we know what the man in
the middle attack is about, let’s take a
look at what you would do to carry out
one of these ARP spoofs and then initiate
a man in the middle attack with Python.
For this one, we are going to use the
Scapy. We are also going to have the
target and the hacker's computer be on
the same network of 10.0.0.0/24. The IP
address of the hacker's computer is
going to be 10.0.0.231 and their MAC
address is going to be 00:14:38:00:0:01.
For the target computer, we are going to
use an IP address of 10.0.0.209 and their
MAC address is going to be
00:19:56:00:00:01.
So here we are going to begin this attack
by forging an ARP packet so that the
victim is fooled, and we will be able to
use the Scapy module to make this
happen.
>>>arpFake = ARP()
>>>arpFake.op=2
>>>arpFake.psrc=”10.0.01.1>arpFake.
###[ARP]###
hwtype=0x1
ptype=0x800
hwlen=6
plen=4
op= is-at
hwsrc= 00:14:28:00:00:01
psrc= 10.0.0.1
hwdst= 00:14:38:00:00:02
pdst= 10.0.0.209
If you take a look at the ARP table for
the target, it is going to look like the
following right before the packet is sent:
user@victim-PC:/# arp-a
?(10.0.0.1) at 00:19:56:00:00:001
[ether] on eth 1
attacker-P.local (10.0.0.231) at
00:14:38:00:00:001 [ether] eth 1
Once you have been able to send this
packet with the help of Scapy by using
the >>>send(arpFake) command, the
ARP table for the target is going to look
like the following:
user@victim-PC:/# arp-a
? (10.0.0.1) at 00:14:38:00:00:01
[ether] on eth 1
Attacker-PC.local (10.0.0.241) at
00:14:38:00:00:01 [ether] eth 1
Now this is a good start, but the problem
with this one is that the default gateway
is eventually going to send out the ARP
with the right MAC address, which
basically means that at some time, the
target isn’t going to be fooled any more
and the communications will stop going
straight to the hacker. The solution to this
is to do some sniffing in the
communications and wherever the
default gateway ends up sending the
ARP reply, the hacker is going to spoof
the target. This is what your code would
look like to get this done.
#!/usr/bin/python
# Import scapy
from scapy.all import*
# Setting variable
attIP=”10.0.0.231”
attMAC=”00:14:38:00:00:01”
vicIP=”10.0.0.209”
vicMAC=”00:14:38:00:00:02
dgwIP=”10.0.0.1”
dgwMAC=”00:19:56:00:00:01”
# Import scapy
from scapy.all import*
# Setting variables
attIP=”10.0.0.231”
attMAC=”00:14:38:00:00:01”
vicIP=”10.0.0.209”
dgwIP=”10.0.0.1”
dgwMAC=”00:19:56:00:00:01”
Hacking Apps
One of the easiest ways to get onto one
of these mobile devices is to create an
app. This is easy to do and very quick
because the target will be able to upload
the app and often they will download all
the malicious stuff that comes with the
app without even really checking to see
how safe it is. Mobile apps are usually
accessed with the help of binary codes,
which is the code that the device is
going to need to have to execute any
code. This means that anyone the access
to hacking tools will have the ability to
turn them into an exploit. Once the
hacker has been able to compromise any
of the mobile apps, it is easy to carry out
their first compromise right away.
The binary code is going to be great for
the hacker because it increases all the
things that they are able to do inside of
the code. Some of the best ways that the
hacker can use this code to their
advantage include:
Modify some of the code
Whenever a hacker gets in and makes
some changes to this code, they are
basically disabling the security controls
that come with the app, as well as some
of the other information such as purchase
requirements and ad prompts. After this
is done, they will place the app out on
the market as a new application or a
patch.
Inject some code that is malicious
A hacker is also able to take the binary
code and inject something more
malicious into it. Then they will just
distribute this as an update or a patch for
the existing app. This is going to fool
any of the app users because they
believe that they are getting a legitimate
update to their app and they will be
happy to upload it to the mobile device.
Reverse engineering
Hackers who can get ahold of some of
the binary code will be able to do a
reverse engineering hack. This kind of
hack is great because it is going to show
up some more of the vulnerabilities,
make some fake apps that they can use
on the system, or rebrand the app so that
the user will take it again.
Ipscan
This one is also known as the Angry IP
Scanner as well and it is used to track
any computer that you want by the IP
address. When you place in the IP
address of the computer you want to
track, it is going to snoop around in the
ports to find out if there are some
gateways that go straight to the target
system.
Kali Linux
This is a version of Linux that does very
well in the hacking world because it has
a lot of features. You can use any
operating system that you want to do a
hack, but Kali Linux as a lot of the
features that you want to see the hack go
well and it works with Python already
so you won’t have an issue with that.
Kali is set up to contain all the interfaces
that you would want to use to get started
in hacking and this even includes the
ability to send out spoof messages, crack
into Wi-Fi passwords, and even create
some fake networks.
Cain and Abel
If you are working for a toolkit that can
go against some of the Microsoft
operating systems, Cain and Abel is the
one that you should pick. It is going to
work to help you with many things such
as doing brute force to get through a
password, recover passwords for some
of the user accounts, and even figure out
the password to the Wi-Fi.
Burp suite
If you are working on mapping out your
computer network, you need to use the
Burp Suite. This tool is going to work
for mapping out the vulnerabilities that
are in your website and it will let you
look at, as well as take the time to
examine, all the cookies that are on a
particular website. You are also able to
use it in order to start some new
connections inside of one of your
applications. This can give you a good
idea of where a hacker may try to get
into your system because it shows all of
the map of where your network is online.
Ettercap
If you are interested in doing a man in
the middle attack, Ettercap is one of the
most efficient tools for making this
happen. These kinds of attacks are
basically designed to make two different
systems think that they are talking to each
other, but in reality, each of them is
talking to a middle computer (which the
hacker will put there themselves). The
middle computer is able to either look at
the information that is being sent or they
can manipulate it and make changes
before sending it on to one of the other
computers. This helps them to intercept
some of the information, read through it,
eavesdrop, and do a lot of damage on a
company network.
Metasploit
This tool is really popular because it is
great at taking a look at a system and
then identifying the security problems
that may be there as well as taking the
time to verify the mitigation of
vulnerabilities that are in the system.
This makes it one of the best tools to use
for cryptography because it can not only
get the information that is needed, but it
can efficiently hide the location as well
as the identity of the attack so it is hard
for the system administrator to find the
information that they need.