色々なプログラムで proxy を使えるようにする proxychains-ng を試す

proxychains-ng というものを見かけたので試してみます.ネットワーク関連の関数をフックして,SOCKS 4a, 5, HTTP proxy を利用できるようにします.
torsocks的な感じ.

とりあえずこんな感じで動きました

$ git clone https://github.com/rofl0r/proxychains-ng
$ cd proxychains-ng
$ ./configure && make

src/proxychains.confにtorの設定が書いてあるのでとりあえずそれで動かします.(tor daemon が動いている前提)
1回目はtimeoutに,2回目は成功.

$ ./proxychains4 -f src/proxychains.conf curl ifconfig.me/ip
  :
[proxychains] Strict chain  ...  127.0.0.1:9050  ...  ifconfig.me:80 <--socket error or timeout!
curl: (7) Couldn't connect to server
$ ./proxychains4 -f src/proxychains.conf curl ifconfig.me/ip
  :
[proxychains] Strict chain  ...  127.0.0.1:9050  ...  ifconfig.me:80  ...  OK
158.69.192.239

torsocksでは起動しないfirefox も起動した.

$ ./proxychains4 -f src/proxychains.conf firefox

Debian package にも proxychains4 という名前であった.こっちのほうが楽ですね.

$ apt show proxychains4
Package: proxychains4
Version: 4.13-4
Priority: optional
Section: net
Source: proxychains-ng
Maintainer: Boyuan Yang <byang@debian.org>
Installed-Size: 45.1 kB
Provides: proxychains, proxychains-ng
Depends: libproxychains4 (= 4.13-4), libc6 (>= 2.4)
Breaks: proxychains (<< 3.1-8)
Replaces: proxychains
Homepage: https://github.com/rofl0r/proxychains-ng
Download-Size: 14.1 kB
APT-Sources: http://ftp.jp.debian.org/debian sid/main amd64 Packages
Description: redirect connections through socks/http proxies (proxychains-ng)
 Proxychains is a UNIX program, that hooks network-related libc functions
 in dynamically linked programs via a preloaded DLL (dlsym(), LD_PRELOAD)
 and redirects the connections through SOCKS4a/5 or HTTP proxies.
 It supports TCP only (no UDP/ICMP etc).
 .
 This project, proxychains-ng, is the continuation of the unmaintained
 proxychains project (known as proxychains package in Debian).
$ sudo apt install proxychains4
$ $ proxychains4 curl ifconfig.me/ip
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.13
[proxychains] Strict chain  ...  127.0.0.1:9050  ...  ifconfig.me:80  ...  OK
94.230.208.147

環境

$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64

apt upgrade で ping(inetutils-ping) が壊れていると言われて失敗する

Debian sid amd64 環境で,apt upgrade するとこんなエラーで失敗しました.

$ sudo apt upgrade
Reading package lists... Done
Building dependency tree     
Reading state information... Done    
Calculating upgrade... Done          
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.         
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 inetutils-ping : Conflicts: ping
E: Broken packages 

ping コマンドはあるし実行も出来る.reinstall してみましたがエラーは解消されず.

$ sudo apt install --reinstall inetutils-ping                                                                     
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  python-newt
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 57 not upgraded.
Need to get 0 B/226 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 472864 files and directories currently installed.)
Preparing to unpack .../inetutils-ping_2%3a1.9.4-7_amd64.deb ...
Unpacking inetutils-ping (2:1.9.4-7) over (2:1.9.4-7) ...
Setting up inetutils-ping (2:1.9.4-7) ...
Processing triggers for man-db (2.8.5-2) ...

一時的に削除してみました.

$ sudo apt remove inetutils-ping
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  python-newt
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  inetutils-ping
0 upgraded, 0 newly installed, 1 to remove and 57 not upgraded.
After this operation, 358 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 472864 files and directories currently installed.)
Removing inetutils-ping (2:1.9.4-7) ...
Processing triggers for man-db (2.8.5-2) ...

