Underc0de - La Casa de los Informáticos

Foros Generales => Dudas y pedidos generales => Mensaje iniciado por: Noporfavor en Febrero 13, 2017, 04:45:54 PM

Título: Analisis de Sb0t 5.36
Publicado por: Noporfavor en Febrero 13, 2017, 04:45:54 PM
Hola,

les quiero dejar un pedazo de codigo llamado Bans.cs:

Código (csharp) [Seleccionar]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Net;
using iconnect;

namespace commands
{
    class Bans
    {
        private class Item
        {
            public IPAddress IP { get; set; }
            public Guid Guid { get; set; }
            public uint Time { get; set; }
            public BanDuration Duration { get; set; }
            public String Name { get; set; }
        }

        public static void AddBan(IUser client, BanDuration duration)
        {
            if (list.Find(x => x.IP.Equals(client.ExternalIP) || x.Guid.Equals(client.Guid)) == null)
            {
                list.Add(new Item
                {
                    Guid = client.Guid,
                    IP = client.ExternalIP,
                    Time = Server.Time,
                    Duration = duration,
                    Name = client.Name
                });

                Save();
            }
        }

        public static void RemoveBan(String name)
        {
            list.RemoveAll(x => x.Name == name);
            Save();
        }

        private static List<Item> list { get; set; }

        public static void Tick(uint time)
        {
            for (int i = (list.Count - 1); i > -1; i--)
            {
                Item m = list[i];

                if ((time - m.Time) > (uint)m.Duration)
                {
                    list.RemoveAt(i);
                    Server.Print(Template.Text(Category.Timeouts, 2).Replace("+n", m.Name), true);

                    Server.Users.Banned(x =>
                    {
                        if (x.ExternalIP.Equals(m.IP) || x.Guid.Equals(m.Guid))
                            x.Unban();
                    });
                }
            }
        }

        public static void Clear()
        {
            list = new List<Item>();
            Save();
        }

        private static void Save()
        {
            XmlDocument xml = new XmlDocument();
            xml.PreserveWhitespace = true;
            xml.AppendChild(xml.CreateXmlDeclaration("1.0", null, null));
            XmlNode root = xml.AppendChild(xml.CreateElement("bans"));

            foreach (Item i in list)
            {
                XmlNode item = root.OwnerDocument.CreateNode(XmlNodeType.Element, "item", root.BaseURI);
                root.AppendChild(item);
                XmlNode ip = item.OwnerDocument.CreateNode(XmlNodeType.Element, "ip", item.BaseURI);
                item.AppendChild(ip);
                ip.InnerText = i.IP.ToString();
                XmlNode guid = item.OwnerDocument.CreateNode(XmlNodeType.Element, "guid", item.BaseURI);
                item.AppendChild(guid);
                guid.InnerText = i.Guid.ToString();
                XmlNode time = item.OwnerDocument.CreateNode(XmlNodeType.Element, "time", item.BaseURI);
                item.AppendChild(time);
                time.InnerText = i.Time.ToString();
                XmlNode duration = item.OwnerDocument.CreateNode(XmlNodeType.Element, "duration", item.BaseURI);
                item.AppendChild(duration);
                duration.InnerText = ((uint)i.Duration).ToString();               
                XmlNode name = item.OwnerDocument.CreateNode(XmlNodeType.Element, "name", item.BaseURI);
                item.AppendChild(name);
                name.InnerText = i.Name;
            }

            try { xml.Save(Path.Combine(Server.DataPath, "bans.xml")); }
            catch { }
        }

        public static void Load()
        {
            list = new List<Item>();

            try
            {
                XmlDocument xml = new XmlDocument();
                xml.PreserveWhitespace = true;
                xml.Load(Path.Combine(Server.DataPath, "bans.xml"));

                XmlNodeList nodes = xml.GetElementsByTagName("item");

                foreach (XmlElement e in nodes)
                    list.Add(new Item
                    {
                        IP = IPAddress.Parse(e.GetElementsByTagName("ip")[0].InnerText),
                        Guid = new Guid(e.GetElementsByTagName("guid")[0].InnerText),
                        Time = uint.Parse(e.GetElementsByTagName("time")[0].InnerText),
                        Duration = e.GetElementsByTagName("duration")[0].InnerText == "600" ? BanDuration.Ten : BanDuration.Sixty,
                        Name = e.GetElementsByTagName("name")[0].InnerText
                    });
            }
            catch { }
        }
    }

    enum BanDuration : uint
    {
        Ten = 600,
        Sixty = 3600
    }
}


En la linea 34 se puede ver:

public IPAddress IP { get; set; }

Yo creo que se saca la ip y se coloca. Estoy en lo correcto?

Gracias y saludos
Título: Re:Analisis de Sb0t 5.36
Publicado por: rush en Febrero 13, 2017, 05:04:56 PM
No entiendo a que te refieres con se saca y se coloca la ip.

Por lo que entiendo son metodos

para banear gente, y se agregan a una lista que esta en .xml


realmente de donde sale la ip es de aca:

Código (c#) [Seleccionar]
IP = IPAddress.Parse(e.GetElementsByTagName("ip")[0].InnerText),
                        Guid = new Guid(e.GetElementsByTagName("guid")[0].InnerText),
                        Time = uint.Parse(e.GetElementsByTagName("time")[0].InnerText),
                        Duration = e.GetElementsByTagName("duration")[0].InnerText == "600" ? BanDuration.Ten : BanDuration.Sixty,
                        Name = e.GetElementsByTagName("name")[0].InnerText




Título: Re:Analisis de Sb0t 5.36
Publicado por: Noporfavor en Febrero 14, 2017, 08:02:23 AM
Hola rush,

en realidad queria analizar el proceso de ban. Y me tope con public IPAddress IP { get; set; }.

Siguiendo con el analisis queria saber lo siguiente.
Si vamos a core > AresClient.cs > Linea 711 podemos observar lo siguiente:

while (this.data_out.Count > 0)

Pero que representa el data_out?

Se declara en la linea 98 pero no se para que es eso.

Lo sabes tu?

Gracias y saludos
Título: Re:Analisis de Sb0t 5.36
Publicado por: rush en Febrero 14, 2017, 03:02:21 PM
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Hola rush,

en realidad queria analizar el proceso de ban. Y me tope con public IPAddress IP { get; set; }.


En realidad no se como explicartelo, pero aca mas informacion Informacion (http://stackoverflow.com/questions/5096926/what-is-the-get-set-syntax-in-c)

Esos métodos hacen una función como su nombre lo indica de get(obtener) y set(asignar)

Con la cual puedes obtener el valor con get en el metodo ipaddress o asignarle valor, son usados para llevar un mejor control y mejor programación, pero en sí es como si hicieras lo siguiente:

public Setaddressip {
       set{
           this.ip = addressip;
        }
}

public Getaddressip{
       get{
             return this.adressip;
       }
}

Puedes recuperar un valor por medio de ese metodo o definirle un valor por ese metodo.

while (this.data_out.Count > 0)

Pero que representa el data_out?


Supongo que hace un proceso hasta desde 0 hasta el numero de datos leidos,

data_out quiero pensar que contiene información, asi mismo tiene un contador para determinar cuando parar.