Installing Apache Bloodhound 0.7 on Windows

Table of Content

  1. Preface
    1. Software and Versions
    2. Creating the Bloodhound Installation Directory
  2. Python Part
    1. Installing Python
    2. Installing Setuptools, Pip and Virtualenv
    3. Creating a Virtual Python Environment for Apache Bloodhound
    4. Creating a Script for Setting the Bloodhound Environment
    5. Installing win-psycopg in the Virtual Python Environment
  3. PostgreSQL Part
    1. Installing PostgreSQL
    2. Adding PostgreSQL to the Bloodhound Environment Script
    3. Creating the Database User and the Bloodhound Database
  4. Apache Bloodhound Part
    1. Installing Apache Bloodhound
    2. Starting Apache Bloodhound
  5. Apache HTTPD Server Part
    1. Installing the Apache HTTPD Server
    2. Adding Apache HTTPD Server to the Bloodhound Environment Script
    3. Configuring the HTTPD Server to run Bloodhound
  6. Known Issues

Preface

I decided to use Apache Bloodhound for my Personal Toolchain. Unfortunately the Installation Instructions on the Bloodhound Page are mainly for Linux Users (although there are some hints for Windows People). After a while I figured out how to Install Apache Bloodhound and run it with the Apache HTTP Server. Because this might be interesting for other People I will share it here.

Software and Versions

Here is the Software that I have used to get Apache Bloodhound running:

Software Version Download Link
Apache Bloodhound 0.7 http://www.apache.org/dyn/closer.cgi/bloodhound/
Python 2.7.8 https://www.python.org/downloads/release/python-278/
pip 1.5.6 https://bootstrap.pypa.io/get-pip.py
virtualenv 1.11.16 will be downloaded with pip
PostgreSQL 9.3.5.1 http://www.enterprisedb.com/products/pgdownload.do#windows
7-Zip 9.22 beta http://sourceforge.net/projects/sevenzip/files/7-Zip/9.22/
win-psycopg 2.5.4 http://stickpeople.com/projects/python/win-psycopg/
Apache HTTP Server 2.4.10 http://www.apachelounge.com/download/VC11/binaries/httpd-2.4.10-win64-VC11.zip
mod_wsgi 3.5.ap24.win32-py2.7 http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi

Creating the Bloodhound Installation Directory

  1. Create the Folder where Apache Bloodhound should later be installed. I use C:\bloodhound.

Python Part

If you already have a working Python Installation with pip, setuptools and virtualenv you can directly go to: Creating a Virtual Python Environment for Apache Bloodhound

Installing Python

  1. Run the Python Installer and select Install for all users python_install_for_all_users
  2. Leave the preselected Options python_install_preselected_options

Troubleshooting:

Installing Setuptools, Pip and Virtualenv

  1. Move get-pip.py into C:\Python27
  2. Open cmd and navigate to C:\Python27
  3. Execute:
    python get-pip.py
  4. You should see the following Output: python_get_pip
  5. Now install virtualenv by executing:
    Scripts\pip install virtualenv

You should see: python_get_virtualenv

Troubleshooting:

  • If you have Trouble installing pip see: https://pip.pypa.io/en/latest/installing.html
  • If something went wrong you can delete the already installed packages by opening the Lib\site-packages Directory in your Python Installation and deleting the Folders from the Packages like pip and pip-1.5.6.dist-info
  • You can also delete pip, setuptools and virtualenv by executing the following command:
    python -m pip uninstall pip setuptools virtualenv

Creating a Virtual Python Environment for Apache Bloodhound

Apache Bloodhound depends on a lot of Libraries like Babel, Genshi, Whoosh etc. Therefore it is necessary to create a Virtual Python Environment that Apache Bloodhound can use.
We will create the Virtual Environment as a Subfolder of C:\bloodhound.

  1. Open cmd and navigate to C:\bloodhound
  2. Execute:
    C:\Python27\Scripts\virtualenv VirtualPythonEnvironment

    and press Enter

  3. You should see the following Output: virtualenv_created

