Ejemplo n.º 1
0
    def send_payload(self, project, message):
        server = self.get_option('server', project)
        port = self.get_option('port', project)
        nick = self.get_option('nick', project)
        rooms = self.get_option('room', project) or ''
        without_join = self.get_option('without_join', project)
        users = self.get_option('user', project) or ''
        rooms = [
            x.startswith('#') and x or '#%s' % x
            for x in (x.strip() for x in rooms.split(','))
        ]
        users = [x.strip() for x in users.split(',')]
        password = self.get_option('password', project)
        ssl_c = self.get_option('ssl', project)

        start = time.time()
        ircsock = safe_socket_connect((server, int(port)), ssl=ssl_c)
        try:
            if password:
                ircsock.send("PASS %s\n" % password)
            ircsock.send("USER %s %s %s :Sentry IRC bot\n" % ((nick, ) * 3))
            ircsock.send("NICK %s\n" % nick)
            while (time.time() - start) < self.timeout:
                ircmsg = ircsock.recv(2048).strip('\n\r')
                real_nick = CONN_RE.search(ircmsg)
                if real_nick is not None:
                    nick = real_nick.group(1)
                pong = PING_RE.findall(ircmsg)
                if pong:
                    ircsock.send("PONG %s\n" % pong)
                if re.findall(' 433 \* %s' % nick, ircmsg):
                    nick += '%s' % randrange(1000, 2000)
                    ircsock.send("NICK %s\n" % nick)
                    ircmsg = ircsock.recv(2048)
                if re.findall(' 00[1-4] %s' % nick, ircmsg):
                    for room in rooms:
                        if not without_join:
                            ircsock.send("JOIN %s\n" % room)
                        ircsock.send("PRIVMSG %s :%s\n" % (room, message))
                        if not without_join:
                            ircsock.send("PART %s\n" % room)
                    for user in users:
                        ircsock.send("PRIVMSG %s :%s\n" % (user, message))
                    break

            ircsock.send("QUIT\n")

            # try to flush pending buffer
            while (time.time() - start) < self.timeout and ircmsg:
                ircmsg = ircsock.recv(2048)
        finally:
            ircsock.close()
Ejemplo n.º 2
0
    def send_payload(self, project, message):
        server = self.get_option('server', project)
        port = self.get_option('port', project)
        nick = self.get_option('nick', project)
        rooms = self.get_option('room', project) or ''
        without_join = self.get_option('without_join', project)
        users = self.get_option('user', project) or ''
        rooms = [x.startswith('#') and x or '#%s' % x
                 for x in (x.strip() for x in rooms.split(','))]
        users = [x.strip() for x in users.split(',')]
        password = self.get_option('password', project)
        ssl_c = self.get_option('ssl', project)

        start = time.time()
        ircsock = safe_socket_connect((server, int(port)), ssl=ssl_c)
        try:
            if password:
                ircsock.send("PASS %s\n" % password)
            ircsock.send("USER %s %s %s :Sentry IRC bot\n" % ((nick,) * 3))
            ircsock.send("NICK %s\n" % nick)
            while (time.time() - start) < self.timeout:
                ircmsg = ircsock.recv(2048).strip('\n\r')
                real_nick = CONN_RE.search(ircmsg)
                if real_nick is not None:
                    nick = real_nick.group(1)
                pong = PING_RE.findall(ircmsg)
                if pong:
                    ircsock.send("PONG %s\n" % pong)
                if re.findall(' 433 \* %s' % nick, ircmsg):
                    nick += '%s' % randrange(1000, 2000)
                    ircsock.send("NICK %s\n" % nick)
                    ircmsg = ircsock.recv(2048)
                if re.findall(' 00[1-4] %s' % nick, ircmsg):
                    for room in rooms:
                        if not without_join:
                            ircsock.send("JOIN %s\n" % room)
                        ircsock.send("PRIVMSG %s :%s\n" % (room, message))
                        if not without_join:
                            ircsock.send("PART %s\n" % room)
                    for user in users:
                        ircsock.send("PRIVMSG %s :%s\n" % (user, message))
                    break

            ircsock.send("QUIT\n")

            # try to flush pending buffer
            while (time.time() - start) < self.timeout and ircmsg:
                ircmsg = ircsock.recv(2048)
        finally:
            ircsock.close()
Ejemplo n.º 3
0
def test_safe_socket_connect():
    with pytest.raises(SuspiciousOperation):
        http.safe_socket_connect(("127.0.0.1", 80))
Ejemplo n.º 4
0
 def test_safe_socket_connect(self):
     with pytest.raises(SuspiciousOperation):
         http.safe_socket_connect(('127.0.0.1', 80))
Ejemplo n.º 5
0
 def test_safe_socket_connect(self):
     http.DISALLOWED_IPS = set([ipaddress.ip_network(u'127.0.0.1')])
     with pytest.raises(SuspiciousOperation):
         http.safe_socket_connect(('127.0.0.1', 80))