mirror of
https://github.com/rofl0r/proxychains-ng
synced 2026-05-14 01:12:34 +08:00
Compare commits
14 Commits
@@ -1,8 +1,8 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
675 Mass Ave, Cambridge, MA 02139, USA
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ OBJS = $(SRCS:.c=.o)
|
|||||||
LOBJS = src/nameinfo.o src/version.o \
|
LOBJS = src/nameinfo.o src/version.o \
|
||||||
src/core.o src/common.o src/libproxychains.o src/shm.o \
|
src/core.o src/common.o src/libproxychains.o src/shm.o \
|
||||||
src/allocator_thread.o src/ip_type.o src/stringdump.o \
|
src/allocator_thread.o src/ip_type.o src/stringdump.o \
|
||||||
src/hostentdb.o src/hash.o src/debug.o
|
src/hostsreader.o src/hash.o src/debug.o
|
||||||
|
|
||||||
GENH = src/version.h
|
GENH = src/version.h
|
||||||
|
|
||||||
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe
|
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe
|
||||||
NO_AS_NEEDED = -Wl,--no-as-needed
|
NO_AS_NEEDED = -Wl,--no-as-needed
|
||||||
LIBDL = -ldl
|
LIBDL = -ldl
|
||||||
LDFLAGS = -shared -fPIC $(NO_AS_NEEDED) $(LIBDL) -lpthread
|
LDFLAGS = -fPIC $(NO_AS_NEEDED)
|
||||||
INC =
|
INC =
|
||||||
PIC = -fPIC
|
PIC = -fPIC
|
||||||
AR = $(CROSS_COMPILE)ar
|
AR = $(CROSS_COMPILE)ar
|
||||||
@@ -46,6 +46,7 @@ ALL_CONFIGS = src/proxychains.conf
|
|||||||
-include config.mak
|
-include config.mak
|
||||||
|
|
||||||
CFLAGS+=$(USER_CFLAGS) $(MAC_CFLAGS)
|
CFLAGS+=$(USER_CFLAGS) $(MAC_CFLAGS)
|
||||||
|
LDFLAGS+=$(USER_LDFLAGS)
|
||||||
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DSYSCONFDIR=\"$(sysconfdir)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\"
|
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DSYSCONFDIR=\"$(sysconfdir)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\"
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ $(DESTDIR)$(bindir)/%: %
|
|||||||
$(DESTDIR)$(libdir)/%: %
|
$(DESTDIR)$(libdir)/%: %
|
||||||
$(INSTALL) -D -m 644 $< $@
|
$(INSTALL) -D -m 644 $< $@
|
||||||
|
|
||||||
$(DESTDIR)$(sysconfdir)/%: %
|
$(DESTDIR)$(sysconfdir)/%: src/%
|
||||||
$(INSTALL) -D -m 644 $< $@
|
$(INSTALL) -D -m 644 $< $@
|
||||||
|
|
||||||
install-libs: $(ALL_LIBS:%=$(DESTDIR)$(libdir)/%)
|
install-libs: $(ALL_LIBS:%=$(DESTDIR)$(libdir)/%)
|
||||||
@@ -81,10 +82,10 @@ src/version.o: src/version.h
|
|||||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
||||||
|
|
||||||
$(LDSO_PATHNAME): $(LOBJS)
|
$(LDSO_PATHNAME): $(LOBJS)
|
||||||
$(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) -o $@ $(LOBJS)
|
$(CC) -shared $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) -lpthread $(LIBDL) -o $@ $(LOBJS)
|
||||||
|
|
||||||
$(ALL_TOOLS): $(OBJS)
|
$(ALL_TOOLS): $(OBJS)
|
||||||
$(CC) src/main.o src/common.o -o $(PXCHAINS)
|
$(CC) $(LDFLAGS) src/main.o src/common.o -o $(PXCHAINS)
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all clean install install-config install-libs install-tools
|
.PHONY: all clean install install-config install-libs install-tools
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ ProxyChains-NG ver 4.8 README
|
|||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
----------
|
----------
|
||||||
|
Version 4.8.1:
|
||||||
|
- fix regression in 4.8 install-config Makefile target
|
||||||
|
|
||||||
Version 4.8:
|
Version 4.8:
|
||||||
- fix for odd cornercase where getaddrinfo was used with AI_NUMERICHOST
|
- fix for odd cornercase where getaddrinfo was used with AI_NUMERICHOST
|
||||||
to test for a numeric ip instead of resolving it (fixes nmap).
|
to test for a numeric ip instead of resolving it (fixes nmap).
|
||||||
@@ -66,9 +69,11 @@ Version 4.7:
|
|||||||
- return EBADF rather than EINTR in close hook.
|
- return EBADF rather than EINTR in close hook.
|
||||||
it's legal for a program to retry close() calls when they receive
|
it's legal for a program to retry close() calls when they receive
|
||||||
EINTR, which could cause an infinite loop, as seen in chromium.
|
EINTR, which could cause an infinite loop, as seen in chromium.
|
||||||
|
|
||||||
Version 4.6:
|
Version 4.6:
|
||||||
- some cosmetic fixes to Makefile, fix a bug when non-numeric ip was
|
- some cosmetic fixes to Makefile, fix a bug when non-numeric ip was
|
||||||
user as proxy server address.
|
used as proxy server address.
|
||||||
|
|
||||||
Version 4.5:
|
Version 4.5:
|
||||||
- hook close() to prevent OpenSSH from messing with internal infrastructure.
|
- hook close() to prevent OpenSSH from messing with internal infrastructure.
|
||||||
this caused ssh client to segfault when proxified.
|
this caused ssh client to segfault when proxified.
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ isbsd() {
|
|||||||
uname -s | grep BSD >/dev/null
|
uname -s | grep BSD >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isopenbsd() {
|
||||||
|
uname -s | grep OpenBSD >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "supported arguments"
|
echo "supported arguments"
|
||||||
echo "--prefix=/path default: $prefix"
|
echo "--prefix=/path default: $prefix"
|
||||||
@@ -83,6 +87,7 @@ fi
|
|||||||
echo CC?=$CC>config.mak
|
echo CC?=$CC>config.mak
|
||||||
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
|
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
|
||||||
[ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak
|
[ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak
|
||||||
|
[ -z "$LDFLAGS" ] || echo USER_LDFLAGS?=$LDFLAGS>>config.mak
|
||||||
echo prefix=$prefix>>config.mak
|
echo prefix=$prefix>>config.mak
|
||||||
echo exec_prefix=$exec_prefix>>config.mak
|
echo exec_prefix=$exec_prefix>>config.mak
|
||||||
echo bindir=$bindir>>config.mak
|
echo bindir=$bindir>>config.mak
|
||||||
@@ -103,6 +108,7 @@ if ismac ; then
|
|||||||
elif isbsd ; then
|
elif isbsd ; then
|
||||||
echo LIBDL=>>config.mak
|
echo LIBDL=>>config.mak
|
||||||
echo "CFLAGS+=-DIS_BSD">>config.mak
|
echo "CFLAGS+=-DIS_BSD">>config.mak
|
||||||
|
isopenbsd && echo "CFLAGS+=-DIS_OPENBSD">>config.mak
|
||||||
make_cmd=gmake
|
make_cmd=gmake
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+11
-9
@@ -719,11 +719,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "hostentdb.h"
|
|
||||||
struct hostent_list hl;
|
|
||||||
|
|
||||||
void core_initialize(void) {
|
void core_initialize(void) {
|
||||||
hdb_init(&hl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void core_unload(void) {
|
void core_unload(void) {
|
||||||
@@ -734,6 +730,7 @@ static void gethostbyname_data_setstring(struct gethostbyname_data* data, char*
|
|||||||
data->hostent_space.h_name = data->addr_name;
|
data->hostent_space.h_name = data->addr_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern ip_type hostsreader_get_numeric_ip_for_name(const char* name);
|
||||||
struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data* data) {
|
struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data* data) {
|
||||||
PFUNC();
|
PFUNC();
|
||||||
char buff[256];
|
char buff[256];
|
||||||
@@ -758,10 +755,8 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data*
|
|||||||
goto retname;
|
goto retname;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buff, 0, sizeof(buff));
|
|
||||||
|
|
||||||
// this iterates over the "known hosts" db, usually /etc/hosts
|
// this iterates over the "known hosts" db, usually /etc/hosts
|
||||||
ip_type hdb_res = hdb_get(&hl, (char*) name);
|
ip_type hdb_res = hostsreader_get_numeric_ip_for_name(name);
|
||||||
if(hdb_res.as_int != ip_type_invalid.as_int) {
|
if(hdb_res.as_int != ip_type_invalid.as_int) {
|
||||||
data->resolved_addr = hdb_res.as_int;
|
data->resolved_addr = hdb_res.as_int;
|
||||||
goto retname;
|
goto retname;
|
||||||
@@ -790,8 +785,12 @@ void proxy_freeaddrinfo(struct addrinfo *res) {
|
|||||||
free(res);
|
free(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IS_MAC
|
#if defined(IS_MAC) || defined(IS_OPENBSD)
|
||||||
/* getservbyname on mac is using thread local storage, so we dont need mutex */
|
#ifdef IS_OPENBSD /* OpenBSD has its own incompatible getservbyname_r */
|
||||||
|
#define getservbyname_r mygetservbyname_r
|
||||||
|
#endif
|
||||||
|
/* getservbyname on mac is using thread local storage, so we dont need mutex
|
||||||
|
TODO: check if the same applies to OpenBSD */
|
||||||
static int getservbyname_r(const char* name, const char* proto, struct servent* result_buf,
|
static int getservbyname_r(const char* name, const char* proto, struct servent* result_buf,
|
||||||
char* buf, size_t buflen, struct servent** result) {
|
char* buf, size_t buflen, struct servent** result) {
|
||||||
PFUNC();
|
PFUNC();
|
||||||
@@ -858,6 +857,9 @@ int proxy_getaddrinfo(const char *node, const char *service, const struct addrin
|
|||||||
p->ai_flags = hints->ai_flags;
|
p->ai_flags = hints->ai_flags;
|
||||||
p->ai_protocol = hints->ai_protocol;
|
p->ai_protocol = hints->ai_protocol;
|
||||||
} else {
|
} else {
|
||||||
|
#ifndef AI_V4MAPPED
|
||||||
|
#define AI_V4MAPPED 0
|
||||||
|
#endif
|
||||||
p->ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
|
p->ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *
|
|||||||
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
|
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
|
||||||
socklen_t, char *, socklen_t, int);
|
socklen_t, char *, socklen_t, int);
|
||||||
|
|
||||||
|
typedef ssize_t (*sendto_t) (int sockfd, const void *buf, size_t len, int flags,
|
||||||
|
const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern connect_t true_connect;
|
extern connect_t true_connect;
|
||||||
extern gethostbyname_t true_gethostbyname;
|
extern gethostbyname_t true_gethostbyname;
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#include "ip_type.h"
|
|
||||||
#include "hash.h"
|
|
||||||
#include "stringdump.h"
|
|
||||||
#include "hostentdb.h"
|
|
||||||
#include "common.h"
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
#define STEP 16
|
|
||||||
static void hdb_add(struct hostent_list* hl, char* host, ip_type ip) {
|
|
||||||
if(hl->count +1 > hl->capa) {
|
|
||||||
void * nu = realloc(hl->entries, (hl->capa + STEP) * sizeof(struct hostent_entry));
|
|
||||||
if(!nu) return;
|
|
||||||
hl->entries = nu;
|
|
||||||
hl->capa += STEP;
|
|
||||||
}
|
|
||||||
struct hostent_entry *h = &hl->entries[hl->count];
|
|
||||||
h->hash = dalias_hash(host);
|
|
||||||
h->ip.as_int = ip.as_int;
|
|
||||||
h->str = dumpstring(host, strlen(host) + 1);
|
|
||||||
if(h->str) hl->count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void hdb_fill(struct hostent_list *hl) {
|
|
||||||
#ifndef IS_BSD
|
|
||||||
struct hostent* hp;
|
|
||||||
while((hp = gethostent()))
|
|
||||||
if(hp->h_addrtype == AF_INET && hp->h_length == sizeof(in_addr_t)) {
|
|
||||||
hdb_add(hl, hp->h_name, (ip_type) { .as_int = *((in_addr_t*)(hp->h_addr_list[0])) });
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/* FreeBSD hangs on gethostent(). since this feature is not crucial, we just do nothing */
|
|
||||||
(void) hl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void hdb_init(struct hostent_list *hl) {
|
|
||||||
memset(hl, 0, sizeof *hl);
|
|
||||||
hdb_fill(hl);
|
|
||||||
}
|
|
||||||
|
|
||||||
ip_type hdb_get(struct hostent_list *hl, char* host) {
|
|
||||||
size_t i;
|
|
||||||
PFUNC();
|
|
||||||
uint32_t hash = dalias_hash(host);
|
|
||||||
for(i = 0; i < hl->count; i++) {
|
|
||||||
if(hl->entries[i].hash == hash && !strcmp(hl->entries[i].str, host)) {
|
|
||||||
#ifdef DEBUG
|
|
||||||
char ipbuf[16];
|
|
||||||
pc_stringfromipv4(hl->entries[i].ip.octet, ipbuf);
|
|
||||||
PDEBUG("got ip %s for hostent entry %s\n", ipbuf, host);
|
|
||||||
#endif
|
|
||||||
return hl->entries[i].ip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ip_type_invalid;
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef HOSTENTDB_H
|
|
||||||
#define HOSTENTDB_H
|
|
||||||
|
|
||||||
#include "ip_type.h"
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
struct hostent_entry {
|
|
||||||
uint32_t hash;
|
|
||||||
ip_type ip;
|
|
||||||
char* str;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hostent_list {
|
|
||||||
size_t count;
|
|
||||||
size_t capa;
|
|
||||||
struct hostent_entry *entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
void hdb_init(struct hostent_list *hl);
|
|
||||||
ip_type hdb_get(struct hostent_list *hl, char* host);
|
|
||||||
|
|
||||||
//RcB: DEP "hostendb.c"
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
simple reader for /etc/hosts
|
||||||
|
it only supports comments, blank lines and lines consisting of an ipv4 hostname pair.
|
||||||
|
this is required so we can return entries from the host db without messing up the
|
||||||
|
non-thread-safe state of libc's gethostent().
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct hostsreader {
|
||||||
|
FILE *f;
|
||||||
|
char* ip, *name;
|
||||||
|
};
|
||||||
|
|
||||||
|
int hostsreader_open(struct hostsreader *ctx) {
|
||||||
|
if(!(ctx->f = fopen("/etc/hosts", "r"))) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hostsreader_close(struct hostsreader *ctx) {
|
||||||
|
fclose(ctx->f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isnumericipv4(const char* ipstring);
|
||||||
|
int hostsreader_get(struct hostsreader *ctx, char* buf, size_t bufsize) {
|
||||||
|
while(1) {
|
||||||
|
if(!fgets(buf, bufsize, ctx->f)) return 0;
|
||||||
|
if(*buf == '#') continue;
|
||||||
|
char *p = buf;
|
||||||
|
size_t l = bufsize;
|
||||||
|
ctx->ip = p;
|
||||||
|
while(*p && !isspace(*p) && l) {
|
||||||
|
p++;
|
||||||
|
l--;
|
||||||
|
}
|
||||||
|
if(!l || !*p || p == ctx->ip) continue;
|
||||||
|
*p = 0;
|
||||||
|
p++;
|
||||||
|
while(*p && isspace(*p) && l) {
|
||||||
|
p++;
|
||||||
|
l--;
|
||||||
|
}
|
||||||
|
if(!l || !*p) continue;
|
||||||
|
ctx->name = buf;
|
||||||
|
while(*p && !isspace(*p) && l) {
|
||||||
|
p++;
|
||||||
|
l--;
|
||||||
|
}
|
||||||
|
if(!l || !*p) continue;
|
||||||
|
*p = 0;
|
||||||
|
if(isnumericipv4(ctx->ip)) return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* hostsreader_get_ip_for_name(const char* name, char* buf, size_t bufsize) {
|
||||||
|
struct hostsreader ctx;
|
||||||
|
char *res = 0;
|
||||||
|
if(!hostsreader_open(&ctx)) return 0;
|
||||||
|
while(hostsreader_get(&ctx, buf, bufsize)) {
|
||||||
|
if(!strcmp(ctx.name, name)) {
|
||||||
|
res = ctx.ip;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hostsreader_close(&ctx);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "ip_type.h"
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
ip_type hostsreader_get_numeric_ip_for_name(const char* name) {
|
||||||
|
char *hres;
|
||||||
|
char buf[320];
|
||||||
|
if((hres = hostsreader_get_ip_for_name(name, buf, sizeof buf))) {
|
||||||
|
struct in_addr c;
|
||||||
|
inet_aton(hres, &c);
|
||||||
|
ip_type res;
|
||||||
|
memcpy(res.octet, &c.s_addr, 4);
|
||||||
|
return res;
|
||||||
|
} else return ip_type_invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HOSTSREADER_TEST
|
||||||
|
int main() {
|
||||||
|
char buf[256];
|
||||||
|
char * ret = hostsreader_get_ip_for_name("goo", buf, sizeof buf);
|
||||||
|
printf("%s\n", ret ? ret : "null");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* isnumericipv4() taken from libulz */
|
||||||
|
static int isnumericipv4(const char* ipstring) {
|
||||||
|
size_t x = 0, n = 0, d = 0;
|
||||||
|
int wasdot = 0;
|
||||||
|
while(1) {
|
||||||
|
switch(ipstring[x]) {
|
||||||
|
case 0: goto done;
|
||||||
|
case '.':
|
||||||
|
if(!n || wasdot) return 0;
|
||||||
|
d++;
|
||||||
|
wasdot = 1;
|
||||||
|
break;
|
||||||
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
|
n++;
|
||||||
|
wasdot = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
done:
|
||||||
|
if(d == 3 && n >= 4 && n <= 12) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -52,6 +52,7 @@ getaddrinfo_t true_getaddrinfo;
|
|||||||
freeaddrinfo_t true_freeaddrinfo;
|
freeaddrinfo_t true_freeaddrinfo;
|
||||||
getnameinfo_t true_getnameinfo;
|
getnameinfo_t true_getnameinfo;
|
||||||
gethostbyaddr_t true_gethostbyaddr;
|
gethostbyaddr_t true_gethostbyaddr;
|
||||||
|
sendto_t true_sendto;
|
||||||
|
|
||||||
int tcp_read_time_out;
|
int tcp_read_time_out;
|
||||||
int tcp_connect_time_out;
|
int tcp_connect_time_out;
|
||||||
@@ -113,6 +114,7 @@ static void do_init(void) {
|
|||||||
proxychains_write_log(LOG_PREFIX "DLL init: proxychains-ng %s\n", proxychains_get_version());
|
proxychains_write_log(LOG_PREFIX "DLL init: proxychains-ng %s\n", proxychains_get_version());
|
||||||
|
|
||||||
SETUP_SYM(connect);
|
SETUP_SYM(connect);
|
||||||
|
SETUP_SYM(sendto);
|
||||||
SETUP_SYM(gethostbyname);
|
SETUP_SYM(gethostbyname);
|
||||||
SETUP_SYM(getaddrinfo);
|
SETUP_SYM(getaddrinfo);
|
||||||
SETUP_SYM(freeaddrinfo);
|
SETUP_SYM(freeaddrinfo);
|
||||||
@@ -479,3 +481,20 @@ struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef MSG_FASTOPEN
|
||||||
|
# define MSG_FASTOPEN 0x20000000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||||
|
const struct sockaddr *dest_addr, socklen_t addrlen) {
|
||||||
|
if (flags & MSG_FASTOPEN) {
|
||||||
|
if (!connect(sockfd, dest_addr, addrlen) && errno != EINPROGRESS) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
dest_addr = NULL;
|
||||||
|
addrlen = 0;
|
||||||
|
flags &= ~MSG_FASTOPEN;
|
||||||
|
}
|
||||||
|
return true_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
#ifndef MSG_FASTOPEN
|
||||||
|
# define MSG_FASTOPEN 0x20000000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void error(const char *msg)
|
||||||
|
{
|
||||||
|
perror(msg);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc < 4) {
|
||||||
|
printf("Usage: %s host port method(connect or sendto)\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const char *hostname = argv[1];
|
||||||
|
const int portno = atoi(argv[2]);
|
||||||
|
const char *method = argv[3];
|
||||||
|
char request[BUFSIZ];
|
||||||
|
sprintf(request, "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", hostname);
|
||||||
|
int sockfd, n;
|
||||||
|
struct sockaddr_in serv_addr;
|
||||||
|
struct hostent *server;
|
||||||
|
|
||||||
|
char buffer[BUFSIZ];
|
||||||
|
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (sockfd < 0) error("ERROR opening socket");
|
||||||
|
server = gethostbyname(hostname);
|
||||||
|
if (server == NULL) {
|
||||||
|
fprintf(stderr, "%s: no such host\n", hostname);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||||
|
serv_addr.sin_family = AF_INET;
|
||||||
|
memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);
|
||||||
|
serv_addr.sin_port = htons(portno);
|
||||||
|
if (!strcmp(method, "connect")) {
|
||||||
|
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
|
||||||
|
error("connect");
|
||||||
|
n = send(sockfd, request, strlen(request), 0);
|
||||||
|
} else if (!strcmp(method, "sendto")) {
|
||||||
|
n = sendto(sockfd, request, strlen(request), MSG_FASTOPEN, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
|
||||||
|
} else {
|
||||||
|
printf("Unknown method %s\n", method);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (n < 0)
|
||||||
|
error("send");
|
||||||
|
memset(buffer, 0, BUFSIZ);
|
||||||
|
n = read(sockfd, buffer, BUFSIZ - 1);
|
||||||
|
if (n < 0)
|
||||||
|
error("ERROR reading from socket");
|
||||||
|
printf("%s\n", buffer);
|
||||||
|
close(sockfd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user