2019年12月13日星期五

SQL injection





SQL注入(英語:SQL injection),也稱SQL隱碼SQL注碼,是發生於應用程式與資料庫層的安全漏洞。簡而言之,是在輸入的字串之中夾帶SQL指令,在設計不良的程式當中忽略了字元檢查,那麼這些夾帶進去的惡意指令就會被資料庫伺服器誤認為是正常的SQL指令而執行,因此遭到破壞或是入侵。


  • 方法1:在網頁的 “輸入的字串”   , 夾帶SQL指令 : 
    • 說明:






    • 範例:
帳號密碼輸入 : 1' OR '1'='1
如果可以登入,表示 SQL injection成功








  • 方法2 :


例如:
原本網址:/junior/api-info?id=297ea9e66cd5c297016cdd7cc0670003
修改為:/junior/api-info?id=297ea9e66cd5c297016cdd7cc0670003 or 1=1 







2019年10月1日星期二

縣市 鄉鎮 下拉選單 郵遞區號


找到幾個不錯的範例 :

  • jquery 縣市 鄉鎮 下拉選單


https://wenchunhuang.pixnet.net/blog/post/34598691-jquery-%E7%B8%A3%E5%B8%82-%E9%84%89%E9%8E%AE-%E4%B8%8B%E6%8B%89%E9%81%B8%E5%96%AE












2019年8月22日星期四

Intellij IDEA整合 spring profile



