Exploit vulnerabilities and vulnerability prevention implementation
Building a Vulnerability Detection Application for CVE-2017-8464
CONTENTS:
PART 1: OVERVIEW OF CVE-2017-8464
CONCEPT OF LNK FILE CREATING A SYSTEM VULNERABLE TO CVE-2017-8464 TOOLS FOR EXPLOITING CVE-2017-8464PART 2: USING METASPLOIT TO EXPLOIT CVE-2017-8464
2.1. EXPLOITATION MODEL FOR CVE-2017-8464
2.2. EXECUTING THE EXPLOIT FOR CVE-2017-8464
PART 3: BUILDING A CVE-2017-8464 DETECTION TOOL USING PYTHON
3.1. ANALYZING THE SIGNATURE OF CVE-2017-8464 BASED ON CAPTURED NETWORK PACKETS
3.2. FUNCTION TO DETECT CVE-2017-8464 EXPLOITS BASED ON PACKET SIGNATURE ANALYSIS
CONCLUSION
**
PART 1: OVERVIEW OF CVE-2017-8464
LNK is a System File - Windows Shortcut, in Binary format developed by Microsoft.

Figure 1: Shortcut icon on Windows
An LNK file is a shortcut or "link" used by Windows as a reference to an original file, folder, or application, similar to an alias on the Macintosh platform. It contains the shortcut's target type, location, and filename, as well as the programs that open the target files and an optional shortcut key. These files can be created in Windows by right-clicking a file, folder, or executable and then selecting Create shortcut.
This vulnerability exists in Microsoft Windows and allows an attacker to execute remote code if the icon of a specially crafted shortcut is processed.

Figure 2: Manually creating a shortcut that executes, loads, and runs attack code via .LNK file
The vulnerable component is linked to the network stack. Such a vulnerability is often called “remotely exploitable” and can be considered an attack that can be exploited at the protocol level or across multiple network hops (e.g., through one or more routers).
Systems affected by CVE-2017-8464 are the Windows Shell in Microsoft Windows Server 2008 SP2 and R2 SP1, Windows 7 SP1, Windows 8, Windows 8.1, Windows Server 2012 Gold and R2, Windows RT 8.1, Windows 10 Gold, 1511, 1607, 1703, and Windows Server 2016, which allow local users or remote attackers to execute arbitrary code via a specially crafted .LNK file that is not properly handled when displaying icons in Windows Explorer or any other application that parses shortcut icons. Also known as the "LNK Remote Code Execution Vulnerability."
The security update fixes the vulnerability by correcting the validation of shortcut icon references. Microsoft Windows released an update for this vulnerability in June 2017. This vulnerability does not affect Windows XP and older Windows versions.
Metasploit
Metasploit Framework is an environment for testing, attacking, and exploiting services using the command line interface. This tool is available on Kali Linux VMware version.

Figure 3: Metasploit Tool
Armitage
A graphical interface tool based on the Metasploit project.

Figure 4: Armitage Tool.
PART 2: USING METASPLOIT TO EXPLOIT CVE-2017-8464
2.1. EXPLOITATION MODEL FOR CVE-2017-8464
Victim machine – Windows 7 Pro

Figure 5: Victim's operating system version

Figure 6: Victim machine IP address
Attacker machine – Kali Linux – Using Metasploit.

Figure 7: Attacker machine IP address
The active network is VMnet8 Subnet 192.168.169.0
2.2. EXECUTING THE EXPLOIT FOR CVE-2017-8464

Figure 8: Creating payloads and listening for TCP connections to the attacker machine

Figure 9: Creating a .lnk file that automatically runs malicious code

Figure 10: Payload setup information

Figure 11: Creating the .lnk file along with malicious code

Figure 12: Copying all malicious code to USB

Figure 13: Victim plugs in USB containing malicious .lnk file

Figure 14: Attacker successfully exploited and gained access to the victim machine
**
PART 3: BUILDING A CVE-2017-8464 DETECTION TOOL USING PYTHON
3.1. ANALYZING THE SIGNATURE OF CVE-2017-8464 BASED ON CAPTURED NETWORK PACKETS

Figure 15: Attack packet on CVE-2017-8464 captured

Figure 16: Packet with PSH flag after successful TCP connection to attacker

Figure 17: Suspicious sign in captured packet sent by attacker to victim.
PE File Format (Portable Executable File Format): is the native Win32 file format. All executable files on Win32 such as *.EXE, *.DLL (32-bit), *.COM, *.NET, *.CPL,… are in PE format; except for VxDs and *.DLL (16-bit) files.

Figure 18: Structure of a PE file.
DOS MZ Header
All PE files start with a simple DOS MZ Header. It occupies the first 64 bytes. This area is used when the program runs under DOS.
e_magic: Signature of the PE file, value: 4Dh, 5Ah (Characters "MZ", named after MS-DOS founder Mark Zbikowsky). This value marks a valid DOS Header and allows execution to continue.

Figure 19: PE file signature in captured packet
e_lfanew: is a DWORD at the end of the DOS Header, a field containing the offset of the PE Header from the beginning of the file.
DOS STUB
DOS Stub is just a small DOS EXE program that displays an error message, included for compatibility with 16-bit Windows.

Figure 20: Information in the DOS STUB packet captured from attacker sent to victim
PE Header
PE Header is essentially the IMAGE_NT_HEADERS structure, containing necessary information for the loader to load the file into memory.
Signature: is a DWORD at the start of the PE Header containing the PE signature: 50h, 45h, 00h, 00

Figure 21: Information from e_lfanew indicating the Signature portion of the PE header.
SECTION TABLE
Section Table is the component right after the PE Header, consisting of an array of IMAGE_SECTION_HEADER structures.

Figure 22: Content of the Section table in captured packet

Figure 23: Storing signatures and related malware information in a CSV file
3.2. FUNCTION TO DETECT CVE-2017-8464 EXPLOITS BASED ON PACKET SIGNATURE ANALYSIS

Figure 24: Function to retrieve protocol information of a packet

Figure 25: Function to retrieve the info field of a packet

Figure 26: Function to convert packets from Pcap to CSV file

Figure 27: Function to check for malware on network traffic

Figure 28: Loop for capturing traffic and checking for malware
*Testing the program's operation by executing the exploit.

Figure 29: Launching the monitoring program on a real machine

Figure 30: Detection and alert when monitoring network traffic

Figure 31: Folder of the CVE-2017-8464 monitoring program

Figure 32: Packet folder with files recording packets after each conversion when capturing

Figure 33: All alerts saved to log
CONCLUSION
Through the process of exploiting and building a detection program for CVE-2017-8464, students understand how to exploit a vulnerability, thereby analyzing the signature as well as the behavioral patterns of the malware exploiting the vulnerability. With that behavioral and signature analysis, students will be able to write their own programs to automatically collect, analyze, and process network security monitoring information to issue malware detection alerts.