-
Notifications
You must be signed in to change notification settings - Fork 10
/
LongTail-sdn.sh
executable file
·5013 lines (4408 loc) · 255 KB
/
LongTail-sdn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
############################################################################
#
# Design note: I am PERFECTLY willing to trade using more disk space in
# order to speed things up.
#
# This is my crontab entry
# 05 * * * * /usr/local/etc/LongTail.sh >> /tmp/LongTail.sh.out 2>> /tmp/LongTail.sh.out
#
# You need to have /usr/local/etc/whois.pl installed also. Sure, I could
# have a faster mysql backend, but I don't NEED it.
#
# I am assuming your /var/log/messages file is really called messages, or
# messages<something>. .gz files are ok too.
#
# you can also call this program with a hostname (from the messages files)
# so that you can analyze different hosts separately, each in
# /honey/<HOSTNAME>/ directories.
#
# Examples:
# gets all hosts and looks for all ssh activity
# /usr/local/etc/LongTail.sh
#
# gets all hosts and looks for all ssh activity
# /usr/local/etc/LongTail.sh -protocol ssh
#
# gets all hosts and looks for all ssh only on port 22 activity
# /usr/local/etc/LongTail.sh -protocol 22
#
# gets all hosts and looks for all ssh only on port 2222 activity
# /usr/local/etc/LongTail.sh -protocol 2222
#
# gets all hosts and looks for telnet activity
# /usr/local/etc/LongTail.sh -protocol telnet
#
# If you are looking for a specific host, you MUST include the protocol
# to search for
# gets all hosts and looks for all ssh activity
# /usr/local/etc/LongTail.sh -protocol ssh -host HOSTNAME
#
# gets all hosts and looks for all ssh only on port 22 activity
# /usr/local/etc/LongTail.sh -protocol 22 -host HOSTNAME
#
# gets all hosts and looks for all ssh only on port 2222 activity
# /usr/local/etc/LongTail.sh -protocol 2222 -host HOSTNAME
#
# gets all hosts and looks for telnet activity
# /usr/local/etc/LongTail.sh -protocol telnet -host HOSTNAME
#
#
# LongTail.sh has been tested and appears to work properly, however
# there may still be some bugs I haven't found yet.
#
############################################################################
# This reads /usr/local/etc/LongTail.config. If the file isn't there,
# then you need to edit in the next subroutine, else edit that file.
function read_local_config_file {
if [ -e "/usr/local/etc/LongTail.config" ] ; then
. /usr/local/etc/LongTail.config
fi
}
############################################################################
# Assorted Variables, you should probably edit /usr/local/etc/LongTail.config
# though... Otherwise when you install a new version you'll lose your
# configuration
#
function init_variables {
# Is this a public webserver? If so then we need to protect
# certain webpages so they are not seen by the badguys. We
# have to do this in order to hide what the current "Hot" or
# "Desirable" account and password combinations are
#
# Do not assume that just because your page isn't indexed
# by Google that your webpage is private.
#
# Set it to 1 if it is public, or 0 if it is private.
PUBLIC_WEBSERVER=0 # 0 does not lock down files so all can be seen in a webbrowser
# Do you want Pretty graphs using jpgraph? Set this to 1
# http://jpgraph.net/ JpGraph - Most powerful PHP-driven charts
GRAPHS=1
# Which honeypot are you running? Uncomment only ONE of the following
#KIPPO=1 ; LONGTAIL=0 # This is for the Kippo honeypot
KIPPO=0 ; LONGTAIL=1 # This is for the LongTail honeypot
#Where is the messages file? Uncomment only ONE of the following
PATH_TO_VAR_LOG="/var/log/" # Typically for messages file from ryslog
#PATH_TO_VAR_LOG="/usr/local/kippo-master/log/" # One place for kippo
#PATH_TO_VAR_LOG="/var/log/kippo/" # another place for kippo
# What is the name of the default log file
LOGFILE="messages"
#LOGFILE="kippo.log"
#Where is the apache access_log file?
PATH_TO_VAR_LOG_HTTPD="/var/log/httpd/"
# Do you want debug output? Set this to 1
DEBUG=0
# Do you want ssh analysis? Set this to 1
DO_SSH=1
# Do you want httpd analysis? Set this to 1
DO_HTTPD=1
# Do we obfuscate/rename the IP addresses? You might want to do this if
# you are copying your reports to a public site.
# OBFUSCATE_IP_ADDRESSES=1 will hide addresses
# OBFUSCATE_IP_ADDRESSES=0 will NOT hide addresses
OBFUSCATE_IP_ADDRESSES=0
# OBFUSCATE_URLS=1 will hide URLs in the http report
# OBFUSCATE_URLS=0 will NOT hide URLs in the http report
# This may not work properly yet.
OBFUSCATE_URLS=0
# These are the search strings from the "LogIt" function in auth-passwd.c
# and are used to figure out which ports are being brute-forced.
# The code for PASSLOG2222 has not yet been written.
PASSLOG="PassLog"
PASSLOG2222="Pass2222Log"
# Where do we put the temporary files
TMP_DIRECTORY="/data/tmp"
# Where are the scripts we need to run?
SCRIPT_DIR="/usr/local/etc/"
# Where do we put the reports?
HTML_DIR="/var/www/html"
# What's the top level directory?
SSH_HTML_TOP_DIR="honey" #NO slashes please, it breaks sed
SSH22_HTML_TOP_DIR="honey-22" #NO slashes please, it breaks sed
SSH2222_HTML_TOP_DIR="honey-2222" #NO slashes please, it breaks sed
TELNET_HTML_TOP_DIR="telnet" #NO slashes please, it breaks sed
RLOGIN_HTML_TOP_DIR="rlogin" #NO slashes please, it breaks sed
FTP_HTML_TOP_DIR="ftp" #NO slashes please, it breaks sed
HTTP_HTML_TOP_DIR="http" #NO slashes please, it breaks sed
SDN_HTML_TOP_DIR="sdn" #NO slashes please, it breaks sed
SSH22_KEYS_HTML_TOP_DIR="ssh-keys"
# This is for my personal debugging, just leave them
# commented out if you aren't me.
#PATH_TO_VAR_LOG="/home/wedaa/source/LongTail/var/log/"
#PATH_TO_VAR_LOG_HTTPD="/home/wedaa/source/LongTail/var/log/httpd/"
# Is this a consolidation server? (A server that
# processes many servers results AND makes individual
# reports for each server).
CONSOLIDATION=0
# What hosts are protected by a firewall or Intrusion Detection System?
# This is used to set the current-attack-count.data.notfullday flag
# in those directories to help "normalize" the data
if [ `hostname` == "longtail.it.marist.edu" ] ; then
HOSTS_PROTECTED="erhp erhp2"
BLACKRIDGE="blackridge"
RESIDENTIAL_SITES="shepherd"
EDUCATIONAL_SITES="syrtest edub edu_c"
CLOUD_SITES="AWS cloud_v cloud_c"
BUSINESS_SITES=""
else
HOSTS_PROTECTED=""
BLACKRIDGE=""
RESIDENTIAL_SITES=""
EDUCATIONAL_SITES=""
CLOUD_SITES=""
BUSINESS_SITES=""
fi
# Do we protect the raw data, and for how long?
# PROTECT_RAW_DATA=1 will protect raw data
# PROTECT_RAW_DATA=0 will NOT protect raw data
PROTECT_RAW_DATA=1
NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA=90;
############################################################################
# You don't need to edit after this.
#
TODAY_AT_START_OF_RUNTIME=`date`
YEAR=`date +%Y`
HOUR=`date +%H` # This is used at the end of the program but we want to know it NOW
START_HOUR=`date +%H` # This is used at the end of the program but we want to know it NOW
YEAR_AT_START_OF_RUNTIME=`date +%Y`
MONTH_AT_START_OF_RUNTIME=`date +%m`
DAY_AT_START_OF_RUNTIME=`date +%d`
REBUILD=0
MIDNIGHT=0
ONE_AM=1
}
# This function is called as
# NEW_STRING=$(convert_kippo_to_longtail "$STRING")
# STRING should look like
# 2015-05-10 18:05:31-0400 [SSHService ssh-userauth on HoneyPotTransport,16534,58.218.204.52] login attempt [root/skata1] failed
function convert_kippo_to_longtail {
STRING=`echo $STRING |sed -e 's/ /T/' \
-e 's/.SSHService ssh-userauth on HoneyPotTransport,.*,//' \
-e 's/\]/ /' \
-e 's/\] failed$//' \
-e 's/\[//' \
-e 's/ / LOCALHOST sshd-22[9999]: IP: /' \
-e 's/login attempt/PassLog: Username:/' \
-e 's/\// Password: /'`
echo $STRING
}
function lock_down_files {
if [ $PUBLIC_WEBSERVER == 1 ] ; then # 1 is means public webserver
if [ "x$HOSTNAME" == "x/" ] ;then
if [ -d $HTML_DIR ] ; then
cd $HTML_DIR
echo "Expect to see chmod warnings until you have run LongTail for at least 24 hours"
files=` find . -name last-7-days-root-passwords.shtml.gz -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name last-7-days-non-root-pairs.shtml -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name last-30-days-root-passwords.shtml.gz -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name last-30-days-non-root-pairs.shtml -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name historical-root-passwords.shtml.gz -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name historical-non-root-pairs.shtml -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA `
if [ "X" = "X$files" ] ; then
echo "Not enough files to protect yet"
else
chmod go-r $files
fi
files=`find . -name todays_password -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name current-root-passwords.shtml.gz -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name current-non-root-passwords.shtml -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name current-account-password-pairs.data.gz -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA \
-o -name current-admin-passwords.shtml -mtime -$NUMBER_OF_DAYS_TO_PROTECT_RAW_DATA `
if [ "X" = "X$files" ] ; then
echo "Not enough files to protect yet"
else
chmod go-r $files
fi
chmod ugo-r /var/www/html/honey/historical_ssh_probes_sorted.shtml
fi
fi
fi
}
############################################################################
#
# Make sure paths really exist
function check_config {
if [ ! -d $PATH_TO_VAR_LOG ] ; then
echo "$PATH_TO_VAR_LOG does not exist, exiting now"
exit
fi
if [ ! -e $PATH_TO_VAR_LOG/$LOGFILE ] ; then
echo "$PATH_TO_VAR_LOG/$LOGFILE does not exist, exiting now"
exit
fi
if [ ! -d $PATH_TO_VAR_LOG_HTTPD ] ; then
echo "$PATH_TO_VAR_LOG_HTTPD does not exist, exiting now"
exit
fi
if [ ! -d $SCRIPT_DIR ] ; then
echo "Can not find SCRIPT_DIR: $SCRIPT_DIR, exiting now"
exit
fi
if [ ! -d $HTML_DIR ] ; then
echo "Can not find HTML_DIR: $HTML_DIR, exiting now"
exit
fi
if [ ! -d $TMP_DIRECTORY ] ; then
echo "Can not find TMP_DIRECTORY: $TMP_DIRECTORY, exiting now"
exit
fi
if [ ! -r "$PATH_TO_VAR_LOG/$LOGFILE" ] ; then
echo "Can not read $PATH_TO_VAR_LOG/$LOGFILE, please check file permissions"
echo "Exiting now"
exit
fi
rsyslog_format_check=`tail -1 $PATH_TO_VAR_LOG/$LOGFILE |awk '{print $1}'`
rsyslog_format_check_exit=0
if [ $rsyslog_format_check = "Jan" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Feb" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Mar" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Apr" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "May" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Jun" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Jul" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Aug" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Sep" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Oct" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Nov" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check = "Dec" ] ; then rsyslog_format_check_exit=1 ; fi
if [ $rsyslog_format_check_exit -eq 1 ] ; then
echo "$PATH_TO_VAR_LOG/$LOGFILE file appears to have the wrong style data stamp (monthName vs YYYY-MM-DD format) Please see the README again."
echo "rsyslog format line should be \"\$ActionFileDefaultTemplate RSYSLOG_FileFormat\""
echo "You will have to edit $PATH_TO_VAR_LOG/$LOGFILE by hand to fix the formating or start with a fresh $PATH_TO_VAR_LOG/$LOGFILE file"
exit
fi
}
############################################################################
# Lets make sure we can write to the directory
#
function is_directory_good {
if [ ! -d $1 ] ; then
echo "$1 is not a directory, exiting now "
exit
fi
if [ ! -w $1 ] ; then
echo "I can't write to $1", exiting now
exit
fi
}
############################################################################
# Lets make sure we can write to the directory
#
function is_file_good {
if [ ! -e $1 ] ; then
echo "DANGER DANGER DANGER"
echo "$1 does not exist, exiting now "
exit
fi
if [ ! -w $1 ] ; then
echo "DANGER DANGER DANGER"
echo "I can't write to $1", exiting now
exit
fi
}
############################################################################
# Change the date in index.shtml
#
function change_date_in_index {
local DATE=`date`
is_file_good $1/index.shtml
is_file_good $1/index-long.shtml
is_file_good $1/graphics.shtml
sed -i "s/updated on..*$/updated on $DATE/" $1/index.shtml
sed -i "s/updated on..*$/updated on $DATE/" $1/index-map.shtml
sed -i "s/updated on..*$/updated on $DATE/" $1/index-long.shtml
sed -i "s/updated on..*$/updated on $DATE/" $1/index-long-map.shtml
sed -i "s/updated on..*$/updated on $DATE/" $1/graphics.shtml
}
############################################################################
# Make a proper HTML header for assorted columns
#
function make_header {
# first argument, the full path including the filename you want to write to
# second argument, the title of the web page
# Third argument, text for description
# Other arguments are the column headers
# NOTE: This destroys $MAKE_HEADER_FILENAME before adding to it.
MAKE_HEADER_DATE=`date`
if [ "$#" == "0" ]; then
echo "You forgot to pass arguments, exiting now"
exit 1
fi
MAKE_HEADER_FILENAME=$1
#echo "filename is $MAKE_HEADER_FILENAME"
touch $MAKE_HEADER_FILENAME
if [ ! -w $MAKE_HEADER_FILENAME ] ; then
echo "Can not write to $MAKE_HEADER_FILENAME, exiting now"
exit
fi
shift
TITLE=$1
shift
DESCRIPTION=$1
shift
echo "<HTML><!--HEADERLINE -->" > $MAKE_HEADER_FILENAME
echo "<HEAD><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<META http-equiv=\"pragma\" content=\"no-cache\"><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<TITLE>LongTail Log Analysis $TITLE</TITLE> <!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<style> /* HEADERLINE */ " >> $MAKE_HEADER_FILENAME
echo ".td-some-name /* HEADERLINE */ " >> $MAKE_HEADER_FILENAME
echo "{ /* HEADERLINE */ " >> $MAKE_HEADER_FILENAME
echo " white-space:nowrap; /* HEADERLINE */ " >> $MAKE_HEADER_FILENAME
echo " vertical-align:top; /* HEADERLINE */ " >> $MAKE_HEADER_FILENAME
echo "} /* HEADERLINE */ " >> $MAKE_HEADER_FILENAME
echo "</style> <!--HEADERLINE --> " >> $MAKE_HEADER_FILENAME
echo "</HEAD><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<BODY BGCOLOR=#00f0FF><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<!--#include virtual="/$HTML_TOP_DIR/header.html" --> <!--HEADERLINE --> " >> $MAKE_HEADER_FILENAME
echo "<H1>LongTail Log Analysis</H1><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<H3>$TITLE</H3><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<P>$DESCRIPTION <!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
# echo "<P><font color="red">SPACECHAR</font> Indicates a space in the incoming data <!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<P>Created on $MAKE_HEADER_DATE<!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
if [ $OBFUSCATE_IP_ADDRESSES -gt 0 ] ; then
echo "<P>IP Addresses have been obfuscated to hide the guilty. <!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "ALL IP addresses have been reset to end in .127. <!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
fi
echo "<TABLE border=1><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
echo "<TR><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
while (( "$#" )); do
echo "<TH>$1</TH><!--HEADERLINE -->" >>$MAKE_HEADER_FILENAME
shift
done
echo "</TR><!--HEADERLINE -->" >> $MAKE_HEADER_FILENAME
}
############################################################################
# Make a proper HTML footer for assorted columns
#
function make_footer {
# One argument, the full path including the filename you want to write to
if [ "$#" == "0" ]; then
echo "You forgot to pass arguments, exiting now"
exit 1
fi
MAKE_FOOTER_FILENAME=$1
#echo "filename is $MAKE_FOOTER_FILENAME"
touch $MAKE_FOOTER_FILENAME
if [ ! -w $MAKE_FOOTER_FILENAME ] ; then
echo "Can not write to $MAKE_FOOTER_FILENAME, exiting now"
exit
fi
echo "" >> $MAKE_FOOTER_FILENAME
echo "</TABLE><!--HEADERLINE -->" >> $MAKE_FOOTER_FILENAME
echo "<!--#include virtual="/$HTML_TOP_DIR/footer.html" --> <!--HEADERLINE --> " >> $MAKE_FOOTER_FILENAME
echo "</BODY><!--HEADERLINE -->" >> $MAKE_FOOTER_FILENAME
echo "</HTML><!--HEADERLINE -->" >> $MAKE_FOOTER_FILENAME
if [ $OBFUSCATE_IP_ADDRESSES -gt 0 ] ; then
hide_ip $1
fi
}
############################################################################
# Obfuscate any IP addresses found by setting the last octet to 128
# I am assuming that any address in a class C address is controlled
# or owned by whoever owns the Class C
#
# This way the report does not name any single user, but blames the
# owner of the Class C range.
#
function hide_ip {
# One argument, the full path including the filename you want to write to
if [ "$#" == "0" ]; then
echo "You forgot to pass arguments, exiting now"
exit 1
fi
sed -i -r 's/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)[0-9]{1,3}/\1127/g' $1
}
############################################################################
# Count ssh attacks and modify $HTML_DIR/index.html
#
# Called as count_ssh_attacks $HTML_DIR $PATH_TO_VAR_LOG "messages*"
#
function count_http_attacks {
if [ $DEBUG == 1 ] ; then echo "DEBUG-in count_http_attacks now" ; fi
TMP_HTML_DIR=$1
PATH_TO_VAR_LOG=$2
MESSAGES=$3
ORIGINAL_DIRECTORY=`pwd`
TMP_DATE=`date +"%Y-%m-%d"`
TMP_YEAR=`date +%Y`
TMP_MONTH=`date +%m`
TMP_DAY=`date +%d`
#
# Lets make sure we have one for today and this month and this year
TMP_DIR="$TMP_HTML"
if [ ! -d $TMP_DIR ] ; then mkdir $TMP_DIR ; chmod a+rx $TMP_DIR; fi
TMP_DIR="$TMP_HTML_DIR/historical"
if [ ! -d $TMP_DIR ] ; then mkdir $TMP_DIR ; chmod a+rx $TMP_DIR; fi
TMP_DIR="$TMP_HTML_DIR/historical/$TMP_YEAR"
if [ ! -d $TMP_DIR ] ; then mkdir $TMP_DIR ; chmod a+rx $TMP_DIR; fi
TMP_DIR="$TMP_HTML_DIR/historical/$TMP_YEAR/$TMP_MONTH"
if [ ! -d $TMP_DIR ] ; then mkdir $TMP_DIR ; chmod a+rx $TMP_DIR; fi
TMP_DIR="$TMP_HTML_DIR/historical/$TMP_YEAR/$TMP_MONTH/$TMP_DAY"
if [ ! -d $TMP_DIR ] ; then mkdir $TMP_DIR ; chmod a+rx $TMP_DIR; fi
for dir in $HOSTS_PROTECTED $BLACKRIDGE ; do
if [ "x$HOSTNAME" == "x$dir" ] ; then
touch $TMP_HTML_DIR/historical/$TMP_YEAR/$TMP_MONTH/$TMP_DAY/current-attack-count.data.notfullday
echo $TMP_HTML_DIR/historical/$TMP_YEAR/$TMP_MONTH/$TMP_DAY/
fi
done
#
# Why did I add this line?
# This makes sure the current day exists and is set to no data ?
# But why am I creating this file later?
# So I commented out the if statement so I ALWAYS clear the current data.
#if [ ! -e $TMP_HTML_DIR/historical/$TMP_YEAR/$TMP_MONTH/$TMP_DAY/current-raw-data.gz ] ; then
echo "" |gzip -c > $TMP_HTML_DIR/historical/$TMP_YEAR/$TMP_MONTH/$TMP_DAY/current-raw-data.gz
chmod a+r $TMP_HTML_DIR/historical/$TMP_YEAR/$TMP_MONTH/$TMP_DAY/current-raw-data.gz
#fi
####################################################################################
#
# 404 Webpages requested
#
# TODAY
#
FILE_TO_SEARCH_FOR="todays_uniq_404_webpages.count"
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_404 requests/TODAY now " ; date; fi
cd $PATH_TO_VAR_LOG
if [ "x$HOSTNAME" == "x/" ] ;then
#echo "$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep $TMP_DATE "
TODAY_404=`$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep ' 404 '|grep -iv xymon |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep |uniq | wc -l`
#$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep ' 404 '|grep -iv xymon |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep |uniq
else
#echo "foo-3"
TODAY_404=`$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep ' 404 ' |grep -iv xymon|awk '$2 == "'$HOSTNAME'" {print}' |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep | grep -F -vf $SCRIPT_DIR/LongTail-exclude-accounts.grep |uniq |wc -l`
fi
echo $TODAY_404 > $TMP_HTML_DIR/$FILE_TO_SEARCH_FOR
#echo "TODAY'S 404 uniq count is is $TODAY_404"
#
# THIS MONTH
#
cd $TMP_HTML_DIR/historical/
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_404 requests/This Month now " ;date; fi
TMP=0
for FILE in `find $TMP_YEAR/$TMP_MONTH -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
#echo "DEBUG file $FILE found"
#ls -l $FILE
(( TMP += $COUNT ))
done
THIS_MONTH_404=`expr $TMP + $TODAY_404`
#echo ""
#echo ""
#echo "this month is $TMP , today is $TODAY_404 "
#echo ""
#echo ""
#
# So there's a problem if it's the first day of the month and there's
# No real statistics yet.
#
# This fails on the first of the month
#
#
# LAST MONTH
#
cd $TMP_HTML_DIR/historical/
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in 404 requests/Last Month now " ; date ; fi
#
# Gotta fix this for the year boundary
#
TMP_LAST_MONTH=`date "+%m" --date="last month"`
TMP_LAST_MONTH_YEAR=`date "+%Y" --date="last month"`
TMP=0
for FILE in `find $TMP_LAST_MONTH_YEAR/$TMP_LAST_MONTH -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
LAST_MONTH_404=$TMP
# OK, this may not be 100% secure, but it's close enough for now
#
# THIS YEAR
#
# This was tested and works with 365 files :-)
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_404 requests/This Year now " ; date; fi
TMP=0
for FILE in `find $TMP_YEAR/ -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
THIS_YEAR_404=`expr $TMP + $TODAY_404`
#
# EVERYTHING
#
# I have no idea where this breaks, but it's a big-ass number of files
TMP=0
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_404 requests/everything " ; date;fi
for FILE in `find . -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
TOTAL_404=`expr $TMP + $TODAY_404`
# OK, this may not be 100% secure, but it's close enough for now
if [ $DEBUG == 1 ] ; then echo -n "DEBUG ALL statistics " ; date; fi
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
sed -i "s/Unique 404 Requests Today:.*$/Unique 404 Requests Today:--> $TODAY_404/" $1/index.shtml
sed -i "s/Unique 404 Requests Today:.*$/Unique 404 Requests Today:--> $TODAY_404/" $1/index-long.shtml
sed -i "s/Unique 404 Requests This Month:.*$/Unique 404 Requests This Month:--> $THIS_MONTH_404/" $1/index.shtml
sed -i "s/Unique 404 Requests This Month:.*$/Unique 404 Requests This Month:--> $THIS_MONTH_404/" $1/index-long.shtml
sed -i "s/Unique 404 Requests This Year:.*$/Unique 404 Requests This Year:--> $THIS_YEAR_404/" $1/index.shtml
sed -i "s/Unique 404 Requests This Year:.*$/Unique 404 Requests This Year:--> $THIS_YEAR_404/" $1/index-long.shtml
sed -i "s/Unique 404 Requests Since Logging Started:.*$/Unique 404 Requests Since Logging Started:--> $TOTAL_404/" $1/index.shtml
sed -i "s/Unique 404 Requests Since Logging Started:.*$/Unique 404 Requests Since Logging Started:--> $TOTAL_404/" $1/index-long.shtml
####################################################################################
#
# shellshock Webpages requested
#
# TODAY
#
FILE_TO_SEARCH_FOR="todays_uniq_shellshock_webpages.count"
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_shellshock requests/TODAY now " ; date; fi
cd $PATH_TO_VAR_LOG
if [ "x$HOSTNAME" == "x/" ] ;then
#echo "$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep $TMP_DATE "
TODAY_shellshock=`$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep '\:\;'|grep -iv xymon |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep |uniq | wc -l`
#$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep '\:\;'|grep -iv xymon |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep |uniq
else
#echo "foo-3"
TODAY_shellshock=`$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep '\:\;' |grep -iv xymon|awk '$2 == "'$HOSTNAME'" {print}' |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep | grep -F -vf $SCRIPT_DIR/LongTail-exclude-accounts.grep |uniq |wc -l`
fi
echo $TODAY_shellshock > $TMP_HTML_DIR/$FILE_TO_SEARCH_FOR
#echo "TODAY'S shellshock uniq count is is $TODAY_shellshock"
#
# THIS MONTH
#
cd $TMP_HTML_DIR/historical/
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_shellshock requests/This Month now " ;date; fi
TMP=0
for FILE in `find $TMP_YEAR/$TMP_MONTH -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
#echo "DEBUG file $FILE found"
#ls -l $FILE
(( TMP += $COUNT ))
done
THIS_MONTH_shellshock=`expr $TMP + $TODAY_shellshock`
#echo ""
#echo ""
#echo "this month is $TMP , today is $TODAY_shellshock "
#echo ""
#echo ""
#
# So there's a problem if it's the first day of the month and there's
# No real statistics yet.
#
# This fails on the first of the month
#
#
# LAST MONTH
#
cd $TMP_HTML_DIR/historical/
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in shellshock requests/Last Month now " ; date ; fi
#
# Gotta fix this for the year boundary
#
TMP_LAST_MONTH=`date "+%m" --date="last month"`
TMP_LAST_MONTH_YEAR=`date "+%Y" --date="last month"`
TMP=0
for FILE in `find $TMP_LAST_MONTH_YEAR/$TMP_LAST_MONTH -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
LAST_MONTH_shellshock=$TMP
# OK, this may not be 100% secure, but it's close enough for now
#
# THIS YEAR
#
# This was tested and works with 365 files :-)
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_shellshock requests/This Year now " ; date; fi
TMP=0
for FILE in `find $TMP_YEAR/ -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
THIS_YEAR_shellshock=`expr $TMP + $TODAY_shellshock`
#
# EVERYTHING
#
# I have no idea where this breaks, but it's a big-ass number of files
TMP=0
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_shellshock requests/everything " ; date;fi
for FILE in `find . -name $FILE_TO_SEARCH_FOR` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
TOTAL_shellshock=`expr $TMP + $TODAY_shellshock`
# OK, this may not be 100% secure, but it's close enough for now
if [ $DEBUG == 1 ] ; then echo -n "DEBUG ALL statistics " ; date; fi
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
sed -i "s/Unique ShellShock Today:.*$/Unique ShellShock Today:--> $TODAY_shellshock/" $1/index.shtml
sed -i "s/Unique ShellShock Today:.*$/Unique ShellShock Today:--> $TODAY_shellshock/" $1/index-long.shtml
sed -i "s/Unique ShellShock This Month:.*$/Unique ShellShock This Month:--> $THIS_MONTH_shellshock/" $1/index.shtml
sed -i "s/Unique ShellShock This Month:.*$/Unique ShellShock This Month:--> $THIS_MONTH_shellshock/" $1/index-long.shtml
sed -i "s/Unique ShellShock This Year:.*$/Unique ShellShock This Year:--> $THIS_YEAR_shellshock/" $1/index.shtml
sed -i "s/Unique ShellShock This Year:.*$/Unique ShellShock This Year:--> $THIS_YEAR_shellshock/" $1/index-long.shtml
sed -i "s/Unique ShellShock Since Logging Started:.*$/Unique ShellShock Since Logging Started:--> $TOTAL_shellshock/" $1/index.shtml
sed -i "s/Unique ShellShock Since Logging Started:.*$/Unique ShellShock Since Logging Started:--> $TOTAL_shellshock/" $1/index-long.shtml
####################################################################################
#
# Webpages requested
#
# TODAY
#
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_http_attacks/TODAY now " ; date; fi
cd $PATH_TO_VAR_LOG
if [ "x$HOSTNAME" == "x/" ] ;then
#echo "$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep $TMP_DATE "
TODAY=`$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep -iv xymon |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep | wc -l`
else
TODAY=`$SCRIPT_DIR/catall.sh $PATH_TO_VAR_LOG/$MESSAGES |grep $PROTOCOL |grep -iv xymon|awk '$2 == "'$HOSTNAME'" {print}' |grep "$TMP_DATE" | grep -F -vf $SCRIPT_DIR/LongTail-exclude-IPs-ssh.grep | grep -F -vf $SCRIPT_DIR/LongTail-exclude-accounts.grep |wc -l`
fi
echo $TODAY > $TMP_HTML_DIR/current-attack-count.data
#
# THIS MONTH
#
cd $TMP_HTML_DIR/historical/
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_http_attacks/This Month now " ;date; fi
TMP=0
for FILE in `find $TMP_YEAR/$TMP_MONTH -name current-attack-count.data` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
THIS_MONTH=`expr $TMP + $TODAY`
# OK, this may not be 100% secure, but it's close enough for now
if [ $DEBUG == 1 ] ; then echo -n "DEBUG this month statistics " ;date; fi
#
# So there's a problem if it's the first day of the month and there's
# No real statistics yet.
#
# This fails on the first of the month
#
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
if [ -e $TMP_YEAR/$TMP_MONTH ] ; then
if [ $DEBUG == 1 ] ; then echo "DEBUG-in count_http_attacks/This Month/Statistics now " ; fi
#echo ""
#echo "=============================================================================="
#echo ""
#echo "DEBUG MONTH webpages"
#echo "$TMP_YEAR/$TMP_MONTH/*/current-attack-count.data"
#ls -l $TMP_YEAR/$TMP_MONTH/*/current-attack-count.data
cat $TMP_YEAR/$TMP_MONTH/*/current-attack-count.data|perl -e 'use List::Util qw(max min sum); @a=();while(<>){$sqsum+=$_*$_; push(@a,$_)}; $n=@a;$s=sum(@a);$a=$s/@a;$m=max(@a);$mm=min(@a);$std=sqrt($sqsum/$n-($s/$n)*($s/$n));$mid=int @a/2;@srtd=sort { $a <=> $b } @a;if(@a%2){$med=$srtd[$mid];}else{$med=($srtd[$mid-1]+$srtd[$mid])/2;}; $n; print "MONTH_COUNT=$n\nMONTH_SUM=$s\nMONTH_AVERAGE=$a\nMONTH_STD=$std\nMONTH_MEDIAN=$med\nMONTH_MAX=$m\nMONTH_MIN=$mm";' > $TMPFILE
# Now we "source" the script to set environment varaibles we use later
. $TMPFILE
# Now we "clean up" the average and STD deviation
MONTH_AVERAGE=`printf '%.2f' $MONTH_AVERAGE`
MONTH_STD=`printf '%.2f' $MONTH_STD`
else
MONTH_COUNT=1
MONTH_SUM=$TODAY
MONTH_AVERAGE=$TODAY
MONTH_STD=0
MONTH_MEDIAN=$TODAY
MONTH_MAX=$TODAY
MONTH_MIN=$TODAY
#MONTH_AVERAGE=`printf '%.2f' 0`
MONTH_STD=`printf '%.2f' 0`
fi
rm $TMPFILE
MONTH_COUNT=`echo $MONTH_COUNT | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
MONTH_SUM=`echo $MONTH_SUM | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
MONTH_AVERAGE=`echo $MONTH_AVERAGE | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
MONTH_STD=`echo $MONTH_STD | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
MONTH_MEDIAN=`echo $MONTH_MEDIAN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
MONTH_MAX=`echo $MONTH_MAX | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
MONTH_MIN=`echo $MONTH_MIN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
#echo "MONTH_SUM is $MONTH_SUM"
#exit
#
# LAST MONTH
#
cd $TMP_HTML_DIR/historical/
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_http_attacks/Last Month now " ; date ; fi
#
# Gotta fix this for the year boundary
#
TMP_LAST_MONTH=`date "+%m" --date="last month"`
TMP_LAST_MONTH_YEAR=`date "+%Y" --date="last month"`
TMP=0
for FILE in `find $TMP_LAST_MONTH_YEAR/$TMP_LAST_MONTH -name current-attack-count.data` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
LAST_MONTH=$TMP
# OK, this may not be 100% secure, but it's close enough for now
if [ $DEBUG == 1 ] ; then echo -n "DEBUG Last month statistics " ;date ; fi
#
# So there's a problem if it's the first day of the month and there's
# No real statistics yet.
#
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
#
# Gotta do the date calculation to figure out "When" is last month
#
if [ -d $TMP_LAST_MONTH_YEAR/$TMP_LAST_MONTH/ ] ; then
if [ $DEBUG == 1 ] ; then echo "DEBUG-in count_http_attacks/Last Month/statistics now " ; fi
cat $TMP_LAST_MONTH_YEAR/$TMP_LAST_MONTH/*/current-attack-count.data|perl -e 'use List::Util qw(max min sum); @a=();while(<>){$sqsum+=$_*$_; push(@a,$_)}; $n=@a;$s=sum(@a);$a=$s/@a;$m=max(@a);$mm=min(@a);$std=sqrt($sqsum/$n-($s/$n)*($s/$n));$mid=int @a/2;@srtd=sort { $a <=> $b } @a;if(@a%2){$med=$srtd[$mid];}else{$med=($srtd[$mid-1]+$srtd[$mid])/2;};print "LAST_MONTH_COUNT=$n\nLAST_MONTH_SUM=$s\nLAST_MONTH_AVERAGE=$a\nLAST_MONTH_STD=$std\nLAST_MONTH_MEDIAN=$med\nLAST_MONTH_MAX=$m\nLAST_MONTH_MIN=$mm";' > $TMPFILE
# Now we "source" the script to set environment varaibles we use later
. $TMPFILE
# Now we "clean up" the average and STD deviation
LAST_MONTH_AVERAGE=`printf '%.2f' $LAST_MONTH_AVERAGE`
LAST_MONTH_STD=`printf '%.2f' $LAST_MONTH_STD`
else
LAST_MONTH_COUNT="N/A"
LAST_MONTH_SUM="N/A"
LAST_MONTH_AVERAGE="N/A"
LAST_MONTH_STD="N/A"
LAST_MONTH_MEDIAN="N/A"
LAST_MONTH_MAX="N/A"
LAST_MONTH_MIN="N/A"
LAST_MONTH_STD="N/A"
fi
rm $TMPFILE
LAST_MONTH_COUNT=`echo $LAST_MONTH_COUNT | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
LAST_MONTH_SUM=`echo $LAST_MONTH_SUM | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
LAST_MONTH_AVERAGE=`echo $LAST_MONTH_AVERAGE | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
LAST_MONTH_STD=`echo $LAST_MONTH_STD | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
LAST_MONTH_MEDIAN=`echo $LAST_MONTH_MEDIAN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
LAST_MONTH_MAX=`echo $LAST_MONTH_MAX | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
LAST_MONTH_MIN=`echo $LAST_MONTH_MIN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
#echo "DEBUG - EEE"
#
# THIS YEAR
#
# This was tested and works with 365 files :-)
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_http_attacks/This Year now " ; date; fi
TMP=0
for FILE in `find $TMP_YEAR/ -name current-attack-count.data` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
THIS_YEAR=`expr $TMP + $TODAY`
if [ $DEBUG == 1 ] ; then echo -n "DEBUG this year statistics " ; date; fi
# OK, this may not be 100% secure, but it's close enough for now
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
if [ $DEBUG == 1 ] ; then echo "DEBUG-in count_http_attacks/This Year now/statistics" ; fi
for FILE in `find $TMP_YEAR/ -name current-attack-count.data` ; do cat $FILE; done |perl -e 'use List::Util qw(max min sum); @a=();while(<>){$sqsum+=$_*$_; push(@a,$_)}; $n=@a;$s=sum(@a);$a=$s/@a;$m=max(@a);$mm=min(@a);$std=sqrt($sqsum/$n-($s/$n)*($s/$n));$mid=int @a/2;@srtd=sort { $a <=> $b } @a;if(@a%2){$med=$srtd[$mid];}else{$med=($srtd[$mid-1]+$srtd[$mid])/2;};print "YEAR_COUNT=$n\nYEAR_SUM=$s\nYEAR_AVERAGE=$a\nYEAR_STD=$std\nYEAR_MEDIAN=$med\nYEAR_MAX=$m\nYEAR_MIN=$mm";' > $TMPFILE
. $TMPFILE
rm $TMPFILE
YEAR_AVERAGE=`printf '%.2f' $YEAR_AVERAGE`
YEAR_STD=`printf '%.2f' $YEAR_STD`
YEAR_COUNT=`echo $YEAR_COUNT | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
YEAR_SUM=`echo $YEAR_SUM | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
YEAR_AVERAGE=`echo $YEAR_AVERAGE | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
YEAR_STD=`echo $YEAR_STD | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
YEAR_MEDIAN=`echo $YEAR_MEDIAN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
YEAR_MAX=`echo $YEAR_MAX | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
YEAR_MIN=`echo $YEAR_MIN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
#
# EVERYTHING
#
# I have no idea where this breaks, but it's a big-ass number of files
TMP=0
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-in count_http_attacks/everything " ; date;fi
for FILE in `find . -name current-attack-count.data` ; do
COUNT=`cat $FILE`
(( TMP += $COUNT ))
done
TOTAL=`expr $TMP + $TODAY`
# OK, this may not be 100% secure, but it's close enough for now
if [ $DEBUG == 1 ] ; then echo -n "DEBUG ALL statistics " ; date; fi
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
if [ $DEBUG == 1 ] ; then echo "DEBUG-in count_http_attacks/everything/statistics" ; fi
for FILE in `find . -name current-attack-count.data` ; do cat $FILE; done |perl -e 'use List::Util qw(max min sum); @a=();while(<>){$sqsum+=$_*$_; push(@a,$_)}; $n=@a;$s=sum(@a);$a=$s/@a;$m=max(@a);$mm=min(@a);$std=sqrt($sqsum/$n-($s/$n)*($s/$n));$mid=int @a/2;@srtd=sort { $a <=> $b } @a;if(@a%2){$med=$srtd[$mid];}else{$med=($srtd[$mid-1]+$srtd[$mid])/2;};print "EVERYTHING_COUNT=$n\nEVERYTHING_SUM=$s\nEVERYTHING_AVERAGE=$a\nEVERYTHING_STD=$std\nEVERYTHING_MEDIAN=$med\nEVERYTHING_MAX=$m\nEVERYTHING_MIN=$mm";' > $TMPFILE
. $TMPFILE
rm $TMPFILE
EVERYTHING_AVERAGE=`printf '%.2f' $EVERYTHING_AVERAGE`
EVERYTHING_STD=`printf '%.2f' $EVERYTHING_STD`
EVERYTHING_COUNT=`echo $EVERYTHING_COUNT | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
EVERYTHING_SUM=`echo $EVERYTHING_SUM | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
EVERYTHING_AVERAGE=`echo $EVERYTHING_AVERAGE | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
EVERYTHING_STD=`echo $EVERYTHING_STD | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
EVERYTHING_MEDIAN=`echo $EVERYTHING_MEDIAN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
EVERYTHING_MAX=`echo $EVERYTHING_MAX | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
EVERYTHING_MIN=`echo $EVERYTHING_MIN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
#
# Normalized data
#
if [ "x$HOSTNAME" == "x/" ] ;then
# I have no idea where this breaks, but it's a big-ass number of files
cd $HTML_DIR
# OK, this may not be 100% secure, but it's close enough for now
if [ $DEBUG == 1 ] ; then echo -n "DEBUG ALL Normalized statistics " ; date ; fi
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
for FILE in `find */historical -name current-attack-count.data ` ; do if [ ! -e $FILE.notfullday ] ; then cat $FILE ; fi ; done |perl -e 'use List::Util qw(max min sum); @a=();while(<>){$sqsum+=$_*$_; push(@a,$_)}; $n=@a;$s=sum(@a);$a=$s/@a;$m=max(@a);$mm=min(@a);$std=sqrt($sqsum/$n-($s/$n)*($s/$n));$mid=int @a/2;@srtd=sort { $a <=> $b } @a;if(@a%2){$med=$srtd[$mid];}else{$med=($srtd[$mid-1]+$srtd[$mid])/2;};print "NORMALIZED_COUNT=$n\nNORMALIZED_SUM=$s\nNORMALIZED_AVERAGE=$a\nNORMALIZED_STD=$std\nNORMALIZED_MEDIAN=$med\nNORMALIZED_MAX=$m\nNORMALIZED_MIN=$mm";' > $TMPFILE
. $TMPFILE
rm $TMPFILE
NORMALIZED_AVERAGE=`printf '%.2f' $NORMALIZED_AVERAGE`
NORMALIZED_STD=`printf '%.2f' $NORMALIZED_STD`
else
# I have no idea where this breaks, but it's a big-ass number of files
cd $HTML_DIR
# OK, this may not be 100% secure, but it's close enough for now
if [ $DEBUG == 1 ] ; then echo "DEBUG Hostname only ALL statistics" ; fi
TMPFILE=$(mktemp $TMP_DIRECTORY/output.XXXXXXXXXX)
for FILE in `find ./historical -name current-attack-count.data ` ; do if [ ! -e $FILE.notfullday ] ; then cat $FILE ; fi ; done |perl -e 'use List::Util qw(max min sum); @a=();while(<>){$sqsum+=$_*$_; push(@a,$_)}; $n=@a;$s=sum(@a);$a=$s/@a;$m=max(@a);$mm=min(@a);$std=sqrt($sqsum/$n-($s/$n)*($s/$n));$mid=int @a/2;@srtd=sort { $a <=> $b } @a;if(@a%2){$med=$srtd[$mid];}else{$med=($srtd[$mid-1]+$srtd[$mid])/2;};print "NORMALIZED_COUNT=$n\nNORMALIZED_SUM=$s\nNORMALIZED_AVERAGE=$a\nNORMALIZED_STD=$std\nNORMALIZED_MEDIAN=$med\nNORMALIZED_MAX=$m\nNORMALIZED_MIN=$mm";' > $TMPFILE
. $TMPFILE
rm $TMPFILE
NORMALIZED_AVERAGE=`printf '%.2f' $NORMALIZED_AVERAGE`
NORMALIZED_STD=`printf '%.2f' $NORMALIZED_STD`
fi
NORMALIZED_COUNT=`echo $NORMALIZED_COUNT | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
NORMALIZED_SUM=`echo $NORMALIZED_SUM | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
NORMALIZED_AVERAGE=`echo $NORMALIZED_AVERAGE | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
NORMALIZED_STD=`echo $NORMALIZED_STD | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
NORMALIZED_MEDIAN=`echo $NORMALIZED_MEDIAN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
NORMALIZED_MAX=`echo $NORMALIZED_MAX | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
NORMALIZED_MIN=`echo $NORMALIZED_MIN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
sed -i "s/Hack Attempts Today:.*$/Hack Attempts Today:--> $TODAY/" $1/index.shtml
sed -i "s/Hack Attempts Today:.*$/Hack Attempts Today:--> $TODAY/" $1/index-long.shtml
sed -i "s/Hack Attempts This Month:.*$/Hack Attempts This Month:--> $THIS_MONTH/" $1/index.shtml
sed -i "s/Hack Attempts This Month:.*$/Hack Attempts This Month:--> $THIS_MONTH/" $1/index-long.shtml
sed -i "s/Hack Attempts This Year:.*$/Hack Attempts This Year:--> $THIS_YEAR/" $1/index.shtml
sed -i "s/Hack Attempts This Year:.*$/Hack Attempts This Year:--> $THIS_YEAR/" $1/index-long.shtml
sed -i "s/Hack Attempts Since Logging Started:.*$/Hack Attempts Since Logging Started:--> $TOTAL/" $1/index.shtml
sed -i "s/Hack Attempts Since Logging Started:.*$/Hack Attempts Since Logging Started:--> $TOTAL/" $1/index-long.shtml
#
# This really needs to be sped up somehow
#
# Couting honeypots here
if [ $START_HOUR -eq $MIDNIGHT ]; then
if [ "x$HOSTNAME" == "x/" ] ;then
if [ $SEARCH_FOR == "http" ] ; then
if [ $DEBUG == 1 ] ; then echo -n "DEBUG-Getting all http honeypots now "; date ; fi
honey_file="todays-honeypots.txt"
TMP=0
touch /$TMP_DIRECTORY/honeypots.$$
rm /$TMP_DIRECTORY/honeypots.$$
for FILE in `find historical/$TMP_YEAR/$TMP_MONTH -name $honey_file` ; do
awk '{print $2}' $FILE |grep -v ^$ >> /$TMP_DIRECTORY/honeypots.$$
done
THISMONTHUNIQUEHONEYPOTS=`sort -u /$TMP_DIRECTORY/honeypots.$$|grep -v ^$ | wc -l `
rm /$TMP_DIRECTORY/honeypots.$$
TMP=0
touch /$TMP_DIRECTORY/honeypots.$$
rm /$TMP_DIRECTORY/honeypots.$$
for FILE in `find historical/$TMP_YEAR/ -name $honey_file` ; do
awk '{print $2}' $FILE |grep -v ^$ >> /$TMP_DIRECTORY/honeypots.$$
done
THISYEARUNIQUEHONEYPOTS=`sort -u /$TMP_DIRECTORY/honeypots.$$|grep -v ^$ | wc -l `
rm /$TMP_DIRECTORY/honeypots.$$
TMP=0
touch /$TMP_DIRECTORY/honeypots.$$
rm /$TMP_DIRECTORY/honeypots.$$
for FILE in `find historical/ -name $honey_file` ; do
awk '{print $2}' $FILE |grep -v ^$ >> /$TMP_DIRECTORY/honeypots.$$
done
ALLUNIQUEHONEYPOTS=`sort -u /$TMP_DIRECTORY/honeypots.$$|grep -v ^$ | wc -l `
rm /$TMP_DIRECTORY/honeypots.$$
THISMONTHUNIQUEHONEYPOTS=`echo $THISMONTHUNIQUEHONEYPOTS|sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
THISYEARUNIQUEHONEYPOTS=`echo $THISYEARUNIQUEHONEYPOTS|sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
ALLUNIQUEHONEYPOTS=`echo $ALLUNIQUEHONEYPOTS|sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
sed -i "s/Number of Honeypots This Month.*$/Number of Honeypots This Month:--> $THISMONTHUNIQUEHONEYPOTS/" $1/index.shtml
sed -i "s/Number of Honeypots This Year.*$/Number of Honeypots This Year:--> $THISYEARUNIQUEHONEYPOTS/" $1/index.shtml
sed -i "s/Number of Honeypots Since Logging Started.*$/Number of Honeypots Since Logging Started:--> $ALLUNIQUEHONEYPOTS/" $1/index.shtml
sed -i "s/Number of Honeypots This Month.*$/Number of Honeypots This Month:--> $THISMONTHUNIQUEHONEYPOTS/" $1/index-long.shtml
sed -i "s/Number of Honeypots This Year.*$/Number of Honeypots This Year:--> $THISYEARUNIQUEHONEYPOTS/" $1/index-long.shtml
sed -i "s/Number of Honeypots Since Logging Started.*$/Number of Honeypots Since Logging Started:--> $ALLUNIQUEHONEYPOTS/" $1/index-long.shtml