惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
博客园 - Franky
MyScale Blog
MyScale Blog
Jina AI
Jina AI
B
Blog
Microsoft Security Blog
Microsoft Security Blog
T
Troy Hunt's Blog
博客园_首页
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
GbyAI
GbyAI
T
Tenable Blog
B
Blog RSS Feed
S
Securelist
T
Threat Research - Cisco Blogs
P
Privacy International News Feed
P
Proofpoint News Feed
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
罗磊的独立博客
AWS News Blog
AWS News Blog
V
V2EX
宝玉的分享
宝玉的分享
J
Java Code Geeks
小众软件
小众软件
Spread Privacy
Spread Privacy
腾讯CDC
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
V
Visual Studio Blog
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Know Your Adversary
Know Your Adversary
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
C
Check Point Blog
Webroot Blog
Webroot Blog
D
DataBreaches.Net
Cloudbric
Cloudbric
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家

Martin Heinz's Blog

A Guide to Python's Weak References Using weakref Module Recent Docker BuildKit Features You're Missing Out On Modern Git Commands and Features You Should Be Using Everything You Can Do with Python's textwrap Module Monitoring Indoor Air Quality with Prometheus, Grafana and a CO2 Sensor Everything You Can Do with Python's bisect Module You Don't Need a Dedicated Cache Service - PostgreSQL as a Cache A Collection of Docker Images To Solve All Your Debugging Needs Weird Python "Features" That Might Catch You By Surprise Lessons Learned From Writing 100 Articles Debugging Crashes and Deadlocks in Python using PyStack Goodbye etcd, Hello PostgreSQL: Running Kubernetes with an SQL Database Remote Interactive Debugging of Python Applications Running in Kubernetes The Right Way to Run Shell Commands From Python Real Multithreading is Coming to Python - Learn How You Can Use It Now Python's Missing Batteries: Essential Libraries You're Missing Out On Kubernetes-Native Synthetic Monitoring with Kuberhealthy Make Your CLI Demos a Breeze with Zero Stress and Zero Mistakes Reduce - The Power of a Single Python Function Why I Will Never Use Alpine Linux Ever Again Cgroups - Deep Dive into Resource Management in Kubernetes Dictionary Dispatch Pattern in Python Boost Your Python Application Performance using Continuous Profiling Lazy Evaluation Using Recursive Python Generators Python Magic Methods You Haven't Heard About Getting Started with Mastodon API in Python Backup-and-Restore of Containers with Kubernetes Checkpointing API Getting Started with Google APIs in Python Python CLI Tricks That Don't Require Any Code Whatsoever All The Ways To Introspect Python Objects at Runtime What is Python's "self" Argument, Anyway? Python List Comprehensions Are More Powerful Than You Might Think You Should Be Using Python's Walrus Operator - Here's Why Recipes and Tricks for Effective Structural Pattern Matching in Python It's Time to Say Goodbye to These Obsolete Python Libraries Advanced Features of Kubernetes' Horizontal Pod Autoscaler Data and System Visualization Tools That Will Boost Your Productivity Stop Messing with Kubernetes Finalizers Automate All the Boring Kubernetes Operations with Python End-to-End Monitoring with Grafana Cloud with Minimal Effort Bitly | bit.ly/3JLmSgA Bitly | bit.ly/3uETfbi Bitly | bit.ly/3MI4Iz0 Bitly | bit.ly/3M30D82 Bitly | bit.ly/3oMJ6qR Bitly | bit.ly/3IRD7IK Bitly | bit.ly/3A3B69t Bitly | bit.ly/31lKCYA Bitly | bit.ly/30uviIM Bitly | bit.ly/3E1X2mw Bitly | bit.ly/3Dv7JxP Bitly | bit.ly/3GG1BEz Bitly | bit.ly/3lLavs4 Bitly | bit.ly/39TqP3m Bitly | bit.ly/3A5Mpx8 Bitly | bit.ly/3kGwPl4 Bitly | bit.ly/3iHtulU Bitly | bit.ly/3xGjtKS Bitly | bit.ly/3h8DZg0 Bitly | bit.ly/2RQn1dG Bitly | bit.ly/3p2B5wW The Easiest Way to Debug Kubernetes Workloads Bitly | bit.ly/2PHVudx Cloud Native CI/CD with Tekton - Building Custom Tasks Bitly | bit.ly/3dg3QR9 Bitly | bit.ly/3qHtSkZ Deep Dive into Docker Internals - Union Filesystem Bitly | bit.ly/3qlRAUN Bitly | bit.ly/3pCUJ26 Bitly | bit.ly/3ifZxYr Bitly | bit.ly/34ZhIMt Bitly | bit.ly/3qSO7h0 Bitly | bit.ly/3muGLOk Bitly | bit.ly/35xN79v Bitly | bit.ly/3mLGshK Bitly | bit.ly/2IvkGQl Bitly | bit.ly/2Sk1KFK Bitly | bit.ly/3iCNIL6 Bitly | bit.ly/3beQPpy Saving Your Linux Machine from Certain Death New Features in Python 3.9 You Should Know About Deploy Any Python Project to Kubernetes Analyzing Docker Image Security Recursive SQL Queries with PostgreSQL Automating Every Aspect of Your Python Project Tour of Python Itertools Implementing 2D Physics in Javascript Ultimate Setup for Your Next Python Project Making Python Programs Blazingly Fast Going Serverless with OpenFaaS and Golang - Building Optimized Templates Going Serverless with OpenFaaS and Golang - The Ultimate Setup and Workflow Setting Up Swagger Docs for Golang API Building RESTful APIs in Golang Pytest Features, That You Need in Your (Testing) Life Setting up GitHub Package Registry with Docker and Golang Ultimate Setup for Your Next Golang Project Python Tips and Trick, You Haven't Already Seen, Part 2. Tricks for Postgres and Docker that will make your life easier Getting The Most Out of Reading Books - Reading The "Professional Way" Python Tips and Trick, You Haven't Already Seen
Security and Cryptography Mistakes You Are Probably Doing All The Time
Martin · 2019-12-13 · via Martin Heinz's Blog

