Exemple #1
0
        static void DisplayAvailableCommands(CommandMenuItem menu, bool inner)
        {
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            CommandTable tb = new CommandTable();

            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Available_Commands") + ":");
                menu.IO.WriteLine("");

                tb.AddRow(tb.AddRow(Lang.Get("Short"), Lang.Get("Command")).MakeSeparator());
            }

            bool entra         = false;
            var  abbreviations = menu.CommandAbbreviations().OrderBy(it => it.Key);

            foreach (var ab in abbreviations)
            {
                //if (ab.Value == null)
                //{
                //    menu.IO.Write("      ");
                //}
                //else
                //{
                //    menu.IO.Write(ab.Value.PadRight(3) + " | ");
                //}

                tb.AddRow(ab.Value, ab.Key)[0].Align = CommandTableCol.EAlign.Right;
                //menu.IO.WriteLine(ab.Key);
                entra = true;
            }

            if (entra)
            {
                menu.IO.WriteLine(tb.Output());
            }

            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Type_Help"));
            }
        }
Exemple #2
0
        public void cmdVersion(string args)
        {
            _IO.WriteLine("");

            CommandTable tb = new CommandTable();

            _IO.WriteLine(Lang.Get("Version_Start"));
            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("File"), Lang.Get("Version")).MakeSeparator());

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (asm.GlobalAssemblyCache)
                {
                    continue;
                }

                string file = "??";
                if (string.IsNullOrEmpty(asm.Location))
                {
                    file = asm.ManifestModule.ScopeName;
                }
                else
                {
                    file = Path.GetFileName(asm.Location);
                }

                tb.AddRow(file, asm.ImageRuntimeVersion);
            }

            tb.AddRow("", "");

            tb.AddRow(tb.AddRow(Lang.Get("Module"), Lang.Get("Count")).MakeSeparator());
            tb.AddRow(Lang.Get("Modules"), ModuleCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Encoders"), EncoderCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Payloads"), PayloadCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Nops"), NopCollection.Current.Count.ToString());

            _IO.WriteLine(tb.Output());
        }
