wpcli-vulnerability-scanner.php
/**
	 * Check wpvulndb.com for reports
	 * Total how many are relevant
	 *
	 * @param string       $slug Installed plugin/theme slug
	 * @param string       $version Installed plugin/theme version
	 * @param string|array $type The "thing" we're checking, "plugin" or "theme"
	 *                           If string, it's pluralized with an "s"
	 *                           If array, should be [ single, plural ]
	 *
	 * @return array Data array
	 */
Check wpvulndb.com for reports
Total how many are relevant



@return array Data array
Check wpvulndb . com for reports Total how many are relevant @return array Data array
private function _check_status( $slug, $version, $type ) {
		list( $singular_type, $plural_type ) = $this->_get_slugs( $type );
		$endpoint = $plural_type . '/' . $slug;
		$response = $this->call( $endpoint );
		$code = wp_remote_retrieve_response_code( $response );
		$body = wp_remote_retrieve_body( $response );
		$assoc_args = "assoc_args_{$singular_type}";
		$table_format = false;
		if ( ! isset( $this->{$assoc_args}['format'] ) || 'table' == $this->{$assoc_args}['format'] ) {
			$table_format = true;
		}
		$report = array();
		if ( 404 === $code ) {
			$report[] = array(
				'title' => "Error generating report for $slug",
			);
		} else {
			$vulndb = json_decode( $body );
			if ( isset( $vulndb->error ) ) {
				$report[] = array(
					'title' => "Error generating report for $slug",
				);
			}
			$vulnerabilities = array();
			if ( isset( $vulndb->$slug ) && isset( $vulndb->$slug->vulnerabilities ) ) {
				$vulnerabilities = $vulndb->$slug->vulnerabilities;
			}
			if ( is_array( $vulnerabilities ) && ! empty( $vulnerabilities ) ) {
				foreach ( $vulnerabilities as $k => $vuln ) {
										$reported_since = $this->obj_has_non_empty_prop( 'introduced_in', $vuln );
					$fixed_since = $this->obj_has_non_empty_prop( 'fixed_in', $vuln );
					if ( ! $fixed_since ) {
						$report[] = array(
							'id'            => $vuln->id,
							'title'         => $vuln->title,
							'fix'           => 'Not fixed',
							'introduced_in' => $reported_since ? $vuln->introduced_in : 'n/a',
							'action'        => 'watch',
						);
					} elseif (
						(
							! $reported_since
							&& version_compare( $version, $vuln->fixed_in, '<' )
						)
						||
						(
							$reported_since
							&& version_compare( $version, $vuln->introduced_in, '>=' )
							&& version_compare( $version, $vuln->fixed_in, '<' )
						)
					) {
						$report[] = array(
							'id'            => $vuln->id,
							'title'         => $vuln->title,
							'fix'           => "Fixed in {$vuln->fixed_in}",
							'introduced_in' => $reported_since ? $vuln->introduced_in : 'n/a',
							'action'        => 'update',
						);
					} else {
						unset( $vulnerabilities[ $k ] );
					}
				}
			}
			$total = count( $report );
			if ( $total <= 0 ) {
				$report[] = array(
					'title' => "No vulnerabilities reported for this version of $slug",
				);
			}
		}
		$data = array();
		$last_item = '';
		foreach ( $report as $stat ) {
			$stat = wp_parse_args(
				$stat,
				array(
					'id'            => '',
					'action'        => '',
					'fix'           => 'n/a',
					'introduced_in' => 'n/a',
				)
			);
			$name = ( $table_format && $slug == $last_item ? '' : $slug );
			if ( $table_format ) {
				switch ( $stat['action'] ) {
					case 'update':
						$name = WP_CLI::colorize( "%r$name%n" );
						break;
					case 'watch':
						$name = WP_CLI::colorize( "%y$name%n" );
						break;
					default;
				}
			}
			$data[]    = array(
				'name'              => $name,
				'slug'              => $slug,
				'installed version' => $version,
				'id'                => $stat['id'],
				'status'            => $stat['title'],
				'fix'               => $stat['fix'],
				'introduced in'     => $stat['introduced_in'],
				'action'            => $stat['action'],
			);
			$last_item = $slug;
		}
		return $data;
	}
