# HustDetours **Repository Path**: Ecila01/hust-detours ## Basic Information - **Project Name**: HustDetours - **Description**: HUST CSE 2024 Spring Software Security Course Design, by CSE 2101 team C. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 272 - **Created**: 2024-02-27 - **Last Updated**: 2024-05-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HustDetours => API Hooker 2024春 HUST CSE 软件安全课程设计 基于 API HOOK 的软件行为分析系统 ## 环境配置 !特别更新:因用于界面编写的 Qt 环境为 x64 环境,x86无法编译,故将整体配置修改为 x64 ! 特别更新2:因界面编写修改为使用Vue,故环境切换回x86,各个受影响的.h文件和.lib文件已经重新编译并放置到各项目中 ## 项目架构 - 解决方案:Detours - 基本前提项目:Detours 【已获取】 - 钩子项目:hookdll 【待完善】 - 钩子测试项目 - MessageBoxTest 【已完成】 - HeapTest - FileOperationTest - RegisterTest - SocketTest - 控制台dll注入器:ConsoleInjector 【已完成】 - 图形界面: React 【开发中】 - 操作流程 - Client: 向后端发送 Post 请求,传输前端输入的可执行文件路径 - Server:接收请求,使用注入器和dll对可执行文件进行注入执行,传回信息 1. 注入并执行 2. 信息传递与接收 3. 执行信息回传 - Client: 显示回传的执行 log - 待开发:警告统计,执行记录,综合风险评价展示 - 通信结构 - 前后端通信 - 前端使用 POST 方法向后端接口发出请求,并等待后端回复 - 后端执行程序,执行结束后发回 POST 回复 - 预期优化:后端修改为SEE模式动态发回json - 后端内部管道 - 后端不同进程之间使用管道进行消息传输,管道名为mypipe - 管道由后端服务器开启,之后由后端注入dll的子进程连接 - 管道传递标准格式,等宽字符(utf-8),完整json信息 - 由后端服务器收集并回传 - 管道事件 ```json 待完善 ``` ## 课程设计任务与要求 对于无源码情况下分析样本程序的行为,有多种方法。本次课程设计是利用Detours开源项目包提供的接口,完成基本的程序行为分析。具体课程设计任务见表1。任务主要分为API调用截获及分析两大部分。任务可以自己选择Windows(含Win7/win8/win10)平台上实现,编程用语言为C或者C++。其中使用的Windows平台使用微软的Detours开源库,可以在VS2019环境下编译后使用,后面会有详细介绍。 平台:Win7/Win8/Win10,VC++(VS2013/VS2015/VS2019)。 ### 实现基本的第三方进程 WindowsAPI 截获框架 此任务参考 [CSDN1](https://blog.csdn.net/DOwnstairs/article/details/123753532) 与 [CSDN2](https://blog.csdn.net/DOwnstairs/article/details/123753532) 1. 编译生成Detours库 【已完成】 2. 完成挂钩框架DLL,实现对MessageBox调用截获,能打印出调用的参数、进程名称以及进程Exe文件信息 - 新建项目DLL 【已完成】 - 实现MessageBox调用截获 【已完成】 - 打印参数、进程名称、exe文件信息 【已完成】 3. 自编或者利用已有恶意代码,制造恶意代码样例(包含弹出对话框动作) 【已完成】 4. 完成注入动作开启和关闭的“注射器”控制程序 【已完成】 ### 实现堆操作 API 截获 参考任务1,将 Hook MessageBox 修改为 Hook 堆操作(创建,释放)对应函数 1. 实现对堆操作调用截获,打印参数信息 2. 编写恶意代码实例 ### 实现文件操作API截获 同上,实现对文件操作(创建,关闭,读写)API进行截获,打印出所有参数信息。 ### 实现注册表操作API截获 实现对注册表操作(创建,关闭,读写)API进行截获,打印出所有参数信息。 ### 堆操作异常行为分析 设计并完成算法,记录并给出提示: 1. 检测堆申请与释放是否一致(正常); 2. 是否发生重复的多次释放(异常)。 ### 文件操作异常行为分析 设计并完成算法,记录并给出提示: 1. 判断操作范围是否有多个文件夹; 2. 是否存在自我复制的情况; 3. 是否修改了其它可执行代码包括exe,dll,ocx等; 4. 是否将文件内容读取后发送到网络(选做); ### 注册表操作异常行为分析 设计并完成算法,记录并给出提示: 1. 判断是否新增注册表项并判断是否为自启动执行文件项; 2. 是否修改了注册表; 3. 输出所有的注册表操作项; ### 提供系统界面 为所有设计的功能提供图形界面展示 ### 创建行为检测样本库 提供至少5个待检测的可能存在恶意的exe样本; ### 项目开源 在Gitee平台上开源各自完成的行为分析系统,小组成员通过Gitee协同开发 ### 项目文档撰写 在开源项目中编写项目构建与使用文档 ### 在指定的开源仓库完成开源贡献 在以下开源仓库中提交PR: (1) Gitee的HustDetours(待公布具体网址) (2) 软件安全课程平台的基础架构仓库(https://github.com/HUSTSeclab/dojo) 理论课实验课实验仓库(https://github.com/HUSTSeclab/software-security-dojo) ### 网络通信操作异常行为分析(选做) 设计并完成算法,记录并给出提示: 1. 实现对网络传输SOCKET操作(连接、发送与接收)API的截获; 2. 打印进程连接端口、协议类型、IP信息 3. HTTP连接协议的解析,判断传输的内容是否为明文 ### 内存拷贝监测与关联分析(选做) 设计并完成算法,记录并给出提示: 1. 能够输出内存拷贝信息,并分析拷贝的内容流向。 # microsoft/Detours 项目原版 README # Microsoft Research Detours Package Detours is a software package for monitoring and instrumenting API calls on Windows. Detours has been used by many ISVs and is also used by product teams at Microsoft. Detours is now available under a standard open source license ([MIT](https://github.com/microsoft/Detours/blob/master/LICENSE.md)). This simplifies licensing for programmers using Detours and allows the community to support Detours using open source tools and processes. Detours is compatible with the Windows NT family of operating systems: Windows NT, Windows XP, Windows Server 2003, Windows 7, Windows 8, and Windows 10. It cannot be used by Windows Store apps because Detours requires APIs not available to those applications. This repo contains the source code for version 4.0.1 of Detours. For technical documentation on Detours, see the [Detours Wiki](https://github.com/microsoft/Detours/wiki). For directions on how to build and run samples, see the samples [README.txt](https://github.com/Microsoft/Detours/blob/master/samples/README.TXT) file. ## Contributing The [`Detours`](https://github.com/microsoft/detours) repository is where development is done. Here are some ways you can participate in the project: * [Answer questions](https://github.com/microsoft/detours/issues) about using Detours. * [Improve the Wiki](https://github.com/microsoft/detours/wiki). * [Submit bugs](https://github.com/microsoft/detours/issues) and help us verify fixes and changes as they are checked in. * Review [source code changes](https://github.com/microsoft/detours/pulls). Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. ## Issues, questions, and feedback * Open an issue on [GitHub Issues](https://github.com/Microsoft/detours/issues). ## Mailing list for announcements The detours-announce mailing list is a low-traffic email list for important announcements about the project, such as the availability of new versions of Detours. To join it, send an email to listserv@lists.research.microsoft.com with a message body containing only the text SUBSCRIBE DETOURS-ANNOUNCE. To leave it, send an email to listserv@lists.research.microsoft.com with a message body containing only the text UNSUBSCRIBE DETOURS-ANNOUNCE. ## License Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the [MIT](LICENSE.md) License.