Skip to content

Commit

Permalink
update to 0.4.4 with various fixes. see below
Browse files Browse the repository at this point in the history
fix: finally resolved x64 -> x86 injection issue;
fix: switch to non-debug runtime dlls, enabling debug versions to run on
machines without dev env
fix: avoid hanging when first injection fails
  • Loading branch information
shunf4 committed Mar 2, 2020
1 parent 6de579a commit c619f33
Show file tree
Hide file tree
Showing 57 changed files with 649 additions and 442 deletions.
23 changes: 11 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,14 @@ ASALocalRun/
healthchecksdb

cygwin-archive
cygwin-build/**/*.d
cygwin-build/**/*.o
cygwin-build/**/*.dll
cygwin-build/**/*.exe
cygwin-build/**/*.a
cygwin-build/**/*.lib
cygwin-build/**/MAKING_*
cygwin-build/**/distx*
cygwin-build/**/*.stackdump
cygwin-build/**/*.bin
win32_output/
include/function_pointers_configured.h
cygwin_build/**/*.d
cygwin_build/**/*.o
cygwin_build/**/*.dll
cygwin_build/**/*.exe
cygwin_build/**/*.a
cygwin_build/**/*.lib
cygwin_build/**/MAKING_*
cygwin_build/**/distx*
cygwin_build/**/*.stackdump
cygwin_build/**/*.bin
win32_output/
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"initializer_list": "c",
"utility": "c",
"hookdll_interior_win32.h": "c",
"hookdll_interior_generic.h": "c"
"hookdll_interior_generic.h": "c",
"ut_helpers.h": "c"
}
}
22 changes: 0 additions & 22 deletions Configure/Configure.vcxproj.filters

This file was deleted.

39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

[README](README.md) | [简体中文文档](README_zh-Hans.md)

Proxychains.exe is a proxifier for Win32(Windows) or Cygwin programs. It hijacks
most of the Win32 or Cygwin programs' TCP connection, making them through one or
more SOCKS5 proxy(ies).
Proxychains.exe is a proxifier for Win32(Windows) or Cygwin programs.
It hijacks most of the Win32 or Cygwin programs' TCP connection, making
them through one or more SOCKS5 proxy(ies).

Proxychains.exe hooks network-related Ws2_32.dll Winsock functions in
dynamically linked programs via injecting a DLL and redirects the connections
Expand All @@ -19,8 +19,8 @@ It also uses [uthash](https://github.com/troydhanson/uthash) for some data
structures and [minhook](https://github.com/TsudaKageyu/minhook) for API
hooking.

Proxychains.exe is tested on Windows 10 x64 1909 (18363.418), Windows XP x86 SP3
and Cygwin 64-bit 3.1.2. Target OS should have
Proxychains.exe is tested on Windows 10 x64 1909 (18363.418), Windows 7 x64
SP1, Windows XP x86 SP3 and Cygwin 64-bit 3.1.2. Target OS should have
[Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/en-us/download/details.aspx?id=48145)
installed.

Expand All @@ -41,10 +41,10 @@ doing so can be VERY DANGEROUS in certain countries.
ALWAYS MAKE SURE THAT PROXYCHAINS.EXE WORKS AS EXPECTED
BEFORE USING IT FOR ANYTHING SERIOUS.

this involves both the program and the proxy that you're going to
This involves both the program and the proxy that you're going to
use.

for example, you can connect to some "what is my ip" service
For example, you can connect to some "what is my ip" service
like ifconfig.me to make sure that it's not using your real ip.

ONLY USE PROXYCHAINS.EXE IF YOU KNOW WHAT YOU'RE DOING.
Expand All @@ -61,19 +61,21 @@ First you need to clone this repository and run
## Win32 Build

Open proxychains.exe.sln with a recent version Visual Studio (tested with
Visual Studio 2019) with platform toolset v141_xp. Build Solution and see
DLL file and executable file generated under `win32_output/`.
Visual Studio 2019) with platform toolset v141_xp on a 64-bit Windows.

Build the whole solution and you will see DLL file and executable
file generated under `win32_output/`.

## Cygwin Build

Install Cygwin and various build tool packages (gcc, w32api-headers,
w32api-runtime etc). Run Cygwin bash, switch to `cygwin-build` directory and
w32api-runtime etc). Run Cygwin bash, switch to `cygwin_build` directory and
run `make`.

