【ARTS】01_07_左耳听风-20181224~1230
ARTS:
- Algrothm: leetcode算法題目
- Review: 閱讀并且點評一篇英文技術文章
- Tip/Techni: 學習一個技術技巧
- Share: 分享一篇有觀點和思考的技術文章
Algorithm
【leetcode】Unique Morse Code Words
https://leetcode.com/problems/unique-morse-code-words/
1)problem
International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on For convenience, the full table for the 26 letters of the English alphabet is given below:[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cba" can be written as "-.-..--...", (which is the concatenation "-.-." + "-..." + ".-"). We'll call such a concatenation, the transformation of a word.Return the number of different transformations among all words we have.Example:Input: words = ["gin", "zen", "gig", "msg"]Output: 2Explanation: The transformation of each word is:"gin" -> "--...-.""zen" -> "--...-.""gig" -> "--...--.""msg" -> "--...--."There are 2 different transformations, "--...-." and "--...--.".Note:The length of words will be at most 100.Each words[i] will have length in range [1, 12].words[i] will only consist of lowercase letters.2)answer
將26個因為字母映射為摩斯電碼,然后根據每組字母每個字符對應的摩斯電碼組合起來。至于那個簡寫是為什么可以那么寫,沒搞清楚。【“cba” can be written as “-.-…–…”, (which is the concatenation “-.-.” + “-…” + “.-”).】
3)solution
#include "pch.h" #include <stdio.h> #include <string> #include <vector> #include <unordered_set> using std::string; using std::vector; using std::unordered_set;class Solution { public:int uniqueMorseRepresentations(vector<string>& words) {vector<string> morse_code = { ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.." };// vector<string> store;unordered_set<string> result_val;int count = 0;for (auto str: words){string tmp;for (auto ch: str){//-'a'是找到輸入字的索引。例如,'a' - 'a'為0.所以'a'對應于morse_code中的第一個元素。tmp += morse_code[(int)ch - (int)('a')];}result_val.insert(tmp);}return result_val.size();} };int main() {vector<string> words;words.push_back("cba");// 使用內容Solution nSolution;nSolution.uniqueMorseRepresentations(words); }Review
【漏洞挖掘】SQL 注入攻擊防御方案
https://www.netsparker.com/blog/web-security/fragmented-sql-injection-attacks/
1)場景
SQL注入產生的原因,怎么防護
2)問題難點
- SQL注入是什么?
- 怎么解決?
3)解決問題的方法
- SQL注入是什么:
在系統(例如命令解釋器,文件系統或數據庫管理系統)中,具有特殊含義的字符稱為元字符。例如,在SQL查詢上下文中,單引號和雙引號用作字符串分隔符,它們在字符串的開頭和結尾都會被使用。當字符串中含有單引號和雙引號,可是又沒有被轉義的時候,就會造成解析錯誤的問題。
- 怎么防護SQL注入?
參數化查詢的方法解決。
4)方法細節
- SQL注入是什么:
當單引號或雙引號被注入查詢時,查詢會中斷并拋出錯誤。以下是在查詢中放置引號的示例。
SELECT * FROM users WHERE user_name='USER_INPUT'當單引號被注入上面的入口點時,查詢解釋器將提示無效語法或者報告在字符串末尾找不到配對的引號。
Code: $username = "'"; $query = "SELECT * FROM users WHERE username='".$username."'"Result: SELECT * FROM users WHERE username='''在輸入的位置寫進單引號而返回錯誤可能表示來自用戶的輸入沒有以任何方式過濾或清理,并且輸入了包含對數據庫具有特殊含義的字符。
- 怎么防護SQL注入?
如果單引號被反斜杠\轉義了,那么單引號類型的SQL注入也就沒有效果了。
$username ="' or 1=1 --"; $password ="qwerty123456"; // . . . $query = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."'";select * from users where username='\' or 1=1 -- ' or password='qwerty123456';如果黑客可以控制多個點,并且這些點的值在同一個上下文中,則可以使用片段化的Payload來繞過黑名單和字符限制。
username: \ password: or 1 # $query = select * from users where username='".$username."' and password='".$password."'";select * from users where username='\' or password=' or 1 #';反斜杠中和了單引號。因此username列的值將以*password=*之后的單引號結束。這樣做將從命令中刪除所需的密碼字段。由于【or 1】命令,條件將始終返回“true”。#(hash)將忽略函數的其余部分,從而能夠繞過登錄控件和登錄表單。
htmlentities()函數防護: 設置ENT_QUOTES標志,HTML編碼會將單引號,雙引號以及tag打開和關閉轉換為其對應的HTML實體。例如,一個雙引號將被編碼為“ &QUOT ;”。
但這種方法容易因為寬字符編碼的處理方式繞過,因此并不可靠。參見:addslashes()與mysql_real_escape_string()
http://shiflett.org/blog/2006/addslashes-versus-mysql-real-escape-string
參數化查詢(Prepared Statement):參數化查詢將SQL查詢的結構與其值分開。
- PHP:
- .NET應用程序
5)總結
參數化查詢會比使用其他方法的防止SQL注入的方法靠譜,但仍然有人使用黑名單的方式來防止SQL注入漏洞,我們每天都會遇到新的信息安全策略試圖繞過這些黑名單。使用參數化查詢(Prepared Statement)可以引導系統不把用戶控制的參數作為查詢結構的一部分直接執行。
Tip
【逆向調試】OD調試腳本
1)場景
調試腳本類病毒
2)問題難點
混淆加密后,直接分析有難度。
3)解決思路
定位關鍵行為API,聯網、創建進程類的再通過棧傳參查找。
4)方法細節
- VS調試wscript.exe /x XXX.js - OD調試快捷方式運行 wscript.exe XXX.js E查看模塊,找kernel32.dll createfile,ws2_32.dll getaddrinfo 設定條件斷點,不暫停程序,記錄程序參數。 M查看內存狀態 L查看日志- apateDNS記錄網絡訪問5)總結
1、找到關鍵行為
2、推斷關鍵行為的API
3、條件斷點記錄日志
4、查看有沒有特征庫之外的域名
Share
【業務】極客時間-左耳聽風-開篇詞1
1)場景
- 怎么知道自己應該學什么
- 對待新技術如何思考
- 做一個怎樣的人
2)問題難點
- 程序員應該知道的知識
- 對技術的看法,保持熱情的方法
- 什么是Leader
3)解決思路
- 算法、數據結構、代碼整潔、Linux環境編程
- 保持對技術追求的熱情,懂得與他人交互
- 認識到做一個好的 Leader 真的不容易,你需要比大家強很多,你需要比大家付出更多;你需要容天下難容之事,你還需要保持熱情和朝氣;你需要帶領團隊守護理想,你還需要直面困難迎刃而上……
4)方法細節
極客時間-左耳聽風-開篇詞1
https://www.cnblogs.com/17bdw/p/10183216.html
5)總結
- 程序員
總結
以上是生活随笔為你收集整理的【ARTS】01_07_左耳听风-20181224~1230的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 插入数据 java_JAVA插入数据笔记
- 下一篇: 船舶航行matlab程序,基于船舶运动控