Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
500
Cap'n Webについて
yusukebe
0
150
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
130
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
120
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
600
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
170
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
220
AIコーディングエージェント(Manus)
kondai24
0
230
PostgreSQLで手軽にDuckDBを使う!DuckDB&pg_duckdb入門/osc25hi-duckdb
takahashiikki
0
200
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
150
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
190
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
31
Building Flexible Design Systems
yeseniaperezcruz
330
39k
How to Talk to Developers About Accessibility
jct
1
87
SEO for Brand Visibility & Recognition
aleyda
0
4.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Exploring anti-patterns in Rails
aemeredith
2
210
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
410
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
31
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
280
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
170
How to train your dragon (web standard)
notwaldorf
97
6.5k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1k
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
จบ ถามไดไมกัด