色々あって、MySQL ProxyでMySQLの認証パケットを書き換えたい。
具体的にはこんな感じ。
で、まあ取り敢えずソースコードに付属していたExampleのLuaスクリプトを覗いてみる。
https://github.com/cwarden/mysql-proxy/blob/master/examples/tutorial-scramble.lua
Lua読めないけど感じ的に、「user: replace, password: me」で認証パケットを投げると、「user: root, password: secret」に書き換えてバックエンドに投げてくれるような気配がする。
良いじゃない、素敵。
サンプルスクリプトだと書き換える先はテーブルで持ってるけど、これをユーザー名は正規表現で抽出してやって、パスワードは書き換えない方針にすればきっといける。
…と思ったのが1週間前、で、今まだ出来てない(´・ω・`)
起動は問題なく。
実在するユーザーで認証をかけるのも問題なし。
でも。
え、ユーザー名すりかえられてない。。
しかも認証パケットの長さがおかしいとか言われてる。。
バックエンドが5.6だからかなぁと思って5.5につないでみても同じ。
5.1, 5.0だとエラーメッセージがチャレンジコードの長さ云々じゃなくて.server_capabilities has to be setというのに変わるので云々。。
先は長そうだ。
具体的にはこんな感じ。
- ユーザー名に"+"が含まれていた場合、"+"とそれ以降の文字列を握りつぶす。
- mysql -uroot+yoku0825 -p だったら、rootに変換してやる。
- パスワードやその他のオプションは入力されたものを素通し。
- クライアントはmysqlコマンドラインクライアントとは限らない。
で、まあ取り敢えずソースコードに付属していたExampleのLuaスクリプトを覗いてみる。
https://github.com/cwarden/mysql-proxy/blob/master/examples/tutorial-scramble.lua
Lua読めないけど感じ的に、「user: replace, password: me」で認証パケットを投げると、「user: root, password: secret」に書き換えてバックエンドに投げてくれるような気配がする。
良いじゃない、素敵。
サンプルスクリプトだと書き換える先はテーブルで持ってるけど、これをユーザー名は正規表現で抽出してやって、パスワードは書き換えない方針にすればきっといける。
…と思ったのが1週間前、で、今まだ出来てない(´・ω・`)
$ /usr/mysql/proxy/bin/mysql-proxy --proxy-address=127.0.0.56:3306 --proxy-backend-addresses=127.0.0.1:64056 --proxy-lua-script=/usr/local/src/mysql-proxy-0.8.3/examples/tutorial-scramble.lua --log-level=debug
2013-07-24 18:38:24: (critical) plugin proxy 0.8.3 started
2013-07-24 18:38:24: (debug) max open file-descriptors = 8192
2013-07-24 18:38:24: (message) proxy listening on port 127.0.0.56:3306
2013-07-24 18:38:24: (message) added read/write backend: 127.0.0.1:64055
起動は問題なく。
$ mysql -h 127.0.0.56 -P 3306 -utpcc -ptest
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 214
Server version: 5.6.12-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT current_user();
+----------------+
| current_user() |
+----------------+
| tpcc@% |
+----------------+
1 row in set (0.05 sec)
実在するユーザーで認証をかけるのも問題なし。
でも。
$ mysql -h 127.0.0.56 -P 3306 -ureplace -pme
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'replace'@'localhost' (using password: YES)
え、ユーザー名すりかえられてない。。
for challenge "l-7mA=KCL7j3]Z,l^q>!\000" the client sent ",wョ。ア3礼P|ェ\
&濘\\m"
2013-07-24 18:45:20: (critical) network_mysqld_proto_password_check: assertion `20 == challenge_len' failed
2013-07-24 18:45:20: (debug) [network-mysqld.c:1134]: error on a connection (fd: -1 event: 0). closing client connection.
しかも認証パケットの長さがおかしいとか言われてる。。
バックエンドが5.6だからかなぁと思って5.5につないでみても同じ。
5.1, 5.0だとエラーメッセージがチャレンジコードの長さ云々じゃなくて.server_capabilities has to be setというのに変わるので云々。。
先は長そうだ。