Skip to content

Commit

Permalink
Update Scanner: create excluder.py
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNinjaCyclone committed Jul 25, 2023
1 parent 333c209 commit ca3e5de
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 73 deletions.
4 changes: 2 additions & 2 deletions core/config/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def buildMode(self):
def buildHeaders(self):
pass

def buildExcludedModules(self):
def buildExcluder(self):
pass

def buildOutput(self):
Expand All @@ -41,7 +41,7 @@ def buildScanner(self):
scanner = ScannerConfig()
self.buildSharedData(scanner)
scanner.SetModuleConfig(self.buildModule())
scanner.SetExcludedModules(self.buildExcludedModules())
scanner.SetExcluder(self.buildExcluder())
scanner.SetCrawlerConfig(self.buildCrawler())
return scanner

Expand Down
60 changes: 1 addition & 59 deletions core/config/module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import os
from core.data import rockPATH

from core.config.base import Config


Expand Down Expand Up @@ -61,60 +60,3 @@ def GetModulesOptions(self):
return self.__modules_options


class ExcludedModules:
def __init__(self) -> None:
self.__excluded_modules = []

def excludeA(self, moduleName):
# Exclude only one module
if moduleName not in self.__excluded_modules:
moduleName += '.py' if not moduleName.endswith('.py') else str()
self.__excluded_modules.append(moduleName)


def excludeL(self, modules):
# Exclude list of modules
if not isinstance(modules, list):
raise TypeError("excludeL takes a list")

for module in modules:
self.excludeA(module)

def excludeAll(self):
# Exclude all of modules
modules = list()
path = os.path.join(rockPATH(), "modules")
files = os.listdir(path)
for file in files:
if file.endswith('.py'):
modules.append(file)

self.excludeL(modules)

def include(self, moduleName):
# Include one module
moduleName += '.py' if not moduleName.endswith('.py') else str()
self.__excluded_modules.remove(moduleName)

def includeA(self, moduleName):
# Include one module, with excluding all modules
self.excludeAll()
self.include(moduleName)

def includeL(self, modules):
# Include list of modules, with excluding all another modules
if not isinstance(modules, list):
raise TypeError("includeL takes a list")

self.excludeAll()

for module in modules:
self.include(module)

def excluded(self, moduleName):
# check if module excluded
return moduleName in self.__excluded_modules

def included(self, moduleName):
# check if module included
return not self.excluded(moduleName)
10 changes: 5 additions & 5 deletions core/config/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ScannerConfig(Config, CrawlerProxy):
def __init__(self) -> None:
self.__excluded_modules = None
self.__excluder = None
self.__module_config = None
Config.__init__(self)
CrawlerProxy.__init__(self)
Expand All @@ -22,11 +22,11 @@ def SetTarget(self, target):

Config.SetTarget(self, target)

def SetExcludedModules(self, excluded: ExcludedModules):
self.__excluded_modules = excluded
def SetExcluder(self, excluder):
self.__excluder = excluder

def GetExcludedModules(self):
return self.__excluded_modules
def GetExcluder(self):
return self.__excluder

def SetModuleConfig(self, module: ModuleConfig):
self.__module_config = module
Expand Down
62 changes: 62 additions & 0 deletions core/scanner/excluder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

import os
from core.data import rockPATH


class Excluder:

def __init__(self) -> None:
self.__excluded_modules = []

def excludeA(self, moduleName):
# Exclude only one module
if moduleName not in self.__excluded_modules:
moduleName += '.py' if not moduleName.endswith('.py') else str()
self.__excluded_modules.append(moduleName)

def excludeL(self, modules):
# Exclude list of modules
if not isinstance(modules, list):
raise TypeError("excludeL takes a list")

for module in modules:
self.excludeA(module)

def excludeAll(self):
# Exclude all of modules
modules = list()
path = os.path.join(rockPATH(), "modules")
files = os.listdir(path)
for file in files:
if file.endswith('.py'):
modules.append(file)

self.excludeL(modules)

def include(self, moduleName):
# Include one module
moduleName += '.py' if not moduleName.endswith('.py') else str()
self.__excluded_modules.remove(moduleName)

def includeA(self, moduleName):
# Include one module, with excluding all modules
self.excludeAll()
self.include(moduleName)

def includeL(self, modules):
# Include list of modules, with excluding all another modules
if not isinstance(modules, list):
raise TypeError("includeL takes a list")

self.excludeAll()

for module in modules:
self.include(module)

def excluded(self, moduleName):
# check if module excluded
return moduleName in self.__excluded_modules

def included(self, moduleName):
# check if module included
return not self.excluded(moduleName)
4 changes: 2 additions & 2 deletions core/scanner/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, config: ScannerConfig, scantype) -> None:
self.url = self.config.GetTarget()
self.headers = self.config.GetHeaders()
self.threads = self.config.GetThreads()
self.excludedM = self.config.GetExcludedModules()
self.excluder = self.config.GetExcluder()
self.rock_path = rockPATH()
self.scantype = scantype
self.LoadAllModules()
Expand Down Expand Up @@ -67,7 +67,7 @@ def start(self) -> ScanResults:
pass

def __loadmodules__(self, path):
for py in [f[:-3] for f in os.listdir(path) if f.endswith('.py') and self.excludedM.included(f)]:
for py in [f[:-3] for f in os.listdir(path) if f.endswith('.py') and self.excluder.included(f)]:
mod = __import__('.'.join(['modules', py]), fromlist=[py])
classes = [getattr(mod, x) for x in dir(mod) if isinstance(getattr(mod, x), type)]
for cls in classes:
Expand Down
11 changes: 6 additions & 5 deletions ui/cli/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import yaml, os.path
from core.config.fuzzer import FuzzerConfig
from core.config.jsanlyzer import JsAnalyzerConfig
from core.scanner.excluder import Excluder
from core.jsanalyzer.anlysis import ExtractorsLoader
from core.logger import Level
from core.utils import *
Expand Down Expand Up @@ -174,8 +175,8 @@ def buildMode(self):

return modecfg

def buildExcludedModules(self):
excluded_modules = ExcludedModules()
def buildExcluder(self):
excluder = Excluder()

if self.data.included_modules:
included = self.data.included_modules.split(',') if ',' in self.data.included_modules else [self.data.included_modules]
Expand All @@ -188,12 +189,12 @@ def buildExcludedModules(self):
excluded.append(module[1:])

if exclude_case:
excluded_modules.excludeL(excluded)
excluder.excludeL(excluded)

else:
excluded_modules.includeL(included)
excluder.includeL(included)

return excluded_modules
return excluder

def buildModulesOptions(self):
options = ModulesOptions()
Expand Down

0 comments on commit ca3e5de

Please sign in to comment.