test_SMBScan.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import unittest
  2. import unittest.mock as mock
  3. import Test.GenericTest as GenericTest
  4. sha_default = '213e194da7bc952cc093868c7450901b0fb93c7255d694eb37ea0b9b48bca65d'
  5. sha_one_victim_linux = '4928d421caaec8f2c4e5c5bb835b5521b705478779cbc8f343b77143a5a66995'
  6. sha_victim_range_winxp_hosting = '4c6cb5cb4f838e75b41af4feb2fd9a6fe7e1b226a38b3e8759ce3d31e5a2535e'
  7. sha_multiple_victims_macos = '0be79b9ad7346562f392e07a5156de978e02f4f25ae8d409b81cc6e0d726012c'
  8. sha_port_shuffle = '8ef501fa31135b8fea845a2be6a9605e0c3f9c4895b717f9206d485a669c2a73'
  9. sha_dest_mac_only = '0814dadb666e0056ef5b3a572a4971f333376b61e602acb84cb99c851845f016'
  10. sha_ip_src_shuffle = '6c0c9ccbedb631e4965ec36932276a1bd73b8a4aca5a5c46f01fd0a2800a064f'
  11. sha_smb2 = '8755a901295a90362d8041ecf1243a31fff582f5fe64555205625263c253476e'
  12. """
  13. CURRENT COVERAGE
  14. Name Stmts Miss Cover Missing (lines)
  15. ---------------------------------------------------------------------------
  16. Attack/SMBScanAttack.py 239 9 96% 65, 73-74, 82, 193, 210-211, 284-285
  17. """
  18. # TODO: get 100% coverage
  19. class UnitTestSMBScan(GenericTest.GenericTest):
  20. def test_smbscan_default(self):
  21. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  22. self.generic_test([['SMBScanAttack']], sha_default)
  23. def test_smbscan_one_victim_linux(self):
  24. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="linux"):
  25. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.10']],
  26. sha_one_victim_linux)
  27. def test_smbscan_victim_range_winxp_hosting(self):
  28. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="winxp"):
  29. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  30. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5']],
  31. sha_victim_range_winxp_hosting)
  32. def test_smbscan_multiple_victims_macos(self):
  33. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="macos"):
  34. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1',
  35. 'ip.dst=192.168.178.10,192.168.178.15,192.168.178.20',
  36. 'hosting.ip=192.168.178.15,192.168.178.20']], sha_multiple_victims_macos)
  37. def test_smbscan_invalid_smb_version(self):
  38. with self.assertRaises(SystemExit):
  39. self.generic_test([['SMBScanAttack', 'protocol.version=42']], 'somehash')
  40. def test_smbscan_invalid_smb_platform(self):
  41. with self.assertRaises(SystemExit):
  42. self.generic_test([['SMBScanAttack', 'hosting.version=1337']], 'somehash')
  43. def test_smbscan_port_shuffle(self):
  44. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  45. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  46. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5', 'port.src.shuffle=false']],
  47. sha_port_shuffle)
  48. def test_smbscan_dest_mac_only(self):
  49. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  50. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1',
  51. 'mac.dst=00:0C:29:9C:70:64']], sha_dest_mac_only)
  52. def test_smbscan_src_ip_shuffle(self):
  53. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):
  54. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  55. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5', 'ip.src.shuffle=True']],
  56. sha_ip_src_shuffle)
  57. def test_smbscan_smb2(self):
  58. with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="linux"):
  59. self.generic_test([['SMBScanAttack', 'ip.src=192.168.178.1', 'ip.dst=192.168.178.5',
  60. 'ip.dst.end=192.168.178.10', 'hosting.ip=192.168.178.5', 'protocol.version=2.1',
  61. 'hosting.version=2.1']], sha_smb2)
  62. if __name__ == '__main__':
  63. unittest.main()