Creating a Script for Setting the Bloodhound Environment

So far we always had to call the programs with the complete Path like C:\Python27\python.exe which involves a lot of typing and is thus error prone.
So to simplify things we will create a script where we add these programs to the Environment Variable ‘PATH’. This makes the programs executable from everywhere.

  1. Right click in C:\bloodhound and choose New > Text Document
  2. As name choose: SetBloodhoundEnvironment.cmd
  3. Click Yes on the Message Box that asks if you want to change the Filename Extension.
  4. You should now have the following File: set_environment_file
  5. Now open the File with your preferred Editor. I use Notepad++
  6. Copy and Paste the following into the File:
    @ echo off
    REM Retrieve the Path to the Directory from this Batch File
    set THIS_BATCH_PATH=%~dp0
    if "%INITIALIZE_STATE%" == "" (
        REM Expand variables at execution time rather than at parse time
        setlocal EnableDelayedExpansion
    
        REM Temporarily change to the Bloodhound Root Directory
        REM to retrieve the full path to that Directory
        pushd !THIS_BATCH_PATH!..
        set BLOODHOUND_DIR=!CD!
        popd
    
        REM Set Variables for our Environment
        set VENV_SCRIPTS_DIR=C:\bloodhound\VirtualPythonEnvironment\Scripts
    
        REM Add our Directorys to PATH
        set "PATH=!VENV_SCRIPTS_DIR!;!PATH!"
    
        goto finish_init
    ) else (
        REM Environment Variables are already set so lets just print the Overview
        goto print_overview
    )
    
    :finish_init
    endlocal & (
        REM Make the Variables globally available
        set INITIALIZE_STATE=INITIALIZED
        set BLOODHOUND_DIR=%BLOODHOUND_DIR%
        set VENV_SCRIPTS_DIR=%VENV_SCRIPTS_DIR%
        set PATH=%PATH%
    )
    
    :print_overview
    echo Bloodhound Environment is now set. 
    echo Here is an overview of the most commonly used commands to help you get started:
    echo 1. Python Interpreter          (Command: python)
    echo 2. Python Package Manager      (Command: pip)
    echo 3. Python Setuptools           (Command: easy_install)
    echo.
    
  7. Save the File and Close the Editor
  8. Reopen cmd
  9. Navigate to C:\bloodhound
  10. Execute:
    SetBloodhoundEnvironment.cmd
  11. Execute:
    pip --version

    Output:

    pip 1.5.6 from C:\bloodhound\VirtualPythonEnvironment\lib\site-packages (python 2.7)

  12. Example:
    pip_installed

Installing win-psycopg in the Virtual Python Environment

psycopg is the PostgreSQL Interface for Python. The recommended way to Install it is to open a CMD change to the Bloodhound\installer Directory and execute pip install -r pgrequirements.txt. However that won’t work on Windows because here we need a port of psycopg called win-psycopg. So we can’t use the recommended way and instead must do it manually. Then during the Bloodhound Installation we will only get a Requirement already satisfied Message.

  1. Put the File psycopg2-2.5.4.win32-py2.7-pg9.3.5-release.exe into C:\bloodhound
  2. Now in cmd type
    easy_install.exe psycopg2-2.5.4.win32-py2.7-pg9.3.5-release.exe

    and press Enter

  3. If you see the following Output everything went well: win_psycopg_installed
  4. Now delete psycopg2-2.5.4.win32-py2.7-pg9.3.5-release.exe we don’t need it anymore

PostgreSQL Part

If you already have a working PostgreSQL Installation and don’t wan’t to use the Batchfile for Setting the Bloodhound Environment you can directly continue with: Creating the Database User and the Bloodhound Database

Installing PostgreSQL

  1. Execute the PostgreSQL Installer and leave every Option as it is
  2. As password choose postgres

