lnk

The lnk module parses Windows Link files (.lnk), and exposes metadata contained in those files to YARA.


Module structure

FieldTypeDescription
is_lnkboolTrue if the file is a LNK file.
namestringA description of the shortcut that is displayed to end users to identify the purpose of the link.
creation_timeintegerTime when the LNK file was created.
access_timeintegerTime when the LNK file was last accessed.
write_timeintegerTime when the LNK files was last modified.
file_sizeintegerSize of the target file in bytes. The target file is the file that this link references to. If the link target file is larger than 0xFFFFFFFF, this value specifies the least significant 32 bits of the link target file size.
file_attributesintegerAttributes of the link target file.
icon_locationstringLocation where the icon associated to the link is found. This is usually an EXE or DLL file that contains the icon among its resources. The specific icon to be used is indicated by the icon_index field.
icon_indexintegerIndex of the icon that is associated to the link, within an icon location.
show_commandShowCommandExpected window state of an application launched by this link.
drive_typeDriveTypeType of drive the link is stored on.
drive_serial_numberintegerDrive serial number of the volume the link target is stored on.
volume_labelstringVolume label of the drive the link target is stored on.
local_base_pathstringString used to construct the full path to the link target by appending the common_path_suffix field.
common_path_suffixstringString used to construct the full path to the link target by being appended to the local_base_path field.
relative_pathstringLocation of the link target relative to the LNK file.
working_dirstringPath of the working directory to be used when activating the link target.
cmd_line_argsstringCommand-line arguments that are specified when activating the link target.
overlay_sizeintegerSize in bytes of any extra data appended to the LNK file.
overlay_offsetintegerOffset within the LNK file where the overlay starts.
tracker_dataTrackerDataDistributed link tracker information.
target_id_listShellItem arrayShell items parsed from the link target ID list. Describes the target of the shortcut as a chain of shell items (root folder, volume, file entry, control panel item, etc.).

ShellItem

These are the fields in each entry of the target_id_list array. Each entry corresponds to an ItemID within the LinkTargetIDList structure defined in the Microsoft [MS-SHLLINK] specification (section 2.2). The internal layout of each shell item is not specified by Microsoft; the type-specific fields below follow the reverse-engineered Windows Shell Item format documentation. Which fields are populated depends on the shell item type (item_type); the raw data field is always populated, so rules can match on shell item types that are not decoded into a dedicated field. The fields are listed in order of the item_type they belong to.

FieldTypeDescription
item_typeShellItemTypeCategory of the shell item, derived from its class type indicator byte. Always set for every shell item (if the class type indicator does not map to a known category, the raw byte value is stored as an unknown value).
datastringRaw class type specific data: all the bytes that follow the class type indicator byte. Always populated, so rules can match on shell items whose type is not decoded into a dedicated field.
cpl_file_pathstringPath to the control panel CPL file. Populated for control panel CPL file shell items (item_type CONTROL_PANEL_CPL). This field is abused by CVE-2010-2568 to point to an arbitrary DLL.
root_folder_idstringShell folder identifier (a GUID). Populated for root folder shell items (item_type ROOT_FOLDER).
volume_namestringVolume name. Populated for volume shell items (item_type VOLUME) that carry a name.
volume_idstringVolume identifier (a GUID). Populated for volume shell items (item_type VOLUME) that carry an identifier instead of a name.
file_entry_namestringFile or directory name. Populated for file entry shell items (item_type FILE_ENTRY).
network_locationstringNetwork location, usually a UNC path. Populated for network location shell items (item_type NETWORK_LOCATION).

Example

import "lnk"

rule lnk_suspicious_cpl_target {
    condition:
        for any item in lnk.target_id_list : (
            item.item_type == lnk.ShellItemType.CONTROL_PANEL_CPL and
            item.cpl_file_path endswith ".dll"
        )
}

ShellItemType

These are the possible values for the item_type field of a ShellItem. The values are the class type indicators from the Windows Shell Item format; for the volume, file entry and network location items (whose class type indicator is a range) the value is the base of the range.

NameValue
ShellItemType.CONTROL_PANEL_CPL0x00
ShellItemType.CONTROL_PANEL_CATEGORY0x01
ShellItemType.ROOT_FOLDER0x1F
ShellItemType.VOLUME0x20
ShellItemType.FILE_ENTRY0x30
ShellItemType.NETWORK_LOCATION0x40
ShellItemType.COMPRESSED_FOLDER0x52
ShellItemType.URI0x61
ShellItemType.CONTROL_PANEL0x71
ShellItemType.PRINTERS0x72
ShellItemType.COMMON_PLACES_FOLDER0x73
ShellItemType.USERS_FILES_FOLDER0x74

TrackerData

These are the fields in the tracker_data structure, which contains data that can be used to resolve a link target if it is not found in its original location when the link is resolved. This data is passed to the Link Tracking service [MS-DLTW] to find the link target.

FieldType
versioninteger
machine_idstring
droid_volume_idstring
droid_file_idstring
droid_birth_volume_idstring
droid_birth_file_idstring

Example

import "lnk"

rule lnk_cdrom {
    condition:
        lnk.tracker_data.machine_id == "chris-xps"
}

DriveType

These are the possible values for the drive_type field.

NameValue
DriveType.UNKNOWN0
DriveType.NO_ROOT_DIR1
DriveType.REMOVABLE2
DriveType.FIXED3
DriveType.REMOTE4
DriveType.CDROM5
DriveType.RAMDISK6

Example

import "lnk"

rule lnk_cdrom {
    condition:
        lnk.drive_type == lnk.DriveType.CDROM 
}

FileAttributes

NameValue
FILE_ATTRIBUTE_READONLY0x0001
FILE_ATTRIBUTE_HIDDEN0x0002
FILE_ATTRIBUTE_SYSTEM0x0004
FILE_ATTRIBUTE_DIRECTORY0x0010
FILE_ATTRIBUTE_ARCHIVE0x0020
FILE_ATTRIBUTE_NORMAL0x0080
FILE_ATTRIBUTE_TEMPORARY0x0100
FILE_ATTRIBUTE_SPARSE_FILE0x0200
FILE_ATTRIBUTE_REPARSE_POINT0x0400
FILE_ATTRIBUTE_COMPRESSED0x0800
FILE_ATTRIBUTE_OFFLINE0x1000
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED0x2000
FILE_ATTRIBUTE_ENCRYPTED0x4000

ShowCommand

These are the possible values for the show_command field.

NameValue
ShowCommand.NORMAL1
ShowCommand.MAXIMIZED3
ShowCommand.MIN_NO_ACTIVE7

Example

import "lnk"

rule lnk_maximized {
    condition:
        lnk.show_command == lnk.ShowCommand.MAXIMIZED
}