【ARTS】01_07_左耳听风-20181224~1230
ARTS:
- Algrothm: leetcode算法題目
- Review: 閱讀并且點(diǎn)評(píng)一篇英文技術(shù)文章
- Tip/Techni: 學(xué)習(xí)一個(gè)技術(shù)技巧
- Share: 分享一篇有觀點(diǎn)和思考的技術(shù)文章
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個(gè)因?yàn)樽帜赣成錇槟λ闺姶a,然后根據(jù)每組字母每個(gè)字符對(duì)應(yīng)的摩斯電碼組合起來。至于那個(gè)簡(jiǎn)寫是為什么可以那么寫,沒搞清楚。【“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'對(duì)應(yīng)于morse_code中的第一個(gè)元素。tmp += morse_code[(int)ch - (int)('a')];}result_val.insert(tmp);}return result_val.size();} };int main() {vector<string> words;words.push_back("cba");// 使用內(nèi)容Solution nSolution;nSolution.uniqueMorseRepresentations(words); }Review
【漏洞挖掘】SQL 注入攻擊防御方案
https://www.netsparker.com/blog/web-security/fragmented-sql-injection-attacks/
1)場(chǎng)景
SQL注入產(chǎn)生的原因,怎么防護(hù)
2)問題難點(diǎn)
- SQL注入是什么?
- 怎么解決?
3)解決問題的方法
- SQL注入是什么:
在系統(tǒng)(例如命令解釋器,文件系統(tǒng)或數(shù)據(jù)庫(kù)管理系統(tǒng))中,具有特殊含義的字符稱為元字符。例如,在SQL查詢上下文中,單引號(hào)和雙引號(hào)用作字符串分隔符,它們?cè)谧址拈_頭和結(jié)尾都會(huì)被使用。當(dāng)字符串中含有單引號(hào)和雙引號(hào),可是又沒有被轉(zhuǎn)義的時(shí)候,就會(huì)造成解析錯(cuò)誤的問題。
- 怎么防護(hù)SQL注入?
參數(shù)化查詢的方法解決。
4)方法細(xì)節(jié)
- SQL注入是什么:
當(dāng)單引號(hào)或雙引號(hào)被注入查詢時(shí),查詢會(huì)中斷并拋出錯(cuò)誤。以下是在查詢中放置引號(hào)的示例。
SELECT * FROM users WHERE user_name='USER_INPUT'當(dāng)單引號(hào)被注入上面的入口點(diǎn)時(shí),查詢解釋器將提示無效語法或者報(bào)告在字符串末尾找不到配對(duì)的引號(hào)。
Code: $username = "'"; $query = "SELECT * FROM users WHERE username='".$username."'"Result: SELECT * FROM users WHERE username='''在輸入的位置寫進(jìn)單引號(hào)而返回錯(cuò)誤可能表示來自用戶的輸入沒有以任何方式過濾或清理,并且輸入了包含對(duì)數(shù)據(jù)庫(kù)具有特殊含義的字符。
- 怎么防護(hù)SQL注入?
如果單引號(hào)被反斜杠\轉(zhuǎn)義了,那么單引號(hào)類型的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';如果黑客可以控制多個(gè)點(diǎn),并且這些點(diǎn)的值在同一個(gè)上下文中,則可以使用片段化的Payload來繞過黑名單和字符限制。
username: \ password: or 1 # $query = select * from users where username='".$username."' and password='".$password."'";select * from users where username='\' or password=' or 1 #';反斜杠中和了單引號(hào)。因此username列的值將以*password=*之后的單引號(hào)結(jié)束。這樣做將從命令中刪除所需的密碼字段。由于【or 1】命令,條件將始終返回“true”。#(hash)將忽略函數(shù)的其余部分,從而能夠繞過登錄控件和登錄表單。
htmlentities()函數(shù)防護(hù): 設(shè)置ENT_QUOTES標(biāo)志,HTML編碼會(huì)將單引號(hào),雙引號(hào)以及tag打開和關(guān)閉轉(zhuǎn)換為其對(duì)應(yīng)的HTML實(shí)體。例如,一個(gè)雙引號(hào)將被編碼為“ &QUOT ;”。
但這種方法容易因?yàn)閷捵址幋a的處理方式繞過,因此并不可靠。參見:addslashes()與mysql_real_escape_string()
http://shiflett.org/blog/2006/addslashes-versus-mysql-real-escape-string
參數(shù)化查詢(Prepared Statement):參數(shù)化查詢將SQL查詢的結(jié)構(gòu)與其值分開。
- PHP:
- .NET應(yīng)用程序
5)總結(jié)
參數(shù)化查詢會(huì)比使用其他方法的防止SQL注入的方法靠譜,但仍然有人使用黑名單的方式來防止SQL注入漏洞,我們每天都會(huì)遇到新的信息安全策略試圖繞過這些黑名單。使用參數(shù)化查詢(Prepared Statement)可以引導(dǎo)系統(tǒng)不把用戶控制的參數(shù)作為查詢結(jié)構(gòu)的一部分直接執(zhí)行。
Tip
【逆向調(diào)試】OD調(diào)試腳本
1)場(chǎng)景
調(diào)試腳本類病毒
2)問題難點(diǎn)
混淆加密后,直接分析有難度。
3)解決思路
定位關(guān)鍵行為API,聯(lián)網(wǎng)、創(chuàng)建進(jìn)程類的再通過棧傳參查找。
4)方法細(xì)節(jié)
- VS調(diào)試wscript.exe /x XXX.js - OD調(diào)試快捷方式運(yùn)行 wscript.exe XXX.js E查看模塊,找kernel32.dll createfile,ws2_32.dll getaddrinfo 設(shè)定條件斷點(diǎn),不暫停程序,記錄程序參數(shù)。 M查看內(nèi)存狀態(tài) L查看日志- apateDNS記錄網(wǎng)絡(luò)訪問5)總結(jié)
1、找到關(guān)鍵行為
2、推斷關(guān)鍵行為的API
3、條件斷點(diǎn)記錄日志
4、查看有沒有特征庫(kù)之外的域名
Share
【業(yè)務(wù)】極客時(shí)間-左耳聽風(fēng)-開篇詞1
1)場(chǎng)景
- 怎么知道自己應(yīng)該學(xué)什么
- 對(duì)待新技術(shù)如何思考
- 做一個(gè)怎樣的人
2)問題難點(diǎn)
- 程序員應(yīng)該知道的知識(shí)
- 對(duì)技術(shù)的看法,保持熱情的方法
- 什么是Leader
3)解決思路
- 算法、數(shù)據(jù)結(jié)構(gòu)、代碼整潔、Linux環(huán)境編程
- 保持對(duì)技術(shù)追求的熱情,懂得與他人交互
- 認(rèn)識(shí)到做一個(gè)好的 Leader 真的不容易,你需要比大家強(qiáng)很多,你需要比大家付出更多;你需要容天下難容之事,你還需要保持熱情和朝氣;你需要帶領(lǐng)團(tuán)隊(duì)守護(hù)理想,你還需要直面困難迎刃而上……
4)方法細(xì)節(jié)
極客時(shí)間-左耳聽風(fēng)-開篇詞1
https://www.cnblogs.com/17bdw/p/10183216.html
5)總結(jié)
- 程序員
總結(jié)
以上是生活随笔為你收集整理的【ARTS】01_07_左耳听风-20181224~1230的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 插入数据 java_JAVA插入数据笔记
- 下一篇: 船舶航行matlab程序,基于船舶运动控