Exemple #3
0
        public void cmdShow(string args)
        {
            if (!CheckModule(false, EModuleType.None)) return;
            args = args.Trim().ToLowerInvariant();

            Module curM = _Current.ModuleType == EModuleType.Module ? (Module)_Current : null;

            switch (args)
            {
                case "":
                case "info": { cmdInfo(args); break; }
                case "options":
                case "config":
                    {
                        // set target id
                        Target[] ps = null;

                        if (curM != null)
                        {
                            ps = curM.Targets;
                            if (ps != null)
                            {
                                int ix = 0;
                                foreach (Target t in ps) { t.Id = ix; ix++; }
                            }
                        }

                        CommandTable tb = new CommandTable();

                        string title = "";
                        for (int x = 0; x <= 2; x++)
                        {
                            PropertyInfo[] pis = null;

                            object pv = _Current;
                            switch (x)
                            {
                                case 0:
                                    {
                                        if (_Current.ModuleType == EModuleType.Payload)
                                            title = Lang.Get("Payload_Options", _Current.FullPath);
                                        else
                                            title = Lang.Get("Module_Options", _Current.FullPath);

                                        pis = ReflectionHelper.GetProperties(_Current, true, true, true);
                                        break;
                                    }
                                case 1:
                                    {
                                        title = Lang.Get("Current_Target");
                                        if (ps != null && ps.Length > 1)
                                            pis = ReflectionHelper.GetProperties(_Current, "Target");
                                        break;
                                    }
                                case 2:
                                    {
                                        if (curM != null)
                                        {
                                            if (curM.Payload != null)
                                            {
                                                pv = curM.Payload;
                                                pis = ReflectionHelper.GetProperties(curM.Payload, true, true, true);
                                                title = Lang.Get("Payload_Options", curM.Payload.FullPath);
                                            }
                                            else
                                            {
                                                if (curM.PayloadRequirements != null)
                                                {
                                                    pis = ReflectionHelper.GetProperties(_Current, "Payload");
                                                    title = Lang.Get("Selected_Payload");
                                                }
                                            }
                                        }
                                        break;
                                    }
                            }

                            if (pis != null)
                            {
                                bool primera = true;// (x != 1 || !hasX0);
                                foreach (PropertyInfo pi in pis)
                                {
                                    ConfigurableProperty c = pi.GetCustomAttribute<ConfigurableProperty>();
                                    if (c == null)
                                        continue;

                                    if (primera)
                                    {
                                        if (tb.Count > 0) tb.AddRow("", "", "");
                                        CommandTableRow row = tb.AddRow(0, title, "", "");
                                        tb.AddRow("", "", "");

                                        row[0].Align = CommandTableCol.EAlign.None;
                                        row[1].Align = CommandTableCol.EAlign.None;
                                        row[2].Align = CommandTableCol.EAlign.None;
                                        primera = false;
                                    }

                                    object val = pi.GetValue(pv);
                                    if (val == null)
                                    {
                                        val = "NULL";
                                        CommandTableRow row = tb.AddRow(pi.Name, val.ToString(), c.Description);
                                        if (c.Required) row[1].ForeColor = ConsoleColor.Red;
                                        else
                                        {
                                            if (x == 0 || x == 3)
                                                row[1].ForeColor = ConsoleColor.Cyan;
                                        }
                                    }
                                    else
                                    {
                                        CommandTableRow row = tb.AddRow(pi.Name, val.ToString(), c.Description);
                                        if (x == 0 || x == 3)
                                            row[1].ForeColor = ConsoleColor.Cyan;
                                    }
                                }
                            }
                        }

                        string separator = tb.Separator;
                        foreach (CommandTableRow row in tb)
                        {
                            foreach (CommandTableCol col in row)
                            {
                                if (col.ReplicatedChar == '\0')
                                {
                                    switch (col.Index)
                                    {
                                        case 0: _IO.SetForeColor(ConsoleColor.DarkGray); break;
                                        case 1: _IO.SetForeColor(col.ForeColor); break;
                                        case 2: _IO.SetForeColor(ConsoleColor.Yellow); break;
                                    }
                                }
                                else _IO.SetForeColor(col.ForeColor);

                                if (col.Index != 0) _IO.Write(separator);
                                _IO.Write(col.GetFormatedValue());
                            }
                            _IO.WriteLine("");
                        }
                        break;
                    }
                case "payloads":
                    {
                        Payload[] ps = curM == null ? null : PayloadCollection.Current.GetPayloadAvailables(curM.PayloadRequirements);
                        if (ps == null || ps.Length == 0)
                            _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                        else
                        {
                            CommandTable tb = new CommandTable();

                            tb.AddRow(tb.AddRow(Lang.Get("Name"), Lang.Get("Description")).MakeSeparator());

                            foreach (Payload p in ps)
                                tb.AddRow(p.FullPath, p.Description);

                            _IO.Write(tb.Output());
                        }
                        break;
                    }
                case "targets":
                    {
                        Target[] ps = curM == null ? null : curM.Targets;
                        if (ps == null || ps.Length <= 1)
                            _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                        else
                        {
                            CommandTable tb = new CommandTable();

                            tb.AddRow(tb.AddRow(Lang.Get("Name"), Lang.Get("Description")).MakeSeparator());

                            int ix = 0;
                            foreach (Target p in ps)
                            {
                                p.Id = ix; ix++;
                                tb.AddRow(p.Id.ToString(), p.Name);
                            }

                            _IO.Write(tb.Output());
                        }
                        break;
                    }
                default:
                    {
                        // incorrect use
                        _IO.WriteError(Lang.Get("Incorrect_Command_Usage"));
                        _IO.AddInput("help show");
                        break;
                    }
            }
        }
Exemple #4
0
        public void cmdVersion(string args)
        {
            _IO.WriteLine("");

            CommandTable tb = new CommandTable();

            _IO.WriteLine(Lang.Get("Version_Start"));
            _IO.WriteLine("");

            tb.AddRow(tb.AddRow(Lang.Get("File"), Lang.Get("Version")).MakeSeparator());

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (asm.GlobalAssemblyCache) continue;

                string file = "??";
                if (string.IsNullOrEmpty(asm.Location))
                    file = asm.ManifestModule.ScopeName;
                else file = Path.GetFileName(asm.Location);

                tb.AddRow(file, asm.ImageRuntimeVersion);
            }

            tb.AddRow("", "");

            tb.AddRow(tb.AddRow(Lang.Get("Module"), Lang.Get("Count")).MakeSeparator());
            tb.AddRow(Lang.Get("Modules"), ModuleCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Encoders"), EncoderCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Payloads"), PayloadCollection.Current.Count.ToString());
            tb.AddRow(Lang.Get("Nops"), NopCollection.Current.Count.ToString());

            _IO.WriteLine(tb.Output());
        }
