security-gem 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1861d7d816f659f59c15391e75fb1e95aeac0088dff85af4ee111f76e743b936
4
- data.tar.gz: 63dba123845017c076c57b52b64fa1be6425de43ced46e74d628deab1e0db29f
3
+ metadata.gz: 2f2eecdfc5fb7ffdb08c8233fbc0c31528364e5e787241bc89351b3ceb54c844
4
+ data.tar.gz: e5d719157b9158bca6784763a1f8e0d6fcbcb08f11bc11246d6e14b979352753
5
5
  SHA512:
6
- metadata.gz: c70695d1dffa5d4b06710182dc885854f95eccaee3f90efaca572d1f1b4487edc29cf2fbe169291dfb2d58e7dcbdbabe257e89d5360677df307d9c2e8a6f85ad
7
- data.tar.gz: b8150a3d21a3a0aada6f788d0ffe5f30dcd31fd27e29cd1a71a1ca5b5bb814e5677078e59cb24801bc518006040cb4858f43e5bfd4f61204031db14b6fd686a1
6
+ metadata.gz: 19bf4b7bf2291c2a4c5f704829f7f78b03e0726d977fdf3c72171f01c51993c3e5ee21b854407f6ff72ab089fac36822a3be9ed113603e934884c166dc039d63
7
+ data.tar.gz: c5914aa0c01e1978d1a2774ad2d13866e8d6bf3c3b3f20b3a40e3debb8c9588d0a748f48201754a34ca528350662eb5a8271109d2fbd917536e02ae7ae324233
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- security-gem (0.1.4)
4
+ security-gem (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,14 +1,43 @@
1
+ =begin
2
+
3
+ SecurityLogger
4
+ ______________
5
+
6
+ Description:
7
+ This module provides a simple and unified format to log security events
8
+
9
+ Classes:
10
+ Sql_Injection, Xss_Injection, User_Agent
11
+
12
+ Owner:
13
+ Tucker Weibell - 05/09/2022
14
+
15
+ =end
16
+
1
17
  require 'json'
2
18
  require 'logger'
3
19
  require 'logger/formatter'
4
20
  require 'net/http'
5
- require 'open-uri'
6
21
  require 'dotenv'
7
22
  Dotenv.load
8
23
 
9
24
  module SecurityLogger
10
25
 
11
- #Create logs used for SQL Injection detections
26
+ =begin
27
+
28
+ Sql_Injection Class
29
+ ___________________
30
+
31
+ Description:
32
+ - Checks inputs against most commonly used sql injection commands.
33
+ - Inputs that match or contain probably sql commands will be logged.
34
+ - Payloads can be replaced by simply changing the ENV varibles
35
+ and pointing the URI to any custom text file
36
+
37
+ Usage: SecurityLogger::Sql_Injection.new(ip_origin: request.ip).check_input(input)
38
+
39
+ =end
40
+
12
41
  class Sql_Injection
13
42
  def initialize (ip_origin:)
14
43
  @ip_origin = ip_origin
@@ -25,8 +54,9 @@ module SecurityLogger
25
54
  }.to_json + $/
26
55
  end
27
56
 
28
- error = {:threat => "sql_injection_attack", :input => input, :ip_origin => @ip_origin}
29
- logger.warn(JSON.parse(error.to_json))
57
+ message = {:threat => "sql_injection_attack", :input => input, :ip_origin => @ip_origin}
58
+ logger.warn(JSON.parse(message.to_json))
59
+ return
30
60
  end
31
61
 
32
62
  def check_input(input)
@@ -36,13 +66,39 @@ module SecurityLogger
36
66
  file.each_line do |file|
37
67
  if file.strip == input.strip
38
68
  self.log(input.strip)
39
- break
69
+ return
40
70
  end
41
71
  end
42
72
 
73
+ uri = ENV['PATH_TO_SQL_COMMON_COMMANDS']
74
+ uri = URI(uri)
75
+ file = Net::HTTP.get(uri)
76
+ file.each_line do |file|
77
+ if input.strip.downcase.include?(file.strip.downcase)
78
+ self.log(input.strip)
79
+ return
80
+ end
81
+ end
82
+
43
83
  end
44
84
  end
45
85
 
86
+
87
+ =begin
88
+
89
+ Xss_Injection Class
90
+ ___________________
91
+
92
+ Description:
93
+ - Checks inputs against most commonly used xss scripts.
94
+ - Inputs that match or contain common keywords will be logged.
95
+ - Payloads can be replaced by simply changing the ENV varibles
96
+ and pointing the URI to any custom text file
97
+
98
+ Usage: SecurityLogger::Xss_Injection.new(ip_origin: request.ip).check_input(input)
99
+
100
+ =end
101
+
46
102
  class Xss_Injection
47
103
  def initialize (ip_origin:)
48
104
  @ip_origin = ip_origin
@@ -59,8 +115,8 @@ module SecurityLogger
59
115
  }.to_json + $/
60
116
  end
61
117
 
62
- error = {:threat => "xss_attack", :input => input, :ip_origin => @ip_origin}
63
- logger.warn(JSON.parse(error.to_json))
118
+ message = {:threat => "xss_attack", :input => input, :ip_origin => @ip_origin}
119
+ logger.warn(JSON.parse(message.to_json))
64
120
  end
