Пример #1
0
def run(args: argparse.Namespace):
    quiet = args.quiet or False

    # -------------------------------------------------------------------------
    # Read info by stdin or parameter
    # -------------------------------------------------------------------------
    for has_stdin_pipe, has_stdout_pipe, json_line in read_stdin_lines():
        if not has_stdin_pipe:
            raise FileNotFoundError(
                "Input data must be entered as a UNIX pipeline. For example: "
                "'cat info.json | tool-name'")

        request_url, response = send_one_input_data(json_line, args)

        # You're being piped or redirected
        if has_stdout_pipe:

            # Info for next piped command
            sys.stdout.write(f"{json_line}\n")
            sys.stdout.flush()

        if not quiet:

            if has_stdout_pipe:
                console_print = sys.stderr.write
                console_flush = sys.stderr.flush
            else:
                console_print = sys.stdout.write
                console_flush = sys.stdout.flush

            console_print(f"[*] Request sent: '{request_url}'\n")
            console_flush()
Пример #2
0
def cli_analyze(args: argparse.Namespace):
    quiet = args.quiet

    # -------------------------------------------------------------------------
    # Read info by stdin or parameter
    # -------------------------------------------------------------------------
    for has_stdin_pipe, has_stdout_pipe, json_line in read_stdin_lines():
        if not has_stdin_pipe:
            raise FileNotFoundError(
                "Input data must be entered as a UNIX pipeline. For example: "
                "'cat info.json | tool-name'")

        rules = _load_rules(args)
        ignores = set(_load_ignore_ids(args))

        # this var contains JSON data in APICheck format
        content_json: dict = json.loads(json_line)

        found_issues = search_issues(content_json, rules, ignores)

        # You're being piped or redirected
        if has_stdout_pipe:

            #
            # Dump content as APICheck format
            #
            if not hasattr(content_json, "_meta"):
                content_json["_meta"] = {}

            if type(content_json["_meta"]) is not dict:
                content_json["_meta"] = {}

            content_json["_meta"]["sensitive-json"] = found_issues

            output_apicheck_data = json.dumps(content_json)

            # Info for next pip command
            sys.stdout.write(f"{output_apicheck_data}\n")
            sys.stdout.flush()

        # If not quiet also display in console. If has output pipe -> write
        # console into stderr, otherwise write in stdout
        if has_stdout_pipe:
            console_print = sys.stderr.write
            console_flush = sys.stderr.flush
        else:
            console_print = sys.stdout.write
            console_flush = sys.stdout.flush

        if not quiet:
            console_print(f"\n")

            for issue in found_issues:
                url = content_json['request']['url']
                console_print(f"{url}\n")
                console_print(f"{'-' * len(url)}\n\n")

                for x, y in issue.items():
                    console_print(f" > {x.ljust(15)}-> {y}\n")

                console_print(f"\n")
                console_flush()
Пример #3
0
def main():
    for is_stdin_pipe, is_stdout_pipe, line in read_stdin_lines():
        print("Input connected to pipe: ", is_stdin_pipe)
        print("Output  connected to pipe: ", is_stdout_pipe)
        print("Line read: ", line)