Ejemplo n.º 1
0
    def __init__(self):

        format = "%(asctime)s \t%(message)s"
        BaseLogging.__init__(self, 'http', 'file_http', format)

        self.cfg = ConfigReader()
        self.log_extended = self.cfg.getConfig('logging', 'http_extended')
Ejemplo n.º 2
0
def FakeCPEInstance():
    cfg = ConfigReader()
    global FAKECPEINSTANCE
    if FAKECPEINSTANCE is None:
        FAKECPEINSTANCE = os.getenv('FAKECPEINSTANCE',
                                    cfg.getConfig("cpe", "serial_number"))
    return FAKECPEINSTANCE
Ejemplo n.º 3
0
class HTTPLogging(BaseLogging):
    def __init__(self):

        format = "%(asctime)s \t%(message)s"
        BaseLogging.__init__(self, 'http', 'file_http', format)

        self.cfg = ConfigReader()
        self.log_extended = self.cfg.getConfig('logging', 'http_extended')

    '''
    Get HTTP log message and write it to
    file in readable/parseable format.
    @message: HTTP logging values (headers, IPs, etc.)
    '''

    def log_message(self, message):

        request = message['request'].split()
        headers = ['Host', 'Referer', 'User-Agent', 'Cookie']

        for val in headers:
            if val not in message['headers']:
                message['headers'][val] = '-'

        if not message['post']:
            message['post'] = '-'

        msg = [
            str(message['client'][0]),  # Source IP
            str(message['client'][1]),  # Source Port
            str(message['headers']['Host']),  # Destination IP
            str(self.cfg.getConfig('http', 'port')),  # Destination Port
            str(request[0]),  # Method
            str(request[1]),  # Uri
            str(message['response'][1]),  # Status Message
        ]

        if self.log_extended == "yes":

            msg.insert(5, str(message['headers']['Host']))  # Host
            msg.insert(7, str(message['headers']['Referer']))  # Referer
            msg.insert(8, str(message['headers']['User-Agent']))  # User-Agent
            msg.insert(9, str(message['response'][0]))  # Status Code
            msg.extend([
                str(message['headers']['Cookie']),  # Cookie
                str(message['post'])
            ])  # POST Method Variables

        log = ''

        for value in msg:
            log += value + '\t'

        self.logger.critical(log)
Ejemplo n.º 4
0
class HTTPLogging(BaseLogging):

    def __init__(self):

        format = "%(asctime)s \t%(message)s"
        BaseLogging.__init__(self, 'http', 'file_http', format)

        self.cfg = ConfigReader()
        self.log_extended = self.cfg.getConfig('logging', 'http_extended')


    '''
    Get HTTP log message and write it to
    file in readable/parseable format.
    @message: HTTP logging values (headers, IPs, etc.)
    '''

    def log_message(self, message):

        request =  message['request'].split()
        headers = ['Host', 'Referer', 'User-Agent', 'Cookie']

        for val in headers:
            if val not in message['headers']:
                message['headers'][val] = '-'

        if not message['post']:
            message['post'] = '-'

        msg = [
            str(message['client'][0]),                                  # Source IP
            str(message['client'][1]),                                  # Source Port
            str(message['headers']['Host']),                            # Destination IP
            str(self.cfg.getConfig('http', 'port')),                    # Destination Port
            str(request[0]),                                            # Method
            str(request[1]),                                            # Uri
            str(message['response'][1]),                                # Status Message
        ]

        if self.log_extended == "yes":

            msg.insert(5, str(message['headers']['Host']))              # Host
            msg.insert(7, str(message['headers']['Referer']))           # Referer
            msg.insert(8, str(message['headers']['User-Agent']))        # User-Agent
            msg.insert(9, str(message['response'][0]))                  # Status Code
            msg.extend([str(message['headers']['Cookie']),              # Cookie
                        str(message['post'])])                          # POST Method Variables

        log = ''

        for value in msg:
            log += value + '\t'

        self.logger.critical(log)
Ejemplo n.º 5
0
    def __init__(self, name, file, format):

        cfg = ConfigReader()

        logfile = cfg.getConfig('logging', file)
        loglevel = cfg.getConfig('logging', 'level')

        self.name = name
        formatter = logging.Formatter(format)
        self.log_handler = logging.FileHandler(logfile)
        self.log_handler.setFormatter(formatter)
        self.initialize_logger(loglevel)
