安全攻防技能-安全基础概念

相关概念 cybersecurity: 网络空间安全涉及旨在保护设备,网络,程序和数据免受攻击和未经授权的访问的一系列实践,流程和技术; 网络安全不仅可以保护数据,还可以保护存储数据的资源和技术。 information security: 信息安全是关于保护信息的,通常集中在信息的机密性,完整性和可用性方面。 cyberseurity应用于信息技术的安全,wiki上的 Cybersecurity information technology list 几乎列出了wiki上所有网域安全相关信息 wiki相关主题,关于英文的关键字是 Information security, cybersecurity,cyberspace, 后两者者常用户的翻译是网络空间安全, 网络空间。现在的安全相关相关信息用后者搜索到的信息更新一些. 基本原则 安全三元组 CIA triad: Confidentiality, Integrity, Availability Confidentiality 机密性, 隐私信息, 防止被他人看到,保证机密性的例子如在线支付,涉及的用户信息,密码保护等等。 Integrity 完整性, 数据一致、准确、可信的, 不会在传输过程中改变,保证完整性的例子如用户访问控制,文件权限; 版本控制(防止已授权用户误操作); 为了检测由于故障可能发生的数据变化,一些数据设置了校验和, 验证数据完整性。必须有冗余和备份才能将受影响的数据还原成正常状态。 Availabilty 可用性: 保障数据能够被正常访问。保证可用性的例子,比如磁盘的RAID, 应用集群,机房建设,同城异地灾备,通信线路选取多家运营商等等 。 面临挑战 大数据 由于要保护的数据信息量巨大,考虑到冗余和备份, 数据保存的成本会成倍增加。此外,由于大数据更关注于数据收集和对用户信息、行为的分析和理解, 通常缺乏数据监管。比如 Whistleblower Edward Snowden 物联网 物联网中实体和对象会有一个唯一标识符,并且具有网络通讯能力,单个接入设备可能不会引起任何隐私问题, 但是当整理和分析来自多个终端的数据时, 可能就会产生敏感数据。涉及领域如智能玩具,智能家居,智能医疗。 而且物联网设备通常不会经常打补丁,并且会使用默认密码或弱密码及进行配置,如不加保护很可能成为黑客用于攻击的载体。 解决方案 黄金法则: Authentication, Authorization, Audit 黄金法则是系统安全设计的指导规范,是用户在访问使用系统过程中, 应考虑的最基本的安全设计要求。 Authentication 身份认证和识别, 软件系统常用的就是用户, 密码,为了加强强度,后续又增加了多因素认证, 一般是双因素认证(2FA) Authorization 授权确定能再系统中使用资源的范围 Audit 通过日志还原用户的操作,一般是出现问题后的一种防御措施. 安全最佳实践 设立专门防止内部威胁的职位 进行网络钓鱼模拟 确保员工远程访问安全 优先员工的隐私 进行安全相关培训 外包厂商应遵守相同的安全策略并接收培训 建立使用适合的信息安全框架(ISO/IEC27001) 监控用户和文件防止数据丢失 高价值行业(医疗,技术,银行)应防范更高层次的威胁 加强用户密码管理使用SSO,MFAs 特权用户审计 控制访问权限防止数据泄露 检测内部威胁 备份数据 雇佣合同,第三方外包时合同中应写明相关的保密条款 更新定期更新软件和使用系统 指定安全时间响应预案, 定期进行演练 定期进行安全培训及演练 合规要求:HIPAA, PCI, ISO, and DSS 在使用软件,组件之前应考虑相关安全性 指定标准人事流程防止人员离职到的数据流失 可以持续监控用户活动 自动化减少认为操作的错误 GDPR合规要求 使用https提供服务 best practices 通过这个关键字搜索的一些信息, 参见文末链接19 Cybersecurity Best Practices to Protect Your Business ...

2020-06-20 · 3 min · 467 words

LeetCode – Binary Tree Level Order Traversal Solution