削除した後 apt upgrade を試すと通りました.

$ sudo apt upgrade

その後 ping を install し直したあと upgrade を試すとエラーは出なくなりました.

$ sudo apt install inetutils-ping
$ sudo apt upgrade>/dev/null 2>&1;echo $?
0

原因がよくわからないですね…….

環境

$ dpkg-query -W apt inetutils-ping
apt     1.8.0
inetutils-ping  2:1.9.4-7
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64

dhcp パケットをキャプチャするメモ

tcpdumpの場合
$ sudo tcpdump -i wlp3s0 port 67 or port 68 -e -n
[sudo] password for matoken:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlp3s0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:07:44.898511 00:23:15:5b:a6:60 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 342: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:23:15:5b:a6:60, length 300
dhcpdump も読みやすくて便利
$ sudo dhcpdump -i wlp3s0
  TIME: 2019-04-10 21:17:17.398
	IP: 0.0.0.0 (0:23:15:5b:a6:60) > 255.255.255.255 (ff:ff:ff:ff:ff:ff)
	OP: 1 (BOOTPREQUEST)
 HTYPE: 1 (Ethernet)
  HLEN: 6
  HOPS: 0
   XID: 011d073a
  SECS: 0
 FLAGS: 0
CIADDR: 0.0.0.0
YIADDR: 0.0.0.0
SIADDR: 0.0.0.0
GIADDR: 0.0.0.0
CHADDR: 00:23:15:5b:a6:60:00:00:00:00:00:00:00:00:00:00
 SNAME: .
 FNAME: .
OPTION:  53 (  1) DHCP message type         3 (DHCPREQUEST)
OPTION:  50 (  4) Request IP address        192.168.1.5
OPTION:  12 (  5) Host name                 x201i
OPTION:  55 ( 17) Parameter Request List      1 (Subnet mask)
											 28 (Broadcast address)
											  2 (Time offset)
											  3 (Routers)
											 15 (Domainname)
											  6 (DNS server)
											119 (Domain Search)
											 12 (Host name)
											 44 (NetBIOS name server)
											 47 (NetBIOS scope)
											 26 (Interface MTU)
											121 (Classless Static Route)
											 42 (NTP servers)
											249 (MSFT - Classless route)
											 33 (Static route)
											252 (MSFT - WinSock Proxy Auto Detect)
											 17 (Root path)


--------------------


^C

subscribeonandroid.com 経由のpodcast をAndroid 以外で購読する

最近のPodcast の購読はPodget というアプリケーションで購読してダウンロードしたファイルを聞いています.

cron で回しているのですが,最近購読開始したPodcast がエラーになっています.購読URL を間違えたかな?と確認するとURL はPodcast ページのRSS のものと同じで正しそうだけどウェブブラウザで閲覧するとhtml のページが表示されています.

これはPodcast サービスがSubscribe on Android というサービスを利用していて,対応アプリでアクセスするとiTunes のようにワンクリック登録が出来てそうでない場合Android Podcast アプリを紹介するサービスのようです.podget はAndroid でもないしもちろん対応アプリケーションでもないので駄目ということのようです.

User-Agent で判別しているのかな?だとするとUser-Agent を詐称するGW を用意すれば良さそう対応アプリケーションのPodcastAddict に適当な自分の管理しているサーバのアドレスを登録してアクセスさせてログでUser-Agent を確認してみます.

127.0.0.1 - - [05/Apr/2019:19:43:23 +0900] "GET /podcast HTTP/1.1" 404 3806 "-" "PodcastAddict/v2 - Dalvik/2.1.0 (Linux; U; Android 9; PH-1 Build/PQ1A.190105.045)"

PodcastAddict/v2 - Dalvik/2.1.0 (Linux; U; Android 9; PH-1 Build/PQ1A.190105.045) というのがそれのようです.

curl でUser-Agent を詐称してアクセスしてみましたがhtml ドキュメントが渡ってきます.この方法ではダメそう.

