收藏本站
联系我们
设为首页


Linux区

 

windows文件保护机制

如果我们在win2000下运行任何过时的win32病毒,我们会发现一个讨厌的对话框,上面显示:

“一个受Windows保护的系统文件被替换,为了维持系统的稳定性,这个文件已经被恢复成正确的系统版本,如

果你的程序发生了错误,请联系微软帮助中心获得支持。”

Heh!Windows2000维护着一个被系统保护的文件的列表,并且忽略任何替换或修改这些文件的请求,同时显示

上面的信息。通过翻阅Windows2000 DDK文档,我们可以发现更多有关文件保护的信息,

“当SFP检测到一个受保护的系统文件被替换,它会还原这个系统文件。当一个在系统保护目录下的文件被更改

时,SFP收到一个目录变更通知并被激活,SFP收到这个通知之后,它将检测哪个文件被更改,如果这个文件是

受保护的,SFP将从某个目录文件中寻找这个文件的数字签名来判断它是否是正确的版本,如果这个文件的版本

不正确,系统将试着用dllcache目录中的一个文件来恢复它,如果dllcache中没有这个文件,系统将会从distrib

ution media中寻找一个替代文件.

查找注册表我们可以找到一些与SFP有关的键:

HKEY_LOCAL_MACHINE

\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

SfcBugcheck

SfcDisable

SfcQuota

SfcScan

SfcDisable这个键似乎就是我们所要找的,这个键值可以是FLASE (00h) 或者 TRUE (01h),现在让我们把它设

成TRUE

FUCK! 真倒霉,我们没能改变世界,SfcDisable的确可以禁用SFP,但是只有下次启动之后才能生效,最糟的是

,下次启动的时候,系统将跳出一个消息框通知用户SFP已被禁用,然后系统将重新激活SFP。

当我在Windows2000 bata 2 下工作时,我发现把 SfcDisable键值设成除00h和01h之外的数值(例如设置成04h

),可以防止系统在下次启动时显示警告对话框,这样很好。当系统重新激活SFP时,SFP将对受保护的文件进

行一次扫描,那个时候系统将警告我们哪些文件受到了修改。

当我写这篇文章的时候,Windows2000 beta 3 build 2072已经推出了,我没有预料到SFP的执行过程被大幅度

的更改了,因此让我们仔细的看看它的内部运行机制。

在查看WINLOGON.EXE 输入节的时候,我注意到以下描述符:

SFC.DLL

Hint/Name Table: 0001BA80

TimeDateStamp: FFFFFFFF

ForwarderChain: FFFFFFFF

First thunk RVA: 00001690

Ordn Name

1

2

SFC.DLL是一个包含了SFP运行期函数的动态链接库,让我们看看它提供了哪些API

exports table:

Name: sfc.dll

Characteristics: 00000000

TimeDateStamp: 37741427

Version: 0.00

Ordinal base: 00000001

# of functions: 0000000B

# of Names: 00000004

Entry Pt Ordn Name

0000743A 1

000073D2 2

00003D70 3

00003DA9 4

00003DB5 5

00003DED 6

00003E21 7

00003F0B 8 SfcGetNextProtectedFile

00003FA0 9 SfcIsFileProtected

00008D1D 10 SfcWLEventLogoff

00008C5A 11 SfcWLEventLogon

看了这一大堆另人厌烦的函数之后,我决定仔细研究SfcIsFileProtected这个API,当我们传递一个文件名给Sf

cIsFileProtected,它将告诉我们这个文件是否受到SFP的保护,让我们来看看下面这段C代码:

if ( SfcIsFileProtected( NULL, szFileName) == 0)

{

printf ( "Not protected.\n") ;

}

else

{

printf ( "Yes, its protected.\n") ;

}

通过使用这个API,我们可以防止操作系统的重要文件受到病毒的感染,并且病毒无法寄生在这些受保护的文件

上去感染其它的计算机,这可能是一种防止病毒感染的办法。。。我从没见过有什么软件站点提供Windows的计

算器程序下载: P

下面给出一些代码,演示SFC.DLL提供的一些API的用法

----------------------------------------------------------------------------------

GriYo / 29A

I'm not in the business...

...I am the business

哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪[win2k-sfp.txt]哪?

哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪[Sfc.c]哪?

//

// Sfc check

//

// A stupid but useful program to check if a file is protected

// by System File Protection

//

// Tested under Windows 2000 Professional Build 2128

//

// GriYo / 29A

//

#include "stdio.h"

#include <Windows.h>

#include <sfc.h>

int main( int argc, char* argv[])

