简体   繁体   English

使用Java ProcessBuilder在会话期间将参数传递给开膛手约翰

[英]Passing arguments to John the Ripper during session using Java ProcessBuilder

i am trying to run John the Ripper with the Java ProcessBuilder. 我正在尝试使用Java ProcessBuilder运行开膛手约翰。 Everything is working so far. 到目前为止,一切正常。

My problem is regarding the John the Ripper Status information. 我的问题是关于开膛手约翰的状态信息。 While a cracking session is running in a Bash, you can press any key to display status information like this one: 在Bash中运行破解会话时,您可以按任意键以显示如下状态信息:

guesses: 0 time: 51:06:37:19 0.00% (3) c/s: 4466 trying: shs1geO - shs1god 猜测:0时间:51:06:37:19 0.00%(3)c / s:4466尝试:shs1geO-shs1god

What i am not able to achieve is to pass the "any key" to the Process during execution so that status line is returned. 我无法实现的是在执行过程中将“任何键”传递给流程,以便返回状态行。

I have tried the BufferedWriter and passed all kinds of Strings, line separators and backslash n. 我已经尝试过BufferedWriter并传递了各种字符串,行分隔符和反斜杠n。 Nothing has worked so far, my write(x) just gets ignored. 到目前为止没有任何工作,我的write(x)只是被忽略了。 The process terminates normally and returns the normal process output. 该过程正常终止并返回正常过程输出。

Here is some code to illustrate: 这是一些代码说明:

        long lastStatusTime = System.nanoTime();
        long interval = 5 * 1000L * 1000 * 1000;
        int counter = 0;

        while(!(proM.isComplete())){
            if((lastStatusTime + interval) <= System.nanoTime()){
                bw.write("q");
                bw.flush();

                line = br.readLine();
                System.out.println(line);
                lastStatusTime = System.nanoTime();

            }
        }

        //Proc output
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

the first while is executed as long as the process didnt finish and writes the "q" (or any key other key) to the BufferedWriter every 5 seconds (or at least it is supposed to). 只要进程没有完成就执行第一个while,并且每5秒(或者至少应该这样做)将“ q”(或任何其他键)写入BufferedWriter。

When the Process is terminated the while stops and the second while captures the normal process output. 当进程终止时,while停止,第二while捕获正常的进程输出。

Unfortunately the write is completely ignored and the readLine inside the if-statement blocks until the first Line of the normal termination output is received. 不幸的是,写入操作被完全忽略,并且if语句中的readLine块被阻止,直到接收到正常终止输出的第一行为止。

Building of the BufferedWriter: BufferedWriter的构建:

        OutputStream os = process.getOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(os);
        BufferedWriter bw = new BufferedWriter(osw);

Is anyone able to help resolve this issue? 有谁能够帮助解决此问题? i am trying for hours 我正在努力几个小时

Thanks in advance for any help 预先感谢您的任何帮助

You don't show us how you construct your BufferedWriter. 您没有向我们展示如何构造BufferedWriter。 When you create your Process, are you getting the Streams associated with the process, ie, the InputStream, OutputStream and ErrorStreams? 创建流程时,您是否正在获得与流程关联的流,即InputStream,OutputStream和ErrorStreams? You should, and then you should try to send a new line char to the OutputStream. 您应该,然后应该尝试将新行char发送到OutputStream。

Myself, I'd wrap the OutputStream in a PrintStream, and simply call println() on it. 我自己,将OutputStream包装在PrintStream中,然后简单地对其调用println()


Edit 编辑
Note that I am not familiar with the program that you are trying to control. 请注意,我不熟悉您要控制的程序。 If it is not a console program, then writing to the OutputStream will not help. 如果不是控制台程序,则写入OutputStream将无济于事。 Instead you would need to send key strokes to the game's window, perhaps via the Robot class. 相反,您可能需要通过Robot类将击键发送到游戏窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM