<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    3種常見的數據脫敏方案

    VSole2023-03-03 15:45:32

    目錄

    1. SQL數據脫敏實現
    2. JAVA數據脫敏實現
    3. mybatis-mate-sensitive-jackson

    1、SQL數據脫敏實現

    MYSQL(電話號碼,身份證)數據脫敏的實現

    -- CONCAT()、LEFT()和RIGHT()字符串函數組合使用,請看下面具體實現
     
    -- CONCAT(str1,str2,…):返回結果為連接參數產生的字符串
    -- LEFT(str,len):返回從字符串str 開始的len 最左字符
    -- RIGHT(str,len):從字符串str 開始,返回最右len 字符
     
    -- 電話號碼脫敏sql:
     
    SELECT mobilePhone AS 脫敏前電話號碼,CONCAT(LEFT(mobilePhone,3), '********' ) AS 脫敏后電話號碼 FROM t_s_user
     
    -- 身份證號碼脫敏sql:
     
    SELECT idcard AS 未脫敏身份證, CONCAT(LEFT(idcard,3), '****' ,RIGHT(idcard,4)) AS 脫敏后身份證號 FROM t_s_user
    

    2、JAVA數據脫敏實現

    可參考:海強 / sensitive-plus

    https://gitee.com/strong_sea/sensitive-plus

    數據脫敏插件,目前支持地址脫敏、銀行卡號脫敏、中文姓名脫敏、固話脫敏、身份證號脫敏、手機號脫敏、密碼脫敏 一個是正則脫敏、另外一個根據顯示長度脫敏,默認是正則脫敏,可以根據自己的需要配置自己的規則。

    3、mybatis-mate-sensitive-jackson

    mybatisplus 的新作,可以測試使用,生產需要收費。

    根據定義的策略類型,對數據進行脫敏,當然策略可以自定義。

    # 目前已有
    package mybatis.mate.strategy;
     
    public interface SensitiveType {
        String chineseName = "chineseName";
        String idCard = "idCard";
        String phone = "phone";
        String mobile = "mobile";
        String address = "address";
        String email = "email";
        String bankCard = "bankCard";
        String password = "password";
        String carNumber = "carNumber";
    }
    

    Demo 代碼目錄

    1、pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <parent>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-mate-examplesartifactId>
            <version>0.0.1-SNAPSHOTversion>
        parent>
        <modelVersion>4.0.0modelVersion>
        <artifactId>mybatis-mate-sensitive-jacksonartifactId>
        <dependencies>
            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
            dependency>
        dependencies>
     
    project>
    

    2、appliation.yml

    # DataSource Config
    spring:
      datasource:
    #    driver-class-name: org.h2.Driver
    #    schema: classpath:db/schema-h2.sql
    #    data: classpath:db/data-h2.sql
    #    url: jdbc:h2:mem:test
    #    username: root
    #    password: test
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/mybatis_mate?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
        username: root
        password: 123456
    # Mybatis Mate 配置
    mybatis-mate:
      cert:
        # 請添加微信wx153666購買授權,不白嫖從我做起! 測試證書會失效,請勿正式環境使用
        grant: thisIsTestLicense
        license: as/bsBaSVrsA9FfjC/N77ruEt2/QZDrW+MHETNuEuZBra5mlaXZU+DE1ZvF8UjzlLCpH3TFVH3WPV+Ya7Ugiz1Rx4wSh/FK6Ug9lhos7rnsNaRB/+mR30aXqtlLt4dAmLAOCT56r9mikW+t1DDJY8TVhERWMjEipbqGO9oe1fqYCegCEX8tVCpToKr5J1g1V86mNsNnEGXujnLlEw9jBTrGxAyQroD7Ns1Dhwz1K4Y188mvmRQp9t7OYrpgsC7N9CXq1s1c2GtvfItHArkqHE4oDrhaPjpbMjFWLI5/XqZDtW3D+AVcH7pTcYZn6vzFfDZEmfDFV5fQlT3Rc+GENEg==
     
    # Logger Config
    logging:
      level:
        mybatis.mate: debug
    

    3、Appliation啟動類

    package mybatis.mate.sensitive.jackson;
     
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
     
    @SpringBootApplication
    public class SensitiveJacksonApplication {
     
        // 測試訪問 http://localhost:8080/info ,http://localhost:8080/list
        public static void main(String[] args) {
            SpringApplication.run(SensitiveJacksonApplication.class, args);
        }
    }
    

    4、配置類,自定義脫敏策略

    package mybatis.mate.sensitive.jackson.config;
     
    import mybatis.mate.databind.ISensitiveStrategy;
    import mybatis.mate.strategy.SensitiveStrategy;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
     
    @Configuration
    public class SensitiveStrategyConfig {
     
        /**
         * 注入脫敏策略
         */
        @Bean
        public ISensitiveStrategy sensitiveStrategy() {
            // 自定義 testStrategy 類型脫敏處理
            return new SensitiveStrategy().addStrategy("testStrategy", t -> t + "***test***");
        }
    }
    

    5、業務類

    User,注解標識脫敏字段,及選用脫敏策略

    package mybatis.mate.sensitive.jackson.entity;
     
    import lombok.Getter;
    import lombok.Setter;
    import mybatis.mate.annotation.FieldSensitive;
    import mybatis.mate.sensitive.jackson.config.SensitiveStrategyConfig;
    import mybatis.mate.strategy.SensitiveType;
     
    @Getter
    @Setter
    public class User {
        private Long id;
        /**
         * 這里是一個自定義的策略 {@link SensitiveStrategyConfig} 初始化注入
         */
        @FieldSensitive("testStrategy")
        private String username;
        /**
         * 默認支持策略 {@link SensitiveType }
         */
        @FieldSensitive(SensitiveType.mobile)
        private String mobile;
        @FieldSensitive(SensitiveType.email)
        private String email;
     
    }
    

    UserController

    package mybatis.mate.sensitive.jackson.controller;
     
    import mybatis.mate.databind.ISensitiveStrategy;
    import mybatis.mate.databind.RequestDataTransfer;
    import mybatis.mate.sensitive.jackson.entity.User;
    import mybatis.mate.sensitive.jackson.mapper.UserMapper;
    import mybatis.mate.strategy.SensitiveType;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
     
    import javax.servlet.http.HttpServletRequest;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
     
    @RestController
    public class UserController {
        @Autowired
        private UserMapper userMapper;
        @Autowired
        private ISensitiveStrategy sensitiveStrategy;
     
        // 測試訪問 http://localhost:8080/info
        @GetMapping("/info")
        public User info() {
            return userMapper.selectById(1L);
        }
     
        // 測試返回 map 訪問 http://localhost:8080/map
        @GetMapping("/map")
        public Map map() {
            // 測試嵌套對象脫敏
            Map userMap = new HashMap<>();
            userMap.put("user", userMapper.selectById(1L));
            userMap.put("test", 123);
            userMap.put("userMap", new HashMap() {{
                put("user2", userMapper.selectById(2L));
                put("test2", "hi china");
            }});
            // 手動調用策略脫敏
            userMap.put("mobile", sensitiveStrategy.getStrategyFunctionMap()
                    .get(SensitiveType.mobile).apply("15315388888"));
            return userMap;
        }
     
        // 測試訪問 http://localhost:8080/list
        // 不脫敏 http://localhost:8080/list?skip=1
        @GetMapping("/list")
        public List list(HttpServletRequest request) {
            if ("1".equals(request.getParameter("skip"))) {
                // 跳過脫密處理
                RequestDataTransfer.skipSensitive();
            }
            return userMapper.selectList(null);
        }
    }
    

    UserMapper

    package mybatis.mate.sensitive.jackson.mapper;
     
    import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    import mybatis.mate.sensitive.jackson.entity.User;
    import org.apache.ibatis.annotations.Mapper;
     
    @Mapper
    public interface UserMapper extends BaseMapper<User> {
     
    }
    

    6、測試

    GET http://localhost:8080/list

    [
      {
        "id": 1,
        "username": "Jone***test***",
        "mobile": "153******81",
        "email": "t****@baomidou.com"
      },
      {
        "id": 2,
        "username": "Jack***test***",
        "mobile": "153******82",
        "email": "t****@baomidou.com"
      },
      {
        "id": 3,
        "username": "Tom***test***",
        "mobile": "153******83",
        "email": "t****@baomidou.com"
      }
    ]
    

    GET http://localhost:8080/list?skip=1

    [
      {
        "id": 1,
        "username": "Jone",
        "mobile": "15315388881",
        "email": "test1@baomidou.com"
      },
      {
        "id": 2,
        "username": "Jack",
        "mobile": "15315388882",
        "email": "test2@baomidou.com"
      },
      {
        "id": 3,
        "username": "Tom",
        "mobile": "15315388883",
        "email": "test3@baomidou.com"
      }
    ]
    
    string數據脫敏
    本作品采用《CC 協議》,轉載必須注明作者和本文鏈接
    脫敏前電話號碼,CONCAT(LEFT(mobilePhone,3),?身份證號碼脫敏sql:. 根據定義的策略類型,對數據進行脫敏,當然策略可以自定義。請添加微信wx153666購買授權,不白嫖從我做起!?測試證書會失效,請勿正式環境使用
    可以認為IAM分成兩類,一個是AWS提供的IAM,這是一個完整的身份管理系統,但AWS只提供了系統,基于該系統的配置及信息維護,由客戶完全負責。AWS 提供了虛擬網絡及其之上的VPC,子網,ACL,安全組等,客戶需要準確設計配置自己的網絡,以確保正確的隔離和防護。用戶控制權限的修改通常由特權用戶或者管理員組實現。
    2020年3月9日,國家市場監督管理總局、國家標準化管理委員會發布中華人民共和國國家標準公告(2020年第1號),全國信息安全標準化技術委員會歸口的國家標準GB/T 35273-2020《信息安全技術 個人信息安全規范》完成修...
    經常會遇到這樣一種情況:項目的配置文件中總有一些敏感信息,比如數據源的url、用戶名、密碼....這些信息一旦被暴露那么整個數據庫都將會被泄漏,那么如何將這些配置隱藏呢?今天介紹一種方案,讓你在無感知的情況下實現配置文件的加密、解密。
    Android 應用gl,使用了加固i,老版本的應用gl是js源碼,新版本更新后,剛開始以為是加密了源碼,分析后才知道是使用了Hermes優化引擎。Hermes優化的優化效果如下:優化前:優化后:二、前期準備2.1 繞過root檢測應用gl使用了加固i,在被root 的手機上運行,閃退。繞過方法也很簡單,在magisk的設置中,開啟遵守排除列表,然后在配置排除列表中選擇應用gl。
    文章主要內容記錄對某次應急事件中獲取到的特殊釣魚樣本的分析,該樣本通過sapien powershell studio將powershell代碼封裝成可執行文件來繞過一些查殺和限制;0x01 背景某次應急事件中拿到一個攻擊者使用的釣魚樣本,這個樣本比較有意思和之前的分析有些不同,第一次分析也算曲折,此文記錄下對該樣本的分析過程。光從行為側去下結論是不太行的。
    文章主要內容記錄對某次應急事件中獲取到的特殊釣魚樣本的分析,該樣本通過sapien powershell studio將powershell代碼封裝成可執行文件來繞過一些查殺和限制;0x01 背景某次應急事件中拿到一個攻擊者使用的釣魚樣本,這個樣本比較有意思和之前的分析有些不同,第一次分析也算曲折,此文記錄下對該樣本的分析過程。光從行為側去下結論是不太行的。
    根據廠商的要求,在修補后的固件未發布前,我對該漏洞細節進行了保密。若讀者將本文內容用作其他用途,由讀者承擔全部法律及連帶責任,文章作者不承擔任何法律及連帶責任。此時,我們驚喜地發現xxx系列產品的xxx型號固件并沒有被加密,可以成功解開。漏洞分析此部分以xxx固件為例進行分析,該固件是aarch64架構的。其他固件也許架構或部分字段的偏移不同,但均存在該漏洞。找到無鑒權的API接口顯然,此類固件的cgi部分是用Lua所寫的。
    C:\Users\bk\Desktop\天府科技云APP\天府科技云服務平臺\天府科技云服務平臺.apkC:\Program Files\Java\jdk1.8.0_111\bin\jarsigner.exe?文件將解壓出來的classes.dex文件拷貝到dex2jar工具文件夾中執行命令:d2j-dex2jar classes.dex執行完畢后,得到反編譯而來的classes-dex2jar.jar文件使用jd-gui.exe或者luyten-0.5.4打開 classes-dex2jar.jar文件,得到360安全加固混淆加密的源代碼。應同時使用V1+V2簽名)6.應用完整性校檢將反編譯出來源碼中修改圖片文件名為test.png進行重新生成apk包,命令如下:java -jar apktool.jar b -f?
    VSole
    網絡安全專家
      亚洲 欧美 自拍 唯美 另类