做技術(shù)網(wǎng)站在背景圖產(chǎn)品推廣步驟
網(wǎng)上看到的一些關(guān)于網(wǎng)絡(luò)安全的學(xué)習(xí)資料小結(jié)。
對(duì)稱加密: 通信雙方共享同一個(gè)密鑰。發(fā)送方用它來加密,接收方用它來解密。
非對(duì)稱加密: 有公鑰和私鑰。
現(xiàn)在的做法一般是用非對(duì)稱加密生成?鑰(公鑰還是私鑰?)用于傳輸?,然后再用對(duì)稱加密進(jìn)行通信。
加密 : 公鑰加密,私鑰解密 (公鑰是lock,私鑰是key)
數(shù)字簽名證書: 私鑰加密(生成簽名),公鑰解密(驗(yàn)證簽名)
既然是加密,那肯定是不希望別人知道我的消息,所以只有我才能解密,所以可得出公鑰負(fù)責(zé)加密,私鑰負(fù)責(zé)解密;同理,既然是簽名,那肯定是不希望有人冒充我發(fā)消息,只有我才能發(fā)布這個(gè)簽名,所以可得出私鑰負(fù)責(zé)簽名,公鑰負(fù)責(zé)驗(yàn)證。
對(duì)稱加密分為兩大類: 序列型 stream cipher 和 分組型 block cipher (更流行).
stream cipher: RC4
RC4: secret key 通過RC4 會(huì)生成一個(gè)無限長(zhǎng)的序列,Plain Text跟RC4進(jìn)行操作(比如說異或)會(huì)生成加密文本。不安全。
block cipher: DES, 3DES, AES, BLOWFISH, RC5, RC6.
非對(duì)稱加密: RSA
Hash函數(shù)最快,其次是對(duì)稱加密,再是非對(duì)稱加密。
計(jì)算機(jī)中的Hash表主要用來存儲(chǔ)和查找。
密碼學(xué)中的Hash函數(shù)用途:
- 完整性檢測(cè)(下載文件,解壓文件)
- 注意:奇偶校驗(yàn)和CRC校驗(yàn)都沒有抗數(shù)據(jù)篡改的能力。Hash函數(shù)也不可以,但加上key就可以(見數(shù)字簽名)。
- 登錄驗(yàn)證,校對(duì)密碼(加上salt)
- 數(shù)字簽名(加上key)
- 區(qū)塊鏈
Hash算法有:
- MD5: 128 bits
- SHA-1: 160 bits
- SHA-2
- SHA-224 224 bits
- SHA-256 256 bits
- SHA-384 384 bits
- SHA-512 512 bits
- Whirlpool
- SHA-3
- SM3
MAC: Message Authentication Code 用來確保消息完整性
HMAC: Hash-based MAC
TLS 1.3之前是MAC, then encrypt
1. plaintext先通過Hash function運(yùn)算,結(jié)果再加上key,生成MAC
2. plaintext再加上MAC進(jìn)行Encryption,生成Ciphertext
TLS 1.3之后通信雙方可以自己定義是MAC then encypt,還是encrypt then MAC
SHA256 + RSA加密,最常見。
數(shù)字簽名和指紋區(qū)別:
指紋只是校驗(yàn)用的,數(shù)字簽名才是防黑客篡改。
查看證書: 瀏覽器,命令行
openssl x509 -text -noout -in amazon.cer
CIA原則:
Confidentiality: 保密 (可以通過加密,權(quán)限管理和敏感信息不被暴露來實(shí)現(xiàn))
Integrity: 數(shù)據(jù)內(nèi)容完整,沒有被篡改 (可以通過數(shù)字簽名校驗(yàn)來實(shí)現(xiàn))
Availability: 不讓人家無限制調(diào)用你的服務(wù)
微軟提出的STRIDE模型:
欺騙(Spoofing)
篡改(Tampering):也就是資料修改
否認(rèn)(Repudiation)
資訊泄露(Information disclosure),可能是私隱泄露或是資料外泄
阻斷服務(wù)攻擊(Denial of service)
特權(quán)提升(Elevation of privilege):例如黑客把自己的權(quán)限提高
實(shí)戰(zhàn)原則:
- 白名單和黑名單:白名單更嚴(yán)格
- 最小權(quán)限原則: 人家需要什么權(quán)限就給他什么權(quán)限,不要圖省事給Admin原則
- 縱深防御:各個(gè)層面都需要考慮安全 (網(wǎng)絡(luò)層,數(shù)據(jù)庫層,操作系統(tǒng)層)
- 數(shù)據(jù)和代碼分離原則: (注入攻擊,緩存區(qū)溢出) 不要把用戶輸入作為命令的一部分。
- 不可預(yù)測(cè)性。在設(shè)計(jì)代碼的時(shí)候,ID最好是隨機(jī)變化。
DoS: 拒絕服務(wù) (例如大量的攻擊,持續(xù)發(fā)送SYN包)
用防護(hù)墻可以防止網(wǎng)絡(luò)層攻擊。
如何防止應(yīng)用層DoS攻擊?核心是對(duì)資源進(jìn)行限制。不然黑客就會(huì)濫用服務(wù)。
1. 負(fù)載均衡(至少不會(huì)攻擊同一臺(tái)服務(wù)器。)
2. 限流
3. 緩存(在緩存區(qū)就把請(qǐng)求給處理了)
DDoS: Distributed DoS (攻擊來自不同IP)
隨機(jī)數(shù): 用作蜜鑰
不能用日期或時(shí)間做seed
不用用簡(jiǎn)單的rand()函數(shù)。JAVA里面有security包,用其它時(shí)間比如用戶鼠標(biāo)點(diǎn)擊數(shù)作為seed。
Linux里面的/dev/random 和 /dev/urandom比較安全一些。
通過增大隨機(jī)數(shù)空間或者組合隨機(jī)數(shù)可以增加安全。
黑客攻防:
- 文件上傳攻擊: 黑客把一個(gè)包含木馬程序的文件直接上傳??梢酝ㄟ^限制文件后綴類型(比用MIME格式限制好)和文件大小來防止。
如果黑客把木馬程序直接寫到文件內(nèi)容里面,可以通過壓縮或resize文件來破壞可能包含的HTML代碼。
另外一些好辦法:
a)把接受上傳的文件服務(wù)器單獨(dú)分開。把文件服務(wù)器和應(yīng)用服務(wù)器分開。
b)把存放文件的目錄權(quán)限設(shè)為只讀,不給它執(zhí)行權(quán)限。
c)隨機(jī)數(shù)改寫文件名和文件路徑,讓黑客找不到上傳的文件。
d)如果網(wǎng)站不需要文件上傳功能,就關(guān)閉文件上傳功能。 - 文件包含漏洞: 文件包含其他文件,
不推薦include *,不要用通配符。這樣如果有文件上傳漏洞,惡意代碼就會(huì)被包含進(jìn)去。
遠(yuǎn)程文件包含功能,不用的話,關(guān)閉。
#############################
SSL/TLS 學(xué)習(xí)小結(jié)
#############################
SSL/TLS 的目的有3個(gè):
- Confidentiality - Data is only accessible by Client and Server. 通過加密encription來實(shí)現(xiàn)
- Integrity - Data is not modified between Client and Server. 通過Hashing來實(shí)現(xiàn)
- Authentication - Client/Server are indeed who they say they are. 通過PKI(public key infrastructure)來實(shí)現(xiàn)
// Replay: 在Client和Server之間的第三者把截取的消息發(fā)送多次。
Anti-Replay:
1) Provided with build-in sequence numbers.
2) Built in to Integrity + Authentication mechanism.
// Repudiation: dishonest sender.
Non-Repudiation:
1) Sender cannot later deny sending a message
2) Byproduct of Integrity + Authentication
If the message is protected by Integrity and Authentication, then we know no one is modifying this message.
SSL/TLS ecosystem involves three key players:
- Client:
- Entity initiating the TLS handshake
- Web Browser
- Phone, Apps, Smart Toaster, Internet of Things
- Optionally authenticated (rare)
- Server:
- Entity receiving the TLS handshake
- Web Server
- Apache, IIS, NginX, etc…
- Load Balancer or SSL Accelerator
- Always authenticatied
- Certification Authority (CA)
- Governing Entity that issues Certificates
- Trusted by Client and Server
- Provides Trust Anchor
- If we trust the CA, we trust what the CA trusts
- Five organizations secure 98% of the Internet (IdenTrust, DigiCert, Sectigo, GoDaddy, GlobalSign)
Hashing 算法四原則:
- Infeasible to produce a given digest
- Impossible to extract original message
- Slight changes produce drastic differences
- Resulting digest is fixed width (length)
Sender光Hashing Message還不能保證Message不會(huì)被中間者篡改,因?yàn)橹虚g者可以篡改Message并加上自己的Hashing值。
如果Sender Hashing (Secret Key+Message),可以保證Message不會(huì)被中間者篡改,因?yàn)橹虚g者得不到Secret Key。
如果Receiver 收到后驗(yàn)證Hash值正確,說明:
- 消息沒有被篡改 //Integrity
- Sender有著同一個(gè)Secret Key //Authentication
MAC: Message Authentication Code
- Concept combining Message + Secret Key when calculating digest
- Provides Integrity and Authentication for Bulk data transfer
HMAC: Hash Based Message Authentication Code (MAC的工業(yè)標(biāo)準(zhǔn)實(shí)現(xiàn)) - RFC 2104
- 描述如何Combine Message 和 Key。Sender 和 Receiver都必須遵循同樣的Combination,不然Hashing值還是不match。
Data Integrity:
- Hashing Algorithm
- INPUT: Message
- OUTPUT: Digest
- Example: MD5, SHA1, etc…
- MAC - Message Authentication Code
- INPUT: Message + Secret Key
- OUTPUT: Digest
- Example: HMAC (Hash Based Message Authentication Code)
Encryption:
- 簡(jiǎn)單的加密Message is not scalable。因?yàn)榧用芊椒ㄒ粯?#xff0c;如果接收到的加密結(jié)果一樣,接收方1可以知道接收方2的Message。
- Key Based Encryption 針對(duì)每個(gè)接收方生成一個(gè)不同的Secret Key, allows encryption to scale to the whole Internet.
- Combines industry vetted algorithm with a Secret Key
- Algorithm is created by experts
- Secret Keys can be randomly generated
- Combines industry vetted algorithm with a Secret Key
- Two types of Key Based Encryption
-
Symmetric Encryption - Ideal for Bulk Data
- Encrypt and Decrypt using the same keys
- Strength: Faster - Lower CPU Cost
- Strength: Cipher text is the same size as Plain Text
- Weakness: Secret key must be shared - Less Secure
- Examples:
- DES 56 bit key
- RC4 128 bit key
- 3DES 168 bit key
- AES 128, 192, or 256 bit keys
- ChaCha20 128 or 256 bit keys
-
Asymmetric Encryption - Restricted to Limited Data
- Encrypt and Decrypt using different keys
- Two different keys are mathematically related
- What one key Encrypts, only the other can Decrypts
– One key will be made Public
– Other key will be kept Private - Weakness: Slower - Requires much larger key sizes
- Weakness: Cipher text expansion
- Strength: Private Key is never shared - More Secure
- Examples:
- DSA
- RSA - Recommended Key Size 2048 bits
- Diffie-Hellman
- ECDSA
- ECDH
-