-
Notifications
You must be signed in to change notification settings - Fork 0
/
1gadgetsarmy
executable file
·112 lines (99 loc) · 3.2 KB
/
1gadgetsarmy
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
#!/bin/bash
# This shell script takes an input file and searches for all the magic gadgets within it.
# It then proceeds to call the provided Python script with each discovered magic gadget offset as an argument.
display_help() {
echo "Usage: $(basename "$0") [OPTIONS] [FILE]"
echo "shell script that given a file in input searches all the magic_gadgets inside it and then"
echo "calls the python script you provided in input with as argument each magic_gadget's offset it has found"
echo "Options:"
echo " -h, --help Display this help message"
echo " -s, --script python script file script file to be called with provided arg. DEFAULT: 'script.py'"
echo " -r, --remote runs the python script appending also the \"REMOTE\" argument. DEFAULT: false"
echo " -l, --log appends the output of one_gadget into the file lotta1gadgets. DEFUALT: false"
}
# default script file is named "script.py"
script_file="./script.py"
log=false
onegadget_out_file="./1gadgetsarmy"
input_file=""
remote=false
if [ "$#" -le 0 ]; then
echo "too few arguments!"
display_help
exit -1
fi
# Parsing options
while [ "$#" -gt 0 ] && [[ "$1" == -* ]]; do
case "$1" in
-h | --help)
display_help
exit 0
;;
-s | --script)
if [ ! -n "$2" -o ! -e "$2" ]; then
echo "script file not found"
exit -1
else
script_file="$2"
shift
fi
;;
-r | --remote)
remote=true
;;
-l | --log)
log=true
;;
*)
echo "Invalid option: $1" >&2
display_help
exit -1
;;
esac
shift
done
# gets libc in input
if [ ! -n "$1" -o ! -e "$1" ]; then
echo "input file not found"
exit -1
else
input_file="$1"
fi
#running one_gadget and check if everything went good otherwise display error
one_gadget_output=$(one_gadget "$input_file")
if [ ! $? -eq 0 ]; then
echo "$one_gadget_output"
exit -1
fi
#outputting command to onegadgets_out_file if logging was set to true in cmd line arguments
if $log; then
echo "$one_gadget_output" > "$onegadget_out_file"
fi
#filtering one_gadget output and getting only the offsets of the magic gadgets
magic_gadgets=$(echo "$one_gadget_output" | awk '{
#awk filter for one_gadgte typical output
# print first column of all lines in which first coulmn is an hex number
if($1 ~ /^0x[a-z1-9A-F]+/)
print $1;
}'
)
# for each magic_gadget found, run the script with the magic_gadget as argument
counter=0
nlines=$(echo "$magic_gadgets" | wc -l)-1
while IFS= read -r magic_gadget; do
echo -e "[\e[31m1GADGETARMY\e[0m]: using magic_gadget $magic_gadget"
if $remote; then
python3 "$script_file" MAGIC_GADGET="$magic_gadget" REMOTE < /dev/tty
else
python3 "$script_file" MAGIC_GADGET="$magic_gadget" < /dev/tty
fi
if [[ $counter -lt $nlines ]]; then
echo -e -n "[\e[31m1GADGETARMY\e[0m]: script with magic_gadget finished, continue with next one? (Y/N) [Y]: "
read -n 1 -r char < /dev/tty
echo ""
if [ "$char" != 'Y' -a "$char" != 'y' -a "$char" != '' ]; then
break
fi
counter=$counter+1
fi
done <<< "$magic_gadgets"