build.sh 3.4 KB

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