Ejemplo n.º 1
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement addressNode = document.CreateElement("idmef:UserId", "http://iana.org/idmef");

            addressNode.SetAttribute("ident", ident);
            addressNode.SetAttribute("type", EnumDescription.GetEnumDescription(type));
            if (!string.IsNullOrEmpty(tty))
            {
                addressNode.SetAttribute("tty", tty);
            }

            if (!string.IsNullOrEmpty(name))
            {
                XmlElement addressSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
                XmlNode    subNode        = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");
                subNode.Value = name;
                addressSubNode.AppendChild(subNode);
                addressNode.AppendChild(addressSubNode);
            }
            if (number != null)
            {
                XmlElement addressSubNode = document.CreateElement("idmef:number", "http://iana.org/idmef");
                XmlNode    subNode        = document.CreateNode(XmlNodeType.Text, "idmef", "number", "http://iana.org/idmef");
                subNode.Value = number.ToString();
                addressSubNode.AppendChild(subNode);
                addressNode.AppendChild(addressSubNode);
            }

            return(addressNode);
        }
Ejemplo n.º 2
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement actionNode = document.CreateElement("idmef:Confidence", "http://iana.org/idmef");

            actionNode.SetAttribute("rating", EnumDescription.GetEnumDescription(rating));

            if (rating == ConfidenceRatingEnum.numeric)
            {
                XmlNode impactSubNode = document.CreateNode(XmlNodeType.Text, "idmef", "Confidence", "http://iana.org/idmef");
                impactSubNode.Value = value.ToString();
                actionNode.AppendChild(impactSubNode);
            }

            return(actionNode);
        }
Ejemplo n.º 3
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement actionNode = document.CreateElement("idmef:Action", "http://iana.org/idmef");

            actionNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));

            if ((description != null) && (description.Length > 0))
            {
                XmlNode impactSubNode = document
                                        .CreateNode(XmlNodeType.Text, "idmef", "Action", "http://iana.org/idmef");
                impactSubNode.Value = description;
                actionNode.AppendChild(impactSubNode);
            }

            return(actionNode);
        }
Ejemplo n.º 4
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement linkageNode = document.CreateElement("idmef:Linkage", "http://iana.org/idmef");

            linkageNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));

            XmlElement linkageSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
            XmlNode    subNode        = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");

            subNode.Value = name;
            linkageSubNode.AppendChild(subNode);
            linkageNode.AppendChild(linkageSubNode);
            linkageSubNode = document.CreateElement("idmef:path", "http://iana.org/idmef");
            subNode        = document.CreateNode(XmlNodeType.Text, "idmef", "path", "http://iana.org/idmef");
            subNode.Value  = path;
            linkageSubNode.AppendChild(subNode);
            linkageNode.AppendChild(linkageSubNode);
            linkageNode.AppendChild(file.ToXml(document));

            return(linkageNode);
        }
Ejemplo n.º 5
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement userNode = document.CreateElement("idmef:User", "http://iana.org/idmef");

            userNode.SetAttribute("ident", ident);
            userNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));

            if ((userId == null) || (userId.Length == 0))
            {
                throw new InvalidOperationException("User must have at least one UserId node.");
            }
            foreach (var ui in userId)
            {
                if (ui != null)
                {
                    userNode.AppendChild(ui.ToXml(document));
                }
            }

            return(userNode);
        }
Ejemplo n.º 6
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement fileAccessNode = document.CreateElement("idmef:FileAccess", "http://iana.org/idmef");

            if (!((userId.type == UserIdTypeEnum.userPrivs) ||
                  (userId.type == UserIdTypeEnum.groupPrivs) ||
                  (userId.type == UserIdTypeEnum.otherPrivs)))
            {
                throw new InvalidOperationException(string.Format("FileAcces node can't hold UserId of type {0}!", userId));
            }
            fileAccessNode.AppendChild(userId.ToXml(document));
            foreach (var p in permission)
            {
                XmlElement fileAccessSubNode = document.CreateElement("idmef:Permission", "http://iana.org/idmef");
                XmlNode    subNode           = document.CreateNode(XmlNodeType.Text, "idmef", "Permission", "http://iana.org/idmef");
                subNode.Value = EnumDescription.GetEnumDescription(p);
                fileAccessSubNode.AppendChild(subNode);
                fileAccessNode.AppendChild(fileAccessSubNode);
            }

            return(fileAccessNode);
        }
