qzmjef 发表于 2024-7-11 05:09:08

PHP 代码加密实践


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">咱们</span><span style="color: black;">研发</span>的项目中,有一部分可能是用于<span style="color: black;">商场</span>用途,会<span style="color: black;">安排</span>在客户<span style="color: black;">供给</span>的<span style="color: black;">设备</span>环境中。<span style="color: black;">由于</span> PHP 本身是解释型语言,<span style="color: black;">因此</span>未进行处理的代码,就会有<span style="color: black;">泄密</span>或被修改的<span style="color: black;">危害</span>。<span style="color: black;">那样</span><span style="color: black;">咱们</span>可能会想到最简单有效的<span style="color: black;">办法</span><span style="color: black;">便是</span>进行加密混淆,<span style="color: black;">而后</span><span style="color: black;">协同</span>一系列的校验,来<span style="color: black;">守护</span><span style="color: black;">咱们</span>的代码。<span style="color: black;">那样</span>本篇<span style="color: black;">文案</span>中,<span style="color: black;">咱们</span>就采用了开源的 PHP 加密扩展 screw-plus 进行<span style="color: black;">关联</span>实践分析。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">日前</span>市场上有多种加密<span style="color: black;">方法</span>,但基本都是收费的。<span style="color: black;">咱们</span><span style="color: black;">这次</span>实践采用了开源的<span style="color: black;">方法</span>。screw-plus 是一款开源 php 加密运行扩展,基于 screw 二次<span style="color: black;">研发</span>,暂时只能运行在 linux 下。虽然有些不足,<span style="color: black;">然则</span><span style="color: black;">倘若</span>加强一下,<span style="color: black;">亦</span>是<span style="color: black;">能够</span>满足<span style="color: black;">有些</span>场景。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic2.zhimg.com/80/v2-a0319eb5aca9f0123e56cfd4f7a73fc9_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在介绍实现之前,<span style="color: black;">咱们</span>先简单介绍下 PHP 扩展的<span style="color: black;">关联</span>知识以及 Hook 机制。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">1 PHP 扩展周期</h2>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-e9c4cf14f967db9f30ebc39288573866_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">一款扩展的<span style="color: black;">重点</span>生命周期,<span style="color: black;">便是</span>上面的四个宏定义。</p>MINIT:扩展模块初始化时执行的动作MSHUTDOWN:扩展模块结束时执行的动作RINIT:请求初始化时的动作RSHUTDOWN:请求结束时的动作<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">对应于 zend_module_entry 结构中的四个函数指针:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">int</span> <span style="color: black;">(</span><span style="color: black;">*</span><span style="color: black;">module_startup_func</span><span style="color: black;">)(</span><span style="color: black;">INIT_FUNC_ARGS</span><span style="color: black;">);</span> <span style="color: black;">/* MINIT() */</span><span style="color: black;">int</span> <span style="color: black;">(</span><span style="color: black;">*</span><span style="color: black;">module_shutdown_func</span><span style="color: black;">)(</span><span style="color: black;">SHUTDOWN_FUNC_ARGS</span><span style="color: black;">);</span> <span style="color: black;">/* MSHUTDOWN() */</span><span style="color: black;">int</span> <span style="color: black;">(</span><span style="color: black;">*</span><span style="color: black;">request_startup_func</span><span style="color: black;">)(</span><span style="color: black;">INIT_FUNC_ARGS</span><span style="color: black;">);</span> <span style="color: black;">/* RINIT() */</span><span style="color: black;">int</span> <span style="color: black;">(</span><span style="color: black;">*</span><span style="color: black;">request_shutdown_func</span><span style="color: black;">)(</span><span style="color: black;">SHUTDOWN_FUNC_ARGS</span><span style="color: black;">);</span> <span style="color: black;">/* RSHUTDOWN() */</span>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>在实现一款扩展时,基本都会用到上面四个周期宏定义。完整的 PHP 周期见下图:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic1.zhimg.com/80/v2-481b9875201f9a84fc84d14fe58c89f8_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">本篇<span style="color: black;">文案</span>中<span style="color: black;">咱们</span>只是介绍下跟该扩展<span style="color: black;">关联</span>的信息,<span style="color: black;">倘若</span>想深入<span style="color: black;">认识</span>,<span style="color: black;">能够</span>参考底部链接,<span style="color: black;">自动</span>深入学习。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">2 PHP 扩展钩子</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在 PHP 内核中,各个执行周期几乎都有<span style="color: black;">供给</span>可重写的钩子,如下表所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">// AST, Zend/zend_ast.h:void (*zend_ast_process_t)(zend_ast *ast) // Compiler, Zend/zend_compile.h:zend_op_array *(*zend_compile_file)(zend</span></div>




情迷布拉格 发表于 2024-9-8 23:31:43

回顾过去一年,是艰难的一年;展望未来,是辉煌的一年。

m5k1umn 发表于 昨天 11:50

你的努力一定会被看见,相信自己,加油。
页: [1]
查看完整版本: PHP 代码加密实践