题目: Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its level order traversal as: [ [3], [9,20], [15,7] ] 解题: 两种方式处理, 广度优先搜索借助队列,一层一层处理,并放入二维数组; 深度优先搜索借助栈, 一个一个处理, 将每一个元素方式所属层对应的一维数组中。 实现: BFS 使用队列实现 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: vector<vector<int>> levelOrder(TreeNode* root) { vector<vector<int>> result; if (!root) { return result; } queue<TreeNode*> q; q.push(root); while (!q.empty()){ vector<int> current; int level_size = q.size(); for (int i=0; i<level_size; i++){ TreeNode* node = q.front(); q.pop(); current.push_back(node->val); if (node->left) { q.push(node->left); } if (node->right) { q.push(node->right); } } result.push_back(current); } return result; } }; 实现: DFS 递归实现: class Solution { public: vector<vector<int>> levelOrder(TreeNode* root) { vector<vector<int>> result; if (!root){ return result; } result = _dfs(root, 0, result); return result; } vector<vector<int>> _dfs(TreeNode *node, int level, vector<vector<int>> &res){ if (!node){ return res; } if (res.size() < level+1){ res.push_back({}); } res[level].push_back(node->val); _dfs(node->left, level+1, res); _dfs(node->right, level+1, res); return res; } };

2020-06-09 · 2 min · 218 words

Timers and time management in the Linux kernel. Part 7.

这篇文章 Timers and time management in the Linux kernel. Part 7. 是出自 linux-insides一书中 Timers and time management 章节 内核版本比对5.7 进行了相关调整, 增加相关备注 Linux内核中与时间相关的系统调用 这是第七章也是最后一章chapter, 它描述了Linux内核中计数器和时间管理相关的内容. 在前面的章节 part, 我们在 x86_64: High Precision Event Timer 和Time Stamp Counter. 内部时间管理是Linux内核中一个有趣的部分, 但是,当然,不仅内核需要time概念. 我们的程序还需要知道时间。这一部分中,我们将考虑实际一些与时间管理相关的 system calls. 这些系统调用: clock_gettime; gettimeofday; nanosleep. 我们将从一个简单的用户空间C 程序开始, 并从standard library 函数执行某些系统调用。由于每个 architecture 提供了自己的某些系统调用实现,因此我们将仅考虑x86_64系统调用的特定实现,因为本书与此体系结构相关。 Additionally, we will not consider the concept of system calls in this part, but only implementations of these three system calls in the Linux kernel. If you are interested in what is a system call, there is a special chapter about this. ...

2020-06-07 · 8 min · 1541 words

/proc/buddyinfo文件

/proc/buddyinfo文件 /proc/buddyinfo 文件可以查看Linux机器上可用的内存页, 可以查看每个节点,不同区域的每个order大小的块的可用数量, 下面是我们虚拟机的信息: cat /proc/buddyinfo Node 0, zone DMA 97 90 51 31 10 9 6 2 0 0 0 Node 0, zone DMA32 456 876 665 457 192 83 25 5 1 0 0 mm/vmstat.c walk_zones_in_node 实现了其proc文件输出 可以看到显示的单一NUMA节点Node 0在内核使用pglist_data结构表示, 每个节点包含多个 区域, 使用zone结构标识。 ZONE类型如下: ZONE_DMA 这个区域为一些不能在所有内存地址初始化DMA的设备保留,大小和体系结构有关 , 一些ISA需要它 ZONE_DMA32 这个区域仅存在与X86_64体系中,支持32位设备放到到小于4G的内存 ZONE_NORMAL 可以直接映射的区域, 如果DMA设备支持所有可寻址内存,则可以将所有可寻址内存视为正常区域, DMA操作可以在这些页面上启动 ZONE_HIGHMEM 对于32bit系统内核空间和用户空间比例是1:3模式下(3G用户空间,1G 内核空间), 该区域包含的页面只能由内核通过显式映射到其地址空间来访问,内核段以外的所有物理内存页都可以通过映射到该区域 ZONE_MOVABLE 从最高内存区域划出一片的内存, 处理内存碎片,X86-32bit大于ZONE_HIGH的区域, X86-64bit 大于ZONE_DMA32的区域,启动是根据内核有参数kernelcore用于设置不可移动的内存大小。 如果指定了“mirror”选项,则mirror内存用于非移动分配,其余内存用于移动页面。 ZONE_DEVICE 与SPARSEMEM这种新的物理内存模型有关, 这种模型支持内存热插拔, 这类内存通过devm_memremap_pages,映射到内存的这个区域. 伙伴分配将每个区域ZONE进一步划分为2次幂(order)个页面大小的块, 就是后面的那串数字 collectl 工具可以实时监控相关剩余内存的变化 #collectl -sB -oT waiting for 1 second sample... # MEMORY FRAGMENTATION (4K pages) #Time Node Zone 1Pg 2Pgs 4Pgs 8Pgs 16Pgs 32Pgs 64Pgs 128Pgs 256Pgs 512Pgs 1024Pgs 12:50:41 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:41 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:42 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:42 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:43 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:43 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:44 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:44 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:45 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:45 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:46 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:46 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:47 0 DMA 126 94 71 66 40 13 4 2 0 0 0 12:50:47 0 DMA32 452 354 97 40 19 0 0 0 0 0 0 相关资料 一篇介绍/proc/buddyinfo博客文章Making sense of /proc/buddyinfo quora上关于这个问题的讨论里面有What is the purpose of “/proc/buddyinfo” entry on Linux systems? [v4,2/2] mm/page_alloc.c: introduce kernelcore=mirror option KernelNewbies: Linux_4.6 Mastering Linux Kernel Development: A kernel developer’s reference manual Physical Memory Model Memory Fragmentation

