3
0

build.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/bash
  2. FULLBUILD=false
  3. NONINTERACTIVE=false
  4. while test $# -gt 0
  5. do
  6. case "$1" in
  7. --non-interactive)
  8. NONINTERACTIVE=true
  9. ;;
  10. --full)
  11. FULLBUILD=true
  12. ;;
  13. esac
  14. shift
  15. done
  16. # Install required packages
  17. if [ ! ${NONINTERACTIVE} = true ]; then
  18. ./resources/install_dependencies.sh
  19. fi
  20. # Fullbuild or nonexistent venv
  21. if [ ${FULLBUILD} = true -o ! -d .venv ]; then
  22. rm -Rf .venv
  23. python3 -m venv .venv
  24. if [ $? != 0 ]; then
  25. echo "Error: Could not create the venv. Please make sure the 'venv' Python-module is installed."
  26. exit
  27. fi
  28. fi
  29. # Activate the venv
  30. source .venv/bin/activate
  31. # Install python packages
  32. pip3 install -r resources/requirements.txt
  33. # Deactivate the venv
  34. deactivate
  35. # Create the Makefile using cmake, from a clean build directory
  36. cd code_boost/src/build/
  37. if [ ${PWD##*/} = 'build' ]; then
  38. if [ ${FULLBUILD} = true ]; then
  39. # Only delete everything if we are in a folder called 'build'.
  40. rm -rf ./*
  41. fi
  42. else
  43. echo "Error: The 'build' directory was not found."
  44. exit
  45. fi
  46. which ninja &>/dev/null
  47. if [ $? != 0 ]; then
  48. cmake ..
  49. # Make sure we're able to get the number of cores
  50. if [ $(uname) = 'Darwin' ]; then
  51. NUMCORES=$(sysctl -n hw.logicalcpu)
  52. else
  53. NUMCORES=$(nproc)
  54. fi
  55. if [ -f Makefile ]; then
  56. make -j$NUMCORES
  57. else
  58. echo "Error: 'cmake' did not finish successfully."
  59. exit
  60. fi
  61. else
  62. cmake .. -G Ninja
  63. if [ -f build.ninja ]; then
  64. ninja
  65. else
  66. echo "Error: 'cmake' did not finish successfully."
  67. exit
  68. fi
  69. fi
  70. if [ $? -eq 0 ]; then
  71. cp libpcapreader.so ../../../code/ID2TLib/
  72. cp libbotnetcomm.so ../../../code/ID2TLib/Botnet
  73. else
  74. echo "Error: 'make' did not finish successfully."
  75. exit
  76. fi
  77. cd ../../../
  78. # Create the ID2T script
  79. cat >./id2t <<EOF
  80. #!/bin/bash
  81. # Find the executable
  82. if [ $(uname) = 'Darwin' ]; then
  83. ID2T_DIR=\$(greadlink -f \$0)
  84. else
  85. ID2T_DIR=\$(readlink -f \$0)
  86. fi
  87. SCRIPT_PATH=\${ID2T_DIR%/*}
  88. # Execute ID2T
  89. source "\$SCRIPT_PATH"/.venv/bin/activate
  90. exec "\$SCRIPT_PATH"/code/CLI.py "\$@"
  91. deactivate
  92. EOF
  93. # Create the test script
  94. cat >./run_tests <<EOF
  95. #!/bin/bash
  96. # Find the executable
  97. if [ $(uname) = 'Darwin' ]; then
  98. ID2T_DIR=\$(greadlink -f \$0)
  99. else
  100. ID2T_DIR=\$(readlink -f \$0)
  101. fi
  102. SCRIPT_PATH=\${ID2T_DIR%/*}
  103. cd \$SCRIPT_PATH
  104. source .venv/bin/activate
  105. # Regenerate the statistics DB
  106. ./id2t -i resources/test/reference_1998.pcap -r >/dev/null
  107. cd code
  108. # Execute tests
  109. set -e
  110. PRINT_COV=true
  111. testpath="discover -s Test/"
  112. if [ -e "Test/test_\$1.py" ]; then
  113. testpath="Test/test_\$1.py"
  114. PRINT_COV=false
  115. fi
  116. PYTHONWARNINGS="ignore" python3 -m coverage run --source=. -m unittest \$testpath >/dev/null
  117. if \$PRINT_COV ; then
  118. python3 -m coverage html
  119. python3 -m coverage report -m
  120. fi
  121. deactivate
  122. EOF
  123. # Create the test script
  124. cat >./test_efficiency <<EOF
  125. #!/bin/bash
  126. # Find the executable
  127. if [ $(uname) = 'Darwin' ]; then
  128. ID2T_DIR=\$(greadlink -f \$0)
  129. else
  130. ID2T_DIR=\$(readlink -f \$0)
  131. fi
  132. SCRIPT_PATH=\${ID2T_DIR%/*}
  133. TEST_DIR=\${SCRIPT_PATH}/resources/test/
  134. TEST_PCAP=\${TEST_DIR}reference_1998.pcap
  135. PLOT_DIR=\${TEST_DIR}/plot/
  136. cd \${SCRIPT_PATH}/code
  137. error=0
  138. # Execute tests
  139. set +e
  140. python3 -m unittest Test/efficiency_testing.py
  141. error=\$?
  142. cd \$SCRIPT_PATH
  143. source .venv/bin/activate
  144. mkdir \$PLOT_DIR
  145. smbloris="SMBLorisAttack attackers.count=4 packets.per-second=8.0"
  146. smbscan1="SMBScanAttack ip.src=192.168.178.1 ip.dst=192.168.178.10-192.168.179.253"
  147. smbscan2="SMBScanAttack ip.src=192.168.178.1 ip.dst=192.168.178.10-192.168.178.109 hosting.ip=192.168.178.10-192.168.178.109"
  148. ftp="FTPWinaXeExploit ip.src=192.168.178.1 ip.dst=192.168.178.10"
  149. porto="PortscanAttack ip.src=192.168.178.1 port.open=80"
  150. portc="PortscanAttack ip.src=192.168.178.1 port.open=20"
  151. sqli="SQLiAttack ip.dst=192.168.0.1"
  152. joomla="JoomlaRegPrivExploit ip.src=192.168.178.1"
  153. sality="SalityBotnet"
  154. ddos="DDoSAttack attackers.count=10 packets.per-second=95 attack.duration=10"
  155. ms17="MS17Scan ip.src=192.168.178.1"
  156. memcrashed="MemcrashedSpooferAttack"
  157. eb="EternalBlue"
  158. for i in "\$smbloris" "\$smbscan1" "\$smbscan2" "\$ftp" "\$porto" "\$portc" "\$sqli" "\$joomla" "\$sality" "\$ddos" "\$ms17" "\$memcrashed" "\$eb"; do
  159. mprof run ./id2t -i \${TEST_PCAP} -a \${i}
  160. mprof plot -t "\${i}" -o "\${PLOT_DIR}\${i}.png"
  161. mv mprofile_* "\${PLOT_DIR}\${i}.dat"
  162. done
  163. echo "\nPlotted images can be found in \"\${TEST_DIR}\"."
  164. echo "By executing \"mprof plot <file>.dat\" you can get a more detailed look."
  165. deactivate
  166. exit \$error
  167. EOF
  168. chmod +x ./code/CLI.py
  169. chmod +x ./id2t
  170. chmod +x ./run_tests
  171. chmod +x ./test_efficiency
  172. echo -e "\n\nAll is set. ID2T is ready."
  173. echo -e "\nRun efficiency tests with the command './test_efficiency'"
  174. echo -e "Run unit tests with the command './run_tests'"
  175. echo -e "Run ID2T with the command './id2t'"