Example #1
0
def main():
    config = MalwasmConfig().get('database')

    parser = argparse.ArgumentParser(description = 'Malwasm create DB')
    parser.add_argument('--version', action='version', 
        version="%(prog)s version " + MALWASM_VERSION)
    
    # software configuration required param
    parser.add_argument('-f', '--force', action='store_true',
        default=False,
        help='Force to drop the database and use the new schema')
    
    # database configuration
    parser.add_argument('-u', '--username', action='store', 
        default=config['username'], help='Database username')
    parser.add_argument('-p', '--password', action='store', 
        default=config['password'], help='Database password')
    parser.add_argument('-d', '--db', action='store', 
        default=config['dbname'], help='Database name')
    parser.add_argument('--host', action='store', 
        default=config['host'], help='Database hostname')

    # logging configuration
    parser.add_argument('--debug', action='store_const', const=logging.DEBUG,
        default=logging.CRITICAL, dest='logging', help='Show debug output')


    # parse cli argument
    r = parser.parse_args()

    logging.basicConfig(level=r.logging)
    

    # build the new configuration
    c = {
        'username': r.username,
        'password': r.password,
        'dbname': r.db,
        'host': r.host,
    }
    config.update(c)

    ret = os.EX_SOFTWARE
    try:
        m = MalwasmDb(config)
        if r.force:
            m.close()
            m.generate()
        print "Database '%s' correctly created!" % r.db
        ret = os.EX_OK
    except MalwasmExceptDbConn as e:
        print >> sys.stderr, "Database connection error:", e
    except MalwasmExceptDb as e:
        print >> sys.stderr, "Database error:", e
    except Exception as e:
        print >> sys.stderr, e

    sys.exit(ret)
Example #2
0
 def __init__(self, config=MalwasmConfig().get('database')):
     self.conn = None
     self.c = config
     try:
         self.connect()
     except MalwasmExceptDbNotExist as e:
         self.generate()
Example #3
0
def main():
    parser = argparse.ArgumentParser(description='Malwasm submit samples')
    parser.add_argument('--version',
                        action='version',
                        version="%(prog)s version " + MALWASM_VERSION)
    parser.add_argument("--custom",
                        type=str,
                        action="store",
                        default="",
                        help="Specify any custom value",
                        required=False)
    parser.add_argument("--timeout",
                        type=int,
                        action="store",
                        default=0,
                        help="Specify an analysis timeout",
                        required=False)
    parser.add_argument(
        "--options",
        type=str,
        action="store",
        default="",
        help=
        "Specify options for the analysis package (e.g. \"name=value,name2=value2\")",
        required=False)
    parser.add_argument(
        "--priority",
        type=int,
        action="store",
        default=1,
        help="Specify a priority for the analysis represented by an integer",
        required=False)
    parser.add_argument(
        "--machine",
        type=str,
        action="store",
        default="",
        help="Specify the identifier of a machine you want to use",
        required=False)
    parser.add_argument(
        "--platform",
        type=str,
        action="store",
        default="",
        help=
        "Specify the operating system platform you want to use (windows/darwin/linux)",
        required=False)

    parser.add_argument("path", type=str, help="Path to the file to analyze")

    r = parser.parse_args()

    r.path = os.path.abspath(r.path)

    if not os.path.exists(r.path):
        print("ERROR: the specified file does not exist at path \"%s\"" %
              args.path)
        sys.exit(os.EX_USAGE)

    config = MalwasmConfig().get('cuckoo')
    sub_folder = str(time.time()).replace('.', '')
    share_path = os.path.join(config['share_host_path'], sub_folder)
    print " [*] Use the following share_path %s..." % share_path

    os.mkdir(share_path)

    # Add the share letter parameter
    if r.options:
        pin_param = r.options
        r.options += ",share_letter=%s\\%s" % (config['share_vm_letter'],
                                               sub_folder)
    else:
        r.options = "share_letter=%s\\%s" % (config['share_vm_letter'],
                                             sub_folder)
        pin_param = ""

    xml_sample = "<sample>" + \
        "<filename>%s</filename>" + \
        "<md5>%s</md5>" + \
        "<pin_param>%s</pin_param>" + \
        "</sample>"
    xml_sample = xml_sample % (os.path.basename(r.path), File(
        r.path).get_md5(), pin_param)

    open(os.path.join(share_path, 'sample.xml'), 'w').write(xml_sample)
    db = MalwasmCuckooDb()

    task_id = db.add(File(r.path),
                     package="malwasm",
                     timeout=r.timeout,
                     options=r.options,
                     priority=r.priority,
                     machine=r.machine,
                     platform=r.platform,
                     custom=r.custom)

    print " [*] Task added with id %d in cuckoo" % task_id
    print " [*] Wait to task finish..."

    while db.get_status(task_id) != "success":
        time.sleep(1)

    print " [*] Task complete"
    print " [*] Insert into malwasm database..."

    ret = os.EX_SOFTWARE
    try:
        m = MalwasmDb()
        m.insert(share_path)
        ret = os.EX_OK
    except MalwasmExceptDbConn as e:
        print >> sys.stderr, "Database connection error:", e
    except MalwasmExceptDb as e:
        print >> sys.stderr, "Database error:", e
    except Exception as e:
        logging.exception(e)
        print >> sys.stderr, e

    print " [*] Job complete go on the web interface"

    sys.exit(ret)
Example #4
0
def main():
    parser = argparse.ArgumentParser(description = 'Malwasm insert XML into DB')
    parser.add_argument('--version', action='version', 
        version="%(prog)s version " + MALWASM_VERSION)
    
    # software configuration required param
    parser.add_argument('-d', '--dir', action='store', required=True,
        help='Directory where generated data are stocked')
    parser.add_argument('-i', '--sample-id', action='store', required=True,
        help='Sample id')
    
    config = MalwasmConfig().get('database')

    # database configuration
    parser.add_argument('-u', '--username', action='store', 
        default=config['username'], help='Database username')
    parser.add_argument('-p', '--password', action='store', 
        default=config['password'], help='Database password')
    parser.add_argument('--db', action='store', 
        default=config['dbname'], help='Database name')
    parser.add_argument('--host', action='store', 
        default=config['host'], help='Database hostname')
    
    # logging configuration
    parser.add_argument('--debug', action='store_const', const=logging.DEBUG,
        default=logging.INFO, dest='logging', help='Show debug output')

    # parse cli argument
    r = parser.parse_args()

    logging.basicConfig(level=r.logging)
    
    # build the new configuration
    c = {
        'username': r.username,
        'password': r.password,
        'dbname': r.db,
        'host': r.host,
    }
    config.update(c)

    ret = os.EX_SOFTWARE
    try:
        c = connect_db(config)
        try: 
            os.mkdir(r.dir)
        except:
            pass
        path_memory = os.path.join(r.dir, "memory")
        try:
            os.mkdir(path_memory)
        except:
            pass


        build_xml(c, r.sample_id, r.dir)
        build_dump(c, r.sample_id, path_memory)
        c.close() 
        ret = os.EX_OK
    except Exception as e:
        logging.exception(e)
        print >> sys.stderr, e

    sys.exit(ret)
Example #5
0
def main():
    config = MalwasmConfig().get('database')

    parser = argparse.ArgumentParser(description='Malwasm create DB')
    parser.add_argument('--version',
                        action='version',
                        version="%(prog)s version " + MALWASM_VERSION)

    # software configuration required param
    parser.add_argument(
        '-f',
        '--force',
        action='store_true',
        default=False,
        help='Force to drop the database and use the new schema')

    # database configuration
    parser.add_argument('-u',
                        '--username',
                        action='store',
                        default=config['username'],
                        help='Database username')
    parser.add_argument('-p',
                        '--password',
                        action='store',
                        default=config['password'],
                        help='Database password')
    parser.add_argument('-d',
                        '--db',
                        action='store',
                        default=config['dbname'],
                        help='Database name')
    parser.add_argument('--host',
                        action='store',
                        default=config['host'],
                        help='Database hostname')

    # logging configuration
    parser.add_argument('--debug',
                        action='store_const',
                        const=logging.DEBUG,
                        default=logging.CRITICAL,
                        dest='logging',
                        help='Show debug output')

    # parse cli argument
    r = parser.parse_args()

    logging.basicConfig(level=r.logging)

    # build the new configuration
    c = {
        'username': r.username,
        'password': r.password,
        'dbname': r.db,
        'host': r.host,
    }
    config.update(c)

    ret = os.EX_SOFTWARE
    try:
        m = MalwasmDb(config)
        if r.force:
            m.close()
            m.generate()
        print "Database '%s' correctly created!" % r.db
        ret = os.EX_OK
    except MalwasmExceptDbConn as e:
        print >> sys.stderr, "Database connection error:", e
    except MalwasmExceptDb as e:
        print >> sys.stderr, "Database error:", e
    except Exception as e:
        print >> sys.stderr, e

    sys.exit(ret)
Example #6
0
import psycopg2.extras
import json, StringIO
import sys, os
import datetime
from flask import Flask, request, session, g, redirect, url_for, abort, \
     render_template, flash, jsonify, send_file

sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), ".."))

from core.MalwasmConfig import *

# Debug flag
DEBUG = True

# Db config from MalwasmConfig
config = MalwasmConfig().get('database')

app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)


def connect_db():
    """Returns a new connection to the database."""
    return psycopg2.connect("dbname=%s user=%s password=%s host=%s" %
                            (config['dbname'], config['username'],
                             config['password'], config['host']))


@app.before_request
def before_request():
Example #7
0
def main():
    parser = argparse.ArgumentParser(description = 'Malwasm insert XML into DB')
    parser.add_argument('--version', action='version', 
        version="%(prog)s version " + MALWASM_VERSION)
    
    # software configuration required param
    #parser.add_argument('-e', '--exe', action='store', required=True,
        #help='Sample file related to the data')
    parser.add_argument('-d', '--dir', action='store', required=True,
        help='Directory where generated data are stocked')
    #parser.add_argument('--pin-param', action='store', default="",
        #help='Directory where generated data are stocked')
    
    config = MalwasmConfig().get('database')

    # database configuration
    parser.add_argument('-u', '--username', action='store', 
        default=config['username'], help='Database username')
    parser.add_argument('-p', '--password', action='store', 
        default=config['password'], help='Database password')
    parser.add_argument('--db', action='store', 
        default=config['dbname'], help='Database name')
    parser.add_argument('--host', action='store', 
        default=config['host'], help='Database hostname')
    
    # logging configuration
    parser.add_argument('--debug', action='store_const', const=logging.DEBUG,
        default=logging.INFO, dest='logging', help='Show debug output')

    # parse cli argument
    r = parser.parse_args()

    logging.basicConfig(level=r.logging)
    
    # build the new configuration
    c = {
        'username': r.username,
        'password': r.password,
        'dbname': r.db,
        'host': r.host,
    }
    config.update(c)

    ret = os.EX_SOFTWARE
    try:
        m = MalwasmDb(config)
        m.insert(r.dir)
        ret = os.EX_OK
    except MalwasmExceptDbConn as e:
        print >> sys.stderr, "Database connection error:", e
    except MalwasmExceptDb as e:
        print >> sys.stderr, "Database error:", e
    except Exception as e:
        logging.exception(e)
        print >> sys.stderr, e

    sys.exit(ret)

    conn.close()

    sys.exit(os.EX_OK)
Example #8
0
def main():
    parser = argparse.ArgumentParser(description='Malwasm insert XML into DB')
    parser.add_argument('--version',
                        action='version',
                        version="%(prog)s version " + MALWASM_VERSION)

    # software configuration required param
    parser.add_argument('-d',
                        '--dir',
                        action='store',
                        required=True,
                        help='Directory where generated data are stocked')
    parser.add_argument('-i',
                        '--sample-id',
                        action='store',
                        required=True,
                        help='Sample id')

    config = MalwasmConfig().get('database')

    # database configuration
    parser.add_argument('-u',
                        '--username',
                        action='store',
                        default=config['username'],
                        help='Database username')
    parser.add_argument('-p',
                        '--password',
                        action='store',
                        default=config['password'],
                        help='Database password')
    parser.add_argument('--db',
                        action='store',
                        default=config['dbname'],
                        help='Database name')
    parser.add_argument('--host',
                        action='store',
                        default=config['host'],
                        help='Database hostname')

    # logging configuration
    parser.add_argument('--debug',
                        action='store_const',
                        const=logging.DEBUG,
                        default=logging.INFO,
                        dest='logging',
                        help='Show debug output')

    # parse cli argument
    r = parser.parse_args()

    logging.basicConfig(level=r.logging)

    # build the new configuration
    c = {
        'username': r.username,
        'password': r.password,
        'dbname': r.db,
        'host': r.host,
    }
    config.update(c)

    ret = os.EX_SOFTWARE
    try:
        c = connect_db(config)
        try:
            os.mkdir(r.dir)
        except:
            pass
        path_memory = os.path.join(r.dir, "memory")
        try:
            os.mkdir(path_memory)
        except:
            pass

        build_xml(c, r.sample_id, r.dir)
        build_dump(c, r.sample_id, path_memory)
        c.close()
        ret = os.EX_OK
    except Exception as e:
        logging.exception(e)
        print >> sys.stderr, e

    sys.exit(ret)