-
Notifications
You must be signed in to change notification settings - Fork 60
/
cuckooautoinstall.bash
287 lines (237 loc) · 8.68 KB
/
cuckooautoinstall.bash
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
#!/bin/bash
# CuckooAutoInstall
# Copyright (C) 2014-2015 David Reguera García - [email protected]
# Copyright (C) 2015 David Francos Cuartero - [email protected]
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
source /etc/os-release
# Configuration variables. You can override these in config.
SUDO="sudo"
TMPDIR=$(mktemp -d)
RELEASE=$(lsb_release -cs)
CUCKOO_USER="cuckoo"
CUSTOM_PKGS=""
ORIG_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
VOLATILITY_URL="http://downloads.volatilityfoundation.org/releases/2.4/volatility-2.4.tar.gz"
VIRTUALBOX_REP="deb http://download.virtualbox.org/virtualbox/debian $RELEASE contrib"
CUCKOO_REPO='https://github.com/cuckoobox/cuckoo'
YARA_REPO="https://github.com/plusvic/yara"
JANSSON_REPO="https://github.com/akheron/jansson"
LOG=$(mktemp)
UPGRADE=false
declare -a packages
declare -a python_packages
packages["debian"]="python-pip python-sqlalchemy mongodb python-bson python-dpkt python-jinja2 python-magic python-gridfs python-libvirt python-bottle python-pefile python-chardet git build-essential autoconf automake libtool dh-autoreconf libcurl4-gnutls-dev libmagic-dev python-dev tcpdump libcap2-bin virtualbox dkms python-pyrex"
packages["ubuntu"]="python-pip python-sqlalchemy mongodb python-bson python-dpkt python-jinja2 python-magic python-gridfs python-libvirt python-bottle python-pefile python-chardet git build-essential autoconf automake libtool dh-autoreconf libcurl4-gnutls-dev libmagic-dev python-dev tcpdump libcap2-bin virtualbox dkms python-pyrex"
python_packages=(pymongo django pydeep maec py3compat lxml cybox distorm3 pycrypto)
# Pretty icons
log_icon="\e[31m✓\e[0m"
log_icon_ok="\e[32m✓\e[0m"
log_icon_nok="\e[31m✗\e[0m"
# -
print_copy(){
cat <<EO
┌─────────────────────────────────────────────────────────┐
│ CuckooAutoInstall 0.2 │
│ David Reguera García - Dreg <[email protected]> │
│ David Francos Cuartero - XayOn <[email protected]> │
│ Buguroo Offensive Security - 2015 │
└─────────────────────────────────────────────────────────┘
EO
}
check_viability(){
[[ $UID != 0 ]] && {
type -f $SUDO || {
echo "You're not root and you don't have $SUDO, please become root or install $SUDO before executing $0"
exit
}
} || {
SUDO=""
}
[[ ! -e /etc/debian_version ]] && {
echo "This script currently works only on debian-based (debian, ubuntu...) distros"
exit 1
}
}
print_help(){
cat <<EOH
Usage: $0 [--verbose|-v] [--help|-h] [--upgrade|-u]
--verbose Print output to stdout instead of temp logfile
--help This help menu
--upgrade Use newer volatility, yara and jansson versions (install from source)
EOH
exit 1
}
setopts(){
optspec=":hvu-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
help) print_help ;;
upgrade) UPGRADE=true ;;
verbose) LOG=/dev/stdout ;;
esac;;
h) print_help ;;
v) LOG=/dev/stdout;;
u) UPGRADE=true;;
esac
done
}
run_and_log(){
$1 &> ${LOG} && {
_log_icon=$log_icon_ok
} || {
_log_icon=$log_icon_nok
exit_=1
}
echo -e "${_log_icon} ${2}"
[[ $exit_ ]] && { echo -e "\t -> ${_log_icon} $3"; exit; }
}
clone_repos(){
git clone ${JANSSON_REPO}
git clone ${YARA_REPO}
return 0
}
cdcuckoo(){
eval cd ~${CUCKOO_USER}
return 0
}
create_cuckoo_user(){
$SUDO adduser --disabled-password -gecos "" ${CUCKOO_USER}
$SUDO usermod -G vboxusers ${CUCKOO_USER}
return 0
}
clone_cuckoo(){
cdcuckoo
$SUDO git clone $CUCKOO_REPO
cd $CUCKOO_REPO
[[ $STABLE ]] && $SUDO git checkout 5231ff3a455e9c1c36239a025a1f6840029a9ed8
cd ..
$SUDO chown -R ${CUCKOO_USER}:${CUCKOO_USER} cuckoo
cd $TMPDIR
return 0
}
create_hostonly_iface(){
$SUDO vboxmanage hostonlyif create
$SUDO iptables -A FORWARD -o eth0 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT
$SUDO iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$SUDO iptables -A POSTROUTING -t nat -j MASQUERADE
$SUDO sysctl -w net.ipv4.ip_forward=1
return 0
}
setcap(){
$SUDO /bin/bash -c 'setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump' 2 &> /dev/null
return 0
}
fix_django_version(){
cdcuckoo
python -c "import django; from distutils.version import LooseVersion; import sys; sys.exit(LooseVersion(django.get_version()) <= LooseVersion('1.5'))" && {
egrep -i "templates = \(.*\)" cuckoo/web/web/settings.py || $SUDO sed -i '/TEMPLATE_DIRS/{ N; s/.*/TEMPLATE_DIRS = \( \("templates"\),/; }' cuckoo/web/web/settings.py
}
cd $TMPDIR
return 0
}
enable_mongodb(){
cdcuckoo
$SUDO sed -i '/\[mongodb\]/{ N; s/.*/\[mongodb\]\nenabled = yes/; }' cuckoo/conf/reporting.conf
cd $TMPDIR
return 0
}
build_jansson(){
# Not cool =(
cd ${TMPDIR}/jansson
autoreconf -vi --force
./configure
make
make check
$SUDO make install
cd ${TMPDIR}
return 0
}
build_yara(){
cd ${TMPDIR}/yara
./bootstrap.sh
$SUDO autoreconf -vi --force
./configure --enable-cuckoo --enable-magic
make
$SUDO make install
cd yara-python/
$SUDO python setup.py install
cd ${TMPDIR}
return 0
}
build_volatility(){
wget $VOLATILITY_URL
tar xvf volatility-2.4.tar.gz
cd volatility-2.4/
$SUDO python setup.py build
$SUDO python setup.py install
return 0
}
pip(){
# TODO: Calling upgrade here should be optional.
# Unless we make all of this into a virtualenv, wich seems like the
# correct way to follow
for package in ${@}; do $SUDO pip install ${package} --upgrade; done
return 0
}
prepare_virtualbox(){
cd ${TMPDIR}
echo ${VIRTUALBOX_REP} |$SUDO tee /etc/apt/sources.list.d/virtualbox.list
wget -O - https://www.virtualbox.org/download/oracle_vbox.asc | $SUDO apt-key add -
pgrep virtualbox && return 1
pgrep VBox && return 1
return 0
}
install_packages(){
$SUDO apt-get update
$SUDO apt-get install -y ${packages["${RELEASE}"]}
$SUDO apt-get install -y $CUSTOM_PKGS
$SUDO apt-get -y install
return 0
}
install_python_packages(){
pip ${python_packages[@]}
return 0
}
# Init.
print_copy
check_viability
setopts ${@}
# Load config
source config &>/dev/null
echo "Logging enabled on ${LOG}"
# If we're notupgrading to recent yara, jansson and volatility, install them as packages.
[[ $UPGRADE != true ]] && {
CUSTOM_PKGS="volatility yara python-yara libyara3 libjansson4 ${CUSTOM_PKGS}"
}
# Install packages
run_and_log prepare_virtualbox "Getting virtualbox repo ready" "Virtualbox is running, please close it"
run_and_log install_packages "Installing packages ${CUSTOM_PKGS} and ${packages[$RELEASE]}" "Something failed installing packages, please look at the log file"
# Install python packages
run_and_log install_python_packages "Installing python packages: ${python_packages[@]}" "Something failed install python packages, please look at the log file"
# Create user and clone repos
run_and_log create_cuckoo_user "Creating cuckoo user" "Could not create cuckoo user"
run_and_log clone_repos "Cloning repositories" "Could not clone repos"
run_and_log clone_cuckoo "Cloning cuckoo repository" "Failed"
# Build packages
[[ $UPGRADE == true ]] && {
run_and_log build_jansson "Building and installing jansson"
run_and_log build_yara "Building and installing yara"
run_and_log build_volatility "Installing volatility"
}
# Configuration
run_and_log fix_django_version "Fixing django problems on old versions"
run_and_log enable_mongodb "Enabling mongodb in cuckoo"
# Networking (latest, because sometimes it crashes...)
run_and_log create_hostonly_iface "Creating hostonly interface for cuckoo"
run_and_log setcap "Setting capabilities"