欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

【ARTS】01_07_左耳听风-20181224~1230

发布时间:2023/12/20 编程问答 56 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【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:
$stmt = $dbh->prepare("UPDATE users SET email=:new_email WHERE id=:user_id"); $stmt->bindParam(':new_email', $email); $stmt->bindParam(':user_id', $id);
  • .NET应用程序
string sql = "SELECT * FROM Customers WHERE CustomerId = @CustomerId"; SqlCommand command = new SqlCommand(sql); command.Parameters.Add(new SqlParameter("@CustomerId", System.Data.SqlDbType.Int)); command.Parameters["@CustomerId"].Value = 1;

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)总结

  • 程序员
懂得读书:算法、数据结构、代码整洁、Unix编程 应有的知识:代码复查、编程语言和代码质量对比、不但要做出来还要写出来和说出来与他人交互 Leader:迎难而上、赢得信任、开放的心态

总结

以上是生活随笔为你收集整理的【ARTS】01_07_左耳听风-20181224~1230的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。