仓库链接:https://github.com/sixsixQAQ/ip_file_hook
Linux下实现IP和文件访问拦截,代码量1000行。
1. 使用技术
C++实现,构建工具cmake。
- so preload机制
- inotify API
- ptrace系统调用
- 其他常用linux系统调用
2. 前导知识
这个小项目可以拆出多个模块,前几篇博客都有总结。
1. 优雅地细化异常
2. 自定义format
3. 优雅地实现简易日志
ptrace()手册翻译文章来源:https://www.toymoban.com/news/detail-565483.html
3. 使用效果
通过配置文件来控制文章来源地址https://www.toymoban.com/news/detail-565483.html
{
"file_black_list": [
{
"file": "/home/sixqaq/protect_ip_file/test/test_black_list.txt",
"exe": [
"/home/sixqaq/protect_ip_file/test/deny_1",
"/home/sixqaq/protect_ip_file/test/deny_2",
"/home/sixqaq/protect_ip_file/test/deny_3",
"/usr/bin/gedit",
"/usr/bin/vim",
"/software/pkg/vnote"
]
}
],
"file_white_list": [
{
"file": "/home/sixqaq/protect_ip_file/test/test_white_list.txt",
"exe": [
"/home/sixqaq/protect_ip_file/test/allow_1",
"/home/sixqaq/protect_ip_file/test/allow_2",
"/home/sixqaq/protect_ip_file/test/allow_3",
"/usr/bin/cat",
"/usr/bin/vim",
"/usr/bin/cp"
]
}
],
"ip_black_list": [
{
"ip": "39.156.66.10",
"exe": [
"/home/sixqaq/protect_ip_file/test/deny_1",
"/home/sixqaq/protect_ip_file/test/deny_2",
"/home/sixqaq/protect_ip_file/test/deny_3"
]
}
],
"ip_white_list": [
{
"ip": "106.13.8.123",
"exe": [
"/home/sixqaq/protect_ip_file/test/allow_1",
"/home/sixqaq/protect_ip_file/test/allow_2",
"/home/sixqaq/protect_ip_file/test/allow_3",
"/usr/bin/ping",
"/usr/bin/ssh"
]
}
]
}
``
到了这里,关于小项目:C++拦截Linux下IP和文件访问的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!