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 +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +3 -1
- data/lib/security/gem/security.rb +206 -0
- data/lib/security/gem/version.rb +1 -1
- data/lib/security/gem.rb +1 -1
- data/lib/security/test.rb +13 -3
- data/sql_common_commands.txt +37 -0
- data/{payloads.txt → sql_payloads.txt} +1 -1
- data/top_user_agents.txt +1037 -0
- data/xss_common_scripts.txt +34 -0
- data/xss_payloads.txt +6606 -0
- metadata +7 -3
- data/lib/security/gem/builder.rb +0 -45
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 91195d81663461672214a7b6dd7e6b255f1a9560447d97931dcbafdb5b3d7703
|
|
4
|
+
data.tar.gz: 3c56de327c041550882758d7874b9ded3ed693c897cde0740629cd93baca1291
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dae9cc4b1068fc4379719a45ff3c499a4fd89c8013ed9855947bf416b6ad87f12f983b040377373d8848bd25678a8455ebfb522180f1f9147ae77a5b9dcd160a
|
|
7
|
+
data.tar.gz: 7a625a3b0f0513eb6c2a226c52625326c2d8596ac90737be8101b83fad6120f36b9457ed2a0c4ed2df915c07323670b2a3f9828037bbf2c40cb4931516fac017
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
security-gem (0.1.
|
|
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
|
data/lib/security/gem/version.rb
CHANGED
data/lib/security/gem.rb
CHANGED
data/lib/security/test.rb
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
require_relative "gem/
|
|
1
|
+
require_relative "gem/security"
|
|
2
2
|
|
|
3
3
|
# Sample SQL input
|
|
4
|
-
input = "
|
|
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
|