3
0

test_FTPWinaXeExploit.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import unittest
  2. import unittest.mock as mock
  3. from Test.GenericTest import GenericTest
  4. from Test.Lib import *
  5. sha_ftp_basic = '941947ccc42ea10e724d2a20626882130d62fc5dbbe007095a90f67a943ab3bf'
  6. sha_ftp_most_used_ip = '941947ccc42ea10e724d2a20626882130d62fc5dbbe007095a90f67a943ab3bf'
  7. sha_ftp_mac = 'c2e83e62bb8a15402725faef47a53c6e5afa3dd82a17435d48000058976160cb'
  8. sha_ftp_random_ip_src = '41ae677b553064428905682f6a17447850cc4c1b617c337e046ee6e50f51217b'
  9. sha_not_empty_custom_payload_empty_file = '369d59174de5f01787ea623673f320e8342ddd6be9761edb607bf635f44a3749'
  10. sha_empty_custom_payload_not_empty_file = '9d3ec2451b05acc72b99b40309b714bc015b6d12b5477f6490cd2f9ba8f1ffa8'
  11. sha_valid_ip = '941947ccc42ea10e724d2a20626882130d62fc5dbbe007095a90f67a943ab3bf'
  12. """
  13. Name Stmts Miss Cover Missing
  14. --------------------------------------------------------------------------------------------
  15. Attack/FTPWinaXeExploit.py 141 14 99% 67
  16. """
  17. class UnitTestFTPWinaXeExploit(GenericTest):
  18. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
  19. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
  20. def test_ftp_basic(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  21. self.generic_test([['FTPWinaXeExploit']], sha_ftp_basic)
  22. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
  23. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
  24. @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
  25. def test_ftp_most_used_ips(self,mock_most_used_ip_address, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  26. mock_most_used_ip_address.return_value = test_pcap_ips
  27. self.generic_test([['FTPWinaXeExploit']], sha_ftp_most_used_ip)
  28. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
  29. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
  30. @mock.patch('ID2TLib.Statistics.Statistics.get_mac_address')
  31. def test_ftp_mac(self, mock_mac_address, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  32. mock_mac_address.return_value = test_pcap_empty
  33. self.generic_test([['FTPWinaXeExploit']], sha_ftp_mac)
  34. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
  35. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
  36. def test_ftp_random_ip_src(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  37. self.generic_test([['FTPWinaXeExploit', 'ip.src.shuffle=1']], sha_ftp_random_ip_src)
  38. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
  39. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
  40. def test_ftp_not_empty_custom_payload_empty_file(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  41. self.generic_test([['FTPWinaXeExploit', 'custom.payload=1']], sha_not_empty_custom_payload_empty_file)
  42. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
  43. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
  44. @mock.patch('ID2TLib.Utility.check_payload_len')
  45. @mock.patch('ID2TLib.Utility.get_bytes_from_file', return_value=b'AAAAA')
  46. def test_ftp_empty_custom_payload_not_empty_file(self, mock_bytes_from_file, mock_payload_len, mock_get_rnd_x86_nop,
  47. mock_get_rnd_bytes):
  48. self.generic_test([['FTPWinaXeExploit', 'custom.payload.file=1']], sha_empty_custom_payload_not_empty_file)
  49. @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
  50. @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
  51. @mock.patch('Attack.BaseAttack.BaseAttack.is_valid_ip_address', return_values=[False, True])
  52. def test_ftp_invalid_ip(self, mock_valid_ip_check, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
  53. self.generic_test([['FTPWinaXeExploit']], sha_valid_ip)
  54. if __name__ == '__main__':
  55. unittest.main()