예제 #1
0
        /// <summary>
        /// Update the available targets.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void comboBoxTargetType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                comboBoxTarget.ItemsSource  = null;
                comboBoxTarget.SelectedItem = null;
                stackPanelOptions.Children.Clear();

                if (Targets.ContainsKey(SelectedTargetType))
                {
                    comboBoxTarget.ItemsSource = Targets[SelectedTargetType];
                }

                if (TargetTypeOptions.ContainsKey(SelectedTargetType))
                {
                    foreach (string option in TargetTypeOptions[SelectedTargetType])
                    {
                        stackPanelOptions.Children.Add(new CheckBox()
                        {
                            Content = option
                        });
                    }
                }

                textBlockOptions.Visibility  = (stackPanelOptions.Children.Count == 0) ? Visibility.Collapsed : Visibility.Visible;
                stackPanelOptions.Visibility = (stackPanelOptions.Children.Count == 0) ? Visibility.Collapsed : Visibility.Visible;
            }
            catch (Exception err)
            {
                App.HandleException(err);
            }
        }
예제 #2
0
 public void RemoveTarget(String targetId)
 {
     if (Targets.ContainsKey(targetId))
     {
         Targets.TryRemove(targetId, out TargetInfo trgtinfo);
     }
 }
예제 #3
0
 public void AddTarget(String targetId, TargetInfo trgtinfo)
 {
     if (!Targets.ContainsKey(targetId))
     {
         Targets.TryAdd(targetId, trgtinfo);
     }
 }
예제 #4
0
        /// <summary>
        /// Execute any ArgZero arguments specified on the command line.  Has no effect if no relevant arguments
        /// are detected.
        /// </summary>
        public static void ExecuteArgZero(string[] arguments, Action onArgZeroExecuted = null)
        {
            if (arguments.Length == 0)
            {
                return;
            }

            if (Environment.GetCommandLineArgs().Any(a => a.Equals("/pause")))
            {
                Pause("Press enter to continue");
            }

            onArgZeroExecuted ??= (() => { });

            if (Targets.ContainsKey(arguments[0]))
            {
                List <string>       targetArguments = new List <string>();
                List <ArgumentInfo> argumentInfos   = new List <ArgumentInfo>();
                arguments.Rest(2, (val) =>
                {
                    targetArguments.Add(val);
                    if (val.StartsWith("/"))
                    {
                        string argName = val.TruncateFront(1).ReadUntil(':', out string argVal);
                        argumentInfos.Add(new ArgumentInfo(argName, true));
                    }
                });
                Arguments = new ParsedArguments(targetArguments.ToArray(), argumentInfos.ToArray());
                MethodInfo method = Targets[arguments[0]];
                if (method.HasCustomAttributeOfType <ArgZeroAttribute>(out ArgZeroAttribute argZeroAttribute))
                {
                    if (argZeroAttribute.BaseType != null)
                    {
                        RegisterArgZeroProviderTypes(argZeroAttribute.BaseType, arguments, argZeroAttribute.BaseType.Assembly);
                    }
                }

                object instance = null;
                if (!method.IsStatic)
                {
                    instance = method.DeclaringType.Construct();
                }

                try
                {
                    ArgZeroDelegator.CommandLineArguments = arguments;
                    method.Invoke(instance, null);
                }
                catch (Exception ex)
                {
                    Message.PrintLine("Exception executing ArgZero: {0}", ConsoleColor.Magenta, ex.Message);
                }

                onArgZeroExecuted();
            }
        }
예제 #5
0
        public virtual ILogger GetTarget(string name)
        {
            ILogger logger = null;

            if (Targets.ContainsKey(name))
            {
                Targets.TryGetValue(name, out logger);
            }

            return(logger);
        }
예제 #6
0
            public DependencyMetadata AddDependency(string itemSpec, IImmutableDictionary <string, string> properties)
            {
                if (!itemSpec.Contains("/") && !Targets.ContainsKey(itemSpec))
                {
                    var newTarget = new TargetMetadata(properties);
                    Targets.Add(itemSpec, newTarget);
                }

                var newDependency = new DependencyMetadata(itemSpec, properties);

                DependenciesWorld[itemSpec] = newDependency;

                return(newDependency);
            }