There are a lot of myths and wrong assumptions about cryptography and security in general. It's common for people to misuse cryptographic primitives, assume that something is secure by default or use outdated technology/algorithms. So, let's look at some of those myths and common mistakes, so that you can avoid them in the future.

Stop Using /dev/random Already

Pretty much anybody would say that you should always use /dev/random for cryptographic purposes. Well, that's wrong. Both /dev/urandom and /dev/random are using the exact same CSPRNG. The difference between them is, that /dev/random blocks until it has enough entropy. Which is another issue - you don't want your applications to wait for entropy and design logic around possibility of /dev/random blocking, especially considering that you don't need that much entropy... All you need is about 256 bits of entropy, which you will get from /dev/urandom. If you want to delve deeper into this topic, then see article here.

Never Use AES ECB

As you surely know AES is a block cipher. It encrypts plain text in blocks of 128 bits. Alright, sounds good, so what is problem with using ECB (Electronic Code Book) mode? It uses unaltered key on every block, so if you encrypt more than 128 bits of data, your ciphertext will look something like this:

That's not much of an encryption, right? So, what should you use instead of ECB? Counter mode (CTR)! Why? Because encryption can be done in parallel and it uses IV (nonce) to get rid of the unaltered key problem, that ECB mode has. Just remember to never reuse the IV.

This is how the cipher text would look with CTR mode:

You can try it yourself with openssl:


~ $ identify gopher.png
gopher.png PNG 650x650 650x650+0+0 8-bit sRGB 38.9KB 0.000u 0:00.000  # Note the dimensions
~ $ convert -depth 32 gopher.png gopher.rgba
~ $ openssl enc -aes-128-ecb -e -in gopher.rgba -out gopher-ecb.rgba -k toomanysecrets  # Replace ecb with other modes too (e.g. ctr)
~ $ convert -size 650x650 -depth 32 gopher-ecb.rgba gopher-ecb.png

Never Use MD5 For Anything, Ever

While we are on the topic of never using stuff... Forget about MD5, like, right now. It was designed for use as a secure cryptographic hash algorithm, but there is nothing secure about it at this point. It has collision vulnerability, where you can create a pair of files that have same MD5 hash, meaning that you can fake a SSL or CA certificates.

