Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Outlook constraint #1

Open
n3tsurge opened this issue Nov 9, 2017 · 7 comments
Open

Remove Outlook constraint #1

n3tsurge opened this issue Nov 9, 2017 · 7 comments

Comments

@n3tsurge
Copy link

n3tsurge commented Nov 9, 2017

It would be more efficient to use EWS to periodically poll your phishing mailbox and send the reply than to install an Outlook client and leave it open on a server.

# Build a connection the Exchange Server
        $ExchangeService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
        $ExchangeService.Credentials = New-Object System.Net.NetworkCredential("DOMAIN\phishing", "<credentials>")
        $ExchangeService.Url = "https://mymailserver/EWS/Exchange.asmx"

        # Find the Inbox for the Phishing Mailbox
        $folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$Mailbox)     
        $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ExchangeService,$folderid)
        
        # Define a filter to only grab unread items
        $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10)
        $SearchFilter = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $false)
        
        # Search the Inbox for unread items
        $Items = $Inbox.FindItems($searchFilter, $view)
        $itemCount = $Items.TotalCount
@gfoss
Copy link
Contributor

gfoss commented Nov 10, 2017

This is great, thanks! I'll take a look over the next few days.

@n3tsurge
Copy link
Author

No problem, I saw the talk on this in Vail and was interested to see how it worked under the hood, went out and started experimenting before this was released to try and self replicate and came away with these shortcuts.

Here is a snippet for sending the response to the reporting user using EWS in case you are interested in that as well.

Just create the HTML formatted email. Make sure you reference any pictures in the HTML using their cid, and they have to be added as an inline attachment (see the Send-ThankYou snippet)

<img width=220 height=121 style='width:2.2916in;height:1.2604in' id="Picture_x0020_2" src="cid:logo.png" alt="cid:logo.png">

Function to send Thank You E-mail

function Send-ThankYou {
    Param(
        [string]$MailTo,
        [Microsoft.Exchange.WebServices.Data.ExchangeService]$Service,
        [switch]$Error
    )

    $email = New-Object Microsoft.Exchange.WebServices.Data.EmailMessage($Service)

    $email.Subject = "Thank you for your Phishing submission"
    $email.body = Get-Content $scriptPath"\Thank You.html" -Raw
    [void]$email.ToRecipients.Add($MailTo)
    [void]$email.Attachments.AddFileAttachment("logo.png", $scriptPath+"\logo.png")
    $email.Attachments[0].IsInline = $true
    $email.Attachments[0].ContentId = "logo.png"

    $email.SendAndSaveCopy()

}

@gfoss
Copy link
Contributor

gfoss commented Nov 29, 2017

Thanks!

I actually have the response aspect of the script configured to use the server, via the O365 phishing report account. I'm looking at adapting your scripts into the next piece, which performs analysis of the email that was submitted. If I can get that figured out, there will be no need to leave Outlook open. :-)

@hbteibetLZ
Copy link

Hello @gfoss have you had a chance to look into doing everything via EWS API instead of the Outlook client?

@n3tsurge
Copy link
Author

Got a sample here that I was toying with that you can pick apart and use that does the analysis and stuff right in the ps1 and is proxy aware. It does not do any of the LR integration.

https://github.com/krypticnetworks/smells-phishy

@gfoss
Copy link
Contributor

gfoss commented Feb 15, 2018

I have not had time to dive into this issue just yet, unfortunately. Appreciate the link to this project though - will have to dive into this and see if I can apply this non-interactive mailbox fix to PIE!

@gfoss
Copy link
Contributor

gfoss commented Mar 6, 2018

I believe that I've inadvertently fixed this problem with the following commit:

9e90ee1

I was solving a separate issue and a side-effect is that you actually have to leave Outlook closed now in order to process mail properly in the background. If you have some time, please test and let me know if the updated code works for you.

gfoss pushed a commit that referenced this issue Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants