Exemple #1
0
        // This method runs DDT tool with specific parameters on remote server using WMI
        public static void Runddtremotely(ServerConnectionCredentials serverCreds, DDTParameters ddtParameters, CancellationToken token)
        {
            string remotePath = "\\\\" + serverCreds.IP + "\\" + HelperMethods.separateVolumeAndFolder(ddtParameters.Filepath, HelperMethods.FilepathParts.volume)
                        + "$\\" + HelperMethods.separateVolumeAndFolder(ddtParameters.Filepath, HelperMethods.FilepathParts.folder);

            WMIKillDDT(serverCreds);

            CopyDDTtoRemoteMachine(serverCreds);

            Logger.Log("Data generation started on remote server " + serverCreds.IP, Logger.LogLevel.Info, serverCreds.IP);

            while (true)
            {
                if (token.IsCancellationRequested)
                {
                    Logger.Log("DDT operation has been canceled by user", Logger.LogLevel.Info, serverCreds.IP);
                    break;
                }

                cleanFilepathRemotely(serverCreds, remotePath);

                WMIRunDDT(serverCreds, ddtParameters);

                Thread.Sleep(ddtParameters.Interval * 60000);
            }
        }
        // This method runs DDT tool with specific parameters on remote server using WMI
        public static void Runddtremotely(ServerConnectionCredentials serverCreds, DdtParameters ddtParameters, CancellationToken token)
        {
            var remotePath = "\\\\" + serverCreds.Ip + "\\" + HelperMethods.SeparateVolumeAndFolder(ddtParameters.Filepath, HelperMethods.FilepathParts.Volume)
                             + "$\\" + HelperMethods.SeparateVolumeAndFolder(ddtParameters.Filepath, HelperMethods.FilepathParts.Folder);

            WmiKillDdt(serverCreds);

            CopyDdTtoRemoteMachine(serverCreds);

            CreateTargetDirectory(serverCreds, remotePath);

            Logger.Log("Data generation started on remote server " + serverCreds.Ip, Logger.LogLevel.Info, serverCreds.Ip);

            while (true)
            {
                if (token.IsCancellationRequested)
                {
                    Logger.Log("DDT operation has been canceled by user", Logger.LogLevel.Info, serverCreds.Ip);
                    break;
                }

                if (!ddtParameters.FillingGeneration)
                {
                    CleanFilepathRemotely(serverCreds, remotePath);
                }

                WmiRunDdt(serverCreds, ddtParameters);

                Thread.Sleep(ddtParameters.Interval * 60000);
            }
        }
        // This method is used to perform action delegate remotely on CIFS Share
        public static void PerformActionRemotely(Action action, ServerConnectionCredentials serverCreds)
        {
            WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
            WindowsImpersonationContext wic = null;
            try
            {
                IntPtr admin_token = new IntPtr();
                if (LogonUser(serverCreds.Username, ".", serverCreds.Password, 9, 0, ref admin_token) != 0)
                {
                    wic = new WindowsIdentity(admin_token).Impersonate();

                    action();
                }
            }
            catch (Exception se)
            {
                int ret = Marshal.GetLastWin32Error();
                Logger.LogError("Invoking action on remote machine failed with Error code " + ret.ToString(), serverCreds.IP, se);
                return;
            }
            finally
            {
                if (wic != null)
                {
                    wic.Undo();
                }
            }
        }
Exemple #4
0
        // This method is used to perform action delegate remotely on CIFS Share
        public static void PerformActionRemotely(Action action, ServerConnectionCredentials serverCreds)
        {
            WindowsIdentity.GetCurrent();
            WindowsImpersonationContext wic = null;

            try
            {
                var adminToken = new IntPtr();
                if (LogonUser(serverCreds.Username, ".", serverCreds.Password, 9, 0, ref adminToken) == 0)
                {
                    return;
                }
                wic = new WindowsIdentity(adminToken).Impersonate();

                action();
            }
            catch (Exception se)
            {
                var ret = Marshal.GetLastWin32Error();
                Logger.LogError("Invoking action on remote machine failed with Error code " + ret.ToString(), serverCreds.Ip, se);
                return;
            }
            finally
            {
                wic?.Undo();
            }
        }
 // This construcor is using when creating new instance using data from Core.
 public Server(string ip, string displayname, string repository, string username, string password)
 {
     DisplayName = displayname;
     Repository = repository;
     ServerCredentials = new ServerConnectionCredentials();
     ServerCredentials.Username = username;
     ServerCredentials.Password = password;
     ServerCredentials.IP = ip;
 }