Ejemplo n.º 6
0
    def __init__(self, name, file, format):

        cfg = ConfigReader()

        logfile = cfg.getConfig('logging', file)
        loglevel = cfg.getConfig('logging', 'level')

        self.name = name
        formatter = logging.Formatter(format)
        self.log_handler = logging.FileHandler(logfile)
        self.log_handler.setFormatter(formatter)
        self.initialize_logger(loglevel)
Ejemplo n.º 7
0
    def __init__(self):

        format = "%(asctime)s \t%(message)s"
        BaseLogging.__init__(self, 'http', 'file_http', format)

        self.cfg = ConfigReader()
        self.log_extended = self.cfg.getConfig('logging', 'http_extended')
Ejemplo n.º 8
0
class PlatformConfig(platform_config.PlatformConfigMeta):
    """PlatformConfig for FakeCPE."""

    cfg = ConfigReader()

    def __init__(self, ioloop=None):
        platform_config.PlatformConfigMeta.__init__(self)

    def ConfigDir(self):
        #return '/tmp/catawampus.%s/config/' % FakeCPEInstance()
        return PlatformConfig.cfg.getConfig(
            'cwmp', 'cwmp_dir') + '/cpe.%s/config/' % FakeCPEInstance()

    def DownloadDir(self):
        #return '/tmp/catawampus.%s/download/' % FakeCPEInstance()
        return PlatformConfig.cfg.getConfig(
            'cwmp', 'cwmp_dir') + '/cpe.%s/download/' % FakeCPEInstance()

    def GetAcsUrl(self):
        """FakeCPE requires a --acs_url parameter, there is no platform handling."""
        return None

    def SetAcsUrl(self, url):
        raise AttributeError('URL is read-only')

    def AcsAccessAttempt(self, url):
        pass

    def AcsAccessSuccess(self, url):
        pass
Ejemplo n.º 9
0
class DeviceIdFakeCPE(dm.device_info.DeviceIdMeta):
    """Parameters for the DeviceInfo object for a FakeCPE platform."""

    cfg = ConfigReader()

    @property
    def Manufacturer(self):
        #return 'Catawampus'
        return DeviceIdFakeCPE.cfg.getConfig("cpe", "manufacturer")

    @property
    def ManufacturerOUI(self):
        #return '001A11'
        return DeviceIdFakeCPE.cfg.getConfig("cpe", "manufacturer_oui")

    @property
    def ModelName(self):
        #return 'FakeCPE'
        return DeviceIdFakeCPE.cfg.getConfig("cpe", "model_name")

    @property
    def Description(self):
        #return 'Simulated CPE device'
        return DeviceIdFakeCPE.cfg.getConfig("cpe", "description")

    @property
    def SerialNumber(self):
        return str(FakeCPEInstance())

    @property
    def HardwareVersion(self):
        #return '0'
        return DeviceIdFakeCPE.cfg.getConfig("cpe", "hardware_version")

    @property
    def AdditionalHardwareVersion(self):
        return '0'

    @property
    def SoftwareVersion(self):
        try:
            #with open('platform/fakecpe/version', 'r') as f:
            #  return f.readline().strip()
            return DeviceIdFakeCPE.cfg.getConfig("cpe", "software_version")
        except IOError:
            return 'unknown_version'

    @property
    def AdditionalSoftwareVersion(self):
        return '0'

    @property
    def ProductClass(self):
        #return 'Simulation'
        return DeviceIdFakeCPE.cfg.getConfig("cpe", "product_class")

    @property
    def ModemFirmwareVersion(self):
        #return '0'
        return DeviceIdFakeCPE.cfg.getConfig("cpe", "firmware_version")
