build.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. else
  42. echo "Error: 'make' did not finish successfully."
  43. exit
  44. fi
  45. cd ../../../
  46. # Create the ID2T script
  47. cat >./id2t <<EOF
  48. #!/bin/sh
  49. # Find the executable
  50. if [ $(uname) = 'Darwin' ]; then
  51. alias readlink='greadlink'
  52. fi
  53. ID2T_DIR=\$(readlink -f \$0)
  54. SCRIPT_PATH=\${ID2T_DIR%/*}
  55. cd \$SCRIPT_PATH
  56. # Execute ID2T
  57. exec ./code/CLI.py "\$@"
  58. EOF
  59. # Create the test script
  60. cat >./run_tests <<EOF
  61. #!/bin/sh
  62. # Find the executable
  63. if [ $(uname) = 'Darwin' ]; then
  64. alias readlink='greadlink'
  65. fi
  66. ID2T_DIR=\$(readlink -f \$0)
  67. SCRIPT_PATH=\${ID2T_DIR%/*}
  68. cd \$SCRIPT_PATH
  69. # Regenerate the statistics DB
  70. ./id2t -i resources/test/reference_1998.pcap -r >/dev/null
  71. cd code
  72. # Execute tests
  73. set -e
  74. PRINT_COV=true
  75. testpath="discover -s Test/"
  76. if [ -e "Test/test_\$1.py" ]; then
  77. testpath="Test/test_\$1.py"
  78. PRINT_COV=false
  79. fi
  80. PYTHONWARNINGS="ignore" coverage3 run --source=. -m unittest \$testpath >/dev/null
  81. if \$PRINT_COV ; then
  82. coverage3 html
  83. coverage3 report -m
  84. fi
  85. EOF
  86. # Create the test script
  87. cat >./test_efficiency <<EOF
  88. #!/bin/sh
  89. # Find the executable
  90. if [ $(uname) = 'Darwin' ]; then
  91. alias readlink='greadlink'
  92. fi
  93. ID2T_DIR=\$(readlink -f \$0)
  94. SCRIPT_PATH=\${ID2T_DIR%/*}
  95. TEST_DIR=\${SCRIPT_PATH}/resources/test/
  96. TEST_PCAP=\${TEST_DIR}reference_1998.pcap
  97. PLOT_DIR=\${TEST_DIR}/plot/
  98. cd \${SCRIPT_PATH}/code
  99. error=0
  100. # Execute tests
  101. set +e
  102. python3 -m unittest Test/efficiency_testing.py
  103. error=\$?
  104. cd \$SCRIPT_PATH
  105. mkdir \$PLOT_DIR
  106. smbloris="SMBLorisAttack attackers.count=4 packets.per-second=8.0"
  107. smbscan1="SMBScanAttack ip.src=192.168.178.1 ip.dst=192.168.178.10-192.168.179.253"
  108. 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"
  109. ftp="FTPWinaXeExploit ip.src=192.168.178.1 ip.dst=192.168.178.10"
  110. porto="PortscanAttack ip.src=192.168.178.1 port.open=80"
  111. portc="PortscanAttack ip.src=192.168.178.1 port.open=20"
  112. sqli="SQLiAttack ip.dst=192.168.0.1"
  113. joomla="JoomlaRegPrivExploit ip.src=192.168.178.1"
  114. sality="SalityBotnet"
  115. ddos="DDoSAttack attackers.count=10 packets.per-second=95 attack.duration=10"
  116. ms17="MS17Scan ip.src=192.168.178.1"
  117. eb="EternalBlue"
  118. for i in "\$smbloris" "\$smbscan1" "\$smbscan2" "\$ftp" "\$porto" "\$portc" "\$sqli" "\$joomla" "\$sality" "\$ddos" "\$ms17" "\$eb"; do
  119. mprof run ./id2t -i \${TEST_PCAP} -a \${i}
  120. mprof plot -t "\${i}" -o "\${PLOT_DIR}\${i}.png"
  121. mv mprofile_* "\${PLOT_DIR}\${i}.dat"
  122. done
  123. echo "\nPlotted images can be found in \"\${TEST_DIR}\"."
  124. echo "By executing \"mprof plot <file>.dat\" you can get a more detailed look."
  125. exit \$error
  126. EOF
  127. chmod +x ./code/CLI.py
  128. chmod +x ./id2t
  129. chmod +x ./run_tests
  130. chmod +x ./test_efficiency
  131. echo -e "\n\nAll is set. ID2T is ready."
  132. echo -e "\nRun efficiency tests with the command './test_efficiency'"
  133. echo -e "Run unit tests with the command './run_tests'"
  134. echo -e "Run ID2T with the command './id2t'"