-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash.py
31 lines (23 loc) · 1.04 KB
/
bash.py
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
import re
import sys
def deobfuscate_bash_script(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as f:
obfuscated_content = f.read()
# Mendeteksi urutan escape dan mengonversinya
def decode_escape_sequences(match):
return bytes.fromhex(match.group(0).replace("\\x", "")).decode('utf-8', errors='ignore')
# Mengganti urutan escape hex
deobfuscated_content = re.sub(r'(\\x[0-9A-Fa-f]{2})+', decode_escape_sequences, obfuscated_content)
# Menyimpan hasil deobfuscate ke output file
with open(output_file, 'w', encoding='utf-8') as f:
f.write(deobfuscated_content)
print(f"Deobfuscation selesai, hasil disimpan di {output_file}")
# Mengecek apakah argumen input dan output telah diberikan
if len(sys.argv) != 3:
print("Usage: python3 deobfuscate_bash.py <input_file> <output_file>")
sys.exit(1)
# Mendapatkan nama file input dan output dari argumen
input_file = sys.argv[1]
output_file = sys.argv[2]
# Menjalankan deobfuscation
deobfuscate_bash_script(input_file, output_file)