1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# 悪用厳禁!

# RPI (Wi-Fi) <> Ethernet <> PC
# CGI (192.168.4.1:8080) => RPI (HTTP)
# TOR (192.168.4.1:9050) => WEB (SOCK)
# TOR (192.168.4.1:9090) => WEB (HTTP)
# RAW (192.168.4.1:8118) => WEB (HTTP)
# WARP(192.168.4.1:8888) => WEB (HTTP)
# DEFAULT(Tor透過プロキシ) => WEB (ALL)

# WARPでの注意!
# 真: O: ISP => WARP => WEB
# 偽: X: ISP => WARP => TOR  => WEB
# 偽: X: ISP => TOR  => WARP => WEB

# Raspberry Pi Imager v2
# APP OPTIONS: DISABLE-ALL
set SSH
set WIFI
set CITY
set HOSTNAME
set TIMEZONE
set KEYBOARD
set USERNAME
set PASSWORD
not RPI-CONNECT

# login ssh
sudo arp-scan --localnet
ssh [USERNAME]@[IP]

# static ip
sudo nmtui
delete eth0
enable eth0
  ip: 192.168.4.1/24
enable wlan0
  ip: [IP]
  dns: 127.0.0.1
  gateway: [IP_GATEWAY]
disable ipv6
[x] Automatically connect
[x] Available to all users

Tmp /etc/resolv.conf
  nameserver 1.1.1.1

Radio
  WWAN: Disabled (SIM)

