build.sh 3.4 KB

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