*** empty log message ***
authordev <dev>
Tue, 18 Oct 2022 05:09:52 +0000 (05:09 +0000)
committerdev <dev>
Tue, 18 Oct 2022 05:09:52 +0000 (05:09 +0000)
.gitignore [new file with mode: 0644]
chroot.sh [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..da8168b
--- /dev/null
@@ -0,0 +1,28 @@
+# CVS default ignores begin
+tags
+TAGS
+.make.state
+.nse_depinfo
+*~
+\#*
+.#*
+,*
+_$*
+*$
+*.old
+*.bak
+*.BAK
+*.orig
+*.rej
+.del-*
+*.a
+*.olb
+*.o
+*.obj
+*.so
+*.exe
+*.Z
+*.elc
+*.ln
+core
+# CVS default ignores end
diff --git a/chroot.sh b/chroot.sh
new file mode 100755 (executable)
index 0000000..a407099
--- /dev/null
+++ b/chroot.sh
@@ -0,0 +1,141 @@
+#!/bin/bash
+
+#####################################################################################
+#
+#   chroot 環境を作成
+#     chroot環境を構築する為のスクリプト。
+#     主な利用用途として、
+#       ・SSHでポートフォワードする
+#       ・Linux初心者が業務等で操作を行う場合など、実行可能コマンドを制限
+#         -> 別手法としてrbash
+#         -> ディレクトリの移動制限は、sshd_config の ChrootDirectory を利用
+#
+#   使用上の注意
+#     - このスクリプトでchroot環境を構築後に、スクリプト再実行すると上書きされる
+#       ので、chroot環境のファイルを修正した場合は、注意する事
+#
+#   $Id: chroot.sh,v 1.1 2022/10/18 05:09:52 dev Exp $
+#
+#####################################################################################
+
+# Settings
+# --- 設定変更 ここから ---
+# chroot を作成するディレクトリを指定
+CHG_ROOT=/chroot
+
+# chroot環境で利用するプログラムを指定
+CMD_LIST="pwd ls mkdir rmdir cp mv rm touch cat less more vi find grep telnet ssh ping traceroute"
+
+# --- ここまで ---
+
+# Base Settings
+# 基本的に変更する必要はありません。
+
+REQUIRED_CMD="sh bash env id readlink basename hostname groups tty"
+REQUIRED_SO=(
+  /lib64/ld-linux-x86-64.so.2
+  /lib64/libnss_sss.so.2
+  /lib64/libnss_files.so.2
+  /lib64/libnss_systemd.so.2
+  /lib64/librt.so.1
+  /lib64/libmount.so.1
+  /lib64/libgcc_s.so.1
+  /lib64/libblkid.so.1
+  /lib64/libuuid.so.1
+)
+
+LINKED_DIRS=(
+  /etc/profile.d
+  /usr/share/terminfo
+)
+LINKED_FILES=(
+  /etc/profile
+  /etc/bashrc
+  /etc/inputrc
+  /etc/openldap/ldap.conf
+  /etc/nsswitch.conf
+  /etc/hosts
+  /etc/fstab
+  /usr/libexec/grepconf.sh
+)
+
+# Init
+FLG=0
+EXEC_CMD=(
+  /usr/bin/which
+  /usr/bin/install
+  /usr/bin/ldd
+  /usr/bin/awk
+  /usr/bin/mknod
+  /usr/bin/chmod
+)
+
+for valf in ${LINKED_DIRS[@]}
+do
+  if [ ! -x $valf ]; then
+    echo "File ($valf) not found"
+    FLG=1
+  fi
+done
+
+if [ $FLG -eq 1 ]; then
+  echo "--- Error ---"
+  exit 1
+fi
+
+# Main
+
+install -m 0755 -o root -g root -d ${CHG_ROOT}
+install -m 0755 -o root -g root -d ${CHG_ROOT}/{dev,home,etc,usr,tmp}
+install -m 0755 -o root -g root -d ${CHG_ROOT}/usr/{bin,sbin,lib,lib64,libexec}
+install -m 0755 -o root -g root -d ${CHG_ROOT}/usr/local/bin
+
+cd ${CHG_ROOT}
+test ! -L bin && ln -s usr/bin .
+test ! -L lib && ln -s usr/lib .
+test ! -L lib64 && ln -s usr/lib64 .
+
+# 静的ディレクトリ(LINKED_DIRS)のコピー
+for vald in ${LINKED_DIRS[@]}
+do
+    test ! -d `dirname ${CHG_ROOT}$vald` && install -m 0755 -o root -g root -d `dirname ${CHG_ROOT}$vald`
+    cp -Rpf $vald ${CHG_ROOT}$vald
+done
+
+# 静的ファイル(LINKED_FILES)のコピー
+for valf in ${LINKED_FILES[@]}
+do
+    test ! -d `dirname ${CHG_ROOT}$valf` && install -m 0755 -o root -g root -d `dirname ${CHG_ROOT}$valf`
+    cp -pf $valf ${CHG_ROOT}$valf
+done
+
+# 利用コマンドとライブラリーのコピー
+for valp in `which $CMD_LIST`;
+do
+    # command
+    test -e ./$valp && continue
+    cp -pf $valp ./$valp
+
+    # library
+    LIBS=`ldd $valp | awk '{ print $3 }'`
+    if [ ${#LIBS[*]} -gt 0 ]; then
+      for valf in $LIBS;
+      do
+        test ! -d `dirname ${CHG_ROOT}$valf` && install -m 0755 -o root -g root -d `dirname ${CHG_ROOT}$valf`
+        test ! -f ${CHG_ROOT}$valf && cp -p $valf ./$valf
+      done
+    fi
+done
+
+# 追加(静的)ライブラリーのコピー
+for valf in ${REQUIRED_SO[@]}
+do
+    test ! -d `dirname ${CHG_ROOT}$valf` && install -m 0755 -o root -g root -d `dirname ${CHG_ROOT}$valf`
+    cp -pf $valf ${CHG_ROOT}$valf
+done
+
+test ! -c ${CHG_ROOT}/dev/null && mknod ${CHG_ROOT}/dev/null c 1 3
+test ! -c ${CHG_ROOT}/dev/zero && mknod ${CHG_ROOT}/dev/zero c 1 5
+test ! -c ${CHG_ROOT}/dev/random && mknod ${CHG_ROOT}/dev/random c 1 8
+test ! -c ${CHG_ROOT}/dev/urandom && mknod ${CHG_ROOT}/dev/urandom c 1 9
+chmod 0666 ${CHG_ROOT}/dev/{null,zero,random,urandom}