Adding PostgreSQL to the Bloodhound Environment Script

  1. Open SetBloodhoundEnvironment.cmd with your preferred Editor.
  2. Make the following Changes (changes are red marked and bold)
    @ echo off
    REM Retrieve the Path to the Directory from this Batch File
    set THIS_BATCH_PATH=%~dp0
    if "%INITIALIZE_STATE%" == "" (
        REM Expand variables at execution time rather than at parse time
        setlocal EnableDelayedExpansion
    
        REM Temporarily change to the Bloodhound Root Directory
        REM to retrieve the full path to that Directory
        pushd !THIS_BATCH_PATH!..
        set BLOODHOUND_DIR=!CD!
        popd
    
        REM Set Variables for our Environment
        set VENV_SCRIPTS_DIR=C:\bloodhound\VirtualPythonEnvironment\Scripts
        set POSTGRESQL_DIR=C:\Programme\PostgreSQL\9.3\bin
    
        REM Add our Directorys to PATH
        set "PATH=!POSTGRESQL_DIR!;!VENV_SCRIPTS_DIR!;!PATH!"
    
        goto finish_init
    ) else (
        REM Environment Variables are already set so lets just print the Overview
        goto print_overview
    )
    
    :finish_init
    endlocal & (
        REM Make the Variables globally available
        set INITIALIZE_STATE=INITIALIZED
        set BLOODHOUND_DIR=%BLOODHOUND_DIR%
        set VENV_SCRIPTS_DIR=%VENV_SCRIPTS_DIR%
        set POSTGRESQL_DIR=%POSTGRESQL_DIR%
        set PATH=%PATH%
    )
    
    :print_overview
    echo Bloodhound Environment is now set. 
    echo Here is an overview of the most commonly used commands to help you get started:
    echo 1. Python Interpreter          (Command: python)
    echo 2. Python Package Manager      (Command: pip)
    echo 3. Python Setuptools           (Command: easy_install)
    echo 4. PostgreSQL Control Utility  (Command: pg_ctl)
    echo.
    
  3. Save the File and Close the Editor
  4. Reopen cmd
  5. Execute:
    SetBloodhoundEnvironment.cmd
  6. Execute:
    pg_ctl --version

    Output:

    pg_ctl (PostgreSQL) 9.3.5

  7. Example: pg_ctl_version

Creating the Database User and the Bloodhound Database

  1. Execute the following Command to create the Database User:
    createuser --username=postgres --no-superuser --no-createdb --no-createrole --encrypted --pwprompt bloodhound
  2. The createuser program will ask some Questions. Answer them like here:
    • Geben sie das Passwort der neuen Rolle ein: bloodhound
    • Geben Sie es nochmal ein: bloodhound
    • Password: postgres
  3. Example:
    postgres_config_createuser
  4. Execute the following Command to create the Bloodhound Database:
    createdb --username=postgres --owner=bloodhound --encoding=UTF-8 bloodhound
  5. The createdb program will ask for the PostgreSQL Password. Enter:
    postgres
  6. Example:
    postgres_config_createdb

Apache Bloodhound Part

Installing Apache Bloodhound

  1. Open apache-bloodhound-0.7.tar.gz with 7-Zip and copy the contents of the Folder apache-bloodhound-0.7 into the BloodhoundInstallDir Folder
  2. The Bloodhound Directory should now have the following Content: bloodhound_files-extracted
  3. In cmd change to Subfolder VirtualPythonEnvironment\Scripts
  4. Execute:
    activate.bat

    That should change the Command Prompt bloodhound_changed_cmp

  5. Now change the Path to BloodhoundInstallDir\installer
  6. Execute the command:
    pip install -r requirements.txt
  7. The Bloodhound Requirements will now be installed. If everything goes right you should see this Message afterwards: bloodhound_requirements_installed
  8. Now execute the command
     python bloodhound_setup.py --environments_directory=C:\bloodhound\bloodhound_environments --default-product-prefix=Test
  9. The installer will now ask a few Questions. Answer them like here:
    • Do you want to install to a PostgreSQL database [Y/n]: y
    • DB user name [bloodhound]: bloodhound
    • Enter a new password for “bloodhound”: bloodhound
    • Please supply a username for the admin user [admin]: admin
    • Enter a new password for “admin”: admin
    • Please reenter the password: admin
  10. Apache Bloodhound will now be installed. The Installation should end with: bloodhound_installation_end
  11. Now to check if the Installation was successfull do the following:
    1. In cmd execute:
      tracd --port=8000 C:\bloodhound\bloodhound_environments\main

      bloodhound_running

    2. Start your Browser and open http://localhost:8000/main
      bloodhound_in_browser
    3. Click on Login
    4. Login with
      • Username: admin
      • Password: admin

      bloodhound_login

