import unittest.mock as mock import ID2TLib.TestLibrary as Lib import Test.ID2TAttackTest as Test sha_ftp_basic = '3152c9b06a1c7f45b4bfcd7c1947c9d924701b1f90947e9cac9f9b52efa85fb5' sha_ftp_mac = '95a3a68e0b8d7ed414082e9abfe9806de6b62cdbee0747f2ba751b2367255646' sha_ftp_random_ip_src = '3d175f9d5a19682fd2122161b6f9cd6189a32d7547f78e998600803a3952138d' sha_not_empty_custom_payload_empty_file = '62fd066efc6f12d4d0641e4851c10ac29b647aa330d2e1ba6938a639e8b2445e' sha_empty_custom_payload_not_empty_file = '68e26d70f33c4fd6c004bbf3458c2847cbee7ab1d316247750754a31081fc8b6' sha_valid_ip = '3152c9b06a1c7f45b4bfcd7c1947c9d924701b1f90947e9cac9f9b52efa85fb5' # TODO: improve coverage class UnitTestFTPWinaXeExploit(Test.ID2TAttackTest): @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes) @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop) def test_ftp_basic(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes): self.checksum_test([['FTPWinaXeExploit']], sha_ftp_basic) @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes) @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop) @mock.patch('Core.Statistics.Statistics.get_mac_address') def test_ftp_mac(self, mock_mac_address, mock_get_rnd_x86_nop, mock_get_rnd_bytes): mock_mac_address.return_value = Lib.test_pcap_empty self.checksum_test([['FTPWinaXeExploit']], sha_ftp_mac) @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes) @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop) def test_ftp_random_ip_src(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes): self.checksum_test([['FTPWinaXeExploit', 'ip.src.shuffle=1']], sha_ftp_random_ip_src) @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes) @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop) def test_ftp_not_empty_custom_payload_empty_file(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes): self.checksum_test([['FTPWinaXeExploit', 'custom.payload=1']], sha_not_empty_custom_payload_empty_file) @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes) @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop) @mock.patch('ID2TLib.Utility.check_payload_len') @mock.patch('ID2TLib.Utility.get_bytes_from_file', return_value=b'AAAAA') def test_ftp_empty_custom_payload_not_empty_file(self, mock_bytes_from_file, mock_payload_len, mock_get_rnd_x86_nop, mock_get_rnd_bytes): self.checksum_test([['FTPWinaXeExploit', 'custom.payload.file=1']], sha_empty_custom_payload_not_empty_file) @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes) @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop) @mock.patch('Attack.BaseAttack.BaseAttack.is_valid_ip_address', return_values=[False, True]) def test_ftp_invalid_ip(self, mock_valid_ip_check, mock_get_rnd_x86_nop, mock_get_rnd_bytes): self.checksum_test([['FTPWinaXeExploit']], sha_valid_ip) def test_ftp_order(self): self.order_test([['FTPWinaXeExploit']])