Projects STRLCPY flan Commits 8ba0a59e
🤬
  • new report formats and arguments to use them

  • Loading...
  • sw committed 4 years ago
    8ba0a59e
    1 parent ed03000e
  • ■ ■ ■ ■ ■
    Makefile
    skipped 2 lines
    3 3   
    4 4  container_name = flan_$(shell date +'%s')
    5 5  start :
    6  - docker run --name $(container_name) -v "$(pwd)/shared:/shared:Z" flan_scan
     6 + docker run --name $(container_name) -v "$(shell pwd)/shared:/shared:Z" flan_scan
     7 + 
     8 +md :
     9 + docker run --name $(container_name) -v "$(shell pwd)/shared:/shared:Z" -e format=md flan_scan
     10 + 
     11 +html :
     12 + docker run --name $(container_name) -v "$(shell pwd)/shared:/shared:Z" -e format=html flan_scan
     13 + 
     14 +json :
     15 + docker run --name $(container_name) -v "$(shell pwd)/shared:/shared:Z" -e format=json flan_scan
    7 16   
  • ■ ■ ■ ■ ■
    README.md
    skipped 25 lines
    26 26  $ make start
    27 27  ```
    28 28   
     29 +6. To use another output format:
     30 +```
     31 +$ make html
     32 +```
     33 +Additional supported formats are *md* (markdown), *html* and *json*.
     34 + 
    29 35  When the scan finishes you will find a Latex report of the summarizing the scan in `shared/reports`. You can also see the raw XML output from Nmap in `shared/xml_files`.
    30 36   
    31 37  <div>
    skipped 10 lines
    42 48  ```
    43 49  The `-oX` flag adds an XML version of the scan results to the `/shared/xml_files` directory and the `-oN -` flag outputs "normal" Nmap results to the console. The `-v1` flag increases the verbosity to 1 and the `-sV` flag runs a service detection scan (aside from Nmap's default port and SYN scans). The `--script=vulners/vulners.nse` is the script that matches the services detected with relevant CVEs.
    44 50   
    45  -Nmap also allows you to run UDP scans and to scan IPv6 addresses. To add these and other flags to Scan Flan's Nmap command after running `make build` run the container and pass in you Nmap flags like so:
     51 +Nmap also allows you to run UDP scans and to scan IPv6 addresses. To add these and other flags to Scan Flan's Nmap command after running `make build` run the container and pass in your Nmap flags like so:
    46 52   
    47 53  ```bash
    48 54  $ docker run -v $(pwd)/shared:/shared flan_scan <Nmap-flags>
    skipped 8 lines
    57 63   -v $(pwd)/shared:/shared \
    58 64   -e upload=<gcp or aws> \
    59 65   -e bucket=<bucket-name> \
     66 + -e format=<optional, one of: md, html or json> \
    60 67   flan_scan
    61 68  ```
    62 69   
    skipped 50 lines
  • ■ ■ ■ ■ ■ ■
    contrib/internal_types/flan_types.py
    skipped 21 lines
    22 22   self.vuln_type = vuln_type
    23 23   self.severity = severity
    24 24   
     25 + def to_dict(self):
     26 + return {
     27 + 'name': self.name,
     28 + 'type': self.vuln_type,
     29 + 'severity': self.severity,
     30 + 'severity_str': self.severity_str
     31 + }
     32 + 
    25 33   @staticmethod
    26 34   def convert_severity(severity: float) -> str:
    27 35   """
    skipped 24 lines
  • ■ ■ ■ ■ ■ ■
    contrib/report_builders/__init__.py
    1 1  from .report_builder import ReportBuilder
    2 2  from .latex_report_builder import LatexReportBuilder
    3 3  from .markdown_report_builder import MarkdownReportBuilder
     4 +from .json_report_builder import JsonReportBuilder
     5 +from .html_report_builder import JinjaHtmlReportBuilder
    4 6   
  • ■ ■ ■ ■ ■ ■
    contrib/report_builders/report_builder.py
    skipped 7 lines
    8 8   
    9 9   
    10 10  class ReportBuilder(metaclass=abc.ABCMeta):
    11  - @abc.abstractmethod
    12 11   def init_report(self, start_date: str, nmap_command: str):
    13 12   """
    14 13   Creates document section with report overview
    15 14   """
    16 15   pass
    17 16   
    18  - @abc.abstractmethod
    19 17   def build(self) -> Any:
    20 18   """
    21 19   :return: Ready report in specific format
    22 20   """
    23 21   pass
    24 22   
    25  - @abc.abstractmethod
    26 23   def add_vulnerable_section(self):
    27 24   """
    28 25   Adds header for section with vulnerable services
    29 26   """
    30 27   pass
    31 28   
    32  - @abc.abstractmethod
    33 29   def add_non_vulnerable_section(self):
    34 30   """
    35 31   Adds header for section with services without detected vulnerabilities
    36 32   """
    37 33   pass
    38 34   
    39  - @abc.abstractmethod
    40 35   def add_vulnerable_services(self, scan_results: Dict[str, ScanResult]):
    41 36   """
    42 37   Adds descriptions of vulnerable services
    43 38   """
    44 39   pass
    45 40   
    46  - @abc.abstractmethod
    47 41   def add_non_vulnerable_services(self, scan_results: Dict[str, ScanResult]):
    48 42   """
    49 43   Adds descriptions of services without detected vulnerabilities
    50 44   """
    51 45   pass
    52 46   
    53  - @abc.abstractmethod
    54 47   def initialize_section(self):
    55 48   """
    56 49   Adds begin of report section
    57 50   """
    58 51   pass
    59 52   
    60  - @abc.abstractmethod
    61 53   def add_ips_section(self):
    62 54   """
    63 55   Adds section with list of scanned ip addresses
    64 56   """
    65 57   pass
    66 58   
    67  - @abc.abstractmethod
    68 59   def add_ip_address(self, ip: str):
    69 60   """
    70 61   Adds IP-address to scanned addresses section
    71 62   """
    72 63   pass
    73 64   
    74  - @abc.abstractmethod
    75 65   def finalize(self):
    76 66   """
    77 67   Adds report footer
    78 68   """
    79 69   pass
    80 70   
    81  - @property
    82  - @abc.abstractmethod
    83  - def header(self) -> Any:
    84  - """
    85  - :return: Common document header for format type (e.g. for latex report)
    86  - """
    87  - pass
    88  - 
  • ■ ■ ■ ■ ■ ■
    kubernetes_templates/cron_job.yaml
    skipped 32 lines
    33 33   value: <GCP_OR_AWS>
    34 34   - name: bucket
    35 35   value: <BUCKET_NAME>
     36 + - name: format
     37 + value: <REPORT_FORMAT>
    36 38   
  • ■ ■ ■ ■ ■ ■
    kubernetes_templates/deployment.yaml
    skipped 34 lines
    35 35   value: <GCP_OR_AWS>
    36 36   - name: bucket
    37 37   value: <BUCKET_NAME>
     38 + - name: format
     39 + value: <REPORT_FORMAT>
    38 40   
  • ■ ■ ■ ■ ■ ■
    output_report.py
    skipped 3 lines
    4 4   
    5 5  from requests import Session
    6 6   
    7  -from contrib.descriptions import CveProjectProvider
     7 +from contrib.descriptions import CveProjectProvider, VulnDescriptionProvider
    8 8  from contrib.parsers import FlanXmlParser
    9  -from contrib.report_builders import ReportBuilder, LatexReportBuilder, MarkdownReportBuilder
     9 +from contrib.report_builders import ReportBuilder, LatexReportBuilder, MarkdownReportBuilder, JinjaHtmlReportBuilder, \
     10 + JsonReportBuilder
    10 11   
    11 12   
    12 13  def create_report(parser: FlanXmlParser, builder: ReportBuilder, nmap_command: str, start_date: str, output_writer: IO,
    skipped 13 lines
    26 27   
    27 28   builder.add_ips_section()
    28 29   for ip in ip_reader:
    29  - builder.add_ip_address(ip)
     30 + builder.add_ip_address(ip.strip())
    30 31   
    31 32   builder.finalize()
    32 33   output_writer.write(builder.build())
    skipped 5 lines
    38 39   return ' '.join(nmap_split)
    39 40   
    40 41   
    41  -def create_default_provider():
     42 +def create_default_provider() -> VulnDescriptionProvider:
    42 43   return CveProjectProvider(Session())
    43 44   
    44 45   
    45 46  def create_report_builder(report_type: str) -> ReportBuilder:
    46  - if report_type == 'latex':
    47  - return LatexReportBuilder(create_default_provider())
    48  - if report_type == 'md':
    49  - return MarkdownReportBuilder(create_default_provider())
    50  - raise NotImplementedError(report_type)
     47 + builder_map = {
     48 + 'tex': lambda p: LatexReportBuilder(p),
     49 + 'md': lambda p: MarkdownReportBuilder(p),
     50 + 'html': lambda p: JinjaHtmlReportBuilder(p),
     51 + 'json': lambda p: JsonReportBuilder(p)
     52 + }
     53 + 
     54 + if report_type not in builder_map:
     55 + raise NotImplementedError(report_type)
    51 56   
     57 + provider = create_default_provider()
     58 + return builder_map[report_type](provider)
    52 59   
    53  -def main(dirname: str, output_file: str, ip_file: str, report_type: str = 'latex'):
     60 + 
     61 +def main(dirname: str, output_file: str, ip_file: str, report_type: str = 'tex'):
    54 62   nmap_command = ''
    55 63   start_date = ''
    56 64   builder = create_report_builder(report_type)
    skipped 12 lines
    69 77   
    70 78   
    71 79  if __name__ == '__main__':
    72  - main(*sys.argv[1:4], report_type='latex')
     80 + report_format = os.getenv('format', 'tex')
     81 + main(*sys.argv[1:4], report_type=report_format)
    73 82   
  • ■ ■ ■ ■
    requirements.txt
    1 1  xmltodict==0.12.0
    2 2  google-cloud-storage==1.23.0
    3 3  boto3==1.12.15
    4  - 
     4 +Jinja2==2.10.3
  • ■ ■ ■ ■ ■
    run.sh
    skipped 9 lines
    10 10   mkdir /reports
    11 11  fi
    12 12   
     13 +report_extension="tex"
     14 + 
     15 +if [[ ! -z $format ]]
     16 +then
     17 + report_extension=$format
     18 +fi
     19 + 
    13 20  xml_dir=xml_files/$current_time
    14  -report_file=reports/report_$current_time.tex
     21 +report_file=reports/report_$current_time.$report_extension
    15 22   
    16 23  function upload {
    17 24   if [[ -z $upload ]]
    skipped 22 lines
    40 47  done < /shared/ips.txt
    41 48   
    42 49  python /output_report.py $root_dir$xml_dir $root_dir$report_file /shared/ips.txt
    43  -sed -i 's/_/\\_/g' $root_dir$report_file
    44  -sed -i 's/\$/\\\$/g' $root_dir$report_file
    45  -sed -i 's/#/\\#/g' $root_dir$report_file
    46  -sed -i 's/%/\\%/g' $root_dir$report_file
     50 +if [[ $report_extension = "tex" ]]
     51 +then
     52 + sed -i 's/_/\\_/g' $root_dir$report_file
     53 + sed -i 's/\$/\\\$/g' $root_dir$report_file
     54 + sed -i 's/#/\\#/g' $root_dir$report_file
     55 + sed -i 's/%/\\%/g' $root_dir$report_file
     56 +fi
    47 57  upload $report_file
    48 58   
Please wait...
Page is in error, reload to recover