3
0

test_FTPWinaXeExploit.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import unittest.mock as mock
  2. import ID2TLib.TestLibrary as Lib
  3. import Test.ID2TAttackTest as Test
  4. sha_ftp_basic = '11af85015d4db6e218cb59d9b674e67144e1c64dbdfc83a474917c00f85979e3'
  5. sha_ftp_mac = '088ef4af557101664d5eb8ff13d4ff33fd71c8d47a9c622381388948cfdfbb1a'
  6. sha_ftp_random_ip_src = '1379b3e6d585d50e9f9b577e4bbba5ca621a6521e24ad483b2f826a20c8df8ed'
  7. sha_not_empty_custom_payload_empty_file = 'b561442183789ad36adcce085fdff7f84bebc65e4b4e8c134ba578864c4d8e35'
  8. sha_empty_custom_payload_not_empty_file = 'e577fa534a05606af1a5b3fbf71e04eb7c1713fc3d8923c6f12c7b7a2301693e'
  9. sha_valid_ip = '11af85015d4db6e218cb59d9b674e67144e1c64dbdfc83a474917c00f85979e3'
  10. # TODO: improve coverage
  11. class UnitTestFTPWinaXeExploit(Test.ID2TAttackTest):
  12. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
  13. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
  14. def test_ftp_basic(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  15. self.checksum_test([['FTPWinaXeExploit']], sha_ftp_basic)
  16. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
  17. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
  18. @mock.patch('Core.Statistics.Statistics.get_mac_address')
  19. def test_ftp_mac(self, mock_mac_address, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  20. mock_mac_address.return_value = Lib.test_pcap_empty
  21. self.checksum_test([['FTPWinaXeExploit']], sha_ftp_mac)
  22. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
  23. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
  24. def test_ftp_random_ip_src(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  25. self.checksum_test([['FTPWinaXeExploit', 'ip.src.shuffle=1']], sha_ftp_random_ip_src)
  26. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
  27. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
  28. def test_ftp_not_empty_custom_payload_empty_file(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  29. self.checksum_test([['FTPWinaXeExploit', 'custom.payload=1']], sha_not_empty_custom_payload_empty_file)
  30. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
  31. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
  32. @mock.patch('ID2TLib.Utility.check_payload_len')
  33. @mock.patch('ID2TLib.Utility.get_bytes_from_file', return_value=b'AAAAA')
  34. def test_ftp_empty_custom_payload_not_empty_file(self, mock_bytes_from_file, mock_payload_len, mock_get_rnd_x86_nop,
  35. mock_get_rnd_bytes):
  36. self.checksum_test([['FTPWinaXeExploit', 'custom.payload.file=1']], sha_empty_custom_payload_not_empty_file)
  37. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
  38. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
  39. @mock.patch('Attack.BaseAttack.BaseAttack.is_valid_ip_address', return_values=[False, True])
  40. def test_ftp_invalid_ip(self, mock_valid_ip_check, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  41. self.checksum_test([['FTPWinaXeExploit']], sha_valid_ip)
  42. def test_ftp_order(self):
  43. self.order_test([['FTPWinaXeExploit']])