Skip to content

Commit

Permalink
Merge pull request #63 from gmkbenjamin/dev
Browse files Browse the repository at this point in the history
Add useragent option
  • Loading branch information
OscarAkaElvis authored Jul 1, 2024
2 parents 09158f6 + 45f24cf commit bd6ce52
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion evil-winrm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 15 additions & 6 deletions evil-winrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -290,15 +295,17 @@ 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(
endpoint: "https://#{$host}:#{$port}/#{$url}",
user: $user,
password: $password,
no_ssl_peer_verification: true,
transport: :ssl
transport: :ssl,
user_agent: $user_agent
)
end

Expand All @@ -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
Expand Down

0 comments on commit bd6ce52

Please sign in to comment.