# Install

Copy `proxychains*.exe`, `[cyg]proxychains_hook*.dll`,
`proxychains_remote_function_*.bin` to some directory included in your `PATH`
Copy `proxychains*.exe`, `[cyg]proxychains_hook*.dll`
to some directory included in your `PATH`
environment variable. Also create the needed configuration file in correct
place. See "Configuration".

Expand Down Expand Up @@ -136,7 +138,8 @@ programs). See "To-do and Known Issues". Perhaps solution based on

- [ ] Remote DNS resolving based on UDP associate
- [ ] Hook `sendto()`, coping with applications which do TCP fast open
- [ ] Fix Cygwin proxychains pip failure (0xc0000005 Access Denied)
- [ ] ~~Fix Cygwin proxychains pip failure (0xc0000005 Access Denied)~~
Not reproduced
- [ ] ~~Adapt proxychains_hook.dll to Sandboxie (???)~~
- [X] ~~Make -lVERBOSE available in proxychainsd.exe (The debug versions)~~
Fixed in 0.4
Expand All @@ -146,16 +149,16 @@ programs). See "To-do and Known Issues". Perhaps solution based on
- [ ] ~~Fix 32-bit proxychains SearchPath(ssh) failure~~
(Windows Filesystem Redirection)
- [X] ~~Dynamic selection of 32-bit DLL and 64-bit DLL~~ ~~Fixed in 0.4~~
Finally fixed in 0.4.3 (More tests needed)
Finally fixed in ~~0.4.3~~ ~~0.4.4~~ 0.4.5
- [ ] ~~Try to fix `proxychains git clone https://...` under Cygwin~~
Using `-q` in 0.4.1 reduces the probability to happen
- [X] ~~Try to fix `proxychains npm install` in a huge project~~
(may be caused by excess usage of stack in GetAddrInfoW, turning off
`proxy_dns` in 0.4 fixes this)
- [X] ~~Resolve race condition in `FormatHostPortToStr()`~~ (0.4.3)
~~(may be caused by excess usage of stack in GetAddrInfoW, turning off
`proxy_dns` in 0.4 fixes this)~~ Fixed in 0.4.3
- [X] ~~Resolve race condition in `FormatHostPortToStr()`~~ Fixed in 0.4.3
- [X] ~~Resolve remote thread exit code `0xc0000005` (Access Denied)
when calling `C:\ProgramData\chocolatey\tools\7z.exe`~~
Finally fixed in 0.4.3 (More tests needed)
Finally fixed in ~~0.4.3~~ ~~0.4.4~~ 0.4.5

# Licensing

Expand Down
10 changes: 6 additions & 4 deletions README_zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Proxychains.exe 通过给动态链接的程序注入一个 DLL,对 Ws2_32.dll

