summaryrefslogtreecommitdiff
path: root/src/main/scala/com/tylerstonge/honeypot/ftp
diff options
context:
space:
mode:
authorTyler St. Onge <tylertstonge@gmail.com>2020-07-25 22:38:14 -0400
committerTyler St. Onge <tylertstonge@gmail.com>2020-07-25 22:38:14 -0400
commit747b6af76b23650756811d896bf76b4331419784 (patch)
tree2e942c8296567cbe4d57f205f72029a62829bdda /src/main/scala/com/tylerstonge/honeypot/ftp
parent945332ca057383f258c78fd15cbc22f8b8d58a83 (diff)
refine ftp component and add configuration capabilities
Diffstat (limited to 'src/main/scala/com/tylerstonge/honeypot/ftp')
-rw-r--r--src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala29
-rw-r--r--src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala6
2 files changed, 22 insertions, 13 deletions
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)