# Example of FTP 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 FTP server banner...
    if count == 0:
        flags   = ack
        window  = 1024

    # First command
    if count == 1:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "USER root\r\n"

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

    # Second command
    if count == 3:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "PASS foo\r\n"

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

    # Request help
    if count == 5:
        flags   = ack | push
        window  = 1024
        action  = act_wait
        payload = "help\r\n"

    # Ack received help
    if count == 6:
        flags   = ack
        window  = 1024

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

    # Ack and close the connection...
    if count > 7:
        action  = act_end

