如何在没有 sudo 的情况下获取 ldap 用户列表?

yuk*_*say 6 linux users ssh ldap

我对我想知道用户列表的服务器具有非 sudo ssh 访问权限,我认为该服务器正在使用 ldap,因为:

-bash-4.2$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd: files ldap
group: files ldap
shadow: files ldap

hosts: files dns
networks: files

protocols: db files
services: db files
ethers: db files
rpc: db files

netgroup: nis
Run Code Online (Sandbox Code Playgroud)

但:

-bash-4.2$ cd /etc/sssd/
-bash: cd: /etc/sssd/: No such file or directory
Run Code Online (Sandbox Code Playgroud)

请注意两者都没有/etc/passwdls -lsa /vargetent passwd没有给出我想要的列表(它们甚至不包括我自己的用户名)

那么,有没有人知道如何获取该服务器的用户名和 ID 列表?

-bash-4.2$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 7.11 (wheezy)
Release:    7.11
Codename:   wheezy
Run Code Online (Sandbox Code Playgroud)

Sté*_*las 7

很可能 ldap 配置不允许枚举。

如果您知道用户 ID 的范围,您可以尝试通过查询每个可能的用户 ID 来获取用户列表:

getent passwd {0..65535}
Run Code Online (Sandbox Code Playgroud)

这里假设一个 shell 支持{x..y}大括号扩展的形式(zsh、bash、ksh93、tcsh、yash -o braceexpand)。

请注意,在 Linux 上,uid 不再限制为 16 位,并且一些基于 Microsoft AD 或 samba 的目录服务器至少经常使用大于 65535 的值。但是查询{0..2147483647}将是不可能的。

您的网络管理员可能不会喜欢这样,因为这意味着要对目录服务器进行大量 LDAP 查询。

需要注意的是,因为主键passwd数据库的用户,而不是ID,有可能是为每个用户名不止一个ID,一个getent passwd <id>只返回一个条目,所以你可能会丢失一些用户。

如果用户通常在其主要组旁边至少有一个组,则获取用户列表的一种方法可能是使用相同的方法查询组列表并查看其成员:

getent group {0..65535} | cut -d: -f4 | tr , '\n' | sort -u
Run Code Online (Sandbox Code Playgroud)

这里sss没有使用。你有sss而不是ldapnsswitch.conf.

那将是libnss-ldap(或者可能是 libnss-ldapd,检查dpkg -l | grep ldap)处理ldap. 配置是可能的/etc/libnss-ldap.conf/etc/ldap.conf/etc/ldap/ldap.conf

如果您可以阅读这些内容,那么您将找到服务器名称和用户在目录树中的位置的详细信息,并且您可以使用它ldapsearch来获取相关信息(前提是您被授予访问权限)。