package com.tylerstonge.honeypot.reporter import akka.actor.{Actor, Props} import akka.event.{Logging, LoggingAdapter} import scalaj.http.Http import com.tylerstonge.honeypot.messages.{MFoundFile, MFoundPassword, MFoundUsername, MNewConnection} object DiscordReporter { def props(webhook: String): Props = Props(new DiscordReporter(webhook)) } class DiscordReporter(webhook: String) extends Actor { val log: LoggingAdapter = Logging(context.system, this) context.system.eventStream.subscribe(self, classOf[MNewConnection]) context.system.eventStream.subscribe(self, classOf[MFoundUsername]) context.system.eventStream.subscribe(self, classOf[MFoundPassword]) context.system.eventStream.subscribe(self, classOf[MFoundFile]) override def postStop(): Unit = { super.postStop() } override def receive: Receive = { case msg: MNewConnection => log.debug(">> DISCORD REPORTER (MNewConnection) >> :: {}", msg.ip) Http(webhook).postData(formatMessage("attacker detected @ " + msg.ip)).header("content-type", "application/json").asString case msg: MFoundUsername => log.debug(">> DISCORD REPORTER >> (MFoundUsername) :: {}", msg.username) Http(webhook).postData(formatMessage("attacker identified as " + msg.username)).header("content-type", "application/json").asString case msg: MFoundPassword => log.debug(">> DISCORD REPORTER (MFoundPassword) >> :: {}", msg.password) Http(webhook).postData(formatMessage("attacker password is " + msg.password)).header("content-type", "application/json").asString case msg: MFoundFile => log.debug(">> DISCORD REPORTER (MFoundFile) >> :: {}", msg.filename) Http(webhook).postData(formatMessage("attacker deposited a file called " + msg.filename)).header("content-type", "application/json").asString } def formatMessage(msg: String): String = { """{ "username": "phreak", "content": "%s" }""".format(msg) } }