icaprb-filter 0.0.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.
@@ -0,0 +1,91 @@
1
+
2
+ require 'chunky_png'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ # ICAPrb
7
+ module ICAPrb
8
+ # Filter module
9
+ module Filter
10
+ # the steganography code of the filter - used to watermark files which are sent and downloaded.
11
+ module Steganography
12
+ # contains the code to encrypt the watermarks
13
+ module Cryptography
14
+ # Cipher to use
15
+ Cipher_To_Use = 'CAMELLIA-256-CBC'
16
+
17
+ class << self
18
+ # encrypt data using the the algorithm given in Cipher_To_Use using OpenSSL
19
+ # parameters:
20
+ # data:: data to encrypt
21
+ # key:: the key to use when encrypting data - when the default cipher is used, this must be 32 bytes
22
+ #
23
+ # returns the cipher string
24
+ def encrypt(data, key)
25
+ cipher = OpenSSL::Cipher.new(Cipher_To_Use)
26
+ cipher.encrypt
27
+ iv = cipher.random_iv
28
+ cipher.key = key
29
+ encrypted_data = cipher.update(data) + cipher.final
30
+ iv + encrypted_data
31
+ end
32
+
33
+ # decrypt data using the the algorithm given in Cipher_To_Use using OpenSSL
34
+ # parameters:
35
+ # data:: data to decrypt
36
+ # key:: the key to use when decrypting data - when the default cipher is used, this must be 32 bytes
37
+ #
38
+ # returns the decrypted string
39
+ # raises an error if the decryption is not successful
40
+ def decrypt(data, key)
41
+ cipher = OpenSSL::Cipher.new(Cipher_To_Use)
42
+ cipher.decrypt
43
+ iv = data[0..15]
44
+ encrypted_data = data[16...(data.length)]
45
+ cipher.iv = iv
46
+ cipher.key = key
47
+ cipher.update(encrypted_data) + cipher.final
48
+ end
49
+ end
50
+ end
51
+
52
+ # contains classes which are used to support hiding messages in different file formats such as images,
53
+ # documents etc.
54
+ module Formats
55
+ # hide data in the png alpha channel
56
+ module PNG
57
+ class << self
58
+ # hide a string in a png file inside the last two significant bits of the alpha channel
59
+ # parameters:
60
+ # message:: the data (string) to hide in the image
61
+ # data_stream:: the png as a string
62
+ #
63
+ # returns the new image
64
+ def hide(message, data_stream)
65
+ png = ::ChunkyPNG::Image.from_blob(data_stream)
66
+ msg = message.bytes.map {|e| e.to_s(2).rjust(8,'0').scan(/../)}.flatten.map{|str| str.to_i(2)}
67
+ prepared_pixel = png.pixels.map {|pixel| pixel & 0xfffffffc}
68
+ 0.upto(msg.length-1) { |i| prepared_pixel[i] |= msg[i] }
69
+
70
+ my_chunks = prepared_pixel.each_slice(png.width).to_a
71
+ (0.upto(png.height - 1)).each { |r| png.replace_row!(r,my_chunks[r]) }
72
+ png.to_blob(:fast_rgba)
73
+ end
74
+
75
+ # extract the data from the png
76
+ # parameters:
77
+ # data_stream:: the png file from which the data should be extracted
78
+ #
79
+ # returns the extracted string
80
+ def extract(data_stream)
81
+ png = ::ChunkyPNG::Image.from_blob(data_stream)
82
+ ac_data = png.pixels.map {|e| e & 3}.map {|e| e.to_s(2).rjust(2,'0') }.join.scan(/.{8}/).map {|e| e.to_i(2) }
83
+ real_length = ac_data.map.with_index {|a, i| a != 0 ? i : nil}.delete_if {|a| a.nil? }.last
84
+ ac_data[0..real_length].map{|c| c.chr}.join
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,8 @@
1
+ # ICAPrb
2
+ module ICAPrb
3
+ # Filter module
4
+ module Filter
5
+ #version of the Filter-Service
6
+ VERSION = "0.0.1"
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ request_filter do
2
+
3
+ end
4
+
5
+ response_filter do
6
+ block 'Block hashes of bad file', :check_hashes => ['./spec/icaprb/block_samples/check_hashes_test.txt']
7
+ end
@@ -0,0 +1,2 @@
1
+ 8603effde36c3c39e50c1ad0b4909ee48318ab760c85a7555bd821b026856bf7
2
+ 48ac3d29e2b72d1501b57538d31e6457173ba317aec4478665abbf5ffe0f72b5
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Title</title>
6
+ </head>
7
+ <body>
8
+ <a post="value"></a>
9
+ </body>
10
+ </html>
@@ -0,0 +1,6 @@
1
+ request_filter do
2
+ end
3
+
4
+ response_filter do
5
+ block 'Block postings', content_has_key: ['message', 'posting', 'post']
6
+ end
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Title</title>
6
+ </head>
7
+ <body>
8
+ <a>porn</a>
9
+ </body>
10
+ </html>
@@ -0,0 +1,6 @@
1
+ request_filter do
2
+ end
3
+
4
+ response_filter do
5
+ block 'Block pages may contain pornographic content', content_includes: ['porn', 'sex']
6
+ end
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Title</title>
6
+ </head>
7
+ <body>
8
+
9
+ </body>
10
+ </html>
@@ -0,0 +1,6 @@
1
+ request_filter do
2
+ end
3
+
4
+ response_filter do
5
+ block 'reserved top level domain', url_contains: ['invalid', 'localhost', 'test']
6
+ end
@@ -0,0 +1,6 @@
1
+ request_filter do
2
+ custom_action 'Send URL to virustotal', :send_url_to_virustotal, settings: { :api_key => "FILL IN YOUR API KEY", :log_file => "~/virustotal_url.log"}
3
+ end
4
+
5
+ response_filter do
6
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: icaprb-filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fabian Franz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: uirusu
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: pdf-reader
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.4'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.4'
61
+ - !ruby/object:Gem::Dependency
62
+ name: chunky_png
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: icaprb-server
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rest-client
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: bundler
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.11'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.11'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rake
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.0'
145
+ description:
146
+ email:
147
+ - fabian.franz@students.fh-hagenberg.at
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - ".gitignore"
153
+ - ".rspec"
154
+ - ".travis.yml"
155
+ - Gemfile
156
+ - LICENSE
157
+ - README.md
158
+ - README.rdoc
159
+ - Rakefile
160
+ - bin/console
161
+ - bin/setup
162
+ - bin/start_server.rb
163
+ - icaprb-filter.gemspec
164
+ - lib/icaprb/filter.rb
165
+ - lib/icaprb/filter/service.rb
166
+ - lib/icaprb/filter/solution.rb
167
+ - lib/icaprb/filter/steganography.rb
168
+ - lib/icaprb/filter/version.rb
169
+ - samples/block_samples/check_hashes_test.rb
170
+ - samples/block_samples/check_hashes_test.txt
171
+ - samples/block_samples/content_has_key_test.html
172
+ - samples/block_samples/content_has_key_test.rb
173
+ - samples/block_samples/content_includes_test.html
174
+ - samples/block_samples/content_includes_test.rb
175
+ - samples/block_samples/nothing_to_filter_test.html
176
+ - samples/block_samples/url_contains_test.rb
177
+ - samples/custom_samples/virustotal_config.rb
178
+ homepage: https://github.com/fabianfrz/ICAPrb-Filter
179
+ licenses: []
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.5.1
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Filter framework for ICAPrb-server. Does not work standalone. This gem includes
201
+ a framework to create a content filter which allows to filter content instead of
202
+ only the urls. It is extensible by plug ins. For example it can be used to enforce
203
+ your companies network usage policies at the proxy.
204
+ test_files: []
205
+ has_rdoc: