-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcsitoolsupdate24.sh
1615 lines (1473 loc) · 67.5 KB
/
csitoolsupdate24.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/bash
# -----------------------------------------------------------------------------------
# Script Name: csitoolsupdate - powerup
# Description: CSI Linux PowerUp - updater and installer script for maintaining updates for the OS, CSI Linux Tools, and Third Party Tools.
# Author: Jeremy Martin
# Website: https://csilinux.com
#
# Copyright: © 2024 CSI Linux - csilinux.com. All rights reserved.
#
# This script is proprietary software and is part of the CSI Linux project. It is available for use subject to the following conditions:
#
# 1. This script may only be used on CSI Linux platforms, and you must have a valid license for that use. This license does not grant you rights to modify, distribute,
# or create derivative works unless expressly stated in the license terms.
#
# 2. Unauthorized copying of this script, via any medium, is strictly prohibited. Modifications, derivatives, and distribution are also prohibited without prior
# written consent from CSI Linux.
#
# 3. This script is provided "as is" and without warranties as to performance or merchantability. The author and CSI Linux disclaim all warranties, express or
# implied, including, but not limited to, implied warranties of merchantability and fitness for a particular purpose, concerning this script.
#
# 4. In no event shall CSI Linux or the author be liable for any special, indirect, or consequential damages or any damages whatsoever resulting from loss of use, data or
# profits, whether in an action of contract, negligence, or other tortious action, arising out of or in connection with the use or performance of this script.
#
# For further information on licensing, please visit CSI Linux Academy: # https://csilinux.com/academy
# Support CSI Linux by purchasing official merchandise: # https://csilinux.com/shop
# -----------------------------------------------------------------------------------
echo "Welcome to CSI Linux. This will take a while, but the update has a LOT of content..."
start_time=$(date +%s)
# Attempt to verify the first argument as a sudo password
key_attempt="$1"
key="" # Initialize key as an empty string for clarity
if echo "$key_attempt" | sudo -S -v -k &> /dev/null; then
key="$key_attempt"
sudo -k # Reset the sudo timestamp after verification
echo "sudo access verified with the provided key."
shift # Remove the first argument since it's the sudo password
else
echo "First argument is not a sudo password. It will be treated as a powerup option if applicable."
# If key_attempt was not empty but failed verification, include it back in arguments for processing
if [ -n "$key_attempt" ]; then
set -- "$key_attempt" "$@"
fi
fi
# Prompt for the sudo password if not already verified
if [ -z "$key" ]; then
prompt_for_sudo
fi
# All remaining arguments are considered as powerup options
powerup_options=("$@")
# Check if powerup_options is empty
if [[ ${#powerup_options[@]} -eq 0 ]]; then
powerup_options+=("csi-linux-base" "os-update" "csi-linux-themes" "encryption" "malware-analysis" "sigint" "virtualization" "security" "Navi-AI")
fi
echo "Power-up options selected:"
for option in "${powerup_options[@]}"; do
echo "- $option"
done
# Define the function to prompt for sudo password
prompt_for_sudo() {
while true; do
key=$(zenity --password --title "Power up your system with an upgrade." --text "Enter your CSI password." --width=400)
if [ $? -ne 0 ]; then
zenity --info --text="Operation cancelled. Exiting script." --width=400
exit 1
fi
if echo $key | sudo -S -v -k &> /dev/null; then
sudo -k
echo "sudo access verified."
break
else
zenity --error --title="Authentication Failure" --text="Incorrect password or lack of sudo privileges. Please try again." --width=400
fi
done
}
install_vm_tools() {
# Define all possible packages for virtualization tools
vmware_packages="open-vm-tools-desktop"
virtualbox_packages="virtualbox-guest*"
qemu_kvm_packages="qemu-guest-agent"
hyperv_packages="linux-tools-virtual linux-cloud-tools-virtual"
xen_packages="xe-guest-utilities"
all_packages="$vmware_packages $virtualbox_packages $qemu_kvm_packages $hyperv_packages $xen_packages"
# Detect the virtualization environment
if grep -q VMware /sys/class/dmi/id/product_name; then
environment="vmware"
echo "VMware detected. Installing ${vmware_packages}..."
elif lspci | grep -iq 'virtualbox'; then
environment="virtualbox"
echo "VirtualBox detected. Installing ${virtualbox_packages}..."
elif grep -q 'QEMU' /sys/class/dmi/id/sys_vendor || grep -q 'KVM' /sys/class/dmi/id/sys_vendor; then
environment="qemu_kvm"
echo "QEMU/KVM detected. Installing ${qemu_kvm_packages}..."
elif grep -q 'Microsoft Corporation Hyper-V' /sys/class/dmi/id/sys_vendor; then
environment="hyperv"
echo "Hyper-V detected. Installing ${hyperv_packages}..."
elif grep -q 'Xen' /sys/class/dmi/id/sys_vendor; then
environment="xen"
echo "Xen detected. Installing ${xen_packages}..."
else
environment="hardware"
echo "No known virtualization detected or the system is a physical machine."
fi
# Install the necessary packages for the detected environment and purge the rest
case $environment in
vmware)
sudo apt install -y $vmware_packages
sudo apt purge -y ${all_packages//$vmware_packages/}
;;
virtualbox)
sudo apt purge -y ${all_packages//$virtualbox_packages/}
;;
qemu_kvm)
sudo apt install -y $qemu_kvm_packages
sudo apt purge -y ${all_packages//$qemu_kvm_packages/}
;;
hyperv)
sudo apt install -y $hyperv_packages
sudo apt purge -y ${all_packages//$hyperv_packages/}
;;
xen)
sudo apt install -y $xen_packages
sudo apt purge -y ${all_packages//$xen_packages/}
;;
hardware)
# If no virtualization is detected, purge all tools
sudo apt purge -y $all_packages
;;
esac
echo "System set for running with $environment..."
# Optional: Remove any packages that were automatically installed to satisfy dependencies
sudo apt autoremove -y
}
install_missing_programs() {
local programs=(curl bpytop xterm aria2 yad zenity)
local missing_programs=()
local output_file="/tmp/outputfile.txt" # Define the output file path correctly
echo "Creating file at: $output_file"
sudo touch "$output_file"
for program in "${programs[@]}"; do
if ! dpkg -s "$program" &> /dev/null; then
echo "$program is not installed. Will attempt to install." | tee -a "$output_file"
missing_programs+=("$program")
else
echo "$program is already installed." | tee -a "$output_file"
fi
done
if [ ${#missing_programs[@]} -ne 0 ]; then
echo "Updating package lists..." | tee -a "$output_file"
echo $key | sudo -S apt update | tee -a "$output_file"
for program in "${missing_programs[@]}"; do
echo "Attempting to install $program..." | tee -a "$output_file"
if echo $key | sudo -S -E DEBIAN_FRONTEND=noninteractive apt-get install -yq "$program" 2>&1 | tee -a "$output_file"; then
echo "$program installed successfully." | tee -a "$output_file"
else
echo "Failed to install $program. It may not be available in the repository or another error occurred." | tee -a "$output_file"
fi
done
else
echo "Starter programs are already installed." | tee -a "$output_file"
fi
}
install_csi_tools() {
local flag_file="/tmp/csi_tools_installed.flag" # Secure location for flag file
# Check if the flag file exists, indicating the function was already run
if [[ -f "$flag_file" ]]; then
echo "CSI Tools have already been installed. Exiting."
return 0 # Exit the function successfully
fi
local backup_dir="/tmp/restorecsitools"
local backup_file_name="csitools"
local archive_path="$backup_dir/$backup_file_name.7z"
echo "$key" | sudo -S DEBIAN_FRONTEND=noninteractive apt install aria2 -y
echo "Preparing for CSI Tools download..."
echo "$key" | sudo -S rm -rf "$backup_dir" # Remove the entire backup directory
echo "$key" | sudo -S mkdir -p "$backup_dir"
echo "$key" | sudo -S chmod 777 "$backup_dir" # Set full permissions temporarily for download
echo "Downloading CSI Tools..."
if aria2c -x3 -k1M http://echothislabs.com/downloads/csitools.7z https://csilinux.com/downloads/csitools.7z https://informationwarfarecenter.com/downloads/csitools.7z -d "$backup_dir" -o "$backup_file_name.7z"; then
echo "Download successful."
echo "# Installing CSI Tools..."
if restore_backup_to_root "$backup_dir" "$backup_file_name"; then
echo "CSI Tools restored successfully."
echo "Setting permissions and configurations for CSI Tools..."
echo "$key" | sudo -S chown csi:csi -R /opt/csitools
echo "$key" | sudo -S chmod +x /opt/csitools/* -R
echo "$key" | sudo -S chmod +x ~/Desktop/*.desktop
echo "Converting DOS format to UNIX format in CSI Tools directories..."
find /opt/csitools /opt/csitools/helpers -type f -exec sudo dos2unix {} + &>/dev/null
echo "CSI Tools installation and configuration completed successfully."
echo "$key" | sudo -S touch "$flag_file"
else
echo "Failed to restore CSI Tools from the backup."
return 1 # Restoration failed
fi
else
echo "Failed to download CSI Tools."
return 1 # Download failed
fi
return 0 # Successfully completed the function
}
restore_backup_to_root() {
echo $key | sudo -S sleep 1
sudo -k
local backup_dir=$1
local backup_file_name=$2
local archive_path="$backup_dir/$backup_file_name.7z"
mkdir -p "/opt/AppImages" 2>/dev/null
echo "Restoring CSI Tools backup..."
# Extract the .7z file safely and ensure files are overwritten without prompting
if ! echo $key | sudo -S 7z x -aoa -o"$backup_dir" "$archive_path"; then
echo "Failed to extract $archive_path. Please check the file and try again."
return 1 # Exit the function with an error status
fi
local tar_file="$backup_dir/$backup_file_name.tar"
if [ -f "$tar_file" ]; then
echo "Restoring backup from tar file..."
# Extract the tar file and ensure files are overwritten without prompting
if ! echo $key | sudo -S tar --overwrite -xpf "$tar_file" -C /; then
echo "Failed to restore from $tar_file. Please check the archive and try again."
return 1 # Exit the function with an error status
fi
echo "Backup restored successfully."
echo $key | sudo -S rm "$tar_file"
else
echo "Backup .tar file not found. Please check the archive path and try again."
return 1 # Exit the function with an error status
fi
return 0 # Successfully completed the function
}
install_packages() {
local -n packages=$1
local newpackages=()
local already_installed=0
local installed=0
local failed=0
local total_packages=${#packages[@]}
local current_package=0
echo "Checking which packages need installation..."
# Pre-check installed status to avoid unnecessary operations
for package in "${packages[@]}"; do
let current_package++
if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q "install ok installed"; then
# echo "[$current_package/$total_packages] Package $package is already installed, skipping."
((already_installed++))
else
newpackages+=("$package")
fi
done
echo "Out of $total_packages packages, $already_installed are already installed."
local new_total=${#newpackages[@]}
if [ "$new_total" -eq 0 ]; then
echo "No new packages to install."
return
fi
echo "Starting installation of $new_total new packages..."
current_package=0
for package in "${newpackages[@]}"; do
let current_package++
echo -n "[$current_package/$new_total] Installing $package... "
echo $key | sudo -S apt install --fix-broken
if echo $key | sudo -S -E DEBIAN_FRONTEND=noninteractive apt-get install -yq --assume-yes "$package"; then
echo "SUCCESS"
((installed++))
else
echo "FAILED"
((failed++))
echo "$package" >> /opt/csitools/apt-failed.txt
fi
done
echo -e "\nInstallation complete."
echo "Summary: $already_installed skipped, $installed installed, $failed failed."
if [ $failed -gt 0 ]; then
echo "Details of failed installations have been logged to /opt/csitools/apt-failed.txt."
fi
}
# Function to remove specific files
csi_remove() {
echo $key | sudo -S sleep 1
# Assuming $1 is the full path with potential wildcards
local path="$1"
if [[ "$path" == *\** ]]; then
# If there's a wildcard, use find to safely handle file names and check existence
local files=$(find $(dirname "$path") -name "$(basename "$path")" 2> /dev/null)
if [ -n "$files" ]; then
echo "Deleting files: $files"
echo $files | xargs -I {} echo $key | sudo -S csi_remove "{}"
fi
else
# If it's a specific file or directory, check if it exists and then delete
if [ -e "$path" ]; then
echo "Deleting: $path"
echo $key | sudo -S csi_remove "$path"
fi
fi
}
add_repository() {
echo $key | sudo -S sleep 1
local repo_type="$1"
local repo_url="$2"
local gpg_key_info="$3" # Contains the keyserver and the keys to receiving for 'key' type
local repo_name="$4"
if [ "$repo_type" == "ppa" ]; then
# Convert PPA URL to a format that is likely used in the .list files
local ppa_formatted_url="ppa.launchpadcontent.net/${repo_url#ppa:}/ubuntu"
local ppa_present=$(grep -RlF "$ppa_formatted_url" /etc/apt/sources.list.d/ 2>/dev/null)
if [[ -n "$ppa_present" ]]; then
echo "PPA '${repo_url}' already added as found in $ppa_present. Skipping addition."
return 0
fi
elif [ -f "/etc/apt/sources.list.d/${repo_name}.list" ]; then
echo "Repository '${repo_name}' list file already exists. Skipping addition."
return 0
fi
# First, check if the repository list file already exists
if [ -f "/etc/apt/sources.list.d/${repo_name}.list" ]; then
echo "Repository '${repo_name}' list file already exists. Skipping addition."
return 0
fi
# Since the .list file does not exist, proceed with adding the GPG key (for 'apt' and 'key')
if [[ "$repo_type" == "apt" || "$repo_type" == "key" ]] && [ ! -f "/etc/apt/trusted.gpg.d/${repo_name}.gpg" ]; then
echo "Adding GPG key for '${repo_name}'..."
cd /tmp
if [ "$repo_type" == "apt" ]; then
echo "$key" | sudo -S curl -fsSL "$gpg_key_info" | sudo gpg --dearmor | sudo tee "/etc/apt/trusted.gpg.d/${repo_name}.gpg" > /dev/null
elif [ "$repo_type" == "key" ]; then
# Correctly handle the 'key' type using the original working code snippet
local keyserver=$(echo "$gpg_key_info" | cut -d ' ' -f1)
local recv_keys=$(echo "$gpg_key_info" | cut -d ' ' -f2-)
echo "$key" | sudo -S gpg --no-default-keyring --keyring gnupg-ring:/tmp/"$repo_name".gpg --keyserver "$keyserver" --recv-keys $recv_keys
echo "$key" | sudo -S gpg --no-default-keyring --keyring gnupg-ring:/tmp/"$repo_name".gpg --export | sudo tee "/etc/apt/trusted.gpg.d/$repo_name.gpg" > /dev/null
fi
if [ $? -ne 0 ]; then
echo "Error adding GPG key for '${repo_name}'."
return 1
fi
fi
# Add the repository
echo "Adding repository '${repo_name}'..."
if [ "$repo_type" == "apt" ] || [ "$repo_type" == "key" ]; then
echo "deb [signed-by=/etc/apt/trusted.gpg.d/${repo_name}.gpg] $repo_url" | sudo tee "/etc/apt/sources.list.d/${repo_name}.list" > /dev/null
elif [ "$repo_type" == "ppa" ]; then
echo "$key" | sudo -S add-apt-repository --no-update -y "$repo_url"
fi
if [ $? -eq 0 ]; then
echo "Repository '${repo_name}' added successfully."
else
echo "Error adding repository '${repo_name}'."
return 1
fi
}
fix_broken() {
echo $key | sudo -S sleep 1
echo "# Verifying and configuring any remaining packages (dpkg --configure -a --force-confold)..."
echo $key | sudo -S dpkg --configure -a --force-confold
echo "# Fixing and configuring broken apt installs (dpkg --configure -a)..."
echo $key | sudo -S dpkg --configure -a
echo $key | sudo -S apt remove sleuthkit &>/dev/null
echo "# Fixing and configuring broken apt installs (apt install --fix-broken -y)..."
echo $key | sudo -S apt install --fix-broken -y
}
update_git_repository() {
local repo_name="$1"
local repo_url="$2"
local _venv="$3" # Accepting the new _venv argument
local repo_dir="/opt/$repo_name"
# Check if the repository directory already exists
if [ -d "$repo_dir" ]; then
echo "Repository $repo_name already exists. Skipping..."
return # Exit the function to avoid further actions
fi
# If the directory does not exist, clone the new repository
echo "Cloning new repository $repo_name..."
echo $key | sudo -S git clone "$repo_url" "$repo_dir"
echo $key | sudo -S chown -R $USER:$USER "$repo_dir"
# After cloning, handle Python dependencies if required
if [ -f "$repo_dir/requirements.txt" ]; then
# Setup virtual environment if required
if [[ -n $_venv ]]; then
echo "Setting up Python virtual environment and installing dependencies..."
python -m venv "${repo_dir}/${repo_name}-venv"
source "${repo_dir}/${repo_name}-venv/bin/activate"
fi
# Read each line in requirements.txt and check if the package is installed
while IFS= read -r requirement; do
local package_name=$(echo "$requirement" | cut -d= -f1)
if ! pip show "$package_name" &>/dev/null; then
echo "Installing $requirement..."
pip install "$requirement"
if [ $? -eq 0 ]; then
echo "$requirement installed successfully."
else
echo "Failed to install $requirement."
fi
else
echo "$requirement is already installed."
fi
done < "${repo_dir}/requirements.txt"
# Deactivate virtual environment if one was set up
if [[ -n $_venv ]]; then
deactivate
echo "Virtual environment deactivated."
fi
echo "Dependencies setup completed."
fi
}
disable_services() {
# Define a list of services to disable
local disableservices=(
"apache-htcacheclean.service"
"apache2.service"
"bettercap.service"
"clamav-daemon.service"
"clamav-freshclam.service"
"clamav-milter.service"
"cups-browsed.service"
"cups.service"
"i2p"
"i2pd"
"kismet.service"
"lokinet"
"lokinet-testnet.service"
"openvpn.service"
"privoxy.service"
"rsync.service"
"systemd-networkd-wait-online.service"
"NetworkManager-wait-online.service"
"xl2tpd.service"
"mono-xsp4.service"
)
# Iterate through the list and disable each service
for service in "${disableservices[@]}"; do
echo "Disabling $service..."
echo $key | sudo -S systemctl stop "$service" &>/dev/null
echo $key | sudo -S systemctl disable "$service" &>/dev/null
echo "$service disabled successfully."
done
}
reset_DNS() {
check_connection() {
ping -c 1 8.8.8.8 >/dev/null
}
check_dns() {
ping -c 1 google.com >/dev/null
}
echo $key | sudo -S apt install systemd-resolved -y
echo "# Checking and updating /etc/resolv.conf"
echo $key | sudo -S mv /etc/resolv.conf /etc/resolv.conf.bak
echo "nameserver 127.0.0.53" | sudo tee /etc/resolv.conf > /dev/null
echo "nameserver 127.3.2.1" | sudo tee -a /etc/resolv.conf > /dev/null
printf "\nDNS nameservers updated.\n"
echo $key | sudo -S systemctl restart systemd-resolved
while ! systemctl is-active --quiet systemd-resolved; do
echo "Waiting for systemd-resolved to restart..."
sleep 1
done
echo "systemd-resolved restarted successfully."
max_retries=5
retry_count=0
while [[ $retry_count -lt $max_retries ]]; do
if check_connection; then
echo "Internet connection is working."
if ! check_dns; then
echo "The internet is working, but DNS is not working. Please check your resolv.conf file"
((retry_count++))
else
break
fi
else
echo "Internet connection is not working. Please check your network."
((retry_count++))
fi
done
if [[ $retry_count -eq $max_retries ]]; then
echo "Maximum retries reached. Exiting."
fi
echo $key | sudo -S sleep 1
sudo -k
}
setup_new_csi_system() {
echo $key | sudo -S sleep 1
sudo -k
# Sub-function to check if a user exists
user_exists() {
if id "$1" &>/dev/null; then
return 0
else
return 1
fi
}
# sudo apt-get install xubuntu-desktop --no-install-recommends
# Sub-function to add a user to a group
add_user_to_group() {
echo $key | sudo -S adduser "$1" "$2" &>/dev/null
}
# Sub-function to set up the user environment
setup_user_environment() {
USERNAME="csi"
echo "# Setting up user $USERNAME"
if ! user_exists "$USERNAME"; then
echo $key | sudo -S useradd -m "$USERNAME" -G sudo /bin/bash || { echo -e "${USERNAME}\n${USERNAME}\n" | sudo passwd "$USERNAME"; }
fi
add_user_to_group "$USERNAME" vboxsf &>/dev/null
add_user_to_group "$USERNAME" libvirt &>/dev/null
add_user_to_group "$USERNAME" kvm &>/dev/null
if ! grep -q "^default_user\s*$USERNAME" /etc/slim.conf; then
echo "Setting default_user to $USERNAME in SLiM configuration..."
echo "default_user $USERNAME" | sudo tee -a /etc/slim.conf > /dev/null
else
echo "default_user is already set to $USERNAME."
fi
}
# Main user and system setup
echo "# Initiating CSI Linux system setup..."
setup_user_environment
echo 'Acquire::Languages "none";' | sudo tee /etc/apt/apt.conf.d/99disable-translations
echo "# System setup starting..."
echo "\$nrconf{'restart'} = 'a';" | sudo tee /etc/needrestart/conf.d/autorestart.conf > /dev/null
export DEBIAN_FRONTEND=noninteractive
export apt_LISTCHANGES_FRONTEND=none
# export DISPLAY=:0.0
# export TERM=xterm
echo $key | sudo -S apt-mark hold lightdm &>/dev/null
echo $key | sudo -S apt-mark hold lightdm-gtk-greeter &>/dev/null
echo 'Dpkg::Options {
"--force-confdef";
"--force-confold";
}' | sudo tee /etc/apt/apt.conf.d/99force-conf &>/dev/null
echo "# Architecture cleanup"
if dpkg --print-foreign-architectures | grep -q 'i386'; then
echo "# Cleaning up old Arch"
i386_packages=$(dpkg --get-selections | awk '/i386/{print $1}')
if [ ! -z "$i386_packages" ]; then
echo "Removing i386 packages..."
echo $key | sudo -S apt remove sleuthkit &>/dev/null
echo $key | sudo -S apt remove --purge --allow-remove-essential -y $i386_packages
fi
echo "# Standardizing Arch"
echo $key | sudo -S dpkg --remove-architecture i386
fi
echo $key | sudo -S dpkg-reconfigure debconf --frontend=noninteractive
echo $key | sudo -S DEBIAN_FRONTEND=noninteractive dpkg --configure -a &>/dev/null
echo $key | sudo -S NEEDRESTART_MODE=a apt update --ignore-missing &>/dev/null
echo "# Cleaning old tools"
csi_remove /var/lib/tor/hidden_service/ &>/dev/null
csi_remove /var/lib/tor/other_hidden_service/ &>/dev/null
cd /tmp
wget -O - https://raw.githubusercontent.com/CSILinux/CSILinux-Powerup/main/csi-linux-terminal.sh | bash #&>/dev/null
source ~/.bashrc
git config --global safe.directory '*'
echo $key | sudo -S sysctl vm.swappiness=10
echo "vm.swappiness=10" | sudo tee /etc/sysctl.d/99-sysctl.conf
echo $key | sudo -S systemctl enable fstrim.timer
echo "Warning Banners - Configuring system banners..."
# Define the security banner
security_banner="
+-------------------------------------------------------------------+
| SECURITY NOTICE |
| |
| ** Unauthorized Access and Usage is Strictly Prohibited ** |
| |
| All activity on this system is monitored and recorded. Any |
| unauthorized access will be investigated and could lead to |
| legal consequences, including prosecution. |
| |
| If you are not an authorized user, disconnect immediately. |
| |
| By accessing this system, you consent to monitoring, and you |
| acknowledge your responsibility for protecting sensitive data. |
| |
| For any suspicious activity, notify the IT Security Team. |
| |
| Thank you for contributing to a secure work environment. |
| |
| ** Protecting Data - Protecting Our Future ** |
+-------------------------------------------------------------------+
"
# Print the security banner
echo "$security_banner"
echo "$security_banner" | sudo tee /etc/issue.net /etc/issue /etc/motd &>/dev/null
# SSH configuration
echo "Configuring SSH..."
echo $key | sudo -S sed -i 's|#Banner none|Banner /etc/issue.net|' /etc/ssh/sshd_config
echo $key | sudo -S sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
echo $key | sudo -S sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config
echo $key | sudo -S sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
echo $key | sudo -S systemctl restart sshd
sudo -k
}
update_xfce_wallpapers() {
local wallpaper_path="$1" # Use the first argument as the wallpaper path
if [[ -z "$wallpaper_path" ]]; then
echo "Usage: update_xfce_wallpapers /path/to/your/wallpaper.jpg"
return 1 # Exit the function if no wallpaper path is provided
fi
if [ ! -f "$wallpaper_path" ]; then
echo "The specified wallpaper file does not exist: $wallpaper_path"
return 1 # Exit the function if the wallpaper file doesn't exist
fi
screens=$(xfconf-query -c xfce4-desktop -l | grep -Eo 'screen[^/]+' | uniq)
for screen in $screens; do
monitors=$(xfconf-query -c xfce4-desktop -l | grep "${screen}/" | grep -Eo 'monitor[^/]+' | uniq)
for monitor in $monitors; do
workspaces=$(xfconf-query -c xfce4-desktop -l | grep "${screen}/${monitor}/" | grep -Eo 'workspace[^/]+' | uniq)
for workspace in $workspaces; do
# Construct the property path
property_path="/backdrop/${screen}/${monitor}/${workspace}/last-image"
echo "Updating wallpaper for ${property_path} to ${wallpaper_path}"
xfconf-query -c xfce4-desktop -p "${property_path}" -n -t string -s "${wallpaper_path}"
done
done
done
}
install_from_requirements_url() {
local requirements_url="$1"
rm /tmp/requirements.txt &>/dev/null
curl -s "$requirements_url" -o /tmp/requirements.txt
# Prepare a list of installed packages for reference
local installed_packages=$(python3 -m pip list --format=freeze)
local total_packages=$(wc -l < /tmp/requirements.txt)
local current_package=0
echo "Checking and installing Python packages..."
while IFS= read -r package; do
local package_name=$(echo "$package" | cut -d'=' -f1) # Extract package name
if ! echo "$installed_packages" | grep -Fq "$package_name"; then
let current_package++
if ! python3 -m pip install "$package" --quiet &>/dev/null; then
echo "Failed to install $package_name"
fi
else
echo "Package $package_name already installed, skipping."
fi
done < /tmp/requirements.txt
echo "Installation complete."
}
installed_packages_desc() {
local -n packages=$1 # Indirect reference to the array variable
local descriptions_file="$HOME/Documents/${1}_descriptions.csv"
local no_descriptions_file="$HOME/Documents/${1}_no_descriptions.csv"
echo "# Listing Installed Packages and Descriptions"
# Ensure the Documents directory exists
mkdir -p "$HOME/Documents"
# Initialize files with headers
echo "package_name,description" > "$descriptions_file"
echo "package_name" > "$no_descriptions_file"
local description_found=false
for pkg in "${packages[@]}"; do
local description=$(apt-cache show "$pkg" 2>/dev/null | grep -m 1 -Po '^Description: \K.*')
if [ -n "$description" ]; then
# Append package name and description to CSV, escaping internal quotes in descriptions
echo "${pkg},\"${description//\"/\"\"}\"" >> "$descriptions_file"
description_found=true
else
# Log packages without descriptions separately
echo "$pkg" >> "$no_descriptions_file"
fi
done
# Remove the no_descriptions_file if no packages were found without descriptions
if [ "$description_found" = false ]; then
rm -f "$no_descriptions_file"
echo "All packages had descriptions. No packages without descriptions file created."
else
echo "Some packages had no descriptions. Check the no_descriptions.csv file."
fi
echo "CSV files created in the Documents folder:"
echo "- With descriptions: $descriptions_file"
if [ -f "$no_descriptions_file" ]; then
echo "- Without descriptions: $no_descriptions_file"
fi
}
# echo "To remember the null output " &>/dev/null
# echo $key | sudo -S ln -s /opt/csitools/csi_app /usr/bin/csi_app &>/dev/null
# Use sudo with the provided key
echo $key | sudo -S sleep 1
echo $key | sudo -S df -h
cd /tmp
# unredactedmagazine
# Main script logic
sudo -k
for option in "${powerup_options[@]}"; do
echo "Processing option: $option"
case $option in
"csi-linux-base")
cd /tmp
echo "Cleaning up CSI Linux base..."
# File to modify
HOSTS_FILE="/etc/hosts"
# Backup the original hosts file
echo $key | sudo -S cp "$HOSTS_FILE" "$HOSTS_FILE.bak"
echo $key | sudo -S -K
# Define entries to add
declare -A HOSTS
HOSTS["archive.ubuntu.com"]="185.125.190.82 91.189.91.81 91.189.91.83 185.125.190.83 185.125.190.81 2620:2d:4002:1::101 2620:2d:4000:1::102 2620:2d:4000:1::101 2620:2d:4000:1::103 2620:2d:4002:1::103"
HOSTS["archive.canonical.com"]="91.189.91.15 185.125.188.12 185.125.188.87 2001:67c:1562::1c 2620:2d:4000:1003::111 2620:2d:4000:1003::3c9"
# Add each entry if it doesn't already exist
for DOMAIN in "${!HOSTS[@]}"; do
for IP in ${HOSTS[$DOMAIN]}; do
if ! grep -q "$IP[[:space:]]\+$DOMAIN" "$HOSTS_FILE"; then
echo "Adding $IP $DOMAIN"
echo "$IP $DOMAIN" | sudo tee -a "$HOSTS_FILE" > /dev/null
else
echo "$IP $DOMAIN already exists in $HOSTS_FILE"
fi
done
done
# Notify user
echo "Entries added to $HOSTS_FILE. Backup saved as $HOSTS_FILE.bak."
echo $key | sudo -S apt purge sleuthkit &>/dev/null
echo $key | sudo -S apt-mark hold lightdm &>/dev/null
echo $key | sudo -S echo lightdm hold | dpkg --set-selections &>/dev/null
echo $key | sudo -S apt-mark hold lightdm-gtk-greeter &>/dev/null
echo $key | sudo -S echo lightdm-gtk-greeter hold | dpkg --set-selections &>/dev/null
echo $key | sudo -S apt-mark hold postfix &>/dev/null
echo $key | sudo -S echo postfix hold | dpkg --set-selections &>/dev/null
echo $key | sudo -S apt-mark hold sleuthkit &>/dev/null
echo $key | sudo -S echo sleuthkit hold | dpkg --set-selections &>/dev/null
echo $key | sudo -S ssh-keygen -A
echo $key | sudo -S rm -rf /etc/apt/sources.list.d/archive_u* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/sources.list.d/brave* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/sources.list.d/signal* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/sources.list.d/apt-vulns-sexy* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/trusted.gpg.d/apt-vulns-sexy* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/sources.list.d/wine* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/trusted.gpg.d/wine* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/trusted.gpg.d/brave* &>/dev/null
echo $key | sudo -S rm -rf /etc/apt/trusted.gpg.d/signal* &>/dev/null
echo $key | sudo -S csi_remove /var/crash/* &>/dev/null
echo $key | sudo -S rm /var/crash/* &>/dev/null
rm ~/.vbox* &>/dev/null
echo "# Setting up CSI Linux environment..."
setup_new_csi_system
echo $key | sudo -S apt remove sleuthkit &>/dev/null
echo "# Setting up repo environment"
REPOS=(
"deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse"
"deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse"
"deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse"
"deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse"
"deb http://archive.canonical.com/ubuntu/ jammy partner"
)
# The file to be checked and modified
FILE="/etc/apt/sources.list"
# Iterate over each repository line
for repo in "${REPOS[@]}"; do
# Use grep to check if the line is already in the file
if ! grep -q "^$(echo $repo | sed 's/ /\\ /g')" "$FILE"; then
# If the line is not found, append it to the file
echo "Adding repository: $repo"
echo "$repo" | sudo tee -a "$FILE" > /dev/null
else
echo "Repository already exists: $repo"
fi
done
cd /tmp
echo "# Setting up apt Repos"
add_repository "apt" "https://apt.bell-sw.com/ stable main" "https://download.bell-sw.com/pki/GPG-KEY-bellsoft" "bellsoft"
add_repository "apt" "http://apt.vulns.xyz stable main" "http://apt.vulns.xyz/kpcyrd.pgp" "apt-vulns-sexy"
add_repository "apt" "https://dl.winehq.org/wine-builds/ubuntu/ noble main" "https://dl.winehq.org/wine-builds/winehq.key" "winehq"
add_repository "apt" "https://www.kismetwireless.net/repos/apt/release/jammy jammy main" "https://www.kismetwireless.net/repos/kismet-release.gpg.key" "kismet"
add_repository "apt" "https://packages.element.io/debian/ default main" "https://packages.element.io/debian/element-io-archive-keyring.gpg" "element-io"
add_repository "apt" "https://deb.oxen.io $(lsb_release -sc) main" "https://deb.oxen.io/pub.gpg" "oxen"
add_repository "apt" "https://updates.signal.org/desktop/apt xenial main" "https://updates.signal.org/desktop/apt/keys.asc" "signal-desktop"
add_repository "apt" "https://brave-browser-apt-release.s3.brave.com/ stable main" "https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg" "brave-browser"
add_repository "apt" "https://packages.microsoft.com/repos/code stable main" "https://packages.microsoft.com/keys/microsoft.asc" "vscode"
add_repository "apt" "https://packages.cisofy.com/community/lynis/deb/ stable main" "https://packages.cisofy.com/keys/cisofy-software-public.key" "cisofy-lynis"
add_repository "apt" "https://download.docker.com/linux/ubuntu noble stable" "https://download.docker.com/linux/ubuntu/gpg" "docker"
# add_repository "key" "https://download.onlyoffice.com/repo/debian squeeze main" "hkp://keyserver.ubuntu.com:80 --recv-keys CB2DE8E5" "onlyoffice"
add_repository "ppa" "ppa:danielrichter2007/grub-customizer" "" "grub-customizer"
add_repository "ppa" "ppa:phoerious/keepassxc" "" "keepassxc"
add_repository "ppa" "ppa:cappelikan/ppa" "" "mainline"
add_repository "ppa" "ppa:apt-fast/stable" "" "apt-fast"
add_repository "ppa" "ppa:obsproject/obs-studio" "" "obs-studio"
add_repository "ppa" "ppa:savoury1/backports" "" "savoury1"
# File to remove duplicates from
FILE="/etc/apt/sources.list"
# Backup the original sources.list file
echo $key | sudo -S cp "/etc/apt/sources.list" "/etc/apt/sources.bak"
# Remove duplicate lines from sources.list
echo $key | sudo -S awk '!seen[$0]++' "/etc/apt/sources.list" > /tmp/sources.list && sudo mv /tmp/sources.list "/etc/apt/sources.list"
# Notify user
echo "Duplicates removed from /etc/apt/sources.list. Backup saved as /etc/apt/sources.bak."
echo "# Updating APT with updated repos"
echo $key | sudo -S apt update
fix_broken
install_vm_tools
echo $key | sudo -S apt upgrade -y
echo "# Checking Starter Apps"
install_missing_programs
echo $key | sudo -S apt remove sleuthkit -y &>/dev/null
echo "# Disabling un-needed Services"
disable_services &>/dev/null
if ! which python3-venv > /dev/null; then
echo "# python3-venv"
echo $key | sudo -S apt install python3-venv &>/dev/null
fi
install_from_requirements_url "https://csilinux.com/downloads/csitools-requirements.txt"
echo $key | sudo -S ln -s /usr/bin/python3 /usr/bin/python &>/dev/null
echo $key | sudo -S timedatectl set-timezone UTC
echo "# Installing CSI Linux Base Tools"
cd /tmp
rm csi_linux_base.txt &>/dev/null
wget https://csilinux.com/downloads/csi_linux_base.txt -O csi_linux_base.txt
dos2unix csi_linux_base.txt
mapfile -t csi_linux_base < <(grep -vE "^\s*#|^$" csi_linux_base.txt | sed -e 's/#.*//')
install_packages csi_linux_base
# installed_packages_desc csi_linux_base
echo "Installing additional system tools..."
cd /tmp
if ! which calibre > /dev/null; then
echo "# Installing calibre"
echo $key | sudo -S -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | bash
fi
if ! which onlyoffice-desktopeditors > /dev/null; then
wget https://download.onlyoffice.com/install/desktop/editors/linux/onlyoffice-desktopeditors_amd64.deb
echo $key | sudo -S DEBIAN_FRONTEND=noninteractive apt-get install -y ./onlyoffice-desktopeditors_amd64.deb
fi
echo "Setting up media tools..."
if ! which xnview > /dev/null; then
wget https://download.xnview.com/XnViewMP-linux-x64.deb
echo $key | sudo -S DEBIAN_FRONTEND=noninteractive apt-get install -y ./XnViewMP-linux-x64.deb
fi
if ! which zenmap > /dev/null; then
wget http://archive.ubuntu.com/ubuntu/pool/universe/n/nmap/zenmap_7.94+git20230807.3be01efb1+dfsg-4_all.deb
echo $key | sudo -S DEBIAN_FRONTEND=noninteractive apt-get install -y ./zenmap_7.94+git20230807.3be01efb1+dfsg-4_all.deb
fi
# cis_lvl_1 $key
echo $key | sudo -S ssh-keygen -A
reset_DNS
sudo -k
;;
"csi-linux-themes")
cd /tmp
backup_dirct="/tmp/restorecsitheme"
backup_file_namect="csitools_theme"
archive_pathct="$backup_dirct/$backup_file_namect.7z"
echo "$key" | sudo -S DEBIAN_FRONTEND=noninteractive apt install aria2 -y &>/dev/null
echo "Preparing for the CSI Theme download..."
echo "$key" | sudo -S rm -rf "$backup_dirctct" # Remove the entire backup directory
echo "$key" | sudo -S mkdir -p "$backup_dirct"
echo "$key" | sudo -S chmod 777 "$backup_dirct" # Set full permissions temporarily for download
echo "Downloading the CSI Theme..."
if aria2c -x3 -k1M "https://csilinux.com/downloads/$backup_file_namect.7z" -d "$backup_dirct" -o "$backup_file_namect.7z"; then
echo "Download successful."
echo "# Installing the CSI Theme..."
if restore_backup_to_root "$backup_dirct" "$backup_file_namect"; then
echo "The CSI Theme restored successfully."
echo "Setting permissions and configurations for the CSI Theme..."
echo "$key" | sudo -S chown csi:csi -R /home/csi/
echo "The CSI Theme installation and configuration completed successfully."
else
echo "Failed to restore the CSI Theme from the backup."
fi
else
echo "Failed to download CSI Tools."
return 1 # Download failed
fi
rm csi_linux_themes.txt &>/dev/null
wget https://csilinux.com/downloads/csi_linux_themes.txt -O csi_linux_themes.txt
dos2unix csi_linux_themes.txt
mapfile -t csi_linux_themes < <(grep -vE "^\s*#|^$" csi_linux_themes.txt | sed -e 's/#.*//')
install_packages csi_linux_themes
# installed_packages_desc csi_linux_themes
reset_DNS
echo "# Configuring Background"
update_xfce_wallpapers "/opt/csitools/wallpaper/CSI-Linux-Dark.jpg"
echo "Doing Grub stuff..."
echo $key | sudo -S "/sbin/modprobe zfs"
if echo $key | sudo -S grep -q "GRUB_DISABLE_OS_PROBER=false" /etc/default/grub; then
echo $key | sudo -S sed -i 's/#GRUB_DISABLE_OS_PROBER=false/GRUB_DISABLE_OS_PROBER=false/g' /etc/default/grub
echo "Grub is already configured for os-probe"
fi
echo $key | sudo -S sed -i '/recordfail_broken=/{s/1/0/}' /etc/grub.d/00_header
echo $key | sudo -S update-grub
PLYMOUTH_THEME_PATH="/usr/share/plymouth/themes/vortex-ubuntu/vortex-ubuntu.plymouth"
if [ -f "$PLYMOUTH_THEME_PATH" ]; then
echo $key | sudo -S update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth "$PLYMOUTH_THEME_PATH" 100 &> /dev/null
echo $key | sudo -S update-alternatives --set default.plymouth "$PLYMOUTH_THEME_PATH"
else
echo "Plymouth theme not found: $PLYMOUTH_THEME_PATH"
fi
echo $key | sudo -S update-initramfs -u
sudo -k
;;
"os-update")
echo "Updating operating system..."
cd /tmp
rm csi_os_update.txt &>/dev/null
wget https://csilinux.com/downloads/csi_os_update.txt -O csi_os_update.txt
dos2unix csi_os_update.txt
mapfile -t csi_os_update < <(grep -vE "^\s*#|^$" csi_os_update.txt | sed -e 's/#.*//')