build.sh 3.6 KB

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