Codebase list osrframework / 2a83a63 debian / patches / initalize-config.patch
2a83a63

Tree @2a83a63 (Download .tar.gz)

initalize-config.patch @2a83a63raw · history · blame

Description: Initialize the config directory and files
 Upstream creates and initializes the ~/.config/OSRFramework in the
 setup.py. We disable this for Kali and create a function
 initialize_config_files to manage the creation and installation of all
 the required files, including maltego settings.
Author: Sophie Brun <[email protected]>
Last-Update: 2017-09-18
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/osrframework/utils/configuration.py
+++ b/osrframework/utils/configuration.py
@@ -22,8 +22,52 @@
 
 import os
 import sys
+import shutil
+import glob
 import osrframework.utils.errors as errors
 
+
+def initialize_config_files():
+    """
+        Function to create and initialize the configuration files and
+        directories.
+    """
+    LOCAL_CONFIG_DIR = getConfigPath()["appPath"]
+    LOCAL_CONFIG_TRANSFORMS_DIR = getConfigPath()["appPathTransforms"]
+    INSTALL_PATH = '/usr/lib/python2.7/dist-packages/osrframework'
+
+    # Copy default config file into osrframework local config
+    for dirconf in ["default", "plugins", "server"]:
+        shutil.copytree(os.path.join('/etc/osrframework',dirconf), os.path.join(LOCAL_CONFIG_DIR, dirconf))
+
+    # Create directory data
+    os.mkdir(getConfigPath()["appPathData"])
+
+    # Create directory Transforms before copy *.py files
+    os.mkdir(LOCAL_CONFIG_TRANSFORMS_DIR)
+
+    # Copy *.py files in transforms directory
+    for f in glob.glob(os.path.join(INSTALL_PATH, "transforms/[a-z]*.py")):
+        shutil.copy(f, LOCAL_CONFIG_TRANSFORMS_DIR)
+    for f in ["alias_generator.py", "entify.py", "phonefy.py", "searchfy.py", "mailfy.py", "usufy.py", "domainfy.py"]:
+        shutil.copy((os.path.join(INSTALL_PATH, f)), LOCAL_CONFIG_TRANSFORMS_DIR)
+
+    # Copy default config files for the user
+    for f in ["browser.cfg", "general.cfg"]:
+        shutil.copy((os.path.join(getConfigPath()["appPathDefaults"], f)),LOCAL_CONFIG_DIR)
+
+    # Configure maltego
+    LOCAL_CONFIG_DEFAULT_DIR = getConfigPath()["appPathDefaults"]
+    try:
+        import osrframework.transforms.lib.configure_maltego as maltego
+        maltego.configureMaltego(transformsConfigFolder=LOCAL_CONFIG_TRANSFORMS_DIR,
+            base=os.path.join(LOCAL_CONFIG_DEFAULT_DIR, "osrframework-maltego-settings"),
+            debug=False, backupPath=LOCAL_CONFIG_DEFAULT_DIR)
+    except Exception, e:
+        print "[!] The Maltego configuration file to use i3visio transforms could not be created and thus, cannot be used. Check the following error:"
+        print str(e)
+
+
 def changePermissionsRecursively(path, uid, gid):
     """
         Function to recursively change the user id and group id. It sets 700
@@ -84,9 +128,10 @@ def getConfigPath(configFileName = None)
     }
 
     # Creating them if they don't exist
-    for path in paths.keys():
-        if not os.path.exists(paths[path]):
-            os.makedirs(paths[path])
+#Don't create them in Kali: initialize_config_files() will create them
+#    for path in paths.keys():
+#        if not os.path.exists(paths[path]):
+#            os.makedirs(paths[path])
 
     return paths
 
@@ -100,6 +145,8 @@ def returnListOfConfigurationValues(util
     '''
 
     VALUES = {}
+    if not os.path.exists(getConfigPath()["appPath"]):
+        initialize_config_files()
 
     # If a api_keys.cfg has not been found, creating it by copying from default
     configPath = os.path.join(getConfigPath()["appPath"], "general.cfg")