Yearly Archives

18 Articles

启用yoooo.us

10   13453 转为繁体

准备把之前用的一套(山寨)cdn用到博客和其他一堆乱七八糟的站上面,用了yoooo.us(4个o)来做cname。主要现在的yooooo.us还依赖cloudflare的服务没法搬,所以另外注册了一个放到cloudxns上根据运营商区分解析。现在电信走的是idcf;联通移动和港澳台小伙伴是vultr日本;国外是cc的lax。韩国kt用来做冗余。

所以对于你们来说,每次打开我的博客的时候,可以至少省一个字节的流量了。

被害妄想症如何保护服务器安全

15   13806 转为繁体

自从有次过海关的时候电脑被TSA开包检查硬盘还掉下来了之后,我的被害妄想症就越来越没救了。

这篇文章假设有人可以物理接触你的电脑,以及你所在的网络不可信,这种情况下应该怎么保护你的服务器数据安全。

 

  • 使用代理登录SSH以隐藏服务器IP。如果有多台服务器,选择一个位置最近的做跳板机,加密它的文件系统(OpenVZ再见)。设置另外机器的hosts.deny和hosts.allow为仅允许跳板机IP登录;如果使用不支持tcpwrapper的服务如dropbear,需手动设置iptables。
  • 登录跳板机的方式要和登录另外机器的方式不同。
    • 使用密码+google authenicator登录跳板机,然后通过公钥登录别的机器。设置跳板机的sudo需要密码,且设置为不同于当前账户的密码;方法是在/etc/passwd中添加一行toor:x:0:0:root:/root:/usr/sbin/nologin,使用passwd修改toor的密码,在/etc/sudoers中添加一行Defaults        runas_default=toor, runaspw。
    • 使用密钥A登录跳板机,使用另一个密钥B登录别的机器。密钥B应保存在本地,通过ssh-agent转发到跳板机。不同设备上的密钥B可以设置不同的passphrase。dropbear不支持ed25519,而ecdsa据都市传说可能存在NSA的后门。
  • 每三个月更换一次密钥。
  • 保证密钥的passphrase的强度;不使用任何云服务保存密码和密钥;如果实在记性太差,在本地AES加密一次,然后做好伪装(比如将二进制密文附到图片文件之后或压缩文件之前,[密文|!Rar…] 或 [\xFF\xD8…\xFF\xD9|密文])。
  • 设置fail2ban。
  • 监控跳板机/var/log/wtmp中的登录IP。
  • 如果没有必要,关闭SSH和其他各类开放端口。
  • 所有明文服务尽可能走tls。如果客户端支持SNI,配置假证书以防止被猜测域名。可以使用lua-resty-sniproxy

欢迎交流

cidr.me地理位置查询

2   14648 转为繁体

基于OpenResty ,MaxMind GeoIP数据库和从bgp.he.net生成的ASN数据库,因为没有经纬度的需求所以没有显示。下文有源代码的链接,如果需要可以自行修改加上经纬度或者将输出变为JSON等。

这里有chrome插件

使用方法

查询当前IPv4地址

$ curl http://cidr.me/ip
x.x.x.x

查询当前IPv6地址

$ curl http://ipv6.cidr.me/ip
x.x.x.x

查询当前IP的PTR记录(反向DNS),地理位置和ASN

$ curl http://cidr.me/
x.x.x.x
Country, City
ASN number

查询当前IP的PTR记录

$ curl http://cidr.me/rdns
x-x-x-x.com

查询指定IP的地理位置

$ curl http://cidr.me/74.125.203.199
74.125.203.199 th-in-f199.1e100.net
United States, California, Mountain View
AS15169 Google Inc.

查询域名的地理位置

$ curl http://cidr.me/www.google.com.hk
172.217.3.195 sea15s12-in-f3.1e100.net
United States, California, Mountain View
AS15169 Google LLC

2607:f8b0:400a:809::2003 sea15s12-in-x03.1e100.net
United States
AS15169 Google LLC

查询域名的IP

$ curl http://cidr.me/www.google.com.hk/ip
74.125.203.199
2607:f8b0:400a:809::2003

查询域名的IP和CNAME(如果存在)

$ curl http://cidr.me/www.youtube.com/dns
youtube-ui.l.google.com 172.217.3.174
172.217.3.206
216.58.193.78
216.58.217.46
2607:f8b0:400a:808::200e

源代码

在这里https://gist.github.com/fffonion/44e5fb59e2a8f0efba5c1965c6043584

需要ngx_http_geoip_module, echo-nginx-module, lua-nginx-module,安装libgeoip,并将maxmind的旧版geoip数据库放在/usr/share/GeoIP

通过bgp.he.net生成ASN数据库

Read More

离线下载一条龙

9   8961 转为繁体

因为怕死 遵纪守法,所以不在自家bt下新番和剧。目前的架构是这样的,造福一下海外党

  1. 一个offshore的DMCA不敏感的服务器。RSS爬取某两个网站添加磁力链接到deluge。nginx添加一个下载目录的location,记得要https,并且给default_server加上假证书,参见这篇博客
  2. 家里一个树莓派或者类似的硬件,运行aria2,开放aria2 rpc端口到公网,加上token。或者ssh转发aria2的端口到一个跳板机。
  3. deluge使用execute插件,在Torrent Complete事件执行shell脚本添加到家里的aria2,并且设置pause值为true。
  4. 树莓派crontab半夜执行aria2.unpauseAll开始下载

用 OpenResty 写了一个 SNI 代理

0   12477 转为繁体

功能类似于dlundquist/sniproxy

推荐 OpenResty 加上 stream 模块和 ngx_stream_lua_module 模块。在 1.9.15.1 上测试通过。

示例配置:

A Lua table sni_rules should be defined in the init_worker_by_lua_block directive.

The key can be either whole host name or regular expression. Use . for a default host name. If no entry is matched, connection will be closed.

The value is a table containing host name and port. If host is set to nil, the server_name in SNI will be used. If the port is not defined or set to nil, 443 will be used.

Rules are applied with the priority as its occurrence sequence in the table. In the example above, twitter.com will match the third rule rather than the fourth.

If the protocol version is less than TLSv1 (eg. SSLv3, SSLv2), connection will be closed, since SNI extension is not supported in these versions.