Пример #1
0
def test_argv_parse_5(capsys):
    happend = False
    try:
        argv_parser.parse(["--test"], "--test")
    except ValueError:
        happend = True
    assert happend
Пример #2
0
def test_argv_parse_4(capsys):
    happend = False
    try:
        argv_parser.parse([], "")
    except NameError:
        happend = True
    assert happend
Пример #3
0
def test_argv_parse_2(capsys):
    happend = False
    try:
        argv_parser.parse(["--test", "hello"], "--test2")
    except NameError:
        happend = True
    assert happend
Пример #4
0
def interface_test():
    """Test argument parsing"""
    print("Testing argument parser ...")

    # TODO add tests for long options too

    parsed = argv_parser.parse(['checkpot.py', '-t', '172.17.0.2', '-O', '-p', '20-100,102'])
    expected = {'target': '172.17.0.2', 'scan_os': True, 'scan_level': 5, 'port_range': '20-100,102', 'fast': False,
                'brief': False}

    if parsed != expected:
        print("ERROR: parsed != expected")
        sys.exit(1)

    parsed = argv_parser.parse(['checkpot.py', '-t', '172.17.0.2', '-p', '20-1000'])
    expected = {'target': '172.17.0.2', 'scan_os': False, 'scan_level': 5, 'port_range': '20-1000', 'fast': False,
                'brief': False}

    if parsed != expected:
        print("ERROR: parsed != expected")
        sys.exit(1)

    parsed = argv_parser.parse(['checkpot.py', '-t', '172.17.0.2', '-O', '-l', '3'])
    expected = {'target': '172.17.0.2', 'scan_os': True, 'scan_level': 3, 'port_range': None, 'fast': False,
                'brief': False}

    if parsed != expected:
        print("ERROR: parsed != expected")
        sys.exit(1)

    parsed = argv_parser.parse(['checkpot.py', '-O', '-t', '172.17.0.2', '-l', '3', '-f'])
    expected = {'target': '172.17.0.2', 'scan_os': True, 'scan_level': 3, 'port_range': None, 'fast': True,
                'brief': False}

    if parsed != expected:
        print("ERROR: parsed != expected")
        sys.exit(1)

    parsed = argv_parser.parse(['checkpot.py', '-O', '-t', '172.17.0.2', '-l', '3'])
    expected = {'target': '172.17.0.2', 'scan_os': True, 'scan_level': 3, 'port_range': None, 'fast': False,
                'brief': False}

    if parsed != expected:
        print("ERROR: parsed != expected")
        sys.exit(1)

    print("OK")
Пример #5
0
def main(argv: List[str]):
    csv_location = None  # type: str
    try:
        csv_location = argv_parser.parse(argv, "--path")
    except:
        print_help()
        sys.exit(1)
        return

    # Create statistics
    oxygen_ms = entity.MeasurementStatistics()
    pulse_ms = entity.MeasurementStatistics()
    blood_pressure_systolic_ms = entity.MeasurementStatistics()
    blood_pressure_diastolic_ms = entity.MeasurementStatistics()
    statistics = entity.Statistics(oxygen_ms, pulse_ms,
                                   blood_pressure_systolic_ms,
                                   blood_pressure_diastolic_ms)
    number_of_measurements = 0
    try:
        recording = None  # type: entity.FileRecording
        try:
            recording = entity.FileRecording(csv_location).get_iterator()
        except:
            print_help()
            sys.exit(1)
            return

        while True:
            m = None  # type: entity.Measurement
            try:
                m = recording.__next__(make_invalid_measurement_missing=True)
            except StopIteration:
                break

            measurement_results = processor.processing_agent(m, statistics)
            result_string = output_parser.format_status(measurement_results)
            print(result_string, flush=True)
            logger.log(result_string)
            number_of_measurements += 1
            wait_on_new_measurement()
    except KeyboardInterrupt:
        # When someone wants to stop the program prematurely.
        pass
    statistics_string = output_parser.format_statistics(statistics)
    print(statistics_string, flush=True)
    logger.log(statistics_string)
    print(f"Processed {number_of_measurements} measurements")
Пример #6
0
def test_argv_parse_1(capsys):
    res = argv_parser.parse(["--test", "hello"], "--test")
    assert "hello" == res
Пример #7
0
def main(argv):
    """Entry point for the main application"""

    options = argv_parser.parse(argv)

    if options is None:
        sys.exit(2)

    print(
        "Checkpot - Honeypot Checker, Copyright (C) 2018  Vlad Florea\n"
        "This program comes with ABSOLUTELY NO WARRANTY; for details\n"
        "run `python checkpot.py --show w`.\n"
        "This is free software, and you are welcome to redistribute it\n"
        "under certain conditions; run `python checkpot.py --show c` for details.\n"
    )

    first_run()

    # run scan

    print("Running scan on " + options["target"])

    hp = Honeypot(options["target"], options["scan_os"])

    test_list = []

    print("Scanning ports ...\n")

    # collect data

    try:
        if options["port_range"]:
            hp.scan(port_range=options["port_range"],
                    fast=options["fast"])  # TODO restrict access to this?
        else:
            hp.scan()
    except ScanFailure as e:
        print("Scan failed: " + str(e))
        sys.exit(1)

    # run tests

    if options["scan_level"] > 0:

        test_list.append(direct_fingerprinting.DirectFingerprintTest())

        if options["scan_os"]:
            test_list.append(direct_fingerprinting.OSServiceCombinationTest())

        test_list.append(direct_fingerprinting.DefaultServiceCombinationTest())
        test_list.append(direct_fingerprinting.DuplicateServicesCheck())

    if options["scan_level"] > 1:
        test_list.append(default_ftp.DefaultFTPBannerTest())

        test_list.append(service_implementation.HTTPTest())
        test_list.append(default_http.DefaultWebsiteTest())
        test_list.append(default_http.DefaultGlastopfWebsiteTest())
        test_list.append(default_http.DefaultStylesheetTest())
        test_list.append(default_http.CertificateValidationTest())

        test_list.append(default_imap.DefaultIMAPBannerTest())

        test_list.append(default_smtp.DefaultSMTPBannerTest())
        test_list.append(service_implementation.SMTPTest())

        test_list.append(default_telnet.DefaultTelnetBannerTest())
        test_list.append(old_version_bugs.KippoErrorMessageBugTest())

        test_list.append(default_templates.DefaultTemplateFileTest())

    if options["scan_level"] > 2:
        pass

    tp = TestPlatform(
        test_list,
        hp,
    )

    tp.run_tests(verbose=True, brief=options["brief"])