Skip to content

Add switch to specify XMPP-Domain #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions sslscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ struct sslCheckOptions
int starttls_pop3;
int starttls_smtp;
int starttls_xmpp;
char *xmpp_domain;
int socket_timeout;
int sslVersion;
int targets;
int pout;
Expand Down Expand Up @@ -270,6 +272,7 @@ int tcpConnect(struct sslCheckOptions *options)
int tlsStarted = 0;
char buffer[BUFFERSIZE];
int status;
struct timeval timeout;

// Create Socket
socketDescriptor = socket(AF_INET, SOCK_STREAM, 0);
Expand All @@ -279,6 +282,19 @@ int tcpConnect(struct sslCheckOptions *options)
return 0;
}

// set socket timeout
if (options->socket_timeout > 0) {
timeout.tv_sec = options->socket_timeout;
timeout.tv_usec = 0;

if (setsockopt (socketDescriptor, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
printf("%s WARNING: Unable to set receive timeout.%s\n", COL_RED, RESET);
}
if (setsockopt (socketDescriptor, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
printf("%s WARNING: Unable to set receive timeout.%s\n", COL_RED, RESET);
}
}

// Connect
status = connect(socketDescriptor, (struct sockaddr *) &options->serverAddress, sizeof(options->serverAddress));
if(status < 0)
Expand Down Expand Up @@ -326,16 +342,16 @@ int tcpConnect(struct sslCheckOptions *options)

/* This is so ghetto, you cannot release it! */
char xmpp_setup[1024]; // options->host is 512 bytes long
/* XXX: TODO - options->host isn't always the host you want to test
eg:
talk.google.com actually expects gmail.com, not talk.google.com
jabber.ccc.de expects jabber.ccc.de

It may be useful to provide a commandline switch to provide the
expected hostname.
*/
char xmpp_to[512];
// use hostname if not defined explicitly
if( options->xmpp_domain == 0) {
strncpy(xmpp_to, options->host, sizeof(xmpp_to));
} else {
strncpy(xmpp_to, options->xmpp_domain, sizeof(xmpp_to));
}

if (snprintf(xmpp_setup, sizeof(xmpp_setup), "<?xml version='1.0' ?>\r\n"
"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='%s' version='1.0'>\r\n", options->host) >= sizeof(xmpp_setup)) {
"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='%s' version='1.0'>\r\n", xmpp_to) >= sizeof(xmpp_setup)) {
printf("(internal error: xmpp_setup buffer too small)\n");
abort();
}
Expand Down Expand Up @@ -1933,6 +1949,11 @@ int main(int argc, char *argv[])
options.sslVersion = tls_v1;
options.starttls_xmpp = true;
}
// XMPP... Domain
else if (strncmp("--xmpp-domain=", argv[argLoop], 14) == 0)
{
options.xmpp_domain = argv[argLoop] +14;
}

// SSL v2 only...
else if (strcmp("--ssl2", argv[argLoop]) == 0)
Expand All @@ -1954,6 +1975,12 @@ int main(int argc, char *argv[])
else if (strcmp("--http", argv[argLoop]) == 0)
options.http = 1;

// Socket Timeout
else if ((strncmp("--timeout=", argv[argLoop], 10) == 0) && (strlen(argv[argLoop]) > 10))
{
options.socket_timeout = atoi(argv[argLoop] + 10);
}

// Host (maybe port too)...
else if (argLoop + 1 == argc)
{
Expand Down Expand Up @@ -2048,10 +2075,12 @@ int main(int argc, char *argv[])
printf(" %s--starttls-pop3%s STARTTLS setup for POP3\n", COL_GREEN, RESET);
printf(" %s--starttls-smtp%s STARTTLS setup for SMTP\n", COL_GREEN, RESET);
printf(" %s--starttls-xmpp%s STARTTLS setup for XMPP\n", COL_GREEN, RESET);
printf(" %s--xmpp-domain=<domain>%s Specify this if the XMPP domain is different from the hostname\n", COL_GREEN, RESET);
printf(" %s--http%s Test a HTTP connection.\n", COL_GREEN, RESET);
printf(" %s--bugs%s Enable SSL implementation bug work-\n", COL_GREEN, RESET);
printf(" arounds.\n");
printf(" %s--xml=<file>%s Output results to an XML file.\n", COL_GREEN, RESET);
printf(" %s--timeout=<seconds>%s Set timeout in seconds.\n", COL_GREEN, RESET);
printf(" %s--version%s Display the program version.\n", COL_GREEN, RESET);
printf(" %s--verbose%s Display verbose output.\n", COL_GREEN, RESET);
printf(" %s--help%s Display the help text you are now\n", COL_GREEN, RESET);
Expand Down