-
Notifications
You must be signed in to change notification settings - Fork 8
/
CryptIt.cpp
172 lines (146 loc) · 4.44 KB
/
CryptIt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "NetBind.h"
#include "CryptIt.h"
#include "Configure.h"
#include "Xor.h"
#include "LogFilePort.h"
#include <vector>
std::vector<int> g_xSocket;
//std::vector<int> g_nSocket;
extern CONFIGURE_STRUCT g_Configure;
CRITICAL_SECTION g_SockX = {0};
//fp_send g_pMySend = NULL;
//fp_recv g_pMyRecv = NULL;
//fp_connect g_pConnect = NULL;
#ifdef _WIN32
typedef int (__stdcall * fp_send)(IN SOCKET s, const char FAR * buf, IN int len, IN int flags);
typedef int (__stdcall * fp_recv)(IN SOCKET s, char FAR * buf, IN int len, IN int flags);
typedef int (__stdcall * fp_connect)(IN SOCKET s, const struct sockaddr FAR * name, IN int namelen);
DECLARE_DETOURE( fp_send, send );
DECLARE_DETOURE( fp_recv, recv );
DECLARE_DETOURE( fp_connect, connect );
#elif _LINUX
#endif
void SetSockToXList(int s)
{
XLOGI("Entry SetSockToXList");
EnterCriticalSection(&g_SockX);
g_xSocket.push_back(s);
LeaveCriticalSection(&g_SockX);
XLOGI("Leave SetSockToXList");
}
void DeleteSockFromXList(int s)
{
XLOGI("Entry DeleteSockFromXList");
EnterCriticalSection(&g_SockX);
for (std::vector<int>::iterator i = g_xSocket.begin(); i < g_xSocket.end(); i++)
{
if (s == *i)
{
g_xSocket.erase(i);
LeaveCriticalSection(&g_SockX);
XLOGI("Erase socket and Leave DeleteSockFromXList");
return;
}
}
LeaveCriticalSection(&g_SockX);
XLOGI("Leave SetSockToXList");
}
bool FindXSocket( int s )
{
EnterCriticalSection(&g_SockX);
for (std::vector<int>::iterator i = g_xSocket.begin(); i < g_xSocket.end(); i++)
{
if (s == *i)
{
LeaveCriticalSection(&g_SockX);
return true;
}
}
LeaveCriticalSection(&g_SockX);
return false;
}
//////////////////////////////////////////////////////////////////////////
int __stdcall DECLARE_DETOURE_FUN(send)(IN SOCKET s, const char FAR * buf, IN int len, IN int flags)
{
int ret = 0;
XLOGI("send to Length:%d bytes -> 0x%4X, password = 0x%4X", len, (int)s, g_Configure.dwCrc32Password);
if ((g_Configure.bHashX == TRUE) &&
(g_Configure.bSock5Proxy == FALSE))
{
if (FindXSocket((int)s) == TRUE)
{
//XLOGI("send crypt data size = %d", len);
//ret = CALL_ORIGINAL(send)(s, (char *)&len, 4, flags);
//if (ret <= 0) return ret;
XLOGI("send crypt data");
XorArrayForArray(g_Configure.dwCrc32Password, (unsigned char*)buf, (unsigned char*)buf, len);
ret = CALL_ORIGINAL(send)(s, buf, len, flags);
return ret;
}
}
// Èç¹û²»¼ÓÃÜÔòÖ±½Ó·¢ËÍ
ret = CALL_ORIGINAL(send)(s, buf, len, flags);
return ret;
}
int __stdcall DECLARE_DETOURE_FUN(recv)(IN SOCKET s, char FAR * buf, IN int len, IN int flags)
{
int ret = 0;
XLOGI("recv from 0x%4X, password = 0x%4X", (int)s, g_Configure.dwCrc32Password);
// Èç¹ûÊÇÒª¼ÓÃܵÄÌ×½Ó×ÖÔòÔÚÕâÀï°ÑËùÓаü¶¼»º³åÍê±Ï
if ((g_Configure.bHashX == TRUE) && (
g_Configure.bSock5Proxy == FALSE))
{
// Èç¹û´ËÌ×½Ó×ÖÒª½øÐмÓÃÜ
if (FindXSocket((int)s) == TRUE)
{
XLOGI("crypt recv data");
// Ê×ÏȽÓÊÕ°ü³¤¶È
//int psize = 0;
//ret = CALL_ORIGINAL(recv)(s, (char *)&psize, 4, flags);
//if (ret <= 0) return ret;
//int getsize = 0;
//char *tmp = (char *)malloc(MAXSIZE);
// ÔÚÕâÀﻺ´æËùÓаü
//while (psize > 0)
//{
// ret = CALL_ORIGINAL(recv)(s, tmp+getsize, MAXSIZE-getsize, flags);
// if (ret <= 0) {
// free(tmp);
// return ret;
// }
// psize -= getsize;
//}
// ½øÐмӽâÃÜ
ret = CALL_ORIGINAL(recv)(s, buf, len, flags);
XorArrayForArray(g_Configure.dwCrc32Password, (unsigned char*)buf, (unsigned char*)buf, len);
return ret;
//free(tmp);
//return psize;
}
}
// Èç¹û¼ÓÃÜûÓпªÆôµÄ»°
ret = CALL_ORIGINAL(recv)(s, buf, len, flags);
return ret;
}
int __stdcall DECLARE_DETOURE_FUN(connect)(IN SOCKET s, const struct sockaddr FAR * name, IN int namelen)
{
XLOGI("Entry connect");
int ret = CALL_ORIGINAL(connect)(s, name, namelen);
XLOGI("Level connect, return value = %d, error = %d", ret, WSAGetLastError());
return ret;
}
unsigned long GetCurrAddress( void *pAddress )
{
unsigned long ret = 0;
unsigned long *pCurr = (unsigned long *)pAddress;
if (*(char *)pCurr == 0xE9)// Ò»¸öÔ¶Ìø
{
}
Return ret;
}
void InstallCrypt()
{
INSTALL_DETOURE( send );
INSTALL_DETOURE( recv );
INSTALL_DETOURE( connect );
}