forked from cSploit/android.native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·409 lines (312 loc) · 10.6 KB
/
build.sh
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#!/bin/bash
oldpwd=$(pwd)
UPDATE_SERVER="http://update.csploit.org/"
RUBY_VERSION=1.0.0
CORE_VERSION=1.0.1
DEBUG=false
die() {
echo "FAILED"
echo "--------------------------------------------------"
echo "an error occurred while creating the $pkg package."
echo "see build.log for more info"
echo "--------------------------------------------------"
cd "${oldpwd}"
exit 1
}
test -d "${oldpwd}" || die
exec 3> build.log
pkg="init"
nmap_data="nmap-mac-prefixes
nmap-payloads
nmap-rpc
nmap-os-db
nmap-protocols
nmap-services
nmap-service-probes"
ettercap_share="etter.mime
etter.filter.kill
etter.services
etterfilter.cnt
etter.fields
etter.conf
etter.ssl.crt
etter.filter.ssh
etter.filter
etter.dns
etterfilter.tbl
etter.finger.os
etterlog.dtd
etter.filter.examples
etter.filter.pcre
etter.finger.mac"
ndk_empty_scripts="build-host-executable.mk
build-host-shared-library.mk
build-host-static-library.mk"
directories="/enc/trans/
/enc/
/io/
/digest/
/dl/
/json/ext/
/mathn/
/racc/
/"
apis="9
16"
abis="armeabi
armeabi-v7a
arm64-v8a"
check_ndk() {
ndk_build=$(which ndk-build) || \
(echo "android NDK not found, please ensure that it's directory is in your PATH"; die)
ndk_dir=$(dirname "${ndk_build}")
ndk_dir="${ndk_dir}/build/core/"
sudo=""
test -w "${ndk_dir}" || sudo="sudo"
for s in $ndk_empty_scripts; do
if [ ! -f "${ndk_dir}${s}" ]; then
{ $sudo touch "${ndk_dir}${s}" 2>&1 | tee >(cat - >&3) ;} || die
fi
done
}
delete_core_packages() {
find ../dist/ -name "core*" -type f -exec rm "{}" \; 2>&3
}
delete_ruby_packages() {
find ../dist/ -name "ruby*" -type f -exec rm "{}" \; 2>&3
}
build() {
app_root=$(readlink -f ../)
ndk_args=""
test "x$DEBUG" == "xtrue" && ndk_args+="APP_OPTIM=debug NDK_DEBUG=1 " # debug
ndk_args+="APP_PLATFORM=android-${api} " # force android api level
ndk_args+="NDK_OUT=${app_root}/obj/android-${api} " # objects directory
echo
echo -n "[$pkg] compiling for android-${api}..."
cpus=$(grep -E "^processor" /proc/cpuinfo | wc -l)
echo "running: ndk-build $ndk_args -j${cpus} $@" >&3
ndk-build $ndk_args -j${cpus} $@ >&3 2>&1 || die
echo "ok"
}
select_lower_api() {
api="0"
for _api in $apis; do
test ${_api} -lt ${api} -o ${api} -eq 0 && api="${_api}"
done
}
# this is a temporary fix to https://github.com/android-ndk/ndk/issues/56
# $1: path to translate
# $2: target ABI
from_armeabi_to_another_abi() {
case $2 in
arm64-*)
sed -E 's/arm-linux-androideabi-[0-9.]+/aarch64-linux-android-4.9/;s/arm-linux-androideabi-/aarch64-linux-android-/' <<<$1
;;
*)
echo $1
;;
esac
}
build_jni_libs() {
app_root=$(readlink -f ../)
strip=$( ndk-which strip ) 2>&3 || die
build cSploitCommon cSploitClient
echo -ne "[jni] installing into libs..."
for abi in $abis; do
objs="${app_root}/obj/android-${api}/local/${abi}"
bins=$(readlink -fm ../libs/${abi})
mkdir -p "${bins}"
strip_abi=$(from_armeabi_to_another_abi $strip $abi)
for lib in cSploitCommon cSploitClient; do
install -p "${objs}/lib${lib}.so" "${bins}/lib${lib}.so" >&3 2>&1 || die
${strip_abi} --strip-unneeded "${bins}/lib${lib}.so" >&3 2>&1 || die
done
done
echo "ok"
}
copy_jni_libs() {
select_lower_api
echo -n "[jni] copying libs to java project..."
for abi in $abis; do
javaLibs=$(readlink -fm ../src/main/jniLibs/${abi}/)
bins=$(readlink -fm ../libs/${abi})
{ test -d "${javaLibs}" || mkdir -p "${javaLibs}" ;} >&3 2>&1 || die
cp "${bins}/libcSploitClient.so" "${bins}/libcSploitCommon.so" "${javaLibs}" >&3 2>&1 || die
done
echo "ok"
}
pack_core() {
echo
echo "[core] building android${api}.${abi} package"
jni_root=$(readlink -f ./)
out="/tmp/cSploitCore"
bins=$(readlink -f ../libs/${abi})
rm -rf "${out}" >&3 2>&1 || die
mkdir -p "${out}" >&3 2>&1 || die
echo -n "[core] - copying programs..."
for prog in cSploitd known-issues; do
cp "${bins}/${prog}" "${out}/" >&3 2>&1 || die
done
for tool in arpspoof tcpdump ettercap hydra nmap fusemounts network-radar; do
mkdir -p "${out}/tools/$tool" >&3 2>&1
cp "${bins}/$tool" "${out}/tools/$tool/$tool" >&3 2>&1 || die
done
echo -ne "ok\n[core] - copying libraries..."
mkdir -p "${out}/handlers" >&3 2>&1 || die
for lib in ${bins}/libhandlers_*.so; do
lib=$(basename "$lib")
cp "${bins}/${lib}" "${out}/handlers/${lib:12}" >&3 2>&1 || die
done
for ec_lib in ${bins}/libec_*.so; do
ec_lib=$(basename "$ec_lib")
cp "${bins}/$ec_lib" "${out}/tools/ettercap/${ec_lib:3}" >&3 2>&1 || die
done
echo -ne "ok\n[core] - copying scripts..."
rsync -aq --include "*/" --include "*.lua" --exclude "*" "${jni_root}/nmap/" "${out}/tools/nmap/" >&3 2>&1 || die
rsync -aq "${jni_root}/nmap/scripts/" "${out}/tools/nmap/scripts/" >&3 2>&1 || die
cp "${jni_root}/known-issues/start_daemon.sh" "${out}/"
chmod 700 "${out}/start_daemon.sh"
echo -ne "ok\n[core] - copying configuration/database files..."
for f in $nmap_data; do
cp "${jni_root}/nmap/$f" "${out}/tools/nmap/" >&3 2>&1 || die
done
# strip out useless data
sed -i -E '/^unknown/d;/^\s*#/d' "${out}/tools/nmap/nmap-services" >&3 2>&1 || die
mkdir -p "${out}/tools/ettercap/share" || die
for f in $ettercap_share; do
cp ${jni_root}/ettercap*/share/$f "${out}/tools/ettercap/share/" >&3 2>&1 || die
done
echo "android:DEADBEEF" > "${out}/users" 2>&3 || die
echo -ne "ok\n[core] - creating archive..."
(cd ${out} && tar -cJf ../core.tar.xz ./) >&3 2>&1 || die
rm -rf "${out}" >&3 2>&1 || die
if [ ! -d ../dist ]; then
mkdir ../dist >&3 2>&1 || die
fi
core_basename="core-v${CORE_VERSION}+android${api}.${abi}"
core_path="../dist/${core_basename}.tar.xz"
core_json="../dist/${core_basename}.json"
mv /tmp/core.tar.xz $core_path >&3 2>&1 || die
echo "ok"
}
build_cores() {
check_ndk
delete_core_packages
for api in $apis; do
build
for abi in $abis; do
pack_core
done
done
}
build_ruby() {
check_ndk
delete_ruby_packages
for api in $apis; do
build
for abi in $abis; do
pack_ruby
done
done
}
build_jni() {
check_ndk
select_lower_api
build_jni_libs
}
pack_ruby() {
system_ruby=""
echo
echo "[ruby] building android${api}.${abi} package"
for bin in ruby ruby19; do
bin=$(which "$bin")
test -n "$bin" && { $bin -v | grep -q "1.9" ;} && system_ruby="${bin}"
done
test -n "${system_ruby}" || { echo "ruby 1.9 not found" >&2; echo "ruby 1.9 not found" >&3; die ;}
echo -n "[ruby] - creating root..."
rm -rf rubyroot >&3 2>&1 || die
rubyroot=$(readlink -f rubyroot) || die
echo "rubyroot='${rubyroot}'" >&3
test -n "${rubyroot}" || die
for d in $directories; do
echo "making \`${rubyroot}/lib/ruby/1.9.1/arm-linux-androideabi$d'" >&3
mkdir -p "${rubyroot}/lib/ruby/1.9.1/arm-linux-androideabi$d" >&3 2>&1 || die
done
mkdir -p "${rubyroot}/lib/ruby/site_ruby/1.9.1/arm-linux-androideabi" || die
mkdir -p "${rubyroot}/lib/ruby/vendor_ruby/1.9.1/arm-linux-androideabi" || die
mkdir -p "${rubyroot}/bin" >&3 2>&1 || die
mkdir -p "${rubyroot}/etc" >&3 2>&1 || die
mkdir -p "${rubyroot}/home/ruby" >&3 2>&1 || die
echo -ne "ok\n[ruby] - disabling documentation when installing gems..."
echo -e 'install: --no-document\nupdate: --no-document' > "${rubyroot}/etc/gemrc" 2>&3 || die
cp "${rubyroot}/etc/gemrc" "${rubyroot}/home/ruby/.gemrc" || die
echo -ne "ok\n[ruby] - copying binaries..."
rsync -va ruby/bin/ rubyroot/bin/ >&3 2>&1 || die
for prog in clear infocmp tabs tic toe tput; do
cp "../libs/${abi}/${prog}" "${rubyroot}/bin/" >&3 2>&1 || die
done
cp "../libs/${abi}/ruby" "${rubyroot}/bin/" >&3 2>&1 || die
echo -ne "ok\n[ruby] - copying libraries..."
for d in $directories; do
base="libRUBY${d//\//_}"
search_name="${base}*.so"
dest="${oldpwd}/rubyroot/lib/ruby/1.9.1/arm-linux-androideabi$d"
find "${oldpwd}/../libs/${abi}/" -name "${search_name}" | while read file; do
newname=$(basename "$file")
newname=${newname/$base/}
echo "copying \`${file}' to \`${dest}${newname}'" >&3
cp "$file" "${dest}${newname}" >&3 2>&1|| die
done
done
echo -ne "ok\n[ruby] - copying script libraries..."
cd ruby/lib >&3 2>&1 || die
( find . -name "*.rb" -print0 | rsync -va --files-from=- --from0 ./ ../../rubyroot/lib/ruby/1.9.1/ ) >&3 2>&1 || die
cd ../.ext/common >&3 2>&1 || die
( find . -name "*.rb" -print0 | rsync -va --files-from=- --from0 ./ ../../../rubyroot/lib/ruby/1.9.1/ ) >&3 2>&1 || die
cp "${oldpwd}/ruby/rbconfig.rb" "${rubyroot}/lib/ruby/1.9.1/arm-linux-androideabi/" >&3 2>&1 || die
echo -ne "ok\n[ruby] - updating rubygems..."
echo -e "require 'arm-linux-androideabi/rbconfig'" > "${rubyroot}/lib/ruby/1.9.1/rbconfig.rb" 2>&3 || die
unset RUBYOPT
export RUBYLIB="${rubyroot}/lib/ruby/site_ruby/1.9.1:${rubyroot}/lib/ruby/site_ruby:${rubyroot}/lib/ruby/vendor_ruby/1.9.1:${rubyroot}/lib/ruby/vendor_ruby:${rubyroot}/lib/ruby/1.9.1"
export HOME="${rubyroot}/home/ruby"
export GEM_HOME="${rubyroot}/lib/ruby/gems/1.9.1"
echo "RUBYLIB=${RUBYLIB}" >&3
mv "${rubyroot}/bin/ruby" "${rubyroot}/bin/ruby.arm" >&3 2>&1 || die
ln -s "${system_ruby}" "${rubyroot}/bin/ruby" >&3 2>&1 || die
$system_ruby "${rubyroot}/bin/gem" "update" "--system" "--no-ri" "--no-rdoc" "-V" >&3 2>&1 || die
echo -ne "ok\n[ruby] - installing bundler..."
$system_ruby "${rubyroot}/bin/gem" "install" "bundler" "--no-ri" "--no-rdoc" "--bindir=${rubyroot}/bin" "-V" >&3 2>&1 || die
rm "${rubyroot}/bin/ruby" >&3 2>&1 || die
rm "${rubyroot}/lib/ruby/1.9.1/rbconfig.rb" >&3 2>&1 || die
rm -rf "${rubyroot}/home/ruby/.gem" >&3 2>&1 || die
mv "${rubyroot}/bin/ruby.arm" "${rubyroot}/bin/ruby" >&3 2>&1 || die
cd "${rubyroot}"
sed -i "1s,^#!${rubyroot}/bin/ruby,#!/usr/bin/env ruby," $(find . -type f) >&3 2>&1 || die
echo -ne "ok\n[ruby] - creating archive..."
cd "${oldpwd}"
mkdir -p ../dist >&3 2>&1 || die
cd rubyroot
tar -cJf "../../dist/ruby-${RUBY_VERSION}+android${api}.${abi}.tar.xz" . >&3 2>&1 || die
cd "${oldpwd}"
rm -rf rubyroot
echo "ok"
}
pkg="jni"
test "$#" -eq 0 || pkg=$1
case $pkg in
ruby) RUBY_VERSION=${2:-$RUBY_VERSION}
build_ruby
;;
core|cores) CORE_VERSION=${2:-$CORE_VERSION}
build_cores
copy_jni_libs
;;
jni) build_jni
copy_jni_libs
;;
*)
scriptname=$(basename "$0")
echo -e "Usage: $scriptname <task> [version]\n\ntask must be one of:\n - ruby : build the ruby archive\n - cores: build native tools used by cSploit (default)" >&2
;;
esac
exit 0