From 45f24cf6792edb081cbfd271716f25043785d85d Mon Sep 17 00:00:00 2001 From: gmkbenjamin Date: Mon, 1 Jul 2024 21:18:41 +1000 Subject: [PATCH] Add useragent option --- CHANGELOG.md | 1 + README.md | 3 ++- evil-winrm.gemspec | 2 +- evil-winrm.rb | 21 +++++++++++++++------ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7755b..8b5b164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Improvements of paths parsing - Fixed bug downloading files without extension - Replaced deprecated File.exists by File.exist function to avoid errors on newer Ruby versions + - Added useragent option ### 3.5 - Improvements on powershell functions loading diff --git a/README.md b/README.md index ff94453..4ed74fb 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Usage: evil-winrm -i IP -u USER [-s SCRIPTS_PATH] [-e EXES_PATH] [-P PORT] [-p P -p, --password PASS Password -H, --hash HASH NTHash -P, --port PORT Remote host port (default 5985) + -a, --user-agent Specify connection useragent (default Microsoft WinRM Client) -V, --version Show version -n, --no-colors Disable colors -N, --no-rpath-completion Disable remote path completion @@ -64,7 +65,7 @@ Usage: evil-winrm -i IP -u USER [-s SCRIPTS_PATH] [-e EXES_PATH] [-P PORT] [-p P ``` ## Requirements -Ruby 2.3 or higher is needed. Some ruby gems are needed as well: `winrm >=2.3.2`, `winrm-fs >=1.3.2`, `stringio >=0.0.2`, `logger >= 1.4.3`, `fileutils >= 0.7.2`. +Ruby 2.3 or higher is needed. Some ruby gems are needed as well: `winrm >=2.3.7`, `winrm-fs >=1.3.2`, `stringio >=0.0.2`, `logger >= 1.4.3`, `fileutils >= 0.7.2`. Depending of your installation method (4 availables) the installation of them could be required to be done manually. Another important requirement only used for Kerberos auth is to install the Kerberos package used for network authentication. diff --git a/evil-winrm.gemspec b/evil-winrm.gemspec index 80a2184..699c386 100644 --- a/evil-winrm.gemspec +++ b/evil-winrm.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'fileutils', '~> 1.0' spec.add_dependency 'logger', '~> 1.4', '>= 1.4.3' spec.add_dependency 'stringio', '~> 3.0' - spec.add_dependency 'winrm', '~> 2.3', '>= 2.3.2' + spec.add_dependency 'winrm', '~> 2.3', '>= 2.3.7' spec.add_dependency 'winrm-fs', '~> 1.3', '>= 1.3.2' spec.add_development_dependency 'bundler', '~> 2.0' diff --git a/evil-winrm.rb b/evil-winrm.rb index 8fe718e..3eedca0 100755 --- a/evil-winrm.rb +++ b/evil-winrm.rb @@ -57,6 +57,7 @@ $url = 'wsman' $default_service = 'HTTP' $full_logging_path = "#{Dir.home}/evil-winrm-logs" +$user_agent = "Microsoft WinRM Client" # Redefine download method from winrm-fs module WinRM @@ -156,13 +157,16 @@ def completion_check # Arguments def arguments - options = { port: $port, url: $url, service: $service } + options = { port: $port, url: $url, service: $service, user_agent: $user_agent } optparse = OptionParser.new do |opts| - opts.banner = 'Usage: evil-winrm -i IP -u USER [-s SCRIPTS_PATH] [-e EXES_PATH] [-P PORT] [-p PASS] [-H HASH] [-U URL] [-S] [-c PUBLIC_KEY_PATH ] [-k PRIVATE_KEY_PATH ] [-r REALM] [--spn SPN_PREFIX] [-l]' + opts.banner = 'Usage: evil-winrm -i IP -u USER [-s SCRIPTS_PATH] [-e EXES_PATH] [-P PORT] [-a USERAGENT] [-p PASS] [-H HASH] [-U URL] [-S] [-c PUBLIC_KEY_PATH ] [-k PRIVATE_KEY_PATH ] [-r REALM] [--spn SPN_PREFIX] [-l]' opts.on('-S', '--ssl', 'Enable ssl') do |_val| $ssl = true options[:port] = '5986' end + opts.on('-a', '--user-agent USERAGENT', 'Specify connection useragent (default Microsoft WinRM Client)') do |val| + options[:user_agent] = val + end opts.on('-c', '--pub-key PUBLIC_KEY_PATH', 'Local path to public key certificate') do |val| options[:pub_key] = val end @@ -254,6 +258,7 @@ def arguments $priv_key = options[:priv_key] $realm = options[:realm] $service = options[:service] + $user_agent = options[:user_agent] unless $log.nil? FileUtils.mkdir_p $full_logging_path @@ -290,7 +295,8 @@ def connection_initialization no_ssl_peer_verification: true, transport: :ssl, client_cert: $pub_key, - client_key: $priv_key + client_key: $priv_key, + user_agent: $user_agent ) else WinRM::Connection.new( @@ -298,7 +304,8 @@ def connection_initialization user: $user, password: $password, no_ssl_peer_verification: true, - transport: :ssl + transport: :ssl, + user_agent: $user_agent ) end @@ -309,14 +316,16 @@ def connection_initialization password: '', transport: :kerberos, realm: $realm, - service: $service + service: $service, + user_agent: $user_agent ) else $conn = WinRM::Connection.new( endpoint: "http://#{$host}:#{$port}/#{$url}", user: $user, password: $password, - no_ssl_peer_verification: true + no_ssl_peer_verification: true, + user_agent: $user_agent ) end end