2020-06-06 · 2 min · 333 words

LeetCode –Binary Tree Postorder Traversal

题目: Given a binary tree, return the postorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [3,2,1] Follow up: Recursive solution is trivial, could you do it iteratively? 解题: 遍历顺序“根-左-右” 实现: 使用栈实现 从根节点开始,先将根节点压入栈,保存结果值,然后移动到右节点, 保证“根-右边”顺序, 为空后出栈,取其左节点入栈中。这样入栈就保证了访问顺序为“根-右-左”, 出栈实现“左-右-根”。 class Solution { public: vector<int> postorderTraversal(TreeNode* root) { vector<int> res; stack<TreeNode*> ss; TreeNode *p= root, *t; while(!ss.empty()||p){ if (p){ ss.push(p); res.insert(res.begin(), p->val); p = p->right; } else { p=ss.top(); ss.pop(); p= p->left; } } return res; } }; 实现: 递归实现 class Solution { public: vector<int> postorderTraversal(TreeNode* root) { vector <int> res; postorder(root, res); return res; } void postorder(TreeNode *root, vector<int> &res){ if (!root) { return; } if (root->left) { postorder(root->left, res); } if (root->right){ postorder(root->right, res); } res.push_back(root->val); } }; 参考: [LeetCode] 145. Binary Tree Postorder Traversal 二叉树的后序遍历

2020-06-04 · 1 min · 130 words

功能点分析法整理

由于工作需要,需要在项目立项前都需要进行功能点估算, 为后续计算项目组的的工作效率做准备。目前做了几次估算,在这里整理和总结一下。 我们目前使用的评估的标准参考 IFPUG: ISO/IEC 20926:2009 概述 定义: The function point is a "unit of measurement" to express the amount of business functionality an information system (as a product) provides to a user. 功能点是业务功能的单位, 也就是从用户视角的进行评估, 是可以和用户交流的。对于我现在实施的外包项目来说就是用一种方法和甲方达成共识。相比较与之前的根据经验评估更有依据些。 步骤 1. 功能点应用的分类 开发项目: 从无到有 升级项目: 功能升级 应用项目: 基线评估 2. 识别应用边界 被测应用与用户间的边界。 3. 确认功能点 被测应用与用户间的边界。 数据功能 ILF: 容纳本应用维护的一组业务数据, 控制数据 ELF: 容纳外部应用维护的数据, 对于外部数据来说是他的ILF 处理功能 EI: 处理来自应用外部的的数据, 主要实现ILF的维护, 应用的控制 EO: 通过ILF生成新数据, 已报表,数据流形式送到应用以外 EQ: 请求来自应用外部, 处理过程包含输入,输出, 但输入不进行ILF文件的维护 复杂度 1. 复杂度评估涉及三种元素 RET & DET & FTR DET :用户可识别的,非重复的域 RET :用户可识别的数据的子集合 FTR: 引用文件类型 2. ILF & EIF 的复杂度 ILF & EIF 1 to 19 DET 20 to 50 DET 51 or more DET 1 RET Low Low Average 2 to 5 RET Low Average High 6 or more RET Average High High ILF: Functional Complexity Rating Unadjusted Function Points Low 7 Average 10 High 15 EIF: Functional Complexity Rating Unadjusted Function Points Low 5 Average 7 High 10 3. EI & EO & EQ 的复杂度 EI: 1 to 4 DET 5 to 15 DET 16 or more DET 0 to 1 FTR Low Low Average 2 FTRs Low Average High 3 or more FTRs Average High High EO & EQ 1 to 5 DET 6 to 19 DET 20 or more DET 0 to 1 FTR Low Low Average 2 to 3 FTRs Low Average High 4 or more FTRs Average High High EI & EQ: Functional Complexity Rating Unadjusted Function Points Low 3 Average 4 High 6 EO: Functional Complexity Rating Unadjusted Function Points Low 4 Average 5 High 7 关于复杂度我们实际场景中目前取的都是平均数, 没有对功能点负责度进一步分析,后续会对数据进行统计, 折算出应用的固定的权重。 ...

