├── .gitignore ├── images └── encrypted-email.png ├── README.md └── keybase-mail.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | keybase-mail-customized.ps1 -------------------------------------------------------------------------------- /images/encrypted-email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfoss/keybase-mail/master/images/encrypted-email.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##Keybase Mail - PowerShell Encrypted Mailer 2 | 3 | greg . foss [at] owasp . org 4 | @heinzarelli 5 | https://keybase.io/heinzarelli 6 | v0.1 -- August 2015 7 | 8 | ## [About] 9 | 10 | Keybase-Mail.ps1 is a basic PowerShell wrapper for the windows command-line version of keybase.io. This allows you to send encrypted / signed email directly from the command line. 11 | 12 | ![encrypted](/images/encrypted-email.png) 13 | 14 | Please note, this requries the Windows Command-Line version of Keybase: https://keybase.io/docs/command_line 15 | 16 | ## [How To] 17 | 18 | Install Invoke-KeybaseMail Module (note the two dots!). Once this is installed, you can simply call the function (Invoke-KeybaseMail)... 19 | 20 | PS C:\> . .\keybase-mail.ps1 21 | 22 | Send Encrypted Email 23 | 24 | PS C:\> Invoke-KeybaseMail -encrypt [recipient's keybase user name] -from from@address.com -to to@address.com -smtpServer 127.0.0.1 -subject "test" -message "test" 25 | 26 | Send Signed and Encrypted Email 27 | 28 | PS C:\> Invoke-KeybaseMail -encrypt [recipient's keybase user name] -sign -from from@address.com -to to@address.com -smtpServer 127.0.0.1 -subject "test" -message "test" 29 | 30 | Send Clear-Signed Email 31 | 32 | PS C:\> Invoke-KeybaseMail -clearSign -from from@address.com -to to@address.com -smtpServer 127.0.0.1 -subject "test" -message "test" 33 | 34 | ## [Parameter Breakdown] 35 | 36 | You may want to hard-code most of these parameters, so you can send mail easily without having to supply these parameters at run-time. 37 | 38 | Keybase Commands: 39 | 40 | -encrypt : Encrypt the message using Keybase. You will need to supply the recipient's Keybase username 41 | -sign : Sign the message using Keybase 42 | -clearSign : Send the message in clear-text with an accompanied PGP signature via Keybase 43 | -file : Attach an encrypted file to the email (coming soon...) 44 | 45 | Email Commands: 46 | 47 | -smtpServer : Sets the remote SMTP Server that will be used to forward reports 48 | -to : Defines the email recipient. Multiple recipients can be separated by commas 49 | -from : Defines the email sender 50 | -subject : Define the email subject 51 | -message : Message body 52 | 53 | ## [License] 54 | 55 | Copyright (c) 2015, Greg Foss 56 | All rights reserved. 57 | 58 | Redistribution and use in source and binary forms, with or without 59 | modification, are permitted provided that the following conditions are met: 60 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 61 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 62 | * Neither the name of Greg Foss, LogRhythm, LogRhythm Labs, nor the names of any of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 63 | * This script is not 'forensically sound' as it will write to the target host. Please keep this in mind. 64 | 65 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 66 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 67 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 68 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 69 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 70 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 71 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 72 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 73 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 74 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /keybase-mail.ps1: -------------------------------------------------------------------------------- 1 | 2 | #==========================================# 3 | # Keybase Encrypted Mailer # 4 | # greg . foss [at] owasp . org # 5 | # https://keybase.io/heinzarelli # 6 | # v0.1 -- August 2015 # 7 | #==========================================# 8 | 9 | <# 10 | Requires Keybase Command Line for Windows 11 | https://keybase.io/docs/command_line 12 | 13 | .NAME 14 | Invoke-KeybaseMail 15 | 16 | .SYNOPSIS 17 | PowerShell Keybase Encrypted Mailer 18 | 19 | .DESCRIPTION 20 | A simple script that takes the existing Keybase Windows Command Line parameters and utilizes them to send encrypted/signed mail directly. 21 | 22 | .INSTALL 23 | Install Invoke-KeybaseMail Module (note the two dots!). Once this is installed, you can simply call the function. 24 | PS C:\> . .\keybase-mail.ps1 25 | 26 | .EXAMPLE 27 | Send Emcrypted Email 28 | PS C:\> Invoke-KeybaseMail -encrypt [recipient's keybase user name] -from from@address.com -to to@address.com -smtpServer 127.0.0.1 -subject "test" -message "test" 29 | 30 | .EXAMPLE 31 | Send Signed and Encrypted Email 32 | PS C:\> Invoke-KeybaseMail -encrypt [recipient's keybase user name] -sign -from from@address.com -to to@address.com -smtpServer 127.0.0.1 -subject "test" -message "test" 33 | 34 | .EXAMPLE 35 | Send Clear-Signed Email 36 | PS C:\> Invoke-KeybaseMail -clearSign -from from@address.com -to to@address.com -smtpServer 127.0.0.1 -subject "test" -message "test" 37 | 38 | .EXAMPLE 39 | Attach a file 40 | Coming soon... 41 | 42 | .NOTES 43 | You may want to hard-code most of these parameters, so you can send mail easily without having to supply these parameters at run-time. 44 | #> 45 | 46 | Function Invoke-KeybaseMail { 47 | 48 | [CmdLetBinding()] 49 | param( 50 | [Parameter(Mandatory=$false,Position=0)] 51 | [string]$to, 52 | 53 | [Parameter(Mandatory=$false,Position=1)] 54 | [string]$from, 55 | 56 | [Parameter(Mandatory=$false,Position=2)] 57 | [string]$smtpServer, 58 | 59 | [Parameter(Mandatory=$false,Position=3)] 60 | [string]$subject, 61 | 62 | [Parameter(Mandatory=$false,Position=4)] 63 | [string]$message, 64 | 65 | [Parameter(Mandatory=$false,Position=5)] 66 | [string]$encrypt, # enter the recipient's keybase username 67 | 68 | [Parameter(Mandatory=$false,Position=6)] 69 | [switch]$sign = $false, 70 | 71 | [Parameter(Mandatory=$false,Position=7)] 72 | [switch]$clearSign = $false, 73 | 74 | [Parameter(Mandatory=$false,Position=8)] 75 | [string]$file 76 | ) 77 | 78 | $ErrorActionPreference= 'silentlycontinue' 79 | 80 | #------------------------------ 81 | # Build Message 82 | #------------------------------ 83 | 84 | if ( $encrypt ) { 85 | if ( $sign ) { 86 | $encryptedMessage = keybase encrypt $encrypt -s -m @" 87 | $message 88 | "@ 89 | } Else { 90 | $encryptedMessage = keybase encrypt $encrypt -m @" 91 | $message 92 | "@ 93 | } 94 | } Elseif ( $clearSign ) { 95 | $encryptedMessage = keybase sign --clearsign -m @" 96 | $message
97 | "@ 98 | } ElseIf ( $sign) { 99 | $encryptedMessage = keybase sign -m @" 100 | $message 101 | "@ 102 | } Else { 103 | Write-Host "" 104 | Write-Host "Please specify how you'd like to encrypt and/or sign the message" 105 | } 106 | $encryptedMessageHTML = $encryptedMessage | foreach {$_ + "
"} 107 | 108 | #------------------------------ 109 | # Send Email 110 | #------------------------------ 111 | 112 | function sendEmail { 113 | $msg = New-Object System.Net.Mail.MailMessage 114 | $smtp = New-Object System.Net.Mail.SMTPClient($smtpServer) 115 | if ( $file ) { $attachment = New-Object Net.Mail.Attachment($file) } 116 | $msg.From = $from 117 | $msg.To.Add($to) 118 | $msg.Subject = $subject 119 | $msg.Body = @" 120 | 121 |

122 | $encryptedMessageHTML 123 |

124 | 125 | "@ 126 | $msg.IsBodyHTML = $true 127 | if ( $file ) { $msg.Attachments.Add($attachment) } 128 | $smtp.Send($msg) 129 | } 130 | Write-Host "" 131 | If ( $encrypt ) { Write-Host " Sending encrypted email using SMTP Server : $smtpServer" } 132 | ElseIf ( $clearSign ) { Write-Host " Sending signed email using SMTP Server: $smtpServer" } 133 | Else { Write-Host " Sending email using SMTP Server: $smtpServer" } 134 | sendEmail 135 | Write-Host " Message From : $from" 136 | Write-Host " Message To : $to" 137 | Write-Host " Subject : $subject" 138 | Write-Host "" 139 | $encryptedMessage 140 | } --------------------------------------------------------------------------------