$ curl -sA 'PodcastAddict/v2 - Dalvik/2.1.0 (Linux; U; Android 9; PH-1 Build/PQ1A.190105.045)' http://subscribeonandroid.com/example.com/rss | head -1
<!DOCTYPE html>

以下のページを見ると,subscribeonandroid.com のURL の後ろに RSS のURL を指定してあるよう.

Web Developers
Web developers are welcome to create Subscribe On Android links and buttons.

http://geeknewscentral.com/podcast.xml
Separate the scheme from the URL to a podcast feed.

http:// geeknewscentral.com/podcast.xml
Add “subscribeonandroid.com/” between the scheme and remaining URL.

http:// + subscribeonandroid.com/ + geeknewscentral.com/podcast.xml
The Subscribe-on-Android URL will have the following format:

http://subscribeonandroid.com/geeknewscentral.com/podcast.xml
Both http:// and https:// protocols are supported.

単純に subscribeonandroid.com/ を削ればいけるのではと試すとそのとおりでPodget でも問題なく購読できるようになりました.

100円ショップでスライム状のクリーナーを購入

100円ショップのダイソーに行ってきました.

ダイソー&アオヤマ 100YEN PLAZA 鹿児島いづろ店

そこで以前から100円ショップにあっても良さそうなのに見かけないなと思っていたスライム状のクリーナーを見つけました.
関東に居た頃はPCショップなどのレジ横とかによくあってひょいと買えたのだけどAmazonとかでは案外高くてうーんとなっていたものです.
ダイソーにはいろんな粘土材質の粘土があるのでそれでどうにか出来ないだろうかとか考えていたんだけど試す前に扱ってくれました.

cleaner IMG 20190403 124107
cleaner IMG 20190403 124121

以前使っていたものより千切れやすいような感じですが問題なく使えています.そのまま放置すると乾いてしまうでしょうが,入っていた元の袋にはジッバーがついているので保管も問題無さそうです.
自分の場合,NotePCやカメラなどに使います.特にカメラのSD Card やバッテリー蓋周りなどこれを使うととても便利です.
売れて定番商品になってくれるといいな.

Amazonで取り扱っているもの880円ちょっとはちょっと高く感じます.

今見ると250円と安いものもあった.

無線マウスも2種類ありました.2.4GHz帯だけど専用ドングル,Bluetooth接続なら欲しかったです.価格は300円.

IMG 20190403 124313
IMG 20190403 124319
IMG 20190403 124325
IMG 20190403 124331

普通のマウスも同じ値段の300円.

IMG 20190403 124338
IMG 20190403 124343

そういえばCan★Doには100円の有線マウスがありました.これは持ち運び向けにと買って少し使いましたが流石にスクロールホイールなどは使いづらいです.それとLEDが眩しい(2019年2月にニシムタスカイマーケット店にて確認)

IMG 20190403 141843
IMG 20190403 141848

apt/apt-get のエイプリルフール牛さん

昨夜なんとなく apt コマンドのイースターエッグの apt moo を実行してみました.するといつもとは違った牛が!

20190402 00 04 09 23354

Debian sid 環境だったのでもしかしてキャラクター変更されたのだろうかと思ったのですがしばらくしてから再度実行するといつもの牛.

20190402 20 04 14 16775

時計を見ると日付が04/01から04/02に変わったところでした.
04/01に出現したってことはエイプリルフールな牛かな?と faketime command を利用して1日前にして実行すると出てきました.

