Skip to content

Commit

Permalink
Changed index() to strchr()
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmacorz committed May 12, 2021
1 parent d6a42ac commit c81f0b9
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 47 deletions.
20 changes: 10 additions & 10 deletions hydra-http-form.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,17 @@ char *html_encode(char *string) {
if (ret == NULL)
return NULL;

if (index(ret, '%') != NULL)
if (strchr(ret, '%') != NULL)
ret = hydra_strrep(ret, "%", "%25");
if (index(ret, ' ') != NULL)
if (strchr(ret, ' ') != NULL)
ret = hydra_strrep(ret, " ", "%20");
if (index(ret, '&') != NULL)
if (strchr(ret, '&') != NULL)
ret = hydra_strrep(ret, "&", "%26");
if (index(ret, '#') != NULL)
if (strchr(ret, '#') != NULL)
ret = hydra_strrep(ret, "#", "%23");
if (index(ret, '=') != NULL)
if (strchr(ret, '=') != NULL)
ret = hydra_strrep(ret, "=", "%3D");
if (index(ret, '+') != NULL)
if (strchr(ret, '+') != NULL)
ret = hydra_strrep(ret, "+", "%2B");

return ret;
Expand Down Expand Up @@ -646,10 +646,10 @@ int32_t analyze_server_response(int32_t s) {
} else if (endcookie2 != NULL)
*endcookie2 = 0;
// is the cookie already there? if yes, remove it!
if (index(startcookie, '=') != NULL && (ptr = index(startcookie, '=')) - startcookie + 1 <= sizeof(tmpname)) {
if (strchr(startcookie, '=') != NULL && (ptr = strchr(startcookie, '=')) - startcookie + 1 <= sizeof(tmpname)) {
strncpy(tmpname, startcookie, sizeof(tmpname) - 2);
tmpname[sizeof(tmpname) - 2] = 0;
ptr = index(tmpname, '=');
ptr = strchr(tmpname, '=');
*(++ptr) = 0;
// is the cookie already in the cookiejar? (so, does it have to be
// replaced?)
Expand All @@ -675,7 +675,7 @@ int32_t analyze_server_response(int32_t s) {
strcpy(cookie, tmpcookie);
}
}
ptr = index(str, '=');
ptr = strchr(str, '=');
// only copy the cookie if it has a value (otherwise the server wants to
// delete the cookie)
if (ptr != NULL && *(ptr + 1) != ';' && *(ptr + 1) != 0 && *(ptr + 1) != '\n' && *(ptr + 1) != '\r') {
Expand Down Expand Up @@ -1286,7 +1286,7 @@ ptr_header_node initialize(char *ip, unsigned char options, char *miscptr) {

cond = ptr;

if ((ptr2 = index(ptr, ':')) != NULL) {
if ((ptr2 = strchr(ptr, ':')) != NULL) {
*ptr2++ = 0;
if (*ptr2)
optional1 = ptr2;
Expand Down
12 changes: 6 additions & 6 deletions hydra-http-proxy-urlenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ int32_t start_http_proxy_urlenum(int32_t s, char *ip, int32_t port, unsigned cha
ptr++;
strncpy(mhost, ptr, sizeof(mhost) - 1);
mhost[sizeof(mhost) - 1] = 0;
if ((ptr = index(mhost, '/')) != NULL)
if ((ptr = strchr(mhost, '/')) != NULL)
*ptr = 0;
if ((ptr = index(mhost, ']')) != NULL)
if ((ptr = strchr(mhost, ']')) != NULL)
*ptr = 0;
else if ((ptr = index(mhost, ':')) != NULL)
else if ((ptr = strchr(mhost, ':')) != NULL)
*ptr = 0;

if (miscptr != NULL && index(miscptr, ':') != NULL) {
if (miscptr != NULL && strchr(miscptr, ':') != NULL) {
strncpy(mlogin, miscptr, sizeof(mlogin) - 1);
mlogin[sizeof(mlogin) - 1] = 0;
ptr = index(mlogin, ':');
ptr = strchr(mlogin, ':');
*ptr++ = 0;
strncpy(mpass, ptr, sizeof(mpass) - 1);
mpass[sizeof(mpass) - 1] = 0;
Expand Down Expand Up @@ -215,7 +215,7 @@ int32_t start_http_proxy_urlenum(int32_t s, char *ip, int32_t port, unsigned cha
}
}
// result analysis
ptr = ((char *)index(buf, ' ')) + 1;
ptr = ((char *)strchr(buf, ' ')) + 1;
if (*ptr == '2' || (*ptr == '3' && (*(ptr + 2) == '1' || *(ptr + 2) == '2')) || strncmp(ptr, "404", 4) == 0 || strncmp(ptr, "403", 4) == 0) {
hydra_report_found_host(port, ip, "http-proxy", fp);
if (fp != stdout)
Expand Down
8 changes: 4 additions & 4 deletions hydra-http-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ int32_t start_http_proxy(int32_t s, char *ip, int32_t port, unsigned char option
sprintf(url, "%.500s", miscptr);
ptr = strstr(miscptr, "://"); // :// check is in hydra.c
sprintf(host, "Host: %.50s", ptr + 3);
if ((ptr = index(host, '/')) != NULL)
if ((ptr = strchr(host, '/')) != NULL)
*ptr = 0;
if ((ptr = index(host + 6, ':')) != NULL && host[0] != '[')
if ((ptr = strchr(host + 6, ':')) != NULL && host[0] != '[')
*ptr = 0;
strcat(host, "\r\n");
}
Expand Down Expand Up @@ -232,15 +232,15 @@ int32_t start_http_proxy(int32_t s, char *ip, int32_t port, unsigned char option
}
}

ptr = ((char *)index(http_proxy_buf, ' ')) + 1;
ptr = ((char *)strchr(http_proxy_buf, ' ')) + 1;
if (*ptr == '2' || (*ptr == '3' && *(ptr + 2) == '1') || (*ptr == '3' && *(ptr + 2) == '2') || (*ptr == '4' && *(ptr + 2) == '4')) {
hydra_report_found_host(port, ip, "http-proxy", fp);
hydra_completed_pair_found();
free(http_proxy_buf);
http_proxy_buf = NULL;
} else {
if (*ptr != '4')
hydra_report(stderr, "[INFO] Unusual return code: %c for %s:%s\n", (char)*(index(http_proxy_buf, ' ') + 1), login, pass);
hydra_report(stderr, "[INFO] Unusual return code: %c for %s:%s\n", (char)*(strchr(http_proxy_buf, ' ') + 1), login, pass);
else if (verbose && *(ptr + 2) == '3')
hydra_report(stderr, "[INFO] Potential success, could be false positive: %s:%s\n", login, pass);
hydra_completed_pair();
Expand Down
4 changes: 2 additions & 2 deletions hydra-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int32_t start_http(int32_t s, char *ip, int32_t port, unsigned char options, cha
complete_line = 0;
tmpreplybuf[0] = 0;

while (http_buf != NULL && (strstr(http_buf, "HTTP/1.") == NULL || (index(http_buf, '\n') == NULL && complete_line == 0))) {
while (http_buf != NULL && (strstr(http_buf, "HTTP/1.") == NULL || (strchr(http_buf, '\n') == NULL && complete_line == 0))) {
if (debug)
printf("il: %d, tmpreplybuf: %s, http_buf: %s\n", complete_line, tmpreplybuf, http_buf);
if (tmpreplybuf[0] == 0 && strstr(http_buf, "HTTP/1.") != NULL) {
Expand Down Expand Up @@ -245,7 +245,7 @@ int32_t start_http(int32_t s, char *ip, int32_t port, unsigned char options, cha
if (debug)
hydra_report(stderr, "S:%s\n", http_buf);

ptr = ((char *)index(http_buf, ' '));
ptr = ((char *)strchr(http_buf, ' '));
if (ptr != NULL)
ptr++;
if (ptr != NULL && (*ptr == '2' || *ptr == '3' || strncmp(ptr, "403", 3) == 0 || strncmp(ptr, "404", 3) == 0)) {
Expand Down
4 changes: 2 additions & 2 deletions hydra-mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ int32_t internal__hydra_connect(char *host, int32_t port, int32_t type, int32_t

send(s, buf, strlen(buf), 0);
if (debug) {
char *ptr = index(buf, '\r');
char *ptr = strchr(buf, '\r');
if (ptr != NULL)
*ptr = 0;
printf("DEBUG_CONNECT_PROXY_SENT: %s\n", buf);
}
recv(s, buf, 4096, 0);
if (strncmp("HTTP/", buf, 5) == 0 && (tmpptr = index(buf, ' ')) != NULL && *++tmpptr == '2') {
if (strncmp("HTTP/", buf, 5) == 0 && (tmpptr = strchr(buf, ' ')) != NULL && *++tmpptr == '2') {
if (debug)
printf("DEBUG_CONNECT_PROXY_OK\n");
} else {
Expand Down
4 changes: 2 additions & 2 deletions hydra-telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int32_t start_telnet(int32_t s, char *ip, int32_t port, unsigned char options, c
if ((buf = hydra_receive_line(s)) == NULL)
return 1;

if (index(buf, '/') != NULL || index(buf, '>') != NULL || index(buf, '%') != NULL || index(buf, '$') != NULL || index(buf, '#') != NULL) {
if (strchr(buf, '/') != NULL || strchr(buf, '>') != NULL || strchr(buf, '%') != NULL || strchr(buf, '$') != NULL || strchr(buf, '#') != NULL) {
hydra_report_found_host(port, ip, "telnet", fp);
hydra_completed_pair_found();
free(buf);
Expand Down Expand Up @@ -76,7 +76,7 @@ int32_t start_telnet(int32_t s, char *ip, int32_t port, unsigned char options, c

/*win7 answering with do terminal type = 0xfd 0x18 */
while ((buf = hydra_receive_line(s)) != NULL && make_to_lower(buf) && (strstr(buf, "login:") == NULL || strstr(buf, "last login:") != NULL) && strstr(buf, "sername:") == NULL) {
if ((miscptr != NULL && strstr(buf, miscptr) != NULL) || (miscptr == NULL && strstr(buf, "invalid") == NULL && strstr(buf, "failed") == NULL && strstr(buf, "bad ") == NULL && (index(buf, '/') != NULL || index(buf, '>') != NULL || index(buf, '$') != NULL || index(buf, '#') != NULL || index(buf, '%') != NULL || ((buf[1] == '\xfd') && (buf[2] == '\x18'))))) {
if ((miscptr != NULL && strstr(buf, miscptr) != NULL) || (miscptr == NULL && strstr(buf, "invalid") == NULL && strstr(buf, "failed") == NULL && strstr(buf, "bad ") == NULL && (strchr(buf, '/') != NULL || strchr(buf, '>') != NULL || strchr(buf, '$') != NULL || strchr(buf, '#') != NULL || strchr(buf, '%') != NULL || ((buf[1] == '\xfd') && (buf[2] == '\x18'))))) {
hydra_report_found_host(port, ip, "telnet", fp);
hydra_completed_pair_found();
free(buf);
Expand Down
42 changes: 21 additions & 21 deletions hydra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ void fill_mem(char *ptr, FILE *fd, int32_t colonmode) {
tmp[len] = 0;
}
if (colonmode) {
if ((ptr2 = index(tmp, ':')) == NULL) {
if ((ptr2 = strchr(tmp, ':')) == NULL) {
fprintf(stderr,
"[ERROR] invalid line in colon file (-C), missing colon "
"in line: %s\n",
Expand Down Expand Up @@ -1494,7 +1494,7 @@ void hydra_increase_fail_count(int32_t target_no, int32_t head_no) {
fprintf(stderr,
"[ERROR] Too many connect errors to target, disabling "
"%s://%s%s%s:%d\n",
hydra_options.service, hydra_targets[target_no]->ip[0] == 16 && index(hydra_targets[target_no]->target, ':') != NULL ? "[" : "", hydra_targets[target_no]->target, hydra_targets[target_no]->ip[0] == 16 && index(hydra_targets[target_no]->target, ':') != NULL ? "]" : "", hydra_targets[target_no]->port);
hydra_options.service, hydra_targets[target_no]->ip[0] == 16 && strchr(hydra_targets[target_no]->target, ':') != NULL ? "[" : "", hydra_targets[target_no]->target, hydra_targets[target_no]->ip[0] == 16 && strchr(hydra_targets[target_no]->target, ':') != NULL ? "]" : "", hydra_targets[target_no]->port);
}
if (hydra_brains.targets > hydra_brains.finished)
hydra_kill_head(head_no, 1, 0);
Expand Down Expand Up @@ -2047,26 +2047,26 @@ void process_proxy_line(int32_t type, char *string) {
}
*sep = 0;
target_string = sep + 3;
if ((sep = index(target_string, '@')) != NULL) {
if ((sep = strchr(target_string, '@')) != NULL) {
auth_string = target_string;
*sep = 0;
target_string = sep + 1;
if (index(auth_string, ':') == NULL) {
if (strchr(auth_string, ':') == NULL) {
fprintf(stderr,
"[WARNING] %s has an invalid authentication definition %s, must "
"be in the format login:pass, entry ignored\n",
target_string, auth_string);
return;
}
}
if ((sep = index(target_string, ':')) != NULL) {
if ((sep = strchr(target_string, ':')) != NULL) {
*sep = 0;
port_string = sep + 1;
if ((sep = index(port_string, '%')) != NULL) {
if ((sep = strchr(port_string, '%')) != NULL) {
*sep = 0;
device_string = sep + 1;
}
if ((sep = index(port_string, '/')) != NULL)
if ((sep = strchr(port_string, '/')) != NULL)
*sep = 0;
port = atoi(port_string);
if (port < 1 || port > 65535) {
Expand Down Expand Up @@ -2595,23 +2595,23 @@ int main(int argc, char *argv[]) {

if (*target_pos == '[') {
target_pos++;
if ((param_pos = index(target_pos, ']')) == NULL)
if ((param_pos = strchr(target_pos, ']')) == NULL)
bail("no closing ']' found in target definition");
*param_pos++ = 0;
if (*param_pos == ':')
port_pos = ++param_pos;
if ((param_pos = index(param_pos, '/')) != NULL)
if ((param_pos = strchr(param_pos, '/')) != NULL)
*param_pos++ = 0;
} else {
port_pos = index(target_pos, ':');
param_pos = index(target_pos, '/');
port_pos = strchr(target_pos, ':');
param_pos = strchr(target_pos, '/');
if (port_pos != NULL && param_pos != NULL && port_pos > param_pos)
port_pos = NULL;
if (port_pos != NULL)
*port_pos++ = 0;
if (param_pos != NULL)
*param_pos++ = 0;
if (port_pos != NULL && index(port_pos, ':') != NULL) {
if (port_pos != NULL && strchr(port_pos, ':') != NULL) {
if (prefer_ipv6)
bail("Illegal IPv6 target definition must be written within '[' "
"']'");
Expand Down Expand Up @@ -2894,7 +2894,7 @@ int main(int argc, char *argv[]) {
"like parallel connections)\n");
hydra_options.tasks = 1;
}
if (hydra_options.login != NULL && (index(hydra_options.login, '\\') != NULL || index(hydra_options.login, '/') != NULL))
if (hydra_options.login != NULL && (strchr(hydra_options.login, '\\') != NULL || strchr(hydra_options.login, '/') != NULL))
fprintf(stderr, "[WARNING] potential windows domain specification found in "
"login. You must use the -m option to pass a domain.\n");
i = 1;
Expand All @@ -2918,7 +2918,7 @@ int main(int argc, char *argv[]) {
#if !defined(LIBSMBCLIENT)
bail("Compiled without LIBSMBCLIENT support, module not available!");
#else
if (hydra_options.login != NULL && (index(hydra_options.login, '\\') != NULL || index(hydra_options.login, '/') != NULL))
if (hydra_options.login != NULL && (strchr(hydra_options.login, '\\') != NULL || strchr(hydra_options.login, '/') != NULL))
fprintf(stderr, "[WARNING] potential windows domain specification found in "
"login. You must use the -m option to pass a domain.\n");
if (hydra_options.miscptr == NULL || (strlen(hydra_options.miscptr) == 0)) {
Expand Down Expand Up @@ -3571,13 +3571,13 @@ int main(int argc, char *argv[]) {
if (*tmpptr == '[') {
tmpptr++;
hydra_targets[i]->target = tmpptr;
if ((tmpptr2 = index(tmpptr, ']')) != NULL) {
if ((tmpptr2 = strchr(tmpptr, ']')) != NULL) {
*tmpptr2++ = 0;
tmpptr = tmpptr2;
}
} else
hydra_targets[i]->target = tmpptr;
if ((tmpptr2 = index(hydra_targets[i]->target, ':')) != NULL) {
if ((tmpptr2 = strchr(hydra_targets[i]->target, ':')) != NULL) {
*tmpptr2++ = 0;
tmpptr = tmpptr2;
hydra_targets[i]->port = atoi(tmpptr2);
Expand All @@ -3593,13 +3593,13 @@ int main(int argc, char *argv[]) {
} else if (hydra_options.server == NULL) {
fprintf(stderr, "Error: no target server given, nor -M option used\n");
exit(-1);
} else if (index(hydra_options.server, '/') != NULL) {
} else if (strchr(hydra_options.server, '/') != NULL) {
if (cmdlinetarget == NULL)
bail("You seem to mix up \"service://target:port/options\" syntax with "
"\"target service options\" syntax. Read the README on how to use "
"hydra correctly!");
if (strstr(cmdlinetarget, "://") != NULL) {
tmpptr = index(hydra_options.server, '/');
tmpptr = strchr(hydra_options.server, '/');
if (tmpptr != NULL)
*tmpptr = 0;
countservers = hydra_brains.targets = 1;
Expand All @@ -3622,7 +3622,7 @@ int main(int argc, char *argv[]) {
exit(-1);
}
strcpy(tmpptr, hydra_options.server);
tmpptr2 = index(tmpptr, '/');
tmpptr2 = strchr(tmpptr, '/');
*tmpptr2++ = 0;
if ((k = atoi(tmpptr2)) < 16 || k > 31) {
fprintf(stderr, "Error: network size may only be between /16 and /31: %s\n", hydra_options.server);
Expand Down Expand Up @@ -3788,7 +3788,7 @@ int main(int argc, char *argv[]) {
printf(" per task\n");

if (hydra_brains.targets == 1) {
if (index(hydra_targets[0]->target, ':') == NULL) {
if (strchr(hydra_targets[0]->target, ':') == NULL) {
printf("[DATA] attacking %s%s://%s:", hydra_options.service, hydra_options.ssl == 1 ? "s" : "", hydra_targets[0]->target);
printf("%d%s%s\n", port, hydra_options.miscptr == NULL || hydra_options.miscptr[0] != '/' ? "/" : "", hydra_options.miscptr != NULL ? hydra_options.miscptr : "");
} else {
Expand Down Expand Up @@ -3864,7 +3864,7 @@ int main(int argc, char *argv[]) {
#ifdef AF_INET6
ipv6 = NULL;
#endif
if ((device = index(hydra_targets[i]->target, '%')) != NULL)
if ((device = strchr(hydra_targets[i]->target, '%')) != NULL)
*device++ = 0;
if (getaddrinfo(hydra_targets[i]->target, NULL, &hints, &res) != 0) {
if (use_proxy == 0) {
Expand Down

0 comments on commit c81f0b9

Please sign in to comment.