3
0

build.sh 4.2 KB

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