Skip to content

Instantly share code, notes, and snippets.

@weiss
Created May 12, 2015 11:58
Show Gist options
  • Save weiss/2d64ecac01eb08a22428 to your computer and use it in GitHub Desktop.
Save weiss/2d64ecac01eb08a22428 to your computer and use it in GitHub Desktop.
Let two XMPP resources flood each other with messages
#!/usr/bin/env python
#
# By Holger Weiss, based on a script provided by Stefan Karlsson.
#
"""
Log in with two resources and have each of them send a never-ending message
flood to the other one.
1. Install SleekXMPP, e.g. on Debian:
$ sudo apt-get install python-sleekxmpp
2. Create a "test" user on your XMPP server and run the script like this:
$ xmpp-flood.py -j [email protected] -p secret
"""
import logging
import os
import signal
import sleekxmpp
import socket
import ssl
import sys
from optparse import OptionParser
def signal_handler(signal, frame):
print('Exiting.')
sys.exit(0)
class Client(sleekxmpp.ClientXMPP):
def __init__(self, jid, password):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.jid = jid
self.payload = 'I shall not garble TLS records!'
self.add_event_handler('session_start', self.start)
self.add_event_handler('failed_auth', self.auth_error)
def start(self, event):
self.send_presence()
def auth_error(self, event):
print('Cannot authenticate as ' + self.jid)
if __name__ == '__main__':
optp = OptionParser()
optp.add_option('-j', '--jid', dest='jid', help='JID to use')
optp.add_option('-p', '--password', dest='password', help='Password to use')
opts, args = optp.parse_args()
if opts.jid is None:
opts.jid = 'test@' + socket.getfqdn()
if opts.password is None:
opts.password = 'test'
logging.basicConfig(level=logging.ERROR,
format='[%(levelname)s] %(message)s')
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
if os.fork() == 0:
my_jid = opts.jid + '/Child'
peer_jid = opts.jid + '/Parent'
else:
my_jid = opts.jid + '/Parent'
peer_jid = opts.jid + '/Child'
ssl.RAND_add('Nothing', 0.0) # Update parent's PRNG state.
xmpp = Client(my_jid, opts.password)
if xmpp.connect():
"""
If you don't have the "dnspython" library installed, you will need to
manually specify the name of the server if it does not match the one in
the JID. For example, to use Google Talk you would need to use:
if xmpp.connect('talk.google.com', 5222):
"""
xmpp.process()
print('Logged in as ' + my_jid + ', going to flood ' + peer_jid + '.')
while True:
xmpp.send_message(mto=peer_jid, mbody=xmpp.payload)
else:
print('Unable to connect as ' + my_jid + '.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment