FTPの暗号化
FTPのセキュリティ強化
 
2004/01/02
written Komuro



 

SafeTpの構築手順
説明
       
まず以下のサイトから、UNIX用のソースコードを引っ張ってくる。
もちろん、Windowsからログインを試みる場合は、Windows用クライアントも必要になってくるわけだが、専用のWizerdも用意されてるし何もいじるところが無いので、サーバの構築のみにとどめる。
http://safetp.cs.berkeley.edu/unix.html
       
 

ソースは、C++で書かれているようだった
特に、注意しなければいけないオプションも存在しなかったので、普通にconfigureを書けるだけで、makefileは、作成されるはずだが、こちらの環境では、libgmp.a (the GNU multi-precision math library)という物が存在しなかった。コンパイルの際必要らしいので、こちらもインストールする。


このライブラリに必要なパッケージの冒頭を少し読んでみた。
GMP(GNU Multiple Precision)は、整数、有理数および浮動小数点番号上で動作する絶対制度を持つ計算ライブラリである。
GMPが走るマシーンは、メモリ以外には、制限はない。

GMPは、豊富な機能を持っている。
また、それぞれの機能は規則的なインターフェースを持っている。
GMPのための主要な適用機能は暗号学および研究、インターネット・セキュリティ、代数システム、計算上の代数研究だ。

       
./configure
gmake
gmake check
  make作業を行った後、sc/install.pl スクリプトを利用して、インストールしろと書いてあるが、このスクリプトは、inetd.confを利用しているのが前提で作られているらしいので、使えなかった。


gmake後、コンパイル済みのバイナリーを、自分でコピーした。

cp sftpd sftpc makekeys viewkey addent /usr/local/safetp
chmod 755 /usr/local/safetp
chown -R safetp /usr/local/safetp
chgrp -R safetp /usr/local/safetp
       
SafeTPの構築手順

sftpd の公開鍵と秘密鍵を作成する。

su safefp
cd /usr/local/safetp
./makekeys 0 1024
以下のような画面が出た。

./makekeys 0 1024
Part of SafeTP's countermeasures against interception attacks
is the use of "branded" DSA keys-- that is, keys that include
a string that identifies the server who owns that key. This
string is attached to the public key, and the pair is signed with
the private key. Users will see this string when they first
connect to your server.

The string should include a domain name that users are likely
to use when connecting to your server. It can contain additional
information as well. (A creation date will be automatically
appended.)

For example: "UCB CS FTP server, ftp.cs.berkeley.edu"

Enter an identifying string (80 chars maximum):
kmr.homeip.net <- FQDNを入れた

SafeTP will now generate your new security keys. In order to make your keys
truly secure, you must provide us with some random input on the keyboard.
SafeTP will measure the time intervals between your keypresses and use this
to add entropy to the key generation procedure.
Now gathering entropy from system... If this appears to stall,
try moving the mouse or typing into another console window.
Entropy progress: [..........]
creating DSA keys with 1024 bits...
Time used to create DSA key: 0.0080 sec
Verifying DSA keys
server name: kmr.homeip.net [1/1/2004]
Verified.

 


