0

It sounds a little strange,doesn't it? I am working with a project - https://github.com/sherlock-project/sherlock I need to run this program using Java Process API.

Here is that program usage.

$ python3 sherlock.py --help
usage: sherlock.py [-h] [--version] [--verbose] [--rank]
               [--folderoutput FOLDEROUTPUT] [--output OUTPUT] [--tor]
               [--unique-tor] [--csv] [--site SITE_NAME]
               [--proxy PROXY_URL] [--json JSON_FILE]
               [--proxy_list PROXY_LIST] [--check_proxies CHECK_PROXY]
               [--timeout TIMEOUT] [--print-found]
               USERNAMES [USERNAMES ...]

I have a problem in using USERNAMES. When I specify a username that has a white space, from command line it works well(The white space is interpreted well). Pay attention for the property - checking username .

// command to be executed
python3 ${SHERLOCK_HOME}/sherlock.py --print-found --timeout 10 "skoriy serhii"

[*] Checking username skoriy serhii on:
[+] 500px: https://500px.com/skoriy serhii
[-] Error Connecting: Aptoide
[-] Error Connecting: Basecamp
[+] CapFriendly: https://www.capfriendly.com/users/skoriy serhii

But,when I am using Java Process API , I get the following:

// command to be executed
python3 /home/gorilla/sherlock/sherlock.py --print-found --timeout 10 "skoriy serhii" 

[*] Checking username "skoriy on:
[+] 500px: https://500px.com/"skoriy
[-] Error Connecting: Aptoide
[-] Error Connecting: Basecamp
[+] Bookcrossing: https://www.bookcrossing.com/mybookshelf/"skoriy/
[+] CapFriendly: https://www.capfriendly.com/users/"skoriy
[-] Error Connecting: Carbonmade
[+] CashMe: https://cash.me/$"skoriy
[+] Chatujme.cz: https://profil.chatujme.cz/"skoriy
[+] Cloob: https://www.cloob.com/name/"skoriy
[-] Error Connecting: Crevado

As you can see there is some troubles with interpretation of the username argument. Here is java code.

public class Main {

public static void main(String[] args) {
    try {
        CommandBuilder commandBuilder = new CommandBuilder();
        String command = commandBuilder.user("skoriy serhii").build();
        System.out.println(command);
        Process process = Runtime.getRuntime().exec(command);
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = null;
        while ((line = reader.readLine()) != null)
            System.out.println(line);
        process.destroy();
        if (process.isAlive())
            process.destroyForcibly();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

//CommandBuilder.java
public class CommandBuilder {

private final static String BASE = "python3 /home/gorilla/sherlock/sherlock.py --print-found --timeout 10";
private StringBuffer buffer = new StringBuffer();

public CommandBuilder user(String user) {
    buffer.append(" \"" + user + "\" ");
    return this;
}

public String build() {
    return BASE + new String(buffer);
}

}

skoriy
  • 186
  • 10
  • Use `ProcessBuilder` unless you're nostalgic for legacy APIs (and creating your own non-working CommandBuilders). – Kayaman Jan 18 '20 at 15:42
  • @Kayaman , roger it – skoriy Jan 18 '20 at 16:24
  • @Kayaman: also `ProcessBuilder` has many improved features, for this case the other overload `Runtime.exec(String[])` would work. It is only the tokenization done by `exec(String)` that is almost totally unlike a shell. – dave_thompson_085 Jan 19 '20 at 00:38

0 Answers0