Troubleshooting

  • If something goes wrong delete the Folder C:\bloodhound\bloodhound_environments\main and try it again.

Running Bloodhound

Here is the full Procedure that needs to be done if you want to start Bloodhound again after closing it.

  1. Open a cmd and navigate to C:\bloodhound
  2. Type SetBloodhoundEnvironment.cmd and press Enter
  3. Change to Subfolder VirtualPythonEnvironment\Scripts
  4. Execute:
    activate.bat

    That should change the Command Prompt

  5. Execute the command:
    tracd --port=8000 C:\bloodhound\bloodhound_environments/main
  6. Apache Bloodhound is now running. You can use it from your Webbrowser by opening the Site http://localhost:8000/main. bloodhound_in_browser

Apache HTTPD Server Part

Installing the Apache HTTPD Server

  1. Create the Folder where you want to install the Apache HTTPD Server. I use C:\ApacheHTTPD
  2. Open Apache Webserver File httpd-2.4.10-win32-VC11.zip with 7-Zip
  3. Inside 7-Zip make a doubleclick on the Apache24 Folder
    apache_folder_in_seven_zip
  4. Now copy everything from the 7-Zip Window to C:\ApacheHTTPD. The Content of the Directory should now be like this:
    apache_directory_content

Adding Apache HTTPD Server to the Bloodhound Environment Script

  1. Open SetBloodhoundEnvironment.cmd with your preferred Editor.
  2. Make the following Changes (changes are red marked and bold)
    @ echo off
    REM Retrieve the Path to the Directory from this Batch File
    set THIS_BATCH_PATH=%~dp0
    if "%INITIALIZE_STATE%" == "" (
        REM Expand variables at execution time rather than at parse time
        setlocal EnableDelayedExpansion
    
        REM Temporarily change to the Bloodhound Root Directory
        REM to retrieve the full path to that Directory
        pushd !THIS_BATCH_PATH!..
        set BLOODHOUND_DIR=!CD!
        popd
    
        REM Set Variables for our Environment
        set VENV_SCRIPTS_DIR=C:\bloodhound\VirtualPythonEnvironment\Scripts
        set POSTGRESQL_DIR=C:\Programme\PostgreSQL\9.3\bin
        set APACHE_HTTP_SERVER_DIR=C:\ApacheHTTPD\bin
    
        REM Add our Directorys to PATH
        set "PATH=!APACHE_HTTP_SERVER_DIR!;!POSTGRESQL_DIR!;!VENV_SCRIPTS_DIR!;!PATH!"
    
        goto finish_init
    ) else (
        REM Environment Variables are already set so lets just print the Overview
        goto print_overview
    )
    
    :finish_init
    endlocal & (
        REM Make the Variables globally available
        set INITIALIZE_STATE=INITIALIZED
        set BLOODHOUND_DIR=%BLOODHOUND_DIR%
        set VENV_SCRIPTS_DIR=%VENV_SCRIPTS_DIR%
        set POSTGRESQL_DIR=%POSTGRESQL_DIR%
        set APACHE_HTTP_SERVER_DIR=%APACHE_HTTP_SERVER_DIR%
        set PATH=%PATH%
    )
    
    :print_overview
    echo Bloodhound Environment is now set. 
    echo Here is an overview of the most commonly used commands to help you get started:
    echo 1. Python Interpreter          (Command: python)
    echo 2. Python Package Manager      (Command: pip)
    echo 3. Python Setuptools           (Command: easy_install)
    echo 4. PostgreSQL Control Utility  (Command: pg_ctl)
    echo 5. Apache HTTP Server          (Command: httpd)
    echo.
    

