liferay_scan 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d177ff3f289de17f0919c5b88c586762003f7a2a14524515e97162c3ccfc8b8e
4
+ data.tar.gz: 611b560648424420d6a436b0a4d6f8cadea0b94523899316145bb48d933a60ea
5
+ SHA512:
6
+ metadata.gz: 234b696bcd498735bb1ff5946ab55818ff9f6244e6c7967748800f34df67be30385078d7f3921e727f1a1192de6a8a6c84ebb92e8cb5b3bf43efad2337ef8cf5
7
+ data.tar.gz: c02e36fe456b37e5fed936c5685ee88663e38c54377cbcc0b62d818ae29e88ff5fa507c8a757bc5925626825630e136a8933446713060fe653a7998977b2b968
data/bin/liferay-scan ADDED
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file is part of LiferayScan
4
+ # https://github.com/bcoles/liferay_scan
5
+ #
6
+
7
+ require 'liferay_scan'
8
+ require 'optparse'
9
+ require 'terminal-table'
10
+ require 'resolv'
11
+
12
+ def banner
13
+ puts "
14
+ _ _ __ _____
15
+ | | (_)/ _| / ___|
16
+ | | _| |_ ___ _ __ __ _ _ _\\ `--. ___ __ _ _ __
17
+ | | | | _/ _ \\ '__/ _` | | | |`--. \\/ __/ _` | '_ \\
18
+ | |___| | || __/ | | (_| | |_| /\\__/ / (_| (_| | | | |
19
+ \\_____/_|_| \\___|_| \\__,_|\\__, \\____/ \\___\\__,_|_| |_|
20
+ __/ |
21
+ |___/ version #{LiferayScan::VERSION}"
22
+ puts
23
+ puts '-' * 60
24
+ end
25
+
26
+ banner
27
+ options = {}
28
+ opts = OptionParser.new do |opts|
29
+ opts.banner = 'Usage: liferay-scan [options]'
30
+
31
+ opts.on('-u URL', '--url URL', 'Liferay URL to scan') do |v|
32
+ unless v.match(%r{\Ahttps?://})
33
+ puts opts
34
+ exit
35
+ end
36
+ options[:url] = v
37
+ end
38
+
39
+ opts.on('-s', '--skip', 'Skip check for Liferay') do
40
+ options[:skip] = true
41
+ end
42
+
43
+ opts.on('-i', '--insecure', 'Skip SSL/TLS validation') do
44
+ options[:insecure] = true
45
+ end
46
+
47
+ opts.on('--enum-users', 'Enumerate users') do
48
+ options[:enum_users] = true
49
+ end
50
+
51
+ opts.on('-v', '--verbose', 'Enable verbose output') do
52
+ options[:verbose] = true
53
+ end
54
+
55
+ opts.on('-h', '--help', 'Show this help') do
56
+ puts opts
57
+ exit
58
+ end
59
+ end
60
+
61
+ opts.parse!
62
+
63
+ if options[:url].nil?
64
+ puts opts
65
+ exit
66
+ end
67
+
68
+ def scan(url, check: true, insecure: false, enum_users: false, verbose: false)
69
+ LiferayScan.logger = ::Logger.new($stdout).tap do |log|
70
+ log.progname = 'liferay-scan'
71
+ log.level = verbose ? ::Logger::INFO : ::Logger::WARN
72
+ log.datetime_format = '%Y-%m-%d %H:%M:%S '
73
+ end
74
+
75
+ LiferayScan.insecure = insecure
76
+
77
+ puts "Scan started at #{Time.now.getutc}"
78
+ puts "URL: #{url}"
79
+
80
+ # parse URL
81
+ target = nil
82
+ begin
83
+ target = URI.parse(url.split('?').first)
84
+ rescue StandardError
85
+ puts "- Could not parse target URL: #{url}"
86
+ end
87
+ exit(1) if target.nil?
88
+
89
+ # resolve IP address
90
+ begin
91
+ ip = Resolv.getaddress(target.host).to_s
92
+ puts "IP: #{ip}" unless ip.nil?
93
+ rescue StandardError
94
+ puts "- Could not resolve hostname #{target.host}"
95
+ end
96
+
97
+ puts "Port: #{target.port}"
98
+ puts '-' * 60
99
+
100
+ # Check if the URL is Liferay
101
+ if check
102
+ unless LiferayScan.detectLiferay(url)
103
+ puts '- Liferay Portal not found'
104
+ exit(1)
105
+ end
106
+ puts '+ Found Liferay Portal'
107
+ end
108
+
109
+ # Retrieve Liferay version
110
+ version = LiferayScan.getVersion(url)
111
+ puts "+ Version: #{version}" if version
112
+
113
+ # Retrieve server version
114
+ server_version = LiferayScan.getServerVersion(url)
115
+ puts "+ Server version: #{server_version}" if server_version
116
+
117
+ # Retrieve client IP address
118
+ client_ip = LiferayScan.getClientIpAddress(url)
119
+ puts "+ Client IP address: #{client_ip}" if client_ip
120
+
121
+ # Retrieve language
122
+ language = LiferayScan.getLanguage(url)
123
+ puts "+ Language: #{language}" if language
124
+
125
+ # Retrieve organisation email address domain
126
+ domain = LiferayScan.getOrganisationEmail(url)
127
+ puts "+ Organisation Email: #{domain}" if domain
128
+
129
+ # Check if SSO is enabled
130
+ sso = LiferayScan.ssoAuthEnabled(url)
131
+ puts '+ SSO authentication is enabled' if sso
132
+
133
+ # Retrieve users from Open Search
134
+ users = LiferayScan.getUsersFromSearch(url)
135
+ unless users.empty?
136
+ puts "+ Found users (#{users.length}):"
137
+ table = Terminal::Table.new(headings: ['Screen Name', 'Full Name'], rows: users)
138
+ puts table
139
+ end
140
+
141
+ # Check if user registration enabled
142
+ puts '+ User registration is enabled' if LiferayScan.userRegistration(url)
143
+
144
+ # Check if SOAP API accessible
145
+ puts '+ Remote SOAP API is available' if LiferayScan.remoteSoapApi(url)
146
+
147
+ # Check if JSON API accessible
148
+ puts '+ Remote JSON API is available' if LiferayScan.remoteJsonApi(url)
149
+
150
+ # Check if Forgot Password is enabled
151
+ if LiferayScan.passwordResetEnabled(url)
152
+ puts '+ Password reset is enabled'
153
+ # Check if Forgot Password uses CAPTCHA
154
+ puts '+ Password reset does not use CAPTCHA' unless LiferayScan.passwordResetUsesCaptcha(url)
155
+ end
156
+
157
+ # Enumerate users
158
+ if enum_users
159
+ users = LiferayScan.enumerateUsersFromBlogRss(url)
160
+ unless users.empty?
161
+ puts "+ Found users (#{users.length}):"
162
+ table = Terminal::Table.new(headings: ['Screen Name', 'Full Name'], rows: users)
163
+ puts table
164
+ end
165
+ end
166
+
167
+ puts "Scan finished at #{Time.now.getutc}"
168
+ puts '-' * 60
169
+ end
170
+
171
+ scan(
172
+ options[:url],
173
+ insecure: options[:insecure],
174
+ check: !options[:skip],
175
+ enum_users: options[:enum_users],
176
+ verbose: options[:verbose]
177
+ )