So, what to use instead? It depends on use case - for password hashing use bcrypt or scrypt. Which one of those you use, is in my opinion personal preference - scrypt was designed to be "better" than bcrypt but it's newer so it faced less scrutiny. I - personally - still use bcrypt. As for the other use cases, use hash function from SHA-2 family, preferably longer digests like SHA-512.

Always Encrypt-then-MAC

The title of this section says "Encrypt-then-MAC", but let's backtrack a little bit first. A lot of people don't realize that they should always use encryption in conjunction with message authentication. I don't want to go into too much detail about why you should actually authenticate messages, all I'm gonna say is that if you don't authenticate messages, then you are opening your applications to quite a few possible attacks, like replay attack or active attack.

With that out of the way, why encrypt-then-MAC? Simply put, it's only way to get provable security, which isn't always necessary, but it means that it's essentially impossible to mess up cryptographically when using this construction.

If you want more in-depth explanation, then I recommend article here by Colin Percival.

Special Characters Don't Make Your Passwords Good

Not necessarily at least. Good password is one that you can remember, so throwing in characters like !@#$%^&* will make it more likely that you or users of your application will either forget it or write it down somewhere where someone else can see it.

What is reason to add special characters to password in the first place? It's entropy, so if we don't want to force users to include special characters in their passwords, then what is the alternative to keep the entropy high enough?

Make it loooong. As shown in popular xkcd Password Strength comic, it makes more sense to use password made by concatenating few random words, than trying to remember some gibberish. Creating these kinds of passwords satisfies both human and computer aspect of it, in other words it's easy to remember and reasonably hard to guess (high entropy, no way to brute force it).

Note: In ideal world everybody would use password manager and generate their random super high entropy passwords, but that's not something we can expect of average, non-tech savvy user.

Encryption Keys Rotation Misconception

Somebody probably already told you, that you should rotate your keys at some time interval and that's right, you absolutely should do that. A lot of people though, think that they should do it to decrease the probability of key being broken, which is not the case for encryption keys. You should rotate encryption keys to reduce the amount of data encrypted by the key, to lower the potential damage caused by single key being compromised. This misconception doesn't change the fact that you should rotate keys, but it's important to know why you are doing it, so that you can correctly assess what intervals should be used.

Never Store User Passwords

Back to the "never do stuff" topic once more. This one is little bit of rant, I've seen so many times, that website send me password by email after I registered... like... first thing you should do when you get password from user is to hash it and throw away the clear text version of password and if you are sending it to me by email, then you are clearly not doing that (end of rant)!

So, let's take a deep breath... how to store those passwords then?

As soon as you receive the password from user - hash it with slow hash function like bcrypt using work factor of at least 12 and erase the clear text password from memory. The work factor of 12 is valid now, at the time of posting and will not be enough a year from now. I would personally shoot for up to 400ms for validation of password, you can check on your machine which work factor would give you that.

If you're not gonna use bcrypt make sure to add salt to password to prevent precomputation attacks like rainbow table attack.

Containers Aren't Secure

A lot of people think that Docker containers are secure by default, but that's not the case. They were built to solve deployment problems not security ones.

There are even vulnerabilities that would allow attacker to get root access to host system and all that is needed is shell access to container. So, how to avoid these security problems and vulnerabilities?

  • Use minimal base images to reduce attack surface - Example of these images are alpine-based images or Red Hat universal base images.
  • Install only necessary libraries - The less you have in the container, the lower is chance, that there will be something to exploit.
  • Use trusted images - Don't just download any image from Docker Hub. Use ones that are reviewed, maintained by trustworthy teams and have lots of downloads (lots of eyes on them).
  • Don't use latest tags - By using fixed tags you make sure that no vulnerabilities will get introduced with your next build.
  • Use the least privileged user (Never run under root) - It is a good practice end your Dockerfiles with USER 1001 command to make sure that you use user with no privileges that could open your container to extra vulnerabilities.

There are much more things that you could do to secure your images, which you can google later, but I think the list above is bare minimum that everybody should have in mind when using Docker images/containers.

Conclusion

Every software developer/DevOps engineer is responsible for security of applications and system, at least to some extent (whether you like it or not). Therefore, I believe that all of us should take little bit of time to do the necessary research to make sure to avoid stupid mistakes and misconceptions like the ones above.

Don't just trust what people tell you (people make mistakes all the time). When it comes to security and cryptography look things up and check it yourself - make decisions based on facts.