From 747b6af76b23650756811d896bf76b4331419784 Mon Sep 17 00:00:00 2001 From: "Tyler St. Onge" Date: Sat, 25 Jul 2020 22:38:14 -0400 Subject: refine ftp component and add configuration capabilities --- .../com/tylerstonge/honeypot/ftp/FtpHandler.scala | 29 ++++++++++++++-------- .../com/tylerstonge/honeypot/ftp/FtpListener.scala | 6 ++--- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src/main/scala/com/tylerstonge/honeypot/ftp') diff --git a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala index 8a55396..48db3f5 100644 --- a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala +++ b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala @@ -6,22 +6,31 @@ import akka.io.Tcp.{PeerClosed, Received, Write} import akka.util.ByteString class FtpHandler extends Actor { + val log: LoggingAdapter = Logging(context.system, this) override def receive: Receive = { - case Received(data) => - log.info(">> {}", data.utf8String) - sender() ! Write(ByteString.apply(parse(data.utf8String))) + case Received(data) => sender() ! Write(ByteString.apply(parse(sanitize(data)))) case PeerClosed => - log.info("closing connection") + log.info("peer closed connection") context.stop(self) } - def parse(msg: String): String = msg match { - case "USER anonymous\n" => "331 Please specify password.\n" - case "PASS password\n" => "230 Login successful.\n" - case "PWD\n" => "257 \"/\" is the current directory\n" - case "QUIT\n" => "221 Goodbye.\n" - case _ => "200 sure\n" + def parse(msg: Array[String]): String = msg(0) match { + case "user" => + log.info("attempted login with username: {}", msg(1)) + "331 Please specify password.\n" + case "pass" => + log.info("attempted login with password: {}", msg(1)) + "230 Login successful.\n" + case "pwd" => "257 \"/\" is the current directory\n" + case "quit" => "221 Goodbye.\n" + case _ => + log.info("unsupported command received: {}", msg.mkString(" ")) + "451 Requested action aborted. Local error in processing.\n" + } + + def sanitize(data: ByteString): Array[String] = { + data.utf8String.trim.toLowerCase().split(" ") } } diff --git a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala index 3e6606a..b988ba3 100644 --- a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala +++ b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala @@ -8,16 +8,16 @@ import akka.io.Tcp._ import akka.io.{IO, Tcp} import akka.util.ByteString -class FtpListener extends Actor { +class FtpListener (port: Int) extends Actor { val log: LoggingAdapter = Logging(context.system, this) - IO(Tcp)(context.system) ! Bind(self, new InetSocketAddress("localhost", 2121)) + IO(Tcp)(context.system) ! Bind(self, new InetSocketAddress("localhost", port)) override def receive: Receive = { case Bound(localAddress) => log.info("listening on {}", localAddress) case CommandFailed(_: Bind) => context.stop(self) - case Connected(remote, local) => + case Connected => val handler = context.actorOf(Props[FtpHandler]) val connection = sender() connection ! Register(handler) -- cgit v1.1