-
Notifications
You must be signed in to change notification settings - Fork 3
/
package
executable file
·158 lines (140 loc) · 3.31 KB
/
package
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
#!/bin/bash
TEMPDIR=$(mktemp -d package-cshell.XXXXXXXXXX)
trap "rm -rf $TEMPDIR" EXIT
echo '#!/bin/bash' > $TEMPDIR/frida-cshell
echo 'SCRIPT=$(cat <<EOF' >> $TEMPDIR/frida-cshell
gzip -c frida-cshell.js | base64 >> $TEMPDIR/frida-cshell
echo 'EOF' >> $TEMPDIR/frida-cshell
echo ')' >> $TEMPDIR/frida-cshell
cat <<EOF >> $TEMPDIR/frida-cshell
debug=
file=
name=
pid=
show_help () {
echo Usage
echo " \$0 [OPTION?]"
echo
echo Help Options:
echo " -h, show help options"
echo
echo Application Options:
echo " -f spawn FILE"
echo " -n attach to NAME"
echo " -p attach to PID"
echo " -d enable debug mode"
echo
}
if [[ "\$1" == "--help" ]]; then
show_help
exit 0
fi
while getopts ":f:hn:p:d" opt; do
case \$opt in
f)
file=\$OPTARG
;;
h)
help=true
;;
n)
name=\$OPTARG
;;
p)
pid=\$OPTARG
;;
d)
debug=true
;;
:)
echo "Option - \$OPTARG requires an argument."
exit 1
;;
*)
echo "Invalid option: - \$OPTARG"
show_help
exit 1
;;
esac
done
if [ \${help} ]; then
show_help
exit 0
fi
FRIDA_INJECT="\${FRIDA_INJECT:-frida-inject}"
if ! command -v \$FRIDA_INJECT &> /dev/null
then
echo "\$FRIDA_INJECT could not be found. Try setting set FRIDA_INJECT environment variable"
exit 1
fi
if [ \${debug} ]; then
opt="{\"debug\":true}"
else
opt="{}"
fi
if [ -z \${file} ] && [ -z \${name} ] && [ -z \${pid} ]; then
echo "file, name or pid must be specified";
show_help
exit 1
fi
FILE=\$(mktemp /tmp/frida-cshell.XXXXXXXXXX)
trap "rm -f \$FILE" EXIT
if command -v base64 &> /dev/null; then
echo "\$SCRIPT" | base64 -d | gzip -d > \$FILE
else
BASE64=\$(mktemp /tmp/frida-cshell-base64.XXXXXXXXXX)
cat <<EOI > \$BASE64
#!/usr/bin/awk -f
function decode64()
{
b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
while( getline < "/dev/stdin" )
{
l = length( \\\$0 );
for( i = 1; i <= l; ++i )
{
c = index( b64, substr( \\\$0, i, 1 ) );
if( c-- )
{
for( b = 0; b < 6; ++b )
{
o = o*2+int( c/32 );
c = (c*2)%64;
if( ++obc == 8 )
{
printf "%c", o;
obc = 0;
o = 0;
}
}
}
}
}
}
BEGIN { decode64() }
EOI
trap "rm -f \$BASE64" EXIT
echo "\$SCRIPT" | awk -f "\$BASE64" | gzip -d > \$FILE
fi
if [ \${file} ]; then
if [ \${name} ] || [ \${pid}]; then
echo "file, name and pid are mutually exclusive"
exit 1
fi
exec \$FRIDA_INJECT --interactive -s \$FILE -P \$opt -f \$file
elif [ \${name} ]; then
if [ \${file} ] || [ \${pid}]; then
echo "file, name and pid are mutually exclusive"
exit 1
fi
exec \$FRIDA_INJECT --interactive -s \$FILE -P \$opt -n \$name
elif [ \${pid} ]; then
if [ \${file} ] || [ \${name}]; then
echo "file, name and pid are mutually exclusive"
exit 1
fi
exec \$FRIDA_INJECT --interactive -s \$FILE -P \$opt -p \$pid
fi
EOF
cp $TEMPDIR/frida-cshell ./frida-cshell
chmod +x ./frida-cshell