You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "dgü (Jira)" <ji...@apache.org> on 2023/01/10 11:03:00 UTC
[jira] [Commented] (SSHD-1317) Finding default shell and its escape, quote characters
[ https://issues.apache.org/jira/browse/SSHD-1317?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17656582#comment-17656582 ]
dgü commented on SSHD-1317:
---------------------------
Hello!
Using _echo_ command may be useful if shell builtin _echo_ takes precedence over {_}/bin/echo{_},etc. or they work same.
This may be a pseudo code to find escape character:
{code:java}
char escapeChar;
String commandOutput = execute("echo ^^``\\\\");
switch (commandOutput) {
case "^``\\\\" : //for CMD
escapeChar = '^';
break;
case "^^`\\\\" : //for PowerShell
escapeChar = '`';
break;
case "^^``\\" : //for sh
escapeChar = '\\';
break;
default : //not found
escapeChar = 0;
break;
}
After escape character found, quote character can be found too.
This may be a pseudo code to find quote character:
boolean isQuoteChar(char pQuoteChar, char pEscapeChar} {
String escapeString =
String.valueOf(pEscapeChar)+String.valueOf(pEscapeChar);
String commandOutput = execute("echo " +
pQuoteChar+escapeString+pQuoteChar);
if (commandOutput.contains(escapeString)) {
// escape chracter is preserved.
return true;
} else {
// escape chracter is not preserved.
return false;
}
}
{code}
I'm not a shell expert. If you see an error, please let me know.
Thanks!
> Finding default shell and its escape, quote characters
> ------------------------------------------------------
>
> Key: SSHD-1317
> URL: https://issues.apache.org/jira/browse/SSHD-1317
> Project: MINA SSHD
> Issue Type: Question
> Reporter: dgü
> Priority: Major
>
> Hello!
> I execute remote commands by exec channel. Arguments of the commands may include shell ({_}sh{_},{_}cmd{_},...) special characters(ie: _^_ for {_}cmd{_}). These special characters may work different on different shells. So, I must escape or quote them.
> is it possible to find the followings by SSHD ?
> * Default shell of SSH server
> * Escape character of shell
> * Quote character of shell
> Thanks in advance!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org