security-gem 0.1.3 → 0.1.6

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: 1e19b4ce5337fef141ece0c5db7d4b76031f6171065a9fee2ff1444692b3c2de
4
- data.tar.gz: 85b6afc1258a32aa7ce7c61a8b465384630bb0838122b6d2d19e2cd2a270c5ae
3
+ metadata.gz: 91195d81663461672214a7b6dd7e6b255f1a9560447d97931dcbafdb5b3d7703
4
+ data.tar.gz: 3c56de327c041550882758d7874b9ded3ed693c897cde0740629cd93baca1291
5
5
  SHA512:
6
- metadata.gz: b3f5b0d39f1b9f2a88f8a573881dad6e2cc265706e2fad78501c2d338f3cd431c9886f5ac60c8fd70af55aca6fc28aff5ac5c458d86512f2b3c6ba053ca003c8
7
- data.tar.gz: 1a8a91cc11c917bf651c8675f90a16db7c5833ce9830eb8424647ea67095ce6f7089dd631cf7c6e0239be8f470a42dd8ce7072ebb31becb7e6cb47bf173558f1
6
+ metadata.gz: dae9cc4b1068fc4379719a45ff3c499a4fd89c8013ed9855947bf416b6ad87f12f983b040377373d8848bd25678a8455ebfb522180f1f9147ae77a5b9dcd160a
7
+ data.tar.gz: 7a625a3b0f0513eb6c2a226c52625326c2d8596ac90737be8101b83fad6120f36b9457ed2a0c4ed2df915c07323670b2a3f9828037bbf2c40cb4931516fac017
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rubocop", "~> 0.80"
11
+
12
+ gem 'colored', '~> 1.2'
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- security-gem (0.1.3)
4
+ security-gem (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
+ colored (1.2)
10
11
  parallel (1.22.1)
11
12
  parser (3.1.2.0)
12
13
  ast (~> 2.4.1)
@@ -32,6 +33,7 @@ PLATFORMS
32
33
  x86_64-darwin-20
33
34
 
34
35
  DEPENDENCIES
36
+ colored (~> 1.2)
35
37
  rake (~> 13.0)
36
38
  rubocop (~> 0.80)
37
39
  security-gem!
@@ -0,0 +1,206 @@
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
+
17
+ require 'json'
18
+ require 'logger'
19
+ require 'logger/formatter'
20
+ require 'net/http'
21
+ require 'dotenv'
22
+ require 'colored'
23
+ Dotenv.load
24
+
25
+ module SecurityLogger
26
+
27
+ =begin
28
+
29
+ Sql_Injection Class
30
+ ___________________
31
+
32
+ Description:
33
+ - Checks inputs against most commonly used sql injection commands.
34
+ - Inputs that match or contain probably sql commands will be logged.
35
+ - Payloads can be replaced by simply changing the ENV varibles
36
+ and pointing the URI to any custom text file
37
+
38
+ Usage: SecurityLogger::Sql_Injection.new(ip_origin: request.ip).check_input(input)
39
+
40
+ =end
41
+
42
+ class Sql_Injection
43
+ def initialize (ip_origin:)
44
+ @ip_origin = ip_origin
45
+ end
46
+
47
+ def log(input)
48
+ logger = Logger.new(STDOUT)
49
+ logger.formatter = proc do |severity, datetime, progname, msg|
50
+ {
51
+ severity: severity,
52
+ timestamp: datetime.to_s,
53
+ app: progname,
54
+ message: msg
55
+ }.to_json + $/
56
+ end
57
+
58
+ message = {:threat => "sql_injection_attack", :input => input, :ip_origin => @ip_origin}
59
+ puts
60
+ logger.warn(JSON.parse(message.to_json))
61
+ puts
62
+ return
63
+ end
64
+
65
+ def check_input(input)
66
+ uri = ENV['PATH_TO_SQL_PAYLOAD']
67
+ uri = URI(uri)
68
+ file = Net::HTTP.get(uri)
69
+ file.each_line do |file|
70
+ if file.strip == input.strip
71
+ self.log(input.strip)
72
+ return
73
+ end
74
+ end
75
+
76
+ uri = ENV['PATH_TO_SQL_COMMON_COMMANDS']
77
+ uri = URI(uri)
78
+ file = Net::HTTP.get(uri)
79
+ file.each_line do |file|
80
+ if input.strip.downcase.include?(file.strip.downcase)
81
+ self.log(input.strip)
82
+ return
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+
89
+
90
+ =begin
91
+
92
+ Xss_Injection Class
93
+ ___________________
94
+
95
+ Description:
96
+ - Checks inputs against most commonly used xss scripts.
97
+ - Inputs that match or contain common keywords will be logged.
98
+ - Payloads can be replaced by simply changing the ENV varibles
99
+ and pointing the URI to any custom text file
100
+
101
+ Usage: SecurityLogger::Xss_Injection.new(ip_origin: request.ip).check_input(input)
102
+
103
+ =end
104
+
105
+ class Xss_Injection
106
+ def initialize (ip_origin:)
107
+ @ip_origin = ip_origin
108
+ end
109
+
110
+ def log(input)
111
+ logger = Logger.new(STDOUT)
112
+ logger.formatter = proc do |severity, datetime, progname, msg|
113
+ {
114
+ severity: severity,
115
+ timestamp: datetime.to_s,
116
+ app: progname,
117
+ message: msg
118
+ }.to_json + $/
119
+ end
120
+
121
+ message = {:threat => "xss_attack", :input => input, :ip_origin => @ip_origin}
122
+ puts
123
+ logger.warn(JSON.parse(message.to_json))
124
+ puts
125
+ end
126
+
127
+ def check_input(input)
128
+ uri = ENV['PATH_TO_XSS_PAYLOAD']
129
+ uri = URI(uri)
130
+ file = Net::HTTP.get(uri)
131
+ file.each_line do |file|
132
+ if file.strip == input.strip
133
+ self.log(input.strip)
134
+ return
135
+ end
136
+ end
137
+
138
+ uri = ENV['PATH_TO_XSS_COMMON_SCRIPTS']
139
+ uri = URI(uri)
140
+ file = Net::HTTP.get(uri)
141
+ file.each_line do |file|
142
+ if input.strip.downcase.include?(file.strip.downcase)
143
+ self.log(input.strip)
144
+ return
145
+ end
146
+ end
147
+
148
+ end
149
+ end
150
+
151
+
152
+ =begin
153
+
154
+ User_Agent Class
155
+ ___________________
156
+
157
+ Description:
158
+ - Checks inputs against most common user_agents (approx. top 1000).
159
+ - Inputs that DO NOT match any of the most common user agents will be logged.
160
+ - Payloads can be replaced by simply changing the ENV varibles
161
+ and pointing the URI to any custom text file
162
+
163
+ Usage: SecurityLogger::User_Agent.new(ip_origin: request.ip).check_input(input)
164
+
165
+ =end
166
+
167
+ class User_Agent
168
+ def initialize (ip_origin:)
169
+ @ip_origin = ip_origin
170
+ end
171
+
172
+ def log(input)
173
+ logger = Logger.new(STDOUT)
174
+ logger.formatter = proc do |severity, datetime, progname, msg|
175
+ {
176
+ severity: severity,
177
+ timestamp: datetime.to_s,
178
+ app: progname,
179
+ message: msg
180
+ }.to_json + $/
181
+ end
182
+
183
+ message = {:threat => "uncommon_user_agent", :input => input, :ip_origin => @ip_origin}
184
+ puts
185
+ logger.warn(JSON.parse(message.to_json))
186
+ puts
187
+ end
188
+
189
+ def check_input(input)
190
+ uri = ENV['PATH_TO_USER_AGENT_PAYLOAD']
191
+ uri = URI(uri)
192
+ file = Net::HTTP.get(uri)
193
+ @matches = 0
194
+ file.each_line do |file|
195
+ if file.strip == input.strip
196
+ @matches += 1
197
+ end
198
+ end
199
+
200
+ if @matches == 0
201
+ self.log(input.strip)
202
+ return
203
+ end
204
+ end
205
+ end
206
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Security
4
4
  module Gem
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
data/lib/security/gem.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "gem/version"
4
- require_relative "gem/builder"
4
+ require_relative "gem/security"
5
5
 
6
6
  module Security
7
7
  module Gem
data/lib/security/test.rb CHANGED
@@ -1,7 +1,17 @@
1
- require_relative "gem/builder"
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
- SecurityLogger::Sql_Injection.new(ip_origin: "123.123.123.1").check_input(input)
7
+ SecurityLogger::Sql_Injection.new(ip_origin: "123.123.123.1").check_input(input)
8
+
9
+ input = "<svg"
10
+
11
+ # Using gem to log xss attempts
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
@@ -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 --