diff options
author | Tyler St. Onge <tylertstonge@gmail.com> | 2020-11-05 15:16:00 -0500 |
---|---|---|
committer | Tyler St. Onge <tylertstonge@gmail.com> | 2020-11-05 15:16:00 -0500 |
commit | a7ba75b1b6ca4faa392cb3e5655fc784687e02ac (patch) | |
tree | 2fbb86557038b616513e1e2561d4e7ad7ae30d0e /src/main/scala/com/tylerstonge/honeypot/ftp | |
parent | 07abec1108c69cf1f85ae039066e90f14eaca78a (diff) |
added discord reporter
Diffstat (limited to 'src/main/scala/com/tylerstonge/honeypot/ftp')
3 files changed, 19 insertions, 11 deletions
diff --git a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpFileReceiver.scala b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpFileReceiver.scala index bf74e8b..aee40cb 100644 --- a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpFileReceiver.scala +++ b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpFileReceiver.scala @@ -2,7 +2,7 @@ package com.tylerstonge.honeypot.ftp import java.io.File
import java.net.InetSocketAddress
-import java.nio.file.{Files, Paths, StandardOpenOption}
+import java.nio.file.{Files, StandardOpenOption}
import java.util.UUID
import akka.actor.{Actor, ActorRef, Props}
@@ -10,7 +10,7 @@ import akka.event.{Logging, LoggingAdapter} import akka.io.Tcp._
import akka.io.{IO, Tcp}
import akka.util.{ByteString, ByteStringBuilder}
-import com.tylerstonge.honeypot.messages.{MFoundFile, MFoundPassword}
+import com.tylerstonge.honeypot.messages.MFoundFile
object FtpFileReceiver {
@@ -19,11 +19,11 @@ object FtpFileReceiver { class FtpFileReceiver(port: Int, controller: ActorRef) extends Actor {
- val path = "/home/dropkick/honeypot/"
+ val path = "/tmp/files/"
val log: LoggingAdapter = Logging(context.system, this)
IO(Tcp)(context.system) ! Bind(self, new InetSocketAddress("127.0.0.1", port))
val fileData: ByteStringBuilder = ByteString.newBuilder
- val name: String = UUID.randomUUID().toString
+ var name: String = UUID.randomUUID().toString
override def postStop {
log.debug("shutting down")
@@ -38,19 +38,23 @@ class FtpFileReceiver(port: Int, controller: ActorRef) extends Actor { connection ! Register(self)
context.become {
case Received(data) =>
- log.info("read {} bytes", data.length)
+ log.debug("read {} bytes", data.length)
fileData.addAll(data)
case PeerClosed =>
log.debug("peer closed connection, writing file to disk")
- val out = Files.newByteChannel(new File(this.path + "/" + this.name).toPath, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)
- context.system.eventStream.publish(MFoundFile(this.path + "/" + this.name))
+ val out = Files.newByteChannel(new File(this.path + this.name).toPath, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)
out.write(fileData.result().toByteBuffer)
out.close()
controller.tell(Write(ByteString.apply("226 File transferred.\n")), context.parent)
+ context.system.eventStream.publish(MFoundFile(this.path + this.name))
context.stop(self)
+ case SetName(name) =>
+ log.info("file accepted as {}", name)
+ this.name = name
case msg@_ => log.warning("unknown message: {}", msg)
}
}
}
-case class Ready()
\ No newline at end of file +case class Ready()
+case class SetName(name: String)
\ No newline at end of file diff --git a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala index b7b6f03..313bf64 100644 --- a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala +++ b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala @@ -15,6 +15,7 @@ object FtpHandler { class FtpHandler(client: ActorRef) extends Actor { val log: LoggingAdapter = Logging(context.system, this) + var fileReceiver: ActorRef = ActorRef.noSender override def receive: Receive = { case Received(data) => client ! Write(ByteString.apply(parse(sanitize(data)))) @@ -39,11 +40,12 @@ class FtpHandler(client: ActorRef) extends Actor { val r = new Random() val p1 = r.nextInt(200) val p2 = r.nextInt(200) - context.actorOf(FtpFileReceiver.props(p1 * 256 + p2, client), name = "passive-connection") + fileReceiver = context.actorOf(FtpFileReceiver.props(p1 * 256 + p2, client), name = "passive-connection") Thread.sleep(256) "227 entering passive mode (127,0,0,1," + p1 + "," + p2 + ")\n" case "stor" => log.debug("stor: {}", msg(1)) + fileReceiver ! SetName(msg(1)) "150 File status okay; about to open data connection.\n" case _ => log.debug("unsupported command received: {}", msg.mkString(" ")) diff --git a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala index b7ce337..2f581bd 100644 --- a/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala +++ b/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala @@ -7,6 +7,7 @@ import akka.event.{Logging, LoggingAdapter} import akka.io.Tcp._ import akka.io.{IO, Tcp} import akka.util.ByteString +import com.tylerstonge.honeypot.messages.MNewConnection object FtpListener { def props(port: Int): Props = Props(new FtpListener(port)) @@ -15,15 +16,16 @@ object FtpListener { class FtpListener(port: Int) extends Actor { val log: LoggingAdapter = Logging(context.system, this) - IO(Tcp)(context.system) ! Bind(self, new InetSocketAddress("localhost", port)) + IO(Tcp)(context.system) ! Bind(self, new InetSocketAddress("0.0.0.0", port)) override def receive: Receive = { case Bound(localAddress) => log.info("listening on {}", localAddress) case CommandFailed(_: Bind) => context.stop(self) - case Connected(_, _) => + case Connected(remote, _) => val connection = sender() val handler = context.actorOf(FtpHandler.props(connection), name = "handler") + context.system.eventStream.publish(MNewConnection(remote.getHostString)) connection ! Register(handler) connection ! Write(ByteString.apply("220 (vulnFTPd 2.0.1)\n")) } |