Loads preprocess function(s) from given script(s)
()
| 867 | kb.tamperFunctions.append(function) |
| 868 | |
| 869 | def _setPreprocessFunctions(): |
| 870 | """ |
| 871 | Loads preprocess function(s) from given script(s) |
| 872 | """ |
| 873 | |
| 874 | if conf.preprocess: |
| 875 | for script in re.split(PARAMETER_SPLITTING_REGEX, conf.preprocess): |
| 876 | found = False |
| 877 | function = None |
| 878 | |
| 879 | script = safeFilepathEncode(script.strip()) |
| 880 | |
| 881 | try: |
| 882 | if not script: |
| 883 | continue |
| 884 | |
| 885 | if not os.path.exists(script): |
| 886 | errMsg = "preprocess script '%s' does not exist" % script |
| 887 | raise SqlmapFilePathException(errMsg) |
| 888 | |
| 889 | elif not script.endswith(".py"): |
| 890 | errMsg = "preprocess script '%s' should have an extension '.py'" % script |
| 891 | raise SqlmapSyntaxException(errMsg) |
| 892 | except UnicodeDecodeError: |
| 893 | errMsg = "invalid character provided in option '--preprocess'" |
| 894 | raise SqlmapSyntaxException(errMsg) |
| 895 | |
| 896 | dirname, filename = os.path.split(script) |
| 897 | dirname = os.path.abspath(dirname) |
| 898 | |
| 899 | infoMsg = "loading preprocess module '%s'" % filename[:-3] |
| 900 | logger.info(infoMsg) |
| 901 | |
| 902 | if not os.path.exists(os.path.join(dirname, "__init__.py")): |
| 903 | errMsg = "make sure that there is an empty file '__init__.py' " |
| 904 | errMsg += "inside of preprocess scripts directory '%s'" % dirname |
| 905 | raise SqlmapGenericException(errMsg) |
| 906 | |
| 907 | if dirname not in sys.path: |
| 908 | sys.path.insert(0, dirname) |
| 909 | |
| 910 | try: |
| 911 | module = __import__(safeFilepathEncode(filename[:-3])) |
| 912 | except Exception as ex: |
| 913 | raise SqlmapSyntaxException("cannot import preprocess module '%s' (%s)" % (getUnicode(filename[:-3]), getSafeExString(ex))) |
| 914 | |
| 915 | for name, function in inspect.getmembers(module, inspect.isfunction): |
| 916 | try: |
| 917 | if name == "preprocess" and inspect.getargspec(function).args and all(_ in inspect.getargspec(function).args for _ in ("req",)): |
| 918 | found = True |
| 919 | |
| 920 | kb.preprocessFunctions.append(function) |
| 921 | function.__name__ = module.__name__ |
| 922 | |
| 923 | break |
| 924 | except ValueError: # Note: https://github.com/sqlmapproject/sqlmap/issues/4357 |
| 925 | pass |
| 926 |
no test coverage detected
searching dependent graphs…