Skip to content

Commit

Permalink
fix: correct PXCH_CONFIG_EXTRA_SIZE calc, preventing possible crash;
Browse files Browse the repository at this point in the history
releasing 0.4.2
  • Loading branch information
shunf4 committed Feb 28, 2020
1 parent 1db85ff commit 449819a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,6 @@ cygwin-build/**/*.lib
cygwin-build/**/MAKING_*
cygwin-build/**/distx*
cygwin-build/**/*.stackdump
cygwin-build/**/*.bin
win32_output/
include/function_pointers_configured.h
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ 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~~ Use `-q` in 0.4.1
reduces the probability to happen
- [ ] ~~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, turn off `proxy_dns` in
0.4 fixes this)
- [ ] Resolve race condition in `FormatHostPortToStr()`

# Licensing

Expand Down
Binary file removed cygwin-build/proxychains_remote_function_x64d.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions include/defines_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ typedef struct _PXCH_HOSTS_ENTRY {


#define PXCH_CONFIG_EXTRA_SIZE_G PXCH_CONFIG_EXTRA_SIZE(g_pPxchConfig)
#define PXCH_CONFIG_EXTRA_SIZE_BY_N(proxyNum, ruleNum, hostsEntryNum, remoteFuncX64SizeInBytes, remoteFuncX86SizeInBytes) ((sizeof(PXCH_RULE) * ruleNum) + (sizeof(PXCH_PROXY_DATA) * proxyNum) + (sizeof(PXCH_HOSTS_ENTRY) * hostsEntryNum) + remoteFuncX64SizeInBytes + remoteFuncX86SizeInBytes)
#define PXCH_CONFIG_EXTRA_SIZE(pPxchConfig) PXCH_CONFIG_EXTRA_SIZE_BY_N((pPxchConfig)->dwRuleNum, (pPxchConfig)->dwProxyNum, (pPxchConfig)->dwHostsEntryNum, (pPxchConfig)->cbRemoteFuncX64Size, (pPxchConfig)->cbRemoteFuncX86Size)
#define PXCH_CONFIG_EXTRA_SIZE_BY_N(proxyNum, ruleNum, hostsEntryNum, remoteFuncX64SizeInBytes, remoteFuncX86SizeInBytes) ((sizeof(PXCH_PROXY_DATA) * proxyNum) + (sizeof(PXCH_RULE) * ruleNum) + (sizeof(PXCH_HOSTS_ENTRY) * hostsEntryNum) + remoteFuncX64SizeInBytes + remoteFuncX86SizeInBytes)
#define PXCH_CONFIG_EXTRA_SIZE(pPxchConfig) PXCH_CONFIG_EXTRA_SIZE_BY_N((pPxchConfig)->dwProxyNum, (pPxchConfig)->dwRuleNum, (pPxchConfig)->dwHostsEntryNum, (pPxchConfig)->cbRemoteFuncX64Size, (pPxchConfig)->cbRemoteFuncX86Size)

#define PXCH_CONFIG_PROXY_ARR(pPxchConfig) ((PXCH_PROXY_DATA*)((char*)(pPxchConfig) + pPxchConfig->cbProxyListOffset))
#define PXCH_CONFIG_RULE_ARR(pPxchConfig) ((PXCH_RULE*)((char*)(pPxchConfig) + pPxchConfig->cbRuleListOffset))
Expand Down
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 1
#define PXCH_VERSION_PATCH 2
#endif
50 changes: 26 additions & 24 deletions src/exe/args_and_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,26 @@ void PrintConfiguration(PROXYCHAINS_CONFIG* pPxchConfig)
default: pszTargetDesc = L"???"; break;
}
LOGD(L"DefaultTarget: %ls", pszTargetDesc);
LOGD(L"sizeof(PROXYCHAINS_CONFIG): %lu", (unsigned long)(sizeof(PROXYCHAINS_CONFIG)));
LOGD(L"");
LOGD(L"[RuleList] " WPRDW L", Offset " WPRDW, pPxchConfig->dwRuleNum, pPxchConfig->cbRuleListOffset);

LOGD(L"[ProxyList] Offset: " WPRDW L", sizeof(): " WPRDW L", Length: " WPRDW, pPxchConfig->cbProxyListOffset, (DWORD)(sizeof(PXCH_PROXY_DATA)), pPxchConfig->dwProxyNum);
arrProxy = PXCH_CONFIG_PROXY_ARR(pPxchConfig);
for (dw = 0; dw < pPxchConfig->dwProxyNum; dw++) {
switch (arrProxy[dw].dwTag) {
case PXCH_PROXY_TYPE_INVALID: pszTagDesc = L"INVALID"; break;
case PXCH_PROXY_TYPE_SOCKS5: pszTagDesc = L"SOCKS5"; break;
case PXCH_PROXY_TYPE_DIRECT: pszTagDesc = L"DIRECT"; break;
default: pszTagDesc = L"???"; break;
}

if (ProxyIsType(SOCKS5, arrProxy[dw])) {
LOGD(L"[" WPRDW L"] <%ls> %ls(%d) " WPRS L" " WPRS L" %ls %ls", dw, pszTagDesc, FormatHostPortToStr(&arrProxy[dw].CommonHeader.HostPort, arrProxy[dw].CommonHeader.iAddrLen), arrProxy[dw].CommonHeader.iAddrLen, arrProxy[dw].CommonHeader.Ws2_32_ConnectFunctionName, arrProxy[dw].CommonHeader.Ws2_32_HandshakeFunctionName, arrProxy[dw].Socks5.szUsername, arrProxy[dw].Socks5.szPassword);
}
}
LOGD(L"");

