Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rofl0r/proxychains-ng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrofl0r <rofl0r@users.noreply.github.com>2021-05-14 17:10:14 +0300
committerrofl0r <rofl0r@users.noreply.github.com>2021-05-14 17:10:14 +0300
commit092d7042e092a033ac0c33a238927050c2cc7de0 (patch)
tree9bde08d939dddea55758dc0040de5a72890f3b7e
parent6af2686a52e0e2272f8167cc170e9c572157e7b3 (diff)
initialize rand seed with nano-second granularity
in scenarios where one is to spin up several processes with the same proxy list in random mode, all processes started in the same second would pick the same proxy due to using the same srand() seed. closes #380
-rwxr-xr-xconfigure3
-rw-r--r--src/libproxychains.c12
2 files changed, 14 insertions, 1 deletions
diff --git a/configure b/configure
index 1e9ca3f..8b21b97 100755
--- a/configure
+++ b/configure
@@ -165,6 +165,9 @@ check_compile 'whether we have pipe2() and O_CLOEXEC' "-DHAVE_PIPE2" \
check_compile 'whether we have SOCK_CLOEXEC' "-DHAVE_SOCK_CLOEXEC" \
'#define _GNU_SOURCE\n#include <sys/socket.h>\nint main() {\nreturn socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);}'
+check_compile 'whether we have clock_gettime' "-DHAVE_CLOCK_GETTIME" \
+'#define _GNU_SOURCE\n#include <time.h>\nint main() {\nstruct timespec now;clock_gettime(CLOCK_REALTIME, &now);\nreturn now.tv_sec ^ now.tv_nsec;}'
+
check_define __APPLE__ && {
mac_detected=true
check_define __x86_64__ && mac_64=true
diff --git a/src/libproxychains.c b/src/libproxychains.c
index a3509c9..b67ce83 100644
--- a/src/libproxychains.c
+++ b/src/libproxychains.c
@@ -127,8 +127,18 @@ static void setup_hooks(void) {
static int close_fds[16];
static int close_fds_cnt = 0;
+static unsigned get_rand_seed(void) {
+#ifdef HAVE_CLOCK_GETTIME
+ struct timespec now;
+ clock_gettime(CLOCK_REALTIME, &now);
+ return now.tv_sec ^ now.tv_nsec;
+#else
+ return time(NULL);
+#endif
+}
+
static void do_init(void) {
- srand(time(NULL));
+ srand(get_rand_seed());
core_initialize();
/* read the config file */