test_SMBScan.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import unittest
  2. import unittest.mock as mock
  3. from Test.GenericTest import GenericTest
  4. # FIXME: create new hashes if new test.pcap is used
  5. sha_default = '6650602f7ac54b0032504bba24c05a99ed09dcf094a0b6ea3172b95d805807f4'
  6. sha_one_victim_linux = '9da7ca3fe34f7a4f8d93d67b297afd198f0a4eb628171fbd25e15dc3d9bc97b5'
  7. sha_victim_range_winxp_hosting = '5d58804c68e1d94e12150283e4013c678f22fb819eb2207100f0341dacba88ec'
  8. sha_multiple_victims_macos = 'd39cd3dbdb85304d2629884118df070a78f9689ab7b3fd3a046c3706c3cd0f7e'
  9. sha_port_shuffle = 'd32d557c65c01f46ec3de769dc15d223ec13234016898f5ec7aaab1b9549801a'
  10. sha_dest_mac_only = 'af0140c0a2883927d429da82409f6bc091c9743e984111bda7c27d2bf99992ab'
  11. sha_ip_src_shuffle = 'c6ed7baf850ccc3f53551e9a93c0a397629eb064abae7deeafb05d84b2633b05'
  12. sha_smb2 = '8407a3316ba8dfb4ae610cedeeddfe4a7c0be1d420c2cad1c2750a213893618e'
  13. """
  14. CURRENT COVERAGE
  15. Name Stmts Miss Cover Missing (lines)
  16. ---------------------------------------------------------------------------
  17. Attack/SMBScanAttack.py 239 9 96% 65, 73-74, 82, 193, 210-211, 284-285
  18. """
  19. # TODO: get 100% coverage
  20. class UnitTestSMBScan(GenericTest):
  21. def test_default(self):
  22. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  23. self.generic_test([['SMBScanAttack']], sha_default)
  24. def test_one_victim_linux(self):
  25. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="linux"):
  26. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.10']],
  27. sha_one_victim_linux)
  28. def test_victim_range_winxp_hosting(self):
  29. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="winxp"):
  30. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  31. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5']],
  32. sha_victim_range_winxp_hosting)
  33. def test_multiple_victims_macos(self):
  34. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="macos"):
  35. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1',
  36. 'ip.dst=192.168.178.10,192.168.178.15,192.168.178.20',
  37. 'hosting.ip=192.168.178.15,192.168.178.20']], sha_multiple_victims_macos)
  38. def test_invalid_smb_version(self):
  39. with self.assertRaises(SystemExit):
  40. self.generic_test([['SMBScanAttack', 'protocol.version=42']], 'somehash')
  41. def test_invalid_smb_platform(self):
  42. with self.assertRaises(SystemExit):
  43. self.generic_test([['SMBScanAttack', 'hosting.version=1337']], 'somehash')
  44. def test_port_shuffle(self):
  45. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  46. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  47. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5', 'port.src.shuffle=false']],
  48. sha_port_shuffle)
  49. def test_dest_mac_only(self):
  50. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  51. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1',
  52. 'mac.dst=00:0C:29:9C:70:64']], sha_dest_mac_only)
  53. def test_src_ip_shuffle(self):
  54. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  55. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  56. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5', 'ip.src.shuffle=True']],
  57. sha_ip_src_shuffle)
  58. def test_smb2(self):
  59. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="linux"):
  60. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  61. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5', 'protocol.version=2.1',
  62. 'hosting.version=2.1']], sha_smb2)
  63. if __name__ == '__main__':
  64. unittest.main()