Merge pull request #370 from StefanAlexandruBogdan/master

Add support for using ShellInABox with a custom port in SSH service.
This commit is contained in:
Luka Krajger 2016-05-04 06:30:26 -04:00
commit 0f1e9ba31c

View file

@ -121,19 +121,28 @@ void initService(struct Service *service, const char *arg) {
service->group = NULL; service->group = NULL;
check(service->cwd = strdup("/")); check(service->cwd = strdup("/"));
char *host; char *host;
char *sshPort;
check(host = strdup("localhost")); check(host = strdup("localhost"));
check(sshPort = strdup("22"));
if ((ptr = strchr(arg, ':')) != NULL) { if ((ptr = strchr(arg, ':')) != NULL) {
check(ptr = strdup(ptr + 1)); ptr = ptr + 1;
char *end; if (*ptr) {
if ((end = strchr(ptr, ':')) != NULL) { char * tmp = strchr(ptr, ':');
*end = '\000'; if(tmp == NULL)//if the second ":" is not found, keep as host whatever is after first ":"
} {
if (*ptr) { free(host);
free(host); host = strdup(ptr);
host = ptr; }
} else { else // if we find a second ":", keep as a host whatever is in between first ":" and second ":" and as sshPort whatever is after second ":"
free(ptr); {
} int size = (tmp - ptr + 1);
free(host);
host = malloc(size);
memset(host, 0, size);
memcpy(host, ptr , size-1);
sshPort = strdup (tmp + 1);
}
}
} }
// Don't allow manipulation of the SSH command line through "creative" use // Don't allow manipulation of the SSH command line through "creative" use
@ -148,6 +157,14 @@ void initService(struct Service *service, const char *arg) {
} }
} }
// Don't allow manipulation of the SSH command line through "creative" use
// of the port.
for (char *h = sshPort; *h; h++) {
char ch = *h;
if (!(ch >= '0' && ch <= '9')) {
fatal("[config] Invalid port \"%s\" in service definition!", sshPort);
}
}
service->cmdline = stringPrintf(NULL, service->cmdline = stringPrintf(NULL,
"ssh -a -e none -i /dev/null -x -oChallengeResponseAuthentication=no " "ssh -a -e none -i /dev/null -x -oChallengeResponseAuthentication=no "
"-oCheckHostIP=no -oClearAllForwardings=yes -oCompression=no " "-oCheckHostIP=no -oClearAllForwardings=yes -oCompression=no "
@ -162,8 +179,9 @@ void initService(struct Service *service, const char *arg) {
// feature, we cannot be sure that it is available on the // feature, we cannot be sure that it is available on the
// target server. Removing it for the sake of Centos. // target server. Removing it for the sake of Centos.
// "-oVisualHostKey=no" // "-oVisualHostKey=no"
" -oLogLevel=FATAL %%s@%s", host); " -oLogLevel=FATAL -p%s %%s@%s",sshPort, host);
free(host); free(host);
free(sshPort);
} else { } else {
service->useLogin = 0; service->useLogin = 0;