f2bread 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/License.txt +15 -0
- data/bin/f2bread +102 -0
- data/lib/GeoIP.dat +0 -0
- data/lib/f2bread.rb +388 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 46c6943b217daeea409dea49d8a6bcd3a99d22cb
|
4
|
+
data.tar.gz: 1dc79cd7aaaf04718788795d3417070a5426c5cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03ed98fac8cf659a79c028f61df66053d8cdca225740548714843837312092c1fa2d36977f75fdb69f0c42cc9ac2a9229835b2a63a262ba3c69fb8f6681cd28b
|
7
|
+
data.tar.gz: b5f79f16b704ed11f800deedfa95f86078a38e03f1537cb76381482797000866d79135b2bf1619179d48be6fa8f3fc8945fbd554ff745d871bf49fc8f63fc380
|
data/License.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Copyright (c) 2013 Panagiotis Atmatzidis
|
2
|
+
email: atma[at]convalesco.org
|
3
|
+
|
4
|
+
f2bread gem is distributed under MIT license:
|
5
|
+
The MIT License (MIT)
|
6
|
+
---------------------
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
|
+
|
11
|
+
This product includes *GeoLite data* created by MaxMind, available from www.maxmind.com[1]. The GeoLite databases are distributed under the Creative Commons Attribution-ShareAlike 3.0 Unported License[2].
|
12
|
+
|
13
|
+
|
14
|
+
[1] http://www.maxmind.com
|
15
|
+
[2] http://creativecommons.org/licenses/by-sa/3.0/
|
data/bin/f2bread
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'f2bread'
|
4
|
+
|
5
|
+
# Global vars
|
6
|
+
$version = "0.0.1-alpha"
|
7
|
+
filename = File.basename(__FILE__)
|
8
|
+
$banner = "#{filename} #{$version}\n--------------------------------------------------------\n"
|
9
|
+
pwd = File.dirname(File.expand_path(__FILE__))
|
10
|
+
$GeoIP = "#{pwd}/../lib/GeoIP.dat"
|
11
|
+
|
12
|
+
#optparse options
|
13
|
+
options = {:no => 0}
|
14
|
+
|
15
|
+
optparse = OptionParser.new do |opts|
|
16
|
+
|
17
|
+
opts.banner = "Usage: f2bread -l /path/to/fail2ban.log -s country -n 5\n"
|
18
|
+
|
19
|
+
opts.on('-l', '--log FILE', 'Define the location of fail2ban.log. Default is /var/log/fail2ban.log') do |log|
|
20
|
+
options[:log] = log
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-n', '--no N', Integer, 'Number of top entries to be displayed. By default all entries are displayed.') do |no|
|
24
|
+
if no > 0
|
25
|
+
options[:no] = no
|
26
|
+
else
|
27
|
+
warn "Negative value is not accepted. Using default '0'"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# next version
|
32
|
+
# opts.on('-r', '--resolv', 'Resolv hostnames on IP addresses') do |resolv|
|
33
|
+
# options[:resolv] = resolv
|
34
|
+
# end
|
35
|
+
|
36
|
+
opts.on('-i', '--info', 'Display fail2ban.log summary') do |info|
|
37
|
+
options[:info] = info
|
38
|
+
end
|
39
|
+
|
40
|
+
# http://ruby.about.com/od/advancedruby/a/optionparser2.htm
|
41
|
+
options[:sort] = :yes
|
42
|
+
opts.on('-s', '--sort OPT', [:date, :country, :ip], 'Sorts by [date, country, ip (ip frequency)]') do |sort|
|
43
|
+
options[:sort] = sort
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('-v', '--version', 'Display version') do
|
47
|
+
puts $banner
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on('-h', '--help', 'Display help menu') do
|
52
|
+
puts opts
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
optparse.parse!
|
58
|
+
|
59
|
+
# adjust $logfile and $no
|
60
|
+
if options[:log]
|
61
|
+
$logfile = options[:log]
|
62
|
+
$f2b = F2bread.new($logfile)
|
63
|
+
else
|
64
|
+
if File.exists?('/var/log/fail2ban.log')
|
65
|
+
$logfile = '/var/log/fail2ban.log'
|
66
|
+
$f2b = F2bread.new($logfile)
|
67
|
+
else
|
68
|
+
puts $banner
|
69
|
+
puts "No fail2ban.log found!"
|
70
|
+
puts "Type '#{filename} -h' for help"
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if options[:no]
|
76
|
+
begin
|
77
|
+
$no = Integer(options[:no])
|
78
|
+
rescue ArgumentError
|
79
|
+
puts "#{$no} is not an Integer!"
|
80
|
+
else
|
81
|
+
true
|
82
|
+
end
|
83
|
+
else
|
84
|
+
$no = 0
|
85
|
+
end
|
86
|
+
|
87
|
+
# exec starts here
|
88
|
+
if options[:info]
|
89
|
+
$f2b.info
|
90
|
+
elsif options[:sort]
|
91
|
+
if options[:sort] == :date
|
92
|
+
$f2b.sort_by_date($no)
|
93
|
+
elsif options[:sort] == :country
|
94
|
+
$f2b.sort_by_country($no)
|
95
|
+
elsif options[:sort] == :ip
|
96
|
+
$f2b.sort_by_ip($no)
|
97
|
+
else
|
98
|
+
puts "Option not recognized for '--sort', please read '--help'"
|
99
|
+
end
|
100
|
+
else
|
101
|
+
puts "Option not recognized. Type '#{__FILE__} -h' "
|
102
|
+
end
|
data/lib/GeoIP.dat
ADDED
Binary file
|
data/lib/f2bread.rb
ADDED
@@ -0,0 +1,388 @@
|
|
1
|
+
#/usr/bin/env ruby
|
2
|
+
|
3
|
+
# coding: utf-8
|
4
|
+
|
5
|
+
=begin
|
6
|
+
|
7
|
+
Description
|
8
|
+
===========
|
9
|
+
'f2bread' library file for f2bread gem.
|
10
|
+
|
11
|
+
License
|
12
|
+
=======
|
13
|
+
The MIT License (MIT)
|
14
|
+
Copyright (c) 2012 Panagiotis Atmatzidis <atma[at]convalesco.org>
|
15
|
+
For more read: https://github.com/atmosx/f2bread/blob/master/LICENSE.md
|
16
|
+
|
17
|
+
=end
|
18
|
+
|
19
|
+
require 'optparse'
|
20
|
+
require 'geoip'
|
21
|
+
#require 'socket'
|
22
|
+
require 'time_diff'
|
23
|
+
|
24
|
+
# class starts here
|
25
|
+
class F2bread
|
26
|
+
attr_accessor :log
|
27
|
+
def initialize(log)
|
28
|
+
# check if Fail2ban.log exists and then check if it's valid!
|
29
|
+
raise ArgumentError, "No fail2ban.log found!!!" if File.exists?(log) == FALSE # <-- this is not needed right now!
|
30
|
+
|
31
|
+
@data_table = []
|
32
|
+
@log = log
|
33
|
+
|
34
|
+
# grep lines that containt the keyword 'Ban' from log file
|
35
|
+
lines = File.readlines(log).select {|line| line.match /Ban/}
|
36
|
+
|
37
|
+
# Available internet country codes
|
38
|
+
cdc = {
|
39
|
+
"AD" => "Andorra",
|
40
|
+
"AE" => "United_Arab_Emirates",
|
41
|
+
"AF" => "Afghanistan",
|
42
|
+
"AG" => "Antigua_and_Barbuda",
|
43
|
+
"AI" => "Anguilla",
|
44
|
+
"AL" => "Albania",
|
45
|
+
"AM" => "Armenia",
|
46
|
+
"AN" => "Netherlands_Antilles",
|
47
|
+
"AO" => "Angola",
|
48
|
+
"AQ" => "Antarctica",
|
49
|
+
"AR" => "Argentina",
|
50
|
+
"ARPA" => "Old_style_Arpanet",
|
51
|
+
"AS" => "American Samoa",
|
52
|
+
"AT" => "Austria",
|
53
|
+
"AU" => "Australia",
|
54
|
+
"AW" => "Aruba",
|
55
|
+
"AZ" => "Azerbaijan",
|
56
|
+
"BA" => "Bosnia_and_Herzegovina",
|
57
|
+
"BB" => "Barbados",
|
58
|
+
"BD" => "Bangladesh",
|
59
|
+
"BE" => "Belgium",
|
60
|
+
"BF" => "Burkina_Faso",
|
61
|
+
"BG" => "Bulgaria",
|
62
|
+
"BH" => "Bahrain",
|
63
|
+
"BI" => "Burundi",
|
64
|
+
"BJ" => "Benin",
|
65
|
+
"BM" => "Bermuda",
|
66
|
+
"BN" => "Brunei_Darussalam",
|
67
|
+
"BO" => "Bolivia",
|
68
|
+
"BR" => "Brazil",
|
69
|
+
"BS" => "Bahamas",
|
70
|
+
"BT" => "Bhutan",
|
71
|
+
"BV" => "Bouvet_Island",
|
72
|
+
"BW" => "Botswana",
|
73
|
+
"BY" => "Belarus",
|
74
|
+
"BZ" => "Belize",
|
75
|
+
"CA" => "Canada",
|
76
|
+
"CC" => "Cocos_Islands",
|
77
|
+
"CF" => "Central_African_Republic",
|
78
|
+
"CG" => "Congo",
|
79
|
+
"CH" => "Switzerland",
|
80
|
+
"CI" => "Ivory_Coast",
|
81
|
+
"CK" => "Cook_Islands",
|
82
|
+
"CL" => "Chile",
|
83
|
+
"CM" => "Cameroon",
|
84
|
+
"CN" => "China",
|
85
|
+
"CO" => "Colombia",
|
86
|
+
"COM" => "US_Commercial(USA)",
|
87
|
+
"CR" => "Costa Rica",
|
88
|
+
"CS" => "Czechoslovakia(former)",
|
89
|
+
"CU" => "Cuba",
|
90
|
+
"CV" => "Cape Verde",
|
91
|
+
"CX" => "Christmas_Island",
|
92
|
+
"CY" => "Cyprus",
|
93
|
+
"CZ" => "Czech_Republic",
|
94
|
+
"DE" => "Germany",
|
95
|
+
"DJ" => "Djibouti",
|
96
|
+
"DK" => "Denmark",
|
97
|
+
"DM" => "Dominica",
|
98
|
+
"DO" => "Dominican_Republic",
|
99
|
+
"DZ" => "Algeria",
|
100
|
+
"EC" => "Ecuador",
|
101
|
+
"EDU" => "US_Educational(USA)",
|
102
|
+
"EE" => "Estonia",
|
103
|
+
"EG" => "Egypt",
|
104
|
+
"EH" => "Western_Sahara",
|
105
|
+
"ER" => "Eritrea",
|
106
|
+
"ES" => "Spain",
|
107
|
+
"ET" => "Ethiopia",
|
108
|
+
"FI" => "Finland",
|
109
|
+
"FJ" => "Fiji",
|
110
|
+
"FK" => "Falkland_Islands",
|
111
|
+
"FM" => "Micronesia",
|
112
|
+
"FO" => "Faroe_Islands",
|
113
|
+
"FR" => "France_(Francie)",
|
114
|
+
"FX" => "France_Metropolitan",
|
115
|
+
"GA" => "Gabon",
|
116
|
+
"GB" => "Great_Britain(UK)",
|
117
|
+
"GD" => "Grenada",
|
118
|
+
"GE" => "Georgia",
|
119
|
+
"GF" => "French_Guiana",
|
120
|
+
"GH" => "Ghana",
|
121
|
+
"GI" => "Gibraltar",
|
122
|
+
"GL" => "Greenland(Island)",
|
123
|
+
"GM" => "Gambia",
|
124
|
+
"GN" => "Guinea",
|
125
|
+
"GOV" => "US_Government(USA)",
|
126
|
+
"GP" => "Guadeloupe",
|
127
|
+
"GQ" => "Equatorial_Guinea",
|
128
|
+
"GR" => "Greece",
|
129
|
+
"GS" => "S.Georgia_and_S.Sandwich_Isls.",
|
130
|
+
"GT" => "Guatemala",
|
131
|
+
"GU" => "Guam",
|
132
|
+
"GW" => "Guinea-Bissau",
|
133
|
+
"GY" => "Guyana",
|
134
|
+
"HK" => "Hong Kong",
|
135
|
+
"HM" => "Heard_and_McDonald_Islands",
|
136
|
+
"HN" => "Honduras",
|
137
|
+
"HR" => "Croatia",
|
138
|
+
"HT" => "Haiti",
|
139
|
+
"HU" => "Hungary",
|
140
|
+
"ID" => "Indonesia",
|
141
|
+
"IE" => "Ireland",
|
142
|
+
"IL" => "Israel",
|
143
|
+
"IN" => "India",
|
144
|
+
"INT" => "International",
|
145
|
+
"IO" => "British_Indian_Ocean_Territory",
|
146
|
+
"IQ" => "Iraq",
|
147
|
+
"IR" => "Iran",
|
148
|
+
"IS" => "Iceland(Island)",
|
149
|
+
"IT" => "Italy",
|
150
|
+
"JM" => "Jamaica",
|
151
|
+
"JO" => "Jordan",
|
152
|
+
"JP" => "Japan",
|
153
|
+
"KE" => "Kenya",
|
154
|
+
"KG" => "Kyrgyzstan",
|
155
|
+
"KH" => "Cambodia",
|
156
|
+
"KI" => "Kiribati",
|
157
|
+
"KM" => "Comoros",
|
158
|
+
"KN" => "Saint_Kitts_and_Nevis",
|
159
|
+
"KP" => "Korea(North)",
|
160
|
+
"KR" => "Korea(South)",
|
161
|
+
"KW" => "Kuwait",
|
162
|
+
"KY" => "Cayman_Islands",
|
163
|
+
"KZ" => "Kazakhstan",
|
164
|
+
"LA" => "Laos",
|
165
|
+
"LB" => "Lebanon",
|
166
|
+
"LC" => "Saint_Lucia",
|
167
|
+
"LI" => "Liechtenstein",
|
168
|
+
"LK" => "Sri_Lanka",
|
169
|
+
"LR" => "Liberia",
|
170
|
+
"LS" => "Lesotho",
|
171
|
+
"LT" => "Lithuania",
|
172
|
+
"LU" => "Luxembourg",
|
173
|
+
"LV" => "Latvia",
|
174
|
+
"LY" => "Libya",
|
175
|
+
"MA" => "Morocco",
|
176
|
+
"MC" => "Monaco",
|
177
|
+
"MD" => "Moldova",
|
178
|
+
"MG" => "Madagascar",
|
179
|
+
"MH" => "Marshall_Islands",
|
180
|
+
"MIL" => "US_Military",
|
181
|
+
"MK" => "Macedonia",
|
182
|
+
"ML" => "Mali",
|
183
|
+
"MM" => "Myanmar",
|
184
|
+
"MN" => "Mongolia",
|
185
|
+
"MO" => "Macau",
|
186
|
+
"MP" => "Northern_Mariana_Islands",
|
187
|
+
"MQ" => "Martinique",
|
188
|
+
"MR" => "Mauritania",
|
189
|
+
"MS" => "Montserrat",
|
190
|
+
"MT" => "Malta",
|
191
|
+
"MU" => "Mauritius",
|
192
|
+
"MV" => "Maldives",
|
193
|
+
"MW" => "Malawi",
|
194
|
+
"MX" => "Mexico",
|
195
|
+
"MY" => "Malaysia",
|
196
|
+
"MZ" => "Mozambique",
|
197
|
+
"NA" => "Namibia",
|
198
|
+
"NATO" => "Nato_field",
|
199
|
+
"NC" => "New_Caledonia",
|
200
|
+
"NE" => "Niger",
|
201
|
+
"NET" => "Network",
|
202
|
+
"NF" => "Norfolk_Island",
|
203
|
+
"NG" => "Nigeria",
|
204
|
+
"NI" => "Nicaragua",
|
205
|
+
"NL" => "Netherlands",
|
206
|
+
"NO" => "Norway",
|
207
|
+
"NP" => "Nepal",
|
208
|
+
"NR" => "Nauru",
|
209
|
+
"NT" => "Neutral_Zone",
|
210
|
+
"NU" => "Niue",
|
211
|
+
"NZ" => "New_Zealand",
|
212
|
+
"OM" => "Oman",
|
213
|
+
"ORG" => "US-Non-Profit_Organization(USA)",
|
214
|
+
"PA" => "Panama",
|
215
|
+
"PE" => "Peru",
|
216
|
+
"PF" => "French_Polynesia",
|
217
|
+
"PG" => "Papua_New_Guinea",
|
218
|
+
"PH" => "Philippines",
|
219
|
+
"PK" => "Pakistan",
|
220
|
+
"PL" => "Poland",
|
221
|
+
"PM" => "St.Pierre_and_Miquelon",
|
222
|
+
"PN" => "Pitcairn",
|
223
|
+
"PR" => "Puerto_Rico",
|
224
|
+
"PT" => "Portugal",
|
225
|
+
"PW" => "Palau",
|
226
|
+
"PY" => "Paraguay",
|
227
|
+
"QA" => "Qatar",
|
228
|
+
"RE" => "Reunion",
|
229
|
+
"RO" => "Romania",
|
230
|
+
"RU" => "Russian_Federation",
|
231
|
+
"RW" => "Rwanda",
|
232
|
+
"SA" => "Saudi_Arabia",
|
233
|
+
"SC" => "Seychelles",
|
234
|
+
"SD" => "Sudan",
|
235
|
+
"SE" => "Sweden",
|
236
|
+
"SG" => "Singapore",
|
237
|
+
"SH" => "St.Helena",
|
238
|
+
"SI" => "Slovenia",
|
239
|
+
"SJ" => "Svalbard_and_Jan_Mayen_Islands",
|
240
|
+
"SK" => "SlovakRepublic",
|
241
|
+
"SL" => "SierraLeone",
|
242
|
+
"SM" => "SanMarino",
|
243
|
+
"SN" => "Senegal",
|
244
|
+
"SO" => "Somalia",
|
245
|
+
"SR" => "Suriname",
|
246
|
+
"ST" => "Sao_Tome_and_Principe",
|
247
|
+
"SU" => "USSR(former)",
|
248
|
+
"SV" => "ElSalvador",
|
249
|
+
"SY" => "Syria",
|
250
|
+
"SZ" => "Swaziland",
|
251
|
+
"Sb" => "SolomonIslands",
|
252
|
+
"TC" => "Turks_and_Caicos_Islands",
|
253
|
+
"TD" => "Chad",
|
254
|
+
"TF" => "French_Southern_Territories",
|
255
|
+
"TG" => "Togo",
|
256
|
+
"TH" => "Thailand",
|
257
|
+
"TJ" => "Tajikistan",
|
258
|
+
"TK" => "Tokelau",
|
259
|
+
"TM" => "Turkmenistan",
|
260
|
+
"TN" => "Tunisia",
|
261
|
+
"TO" => "Tonga",
|
262
|
+
"TP" => "East_Timor",
|
263
|
+
"TR" => "Turkey",
|
264
|
+
"TT" => "Trinidad_and_Tobago",
|
265
|
+
"TV" => "Tuvalu",
|
266
|
+
"TW" => "Taiwan",
|
267
|
+
"TZ" => "Tanzania",
|
268
|
+
"UA" => "Ukraine",
|
269
|
+
"UG" => "Uganda",
|
270
|
+
"UK" => "United_Kingdom",
|
271
|
+
"UM" => "USMinor_Outlying_Islands",
|
272
|
+
"US" => "United_States (USA)",
|
273
|
+
"UY" => "Uruguay",
|
274
|
+
"UZ" => "Uzbekistan",
|
275
|
+
"VA" => "Vatican City State",
|
276
|
+
"VC" => "Saint Vincent and the Grenadines",
|
277
|
+
"VE" => "Venezuela",
|
278
|
+
"VG" => "Virgin_Islands(British)",
|
279
|
+
"VI" => "Virgin_Islands(U.S.)",
|
280
|
+
"VN" => "Vietnam",
|
281
|
+
"VU" => "Vanuatu",
|
282
|
+
"WF" => "Wallis_and_FutunaIslands",
|
283
|
+
"WS" => "Samoa",
|
284
|
+
"YE" => "Yemen",
|
285
|
+
"YT" => "Mayotte",
|
286
|
+
"YU" => "Yugoslavia",
|
287
|
+
"ZA" => "South_Africa",
|
288
|
+
"ZM" => "Zambia",
|
289
|
+
"ZR" => "Zaire",
|
290
|
+
"ZW" => "Zimbabwe",
|
291
|
+
}
|
292
|
+
|
293
|
+
lines.each do |line|
|
294
|
+
kwords = line.split(' ')
|
295
|
+
time = kwords[1].split(',')
|
296
|
+
ip = kwords[6] # the IP string
|
297
|
+
c = GeoIP.new($GeoIP).country(ip) # <= resolv country by IP using the GeoIP database
|
298
|
+
country = cdc[c.country_code2] # <= retrieve country from cdc hash table
|
299
|
+
@data_table << "#{kwords[0]} #{time[0]} #{kwords[4]} #{ip} #{c.country_code2} #{country}"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# print all data considered 'important' here
|
304
|
+
def info
|
305
|
+
entries = @data_table.size
|
306
|
+
f2blog = File.expand_path(@log)
|
307
|
+
fdate = "#{@data_table[0].split(' ')[0]} #{@data_table[0].split(' ')[1]}" #Firt entry date
|
308
|
+
ldate = "#{@data_table[entries-1].split(' ')[0]} #{@data_table[entries-1].split(' ')[1]} " #Last entry date
|
309
|
+
tdiff = Time.diff(fdate, ldate) #time diference
|
310
|
+
ucl = [] # unique country list
|
311
|
+
upl = [] # unique protocol list
|
312
|
+
@data_table.each { |line| c = line.split(' ')[5]; ucl << c if ucl.include?(c) == false} # create the ucl list
|
313
|
+
@data_table.each { |line| c = line.split(' ')[2]; upl << c if upl.include?(c) == false} # create the ucl list
|
314
|
+
upl.size > 1 ? upl_print = upl.size.join(', ') : upl_print = upl[0]
|
315
|
+
ban_avg = entries.to_f/((tdiff[:year] * 365) + (tdiff[:month] * 30) + (tdiff[:week] * 7) + tdiff[:day]).to_f
|
316
|
+
sbanner = "Log file: '#{f2blog}'"
|
317
|
+
puts "=" * sbanner.length
|
318
|
+
puts sbanner
|
319
|
+
puts ""
|
320
|
+
printf("First entry: %s\n", fdate)
|
321
|
+
printf("Last entry: %s\n", ldate)
|
322
|
+
printf("Time frame:\t%s\n", tdiff[:diff])
|
323
|
+
printf("Banned IPs:\t%i\n", entries)
|
324
|
+
printf("Countries:\t%i\n", ucl.size)
|
325
|
+
printf("Protocol(s):\t%s\n", upl_print)
|
326
|
+
printf("Bans per day:\t%0.2f\n\n", ban_avg)
|
327
|
+
puts "Most banned IP(s) by fail2ban: "
|
328
|
+
puts "-------------------------"
|
329
|
+
puts "IP address - Attacks"
|
330
|
+
puts "-------------------------"
|
331
|
+
top_ips
|
332
|
+
puts ""
|
333
|
+
puts "Most hostile Countries:"
|
334
|
+
puts "--------------------------"
|
335
|
+
sort_by_country(5)
|
336
|
+
end
|
337
|
+
|
338
|
+
|
339
|
+
def top_ips
|
340
|
+
count = Hash.new(0)
|
341
|
+
for entry in @data_table
|
342
|
+
count[entry.split(' ')[3]] += 1
|
343
|
+
end
|
344
|
+
sorted = count.sort_by {|data, no| no }.reverse
|
345
|
+
$top_list = []
|
346
|
+
best_count = sorted[0][1]
|
347
|
+
ready = sorted.select { |data,no| no == best_count }
|
348
|
+
ready.each {|line| printf("%s\t\t%s\n", line[0], line[1])}
|
349
|
+
end
|
350
|
+
|
351
|
+
# sort banned hosts by country
|
352
|
+
def sort_by_country(a)
|
353
|
+
count = Hash.new(0)
|
354
|
+
elog = []
|
355
|
+
@data_table.each do |x|
|
356
|
+
elog << "#{x.split(' ')[3]} #{x.split(' ')[5]}"
|
357
|
+
end
|
358
|
+
for entry in elog
|
359
|
+
count[entry.split(' ')[1]] += 1
|
360
|
+
end
|
361
|
+
sorted = count.sort_by { |country, no| no }.reverse
|
362
|
+
x = a.to_i
|
363
|
+
if x.to_i > 0
|
364
|
+
sorted.take(x).each {|line| puts "Country: #{line[0]} - IP(s): #{line[1]}"}
|
365
|
+
else
|
366
|
+
sorted.each {|line| puts "Country: #{line[0]} - IP(s): #{line[1]}"}
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# sort banned hosts by IP (if more than one!)
|
371
|
+
def sort_by_ip(a)
|
372
|
+
count = Hash.new(0)
|
373
|
+
for entry in @data_table
|
374
|
+
count[entry.split(' ')[3]] += 1
|
375
|
+
end
|
376
|
+
sorted = count.sort_by {|data, no| no }.reverse
|
377
|
+
a.to_i > 0 ? sorted.take(a).each{|line| puts "Received #{line[1]} attacks from #{line[0]}"} : sorted.each{|line| puts "Received #{line[1]} attacks from #{line[0]}"}
|
378
|
+
end
|
379
|
+
|
380
|
+
# sort by date
|
381
|
+
def sort_by_date(a)
|
382
|
+
if a.to_i > 0
|
383
|
+
@data_table.take(a).each {|line| puts line}
|
384
|
+
else
|
385
|
+
@data_table.each {|line| puts line}
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: f2bread
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Panagiotis Atmatzidis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: geoip
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: time_diff
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
41
|
+
description: A simple gem that reads 'fail2ban.log' and displays statistics
|
42
|
+
email: atma@convalesco.org
|
43
|
+
executables:
|
44
|
+
- f2bread
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- bin/f2bread
|
49
|
+
- License.txt
|
50
|
+
- lib/f2bread.rb
|
51
|
+
- lib/GeoIP.dat
|
52
|
+
homepage: https://github.com/atmosx/f2bread
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.0.3
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Fail2ban statistics
|
76
|
+
test_files: []
|