Skip to content

Commit

Permalink
安全性提升
Browse files Browse the repository at this point in the history
  • Loading branch information
lianglixin committed Mar 13, 2019
1 parent acf0822 commit 86a1dd2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions SKSocks-server/SKSocks-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,23 @@ class SKCommonApp
return close(toClose);
#endif
}

BOOL isIPLAN(const string ipstring)
{
istringstream st(ipstring);
int ip[2];
for (int i = 0; i < 2; i++)
{
string temp;
getline(st, temp, '.');
istringstream a(temp);
a >> ip[i];
}
if ((ip[0] == 10) || (ip[0] == 172 && ip[1] >= 16 && ip[1] <= 31) || (ip[0] == 192 && ip[1] == 168))
return TRUE;
else return FALSE;
}

public:
// 成员变量和函数声明
};
Expand Down Expand Up @@ -315,6 +332,14 @@ class SKServerApp:public SKCommonApp
* 建议添加IP过滤规则,防止恶意利用。
*/

if (isIPLAN(IPAddr))
{
#ifdef _DEBUG
cout << "禁止访问内网资源!" << CPPFAILED_INFO << endl;
#endif // _DEBUG
return INVALID_SOCKET;
}

int theFlagV6 = AF_INET;
if (isIPV6)theFlagV6 = AF_INET6;

Expand Down Expand Up @@ -375,6 +400,7 @@ class SKServerApp:public SKCommonApp

void AddUser(string UNAME, string PWD)
{
// 有空建议使用 非可逆加密 加密一下密码。
userMap[UNAME] = PWD;
}

Expand Down

0 comments on commit 86a1dd2

Please sign in to comment.