test_FTPWinaXeExploit.py 3.9 KB

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