Ejemplo n.º 7
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement checksumNode = document.CreateElement("idmef:Checksum", "http://iana.org/idmef");

            checksumNode.SetAttribute("category", EnumDescription.GetEnumDescription(algorithm));

            XmlElement checksumSubNode = document.CreateElement("idmef:value", "http://iana.org/idmef");
            XmlNode    subNode         = document.CreateNode(XmlNodeType.Text, "idmef", "value", "http://iana.org/idmef");

            subNode.Value = value;
            checksumSubNode.AppendChild(subNode);
            checksumNode.AppendChild(checksumSubNode);
            if (!string.IsNullOrEmpty(key))
            {
                checksumSubNode = document.CreateElement("idmef:key", "http://iana.org/idmef");
                subNode         = document.CreateNode(XmlNodeType.Text, "idmef", "key", "http://iana.org/idmef");
                subNode.Value   = key;
                checksumSubNode.AppendChild(subNode);
                checksumNode.AppendChild(checksumSubNode);
            }

            return(checksumNode);
        }
Ejemplo n.º 8
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement addressNode = document.CreateElement("idmef:Address", "http://iana.org/idmef");

            addressNode.SetAttribute("ident", ident);
            addressNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));
            if (!string.IsNullOrEmpty(vlanName))
            {
                addressNode.SetAttribute("vlan-name", vlanName);
            }
            if (vlanNum != null)
            {
                addressNode.SetAttribute("vlan-num", vlanNum.ToString());
            }

            if (string.IsNullOrEmpty(address))
            {
                throw new InvalidOperationException("Address must have an address node.");
            }
            XmlElement addressSubNode = document.CreateElement("idmef:address", "http://iana.org/idmef");
            XmlNode    subNode        = document.CreateNode(XmlNodeType.Text, "idmef", "address", "http://iana.org/idmef");

            subNode.Value = address;
            addressSubNode.AppendChild(subNode);
            addressNode.AppendChild(addressSubNode);

            if (!string.IsNullOrEmpty(netmask))
            {
                addressSubNode = document.CreateElement("idmef:netmask", "http://iana.org/idmef");
                subNode        = document.CreateNode(XmlNodeType.Text, "idmef", "netmask", "http://iana.org/idmef");
                subNode.Value  = netmask;
                addressSubNode.AppendChild(subNode);
                addressNode.AppendChild(addressSubNode);
            }

            return(addressNode);
        }
Ejemplo n.º 9
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement nodeNode = document.CreateElement("idmef:Node", "http://iana.org/idmef");

            nodeNode.SetAttribute("ident", ident);
            nodeNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));

            if (!string.IsNullOrEmpty(location))
            {
                XmlElement nodeSubNode = document.CreateElement("idmef:location", "http://iana.org/idmef");
                XmlNode    subNode     = document.CreateNode(XmlNodeType.Text, "idmef", "location", "http://iana.org/idmef");
                subNode.Value = location;
                nodeSubNode.AppendChild(subNode);
                nodeNode.AppendChild(nodeSubNode);
            }
            if (!string.IsNullOrEmpty(name))
            {
                XmlElement nodeSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
                XmlNode    subNode     = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");
                subNode.Value = name;
                nodeSubNode.AppendChild(subNode);
                nodeNode.AppendChild(nodeSubNode);
            }
            if ((address != null) && (address.Length > 0))
            {
                foreach (var a in address)
                {
                    if (a != null)
                    {
                        nodeNode.AppendChild(a.ToXml(document));
                    }
                }
            }

            return(nodeNode);
        }
Ejemplo n.º 10
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement referenceNode = document.CreateElement("idmef:Reference", "http://iana.org/idmef");

            referenceNode.SetAttribute("origin", EnumDescription.GetEnumDescription(origin));
            if (((origin == OriginEnum.userSpecific) || (origin == OriginEnum.vendorSpecific)) && !string.IsNullOrEmpty(meaning))
            {
                referenceNode.SetAttribute("meaning", meaning);
            }

            XmlElement referenceSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
            XmlNode    impactSubNode    = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");

            impactSubNode.Value = name;
            referenceSubNode.AppendChild(impactSubNode);
            referenceNode.AppendChild(referenceSubNode);
            referenceSubNode    = document.CreateElement("idmef:url", "http://iana.org/idmef");
            impactSubNode       = document.CreateNode(XmlNodeType.Text, "idmef", "url", "http://iana.org/idmef");
            impactSubNode.Value = url;
            referenceSubNode.AppendChild(impactSubNode);
            referenceNode.AppendChild(referenceSubNode);

            return(referenceNode);
        }
