Skip to content

Commit

Permalink
fix: 0xc0000005 caused by delayed hook under cygwin; update to 0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shunf4 committed Feb 23, 2020
1 parent 801f99f commit 218411f
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,5 @@ cygwin-build/**/*.a
cygwin-build/**/*.lib
cygwin-build/**/MAKING_*
cygwin-build/**/distx*
windows_install.bat
cygwin-build/**/*.stackdump
win32_output/
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
"common_generic.h": "c",
"sstream": "c",
"version.h": "c",
"tls_generic.h": "c"
"tls_generic.h": "c",
"*.tcc": "c",
"cstdio": "c",
"array": "c",
"string_view": "c",
"initializer_list": "c",
"utility": "c",
"hookdll_interior_win32.h": "c",
"hookdll_interior_generic.h": "c"
}
}
60 changes: 56 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ programs). See "To-do and Known Issues". Perhaps solution based on
- [X] ~~Add ".bat" etc. extension (PATHEXT) when SearchPath()~~ Fixed in 0.4
- [ ] ~~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
- [ ] Try to fix `proxychains git clone https://...` under Cygwin
- [ ] ~~Try to fix `proxychains git clone https://...` under Cygwin~~ Use `-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, turn off `proxy_dns` in
0.4 fixes this)
Expand All @@ -158,19 +159,70 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License version 2 for more details.

You should have received a copy of the GNU General Public License
version 2 along with this program. If not, see
version 2 along with this program (COPYING). If not, see
<http://www.gnu.org/licenses/>.

## Uthash

https://github.com/troydhanson/uthash

This program contains uthash as a git submodule, which is published
under The 1-clause BSD License.
under The 1-clause BSD License:

```
Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

## Minhook

https://github.com/TsudaKageyu/minhook

This program contains minhook as a git submodule, which is published
under The 2-clause BSD License.
under The 2-clause BSD License:

```
MinHook - The Minimalistic API Hooking Library for x64/x86
Copyright (C) 2009-2017 Tsuda Kageyu.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
57 changes: 54 additions & 3 deletions README_zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,70 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License version 2 for more details.

You should have received a copy of the GNU General Public License
version 2 along with this program. If not, see
version 2 along with this program (COPYING). If not, see
<http://www.gnu.org/licenses/>.

## Uthash

https://github.com/troydhanson/uthash

This program contains uthash as a git submodule, which is published
under The 1-clause BSD License.
under The 1-clause BSD License:

```
Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

## Minhook

https://github.com/TsudaKageyu/minhook

This program contains minhook as a git submodule, which is published
under The 2-clause BSD License.
under The 2-clause BSD License:

```
MinHook - The Minimalistic API Hooking Library for x64/x86
Copyright (C) 2009-2017 Tsuda Kageyu.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
17 changes: 15 additions & 2 deletions cygwin-build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,21 @@ dist :
PXCH_VERSION=$$(gcc -dM -E - < ../include/version.h | grep PXCH_VERSION | sort | awk '{print $$3}' | head -c -1 | tr '\n' '.') ./dist.sh

install :
(install $(EXEC_PATH_RELEASE) $(PREFIX)/bin/proxychains.exe && install $(DLL_PATH_RELEASE) $(PREFIX)/bin/) || \
(install $(EXEC_PATH_DEBUG) $(PREFIX)/bin/proxychains.exe && install $(DLL_PATH_DEBUG) $(PREFIX)/bin/)
PXCH_VERSION=$$(gcc -dM -E - < ../include/version.h | grep PXCH_VERSION | sort | awk '{print $$3}' | head -c -1 | tr '\n' '.') ./dist.sh --install

install_legacy:
make release
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/

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/


rebuild : clean all
rebuildrelease : clean release
Expand Down
20 changes: 20 additions & 0 deletions cygwin-build/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,25 @@ zip -j ../../proxychains_"$PXCH_VERSION"_win32_x64d.zip ../COPYING ../README*.md
zip -j ../../proxychains_"$PXCH_VERSION"_win32_x64.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x64.exe ../win32_output/proxychains_hook_x64.dll ../win32_output/proxychains_hook_x86.dll ../win32_output/proxychains_remote_function_x64.bin ../win32_output/proxychains_remote_function_x86.bin
zip -j ../../proxychains_"$PXCH_VERSION"_win32_x86d.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x86d.exe ../win32_output/proxychains_hook_x86d.dll ../win32_output/proxychains_remote_function_x86d.bin
zip -j ../../proxychains_"$PXCH_VERSION"_win32_x86.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x86.exe ../win32_output/proxychains_hook_x86.dll ../win32_output/proxychains_remote_function_x86.bin

make release
if [ "$1" = "--install" ]; then
cp proxychains_x64.exe /bin/proxychains.exe
ln -sf /bin/proxychains.exe /bin/px.exe
cp cygproxychains_hook_x64.dll /bin/
cp proxychains_remote_function_*.bin /bin/
fi
zip -j ../../proxychains_"$PXCH_VERSION"_cygwin_x64.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64.exe cygproxychains_hook_x64.dll proxychains_remote_function_x64.bin

make debug
if [ "$1" = "--install" ]; then
cp proxychains_x64d.exe /bin/proxychainsd.exe
ln -sf /bin/proxychainsd.exe /bin/pxd.exe
cp cygproxychains_hook_x64d.dll /bin/
cp proxychains_remote_function_*.bin /bin/
fi
zip -j ../../proxychains_"$PXCH_VERSION"_cygwin_x64d.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64d.exe cygproxychains_hook_x64d.dll proxychains_remote_function_x64d.bin

if [ "$1" = "--install" ]; then
cmd /c windows_install.bat
fi
Binary file added cygwin-build/proxychains_remote_function_x64d.bin
Binary file not shown.
15 changes: 15 additions & 0 deletions cygwin-build/windows_install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
copy %cd%\..\win32_output\proxychains_x64.exe %USERPROFILE%\bin\proxychains.exe || pause
copy %cd%\..\win32_output\proxychains_x86.exe %USERPROFILE%\bin\proxychains32.exe || pause
copy %cd%\..\win32_output\proxychains_hook_x64.dll %USERPROFILE%\bin\ || pause
copy %cd%\..\win32_output\proxychains_hook_x86.dll %USERPROFILE%\bin\ || pause
copy %cd%\..\win32_output\proxychains_x64d.exe %USERPROFILE%\bin\proxychainsd.exe || pause
copy %cd%\..\win32_output\proxychains_x86d.exe %USERPROFILE%\bin\proxychains32d.exe || pause
copy %cd%\..\win32_output\proxychains_hook_x64d.dll %USERPROFILE%\bin\ || pause
copy %cd%\..\win32_output\proxychains_hook_x86d.dll %USERPROFILE%\bin\ || pause

copy %cd%\..\win32_output\proxychains_x64.exe %USERPROFILE%\bin\px.exe || pause
copy %cd%\..\win32_output\proxychains_x86.exe %USERPROFILE%\bin\px32.exe || pause
copy %cd%\..\win32_output\proxychains_x64d.exe %USERPROFILE%\bin\pxd.exe || pause
copy %cd%\..\win32_output\proxychains_x86d.exe %USERPROFILE%\bin\px32d.exe || pause

copy %cd%\..\win32_output\proxychains_remote_function_*.bin %USERPROFILE%\bin\ || pause
6 changes: 6 additions & 0 deletions include/function_pointers_configured.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define PXCH_ADDRESS_FreeLibrary 0x0
#define PXCH_ADDRESS_GetModuleHandleW 0x0
#define PXCH_ADDRESS_GetProcAddress 0x0
#define PXCH_ADDRESS_LoadLibraryW 0x0
#define PXCH_ADDRESS_GetLastError 0x0
#define PXCH_ADDRESS_OutputDebugStringA 0x0
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
#define PXCH_VERSION_MINOR 4
#endif
#ifndef PXCH_VERSION_PATCH
#define PXCH_VERSION_PATCH 0
#define PXCH_VERSION_PATCH 1
#endif
2 changes: 2 additions & 0 deletions src/dll/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ PXCH_DLL_API DWORD __stdcall InitHook(PXCH_INJECT_REMOTE_DATA* pRemoteData)

IPCLOGD(L"(In InitHook) g_pRemoteData->dwDebugDepth = " WPRDW, g_pRemoteData ? g_pRemoteData->dwDebugDepth : -1);

// ALL HOOKS MUST BE DONE HERE
// AFTER fork() RESTORES DATA SEGMENT, MINHOOK IS IN UNCERTAIN STATE
Win32HookWs2_32();
//CygwinHook();

Expand Down
22 changes: 2 additions & 20 deletions src/dll/hook_connect_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,26 +1049,8 @@ PROXY_FUNC2(Mswsock, ConnectEx)

PROXY_FUNC2(Ws2_32, WSAStartup)
{
int iReturn;
FUNCIPCLOGD(L"Ws2_32.dll WSAStartup() called");
iReturn = orig_fpWs2_32_WSAStartup(wVersionRequested, lpWSAData);
if (iReturn == 0) {
SOCKET DummySocket;
GUID GuidConnectEx = WSAID_CONNECTEX;
LPFN_CONNECTEX fpConnectEx = NULL;
DWORD cb;

DummySocket = socket(AF_INET, SOCK_STREAM, 0);
if (DummySocket == INVALID_SOCKET) goto out;
if (WSAIoctl(DummySocket, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidConnectEx, sizeof(GUID), &fpConnectEx, sizeof(LPFN_CONNECTEX), &cb, NULL, NULL) != 0) goto out;
if (!fpConnectEx) goto out;

CREATE_HOOK3_IFNOTNULL(Mswsock, ConnectEx, fpConnectEx);
MH_EnableHook(fpConnectEx);
}

out:
return iReturn;
// Not used
return 0;
}

// Hook WSAConnect
Expand Down
Loading

0 comments on commit 218411f

Please sign in to comment.