$ faketime -f '-1d' apt moo
               _     _
              (_\___( \,
                )___   _  Have you smashed some milk today?
               /( (_)-(_)    /
    ,---------'         \_
  //(  ',__,'      \  (' ')
 //  )              '----'
 '' ; \     .--.  ,/
    | )',_,'----( ;
    ||| '''     '||

若しくは04/01を指定

$ faketime '20190401' apt moo
               _     _
              (_\___( \,
                )___   _  Have you smashed some milk today?
               /( (_)-(_)    /
    ,---------'         \_
  //(  ',__,'      \  (' ')
 //  )              '----'
 '' ; \     .--.  ,/
    | )',_,'----( ;
    ||| '''     '||

多分この辺ですね

$ grep -A21 bool\ DoMooApril ./apt-private/private-moo.cc
static bool DoMooApril()                                                /*{{{*/
{
   // by Christopher Allan Webber and proposed by Paul Tagliamonte
   // in a "Community outreach": https://lists.debian.org/debian-devel/2013/04/msg00045.html
   if (_config->FindI("quiet") >= 2)
   {
      std::cerr << "Have you smashed some milk today?" << std::endl;
      return true;
   }
   c1out <<
      "               _     _\n"
      "              (_\\___( \\,\n"
      "                )___   _  Have you smashed some milk today?\n"
      "               /( (_)-(_)    /\n"
      "    ,---------'         \\_\n"
      "  //(  ',__,'      \\  (' ')\n"
      " //  )              '----'\n"
      " '' ; \\     .--.  ,/\n"
      "    | )',_,'----( ;\n"
      "    ||| '''     '||\n";
   return true;
}

1.4 で入ったぽい?

$ zgrep -A2 \(1.4\) /usr/share/doc/apt/changelog.gz
apt (1.4) unstable; urgency=medium

  * The April Fools' Release

ちなみに moo moo でカラフルな牛が出てこないときは,APT::Moo::Color オプションが使えるようです.(エイプリルフール牛は単色のみみたい)

20190402 20 04 40 17194

永続化する場合や色をカスタマイズしたい場合は /usr/share/doc/apt/examples/configure-index.gz を参考に /etc/apt/apt.conf に設定すればok.

$ zgrep moo::color /usr/share/doc/apt/examples/configure-index.gz
apt::moo::color "<BOOL>";
$ echo 'apt::moo::color "true";' | sudo tee -a /etc/apt/apt.conf
apt::moo::color "true";
$ dpkg-query -W apt faketime
apt     1.8.0
faketime        0.9.7-3
$ lsb_release -dr
Description:    Debian GNU/Linux buster/sid
Release:        unstable
$ uname -m
x86_64

Ubuntu Server インストーラの Github, Launchpad からの ssh公開鍵インポート機能

github.com/settings/keys からSSH Keyとして突っ込んどくと便利だし、今のUbuntu Serverはセットアップでそれを使う項目すらあるので

なるほど便利そう
試してみようと Ubuntu Server 18.04.2 LTS
(ubuntu-18.04.2-live-server-amd64.iso) のインストーラで試してみました.

OpenSSH を導入するようにすると,SSH鍵をインポートするオプションで Github / Launchpad が選べます.
Screenshot ubuntu18 04 2019 03 30 13 02 56

こんな感じでインポートされました.
Screenshot ubuntu18 04 2019 03 30 13 05 37

インストールが終了して ssh login するとインポートされた鍵で login 出来ました.

インポートされた公開鍵を確認するとコメント部分が少し書き換わっています.

$ cat ~/.ssh/authorized_keys
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPgwY9aZPxN/YoBBzd7TOcCk7EuGO0E9PuUjCHPtTuHP matoken@github/16598604 # ssh-import-id gh:matoken
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEoKnbjj7cVafcAJbYHqUEua1x/81uzoK0LnjgqmR6H8 matoken@github/33364582 # ssh-import-id gh:matoken

sshd_config を見ると編集ではなく末尾に追記してるのでちょっと雑い感.

$ grep PasswordAuthentication /etc/ssh/sshd_config
#PasswordAuthentication yes
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication, then enable this but set PasswordAuthentication
PasswordAuthentication no
$ tail -1 /etc/ssh/sshd_config
PasswordAuthentication no

ちなみに,Github から鍵を入手するのはこんな感じで行けるようです.
(<USERNAME>部分を該当ユーザ名に修正)

Launchpad はこんな感じ.

ちなみにLaunchpad は未だED25519形式には未対応なようです.
20190330 13 03 12 27418

Bitbucket の鍵も同様に https://api.bitbucket.org/2.0/users/<USERNAME>/ssh-keys で入手できそうと思ったのですが,未認証では駄目みたいです.

$ curl -s https://api.bitbucket.org/2.0/users/matoken/ssh-keys|jq
{
  "type": "error",
  "error": {
    "message": "This API is only accessible with the following authentication types: session, password, apppassword"
  }
}
環境
$ lsb_release -d
Description:	Ubuntu 18.04.2 LTS
$ uname -m
x86_64

Ansibleもくもく会(サーバ編)2019.03 in オイシックス・ラ・大地!に遠隔参加 #ansiblejp

03/26にこのイベントに遠隔参加してみました.遠隔枠がある!てことで申し込み.人気があるようで申込み時点ではギリギリ選外でしたがその後繰り上がりで参加できました.

構成管理ツールの1つである Ansible 及び Ansible Tower のもくもく会です.
遠隔枠では BlueJeans という会議システムを利用でしたがトラブルのためほぼなしで最後のLTの一部のみ聞けた感じでした.
教材となるドキュメント(Ansible を1から始める人でもok)を見ながら用意されたAWS 環境を利用して各自学習していき,質問等はGoogleDoc を共有してそこで質問するとメンターの方が答えてくれるという形でした.
会議システムがうまく行きませんでしたが,GoogleDocとメンターの方々のおかげで十分成り立つ感じでした.

興味がある方は教材は公開されているのでそれを利用して自習したり(要環境構築),04/20にもリモート枠のある(恐らく)同じイベントがあるので参加してみるといいかもしれません.

また,もくもく会ではありませんがこういうイベントも開催されるようです.
こちらもウェブ参加枠があるので可能なら参加してみようと思っています.

ここから自分のハマったところ

サーバのパスワードが短い単語1つだったのでログインして即変更したけど,認証にパスワード認証を使っていたのでansible が通信できなくなってしまった.

$ ansible control -m command -a "uptime" -o
ansible | UNREACHABLE!: Invalid/incorrect password: no such identity: /home/student4/.ssh/aws-private.pem: No such file or directory
Permission denied, please try again.

passwdコマンドで治そうと思ったけど弱いパスワードなので起こられて設定できない

BAD PASSWORD: The password is shorter than 8 characters

なので,

$ openssl passwd -6 -salt $(openssl rand -base64 6) PASS

として SHADOW を作り,sudo vipw -s で該当ユーザの第2フィールドを書き換えた.

Ansible Tower Exercise 3 の Step 4 の「ADD SURVEY」ボタンが見つからない

ライセンスを間違えていた.

Ansible Towerのインストール に載っている Ansible Tower License ではなく, Exercise 2 – Ansible Towerのコンフィグレーション Step2 に載っている Ansible Workshop License のライセンスと差し替えて利用可能になった.

前日に Ansible Tower の環境構築で何箇所か嵌った

以下のページに

ansible-tower setupメモ

「Ansibleもくもく会 (サーバ編)2019.03 in オイシックス・ラ・大地!」にリモート枠が!鹿児島からでも参加できそうと申し込みました.

参加するに当たってAWSの環境が用意されるようだけど手元の回線は不安定だし勉強会後のことも考えると手元にも環境を用意しておいたほうが良さそうということで以下のページを参考にセットアップしました.その時つまずいたときのメモです.

※Debian sid amd64 上のKVM 環境に CentOS7 x86_64 環境を用意してその中で設定しました. ansible-tower-setup のバージョンはlatest で 3.4.2-1 でした.

setup.sh の実行は tower ディレクトリの下で

Step2 で,setup.shを実行するとリポジトリが見つからずエラーとなる

$ sudo ./ansible-tower-setup-$VERSION.el7/setup.sh
https://releases.ansible.com/ansible-tower/rpm/dependencies//epel-7-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found

以下のあたりでバージョンを取得している

ansible-tower-setup-3.4.2-1/setup.sh:baseurl=$AW_REPO_URL/rpm/dependencies/$(grep version group_vars/all | grep -o ':digit:.:digit:')/epel-$1-x86_64

tower のディレクトリに降りて実行すればok

$ cd ansible-tower-setup-3.4.2-1
$ sudo ./setup

実行環境のRAM は4GB 以上に

RAM 512MBで setup.sh を実行するとエラー.RAMが足りないらしい.

TASK [preflight : Preflight check - Fail if this machine lacks sufficient RAM.] ***********************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "This machine does not have sufficient RAM to run Ansible Tower."}
        to retry, use: --limit @/home/matoken/ansible-tower-setup-3.4.2-1/install.retry

システム要件を確認すると4GB のRAM が必要らしい

4 GB RAM minimum for Tower installations

なそ
にん

時間がないときは LIMITED FEATURES UP TO 10 NODES ライセンスを選択

ADD) もくもく会ではこれとは別のURLから Red Hat Ansible Tower, Standard (10 Managed Nodes) Trial を入手して利用した.以下の LIMITED FEATURES UP TO 10 NODES では最後のあたりで詰まる.(Exercise 3 の Step 4 で「ADD SURVEY」ボタンが出てこない)

