UNIX/Linux shell 脚本是否可以“退出”?并注销当前用户?

发布于 2024-11-29 08:08:18 字数 574 浏览 4 评论 0原文

我们这里遇到了一个奇怪的问题。不幸的是,我不能随意在此处发布代码,因为它属于供应商,但希望可以提供足够的信息,这样就没有必要了。

如果这里有人可以明确地说“bob”是否可以执行“some_script.sh”,并让它从中途退出他的 su'd 会话并让脚本的其余部分继续,那么很多事情都可以解释作为用户“pete”(最初是冒充“bob”),

我相当确定这是不可能的,但是还有人知道吗?

需要记住的事情:

  1. scriptA.sh 执行多个其他进程(串行),这些进程对数据库进行更改
    • 假设这些是 01.sql 到 10.sql。
    • 它通过使用适当的参数执行“sqlplus”来实现此目的。
  2. “sqlplus”二进制文件可供用户“bob”使用,但不能用于用户“pete”。
  3. 用户 pete 当前已 su 为用户“bob”,因为 pete 的 PATH 上没有 sqlplus。
  4. 我们在脚本/数据库中看到的输出表明“01.sql”已成功执行,但其他部分则未成功执行 - 它们因“sqlplus 命令未找到”错误而失败。

干杯,

We're having a strange issue here. Unfortunately I'm not at liberty to post the code here because it belongs to the vendor, but hopefully can provide enough info so that isn't necessary.

Much could be explained if someone here could definitively say whether or not it is possible for 'bob' to execute "some_script.sh", and have it exit out of his su'd session MID-WAY and have the remainder of the script continue as user 'pete' (who originally su'd to impersonate 'bob')

I'm fairly certain that this is not possible, but is there anyone out there that knows otherwise?

Things to keep in mind:

  1. scriptA.sh executes multiple other processes (serially) which make changes to a database
    • lets assume that these are 01.sql through to 10.sql.
    • It does this by executing 'sqlplus' with appropriate arguments.
  2. The 'sqlplus' binary is available to user 'bob', but NOT user 'pete'.
  3. User pete is currently su'd into user 'bob', because pete doesn't have sqlplus on his PATH.
  4. The output we saw in the script/database suggested that the '01.sql' was executed successfully, but not the others - they failed with a 'sqlplus command not found' error.

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感性不性感 2024-12-06 08:08:18

根据您提供的信息,“不。这是不可能的。”

如果用户“pete”su 访问“bob”,他会创建一个新的 shell 作为“bob”。从该新 shell 启动的任何进程都以“bob”身份运行。任何脚本,如果以“bob”身份运行,都无法将其用户/UID 更改为“pete”。任何以“bob”启动的进程都无法更改其用户/UID(可执行文件上缺少 setuid 位)。

更有可能的是,脚本的一部分正在修改 shell 环境并更改其 PATH 或脚本中的某些其他错误。

From the information you've given, "No. It is not possible."

If user 'pete' su's to 'bob', he creates a new shell as 'bob'. Any processes started from that new shell are run as 'bob'. Any script, if run as 'bob', cannot change it's user/UID to 'pete'. Any processes started as 'bob' cannot change their user/UID (absent setuid bit on the executable).

It's far more likely that part of the script is modifying the shell environment and changing its PATH or some other error within the script.

苏大泽ㄣ 2024-12-06 08:08:18

使用脚本尝试切换 UID 注定会失败。根据定义,需要共享登录的权限系统是不安全的。

按预期方式使用 AIX 权限系统。如果您需要 bob 的凭据来执行任务,则拥有一个 Sandipan 可以执行的程序,该程序将仅针对需要 bob 凭据的任务提升到 bob 权限。

这就是最小权限原则,也是处理这项工作的方法。共享密码是一种糟糕的黑客行为,它会鼓励更糟糕的黑客行为。

Using a script to attempt to switch UIDs is doomed to failure. A permissions system that requires shared logins is – by definition – insecure.

Use the AIX permissions system the way it was intended. If you need bob's credentials to perform a task then have a program that Sandipan can execute which will elevate to bob permissions for only that which needs bob's credentials.

This is the Principle of Least Privilege and is how to handle the job. Shared passwords are a bad hack that encourages worse hacks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文