Exemple #6
0
 public Server(string ip, string username, string password)
 {
     ServerCredentials = new ServerConnectionCredentials
     {
         Username = username,
         Password = password,
         Ip       = ip
     };
 }
        // This method kills existing DDT process via WMI
        private static void WmiKillDdt(ServerConnectionCredentials serverCreds)
        {
            var options = new ConnectionOptions
            {
                Username = serverCreds.Username,
                Password = serverCreds.Password
            };


            var scope = new ManagementScope("\\\\" + serverCreds.Ip + "\\root\\cimv2", options);

            var query = new SelectQuery("select * from Win32_Process Where Name='ddt.exe'");

            var retries = 0;

            while (true)
            {
                using (var searcher = new ManagementObjectSearcher(scope, query))
                {
                    try
                    {
                        var collection = searcher.Get();
                        if (collection.Count == 0)
                        {
                            break;
                        }
                        foreach (var process in collection.Cast <ManagementObject>())
                        {
                            process.InvokeMethod("Terminate", null);
                            break;
                        }
                    }
                    catch (COMException e)
                    {
                        if (retries < 3)
                        {
                            retries++;
                            Logger.LogError("Cannot connect to remote RPC server. Retry in 30 seconds", serverCreds.Ip, e);
                            Thread.Sleep(30000);
                        }
                        else
                        {
                            Logger.LogError("Cannot connect to remote RPC server.", serverCreds.Ip, e);

                            throw;
                        }
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        Logger.LogError("Access denied to remote server. Possibly incorrect credentials.", serverCreds.Ip, e);
                        throw;
                    }
                }
            }
        }
Exemple #8
0
 // This constructor is using when creating new instance using data from Core.
 public Server(string ip, string displayname, string repository, string username, string password)
 {
     DisplayName       = displayname;
     Repository        = repository;
     ServerCredentials = new ServerConnectionCredentials
     {
         Username = username,
         Password = password,
         Ip       = ip
     };
 }
Exemple #9
0
        // This method kills existing DDT process via WMI
        public static void WMIKillDDT(ServerConnectionCredentials serverCreds)
        {
            ConnectionOptions options = new ConnectionOptions();

            options.Username = serverCreds.Username;
            options.Password = serverCreds.Password;

            ManagementScope scope = new ManagementScope("\\\\" + serverCreds.IP + "\\root\\cimv2", options);

            SelectQuery query = new SelectQuery("select * from Win32_Process Where Name='ddt.exe'");

            int retries = 0;

            while (true)
            {
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
                {
                    try
                    {
                        ManagementObjectCollection collection = searcher.Get();
                        if (collection.Count == 0)
                        {
                            break;
                        }
                        foreach (ManagementObject process in collection)
                        {
                            process.InvokeMethod("Terminate", null);
                            break;
                        }
                    }
                    catch (COMException e)
                    {
                        if (retries < 3)
                        {
                            retries++;
                            Logger.LogError("Cannot connect to remote RPC server. Retry in 30 seconds", serverCreds.IP, e);
                            Thread.Sleep(30000);
                        }
                        else
                        {
                            Logger.LogError("Cannot connect to remote RPC server.", serverCreds.IP, e);

                            throw;
                        }
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        Logger.LogError("Access denied to remote server. Possibly incorrect credentials.", serverCreds.IP, e);
                        throw;
                    }
                }
            }
        }
