如何使用 PAM 以明文形式检索用户密码?

发布于 2024-12-09 08:56:01 字数 107 浏览 2 评论 0原文

我正在编写一个 PAM 模块,它将用户名/密码写入文件中,以便其他应用程序进行进一步的事务处理。我只看到了 PAM_AUTHTOK 项,但我不确定它是哪种类型。有人知道获取明文密码的方法或其他方法吗?

I am writing a PAM module which writes the username/password in a file for further transaction by an other application. I only saw the PAM_AUTHTOK item but I'm not sure from which type is it. Anybody knows that or another way to get the cleartext password?

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

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

发布评论

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

评论(3

二货你真萌 2024-12-16 08:56:01

这是一个非常古老的线程,但也有 pam_exec:
https://linux.die.net/man/8/pam_exec

例如类似的东西PAM 配置中的以下内容:

auth sufficient pam_exec.so expose_authtok /usr/local/bin/myscript-example

myscript-example 的内容,回显所有变量:

#!/bin/sh
read password
echo "User: $PAM_USER"
echo "Ruser: $PAM_RUSER"
echo "Rhost: $PAM_RHOST"
echo "Service: $PAM_SERVICE"
echo "TTY: $PAM_TTY"
echo "Password : $password"
exit $?

This is a very old thread, but there is also pam_exec:
https://linux.die.net/man/8/pam_exec

e.g. Something like the following in the PAM Config:

auth sufficient pam_exec.so expose_authtok /usr/local/bin/myscript-example

Contents of myscript-example, echoing all the vars out:

#!/bin/sh
read password
echo "User: $PAM_USER"
echo "Ruser: $PAM_RUSER"
echo "Rhost: $PAM_RHOST"
echo "Service: $PAM_SERVICE"
echo "TTY: $PAM_TTY"
echo "Password : $password"
exit $?
请你别敷衍 2024-12-16 08:56:01

您是否阅读过 Linux-PAM 应用程序开发人员指南?在 RHEL 类型的系统上,该文件位于 /usr/share/doc/pam-devel-/Linux-PAM_ADG.txt 中,或者您可以在 在各个地方在线

查看获取 PAM 项部分,其中记录了 pam_get_item() 函数。您可以使用 PAM_AUTH_TOK 常量请求密码:

PAM_AUTHTOK

身份验证令牌(通常是密码)。该标记应被忽略
除 pam_sm_authenticate(3) 和 pam_sm_chauthtok 之外的所有模块函数
(3)。在前一个函数中,它用于传递最新的
从一个堆叠模块到另一个堆叠模块的身份验证令牌。在后者中
函数令牌用于其他目的。它包含当前
主动身份验证令牌。

Have you read the Linux-PAM Application Developer's Guide? On a RHEL-type system this will be in /usr/share/doc/pam-devel-<version>/Linux-PAM_ADG.txt, or you can find it online at online at various places.

Take a look at the Getting PAM items section, which documents the pam_get_item() function. You can request the password with the PAM_AUTH_TOK constant:

PAM_AUTHTOK

The authentication token (often a password). This token should be ignored
by all module functions besides pam_sm_authenticate(3) and pam_sm_chauthtok
(3). In the former function it is used to pass the most recent
authentication token from one stacked module to another. In the latter
function the token is used for another purpose. It contains the currently
active authentication token.
落花浅忆 2024-12-16 08:56:01

在调试时只打印 PAM_AUTHTOK 的内容怎么样?为了有意义地使用它,无论如何,模块之间必须有某种契约或约定。

顺便说一句:将明文密码保留在内存中并尽快从那里删除它(或者更好:在 RAM 中锁定该区域,或进行加密交换)与将该明文密码写入磁盘之间是有区别的。后者太不安全了,不要这样做。

How about just printing the contents of PAM_AUTHTOK when you're debugging? To make a meaningful use of it you must have some sort of a contract or convention between modules anyway.

By the way: there is a difference between keeping a cleartext password in memory and erasing it from there as soon as possible (or better: locking that region in RAM, or having encrypted swap), and writing that cleartext password to disk. The latter is just sooo insecure, don't do that.

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