-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmbytes.sh
More file actions
165 lines (134 loc) · 4.4 KB
/
Copy pathmbytes.sh
File metadata and controls
165 lines (134 loc) · 4.4 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
#!/usr/bin/env bash
# ==============================
# MBYTES 2.0
# Author: Irving SA (Comandre-ex)
# Description: File Magic Number Analyzer & Modifier
# ==============================
VERSION="2.0"
# ===== Colors =====
greenColour="\e[0;32m\033[1m"
endColour="\033[0m\e[0m"
redColour="\e[0;31m\033[1m"
blueColour="\e[0;34m\033[1m"
yellowColour="\e[0;33m\033[1m"
grayColour="\e[0;37m\033[1m"
# ===== Magic Numbers =====
declare -A magic_numbers_list=(
["JPEG"]="FFD8FF"
["PNG"]="89504E470D0A1A0A"
["GIF"]="47494638"
["PDF"]="25504446"
["ZIP"]="504B0304"
["RAR"]="526172211A0700"
["MP3"]="FFFB"
["WAV"]="52494646"
["EXE"]="4D5A"
["TAR"]="7573746172"
)
trap ctrl_c INT
tput civis
function ctrl_c() {
echo -e "\n${grayColour}Exiting...${endColour}"
tput cnorm
exit 0
}
# ===== Backup =====
function backup_file() {
cp "$file" "$file.bak"
echo -e "${blueColour}[+] Backup creado: $file.bak${endColour}"
}
# ===== Detect =====
function detect_magic() {
if [[ ! -f "$file" ]]; then
echo -e "${redColour}[-] Archivo no encontrado${endColour}"
exit 1
fi
header=$(xxd -p -l 8 "$file" | tr '[:lower:]' '[:upper:]')
for type in "${!magic_numbers_list[@]}"; do
if [[ $header == ${magic_numbers_list[$type]}* ]]; then
echo -e "${greenColour}[+] Tipo detectado: $type${endColour}"
return
fi
done
echo -e "${yellowColour}[!] Tipo desconocido${endColour}"
}
# ===== Modify =====
function modify_magic() {
if [[ -n "$custom_magic" ]]; then
hex_string=$custom_magic
else
hex_string=${magic_numbers_list[$type]}
fi
if [[ -z "$hex_string" ]]; then
echo -e "${redColour}[-] Tipo no soportado${endColour}"
exit 1
fi
formatted_hex=""
for (( i=0; i<${#hex_string}; i+=2 )); do
formatted_hex+="\x${hex_string:i:2}"
done
backup_file
echo -ne "$formatted_hex" | dd of="$file" bs=1 count=$((${#hex_string}/2)) conv=notrunc 2>/dev/null
echo -e "${greenColour}[+] Magic number modificado correctamente${endColour}"
}
# ===== Scan Directory =====
function scan_directory() {
echo -e "${yellowColour}[+] Escaneando directorio...${endColour}"
for f in *; do
[[ -f "$f" ]] || continue
header=$(xxd -p -l 4 "$f" 2>/dev/null | tr '[:lower:]' '[:upper:]')
extension="${f##*.}"
case $extension in
jpg|jpeg) expected="FFD8FF" ;;
png) expected="89504E47" ;;
pdf) expected="25504446" ;;
zip) expected="504B0304" ;;
*) continue ;;
esac
if [[ $header != $expected* ]]; then
echo -e "${redColour}[!] Posible archivo camuflado: $f${endColour}"
fi
done
}
# ===== Help =====
function helpPanel() {
echo -e "\n${blueColour}MagicBytes v${VERSION}${endColour} — Magic Number Analyzer & Modifier\n"
echo -e "${grayColour}Uso:${endColour} $0 [opciones]\n"
echo -e " ${yellowColour}-f${endColour} <archivo> Archivo objetivo"
echo -e " ${yellowColour}-t${endColour} <tipo> Tipo de magic number a inyectar (ej: JPEG, PNG, PDF)"
echo -e " ${yellowColour}-m${endColour} <hex> Magic number hexadecimal personalizado (ej: FFD8FF)"
echo -e " ${yellowColour}-d${endColour} Detectar el tipo real del archivo"
echo -e " ${yellowColour}-s${endColour} Escanear directorio actual (extension vs magic number)"
echo -e " ${yellowColour}-h${endColour} Mostrar este panel de ayuda\n"
echo -e "${grayColour}Tipos soportados:${endColour} JPEG PNG GIF PDF ZIP RAR MP3 WAV EXE TAR\n"
echo -e "${grayColour}Ejemplos:${endColour}"
echo -e " $0 -d -f archivo.jpg"
echo -e " $0 -f shell.php -t JPEG"
echo -e " $0 -f archivo.bin -m FFD8FFE0"
echo -e " $0 -s\n"
}
# ===== Arguments =====
while getopts ":f:t:m:dsh" arg; do
case $arg in
f) file=$OPTARG ;;
t) type=$OPTARG ;;
m) custom_magic=$OPTARG ;;
d) detect=1 ;;
s) scan=1 ;;
h) helpPanel; exit 0 ;;
esac
done
if [[ $scan == 1 ]]; then
scan_directory
elif [[ $detect == 1 ]]; then
if [[ -z "$file" ]]; then
echo -e "${redColour}[-] Debes especificar un archivo con -f${endColour}"
exit 1
fi
detect_magic
elif [[ -n "$file" && (-n "$type" || -n "$custom_magic") ]]; then
modify_magic
else
helpPanel
fi
tput cnorm