Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignitetch
GitHub Repository: ignitetch/advphishing
Path: blob/master/PHPMailer/test/fakepopserver.sh
738 views
1
#!/usr/bin/env bash
2
3
# Fake POP3 server
4
# By Marcus Bointon <[email protected]>
5
# Copyright 2010 - 2020 Marcus Bointon
6
# Based on code by 'Frater' found at http://www.linuxquestions.org/questions/programming-9/fake-pop3-server-to-capture-pop3-passwords-933733
7
# Does not actually serve any mail, but supports commands sufficient to test POP-before SMTP
8
# Can be run directly from a shell like this:
9
# mkfifo fifo; nc -l 1100 <fifo |./fakepopserver.sh >fifo; rm fifo
10
# It will accept any user name and will return a positive response for the password 'test'
11
12
# Licensed under the GNU Lesser General Public License: http://www.gnu.org/copyleft/lesser.html
13
14
# Enable debug output
15
#set -xv
16
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
17
18
LOGFOLDER=/tmp
19
20
LOGFILE=${LOGFOLDER}/fakepop.log
21
22
LOGGING=1
23
DEBUG=1
24
TIMEOUT=60
25
26
POP_USER=
27
POP_PASSWRD=test
28
29
LINES=1
30
BREAK=0
31
32
write_log () {
33
if [ ${LINES} -eq 1 ] ; then
34
echo '---' >>${LOGFILE}
35
fi
36
let LINES+=1
37
[ ${LOGGING} = 0 ] || echo -e "`date '+%b %d %H:%M'` pop3 $*" >>${LOGFILE}
38
}
39
40
ANSWER="+OK Fake POP3 Service Ready"
41
42
while [ ${BREAK} -eq 0 ] ; do
43
echo -en "${ANSWER}\r\n"
44
45
REPLY=""
46
47
#Input appears in $REPLY
48
read -t ${TIMEOUT}
49
50
ANSWER="+OK "
51
COMMAND=""
52
ARGS=""
53
TIMEOUT=30
54
55
if [ "$REPLY" ] ; then
56
write_log "RAW input: '`echo "${REPLY}" | tr -cd '[ -~]'`'"
57
58
COMMAND="`echo "${REPLY}" | awk '{print $1}' | tr -cd '\40-\176' | tr 'a-z' 'A-Z'`"
59
ARGS="`echo "${REPLY}" | tr -cd '\40-\176' | awk '{for(i=2;i<=NF;i++){printf "%s ", $i};printf "\n"}' | sed 's/ $//'`"
60
61
write_log "Command: \"${COMMAND}\""
62
write_log "Arguments: \"${ARGS}\""
63
64
case "$COMMAND" in
65
QUIT)
66
break
67
;;
68
USER)
69
if [ -n "${ARGS}" ] ; then
70
POP_USER="${ARGS}"
71
ANSWER="+OK Please send PASS command"
72
fi
73
;;
74
AUTH)
75
ANSWER="+OK \r\n."
76
;;
77
CAPA)
78
ANSWER="+OK Capabilities include\r\nUSER\r\nCAPA\r\n."
79
;;
80
PASS)
81
if [ "${POP_PASSWRD}" == "${ARGS}" ] ; then
82
ANSWER="+OK Logged in."
83
AUTH=1
84
else
85
ANSWER="-ERR Login failed."
86
fi
87
;;
88
LIST)
89
if [ "${AUTH}" = 0 ] ; then
90
ANSWER="-ERR Not authenticated"
91
else
92
if [ -z "${ARGS}" ] ; then
93
ANSWER="+OK No messages, really\r\n."
94
else
95
ANSWER="-ERR No messages, no list, no status"
96
fi
97
fi
98
;;
99
RSET)
100
ANSWER="+OK Resetting or whatever\r\n."
101
;;
102
LAST)
103
if [ "${AUTH}" = 0 ] ; then
104
ANSWER="-ERR Not authenticated"
105
else
106
ANSWER="+OK 0"
107
fi
108
;;
109
STAT)
110
if [ "${AUTH}" = 0 ] ; then
111
ANSWER="-ERR Not authenticated"
112
else
113
ANSWER="+OK 0 0"
114
fi
115
;;
116
NOOP)
117
ANSWER="+OK Hang on, doing nothing"
118
;;
119
esac
120
else
121
echo "+OK Connection timed out"
122
break
123
fi
124
done
125
126
echo "+OK Bye!\r\n"
127
128