firefox

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package firefox is responsible for running checks on Firefox.

Exported function(s): CookieFirefox, ExtensionFirefox, HistoryFirefox, PasswordFirefox

Index

Constants

This section is empty.

Variables

View Source
var OpenAndStatFile = func(tempSearch string) (mocking.File, int64, error) {

	fileInfo, err := os.Stat(tempSearch)
	if err != nil {

		return nil, 0, err
	}

	fileSize := fileInfo.Size()

	file, err := os.Open(filepath.Clean(tempSearch))
	if err != nil {

		return nil, 0, err
	}

	return mocking.Wrap(file), fileSize, nil
}

OpenAndStatFile is a function that opens a file and retrieves its size.

Parameters:

  • tempSearch: A string that represents the path to the file that should be opened.

Returns:

  • mocking.File: A File object that represents the opened file. This object is wrapped in a mocking layer for testing purposes.
  • int64: An integer that represents the size of the file in bytes.
  • error: An error object that encapsulates any errors that occurred during the execution of the function. If no errors occurred, this object is nil.

This function first calls the os.Stat function to retrieve the FileInfo object for the file. If an error occurs during this call, the function returns nil, 0, and the error. If no error occurs, the function retrieves the size of the file from the FileInfo object. The function then calls the os.Open function to open the file. If an error occurs during this call, the function returns nil, 0, and the error. If no error occurs, the function wraps the opened file in a mocking layer and returns the wrapped file, the size of the file, and nil for the error.

Functions

func CloseDatabase added in v0.2.0

func CloseDatabase(db *sql.DB)

CloseDatabase is a utility function that is utilized within the HistoryFirefox function. It is responsible for terminating the established database connection.

Parameters:

  • db (*sql.DB): Represents the active database connection that needs to be closed.

Returns: _

func CloseRows added in v0.2.0

func CloseRows(rows *sql.Rows)

CloseRows is a utility function used within the HistoryFirefox function. It is responsible for closing the result set of a database query.

Parameters:

  • rows (*sql.Rows): Represents the result set of a database query that needs to be closed.

This function does not return any value. However, if an error occurs during the closure of the result set, it will be logged for debugging purposes.

func CookieFirefox

func CookieFirefox() checks.Check

CookieFirefox inspects the cookies stored in the Firefox browser.

Parameters: None

Returns:

  • A checks.Check object representing the result of the check. The result contains a list of cookies stored in the Firefox browser. Each cookie is represented as a string that includes the name, host, and creation time of the cookie. If an error occurs during the check, the result will contain a description of the error.

This function works by locating the Firefox profile directory and copying the cookies.sqlite database to a temporary location. It then opens this database and queries it for the name, host, and creation time of each cookie. The results are returned as a list of strings, each string representing a cookie. If any error occurs during this process, such as an error copying the file or querying the database, this error is returned as the result of the check.

func ExtensionFirefox

func ExtensionFirefox() (checks.Check, checks.Check)

ExtensionFirefox inspects the extensions installed in the Firefox browser and checks for the presence of an ad blocker.

Parameters: None

Returns:

  • A checks.Check object representing the result of the check. The result contains a list of installed extensions in the Firefox browser. Each extension is represented as a string that includes the name, type, creator, and its active status.
  • A checks.Check object representing the result of the ad blocker check. The result is a boolean indicating whether an adblocker is installed or not.

This function works by locating the Firefox profile directory and opening the extensions.json file, which contains a list of all installed Firefox extensions. It decodes the JSON file into a struct and iterates over the addons in the struct. For each addon, it appends a string to the result list that includes the name, type, creator, and active status of the addon. It also checks if the addon is an ad blocker by calling the adblockerFirefox function with the addon's name. If an adblocker is found, it sets a boolean variable to true. The function returns two checks.Check objects: one with the list of extensions and one with the boolean indicating the presence of an adblocker.

func FormatTime added in v0.2.0

func FormatTime(lastVisitDate sql.NullInt64) string

FormatTime is a function that calls the FormatTime method of the current TimeFormatter.

func HistoryFirefox

func HistoryFirefox(profileFinder browserutils.FirefoxProfileFinder) checks.Check

HistoryFirefox inspects the user's browsing history in the Firefox browser for any visits to known phishing domains within the last week.

Parameters: profileFinder: An object that implements the FirefoxProfileFinder interface. It is used to find the Firefox profile directory.

Returns: The phishing domains that the user has visited in the last week and when they visited it

func PasswordFirefox

func PasswordFirefox() checks.Check

PasswordFirefox is a function that checks the passwords stored in the Firefox browser.

Parameters: None

Returns:

  • checks.Check: A Check object that encapsulates the results of the password check. The Check object includes a list of strings, where each string represents a saved password in the Firefox browser. If an error occurs during the password check, the Check object will encapsulate this error.

This function first determines the directory in which the Firefox profile is stored. It then opens the 'logins.json' file, which contains a list of all saved Firefox passwords. The function decodes the JSON file into a struct, and then iterates over the struct to extract the saved passwords. These passwords are added to the results, which are returned as a Check object. If an error occurs at any point during this process, it is encapsulated in the Check object and returned.

