# Example of SMTP multistage payload
# Copyright (C) 2009  Acri Emanuele <crossbower@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Callback function
def callback(count, h_flags, h_payload):

    global flags
    global window
    global action
    global payload

    # Ack SMTP server banner...
    if count == 0:
        flags   = ack
        window  = 1024

    # HELO request
    if count == 1:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "HELO myserver.com\r\n"

    # Ack...
    if count == 2:
        flags   = ack
        window  = 1024

    # MAIL FROM request
    if count == 3:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "MAIL FROM: <mail@domain.ext>\r\n"

    # Ack...
    if count == 4:
        flags   = ack
        window  = 1024

    # RCPT TO request
    if count == 5:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "RCPT TO: <mail@otherdomain.ext>\r\n"

    # Ack...
    if count == 6:
        flags   = ack
        window  = 1024

    # DATA request
    if count == 7:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "DATA\r\n"

    # Ack...
    if count == 8:
        flags   = ack
        window  = 1024

    # Enter subject
    if count == 9:
        flags   = ack | push
        window  = 1024
        payload = "Subject: foo\r\n\r\n" # enter twice (RFC 882)...

    # Message body
    if count == 10:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "Hello!\r\nThis is a test...\r\n\r\n.\r\n"
        # close with a single "." on a line on it's own.

    # Ack...
    if count == 11:
        flags   = ack
        window  = 1024

    # Quit the connection
    if count == 12:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "QUIT\r\n"

    # Close the connection...
    if count > 12:
        flags   = rst
        action  = act_wait


