-
Notifications
You must be signed in to change notification settings - Fork 0
/
observability_product_sniffer.rb
182 lines (156 loc) · 5.8 KB
/
observability_product_sniffer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
class ObservabilityProductSniffer
attr_reader :site, :driver
def initialize(site)
@site = site
end
def sniff
options = Selenium::WebDriver::Chrome::Options.new
# options.add_argument('--headless')
options.add_argument("--disable-notifications")
@driver = Selenium::WebDriver.for :chrome, capabilities: options
@driver.manage.timeouts.page_load = 10 # seconds
begin
puts "Scraping #{site}"
detected_on = nil
#navigate to homepage
driver.get(site)
###################################################
###################################################
####### CHECK MAIN HOMEPAGE #######################
##### FOR OBSERVABILITY TOOLS ####################
###################################################
###################################################
if !tools_used.empty?
return {
tools_used: tools_used,
detected_on: tools_used.empty? ? "n/a" : 'homepage',
error: nil
}
end
###################################################
###################################################
###### CHECK ALL HOMEPAGE FRAMES ##################
###### FOR OBSERVABILITY TOOLS ###################
###################################################
###################################################
all_frames = driver.find_elements(:css,'iframe')
all_frames.each do |frame|
# Switch to the frame
# check_frame_for_sentry(driver, frame)
driver.switch_to.frame frame
if !tools_used.empty?
return {
tools_used: tools_used,
detected_on: tools_used.empty? ? "n/a" : 'homepage (iframe)',
error: nil
}
end
driver.switch_to.default_content
end
# if no observability tool was detected on the homepage,
# navigate to login/account/sign in page, because these are more
# likely to contain app code and therefore observability monitoring.
# using elements plural here to avoid error-throwing, and then jsut selecting first result
sign_in = driver.find_elements(:xpath, "//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'sign in')]").map{|el| el.attribute('href')}
signin = driver.find_elements(:xpath, "//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'signin')]").map{|el| el.attribute('href')}
log_in = driver.find_elements(:xpath, "//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'log in')]").map{|el| el.attribute('href')}
login = driver.find_elements(:xpath, "//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'login')]").map{|el| el.attribute('href')}
account = driver.find_elements(:xpath, "//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'account')]").map{|el| el.attribute('href')}
url = nil
if !sign_in.empty?
detected_on = sign_in.first
url = sign_in.first
elsif !signin.empty?
detected_on = signin.first
url = signin.first
elsif !log_in.empty?
detected_on = log_in.first
url = log_in.first
elsif !login.empty?
detected_on = login.first
url = login.first
elsif !account.empty?
detected_on = account.first
url = account.first
else
detected_on = 'n/a'
end
if url
puts " -> " + url
driver.navigate.to url
###################################################
###################################################
######## CHECK ALL LOGIN PAGE FRAMES ##############
######## FOR OBSERVABILITY TOOLS #################
###################################################
###################################################
all_frames = driver.find_elements(:css,'iframe')
all_frames.each do |frame|
# Switch to the frame
# check_frame_for_sentry(driver, frame)
driver.switch_to.frame frame
if !tools_used.empty?
return {
tools_used: tools_used,
detected_on: tools_used.empty? ? "n/a" : detected_on,
error: nil
}
end
driver.switch_to.default_content
end
end
return {
tools_used: tools_used,
detected_on: tools_used.empty? ? "n/a" : detected_on,
error: nil
}
rescue StandardError => e
# could capture the exception and do something with it. shrug
return {
tools_used: nil,
detected_on: nil,
error: e
}
ensure
begin
driver.quit
rescue StandardError => e
# could capture the exception and do something with it. shrug
return {
tools_used: nil,
detected_on: nil,
error: e
}
end
end
end
def tools_used
tools = []
tools << 'sentry' if sentry?
tools << 'newrelic' if newrelic?
tools << 'bugsnag' if bugsnag?
tools << 'rollbar' if rollbar?
tools << 'datadog' if datadog?
tools << 'logrocket' if logrocket?
tools
end
private
def sentry?
driver.execute_script("return !!window.Sentry || !!window.__SENTRY__ || !!window.Raven;")
end
def newrelic?
driver.execute_script("return !!window.newrelic;")
end
def bugsnag?
driver.execute_script("return !!window.Bugsnag || !!window.bugsnag || !!window.bugsnagClient;")
end
def rollbar?
driver.execute_script("return !!window._rollbarDidLoad;")
end
def datadog?
driver.execute_script("return !!window.DD_RUM;")
end
def logrocket?
driver.execute_script("return !!window._lr_loaded;")
end
end