Firefox で DNS-over-HTTPS を試す

最近の Firefox はTrusted Recursive Resolver(TRR)を利用して DNS-over-HTTPS が利用できるようです.試してみました.

アドレスバーに about:config 入力して移動.

44211559615 6a29ddb6d5

network.trr.mode を設定.今回は`3`のTRRのみ利用を指定した.

44402653684 e26c646cb0
43309711340 4b5d902ae2

  • network.trr.mode

    • 0 : TRR無効(既定値).

    • 1 : 通常のDNSとTRRを並行実行して最初に帰ってきた結果を利用する.

    • 2 : TRRを優先利用.

    • 3 : TRRのみを利用.

    • 4 : 通常のDNSを利用する.TRRは情報収集のためだけに動く.

    • 5 : TRRを明示的に無効にする

次に network.trr.uri を指定.好みのDNS-over-HTTPS のリゾルバを指定.

43309712480 d417a108b5
44402653984 c8538ce5fe

about:networking#dns にアクセスしてTRRが true になっていれば TRR を利用しているはず.

44402654944 daac2b37e3

環境
$ dpkg-query -W firefox
firefox 62.0.3-1
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

44402653394 9392330ef0

Linux で DNS-over-HTTPS を利用する

Android で DNS-over-HTTPS が簡単に出来るようになりました.

Linuxだどうなんだろうと以下の`dns-over-https` を試してみました.ここでは Debian sid amd64 で試していますが,公式の手順には Ubuntu 18.04 LTS, macOS の手順が載っています.