Ejemplo n.º 11
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement fileNode = document.CreateElement("idmef:File", "http://iana.org/idmef");

            fileNode.SetAttribute("ident", ident);
            fileNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));
            if (fstype != FileSystemTypeEnum.unknown)
            {
                fileNode.SetAttribute("fstype", EnumDescription.GetEnumDescription(fstype));
            }
            if (!string.IsNullOrEmpty(fileType))
            {
                fileNode.SetAttribute("file-type", fileType);
            }

            XmlElement fileSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
            XmlNode    subNode     = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");

            subNode.Value = name;
            fileSubNode.AppendChild(subNode);
            fileNode.AppendChild(fileSubNode);
            fileSubNode   = document.CreateElement("idmef:path", "http://iana.org/idmef");
            subNode       = document.CreateNode(XmlNodeType.Text, "idmef", "path", "http://iana.org/idmef");
            subNode.Value = path;
            fileSubNode.AppendChild(subNode);
            fileNode.AppendChild(fileSubNode);
            if (createTime != null)
            {
                fileSubNode   = document.CreateElement("idmef:create-time", "http://iana.org/idmef");
                subNode       = document.CreateNode(XmlNodeType.Text, "idmef", "create-time", "http://iana.org/idmef");
                subNode.Value = ((DateTime)createTime).ToString("o");
                fileSubNode.AppendChild(subNode);
                fileNode.AppendChild(fileSubNode);
            }
            if (modifyTime != null)
            {
                fileSubNode   = document.CreateElement("idmef:modify-time", "http://iana.org/idmef");
                subNode       = document.CreateNode(XmlNodeType.Text, "idmef", "modify-time", "http://iana.org/idmef");
                subNode.Value = ((DateTime)modifyTime).ToString("o");
                fileSubNode.AppendChild(subNode);
                fileNode.AppendChild(fileSubNode);
            }
            if (accessTime != null)
            {
                fileSubNode   = document.CreateElement("idmef:access-time", "http://iana.org/idmef");
                subNode       = document.CreateNode(XmlNodeType.Text, "idmef", "access-time", "http://iana.org/idmef");
                subNode.Value = ((DateTime)accessTime).ToString("o");
                fileSubNode.AppendChild(subNode);
                fileNode.AppendChild(fileSubNode);
            }
            if (dataSize != null)
            {
                fileSubNode   = document.CreateElement("idmef:data-size", "http://iana.org/idmef");
                subNode       = document.CreateNode(XmlNodeType.Text, "idmef", "data-size", "http://iana.org/idmef");
                subNode.Value = dataSize.ToString();
                fileSubNode.AppendChild(subNode);
                fileNode.AppendChild(fileSubNode);
            }
            if (diskSize != null)
            {
                fileSubNode   = document.CreateElement("idmef:disk-size", "http://iana.org/idmef");
                subNode       = document.CreateNode(XmlNodeType.Text, "idmef", "disk-size", "http://iana.org/idmef");
                subNode.Value = diskSize.ToString();
                fileSubNode.AppendChild(subNode);
                fileNode.AppendChild(fileSubNode);
            }
            if ((fileAccess != null) && (fileAccess.Length > 0))
            {
                foreach (var fa in fileAccess)
                {
                    if (fa != null)
                    {
                        fileNode.AppendChild(fa.ToXml(document));
                    }
                }
            }
            if ((linkage != null) && (linkage.Length > 0))
            {
                foreach (var lnk in linkage)
                {
                    if (lnk != null)
                    {
                        fileNode.AppendChild(lnk.ToXml(document));
                    }
                }
            }
            if (inode != null)
            {
                fileNode.AppendChild(inode.ToXml(document));
            }
            if ((checksum != null) && (checksum.Length > 0))
            {
                foreach (var chs in checksum)
                {
                    if (chs != null)
                    {
                        fileNode.AppendChild(chs.ToXml(document));
                    }
                }
            }

            return(fileNode);
        }
Ejemplo n.º 12
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement adNode    = document.CreateElement("idmef:AdditionalData", "http://iana.org/idmef");
            XmlNode    adSubNode = document.CreateNode(XmlNodeType.Text, "idmef", EnumDescription.GetEnumDescription(type), "http://iana.org/idmef");

            switch (type)
            {
            case ADEnum.boolean:
                adSubNode.Value = data_boolean.ToString();
                break;

            case ADEnum.adByte:
                adSubNode.Value = data_byte.ToString();
                break;

            case ADEnum.character:
                adSubNode.Value = data_character.ToString();
                break;

            case ADEnum.datetime:
                adSubNode.Value = data_datetime.ToString("o");
                break;

            case ADEnum.integer:
                adSubNode.Value = data_integer.ToString();
                break;

            case ADEnum.ntpstamp:
                adSubNode.Value = data_ntpstamp.ToString();
                break;

            case ADEnum.portlist:
                adSubNode.Value = data_portlist.ToString();
                break;

            case ADEnum.real:
                adSubNode.Value = data_real.ToString();
                break;

            case ADEnum.adString:
                adSubNode.Value = data_string;
                break;

            case ADEnum.byteString:
                adSubNode.Value = Convert.ToBase64String(data_bytestring);
                break;

            case ADEnum.xml:
                try
                {
                    adSubNode          = document.CreateElement("idmef:xml", "http://iana.org/idmef");
                    adSubNode.InnerXml = data_xml.OuterXml;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                break;
            }

            adNode.SetAttribute("type", EnumDescription.GetEnumDescription(type));
            if (!string.IsNullOrEmpty(meaning))
            {
                adNode.SetAttribute("meaning", meaning);
            }
            adNode.AppendChild(adSubNode);

            return(adNode);
        }