2020-06-04 · 3 min · 524 words

buddy memory allocation相关整理

概述 wiki上的定义: The buddy memory allocation technique is a memory allocation algorithm that divides memory into partitions to try to satisfy a memory request as suitably as possible. This system makes use of splitting memory into halves to try to give a best fit. 伙伴内存分配技术是一种内存分配算法,它将内存划分为多个分区,以尝试尽可能适当地满足内存请求。 该系统利用将内存分成两半来尝试提供最佳匹配。 算法 伙伴系统有多种形式; 将每个块细分为两个较小块的块是最简单,最常见的一种。 选定块的大小要根据实际情况选取,太小则需要更多的内存记录跟踪内存分配, 太大又容易产生空间浪费,另外,就是如果选择2的次幂单位的话, 最大的块有可能不会覆盖整个内存. 例子 同样是wiki的例子,申请的内存调整了下 Step 64K 64K 64K 64K 64K 64K 64K 64K 64K 64K 64K 64K 64K 64K 64K 64K 1 24 2.1 23 23 2.2 22 22 23 2.3 21 21 22 23 2.4 20 20 21 22 23 2.5 A:20 20 21 22 23 3 A:20 20 B: 21 22 23 4 A:20 C:20 B: 21 22 23 5.1 A:20 C:20 B: 21 21 21 23 5.2 A:20 C:20 B: 21 D: 21 21 23 6 A:20 C:20 21 D: 21 21 23 7.1 A:20 C:20 21 21 21 23 7.2 A:20 C:20 21 22 23 8 20 C:20 21 22 23 9.1 20 20 21 22 23 9.2 21 21 22 23 9.3 22 22 23 9.4 23 23 9.5 24 初始化状态,每块64K, 最大的块包含 24 个块, 一个4阶块. ...

2020-05-29 · 3 min · 482 words

python根据excel内容生成文件夹

python根据excel内容生成文件夹 工作需要根据excel数据信息,生成对应的文件夹,用python写了一个脚本处理了一下。 样例中表格内容也进行了调整。 环境: windows10 python3.7 + openpyxl 目标: 以list.xlsx数据为准,抽取指定sheet页中的指定字段信息,生成目录, 并在目录中创建固定的子目录. 表格格式: 表格sheet-A01 序号 项目名称 备注 1 项目1 张三 2 项目2 李四 表格sheet-A02 序号 项目名称 备注 1 项目1 王五 每一个sheet存放一个批次的任务信息, total为批次名称 代码: from openpyxl import load_workbook from openpyxl import Workbook import os import re ## 获取项目清单列表 wb = load_workbook( filename = '.\\test\\list.xlsx') #ws_in = wb_in.active outpath=".\\out\\" ## 名字列表开始结束行号 start_index = 4 ##end_index = ## 目录编号 dir_no = 1 ## 1. 找到指定的sheet页面 sheets_name = ['A01', 'A02'] ## 3. 组成符合要求的目录字符串创建目录 def mkdir(path): try: os.makedirs(path) print("CREATE") except FileExistsError: print("EXIST, NO CREATE") # Get all dirs def mksubdir(path): try: dirnames = [name for name in os.listdir('.\\model') if os.path.isdir(os.path.join('.\\model', name))] for i in dirnames: mkdir(path+"\\"+i) except : print(" CREATE SUB DIR ERROR ") for i in range(len(sheets_name)): print(i) sheet = wb[sheets_name[i]] print(sheet) ## 2. 找到相关的任务信息 for row in range(start_index, sheet.max_row+1): ## 1. 判断内容是否空格 0 or 1? if (str(sheet.cell(row, column=1).value).strip() == "None" ): print(batch_no + " is over") break; ##2. 获取表格内容生成目录 task_no = sheet.cell(row, column=1).value batch_no = sheet.title.split('-')[0] task_context = str(sheet.cell(row, column=2).value).strip() task_manager = re.search(r'张三|李四|王五', sheet.cell(row,column=3).value) task_leader = task_manager.group(0) #(序号)-批次号-批次序号-任务名称(负责人) # mkdir(path) dir_no_str = format(dir_no, '02d') task_no_str = format(task_no, '02d') dirname=dir_no_str+"-"+batch_no+"-"+task_no_str+"-"+task_context+"-"+task_leader mkdir(outpath+dirname) # mksubdir(path) mksubdir(outpath+dirname) dir_no = dir_no+1 运行结果 ├─01-A01-01-项目1-张三 │ ├─01_文档目录1 │ └─02_文档目录2 ├─02-A01-02-项目2-李四 │ ├─01_文档目录1 │ └─02_文档目录2 └─03-A02-01-项目3-王五 ├─01_文档目录1 └─02_文档目录2 ...

