scnr-introspector 0.2 → 0.3.1
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/lib/scnr/introspector/execution_flow/point.rb +3 -1
- data/lib/scnr/introspector/version +1 -1
- data/lib/scnr/introspector.rb +41 -12
- 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: a055f5743ec95419ddfdc219f5ccac33cd598915e9ae31cc01630af3f7862492
|
4
|
+
data.tar.gz: 70bf4d9e143be5226a668582f4771ca39e53de67d5492ce1caebc8988c180bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84cf6bc2e52be2da63cb471a905c633f8e4722439ca7eb4c79ce83dc350a070fe490ad4165eab940af30f7c71e5a35d27adb0824c06ed5d783e695b51b2bb342
|
7
|
+
data.tar.gz: 323c5dd53eb5b8488c15e07db278f82fb306acb298824f646da4929b99728b99a3e8310365a1f51159d4ab94ab3cad01cc18041f28cbd2a829958b4c067b3a19
|
@@ -29,6 +29,7 @@ class Point
|
|
29
29
|
attr_accessor :event
|
30
30
|
|
31
31
|
attr_accessor :source
|
32
|
+
attr_accessor :file_contents
|
32
33
|
|
33
34
|
# @param [Hash] options
|
34
35
|
def initialize( options = {} )
|
@@ -81,7 +82,8 @@ class Point
|
|
81
82
|
class_name: defined_class,
|
82
83
|
method_name: tp.method_id,
|
83
84
|
event: tp.event,
|
84
|
-
source: source_line( tp.path, tp.lineno )
|
85
|
+
source: source_line( tp.path, tp.lineno ),
|
86
|
+
file_contents: IO.read( tp.path )
|
85
87
|
})
|
86
88
|
end
|
87
89
|
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
data/lib/scnr/introspector.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
require 'securerandom'
|
3
3
|
require 'rack/utils'
|
4
|
+
require 'base64'
|
4
5
|
require 'pp'
|
5
6
|
|
6
7
|
module SCNR
|
@@ -30,6 +31,13 @@ class Introspector
|
|
30
31
|
method_source_location = object.allocate.method(m).source_location
|
31
32
|
rnd = SecureRandom.hex(10)
|
32
33
|
|
34
|
+
msg = "[INTROSPECTOR] Injecting trace code for #{object}##{m}"
|
35
|
+
if method_source_location
|
36
|
+
msg << " in #{method_source_location.join(':')}"
|
37
|
+
end
|
38
|
+
|
39
|
+
puts msg
|
40
|
+
|
33
41
|
ov = <<EORUBY
|
34
42
|
module Overloads
|
35
43
|
module #{object.to_s.split( '::' ).join}#{rnd}Overload
|
@@ -45,20 +53,20 @@ EORUBY
|
|
45
53
|
eval ov
|
46
54
|
rescue => e
|
47
55
|
# puts ov
|
48
|
-
# pp
|
56
|
+
# pp e
|
49
57
|
# pp e.backtrace
|
50
58
|
end
|
51
59
|
|
52
60
|
def taint_seed=( t )
|
53
|
-
|
61
|
+
Thread.current[:taint] = t
|
54
62
|
end
|
55
63
|
|
56
64
|
def taint_seed
|
57
|
-
|
65
|
+
Thread.current[:taint]
|
58
66
|
end
|
59
67
|
|
60
68
|
def data_flows
|
61
|
-
|
69
|
+
Thread.current[:data_flows] ||= {}
|
62
70
|
end
|
63
71
|
|
64
72
|
def synchronize( &block )
|
@@ -71,6 +79,12 @@ EORUBY
|
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
82
|
+
def flush_sinks( taint )
|
83
|
+
synchronize do
|
84
|
+
self.data_flows.delete taint
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
74
88
|
def filter_caller( a )
|
75
89
|
dir = File.dirname( __FILE__ )
|
76
90
|
a.reject do |c|
|
@@ -79,7 +93,7 @@ EORUBY
|
|
79
93
|
end
|
80
94
|
|
81
95
|
def find_and_log_taint( object, method, method_source_location, args )
|
82
|
-
taint =
|
96
|
+
taint = self.taint_seed
|
83
97
|
return if !taint
|
84
98
|
|
85
99
|
tainted = find_taint_in_arguments( taint, args )
|
@@ -161,6 +175,8 @@ EORUBY
|
|
161
175
|
@app = app
|
162
176
|
@options = options
|
163
177
|
|
178
|
+
puts "[INTROSPECTOR] Codename SCNR Introspector Initialized."
|
179
|
+
|
164
180
|
overload_application
|
165
181
|
overload_rails if rails?
|
166
182
|
|
@@ -204,10 +220,13 @@ EORUBY
|
|
204
220
|
info << :platforms
|
205
221
|
|
206
222
|
if env.delete( 'HTTP_X_SCNR_INTROSPECTOR_TRACE' )
|
207
|
-
info << :data_flow
|
208
223
|
info << :execution_flow
|
209
224
|
end
|
210
225
|
|
226
|
+
if env['HTTP_X_SCNR_INTROSPECTOR_TAINT']
|
227
|
+
info << :data_flow
|
228
|
+
end
|
229
|
+
|
211
230
|
inject( env, info )
|
212
231
|
|
213
232
|
rescue => e
|
@@ -217,7 +236,12 @@ EORUBY
|
|
217
236
|
|
218
237
|
def inject( env, info = [] )
|
219
238
|
self.class.taint_seed = env.delete( 'HTTP_X_SCNR_INTROSPECTOR_TAINT' )
|
220
|
-
|
239
|
+
if self.class.taint_seed
|
240
|
+
self.class.taint_seed = Base64.decode64( self.class.taint_seed )
|
241
|
+
self.class.taint_seed = nil if self.class.taint_seed.empty?
|
242
|
+
end
|
243
|
+
|
244
|
+
seed = env.delete( 'HTTP_X_SCNR_ENGINE_SCAN_SEED' )
|
221
245
|
|
222
246
|
data = {}
|
223
247
|
|
@@ -245,20 +269,25 @@ EORUBY
|
|
245
269
|
end
|
246
270
|
|
247
271
|
if info.include?( :data_flow ) && self.class.taint_seed
|
248
|
-
data['data_flow'] = self.class.
|
272
|
+
data['data_flow'] = self.class.flush_sinks( self.class.taint_seed )&.to_rpc_data
|
249
273
|
end
|
250
274
|
|
251
275
|
code = response.shift
|
252
276
|
headers = response.shift
|
253
277
|
body = response.shift
|
254
|
-
body = body.respond_to?( :body ) ? body.body : body
|
255
278
|
|
256
|
-
|
257
|
-
|
279
|
+
if headers['Content-Type'] && headers['Content-Type'].include?( 'html' )
|
280
|
+
body = body.respond_to?( :body ) ? body.body : body
|
281
|
+
body = [body].flatten
|
282
|
+
body << "<!-- #{seed}\n#{JSON.dump( data )}\n#{seed} -->"
|
258
283
|
|
259
|
-
|
284
|
+
headers['Content-Length'] = body.map(&:bytesize).inject(:+)
|
285
|
+
end
|
260
286
|
|
261
287
|
[code, headers, [body].flatten ]
|
288
|
+
rescue => e
|
289
|
+
pp e
|
290
|
+
pp e.backtrace
|
262
291
|
end
|
263
292
|
|
264
293
|
def platforms
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scnr-introspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tasos Laskos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|