build.sh 3.9 KB

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