導入例
$ sudo apt install git golang
$ git clone https://github.com/m13253/dns-over-https.git
$ cd dns-over-https
$ make
$ sudo checkinstall
規定値のサーバは Google Public DNS になっている.変更したい場合は設定ファイル( /etc/dns-over-https/doh-client.conf )を編集
$ sudo edit /etc/dns-over-https/doh-client.conf
CleanBrowsingのセキュリティフィルターを利用する場合の設定例
diff --git a/dns-over-https/doh-client.conf b/dns-over-https/doh-client.conf
index 3b5de14..1791397 100644
--- a/dns-over-https/doh-client.conf
+++ b/dns-over-https/doh-client.conf
@@ -11,7 +11,7 @@ listen = [
 upstream_google = [

     # Google's productive resolver, good ECS, bad DNSSEC
-    "https://dns.google.com/resolve",
+    #"https://dns.google.com/resolve",

     # CloudFlare's resolver, bad ECS, good DNSSEC
     #"https://cloudflare-dns.com/dns-query",
@@ -39,6 +39,9 @@ upstream_ietf = [
     # Blog: https://blog.cloudflare.com/welcome-hidden-resolver/
     #"https://dns4torpnlfs2ifuz2s2yf3fc7rdmsbhm6rw75euj35pac6ap25zgqad.onion/dns-query",

+    # CleanBrowsing https://cleanbrowsing.org/dnsoverhttps
+    "https://doh.cleanbrowsing.org/doh/security-filter/"
+
 ]

 # Bootstrap DNS server to resolve the address of the upstream resolver
起動
$ sudo systemctl restart doh-client
名前が引けるのを確認
$ dig @127.0.0.1 | grep SERVER
;; SERVER: 127.0.0.1#53(127.0.0.1)
trace
$ dig +trace matoken.org @127.0.0.1

; <<>> DiG 9.11.4-P2-3-Debian <<>> +trace matoken.org @127.0.0.1
;; global options: +cmd
.                       24820   IN      NS      m.root-servers.net.
.                       24820   IN      NS      b.root-servers.net.
.                       24820   IN      NS      c.root-servers.net.
.                       24820   IN      NS      d.root-servers.net.
.                       24820   IN      NS      e.root-servers.net.
.                       24820   IN      NS      f.root-servers.net.
.                       24820   IN      NS      g.root-servers.net.
.                       24820   IN      NS      h.root-servers.net.
.                       24820   IN      NS      i.root-servers.net.
.                       24820   IN      NS      j.root-servers.net.
.                       24820   IN      NS      a.root-servers.net.
.                       24820   IN      NS      k.root-servers.net.
.                       24820   IN      NS      l.root-servers.net.
;; Received 239 bytes from 127.0.0.1#53(127.0.0.1) in 1334 ms

org.                    172800  IN      NS      a0.org.afilias-nst.info.
org.                    172800  IN      NS      a2.org.afilias-nst.info.
org.                    172800  IN      NS      b0.org.afilias-nst.org.
org.                    172800  IN      NS      b2.org.afilias-nst.org.
org.                    172800  IN      NS      c0.org.afilias-nst.info.
org.                    172800  IN      NS      d0.org.afilias-nst.org.
org.                    86400   IN      DS      9795 7 1 364DFAB3DAF254CAB477B5675B10766DDAA24982
org.                    86400   IN      DS      9795 7 2 3922B31B6F3A4EA92B19EB7B52120F031FD8E05FF0B03BAFCF9F891B FE7FF8E5
org.                    86400   IN      RRSIG   DS 8 1 86400 20181018050000 20181005040000 2134 . bYogBWKVV1SnjoHjS5LnLBE1mWC6UwkYT6muOjcHnuMNzJM1DY3YhSCT d9QOYlvvprUyD37xYIQ10BUZQ8hcNpnQ2TPUTNzd621lsqth6QK8zDN6 eP5AvZXlPy+9wni71rJIHy1wzepn9yrh3jp70zZhnEVxxgItWaYzsayY Jf+UfFQPmOKX0gn0GqcQ09CSZHdZhwbUT2AT1Rs0atkj6VaOy2TT1aQ1 gAtGF+5uA4uqLJegiEe/zneTeyuNE5QDQWKUNaeWEDE9kxylhv6m/3vE tQ8EHFpzOL9x+ed25LNcnRXH8K/xCW43R1FyaVNaA6xcsvGHCysqLneI v/RYMQ==
;; Received 813 bytes from 193.0.14.129#53(k.root-servers.net) in 210 ms

matoken.org.            86400   IN      NS      ns-cloud-d2.googledomains.com.
matoken.org.            86400   IN      NS      ns-cloud-d4.googledomains.com.
matoken.org.            86400   IN      NS      ns-cloud-d1.googledomains.com.
matoken.org.            86400   IN      NS      ns-cloud-d3.googledomains.com.
h9p7u7tr2u91d0v0ljs9l1gidnp90u3h.org. 86400 IN NSEC3 1 1 1 D399EAAB H9PARR669T6U8O1GSG9E1LMITK4DEM0T NS SOA RRSIG DNSKEY NSEC3PARAM
h9p7u7tr2u91d0v0ljs9l1gidnp90u3h.org. 86400 IN RRSIG NSEC3 7 2 86400 20181026101800 20181005091800 1862 org. edCrqcIYiHlMMzuacuX0DlobcQkymqClpK5C4QLzsNWtvp942bFRjbb2 WDX/6TsHO0noBNoKH2i+TU70WqpW7sVsXbjV9nkeLMZjxz/VLyAJOXWk 2ITvZwhjbe96lCSAIafm824pBx94ruieKZ2Yj8pYTBIrhDBoffjPhuem 44k=
a85qqkk8n39d1c6m55g8ucjhm6u3jjcs.org. 86400 IN NSEC3 1 1 1 D399EAAB A86TS1MQ34BR2A3D3CT8D5SCHKAPPBPJ NS DS RRSIG
a85qqkk8n39d1c6m55g8ucjhm6u3jjcs.org. 86400 IN RRSIG NSEC3 7 2 86400 20181022152743 20181001142743 1862 org. G15dhaW+53QBX9nTtsIUCnSRrMO0FCkQJE3jydb6hmRQEA328trp9OqK 6fuvl+RZBhBFeMeJV1Tz0Uezp9YvymfRWwdHiiFFLy3KBt5cTZJUXxTZ jXnMT9PoHZcIVJzN65vqQHDI2MzWYoQYr1WoKmJxOC5FQzFctZElyzEq fNQ=
;; Received 654 bytes from 199.19.56.1#53(a0.org.afilias-nst.info) in 217 ms

matoken.org.            120     IN      A       153.121.44.87
;; Received 56 bytes from 216.239.38.109#53(ns-cloud-d4.googledomains.com) in 388 ms

パケットキャプチャしてみる

  • 通常のDNS

dig 2quepghecPeuj.matoken.org
$ sudo tcpdump -n -nn -t -l -A -s0 2>/dev/null | grep 2quepghecPeuj.matoken.org
IP 192.168.2.203.49026 > 192.168.2.211.53: 49901+ [1au] A? 2quepghecPeuj.matoken.org. (66)
E..^.,..@.0t...........5.J..... .........2quepghecPeuj.matoken.org.......).........
E...z.@.@.8f.........5...w............. .2quepghecPeuj.matoken.org..............x...y,W........2....ns-cloud-d2.googledomains.com.........2....ns-cloud-d4.S........2....ns-cloud-d1.S........2....ns-cloud-d3.S.........d.... m.G.......+...."m.........D....$m.r......#P....&m............ .H`H..2.......m.G......+W.. .H`H..4.......m............ .H`H..6.......m.r......Ov.. .H`H..8.......m..)........
^C
  • DNS over HTTPS

名前は見当たらない

dig 2quepghecPeuj.matoken.org @127.0.0.1
$ sudo tcpdump -n -nn -t -l -A -s0 2>/dev/null | grep 2quepghecPeuj.matoken.org
^C

loopback 部分はHTTPSになる前の部分は見える

dig 2quepghecPeuj.matoken.org @127.0.0.1
$ sudo tcpdump -i lo -n -nn -t -l -A -s0 2>/dev/null | grep 2quepghecPeuj.matoken.org
IP 127.0.0.1.52265 > 127.0.0.1.53: 25766+ [1au] A? 2quepghecPeuj.matoken.org. (66)
E..^C...@.8..........).5.J.]d.. .........2quepghecPeuj.matoken.org.......).........
E..bD(@.@..`.........5.).N.ad............2quepghecPeuj.matoken.org..............w...y,W..)........
^C
永続化
$ sudo systemctl enable doh-client

後は /etc/network/interfaces や NetworkManager で DNS server に 127.0.0.1 を指定する.

環境
$ dpkg-query -W git golang dnsutils
dnsutils        1:9.11.4.P2+dfsg-3
git     1:2.19.0-1
golang  2:1.10~5
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

Dropbox を FUSE mount する dbxfs のアクセストークンを gpg で暗号化する

昨日dbxfs を試したのですが,アクセストークンのgpg での暗号化が出来ませんでした.

するとTwitterで情報をもらい,手動でDropbox app を作成してアクセストークンを入手する必要があるそうです.早速試してみたところうまく行きました!

Dropbox の App Console にアクセスして,Create app で新しいアプリを作成します.
情報を入力してアプリを生成.

44379184824 11e5e5faf4

生成したアプリで Generated access token を押してアクセストークンを生成

43285861640 b2abfddc92 m

dbxfs設定ファイルの場所確認
$ ~/.local/bin/dbxfs --print-default-config-file
/home/matoken/.config/dbxfs/config.json
生成したアクセストークンを gpg で暗号化してファイルに格納.
$ echo -n 'ItBeOfobAlbofEicHefvemsajKicsEjcekDomBaHee-shwijreijKimyatIfnebir' | gpg -r EAA13B982D937827 -e -o /home/matoken/.config/dbxfs/token.gpg
暗号化したアクセストークンファイルを設定ファイルで指定する
$ jq . /home/matoken/.config/dbxfs/config.json
{
  "access_token_command": [
	"gpg",
	"--decrypt",
	"/home/matoken/.config/dbxfs/token.gpg"
  ],
  "send_error_reports": true,
  "asked_send_error_reports": true
}
mount 時に gpg で decrypt されて mount される
$ ~/.local/bin/dbxfs ~/fuse/dbxfs
Running 'gpg --decrypt /home/matoken/.config/dbxfs/token.gpg' for access token
gpg: 4096-ビットRSA鍵, ID EAA13B982D937827, 日付2015-06-11に暗号化されました
	  "K.I.Matohara <matoken@gmail.com>"
$ mount|grep dbxfs
dbxfs on /home/matoken/fuse/dbxfs type fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000,default_permissions)
$ ls /home/matoken/fuse/dbxfs
   :
$ fusermount -u ~/fuse/dbxfs

うまくいきました :)

環境
$ grep ^Version: ~/.local/lib/python3.6/site-packages/dbxfs-1.0.4.dist-info/METADATA
Version: 1.0.4
$ dpkg-query -W gpg libfuse2 python3-pip
gpg     2.2.10-2
libfuse2:amd64  2.9.8-2
python3-pip     9.0.1-2.3
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

Android 4.0 以降を DNS-over-HTTPS 対応にする Intra を少し試す

Alpabet の技術インキュベータのJigsawというところが作った Intra という Android アプリをリリースしました.

通常の DNS は暗号化されず改ざんが可能です.Intra は DNS を暗号化する DNS-over-HTTPS を Android 4.0 以降で利用できるようにするアプリです.

31226501238 7a637260f1
31226501848 d563502159
31226502538 db0efcae0a

VPN接続の確認がされる

31226505068 5cc4feeeb4

DNS保護状態

31226508208 857594ce32
31226510648 7047e8ef20

DNS-over-HTTPS サーバの既定値はGoogleで,Cloudflareも選択できる.その他のサーバも手動で指定できる

31226511688 8b413ac9b8

DNS は 8.8.8.8 の Google を見に行っているのがわかる

31226512688 975b1b6655

VPNが有効になっているが,IPはそのまま

45100103761 d9692f0075

ダッシュボード画面で最近のクエリの確認も出来る

30162180647 1f64018b79

試した環境は仮想環境のAndroid 8.1.0(x86_64), Intra 1.0.0

44189409735 9ecf88c2c2
44380132464 4d9cbeacae

自分は基本的に出先では VPN を利用しているので必要ないかなと思うのですが,お手軽に無料でかつ古いデバイスにも対応しているので良さそうですね.ちなみにこの機能は Android Pie には標準搭載されているそうです.

#Wi-FiなんかでDNS改ざんして認証画面に飛ばしたりするようなのはどういう動きになるんだろう?

macOS, Linux で Dropbox を fuse mount する dbxfs を少し試す

Dropbox を FUSE mount 出来る dbxfs というものを見つけたので試してみました.

Doropbox の Linux client はファイルシステムがext4のみと制限されます.dbxfs であればおそらくこの制限も問題ないのではないかと思います.(未確認)

The Dropbox folder will need to be on an ext4-formatted hard drive or partition
Note: ecryptfs is not supported, but Dropbox will continue to sync with supported file systems that are encrypted via full disk encryption (e.g. LUKS)

導入
$ sudo apt install libfuse2 python3-pip
help
$ ~/.local/bin/dbxfs -h
usage: dbxfs [-h] [-f] [-v] [-s] [-n] [-l SMB_LISTEN_ADDRESS] [-c CONFIG_FILE]
			 [-e ENCRYPTED_FOLDERS] [--print-default-config-file]
			 [mount_point]

positional arguments:
  mount_point

optional arguments:
  -h, --help            show this help message and exit
  -f, --foreground      keep filesystem server in foreground
  -v, --verbose         show log messages, use twice for maximum verbosity
  -s, --smb             force mounting via SMB
  -n, --smb-no-mount    export filesystem via SMB but don't mount it
  -l SMB_LISTEN_ADDRESS, --smb-listen-address SMB_LISTEN_ADDRESS
						address that SMB service should listen on, append
						colon to specify port
  -c CONFIG_FILE, --config-file CONFIG_FILE
						config file path
  -e ENCRYPTED_FOLDERS, --encrypted-folder ENCRYPTED_FOLDERS
						relative paths of encrypted folders, can be used
						multiple times. requires safefs
  --print-default-config-file
						print default config file path to standard out and
						quit
初回mount
$ ~/.local/bin/dbxfs ~/fuse/dbxfs
We need an access token. Perform the following steps:
1. Go to https://www.dropbox.com/oauth2/authorize?response_type=code&client_id=vinkudorurc8kno
2. Click "Allow" (you may have to log in first)
3. Copy the authorization code.
Enter authoritization code (Ctrl-C to quit): NodigIOndefkiwitshOrackazEuweavirtyedCibEdI
We're all connected. Do you want to save your credentials for future runs? [Y/n] Y
Would you like to help us improve dbxfs by providing anonymous error reports? [Y/n] Y
Mount point "/home/matoken/fuse/dbxfs" doesn't exist, do you want to create it? [Y/n] Y
  1. のurl をブラウザで開いて認証を行う
    認証後の画面で cli-dbxfs のアクセスを許可する.

45084023501 7cfd7c4058

許可後に表示されるトークンを 3. の後ろにコピー&ペーストする.

  • We’re all connected. Do you want to save your credentials for future runs?
    次回以降のために資格情報を保存するか?
  • Would you like to help us improve dbxfs by providing anonymous error reports?
    匿名のエラー報告を行いdbxfsに改善の支援を行うか?
  • Mount point “/home/matoken/fuse/dbxfs” doesn’t exist, do you want to create it?
    マウントポイントが存在しないので作成するか?
マウント確認
$ ls ~/fuse/dbxfs/
アンマウントする
$ fusermount -u ~/fuse/dbxfs
資格情報を保存していた場合2回目以降のマウントは何も聞かれない
$ ~/.local/bin/dbxfs ~/fuse/dbxfs

.

アクセストークンをpgpファイルに格納することも出来るようだが手元の環境では未だうまく行っていない(多分何か勘違いをしている)

EDIT: やはり使い方が間違っていた.次の記事に書いた -> Dropbox を FUSE mount する dbxfs のアクセストークンを gpg で暗号化する – matoken’s meme

設定ファイルの場所確認
$ ~/.local/bin/dbxfs --print-default-config-file
/home/matoken/.config/dbxfs/config.json
アクセストークンをpgpファイルにする
$ jq . /home/matoken/.config/dbxfs/config.json
{
  "keyring_user": "yigwulbaf6shnutugaivkilj",
  "send_error_reports": true,
  "asked_send_error_reports": true
}
$ gpg -r EAA13B982D937827 -e /home/matoken/.config/dbxfs/config.json
$ ls -l /home/matoken/.config/dbxfs/config.json*
-rw-r--r-- 1 matoken matoken 115 10月  4 07:19 /home/matoken/.config/dbxfs/config.json
-rw-r--r-- 1 matoken matoken 685 10月  4 07:22 /home/matoken/.config/dbxfs/config.json.gpg
$ shred /home/matoken/.config/dbxfs/config.json
$ echo '"access_token_command": ["gpg", "--decrypt", "/home/matoken/.config/dbxfs/config.json.gpg"]' > /home/matoken/.config/dbxfs/config.json
マウント
$ ~/.local/bin/dbxfs ~/fuse/dbxfs
Running 'gpg --decrypt /home/matoken/.config/dbxfs/config.json.gpg' for access token
gpg: 4096-ビットRSA鍵, ID EAA13B982D937827, 日付2015-06-11に暗号化されました
      "K.I.Matohara <matoken@gmail.com>"
Traceback (most recent call last):
  File "/home/matoken/.local/bin/dbxfs", line 11, in <module>
    sys.exit(main())
  File "/home/matoken/.local/lib/python3.6/site-packages/dbxfs/main.py", line 212, in main
    dropbox.Dropbox(access_token).users_get_current_account()
  File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/base.py", line 4245, in users_get_current_account
    None,
  File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 274, in request
    timeout=timeout)
  File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 365, in request_json_string_with_retry
    timeout=timeout)
  File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 449, in request_json_string
    timeout=timeout,
  File "/home/matoken/.local/lib/python3.6/site-packages/requests/sessions.py", line 559, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/matoken/.local/lib/python3.6/site-packages/requests/sessions.py", line 498, in request
    prep = self.prepare_request(req)
  File "/home/matoken/.local/lib/python3.6/site-packages/requests/sessions.py", line 441, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/home/matoken/.local/lib/python3.6/site-packages/requests/models.py", line 310, in prepare
    self.prepare_headers(headers)
  File "/home/matoken/.local/lib/python3.6/site-packages/requests/models.py", line 444, in prepare_headers
    check_header_validity(header)
  File "/home/matoken/.local/lib/python3.6/site-packages/requests/utils.py", line 941, in check_header_validity
    raise InvalidHeader("Invalid return character or leading space in header: %s" % name)
requests.exceptions.InvalidHeader: Invalid return character or leading space in header: Authorization

持ち運びモバイルPCだと辛いでしょうが,据え置きデスクトップ環境などのオンラインのマシンでは便利そうです.

環境
$ grep ^Version: ~/.local/lib/python3.6/site-packages/dbxfs-1.0.4.dist-info/METADATA
Version: 1.0.4
$ dpkg-query -W libfuse2 python3-pip
libfuse2:amd64  2.9.8-2
python3-pip     9.0.1-2.3
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

ADSLモデムのNATテーブル溢れで困る

古いADSL モデムで自宅サーバを立てている場合の話なので現代では役に立たないでしょうが健忘録として書いておきます.(光回線?圏外なのですorz)

環境
ADSLモデム-SV3
Hardware Revision: 0001
Software Version: 03.20 (Tue Jul 27 20:45:13 JST 2010)
Boot ROM Version: 01.00 (Thu Jun 3 17:07:20 JST 2004)
DSP Firmware Version: 42.20
VDSP Firmware Version: 9.1.60.12

最近よく家のネットワークで名前解決できなくなることがあります.
DNSが多段になっていて無駄が多いのでそのへんの問題かなと思ったのですが,直接ISP や 8.8.8.8 とか 1.1.1.1 とかの PublicDNS に問い合わせても引けません.

ISP — Unbound — PiHole — PC

ip 直なら繋がるだろうと試すとhttpもsshも駄目です.タイムアウトになります.

ルータを再起動すると直ることもあれば,直ってもすぐに元に戻ってしまうこともあります.

ルータのログみると tcp80 に大量のアクセスがあってそれで NAT table が溢れてしまって繋がらないということのようです.NAT table は 1024 しかないのですが,一度に 1 ipから200〜400回くらいのアクセスが来てこれが複数回来ると NAT table が溢れてしまい通信ができなくなるようです.
#NAT table を増やす設定変更項目は見当たらない

31167785778 8d6ed1d3d7

とりあえずルータを再起動しなくてもNAT table をクリアすると一時的に通信できるようになります.でもどんどんこのアクセスが来てすぐに元に戻ります.おまけにこのアクセスは「有効期限(秒)」が9000とかになっているのでなかなかクリアされません.(ほかは60のよう)
#有効期限の設定変更項目は見当たらない

ip を逆引きしてみると大抵は一般の利用者のようで名前が振られていないレンジや,ipアドレス-domain みたいな名前です.おそらく何かのウィルスに感染して攻撃をしているのではないかと思います.(Google Cloud とかもあったけど……)
幸い自宅サーバのtcp80はhttpsへのリダイレクトとテスト用なのでこれらのアクセスをブロックしてみました.
whois で inetnum を確認して,CIDR を計算して「パケットフィルタ設定」でこのネットワークの tcp80 へのアクセスを drop するように設定してNAT table クリアでドロップされるようにありました.ドロップは「セキュリティログ」で確認できます.

44992821992 770d5444e2

これを繰り返していたのですが設定は64個しか書けません.すぐに溢れました…….

別のアプローチを考えます.
このADSLモデムのweb管理画面はレガシーでcurlでアクセスできます.

NAT table の登録件数を求める
$ echo $(curl  -s -u 'user:password' 'http://192.168.1.1/cgi-bin/main.cgi?mbg_webname=nattbl'|lynx -stdin -dump -width=256|grep -m1 '現在の登録件数'|sed -e 's/^.*:\(.*\)\/.*$/\1/')
308

NATクリアも同様に出来ます.

NATテーブル消去
$ curl  -s -u 'user:password' -F 'mbg_webname=natclear' -F 'nat_clear=消去' 'http://192.168.1.1/cgi-bin/main.cgi' | lynx -stdin -dump
   NATテーブル消去
   [1]ヘルプ [2]help
   -----

   NATテーブルの消去を行いました。

   戻る

参照

   1. file:///cgi-bin/main.cgi?mbg_webname=help&mbg_helpname=natclear
   2. file:///cgi-bin/main.cgi?mbg_webname=help&mbg_helpname=natclear

これを使って NAT table を確認して,溢れそうだったらクリアするscriptを用意してみました.

script の中に書きたくないので ID/PASSWORDは ~/.netrc に書いておきます.

// EDIT : wgetに怒られたので netrc の machine を ADSL ROUTER から ADSL_ROUTER に変更(scriptも)
// wget: /home/mk/.netrc:1: "ROUTER" は不明な区切り記号(token)です

~/.netrc に追記
$ echo 'machine ADSL_ROUTER
> login user
> password  password
> ' | tee -a ~/.netrc
machine ADSL_ROUTER
login user
password  password

適当な script を用意して,

nat_clear.bash
#!/bin/bash

# ~/.netrc 読み込み
usrinfo=(`awk 'c&&c--;/ADSL_ROUTER/{c=2}' $HOME/.netrc | awk '{printf "%s ", $2}'`)
USER=${usrinfo[0]}
PASS=${usrinfo[1]}

# NAT table 登録数確認
NAT_TABLE=$(curl  -s -u "${USER}:${PASS}" 'http://192.168.1.1/cgi-bin/main.cgi?mbg_webname=nattbl'|lynx -stdin -dump -width=256|grep -m1 '現在の登録件数'|sed -e 's/^.*:\(.*\)\/.*$/\1/')

# NAT table が 750 より大きいとNAT table clear
if[ 750 -lt $NAT_TABLE ]; then
  echo "NAT table clrar(${NAT_TABLE})"
  # tcp:80 にアクセスしている ip を確認して表示
  curl  -s -u "${USER}:${PASS}" 'http://192.168.1.1/cgi-bin/main.cgi?mbg_webname=nattbl' | lynx -stdin -dump -width=256 | grep 192.168.1.102/80 | awk {'print $6'} | cut -f1 -d\/ | sort | uniq -c
  # NAT table clear
  curl  -s -u "${USER}:${PASS}" -F 'mbg_webname=natclear' -F 'nat_clear=消去' 'http://192.168.1.1/cgi-bin/main.cgi' | lynx -stdin -dump
fi

実行権を付与.

$ chmod +x nat_clear.bash

crontab に登録して5分毎に呼ぶように設定.

// EDIT: 1024使い切ってからクリアが多いので3分毎に変更した

$ crontab -e
crontab: installing new crontab
$ crontab -l | grep nat_clear.bash
*/5 * * * *     /home/mk/bin/nat_clear.bash

// EDIT: 実際に動作したときのログ追記

NAT table clrar(1024)
    837 103.234.73.6
    102 51.254.167.83
   NATテーブル消去
   [1]ヘルプ [2]help
   -----

   NATテーブルの消去を行いました。

   戻る

References

   1. file:///cgi-bin/main.cgi?mbg_webname=help&mbg_helpname=natclear
   2. file:///cgi-bin/main.cgi?mbg_webname=help&mbg_helpname=natclear

とりあえずこれで様子見中です.しかし対処療法でアクセスが増えたら耐えられなくりますね…….
サーバ機能を引っ越して外部からのアクセスを遮断したらこの問題は解決するはずですが出来たら選びたくないです.
ADSLモデムを高機能なものに置き換えると設定でどうにかなるかもとか,しかしそもそもADSL自体が収束なので製品が存在するのか?

とか思いながら設定項目を見ていると「PPPoEブリッジ機能」というものがありました.これを使うとADSLモデムの裏のサーバ等からPPPoEで繋げそうな感じがします.それが出来たらn分以内にn回アクセスがあったらしばらく無視するとか柔軟な設定が出来るようになります.次はこれを試してみたいと思います.

30105335967 6ed05163ae

#光回線はよ……

Nautilus が起動しなくなって困る

Nautilus が起動しなくなりました.nemo は起動するんだけど……
$ nautilus

(nautilus:16178): Tracker-ERROR **: 19:36:23.259: Unable to find default domain ontology rule /usr/share/tracker/domain-ontologies/default.rule
Trace/breakpoint trap
このファイルはなんだろうと中を覗こうとしたら存在しない
$ lv /usr/share/tracker/domain-ontologies/default.rule
/usr/share/tracker/domain-ontologies/default.rule: No such file or directory
tracker pkg に含まれるらしい
$ apt-file search /usr/share/tracker/domain-ontologies/default.rule
tracker: /usr/share/tracker/domain-ontologies/default.rule
インデックスや検索関連
$ apt show tracker
Package: tracker
Version: 2.1.4-1
Priority: optional
Section: utils
Maintainer: Debian GNOME Maintainers <pkg-gnome-maintainers@lists.alioth.debian.org>
Installed-Size: 3,453 kB
Depends: libc6 (>= 2.4), libglib2.0-0 (>= 2.45.3), libtracker-control-2.0-0 (= 2.1.4-1), libtracker-sparql-2.0-0 (= 2.1.4-1), dconf-gsettings-backend | gsettings-backend, shared-mime-info, libglib2.0-bin, default-dbus-session-bus | dbus-session-bus
Recommends: tracker-miner-fs
Homepage: https://wiki.gnome.org/Projects/Tracker
Tag: implemented-in::c, interface::commandline, interface::daemon,
 network::client, network::server, role::program, scope::utility,
 use::organizing, use::searching, works-with::db, works-with::file,
 works-with::pim
Download-Size: 1,009 kB
APT-Manual-Installed: yes
APT-Sources: http://ftp.jp.debian.org/debian sid/main amd64 Packages
Description: メタデータデータベース、索引付けおよび検索ツール
 Tracker は、メタデータとタグに関連付けられた第一クラスオブジェクト用の
 先進的なフレームワークです。全てのメタデータ、タグ、共有オブジェクト
 データベース、検索ツールと索引に対する統一されたソリューションを提供します。

N: 追加レコードが 1 件あります。表示するには '-a' スイッチを付けてください。
導入したら起動するようになりました
$ sudo apt install tracker
環境
$ dpkg-query -W $(dpkg -l nautilus* | grep ^ii | awk {'print $2'} ) tracker nemo
nautilus        3.30.0-4
nautilus-actions        3.2.3-1+b2
nautilus-compare        0.0.4+po1-1
nautilus-data   3.30.0-4
nautilus-filename-repairer      0.2.0-1
nautilus-gtkhash        1.1.1-3.1
nautilus-hide   0.2.3-4
nautilus-image-converter        0.3.1~git20110416-2
nautilus-image-manipulator      1.3-2
nautilus-scripts-manager        2.0-1
nautilus-share  0.7.3-2
nautilus-wipe   0.3-1
nemo    3.8.5-1
tracker 2.1.4-1
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

ssh環境での誤ったシステム停止を防ぐmolly-guard

最近 shutdown の man を見比べたりしてたのですが,そのときに systemd, sysvinit 以外に molly-guard という見知らぬものが.

$ apt-file search /sbin/shutdown
molly-guard: /sbin/shutdown
systemd-sysv: /sbin/shutdown
sysvinit-core: /sbin/shutdown

パッケージ情報をみると shutdown コマンドなどを置き換えて ssh 接続時には確認のためにホスト名を聞くようになるようです.
これにより手元のPCの再起動をしたつもりがリモートのサーバを再起動してしまうなどといったことが防げるようになります.

$ apt show molly-guard
Package: molly-guard
Version: 0.6.4
Priority: extra
Section: admin
Maintainer: Francois Marier <francois@debian.org>
Installed-Size: 57.3 kB
Depends: procps
Enhances: init, kexec-tools, mosh, openssh-server, pm-utils, systemd, sysvinit, upstart
Tag: implemented-in::shell, interface::commandline, network::server,
 protocol::ssh, role::program, scope::utility
Download-Size: 13.8 kB
APT-Manual-Installed: yes
APT-Sources: http://ftp.jp.debian.org/debian stretch/main amd64 Packages
Description: protects machines from accidental shutdowns/reboots
 The package installs a shell script that overrides the existing
 shutdown/reboot/halt/poweroff/coldreboot/pm-hibernate/pm-suspend* commands
 and first runs a set of scripts, which all have to exit successfully,
 before molly-guard invokes the real command.
 .
 One of the scripts checks for existing SSH sessions. If any of the four
 commands are called interactively over an SSH session, the shell script
 prompts you to enter the name of the host you wish to shut down. This should
 adequately prevent you from accidental shutdowns and reboots.
 .
 molly-guard diverts the real binaries to /lib/molly-guard/.  You can bypass
 molly-guard by running those binaries directly.

早速試してみます.

$ sudo apt install molly-guard
    :
package diverts others to: /lib/molly-guard/coldreboot
/sbin/halt
package diverts others to: /lib/molly-guard/halt
/sbin/pm-hibernate
/sbin/pm-suspend
/sbin/pm-suspend-hybrid
/sbin/poweroff
package diverts others to: /lib/molly-guard/poweroff
/sbin/reboot
package diverts others to: /lib/molly-guard/reboot
/sbin/shutdown
package diverts others to: /lib/molly-guard/shutdown

このあたりのコマンドが置き換わっています.

$ ls -l /sbin | grep molly
lrwxrwxrwx 1 root root        28 Aug 16  2016 coldreboot -> /lib/molly-guard/molly-guard
lrwxrwxrwx 1 root root        28 Aug 16  2016 halt -> /lib/molly-guard/molly-guard
lrwxrwxrwx 1 root root        28 Aug 16  2016 pm-hibernate -> /lib/molly-guard/molly-guard
lrwxrwxrwx 1 root root        28 Aug 16  2016 pm-suspend -> /lib/molly-guard/molly-guard
lrwxrwxrwx 1 root root        28 Aug 16  2016 pm-suspend-hybrid -> /lib/molly-guard/molly-guard
lrwxrwxrwx 1 root root        28 Aug 16  2016 poweroff -> /lib/molly-guard/molly-guard
lrwxrwxrwx 1 root root        28 Aug 16  2016 reboot -> /lib/molly-guard/molly-guard
lrwxrwxrwx 1 root root        28 Aug 16  2016 shutdown -> /lib/molly-guard/molly-guard

コマンド類は /lib/molly-guard 以下に退避されるようです.

sysvinit
$ ls -lA /lib/molly-guard
total 48
-rwxr-xr-x 1 root root 18952 Feb 13  2017 halt
-rwxr-xr-x 1 root root  2767 Aug 16  2016 molly-guard
lrwxrwxrwx 1 root root     4 Feb 13  2017 poweroff -> halt
lrwxrwxrwx 1 root root     4 Feb 13  2017 reboot -> halt
-rwxr-xr-x 1 root root 23368 Feb 13  2017 shutdown
systemd
$ ls -lA /lib/molly-guard
total 4
lrwxrwxrwx 1 root root   14 Jun 14 05:20 halt -> /bin/systemctl
-rwxr-xr-x 1 root root 2767 Aug 16  2016 molly-guard
lrwxrwxrwx 1 root root   14 Jun 14 05:20 poweroff -> /bin/systemctl
lrwxrwxrwx 1 root root   14 Jun 14 05:20 reboot -> /bin/systemctl
lrwxrwxrwx 1 root root   14 Jun 14 05:20 shutdown -> /bin/systemctl

ssh 経由で shutdown(sysvinit) を試みるとこのように hostname を求められます.ここで誤った hostname を書くと shutdown がキャンセルされました.

$ sudo shutdown -f -P -h +10 "kernel update (`uname -r`)"
W: molly-guard: SSH session detected!
Please type in hostname of the machine to shutdown: desktop
Good thing I asked; I won't shutdown debian ...
W: aborting shutdown due to 30-query-hostname exiting with code 1.

正しい hostname を指定すると shutdown が呼ばれます.

$ sudo shutdown -f -P -h +10 "kernel update (`uname -r`)"
W: molly-guard: SSH session detected!
Please type in hostname of the machine to shutdown: debian

Broadcast message from root@debian (pts/0) (Thu Sep 27 06:15:28 2018):

kernel update (4.9.0-3-amd64)
The system is going DOWN for system halt in 10 minutes!
^C
Shutdown cancelled.

ssh経由でない場合は molly-guard はすぐに shutdown を呼びます.

$ sudo shutdown -f -P -h +10 'poweroff'
^C
Shutdown cancelled.

環境

$ dpkg-query -W systemd-sysv molly-guard
molly-guard     0.6.4
systemd-sysv    232-25+deb9u4
$ dpkg-query -W sysvinit-core
sysvinit-core   2.88dsf-59.9
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$ cat /etc/debian_version
9.5
$ uname -m
x86_64

qcow2 イメージをマウント

qemuやKVMでよく使われるqcow2イメージのマウントを行いました.

イメージの確認
$ sudo qemu-img info /var/lib/libvirt/images/Debian.qcow2
image: /var/lib/libvirt/images/Debian.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 20G
cluster_size: 65536
Format specific information:
	compat: 1.1
	lazy refcounts: true
	refcount bits: 16
	corrupt: false
nbd モジュールの読み込み
$ sudo modprobe nbd
qcow2 イメージのバインド
$ sudo qemu-nbd -c /dev/nbd0 /var/lib/libvirt/images/Debian.qcow2
$ sudo fdisk -l /dev/nbd0
ディスク /dev/nbd0: 20 GiB, 21474836480 バイト, 41943040 セクタ
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
ディスクラベルのタイプ: dos
ディスク識別子: 0x3c0808c8

デバイス    起動 開始位置 終了位置   セクタ サイズ Id タイプ
/dev/nbd0p1 *        2048   499711   497664   243M 83 Linux
/dev/nbd0p2        501758 41940991 41439234  19.8G  5 拡張領域
/dev/nbd0p5        501760 41940991 41439232  19.8G 83 Linux
kpartx でデバイスマッピング
$ sudo kpartx /dev/nbd0
nbd0p1 : 0 497664 /dev/nbd0 2048
nbd0p2 : 0 2 /dev/nbd0 501758
nbd0p5 : 0 41439232 /dev/dm-1 2
dm-crypt で暗号化されているのでデバイスをオープン
$ sudo cryptsetup open /dev/nbd0p5 crypt
Enter passphrase for /dev/nbd0p5:
lvm領域なのでスキャンする
$ sudo lvmdiskscan
    :
  /dev/mapper/crypt                                     [     <19.76 GiB] LVM physical volume
  /dev/nbd0p5                                           [     <19.76 GiB]
  /dev/debian-vg/root                                   [      18.75 GiB]
  /dev/debian-vg/swap_1                                 [       1.00 GiB]
    :
マウントして内容確認
$ sudo mount -o ro /dev/debian-vg/root /mnt
$ ls /mnt/
bin   dev  home        initrd.img.old  lib64       media  opt   root  sbin  sys  usr  vmlinuz
boot  etc  initrd.img  lib             lost+found  mnt    proc  run   srv   tmp  var  vmlinuz.old
Table of Contents

環境

$ dpkg-query -W kpartx qemu-utils fdisk cryptsetup lvm2 mount linux-image-`uname -r`
cryptsetup      2:2.0.4-2
fdisk   2.32.1-0.1
kpartx  0.7.7-1
linux-image-4.18.0-1-amd64      4.18.8-1
lvm2    2.02.176-4.1
mount   2.32.1-0.1
qemu-utils      1:2.12+dfsg-3
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

Linuxの Google Chrome/Chromium でサインインと同期を無効にする

を見てなるほどと思ったのだけど,macOS, Windows の手順はあるけれどLinux の手順がないなてことで調べてみました.

参考にしたのはこちら.

/etc/opt/chrome, /etc/opt/chromium 以下に json 形式で設定ファイルを設定するだけでした.

Google Chrome の場合

ディレクトリ作成
$ sudo mkdir -p /etc/opt/chrome/policies/managed /etc/opt/chrome/policies/recommended
/etc/opt/chrome/policies/managed/disablesync.json に設定ファイル設置
{
        "SyncDisabled":true,
        "RestrictSigninToPattern":".*@example.com"
}

Chromium の場合

ディレクトリ作成
$ sudo mkdir -p /etc/opt/chromium/policies/managed /etc/opt/chromium/policies/recommended
/etc/opt/chromium/policies/managed/disablesync.json に設定ファイル設置
{
        "SyncDisabled":true,
        "RestrictSigninToPattern":".*@example.com"
}

環境

$ dpkg-query -W google-chrome-stable chromium
chromium        69.0.3497.92-1
google-chrome-stable    69.0.3497.100-1
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64