3
0

build.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. PLOT_DIR=\${TEST_DIR}/plot/
  83. cd \${SCRIPT_PATH}/code
  84. error=0
  85. # Execute tests
  86. set +e
  87. python3 -m unittest Test/efficiency_testing.py
  88. error=\$?
  89. cd \$SCRIPT_PATH
  90. mkdir \$PLOT_DIR
  91. smbloris="SMBLorisAttack attackers.count=4 packets.per-second=8.0"
  92. smbscan1="SMBScanAttack ip.src=192.168.178.1 ip.dst=192.168.178.10-192.168.179.253"
  93. 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"
  94. ftp="FTPWinaXeExploit ip.src=192.168.178.1 ip.dst=192.168.178.10"
  95. porto="PortscanAttack ip.src=192.168.178.1 port.open=80"
  96. portc="PortscanAttack ip.src=192.168.178.1 port.open=20"
  97. sqli="SQLiAttack ip.dst=192.168.0.1"
  98. joomla="JoomlaRegPrivExploit ip.src=192.168.178.1"
  99. sality="SalityBotnet"
  100. ddos="DDoSAttack attackers.count=10 packets.per-second=95 attack.duration=10"
  101. ms17="MS17Scan ip.src=192.168.178.1"
  102. eb="EternalBlue"
  103. for i in "\$smbloris" "\$smbscan1" "\$smbscan2" "\$ftp" "\$porto" "\$portc" "\$sqli" "\$joomla" "\$sality" "\$ddos" "\$ms17" "\$eb"; do
  104. mprof run ./id2t -i \${TEST_PCAP} -a \${i}
  105. mprof plot -t "\${i}" -o "\${PLOT_DIR}\${i}.png"
  106. mv mprofile_* "\${PLOT_DIR}\${i}.dat"
  107. done
  108. echo "\nPlotted images can be found in \"\${TEST_DIR}\"."
  109. echo "By executing \"mprof plot <file>.dat\" you can get a more detailed look."
  110. exit \$error
  111. EOF
  112. chmod +x ./code/CLI.py
  113. chmod +x ./id2t
  114. chmod +x ./run_tests
  115. chmod +x ./test_efficiency
  116. echo -e "\n\nAll is set. ID2T is ready."
  117. echo -e "\nRun efficiency tests with the command './test_efficiency'"
  118. echo -e "Run unit tests with the command './run_tests'"
  119. echo -e "Run ID2T with the command './id2t'"