|
是否有办法不调用OpenProcess就可以直接得到句柄?
用上了google学习大法 转]一段精巧的代码~~ring3文件占坑大法 #include <windows.h> BOOL OccupyFile( LPCTSTR lpFileName ); int main() { OccupyFile("c:\\aaa111.txt"); return 0; } void RaiseToDebugP() { HANDLE hToken; HANDLE hProcess = GetCurrentProcess(); if ( OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) ) { TOKEN_PRIVILEGES tkp; if ( LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid) ) { tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; BOOL bREt = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0) ; } CloseHandle(hToken); } } BOOL OccupyFile( LPCTSTR lpFileName ) { BOOL bRet; RaiseToDebugP(); HANDLE hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, 4); // 4为system进程号 if ( hProcess == NULL ) { hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, 8); // 2K下是 8?? if ( hProcess == NULL ) return FALSE; } HANDLE hFile; HANDLE hTargetHandle; hFile = CreateFile( lpFileName, GENERIC_READ, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { CloseHandle( hProcess ); return FALSE; } bRet = DuplicateHandle( GetCurrentProcess(), hFile, hProcess, &hTargetHandle, 0, FALSE, DUPLICATE_SAME_ACCESS|DUPLICATE_CLOSE_SOURCE); CloseHandle( hProcess ); return bRet; } The DuplicateHandle function duplicates an object handle. The duplicate handle refers to the same object as the original handle.Therefore, any changes to the object are reflected through both handles.For example, the current file mark for a file handle is always the same for both handles. BOOL DuplicateHandle( HANDLE hSourceProcessHandle, // handle to source process HANDLE hSourceHandle, // handle to duplicate HANDLE hTargetProcessHandle, // handle to target process LPHANDLE lpTargetHandle, // duplicate handle DWORD dwDesiredAccess, // requested access BOOL bInheritHandle, // handle inheritance option DWORD dwOptions // optional actions ); hTargetProcessHandle Handle to the process that is to receive the duplicated handle. The handle must have PROCESS_DUP_HANDLE access. ============== 其实就是把该文件的句柄(真正的句柄)复制给了system进程。更详细的东西可以查看windows programming application。 ============== 函数比较: GetCurrentProcess(): GetCurrentProcess得到得到的称之为"伪句柄" 只是一个标识,你可以发现,其实就是返回$FFFFFFFF, 每个进程得句柄都是一样得,只是实用于进程内部得使用. 如果你想得到实际得句柄,在进程间进行通讯,必需要进行转化, 调用DuplicateHandle,注意,得实句柄使用完成以后,你必须要调用CloseHandle去关闭. 其实,你应该明白了为何"伪句柄"得存在,就是使用简单,不用关闭, 不会造成内存泄漏. 同样道理,GetCurrentThread也是伪句柄,其值永远是$FFFFFFFE,只是适用于线程内部得使用. DuplicateHandle() : 在系统中,对象分两类:核心对象和用户对象.如进程对象,线程对象,文件映射 对象等就是核心对象;而向窗口,菜单等都是用户对象. 两者是有差别的,用于标示用户对象的句柄是系统唯一的,也就是说,一个进程 完全可以对另外一个进程中的用户对象进行操作,比如两个进程间通信的方法之一, 就是发送消息.正是由于窗口是用户对象,所以句柄是系统唯一,通过FindWindow(), 得到另外一个进程的窗口句柄,然后用SendMessage(),让hWnd的窗口过程来处理消 息,实现了进程间的通信.因此,对于用户对象,你根本不用DuplicateHandle(),直接 把句柄拿来用就行了. 而核心对象则不一样.核心对象是为了加强系统的稳定性,因此,核心对象句柄是 进程相关的,在每一个进程中都有一个核心对象表,每一个对象的索引(不完全是)作为内和对象的句柄,从而实现进程相关.同一个对象在不同的进程中可能有不同的索引,即句柄.对核心对象进行操作时,系统还要进行安全检验,看一下你是否有权来操作这个对象.因此你不能同用户对象一样,直接把句柄拿过来用.比方说,你想操作另一个进程中的文件映射对象,这个文件映射对象句柄在那个进程中假设是0x000001,但在你的进程中,很有可能0x00000001时表示另一个核心对象,此时的操作就永远不会成功,甚至会产生灾难性的后果.此时,就有必要用DuplicateHandle(). =========================================== 问题:如果要抹掉句柄,该怎么做?因为听说有些防外挂就是采用这样的技术; 复制句柄到system进程后,会有什么情况发生? |
|
[求助]请教各位:安装360安全卫士后,不能恢复SSDT了
恢复SSDT,太难了,我在装了NOD32后,发现有6个函数被HOOK到hal.dll里,当时以为是木马,找了非常多的(冰刃,wsyscheck,rkunhooker...),都不能恢复,技术太高了。 |
|
|
|
[求助]用DELPHI写PE感染修复工具
谢谢回帖,有被感染而不能修复的,如果能判断一下,可能更好,只是这方面没找到方法 还有,如果不用手动操作的话,岂不是更好,只是处理附加数据要从结尾往前搜索到00区域,然后计算rsize的大小,颇为难人。 这个工具是在serverx出台之后,受教了。 |
|
|
|
[原创]世界上最小的下载者,qihoocom来鄙视我吧 - 申精
看大牛的代码看得我头晕脑胀,还是看这个好 |
|
|
|
[原创][公开源代码]集合了无数大牛们的代码,打造自己的山寨版IceSword(KsBinSword)
仿WINHEX功能那块,驱动读的全都是0,是不是这块功能没做完?我是准备用来答360那个题的。 |
|
|
|
[原创]我自己写的一个PE编辑器(附源码:VC6.0)
建议大家都写一下,此是作业 |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值