Exemple #5
0
        public override bool Run()
        {
            DbConnection db = Get();

            if (db == null)
            {
                return(false);
            }

            WriteInfo("Connecting ...");

            using (db)
            {
                try { db.Open(); }
                catch (Exception e)
                {
                    WriteError(e.Message);
                    return(false);
                }

                using (DbCommand cmd = db.CreateCommand())
                {
                    cmd.CommandText = Query;

                    if (IsQuery(Query))
                    {
                        WriteInfo("Detecting Query Type");
                        // Query
                        cmd.CommandType = CommandType.Text;
                        using (DataTable dt = new DataTable()
                        {
                            TableName = Query
                        })
                        {
                            using (DbDataAdapter adapter = DbProviderFactories.GetFactory(db).CreateDataAdapter())
                            {
                                adapter.SelectCommand = cmd;
                                adapter.Fill(dt);
                            }

                            CommandTable table = new CommandTable(dt);

                            switch (QueryOutFormat)
                            {
                            case EFormat.Console:
                            {
                                WriteTable(table);
                                break;
                            }

                            case EFormat.Txt:
                            {
                                File.WriteAllText(QueryOutFile.FullName, table.Output());
                                break;
                            }

                            case EFormat.Xml:
                            {
                                dt.WriteXml(QueryOutFile.FullName, XmlWriteMode.WriteSchema, true);
                                break;
                            }
                            }

                            if (QueryOutFormat != EFormat.Console)
                            {
                                QueryOutFile.Refresh();
                                WriteInfo("OutFile Size: ", QueryOutFile.Length.ToString(), QueryOutFile.Length <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                            }

                            WriteInfo("Rows    : ", dt.Rows.Count.ToString(), dt.Rows.Count <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                            WriteInfo("Columns : ", dt.Columns.Count.ToString(), dt.Columns.Count <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                        }
                    }
                    else
                    {
                        // Non query
                        WriteInfo("Detecting Non-Query Type");

                        int x = cmd.ExecuteNonQuery();
                        WriteInfo("Affected rows", x.ToString(), x <= 0 ? ConsoleColor.Red : ConsoleColor.Green);
                    }

                    WriteInfo("Disconnecting");
                    db.Close();
                }
            }

            return(true);
        }
Exemple #6
0
        public void cmdShow(string args)
        {
            if (!CheckModule(false, EModuleType.None))
            {
                return;
            }
            args = args.Trim().ToLowerInvariant();

            Module curM = _Current.ModuleType == EModuleType.Module ? (Module)_Current : null;

            switch (args)
            {
            case "":
            case "info": { cmdInfo(args); break; }

            case "options":
            case "config":
            {
                // set target id
                Target[] ps = null;

                if (curM != null)
                {
                    ps = curM.Targets;
                    if (ps != null)
                    {
                        int ix = 0;
                        foreach (Target t in ps)
                        {
                            t.Id = ix; ix++;
                        }
                    }
                }

                CommandTable tb = new CommandTable();

                string title = "";
                for (int x = 0; x <= 2; x++)
                {
                    PropertyInfo[] pis = null;

                    object pv = _Current;
                    switch (x)
                    {
                    case 0:
                    {
                        if (_Current.ModuleType == EModuleType.Payload)
                        {
                            title = Lang.Get("Payload_Options", _Current.FullPath);
                        }
                        else
                        {
                            title = Lang.Get("Module_Options", _Current.FullPath);
                        }

                        pis = ReflectionHelper.GetProperties(_Current, true, true, true);
                        break;
                    }

                    case 1:
                    {
                        title = Lang.Get("Current_Target");
                        if (ps != null && ps.Length > 1)
                        {
                            pis = ReflectionHelper.GetProperties(_Current, "Target");
                        }
                        break;
                    }

                    case 2:
                    {
                        if (curM != null)
                        {
                            if (curM.Payload != null)
                            {
                                pv    = curM.Payload;
                                pis   = ReflectionHelper.GetProperties(curM.Payload, true, true, true);
                                title = Lang.Get("Payload_Options", curM.Payload.FullPath);
                            }
                            else
                            {
                                if (curM.PayloadRequirements != null && curM.PayloadRequirements.ItsRequired())
                                {
                                    pis   = ReflectionHelper.GetProperties(_Current, "Payload");
                                    title = Lang.Get("Selected_Payload");
                                }
                            }
                        }
                        break;
                    }
                    }

                    if (pis != null)
                    {
                        bool primera = true;        // (x != 1 || !hasX0);
                        foreach (PropertyInfo pi in pis)
                        {
                            ConfigurableProperty c = pi.GetCustomAttribute <ConfigurableProperty>();
                            if (c == null)
                            {
                                continue;
                            }

                            if (primera)
                            {
                                if (tb.Count > 0)
                                {
                                    tb.AddRow("", "", "");
                                }
                                CommandTableRow row = tb.AddRow(0, title, "", "");
                                tb.AddRow("", "", "");

                                row[0].Align = CommandTableCol.EAlign.None;
                                row[1].Align = CommandTableCol.EAlign.None;
                                row[2].Align = CommandTableCol.EAlign.None;
                                primera      = false;
                            }

                            object val = pi.GetValue(pv);
                            if (val == null)
                            {
                                val = "NULL";
                                CommandTableRow row = tb.AddRow(pi.Name, val.ToString(), c.Description);
                                if (!c.Optional)
                                {
                                    row[1].ForeColor = ConsoleColor.Red;
                                }
                                else
                                {
                                    //if (x == 0 || x == 3)
                                    row[1].ForeColor = ConsoleColor.DarkRed;
                                }
                            }
                            else
                            {
                                val = ConvertHelper.ToString(val);

                                CommandTableRow row = tb.AddRow(pi.Name, val.ToString(), c.Description);
                                if (x == 0 || x == 3)
                                {
                                    row[1].ForeColor = ConsoleColor.Cyan;
                                }
                            }
                        }
                    }
                }

                string separator = tb.Separator;
                foreach (CommandTableRow row in tb)
                {
                    foreach (CommandTableCol col in row)
                    {
                        if (col.ReplicatedChar == '\0')
                        {
                            switch (col.Index)
                            {
                            case 0: _IO.SetForeColor(ConsoleColor.DarkGray); break;

                            case 1: _IO.SetForeColor(col.ForeColor); break;

                            case 2: _IO.SetForeColor(ConsoleColor.Yellow); break;
                            }
                        }
                        else
                        {
                            _IO.SetForeColor(col.ForeColor);
                        }

                        if (col.Index != 0)
                        {
                            _IO.Write(separator);
                        }
                        _IO.Write(col.GetFormatedValue());
                    }
                    _IO.WriteLine("");
                }
                break;
            }

            case "payloads":
            {
                ModuleHeader <Payload>[] ps = curM == null ? null : PayloadCollection.Current.GetAvailables(curM.PayloadRequirements).ToArray();
                if (ps == null || ps.Length <= 0)
                {
                    _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                }
                else
                {
                    CommandTable tb = new CommandTable();

                    tb.AddRow(tb.AddRow(Lang.Get("Name"), Lang.Get("Description")).MakeSeparator());

                    foreach (ModuleHeader <Payload> p in ps)
                    {
                        tb.AddRow(p.FullPath, p.Description);
                    }

                    _IO.Write(tb.Output());
                }
                break;
            }

            case "targets":
            {
                Target[] ps = curM == null ? null : curM.Targets;
                if (ps == null || ps.Length <= 0)
                {
                    _IO.WriteInfo(Lang.Get("Nothing_To_Show"));
                }
                else
                {
                    CommandTable tb = new CommandTable();

                    tb.AddRow(tb.AddRow(Lang.Get("Name"), Lang.Get("Description")).MakeSeparator());

                    int ix = 0;
                    foreach (Target p in ps)
                    {
                        p.Id = ix; ix++;
                        tb.AddRow(p.Id.ToString(), p.Name);
                    }

                    _IO.Write(tb.Output());
                }
                break;
            }

            default:
            {
                // incorrect use
                _IO.WriteError(Lang.Get("Incorrect_Command_Usage"));
                _IO.AddInput("help show");
                break;
            }
            }
        }
Exemple #7
0
        static void DisplayAvailableCommands(CommandMenuItem menu, bool inner)
        {
            if (menu == null) throw new ArgumentNullException("menu");

            CommandTable tb = new CommandTable();

            if (!inner)
            {
                menu.IO.WriteLine(Lang.Get("Available_Commands") + ":");
                menu.IO.WriteLine("");

                tb.AddRow(tb.AddRow(Lang.Get("Short"), Lang.Get("Command")).MakeSeparator());
            }

            bool entra = false;
            var abbreviations = menu.CommandAbbreviations().OrderBy(it => it.Key);
            foreach (var ab in abbreviations)
            {
                //if (ab.Value == null)
                //{
                //    menu.IO.Write("      ");
                //}
                //else
                //{
                //    menu.IO.Write(ab.Value.PadRight(3) + " | ");
                //}

                tb.AddRow(ab.Value, ab.Key)[0].Align = CommandTableCol.EAlign.Right;
                //menu.IO.WriteLine(ab.Key);
                entra = true;
            }

            if (entra) menu.IO.WriteLine(tb.Output());

            if (!inner) menu.IO.WriteLine(Lang.Get("Type_Help"));
        }