build.sh 3.9 KB

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