Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
เก็บรหัสผ่านยังไงดี 2017
Search
Manatsawin Hanmongkolchai
March 11, 2017
Programming
0
570
เก็บรหัสผ่านยังไงดี 2017
YWC Programmer Meetup #4
Manatsawin Hanmongkolchai
March 11, 2017
Tweet
Share
More Decks by Manatsawin Hanmongkolchai
See All by Manatsawin Hanmongkolchai
Nix: Declarative OS
whs
0
100
gRPC load balancing with xDS
whs
0
1k
ArgoCD
whs
0
450
Writing Babel Plugin
whs
0
210
What's new in Cloud Next 2019
whs
0
310
A Date with gRPC
whs
1
1.4k
ตีแผ่ Microservice ด้วย Tracing
whs
0
380
Next Generation Smart Home
whs
0
990
Istio and the Service Mesh Architecture
whs
3
1.1k
Other Decks in Programming
See All in Programming
Cell-Based Architecture
larchanjo
0
140
組み合わせ爆発にのまれない - 責務分割 x テスト
halhorn
1
160
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
410
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
470
perlをWebAssembly上で動かすと何が嬉しいの??? / Where does Perl-on-Wasm actually make sense?
mackee
0
170
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
380
Implementation Patterns
denyspoltorak
0
120
GISエンジニアから見たLINKSデータ
nokonoko1203
0
180
AIコーディングエージェント(Manus)
kondai24
0
220
Go コードベースの構成と AI コンテキスト定義
andpad
0
140
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
310
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
130
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
29
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
65
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
270
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
410
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
230
Are puppies a ranking factor?
jonoalderson
0
2.4k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
2
260
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
720
Tell your own story through comics
letsgokoyo
0
770
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
300
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
31
Transcript
เก็บรหัสผานยังไงดี 2017 YWC Programmer Meetup
คั่นเวลา • ขอรหัสผานหนอย • 6 ตัว อักษรอังกฤษ ตัวเลข • เดี๋ยวจะทําอะไรใหดู
• ไมตองใสรหัสจริงมานะ • https://madoka.whs.in.th/pwcrack.html ◦ HTTPS ดวย!!
Who? • Manatsawin Hanmongkolchai (@awkwin) • ถาไมไดกดรับเฟรนก็สงขอความมาถามไดไมกัด • แตถาเขียนโคด insecure
นี่กัด
Why? • ทํา Freelance มาหลาย project • ทุก project ที่ตองไปยุง
code เดิมมีชองโหวพื้นๆ หมด ◦ SQL Injection ◦ Insecure Password Hashing • ถาใหพูดทุกประเด็นคงไดเปนชั่วโมง
ขออาง • "ใชคนเดียว ไมเปนไรหรอก" • "เดี๋ยวคอยแกก็ได"
There are two primary causes for the unintentional creation of
insecure web applications, regardless of the language being used: 1. A lack of knowledge about security 2. Bad development habits — ParagonIE
เก็บรหัสผานยังไงดี? • สมัยผมหัดเขียนเว็บเคาใช MD5 $hashed = md5($_POST['password']);
อยาใช MD5 • SHA1 จาย 5 แสนเหรียญ collision ได •
แต MD5 รันไวสักวันสองวันก็ collision ได
เก็บรหัสผานยังไงดี? • แลวเคาก็วา SHA1 $hashed = sha1($_POST['password']);
อยาใช SHA1 • มี harddisk เหลือ ทําตาราง SHA1 (Rainbow Table)
ไวก็ crack SHA1 ไดในพริบตา
เก็บรหัสผานยังไงดี? • แลวเคาก็วาใส salt สิ จะไดปลอดภัย $salt = uniqid(); $hashed
= sha1($_POST['password'] . $salt);
ยินดีตอนรับสูยุคของ Cloud computing • เมื่อกี้ขอรหัสผาน ใสกันหรือยัง • ถาพรอมแลว ลุย!
ยินดีตอนรับสูยุคของ Cloud computing • Google Cloud เชา K80 ชั่วโมงละ 30
บาทเทานั้น!!! • งัด MD5 ได 4 พันลานครั้งตอวินาที • งัด SHA256 ได 642.1 ลานครั้งตอวินาที ◦ = รหัส 8 ตัว เสร็จใน 2 นาที • เชาไดถึง 8 ใบตอเครื่อง !!
แลวเอาไงดี???? • ใช Algorithm "ชา" (>100ms) มีการดจอก็งัดไมทันหรอก ◦ Argon2 ◦
bcrypt ◦ scrypt ◦ PBKDF2 (iPhone ใชอยู)
PHP • PHP 5.5+ มี password hash function มาใหแลว ชวยใชหนอยเถอะ
• $hash = password_hash($_POST['password'] PASSWORD_DEFAULT); • แลว Salt? มันจัดการใหหมดแลวไมตองไปยุง • (ตอนนี้) ใช algorithm bcrypt
PHP • เวลาเช็ครหัสผานทําแบบนี้ • if(!password_verify($_POST['password'], $db_password)){ die('Wrong!'); } if(password_needs_rehash($db_password, PASSWORD_DEFAULT)){
$db_password = password_hash($_POST['password'] PASSWORD_DEFAULT); } • password_verify จะเทียบรหัสผานโดยไมโดน timing attack • password_needs_rehash จะเช็ควารหัสใช algorithm ลาสุดหรือเปลา ถาไมใชก็ upgrade ได (ในกรณีที่ในอนาคต PHP เปลี่ยน default algorithm)
PHP • ถาไมมี PHP5.5? • https://github.com/ircmaxell/password_compat • API เดียวกับเมื่อกี้ จบปง
PHP • ถาไมมี PHP5.3.7??? • ไมยอมอัพเกรดขนาดนั้นก็สมควรโดน hack
ใช Framework เถอะ • งงมั้ย? • Security งายนิดเดียว แคใช Framework
◦ Django (Python) ลง Argon2/Bcrypt เพิ่มได (อานใน Docs) หรือ default จะใช PBKDF2 ◦ อยาเขียนสิ่งที่ framework มันมีใหอยูแลว
Paragonie Blog • เขียนสนุก เขาใจงาย สําหรับคนเขียน PHP • https://paragonie.com/blog/category/security-engineering
จบ ถามไดไมกัด