/var/tmp/safetp/DSA に 公開鍵と秘密鍵が作成されているので、これらを移動してきた。
mv /var/tmp/safetp/DSA/* /usr/local/safetp/DSA

mv /var/tmp/safetp/* /usr/local/safetp/DSA

 
公開鍵をテキスト化する。

./viewkey DSA/public.key > DSA/public.key.txt
 

パーミッションの確認(key作成時デフォルトだと思うが念のため確認)/usr/local/safetp

~safetp 755
~safetp/randomSeed 600
~safetp/DSA 711
~safetp/DSA/private.key 600
~safetp/DSA/public.key 644
~safetp/DSA/public.key.txt 644
サービスのrの設定(以下を追加する。コメントを付けとくとなおいい)
vi /etc/services

ftp 21/tcp safetp # safetp added by SafeTP install 2004/01/01
ftp 21/udp fsp fspd
raw-ftp 351/tcp

ftpサーバを、loopbackアドレスと、自サーバに割り振られているアドレスのみとする。
vi /etc/hosts.allow

インターネットスーパーサーバの設定(xinetd)

service safetp
{
disable = no
socket_type = stream
wait = no
user = safetp
server = /usr/local/safetp/sftpd
#-9 をつけると Secure以外のコネクションを拒否 -8 もある
server_args = -s -9 -y/usr/local/safetp

}

 
wu-ftpd+SafeTP起動
SafeTPは、インターネットスーパーサーバの再起動で対応済みである。
待ち受けportは、デフォルトで21番ポートになる。

wu-ftpdは、351番portで走らせる。
in.ftpd -S -p 351

もちろんこのままでは、351番ポートで待機している、ftpサーバも反応してしまうため、iptablesなどで、ルールを設定してやる。

 
課題
ftpサーバがローカルで動いて、SafeTpがグローバルで動くものだから、
本来FTPサーバが持ち合わせているIP制限の機能が正しく動かなかった。

今後の課題として、実験を繰り返す予定
 
実験的なこと〔作成中)2004/01/13

http://safetp.cs.berkeley.edu/unix.html
上記のサイトから、IPなどを制限するパッチがあることを確認した。
すべて英文なので、理解を深めるために全部訳す。

Patchesより

This patch lets you specify a file with usernames and IP addresses, and restricts access accordingly. Also see the README.
このパッチを当てましょう、設定ファイルとともにユーザネームとIPアドレス、認証ユーザを制限します。さらに、READMEを読んでください。

This script is someone's attempt to get sftpc to be usable noninteractively. Caveat emptor.
このスクリプトは、sftpcに与える攻撃に 対話的に使用可能になるだろう。用心してください。

パッチの当て方。
% cd sftpd-1.50
% patch < user-ip-patch.txt

SafeTPマニュアル(作成中)
原文
日本語(勝手に和訳)
   

 

 
Patch後の処理

ます、SafeTPを立ち上げる前に、UserName/IPを制限する設定ファイルを用意しました。

/home/safetp/etc/allow_959 <ユーザ制限(ユーザ名の羅列)
/home/safetp/etc/allow_ip < IP制限(User : CIDR方式のIPで記述)

vi allow_ip
tomoyo 192.168.1.0/24 < CIDR方式のみの記述しか出来ない。

SafeTP-wu-ftpd 環境でログインを試みました。
以下部分的ログを抜粋します。

sftpdがSafeTP Daemonです。
wu-ftpdは ftpdになります。

Jan 14 11:26:15 kmr sftpd[590]: allowed "tomoyo" from 192.168.1.15, rule: tomoyo 192.168.1.0/24 <SafeTPから認証された
Jan 14 11:26:15 kmr sftpd[590]: USER tomoyo
<safetpにより認証された
Jan 14 11:26:15 kmr ftpd[591]: USER tomoyo
Jan 14 11:26:15 kmr ftpd[591]: PASS password
Jan 14 11:26:15 kmr ftpd[591]: FTP LOGIN FROM 192.168.1.1 [192.168.1.1], tomoyo < ftphostsにより認証される
Jan 14 11:26:15 kmr ftpd[591]:
Jan 14 11:26:15 kmr ftpd[591]: DNS:192.168.1.1
Jan 14 11:26:15 kmr ftpd[591]: IP:192.168.1.1
Jan 14 11:26:15 kmr ftpd[591]: PWD
Jan 14 11:26:15 kmr ftpd[591]: TYPE ASCII
Jan 14 11:26:15 kmr ftpd[591]: PORT
Jan 14 11:26:15 kmr ftpd[591]: refused PORT 192.168.1.15,3248 from 192.168.1.1
Jan 14 11:26:15 kmr ftpd[591]: PORT
 
改良を検討。

このログを見ても判るとおりSafeTPでIP制限を受けることはできるが、SafeTPはグローバル、 wu-ftpdはローカルで動いてますのでSafeTPはftpdに対して、ローカルIPをのみを送っています。


問題点としては、これらのことが起こると、wu-ftpd側では、常に、192.168.1.1からのアクセスだと認識してしまうため、wu-ftpd側の、ftphostsが何も役に立たないことになります。


もちろん、SafeTP側で、userとIP制限も行えるが、CIDR方式のみしか、記述が対応していないため、HOSTを念頭においた細かい設定は不可能と思われます。


そこで、以下の改良を検討しています。
1・192.168.1.0/255.255.255.0 などのフォーマットにも対応させたい
2・*.hogehoge.com などの DynamicIP型のHOST名にも対応させたい

(ftphosts と同じようなフォーマット形式で柔軟に対応したい経緯がある)

改良対象Daemon sftpd.cpp 111行目 138行目 455行目
 



 
FTPの暗号化
FTPのセキュリティ強化
 
2003/12/16
written Komuro