In my java class I am running following command for establishing a network connection to server like:
Process process = runtime.exec("net use \"\\\\External\path\download.zip\" password /user:username");
Above, password and username are accepted from user.
As, above process runs with system privileges attacked can use command separators (&, &&, ;, ||, () etc.) and execute multiple commands in above single statements.
I went though this which majorly tasks about changing privileges of the executing command and white listing or black listing user input.
Now, my problem is username and password both can contain any combination of charters, so I can not black list (&, &&, ;, ||, () etc.) and runtime.exec runs in system mode so I am not able to come to a solution.
I have already thought of using ProcessBuilder but runtime.exec calls same code after fragmenting command on spaces. So, this is not of any help.
Also, I do not want to introduce 3rd party library to solve this issue but if that is the only solution then I have to accept it.
If I can remove usage of runtime.exec for establishing network connection then it would be great.