Ejemplo n.º 10
0
class CWMPLogging(BaseLogging):

    def __init__(self):

        format = "%(asctime)s \t%(message)s"
        BaseLogging.__init__(self, 'cwmp', 'file_cwmp', format)

        self.cfg = ConfigReader()


    '''
    Get CWMP log message and write it to
    file in readable/parseable format.
    @message: CWMP communication info (IPs, headers, data etc.)
    '''

    def log_message(self, message):

        fmt = self.cfg.getConfig('logging', 'cwmp_data_format')

        if fmt == 'hex':
            message['data'] = message['data'].encode('hex')

        if not message['method']:
            message['method'] = '-'

        msg = [
            message['source_ip'],                                  # Source IP
            str(message['source_port']),                           # Source Port
            message['destination_ip'],                             # Destination IP
            str(message['destination_port']),                      # Destination Port
            message['type'],                                       # Type (POST, RECEIVE)
            message['method'],                                     # CWMP Method Name
            str(message['headers']),                               # Headers
            '\n' + message['data']                                 # CWMP Method Data
        ]

        for val in msg:
            if not val:
                message[val] = '-'

        log = ''

        for value in msg:
            log += value + '\t'

        self.logger.critical(log)
Ejemplo n.º 11
0
    def __init__(self):

        self.ht = HTLogging()
        self.cfg = ConfigReader()
Ejemplo n.º 12
0
class HoneyThing:

    def __init__(self):

        self.ht = HTLogging()
        self.cfg = ConfigReader()


    '''
    Initialize HTTP server according to stated config
    that try to acs as RomPager server
    '''

    def run_HTTP(self):

        print "Running HTTP..."

        http_listen_address = self.cfg.getConfig("http", "address")
        http_port = self.cfg.getConfig("http", "port")

        httpd = ThreadedHTTPServer((http_listen_address, int(http_port)), HTTPRequestHandler)

        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            pass
        httpd.server_close()


    '''
    Initialize CWMP server according to stated config
    that communicate with ACS server
    '''

    def run_CWMP(self):

        print "Running CWMP..."

        cwmp_listen_address = self.cfg.getConfig("cwmp", "address")
        cwmp_port = self.cfg.getConfig("cwmp", "port")
        acs_url = self.cfg.getConfig("cwmp", "acs_url")
        socket_file = self.cfg.getConfig("cwmp", "socket_file")
        request_path = self.cfg.getConfig("cwmp", "request_path")

        cpe = os.path.dirname(os.path.abspath(__file__)) + \
              '/cwmp/cwmpd --platform=fakecpe --rcmd-port=0 --cpe-listener ' \
              '-l=%s --port=%s --acs-url=%s --unix-path=%s --ping-path=%s &' \
              % (cwmp_listen_address, cwmp_port, acs_url, socket_file, request_path)

        try:
            subprocess.Popen(shlex.split(cpe))
        except subprocess.CalledProcessError as msg:
            self.ht.logger.error(str(msg.output))
        except OSError:
            pass


    '''
    Main function that runs prepared servers
    '''

    def main(self):

        self.ht.logger.info('Starting Honeything...')
        print('Starting Honeything...')

        self.run_CWMP()
        self.run_HTTP()
Ejemplo n.º 13
0
    def __init__(self):

        format = "%(asctime)s \t%(message)s"
        BaseLogging.__init__(self, 'cwmp', 'file_cwmp', format)

        self.cfg = ConfigReader()
Ejemplo n.º 14
0
import google3
import tornado
import tornado.httpclient
import tornado.ioloop
import tornado.web
import core
import helpers
import http_download
import persistobj

import shutil
from src.logger.HoneythingLogging import HTLogging
from src.config.ConfigReader import ConfigReader

ht = HTLogging()
cfg = ConfigReader()

# Persistent object storage filename
DNLDROOTNAME = 'tr69_dnld'
BOOTROOTNAME = 'tr69_boot'

# Download Dir
download_path = cfg.getConfig('cwmp', 'download_dir')


class Installer(object):
    """Install a downloaded image and reboot.

  This default implementation returns an error response. Platforms are
  expected to implement their own Install object, and set
  tr.download.INSTALLER = their object.
Ejemplo n.º 15
0
import tornado
import tornado.httpclient
import tornado.ioloop
import tornado.web
import core
import helpers
import http_download
import persistobj

import shutil
from src.logger.HoneythingLogging import HTLogging
from src.config.ConfigReader import ConfigReader


ht = HTLogging()
cfg = ConfigReader()

# Persistent object storage filename
DNLDROOTNAME = 'tr69_dnld'
BOOTROOTNAME = 'tr69_boot'

# Download Dir
download_path = cfg.getConfig('cwmp', 'download_dir')


class Installer(object):
  """Install a downloaded image and reboot.

  This default implementation returns an error response. Platforms are
  expected to implement their own Install object, and set
  tr.download.INSTALLER = their object.