Browse Source

Improve how ID2T is built and run

Carlos Garcia 7 years ago
parent
commit
50d8000855

+ 32 - 11
README.md

@@ -13,30 +13,51 @@ The ID2T application was first proposed in [[1]](#references) and targets the in
 
 ## Getting Started
 
-### Prerequisities
-ID2T is written using Python 3.4 and C++ 11. The main logic is programmed in Python whereas performance critical components are programmed in C++11. The C++11 module uses the library [Libtins](https://github.com/mfontanini/libtins/). The python and c++ modules interact with each other through the library [Boost.Python](http://www.boost.org/doc/libs/1_62_0/libs/python/doc/html/index.html).
+### Dependencies
+ID2T is written using Python 3 and C++ 11. The main logic is programmed in Python whereas performance critical components are programmed in C++11. The C++11 module uses the [Libtins](https://github.com/mfontanini/libtins/) library. The python and c++ modules interact with each other through the [Boost.Python](http://www.boost.org/doc/libs/1_62_0/libs/python/doc/html/index.html) library .
+
+#### Required C++ Libraries
+The following packages/libraries are required to compile the ID2T C++ modules
+* ``cmake`` (minimum version 3.5)
+    - ubuntu: apt install build-essential cmake
+    - arch: pacman -S cmake
+* ``boost`` with the ``python`` component (minimum version 1.54)
+    - ubuntu: apt install libboost-dev libboost-python.61-dev
+    - arch: pacman -S boost boost-libs
+* ``libtins`` (minimum version 3.4)
+    - ubuntu: apt install libtins-dev
+    - arch: (install from AUR, i.e. pacaur -S libtins)
+* ``python`` development libraries
+    - ubuntu: apt install python3-dev
+    - arch: pacman -S python
+* ``sqlite`` (minimum version 3.0)
+    - ubuntu: apt install sqlite3
+    - arch: pacman -S sqlite
 
 #### Required Python Packages
-The following packages are required to run ID2T. Missing packages can be installed from terminal via  `` sudo pip install <packagename> ``.
+The following packages are required to run ID2T. Install the packages with your preferred package manager. For example, use ``sudo pip install <packagename>``.
+* ``scapy`` (make sure its the python3 version)
+* ``lea``
 
-* ``scapy``: used for packet creation (make sure its the python3 version)
-* ``lea``: used for calculation of parameters derived by the gathered statistics
+#### Notes on the Minimum Package Versions
+The minimum version stated in the previous requirements are the versions we have used in the development of ID2T. Other (older) versions might also work; however, we cannot guarantee nor support them. Furthermore, some compilation scripts would need to be manually modified to accommodate these older versions.
 
-### Installation
-Simply clone the repository to get started:
 
-``git clone https://git.tk.informatik.tu-darmstadt.de/SPIN/ID2T-toolkit ``
+### Compilation and Installation
+Clone the repository to get started:
+``git clone https://git.tk.informatik.tu-darmstadt.de/SPIN/ID2T-toolkit``
 
 After cloning the repository, initialize its submodules with
     git submodule init
     git submodule update
 
-Compile the C++ modules (description pending).
+Build the C++ modules and create the ID2T executable:
+``./build.sh``
 
-Run ID2T with the command ``python ./code/CLI.py`` .
+Run ID2T with the command ``./id2t``.
 
 ## Usage examples
-In this section, we provide some examples on using ID2T.
+In this section, we provide examples on how ID2T is used.
 
 ### Injecting an attack into an existing dataset
 In the following we inject the _PortscanAttack_ into the dataset *pcap_capture.pcap*:

+ 38 - 0
build.sh

@@ -0,0 +1,38 @@
+#!/bin/bash
+
+cd code_boost/src/build/
+cmake ..
+
+if [ -f Makefile ]; then
+    make
+else
+    echo "CMake did not finish successfully."
+    exit
+fi
+
+if [ $? -eq 0 ]; then
+    cp libpcapreader.so ../../../code/ID2TLib/
+else
+    echo "Make did not finish successfully."
+    exit
+fi
+
+cd ../../../
+#ln -s code/CLI.py id2t.py
+
+# Create the ID2T script
+cat >./id2t  <<EOF
+#!/bin/sh
+# Find the executable
+ID2T_DIR=\$(readlink -f \$0)
+SCRIPT_PATH=\${ID2T_DIR%/*}
+cd \$SCRIPT_PATH
+# Execute ID2T
+exec ./code/CLI.py "\$@"
+EOF
+
+chmod +x ./code/CLI.py
+chmod +x ./id2t
+
+echo -e "\n\nAll is set. ID2T is ready to be used."
+echo -e "\nRun ID2T with the command './id2t'"

+ 4 - 3
code/CLI.py

@@ -1,4 +1,4 @@
-#! /usr/bin/python3
+#! /usr/bin/env python3
 import argparse
 import sys
 
@@ -54,7 +54,8 @@ class CLI(object):
         """
         # Create parser for arguments
         parser = argparse.ArgumentParser(description="Intrusion Detection Dataset Toolkit (ID2T) - A toolkit for "
-                                                     "injection of synthetically created attacks into PCAP datasets.")
+                                         "injection of synthetically created attacks into PCAP datasets.",
+                                         prog="id2t")
         # Define required arguments
         # requiredNamed = parser.add_argument_group('required named arguments')
         # requiredNamed.add_argument('-i', '--input', metavar="FILEPATH", help='path to the input pcap file',
@@ -85,7 +86,7 @@ class CLI(object):
 
         # Either PCAP filepath or GUI mode must be enabled
         if not self.args.input and not self.args.gui:
-            parser.error("Parameter -i/--input or -g/--gui required.")
+            parser.error("Parameter -i/--input required. See available options with -h/--help ")
 
         # GUI mode enabled
         if self.args.gui:

BIN
code/ID2TLib/libpcapreader.so


+ 47 - 33
code_boost/src/CMakeLists.txt

@@ -6,56 +6,70 @@ project(cpp-pcapreader)
 # Define CMake settings
 cmake_minimum_required(VERSION 3.5)
 
+IF(NOT CMAKE_BUILD_TYPE)
+   SET(CMAKE_BUILD_TYPE "Release")
+ENDIF()
+
 IF (CMAKE_BUILD_TYPE MATCHES Debug)
-    MESSAGE(STATUS "Running DEBUG configuration. Skipping library generation.")
+    MESSAGE(STATUS "Running Debug configuration.")
 ELSEIF (CMAKE_BUILD_TYPE MATCHES Release)
-    MESSAGE(STATUS "Running RELEASE configuration. Creating library..")
+    MESSAGE(STATUS "Running Release configuration.")
 ENDIF()
 
-#IF(NOT CMAKE_BUILD_TYPE)
-#    SET(CMAKE_BUILD_TYPE "DEBUG")
-#ENDIF()
-set(CMAKE_CXX_STANDARD 11)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
+SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
+
+SET(CMAKE_CXX_STANDARD 11)
+SET(CMAKE_CXX_STANDARD_REQUIRED ON)
 
-# Add source files and build executable cpp-pcapreader
-set(SOURCE_FILES cxx/pcap_processor.cpp cxx/pcap_processor.h cxx/statistics.cpp cxx/statistics.h cxx/statistics_db.cpp cxx/statistics_db.h)
+# Add the library source files
+SET(SOURCE_FILES cxx/pcap_processor.cpp cxx/pcap_processor.h cxx/statistics.cpp cxx/statistics.h cxx/statistics_db.cpp cxx/statistics_db.h)
 
 # Include SQLiteCpp library and build it
+option(SQLITECPP_RUN_CPPLINT OFF)
 include_directories(SQLiteCpp/include)
 add_subdirectory(SQLiteCpp)
 
-# Find libtins library and link it to the executable cpp-pcapreader
-# Libs pthread and dl are prerequisites for SQLiteCpp
+# Find libtins library
 FIND_LIBRARY(TINS_LIBRARY tins)
+IF(TINS_LIBRARY)
+  MESSAGE(STATUS "Tins library found in ${TINS_LIBRARY}")
+ELSE()
+  MESSAGE(FATAL_ERROR "Tins library not found.")
+ENDIF()
+
+FIND_PACKAGE(PythonLibs 3.0 REQUIRED)
+IF(PYTHONLIBS_FOUND)
+  INCLUDE_DIRECTORIES("${PYTHON_INCLUDE_DIRS}")
+ELSE()
+  MESSAGE(FATAL_ERROR "Unable to find Python libraries.")
+ENDIF()
 
 # Find and configure BOOST library
-FIND_PACKAGE(Boost 1.54.0)
-IF (Boost_FOUND AND TINS_LIBRARY)
-    INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}" "/usr/include/python3.4m/")
+FIND_PACKAGE(Boost 1.54 QUIET)
+IF (Boost_FOUND)
+    INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}")
     SET(Boost_USE_STATIC_LIBS OFF)
     SET(Boost_USE_MULTITHREADED ON)
     SET(Boost_USE_STATIC_RUNTIME OFF)
-
-    FIND_PACKAGE(Boost 1.54.0 COMPONENTS "python-py34")
-
-    ADD_EXECUTABLE(cpp-pcapreader ${SOURCE_FILES})
-    ADD_LIBRARY(pcapreader SHARED ${SOURCE_FILES})
-
-    # link it to the executable cpp-pcapreader
-    # Libs pthread and dl are prerequisites for SQLiteCpp
-    TARGET_LINK_LIBRARIES(pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)
-    TARGET_LINK_LIBRARIES(cpp-pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)
+    # Find the boost python 3 component
+    SET(PYTHON_VERSIONS python3 python-py35 python-py34 python-py33 python-py32)
+    FOREACH(VERSION ${PYTHON_VERSIONS})
+      FIND_PACKAGE(Boost COMPONENTS ${VERSION} QUIET)
+      IF(Boost_FOUND)
+        MESSAGE(STATUS "Python Boost found as '${VERSION}'.")
+        BREAK()
+      ENDIF()
+    ENDFOREACH(VERSION)
+    IF(NOT Boost_FOUND)
+      MESSAGE(FATAL_ERROR "Python Boost component not found.")
+    ENDIF()
 ELSE ()
-    MESSAGE(FATAL_ERROR "Unable to find correct Boost version and/or Libtins library")
+    MESSAGE(FATAL_ERROR "Unable to find the Boost libraries (version 1.54 or higher).")
 ENDIF ()
 
+SET_target_properties(sqlite3 PROPERTIES POSITION_INDEPENDENT_CODE ON)
 
-# Check if GNUCXX compiler is configured
-set_target_properties(sqlite3 PROPERTIES POSITION_INDEPENDENT_CODE ON)
-IF(CMAKE_COMPILER_IS_GNUCXX)
-	ADD_DEFINITIONS("-Wall")
-    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")        ## Optimize
-ELSE()
-	MESSAGE(FATAL_ERROR "CMakeLists.txt has not been tested...")
-ENDIF()
+ADD_LIBRARY(pcapreader SHARED ${SOURCE_FILES})
+# Libs pthread and dl are prerequisites of SQLiteCpp
+TARGET_LINK_LIBRARIES(pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)

BIN
code_boost/src/release_test/libpcapreader.so


+ 0 - 16
code_boost/src/release_test/pcapreader.py

@@ -1,16 +0,0 @@
-# import libpcapreader as pr
-import release_test.libpcapreader as pr
-import operator
-
-pcap = pr.pcap_processor("/mnt/hgfs/datasets/95M.pcap")
-
-# target=open(file.getFilePath()+".stat", 'w')
-# target.truncate()
-
-pcap.collect_statistics()
-#print( pcap.get_timestamp_mu_sec(87) )
-
-# filepath_mergedPcap = pcap.merge_pcaps("/mnt/hgfs/datasets/PcapExamples/LDAP.pcap")
-#print(filepath_mergedPcap)
-
-pcap.write_to_database("/home/pjattke/myDB.sqlite3")