ruby_smb 3.3.19 → 3.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/anonymous_auth.rb +5 -0
- data/examples/append_file.rb +57 -14
- data/examples/authenticate.rb +64 -16
- data/examples/delete_file.rb +53 -11
- data/examples/dump_secrets_from_sid.rb +43 -8
- data/examples/enum_domain_users.rb +51 -8
- data/examples/enum_registry_key.rb +51 -7
- data/examples/enum_registry_values.rb +51 -9
- data/examples/get_computer_info.rb +48 -8
- data/examples/list_directory.rb +54 -12
- data/examples/negotiate.rb +54 -42
- data/examples/negotiate_with_netbios_service.rb +55 -16
- data/examples/net_share_enum_all.rb +47 -8
- data/examples/pipes.rb +51 -7
- data/examples/query_service_status.rb +51 -8
- data/examples/read_file_encryption.rb +71 -26
- data/examples/read_registry_key_value.rb +54 -9
- data/examples/rename_file.rb +58 -15
- data/examples/write_file.rb +58 -15
- data/lib/ruby_smb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 370a9f235e5a6ca157a24cd68b3cea3d080b83267d3636a35e436c9637d12992
|
|
4
|
+
data.tar.gz: b821e6d664809c263125e6a62faf9f594008a0451fd07c105567e04a4af81c2e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee8ab909240175369bde0377f4917d24e3507b7d6a6cade9de0ed2e2e6cbdb3af03207965a922f4e4e2da15377d3cdf17c63fccf0f1b7d6b640f7983e6f345f3
|
|
7
|
+
data.tar.gz: 2477f7b6bfd0567f41b1eae568a0d2d7ae463495a3614784d5663711d9e0a94ed36b127e2ed0fb19deb606115deb7dba7f51c47be7111fb409d7fde18c9e58e5
|
data/examples/anonymous_auth.rb
CHANGED
data/examples/append_file.rb
CHANGED
|
@@ -2,27 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
# This example script is used for testing the appending to a file.
|
|
4
4
|
# It will attempt to connect to a specific share and then append to a specified file.
|
|
5
|
-
# Example usage: ruby append_file.rb 192.168.172.138
|
|
5
|
+
# Example usage: ruby append_file.rb --username msfadmin --password msfadmin 192.168.172.138 TEST_SHARE test.txt "data to write"
|
|
6
6
|
# This will try to connect to \\192.168.172.138\TEST_SHARE with the msfadmin:msfadmin credentials
|
|
7
|
-
# and
|
|
7
|
+
# and append "data to write" to the end of the file test.txt
|
|
8
8
|
|
|
9
9
|
require 'bundler/setup'
|
|
10
|
+
require 'optparse'
|
|
10
11
|
require 'ruby_smb'
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
args = ARGV.dup
|
|
14
|
+
options = {
|
|
15
|
+
domain: '.',
|
|
16
|
+
username: '',
|
|
17
|
+
password: '',
|
|
18
|
+
smbv1: true,
|
|
19
|
+
smbv2: true,
|
|
20
|
+
smbv3: true,
|
|
21
|
+
target: nil,
|
|
22
|
+
share: nil,
|
|
23
|
+
file: nil,
|
|
24
|
+
data: nil
|
|
25
|
+
}
|
|
26
|
+
options[:data] = args.pop
|
|
27
|
+
options[:file] = args.pop
|
|
28
|
+
options[:share] = args.pop
|
|
29
|
+
options[:target] = args.pop
|
|
30
|
+
optparser = OptionParser.new do |opts|
|
|
31
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] target share file data"
|
|
32
|
+
opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
|
|
33
|
+
options[:smbv1] = smbv1
|
|
34
|
+
end
|
|
35
|
+
opts.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{options[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2|
|
|
36
|
+
options[:smbv2] = smbv2
|
|
37
|
+
end
|
|
38
|
+
opts.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{options[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3|
|
|
39
|
+
options[:smbv3] = smbv3
|
|
40
|
+
end
|
|
41
|
+
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
42
|
+
if username.include?('\\')
|
|
43
|
+
options[:domain], options[:username] = username.split('\\', 2)
|
|
44
|
+
else
|
|
45
|
+
options[:username] = username
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
49
|
+
options[:password] = password
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
optparser.parse!(args)
|
|
53
|
+
|
|
54
|
+
if [options[:target], options[:share], options[:file], options[:data]].any? { |a| a == '-h' || a == '--help' }
|
|
55
|
+
puts optparser.help
|
|
56
|
+
exit
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if options[:target].nil? || options[:share].nil? || options[:file].nil? || options[:data].nil?
|
|
60
|
+
abort(optparser.help)
|
|
61
|
+
end
|
|
19
62
|
|
|
20
|
-
path = "\\\\#{
|
|
63
|
+
path = "\\\\#{options[:target]}\\#{options[:share]}"
|
|
21
64
|
|
|
22
|
-
sock = TCPSocket.new
|
|
65
|
+
sock = TCPSocket.new options[:target], 445
|
|
23
66
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
|
24
67
|
|
|
25
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
|
68
|
+
client = RubySMB::Client.new(dispatcher, smb1: options[:smbv1], smb2: options[:smbv2], smb3: options[:smbv3], username: options[:username], password: options[:password], domain: options[:domain])
|
|
26
69
|
protocol = client.negotiate
|
|
27
70
|
status = client.authenticate
|
|
28
71
|
|
|
@@ -35,8 +78,8 @@ rescue StandardError => e
|
|
|
35
78
|
puts "Failed to connect to #{path}: #{e.message}"
|
|
36
79
|
end
|
|
37
80
|
|
|
38
|
-
file = tree.open_file(filename: file, write: true, disposition: RubySMB::Dispositions::FILE_OPEN_IF)
|
|
81
|
+
file = tree.open_file(filename: options[:file], write: true, disposition: RubySMB::Dispositions::FILE_OPEN_IF)
|
|
39
82
|
|
|
40
|
-
result = file.append(data: data)
|
|
83
|
+
result = file.append(data: options[:data])
|
|
41
84
|
puts result.to_s
|
|
42
85
|
file.close
|
data/examples/authenticate.rb
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
# including protocol negotiation and authentication.
|
|
5
5
|
|
|
6
6
|
require 'bundler/setup'
|
|
7
|
+
require 'optparse'
|
|
7
8
|
require 'ruby_smb'
|
|
8
9
|
|
|
9
|
-
def run_authentication(address, smb1, smb2, smb3, username, password)
|
|
10
|
+
def run_authentication(address, smb1, smb2, smb3, username, password, domain)
|
|
10
11
|
# Create our socket and add it to the dispatcher
|
|
11
12
|
sock = TCPSocket.new address, 445
|
|
12
13
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
|
13
14
|
|
|
14
|
-
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, smb3: smb3, username: username, password: password)
|
|
15
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, smb3: smb3, username: username, password: password, domain: domain)
|
|
15
16
|
protocol = client.negotiate
|
|
16
17
|
status = client.authenticate
|
|
17
18
|
puts "#{protocol} : #{status}"
|
|
@@ -28,17 +29,64 @@ def run_authentication(address, smb1, smb2, smb3, username, password)
|
|
|
28
29
|
puts "OS Version: #{client.os_version}"
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
args = ARGV.dup
|
|
33
|
+
options = {
|
|
34
|
+
domain: '.',
|
|
35
|
+
username: '',
|
|
36
|
+
password: '',
|
|
37
|
+
smbv1: true,
|
|
38
|
+
smbv2: true,
|
|
39
|
+
smbv3: true,
|
|
40
|
+
target: nil
|
|
41
|
+
}
|
|
42
|
+
options[:target] = args.pop
|
|
43
|
+
optparser = OptionParser.new do |opts|
|
|
44
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] target"
|
|
45
|
+
opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
|
|
46
|
+
options[:smbv1] = smbv1
|
|
47
|
+
end
|
|
48
|
+
opts.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{options[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2|
|
|
49
|
+
options[:smbv2] = smbv2
|
|
50
|
+
end
|
|
51
|
+
opts.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{options[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3|
|
|
52
|
+
options[:smbv3] = smbv3
|
|
53
|
+
end
|
|
54
|
+
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
55
|
+
if username.include?('\\')
|
|
56
|
+
options[:domain], options[:username] = username.split('\\', 2)
|
|
57
|
+
else
|
|
58
|
+
options[:username] = username
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
62
|
+
options[:password] = password
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
optparser.parse!(args)
|
|
66
|
+
|
|
67
|
+
if options[:target] == '-h' || options[:target] == '--help'
|
|
68
|
+
puts optparser.help
|
|
69
|
+
exit
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
if options[:target].nil?
|
|
73
|
+
abort(optparser.help)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# (smb1, smb2, smb3) combinations to exercise — filtered by the user's
|
|
77
|
+
# --[no-]smbv{1,2,3} flags so that any combo requiring a disabled version
|
|
78
|
+
# is skipped.
|
|
79
|
+
combinations = [
|
|
80
|
+
[true, true, true], # SMB1, SMB2 and SMB3 enabled
|
|
81
|
+
[true, true, false], # SMB1 and SMB2 enabled
|
|
82
|
+
[true, false, false], # only SMB1 enabled
|
|
83
|
+
[false, true, false], # only SMB2 enabled
|
|
84
|
+
[false, false, true] # only SMB3 enabled
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
combinations.each do |smb1, smb2, smb3|
|
|
88
|
+
next if smb1 && !options[:smbv1]
|
|
89
|
+
next if smb2 && !options[:smbv2]
|
|
90
|
+
next if smb3 && !options[:smbv3]
|
|
91
|
+
run_authentication(options[:target], smb1, smb2, smb3, options[:username], options[:password], options[:domain])
|
|
92
|
+
end
|
data/examples/delete_file.rb
CHANGED
|
@@ -2,26 +2,68 @@
|
|
|
2
2
|
|
|
3
3
|
# This example script is used for testing the deleting of a file.
|
|
4
4
|
# It will attempt to connect to a specific share and then delete a specified file.
|
|
5
|
-
# Example usage: ruby delete_file.rb 192.168.172.138
|
|
5
|
+
# Example usage: ruby delete_file.rb --username msfadmin --password msfadmin 192.168.172.138 TEST_SHARE short.txt
|
|
6
6
|
# This will try to connect to \\192.168.172.138\TEST_SHARE with the msfadmin:msfadmin credentials
|
|
7
7
|
# and delete the file short.txt
|
|
8
8
|
|
|
9
9
|
require 'bundler/setup'
|
|
10
|
+
require 'optparse'
|
|
10
11
|
require 'ruby_smb'
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
args = ARGV.dup
|
|
14
|
+
options = {
|
|
15
|
+
domain: '.',
|
|
16
|
+
username: '',
|
|
17
|
+
password: '',
|
|
18
|
+
smbv1: true,
|
|
19
|
+
smbv2: true,
|
|
20
|
+
smbv3: true,
|
|
21
|
+
target: nil,
|
|
22
|
+
share: nil,
|
|
23
|
+
file: nil
|
|
24
|
+
}
|
|
25
|
+
options[:file] = args.pop
|
|
26
|
+
options[:share] = args.pop
|
|
27
|
+
options[:target] = args.pop
|
|
28
|
+
optparser = OptionParser.new do |opts|
|
|
29
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] target share file"
|
|
30
|
+
opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
|
|
31
|
+
options[:smbv1] = smbv1
|
|
32
|
+
end
|
|
33
|
+
opts.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{options[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2|
|
|
34
|
+
options[:smbv2] = smbv2
|
|
35
|
+
end
|
|
36
|
+
opts.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{options[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3|
|
|
37
|
+
options[:smbv3] = smbv3
|
|
38
|
+
end
|
|
39
|
+
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
40
|
+
if username.include?('\\')
|
|
41
|
+
options[:domain], options[:username] = username.split('\\', 2)
|
|
42
|
+
else
|
|
43
|
+
options[:username] = username
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
47
|
+
options[:password] = password
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
optparser.parse!(args)
|
|
51
|
+
|
|
52
|
+
if [options[:target], options[:share], options[:file]].any? { |a| a == '-h' || a == '--help' }
|
|
53
|
+
puts optparser.help
|
|
54
|
+
exit
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
if options[:target].nil? || options[:share].nil? || options[:file].nil?
|
|
58
|
+
abort(optparser.help)
|
|
59
|
+
end
|
|
18
60
|
|
|
19
|
-
path
|
|
61
|
+
path = "\\\\#{options[:target]}\\#{options[:share]}"
|
|
20
62
|
|
|
21
|
-
sock = TCPSocket.new
|
|
63
|
+
sock = TCPSocket.new options[:target], 445
|
|
22
64
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
|
23
65
|
|
|
24
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
|
66
|
+
client = RubySMB::Client.new(dispatcher, smb1: options[:smbv1], smb2: options[:smbv2], smb3: options[:smbv3], username: options[:username], password: options[:password], domain: options[:domain])
|
|
25
67
|
|
|
26
68
|
protocol = client.negotiate
|
|
27
69
|
status = client.authenticate
|
|
@@ -35,7 +77,7 @@ rescue StandardError => e
|
|
|
35
77
|
puts "Failed to connect to #{path}: #{e.message}"
|
|
36
78
|
end
|
|
37
79
|
|
|
38
|
-
file = tree.open_file(filename: file, delete: true)
|
|
80
|
+
file = tree.open_file(filename: options[:file], delete: true)
|
|
39
81
|
|
|
40
82
|
data = file.delete
|
|
41
83
|
puts data
|
|
@@ -2,26 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
# This example script is used for testing DCERPC client and DRSR structures.
|
|
4
4
|
# It will attempt to connect to a host and enumerate user secrets.
|
|
5
|
-
# Example usage: ruby dump_secrets_from_sid.rb 192.168.172.138
|
|
5
|
+
# Example usage: ruby dump_secrets_from_sid.rb --username msfadmin --password msfadmin 192.168.172.138 MYDOMAIN S-1-5-21-419547006-9448028-4223375872-500
|
|
6
6
|
# This will try to connect to \\192.168.172.138 with the msfadmin:msfadmin
|
|
7
7
|
# credentials and enumerate secrets of domain user with SID
|
|
8
8
|
# S-1-5-21-419547006-9448028-4223375872-500
|
|
9
9
|
|
|
10
10
|
require 'bundler/setup'
|
|
11
|
+
require 'optparse'
|
|
12
|
+
require 'ruby_smb'
|
|
11
13
|
require 'ruby_smb/dcerpc/client'
|
|
12
14
|
|
|
15
|
+
args = ARGV.dup
|
|
16
|
+
options = {
|
|
17
|
+
domain: '.',
|
|
18
|
+
username: '',
|
|
19
|
+
password: '',
|
|
20
|
+
target: nil,
|
|
21
|
+
lookup_domain: nil,
|
|
22
|
+
sid: nil
|
|
23
|
+
}
|
|
24
|
+
options[:sid] = args.pop
|
|
25
|
+
options[:lookup_domain] = args.pop
|
|
26
|
+
options[:target] = args.pop
|
|
27
|
+
optparser = OptionParser.new do |opts|
|
|
28
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] target domain sid"
|
|
29
|
+
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
30
|
+
if username.include?('\\')
|
|
31
|
+
options[:domain], options[:username] = username.split('\\', 2)
|
|
32
|
+
else
|
|
33
|
+
options[:username] = username
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
37
|
+
options[:password] = password
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
optparser.parse!(args)
|
|
41
|
+
|
|
42
|
+
if [options[:target], options[:lookup_domain], options[:sid]].any? { |a| a == '-h' || a == '--help' }
|
|
43
|
+
puts optparser.help
|
|
44
|
+
exit
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if options[:target].nil? || options[:lookup_domain].nil? || options[:sid].nil?
|
|
48
|
+
abort(optparser.help)
|
|
49
|
+
end
|
|
13
50
|
|
|
14
|
-
address
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
domain = ARGV[3]
|
|
18
|
-
sid = ARGV[4]
|
|
51
|
+
address = options[:target]
|
|
52
|
+
domain = options[:lookup_domain]
|
|
53
|
+
sid = options[:sid]
|
|
19
54
|
|
|
20
55
|
client = RubySMB::Dcerpc::Client.new(
|
|
21
56
|
address,
|
|
22
57
|
RubySMB::Dcerpc::Drsr,
|
|
23
|
-
username: username,
|
|
24
|
-
password: password,
|
|
58
|
+
username: options[:username],
|
|
59
|
+
password: options[:password],
|
|
25
60
|
)
|
|
26
61
|
client.connect
|
|
27
62
|
puts('Binding to DRSR...')
|
|
@@ -2,21 +2,65 @@
|
|
|
2
2
|
|
|
3
3
|
# This example script is used for testing DCERPC SAMR requests.
|
|
4
4
|
# It will attempt to connect to a server object and enumerate domain users.
|
|
5
|
-
# Example usage: ruby enum_domain_users.rb 192.168.172.138
|
|
5
|
+
# Example usage: ruby enum_domain_users.rb --username msfadmin --password msfadmin 192.168.172.138 MyDomain
|
|
6
6
|
|
|
7
7
|
require 'bundler/setup'
|
|
8
|
+
require 'optparse'
|
|
8
9
|
require 'ruby_smb'
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
args = ARGV.dup
|
|
12
|
+
options = {
|
|
13
|
+
domain: '.',
|
|
14
|
+
username: '',
|
|
15
|
+
password: '',
|
|
16
|
+
smbv1: true,
|
|
17
|
+
smbv2: true,
|
|
18
|
+
smbv3: true,
|
|
19
|
+
target: nil,
|
|
20
|
+
lookup_domain: nil
|
|
21
|
+
}
|
|
22
|
+
options[:lookup_domain] = args.pop
|
|
23
|
+
options[:target] = args.pop
|
|
24
|
+
optparser = OptionParser.new do |opts|
|
|
25
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] target domain"
|
|
26
|
+
opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
|
|
27
|
+
options[:smbv1] = smbv1
|
|
28
|
+
end
|
|
29
|
+
opts.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{options[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2|
|
|
30
|
+
options[:smbv2] = smbv2
|
|
31
|
+
end
|
|
32
|
+
opts.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{options[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3|
|
|
33
|
+
options[:smbv3] = smbv3
|
|
34
|
+
end
|
|
35
|
+
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
36
|
+
if username.include?('\\')
|
|
37
|
+
options[:domain], options[:username] = username.split('\\', 2)
|
|
38
|
+
else
|
|
39
|
+
options[:username] = username
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
43
|
+
options[:password] = password
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
optparser.parse!(args)
|
|
47
|
+
|
|
48
|
+
if [options[:target], options[:lookup_domain]].any? { |a| a == '-h' || a == '--help' }
|
|
49
|
+
puts optparser.help
|
|
50
|
+
exit
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
if options[:target].nil? || options[:lookup_domain].nil?
|
|
54
|
+
abort(optparser.help)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
address = options[:target]
|
|
58
|
+
domain = options[:lookup_domain]
|
|
15
59
|
|
|
16
60
|
sock = TCPSocket.new address, 445
|
|
17
61
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
|
18
62
|
|
|
19
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
|
63
|
+
client = RubySMB::Client.new(dispatcher, smb1: options[:smbv1], smb2: options[:smbv2], smb3: options[:smbv3], username: options[:username], password: options[:password], domain: options[:domain])
|
|
20
64
|
protocol = client.negotiate
|
|
21
65
|
status = client.authenticate
|
|
22
66
|
|
|
@@ -72,4 +116,3 @@ samr.close_handle(builtin_domain_handle)
|
|
|
72
116
|
samr.close_handle(server_handle)
|
|
73
117
|
|
|
74
118
|
client.disconnect!
|
|
75
|
-
|
|
@@ -2,22 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
# This example script is used for testing Winreg registry key enumeration functionality
|
|
4
4
|
# It will attempt to connect to a host and enumerate registry subkeys of a specified registry key.
|
|
5
|
-
# Example usage: ruby enum_registry_key.rb 192.168.172.138
|
|
5
|
+
# Example usage: ruby enum_registry_key.rb --username msfadmin --password msfadmin 192.168.172.138 HKLM\\My\\Key
|
|
6
6
|
# This will try to connect to \\192.168.172.138 with the msfadmin:msfadmin credentialas and enumerate HKLM\\My\\Key subkeys.
|
|
7
7
|
|
|
8
8
|
require 'bundler/setup'
|
|
9
|
+
require 'optparse'
|
|
9
10
|
require 'ruby_smb'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
args = ARGV.dup
|
|
13
|
+
options = {
|
|
14
|
+
domain: '.',
|
|
15
|
+
username: '',
|
|
16
|
+
password: '',
|
|
17
|
+
smbv1: true,
|
|
18
|
+
smbv2: true,
|
|
19
|
+
smbv3: true,
|
|
20
|
+
target: nil,
|
|
21
|
+
registry_key: nil
|
|
22
|
+
}
|
|
23
|
+
options[:registry_key] = args.pop
|
|
24
|
+
options[:target] = args.pop
|
|
25
|
+
optparser = OptionParser.new do |opts|
|
|
26
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] target registry_key"
|
|
27
|
+
opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
|
|
28
|
+
options[:smbv1] = smbv1
|
|
29
|
+
end
|
|
30
|
+
opts.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{options[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2|
|
|
31
|
+
options[:smbv2] = smbv2
|
|
32
|
+
end
|
|
33
|
+
opts.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{options[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3|
|
|
34
|
+
options[:smbv3] = smbv3
|
|
35
|
+
end
|
|
36
|
+
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
37
|
+
if username.include?('\\')
|
|
38
|
+
options[:domain], options[:username] = username.split('\\', 2)
|
|
39
|
+
else
|
|
40
|
+
options[:username] = username
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
44
|
+
options[:password] = password
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
optparser.parse!(args)
|
|
48
|
+
|
|
49
|
+
if [options[:target], options[:registry_key]].any? { |a| a == '-h' || a == '--help' }
|
|
50
|
+
puts optparser.help
|
|
51
|
+
exit
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if options[:target].nil? || options[:registry_key].nil?
|
|
55
|
+
abort(optparser.help)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
address = options[:target]
|
|
59
|
+
registry_key = options[:registry_key]
|
|
16
60
|
|
|
17
61
|
sock = TCPSocket.new address, 445
|
|
18
62
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
|
19
63
|
|
|
20
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
|
64
|
+
client = RubySMB::Client.new(dispatcher, smb1: options[:smbv1], smb2: options[:smbv2], smb3: options[:smbv3], username: options[:username], password: options[:password], domain: options[:domain])
|
|
21
65
|
protocol = client.negotiate
|
|
22
66
|
status = client.authenticate
|
|
23
67
|
|
|
@@ -2,22 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
# This example script is used for testing values enumeration of a specific Winreg registry.
|
|
4
4
|
# It will attempt to connect to a host and enumerate values of a specified registry key.
|
|
5
|
-
# Example usage: ruby enum_registry_values.rb 192.168.172.138
|
|
5
|
+
# Example usage: ruby enum_registry_values.rb --username msfadmin --password msfadmin 192.168.172.138 HKLM\\My\\Key
|
|
6
6
|
# This will try to connect to \\192.168.172.138 with the msfadmin:msfadmin credentialas and enumerate HKLM\\My\\Key values.
|
|
7
7
|
|
|
8
8
|
require 'bundler/setup'
|
|
9
|
+
require 'optparse'
|
|
9
10
|
require 'ruby_smb'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
args = ARGV.dup
|
|
13
|
+
options = {
|
|
14
|
+
domain: '.',
|
|
15
|
+
username: '',
|
|
16
|
+
password: '',
|
|
17
|
+
smbv1: true,
|
|
18
|
+
smbv2: true,
|
|
19
|
+
smbv3: true,
|
|
20
|
+
target: nil,
|
|
21
|
+
registry_key: nil
|
|
22
|
+
}
|
|
23
|
+
options[:registry_key] = args.pop
|
|
24
|
+
options[:target] = args.pop
|
|
25
|
+
optparser = OptionParser.new do |opts|
|
|
26
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options] target registry_key"
|
|
27
|
+
opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
|
|
28
|
+
options[:smbv1] = smbv1
|
|
29
|
+
end
|
|
30
|
+
opts.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{options[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2|
|
|
31
|
+
options[:smbv2] = smbv2
|
|
32
|
+
end
|
|
33
|
+
opts.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{options[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3|
|
|
34
|
+
options[:smbv3] = smbv3
|
|
35
|
+
end
|
|
36
|
+
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
37
|
+
if username.include?('\\')
|
|
38
|
+
options[:domain], options[:username] = username.split('\\', 2)
|
|
39
|
+
else
|
|
40
|
+
options[:username] = username
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
44
|
+
options[:password] = password
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
optparser.parse!(args)
|
|
48
|
+
|
|
49
|
+
if [options[:target], options[:registry_key]].any? { |a| a == '-h' || a == '--help' }
|
|
50
|
+
puts optparser.help
|
|
51
|
+
exit
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if options[:target].nil? || options[:registry_key].nil?
|
|
55
|
+
abort(optparser.help)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
address = options[:target]
|
|
59
|
+
registry_key = options[:registry_key]
|
|
16
60
|
|
|
17
61
|
sock = TCPSocket.new address, 445
|
|
18
62
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
|
19
63
|
|
|
20
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
|
64
|
+
client = RubySMB::Client.new(dispatcher, smb1: options[:smbv1], smb2: options[:smbv2], smb3: options[:smbv3], username: options[:username], password: options[:password], domain: options[:domain])
|
|
21
65
|
protocol = client.negotiate
|
|
22
66
|
status = client.authenticate
|
|
23
67
|
|
|
@@ -27,5 +71,3 @@ enum_result = client.enum_registry_values(address, registry_key)
|
|
|
27
71
|
puts enum_result
|
|
28
72
|
|
|
29
73
|
client.disconnect!
|
|
30
|
-
|
|
31
|
-
|