mirror of
https://github.com/rofl0r/proxychains-ng
synced 2026-05-13 17:03:07 +08:00
Compare commits
5 Commits
@@ -19,7 +19,7 @@ DOBJS = src/daemon/hsearch.o \
|
||||
src/daemon/sblist.o src/daemon/sblist_delete.o \
|
||||
src/daemon/daemon.o src/daemon/udpserver.o
|
||||
|
||||
LOBJS = src/nameinfo.o src/version.o \
|
||||
LOBJS = src/version.o \
|
||||
src/core.o src/common.o src/libproxychains.o \
|
||||
src/allocator_thread.o src/rdns.o \
|
||||
src/hostsreader.o src/hash.o src/debug.o
|
||||
|
||||
@@ -50,8 +50,10 @@ check_compile_run() {
|
||||
|
||||
check_link_silent() {
|
||||
printf "$2" > "$tmpc"
|
||||
$CC $OUR_CPPFLAGS $CPPFLAGS $1 $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1
|
||||
local res=0
|
||||
$CC $OUR_CPPFLAGS $CPPFLAGS $1 $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 || res=1
|
||||
rm -f "$tmpc".out
|
||||
return $res
|
||||
}
|
||||
|
||||
check_link() {
|
||||
|
||||
+56
-23
@@ -104,25 +104,12 @@ static void* load_sym(char* symname, void* proxyfunc) {
|
||||
|
||||
#define INIT() init_lib_wrapper(__FUNCTION__)
|
||||
|
||||
#define SETUP_SYM(X) do { if (! true_ ## X ) true_ ## X = load_sym( # X, X ); } while(0)
|
||||
|
||||
#include "allocator_thread.h"
|
||||
|
||||
const char *proxychains_get_version(void);
|
||||
|
||||
static void setup_hooks(void) {
|
||||
SETUP_SYM(connect);
|
||||
SETUP_SYM(sendto);
|
||||
SETUP_SYM(gethostbyname);
|
||||
SETUP_SYM(getaddrinfo);
|
||||
SETUP_SYM(freeaddrinfo);
|
||||
SETUP_SYM(gethostbyaddr);
|
||||
SETUP_SYM(getnameinfo);
|
||||
#ifdef IS_SOLARIS
|
||||
SETUP_SYM(__xnet_connect);
|
||||
#endif
|
||||
SETUP_SYM(close);
|
||||
}
|
||||
static void setup_hooks(void);
|
||||
|
||||
static int close_fds[16];
|
||||
static int close_fds_cnt = 0;
|
||||
@@ -537,7 +524,14 @@ inv_host:
|
||||
|
||||
/******* HOOK FUNCTIONS *******/
|
||||
|
||||
int close(int fd) {
|
||||
#define EXPAND( args...) args
|
||||
#ifdef MONTEREY_HOOKING
|
||||
#define HOOKFUNC(R, N, args...) R pxcng_ ## N ( EXPAND(args) )
|
||||
#else
|
||||
#define HOOKFUNC(R, N, args...) R N ( EXPAND(args) )
|
||||
#endif
|
||||
|
||||
HOOKFUNC(int, close, int fd) {
|
||||
if(!init_l) {
|
||||
if(close_fds_cnt>=(sizeof close_fds/sizeof close_fds[0])) goto err;
|
||||
close_fds[close_fds_cnt++] = fd;
|
||||
@@ -558,7 +552,8 @@ int close(int fd) {
|
||||
static int is_v4inv6(const struct in6_addr *a) {
|
||||
return !memcmp(a->s6_addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
}
|
||||
int connect(int sock, const struct sockaddr *addr, unsigned int len) {
|
||||
|
||||
HOOKFUNC(int, connect, int sock, const struct sockaddr *addr, unsigned int len) {
|
||||
INIT();
|
||||
PFUNC();
|
||||
|
||||
@@ -649,13 +644,13 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
|
||||
}
|
||||
|
||||
#ifdef IS_SOLARIS
|
||||
int __xnet_connect(int sock, const struct sockaddr *addr, unsigned int len) {
|
||||
HOOKFUNC(int, __xnet_connect, int sock, const struct sockaddr *addr, unsigned int len)
|
||||
return connect(sock, addr, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct gethostbyname_data ghbndata;
|
||||
struct hostent *gethostbyname(const char *name) {
|
||||
HOOKFUNC(struct hostent*, gethostbyname, const char *name) {
|
||||
INIT();
|
||||
PDEBUG("gethostbyname: %s\n", name);
|
||||
|
||||
@@ -669,7 +664,7 @@ struct hostent *gethostbyname(const char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
||||
HOOKFUNC(int, getaddrinfo, const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
||||
INIT();
|
||||
PDEBUG("getaddrinfo: %s %s\n", node ? node : "null", service ? service : "null");
|
||||
|
||||
@@ -679,7 +674,7 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi
|
||||
return true_getaddrinfo(node, service, hints, res);
|
||||
}
|
||||
|
||||
void freeaddrinfo(struct addrinfo *res) {
|
||||
HOOKFUNC(void, freeaddrinfo, struct addrinfo *res) {
|
||||
INIT();
|
||||
PDEBUG("freeaddrinfo %p \n", (void *) res);
|
||||
|
||||
@@ -689,7 +684,7 @@ void freeaddrinfo(struct addrinfo *res) {
|
||||
proxy_freeaddrinfo(res);
|
||||
}
|
||||
|
||||
int pc_getnameinfo(const struct sockaddr *sa, socklen_t salen,
|
||||
HOOKFUNC(int, getnameinfo, const struct sockaddr *sa, socklen_t salen,
|
||||
char *host, socklen_t hostlen, char *serv,
|
||||
socklen_t servlen, int flags)
|
||||
{
|
||||
@@ -733,7 +728,7 @@ int pc_getnameinfo(const struct sockaddr *sa, socklen_t salen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
||||
HOOKFUNC(struct hostent*, gethostbyaddr, const void *addr, socklen_t len, int type) {
|
||||
INIT();
|
||||
PDEBUG("TODO: proper gethostbyaddr hook\n");
|
||||
|
||||
@@ -769,7 +764,7 @@ struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
||||
# define MSG_FASTOPEN 0x20000000
|
||||
#endif
|
||||
|
||||
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||
HOOKFUNC(ssize_t, sendto, int sockfd, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t addrlen) {
|
||||
INIT();
|
||||
PFUNC();
|
||||
@@ -783,3 +778,41 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||
}
|
||||
return true_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
|
||||
}
|
||||
|
||||
#ifdef MONTEREY_HOOKING
|
||||
#define SETUP_SYM(X) do { if (! true_ ## X ) true_ ## X = &X; } while(0)
|
||||
#else
|
||||
#define SETUP_SYM(X) do { if (! true_ ## X ) true_ ## X = load_sym( # X, X ); } while(0)
|
||||
#endif
|
||||
|
||||
static void setup_hooks(void) {
|
||||
SETUP_SYM(connect);
|
||||
SETUP_SYM(sendto);
|
||||
SETUP_SYM(gethostbyname);
|
||||
SETUP_SYM(getaddrinfo);
|
||||
SETUP_SYM(freeaddrinfo);
|
||||
SETUP_SYM(gethostbyaddr);
|
||||
SETUP_SYM(getnameinfo);
|
||||
#ifdef IS_SOLARIS
|
||||
SETUP_SYM(__xnet_connect);
|
||||
#endif
|
||||
SETUP_SYM(close);
|
||||
}
|
||||
|
||||
#ifdef MONTEREY_HOOKING
|
||||
|
||||
#define DYLD_INTERPOSE(_replacement,_replacee) \
|
||||
__attribute__((used)) static struct{ const void* replacement; const void* replacee; } _interpose_##_replacee \
|
||||
__attribute__((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee };
|
||||
#define DYLD_HOOK(F) DYLD_INTERPOSE(pxcng_ ## F, F)
|
||||
|
||||
DYLD_HOOK(connect);
|
||||
DYLD_HOOK(sendto);
|
||||
DYLD_HOOK(gethostbyname);
|
||||
DYLD_HOOK(getaddrinfo);
|
||||
DYLD_HOOK(freeaddrinfo);
|
||||
DYLD_HOOK(gethostbyaddr);
|
||||
DYLD_HOOK(getnameinfo);
|
||||
DYLD_HOOK(close);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#include <sys/socket.h>
|
||||
|
||||
extern int pc_getnameinfo(const void *sa, socklen_t salen,
|
||||
char *host, socklen_t hostlen, char *serv,
|
||||
socklen_t servlen, int flags);
|
||||
|
||||
|
||||
int getnameinfo(const void *sa, socklen_t salen,
|
||||
char *host, socklen_t hostlen, char *serv,
|
||||
socklen_t servlen, int flags) {
|
||||
return pc_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef NI_MAXHOST
|
||||
#define NI_MAXHOST 1025
|
||||
@@ -43,9 +45,42 @@ static int doit(const char* host, const char* service) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* reproduce use of getaddrinfo as used by nmap 7.91's canonicalize_address */
|
||||
int canonicalize_address(struct sockaddr_storage *ss, struct sockaddr_storage *output) {
|
||||
char canonical_ip_string[NI_MAXHOST];
|
||||
struct addrinfo *ai;
|
||||
int rc;
|
||||
/* Convert address to string. */
|
||||
rc = getnameinfo((struct sockaddr *) ss, sizeof(*ss),
|
||||
canonical_ip_string, sizeof(canonical_ip_string), NULL, 0, NI_NUMERICHOST);
|
||||
assert(rc == 0);
|
||||
struct addrinfo hints = {
|
||||
.ai_family = ss->ss_family,
|
||||
.ai_socktype = SOCK_DGRAM,
|
||||
.ai_flags = AI_NUMERICHOST,
|
||||
};
|
||||
rc = getaddrinfo(canonical_ip_string, NULL, &hints, &ai);
|
||||
if (rc != 0 || ai == NULL)
|
||||
return -1;
|
||||
assert(ai->ai_addrlen > 0 && ai->ai_addrlen <= (int) sizeof(*output));
|
||||
memcpy(output, ai->ai_addr, ai->ai_addrlen);
|
||||
freeaddrinfo(ai);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int ret;
|
||||
ret = doit("www.example.com", NULL);
|
||||
ret = doit("www.example.com", "80");
|
||||
struct sockaddr_storage o, ss = {.ss_family = PF_INET};
|
||||
struct sockaddr_in *v4 = &ss;
|
||||
struct sockaddr_in6 *v6 = &ss;
|
||||
memcpy(&v4->sin_addr, "\x7f\0\0\1", 4);
|
||||
ret = canonicalize_address(&ss, &o);
|
||||
assert (ret == 0);
|
||||
ss.ss_family = PF_INET6;
|
||||
memcpy(&v6->sin6_addr, "\0\0\0\0" "\0\0\0\0" "\0\0\0\0""\0\0\0\1", 16);
|
||||
ret = canonicalize_address(&ss, &o);
|
||||
assert (ret == 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -123,5 +123,17 @@ int main() {
|
||||
|
||||
ASSERT(ret == 0);
|
||||
|
||||
b.sin6_port = 0;
|
||||
b.sin6_scope_id = 0;
|
||||
memcpy(&b.sin6_addr,"\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\1", 16);
|
||||
|
||||
if ((ret = getnameinfo((void*)sb, sizeof b, hbuf, sizeof(hbuf), NULL,
|
||||
0, NI_NUMERICHOST)) == 0)
|
||||
printf("host=%s\n", hbuf);
|
||||
else
|
||||
printf("%s\n", gai_strerror(ret));
|
||||
|
||||
ASSERT(ret == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user