2018年8月2日木曜日

Orange Pi ZeroでTORルーターを作成する

 せっかく購入した高価なRaspberry Pi 3 Model BをTORルーターにしていては勿体無いので、Orange Pi zeroに役割を譲ることにします。技適的にNGなので、電波暗室で試しましょう。

 Torbox Next Generation(TBNG)とかいうロシア製の怪しいパッケージを導入します。もっとセキュアな方法があるんだと思いますが、とりあえずTORネットワーク上のウェブサイトが見られれば良いやということで…



 基本的にはこちらに書いてある情報と同じものですが、そのままでは動かない手順があります。

http://znoxx.me/2018/04/06/poshaghovaia-installiatsiia-tbng-na-orangepi-zero/

 やっていきましょう。

アップデートしていきます。
$  sudo apt-get update
$  sudo reboot
(スペックの関係でここでリブートしないとupgradeに進まない)


$  sudo apt-get upgrade -y
$  git clone https://github.com/znoxx/tbng
$  sudo run-parts tbng/setup/apt

インストール作業が始まりますので、暫く待ちます。


TORが再起動を繰り返していないか確認します。
$   ps -ef | grep tor
$   ps -ef | grep tor


ネットワークアダプタ類を確認します。
$  ip addr


wlan0のIPアドレスを固定するため、設定ファイルを編集します。
nanoでファイルを開くと設定ファイルが出てきます。
$  sudo nano /etc/network/interfaces

-----------------------------------------------------------------------------------------------------------------------------
# Wireless adapter #1
# Armbian ships with network-manager installed by default. To save you time
# and hassles consider using 'sudo nmtui' instead of configuring Wi-Fi settings
# manually. The below lines are only meant as an example how configuration could
# be done in an anachronistic way:
#

#allow-hotplug wlan0
#iface wlan0 inet dhcp
#address 192.168.0.100
#netmask 255.255.255.0
#gateway 192.168.0.1
#dns-nameservers 8.8.8.8 8.8.4.4
#   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
# Disable power saving on compatible chipsets (prevents SSH/connection dropouts over WiFi)
#wireless-mode Managed
#wireless-power off

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

これを以下のように書き換えます。

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

# Wireless adapter #1
# Armbian ships with network-manager installed by default. To save you time
# and hassles consider using 'sudo nmtui' instead of configuring Wi-Fi settings
# manually. The below lines are only meant as an example how configuration could
# be done in an anachronistic way:
#

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.225.1
netmask 255.255.255.0

#gateway 192.168.0.1
#dns-nameservers 8.8.8.8 8.8.4.4
#   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
# Disable power saving on compatible chipsets (prevents SSH/connection dropouts over WiFi)
#wireless-mode Managed
#wireless-power off

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

 network-manager  を再起動するなどします。
$  sudo systemctl restart network-manager
$  sudo ifup wlan0
$  ip addr


-----------------------------------------------------------------------------------------------------------------------------
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever

2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 02:42:6c:0d:2a:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.104/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:6cff:fe0d:2aa8/64 scope link
       valid_lft forever preferred_lft forever

3: wlan0: mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 12:42:6c:0d:2a:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.225.1/24 brd 192.168.225.255 scope global wlan0
       valid_lft forever preferred_lft forever

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

Hostapdとやらを編集します。
$  sudo tbng/setup/configure_hostapd.py -a armhf -i wlan0

アクセスポイント名とパスワードが出てきます。セットアップ毎に変わるようです。
-----------------------------------------------------------------------------------------------------------------------------

INFO: Static version of hostapd binary installed to /home/nox/tbng/bin/hostapd-tbng.
Configuration located at /home/nox/tbng/config/hostapd-tbng.conf.

Your AP name: ComplexView

Your password: ComplexView306847

SystemD service hostapd-tbng is registered and enabled by default.

Don' forget to confgure dhcp service for wlan0 or use static IPs. Current IP of wlan0 is 192.168.225.1

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


Configuration located at /home/nox/tbng/config/hostapd-tbng.conf.
との事なので、これを編集します。

$  cd
$  sudo nano /home/nox/tbng/config/hostapd-tbng.conf

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

# Basic configuration

interface=wlan0

ssid=ComplexView
channel=4
#bridge=br0
# WPA and WPA2 configuration

macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=ComplexView306847

wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP


# Hardware configuration
#driver=nl80211

driver=rtl871xdrv
driver=nl80211
hw_mode=g
ieee80211n=1

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

太字の部分を編集し、CTRL + Xで抜けて上書き保存します。

次に、dnsmasqとやらを編集します。
$  sudo tbng/setup/configure_dnsmasq.py -i wlan0 -s apt -b 192.168.225.10 -e 192.168.225.30 -m 255.255.255.0


tbngの構成とインストールをやっていきます。
$  cd tbng/config/
$  ls *.example

-----------------------------------------------------------------------------------------------------------------------------
tbng.json.example  torcountry.json.example  user.json.example
-----------------------------------------------------------------------------------------------------------------------------



$  cp tbng.json.example tbng.json
$  cp torcountry.json.example torcountry.json
$  cp user.json.example user.json

wlan0とeth0に一致するようにtbng.jsonを編集します。
$  sudo nano tbng.json

下記のように編集します。
-----------------------------------------------------------------------------------------------------------------------------

{
  "cputemp": "default",
  "wan_interface": [
   {
     "name": "eth0"
   }
    ],
  "lan_interface": [
    {
      "name": "wlan0",
      "wireless": true
    }
  ],
  "allowed_ports_tcp" : [22,3000,7657,9050,8118,4200],
  "allowed_ports_udp" : [53],
  "lock_firewall": false
}

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

configの整合性をチェックします。
$  cd ..
$  sudo engine/tbng.py chkconfig

  INFO: Runtime updated called
  INFO: Check config called
と出ればOKのようです。

次にtbngをインストールします。
$  cd
$  sudo tbng/setup/configure_componetns.py -u nox (ユーザー名)

しばらく待ちます。

空き領域を解放します。
$  sudo apt-get clean


再起動します。
$  sudo reboot


暫くすると、先程ssidで設定したワイヤレスネットワークが表示されます。これに接続し、wpa_passphraseで設定したパスワードで入ります。

普通に接続しただけでは普通のWifiルーターと同じ挙動です。
設定でTORネットワークに接続するようにします。

http://192.168.225.1:3000
id: webui
pass: webui


これで設定画面に入り、TORを有効にします。privoxyモードもあるようです。これで完成です。

2000円程度で高機能なWifiルーターが手に入る訳ですから、すごい時代になったものだなと思います。技適的に違法な点を除けばですが・・・。