Exemple #1
0
def publisher():
    jobs = Queue.objects.filter(published=False)
    try:
        gridfs = connect_gridfs()
    except Exception as e:
        logger.debug(e)

    for j in jobs:
        for r in gridfs.find({'sha256': j.malware.sha256}, limit=1):
            malware = r

        try:
            hpc = hpfeeds.new(j.channel.host, int(j.channel.port),
                              j.channel.ident.encode(),
                              j.channel.secret.encode())
        except Exception as e:
            logger.debug(e)
        else:
            data = malware.read()
            hpc.publish([j.channel.pubchans], data)
            error_msg = hpc.wait()
            if error_msg:
                logger.debug('got error from server: {}'.format(error_msg))
            else:
                # also can add a notification
                j.published = True
                j.save()
Exemple #2
0
def publisher():
    jobs = Queue.objects.filter(published=False)
    try:
        gridfs = connect_gridfs()
    except Exception as e:
        logger.debug(e)

    for j in jobs:
        for r in gridfs.find({'sha256': j.malware.sha256}, limit=1):
            malware = r 

        try:
            hpc = hpfeeds.new(j.channel.host, int(j.channel.port), j.channel.ident.encode(), j.channel.secret.encode())
        except Exception as e:
            logger.debug(e)
        else:
            data = malware.read()
            hpc.publish([j.channel.pubchans], data)
            error_msg = hpc.wait()
            if error_msg:
                logger.debug('got error from server: {}'.format(error_msg))
            else:
                # also can add a notification
                j.published = True
                j.save()
Exemple #3
0
def create_hpc(host, port, ident, secret, subchans, user, source):
    def on_message(identifier, channel, payload):
        from django.db import connection
        connection.close()
        sha256 = save_malware(payload, user=user, source=source)
        link = reverse_lazy('malware.profile', args=[sha256])
        Notification(user=user, subject=SUBJECT, message=MESSAGE.format(link, sha256)).save()

    def on_error(payload):
        print >>sys.stderr, ' -> errormessage from server: {0}'.format(payload)
        hpc.stop()

    hpc = hpfeeds.new(host, port, ident, secret)
    hpc.subscribe(subchans)
    hpc.run(on_message, on_error)
Exemple #4
0
def create_hpc(host, port, ident, secret, subchans, user, source):
    def on_message(identifier, channel, payload):
        from django.db import connection
        connection.close()
        sha256 = save_malware(payload, user=user, source=source)
        link = reverse_lazy('malware.profile', args=[sha256])
        Notification(user=user,
                     subject=SUBJECT,
                     message=MESSAGE.format(link, sha256)).save()

    def on_error(payload):
        print >> sys.stderr, ' -> errormessage from server: {0}'.format(
            payload)
        hpc.stop()

    hpc = hpfeeds.new(host, port, ident, secret)
    hpc.subscribe(subchans)
    hpc.run(on_message, on_error)