Lecture08-Post-Exploitation-Part1
Lecture08-Post-Exploitation-Part1
2: Scanning
1:Reconnaissance 3:Exploitation
4: Post
Exploitation
5: Writing
Report
2
Lecture outline
■ Post Exploitation Overview
■ Privilege Escalation
■ Information Gathering
■ Removing traces
■ About Rootkit
3
Post Exploitation Overview
■ This stage is as important as other stages. Many critical
tasks are done in this stage:
▬ Privilege escalation
▬ Network/system information gathering
▬ Removing traces
▬ Applying rootkits
▬ Installing backdoors
▬ and much more …
■ This lecture focuses on the first four, and the next lecture
will discuss installing backdoors.
4
Lecture outline
■ Post Exploitation Overview
■ Privilege Escalation
■ Information Gathering
■ Removing Traces
■ About Rootkit
5
Privilege escalation overview
■ Often, especially with client side exploitation, we only have
limited user privileges with Meterpreter or other sessions
obtained.
▬ Why?
6
Methods of privilege escalation
■ There are several methods to escalate privileges.
■ We'll talk about the following two in this lecture:
▬ The 'getsystem' command in Meterpreter
▬ Using certain local exploits
7
By ‘getsystem’ command
8
Obtain a meterpreter with user privilege first
■ Login Win7 with the account of ‘Alex’, which is an ordinary user
account. Alex browses the malicious page generated by
exploit/windows/browser/ie_unsafe_scripting
■ When you use the above exploit, make sure to:
▬ set prependmigrate true
▬ set prependmigrateproc explorer.exe
▬ NB: The migration to the true explorer.exe is optional.
9
The usage of getsystem
'-h' gives the help information
10
Simply enter 'getsystem'
11
Local exploits overview
■ Local exploits are the exploits applied after you have gained
access to targets.
▬ E.g., after you have logged into a target through either its monitor or a
Meterpreter session.
12
Local exploit example
■ Next, we'll use the local exploit
exploit/windows/local/ms14_058_track_popup_menu as an
example.
▬ It exploits a NULL Pointer Dereference in win32k.sys. The vulnerability
can be triggered through the use of TrackPopupMenu. Under special
conditions, the NULL pointer dereference can be exploited to achieve
arbitrary code execution.
▬ It will create a new Meterpreter session with SYSTEM privileges.
14
Step 2. Select a local exploit
■ Here we choose the aforementioned local exploit for privilege
escalation:
exploit/windows/local/ms14_058_track_popup_menu.
▬ Besides the existing Meterpreter session, this exploit can start a brand-
new Meterpreter session with system privilege.
▬ Note that the payload is defaulted to windows/meterpreter/reverse_tcp.
We need to change it to its x64 version:
windows/x64/meterpreter/reverse_tcp
15
Step 3. Show architectures supported
by this exploit
■ In the exploitations discussed in previous lectures, this
step is skipped.
■ But for local exploits, this step is usually needed.
■ The command for this step is 'show targets'
16
Step 4. Select the architecture matching
the target
■ Since our Win7 VM is a 64-bit OS, we need to do:
▬ set target 1
17
Step 5. Show options
19
Step 7. Launch the attack
■ Simply enter 'exploit'
21
If the local exploit
'exploit/windows/local/ms18_8120_win32k_privesc' is
used instead, you'll be also successful.
22
Lecture outline
■ Post Exploitation Overview
■ Privilege Escalation
■ Information Gathering
■ Removing Traces
■ About Rootkit
23
Information Gathering Overview
■ After exploitation, plenty of information can be gathered
with the gained access.
■ Meterpreter provides many commands and scripts for
gathering information. We'll talk about:
▬ Command sysinfo
▬ Command hashdump
▬ Command idletime
24
Meterpreter Command: sysinfo
■ Gets information about the remote system: hostname, OS version, CPU
architecture, the number of user accounts logged in, etc.
25
Meterpreter command: hashdump
■ Dump the password hash file to the screen.
27
Notes on password cracking tools
■ Popular password cracking tools include:
▬ Hashcat
▬ John the ripper
▬ Brutus
28
Meterpreter command: idletime
■ Display the idle time of the logged-in user.
29
Lecture outline
■ Post Exploitation Overview
■ Privilege Escalation
■ Information Gathering
■ Removing Traces
■ About Rootkit
30
Events Logging Overview
■ Events logging is important for statistics, security, and
diagnosis purposes.
■ Unix-like systems such as Linux use the syslog standard
for logging events.
■ Windows has its own way.
▬ In Windows, logs can be viewed by Event Viewer.
31
About the syslog in Linux
■ The syslog standard employs a syslog daemon (syslogd) to
log events, thus allowing the separation of log generation,
log storage, and log analysis.
■ Each log basically consists of:
▬ Facility code: indicating the software type generating the log
▬ Severity level: indicating the severity of the log
▬ Message: the detailed log message
Reference: https://en.wikipedia.org/wiki/Syslog
32
Viewing system logs in Linux
■ Most log files in Linux are located under the /var/log
directory.
■ You can 'cd' that directory, and use any text editor to look
at those log files.
▬ You can try this with Kali Linux and Metasploitable2.
■ If you prefer GUI, you can use the 'System Log Viewer'.
▬ To start it, search 'system log' in desktop search
▬ Not all Linux distros provide a GUI for syslog.
Reference: https://www.linux.com/learn/sysadmin/viewing-
linux-logs-command-line
33
Removing traces from log files in Linux
■ You need to be clear which log files may contain your
traces.
▬ For Ubuntu Linux, see:
https://help.ubuntu.com/community/LinuxLogFiles
▬ Different Linux distros often use different log files, which requires you
to do some homework on the target system.
■ Then, you can use any text editor to search and remove
logs about you.
34
Event Viewer in Windows
■ Event Viewer is a component of MS Windows to allow
administrators and users to view the logs generated by OS
and applications.
▬ To start the Event Viewer: search it or run 'eventvwr'
35
Log types in 'Windows Logs'
■ Application: from legacy applications for Windows
▬ At that time, there is no 'Applications and Services' category yet.
37
Viewing logs in Event Viewer
■ You can simply click on a log type and view all log records under
that type.
■ It is better to apply a filter such that you only view the log records
you want to view. The filtering can be done by Event Level, Event
Sources, etc.
38
Clear all logs in Event Viewer
■ If you want to completely delete all logs such that Event
Viewer sees no logs, Meterpreter provides an easy
command for achieving this: clearev (clear events).
■ In a Meterpreter session with system privilege, you simply
enter clearev:
39
'Clearev' Example: in Win7 VM
■ Before executing clearev: e.g., 1887 events in Application
40
Notes to 'clearev'
■ Though it is not stealthy, it can remove all events such
that no trace for a hacker can be found.
■ In this subject, we simply require you to know that you can
do trace removal with 'clearev' on Windows platforms, and
will not dive deeper than this.
41
Lecture outline
■ Post Exploitation Overview
■ Privilege Escalation
■ Information Gathering
■ Removing Traces
■ About Rootkit
42
Rootkit Overview
■ Rootkit typically refers to a kind of software that gains
unauthorized access to computers and can hide its
existence or other programs' existence.
▬ Mostly, it is purely for hiding the existence of other programs.
References:
1. http://www.microsoft.com/security/portal/mmpc/threat/ro
otkits.aspx
2. https://en.wikipedia.org/wiki/Rootkit
43
How Rootkit Works
■ Rootkit intercepts or modifies system calls provided by
OSes.
▬ This means that after a rootkit is installed, you can’t trust any
information that system calls return.
■ For example,
▬ If you ask your PC to list all processes that are running, the rootkit
can remove the processes it doesn’t want you to see.
▬ The same applies to files and folders.
44
How to remove rootkits?
■ In general, you need to boot your computer with another
OS and then use antivirus software to scan the disks.
▬ Another OS is needed as the current OS is already modified.
45
Remarks on rootkits
■ Similar to trace removal, rootkits are another mechanism
for hiding hacking activities.
■ Since 'rootkit' is an advanced topic, this subject won't
have lab tasks on rootkits. However, it is important for you
to know the basic working principle of rootkits mentioned
in the previous slides.
46
Example Short Answer Question:
■ Give two examples on what rootkits can do.
47
Lecture Summary
■ The stage of Post Exploitation happens after the access to
the target has been gained. It includes activities such as
privilege escalation, backdoor installation, etc.
■ A key technique for privilege escalation is to apply local
exploits.
■ Removing traces enables hackers to hide their behaviour.
48
References
■ Online Tutorial from Offensive Security: Metasploit
Unleashed
▬ https://www.offensive-security.com/metasploit-unleashed/
Big reminder:
• Lab 8 is very long, consisting of tasks for
this lecture and the next lecture. You should
start working on it right now!
49