如何用代码操作IP安全策略

psbeond 2020-12-17 05:37:18
如题,想请教下如何用代码操作本地组策略中的IP安全策略,我准备把一个IP加到黑名单里。谢谢。


提供几个函数也行,我可以自己查资料。百度搜了半天,都是直接在操作系统里设置的,没找到用代码设置的。
...全文
267 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
psbeond 2020-12-22
  • 打赏
  • 举报
回复
嗯,我现在用的是CreateProcess调用CMD执行netsh ipsec命令。
an_bachelor 2020-12-22
  • 打赏
  • 举报
回复
如果用脚本,也可以考虑powershell脚本设置,看起来它文档比较清晰:https://docs.microsoft.com/en-us/powershell/module/netsecurity/show-netipsecrule?view=win10-ps
an_bachelor 2020-12-22
  • 打赏
  • 举报
回复
引用 8 楼 psbeond 的回复:
用API monitor监控了一下,似乎完全就是操作注册表。没用到特有的API?
从注册表修改动作反推 这也是个办法,但是这个并不能推断出“没有使用特定(LSA)API”只能说LSA的API修改ipsec设置的实现也许就是简单一改注册表 msdn文档不会骗我们的 我看了一下策略导出文件,好像就是一个二进制格式的注册表导出文件 .regf格式的 但这个格式是文本混和二进制数据 似乎难以直接用做TXT模板 然后去用代码正确修改它 网上有人针对这个.regf格式做了库 单个人觉得麻烦又是野路子 这个办法不如直接包一层命令行或花时间研究LSA API
psbeond 2020-12-22
  • 打赏
  • 举报
回复
查看了ipseccmd源代码,应该就是纯操作注册表实现的。不过,有些键,比如ipsecData,类型是二进制,如何组合里面的数据,还得逆向源代码。源代码中的MarshallPolicyBuffer函数,就是生成这个二进制串的。
psbeond 2020-12-21
  • 打赏
  • 举报
回复
引用 4 楼 陈仲甫 的回复:
https://docs.microsoft.com/en-us/windows/win32/secmgmt/using-lsa-policy
怎么感觉LAS是和帐户相关的API,好像和IPSec没什么关系吧? 在vista上,IPSec可以用WFP API来配置,在server2003上,没找到api.
psbeond 2020-12-21
  • 打赏
  • 举报
回复
用API monitor监控了一下,似乎完全就是操作注册表。没用到特有的API?
psbeond 2020-12-21
  • 打赏
  • 举报
回复
现在用netsh ipsec命令行工具,可以操作server2003,无奈不懂逆向,要不看看里面是如何实现的。
an_bachelor 2020-12-21
  • 打赏
  • 举报
回复
引用 5 楼 psbeond 的回复:
[quote=引用 4 楼 陈仲甫 的回复:]https://docs.microsoft.com/en-us/windows/win32/secmgmt/using-lsa-policy
怎么感觉LAS是和帐户相关的API,好像和IPSec没什么关系吧? 在vista上,IPSec可以用WFP API来配置,在server2003上,没找到api.[/quote]我没有深入研究 从文档的说明来看 组策略数据库就是这个子系统管的: Policy Object The Policy object is used to control access to the Local Security Authority (LSA) database and contains information that applies to the entire system or establishes defaults for the system. Each system has only one Policy object. This Policy object is created by the LSA when the system starts up, and applications cannot create or destroy it. The information stored in a Policy object includes: System default memory quota. Unless otherwise specified, each user logging on to the system will be assigned this memory quota. Special memory quotas can be assigned to individuals or members of groups or local groups through an Account object. System-wide security auditing requirements. The name and SID of the account domain of this system. Information about the primary domain of this system. This information includes the name and SID of the primary domain, the name of the account within the primary domain that is to be used for authentication requests, name and SID translations, and obtaining the names of domain controllers within the domain. These names may be out of date and should be taken only as a hint. The order of this list is assumed to be significant and will be maintained. This allows, for example, the first name in the list to represent the last-known primary domain controller. Information about whether the LSA holds the master copy of the policy information or a replica. Only part of the policy information is replicated; the remainder is established on a per-system basis. 所以你的问题就好像是“要吃饭但是你怎么给我找了家餐厅,以前我是用碗筷吃的” 哈哈 开个玩笑 相信LSA文档里面能找到访问方法,并且好像是有例子的。另外还有一个笨办法就是做好策略导出为文件,这个文件通常是文本格式的,然后用代码依葫芦画瓢,做好一个“导出文件”再用其他方式导入:powershell基本可以肯定有办法导入导出,mmc命令行也许可以。
an_bachelor 2020-12-17
  • 打赏
  • 举报
回复
https://docs.microsoft.com/en-us/windows/win32/secmgmt/using-lsa-policy
psbeond 2020-12-17
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903的回复:
https://www.jianshu.com/p/52dc923a762c
感谢,不过我要找的是用windows api操作的方法。
psbeond 2020-12-17
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903的回复:
https://www.jianshu.com/p/52dc923a762c
感谢,不过我要找的是用windows api操作的方法。
zgl7903 2020-12-17
  • 打赏
  • 举报
回复

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