def makeBot(self,resource): client = Client(bot_jid.getDomain(), debug=[]) client.connect() client.auth(bot_jid.getNode(),bot_passwd,self.resource) client.sendInitPresence() client.RegisterHandler('message',self.getMessage) return client
class XmpppyTransport(Transport): """ Implements the XMPP transport (xmpppy). """ def __init__(self): settings = core.server.server.settings self.domain = settings.get('xmpp_domain') self.host = settings.get('xmpp_host') self.port = settings.get('xmpp_port') self.user = settings.get('xmpp_user') self.password = settings.get('xmpp_password') self.presence = settings.get('xmpp_presence') self.connected = False @classmethod def isIdentifiedBy(cls, type): return type == 'xmpp' def connect(self): """ Connects to an XMPP server. """ self.client = Client(self.domain) if not self.client.connect(server=(self.host, self.port)): raise IOError('Cannot connect to server.') if not self.client.auth(self.user, self.password, self.presence): raise IOError('Cannot auth with server.') self.client.RegisterHandler('message', message_handler) self.client.sendInitPresence() self.connected = True while True: self.client.Process(1) def disconnect(self): """ Disconnects from the current XMPP server. """ if connected: self.client.sendPresence(typ='unavailable') self.client.disconnect() self.client = None self.connected = False def send(self, destination, action): self.client.send(Message('tim@localhost', str(action)))
def xmppBrute0x00(ip, usernames, passwords, port, delay): client = Client(str(ip)) client.connect(server=(str(ip), port)) for username in usernames: for password in passwords: try: if client.auth(username, password): client.sendInitPresence() print(G + ' [+] Username: %s | Password found: %s\n' % (username, password)) client.disconnect() except Exception as e: print(R+" [-] Error caught! Name: "+str(e)) except KeyboardInterrupt: client.disconnect() sys.exit(1) except: print(GR+ " [*] Checking : "+C+"Username: %s | "+B+"Password: %s "+R+"| Incorrect!\n" % (username, password)) sleep(delay)
def _get_connected_client(account): client = Client(account['server'], debug=[]) if not client.connect(): logging.error( "Can not connect to %s server, please check your configuration", account['server']) raise IOError('Can not connect to server.') if not client.auth(account['user'], account['password'], account['resource']): logging.error("Can not auth as %s@%s, please check your configuration", account['user'], account['server']) raise IOError('Can not auth with server.') logging.info("Logged in as %s@%s", account['user'], account['server']) client.RegisterHandler('message', _handle_messages) client.sendInitPresence() client.Process(1) return client
def test(): client = Client('localhost') def message_handler(conn, mess_node): client.send(Message('tim@localhost', 'reponse!')) if not client.connect(server=('127.0.0.1', 5222)): raise IOError('Can not connect to server.') if not client.auth('abitbol', 'abitbol', 'abitbol'): raise IOError('Can not auth with server.') client.RegisterHandler('message', message_handler) client.sendInitPresence() client.send(Message('tim@localhost', 'Test message')) while 1: client.Process(1)
else: presence = Presence(to='%s/%s' % (room, nick)) presence.setTag('x', namespace=NS_MUC).setTagData('password', room_password) presence.getTag('x').addChild('history',{'maxchars':'0','maxstanzas':'0'}) client.send(presence) def msg_room(message): send_msg(room, message, typ='groupchat') def send_msg(to, message, typ='chat'): client.send(Message(to=to, body=message, typ=typ)) # connect to server client = Client(JID(user).getDomain(), debug=[]) client.connect() while not client.auth(JID(user).getNode(), user_password, resource=JID(user).getResource()): print('Unable to authorize.') password = getpass('Password for %s:' % (user)) # register handlers client.RegisterHandler('message', message_callback) client.RegisterHandler('presence', presence_callback) # send presence client.sendInitPresence() join_room() # process incoming messages while True: client.Process(1)