mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 15:59:41 +08:00
socks: a host name with control bytes or spaces is refused where it is read
This commit is contained in:
1 parent
f105a27e68
commit
4f4862e2c1
4 files changed
+19
No files matched your search
@@ -569,11 +569,26 @@ int parsehost(int family, unsigned char *host, struct sockaddr *sa){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A host name is written into the request lines of parent protocols and
|
||||||
|
matched against rules, so a control byte or a space in it could end a
|
||||||
|
line early or pose as another destination. A name carrying one is
|
||||||
|
refused where it is read, and every name a client sends is read on
|
||||||
|
its way to the field. */
|
||||||
|
int badhostname(const char *hostname){
|
||||||
|
const unsigned char *c;
|
||||||
|
|
||||||
|
if(!hostname) return 1;
|
||||||
|
for(c = (const unsigned char *)hostname; *c; c++)
|
||||||
|
if(*c <= ' ' || *c == 0x7f) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
|
int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
|
||||||
char *sp=NULL,*se=NULL;
|
char *sp=NULL,*se=NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if(!hostname || !*hostname)return 2;
|
if(!hostname || !*hostname)return 2;
|
||||||
|
if(badhostname(hostname)) return 1;
|
||||||
if(*hostname == '[') se=strchr(hostname, ']');
|
if(*hostname == '[') se=strchr(hostname, ']');
|
||||||
if ((sp = strchr(se?se:hostname, ':'))) {
|
if ((sp = strchr(se?se:hostname, ':'))) {
|
||||||
if(strchr(sp+1, ':'))sp = NULL;
|
if(strchr(sp+1, ':'))sp = NULL;
|
||||||
|
|||||||
@@ -335,6 +335,7 @@ void hashdelete(struct hashtable *ht, void* name);
|
|||||||
int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl);
|
int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl);
|
||||||
|
|
||||||
int parsehost(int family, unsigned char *host, struct sockaddr *sa);
|
int parsehost(int family, unsigned char *host, struct sockaddr *sa);
|
||||||
|
int badhostname(const char *hostname);
|
||||||
int parsehostname(char *hostname, struct clientparam *param, uint16_t port);
|
int parsehostname(char *hostname, struct clientparam *param, uint16_t port);
|
||||||
int parseusername(char *username, struct clientparam *param, int extpasswd);
|
int parseusername(char *username, struct clientparam *param, int extpasswd);
|
||||||
int parseconnusername(char *username, struct clientparam *param, int extpasswd, uint16_t port);
|
int parseconnusername(char *username, struct clientparam *param, int extpasswd, uint16_t port);
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ void * sockschild(struct clientparam* param) {
|
|||||||
default:
|
default:
|
||||||
RETURN(997);
|
RETURN(997);
|
||||||
}
|
}
|
||||||
|
if(badhostname((char *)buf)) {RETURN(21);}
|
||||||
if(param->hostname)free(param->hostname);
|
if(param->hostname)free(param->hostname);
|
||||||
param->hostname = (unsigned char *)strdup((char *)buf);
|
param->hostname = (unsigned char *)strdup((char *)buf);
|
||||||
if(!param->hostname){RETURN(21);}
|
if(!param->hostname){RETURN(21);}
|
||||||
@@ -159,6 +160,7 @@ void * sockschild(struct clientparam* param) {
|
|||||||
param->service = S_SOCKS45;
|
param->service = S_SOCKS45;
|
||||||
if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);}
|
if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);}
|
||||||
buf[127] = 0;
|
buf[127] = 0;
|
||||||
|
if(badhostname((char *)buf)) {RETURN(21);}
|
||||||
if(param->hostname)free(param->hostname);
|
if(param->hostname)free(param->hostname);
|
||||||
param->hostname = (unsigned char *)strdup((char *)buf);
|
param->hostname = (unsigned char *)strdup((char *)buf);
|
||||||
if(!param->hostname){RETURN(21);}
|
if(!param->hostname){RETURN(21);}
|
||||||
|
|||||||
@@ -277,6 +277,7 @@ int udpsockmap(struct clientparam *param, int timeo)
|
|||||||
if (len < 7 + sz) return 485;
|
if (len < 7 + sz) return 485;
|
||||||
memcpy(dstnamebuf, base + 5, sz);
|
memcpy(dstnamebuf, base + 5, sz);
|
||||||
dstnamebuf[sz] = 0;
|
dstnamebuf[sz] = 0;
|
||||||
|
if (badhostname(dstnamebuf)) continue;
|
||||||
dstname = dstnamebuf;
|
dstname = dstnamebuf;
|
||||||
i = 5 + sz;
|
i = 5 + sz;
|
||||||
if (!getip46(param->srv->family, (unsigned char *)dstnamebuf,
|
if (!getip46(param->srv->family, (unsigned char *)dstnamebuf,
|
||||||
|
|||||||
Reference in new issue
Block a user