Proxychains.exe 是 [proxychains4](https://github.com/haad/proxychains) 或者 [proxychains-ng](https://github.com/rofl0r/proxychains-ng) 到 Win32 和 Cygwin 的移植产物。它也使用了 [uthash](https://github.com/troydhanson/uthash) 构建一些数据结构,以及使用了 [minhook](https://github.com/TsudaKageyu/minhook) 进行 API 的挂钩。

Proxychains.exe 在 Windows 10 x64 1909 (18363.418)、Windows XP x86 SP3 和 Cygwin 64-bit 3.1.2 经过测试。注意目标操作系统需要安装 [Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/zh-cn/download/details.aspx?id=48145)
Proxychains.exe 在 Windows 10 x64 1909 (18363.418)、Windows 7 x64 SP1、Windows XP x86 SP3 和 Cygwin 64-bit 3.1.2 经过测试。注意目标操作系统需要安装 [Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/zh-cn/download/details.aspx?id=48145)

警告:此程序只对动态链接的程序有用。同时,Proxychains.exe 和需要运行的目标程序必须是同一架构和平台(用 proxychains_x86.exe 运行 x86 程序,用 proxychains_x64.exe 运行 x64 程序;用 Cygwin 下构建的版本来运行 Cygwin 程序)。

Expand All @@ -32,15 +32,17 @@ Proxychains.exe 在 Windows 10 x64 1909 (18363.418)、Windows XP x86 SP3 和 Cyg

## 构建 Win32 版本

使用较新版本的 Visual Studio 打开 proxychains.exe.sln (Visual Studio 2019 测试有效)。Visual Studio 应该安装 v141_xp 平台工具集。构建整个解决方案,在 `win32_output/` 找到输出的 EXE 和 DLL 文件。
在 64 位 Windows 下使用较新版本的 Visual Studio 打开 proxychains.exe.sln (Visual Studio 2019 测试有效)。Visual Studio 应该安装 v141_xp 平台工具集。

构建整个解决方案,在 `win32_output/` 找到输出的 EXE 和 DLL 文件。

## 构建 Cygwin 版本

安装 Cygwin 和各种构建工具程序包(gcc、w32api-headers、w32api-runtime 等)。运行 Cygwin bash,切换到 `cygwin-build` 目录下,执行 `make`
安装 Cygwin 和各种构建工具程序包(gcc、w32api-headers、w32api-runtime 等)。运行 Cygwin bash,切换到 `cygwin_build` 目录下,执行 `make`

# 安装

把生成的 `proxychains*.exe``[cyg]proxychains_hook*.dll` `proxychains_remote_function_*.bin` 复制到 `PATH` 环境变量包含的某个目录下。另外你还需要在正确的位置创建配置文件。参见“配置”。
把生成的 `proxychains*.exe``[cyg]proxychains_hook*.dll` 复制到 `PATH` 环境变量包含的某个目录下。另外你还需要在正确的位置创建配置文件。参见“配置”。

# 配置

Expand Down
54 changes: 0 additions & 54 deletions cygwin-build/dist.sh

This file was deleted.

Binary file removed cygwin-build/test/spawn_ctrlc/_ctrlc.exe
Binary file not shown.
Binary file removed cygwin-build/test/spawn_ctrlc/_test.exe
Binary file not shown.
Binary file removed cygwin-build/test/sprintf/_sprintf.exe
Binary file not shown.
15 changes: 0 additions & 15 deletions cygwin-build/windows_install.bat

This file was deleted.

57 changes: 35 additions & 22 deletions cygwin-build/Makefile → cygwin_build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SRC_PREFIX = ../src/
INCLUDE_DIR_CFLAGS = -I../include/ -I../uthash/src -I../minhook/include
LIB_DIR_LDFLAGS = -L../minhook/

DLL_SRCS = $(sort $(sort $(wildcard $(SRC_PREFIX)dll/*.c)) $(sort $(wildcard $(SRC_PREFIX)dll/remote_function/*.c)))
DLL_SRCS = $(sort $(sort $(wildcard $(SRC_PREFIX)dll/*.c)))
DLL_OBJS = $(patsubst $(SRC_PREFIX)%,%,$(DLL_SRCS:.c=.o))

NONDLL_SRCS = $(sort $(wildcard $(SRC_PREFIX)cygwin_strsafe/*.c)) $(sort $(wildcard $(SRC_PREFIX)exe/*.c)) $(sort $(wildcard $(SRC_PREFIX)*.c))
Expand All @@ -44,10 +44,13 @@ endif

EXEC_PATH_DEBUG = ./proxychains_$(ARCHITECT)d.exe
EXEC_PATH_RELEASE = ./proxychains_$(ARCHITECT).exe
DLL_MODULE_NAME = proxychains_hook_$(ARCHITECT)
HELPER_PATH_DEBUG = ./proxychains_helper_$(ARCHITECT)d.exe
HELPER_PATH_RELEASE = ./proxychains_helper_$(ARCHITECT).exe
REMOTE_FUNC_BIN_HEADER_DEBUG = ../include/remote_func_bin_$(ARCHITECT)d.h
REMOTE_FUNC_BIN_HEADER_RELEASE = ../include/remote_func_bin_$(ARCHITECT).h

DLL_MODULE_NAME_DEBUG = $(DLL_MODULE_NAME)d
DLL_MODULE_NAME_RELEASE = $(DLL_MODULE_NAME)
DLL_MODULE_NAME_DEBUG = proxychains_hook_$(ARCHITECT)d
DLL_MODULE_NAME_RELEASE = proxychains_hook_$(ARCHITECT)

DLL_NAME_DEBUG = cyg$(DLL_MODULE_NAME_DEBUG)
DLL_NAME_RELEASE = cyg$(DLL_MODULE_NAME_RELEASE)
Expand All @@ -65,15 +68,14 @@ ALL_SHARED_LIBS_RELEASE = $(DLL_PATH_RELEASE)
ALL_EXECS_RELEASE = $(EXEC_PATH_RELEASE)

MAKE_DIR_1 := $(shell [ -d dll ] || mkdir -p dll)
MAKE_DIR_1 := $(shell [ -d dll/remote_function ] || mkdir -p dll/remote_function)
MAKE_DIR_2 := $(shell [ -d exe ] || mkdir -p exe)
MAKE_DIR_3 := $(shell [ -d cygwin_strsafe ] || mkdir -p cygwin_strsafe)

ifeq ($(DEBUG),0)

all : release
@echo Made release

else
ifndef DEBUG

Expand All @@ -90,13 +92,17 @@ endif

debug : CFLAGS += -g -DDEBUG -D_DEBUG
debug : DLL_CFLAGS += -g -DDEBUG -D_DEBUG
debug : MAKING_DEBUG $(ALL_EXECS_DEBUG)
./$(EXEC_PATH_DEBUG) --dump-remote
debug : pre_debug $(ALL_EXECS_DEBUG)

release : CFLAGS += -DPXCH_LOG_LEVEL=400
release : DLL_CFLAGS += -DPXCH_LOG_LEVEL=400
release : MAKING_RELEASE $(ALL_EXECS_RELEASE)
./$(EXEC_PATH_RELEASE) --dump-remote
release : pre_release $(ALL_EXECS_RELEASE)

pre_debug : MAKING_DEBUG $(REMOTE_FUNC_BIN_HEADER_DEBUG)
$(eval REMOTE_FUNC_BIN_HEADER := $(REMOTE_FUNC_BIN_HEADER_DEBUG))

pre_release : MAKING_RELEASE $(REMOTE_FUNC_BIN_HEADER_RELEASE)
$(eval REMOTE_FUNC_BIN_HEADER := $(REMOTE_FUNC_BIN_HEADER_RELEASE))

MAKING_DEBUG :
$(MAKE) clean
Expand All @@ -114,18 +120,24 @@ $(DLL_OBJS) : %.o : $(SRC_PREFIX)%.c %.d

$(DEPS) :

configure.exe : configure.o
$(CC) -o$@ configure.o -Wl,-Bdynamic -lntdllcrt -lkernel32 -lcygwin

../include/function_pointers_configured.h : configure.exe
./configure.exe > ../include/function_pointers_configured.h
$(HELPER_PATH_DEBUG) : proxychains_helper.o remote_function.o
$(CC) -o$@ $(filter %.c %.o %.a %.lib,$^) -Wl,-Bdynamic -lntdllcrt -lkernel32 -lcygwin

$(HELPER_PATH_RELEASE) : proxychains_helper.o remote_function.o
$(CC) -o$@ $(filter %.c %.o %.a %.lib,$^) -Wl,-Bdynamic -lntdllcrt -lkernel32 -lcygwin

$(REMOTE_FUNC_BIN_HEADER_DEBUG) : $(HELPER_PATH_DEBUG)
$(HELPER_PATH_DEBUG) --dump-remote-function > $@

$(REMOTE_FUNC_BIN_HEADER_RELEASE) : $(HELPER_PATH_RELEASE)
$(HELPER_PATH_RELEASE) --dump-remote-function > $@

$(DLL_PATH_DEBUG) : ../minhook/libMinHook.a ../include/function_pointers_configured.h dll/dllmain.o dll/hook_connect_win32.o dll/hook_connect_win32.o dll/hook_connect_cygwin.o dll/hook_createprocess_win32.o dll/hook_installer.o dll/ipc_client_and_child_data.o dll/dllutil_log_func.o dll/dllutil_wsock.o dll/remote_function/remote_function.o common.o common_wsock.o ipc_message.o log.o cygwin_strsafe/strsafe.o
$(DLL_PATH_DEBUG) : ../minhook/libMinHook.a dll/dllmain.o dll/hook_connect_win32.o dll/hook_connect_win32.o dll/hook_connect_cygwin.o dll/hook_createprocess_win32.o dll/hook_installer.o dll/ipc_client_and_child_data.o dll/dllutil_log_func.o dll/dllutil_wsock.o common.o common_wsock.o ipc_message.o log.o cygwin_strsafe/strsafe.o
$(CC) -shared -o$@ -Wl,--out-implib=$(DLL_IMPLIB_PATH_DEBUG) $(LIB_DIR_LDFLAGS) $(filter %.c %.o %.a %.lib,$^) -Wl,-static -lMinHook -Wl,-Bdynamic -lntdllcrt -lws2_32 -lshlwapi

$(DLL_PATH_RELEASE) : ../minhook/libMinHook.a ../include/function_pointers_configured.h dll/dllmain.o dll/hook_connect_win32.o dll/hook_connect_win32.o dll/hook_connect_cygwin.o dll/hook_createprocess_win32.o dll/hook_installer.o dll/ipc_client_and_child_data.o dll/dllutil_log_func.o dll/dllutil_wsock.o dll/remote_function/remote_function.o common.o common_wsock.o ipc_message.o log.o cygwin_strsafe/strsafe.o
$(DLL_PATH_RELEASE) : ../minhook/libMinHook.a dll/dllmain.o dll/hook_connect_win32.o dll/hook_connect_win32.o dll/hook_connect_cygwin.o dll/hook_createprocess_win32.o dll/hook_installer.o dll/ipc_client_and_child_data.o dll/dllutil_log_func.o dll/dllutil_wsock.o common.o common_wsock.o ipc_message.o log.o cygwin_strsafe/strsafe.o
$(CC) -shared -o$@ -Wl,--out-implib=$(DLL_IMPLIB_PATH_RELEASE) $(LIB_DIR_LDFLAGS) $(filter %.c %.o %.a %.lib,$^) -Wl,-static -lMinHook -Wl,-Bdynamic -lntdllcrt -lws2_32 -lshlwapi

# -Wl,--export-all-symbols \
# -Wl,--enable-auto-import \
Expand All @@ -138,7 +150,7 @@ $(EXEC_PATH_DEBUG) : ../minhook/libMinHook.a exe/main.o exe/args_and_config.o ex
$(EXEC_PATH_RELEASE) : ../minhook/libMinHook.a exe/main.o exe/args_and_config.o exe/ipc_proc_bookkeeping.o stdlib_config_reader.o common.o common_wsock.o ipc_message.o log.o cygwin_strsafe/strsafe.o $(DLL_IMPLIB_PATH_RELEASE)
$(CC) -o$@ $(filter %.c %.o %.a %.lib,$^) $(LIB_DIR_LDFLAGS) -Wl,-static -lMinHook -Wl,-Bdynamic -lntdllcrt -lkernel32 -lshlwapi -ladvapi32 -lcygwin -lws2_32

.PHONY : clean dist configure
.PHONY : clean dist pre_debug pre_release

clean :
$(RM) MAKING_DEBUG MAKING_RELEASE
Expand All @@ -147,7 +159,8 @@ clean :
$(RM) $(ALL_IMPLIBS_DEBUG) $(ALL_IMPLIBS_RELEASE)
$(RM) $(OBJS)
$(RM) $(DEPS)
$(RM) ../include/function_pointers_configured.h configure.exe proxychains_remote_function_*.bin
$(RM) $(HELPER_PATH_DEBUG) $(HELPER_PATH_RELEASE)
$(RM) $(REMOTE_FUNC_BIN_HEADER_DEBUG) $(REMOTE_FUNC_BIN_HEADER_RELEASE)
$(MAKE) -C ../minhook -f ../minhook/build/MinGW/Makefile clean

../minhook/libMinHook.a :
Expand All @@ -164,13 +177,13 @@ distinstall_legacy:
cp $(EXEC_PATH_RELEASE) $(PREFIX)/bin/proxychains.exe
cp $(EXEC_PATH_RELEASE) $(PREFIX)/bin/px.exe
cp $(DLL_PATH_RELEASE) $(PREFIX)/bin/
cp proxychains_remote_function_*.bin $(PREFIX)/bin/
cp $(HELPER_PATH_RELEASE) $(PREFIX)/bin/

make debug
cp $(EXEC_PATH_DEBUG) $(PREFIX)/bin/proxychainsd.exe
cp $(EXEC_PATH_DEBUG) $(PREFIX)/bin/pxd.exe
cp $(DLL_PATH_DEBUG) $(PREFIX)/bin/
cp proxychains_remote_function_*.bin $(PREFIX)/bin/
cp $(HELPER_PATH_DEBUG) $(PREFIX)/bin/


rebuild : clean all
Expand Down
Loading

0 comments on commit c619f33

Please sign in to comment.