Skip to content

Commit

Permalink
Irc action (#158)
Browse files Browse the repository at this point in the history
* Added irc action

* Forgot to import pastepwn util

* Fixed typo
  • Loading branch information
Zrocket authored and d-Rickyy-b committed Nov 3, 2019
1 parent df37d7f commit fc1d1ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pastepwn/actions/__init__.py
Expand Up @@ -4,6 +4,7 @@
from .databaseaction import DatabaseAction
from .discordaction import DiscordAction
from .emailaction import EmailAction
from .ircaction import IrcAction
from .genericaction import GenericAction
from .logaction import LogAction
from .mispaction import MISPAction
Expand All @@ -22,6 +23,7 @@
"SaveJSONAction",
"TwitterAction",
"DiscordAction",
"IrcAction",
"MISPAction",
"EmailAction"
)
40 changes: 40 additions & 0 deletions pastepwn/actions/ircaction.py
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
import socket

from pastepwn.util import TemplatingEngine
from .basicaction import BasicAction


class IrcAction(BasicAction):
"""Action to send an irc message to a certain channel"""
name = "IrcAction"
irc = socket.socket()

def __init__(
self=None,
server=None,
channel=None,
port=6667,
nick="pastepwn"
):
super().__init__()

self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server = server
self.channel = channel
self.port = port
self.nick = nick

def perform(self, paste, analyzer_name=None):
"""Perform the action on the passed paste"""
if self.template is None:
text = "New paste matched by analyzer '{0}' - Link: {1}".format(analyzer_name, paste.full_url)
else:
text = TemplatingEngine.fill_template(paste, analyzer_name, template_string=self.template)

self.ircsock.connect((self.server, self.port))
self.ircsock.send(bytes("USER " + self.nick + " " + self.nick + " " + self.nick + "n", "UTF-8"))
self.ircsock.send(bytes("NICK " + self.nick + "n", "UTF-8"))
self.ircsock.send(bytes("JOIN " + self.channel + "n", "UTF-8"))
self.ircsock.send(bytes("PRIVMSG " + self.channel + " " + text + "n", "UTF-8"))
self.ircsock.send(bytes("QUIT n", "UTF-8"))

0 comments on commit fc1d1ab

Please sign in to comment.