Example #1
0
        static internal bool Run(ExtractBase item, MySqlCommand cmd)
        {
            if (item == null)
            {
                return(false);
            }

            // Raise insert
            ulong id = GetHostId(cmd, item);

            if (item is HttpAttack)
            {
                InsertHttpAttack(cmd, id, (HttpAttack)item);
            }
            else if (item is HttpCredential)
            {
                InsertHttpCredential(cmd, id, (HttpCredential)item);
            }

            else if (item is TelnetCredential)
            {
                InsertTelnetCredential(cmd, id, (TelnetCredential)item);
            }
            else if (item is Pop3Credential)
            {
                InsertPop3Credential(cmd, id, (Pop3Credential)item);
            }
            else if (item is FTPCredential)
            {
                InsertFTPCredential(cmd, id, (FTPCredential)item);
            }

            // Delete item
            return(false);
        }
Example #2
0
        static ulong GetHostId(MySqlCommand cmd, ExtractBase it)
        {
            object o;

            lock (cmd)
            {
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("i", it.Address);
                cmd.CommandText = "SELECT ID FROM hosts WHERE IP= @i";
                o = cmd.ExecuteScalar();

                // Exists
                if (o != null)
                {
                    return(Convert.ToUInt64(o));
                }

                // Not exists
                it.RecallCounty(GeoLite2LocationProvider.Current);

                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("ip", it.Address);
                cmd.Parameters.AddWithValue("cont", EnsureLength(it.Continent, 2, true));
                cmd.Parameters.AddWithValue("count", EnsureLength(it.Country, 2, true));
                cmd.CommandText = "INSERT INTO hosts(IP,CONTINENT,COUNTRY)VALUES( @ip , @cont , @count )";
                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
                cmd.CommandText = "SELECT LAST_INSERT_ID()";

                o = cmd.ExecuteScalar();
            }

            return(Convert.ToUInt64(o));
        }
Example #3
0
        private static List <string> GetSelectorsExpression(ExtractBase extractBase, int t = 0)
        {
            var tab = "";

            for (int i = 0; i < t; i++)
            {
                tab += "\t";
            }

            var expression = new List <string>();

            if (!string.IsNullOrEmpty(extractBase.Name))
            {
                var dateType = "";
                switch (extractBase.DataType)
                {
                case TypeCode.Boolean:
                {
                    dateType = "_b";
                    break;
                }

                case TypeCode.Int32:
                {
                    dateType = "_i";
                    break;
                }

                case TypeCode.Int64:
                {
                    dateType = "_l";
                    break;
                }

                case TypeCode.Decimal:
                {
                    dateType = "_f";
                    break;
                }

                case TypeCode.Double:
                {
                    dateType = "_d";
                    break;
                }

                case TypeCode.DateTime:
                {
                    dateType = "_dt";
                    break;
                }
                }

                expression.Add(tab + "#" + extractBase.Name + dateType);
            }

            if (extractBase.Selectors.Count > 0)
            {
                expression.AddRange(GetSelectorsExpression(extractBase.Selectors, tab));
            }

            if (expression.Count > 0)
            {
                expression[expression.Count - 1] += "\r\n";
            }

            return(expression);
        }
Example #4
0
        /// <summary>
        /// parse block base
        /// </summary>
        /// <param name="expression">ruiji block base expression</param>
        /// <returns>extract base</returns>
        public static ExtractBase ParserBase(string expression)
        {
            expression = expression.Trim();
            var lines = expression.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            var eb = new ExtractBase();

            foreach (var line in lines)
            {
                var ln = line.Trim();

                if (ln.StartsWith("#"))
                {
                    ln = ln.TrimStart('#');
                    if (ln.LastIndexOf("_") == -1)
                    {
                        eb.Name     = ln;
                        eb.DataType = TypeCode.String;
                    }
                    else
                    {
                        var t = ln.Substring(ln.LastIndexOf("_") + 1);
                        eb.Name = ln.Substring(0, ln.LastIndexOf("_"));

                        switch (t)
                        {
                        case "i":
                        {
                            eb.DataType = TypeCode.Int32;
                            break;
                        }

                        case "s":
                        {
                            eb.DataType = TypeCode.String;
                            break;
                        }

                        case "l":
                        {
                            eb.DataType = TypeCode.Int64;
                            break;
                        }

                        case "b":
                        {
                            eb.DataType = TypeCode.Boolean;
                            break;
                        }

                        case "f":
                        {
                            eb.DataType = TypeCode.Single;
                            break;
                        }

                        case "d":
                        {
                            eb.DataType = TypeCode.Double;
                            break;
                        }

                        case "dt":
                        {
                            eb.DataType = TypeCode.DateTime;
                            break;
                        }

                        default:
                        {
                            eb.Name     = ln;
                            eb.DataType = TypeCode.String;
                            break;
                        }
                        }
                    }
                }
                else
                {
                    var s = ParserSelector(ln);
                    if (s != null)
                    {
                        eb.Selectors.Add(s);
                    }
                }
            }

            return(eb);
        }
Example #5
0
        /// <summary>
        /// parse block base
        /// </summary>
        /// <param name="expression">ruiji block base expression</param>
        /// <returns>extract base</returns>
        public static ExtractBase ParserBase(string expression)
        {
            expression = expression.Trim();
            var lines = expression.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            var eb = new ExtractBase();

            foreach (var line in lines)
            {
                var ln = line.Trim();

                if (ln.StartsWith("#"))
                {
                    ln = ln.TrimStart('#');
                    if (ln.LastIndexOf("_") == -1)
                    {
                        eb.Name        = ln;
                        eb.ContentType = typeof(string);
                    }
                    else
                    {
                        var t = ln.Substring(ln.LastIndexOf("_") + 1);
                        eb.Name = ln.Substring(0, ln.LastIndexOf("_"));

                        switch (t)
                        {
                        case "i":
                        {
                            eb.ContentType = typeof(int);
                            break;
                        }

                        case "s":
                        {
                            eb.ContentType = typeof(string);
                            break;
                        }

                        case "l":
                        {
                            eb.ContentType = typeof(long);
                            break;
                        }

                        case "b":
                        {
                            eb.ContentType = typeof(bool);
                            break;
                        }

                        case "f":
                        {
                            eb.ContentType = typeof(float);
                            break;
                        }

                        case "d":
                        {
                            eb.ContentType = typeof(double);
                            break;
                        }

                        case "dt":
                        {
                            eb.ContentType = typeof(DateTime);
                            break;
                        }

                        default:
                        {
                            eb.Name        = ln;
                            eb.ContentType = typeof(string);
                            break;
                        }
                        }
                    }
                }
                else
                {
                    var s = ParserSelector(ln);
                    if (s != null)
                    {
                        eb.Selectors.Add(s);
                    }
                }
            }

            return(eb);
        }