Skip to content

Commit

Permalink
Preparing Osmedeus module
Browse files Browse the repository at this point in the history
  • Loading branch information
linxon committed Aug 14, 2019
1 parent cf33e15 commit 7fab204
Show file tree
Hide file tree
Showing 83 changed files with 233 additions and 256 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include Osmedeus/resources *
File renamed without changes.
File renamed without changes.
19 changes: 11 additions & 8 deletions core/config.py → Osmedeus/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import urllib.parse
from configparser import ConfigParser, ExtendedInterpolation

from core import execute
from core import utils
from Osmedeus.core import execute
from Osmedeus.core import utils
from Osmedeus.resources import *

OSMEDEUS_HOME = str(Path.home().joinpath('.osmedeus'))

# Console colors
W = '\033[1;0m' # white
Expand Down Expand Up @@ -146,7 +149,8 @@ def proxy_parsing(options):
utils.print_info("Detected proxychains file: {0}".format(proxy_file))
return
elif options['PROXY'] != "None":
proxy_file = options['CWD'] + '/core/proxychains.conf'
proxy_file = OSMEDEUS_HOME + '/proxychains.conf'
shutil.copyfile(RESOURCES_PATH.joinpath('proxychains.conf'), proxy_file)
utils.print_info("Detected proxychains file: {0}".format(proxy_file))

if options['PROXY'] != "None":
Expand Down Expand Up @@ -208,13 +212,12 @@ def parsing_config(config_path, args):
cwd = str(os.getcwd())

# create default osmedeus path
osmedeus_home = str(Path.home().joinpath('.osmedeus'))
utils.make_directory(osmedeus_home)
utils.make_directory(OSMEDEUS_HOME)

if config_path:
config_path = os.path.normpath(config_path)
else:
config_path = str(Path.home().joinpath('.osmedeus/config.conf'))
config_path = OSMEDEUS_HOME + '/config.conf'

# just hardcode if gopath not loaded
plugins_path = cwd + "/plugins"
Expand All @@ -239,7 +242,7 @@ def parsing_config(config_path, args):
config.read(config_path)
else:
utils.print_info('New config file created: {0}'.format(config_path))
shutil.copyfile(cwd + '/template-config.conf', config_path)
shutil.copyfile(RESOURCES_PATH.joinpath('template-config.conf'), config_path)

config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(config_path)
Expand All @@ -248,7 +251,7 @@ def parsing_config(config_path, args):
if args.workspace:
workspaces = os.path.abspath(args.workspace)
else:
workspaces = str(Path.home().joinpath('.osmedeus/workspaces'))
workspaces = OSMEDEUS_HOME + '/workspaces'
utils.make_directory(workspaces)

# put config to config.conf file
Expand Down
7 changes: 4 additions & 3 deletions core/execute.py → Osmedeus/core/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import json
import subprocess
import requests
import urllib3

from Osmedeus.core import utils

sys.path.append(os.path.dirname(os.path.realpath(__file__)))

import utils
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
headers = {"User-Agent": "Osmedeus/v1.5", "Accept": "*/*",
"Content-type": "application/json", "Connection": "close"}
Expand Down Expand Up @@ -99,4 +101,3 @@ def send_JSON(options, json_body, token=''):
json=json_body, timeout=0.1)
except:
pass

10 changes: 5 additions & 5 deletions core/report.py → Osmedeus/core/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import sys
from pathlib import Path
from tabulate import tabulate
from core import utils
import requests
import urllib3

from Osmedeus.core import utils
from Osmedeus.resources import *

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
sys.path.append(os.path.dirname(os.path.realpath(__file__)))


# Console colors
W = '\033[1;0m' # white
R = '\033[1;31m' # red
Expand All @@ -20,16 +22,14 @@
C = '\033[1;36m' # cyan
GR = '\033[1;37m' # gray

BASE_DIR = Path(os.path.dirname(os.path.abspath(__file__)))

# Global stuff
headers = {"User-Agent": "Osmedeus/v1.5", "Accept": "*/*",
"Content-type": "application/json", "Connection": "close"}


# checking result locally
def local_get_report(options):
command_path = str(BASE_DIR.joinpath('rest/commands.json'))
command_path = str(RESOURCES_PATH.joinpath('rest/commands.json'))
commands = utils.reading_json(command_path)
# create skeleton dict
final_reports = []
Expand Down
Empty file added Osmedeus/core/rest/__init__.py
Empty file.
12 changes: 5 additions & 7 deletions core/rest/activities.py → Osmedeus/core/rest/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from flask import Flask, jsonify, render_template, request
from urllib.parse import quote, unquote
from ast import literal_eval
import utils

from Osmedeus.core import config
from Osmedeus.core import utils

'''
Logging command
'''

current_path = os.path.dirname(os.path.realpath(__file__))

class Activities(Resource):
parser = reqparse.RequestParser()
parser.add_argument('cmd',
Expand All @@ -30,8 +30,7 @@ class Activities(Resource):

def get_activities(self, workspace):
ws_name = utils.get_workspace(workspace=workspace)
activities_path = current_path + \
'/storages/{0}/activities.json'.format(ws_name)
activities_path = config.OSMEDEUS_HOME + '/storages/{0}/activities.json'.format(ws_name)
self.activities = utils.reading_json(activities_path)
if not self.activities:
return False
Expand Down Expand Up @@ -82,8 +81,7 @@ def post(self, workspace):
@jwt_required
def put(self, workspace):
ws_name = utils.get_workspace(workspace=workspace)
activities_path = current_path + \
'/storages/{0}/activities.json'.format(ws_name)
activities_path = config.OSMEDEUS_HOME + '/storages/{0}/activities.json'.format(ws_name)
if not self.get_activities(workspace=workspace):
return {"error": "activities doesn't exist for {0} workspace".format(
workspace)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
)

from .decorators import local_only
import utils

from Osmedeus.core import config
from Osmedeus.core import utils

'''
Check authentication
'''

current_path = os.path.dirname(os.path.realpath(__file__))


class Authentication(Resource):
parser = reqparse.RequestParser()
parser.add_argument('username',
Expand Down Expand Up @@ -50,8 +49,7 @@ def verify(self, options):

# just look for right cred on any workspace
def get_options(self, username, password):
option_files = glob.glob(
current_path + '/storages/**/options.json', recursive=True)
option_files = glob.glob(config.OSMEDEUS_HOME + '/storages/**/options.json', recursive=True)
# loop though all options avalible
for option in option_files:
json_option = utils.reading_json(option)
Expand Down Expand Up @@ -80,11 +78,7 @@ def post(self, workspace=None):
elif workspace == 'None':
pass

current_path = os.path.dirname(os.path.realpath(__file__))

options_path = current_path + \
'/storages/{0}/options.json'.format(workspace)

options_path = config.OSMEDEUS_HOME + '/storages/{0}/options.json'.format(workspace)
if not utils.not_empty_file(options_path):
return {'error': "Workspace not found"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from flask_restful import Api, Resource, reqparse
from flask_jwt_extended import jwt_required
from flask import Flask, request, escape, make_response
import utils

# incase you can't install ansi2html it's won't break the api
try:
from ansi2html import Ansi2HTMLConverter
except:
pass

current_path = os.path.dirname(os.path.realpath(__file__))
from Osmedeus.core import config
from Osmedeus.core import utils

'''
render stdout content
Expand All @@ -22,8 +22,7 @@
class BashRender(Resource):

def verify_file(self, filename):
option_files = glob.glob(
current_path + '/storages/**/options.json', recursive=True)
option_files = glob.glob(config.OSMEDEUS_HOME + '/storages/**/options.json', recursive=True)
# loop though all options avalible
for option in option_files:
json_option = utils.reading_json(option)
Expand Down
16 changes: 9 additions & 7 deletions core/rest/cmd.py → Osmedeus/core/rest/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
from flask import Flask, jsonify, render_template, request
from flask_restful import Api, Resource, reqparse
from flask_jwt_extended import jwt_required

from .decorators import local_only
import utils, slack, execute

from Osmedeus.core import config
from Osmedeus.core import utils
from Osmedeus.core import slack
from Osmedeus.core import execute

'''
Executing abritary command so it's a feature not an RCE bug :D
'''

current_path = os.path.dirname(os.path.realpath(__file__))

class Cmd(Resource):
parser = reqparse.RequestParser()
parser.add_argument('cmd',
Expand Down Expand Up @@ -44,14 +47,13 @@ class Cmd(Resource):

# # just return list of workspaces
# def __init__(self, **kwargs):
# self.options = utils.reading_json(current_path + '/storages/options.json')
# self.options = utils.reading_json(config.OSMEDEUS_HOME + '/storages/options.json')

@jwt_required
@local_only
def post(self, workspace):
ws_name = utils.get_workspace(workspace=workspace)
options_path = current_path + \
'/storages/{0}/options.json'.format(ws_name)
options_path = config.OSMEDEUS_HOME + '/storages/{0}/options.json'.format(ws_name)

self.options = utils.reading_json(options_path)

Expand All @@ -70,7 +72,7 @@ def post(self, workspace):
}

if nolog == 'False':
activities_path = current_path + '/storages/{0}/activities.json'.format(ws_name)
activities_path = config.OSMEDEUS_HOME + '/storages/{0}/activities.json'.format(ws_name)

# activities = utils.reading_json(activities_path)
activities = utils.reading_json(activities_path)
Expand Down
26 changes: 12 additions & 14 deletions core/rest/configuration.py → Osmedeus/core/rest/configuration.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import os
import utils
from flask_restful import Resource, reqparse
from flask_jwt_extended import jwt_required
from configparser import ConfigParser, ExtendedInterpolation
import utils
from pathlib import Path

from .decorators import local_only
BASE_DIR = Path(os.path.dirname(os.path.abspath(__file__)))

from Osmedeus.core import config
from Osmedeus.resources import *

'''
Set some config
'''


class Configurations(Resource):
parser = reqparse.RequestParser()
parser.add_argument('options',
Expand Down Expand Up @@ -39,8 +41,7 @@ def verify(self, options):
@jwt_required
def get(self, workspace):
ws_name = utils.get_workspace(workspace=workspace)
options_path = str(BASE_DIR.joinpath(
'storages/{0}/options.json'.format(ws_name)))
options_path = config.OSMEDEUS_HOME + '/storages/{0}/options.json'.format(ws_name)

# prevent reading secret from config file though API
secret_things = ['USERNAME', 'PASSWORD', 'BOT_TOKEN', 'GITHUB_API_KEY']
Expand All @@ -64,15 +65,12 @@ def post(self):

# write each workspace seprated folder
ws_name = utils.get_workspace(options)
utils.make_directory(str(BASE_DIR) + '/storages/{0}/'.format(ws_name))
if not os.path.isdir(str(BASE_DIR) + '/storages/{0}/'.format(ws_name)):
return {"error": "Can not create workspace directory with name {0} ".format(
ws_name)}
utils.make_directory(config.OSMEDEUS_HOME + '/storages/{0}/'.format(ws_name))
if not os.path.isdir(config.OSMEDEUS_HOME + '/storages/{0}/'.format(ws_name)):
return {"error": "Can not create workspace directory with name {0} ".format(ws_name)}

activities_path = str(BASE_DIR.joinpath(
'storages/{0}/activities.json'.format(ws_name)))
options_path = str(BASE_DIR.joinpath(
'storages/{0}/options.json'.format(ws_name)))
activities_path = config.OSMEDEUS_HOME + '/storages/{0}/activities.json'.format(ws_name)
options_path = config.OSMEDEUS_HOME + '/storages/{0}/options.json'.format(ws_name)

# consider this is settings db
utils.just_write(options_path, options, is_json=True)
Expand All @@ -92,7 +90,7 @@ def post(self):

utils.print_info("Cleaning activities log")

commands_path = str(BASE_DIR.joinpath('commands.json'))
commands_path = RESOURCES_PATH.joinpath('rest/commands.json')
commands = utils.reading_json(commands_path)

# Create skeleton activities based on commands.json
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions core/rest/logs.py → Osmedeus/core/rest/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from flask_restful import Resource, reqparse
from flask_jwt_extended import jwt_required
from flask import request
import utils
from pathlib import Path
BASE_DIR = Path(os.path.dirname(os.path.abspath(__file__)))

from Osmedeus.core import config
from Osmedeus.core import utils

'''
get local logs command by workspace
Expand All @@ -16,8 +17,7 @@ class Logs(Resource):
def get(self, workspace):
# get options depend on workspace
ws_name = utils.get_workspace(workspace=workspace)
options_path = str(BASE_DIR.joinpath(
'storages/{0}/options.json'.format(ws_name)))
options_path = config.OSMEDEUS_HOME + '/storages/{0}/options.json'.format(ws_name)

self.options = utils.reading_json(options_path)

Expand Down Expand Up @@ -51,8 +51,7 @@ def get(self, workspace):
@jwt_required
def post(self, workspace):
ws_name = utils.get_workspace(workspace=workspace)
options_path = str(BASE_DIR.joinpath(
'storages/{0}/options.json'.format(ws_name)))
options_path = config.OSMEDEUS_HOME + '/storages/{0}/options.json'.format(ws_name)

self.options = utils.reading_json(options_path)
module = request.args.get('module')
Expand Down
Loading

0 comments on commit 7fab204

Please sign in to comment.