{

OSVERSIONINFO VersionInformation ;

HMODULE hSFC ;

FARPROC a_SfcIsFileProtected ;

FARPROC a_SfcGetNextProtectedFile ;

WCHAR wszFileName[ MAX_PATH] ;

PROTECTED_FILE_DATA pfd ;

printf( "Sfp check by GriYo / 29A\n\n") ;

if ( argc > 2)

{

printf( "Usage:\n\n"

"%s <--- List protected files\n\n"

"or\n\n"

"%s /f:filename <--- Check if file is protected\n\n", argv[ 0], argv[ 0]) ;

return -1 ;

}

VersionInformation.dwOSVersionInfoSize = sizeof( OSVERSIONINFO) ;

if ( GetVersionEx( &VersionInformation) == 0)

{

printf( "Error: Api GetVersionEx() failed\n\n", argv[ 0]) ;

return -1 ;

}

if ( ( VersionInformation.dwPlatformId != VER_PLATFORM_WIN32_NT)

( VersionInformation.dwMajorVersion != 5))

{

printf( "Error: This program only runs under Windows 2000\n\n") ;

return -1 ;

}

if ( ( hSFC = LoadLibrary( "SFC.DLL")) == NULL)

{

printf( "Error: SFC.DLL not found\n\n", argv[ 0]) ;

return -1 ;

}

if ( argc == 2)

{

//

// SfcIsFileProtected

//

// [This is preliminary documentation and subject to change.]

//

// The SfcIsFileProtected function determines whether the specified

// file is protected. Applications should avoid replacing protected

// system files.

//

// BOOL WINAPI SfcIsFileProtected( IN HANDLE RpcHandle, // must be NULL

// IN LPCWSTR ProtFileName) ;

//

// Parameters:

//

// ProtFileName

//

// [in] Pointer to a string that specifies the name of the

// file.

//

// Return Value:

//

// If the file is protected, the return value is a nonzero

// value.

//

// If the file is not protected, the return value is zero.

//

// Requirements :

//

// Windows NT/2000: Requires Windows 2000.

// Windows 95/98: Unsupported.

// Windows CE: Unsupported.

// Header: Declared in sfc.h.

// Import Library: Use sfc.lib.

//

// See Also:

//

// SfcGetNextProtectedFile

//

if ( ( a_SfcIsFileProtected = GetProcAddress( hSFC, "SfcIsFileProtected")) == NULL)

{

FreeLibrary( hSFC) ;

printf( "Error: Api SfcIsFileProtected not found\n\n", argv[ 0]) ;

return -1 ;

}

MultiByteToWideChar(CP_ACP, 0, argv[ 1], -1, wszFileName, MAX_PATH) ;

if ( a_SfcIsFileProtected( NULL, wszFileName)) printf( "Protected file\n\n") ;

else printf( "Unprotected file\n\n") ;

}

else

{

//

// SfcGetNextProtectedFile

//

// [This is preliminary documentation and subject to change.]

//

// The SfcGetNextProtectedFile function retrieves the complete list of protected

// files. Applications should avoid replacing these files.

//

// BOOL WINAPI SfcGetNextProtectedFile( IN HANDLE RpcHandle, // must be NULL

// IN PPROTECTED_FILE_DATA ProtFileData) ;

//

// Parameters:

//

// ProtFileData [in/out] Receives the list of protected files. The format

// of this structure is as follows:

//

// typedef struct _PROTECTED_FILE_DATA {

// WCHAR FileName[ MAX_PATH] ;

// DWORD FileNumber ;

// } PROTECTED_FILE_DATA, *PPROTECTED_FILE_DATA ;

//

// Before calling this function the first time, set the FileNumber

// member to zero.

//

// Return Value:

//

// If the function succeeds, the return value is nonzero.

//

// If there are no more protected files to enumerate, the return value

// is zero.

//

// Requirements:

//

// Windows NT/2000: Requires Windows 2000.

// Windows 95/98: Unsupported.

// Windows CE: Unsupported.

// Header: Declared in sfc.h.

// Import Library: Use sfc.lib.

//

// See Also:

//

// SfcIsFileProtected

//

if ( ( a_SfcGetNextProtectedFile = GetProcAddress( hSFC, "SfcGetNextProtectedFile")) == NULL)

{

FreeLibrary( hSFC) ;

printf( "Error: Api SfcGetNextProtectedFile not found\n\n", argv[ 0]) ;

return -1 ;

}

printf( "List of protected files:\n\n") ;

pfd.FileNumber = 0 ;

while( SfcGetNextProtectedFile( NULL, &pfd) != 0)

{

printf( "%ws\n", &pfd.FileName) ;

}

}

FreeLibrary( hSFC) ;

return 0;

}

来源:http://www.pcjx.com/2-1/36026.html

 
Google

秋水轩由秋长水倾情制作  QQ:234626762  群:8184701