-
Notifications
You must be signed in to change notification settings - Fork 11
/
honeynet_setup.sh
962 lines (756 loc) · 27.5 KB
/
honeynet_setup.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
#! /bin/bash
# Used to get the architecture for the installation of ElasticSearch and Kibana:
getarchitecture(){
architecture=0
echo "Are you running on 32 bit or 64 bit architecture? Enter 32 or 64"
read architecture
if [ $architecture -eq 32 ]
then es_architecture="export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/" && kibana="https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x86.tar.gz"
elif [ $architecture -eq 64 ]
then es_architecture="export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/" && kibana="https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x64.tar.gz"
else
getarchitecture;
fi
}
getarchitecture;
HPN=$(dirname "$0")
DIR="$HPN/HoneyNet_Installer/"
# Make directories:
mkdir -p /opt/files/incoming /opt/analysis /usr/local/certs/sslcerts/ /var/www/intel /opt/cronscripts
chown nobody:nogroup /opt/files/incoming
# Copy analysis scripts:
cp $HPN/server/analysis/* /opt/analysis/ && chmod 755 /opt/analysis/* && cp -r $HPN/client /opt/
# cp webserver:
cp -r $HPN/server/flask/intel /var/www/ && chown -R www-data:www-data /var/www/intel
# Make some utilities for troubleshooting logstash when you need to add new things:
cat > /usr/bin/editlogstashconf.sh<<EOF
#!/bin/bash
sudo vim /etc/logstash/conf.d/server.conf
EOF
cat > /usr/bin/restartlogstash.sh<<EOF
#!/bin/bash
sudo service logstash restart
EOF
cat > /usr/bin/statuslogstash.sh<<EOF
#!/bin/bash
sudo service logstash status
EOF
cat > /usr/bin/taillogstashlog.sh<<EOF
#!/bin/bash
tail -f /var/log/logstash/logstash.log
EOF
cat > /usr/bin/testlogstash.sh<<EOF
#!/bin/bash
/usr/local/src/logstash-1.5.4/bin/logstash -f /etc/logstash/conf.d/client.conf --configtest
EOF
chmod 755 /usr/bin/editlogstashconf.sh
chmod 755 /usr/bin/restartlogstash.sh
chmod 755 /usr/bin/statuslogstash.sh
chmod 755 /usr/bin/taillogstashlog.sh
chmod 755 /usr/bin/testlogstash.sh
# Stuff we need for various parts of this installation:
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/mongodb.list
apt-get update && apt-get install build-essential libffi-dev apache2 redis-server stunnel4 supervisor openjdk-7-jdk curl libgeoip-dev mongodb-org git apache2-utils libapache2-mod-wsgi python-dev ntp -y
# Update the date (seems to have been a problem during my testing - my vm's were not udpating their date and time)
echo "This might hang for about 5 seconds:"
service ntp stop && /usr/sbin/ntpdate pool.ntp.org && service ntp start
cd /usr/local/src && wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py
pip install flask-mongoengine pymongo flask-bootstrap requests
####### STUNNEL CONFIG #######
# stunnel is listening for connections on port 6378 on all interfaces and will send connections from there to 127.0.0.1:6379
#Generage a certificate for stunnel:
cd /etc/stunnel && openssl genrsa -out key.pem 2048 && openssl req -new -x509 -key key.pem -out cert.pem -days 2095 -subj "/C=US/ST=CA/L=Oakland/O=Honeynet/OU=Honeynet/CN=Honeynet CA/emailAddress=nonei@tld.com" && cat key.pem cert.pem >> /etc/stunnel/stunnel.pem
sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
cat > /etc/stunnel/stunnel.conf<<EOF
cert = /etc/stunnel/stunnel.pem
[redis]
accept = 6378
connect = 127.0.0.1:6379
[logstash-filetransfer]
accept = 6781
connect = 127.0.0.1:6782
EOF
####### END STUNNEL CONFIG #######
####### LOGSTASH CONFIG #######
cd /usr/local/src && wget https://download.elastic.co/logstash/logstash/packages/debian/logstash_1.5.3-1_all.deb && dpkg -i logstash_1.5.3-1_all.deb
cd /etc/logstash && curl -O "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz" && gunzip GeoLiteCity.dat.gz
cat > /etc/logstash/conf.d/server.conf<<EOF
input {
if ( [type] == "SSH" or [type] == "GasPot" or [type] == "Conpot" ) {
redis {
host => "localhost"
type => "redis-input"
data_type => "list"
key => "honeynet"
}
}
if ( [type] == "ssh_intel" or [type] == "GasPot" or [type] == "ssh_intel2" or [type] == "conpot_intel" or [type] == "malware_from_honeypots" or [type] == "ssh_replaylogs" ) {
tcp {
mode => "server"
codec => json_lines
port => "6782"
}
}
}
filter {
# Conpot honeypot
#
if [type] == "conpot" {
grok {
match => [ "message", "%{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:day} %{TIME:time} : %{IP:srcip} \t%{DATA:srcport} \t %{IP:dstip} \t %{DATA:request_protocol} \t %{DATA:response_code} \t %{DATA:sensor_id} \t '%{DATA:request_raw}' " ]
}
mutate {
add_field => [ "source-ip", "%{srcip}" ]
}
date {
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss" ]
}
}
# GasPot honeypot
if [type] == "GasPot" {
grok {
match => [ "message", "Connection from : %{IP:src-ip}" ]
}
mutate {
add_field => [ "source-ip", "%{src-ip}" ]
}
}
# Cowrie honeypot
if [type] == "SSH" {
if ( [message] =~ "SSHService ssh-userauth on HoneyPotTransport" ) {
grok {
match => [ "message", "%{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:day} %{TIME:time}%{ISO8601_TIMEZONE} \[SSHService ssh-userauth on HoneyPotTransport,%{DATA:ssh-session},%{IP:src-ip}" ]
}
mutate {
add_field => [ "source-ip", "%{src-ip}" ]
}
}
}
# GEO DATA:
if ( [type] == "SSH" or [type] == "GasPot" ) {
geoip {
source => "src-ip"
target => "geoip"
database => "/etc/logstash/GeoLiteCity.dat"
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ]
}
mutate {
convert => [ "[geoip][coordinates]", "float"]
}
}
}
output {
if ( [type] == "SSH" or [type] == "GasPot" or [type] == "Conpot" ) {
elasticsearch {
cluster => "honeynet"
bind_host => "127.0.0.1"
}
}
if [type] == "ssh_intel" {
file {
codec => json
path => "/opt/files/incoming/cowrie.json"
}
}
if [type] == "GasPot" {
file {
path => "/opt/files/incoming/gaspot.log"
}
}
if [type] == "ssh_intel2" {
file {
path => "/opt/files/incoming/cowrie.log"
}
}
if [type] == "conpot_intel" {
file {
path => "/opt/files/incoming/conpot.log"
}
}
if [type] == "malware_from_honeypots" {
file {
path => "/opt/files/incoming/malware_from_honeypots.txt"
}
}
if [type] == "ssh_replaylogs" {
file {
path => "/opt/files/incoming/ssh_replaylogs.txt"
}
}
}
EOF
# Supervisor for logstash:
cat > /etc/supervisor/conf.d/logstash.conf <<EOF
[program:logstash]
command=/opt/startlogstash.sh
directory=/opt/
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
cat > /opt/startlogstash.sh <<EOF
#! /bin/bash
service logstash start
EOF
chmod 755 /opt/startlogstash.sh
chown logstash:logstash /opt/files/incoming/
####### END LOGSTASH CONFIG #######
####### ELASTICSEARCH CONFIG #######
# For 32 bit: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/
# For 64 bit: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
# handled in the beginning with the getarchitecture function
# Install elasticsearch:
cd /usr/local/src && wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.1.deb && echo $es_architecture && dpkg -i elasticsearch-1.7.1.deb && update-rc.d elasticsearch defaults 95 10
sed -i 's/#cluster.name: elasticsearch/cluster.name: honeynet/g' /etc/elasticsearch/elasticsearch.yml
sed -i 's/#node.name: "Franz Kafka"/node.name: "HNServer"/g' /etc/elasticsearch/elasticsearch.yml
sed -i 's/#network.host: 192.168.0.1/network.host: localhost/g' /etc/elasticsearch/elasticsearch.yml
####### END ELASTICSEARCH CONFIG #######
####### KIBANA CONFIG #######
# Kibana and apache
# 64 bit: https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x64.tar.gz
# 32 bit: https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x86.tar.gz
# handled in the beginning with the getarchitecture function
cd /var/www/ && wget $kibana && tar -zxf kibana* && rm *.gz && mv kibana* kibana && chown -R www-data:www-data kibana
# limit access to kibana to local connections only. This is so we can proxy through apache and use https
# The host to bind the server to.
sed -i 's/host: "0.0.0.0"/host: "127.0.0.1"/g' /var/www/kibana/config/kibana.yml
# DEPRECATED Set kibana to be able to read files owned by root:
#usermod -a -G adm logstash
# Setup kibana to start at boot
cat > /opt/kibana_start.sh <<EOF
#!/bin/sh
sh /var/www/kibana/bin/kibana
EOF
chmod 755 /opt/kibana_start.sh
cat > /etc/supervisor/conf.d/kibana.conf <<EOF
[program:kibana]
command=/opt/kibana_start.sh
directory=/var/www/kibana
stdout_logfile=/opt/kibana.out
stderr_logfile=/opt/kibana.err
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
####### END KIBANA CONFIG #######
####### SSL CONFIG #######
# generate ssl keys:
# Generate and copy to /usr/local/certs/sslcerts/
cd /usr/local/certs/sslcerts/
# Create server key and certificate signing request:
openssl req -new -out csr.key -passout pass:honeynet -subj "/C=US/ST=CA/L=Oakland/O=Honeynet/OU=Honeynet/CN=Honeynet CA/emailAddress=nonei@tld.com"
# Remove the Passphrase
openssl rsa -in privkey.pem -passin pass:honeynet -out server.key
# Sign certificate:
openssl x509 -req -days 3600 -in csr.key -signkey server.key -out server.crt
####### SSL CONFIG #######
####### APACHE CONFIG #######
# You have to run htpasswd to set up a user who can access the kibana interface:
#sudo htpasswd -c /opt/.htpasswd-private username
chown www-data:www-data /var/www/intel
rm /etc/apache2/sites-enabled/000-default*
cat > /etc/apache2/sites-enabled/kibana.conf<<EOF
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://localhost:5601/
<Location />
Order allow,deny
Allow from all
# AuthName 'Kibana'
# AuthType Basic
# AuthUserFile /opt/.htpasswd-private
# Require valid-user
# AllowOverride None
</Location>
</VirtualHost>
EOF
cat > /etc/apache2/sites-enabled/intel.conf<<EOF
<VirtualHost *:443>
ServerName intel
ServerAdmin admin@intel
WSGIScriptAlias / /var/www/intel/intel.wsgi
<Directory /var/www/intel/intel/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/intel/intel/static
<Directory /var/www/intel/intel/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /usr/local/certs/sslcerts/server.crt
SSLCertificateKeyFile /usr/local/certs/sslcerts/server.key
</VirtualHost>
EOF
a2enmod proxy_http && a2enmod ssl
####### END APACHE CONFIG #######
####### CRON CONFIG (for analysis scripts) #######
cat > /opt/cronscripts/conpotanalyzer.sh<<EOF
#!/bin/sh
python /opt/analysis/conpot_reader.py
EOF
cat > /opt/cronscripts/malwareanalyzer.sh<<EOF
#!/bin/sh
python /opt/analysis/virustotal_api.py
EOF
cat > /opt/cronscripts/cowrie_log_reader.sh<<EOF
#!/bin/sh
python /opt/analysis/cowrie_log_reader.py
EOF
cat > /opt/cronscripts/cowrie_json_reader.sh<<EOF
#!/bin/sh
python /opt/analysis/cowrie_json_reader.py
EOF
cat > /opt/cronscripts/gaspot_log_analysis.sh<<EOF
#!/bin/sh
python /opt/analysis/gaspot_reader.py
EOF
chmod 755 /opt/cronscripts/conpotanalyzer.sh
chmod 755 /opt/cronscripts/malwareanalyzer.sh
chmod 755 /opt/cronscripts/cowrie_log_reader.sh
chmod 755 /opt/cronscripts/cowrie_json_reader.sh
chmod 755 /opt/cronscripts/gaspot_log_analysis.sh
(crontab -u root -l; echo "*/4 * * * * /opt/cronscripts/conpotanalyzer.sh" ) | crontab -u root -
(crontab -u root -l; echo "*/11 * * * * /opt/cronscripts/malwareanalyzer.sh" ) | crontab -u root -
(crontab -u root -l; echo "*/8 * * * * /opt/cronscripts/cowrie_log_reader.sh" ) | crontab -u root -
(crontab -u root -l; echo "*/6 * * * * /opt/cronscripts/cowrie_json_reader.sh" ) | crontab -u root -
(crontab -u root -l; echo "*/14 * * * * /opt/cronscripts/gaspot_log_analysis.sh" ) | crontab -u root -
####### END CRON CONFIG #######
####### START SERVICES #######
supervisorctl update
service stunnel4 restart
service redis-server restart
service elasticsearch restart
service apache2 restart
###############################################################
# CREATE CLIENT CONFIG (it will be saved to /opt/Honeynet_client_configuration.sh)
# Get the stunnel.pem
echo "cat > /etc/stunnel/stunnel.pem << EOF" > /opt/Honeynet_client_configuration.sh
cat /etc/stunnel/stunnel.pem >> /opt/Honeynet_client_configuration.sh
echo "EOF" >> /opt/Honeynet_client_configuration.sh
echo "chmod 600 /etc/stunnel/stunnel.pem" >> /opt/Honeynet_client_configuration.sh
cat >> /opt/Honeynet_client_configuration.sh<<ENDOFCLIENTSCRIPT
echo "What's the IP address or hostname of the HoneyPot Server?"
read SERVER
add-apt-repository -y ppa:honeynet/nightly
apt-get update
apt-get -y install python-dev openssl python-openssl python-pyasn1 python-twisted git python-pip authbind python-software-properties patch libglib2.0-dev libssl-dev libcurl4-openssl-dev libreadline-dev libsqlite3-dev libtool automake autoconf build-essential subversion git-core flex bison pkg-config libgc-dev libgc1c2 sqlite3 python-geoip sqlite libnl-3-dev libnl-genl-3-dev libnl-nf-3-dev libnl-route-3-dev supervisor stunnel4 openjdk-7-jdk curl authbind python-dev openssl git libsmi2ldbl libsmi2-common python-dev libxml2-dev python-lxml libxslt-dev libmysqlclient-dev dionaea ntp php5 php5-dev
# Update the date (seems to have been a problem during my testing - my vm's were not udpating their date and time)
echo "This might hang for about 5 seconds:"
service ntp stop && /usr/sbin/ntpdate pool.ntp.org && service ntp start
pip install --upgrade distribute
pip install virtualenv
HPN=$(dirname "$0")
DIR="$HPN/HoneyNet_Installer/"
# make directories:
mkdir -p /opt/transfer /opt/conpot /opt/cronscripts /opt/analysis /opt/malware /opt/sshreplays /var/dionaea/wwwroot /var/dionaea/binaries /var/dionaea/log /var/dionaea/bistreams
# Copy analysis scripts:
cp $HPN/client/analysis/* /opt/analysis/ && chmod 755 /opt/analysis/*
# Make some utilities for troubleshooting logstash when you need to add new things:
cat > /usr/bin/editlogstashconf.sh<<EOF
#!/bin/bash
sudo vim /etc/logstash/conf.d/client.conf
EOF
cat > /usr/bin/restartlogstash.sh<<EOF
#!/bin/bash
sudo service logstash restart
EOF
cat > /usr/bin/statuslogstash.sh<<EOF
#!/bin/bash
sudo service logstash status
EOF
cat > /usr/bin/taillogstashlog.sh<<EOF
#!/bin/bash
tail -f /var/log/logstash/logstash.log
EOF
cat > /usr/bin/testlogstash.sh<<EOF
#!/bin/bash
/usr/local/src/logstash-1.5.4/bin/logstash -f /etc/logstash/conf.d/client.conf --configtest
EOF
chmod 755 /usr/bin/editlogstashconf.sh
chmod 755 /usr/bin/restartlogstash.sh
chmod 755 /usr/bin/statuslogstash.sh
chmod 755 /usr/bin/taillogstashlog.sh
chmod 755 /usr/bin/testlogstash.sh
####### sshd_config mod #######
# Modify sshd so it accepts connections on port 2222 instead of 22. Cowrie (the ssh honeypot will accept on 22).
#When connecting for administrative purposes, you'll have to go to ssh -p 2223 username@host or you'll get caught by the honeypot
sed -i 's/Port 22/Port 2223/g' /etc/ssh/sshd_config && reload ssh
####### End sshd_config mod #######
####### STUNNEL CONFIG #######
# Create stunnel.conf. Config for the stunnel for reddis data to transfer to server:
cat > /etc/stunnel/stunnel.conf << EOF
cert = /etc/stunnel/stunnel.pem
client = yes
[reddis]
accept = 127.0.0.1:6379
connect = REPLACEME:6378
[logstash-filetransfer]
accept = 6782
connect = REPLACEME:6781
EOF
#Change ENABLED=0 to ENABLED=1 in /etc/default/stunnel4:
sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
sed -e "s/REPLACEME/$SERVER/g" /etc/stunnel/stunnel.conf
####### END STUNNEL CONFIG #######
####### LOGSTASH CONFIG #######
# Folder to output log files to:
sudo chown logstash:logstash /opt/transfer/
# Install logstash:
cd /usr/local/src && wget https://download.elastic.co/logstash/logstash/packages/debian/logstash_1.5.3-1_all.deb && dpkg -i logstash_1.5.3-1_all.deb
# Set up logstash client config file for sending data from ssh honeypot to elasticsearch on the server
cat > /etc/logstash/conf.d/client.conf << EOF
input {
file {
type => "SSH"
path => "/opt/cowrie/log/cowrie.log"
start_position => "beginning"
}
file {
type => "Conpot"
path => "/opt/conpot/conpot.log"
start_position => "beginning"
}
file {
type => "conpot_intel"
path => "/opt/conpot/conpot.log"
start_position => "beginning"
}
file {
type => "ssh_intel"
path => "/opt/cowrie/log/cowrie.json"
codec => json
# sincedb_path => "/dev/null"
start_position => "beginning"
}
file {
type => "ssh_intel2"
path => "/opt/cowrie/log/cowrie.log"
start_position => "beginning"
}
file {
type => "GasPot"
path => "/opt/GasPot/all_attempts.log"
# sincedb_path => "/dev/null"
start_position => "beginning"
}
file {
type => "malware_from_honeypots"
path => "/opt/malware_from_honeypots.txt"
start_position => "beginning"
}
file {
type => "ssh_replaylogs"
path => "/opt/ssh_replaylogs.txt"
start_position => "beginning"
}
}
output {
if [type] == "SSH" or [type] == "GasPot" or [type] == "Conpot" {
redis {
host => "127.0.0.1"
port => "6379"
data_type => "list"
key => "honeynet"
}
}
if [type] == "ssh_intel" or [type] == "GasPot" or [type] == "ssh_intel2" or [type] == "conpot_intel" or [type] == "malware_from_honeypots" or [type] == "ssh_replaylogs" {
tcp {
host => "127.0.0.1"
port => "6782"
codec => json_lines
}
}
}
EOF
# Supervisor for logstash:
cat > /etc/supervisor/conf.d/logstash.conf <<EOF
[program:logstash]
command=/opt/startlogstash.sh
directory=/opt/
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
cat > /opt/startlogstash.sh <<EOF
#! /bin/bash
service logstash start
EOF
chmod 755 /opt/startlogstash.sh
####### END LOGSTASH CONFIG #######
####### COWRIE INSTALLATION #######
#based off Kippo ssh honeypot
# Create cowrie user
useradd cowrie -U
# Get the Cowrie source
cd /opt && git clone https://github.com/micheloosterhof/cowrie.git
# Configure Cowrie
cd /opt/cowrie && mv cowrie.cfg.dist cowrie.cfg && sed -i 's/hostname = svr03/hostname = payroll/g' cowrie.cfg && sed -i 's/ssh_version_string = SSH-2.0-OpenSSH_5.1p1 Debian-5/ssh_version_string = OpenSSH_5.9p1 Debian-5ubuntu1.4, OpenSSL 1.0.1 14 Mar 2012/g' cowrie.cfg
touch /opt/cowrie/log/cowrie.json
touch /opt/malware_from_honeypots.txt && chmod 777 /opt/malware_from_honeypots.txt
chown nobody:nogroup /opt/cowrie/log/cowrie.json
chown nobody:nogroup /opt/cowrie/log/cowrie.log
chmod 777 /opt/cowrie/log/cowrie.json
chmod 777 /opt/cowrie/log/cowrie.log
chmod 777 /opt/malware_from_honeypots.txt
# Fix permissions for cowrie and set up authbind port
chown -R cowrie /opt/cowrie
# Setup cowrie to start at boot
cat > /opt/cowrie/start.sh <<EOF
#!/bin/sh
su cowrie -c "twistd -l log/cowrie.log --pidfile cowrie.pid cowrie"
EOF
chmod +x /opt/cowrie/start.sh
# Set up supervisor conf file:
cat > /etc/supervisor/conf.d/cowrie.conf <<EOF
[program:cowrie]
command=/opt/cowrie/start.sh
directory=/opt/cowrie
stdout_logfile=/opt/cowrie/log/cowrie.out
stderr_logfile=/opt/cowrie/log/cowrie.err
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
####### END COWRIE INSTALLATION #######
####### GasPot Honeypot #######
cd /opt/ && git clone https://github.com/sjhilt/GasPot.git && cd GasPot && mv config.ini.dist config.ini
touch /opt/GasPot/all_attempts.log && chmod 777 /opt/GasPot/all_attempts.log
# Config for supervisor.
cat > /etc/supervisor/conf.d/gaspot.conf <<EOF
[program:gaspot]
command=/usr/bin/python /opt/GasPot/GasPot.py
directory=/opt/GasPot
stdout_logfile=/opt/GasPot/gaspot.log
stderr_logfile=/opt/GasPot/gaspot.err
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
####### END GasPot Honeypot #######
####### CONPOT Honeypot #######
pip install six gevent pysnmp
pip install python-dateutil --upgrade
cd /opt/conpot
virtualenv env
. env/bin/activate
pip install -U setuptools
pip install -e git+https://github.com/glastopf/conpot.git#egg=conpot-dev
pip install -e git+https://github.com/glastopf/modbus-tk.git#egg=modbus-tk==0.4
cat > /etc/supervisor/conf.d/conpot.conf <<EOF
[program:conpot]
command=/opt/conpot/env/bin/python /opt/conpot/env/bin/conpot --template default -l /opt/conpot/conpot.log
directory=/opt/conpot
stdout_logfile=/var/log/conpot.out
stderr_logfile=/var/log/conpot.err
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
####### END CONPOT Honeypot #######
####### DIONAEA Honeypot #######
add-apt-repository -y ppa:honeynet/nightly && apt-get update
apt-get install -y dionaea
cp /etc/dionaea/dionaea.conf.dist /etc/dionaea/dionaea.conf
chown -R nobody:nogroup /var/dionaea
chown nobody:nogroup /var/dionaea/bistreams
sed -i 's/var\/dionaea\///g' /etc/dionaea/dionaea.conf
sed -i 's/log\//\/var\/dionaea\/log\//g' /etc/dionaea/dionaea.conf
sed -i 's/levels = "all"/levels = "warning,error"/1' /etc/dionaea/dionaea.conf
sed -i 's/mode = "getifaddrs"/mode = "manual"/1' /etc/dionaea/dionaea.conf
sed --in-place='.bak' 's/addrs = { eth0 = \["::"\] }/addrs = { eth0 = ["::", "0.0.0.0"] }/' /etc/dionaea/dionaea.conf
# Config for supervisor.
cat > /etc/supervisor/conf.d/dionaea.conf <<EOF
[program:dionaea]
command=dionaea -c /etc/dionaea/dionaea.conf -w /var/dionaea -u nobody -g nogroup
directory=/var/dionaea
stdout_logfile=/var/log/dionaea.out
stderr_logfile=/var/log/dionaea.err
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
####### END DIONAEA Honeypot #######
####### GLASTOPF Honeypot #######
# This installation inspired by and partially borrowed from MHN
# PHP sandbox
cd /usr/local/src/
git clone git://github.com/glastopf/BFR.git
cd BFR
phpize
./configure --enable-bfr
make && make install
# Updated php.ini to add bfr.so
BFR_BUILD_OUTPUT=`find /usr/lib/php5/ -type f -name "bfr.so" | awk -F"/" '{print $5}'`
echo "zend_extension = /usr/lib/php5/$BFR_BUILD_OUTPUT/bfr.so" >> /etc/php5/apache2/php.ini
# Stop apache2 and disable it from start up
service apache2 stop
update-rc.d -f apache2 remove
# Upgrade python-greenlet
pip install --upgrade greenlet
# Install glastopf
pip install glastopf
mkdir -p /opt/glastopf
cd /opt/glastopf/
cat > /opt/glastopf/glastopf.cfg <<EOF
[webserver]
host = 0.0.0.0
port = 80
uid = nobody
gid = nogroup
proxy_enabled = False
#Generic logging for general monitoring
[logging]
consolelog_enabled = False
filelog_enabled = True
logfile = log/glastopf.log
[dork-db]
enabled = True
pattern = rfi
#Extracts dorks from a online dorks service operated by The Honeynet Project
mnem_service = True
[hpfeed]
enabled = True
host = $HPF_HOST
port = $HPF_PORT
secret = $HPF_SECRET
# channels comma separated
chan_events = glastopf.events
chan_files = glastopf.files
ident = $HPF_IDENT
[main-database]
#If disabled a sqlite database will be created (db/glastopf.db)
#to be used as dork storage.
enabled = True
#mongodb or sqlalchemy connection string, ex:
#mongodb://localhost:27017/glastopf
#mongodb://james:bond@localhost:27017/glastopf
#mysql://james:bond@somehost.com/glastopf
connection_string = sqlite:///db/glastopf.db
[surfcertids]
enabled = False
host = localhost
port = 5432
user =
password =
database = idsserver
[syslog]
enabled = False
socket = /dev/log
[mail]
enabled = False
# an email notification will be sent only if a specified matched pattern is identified.
# Use the wildcard char *, to be notified every time
patterns = rfi,lfi
user =
pwd =
mail_from =
mail_to =
smtp_host = smtp.gmail.com
smtp_port = 587
[taxii]
enabled = False
host = taxiitest.mitre.org
port = 80
inbox_path = /services/inbox/default/
use_https = False
use_auth_basic = False
auth_basic_username = your_username
auth_basic_password = your_password
use_auth_certificate = False
auth_certificate_keyfile = full_path_to_keyfile
auth_certificate_certfile = full_path_to_certfile
include_contact_info = False
contact_name = ...
contact_email = ...
[misc]
# set webserver banner
banner = Apache/2.0.48
EOF
# Set up supervisor
cat > /etc/supervisor/conf.d/glastopf.conf <<EOF
[program:glastopf]
command=/usr/bin/python /usr/local/bin/glastopf-runner
directory=/opt/glastopf
stdout_logfile=/var/log/glastopf.out
stderr_logfile=/var/log/glastopf.err
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
EOF
####### END GLASTOPF Honeypot #######
####### CRON CONFIG (for client analysis scripts) #######
cat > /opt/cronscripts/getmalwareinfo.sh<<EOF
#!/bin/sh
python /opt/analysis/get_malware_info.py
EOF
cat > /opt/cronscripts/readtty.sh<<EOF
#!/bin/sh
python /opt/analysis/readtty.py
EOF
chmod 755 /opt/cronscripts/getmalwareinfo.sh
chmod 755 /opt/cronscripts/readtty.sh
(crontab -u root -l; echo "*/5 * * * * /opt/cronscripts/getmalwareinfo.sh" ) | crontab -u root -
(crontab -u root -l; echo "*/7 * * * * /opt/cronscripts/readtty.sh" ) | crontab -u root -
####### END CRON CONFIG #######
# Set IPTABLES to forward all port 22 traffic to 2222
iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222
apt-get install iptables-persistent -y
# Start up services:
/etc/init.d/stunnel4 start
supervisorctl update
clear
echo "You need to do one manual configuration:
sudo vim (or whatever editor) /etc/stunnel/stunnel.conf
Change the REPLACEME parts to the IP or domain name of the honeypot server.
cert = /etc/stunnel/stunnel.pem
client = yes
[reddis]
accept = 127.0.0.1:6379
connect = REPLACEME:6378
[logstash-filetransfer]
accept = 6782
connect = REPLACEME:6781
Then type: sudo service stunnel4 restart
"
ENDOFCLIENTSCRIPT
cd /opt/ && tar -czf HoneyNet_Client_Installer.tar.gz client/ Honeynet_client_configuration.sh
rm -rf client && rm Honeynet_client_configuration.sh
clear
echo "The server installation is complete. Copy the HoneyNet_Client_Installer.tar.gz from this directory (/opt/HoneyNet_Client_Installer.tar.gz) to any and all clients you want to set up as honeypots, untar the file and run (on the honeypots, not this server):
sudo sh Honeynet_client_configuration.sh
There will be a few prompts. Enter the information requested and select yes when asked.
Some basic information:
1: Intel can be found at https://yourserverip/ (attackers have to attack your honeypots first and then data will start to populate the database)
2: A kibana interface is set up at http://yourserverip/. You can make a dashboard there to show all the stuff.
############################
PORTS:
############################
The server needs to have the following tcp ports open to the public:
6378: Stunnel sends redis traffic to this port
6782: Stunnel sends files through logstash using this port
80: Kibana is running at port 80
443: The intel portion of the system is running at this port
############################
API KEYS:
############################
Add your API keys to:
OpenDNS Investigate: /opt/analysis/investigate_api_key.txt
Virus Total: /opt/analysis/virustotal_api_key.txt
Questions: Visit the github page or email jpyorre @ gmail . com
"