3
0

test_SMBScanAttack.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import unittest.mock as mock
  2. import Test.ID2TAttackTest as Test
  3. sha_default = 'ef321877edfd828f6e6cd4abbffb5ade9cb66b3acd54ba9f3a5e2bfbeac9c964'
  4. sha_one_victim_linux = '4928d421caaec8f2c4e5c5bb835b5521b705478779cbc8f343b77143a5a66995'
  5. sha_victim_range_winxp_hosting = '4c6cb5cb4f838e75b41af4feb2fd9a6fe7e1b226a38b3e8759ce3d31e5a2535e'
  6. sha_multiple_victims_macos = '82d6d7e0471e6395c77df7b5bac141e48d50afe22841c7c53747bbfdd0de184d'
  7. sha_port_shuffle = '8ef501fa31135b8fea845a2be6a9605e0c3f9c4895b717f9206d485a669c2a73'
  8. sha_dest_mac_only = '0814dadb666e0056ef5b3a572a4971f333376b61e602acb84cb99c851845f016'
  9. sha_ip_src_shuffle = '6c0c9ccbedb631e4965ec36932276a1bd73b8a4aca5a5c46f01fd0a2800a064f'
  10. sha_smb2 = '8755a901295a90362d8041ecf1243a31fff582f5fe64555205625263c253476e'
  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_invalid_smb_platform(self):
  33. with self.assertRaises(SystemExit):
  34. self.checksum_test([['SMBScanAttack', 'hosting.version=1337']], 'somehash')
  35. def test_smbscan_port_shuffle(self):
  36. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  37. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5-192.168.178.10',
  38. 'hosting.ip=192.168.178.5', 'port.src.shuffle=false']], sha_port_shuffle)
  39. def test_smbscan_dest_mac_only(self):
  40. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  41. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'mac.dst=00:0C:29:9C:70:64']],
  42. sha_dest_mac_only)
  43. def test_smbscan_src_ip_shuffle(self):
  44. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  45. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5-192.168.178.10',
  46. 'hosting.ip=192.168.178.5', 'ip.src.shuffle=True']], sha_ip_src_shuffle)
  47. def test_smbscan_smb2(self):
  48. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="linux"):
  49. self.checksum_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5-192.168.178.10',
  50. 'hosting.ip=192.168.178.5', 'protocol.version=2.1', 'hosting.version=2.1']], sha_smb2)
  51. def test_smbscan_order(self):
  52. self.order_test([['SMBScanAttack']])