Configuring the HTTPD Server to run Bloodhound

  1. We need the correct Version of the WSGI module to run Apache Bloodhound. Because we have Apache Webserver 2.4.10 and Python 2.7.8 we need: mod_wsgi-3.5.ap24.win32-py2.7.zip
  2. Extract mod_wsgi-3.5.ap24.win32-py2.7.zip into:
    C:\ApacheHTTPD\modules
  3. Open C:\ApacheHTTPD\conf\httpd.conf with your preferred Editor
  4. We need to configure Apache so that it loads the correct Python DLL because otherwise we won’t be able to load the mod_wsgi Module which is needed for Bloodhound.
    To do this add the following Lines before the LoadModule Section:

    # Load the Python DLL because otherwise we won't be able to load the mod_wsgi Module
    LoadFile "C:\bloodhound\VirtualPythonEnvironment\Scripts\python27.dll"
  5. Now search for the Line:
    #LoadModule auth_digest_module modules/mod_auth_digest.so
    and remove the #.
  6. Then after #LoadModule watchdog_module modules/mod_watchdog.so insert:
    LoadModule wsgi_module modules/mod_wsgi.so
  7. Search for the Line: # Virtual hosts
  8. Change it the following Way:
    # Virtual hosts
    <IfModule wsgi_module>
        Include conf/extra/httpd-vhosts.conf
    </IfModule>
    
  9. Open the File C:\ApacheHTTPD\conf\extra\httpd-vhosts.conf
  10. Replace the Content (except the Comments) with the following:
    # Configure wsgi to use our Python Virtual Environment
    WSGIPythonHome C:/bloodhound/VirtualPythonEnvironment
    WSGIPythonPath C:/bloodhound/bloodhound_environments/main/site;C:/bloodhound/VirtualPythonEnvironment/Lib/site-packages
    <VirtualHost *:80>
        WSGIScriptAlias /bloodhound C:/bloodhound/bloodhound_environments/main/site/cgi-bin/trac.wsgi
        <Directory C:/bloodhound/bloodhound_environments/main/site/cgi-bin>
            WSGIApplicationGroup %{GLOBAL}
            Require all granted
            <Files trac.wsgi>
                Require all granted
            <Files>
        </Directory>
        <LocationMatch "/bloodhound/[^/]+/login">
            AuthType Digest
            AuthName "Bloodhound"
            AuthDigestDomain /bloodhound
            AuthUserFile C:/bloodhound/bloodhound_environments/main/bloodhound.htdigest
            Require valid-user
        </LocationMatch>
    </VirtualHost>
    
  11. Open a Commandline and navigate to:

    C:\bloodhound\VirtualPythonEnvironment\Scripts

  12. Execute:
    trac-admin C:\bloodhound\bloodhound_environments\main\ deploy C:\bloodhound\bloodhound_environments\main\site
  13. Start the Apache Webserver by executing:
    C:\ApacheHTTPD\bin\httpd.exe -w -f C:\ApacheHTTPD\conf\httpd.conf
  14. Start the PostgreSQL Server by executing:
    C:\Programme\PostgreSQL\9.3\bin\pg_ctl -D "C:/Programme/PostgreSQL/9.3/data" start
  15. Open your Webbrowser and navigate to: localhost/bloodhound
  16. And you should see the Bloodhound Start Page
    apache_httpd_serving_bloodhound

Known Issues

  • Bloodhound runs under the User you are logged into the System. If you want to change this see the Bloodhound Documentation: Users and file location
  • The Apache HTTP Server prints out a Warning that mod_wsgi was made for Python 2.7.7
Advertisements
Posted in Buildchain | Leave a comment