例如:
- application.properties  (containing common properties)
 - application-local.properties


  • Choosing Run | Edit Configurations...
  • Go to the Configuration tab
  • Expand the Environment section to reveal VM options

  • -Dspring.profiles.active=local




    最後  , Build > Rebuild Project 才會生效


    參考 :
    https://stackoverflow.com/questions/39738901/how-do-i-activate-a-spring-boot-profile-when-running-from-intellij


    2019年7月15日星期一

    BindingResult 用法


    今天踩到一個地雷


    这里一个@Valid的参数后必须紧挨着一个BindingResult 参数,否则spring会在校验不通过时直接抛出异常

    例如:
    @RequestMapping("/login")
        public String testValid(@Valid User user, BindingResult result){
    
    


    2019年3月28日星期四

    android app - 取得 SHA-256 , SHA1 and MD5


    1. 以下是方法:


    1. 1. Faster way:
    1. Open Android Studio
    2. Open your Project
    3. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
    4. Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of your Project)
    5. Click on Your Project (Your Project Name form List (root))
    6. Click on Tasks
    7. Click on Android
    8. Double Click on signingReport (You will get SHA1 and MD5 in Run Bar(Sometimes it will be in Gradle Console))
    9. Select app module from module selection dropdown to run or debug your application

    1.2 比較慢的方式:
    keytool -exportcert -keystore path-to-debug-or-production-keystore -list -v

    2. 使用時機 : 
    android app 使用google sign in API的時候,
    需要到google網站上面登錄app的 --> 
    SHA-1 簽署憑證指紋 

    3. 參考:




    2019年3月18日星期一

    Google sign-in for Android



    1. Google sign-In 流程如下 :

    參考:  https://developers.google.com/identity/sign-in/android/backend-auth


    流程說明:
        1.1 Google sign in 之後, 會得到Google id token
        1.2 Google id token是google id 動態加密後的結果
        1.3 要解密得到google id , 需要安裝google Library,以及加上一些程式(下面會提到)
        1.4 取得google id之後,就是我們自己的登入流程


    2. Google Library :

    在pom.xml增加以下的設定:

      com.google.api-client
      google-api-client
      1.24.1



      com.google.api-client
      google-api-client-gson
      1.25.0



    3. Server side sample :


    @RestController
    public class GoogleSignInController {
        private static final String CLIENT_ID = "xxxxxx-xxxxxx.apps.googleusercontent.com";
    
        @RequestMapping(value = "/googlesignin" ,method = RequestMethod.POST)
        public String googleSignIn(@RequestParam(value="idToken")String idTokenString){
            String result = "Invalid ID token.";
    
            JsonFactory jsonFactory = new GsonFactory();
            NetHttpTransport transport = new NetHttpTransport();
            GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)
                    .setAudience(Collections.singletonList(CLIENT_ID))
                    .build();
    
            // (Receive idTokenString by HTTPS POST)
            GoogleIdToken idToken = null;
            try {
                idToken = verifier.verify(idTokenString);
            } catch (GeneralSecurityException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (idToken != null) {
                GoogleIdToken.Payload payload = idToken.getPayload();
                // Print user identifier
             String googleUserId = payload.getSubject();
                System.out.println("Google User ID: " + googleUserId);
                // todo : Use googleUserId 到資料庫查詢 member profile
                // ...
            }
            return result;
        }
    |

    2019年2月14日星期四

    Android KeyStore 應用


    當android app需要save 帳密等敏感性資料時候,

    google 建議要加密 .
    ===============================
    產生加解密Key的方式, google 建議使用Android KeyStore 
    ===============================

    主要提供了三種功能:

    1. 隨機產生Key
    2. 限制Key的用途(加密、解密、認證⋯⋯)
    3. 安全地存放Key(至少官方是這麼說的)
    知道KeyStore的功能之後,我們就可以存取敏感性資料。
    ===============================
    參考:
    https://medium.com/joe-tsai/%E4%BD%BF%E7%94%A8keystore-%E5%84%B2%E5%AD%98%E6%95%8F%E6%84%9F%E6%80%A7%E8%B3%87%E6%96%99-92ad9b236e58
    ===============================

    要求进行用户身份验证才能使用密钥

    生成密钥或将密钥导入到 AndroidKeyStore 时,您可以指定密钥仅授权给经过身份验证的用户使用。用户使用安全锁定屏幕凭据(模式/PIN/密码、指纹)的子集进行身份验证。
    ===============================
    如果密钥仅授权给经过身份验证的用户使用,可以将其配置为以下列两种模式之一运行:
    • 经过身份验证的用户可以在一段时间内使用密钥。在用户解锁安全锁定屏幕或使用 KeyguardManager.createConfirmDeviceCredentialIntent 流程确认其安全锁定屏幕凭据后,即可使用此模式中的所有密钥。每个密钥的授权持续时间各不相同,并由 setUserAuthenticationValidityDurationSeconds 在密钥生成或导入时指定。此类密钥只能在启用安全锁定屏幕时生成或导入(请参阅 KeyguardManager.isDeviceSecure())。在安全锁定屏幕停用(重新配置为“无”、“滑动”或不验证用户身份的其他模式)或被强制重置(例如由设备管理员执行)时,这些密钥将永久失效。
    • 用户身份验证会授权与某一密钥关联的特定加密操作。在此模式中,涉及此类密钥的每个操作都需要用户单独授权。目前,此类授权的唯一方式是指纹身份验证:FingerprintManager.authenticate。此类密钥只能在至少注册一个指纹时生成或导入(请参阅 FingerprintManager.hasEnrolledFingerprints)。一旦注册新指纹或取消注册所有指纹,这些密钥将永久失效。


    作者:烟雨随风
    链接:https://www.jianshu.com/p/65b2aa6ec85f
    來源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

    ===============================








    2019年2月13日星期三

    兩個 檔案 比較 工具


    Total Commander 是一款應用於 Windows 平台的檔案管理器,它包含兩個並排的窗口,這種設計可以讓用戶方便地對不同位置的「檔案或資料夾」進行操作,例如複製、移動、刪除、比較等,相對 Windows 檔案總管而言方便很多,極大地提高了檔案操作的效率,被廣大軟體愛好者親切地簡稱為:TC



    Beyond Compare是一套由Scooter Software推出的內容比較工具軟體。