首页
社区
课程
招聘
[求助]关于ndis miniport hook的问题
发表于: 2014-3-2 01:53 4149

[求助]关于ndis miniport hook的问题

2014-3-2 01:53
4149
目前已对协议hook了
代码如下
发现只能勾住PtRecivice和PtRevicivePacket
怎么能才能勾住像passthru里面的MPSend和MPSendPacket呢
NTSTATUS HookNdis ()
{
	ULONG ulProtocolPtr;
	NDIS_HANDLE hFakeProtocol = NULL;
	PNDIS_OPEN_BLOCK pNdisOpenBlock = NULL;
	PNDIS_HOOK_LIST_NODE pNode;
	ULONG ulMagic = 0x10;  // Hardcoded offset. Only valid with NDIS 5.0, Windows XP.
	NTSTATUS status;
	PNDIS_MINIPORT_BLOCK pMini;

	// register a fake NDIS protocol in older to obtain a pointer to the NdisOpenBlock structure.
	//注册假协议获取链表头部
	hFakeProtocol = RegisterFakeNDISProtocol();
	

	if (hFakeProtocol == NULL)
		return STATUS_UNSUCCESSFUL;

	//ulProtocolPtr :NextProtocol     : Ptr32 _NDIS_PROTOCOL_BLOCK
	ulProtocolPtr = *(PULONG)((ULONG)hFakeProtocol + ulMagic);
	

	// traverse NDIS protocols to hook all the protocol routines.
	while (ulProtocolPtr != 0) 
	{
		pNdisOpenBlock = *(PNDIS_OPEN_BLOCK *)ulProtocolPtr;

		if (pNdisOpenBlock != NULL) 
		{

			pNode = (PNDIS_HOOK_LIST_NODE)ExAllocatePoolWithTag(NonPagedPool, sizeof(NDIS_HOOK_LIST_NODE), '!nmN');

			if (pNode != NULL) 
			{
				pNode->ProtocolBindingContext = pNdisOpenBlock->Reserved8;
				pNode->MacBindingHandle = pNdisOpenBlock->BindingHandle;
				pNode->pOpenBlock = pNdisOpenBlock;

				// Hook NDIS protocols

				pNode->ulRealReceiveHandler = (ULONG)InterlockedExchange((PLONG)&pNdisOpenBlock->ReceiveHandler, (LONG)FakeNDISReceiveHandler);
				// pNode->ulRealWanReceivePacketHandler = (ULONG)InterlockedExchange((PLONG)&pNdisOpenBlock->WanReceiveHandler, (LONG)FakeNDISWanReceivePacketHandler);
				pNode->ulRealProtocolReceiveHandler = (ULONG)InterlockedExchange((PLONG)&pNdisOpenBlock->ReceivePacketHandler, (LONG)FakeNDISProtocolReceiveHandler);
				pNode->ulRealTransferDataCompleteHandler = (ULONG)InterlockedExchange((PLONG)&pNdisOpenBlock->TransferDataCompleteHandler, (LONG)FakeNDISTransferDataCompleteHandler);

				ExInterlockedInsertTailList(&g_linkListHead, &pNode->ListEntry, &g_lock);
			}
		}
		ulProtocolPtr = ulProtocolPtr + ulMagic;
		ulProtocolPtr = *(PULONG)ulProtocolPtr;
	}

	// unregister the fake NDIS protocol.
	NdisDeregisterProtocol(&status, hFakeProtocol);

	return STATUS_SUCCESS;
}

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 233
活跃值: (285)
能力值: ( LV12,RANK:270 )
在线值:
发帖
回帖
粉丝
2
NDIS_OPEN_BLOCK  -> NDIS_MINIPORT_BLOCK -> NDIS_M_DRIVER_BLOCK -> NDIS51_MINIPORT_CHARACTERISTICS

大概是这个流程,具体变量偏移参照windbg。
2014-3-13 16:00
0
游客
登录 | 注册 方可回帖
返回
//