test_SMBScanAttack.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import unittest.mock as mock
  2. import Test.ID2TAttackTest as Test
  3. sha_default = '68eeaed9682bdd63581cfe55c314ca3c024b487ebcbc2c539453b0ec85bcb21e'
  4. sha_dest_mac_only = '3b79e327a96dd6c8b49193cee794e813cfd6be50dd50c66e9082d984e8e91fc4'
  5. sha_multiple_victims_macos = '35c94ff8efd0958c39807e57477e967fdc100f9e12a68dcb6b368bb7de76056b'
  6. sha_one_victim_linux = 'aeb46ccd80e3862856931dc1d430e5a5e126deef5b291f9581735952f61facad'
  7. sha_port_shuffle = '9d124e51966324528e335e43a2a7bb635b20427a76337a5e1c91d56cc152acab'
  8. sha_smb2 = 'a3b3eebb41da0c8a8b6fd55855bdec44e30d2152947652113d496ec8f2aa60d9'
  9. sha_ip_src_shuffle = '79d86343ec9334cd750a8383f233e619142863c7010e48c28c4bc10a574c67e7'
  10. sha_victim_range_winxp_hosting = '7b3c001c9aab3d1c3a76c59efbaf197a4ea8aed7655a12f3e06d3e88d0fd5689'
  11. # TODO: improve coverage
  12. class UnitTestSMBScan(Test.ID2TAttackTest):
  13. def test_smbscan_default(self):
  14. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  15. self.checksum_test([['SMBScanAttack']], sha_default)
  16. def test_smbscan_one_victim_linux(self):
  17. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="linux"):
  18. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.10']],
  19. sha_one_victim_linux)
  20. def test_smbscan_victim_range_winxp_hosting(self):
  21. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="winxp"):
  22. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5-192.168.178.10',
  23. 'hosting.ip=192.168.178.5']], sha_victim_range_winxp_hosting)
  24. def test_smbscan_multiple_victims_macos(self):
  25. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="macos"):
  26. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1',
  27. 'ip.dst=192.168.178.10,192.168.178.15,192.168.178.20',
  28. 'hosting.ip=192.168.178.15,192.168.178.20']], sha_multiple_victims_macos)
  29. def test_smbscan_invalid_smb_version(self):
  30. with self.assertRaises(SystemExit):
  31. self.checksum_test([['SMBScanAttack', 'protocol.version=42']], 'somehash')
  32. def test_smbscan_port_shuffle(self):
  33. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  34. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5-192.168.178.10',
  35. 'hosting.ip=192.168.178.5', 'port.src.shuffle=false']], sha_port_shuffle)
  36. def test_smbscan_dest_mac_only(self):
  37. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  38. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'mac.dst=00:0C:29:9C:70:64']],
  39. sha_dest_mac_only)
  40. def test_smbscan_src_ip_shuffle(self):
  41. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  42. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5-192.168.178.10',
  43. 'hosting.ip=192.168.178.5', 'ip.src.shuffle=True']], sha_ip_src_shuffle)
  44. def test_smbscan_smb2(self):
  45. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="linux"):
  46. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5-192.168.178.10',
  47. 'hosting.ip=192.168.178.5', 'protocol.version=2.1', 'hosting.version=2.1']], sha_smb2)
  48. def test_smbscan_order(self):
  49. self.order_test([['SMBScanAttack']])