-
Notifications
You must be signed in to change notification settings - Fork 39
/
mailwithtor
executable file
·97 lines (82 loc) · 3.67 KB
/
mailwithtor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
###############################################################################
#
# mailwithtor
# -----------
# A simple socat script to start a local SOCKS4a server to connect msmtp and
# Tor.
#
# Usage:
# $ ./mailwithtor &
# $ mutt
#
# Note: This uses Tor between you and your mailserver. This means:
#
# A local passive observer will see that you're using Tor, and the email
# recipient will see that the email came from your email account at your
# mailserver.
#
# If your mailserver is crappily configured, and include an
# "X-Originating-IP" header or something similar, then this will obscure
# your real IP.
#
# Pretty much the only purpose of this script is to hide from passive
# observers on your local network that you are connecting to a certain
# mailserver.
#
# @author Isis Agora Lovecruft, 0xa3adb67a2cdb8b35
# @date 13 May 2012
# @version 0.0.3
#
###############################################################################
## Directory where your mailconfigs are stored:
MAILRC=$HOME/.mailrc
## Set this to your Tor SocksPort:
SOCKSPORT=9050
## Set these to the IP address (or FQDN) and port of your mailserver:
MAILSERVER_FQDN="mailserver.com"
MAILSERVER_PORT=465
## The "Account" stanza in your msmtp config that you wish to use:
MSMTP_ACCOUNT="default"
## YOU SHOULDN'T NEED TO CHANGE ANY OF THE FOLLOWING VARIABLES:
##----------------------------------------------------------------
LOG_FILE="${MAILRC}/mailwithtor.log"
LOCK_FILE="${MAILRC}/mailwithtor-lockfile"
## Port for socat to pipe incoming connections to its own SOCKS server:
SOCAT_LISTEN_PORT=2525
## Read the private settings file to override previous variables:
test -r "${MAILRC}/mailwithtor.private" && source ${MAILRC}/mailwithtor.private
# MAILWITHTORPID=$(pgrep -u "$USER" mailwithtor)
#
# if test -z "$MAILWITHTORPID" ; then
# if test -e "$HOME/.mailrc/$LOCK_FILE" ; then
# sudo rm -f $HOME/.mailrc/$LOCK_FILE &> $HOME/.mailrc/$LOG_FILE
# fi
# else
# while [[ "$MAILWITHTORPID" != "" ]] ; do
# sudo kill -9 "$MAILWITHTORPID" &> $HOME/.mailrc/$LOG_FILE
# done
# if test -f "$HOME/.mailrc/$LOCK_FILE" ; then
# sudo rm -f $HOME/.mailrc/$LOCK_FILE &> $HOME/.mailrc/$LOG_FILE
# fi
# fi
## USING BEFORE STARTING MUTT (least buggiest):
## --------------------------------------------
## If you're calling this from commandline before starting mutt, uncomment the
## following line and use like so:
## $ ./mailwithtor &
## $ mutt
sudo socat -d -d -d -lu -L $MAILRC/$LOCK_FILE -lf $MAILRC/$LOG_FILE TCP4-LISTEN:$SOCAT_LISTEN_PORT,fork SOCKS4A:localhost:$MAILSERVER_FQDN:$MAILSERVER_PORT,socksport=$SOCKSPORT,socksuser=""
## If you're calling this from commandline before starting mutt, and you also
## wish to use SSL to connect to the server, uncomment the next line instead
## and call with "$ mailwithtor &":
##
## NOTE: Buggy. Sometimes fails.
#sudo socat -d -d -d -lu -L $HOME/.mailrc/$LOCK_FILE -lf $HOME/.mailrc/$LOG_FILE OPENSSL-LISTEN:2525,method=TLSv1,verify=1,cafile=$HOME/.mailrc/CA/AddTrust_External_Root.pem,fork SOCK4a:localhost:$MAILSERVER_FQDN:$MAILSERVER_PORT,socksport=$SOCKSPORT,socksuser=""
## If you're setting "set sendmail='$HOME/path/to/mailwithtor'", then
## uncomment the following lines:
##
## NOTE: This is BROKEN. Specifically the getting-the-passphrase-from-the-sudo-
## prompt part, from inside mutt.
#sudo %?p?--passphrase-fd 0? socat -d -d -d -lu -L ${LOCK_FILE} -lf ${LOG_FILE} TCP4-LISTEN:$SOCAT_LISTEN_PORT,fork SOCKS4A:localhost:$MAILSERVER_FQDN:$MAILSERVER_PORT,socksport=$SOCKSPORT,socksuser="" & /usr/bin/msmtp -a $MSMTP_ACCOUNT
#/usr/bin/msmtp -a default $1 $2 $3 $4 $5 $6 $7 $8