Exemple #10
0
        // This method copies the folder with DDT tools to cifs on the server using PerformActionRemotely method
        public static void CopyDDTtoRemoteMachine(ServerConnectionCredentials serverCreds)
        {

            HelperMethods.PerformActionRemotely(() =>
            {
                string remotePath = "\\\\" + serverCreds.IP + "\\C$\\DDT";
                if (!Directory.Exists(remotePath))
                {
                    Directory.CreateDirectory(remotePath);
                    HelperMethods.DirectoryCopy("DDT", remotePath, true);
                }
            }, serverCreds);
            Logger.Log("Successfully copied DDT to remote server", Logger.LogLevel.Info, serverCreds.IP);
        }
 // This method copies the folder with DDT tools to cifs on the server using PerformActionRemotely method
 private static void CopyDdTtoRemoteMachine(ServerConnectionCredentials serverCreds)
 {
     HelperMethods.PerformActionRemotely(() =>
     {
         var remotePath = "\\\\" + serverCreds.Ip + "\\C$\\DDT";
         if (Directory.Exists(remotePath))
         {
             return;
         }
         Directory.CreateDirectory(remotePath);
         HelperMethods.DirectoryCopy("DDT", remotePath, true);
     }, serverCreds);
     Logger.Log("Successfully copied DDT to remote server", Logger.LogLevel.Info, serverCreds.Ip);
 }
        private static void SendMessages(ExchangeService service, ExchangeGeneratorParameters genParameters, ServerConnectionCredentials serverCreds, Random random1)
        {
            var email = new EmailMessage(service);

            email.ToRecipients.Add(genParameters.Recipient);
            email.Body = new MessageBody(HelperMethods.RandomString((int)genParameters.MessageSize,random1));
            email.Subject = "Exchange Generator (" + genParameters.MessageSize+")";

            var serviceRequestRetryCount = 0;
            var serviceResponseRetryCount = 0;

            while (true)
            {
                try
                {
                    email.Send();
                    break;
                }
                catch (ServiceRequestException e)
                {
                    if (serviceRequestRetryCount < 3)
                    {
                        serviceRequestRetryCount++;
                        Logger.Log("ServiceRequestException has been caught, retry in 15 seconds.", Logger.LogLevel.Warning, serverCreds.Ip);
                        Thread.Sleep(15000);

                    }
                    else
                    {
                        Logger.LogError("Something wrong with exchange server.", serverCreds.Ip, e);
                        throw;
                    }

                }
                catch (ServiceResponseException e)
                {
                    if (serviceResponseRetryCount < 3)
                    {
                        serviceResponseRetryCount++;
                        Logger.Log("ServiceResponseException has been caught, retry in 15 seconds.", Logger.LogLevel.Warning, serverCreds.Ip);
                        Thread.Sleep(15000);
                    }
                    else
                    {
                        Logger.LogError("Something wrong with exchange server.", serverCreds.Ip, e);
                        throw;
                    }
                }
            }
        }
        // This method clean the destination folder for data generation
        private static void CleanFilepathRemotely(ServerConnectionCredentials serverCreds, string remotePath)
        {
            HelperMethods.PerformActionRemotely(() =>
            {
                if (!Directory.Exists(remotePath))
                {
                    return;
                }

                var filesTodelete = new DirectoryInfo(remotePath);
                foreach (var file in filesTodelete.GetFiles())
                {
                    file.Delete();
                }
            }, serverCreds);
        }
 private static void CreateTargetDirectory(ServerConnectionCredentials serverCreds, string remotePath)
 {
     HelperMethods.PerformActionRemotely(() =>
     {
         if (!Directory.Exists(remotePath))
         {
             try
             {
                 Directory.CreateDirectory(remotePath);
             }
             catch (IOException e)
             {
                 Logger.LogError("Remote path doesn't exist", serverCreds.Ip, e);
                 throw;
             }
         }
     }, serverCreds);
 }
        public static void StartGenerator(ServerConnectionCredentials serverCredentials, ExchangeGeneratorParameters genParameters, CancellationToken token)
        {
            ServicePointManager.ServerCertificateValidationCallback = OnValidationCallback;
            var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
            {
                Credentials = new WebCredentials(serverCredentials.Username, serverCredentials.Password),
                Url = new Uri("https://" + serverCredentials.Ip + "/EWS/Exchange.asmx"),
                Timeout = 300000
            };

            Logger.Log("Exchange data generation started for server: " + serverCredentials.Ip + " . With mail size: " + genParameters.MessageSize, Logger.LogLevel.Info, serverCredentials.Ip);

            _random = new Random();

            while (true)
            {
                SendMessages(service, genParameters, serverCredentials, _random);
                if (token.IsCancellationRequested)
                    break;
            }
        }
        // This methdo starts DDT on remote machine using WMI
        private static void WmiRunDdt(ServerConnectionCredentials serverCreds, DdtParameters ddtParameters)
        {
            var seed = new Random().Next();

            object[] processToTun = { @"C:\DDT\ddt.exe op=write threads=1 filename=" + ddtParameters.Filepath + seed + " filesize=" + ddtParameters.Filesize
                                      + " blocksize=512 dup-percentage=" + ddtParameters.Compression + " buffering=direct io=sequential seed=" + seed + " no-ddt-hdr=yes" };
            var      options = new ConnectionOptions
            {
                Username = serverCreds.Username,
                Password = serverCreds.Password
            };


            var scope = new ManagementScope("\\\\" + serverCreds.Ip + "\\root\\cimv2", options);

            var theClass = new ManagementClass(scope, new ManagementPath("Win32_Process"), new ObjectGetOptions());

            var retryCount = 0;

            while (true)
            {
                try
                {
                    theClass.InvokeMethod("Create", processToTun);
                    break;
                }
                catch (COMException e)
                {
                    if (retryCount < 3)
                    {
                        retryCount++;
                    }
                    else
                    {
                        Logger.LogError("Starting DDT on remote machine failed with:", serverCreds.Ip, e);
                        throw;
                    }
                }
            }
        }
        public static void StartGenerator(ServerConnectionCredentials serverCredentials, ExchangeGeneratorParameters genParameters, CancellationToken token)
        {
            ServicePointManager.ServerCertificateValidationCallback = OnValidationCallback;
            var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
            {
                Credentials = new WebCredentials(serverCredentials.Username, serverCredentials.Password),
                Url         = new Uri("https://" + serverCredentials.Ip + "/EWS/Exchange.asmx"),
                Timeout     = 300000
            };

            Logger.Log("Exchange data generation started for server: " + serverCredentials.Ip + " . With mail size: " + genParameters.MessageSize, Logger.LogLevel.Info, serverCredentials.Ip);

            _random = new Random();

            while (true)
            {
                SendMessages(service, genParameters, serverCredentials, _random);
                if (token.IsCancellationRequested)
                {
                    break;
                }
            }
        }
Exemple #18
0
        // This method clean the destination folder for data generation
        private static void cleanFilepathRemotely(ServerConnectionCredentials serverCreds, string remotePath)
        {
            HelperMethods.PerformActionRemotely(() =>
            {
                if (!Directory.Exists(remotePath))
                {
                    try
                    {
                        Directory.CreateDirectory(remotePath);
                    }
                    catch (IOException e)
                    {
                        Logger.LogError("Remote path doesn't exist", serverCreds.IP, e);
                        throw;
                    }
                }

                DirectoryInfo filesTodelete = new DirectoryInfo(remotePath);
                foreach (FileInfo file in filesTodelete.GetFiles())
                {
                    file.Delete();
                }
            }, serverCreds);
        }
        private static void SendMessages(ExchangeService service, ExchangeGeneratorParameters genParameters, ServerConnectionCredentials serverCreds, Random random1)
        {
            var email = new EmailMessage(service);

            email.ToRecipients.Add(genParameters.Recipient);
            email.Body    = new MessageBody(HelperMethods.RandomString((int)genParameters.MessageSize, random1));
            email.Subject = "Exchange Generator (" + genParameters.MessageSize + ")";

            var serviceRequestRetryCount  = 0;
            var serviceResponseRetryCount = 0;

            while (true)
            {
                try
                {
                    email.Send();
                    break;
                }
                catch (ServiceRequestException e)
                {
                    if (serviceRequestRetryCount < 3)
                    {
                        serviceRequestRetryCount++;
                        Logger.Log("ServiceRequestException has been caught, retry in 15 seconds.", Logger.LogLevel.Warning, serverCreds.Ip);
                        Thread.Sleep(15000);
                    }
                    else
                    {
                        Logger.LogError("Something wrong with exchange server.", serverCreds.Ip, e);
                        throw;
                    }
                }
                catch (ServiceResponseException e)
                {
                    if (serviceResponseRetryCount < 3)
                    {
                        serviceResponseRetryCount++;
                        Logger.Log("ServiceResponseException has been caught, retry in 15 seconds.", Logger.LogLevel.Warning, serverCreds.Ip);
                        Thread.Sleep(15000);
                    }
                    else
                    {
                        Logger.LogError("Something wrong with exchange server.", serverCreds.Ip, e);
                        throw;
                    }
                }
            }
        }
Exemple #20
0
        // This methdo starts DDT on remote machine using WMI
        public static void WMIRunDDT(ServerConnectionCredentials serverCreds, DDTParameters ddtParameters)
        {
            var seed = new Random().Next();

            object[] processToTun = { @"C:\DDT\ddt.exe op=write threads=1 filename=" + ddtParameters.Filepath + seed + " filesize=" + ddtParameters.Filesize
                        + " blocksize=512 dup-percentage=" + ddtParameters.Compression + " buffering=direct io=sequential seed=" + seed + " no-ddt-hdr=yes" };
            ConnectionOptions options = new ConnectionOptions();

            options.Username = serverCreds.Username;
            options.Password = serverCreds.Password;

            ManagementScope scope = new ManagementScope("\\\\" + serverCreds.IP + "\\root\\cimv2", options);

            ManagementClass theClass = new ManagementClass(scope, new ManagementPath("Win32_Process"), new ObjectGetOptions());

            int retryCount = 0;

            while (true)
            {
                try
                {
                    theClass.InvokeMethod("Create", processToTun);
                    break;
                }
                catch (COMException e)
                {
                    if (retryCount < 3)
                    {
                        retryCount++;
                    }
                    else
                    {
                        Logger.LogError("Starting DDT on remote machine failed with:", serverCreds.IP, e);
                        throw;
                    }
                }
            }
        }