func ProcessQueryResults added in v0.2.0

func ProcessQueryResults(results []QueryResult) ([]string, error)

ProcessQueryResults is a function used within the HistoryFirefox function. It processes the results of a database query and identifies any visited phishing domains from the past week.

Parameters:

  • results []QueryResult: Represents the result set of a database query, which includes the URLs visited by the user in the past week and their respective visit dates.

Returns:

  • []string: A slice of strings, where each string represents a phishing domain that the user has visited in the past week, along with the time of the visit. If no visits to phishing domains are found, the slice will be empty.
  • error: An error object that encapsulates any error encountered during the processing of the query results. If no error occurred, this will be nil.

This function iterates over each row in the provided result set. For each row, it extracts the URL and last visit date, and checks the URL against a list of known phishing domains. If a match is found, a string is generated that includes the domain name and the time of the visit, and this string is added to the results. If an error occurs during this process, it is returned as well.

func Results added in v0.2.0

func Results(data []byte) string

Results is a utility function used within the SearchEngineFirefox function. It processes the output string from the decompressed 'search.json.mozlz4' file to identify the default search engine.

Parameters:

  • output (string): Represents the decompressed output string from the 'search.json.mozlz4' file.

Returns:

  • string: A string that represents the default search engine in the Firefox browser. If the defaultEngineId is empty, the function returns "Google". If the defaultEngineId matches known search engines (ddg, bing, ebay, wikipedia, amazon), the function returns the name of the matched search engine. If the defaultEngineId does not match any known search engines, the function returns "Other Search Engine".

This function first checks if the defaultEngineId in the output string is empty, which indicates that the default search engine is Google. If the defaultEngineId is not empty, the function checks if it matches the ids of other known search engines. If a match is found, the function returns the name of the matched search engine. If no match is found, the function returns "Other Search Engine".

func SearchEngineFirefox

func SearchEngineFirefox(profileFinder browserutils.FirefoxProfileFinder, boolMock bool, mockSource mocking.File, mockDest mocking.File) checks.Check

SearchEngineFirefox is a function that retrieves the default search engine used in the Firefox browser.

Parameters:

  • profileFinder: An object that implements the FirefoxProfileFinder interface. It is used to find the Firefox profile directory.
  • boolMock: A boolean value that determines whether to use the mockSource and mockDest files for testing.
  • mockSource: A mock file used for testing. It is used as the source file when boolMock is true.
  • mockDest: A mock file used for testing. It is used as the destination file when boolMock is true.

Returns:

  • checks.Check: A Check object that encapsulates the result of the search engine check. The Check object includes a string that represents the default search engine in the Firefox browser. If an error occurs during the check, the Check object will encapsulate this error.

This function first determines the directory in which the Firefox profile is stored. It then opens and reads the 'search.json.mozlz4' file, which contains information about the default search engine. The function decompresses the file, extracts the default search engine information, and returns this information as a Check object. If an error occurs at any point during this process, it is encapsulated in the Check object and returned.

Types

type QueryResult added in v0.2.0

type QueryResult struct {
	URL           string
	LastVisitDate sql.NullInt64
}

QueryResult is a struct used by the HistoryFirefox function to store the results of the query.

func QueryDatabase added in v0.2.0

func QueryDatabase(db *sql.DB) ([]QueryResult, error)

QueryDatabase is a helper function that is utilized within the HistoryFirefox function. It performs a query on the Firefox history database to retrieve the user's browsing history from the past week.

Parameters:

  • db (*sql.DB): Represents the active database connection that will be queried.

Returns:

  • *sql.Rows: The result set of the query, which includes the URLs visited by the user in the past week and their respective visit dates.
  • error: An error object that encapsulates any error encountered during the execution of the query. If no error occurred, this will be nil.

This function constructs a SQL query to select the URL and last visit date from the 'moz_places' table for entries where the last visit date is within the past week. The query is executed against the provided database connection, and the resulting rows are returned. If an error occurs during the execution of the query, it is returned as well.

type RealTimeFormatter added in v0.2.0

type RealTimeFormatter struct{}

RealTimeFormatter is a type that implements TimeFormatter using the real FormatTime function.

func (RealTimeFormatter) FormatTime added in v0.2.0

func (RealTimeFormatter) FormatTime(lastVisitDate sql.NullInt64) string

FormatTime is a helper function used by the processQueryResults function. It formats the last visit date of a website to a human-readable string.

Parameters:

  • lastVisitDate (sql.NullInt64): Represents the Unix timestamp of the last visit date of a website. This value can be null.

Returns: The last visit date of a website as a human-readable string

type TimeFormatter added in v0.2.0

type TimeFormatter interface {
	FormatTime(lastVisitDate sql.NullInt64) string
}

TimeFormatter is an interface that wraps the FormatTime function.

var TimeFormat TimeFormatter = RealTimeFormatter{}

TimeFormat timeFormatter is the TimeFormatter currently in use. It can be reassigned to a mock in tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL