-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_offset.sh
More file actions
executable file
·70 lines (63 loc) · 1.48 KB
/
memory_offset.sh
File metadata and controls
executable file
·70 lines (63 loc) · 1.48 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
#!/bin/bash
# Boris P.
# Like :
# include<stdio.h>
#
# typedef struct _align
# {
# double dbl;
# int i;
# char ch[3];
# char c;
# } align;
#
# int main(void){
# printf("align %zu\n", sizeof(align));
# return 0;
# }
#
_create_file(){
FILE=$(base64 /dev/urandom |tr -d '+/'|head -c6)
FILE+='.c'
printf "[+] %s created\n" "$FILE"
echo -e "#include <stdio.h>\n\nvoid offset(void){\nchar small[17];\ngets(small);\n}\nint main(void){\noffset();\nreturn 0;\n}" > "$FILE"
}
_change_lame(){
local sizeOfArray="$1"
sed -ri 's/small\[.*\]/small\['"$sizeOfArray"'\]/' "$FILE"
}
_compile_lame(){
gcc -ggdb -fno-stack-protector -z execstack "$FILE" -o "${FILE%.*}" 2> /dev/null
}
_result(){
tput cup $X 0 ; printf "[+] Memory offset => %s\n" "$1"
}
_gdb_sub(){
SUB=$(gdb ./"${FILE%.*}" <<< "disassemble offset" |awk '/sub/{print $4}')
[ -z "$FIRST_SUB" ] && \
FIRST_SUB="$SUB" || { \
: $((C++))
_result $C
[ "$FIRST_SUB" != "$SUB" ] && { \
_exit_clean
}
}
echo -n ''
}
_exit_clean(){
rm "$FILE" "${FILE%.*}"
printf "[+] %s and %s have been removed" "$FILE" "${FILE%.*}"
exit 0
}
########## MAIN #############
clear
trap _exit_clean SIGINT SIGKILL
_create_file
printf '\033[6n';read -sdR X; X=${X#*[} ; X=${X%;*}
echo "[+] Calcul in progress"
C=0
for size_array in {1..64}; do
_change_lame "$size_array"
_compile_lame
_gdb_sub "$size_array"
done