Skip to content
Browse files

connection problems put to error bucket, show with command 'showlog' …

…in cli, closes #19
  • Loading branch information...
1 parent a5e03ae commit ff4d2e6c7b3ae25f959fe0edacfd5807d3a6921a pjlantz committed
View
10 src/conf/modules.conf
@@ -4,19 +4,19 @@ http = botnet, method, *base64, *grammar, response_separator
[ircConf]
module = irc
-botnet = irc.freenode.net
+botnet = irc.host.net
port = 6667
password = None
-nick = nickname
+nick = AgentNick
username = agent007
realname = Spying
-channel = #channame
-channel_pass = pass
+channel = #channelname
+channel_pass = None
pass_grammar = PASS
nick_grammar = NICK
user_grammar = USER
join_grammar = JOIN
-version_grammar = VERSION
+version_grammar = VERSION
time_grammar = TIME
privmsg_grammar = PRIVMSG
topic_grammar = TOPIC
View
21 src/modules/httpModule.py
@@ -57,7 +57,7 @@ def run(self):
"""
self.prox = proxySelector.ProxySelector()
- self.factory = HTTPClientFactory(self, self.hash, self.config)
+ self.factory = HTTPClientFactory(self, self.hash, self.config, self)
self.host = self.config['botnet']
self.port = int(self.config['port'])
self.proxyInfo = self.prox.getRandomProxy()
@@ -127,11 +127,12 @@ class HTTPClientFactory(protocol.ClientFactory):
protocol = HTTPProtocol
- def __init__(self, module, hash, config):
+ def __init__(self, module, hash, config, module):
"""
Constructor
"""
+ self.module = module
self.hash = hash
self.config = config
self.cookies = {}
@@ -189,6 +190,20 @@ def handleResponse(self, response):
except IndexError:
# Could not split out wait grammar, maybe base64 decoding is necessary, got response:
return
+
+ def clientConnectionFailed(self, connector, reason):
+ """
+ Called on failed connection to server
+ """
+
+ moduleCoordinator.ModuleCoordinator().putError("Error connecting to " + self.config['botnet'], self.module)
+
+ def clientConnectionLost(self, connector, reason):
+ """
+ Called on lost connection to server
+ """
+
+ moduleCoordinator.ModuleCoordinator().putError("Connection lost to " + self.config['botnet'], self.module)
def __call__(self):
"""
@@ -212,4 +227,4 @@ def noPage(self, reason):
def page(self, response):
pass
-
+
View
31 src/modules/ircModule.py
@@ -53,8 +53,8 @@ def run(self):
"""
Start execution
"""
-
- factory = IRCClientFactory(self.hash, self.config)
+
+ factory = IRCClientFactory(self.hash, self.config, self)
host = self.config['botnet']
port = int(self.config['port'])
proxyInfo = self.prox.getRandomProxy()
@@ -77,7 +77,6 @@ def stop(self):
"""
self.connector.disconnect()
-
def getConfig(self):
"""
@@ -109,7 +108,7 @@ def dataReceived(self, data):
"""
Data is received
"""
-
+
checkHost = data.split(':')[1].split(' ')[0].strip()
match = self.factory.expr.findall(checkHost)
if match:
@@ -125,8 +124,10 @@ def dataReceived(self, data):
else:
self.transport.write(self.factory.config['join_grammar'] + ' ' + self.factory.config['channel'] + '\r\n') # join without pass
self.factory.firstPing = False
+
elif data.find(self.factory.config['topic_grammar']) != -1: # topic
self.factory.putLog(data)
+
elif data.find(self.factory.config['currenttopic_grammar']) != -1: # currenttopic
firstline = data.split('\r\n')[0].split(self.factory.config['nick'])[1].strip()
chan = firstline.split(' ')[0].strip()
@@ -135,10 +136,12 @@ def dataReceived(self, data):
setby = secondline.split(' ')[0].strip()
logmsg = 'CURRENTTOPIC ' + chan + ' ' + topic + ' set by ' + setby
self.factory.putLog(logmsg)
+
elif data.find(self.factory.config['privmsg_grammar']) != -1: # privmsg
if not data.find(self.factory.config['version_grammar']) != -1:
if not data.find(self.factory.config['time_grammar']) != -1:
self.factory.putLog(data)
+
else: # unrecognized commands
if match:
grammars = self.factory.config.values()
@@ -153,17 +156,32 @@ class IRCClientFactory(ClientFactory):
protocol = IRCProtocol # tell base class what proto to build
- def __init__(self, hash, config):
+ def __init__(self, hash, config, module):
"""
Constructor, sets first ping received flag
and config to be used
"""
+ self.module = module
self.expr = re.compile('!~.*?@')
self.config = config
self.firstPing = True
self.hash = hash
-
+
+ def clientConnectionFailed(self, connector, reason):
+ """
+ Called on failed connection to server
+ """
+
+ moduleCoordinator.ModuleCoordinator().putError("Error connecting to " + self.config['botnet'], self.module)
+
+ def clientConnectionLost(self, connector, reason):
+ """
+ Called on lost connection to server
+ """
+
+ moduleCoordinator.ModuleCoordinator().putError("Connection lost to " + self.config['botnet'], self.module)
+
def putLog(self, log):
"""
Put log to the event handler
@@ -195,3 +213,4 @@ def __call__(self):
p = self.protocol()
p.factory = self
return p
+
View
20 src/modules/moduleManager.py
@@ -56,19 +56,15 @@ def execute(module, identifier, hash):
print "[ModuleManager]: No such module " + module
return
func = modules[module]
- try:
- if configHandler.ConfigHandler().correctConfig(module):
- confCopy = copy.copy(configHandler.ConfigHandler().getConfig())
- regmod = func(confCopy, hash)
- if isinstance(regmod, moduleInterface.Module):
- moduleCoordinator.ModuleCoordinator().add(regmod, identifier, hash)
- else:
- print "[ModuleManager]: " + module + " is not subclass of moduleInterface.Module"
+ if configHandler.ConfigHandler().correctConfig(module):
+ confCopy = copy.copy(configHandler.ConfigHandler().getConfig())
+ regmod = func(confCopy, hash)
+ if isinstance(regmod, moduleInterface.Module):
+ moduleCoordinator.ModuleCoordinator().add(regmod, identifier, hash)
else:
- return
- except Exception:
- print sys.exc_info()[1]
- print "[ModuleManager]:", sys.exc_info()[1]
+ print "[ModuleManager]: " + module + " is not subclass of moduleInterface.Module"
+ else:
+ return
def executeExternal(module, identifier, config, hash):
"""
View
8 src/utils/logHandler.py
@@ -147,10 +147,10 @@ def doDownload(self, url, extfilename):
if proxyInfo == None:
pass
else:
- if len(proxyInfo['USER']) == 0:
- socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1080)
+ if len(proxyInfo['USER']) == 0:
+ socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxyInfo['HOST'], proxyInfo['PORT'])
else:
- socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1080, proxyInfo['USER'], proxyInfo['PASS'])
+ socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxyInfo['HOST'], proxyInfo['PORT'], proxyInfo['USER'], proxyInfo['PASS'])
socket.socket = socks.socksocket
opener = urllib2.build_opener()
@@ -191,4 +191,4 @@ def doDownload(self, url, extfilename):
botnetobject.save()
except IntegrityError:
pass
-
+
View
30 src/utils/moduleCoordinator.py
@@ -19,7 +19,7 @@
################################################################################
import Queue, os
-import threading, time
+import threading, time, datetime
from utils import logHandler
from twisted.internet import reactor
from threading import Lock
@@ -230,6 +230,12 @@ def add(self, moduleExe, moduleId, hash, external=False):
conf = self.modules[moduleId].getConfig()
confStr = configHandler.ConfigHandler().getStrFromDict(conf, toDB=True)
coord = self.geo.record_by_name(conf['botnet'])
+
+ if coord == None:
+ self.putError("Unkown host: " + conf['botnet'])
+ self.modules.pop(moduleId)
+ self.configHashes.pop(moduleId)
+ return
b = Botnet(botnethashvalue=hash, botnettype=conf['module'], host=conf['botnet'], config=confStr, longitude=coord['longitude'], latitude=coord['latitude'])
try:
b.save()
@@ -251,14 +257,16 @@ def putError(self, exception, module=None):
in the CLI
"""
+ now = datetime.datetime.now()
+ logMsg = "[" + str(now.date()) + " " + str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) + "]: " + exception
if module != None:
- for key, value in self.modules.items():
- if value == module:
- self.bucket.put(exception) # add more detailed info later, like time etc
- self.stop(key)
- return
+ for key, value in self.modules.items():
+ if value == module:
+ self.bucket.put(logMsg)
+ self.stop(key)
+ return
else:
- self.bucket.put(exception) # add more detailed info later, like time etc
+ self.bucket.put(logMsg)
def getErrors(self):
"""
@@ -268,10 +276,10 @@ def getErrors(self):
"""
try:
- while True:
- print self.bucket.get_nowait()
+ while True:
+ print self.bucket.get_nowait()
except Queue.Empty:
- pass
+ pass
def stop(self, moduleId):
"""
@@ -304,4 +312,4 @@ def stopAll(self):
reactor.stop()
self.runEventListener = False
self.join()
-
+
View
5 src/xmpp/producerBot.py
@@ -184,7 +184,8 @@ def removeBotnet(self, botnet):
monited ones
"""
- self.monitoredBotnets.remove(botnet)
+ if self.__useBot() and self.running:
+ self.monitoredBotnets.remove(botnet)
def getMonitoredBotnets(self):
"""
@@ -260,4 +261,4 @@ def sendLog(self, msg):
if self.__useBot():
self.xmpp.sendMessage(self.sharechannel, msg, None, "groupchat")
-
+

0 comments on commit ff4d2e6

Please sign in to comment.
Something went wrong with that request. Please try again.