NDIS and TDI Hooking, Part II

《光学》全套PPT课件(安徽大学) 立即下载
By: andreas

 

This is the second and last article on how to hook into the NDIS and TDI
layer. The approach we will use will be slightly different from the NDIS
case. However, a neat side effect is that this method can be used to hook
into any device chain, for example the keyboard to sniff key strokes. It all boils down to getting a pointer to the device object and replace all major functions with our own dispatch function.

To be able to fully control the TDI layer, we need access to the IRP both
before and after the original driver has processed it. If we have that, we
can choose what the original driver should process and we can also alter
results before they are returned to user-space. The "before filtering" can
be accomplished in our own, new dispatch function and the "after filtering" can be accomplished in a completion routine.

First, to be able to overwrite and insert our own dispatch function, we need a pointer to the driver object we are going to hook into. An easy way to get this pointer is to call ObReferenceObjectByName with the appropriate driver name. Then we only have to save all old function pointers and overwrite the existing ones with our own. The code to do this would look something like the following:


DRIVER_OBJECT RealTDIDriverObject;

NTSTATUS HookTDI(void)
{
    NTSTATUS Status;
    UNICODE_STRING usDriverName;
    PDRIVER_OBJECT DriverObjectToHookPtr;
    UINT i;



    RtlInitUnicodeString(&usDriverName,L"//Driver//Tcpip");

    Status =
ObReferenceObjectByName(&usDriverName,OBJ_CASE_INSENSITIVE,NULL,0,IoDriverObjectType,KernelMode,NULL,&DriverObjectToHookPtr);
    if(Status != STATUS_SUCCESS) return Status;

    for(i = 0;i < IRP_MJ_MAXIMUM_FUNCTION;i++) {
        RealTDIDriverObject.MajorFunction[i] =
DriverObjectToHookPtr->MajorFunction[i];
        DriverObjectToHookPtr->MajorFunction[i] = TDIDeviceDispatch;
    }

    return STATUS_SUCCESS;
}




RealTDIDriverObject is a DRIVER_OBJECT where we save the original
information to both be able to call the old functions and also be able to
unhook once we are done. The orignal driver gets all its major functions
overwritten with a pointer to our own dispatch function, TDIDeviceDispatch.

We now have control over the IRPs before TDI can process them. But, we still have to make sure we can also control them once TDI is done with it but before it is returned to the IO handler and user-space. We will solve this in our dispatch function with the help of a completion routine. It is not as straight forward as it sounds, since we might be hooking the last entity in the chain, we can't just insert a completion routine with
IoSetCompletionRoutine (see the DDK docs), since it in that case never will be called. Completion routines are set in the next IRP stack location, not the current. If we are the last entity, there will be no next stack location in the IRP. Searching through the header files reveal IoSetCompletionRoutine as a macro which only gets the next IRP stack location and sets the CompletionRoutine pointer together with the Control element. Following the same principcal, we can set our own completion routine to regain control over the IRP with the following dispach function:


NTSTATUS TDIDeviceDispatch(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
{
    NTSTATUS Status;
    PIO_STACK_LOCATION StackLocationPtr;

    if(Irp == NULL) return STATUS_SUCCESS;

    StackLocationPtr = IoGetCurrentIrpStackLocation(Irp);
    if(StackLocationPtr->CompletionRoutine != NULL) StackLocationPtr->Context =
StackLocationPtr->CompletionRoutine;
    else StackLocationPtr->Context = NULL;
    StackLocationPtr->CompletionRoutine =
(PIO_COMPLETION_ROUTINE)TDICompletionRoutine;
    StackLocationPtr->Control = SL_INVOKE_ON_SUCCESS | SL_INVOKE_ON_ERROR |
SL_INVOKE_ON_CANCEL;

    Status =
RealTDIDriverObject.MajorFunction[StackLocationPtr->MajorFunction](DeviceObject,Irp);

    return Status;
}


What we actually do is faking a scenario where the layer above set the
completion routine for us. We also save a potentially already existing
completion routine in the Context element of the IRP. Control is set to
invoke the completion routine in all cases. There are 2 potential issues
with this code. First, we overwrite whatever is in the Context element.
Second, we never save the Control element, so we don't know when to invoke
an already existing completion routine. So far, I have not seen any
side-effects from doing this.

The completion routine would look something like:


NTSTATUS TDICompletionRoutine(PDEVICE_OBJECT DeviceObject,PIRP Irp,PVOID
Context)
{
    COMPLETIONROUTINE RealCompletionRoutine = (COMPLETIONROUTINE)Context;

    if(Context != NULL) return RealCompletionRoutine(DeviceObject,Irp,NULL);
    else return STATUS_SUCCESS;
}


It invokes a potential completion routine as soon as it is done and returns the status from it. Finally, unhooking the driver is just a question of restoring the pointers we overwrote in the hooking function:


NTSTATUS ReleaseTDIDevices(void)
{
    NTSTATUS Status;
    UNICODE_STRING usDriverName;
    PDRIVER_OBJECT DriverObjectToHookPtr;
    UINT i;

    RtlInitUnicodeString(&usDriverName,L"//Driver//Tcpip");

    Status =
ObReferenceObjectByName(&usDriverName,OBJ_CASE_INSENSITIVE,NULL,0,IoDriverObjectType,KernelMode,NULL,&DriverObjectToHookPtr);
    if(Status != STATUS_SUCCESS) return Status;

    for(i = 0;i < IRP_MJ_MAXIMUM_FUNCTION;i++)
        DriverObjectToHookPtr->MajorFunction[i] =
RealTDIDriverObject.MajorFunction[i];

    return STATUS_SUCCESS;
}



There is another way to accomplish the same result which utilizes a more
offically supported mode of operation. It is based upon attaching to the
device chain with GetDeviceObject and AttachToDevice, which will allow us to process all IRPs before the real device. Once in the dispatch function we contruct a new IRP and add a completion routine to regain control of the IRP before it is returned to the IO system and user-space.

One last important thing to mention; This code is quite untested. It seems
to work as intended but it has never been used in any major applications, so use it on your own risk. With that said, hope you have enjoyed this little article series.
YOLO26算法婴幼儿面部情绪识别目标检测+训练好的模型+2681张数据集+pyqt可视化界面.zip 附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[哭泣(crying), 开心(happy)] · 总计:2681 张 · 测试集:186 张 · 验证集:0 张 · 训练集:2495 张 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 100 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.8069** mAP50-95 | 0.5664 Precision | 0.8700 Recall | 0.7726 train/box_loss | 0.7524 train/cls_loss | 0.4490 val/box_loss | 1.1351 val/cls_loss | 0.7588 【训练过程分析】 训练伊始,模型对 box_loss 和 cls_loss 的下降表现出惊人的效率,前 20 轮迅速将训练损失降至低位,显示了训练集的强大适应性。然而,在第 20 轮之后,loss 下降速度明显放缓,整体趋于平稳。到了 60 轮左右,box_loss 值逐渐接近 0.75,而 cls_loss 则稳定在 0.44 左右。从训练集的 box_loss 从 0.7524 降至 0.7325,能看出来 model 正在逐步优化每个实例的边界框准确性,这一过程在前 40 轮尤为显著。相比之下,cls_loss 从 0.4490 降至 0.4389,尽管变化不大,但整体上表现出了模型对类别的清晰度提升... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。 立即下载

相关推荐

依赖专家资源的传统机构与依赖数据算法的现代平台,在转化效率上谁更胜一筹?.docx

依赖专家资源的传统机构与依赖数据算法的现代平台,在转化效率上谁更胜一筹?

利用 TDI HOOK 实现任意端口复用

所谓tdi hook,我这里利用的是hook tcpip dispatch table的方法,实际上复用的原理很简单,关键是hook掉tdi_event_connect,之后从*AcceptIrp中取出conn obj,将其传递到自己定义的tdisend中就可以了。这里唯一蹩脚的地方是在处理TDI EVENT的时候,当进程启动后,它首先系统注册这些event handler,在有相应的网络事件发生

白日梦 4480

PostgreSQL 数据库辅助类(要求 Npgsql 7.0 及以上) .NET Framework 4.7.2+ 或 .NET 6+;C# 7.3+

类别 :方法 数据源: Initialize、Close、DataSource、ConfigureBuilder、CommandTimeout、OnSqlExecuted 参数: CreateParameter(含类型版)、CreateJsonbParameter、CreateArrayParameter、ParamsFrom 执行: ExecuteNonQuery、ExecuteScalar<T>、ExecuteDataTable、ExecuteDataSet、ExecuteList<T>、ExecuteModel<T>、ExecuteDictionaryList、ExecuteColumn<T>、ExecuteReader(均有异步版) 封装: Exists、Count、ExecutePagedDataTable/List、Insert、Update、Delete、Upsert、TableExists、ColumnExists、GetTableNames、GetServerVersion、TestConnection 数据库对象: ExecuteFunctionTable/Scalar、CallProcedure 批量: ExecuteBatch(NpgsqlBatch)、BulkInsert(二进制 COPY)、CopyOut、ToDataTable 事务: ExecuteInTransaction(Async)、OpenTransaction(Async) 其他: Notify、ListenAsync、PgRetry(只读、显式调用)

实用级反主动防御rootkit设计思路[转载]

有兴在这次x'con交流会上认识白远方兄弟,这是他很早前写的文章,提到了很多东西,保存一下。 作者:白远方 (ID: baiyuanfan, baiyuanfan@163.com, baiyuanfan@hotmail.com)June 18, 2007关键字:rootkit,反主动防御,网络监控,ring0,mcafee8.5i,KIS6,ZoneAlarm Pro,实用级产品测试目录...

weixin_30826761的博客 197

知识管理四款团队知识库选型对比:Confluence、OmniBox、语雀、Sward适用场景与部署方案分析

内容概要:本文对2026年主流的四款团队知识库工具Confluence、小黑OmniBox、语雀和Sward进行了横向评测,指出这四款产品并非直接竞争关系,而是分别对应不同组织状态下的解决方案。评测围绕部署方式、权限协作、检索与AI能力三大核心维度展开,强调选型不应仅看功能列表,而应关注资料来源、使用场景与团队特征。Confluence适合已有Atlassian体系的中大型企业,强在权限控制与流程治理;小黑OmniBox聚焦多源资料整合与AI问答,适用于资料分散的团队;语雀以“书本式”结构降低中文团队使用门槛;Sward则主打开源私有化部署,满足内网合规需求。文章最后提供四类典型团队的选型路径,并澄清了“AI万能”“私有化即安全”等常见误区。; 适合人群:企业IT负责人、技术管理者、知识管理相关从业者,尤其是面临知识库选型决策的团队领导者。; 使用场景及目标:①帮助团队根据自身规模、技术栈、数据主权要求和协作习惯选择合适知识库工具;②厘清AI与知识库的关系,避免选型误区;③指导已有系统如何与新工具(如OmniBox)叠加使用,提升知识利用率。; 阅读建议:此评测基于公开资料与产品文档,未进行压力测试或大规模实测,建议结合实际业务场景试用验证,并优先考虑现有系统兼容性与迁移成本。

基于深度学习分类的时相关MIMO信道的递归CSI量化(Matlab代码实现)

内容概要:本文系统阐述了基于深度学习分类的时相关MIMO信道递归CSI量化方法,并提供了完整的Matlab代码实现。该方法针对大规模MIMO系统中因信道状态信息(CSI)反馈开销过大而导致的系统效率下降问题,提出一种结合深度学习与递归结构的量化方案,利用分类网络对时域相关的CSI进行高效压缩,通过递归机制捕捉信道动态的时间连续性特征,显著提升了量化精度与频谱利用率。文中详细介绍了算法设计原理、神经网络架构选型、训练策略设计、损失函数构建及仿真验证流程,展示了在不同信道模型与时变条件下相较于传统量化方法的性能优势。; 适合人群:具备通信工程、信号处理或无线通信领域基础知识,熟悉MIMO系统原理与深度学习基本模型(如RNN、CNN)的研究生、科研人员及工程师,尤其适合从事智能通信、信道建模、CSI反馈优化等相关方向的研究者。; 使用场景及目标:①应用于大规模MIMO和5G/6G系统中的CSI反馈压缩与传输优化;②为时变无线信道环境下的高效信道量化提供基于深度学习的智能化解决方案;③支持科研复现实验,促进先进信号处理技术在通信系统中的融合与创新; 阅读建议:建议读者结合提供的Matlab代码逐模块调试运行,深入理解深度学习模型在信道量化任务中的输入输出设计、网络训练流程与性能评估方式,可尝试在不同信道参数(如多普勒频移、SNR)下进行仿真实验以验证算法鲁棒性与泛化能力。

FSD键盘钩子框架参考爱写驱动的女装大佬

环境:vs2013+wdk8.1 #include <ntddk.h> extern POBJECT_TYPE *IoDriverObjectType; PDRIVER_OBJECT kbdriver = NULL; typedef NTSTATUS(*pBeforeRead)(PDEVICE_OBJECT pDevice, PIRP pIrp); pBeforeRead Befo...

Cosmopolitan的博客 494

konica C368(柯尼卡美能达bizhub C368系列打印机驱动)

1、查看本机 IP,确保电脑和复印机在同一个局域网。 2、安装时 右键以管理员运行 ,旧驱动先卸载干净避免冲突。 3、端口默认:9100(RAW),也可用 LPR。 安装方法: 1. 解压后进入文件夹,64 位运行 `Setup64.exe`,32 位运行 `Setup.exe`。 2. 同意协议 → 选择【安装(网络搜索)】,程序自动扫描局域网内 C368P。 3. 在列表选中对应 IP 的机器,下一步;如果扫不到,切换到【手动设置】,填入复印机 IP。 4. 勾选驱动类型(PCL6),点击安装,等待完成。 5. 安装结束,打印测试页验证。

BASIC TDI DEVICE DRIVER

////////////////////////////////////////////////////////////////////////// BASIC TDI DEVICE DRIVER, version 2// // (c)2004 Rootkit.com//// June 25, 2004 - Initial cut, Greg Hoglund// June 26, 2004 - A

errorlife的专栏 1725

如何利用URDF文件表示并联结构(仅适用于支持SDF格式的仿真环境)

介绍了一种使用URDF文件在Gazebo中表示并联结构的方法,该方法使用了URDF的SDF拓展。在一个具有并联结构的双足机器人上应用并演示了此方法的有效性。

RobotFreak的博客 3857

图像加密与解密(附matlab代码)

详细介绍了三种图像加密解密原理,并基于matlab开发了一套相应系统。

2448

ObReferenceObjectByName用法(自己测试成功)

//全局的一个对象类型 extern POBJECT_TYPE *IoDriverObjectType;  函数原型声明 NTSTATUS ObReferenceObjectByName (     __in PUNICODE_STRING ObjectName,     __in ULONG Attributes,     __in_opt PACCESS_STATE Acce

多媒体编程、网络编程、系统编程、网络安全编程、驱动编程 4174

智能汽车竞赛摄像头处理(4)——摄像头循迹思路讲解

智能汽车竞赛摄像头处理(4)对摄像头循迹思路进行讲解。

weixin_62261692的博客 7070

ObReferenceObjectByName 函数解析

一、由于ObReferenceObjectByName没有文档化,故在使用前先做声明: #ifdef __cplusplus extern "C" { #endif #include <NTDDK.h> NTKERNELAPI NTSTATUS ObReferenceObjectByName( IN PUNICODE_STRING ObjectName, I...

weixin_30311605的博客 299

自动驾驶仿真基础:使用Veristand自定义CAN报文的Checksum和Counter

文章目录前言一、关于Checksum的组成形式二、自定义的Checksum方法一1、实现的主要流程图如下:2、方法一的主要算法参考三、自定义的Checksum方法二1、软件及插件下载;2、Custom device的使用;4、Veristand调用Custom Device;5、Veristand发送信号值;6、部署到实时机; 前言 1、现在很多的车厂对于车辆的安全机制非常重视,车厂通过对发送的CAN数据进行加密而形成一种保护机制,而Checksum和Counter是其中的一种保护介质,当CAN报文数据的

zataji的博客 1万+

玩转单细胞(21):复现Nature图表---单细胞亚群无监督层次聚类分析及环形树状图绘制

这里我们要学习和复现的是一篇nature文章的图表Fig 1d,这篇文章全部数据都来自公共数据库。文章提供了处理好的单细胞数据以及代码,很好的学习资源。计算平均表达量矩阵:这里是anndata,在python中计算好之后使用R分析作图。如果您的单细胞数据是seurat,那么使用Averageexpress函数计算平均表达量矩阵。),之前使用的是ggplot2,如果类似这篇文章这样,celltype很多,可以考虑环形的聚类树图。添加颜色:原文是有设置好的颜色文件,没有找到,可以按照自己需求设置。

qq_42090739的博客 600

TDI, NDIS 驱动的学习

最近,因为项目的需要,想加入防火墙的功能模块,故开始了对这方面知识的学习。。。。<img style="margin: 2px;" title="名称: AFD.jpg查看次数: 271文件大小: 14.4 KB" src="mhtml:file://C:/Documents and Settings/Administrator/桌面/技术专题 【原创】Windows网络体系结构总

xum2008的专栏 1117

别再手动盘点了!教你给微信小程序仓库系统加个‘扫码枪’:完整扫码入库与查询功能实现

本文详细介绍了如何为微信小程序仓库系统添加扫码入库与查询功能,实现零硬件成本的智能仓储管理。通过优化摄像头参数、增强动态识别算法和深度整合业务逻辑,提升扫码精度和效率,同时提供混合查询方案应对复杂场景。这套方案显著提升入库效率,降低错误率,适用于各类仓储管理需求。

weixin_30844577的博客 312
上一篇: 如何写windows系统已保护的内存区域
下一篇: Smss.exe进程分析
iiprogram
博客等级 码龄25年 1068粉丝 1515原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址