65
121
 
66
122
  def check_input(input)
@@ -70,10 +126,74 @@ module SecurityLogger
70
126
  file.each_line do |file|
71
127
  if file.strip == input.strip
72
128
  self.log(input.strip)
73
- break
129
+ return
74
130
  end
75
131
  end
76
132
 
133
+ uri = ENV['PATH_TO_XSS_COMMON_SCRIPTS']
134
+ uri = URI(uri)
135
+ file = Net::HTTP.get(uri)
136
+ file.each_line do |file|
137
+ if input.strip.downcase.include?(file.strip.downcase)
138
+ self.log(input.strip)
139
+ return
140
+ end
141
+ end
142
+
143
+ end
144
+ end
145
+
146
+
147
+ =begin
148
+
149
+ User_Agent Class
150
+ ___________________
151
+
152
+ Description:
153
+ - Checks inputs against most common user_agents (approx. top 1000).
154
+ - Inputs that DO NOT match any of the most common user agents will be logged.
155
+ - Payloads can be replaced by simply changing the ENV varibles
156
+ and pointing the URI to any custom text file
157
+
158
+ Usage: SecurityLogger::User_Agent.new(ip_origin: request.ip).check_input(input)
159
+
160
+ =end
161
+
162
+ class User_Agent
163
+ def initialize (ip_origin:)
164
+ @ip_origin = ip_origin
165
+ end
166
+
167
+ def log(input)
168
+ logger = Logger.new(STDOUT)
169
+ logger.formatter = proc do |severity, datetime, progname, msg|
170
+ {
171
+ severity: severity,
172
+ timestamp: datetime.to_s,
173
+ app: progname,
174
+ message: msg
175
+ }.to_json + $/
176
+ end
177
+
178
+ message = {:threat => "uncommon_user_agent", :input => input, :ip_origin => @ip_origin}
179
+ logger.warn(JSON.parse(message.to_json))
180
+ end
181
+
182
+ def check_input(input)
183
+ uri = ENV['PATH_TO_USER_AGENT_PAYLOAD']
184
+ uri = URI(uri)
185
+ file = Net::HTTP.get(uri)
186
+ @matches = 0
187
+ file.each_line do |file|
188
+ if file.strip == input.strip
189
+ @matches += 1
190
+ end
191
+ end
192
+
193
+ if @matches == 0
194
+ self.log(input.strip)
195
+ return
196
+ end
77
197
  end
78
198
  end
79
199
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Security
4
4
  module Gem
5
- VERSION = "0.1.4"
5
+ VERSION = "0.1.5"
6
6
  end
7
7
  end
data/lib/security/test.rb CHANGED
@@ -1,12 +1,17 @@
1
1
  require_relative "gem/security"
2
2
 
3
3
  # Sample SQL input
4
- input = "or 1=1"
4
+ input = "ALTER TABLE"
5
5
 
6
6
  # Using the gem to log injection attempts
7
7
  SecurityLogger::Sql_Injection.new(ip_origin: "123.123.123.1").check_input(input)
8
8
 
9
- input = "<script>alert(0)</script>"
9
+ input = "<svg"
10
10
 
11
11
  # Using gem to log xss attempts
12
- SecurityLogger::Xss_Injection.new(ip_origin: "123.123.123.1").check_input(input)
12
+ SecurityLogger::Xss_Injection.new(ip_origin: "123.123.123.1").check_input(input)
13
+
14
+ input = "evilhacker"
15
+
16
+ # Using gem to log xss attempts
17
+ SecurityLogger::User_Agent.new(ip_origin: "123.123.123.1").check_input(input)
@@ -0,0 +1,37 @@
1
+ SELECT
2
+ FROM
3
+ SELECT FROM
4
+ UNION
5
+ UNION ALL
6
+ UNION ALL SELECT
7
+ COLLATE
8
+ DELETE
9
+ INSERT INTO
10
+ CREATE DATABASE
11
+ ALTER DATABASE
12
+ CREATE TABLE
13
+ ALTER TABLE
14
+ DROP TABLE
15
+ CREATE INDEX
16
+ DROP INDEX
17
+ DECLARE
18
+ /*!32302 1/0, */
19
+ /*!32302
20
+ CONCAT
21
+ 1--
22
+ admin' --
23
+ admin' #
24
+ admin'/*
25
+ ' or 1=1--
26
+ ' or 1=1#
27
+ ' or 1=1/*
28
+ ') or '1'='1--
29
+ ') or ('1'='1--
30
+ ' HAVING 1=1 --
31
+ GROUP BY
32
+ ORDER BY
33
+ WAITFOR DELAY
34
+ NULL--
35
+ ;
36
+ IF EXISTS
37
+ mysql.user
data/sql_payloads.txt CHANGED
@@ -1823,4 +1823,4 @@ t'exec master..xp_cmdshell 'nslookup www.google.com'--
1823
1823
  %21
1824
1824
  ' or ''='
1825
1825
  ' or 3=3
1826
-  or 3=3 --
1826
+ ' or 3=3 --