rapid7/metasploit-framework

View on GitHub
modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb

Summary

Maintainability
C
1 day
Test Coverage

File junos_phprc_auto_prepend_file.rb has 317 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'unix_crypt'
require 'net/ssh'
require 'net/ssh/command_stream'

class MetasploitModule < Msf::Exploit::Remote
Severity: Minor
Found in modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb - About 3 hrs to fix

    Method initialize has 85 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def initialize(info = {})
        super(
          update_info(
            info,
            'Name' => 'Junos OS PHPRC Environment Variable Manipulation RCE',
    Severity: Major
    Found in modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb - About 3 hrs to fix

      Method create_php_session has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create_php_session
          create_sess = "<?php
      require('main.inc.php');
      global $loginPage;
      global $enterlsysname;
      Severity: Minor
      Found in modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb - About 1 hr to fix

        Method exploit has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def exploit
            case target['Type']
            when :nix_stream
              print_status("Attempting to break out of FreeBSD jail by changing the root user's password, establishing an SSH session and then rewriting the original root user's password hash to /etc/master.passwd.")
              print_warning("This requires a user is authenticated to the J-Web application in order to steal a session token or successfully create one, also 'ssh root-login' has to be set to 'allow' on the device. The option 'SET_ALLOW_ROOT_LOGIN' can be set to true to attempt to set this option.")
        Severity: Minor
        Found in modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb - About 1 hr to fix

          Method exploit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def exploit
              case target['Type']
              when :nix_stream
                print_status("Attempting to break out of FreeBSD jail by changing the root user's password, establishing an SSH session and then rewriting the original root user's password hash to /etc/master.passwd.")
                print_warning("This requires a user is authenticated to the J-Web application in order to steal a session token or successfully create one, also 'ssh root-login' has to be set to 'allow' on the device. The option 'SET_ALLOW_ROOT_LOGIN' can be set to true to attempt to set this option.")
          Severity: Minor
          Found in modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method get_encrypted_root_password has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_encrypted_root_password(php_session_id, csrf_token)
              post_data = "rs=get_cli_data&rsargs[]=getQuery&csrf_token=#{csrf_token}&key=1"
          
              res = send_request_cgi(
                'uri' => normalize_uri(target_uri.path, 'jsdm', 'ajax', 'cli-editor.php'),
          Severity: Minor
          Found in modules/exploits/freebsd/http/junos_phprc_auto_prepend_file.rb - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          There are no issues that match your filters.

          Category
          Status