private function _check_status ( $ slug , $ version , $ type ) { list ( $ singular_type , $ plural_type ) = $ this -> _get_slugs ( $ type ) ; $ endpoint = $ plural_type . '/' . $ slug ; $ response = $ this -> call ( $ endpoint ) ; $ code = wp_remote_retrieve_response_code ( $ response ) ; $ body = wp_remote_retrieve_body ( $ response ) ; $ assoc_args = " assoc_args_ { $ singular_type } " ; $ table_format = false ; if ( ! isset ( $ this -> { $ assoc_args } [ 'format' ] ) || 'table' == $ this -> { $ assoc_args } [ 'format' ] ) { $ table_format = true ; } $ report = array ( ) ; if ( 404 === $ code ) { $ report [ ] = array ( 'title' => " Error generating report for  $ slug " , ) ; } else { $ vulndb = json_decode ( $ body ) ; if ( isset ( $ vulndb -> error ) ) { $ report [ ] = array ( 'title' => " Error generating report for  $ slug " , ) ; } $ vulnerabilities = array ( ) ; if ( isset ( $ vulndb -> $ slug ) && isset ( $ vulndb -> $ slug -> vulnerabilities ) ) { $ vulnerabilities = $ vulndb -> $ slug -> vulnerabilities ; } if ( is_array ( $ vulnerabilities ) && ! empty ( $ vulnerabilities ) ) { foreach ( $ vulnerabilities as $ k => $ vuln ) { $ reported_since = $ this -> obj_has_non_empty_prop ( 'introduced_in' , $ vuln ) ; $ fixed_since = $ this -> obj_has_non_empty_prop ( 'fixed_in' , $ vuln ) ; if ( ! $ fixed_since ) { $ report [ ] = array ( 'id' => $ vuln -> id , 'title' => $ vuln -> title , 'fix' => 'Not fixed' , 'introduced_in' => $ reported_since ? $ vuln -> introduced_in : 'n/a' , 'action' => 'watch' , ) ; } elseif ( ( ! $ reported_since && version_compare ( $ version , $ vuln -> fixed_in , '<' ) ) || ( $ reported_since && version_compare ( $ version , $ vuln -> introduced_in , '>=' ) && version_compare ( $ version , $ vuln -> fixed_in , '<' ) ) ) { $ report [ ] = array ( 'id' => $ vuln -> id , 'title' => $ vuln -> title , 'fix' => " Fixed in  { $ vuln -> fixed_in } " , 'introduced_in' => $ reported_since ? $ vuln -> introduced_in : 'n/a' , 'action' => 'update' , ) ; } else { unset ( $ vulnerabilities [ $ k ] ) ; } } } $ total = count ( $ report ) ; if ( $ total <= 0 ) { $ report [ ] = array ( 'title' => " No vulnerabilities reported for this version of  $ slug " , ) ; } } $ data = array ( ) ; $ last_item = '' ; foreach ( $ report as $ stat ) { $ stat = wp_parse_args ( $ stat , array ( 'id' => '' , 'action' => '' , 'fix' => 'n/a' , 'introduced_in' => 'n/a' , ) ) ; $ name = ( $ table_format && $ slug == $ last_item ? '' : $ slug ) ; if ( $ table_format ) { switch ( $ stat [ 'action' ] ) { case 'update' : $ name = WP_CLI :: colorize ( " %r $ name %n " ) ; break ; case 'watch' : $ name = WP_CLI :: colorize ( " %y $ name %n " ) ; break ; default ; } } $ data [ ] = array ( 'name' => $ name , 'slug' => $ slug , 'installed version' => $ version , 'id' => $ stat [ 'id' ] , 'status' => $ stat [ 'title' ] , 'fix' => $ stat [ 'fix' ] , 'introduced in' => $ stat [ 'introduced_in' ] , 'action' => $ stat [ 'action' ] , ) ; $ last_item = $ slug ; } return $ data ; }
Check wpvulndb.com for reports
 Total how many are relevant
Check wpvulndb . com for reports Total how many are relevant
// let's analyse the report! // API has records for when was introduced ?
 // Check for fix version. // vulnerability that hasn't been fixed :( // vuln version, fix available. // If no records for when it was introduced, compare fixed version against current . // If have records for when it was introduced. // Check if using version with introduced vulnerablity. // Check if using version with vulnerablity fixed. // if installed plugin version is greater than a fixed version, // unset that vuln entry, we don't need it. // This leaves us with an array of relevant vulns // not currently used :/ // these keys must match the column headings in the formatter (extras ok).