CM2025 Midterm · Secure by Design
EN 中文 作业 PDF · 页内阅读 下方可直接阅读完整期中报告;点 EN / 中文切换评论正文。 新标签打开 PDF Reference Guide · Hands-On Hacking™ — practice notes for authorized labs only. Introduction Recently, I completed the midterm project for the CM2025 Cyber Security undergraduate course at the University of London. This assignment covered threat intelligence analysis (such as applying the NIST CSF framework), fundamental OS security, code-level vulnerability remediation (e.g., SQL injection and hardcoded credentials), and practical cryptography. Upon finishing the code and report, my biggest takeaway was this: university education establishes the "minimum compliance baseline" for security defense, but in today's real-world production environments, if we only focus on mitigating "textbook-level" vulnerabilities, our systems will remain riddled with holes. Using my midterm assignment as a starting point, this blog post will critically examine the true threats facing modern websites through the lens of real-world business risk control and penetration testing. 1. Shattering the Illusion: Basic Vulnerabilities "Dead" in Textbooks In Part B of the assignment, we were required to fix a Python script containing a SQL injection vulnerability. The original code constructed queries via simple string concatenation, allowing attackers to easily bypass authentication and gain admin access by inputting ' OR '1'='1. The provided solution was to use parameterized queries, strictly treating user input as data rather than executable code. Real-World Critique: From an academic perspective, this example perfectly illustrates the nature of injection flaws. However, in modern commercial web development, such pure string-concatenation injections are exceedingly rare. Modern backends have almost universally adopted mature frameworks or advanced ORM tools, where parameterized queries are the default underlying configuration. In real-world offensive and defensive scenarios, the "injections" faced by modern security engineers are often hidden much deeper: for instance, API abuse in complex business logic, or blind injections caused by developers forcing raw SQL methods to achieve dynamic queries. Fixing ' OR '1'='1 is merely the passing grade; establishing strict input validation whitelists and parameter type constraints at the API level is the norm for modern risk control. 2. The Real Battlefield: Software Supply Chains and Third-Party Dependencies If the SQL injection in the assignment is too idealized, the analysis of the MOVEit zero-day vulnerability (CVE-2023-34362) and the DPRK APT group's supply chain attacks in Part A hits the absolute pain point of modern web security. The May 2023 MOVEit flaw exploited a web interface SQL injection to achieve remote code execution, ultimately allowing the Cl0p ransomware gang to steal massive amounts of data globally. Real-World Critique: Modern web architectures rely heavily on external components. Your core code might be flawless, but the moment you integrate a third-party payment gateway, upload a vulnerable open-source dependency, or use a file transfer service like MOVEit, your system's defenses can be instantly breached. We need to establish dynamic tracking mechanisms similar to an SBOM (Software Bill of Materials). This is no longer just the developer's responsibility, but a "Zero Trust" model that must be considered during architectural design: assuming third-party services could be compromised at any time, how do we limit lateral movement through network segmentation and strict access controls? 3. Credential Management: From Environment Variables to Dynamic Secrets Another focus of the assignment was fixing hardcoded credentials in the source code. Writing plaintext database passwords in code is highly dangerous, and the assignment demonstrated how to move sensitive information into environment variables by introducing a .env file and the os.getenv() method. Real-World Critique: Extracting keys to environment variables is absolutely a step in the right direction, but it remains rooted in a standalone-server mindset. In modern, cloud-native clusters, static .env files still carry the risks of configuration drift and accidental leakage. The current industry standard is to introduce dynamic secrets management (like HashiCorp Vault or AWS Secrets Manager). Services obtain short-lived, dynamically generated database credentials at runtime through strong authentication. In the event of a leak, these credentials automatically expire within minutes, compressing the attack window to an absolute minimum. 4. Applied Cryptography: The Necessity of Understanding Underlying Logic In the final part of the assignment, I used PyCryptodome to implement an AES-256-CBC encryption and decryption tool with PKCS7 padding. The code demonstrated how to use a 256-bit key and a randomly generated 16-byte Initialization Vector (IV) for each operation to ensure that every encrypted output is unique, thereby preventing replay attacks and pattern guessing. Real-World Reflection: In modern development, business programmers are rarely allowed to write underlying encryption logic manually, as the slightest mistake can collapse the entire cryptographic system. The current standard practice is to call a cloud provider's KMS (Key Management Service). However, understanding these underlying mechanisms remains highly valuable. When facing compliance audits or debugging cross-language inter-service encryption errors, understanding the fundamental logic of symmetric encryption block alignment, the role of IVs, and padding methods allows you to pinpoint problems swiftly. Conclusion: Secure by Design Completing the CM2025 midterm project made me profoundly realize: university courses teach us the fundamental laws of computer science and security frameworks (such as the NIST CSF's Identify, Protect, Detect, Respond, Recover). These laws will never go out of style. However, as modern developers and engineers, we must integrate these theories with the complex realities of the industry. Modern web security is no longer as simple as patching a few SQL injection points; it is a systems engineering effort involving architectural design, supply chain auditing, automated CI/CD security checks, and in-depth business risk control. Only by truly achieving "Secure by Design" can we build genuinely robust digital fortresses in this unpredictable cyber environment. Hands-On Hacking™ 参考笔记 — 仅限授权实验环境。 前言 最近,我完成了伦敦大学计算机科学本科《CM2025 Cyber Security》课程的期中项目。这份作业涵盖了威胁情报分析(如 NIST CSF 框架应用)、基础的操作系统安全、以及代码层面的漏洞修复(如 SQL 注入与硬编码凭证)和密码学基础。 完成代码和报告后,我最大的感触是:学校教育为我们确立了安全防御的“最低合规基线”,但在目前的真实生产环境中,如果我们仅仅停留在防御“教科书级别”的漏洞上,系统依然会千疮百孔。这篇博客将以我的期中作业为引子,结合真实的业务风控与渗透测试视角,批判性地探讨现代网站所面临的真正威胁。 一、破除幻觉:那些“死”在教科书里的基础漏洞 在作业的 Part B 中,我们被要求修复一段存在 SQL 注入漏洞的 Python 代码。原始代码通过简单的字符串拼接构建查询,导致攻击者可以通过输入 ' OR '1'='1 轻松绕过验证,获取管理员权限。作业提供的修复方案是使用参数化查询(Parameterized queries),将用户输入严格作为数据而非可执行代码处理。 实战批判: 从学术角度看,这个例子完美解释了注入漏洞的本质。但在现代商业网站开发中,这种纯粹的字符拼接注入已经极其罕见。现代后端几乎全面拥抱了成熟框架,或者使用高级 ORM 工具,参数化查询早已是底层默认配置。在真实的攻防实战中,现代安全工程师面对的“注入”往往隐藏在更深层:例如复杂业务逻辑的 API 滥用,或是开发者为了实现动态查询强行调用原生 SQL 方法而引发的盲注。修复 ' OR '1'='1 只是开发的及格线;在接口层面建立严格的输入校验白名单和参数类型约束,才是现代风控的常态。 二、真正的战场:软件供应链与第三方依赖 如果说作业里的 SQL 注入过于理想化,那么作业 Part A 中分析的 MOVEit 零日漏洞(CVE-2023-34362)和朝鲜 APT 组织的供应链攻击,则切中了现代 Web 安全的最痛点。2023 年 5 月的 MOVEit 漏洞正是利用了 Web 界面的 SQL 注入实现远程代码执行,最终导致 Cl0p 勒索软件在全球范围内窃取了海量数据。 实战批判: 现代网站架构高度依赖外部组件。你的核心代码可能完美无瑕,但只要你接入了第三方的支付网关、上传了存在漏洞的开源依赖,或者使用了类似 MOVEit 这样的文件传输服务,系统的防线就能被瞬间击穿。我们需要建立类似 SBOM(软件物料清单)的动态追踪机制。这不再仅仅是开发者的责任,更是架构设计时必须考虑的“零信任(Zero Trust)”模型:假设第三方服务随时可能被攻陷,我们该如何通过网络分段和严格的权限控制来限制横向移动(Lateral Movement)? 三、凭证管理:从环境变量到动态机密 作业的另一个重点是修复源代码中的硬编码凭证(Hardcoded Credentials)。将明文的数据库密码写在代码中是非常危险的,作业演示了如何通过引入 .env 文件和 os.getenv() 方法,将机密信息转移到环境变量中。 实战批判: 将密钥抽离到环境变量绝对是正确的迈步,但这依然停留在单机时代的思维。在云原生主导的现代集群中,静态的 .env 文件依然存在配置漂移和意外泄露的风险。工业界目前的标准做法是引入动态机密管理(如 HashiCorp Vault 或 AWS Secrets Manager)。服务在运行时通过强身份认证获取短期、动态生成的数据库凭证。一旦发生泄露,这些凭证会在几分钟后自动失效,将攻击窗口期压缩到极致。 四、密码学落地:理解底层逻辑的必要性 在作业的最后部分,我使用 PyCryptodome 实现了一个带有 PKCS7 填充的 AES-256-CBC 加密与解密工具。代码展示了如何利用 256 位密钥和每次随机生成的 16 字节初始化向量(IV)来保证每次加密输出的密文都不同,从而防止重放攻击和模式推测。 实战思考: 在现代开发中,业务程序员很少被允许直接手写底层加密逻辑,因为稍有不慎就会导致整个加密体系崩溃。现在的常规做法是调用云服务商的 KMS(密钥管理服务)。然而,理解这些底层机制依然极具价值。当你面对合规性审查,或者需要调试跨语言的服务间加密通信报错时,理解对称加密的块对齐、IV 的作用以及填充方式(Padding)的底层逻辑,能让你迅速定位问题所在。 结语 完成 CM2025 的期中项目,让我深刻意识到:大学课程教给我们的是计算机科学的基础法则和安全框架(如 NIST CSF 的识别、保护、检测、响应、恢复)。这些法则永远不会过时。 但是,作为现代开发者和工程师,我们必须将这些理论与工业界的复杂现状结合起来。现代 Web 安全不再是修补几个 SQL 注入点那么简单,它是一项涉及架构设计、供应链审查、自动化 CI/CD 审计以及深度业务风控的系统工程。只有真正做到“默认安全(Secure by Design)”,我们才能在这个充满未知的网络环境中,构建出真正坚固的数字堡垒。 仅在授权范围内使用。Illegal use is not endorsed. 🍌