当サイトの一部ページには、アフィリエイト・アドセンス・アソシエイト・プロモーション広告を掲載しています。

Amazonのアソシエイトとして、Security Akademeiaは適格販売により収入を得ています。

広告配信等の詳細については、プライバシーポリシーページに掲載しています。

消費者庁が、2023年10月1日から施行する景品表示法の規制対象(通称:ステマ規制)にならないよう、配慮して記事を作成しています。もし問題のある表現がありましたら、問い合わせページよりご連絡ください。

参考:令和5年10月1日からステルスマーケティングは景品表示法違反となります。 | 消費者庁

自動マウントするためのrc-local.serviceが異常終了する

エラーの発生

Kaliのバージョンが上がったことで『ハッキング・ラボのつくりかた』(P.156-161)の方法ではうまくいかないので、『ハッキング・ラボの構築で困ったら読む本』(P.46-50)にて解説をアップデートしました[1]方法は変わりましたが、マウントポイントやコマンドを理解するうえでは『ハッキング・ラボのつくりかた』の解説は無駄にはなりません。

ところが、2021年5月の時点でこの方法もうまくいかないことが判明しました。

P.50のステップ6にて、rc-local.serviceの状態を確認すると、"/sbin/mount.vboxsf: mounting failed with the error: No such file or directory"というログが出ており、正常に起動できないという現象が起こります。

原因

結論からいうと、"/etc/rc.local"ファイル内にはmountコマンドを記述していますが、rc-local.serviceから呼び出されると「/sbin/mount.vboxsf」コマンドが呼び出されることが原因です(いつからこのような仕様になったのかは不明)。

通常のmountコマンドでは-tオプションが使えますが、「/sbin/mount.vboxsf」コマンドは-tオプションはいりません。よって、「/sbin/mount.vboxsf」コマンドの実行でエラーが起きて、rc-local.serviceが異常終了していたのです。

「/sbin/mount.vboxsf」コマンドのフォーマット

「/sbin/mount.vboxsf [マウントポイント] [マウントするディレクトリ]」という書式で、VirtualBoxの仮想マシンから見て外にあるフォルダーをマウントできます。

┌──(kali㉿kali)-[~]
└─$ sudo /sbin/mount.vboxsf
[sudo] password for kali: 
Usage: /sbin/mount.vboxsf [OPTIONS] NAME MOUNTPOINT
Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT.

  -w                    mount the shared folder writable (the default)
  -r                    mount the shared folder read-only
  -n                    do not create an mtab entry
  -s                    sloppy parsing, ignore unrecognized mount options
  -o OPTION[,OPTION...] use the mount options specified

Available mount options are:
     rw                 mount writable (the default)
     ro                 mount read only
     uid=UID            set the default file owner user id to UID
     gid=GID            set the default file owner group id to GID
     ttl=MILLIESECSONDS set the "time to live" for both the directory cache
                        and inode info.  -1 for kernel default, 0 disables it.
     dcachettl=MILLIES  set the "time to live" for the directory cache,
                        overriding the 'ttl' option.  Ignored if negative.
     inodettl=MILLIES   set the "time to live" for the inode information,
                        overriding the 'ttl' option.  Ignored if negative.
     maxiopages=PAGES   set the max host I/O buffers size in pages. Uses
                        default if zero.
     dirbuf=BYTES       set the directory enumeration buffer size in bytes.
                        Uses default size if zero.
     cache=MODE         set the caching mode for the mount.  Allowed values:
                          default: use the kernel default (strict)
                             none: no caching; may experience guest side
                                   coherence issues between mmap and read.
                           strict: no caching, except for writably mapped
                                   files (for guest side coherence)
                             read: read via the page cache; host changes
                                   may be completely ignored
                        readwrite: read and write via the page cache; host
                                   changes may be completely ignored and
                                   guest changes takes a while to reach the host
     dmode=MODE         override the mode of all directories to (octal) MODE
     fmode=MODE         override the mode of all regular files to (octal) MODE
     umask=UMASK        set the umask to (octal) UMASK
     dmask=UMASK        set the umask applied to directories only
     fmask=UMASK        set the umask applied to regular files only
     iocharset CHARSET  use the character set CHARSET for I/O operations
                        (default set is utf8)
     convertcp CHARSET  convert the folder name from CHARSET to utf8

Less common used options:
     noexec,exec,nodev,dev,nosuid,suid

対応方法

対応アプローチ

対応策として次の2つのアプローチが考えられます。

  • ①強制的にmountコマンドを呼び出すようにする。
  • ②"/etc/rc.local"ファイルにて、「/sbin/mount.vboxsf」コマンドを実行するように修正する。

ここではアプローチ②を採用します。

対応を考慮した手順

1:ホストOSに"C:\share"フォルダーを作成します。ここが共有フォルダーになります。

2:Kaliの仮想マシンのメニューから「設定」>「共有フォルダー」を選びます。

[+]ボタンで次の共有フォルダーを追加します。

3:shareというマウントポインタを作り、/shareと対応付けてマウントします。

$ sudo mkdir /share ←マウントポインタを作る。
$ sudo mount -t vboxsf share /share ←これが通常のmountコマンドを使った、仮想マシン外のフォルダーに対するマウント方法。
$ ls /share
(共有フォルダー名が見える)
$ sudo /sbin/mount.vboxsf share /share ←「mount.vboxsf」コマンドを使う方法(一応フルパスにしておいた)。2行目のコマンドと同等の動き。このコマンドをステップ3で使う。
(エラーが起きないことをチェック)

3:マウント用の自動起動スクリプトである"/etc/rc.local"ファイルを作成します。

#!/bin/sh
/sbin/mount.vboxsf share /share

4:ファイルに実行権限を与えます。

$ sudo chmod 755 /etc/rc.local

5:マウント用の自動起動スクリプトを呼び出す、"/etc/systemd/system/rc-local.service"ファイルを作成します[2]パスに注意。systemdの後にsystemがあります。

[Unit]
Description=/etc/rc.local

[Service]
ExecStart=/etc/rc.local
Restart=no
Type=simple

[Install]
WantedBy=multi-user.target

6:サービスの自動起動を設定します。

$ sudo systemctl enable rc-local.service

シンボリックの作成のメッセージが出るはずです。出なければ、rc-local.serviceファイル内が間違っているか、パスが間違っています。エラーメッセージをよく見てください。

7:次のコマンドを実行してサービスを起動してから、状態を確認します。

$ sudo systemctl restart rc-local.service ←サービスの再起動。
$ sudo systemctl status rc-local.service ←状態を確認。

8:Kaliを再起動して、自動でマウントできていることとサービスが正常に稼働していることを確認します。

おわりに

今回の問題については『ハッキング・ラボの構築で困ったら読む本』の固定ページにも反映しました。

References

References
1 方法は変わりましたが、マウントポイントやコマンドを理解するうえでは『ハッキング・ラボのつくりかた』の解説は無駄にはなりません。
2 パスに注意。systemdの後にsystemがあります。