> For the complete documentation index, see [llms.txt](https://hacker-mind.gitbook.io/hacker-mind/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacker-mind.gitbook.io/hacker-mind/penetration-testing-notes/import-nessus-to-metasploit.md).

# Import Nessus to Metasploit

1. Check database postgresql

```
sudo systemctl status postgresql
sudo systemctl start postgresql
```

2. Initialization the db

```
sudo msfdb init
```

3. open metasploit

```
msfconsole
```

<figure><img src="/files/THzuDAhFsLIr7zMw3mSy" alt=""><figcaption></figcaption></figure>

4. Check db\_status

```
db_status
```

<figure><img src="/files/g96IdBfrLSn9KxzQ5X6t" alt=""><figcaption></figcaption></figure>

5. Import nessus file.

```
db_import <nessus file name>
```

<figure><img src="/files/ioiKsTuYWZLLJG42v7kn" alt=""><figcaption></figcaption></figure>

6. Make sure you cover all targets. then export vulns into a txt file from meterpreter:

```
vulns -o EntityName_vulns_result.txt
```

7. Summary the findings:

```
#!/bin/bash
# ./recap_findings.sh input.txt


SUMMARY_FILE="summary_report.txt"
BLUE="\e[34m"  # Blue color for findings name
RESET="\e[0m"  # Reset color

# Function to display help
show_help() {
    echo "Usage:"
    echo "  $0 <file1.txt> <file2.txt> ...   # Process Nessus result files"
    echo "  $0 search <keyword>              # Search findings by keyword"
    echo "  $0 --help                        # Show this help message"
    exit 0
}

# Function to validate file format
validate_file() {
    local file="$1"
    local first_line
    first_line=$(head -n 1 "$file")

    if [[ "$first_line" != "Timestamp,Host,Name,References" ]]; then
        echo "❌ Error: File '$file' has an invalid format!"
        return 1
    fi
    return 0
}

# Handle help request
if [[ "$1" == "--help" ]]; then
    show_help
fi

# If searching for findings
if [[ "$1" == "search" ]]; then
    if [ ! -f "$SUMMARY_FILE" ]; then
        echo "❌ No summary file found! Run the script with Nessus files first."
        exit 1
    fi

    SEARCH_QUERY="${@:2}"
    if [ -z "$SEARCH_QUERY" ]; then
        echo "❌ Please provide a keyword to search."
        exit 1
    fi

    echo "🔎 Searching for '$SEARCH_QUERY'..."
    
    # Properly highlight findings name in BLUE
    grep -i "🔹 .*${SEARCH_QUERY}.*" -A 2 "$SUMMARY_FILE" | sed '/^--$/d' | \
        sed -E "s/(🔹 [^:]+)/\x1B[34m\1\x1B[0m/g"

    exit 0
fi

# Ensure at least one input file
if [ "$#" -lt 1 ]; then
    echo "❌ Usage: $0 <file1.txt> <file2.txt> ... OR: $0 search <keyword>"
    exit 1
fi

# Validate all input files before processing
VALID_FILES=()
for file in "$@"; do
    if [[ ! -f "$file" ]]; then
        echo "❌ Error: File '$file' not found!"
        exit 1
    fi

    if validate_file "$file"; then
        VALID_FILES+=("$file")
    else
        echo "❌ Skipping invalid file: $file"
    fi
done

# If no valid files, do not overwrite the summary
if [ "${#VALID_FILES[@]}" -eq 0 ]; then
    echo "❌ No valid input files. Summary report is unchanged."
    exit 1
fi

# Ensure the output file is empty before writing
> "$SUMMARY_FILE"

echo "📊 Processing Nessus result files..."

awk -F ',' '
NR == 1 { next }  # Skip header row
{
    gsub(/"/, "", $0);  # Remove double quotes

    host = $2;
    vuln_name = $3;

    if (vuln_name && host) {
        findings[vuln_name][host] = 1;
    }
}
END {
    print "=== Vulnerability Summary ===\n" > "'$SUMMARY_FILE'";
    for (vuln in findings) {
        printf "🔹 %s\n   Affected Hosts: ", vuln >> "'$SUMMARY_FILE'";
        first = 1;
        for (host in findings[vuln]) {
            if (!first) printf ", " >> "'$SUMMARY_FILE'";
            printf "%s", host >> "'$SUMMARY_FILE'";
            first = 0;
        }
        printf "\n\n" >> "'$SUMMARY_FILE'";
    }
}
' "${VALID_FILES[@]}"

echo "✅ Summary Report saved to $SUMMARY_FILE"
```

If meterpreter problem memory blah blah:

{% hint style="info" %}
Reinstall meterpreter
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacker-mind.gitbook.io/hacker-mind/penetration-testing-notes/import-nessus-to-metasploit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
