elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  [C#] Clase DH Tools
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [C#] Clase DH Tools  (Leído 1,578 veces)
BigBear


Desconectado Desconectado

Mensajes: 545



Ver Perfil
[C#] Clase DH Tools
« en: 20 Junio 2014, 16:04 pm »

Mi primer clase que hice practicando en C#

Con las siguientes funciones :

  • Realizar peticiones GET & POST
  • Ver el numero de HTTP Status en una pagina
  • HTTP FingerPrinting
  • Leer un archivo
  • Escribir o crear un archivo
  • Ver el sistema operativo actual
  • Elimina duplicados en una lista
  • Corta URLS en una lista
  • Descargar y subir archivos
  • Ver el nombre del archivo en una ruta
  • Ejecutar comandos
  • URI Split
  • MD5 Hash Generator
  • Ver el MD5 de un archivo
  • Ver la IP de un hostname

El codigo de la clase :

Código
  1. // Class Name : DH Tools
  2. // Version : Beta
  3. // Author : Doddy Hackman
  4. // (C) Doddy Hackman 2014
  5. //
  6. // Functions :
  7. //
  8. // [+] HTTP Methods GET & POST
  9. // [+] Get HTTP Status code number
  10. // [+] HTTP FingerPrinting
  11. // [+] Read File
  12. // [+] Write File
  13. // [+] GET OS
  14. // [+] Remove duplicates from a List
  15. // [+] Cut urls from a List
  16. // [+] Download
  17. // [+] Upload
  18. // [+] Get Basename from a path
  19. // [+] Execute commands
  20. // [+] URI Split
  21. // [+] MD5 Hash Generator
  22. // [+] Get MD5 of file
  23. // [+] Get IP address from host name
  24. //
  25. // Credits :
  26. //
  27. // Method POST -> https://technet.rapaport.com/Info/Prices/SampleCode/Full_Example.aspx
  28. // Method GET -> http://stackoverflow.com/questions/4510212/how-i-can-get-web-pages-content-and-save-it-into-the-string-variable
  29. // HTTP Headers -> http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.headers%28v=vs.110%29.aspx
  30. // List Cleaner -> http://forums.asp.net/t/1318899.aspx?Remove+duplicate+items+from+List+String+
  31. // Execute command -> http://www.codeproject.com/Articles/25983/How-to-Execute-a-Command-in-C
  32. // MD5 Hash Generator -> http://www.java2s.com/Code/CSharp/Security/GetandverifyMD5Hash.htm
  33. // Get MD5 of file -> http://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file
  34. //
  35. // Thanks to : $DoC and atheros14 (Forum indetectables)
  36. //
  37.  
  38. using System;
  39. using System.Collections.Generic;
  40. using System.Text;
  41.  
  42. using System.Net;
  43. using System.IO;
  44. using System.Text.RegularExpressions;
  45. using System.Security.Cryptography;
  46.  
  47. namespace clasewebtools
  48. {
  49.    class DH_Tools
  50.    {
  51.        public string toma(string url)
  52.        {
  53.            string code = "";
  54.  
  55.            try
  56.            {
  57.                WebClient nave = new WebClient();
  58.                nave.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
  59.                code = nave.DownloadString(url);
  60.            }
  61.            catch
  62.            {
  63.                //
  64.            }
  65.            return code;
  66.        }
  67.  
  68.        public string tomar(string url, string par)
  69.        {
  70.  
  71.            string code = "";
  72.  
  73.            try
  74.            {
  75.  
  76.                HttpWebRequest nave = (HttpWebRequest)
  77.                WebRequest.Create(url);
  78.  
  79.                nave.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
  80.                nave.Method = "POST";
  81.                nave.ContentType = "application/x-www-form-urlencoded";
  82.  
  83.                Stream anteantecode = nave.GetRequestStream();
  84.  
  85.                anteantecode.Write(Encoding.ASCII.GetBytes(par), 0, Encoding.ASCII.GetBytes(par).Length);
  86.                anteantecode.Close();
  87.  
  88.                StreamReader antecode = new StreamReader(nave.GetResponse().GetResponseStream());
  89.                code = antecode.ReadToEnd();
  90.  
  91.            }
  92.            catch
  93.            {
  94.                //
  95.            }
  96.  
  97.            return code;
  98.  
  99.        }
  100.  
  101.        public string respondecode(string url)
  102.        {
  103.            String code = "";
  104.            try
  105.            {
  106.                HttpWebRequest nave = (HttpWebRequest)WebRequest.Create(url);
  107.                nave.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
  108.                HttpWebResponse num = (HttpWebResponse)nave.GetResponse();
  109.  
  110.                int number = (int)num.StatusCode;
  111.                code = Convert.ToString(number);
  112.  
  113.            }
  114.            catch
  115.            {
  116.  
  117.                code = "404";
  118.  
  119.            }
  120.            return code;
  121.        }
  122.  
  123.        public string httpfinger(string url)
  124.        {
  125.  
  126.            String code = "";
  127.  
  128.            try
  129.            {
  130.  
  131.                HttpWebRequest nave1 = (HttpWebRequest)WebRequest.Create(url);
  132.                HttpWebResponse nave2 = (HttpWebResponse)nave1.GetResponse();
  133.  
  134.                for (int num = 0; num < nave2.Headers.Count; ++num)
  135.                {
  136.                    code = code + "[+] " + nave2.Headers.Keys[num] + ":" + nave2.Headers[num] + Environment.NewLine;
  137.                }
  138.  
  139.                nave2.Close();
  140.            }
  141.            catch
  142.            {
  143.                //
  144.            }
  145.  
  146.            return code;
  147.  
  148.        }
  149.  
  150.        public string openword(string file)
  151.        {
  152.            String code = "";
  153.            try
  154.            {
  155.                code = System.IO.File.ReadAllText(file);
  156.            }
  157.            catch
  158.            {
  159.                //
  160.            }
  161.            return code;
  162.        }
  163.  
  164.        public void savefile(string file,string texto) {
  165.  
  166.            try {
  167.            System.IO.StreamWriter save = new System.IO.StreamWriter(file, true);
  168.            save.Write(texto);
  169.            save.Close();
  170.            }
  171.            catch {
  172.                //
  173.            }
  174.        }
  175.  
  176.        public string getos()
  177.        {
  178.            string code = "";
  179.  
  180.            try
  181.            {
  182.                System.OperatingSystem os = System.Environment.OSVersion;
  183.                code = Convert.ToString(os);
  184.            }
  185.            catch
  186.            {
  187.                code = "?";
  188.            }
  189.  
  190.            return code;
  191.        }
  192.  
  193.        public List<string> repes(List<string> array)
  194.        {
  195.            List<string> repe = new List<string>();
  196.            foreach (string lin in array)
  197.            {
  198.                if (!repe.Contains(lin))
  199.                {
  200.                    repe.Add(lin);
  201.                }
  202.            }
  203.  
  204.            return repe;
  205.  
  206.        }
  207.  
  208.        public List<string> cortar(List<string> otroarray)
  209.        {
  210.            List<string> cort = new List<string>();
  211.  
  212.            foreach (string row in otroarray)
  213.            {
  214.  
  215.                String lineafinal = "";
  216.  
  217.                Match regex = Regex.Match(row, @"(.*)\?(.*)=(.*)", RegexOptions.IgnoreCase);
  218.                if (regex.Success)
  219.                {
  220.                    lineafinal = regex.Groups[1].Value + "?" + regex.Groups[2].Value + "=";
  221.                    cort.Add(lineafinal);
  222.                }
  223.  
  224.            }
  225.  
  226.            return cort;
  227.        }
  228.  
  229.        public string download(string url,string savename)
  230.        {
  231.  
  232.            String code = "";
  233.  
  234.            WebClient nave = new WebClient();
  235.            nave.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
  236.  
  237.            try
  238.            {
  239.                nave.DownloadFile(url, savename);
  240.                code = "OK";
  241.            }
  242.            catch
  243.            {
  244.                code = "Error";
  245.            }
  246.  
  247.            return code;
  248.        }
  249.  
  250.        public string upload(string link,string archivo)
  251.        {
  252.  
  253.            String code = "";
  254.  
  255.            try
  256.            {
  257.  
  258.                WebClient nave = new WebClient();
  259.                nave.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0";
  260.                byte[] codedos = nave.UploadFile(link, "POST", archivo);
  261.                code = System.Text.Encoding.UTF8.GetString(codedos, 0, codedos.Length);
  262.  
  263.            }
  264.  
  265.            catch
  266.            {
  267.                code = "Error";
  268.            }
  269.  
  270.            return code;
  271.  
  272.        }
  273.  
  274.        public string basename(string file)
  275.        {
  276.            String nombre = "";
  277.  
  278.            FileInfo basename = new FileInfo(file);
  279.            nombre = basename.Name;
  280.  
  281.            return nombre;
  282.  
  283.        }
  284.  
  285.        public string console(string cmd)
  286.        {
  287.  
  288.            string code = "";
  289.  
  290.            try
  291.            {
  292.  
  293.                System.Diagnostics.ProcessStartInfo loadnow = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + cmd);
  294.                loadnow.RedirectStandardOutput = true;
  295.                loadnow.UseShellExecute = false;
  296.                loadnow.CreateNoWindow = true;
  297.                System.Diagnostics.Process loadnownow = new System.Diagnostics.Process();
  298.                loadnownow.StartInfo = loadnow;
  299.                loadnownow.Start();
  300.                code = loadnownow.StandardOutput.ReadToEnd();
  301.  
  302.            }
  303.  
  304.            catch
  305.            {
  306.                code = "Error";
  307.            }
  308.  
  309.            return code;
  310.  
  311.        }
  312.  
  313.        public string urisplit(string url,string opcion)
  314.        {
  315.  
  316.            string code = "";
  317.  
  318.            Uri dividir = new Uri(url);
  319.  
  320.            if (opcion == "host")
  321.            {
  322.                code = dividir.Host;
  323.            }
  324.  
  325.            if (opcion == "port")
  326.            {
  327.                code = Convert.ToString(dividir.Port);
  328.            }
  329.  
  330.            if (opcion == "path")
  331.            {
  332.                code = dividir.LocalPath;
  333.            }
  334.  
  335.            if (opcion == "file")
  336.            {
  337.                code = dividir.AbsolutePath;
  338.                FileInfo basename = new FileInfo(code);
  339.                code = basename.Name;
  340.            }
  341.  
  342.            if (opcion == "query")
  343.            {
  344.                code = dividir.Query;
  345.            }
  346.  
  347.            if (opcion == "")
  348.            {
  349.                code = "Error";
  350.            }
  351.  
  352.            return code;
  353.        }
  354.  
  355.        public string convertir_md5(string text)
  356.        {
  357.            MD5 convertirmd5 = MD5.Create();
  358.            byte[] infovalor = convertirmd5.ComputeHash(Encoding.Default.GetBytes(text));
  359.            StringBuilder guardar = new StringBuilder();
  360.            for (int numnow = 0; numnow < infovalor.Length; numnow++)
  361.            {
  362.                guardar.Append(infovalor[numnow].ToString("x2"));
  363.            }
  364.            return guardar.ToString();
  365.        }
  366.  
  367.        public string md5file(string file)
  368.        {
  369.  
  370.            string code = "";
  371.  
  372.            try
  373.            {
  374.                var gen = MD5.Create();
  375.                var ar = File.OpenRead(file);
  376.                code = BitConverter.ToString(gen.ComputeHash(ar)).Replace("-", "").ToLower();
  377.  
  378.            }
  379.            catch
  380.            {
  381.                code = "Error";
  382.            }
  383.  
  384.            return code;
  385.        }
  386.  
  387.        public string getip(string host)
  388.        {
  389.            string code = "";
  390.            try
  391.            {
  392.                IPAddress[] find = Dns.GetHostAddresses(host);
  393.                code = find[0].ToString();
  394.            }
  395.            catch
  396.            {
  397.                code = "Error";
  398.            }
  399.            return code;
  400.        }
  401.  
  402.    }
  403. }
  404.  
  405. // The End ?
  406.  

Con los siguientes ejemplos de uso :

Código
  1. namespace clasewebtools
  2. {
  3.    public partial class Form1 : Form
  4.    {
  5.        public Form1()
  6.        {
  7.            InitializeComponent();
  8.        }
  9.  
  10.        private void button1_Click(object sender, EventArgs e)
  11.        {
  12.  
  13.            // Examples
  14.  
  15.            DH_Tools tools = new DH_Tools();
  16.  
  17.            // The GET Method
  18.            //string code = tools.toma("http://www.petardas.com/index.php");
  19.  
  20.            // The POST Method
  21.            //string code = tools.tomar("http://localhost/pos.php", "probar=test&yeah=dos&control=Now");
  22.  
  23.            // HTTP Status code number
  24.            //string code = tools.respondecode("http://www.petardas.com/index.php");
  25.  
  26.            // HTTP FingerPrinting
  27.            //string code = tools.httpfinger("http://www.petardas.com/index.php");
  28.  
  29.            // Read File
  30.            //string code = tools.openword("C:/test.txt");
  31.  
  32.            // Write File
  33.            //tools.savefile("test.txt","yeah");
  34.  
  35.            // GET OS
  36.            //string code = tools.getos();
  37.  
  38.            /* Remove duplicates from a List
  39.            
  40.             List<string> arrays = new List<string> { "test", "test", "test", "bye", "bye" };
  41.  
  42.             List<string> limpio = tools.repes(arrays);
  43.  
  44.             foreach (string text in limpio)
  45.             {
  46.                 richTextBox1.AppendText(text + Environment.NewLine);
  47.             }
  48.            
  49.             */
  50.  
  51.            /* Cut urls from a List
  52.            
  53.             List<string> lista = new List<string> { "http://localhost1/sql.php?id=adsasdsadsa", "http://localhost2/sql.php?id=adsasdsadsa",
  54.             "http://localhost3/sql.php?id=adsasdsadsa"};
  55.  
  56.             List<string> cortar = tools.cortar(lista);
  57.                            
  58.             foreach (string test in cortar)
  59.             {
  60.                 richTextBox1.AppendText(test + Environment.NewLine);
  61.             }
  62.            
  63.             */
  64.  
  65.            // Download File
  66.            //string code = tools.download("http://localhost/backdoor.exe", "backdoor.exe");
  67.  
  68.            // Upload File
  69.            //string code = tools.upload("http://localhost/uploads/upload.php", "c:/test.txt");
  70.  
  71.            // Get Basename from a path
  72.            //string code = tools.basename("c:/dsaaads/test.txt");
  73.  
  74.            // Execute commands
  75.            //string code = tools.console("net user");
  76.  
  77.            // URI Split
  78.            // Options : host,port,path,file,query
  79.            //string code = tools.urisplit("http://localhost/dsadsadsa/sql.php?id=dsadasd","host");
  80.  
  81.            // MD5 Hash Generator
  82.            //string code = convertir_md5("123");
  83.  
  84.            // Get MD5 of file
  85.            //string code = tools.md5file("c:/test.txt");
  86.  
  87.            // Get IP address from host name
  88.            //string code = tools.getip("www.petardas.com");
  89.  
  90.        }
  91.    }
  92. }
  93.  


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines