79 - Pentesting Finger

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

基本信息

The Finger program/service is utilized for retrieving details about computer users. Typically, the information provided includes the user’s login name, full name, and, in some cases, additional details. These extra details could encompass the office location and phone number (if available), the time the user logged in, the period of inactivity (idle time), the last instance mail was read by the user, and the contents of the user’s plan and project files.

From a pentesting perspective, Finger is still interesting because the protocol is extremely small, human-readable, and often implemented with legacy parsing logic. A daemon may disclose:

  • 当前登录用户
  • 全名 / GECOS 数据
  • 主目录、shell、最后登录时间和 TTY
  • .plan / .project 内容
  • 中继 behaviour,通过第一个主机查询第二个主机

默认端口: 79

PORT   STATE SERVICE
79/tcp open  finger

Enumeration

nc -vn <IP> 79
echo "root" | nc -vn <IP> 79
printf '\r\n' | nc -vn <IP> 79         # Null query: ask for logged-in users
printf '/W root\r\n' | nc -vn <IP> 79  # Long format, if the daemon supports it

该协议为 ASCII over TCP/79,通常以 CRLF 结尾,并且 服务器在响应后关闭 TCP 连接。实际上,一个 null query (\r\n) 通常就足以检索当前的用户列表,这也是 Nmap 的默认 finger NSE 脚本所做的。

用户枚举

finger @<Victim>       #List users
finger admin@<Victim>  #Get info of user
finger user@<Victim>   #Get info of user
finger -l user@<Victim> #Long format from common UNIX clients

或者你可以使用来自 pentestmonkeyfinger-user-enum,例如:

finger-user-enum.pl -U users.txt -t 10.0.0.1
finger-user-enum.pl -u root -t 10.0.0.1
finger-user-enum.pl -U users.txt -T ips.txt
finger-user-enum.pl -U users.txt -t 10.0.0.2 -r 10.0.0.1

关于 Finger 枚举 的重要细微差别在于,不同守护进程之间没有严格的响应格式。像 finger-user-enum 这样的工具在针对 Solaris 风格的服务时表现良好,因为有效用户和无效用户会产生不同的文本布局,但如果目标守护进程比较特殊,你可能需要手动比较 正向负向 回复并调整 regexes。

当守护进程没有像原生 Solaris/BSD 那样表现时,有用的探测项:

# Null query: enumerate currently logged-in users
printf '\r\n' | nc -vn <IP> 79

# Long format
printf '/W\r\n' | nc -vn <IP> 79
printf '/W root\r\n' | nc -vn <IP> 79

# Spray several likely accounts in one go against permissive daemons
printf 'root admin oracle mysql ftp user test\r\n' | nc -vn <IP> 79

Nmap 执行脚本(使用默认脚本)

nmap -sV -sC -p79 <IP>
nmap --script finger -p79 <IP>

Nmap 的 finger NSE 脚本是 安全的,并且只是发送一个 空查询 来恢复当前 user 列表。如果想针对 permissive daemons 进行更广泛的 username 猜测,可以考虑用自定义字典扩展该方法,或使用诸如 fat-finger.nse 的项目,这些项目在一次请求中发送多个可能的账户名并查找 username/GECOS 的匹配。

Metasploit 使用的技巧比 Nmap 更多

use auxiliary/scanner/finger/finger_users

Shodan

  • port:79 USER

命令执行

finger "|/bin/id@example.com"
finger "|/bin/ls -a /@example.com"

RFC 1288 明确允许实现针对 Finger 查询执行 用户可控程序,这就是经典的 |/bin/... 滥用来源。如今这种情况已少见,但如果你发现自定义或遗留守护进程,请仔细测试:

  • 用户名处理中的 shell 元字符
  • 在 plan/project hooks 中执行 |program
  • 将用户名传给 shell 脚本或 CGI 的后端包装器

另外记住 Windows 上的 client-side 滥用路径:finger.exe 是一个签名的 LOLBIN,能够从远程 Finger 服务器通过 TCP/79 获取任意文本,然后将该输出通过管道传给另一个进程。该技术在 post-exploitation 阶段比在 service enumeration 更相关,参见 the Linux reverse-shell page 了解 shell 传输的思路,并在模拟 attacker tradecraft 时牢记。

Finger Bounce

Use a system as a finger relay

finger user@host@victim
finger @internal@external

这不仅仅是一个实现上的怪癖:RFC 1288 定义了递归的 @hostname 转发({Q2} 查询)。如果 daemon 支持 relaying,intermediate server 会为你打开第二个 Finger 连接,并通过原始 socket 将响应返回。这意味着:

  • 你的主机可能无法直接连接到最终目标
  • 该 relay 可被用来从暴露的 Finger 服务枚举内部用户
  • finger-user-enum 原生支持此功能,可使用 -r <relay>

示例:

# Ask 10.0.0.1 to finger root on 10.0.0.2
printf 'root@10.0.0.2\r\n' | nc -vn 10.0.0.1 79

# Enumerate usernames on 10.0.0.2 through relay 10.0.0.1
finger-user-enum.pl -U users.txt -t 10.0.0.2 -r 10.0.0.1

如果 relaying 生效,将其作为一个 internal recon primitive 使用,并将 relayed output 与 public daemon 的 direct output 进行比较。不同的 formatting 或 filtering 往往能揭示 relay path 是否由单独的 backend 或 wrapper 处理。

参考资料

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks