Bashログインスクリプト奇妙な動作

Bashログインスクリプト奇妙な動作

私は現在、ユーザーがSSHを介して正常にログインすると、すべてのユーザー入力を記録するハニーポットを作成しています。

仕組みは次のとおりです。ハニーポットユーザーadminのデフォルトシェルをbashスクリプトに設定しました。

admin:x:1001:1001::/home/admin:/home/admin/HoneyPot/spawner.sh

スクリプトspawner.shは引き続きexceptスクリプトを起動し、ログ出力を使用しますscript

#!/bin/bash
cd /home/admin/HoneyPot/template/

pwd
script -c "./script.exp" -t 2> timing.log -a output.session #start recording session, execute except script
echo "we should not get here"

最初の数行は次のとおりですscript.exp

#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Mon Oct  5 13:55:35 
# boilerplate comments and code:

set force_conservative 0  ;# set to 1 to force conservative mode even if
              ;# script wasn't run conservatively originally
if {$force_conservative} {
    set send_slow {1 .1}
    proc send {ignore arg} {
        sleep .1
        exp_send -s -- $arg
    }
}

# start of my code

set timeout -1
spawn emulator #emulator is a simh emulator executable. not a shell script.
...
interact

./template.shadminas using を使用してスクリプトを実行すると、bashスクリプトは正常に実行されます。ただし、loginを使用すると、su次のことが発生します。

austin@ubuntu:~$ su admin
Password: 
/home/admin/HoneyPot/template
Script started, file is output.session
/home/admin/HoneyPot/template
Script started, file is output.session
/home/admin/HoneyPot/template
Script started, file is output.session
/home/admin/HoneyPot/template
Script started, file is output.session
/home/admin/HoneyPot/template
Script started, file is output.session
/home/admin/HoneyPot/template
...

私のbashスクリプトが設定されたユーザーシェルで動作しないのはなぜですか?私のスクリプトには再帰呼び出しがなく、scriptコマンドをブロックする必要があります!

誰かが懸念している場合に備えて、このコンピュータから出るネットワーク接続はありません。 SSH接続のみを許可できます。はい、ユーザーはこの問題を解決できることを知っています。これは仮想マシンで実行されます。

ベストアンサー1

私はあなたがshebangなしでスクリプトを使用していると思います。

バラよりこの回答:

execl() 関数が POSIX.1-2008 システム・インターフェース・ボリュームで定義されている [ENOEXEC] と同じエラーで失敗した場合、シェルは検索結果のパス名を最初のオペランドとしてシェルを呼び出すのと同じコマンド実行する必要があります。残りの引数は新しいシェルに渡されますが、新しいシェルの「$ 0」値をコマンド名に設定できます。実行可能ファイルがテキストファイルではない場合、シェルはこのコマンドの実行をバイパスできます。この場合、エラーメッセージを作成して終了ステータス126を返す必要があります。

spawner.sh追加に関するecho "$@"追加情報を入手してください。

さて、答えはもっと複雑ですが、これは役に立ちます。spawner.sh上部に以下を追加します。

if [[ $1 == -c ]]; then
    exec bash "$@"
fi

おすすめ記事