-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit_linux.sh
3255 lines (2944 loc) · 118 KB
/
audit_linux.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
submit_online="n"
discovery_id=""
# create an XML text file of the result in the current directory
create_file="y"
# optional - assign any PCs audited to this Org - take the org_id from Open-AudIT interface
org_id=""
# if set then delete the audit script upon completion
# useful when starting the script on a remote machine and leaving no trace
self_delete="n"
# 0 = no debug
# 1 = basic debug
# 2 = verbose debug
debugging=2
# Version
version="3.4.0"
# Display help
help="n"
# set by the Discovery function - do not normally set this manually
system_id=""
# Should we attempt to audit any connected SAN's
san_audit="y"
# If we detect the san management software, should we run an auto-discover before the query
san_discover="n"
# If our URL uses https, but the certificate is invalid or unrecognised (self signed), we should submit anyway.
ignore_invalid_ssl="y"
PATH="$PATH:/sbin:/usr/sbin"
export PATH
ORIGIFS=$IFS
#NEWLINEIFS=$(echo -n "\n");
NEWLINEIFS=$(echo -en "\n\b");
IFS="$NEWLINEIFS";
# we set this if we detect we're running on a BB shell
busybox="n"
last_seen_by="audit"
display=""
# This should only be set by Discovery when using the debug option
# DO NOT REMOVE THE LINE BELOW
# Configuration from web UI here
########################################################
# DEFINE SCRIPT FUNCTIONS #
########################################################
timer ()
# Returns the elapsed time in seconds.
#
# usage :
#
# start=$(timer)
# # commands...
# total_seconds=$(timer "$start")
#
{
if [ $# -eq 0 ]; then
date +%s
else
local stime=$1
etime=$(date '+%s')
if [ -z "$stime" ]; then stime=$etime; fi
dt=$((etime - stime))
echo "$dt"
fi
}
lcase ()
# Returns the lower case version of the argument.
#
# usage :
#
# lower_version=$(lcase "$var")
#
{
result=$(echo "$1" | awk '{print tolower($0)}')
echo "$result"
}
ucase ()
# Returns the upper case version of the argument.
#
# usage :
#
# upper_version=$(ucase "$var")
#
{
result=$(echo "$1" | awk '{print toupper($0)}')
echo "$result"
}
pcase ()
# Returns the propper case version of the argument.
#
# usage :
#
# proper_version=$(pcase "$var")
#
{
result=$(lcase "$1" | awk '{ for ( i=1; i <= NF; i++) { sub(".", substr(toupper($i),1,1) , $i) } print }')
echo "$result"
}
trim ()
# Remove the leading/trailing spaces from the argument.
#
# usage :
#
# trimmed_version=$(trim "$var")
#
{
result=$(echo "$1" | sed 's/^ *//g' | sed 's/ *$//g')
echo "$result"
}
escape_xml ()
# If a special character exists in the string, escape the XML.
#
# usage :
#
# xml_version=$(escape_xml "$var")
#
{
result="$1"
# Remove line feed / carriage return
result=$(echo "$result" | tr -d -c '\n\r -~')
# Trim leading/trailing spaces
result=$(trim "$result")
# Enclose in tags if required
if echo "$result" | grep -Eq -e '[&<>"]' -e "'"; then
result="<![CDATA[$result]]>"
fi
echo "$result"
}
# Get the last character in a string
#
# usage :
#
# lc=$(last_char "$str")
#
last_char ()
{
lc=""
str="${1}"
slen=${#1}
if [ "${slen}" > "1" ]; then
lcp=$((slen-1))
lc="${str:$lcp}"
fi
echo "${lc}"
}
# Get the all but the last character in a string
#
# usage :
#
# ablc=$(all_but_last_char "$str")
#
all_but_last_char ()
{
ablc=""
str="${1}"
slen=${#1}
lcp=$((slen-1))
ablc="${str:0:$lcp}"
echo "${ablc}"
}
cidr2mask ()
{
# Number of args to shift, 255..255, first non-255 byte, zeroes
set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
[ $1 -gt 1 ] && shift $1 || shift
echo ${1-0}.${2-0}.${3-0}.${4-0}
}
between_output ()
{
# usage :
#
# test=$(between "command" "delimiter" "match" "variable")
#
command="$1"
delimiter="$2"
match="$3"
variable="$4"
# first get all lines between $start and $end (inclusive)
for line in $(eval $command); do
if echo "$line" | grep -q "$delimiter" ; then
if [ -n "$resultgroup" ]; then
# resultgroup contains data, test it
if [ $(echo "$resultgroup" | grep "$match" -c ) -ne 0 ]; then
# our match is contained within the resultgroup
result=$(echo "$resultgroup" | grep "vendor:")
break
fi
resultgroup=""
else
# resultgroup doesn't contain data, start anew
resultgroup="$line"
fi
else
# not a delimiter, so add to the result group
resultgroup=$(echo "$resultgroup\n$line")
fi
done
# check a last time as we may not have a final delimiter
if [ $(echo "$resultgroup" | grep "$match" -c ) -ne 0 ]; then
# our match is contained within the resultgroup
result=$(echo "$resultgroup" | grep "vendor:")
fi
echo "$result"
}
########################################################
# PROCESS COMMAND-LINE PARAMETERS #
########################################################
# Below we take any command line arguements
# to override the variables above, simply include them on the command line like submit_online=n
# NOTE - argurments are case sensitive
for arg in "$@"; do
parameter=$(echo "$arg" | cut -d= -f1)
parameter=$(lcase "$parameter")
parameter=$(trim "$parameter")
parameter_value=$(echo "$arg" | cut -d= -f2)
parameter_value=$(trim "$parameter_value")
case "$parameter" in
"create_file" )
create_file="$parameter_value" ;;
"self_delete" )
self_delete="$parameter_value" ;;
"debugging" )
debugging="$parameter_value" ;;
"discovery_id" )
discovery_id="$parameter_value" ;;
"display" )
display="$parameter_value" ;;
"ignore_invalid_ssl" )
ignore_invalid_ssl="$parameter_value" ;;
"help" )
help="$parameter_value" ;;
"--help" )
help="y" ;;
"-h" )
help="y" ;;
"last_seen_by" )
last_seen_by="$parameter_value" ;;
"org_id" )
org_id="$parameter_value" ;;
"submit_online" )
submit_online="$parameter_value" ;;
"system_id" )
system_id="$parameter_value" ;;
"san_audit" )
san_audit="$parameter_value" ;;
"san_discover" )
san_discover="$parameter_value" ;;
"url" )
url="$parameter_value" ;;
esac
done
if [ "$help" = "y" ]; then
echo ""
echo "-----------------------------"
echo "Open-AudIT Linux audit script"
echo "Version: $version"
echo "-----------------------------"
echo "This script should be run on a Linux based computer using root or sudo access rights."
echo ""
echo ""
echo "Valid command line options are below (items containing * are the defaults) and should take the format name=value (eg: debugging=1)."
echo ""
echo ""
echo " create_file"
echo " y - Create an XML file containing the audit result."
echo " *n - Do not create an XML result file."
echo ""
echo " self_delete"
echo " *n - Do not delete the audit script after running"
echo " y - Delete the audit script after running"
echo ""
echo " display"
echo " * - Do not display debugging output upon submit"
echo " on - Display debugging output upon submit (used by Discovery with debug)"
echo ""
echo " debugging"
echo " 0 - No output."
echo " 1 - Minimal Output."
echo " *2 - Verbose output."
echo ""
echo " discovery_id"
echo " * - The Open-AudIT discovery id. This is populated by Open-AudIT when running this script from discovery."
echo ""
echo " ignore_invalid_ssl"
echo " *y - If our URL uses https, but the certificate is invalid or unrecognised (self signed), we should submit anyway."
echo " n - Do not submit if certificate is invalid (or self signed)."
echo ""
echo " -h or --help or help=y"
echo " y - Display this help output."
echo " *n - Do not display this output."
echo ""
echo " org_id"
echo " - The org_id (an integer) taken from Open-AudIT. If set all devices found will be associated to that Organisation."
echo ""
echo " san_audit"
echo " *y - Should we audit a SAN if it is detected"
echo " n - Do not attempt to audit any attached SANs"
echo ""
echo " san_discover"
echo " *n - Do not run smcli -A if we detect the SAN management software"
echo " Y - Run the command and update the list of any connected SANs"
echo ""
echo " submit_online"
echo " *y - Submit the audit result to the Open-AudIT Server defined by the 'url' variable."
echo " n - Do not submit the audit result"
echo ""
echo " url"
echo " *http://localhost/open-audit/index.php/discovery/process_subnet - The http url of the Open-AudIT Server used to submit the result to."
echo ""
echo ""
echo "The name of the resulting XML file will be in the format HOSTNAME-YYMMDDHHIISS.xml, as in the hostname of the machine the the complete timestamp the audit was started."
exit
fi
########################################################
# CREATE THE AUDIT FILE #
########################################################
start_time=$(timer)
rev_exists=$(which rev 2>/dev/null)
if [ "$debugging" -gt 0 ]; then
echo "Starting audit"
fi
local_hostname=""
if [ -f /etc/hostname ]; then
local_hostname=$(cat /etc/hostname 2>/dev/null)
else
local_hostname=$(hostname -s 2>/dev/null)
fi
if [ -z "$local_hostname" ]; then
local_hostname=$(hostname 2>/dev/null)
fi
# Set the TimeSamp
system_timestamp=$(date +'%F %T')
script_name=$(basename $0)
system_hostname=$(hostname | cut -d. -f1)
xml_file="$system_hostname"-$(date +%Y%m%d%H%M%S).xml
xml_file_full_path=`pwd`"/$xml_file"
if [ "$debugging" -gt 0 ]; then
echo "----------------------------"
echo "Open-AudIT Linux audit script"
echo "Version: $version"
echo "----------------------------"
echo "My PID is $$"
echo "Audit Start Time $system_timestamp"
echo "Create File $create_file"
echo "Submit Online $submit_online"
echo "Debugging Level $debugging"
echo "Discovery ID $discovery_id"
echo "Org Id $org_id"
echo "Script Name $script_name"
echo "URL $url"
echo "File $xml_file_full_path"
echo "----------------------------"
fi
IFS="$ORIGIFS";
if pidof -x -o $$ "$script_name" >/dev/null 2>&1; then
if [ "$debugging" -gt 0 ]; then
echo "Exiting as other audits are currently running."
for pid in $(pidof -x "$script_name"); do
echo $(ps -p "$pid");
done
fi
exit 0
fi
#========================
# SAN INFO #
#========================
if [ "$san_audit" = "y" ]; then
if [ -f "/opt/IBM_DS/client/SMcli" ]; then
san_url=$(echo "$san_url" | sed 's/input\/devices/san\/add_san/g')
if [ "$debugging" -gt 0 ]; then
echo "SAN info"
fi
if [ "$san_discover" = "y" ]; then
if [ "$debugging" -gt 1 ]; then
echo "Running SAN refresh / discover."
fi
output=$(/opt/IBM_DS/client/SMcli -A)
fi
if [ "$debugging" -gt 1 ]; then
echo "Running SAN list"
fi
for san in $(/opt/IBM_DS/client/SMcli -d | grep -v -e '^$' | grep -v 'SMcli' | cut -f2 ); do
$(echo "input=" > /tmp/"$san".txt)
if [ "$debugging" -gt 1 ]; then
echo "Running command: /opt/IBM_DS/client/SMcli \"$san\" -c \"show storagesubsystem profile;\" >> /tmp/\"$san\".txt"
fi
$(/opt/IBM_DS/client/SMcli "$san" -c "show storagesubsystem profile;" >> /tmp/"$san".txt)
if [ "$submit_online" = "y" ]; then
if [ "$debugging" -gt 1 ]; then
echo "Submitting SAN results to server"
echo "URL: $san_url"
if [ "$debugging" -gt 2 ]; then
head /tmp/"$san".txt
fi
fi
if [ -n "$(which curl 2>/dev/null)" ]; then
if [ "$debugging" -gt 1 ]; then
echo "Sending using curl."
fi
curl --data @/tmp/"$san".txt "$san_url"
fi
else
if [ -n "$(which wget 2>/dev/null)" ]; then
if [ "$debugging" -gt 1 ]; then
echo "Sending using wget."
fi
wget --delete-after --post-file=/tmp/"$san".txt "$san_url" 2>/dev/null
fi
fi
if [ "$create_file" != "y" ]; then
if [ "$debugging" -gt 1 ]; then
echo "Deleting SAN output file /tmp/$san.txt."
fi
$(rm /tmp/"$san".txt)
else
if [ "$debugging" -gt 0 ]; then
echo "SAN output file for uploading to Open-AudIT is $PWD/san-$san.txt"
fi
$(mv /tmp/"$san".txt $PWD/san-$san.txt)
fi
done
fi
fi
#========================
# SYSTEM INFO #
#========================
IFS="$NEWLINEIFS"
if [ "$debugging" -gt "0" ]; then
echo "System Info"
fi
# Set the UUID
system_uuid=""
system_uuid=$(dmidecode -s system-uuid 2>/dev/null | grep -v "^#")
if [ -z "$system_uuid" ] && [ -n "$(which lshal 2>/dev/null)" ]; then
system_uuid=$(lshal 2>/dev/null | grep "system.hardware.uuid" | cut -d\' -f2)
fi
if [ -z "$system_uuid" ] && [ -f "/sys/class/dmi/id/product_uuid" ]; then
system_uuid=$(cat /sys/class/dmi/id/product_uuid 2>/dev/null)
fi
if [ -z "$system_uuid" ] && [ -f "/sys/devices/virtual/dmi/id/product_uuid" ]; then
system_uuid=$(cat /sys/devices/virtual/dmi/id/product_uuid 2>/dev/null)
fi
# Get the hostname & DNS domain
system_domain=$(hostname -d | grep -v \(none\))
system_fqdn=$(hostname -f | grep -v \(none\))
dns_hostname=$(hostname --short 2>/dev/null | head -n1 | cut -d. -f1)
dns_domain=$(hostname --domain 2>/dev/null)
dns_fqdn=$(hostname --fqdn 2>/dev/null | head -n1)
# Get System Family (Distro Name) and the OS Name
# Debian and Ubuntu will match on the below
#system_description=""
system_type="computer"
system_os_group="Linux"
# Changed the below to match the commands run in ssh_helper in-app
# system_os_family=$(lsb_release -is 2>/dev/null | tr -d '"')
# system_os_name=$(lsb_release -ds 2>/dev/null | tr -d '"' | head -n1)
# system_os_version=$(lsb_release -rs 2>/dev/null | tr -d '"')
system_os_family=$(cat /etc/os-release 2>/dev/null | grep -i ^NAME | cut -d= -f2 | cut -d\" -f2)
system_os_name=$(cat /etc/os-release 2>/dev/null | grep -i ^PRETTY_NAME | cut -d= -f2 | cut -d\" -f2)
system_os_version=$(cat /etc/os-release 2>/dev/null | grep -i ^VERSION_ID | cut -d= -f2 | cut -d\" -f2)
system_manufacturer=""
system_model=""
system_serial=""
# Some DD-WRT specials stuff
if [ -z "$system_os_family" ]; then
if [ -f "/etc/motd" ] && [ grep -qi 'DD-WRT' /etc/motd ]; then
system_os_family="DD-WRT"
system_os_version=$(grep DD-WRT /etc/motd | cut -dv -f2)
system_os_version="v$system_os_version"
system_os_name="DD-WRT $system_os_version"
system_model=$(nvram get DD_BOARD)
if echo "$system_model" | grep -qi "tplink"; then
system_manufacturer="TP-Link Technology"
fi
system_ip_address=$(nvram get lan_ipaddr)
system_domain=$(nvram get lan_domain)
system_type="router"
busybox="y"
fi
fi
if [ -z "$system_os_family" ] && [ -f "/etc/avahi/services/dsminfo.service" ]; then
if [ -f "/etc/synoinfo.conf" ]; then
# Keep these as per the SNMP helper
system_type="nas"
system_os_group="Linux"
system_os_family="Synology DSM"
system_manufacturer="Synology"
# Query the OS for these
major=`grep version_major /etc/avahi/services/dsminfo.service 2>/dev/null | cut -d= -f2 | cut -d\< -f1`
minor=`grep version_minor /etc/avahi/services/dsminfo.service 2>/dev/null | cut -d= -f2 | cut -d\< -f1`
build=`grep version_build /etc/avahi/services/dsminfo.service 2>/dev/null | cut -d= -f2 | cut -d\< -f1`
system_os_version="$major.$minor-$build"
system_os_name="Synology DSM $major.$minor-$build"
system_model=`grep model /etc/avahi/services/dsminfo.service 2>/dev/null | cut -d= -f2 | cut -d\< -f1`
system_serial=`grep serial /etc/avahi/services/dsminfo.service 2>/dev/null | cut -d= -f2 | cut -d\< -f1`;
fi
fi
if [ -z "$system_os_family" ] && [ -f "/etc/os-release" ]; then
if grep -q 'Alpine Linux' /etc/os-release ; then
system_os_family="Alpine Linux"
system_os_version=$(grep VERSION_ID /etc/os-release | cut -d\" -f2)
system_os_name=$(grep PRETTY_NAME /etc/os-release | cut -d\" -f2)
busybox="y"
fi
fi
instance_ident=`grep instance_id /etc/default/instance_configs.cfg 2>/dev/null | cut -d= -f2`
for system_release_file in /etc/*[_-]version /etc/*[_-]release; do
[ -f "$system_release_file" ] || continue;
[ "$system_release_file" = "/etc/os-release" ] && continue;
if [ -z "$system_os_name" ]; then
system_os_name=$(head -n1 "$system_release_file")
fi
# Suse Based
# if echo "$system_os_name" | grep -Fqi "Suse" ; then
# if [ -z "$system_os_family" ]; then
# system_os_family="Suse"
# fi
# break;
# fi
if [ -z "$system_os_family" ]; then
if [ -e "/etc/arch-release" ]; then
system_os_name="Arch Linux";
system_os_family="Arch";
fi
fi
# CentOS based - must come before RedHat based
if [ "$system_release_file" = "/etc/centos-release" ]; then
system_os_family="CentOS";
system_os_version=$(grep -o '[0-9]\.[0-9]' "$system_release_file" 2>/dev/null)
if [ -z "$system_os_version" ]; then
system_os_version=$(grep -o '[0-9]' "$system_release_file" 2>/dev/null | head -n1)
fi
break;
fi
# RedHat based
if [ "$system_release_file" = "/etc/redhat-release" ]; then
if cat "$system_release_file" | grep -q "Red Hat" ; then
system_os_family="RedHat"
fi
if cat "$system_release_file" | grep -q "CentOS" ; then
system_os_family="CentOS"
fi
if cat "$system_release_file" | grep -q "Fedora" ; then
system_os_family="Fedora"
fi
if [ -z "$system_os_version" ]; then
system_os_version=$(grep -o '[0-9]\.[0-9].' "$system_release_file" 2>/dev/null)
if [ -z "$system_os_version" ]; then
system_os_version=$(grep -o '[0-9].' "$system_release_file" 2>/dev/null)
fi
fi
break;
fi
done
if [ -z "$system_os_family" ] && [ -f "/etc/os-release" ]; then
system_os_version=$(grep VERSION_ID /etc/os-release | cut -d\" -f2)
system_os_name=$(grep PRETTY_NAME /etc/os-release | cut -d\" -f2)
system_os_family=$(grep ^ID /etc/os-release | grep -v LIKE | cut -d= -f2)
fi
if [ "$system_os_family" == "\"amzn\"" ]; then
system_os_family="Amazon"
fi
if [ "$system_os_family" == "debian" ]; then
system_os_family="Debian GNU/Linux"
fi
if [ "$system_os_family" == "ubuntu" ]; then
system_os_family="Ubuntu"
fi
if [ "$system_os_family" == "centos" ]; then
system_os_family="CentOS"
fi
if [[ "$system_os_family" == *"suse"* ]] || [[ "$system_os_family" == *"SUSE"* ]] || [[ "$system_os_family" == *"SuSE"* ]] || [[ "$system_os_family" == *"SuSe"* ]]; then
system_os_family="Suse"
system_os_version=$(grep VERSION_ID /etc/os-release | cut -d\" -f2)
system_os_name=$(grep PRETTY_NAME /etc/os-release | cut -d\" -f2)
fi
if [ "$busybox" = "n" ] && [ -z "$system_ip_address" ]; then
system_ip_address=$(ip route get $(ip route show 0.0.0.0/0 2>/dev/null | grep -oP 'via \K\S+') 2>/dev/null | grep -oP 'src \K\S+')
fi
if [ -z "$system_ip_address" ]; then
system_ip_address=$(ip addr | grep 'state UP' -A2 | grep inet | awk '{print $2}' | cut -f1 -d'/' | head -n 1)
fi
# Set the icon as the lower case version of the System Family.
system_os_icon=$(lcase "$system_os_family")
# Get the System Serial Number
system_serial=$(dmidecode -s system-serial-number 2>/dev/null | grep -v "^#")
if [ -z "$system_serial" ] || [ "$system_serial" = "0" ]; then
if [ -n "$(which lshal 2>/dev/null)" ]; then
system_serial=$(lshal 2>/dev/null | grep "system.hardware.serial" | cut -d\' -f2)
fi
fi
if [ -z "$system_serial" ] || [ "$system_serial" = "0" ]; then
system_serial=$(cat /sys/class/dmi/id/product_serial 2>/dev/null)
fi
# Get the System Model
if [ -z "$system_model" ]; then
system_model=$(dmidecode -s system-product-name 2>/dev/null | grep -v "^#")
if [ -z "$system_model" ] && [ -n "$(which lshal 2>/dev/null)" ]; then
system_model=$(lshal | grep "system.hardware.product" | cut -d\' -f2)
fi
if [ -z "$system_model" ]; then
system_model=$(cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null)
fi
fi
# get the systemd identifier
dbus_identifier=$(cat /var/lib/dbus/machine-id 2>/dev/null)
if [ -z "$dbus_identifier" ]; then
dbus_identifier=$(cat /etc/machine-id 2>/dev/null)
fi
# Get the System Manufacturer
if [ -z "$system_manufacturer" ]; then
system_manufacturer=$(dmidecode -s system-manufacturer 2>/dev/null | grep -v "^#")
fi
if [ -z "$system_manufacturer" ]; then
if [ -n "$(which lshal 2>/dev/null)" ]; then
system_manufacturer=$(lshal 2>/dev/null | grep "system.hardware.vendor" | cut -d\' -f2)
fi
fi
if [ -z "$system_manufacturer" ]; then
system_manufacturer=$(cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null)
fi
# A few specific checks below here
if [ -z "$system_model" ] && [ -e "/proc/user_beancounters" ] && [ "$(cat /proc/1/status 2>/dev/null | grep "^envID:" | cut -d: -f2 | awk '{print $1}')" != "1" ]; then
# Test for an OpenVZ guest
system_model="OpenVZ"
system_manufacturer="OpenVZ"
fi
if [ -z "$system_model" ] && [ -n "$(which dmidecode 2>/dev/null)" ]; then
if dmidecode | egrep -i 'manufacturer' | grep -q "Microsoft" ; then
# test for a Microsoft virtual machine
system_model="Virtual Machine"
system_manufacturer="Microsoft"
fi
fi
# Get the System Uptime
system_uptime=$(cut -d. -f1 < /proc/uptime)
# Get the System Form factor
system_form_factor=""
if [ "$system_model" = "Bochs" -o \
"$system_model" = "Google Compute Engine" -o \
"$system_model" = "KVM" -o \
"$system_model" = "Virtual Machine" -o \
"$system_model" = "VMware Virtual Platform" -o \
"$system_model" = "OpenVZ" -o \
"$system_model" = "HVM domU" -o \
"$system_model" = "VirtualBox" ]; then
system_form_factor="Virtual"
else
system_form_factor=$(dmidecode -s chassis-type 2>/dev/null | grep -v "^#")
if [ "$system_form_factor" = "<OUT OF SPEC>" ]; then
system_form_factor="Unknown"
fi
system_form_factor=$(pcase $system_form_factor)
fi
if [ -z "$system_form_factor" ]; then
if [ -n "$(which lshal 2>/dev/null)" ]; then
system_form_factor=$(lshal | grep "system.chassis.type" | cut -d\' -f2)
fi
fi
# Get OS bits
system_pc_os_bit=$(uname -m | grep 64 | cut -d_ -f2)
if [ -z "$system_pc_os_bit" ]; then
system_pc_os_bit=$(uname -i | grep 64 | cut -d_ -f2)
fi
if [ -z "$system_pc_os_bit" ]; then
system_pc_os_bit=32
fi
# Get the System Memory
# system_pc_memory=$(grep MemTotal /proc/meminfo | cut -d: -f2 | cut -dk -f1)
# system_pc_memory=$(trim "$system_pc_memory")
memory_slots="0"
system_pc_memory="0"
memory_slots=$(dmidecode -t 17 2>/dev/null | awk '/DMI type 17/{print $2}' | wc -l)
if [ "$memory_slots" != "0" ]; then
IFS="$ORIGIFS";
for memory_handle in $(dmidecode -t 17 2>/dev/null | awk '/DMI type 17/{print $2}'); do
bank_info=$(dmidecode -t 17 2>/dev/null | sed -n '/^Handle '"$memory_handle"'/,/^$/p')
memory_capacity=$(echo "$bank_info" | awk '/Size:/{print $2}' | sed 's/[^0-9]//g')
if [ "$(echo "$bank_info" | awk '/Size:/{print $3}')" = "GB" ];then
memory_capacity=$((memory_capacity * 1024))
fi
system_pc_memory=$((system_pc_memory + memory_capacity))
done;
system_pc_memory=$((system_pc_memory * 1024))
else
system_pc_memory=$(grep MemTotal /proc/meminfo | cut -d: -f2 | cut -dk -f1)
system_pc_memory=$(trim "$system_pc_memory")
fi
# Get the Number of Physical Processors
#
# Each Physical Processor has one or more Processor Cores.
# Each Processor Core has one or more Threads
# Each thread appears as one active processor to the OS
# EX:
# Two Dual Core Processors with Hyper-Threading enabled will show :
# system_pc_total_threads=8
# system_pc_threads_x_processor=4
# system_pc_cores_x_processor=2
#
# Two Dual Core Processors with Hyper-Threading disabled will show :
# system_pc_total_threads=4
# system_pc_threads_x_processor=2
# system_pc_cores_x_processor=2
#
# One Quad Core Processor with Hyper-Threading disabled will show :
# system_pc_total_threads=4
# system_pc_threads_x_processor=4
# system_pc_cores_x_processor=4
#
# system_pc_physical_processors = system_pc_total_threads / system_pc_threads_x_processor
#
system_pc_total_threads=$(grep -c processor /proc/cpuinfo)
system_pc_cores_x_processor=$(grep cores /proc/cpuinfo | head -n1 | cut -d: -f2)
system_pc_cores_x_processor=$(trim "$system_pc_cores_x_processor")
if [ -z "$system_pc_cores_x_processor" ] && [ -n "$(which lshal 2>/dev/null)" ]; then
system_pc_cores_x_processor=$(lshal | grep -c "processor.number")
fi
# RedHat 6.5 doesn't work with the above, so....
if [ -z "$system_pc_cores_x_processor" ]; then
system_pc_cores_x_processor=1
fi
# The number of siblings tell us the number of Threads x Physical Processor
system_pc_threads_x_processor=$(grep siblings /proc/cpuinfo | head -n1 | cut -d: -f2)
system_pc_threads_x_processor=$(trim "$system_pc_threads_x_processor")
if [ -z "$system_pc_threads_x_processor" ]; then
system_pc_threads_x_processor=1
fi
system_pc_physical_processors=$((system_pc_total_threads / system_pc_threads_x_processor))
if [ "$system_pc_physical_processors" = "0" ]; then
system_pc_physical_processors="1"
fi
# Guess the OS Instalation Date
# There is no way to know for sure the install date. /etc/distro-release should give a clue, but it is not really accurate
#
if [ -n "$(which stat 2>/dev/null)" ]; then
system_pc_date_os_installation=$(stat "$system_release_file" | grep "^Modify:" | cut -d" " -f2)
else
system_pc_date_os_installation=""
fi
#'''''''''''''''''''''''''''''''''
#' Write to the audit file '
#'''''''''''''''''''''''''''''''''
{
echo "data=<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
echo "<system>"
echo " <sys>"
echo " <script_version>$version</script_version>"
echo " <uuid>$(escape_xml "$system_uuid")</uuid>"
echo " <hostname>$(escape_xml "$system_hostname")</hostname>"
echo " <domain>$(escape_xml "$system_domain")</domain>"
echo " <fqdn>$(escape_xml "$system_fqdn")</fqdn>"
echo " <dns_hostname>$(escape_xml "$dns_hostname")</dns_hostname>"
echo " <dns_domain>$(escape_xml "$dns_domain")</dns_domain>"
echo " <dns_fqdn>$(escape_xml "$dns_fqdn")</dns_fqdn>"
echo " <ip>$(escape_xml "$system_ip_address")</ip>"
echo " <type>$(escape_xml "$system_type")</type>"
echo " <os_icon>$(escape_xml "$system_os_icon")</os_icon>"
echo " <os_group>$(escape_xml "$system_os_group")</os_group>"
echo " <os_family>$(escape_xml "$system_os_family")</os_family>"
echo " <os_name>$(escape_xml "$system_os_name")</os_name>"
echo " <os_version>$(escape_xml "$system_os_version")</os_version>"
echo " <serial>$(escape_xml "$system_serial")</serial>"
echo " <model>$(escape_xml "$system_model")</model>"
echo " <manufacturer>$(escape_xml "$system_manufacturer")</manufacturer>"
echo " <uptime>$(escape_xml "$system_uptime")</uptime>"
echo " <form_factor>$(escape_xml "$system_form_factor")</form_factor>"
echo " <os_bit>$(escape_xml "$system_pc_os_bit")</os_bit>"
echo " <memory_count>$(escape_xml "$system_pc_memory")</memory_count>"
echo " <processor_count>$(escape_xml "$system_pc_total_threads")</processor_count>"
echo " <os_installation_date>$(escape_xml "$system_pc_date_os_installation")</os_installation_date>"
echo " <org_id>$(escape_xml "$org_id")</org_id>"
echo " <dbus_identifier>$(escape_xml "$dbus_identifier")</dbus_identifier>"
if [ -n "$instance_ident" ]; then
echo " <instance_ident>$(escape_xml "$instance_ident")</instance_ident>"
fi
echo " <last_seen_by>$(escape_xml "$last_seen_by")</last_seen_by>"
echo " <id>$(escape_xml "$system_id")</id>"
echo " <discovery_id>$(escape_xml "$discovery_id")</discovery_id>"
echo " </sys>"
} > "$xml_file"
##################################
# POLICY SECTION #
##################################
if [ "$debugging" -gt "0" ]; then
echo "Policy Info"
fi
echo " <policy>" >> "$xml_file"
IFS="$NEWLINEIFS"
for policy in $(grep -v ^# /etc/login.defs 2>/dev/null | grep -v ^$); do
type="/etc/login.defs"
name=$(echo "$policy" | awk '{print $1}')
value=$(echo "$policy" | awk '{print $2}')
guid=$(echo "$policy" | awk '{print $1}')
{
echo " <item>"
echo " <type>$(escape_xml "$type")</type>"
echo " <name>$(escape_xml "$name")</name>"
echo " <value>$(escape_xml "$value")</value>"
echo " <guid>$(escape_xml "$guid")</guid>"
echo " <options>"
echo " <name>$(escape_xml "$name")</name>"
echo " <value>$(escape_xml "$value")</value>"
echo " </options>"
echo " </item>"
} >> "$xml_file"
done
for policy in $(grep -v ^# /etc/pam.d/common-password 2>/dev/null | grep -v ^$ | sed 's/ \+ /\t/g' | tr -s '\t' '\t'); do
type="/etc/pam.d/common-password"
name=$(echo "$policy" | cut -f1)
enabled=$(echo "$policy" | cut -f2)
json_value=$(echo "$policy" | cut -f3)
value="$enabled : $json_value"
guid="$name-$enabled-$json_value"
{
echo " <item>"
echo " <type>$(escape_xml "$type")</type>"
echo " <name>$(escape_xml "$name")</name>"
echo " <value>$(escape_xml "$value")</value>"
echo " <guid>$(escape_xml "$guid")</guid>"
echo " <options>"
echo " <name>$(escape_xml "$name")</name>"
echo " <enabled>$(escape_xml "$enabled")</enabled>"
echo " <value>$(escape_xml "$json_value")</value>"
echo " </options>"
echo " </item>"
} >> "$xml_file"
done
for policy in $(grep -v ^# /etc/pam.d/system-auth 2>/dev/null | grep -v ^$ | sed 's/ \+ /\t/g' | tr -s '\t' '\t'); do
type="/etc/pam.d/system-auth"
name=$(echo "$policy" | cut -f1)
enabled=$(echo "$policy" | cut -f2)
json_value=$(echo "$policy" | cut -f3)
value="$enabled : $json_value"
guid="$name-$enabled-$json_value"
{
echo " <item>"
echo " <type>$(escape_xml "$type")</type>"
echo " <name>$(escape_xml "$name")</name>"
echo " <value>$(escape_xml "$value")</value>"
echo " <guid>$(escape_xml "$guid")</guid>"
echo " <options>"
echo " <name>$(escape_xml "$name")</name>"
echo " <enabled>$(escape_xml "$enabled")</enabled>"
echo " <value>$(escape_xml "$json_value")</value>"
echo " </options>"
echo " </item>"
} >> "$xml_file"
done
IFS="$ORIGIFS";
echo " </policy>" >> "$xml_file"
##################################
# BIOS SECTION #
##################################
if [ "$debugging" -gt "0" ]; then
echo "BIOS Info"
fi
# Get the BIOS Manufacturer
bios_manufacturer=$(dmidecode -s bios-vendor 2>/dev/null)
if [ -z "$bios_manufacturer" ] && [ -f "/sys/class/dmi/id/bios_vendor" ]; then
bios_manufacturer=$(cat /sys/class/dmi/id/bios_vendor 2>/dev/null)
fi
if [ -z "$bios_manufacturer" ] && [ -n "$(which lshal 2>/dev/null)" ]; then
bios_manufacturer=$(lshal | grep "smbios.bios.vendor" | cut -d\' -f2)
fi
if [ -z "$bios_manufacturer" ] && [ -n "$(which lshal 2>/dev/null)" ]; then
bios_manufacturer=$(lshal | grep "system.firmware.vendor" | cut -d\' -f2)
fi
bios_manufacturer=$(trim "$bios_manufacturer")
# Get the BIOS Version
bios_version=$(dmidecode -s bios-version 2>/dev/null)
if [ -z "$bios_version" ]; then
bios_version=$(dmidecode 2>/dev/null | grep "Firmware Revision" | cut -d: -f2)
fi
if [ -z "$bios_version" ] && [ -f "/sys/class/dmi/id/bios_version" ]; then
bios_version=$(cat /sys/class/dmi/id/bios_version 2>/dev/null)
fi
if [ -z "$bios_version" ] && [ -n "$(which lshal 2>/dev/null)" ]; then
bios_version=$(lshal 2>/dev/null | grep "smbios.bios.version" | cut -d\' -f2)
fi
if [ -z "$bios_version" ] && [ -n "$(which lshal 2>/dev/null)" ]; then
bios_version=$(lshal 2>/dev/null | grep "system.firmware.version" | cut -d\' -f2)
fi
bios_version=$(trim "$bios_version")
# Get the BIOS revision
bios_revision=$(dmidecode 2>/dev/null | grep "BIOS Revision" | cut -d: -f2)
bios_revision=$(trim "$bios_revision")
# Make the BIOS Description using the manufacturer - Firmware Rev
bios_description=""
if [ -n "$bios_version" ] && [ -n "$bios_manufacturer" ]; then
bios_description=$(echo "$bios_manufacturer" | cut -d" " -f1)" BIOS - Firmware Rev. $bios_version"
fi
if [ -z "$bios_description" ] && [ -n "$bios_manufacturer" ]; then
bios_description=$(echo "$bios_manufacturer" | cut -d" " -f1)" BIOS"
fi
# Get the BIOS Serial = System Serial
bios_serial="$system_serial"