gpt4 book ai didi

mysql - 在 MySql 上是否可以将选择授予所有用户?

转载 作者:行者123 更新时间:2023-11-29 00:23:30 25 4
gpt4 key购买 nike

我的问题很简单,我可以向所有(就像来自任何机器的任何密码的任何用户一样)用户授予权限吗?

  • 我知道在某些情况下这可能会有问题。但我们的是一个演示数据库,用户未知。所以,请饶了我们吧。

  • 据我所知和我尝试过的,答案是否定的,我们不能这样做。我发布这个问题是为了确认我的理解。

据我所知,我们不能。有没有办法解决这个问题?

最佳答案

正如人们在评论中所说的那样——这可能是个坏主意。但是,我想,为什么不试一试,看看如何做到这一点。

最简单的起点是创建一个没有用户名的 MySQL 用户:

GRANT ALL ON *.* TO ''@'%' IDENTIFIED BY '';

这将允许您使用任何用户名和空白密码登录。这可能是某些人正在寻找的 - 但听起来您想要任何用户名和密码。

为此 - 我建议使用 mysql-proxy .我会下载源代码。如果您使用的是 Ubuntu,那么您将需要以下软件包来构建它:

apt-get install libmysqlclient-dev \
pkg-config \
lua5.1 liblua5.1-0-dev liblua5.1-0 \
libglib2.0-dev \
libevent-1.4-2 libevent1-dev

如果你确实编译了它,那么之后你需要以 root 身份运行/sbin/ldconfig。

然后我们可以写一个lua脚本来设置每个连接的用户名和密码。 mysql-proxy 客户端有一些示例脚本,但是相关的 examples/tutorial-scramble.lua 文件是旧的,不适用于当前版本。您可以使用以下脚本:

local CLIENT_PROTOCOL_41       = 512    -- New 4.1 protocol
local CLIENT_SECURE_CONNECTION = 32768 -- New 4.1 authentication

local MYSQL_AUTH_CAPABILITIES = ( CLIENT_PROTOCOL_41 + CLIENT_SECURE_CONNECTION )

local password = assert(require("mysql.password"))
local proto = assert(require("mysql.proto"))

function read_auth()
local c = proxy.connection.client
local s = proxy.connection.server

local challenge = (s.scramble_buffer):sub(1,20)

local default_username = "foo"
local default_password = "bar"

proxy.queries:append(1,
proto.to_response_packet({
username = default_username,
response = password.scramble(challenge, password.hash(default_password)),
charset = 8, -- default charset
database = c.default_db,
max_packet_size = 1 * 1024 * 1024,
server_capabilities = MYSQL_AUTH_CAPABILITIES
})
)

return proxy.PROXY_SEND_QUERY
end

将其另存为 any-user-any-pass.lua 或其他名称。然后你需要在我在脚本中引用的数据库中创建用户(用户名 foo,密码 bar):

GRANT ALL ON *.* TO 'foo'@'localhost' IDENTIFIED BY 'bar';

然后我们可以启动 mysql-proxy - 我们将它连接到端口 3306 上的本地 mysql 服务器,它将监听端口 3307。使用类似于此的命令:

mysql-proxy --proxy-lua-script=`pwd`/any-user-any-pass.lua \
--proxy-backend-addresses=localhost:3306 \
--proxy-address=localhost:3307

在不同的终端测试它:

ubuntu@test:~$ mysql -h 127.0.0.1 -P 3306 -u ANYTHING -pSOMETHING
ERROR 1045 (28000): Access denied for user 'ANYTHING'@'localhost' (using password: YES)
ubuntu@test:~$ mysql -h 127.0.0.1 -P 3307 -u ANYTHING -pSOMETHING
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 752
Server version: 5.5.29-0ubuntu1 (Ubuntu)

Copyright (c) 2000, 2012, 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() |
+----------------+
| foo@localhost |
+----------------+
1 row in set (0.00 sec)

mysql>

如您所见 - 首先我测试直接连接到 MySQL - 它拒绝任何/某些凭据。然后我连接到 3307 上的 MySQL 代理,它让我直接进入,因为 lua 脚本正在更改连接使用的用户名和密码。

关于mysql - 在 MySql 上是否可以将选择授予所有用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20157429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com