ENTERPRISE FEATURES の場合人力みたい

An Ansible representative will be reaching out to you within one business day with your Ansible Tower enterprise features trial license key.

LIMITED FEATURES UP TO 10 NODES だとすぐにメールで届いた

You should receive an email shortly with your Ansible Tower Basic Edition trial license key.

試した環境

$ cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
$ uname -m
x86_64

Endlessh を使って ssh 接続をとてもゆっくりと処理して攻撃者に嫌がらせをする

ssh は攻撃が多いです.公開鍵認証にしておくと大分侵入に強くなりますがインターネットに直接繋がっているサーバでは攻撃はとても多いです.

Endlessh はsshd の代わりに起動してバージョン情報を送る前のデータにほぼランダムな文字列をゆっくりと配信し続けて攻撃者の足止めをするプログラムのようです.
本当の sshd は別ポートで起動してそっちを使う感じでしょうか.22番を無くして port knocking や sslh を使うなどのほうがいいかもですが面白そうです.

ということで手元で少し試してみました.

導入とビルド
$ git clone https://github.com/skeeto/endlessh
$ cd endlessh
$ git log |head -1
commit 548a7b1521b2912e7e133d0d9df50e0e514f1f2c
$ make
port 22222 で起動
$ ./endlessh -v -p22222 &
[1] 22698
2019-03-24T04:56:10.338Z Port 22222
2019-03-24T04:56:10.338Z Delay 10000
2019-03-24T04:56:10.338Z MaxLineLength 32
2019-03-24T04:56:10.338Z MaxClients 4096
ssh 接続してみると700分ほど捕まえていた
$ time ssh localhost -p 22222
2019-03-24T04:56:19.510Z ACCEPT host=::1 port=59402 fd=4 n=1/4096
ssh_exchange_identification: No banner received

real    700m30.650s
user    0m0.040s
sys     0m0.240s
2019-03-24T16:37:00.162Z CLOSE host=::1 port=59402 fd=4 time=42040.652 bytes=73944
終了
$ kill %1
[1]+  Done                    ./endlessh -v -p22222

数回試しましたが,標準オプションでは700分前後捕まりました.単にありもののscriptを動かすレベルの攻撃者であればツールが対応するまでは妨害になりそうです.

環境
$ git log |head -1
commit 548a7b1521b2912e7e133d0d9df50e0e514f1f2c
$ dpkg-query -W openssh-client
openssh-client  1:7.9p1-9
$ lsb_release -dr
Description:    Debian GNU/Linux buster/sid
Release:        unstable
$ uname -m
x86_64