13

通常在大型网络中,计算机需要在经过身份验证的代理后面运行 - 任何与外部世界的连接都需要用户名/密码,这通常是用户用于登录电子邮件、工作站等的密码。

这意味着必须将网络密码apt.conf以及通常定义http_proxy, ftp_proxyhttps_proxy环境变量放入文件中~/.profile

我意识到apt.conf你可以设置chmod 600(在 Ubuntu/Debian 上不是默认设置!)但在我们的系统上有些人需要 root priveleges 。

我也意识到从技术上来说,从具有 root 访问权限的人那里保护密码是不可能的,但是我想知道是否有一种方法可以隐藏密码以防止意外发现。Windows 以管理员身份与用户一起操作,但以某种方式存储网络密码(可能以某种方式隐藏在注册表深处),因此在典型使用中您不会以纯文本形式偶然发现它

我从前几天才问起,在比较跨系统的配置文件时,我完全是偶然发现了别人的密码。

@monjardin - 恐怕公钥身份验证不是这个网络上的替代方案。另外,我怀疑大多数命令行工具都支持它。

@Neall - 我不介意其他用户可以访问网络,他们可以使用我的凭据访问网络,我只是不希望他们以纯文本形式出现在我的密码中。

4

9 回答 9

8

使用以下方法,您无需以纯文本格式保存代理密码。只要您需要 http/https/ftp 访问权限,您只需以交互方式输入密码:

  • 使用 openssl 将您的纯文本代理密码加密到文件中,例如 AES256 加密:

openssl enc -aes-256-cbc -in pw.txt -out pw.bin

  • 使用(不同的)密码来保护编码文件
  • 删除纯文本 pw.txt
  • 在例如 ~/.alias 中创建一个别名来设置您的 http_proxy/https_proxy/ftp_proxy 环境变量(为 $USER/proxy/$PORT 设置适当的值)

别名 myproxy='PW=`openssl aes-256-cbc -d -in pw.bin`; PROXY="http://$USER:$PW@proxy:$PORT"; 导出 http_proxy=$PROXY; 导出 https_proxy=$PROXY; 导出 ftp_proxy=$PROXY'

  • 您应该将此文件源到您的正常 shell 环境中(在某些系统上,这是自动完成的)
  • 键入“myproxy”并输入您用于加密文件的 openssl 密码
  • 完毕。

注意:在 shell 会话期间,密码在用户环境中可用(并且可读)。如果您想在使用后从环境中清除它,您可以使用另一个别名:

别名 clearproxy='导出 http_proxy=; 导出 https_proxy=; 导出 ftp_proxy='

于 2013-01-08T13:18:32.083 回答
6

我做了一个修改后的解决方案:

编辑/etc/bash.bashrc并添加以下行:

alias myproxy='read -p "Username: " USER;read -s -p "Password: " PW
PROXY="$USER:$PW@proxy.com:80";
export http_proxy=http://$PROXY;export Proxy=$http_proxy;export https_proxy=https://$PROXY;export ftp_proxy=ftp://$PROXY'

从下次登录输入myproxy并输入您的用户/密码组合!现在与sudo -E

-E, --preserve-env 向安全策略指示用户希望保留他们现有的环境变量。

例如sudo -E apt-get update

备注:代理设置仅在 shell 会话期间有效

于 2017-05-31T13:38:18.313 回答
3

有很多方法可以隐藏密码:您可以以 rot13 格式或 BASE64 存储凭据,或者使用与 CVS 相同的密码加扰算法。真正的诀窍是让您的应用程序了解加扰算法。

对于环境变量,~/.profile您可以将它们编码存储,然后在设置变量之前对其进行解码,例如:

encodedcreds="sbbone:cnffjbeq"
creds=`echo "$encodedcreds" | tr n-za-mN-ZA-M a-zA-Z`

这将设置credsfoobar:password,然后您可以将其嵌入http_proxy等。

我假设您知道这一点,但需要重复一遍:这不会增加任何安全性。它只是防止无意中看到另一个用户的密码。

于 2008-08-25T21:06:27.540 回答
2

Prefer applications that integrate with Gnome Keyring. Another possibility is to use an SSH tunnel to an external machine and run apps through that. Take a look at the -D option for creating a local SOCKS proxy interface, rather than single-serving -L forwards.

于 2008-08-21T14:57:38.333 回答
1

Unless the specific tools you are using allow an obfuscated format, or you can create some sort of workflow to go from obfuscated to plain on demand, you are probably out of luck.

One thing I've seen in cases like this is creating per-server, per-user, or per-server/per-user dedicated credentials that only have access to the proxy from a specific IP. It doesn't solve your core obfuscation problem but it mitigates the effects of someone seeing the password because it's worth so little.

Regarding the latter option, we came up with a "reverse crypt" password encoding at work that we use for stuff like this. It's only obfuscation because all the data needed to decode the pw is stored in the encoded string, but it prevents people from accidentally seeing passwords in plain text. So you might, for instance, store one of the above passwords in this format, and then write a wrapper for apt that builds apt.conf dynamically, calls the real apt, and at exit deletes apt.conf. You still end up with the pw in plaintext for a little while, but it minimizes the window.

于 2008-08-21T15:13:33.817 回答
0

只要这三件事都是真的,你就不走运了:

  1. 服务器需要网络访问
  2. 用户需要绝对控制服务器(root)
  3. 您不希望用户拥有服务器的 Web 访问权限

如果您无法移除#2 或#3,您唯一的选择就是移除#1。设置托管所有软件更新的内部服务器。保持对其他用户的锁定,并且不允许其他服务器访问 Web。

您尝试做的任何其他事情都只是在自欺欺人。

于 2008-08-21T12:26:08.617 回答
0

公钥身份验证对您来说是一个有效的替代方案吗?

于 2008-08-20T22:31:32.493 回答
0

我们通过不要求 rpm、apt 或其他类似更新(病毒数据库、Windows 等)上的代理密码解决了这个问题。这是要添加到代理的已知存储库的小白名单。

于 2008-09-17T14:57:09.513 回答
0

我想您可以创建一个本地代理,通过它指向这些工具,然后让本地代理以交互方式向用户询问它将应用的外部代理密码。它可以选择在模糊的内部存储中记住这一点几分钟。

一个明显的攻击媒介是特权用户修改此本地代理以使用输入的密码执行其他操作(因为他们可以使用其他任何东西,例如请求它的电子邮件客户端或窗口系统本身),但至少你' d 避免不慎观看。

于 2010-11-18T21:01:13.237 回答