For my college days, I was very fascinated by the Google Gtalk Instant messaging.
I always wanted to do something more with Gtalk
So, Here I present a very simple botnet program using python-xmpp (jabber Protocol).
It is primarily a Gtalk bot which in fact uses Extensible Messaging and Presence Protocol (XMPP).
The simple python program will act as xmpp client to talk to Google Gtalk server.
Pre Requisite
a) Very little python understanding [really i do not have]
b) python-xmpp – Python library for communication with XMPP (Jabber) servers
apt-get install python-xmpp [Debian/Ubuntu]
./base_bot.py [run on a command shell]
Code 1 > base_bot.py
It will do nothing but will show you as online
#!/usr/bin/python
import xmpp
user="[email protected]"
password="yourpassword"
server="gmail.com"
jid = xmpp.JID(user)
connection = xmpp.Client(server,debug=[])
connection.connect()
result = connection.auth(jid.getNode(), password, "Bot-Client-Is-Online")
connection.sendInitPresence()
while connection.Process(1):
pass
Code 2 > Lets modify it a little: base_bot_debug.py
It will through hell lot of debug info
You can see “presences” “rosters” “stanzas”
#!/usr/bin/python
import xmpp
user="[email protected]"
password="yourpassword"
server="gmail.com"
jid = xmpp.JID(user)
connection = xmpp.Client(server)
connection.connect()
result = connection.auth(jid.getNode(), password, "Bot-Client-Is-Online")
connection.sendInitPresence()
while connection.Process(1):
pass
Code 3 > run and send a text msg to from other account : gtalk_bot_auto_reply.py
You will receive a auto reply “Welcome to rm07en’s Gtalk Bot :P “
#!/usr/bin/python
import xmpp
user="[email protected]"
password="yourpassword"
server="gmail.com"
def message_handler(connect_object, message_node):
message = "Welcome to rm07en's Gtalk Bot :P "
connect_object.send( xmpp.Message( message_node.getFrom(), message))
jid = xmpp.JID(user)
connection = xmpp.Client(server)
connection.connect()
result = connection.auth(jid.getNode(), password, "Bot-Client-Is-Online")
connection.RegisterHandler('message', message_handler)
connection.sendInitPresence()
while connection.Process(1):
pass
Code 4 > Liitle gift for you : bust_invisible_buddies.py
This will List buddies in invisible mode
#!/usr/bin/python
import xmpp
user="[email protected]"
password="yourpassword"
def presenceHandler(conn, presence):
if presence:
if presence.getType() == "unavailable":
print presence.getFrom().getStripped()
print "Invisible Users:"
jid = xmpp.JID(user)
connection = xmpp.Client(server, debug=[])
connection.connect()
result = connection.auth(jid.getNode(), password, "Client Name")
connection.RegisterHandler('presence', presenceHandler)
connection.sendInitPresence()
while connection.Process(1):
pass
Code 5 > Final perhaps the coolest: gtalk_bot_shell.py
SSH your box via gtalk client anywhere on this earth
All the commands are not functional but you can try find more
#!/usr/bin/python
import xmpp
import subprocess
user="[email protected]"
password="yourpassword"
server="gmail.com"
def message_handler(connect_object, message_node):
admin = "[email protected]" # grant permission to the shell
from_user = message_node.getFrom().getStripped()
if admin == from_user: #allow to exec command only if admin requested
command = str(message_node.getBody())
process = subprocess.Popen(command, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
message = process.stdout.read()
if message=="":
message=process.stderr.read()
else:
message="Access denied! \n Contact System admin"
connect_object.send( xmpp.Message( message_node.getFrom(), message))
jid = xmpp.JID(user)
connection = xmpp.Client(server)
connection.connect()
result = connection.auth(jid.getNode(), password, "Bot-Client-Is-Online")
connection.RegisterHandler('message', message_handler)
connection.sendInitPresence()
while connection.Process(1):
pass
Source : LINUX For You Magazine
The original idea behind this was a genius’s guys article at L4U Mag.
As my post topic says its a baby step toward a bot writing.
I would really want reader : if you have more interest and knowledge to share.
Please Please do write to me.