예제 #7
0
            public DependencyMetadata RemoveDependency(string itemSpec)
            {
                if (!DependenciesWorld.TryGetValue(itemSpec, out DependencyMetadata removedMetadata))
                {
                    return(null);
                }

                DependenciesWorld.Remove(itemSpec);

                RemoveNodeFromCache(itemSpec);

                if (!itemSpec.Contains("/") && Targets.ContainsKey(itemSpec))
                {
                    Targets.Remove(itemSpec);
                }

                return(removedMetadata);
            }
예제 #8
0
 static void ApplyQuality(UValue uValue)
 {
     if (Targets.ContainsKey(uValue.target))
     {
         if (Members.ContainsKey(uValue.member))
         {
             var qTarget      = Targets[uValue.target];
             var targetMember = Members[uValue.target + "." + uValue.member];
             if (targetMember is FieldInfo)
             {
                 ((FieldInfo)targetMember).SetValue(qTarget, uValue.value);
             }
             else if (targetMember is PropertyInfo)
             {
                 ((PropertyInfo)targetMember).SetValue(qTarget, uValue.value, null);
             }
         }
     }
 }
예제 #9
0
        public virtual void DetachTarget(string name, bool dispose = true)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (Targets.ContainsKey(name))
            {
                ILogger value = null;
                if (Targets.TryGetValue(name, out value))
                {
                    Targets.Remove(name);

                    if (dispose)
                    {
                        value.Dispose();
                    }
                }
            }
        }
예제 #10
0
        private List <Request> LoadJson(string json)
        {
            try
            {
                // deserialize json into a list (array)
                List <Request> list = JsonConvert.DeserializeObject <List <Request> >(json);

                if (list != null && list.Count > 0)
                {
                    List <Request> l2 = new List <Request>();

                    foreach (Request r in list)
                    {
                        // Add the default perf targets if exists
                        if (r.PerfTarget != null && r.PerfTarget.Quartiles == null)
                        {
                            if (Targets.ContainsKey(r.PerfTarget.Category))
                            {
                                r.PerfTarget.Quartiles = Targets[r.PerfTarget.Category].Quartiles;
                            }
                        }

                        l2.Add(r);
                    }
                    // success
                    return(l2);
                }

                Console.WriteLine("Invalid JSON file");
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            // couldn't read the list
            return(null);
        }
예제 #11
0
        /// <summary>
        /// Returns the result of the comparison
        /// </summary>
        /// <param name="compareModel"></param>
        /// <returns></returns>
        public static bool Compare(UCompare compareModel)
        {
            var result = false;

            if (Targets.ContainsKey(compareModel.target))
            {
                var targetObject = Targets[compareModel.target];
                if (Members.ContainsKey(compareModel.member))
                {
                    var targetMember = Members[compareModel.member];

                    if (targetMember is FieldInfo)
                    {
                        result = Comparison(((FieldInfo)targetMember).GetValue(targetObject), compareModel.value, compareModel.condition);
                    }
                    else if (targetMember is PropertyInfo)
                    {
                        result = Comparison(((PropertyInfo)targetMember).GetValue(targetObject, null), compareModel.value,
                                            compareModel.condition);
                    }
                    else
                    {
                        try
                        {
                            result = Comparison(((MethodInfo)targetMember).Invoke(targetObject, compareModel.parameters), compareModel.value,
                                                compareModel.condition);
                        }
                        catch (Exception e)
                        {
                            ULog.Log("CompareManager:Compare:Method. \n" + e.Message, ULogType.Error);
                            //InvokeCompareError(compareModel,CompareEventType.Error,e.Message);
                            //Debug.LogError("CompareManager:Compare method " + compareModel.member + " error: " + e.Message);
                        }
                    }
                }
            }
            return(result);
        }
예제 #12
0
        /// <summary>
        /// Apply one options
        /// </summary>
        /// <param name="optionValue"></param>
        static void ApplyOptions(UValue optionValue)
        {
            if (Targets.ContainsKey(optionValue.target))
            {
                var targetObject = Targets[optionValue.target];

                if (Members.ContainsKey(optionValue.target + "." + optionValue.member))
                {
                    var targetMember = Members[optionValue.target + "." + optionValue.member];
                    if (targetMember is FieldInfo)
                    {
                        ((FieldInfo)targetMember).SetValue(targetObject, optionValue.value);
                    }
                    else if (targetMember is PropertyInfo)
                    {
                        ((PropertyInfo)targetMember).SetValue(targetObject, optionValue.value, null);
                    }

                    /*else
                     * {
                     *      try
                     *      {
                     *              /*if (evt.IsPrevios && evt.parameters.Length > evt.parameters.Length - 1)//???? >0 ???
                     *              evt.parameters[evt.parameters.Length - 1] = previosResult;*/
                    /*((MethodInfo)targetMember).Invoke(targetObject, optionValue.parameters);
                     * }
                     * catch (Exception e)
                     * {
                     * ULog.Log("OptionsManager:ApplyOptions error on "+optionValue.member+"  \n" + e.Message, ULogType.Error);
                     * }
                     * }*/
                }
                else
                {
                    ULog.Log("ApplyOptions -2 " + optionValue.member + " : " + Members.Count);
                }
            }
        }
예제 #13
0
        public void ReadFromSocket()
        {
            var arrayBuffer = new byte[512000];
            var bytectr     = 0;

            while (!Cancel.IsCancellationRequested)
            {
                foreach (var key in Targets.Keys)
                {
                    TargetInfo trget = null;
                    try
                    {
                        if (Targets.ContainsKey(key))
                        {
                            trget = Targets[key];
                        }

                        if (!trget.Exit)
                        {
                            var stream = trget.TargetTcpClient.GetStream();
                            if (Cancel.IsCancellationRequested || trget.Exit)
                            {
                                return;
                            }

                            if (IsConnected(trget.TargetTcpClient.Client))
                            {
                                if (stream.CanRead && stream.DataAvailable)
                                {
                                    int ctr = 0;
                                    bytectr = 0;
                                    do
                                    {
                                        var bytesRead = stream.Read(arrayBuffer, 0, 512000);
                                        bytectr += bytesRead;
                                        if (bytesRead > 0)
                                        {
                                            TotalBytesRead += bytesRead;
                                            trget.ReadQueue.Enqueue(arrayBuffer.Take(bytesRead).ToList());
                                        }
                                        ctr++;
                                    } while (!_timeout.WaitOne(10) && stream.CanRead && stream.DataAvailable);
                                    if (ctr >= 1)
                                    {
                                        RecvedData.Set();
                                        ImplantComms.LogMessage($"[{trget.TargetId}] Socks {trget.TargetTcpClient.Client.RemoteEndPoint.ToString()} read {bytectr} available bytes");
                                    }
                                }
                            }
                            else
                            if (null != trget)
                            {
                                trget.Exit = true;
                            }
                        }
                    }
                    catch
                    {
                        if (null != trget)
                        {
                            trget.Exit = true;
                        }
                    }

                    if (trget?.Exit ?? true)
                    {
                        try { if (null != trget?.TargetTcpClient)
                              {
                                  trget.TargetTcpClient.Close();
                              }
                        }
                        catch { /*Dont relly care if exception thrown here*/ }
                        if (Targets.ContainsKey(key))
                        {
                            Targets.TryRemove(key, out TargetInfo tgexit);
                        }
                        ImplantComms.LogMessage($"[{trget.TargetId}] Connection has been closed");
                    }
                }
                _timeout.WaitOne(100);
            }
        }
예제 #14
0
        /*/// <summary>
         * /// Add object to TargetList and members from object to MemberList.
         * /// Members of target must contains AccessAllow attribute
         * /// </summary>
         * /// <param name="targetName"></param>
         * /// <param name="newTarget"></param>
         * public static void AddTarget(string targetName, object newTarget)
         * {
         *      if (!Targets.ContainsKey(targetName))
         *              Targets.Add(targetName, newTarget);
         *      else
         *      {
         *              RemoveMembers(targetName);
         *              Targets[targetName] = newTarget;
         *      }
         *      FillMembers(targetName, newTarget);
         * }
         *
         * /// <summary>
         * /// Remove target and members from lists
         * /// </summary>
         * /// <param name="targetName"></param>
         * public static void RemoveTarget(string targetName)
         * {
         *      if (Targets.ContainsKey(targetName))
         *      {
         *              RemoveMembers(targetName);
         *              Targets.Remove(targetName);
         *      }
         *
         * }*/

        /*public void AddConfiguration(Configuration conf)
         * {
         *  if (!Configurations.ContainsKey(conf.Key))
         *      Configurations.Add(conf.Key, conf);
         *  else
         *      Configurations[conf.Key] = conf;
         * }
         *
         * public void AddConfigSection(string configKey, ConfigSection newSection)
         * {
         *  if (Configurations.ContainsKey(configKey))
         *      Configurations[configKey].AddSection(newSection);
         * }
         *
         * public void AddConfigSections(string configKey, Dictionary<string,ConfigSection> newSections)
         * {
         *  if (!Configurations.ContainsKey(configKey)) return;
         *  var cfg = Configurations[configKey];
         *  foreach (var sec in newSections)
         *      cfg.AddSection(sec.Value);
         * }
         *
         * public void SetConfigSections(string configKey, Dictionary<string, ConfigSection> newSections)
         * {
         *  if (!Configurations.ContainsKey(configKey)) return;
         *  Configurations[configKey].SetSections(newSections);
         * }
         *
         * public void AddParameter(string configKey, string sectionName,UValue parameter)
         * {
         *  if (Configurations.ContainsKey(configKey) && Configurations[configKey].ContainsSection(sectionName))
         *      Configurations[configKey][sectionName].AddParameter(parameter.key, parameter);
         * }
         *
         * public void RemoveParameter(string configKey, string sectionName, string parameterKey)
         * {
         *  if (Configurations.ContainsKey(configKey) && Configurations[configKey].ContainsSection(sectionName))
         *      Configurations[configKey][sectionName].RemoveParameter(parameterKey);
         * }
         *
         * public void RemoveConfiguration(string key)
         * {
         *  if (Configurations.ContainsKey(key))
         *      Configurations.Remove(key);
         * }
         *
         * public void RemoveConfigSection(string configKey, string sectionName)
         * {
         *  if (Configurations.ContainsKey(configKey))
         *      Configurations[configKey].RemoveSection(sectionName);
         * }*/



        /// <summary>
        ///
        /// </summary>
        /// <param name="targetName"></param>
        /// <returns></returns>
        public static bool TargetExists(string targetName)
        {
            return(Targets.ContainsKey(targetName));
        }
예제 #15
0
        public void SendToTarget()
        {
            var SendWait = new ManualResetEvent(false);

            while (!Cancel.IsCancellationRequested)
            {
                RecvedData.WaitOne(-1);;
                RecvedData.Reset();
                foreach (var key in Targets.Keys)
                {
                    TargetInfo trget = null;
                    try
                    {
                        if (Targets.ContainsKey(key))
                        {
                            trget = Targets[key];
                        }

                        if (null != trget && !trget.Exit)
                        {
                            List <byte> readPyld = null;

                            var payload = new List <byte>();
                            while (trget.ReadQueue.Count > 0)
                            {
                                trget.ReadQueue.TryDequeue(out readPyld);
                                payload.AddRange(readPyld);
                            }
                            if (payload.Count > 0)
                            {
                                Task.Factory.StartNew(() =>
                                {
                                    List <byte> toSend = null;
                                    try
                                    {
                                        toSend = CmdCommshandler.Send(trget, "asyncUpload", payload, out bool connectionDead);
                                        ImplantComms.LogMessage($"[{trget.TargetId}] Received {toSend?.Count() ?? 0} bytes after sending {payload?.Count ?? 0 } bytes");
                                        if (null == toSend || connectionDead)
                                        {
                                            ImplantComms.LogError($"[{trget.TargetId}] Connection looks dead EXITING");
                                            trget.Exit = true;
                                        }
                                        else if (toSend.Count > 0)
                                        {
                                            trget.WriteQueue.Enqueue(toSend);
                                            SentData.Set();
                                        }
                                    }
                                    catch
                                    {
                                        trget.Exit = true;
                                        ImplantComms.LogError($"[{trget.TargetId}] Couldn't send {toSend?.Count()} bytes");
                                    }
                                });
                                ImplantComms.LogMessage($"[{trget.TargetId}] {payload?.Count() ?? 0} bytes arrived from target about to send back");
                            }
                        }
                        SendWait.WaitOne(BeaconTime);
                    }
                    catch (Exception ex)
                    {
                        if (null != trget)
                        {
                            trget.Exit = true;
                        }
                        ImplantComms.LogError($"[{trget.TargetId}] Error during Send Data loop {ex}");
                    }
                }
            }
        }
예제 #16
0
        public void WriteToSocket()
        {
            while (!Cancel.IsCancellationRequested)
            {
                SentData.WaitOne(-1);
                SentData.Reset();
                foreach (var key in Targets.Keys)
                {
                    TargetInfo    trget  = null;
                    NetworkStream stream = null;
                    try
                    {
                        if (Targets.ContainsKey(key))
                        {
                            trget = Targets[key];
                        }

                        if (null != trget && !trget.Exit)
                        {
                            stream = trget.TargetTcpClient.GetStream();
                            if (trget.WriteQueue.Count > 0)
                            {
                                var         toSend = new List <byte>();
                                List <byte> pyld   = null;
                                while (trget.WriteQueue.Count() > 0)
                                {
                                    trget.WriteQueue.TryDequeue(out pyld);
                                    if (pyld.Count > 0)
                                    {
                                        toSend.AddRange(pyld);
                                    }
                                }
                                if (IsConnected(trget.TargetTcpClient.Client))
                                {
                                    if (toSend != null && toSend.Count() > 0)
                                    {
                                        TotalBytesWritten += toSend.Count;
                                        stream.Write(toSend.ToArray(), 0, toSend.Count());
                                        stream.Flush();
                                        ImplantComms.LogMessage($"[{trget.TargetId}] Written {toSend.Count()} from client");
                                    }
                                }
                                else
                                if (null != trget)
                                {
                                    trget.Exit = true;
                                }
                            }
                        }
                    }
                    catch
                    {
                        if (null != trget)
                        {
                            trget.Exit = true;
                        }
                    }

                    if (!trget?.TargetTcpClient?.Connected ?? false || (trget?.Exit ?? true))
                    {
                        try { if (null != stream)
                              {
                                  stream.Close();
                              }
                        }
                        catch { /*Dont relly care if exception thrown here*/ }

                        try { if (null != trget?.TargetTcpClient)
                              {
                                  trget.TargetTcpClient.Close();
                              }
                        }
                        catch { /*Dont relly care if exception thrown here*/ }
                        if (Targets.ContainsKey(key))
                        {
                            Targets.TryRemove(key, out TargetInfo tgexit);
                        }
                        ImplantComms.LogMessage($"[{trget.TargetId}] Connection has been closed");
                    }
                }
            }
        }
예제 #17
0
        /// <summary>
        /// Read a json test file
        /// </summary>
        /// <param name="file">file path</param>
        /// <returns>List of Request</returns>
        public List <Request> ReadJson(string file)
        {
            if (string.IsNullOrWhiteSpace(file))
            {
                throw new ArgumentNullException(nameof(file));
            }

            // check for file exists
            if (string.IsNullOrEmpty(file) || !File.Exists(file))
            {
                Console.WriteLine($"File Not Found: {file}");
                return(null);
            }

            // read the file
            string json = File.ReadAllText(file);

            // check for empty file
            if (string.IsNullOrEmpty(json))
            {
                Console.WriteLine($"Unable to read file {file}");
                return(null);
            }

            try
            {
                // deserialize json into a list (array)
                List <Request> list = JsonConvert.DeserializeObject <List <Request> >(json);

                if (list != null && list.Count > 0)
                {
                    List <Request> l2 = new List <Request>();

                    foreach (Request r in list)
                    {
                        // Add the default perf targets if exists
                        if (r.PerfTarget != null && r.PerfTarget.Quartiles == null)
                        {
                            if (Targets.ContainsKey(r.PerfTarget.Category))
                            {
                                r.PerfTarget.Quartiles = Targets[r.PerfTarget.Category].Quartiles;
                            }
                        }

                        l2.Add(r);
                    }
                    // success
                    return(l2);
                }

                Console.WriteLine("Invalid JSON file");
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            // couldn't read the list
            return(null);
        }