赤道企鹅
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 软件安全原理:威胁建模报告 - 项目:[node-websocket-Chatroom](https://github.com/cleverqin/node-websocket-Chatroom) - 成员:董津玮(组长), 赵勇,方俊豪,尚思佳,陈扬帆,燕文浩,吴雨娴,翟墨涵,周子航 - 任务划分: | 分工 | 人员 | 时间 | | -------- | -------- | -------- | | 详细项目代码审计与任务划分 | 董津玮 | day1-day2 | | 分解目标软件(3人) | 赵勇,方俊豪,尚思佳 | day2-day4 | | 数据流图绘制(3人) | 陈扬帆,燕文浩,董津玮 | day3-day4 | | 威胁分析(4人) | 吴雨娴,董津玮,翟墨涵,方俊豪 | day4-day6 | | 风险评级(3人) | 燕文浩,吴雨娴,董津玮 | day6-day7 | | PPT 制作 | / | day7-day8 | ## 一、分解目标软件(系统) ### 威胁模型信息(Threat Model Information) | 目标软件名称 | node-websocket-Chatroom | | -------- | -------- | | 目标软件版本 | 1.1.0 | | 目标软件描述 | WebChat 聊天室是一个基于 node.js+express+socket&#x002e;io 模块构建的网页聊天室工具。前端使用 Vue 作为前端框架,服务端使用 express 搭建,并使用 socket&#x002e;io 来创建 websocket 服务,实现了一些基本的聊天功能。 | ### 过程(Process) | 过程名称 | 过程描述 | | --- | --- | | 会话连接 | 用户通过浏览器打开聊天室 Web 页面后会借助 socket&#x002e;io 与 node.js 后端建立一个新的 websocket 会话。首次建立会话时会检查请求头中是否带有 jwt 编码的 token 字段,该字段存储了先前登陆过的用户的信息,如果有则尝试直接对其中的用户信息进行认证授权和自动登录。如果 token 被攻击者解密并伪造可能存在伪造用户信息窃取用户身份的风险。 | | 登录事件 | 用户输入用户名和密码并点击按钮后会在先前建立好的 webscoket 会话中传输序列化后的用户数据对象,该对象会被 node.js 后端监听登录事件的代码获取,经过过滤和其它处理后送入认证授权模块。如果该对象在发送中被伪造可能导致后端获取到的对象被注入非法属性和值。 | | 消息事件 | 用户在聊天框向其他用户或群组发送文字消息、图片或表情时,消息对象同样会在 webscoket 会话中序列化并传输,然后被 node.js 后端监听消息事件的代码获取。伪造消息对象同样可能导致后端获取的对象被注入非法属性和值。 | | 认证与授权 | 认证与授权模块接收一个用户对象,并在数据库中检索已有的用户信息,判断该用户对象表示的用户是否正确以及是否可以正常登录。同时会为新用户在数据库中插入相应的记录。如果实现不当可能导致认证被绕过和信息泄露。 | | NeDB 数据库操作 | NeDB 是对象型数据库,用户信息和消息数据的读取和写入都要依赖负责操作 NeDB 数据库的代码。这些代码封装好了增删改查等基本的数据库原语。但是该类型数据库如果对输入过滤不严依然可能存在被注入攻击的风险,导致敏感信息被泄露或篡改。 | | 浏览器页面渲染 | Vue.js 编写的前端页面是该聊天室重要组成部分,浏览器会渲染 服务器响应的静态资源以及动态数据。如果前端在渲染攻击者可控的某些数据时没有做好严格的过滤,可能导致 XSS 漏洞,影响 Web 用户浏览器的安全性。 | ### 外部依赖项 (External Dependencies) | 外部依赖项名称 | 外部依赖项描述 | | -------- | -------- | | socket&#x002e;io 模块 | 该模块可借助 websocket 协议实现基于事件的实时双向通信,它包括一个 node.js 服务器端运行库和浏览器的 JavaScript 客户端运行库。 | | crypto 库 | 生成公钥和私钥时通常需要使用加密算法,Node.js 中的 crypto 模块提供了加密函数。在生成 MD5 哈希或其他哈希值时,通常需要使用加密库或模块来执行哈希算法。这些库或模块可以是操作系统提供的、编程语言内置的,或者是第三方的,需要考虑这些库或模块的安全性和可信度。| | 随机数生成器 | 哈希算法通常需要在计算哈希值时使用随机数。这可能涉及到操作系统提供的随机数生成器或特定的随机数库。确保随机数生成的质量和随机性是重要的安全考虑。| | Node.js | 服务端使用 express 搭建 web 服务,express.js 是基于 Node.js 运行的,因此 Node.js 自身是 Express.js 的外部依赖项。你需要确保 Node.js 的安全性,包括维护最新的 Node.js 版本,以便获得安全更新。 | | Express.js 框架 | Express.js 是一个基于 Node.js 的快速、开源、极简的迷你服务端框架,它为 Web 和移动应用提供了一组强大的功能和工具。这些功能包括路由系统、中间件支持和简易的 API,让开发者方便地处理和响应 HTTP 请求。同时,通过支持多种模板引擎,使得生成和提供动态 Web 页面变得更加简单和高效。 | | NeDB 模块 | NeDB 是一种轻量级的 JavaScript 数据库,存放在单个文件中,用于应用程序需要持久性存储的场合。NeDB 支持完全的 javascript 查询语言,几乎与 MongoDB 的查询语法一模一样。数据库存储了用户以及消息数据,需要维护最新的 NeDB 版本,确保数据库的安全性,包括访问控制、数据加密和备份。 | | Json-web-token 模块 | JSON Web Token (JWT) 是一种用于认证和授权的轻量级的开放标准(RFC 7519)。它用于在两个或多个方之间安全地传输信息。JWT 通常包含在 HTTP Header 的 Authorization 字段中,用来实现无状态的用户身份验证。JWT 是一个紧凑且自包含的表示方法,可以将声明以 JSON 对象的形式编码。JWT 的结构包含三部分:头部(Header)、负载(Payload)和签名(Signature)。 | | 浏览器环境 | 该聊天室的用户通过使用浏览器访问 Web 页面进行聊天,因此浏览器环境本身是外部依赖项。在浏览器环境下渲染编写不当的前端页面可能引入的不同安全风险,如跨站脚本攻击(XSS)或跨站请求伪造(CSRF)等。 | | Vue.js 框架 | Vue.js 是一种流行的 JavaScript 前端框架,用于构建交互式的用户界面。它专注于视图层,提供了一种简单而灵活的方式来构建可复用的组件,并通过数据驱动视图的方式实现响应式的界面更新。使用其编写前端页面时要注意避免潜在的 XSS 安全问题。 | ### 外部实体 (External Entities) | 外部实体名称 | 外部实体描述 | | --- | --- | | 服务器管理员 | 保障服务器正常运行,正确配置服务器使其满足业务需求并监控服务器运行情况。 | | 普通 Web 用户 | 他们创建和登录账户,发送和接收文本、图片等多媒体消息以及使用聊天室的各种功能。 | ### 入口点 (Entry Points) | 入口点 | 入口点描述 | | -------- | -------- | | HTTP 请求 | 用户或其他客户端发送给服务器的请求,这是获取资源或提交数据的主要方式。来自外部的请求可能包含恶意数据或攻击向量,尤其是当考虑到潜在的外部攻击者时。| | WebSocket 连接 | 用户信息和消息数据会在序列化后通过 websocket 会话发送到后端中,并被后端解码和处理为 node.js 对象,如果篡改会话中传输的对象数据可能导致服务端受到潜在攻击。 | | 文件系统访问 | 服务器从文件系统中读取图像文件以响应 HTTP 请求。虽然文件系统通常被视为受信任的,但服务器应该限制其访问权限,只读取必要的文件,并避免执行或解析任何潜在的恶意内容。| | 数据库 | 服务器会从数据库读取某些数据并返回给客户端,虽然数据库保存在受信任程度较高的服务器上,但是如果数据库中被插入了精心构造的恶意数据,那么服务器在读取这些数据时就会受到潜在的攻击。 | ### 出口点 (Exit Points) | 出口点 | 出口点描述 | | -------- | -------- | | HTTP 响应 | 服务端发送给用户或其他客户端的响应,包括请求的资源、错误消息等应该只包含预期的内容,并避免泄露敏感信息。| | 错误和日志消息 | 服务端生成错误或日志消息并通过 `console.log` 方式输出到终端中。 | | 数据库 | 服务端将聊天室用户的信息和消息数据写入到指定的数据库文件中。 | ### 资产 (Assets) | 资产名 | 资产描述 | | -------- | -------- | | 服务器数据 | 托管在服务器上的所有内容,静态页面、图片、文件、脚本以及保存了用户信息、聊天数据、会话数据的数据库。 | | 配置信息 | 服务器的配置文件、环境变量或非启动参数等内容。 | | 日志信息 |服务器生成的日志,包括用户活动、错误、性能统计等。 | | 认证和访问控制相关数据 |包括加密或解密系统传输数据的密钥、文件hash值、服务器认证的令牌等。| ### 信任等级 (Trust Levels) | 信任等级 | 信任等级描述 | 关联的实体 | | -------- | -------- | -------- | |完全信任|系统完全信任该实体,并允许它执行所有操作,这样的实体一般具有完全的系统访问权限|服务器管理员| |受限信任|虽然系统信任该实体,但它的操作受到某些限制,这样的实体可能只能访问特定的资源或执行特定的操作|操作系统| |不信任|系统不信任该实体,并且对其实施严格的限制,通常,这样的实体只能访问公共资源,并且其操作受到严格的限制|聊天室用户| ### 绘制数据流图 (Data Flow Diagrams) ![](https://hackmd.io/_uploads/r1JQy28Gp.png) ## 二、威胁分析(STRIDE-per-interaction) | 编号 | 目标元素 | 交互 | S | T | R | I | D | E | | ---- | -------- | ---- | --- | --- | --- | --- | --- | --- | | 1 | 会话连接 | 受到来自 Web 用户的 websocket连接请求 | √ | √ | | √ | | | | 2 | 登录事件 | 用户通过建立好的会话发送序列化数据请求登录 | √ | √ | | √ | √ | | | 3 | 消息事件 | 用户向其它用户或群组中发送消息 | | √ | √ | √ | √ | | | 4 | 认证与授权 | 收到认证请求后读取用户信息、校验用户信息以及自动创建新用户 | √ | | √ | √ | | √ | | 5 | NeDB 数据库操作 | 调用封装好的库使用对应的数据库原语对数据库进行增删改查操作 | | √ | | √ | | | | 6 | 浏览器页面渲染 | 浏览器渲染从服务端返回的静态资源以及动态数据 | √ | √ | | √ | | | - <font color=#FF000 face="monospace" >**1-S**</font>:攻击者可能会伪造请求头中的 token 字段,从而伪造用户身份; - <font color=#FF000 face="monospace" >**1-T**</font>:请求头中的 token 字段使用 JWT 编码,可能会受到暴力猜解算法攻击,猜解成功可以篡改其中被加密存储的数据; - <font color=#FF000 face="monospace" >**1-I**</font>:每次启动使用静态的 JWT 密钥,存在密钥泄露问题; - <font color=#FF000 face="monospace" >**2-S**</font>:攻击者可能尝试伪造用户登录时序列化传输的数据来伪装别的用户登录; - <font color=#FF000 face="monospace" >**2-T**</font>:攻击者可能通过修改序列化传输的用户对象插入特殊的属性和值,造成潜在的原型链污染及任意代码执行; - <font color=#FF000 face="monospace" >**2-I**</font>:以明文方式传输用户密码等数据可能会造成敏感信息泄露; - <font color=#FF000 face="monospace" >**2-D**</font>:并未限制用户登录和创建的速率,可以通过频繁创建新用户向数据库中写入大量数据造成拒绝服务攻击; - <font color=#FF000 face="monospace" >**3-T**</font>:消息传递过程中,攻击者可以通过修改序列化传输的消息对象插入特殊的属性和值,造成潜在的原型链污染及任意代码执行; - <font color=#FF000 face="monospace" >**3-R**</font>:消息传递过程中并没有明显的消息完整性保护措施,因此可能存在伪造发送人身份的风险; - <font color=#FF000 face="monospace" >**3-I**</font>:明文方式传输消息可能存在敏感信息泄露的风险; - <font color=#FF000 face="monospace" >**3-D**</font>:并未限制消息发送的速率,可以通过发送大量消息向数据库写入大量数据造成拒绝服务攻击; - <font color=#FF000 face="monospace" >**4-S**</font>:认证过程使用明文比对且没有对猜解攻击进行防御,可能导致潜在的字典攻击或基于时间的测信道攻击导致用户身份被盗用; - <font color=#FF000 face="monospace" >**4-R**</font>:用户登录的真实 IP 可以通过 HTTP 请求头伪造,导致无法溯源潜在的非法登录的用户; - <font color=#FF000 face="monospace" >**4-I**</font>:可以通过碰撞用户名的方式遍历当前存在的用户; - <font color=#FF000 face="monospace" >**4-E**</font>:用户认证信息中的类型字段可控且未做校验,可能导致潜在的用户权限提升攻击; - <font color=#FF000 face="monospace" >**5-T**</font>:攻击者可能在对象中插入特殊的字段与攻击载荷改变正常数据库原语从而篡改原有数据; - <font color=#FF000 face="monospace" >**5-I**</font>:攻击者可能在对象中插入特殊的字段与攻击载荷改变正常数据库原语进一步泄露整个数据库中的所有数据; - <font color=#FF000 face="monospace" >**6-S**</font>:开发者在编写前端代码时可能造成 XSS 漏洞,攻击者可以进行 CSRF 攻击仿冒用户身份进行网络请求; - <font color=#FF000 face="monospace" >**6-T**</font>:攻击者借助前端 XSS 漏洞可以篡改特定信息达到欺骗和引导用户的目的; - <font color=#FF000 face="monospace" >**6-I**</font>:攻击者借助前端 XSS 漏洞可以盗取用户本地存储的某些凭据。 ## 三、风险评级(Severity of the Risk) 此处选取 1S, 2T, 3D, 5T, 6S 为样例,进行风险评级的分析 ### 可能性(Likelihood) <img src="https://hackmd.io/_uploads/ByI8b4Kfa.png" alt="风险评级-可能性" style="zoom:50%;" /> ### 影响(Impact) <img src="https://hackmd.io/_uploads/B1k7bVKfa.png" alt="风险评级-影响" style="zoom:50%;" /> ### 风险(Risk) <img src="https://hackmd.io/_uploads/BkO2ZVFf6.png" alt="风险评级-可能性" style="zoom:50%;" /> $$ Risk = Likelihood * Impact $$

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully