Facebook
From Rude Bison, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 37
  1. #!/bin/bash
  2.  
  3. set -e
  4. set -x
  5.  
  6. if [ $# -ne 2 ]
  7.     then
  8.         echo "Wrong number of arguments supplied."
  9.         echo "Usage: $0 <server_url> <deploy_key>."
  10.         exit 1
  11. fi
  12.  
  13. apt-get update
  14.  
  15. server_url=$1
  16. deploy_key=$2
  17.  
  18. apt-get update
  19. apt-get -y install python-dev git supervisor authbind openssl python-virtualenv build-essential python-gmpy2 libgmp-dev libmpfr-dev libmpc-dev libssl-dev  libffi-dev
  20.  
  21. pip install -U supervisor
  22. /etc/init.d/supervisor start || true
  23.  
  24. sed -i 's/#Port/Port/g' /etc/ssh/sshd_config
  25. sed -i 's/Port 22$/Port 2222/g' /etc/ssh/sshd_config
  26. service ssh restart
  27. useradd -d /home/cowrie -s /bin/bash -m cowrie -g users
  28.  
  29.  
  30. git clone https://github.com/micheloosterhof/cowrie.git cowrie
  31. cd cowrie
  32.  
  33. # Most recent known working version
  34. git checkout 34f8464
  35.  
  36. # Config for requirements.txt
  37. cat > /home/honey3/cowrie/requirements.txt <<EOF
  38. twisted>=17.1.0
  39. cryptography>=2.1
  40. configparser
  41. pyopenssl
  42. pyparsing
  43. packaging
  44. appdirs>=1.4.0
  45. pyasn1_modules
  46. attrs
  47. service_identity
  48. python-dateutil
  49. tftpy
  50. bcrypt
  51. EOF
  52.  
  53. python -m venv cowrie-env #env name has changed to cowrie-env on latest version of cowrie
  54. source cowrie-env/bin/activate
  55. # without the following, i get this error:
  56. # Could not find a version that satisfies the requirement csirtgsdk (from -r requirements.txt (line 10)) (from versions: 0.0.0a5, 0.0.0a6, 0.0.0a5.linux-x86_64, 0.0.0a6.linux-x86_64, 0.0.0a3)
  57. pip install csirtgsdk==0.0.0a6
  58. pip install -r requirements.txt
  59.  
  60. # Register sensor with MHN server.
  61. wget $server_url/static/registration.txt -O registration.sh
  62. chmod 755 registration.sh
  63. # Note: this will export the HPF_* variables
  64. . ./registration.sh $server_url $deploy_key "cowrie"
  65.  
  66. cd etc
  67. cp cowrie.cfg.dist cowrie.cfg
  68. sed -i 's/hostname = svr04/hostname = server/g' cowrie.cfg
  69. sed -i 's/listen_endpoints = tcp:2222:interface=0.0.0.0/listen_endpoints = tcp:22:interface=0.0.0.0/g' cowrie.cfg
  70. sed -i 's/version = SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u2/version = SSH-2.0-OpenSSH_6.7p1 Ubuntu-5ubuntu1.3/g' cowrie.cfg
  71. sed -i 's/#[output_hpfeeds]/[output_hpfeeds]/g' cowrie.cfg
  72. sed -i '/[output_hpfeeds]/!b;n;cenabled = true' cowrie.cfg
  73. sed -i "s/#server = hpfeeds.mysite.org/server = $HPF_HOST/g" cowrie.cfg
  74. sed -i "s/#port = 10000/port = $HPF_PORT/g" cowrie.cfg
  75. sed -i "s/#identifier = abc123/identifier = $HPF_IDENT/g" cowrie.cfg
  76. sed -i "s/#secret = secret/secret = $HPF_SECRET/g" cowrie.cfg
  77. sed -i 's/#debug=false/debug=false/' cowrie.cfg
  78. cd ..
  79.  
  80. chown -R cowrie:users /home/honey3/cowrie/
  81. touch /etc/authbind/byport/22
  82. chown cowrie /etc/authbind/byport/22
  83. chmod 770 /etc/authbind/byport/22
  84.  
  85. # start.sh is deprecated on new Cowrie version and substituted by "bin/cowrie [start/stop/status]"
  86. sed -i 's/AUTHBIND_ENABLED=no/AUTHBIND_ENABLED=yes/' bin/cowrie
  87. sed -i 's/DAEMONIZE=""/DAEMONIZE="-n"/' bin/cowrie
  88.  
  89. # Config for supervisor
  90. cat > /etc/supervisor/conf.d/cowrie.conf <<EOF
  91. [program:cowrie]
  92. command=/home/honey3/cowrie/bin/cowrie start
  93. directory=/home/honey3/cowrie
  94. stdout_logfile=/home/honey3/cowrie/var/log/cowrie/cowrie.out
  95. stderr_logfile=/home/honey3/cowrie/var/log/cowrie/cowrie.err
  96. autostart=true
  97. autorestart=true
  98. stopasgroup=true
  99. killasgroup=true
  100. user=cowrie
  101. EOF
  102.  
  103. supervisorctl update
  104.  
  105.