If Change Name eth0, wlan0
  sudo rm /etc/netplan/*

# update os
sudo apt update
sudo apt upgrade

# install neovim
sudo apt install neovim

# ---

# Router

# install router
sudo apt install dnsmasq iptables iptables-persistent

# disable avahi-daemon
sudo systemctl disable avahi-daemon

# /etc/hosts.allow
sudo mv /etc/hosts.allow /etc/hosts.allow.orig
sshd:[HOST_IP]
sshd:[HOST_IP]
sshd:[HOST_IP]

# /etc/hosts.deny
sudo mv /etc/hosts.deny /etc/hosts.deny.orig
ALL:ALL

# /etc/ssh/sshd_config.d/99-allow-users.conf
AllowUsers [USERNAME]@[IP] [USERNAME]@[IP] [USERNAME]@[IP]

# service sshd
sudo systemctl restart sshd && sudo systemctl status sshd

# /etc/dnsmasq.conf
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
interface=eth0
dhcp-range=192.168.4.10,192.168.4.50,255.255.255.0,24h
dhcp-option=3,192.168.4.1
dhcp-option=6,192.168.4.1

# service dnsmasq
sudo systemctl restart dnsmasq && sudo systemctl status dnsmasq

# iptables
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

# save iptables
sudo netfilter-persistent save

# /etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1

# reload sysctl
sudo sysctl -p

# install syslog
sudo apt install rsyslog

# ---

# Onion Pie (Pi Eth)

# install tor
sudo apt install tor

# /etc/tor/torrc
sudo mv /etc/tor/torrc /etc/tor/torrc.orig
NewCircuitPeriod 30
MaxCircuitDirtiness 30

FascistFirewall 1
ReachableAddresses *:443

User debian-tor
DataDirectory /var/lib/tor

DNSPort 192.168.4.1:9053
TransPort 192.168.4.1:9040
SocksPort 192.168.4.1:9050
HTTPTunnelPort 192.168.4.1:9090

AutomapHostsOnResolve 1
AutomapHostsSuffixes .onion
VirtualAddrNetworkIPv4 10.192.0.0/10

# service tor
sudo systemctl restart tor && sudo systemctl status tor

# install fail2ban
sudo apt install fail2ban

# /etc/fail2ban/jail.d/defaults-pi.conf
[sshd]
enabled  = true
port     = 22
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 3
findtime = 600
bantime  = -1
backend  = systemd

# service fail2ban
sudo systemctl restart fail2ban && sudo systemctl status fail2ban

# status fail2ban
sudo fail2ban-client status sshd

# all unban fail2ban
sudo fail2ban-client unban --all

# CONNECT-ETH (RPI <> PC) ---

# RAW (privoxy)

# install privoxy
sudo apt install privoxy

# edit /etc/privoxy/config
listen-address  192.168.4.1:8118
#listen-address  [::1]:8118

# service privoxy
sudo systemctl restart privoxy && sudo systemctl status privoxy

# RAW (tinyproxy)

# install tinyproxy
sudo apt install tinyproxy

# add edit /etc/tinyproxy/tinyproxy.conf
Port 8888
LogLevel Critical
Listen 192.168.4.1
Allow 192.168.4.0/24

# service tinyproxy
sudo systemctl restart tinyproxy && sudo systemctl status tinyproxy

# WARP (tinyproxy)

# install warp
sudo mkdir -p /usr/share/keyrings
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [arch=arm64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
sudo apt update && sudo apt install cloudflare-warp

# config warp
sudo warp-cli registration new
sudo warp-cli mode proxy
sudo warp-cli proxy port 1080
sudo warp-cli connect

# add /etc/tinyproxy/tinyproxy.conf
Upstream socks5 127.0.0.1:1080

# disable log
sudo systemctl edit warp-svc
[Service]
StandardOutput=null

# reload systemd
sudo systemctl daemon-reload

# service warp
sudo systemctl restart warp-svc tinyproxy && sudo systemctl status warp-svc tinyproxy

# ---

# Gateway Nginx Server (Tor Restart Server)

# install server
sudo apt install nginx fcgiwrap apache2-utils

# auth basic
sudo htpasswd -c /etc/nginx/.htpasswd admin

# config nginx
sudo nvim /etc/nginx/sites-available/default
server {
    listen 8080;
    root /var/www/html;
    index index.htm index.html;

    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    server_name 192.168.4.1;
    allow 192.168.4.0/24;
    deny all;

    location /config {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/config.cgi;
    }

    location /restart {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/restart.cgi;
    }

    location /shutdown {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/shutdown.cgi;
    }
}

# mkdir cgi
sudo mkdir /usr/lib/cgi-bin/

# config cgi
sudo nvim /usr/lib/cgi-bin/config.cgi
#!/bin/sh
echo "Content-type: text/plain"
echo ""

echo "main"
sudo iptables -nvL; sudo iptables -t nat -nvL; sudo ip6tables -nvL; sudo tail /var/log/syslog

echo
echo "deny"
cat /etc/hosts.deny

echo
echo "allow"
cat /etc/hosts.allow

echo
echo "sshd"
cat /etc/ssh/sshd_config.d/99-allow-users.conf

echo
echo "sysctl"
cat /etc/sysctl.conf

echo
echo "resolv"
cat /etc/resolv.conf

echo
echo "dnsmasq"
cat /etc/dnsmasq.conf

echo
echo "rc"
cat /etc/rc.local

echo
echo "tor"
cat /etc/tor/torrc

echo
echo "nginx"
cat /etc/nginx/sites-available/default

echo
echo "fail2ban"
cat /etc/fail2ban/jail.d/defaults-pi.conf

echo
echo "privoxy"
cat /etc/privoxy/config | grep -e "^listen-address "

echo
echo "tinyproxy"
cat /etc/tinyproxy/tinyproxy.conf | grep -e "^Port " -e "^LogLevel " -e "^Listen " -e "^Allow " -e "^Upstream "

echo
echo "config"
cat /usr/lib/cgi-bin/config.cgi

echo
echo "restart"
cat /usr/lib/cgi-bin/restart.cgi

echo
echo "shutdown"
cat /usr/lib/cgi-bin/shutdown.cgi

# exec config cgi
sudo chmod 0755 /usr/lib/cgi-bin/config.cgi

# restart cgi
sudo nvim /usr/lib/cgi-bin/restart.cgi
#!/bin/sh
echo "Content-type: text/plain"
echo ""

sudo systemctl restart tor warp-svc privoxy tinyproxy
echo "Tor WARP Privoxy Tinyproxy restarted"

# exec restart cgi
sudo chmod 0755 /usr/lib/cgi-bin/restart.cgi

# shutdown cgi
sudo nvim /usr/lib/cgi-bin/shutdown.cgi
#!/bin/sh
echo "Content-type: text/plain"
echo ""

sudo shutdown -h now
echo "See ya."

# exec shutdown cgi
sudo chmod 0755 /usr/lib/cgi-bin/shutdown.cgi

# allow visudo
sudo visudo
www-data ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart tor warp-svc privoxy tinyproxy
www-data ALL=(ALL) NOPASSWD: /usr/bin/tail /var/log/syslog
www-data ALL=(ALL) NOPASSWD: /usr/sbin/iptables -nvL
www-data ALL=(ALL) NOPASSWD: /usr/sbin/iptables -t nat -nvL
www-data ALL=(ALL) NOPASSWD: /usr/sbin/ip6tables -nvL
www-data ALL=(ALL) NOPASSWD: /usr/sbin/shutdown -h now

# service server
sudo systemctl restart nginx fcgiwrap && sudo systemctl status nginx fcgiwrap

# iptables v5.6
TOR_UID='debian-tor'; RAW_UID='privoxy'
WARP_IP='162.158.0.0/15'; RESERVED_IP='255.255.255.255/32 240.0.0.0/4 233.252.0.0/24 224.0.0.0/4 203.0.113.0/24 198.51.100.0/24 198.18.0.0/15 192.168.0.0/16 192.88.99.0/24 192.0.2.0/24 192.0.0.0/24 172.16.0.0/12 169.254.0.0/16 127.0.0.0/8 100.64.0.0/10 10.0.0.0/8 0.0.0.0/8'

sudo ip6tables -F
sudo ip6tables -A INPUT -j DROP
sudo ip6tables -P INPUT DROP
sudo ip6tables -A FORWARD -j DROP
sudo ip6tables -P FORWARD DROP
sudo ip6tables -A OUTPUT -j DROP
sudo ip6tables -P OUTPUT DROP
sudo ip6tables -nvL

sudo iptables -t nat -F
sudo iptables -t nat -A PREROUTING -i eth0 -p udp --dport 53 -j DNAT --to-destination='192.168.4.1:9053'
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp ! -d 192.168.4.1 -m multiport --dport 80,443 --syn -j DNAT --to-destination='192.168.4.1:9040'

sudo iptables -t nat -A OUTPUT -m string --hex-string '|2112a442|' --algo bm -j RETURN
sudo iptables -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to-destination='192.168.4.1:9053'
sudo iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 -m multiport --dports 80,443 --syn -j DNAT --to-destination='192.168.4.1:9040'
sudo iptables -t nat -A OUTPUT -m owner --uid-owner "$TOR_UID" -j RETURN
sudo iptables -t nat -A OUTPUT -m owner --uid-owner "$RAW_UID" -j RETURN
sudo iptables -t nat -A OUTPUT -d "$WARP_IP" -j RETURN
sudo iptables -t nat -A OUTPUT -o lo -j RETURN
for reserved_ip in $(echo "$RESERVED_IP"); do
  sudo iptables -t nat -A OUTPUT -d "$reserved_ip" -j RETURN
done
sudo iptables -t nat -A OUTPUT -p tcp -m multiport --dports 80,443 --syn -j DNAT --to-destination='192.168.4.1:9040'
sudo iptables -t nat -nvL

sudo iptables -F
sudo iptables -A INPUT -p icmp -j DROP
sudo iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i eth0 -p udp --sport 68 --dport 67 -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i eth0 -p udp --dport 9053 -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 9040 --syn -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 9050 --syn -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 9090 --syn -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 8080 --syn -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 8118 --syn -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 8888 --syn -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i wlan0 -p tcp --dport 22 --syn -m state --state NEW -j ACCEPT
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -j LOG
sudo iptables -A INPUT -j DROP
sudo iptables -P INPUT DROP

sudo iptables -A FORWARD -j DROP
sudo iptables -P FORWARD DROP

sudo iptables -A OUTPUT -p icmp -j DROP
sudo iptables -A OUTPUT -m string --hex-string '|2112a442|' --algo bm -j DROP
sudo iptables -A OUTPUT -m state --state INVALID -j DROP
sudo iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p udp --sport 67 --dport 68 -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -p udp -d 192.168.4.1 --dport 9053 -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -p tcp -d 192.168.4.1 --dport 9040 --syn -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -p tcp -d 192.168.4.1 --dport 9050 --syn -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -p tcp -d 127.0.0.1   --dport 1080 --syn -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -o wlan0 -p tcp --dport 443 --syn -m owner --uid-owner "$TOR_UID" -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -o wlan0 -p tcp --dport 443 --syn -m owner --uid-owner "$RAW_UID" -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -o wlan0 -d "$WARP_IP" -m state --state NEW -j ACCEPT
sudo iptables -A OUTPUT -o lo -d 127.0.0.1 -j ACCEPT
sudo iptables -A OUTPUT -j LOG
sudo iptables -A OUTPUT -j DROP
sudo iptables -P OUTPUT DROP
sudo iptables -nvL

# save iptables
sudo netfilter-persistent save

# service persistent
sudo systemctl restart netfilter-persistent && sudo systemctl status netfilter-persistent

# /etc/rc.local
#!/bin/sh
sleep 60; sudo systemctl restart tor warp-svc privoxy tinyproxy

# exec /etc/rc.local
sudo chmod 0755 /etc/rc.local

# sync && reboot
sudo sync && sudo reboot

# show rpi config, restart, shutdown
firefox http://192.168.4.1:8080/config
firefox http://192.168.4.1:8080/restart
firefox http://192.168.4.1:8080/shutdown

# Wi-FiのSSIDとPASSを以下に書き込み起動する
# (元々のSSIDとPASSはファイルごとバックアップしてね)
wpa_passphrase SSID PASS > wlan.txt
/rootfs/etc/netplan/
/rootfs/etc/NetworkManager/system-connections/

# torbrowser: about:config > restart
# proxy: network.proxy.socks_port: 9050
# proxy: network.proxy.socks: 192.168.4.1
# http3: network.http.http3.enable: false
# launcher: extensions.torlauncher.start_tor: false

# no exec raspi[-]config !
# raspi[-]config
Edit

Pub: 26 Jul 2025 07:14 UTC

Edit: 05 Dec 2025 03:03 UTC

Views: 421

Auto Theme: Dark