LOGD(L"[RuleList] Offset: " WPRDW L", sizeof(): " WPRDW L", Length: " WPRDW, pPxchConfig->cbRuleListOffset, (DWORD)(sizeof(PXCH_RULE)), pPxchConfig->dwRuleNum);
arrRule = PXCH_CONFIG_RULE_ARR(pPxchConfig);
for (dw = 0; dw < pPxchConfig->dwRuleNum; dw++) {
switch (arrRule[dw].dwTag) {
Expand All @@ -491,33 +509,17 @@ void PrintConfiguration(PROXYCHAINS_CONFIG* pPxchConfig)
LOGD(L"[" WPRDW L"] <%ls> %ls/" WPRDW L" -> %ls", dw, pszTagDesc, FormatHostPortToStr(&arrRule[dw].HostPort, sizeof(PXCH_IP_ADDRESS)), arrRule[dw].dwCidrPrefixLength, pszTargetDesc);
}
LOGD(L"");
LOGD(L"[ProxyList] " WPRDW L", Offset " WPRDW, pPxchConfig->dwProxyNum, pPxchConfig->cbProxyListOffset);
arrProxy = PXCH_CONFIG_PROXY_ARR(pPxchConfig);
for (dw = 0; dw < pPxchConfig->dwProxyNum; dw++) {
switch (arrProxy[dw].dwTag) {
case PXCH_PROXY_TYPE_INVALID: pszTagDesc = L"INVALID"; break;
case PXCH_PROXY_TYPE_SOCKS5: pszTagDesc = L"SOCKS5"; break;
case PXCH_PROXY_TYPE_DIRECT: pszTagDesc = L"DIRECT"; break;
default: pszTagDesc = L"???"; break;
}

switch (arrRule[dw].dwTarget) {
case PXCH_RULE_TARGET_BLOCK: pszTargetDesc = L"BLOCK"; break;
case PXCH_RULE_TARGET_DIRECT: pszTargetDesc = L"DIRECT"; break;
case PXCH_RULE_TARGET_PROXY: pszTargetDesc = L"PROXY"; break;
default: pszTargetDesc = L"???"; break;
}

if (ProxyIsType(SOCKS5, arrProxy[dw])) {
LOGD(L"[" WPRDW L"] <%ls> %ls(%d) " WPRS L" " WPRS L" %ls %ls", dw, pszTagDesc, FormatHostPortToStr(&arrProxy[dw].CommonHeader.HostPort, arrProxy[dw].CommonHeader.iAddrLen), arrProxy[dw].CommonHeader.iAddrLen, arrProxy[dw].CommonHeader.Ws2_32_ConnectFunctionName, arrProxy[dw].CommonHeader.Ws2_32_HandshakeFunctionName, arrProxy[dw].Socks5.szUsername, arrProxy[dw].Socks5.szPassword);
}
}
LOGD(L"");
LOGD(L"[HostsEntry] " WPRDW L", Offset " WPRDW, pPxchConfig->dwHostsEntryNum, pPxchConfig->cbHostsEntryListOffset);

LOGD(L"[HostsEntry] Offset: " WPRDW L", sizeof(): " WPRDW L", Length: " WPRDW, pPxchConfig->cbHostsEntryListOffset, (DWORD)(sizeof(PXCH_HOSTS_ENTRY)), pPxchConfig->dwHostsEntryNum);
arrHostsEntry = PXCH_CONFIG_HOSTS_ENTRY_ARR(pPxchConfig);
for (dw = 0; dw < pPxchConfig->dwHostsEntryNum; dw++) {
LOGD(L"[" WPRDW L"] %ls %ls", dw, arrHostsEntry[dw].Hostname.szValue, FormatHostPortToStr(&arrHostsEntry[dw].Ip, sizeof(PXCH_IP_ADDRESS)));
}
LOGD(L"");

LOGD(L"RemoteFuncX64 Offset: " WPRDW L", Size: " WPRDW, pPxchConfig->cbRemoteFuncX64Offset, pPxchConfig->cbRemoteFuncX64Size);
LOGD(L"RemoteFuncX86 Offset: " WPRDW L", Size: " WPRDW, pPxchConfig->cbRemoteFuncX86Offset, pPxchConfig->cbRemoteFuncX86Size);
LOGD(L"PXCH_CONFIG_EXTRA_SIZE_G: " WPRDW, PXCH_CONFIG_EXTRA_SIZE_G);
}

DWORD LoadConfiguration(PROXYCHAINS_CONFIG** ppPxchConfig, PROXYCHAINS_CONFIG* pTempPxchConfig)
Expand Down

0 comments on commit 449819a

Please sign in to comment.