2020-05-01 · 2 min · 214 words

Timers and time management in the Linux kernel. Part 6

这篇文章 Timers and time management in the Linux kernel. Part 6. 是出自 linux-insides一书中 Timers and time management 章节 内核版本比对5.7-rc1 进行了相关调整, 增加相关备注 Linux内核中的定时器和时间管理.Part 6. x86_64 相关的时钟源 这是chapter的第六部分,它描述了Linux内核中与计时器和时间管理相关的内容。 在之前的part中,我们看到了clockevents框架,现在我们将继续深入探讨与时间管理相关的问题 Linux内核中的内容。 本部分将描述与时钟源相关的x86架构的实现(有关[clocksource]概念的更多信息,您可以在second part 中找到相关信息. 首先,我们必须知道在x86体系结构中可以使用哪些时钟源。 从 sysfs 或者从下面的文件 /sys/devices/system/clocksource/clocksource0/available_clocksource. /sys/devices/system/clocksource/clocksourceN来获取相关信息: available_clocksource - 提供系统可用是时钟源 current_clocksource - 提供系统当前使用时钟源 实际看一下: $ cat /sys/devices/system/clocksource/clocksource0/available_clocksource tsc hpet acpi_pm 我们可以看到有三个注册的时钟源在这个系统里: tsc - Time Stamp Counter; hpet - High Precision Event Timer; acpi_pm - ACPI Power Management Timer. 现在让我们看看第二个文件,它提供了最佳时钟源(在系统中具有最佳评级的时钟源) $ cat /sys/devices/system/clocksource/clocksource0/current_clocksource tsc tsc是Time Stamp Counter的简写. second part有过描述, 他描述了Linux Kernel的clocksource框架, 系统最好的时钟源应当是最有最好或最高功率,频率的, 或者说是具有最高frequency. ...

2020-04-27 · 6 min · 1139 words

LeetCode –Binary Tree Preorder Traversal

题目: Given a binary tree, return the inorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,3,2] Follow up: Recursive solution is trivial, could you do it iteratively? 解题: 遍历顺序“根-左-右” 实现: 使用栈实现 从根节点开始,先将根节点压入栈,保存结果值,然后移动到左节点, 保证“根-左”顺序, 为空后出栈,取其右节点入栈中。这样就保证了访问顺序为“根-左-右”。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int> preorderTraversal(TreeNode* root) { vector<int> res; stack<TreeNode*> ss; TreeNode *p = root; while (!ss.empty()||p){ if (p!=NULL){ ss.push(p); res.push_back(p->val); p = p->left; } else{ p = ss.top(); ss.pop(); p=p->right; } } return res; } }; 实现: 递归实现 class Solution { public: vector<int> preorderTraversal(TreeNode* root) { vector<int> res; preorder(root, res); return res; } void preorder(TreeNode *root, vector<int> &res){ if (!root) return; res.push_back(root->val); preorder(root->left, res); preorder(root->right, res); } }; 参考: [LeetCode] 144. Binary Tree Preorder Traversal 二叉树的先序遍历 ...

2020-04-16 · 1 min · 157 words