Skip to content

Instantly share code, notes, and snippets.

@jfrantz1-r7
Created September 16, 2019 17:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfrantz1-r7/8f1fa7c1fdd3f4fb7aee6ff9e565f078 to your computer and use it in GitHub Desktop.
Save jfrantz1-r7/8f1fa7c1fdd3f4fb7aee6ff9e565f078 to your computer and use it in GitHub Desktop.
1) Unlock the database
Linux:
Change all the ‘md5’ entries to ‘trust’ in the /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata/pg_hba.conf file.
example: nano /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata/pg_hba.conf
ctrl + w to find all instances of md5
Windows:
In file explorer locate following directory
cd <install dir>\Program Files\rapid7\nexpose\nsc\nxpgsql\nxpdata\
Change all the ‘md5’ entries to ‘trust’
To Change Dir in Command Prompt
2) Reload database
Reloading the database config can only be done when no scans are in progress (not including the scan we are going to abort). To do this run the following command:
Linux:
sudo -u nxpgsql /opt/rapid7/nexpose/nsc/nxpgsql/pgsql/bin/pg_ctl -D /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata reload
Windows:
Services - Search for PostgreSQL - Restart Service
Output will be ‘server signaled’ Or just restart the Nexpose service.
<<< Steps 1 & 2 combined, sets pg_hba.conf to trust and reloads DB >>>
sudo -u nxpgsql -s sed -ibak 's/md5/trust/g' /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata/pg_hba.conf && sudo -u nxpgsql -s /opt/rapid7/nexpose/nsc/nxpgsql/pgsql/bin/pg_ctl -D /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata reload
3) Log into database
Linux:
cd /opt/rapid7/nexpose/nsc/nxpgsql/pgsql/bin
./psql -U nxpgsql -d nexpose
Windows:
cd <install dir>\Program Files\rapid7\nexpose\nsc\nxpgsql\pgsql\bin
psql.exe -U nxpgsql nexpose
You will get output similar to the following:
root@Server1337:/opt/rapid7/nexpose/nsc/nxpgsql/pgsql/bin# ./psql -nU nxpgsql nexpose
psql (9.4.1)
Type "help" for help.
nexpose=#
4) Search for stuck scans
Run the following command:
SET search_path = nxsilo_default;
SELECT * FROM scans WHERE status = 'U';
The affected scan ID should be in this list.
(We will use scan_id 91 as an example Scan_ID in the next series of commands. You can also determine the scan ID by hovering over the 'in progress' link in the browser for the hung or orphaned scan and looking at the bottom of the browser.)
5) Abort hung scans
UPDATE scans SET end_time = now(), status = 'A' WHERE scan_id = 91;
Repeat this process for all affected scan_id's. If you just want to abort all scans you can use the WHERE clause for dispatched scans (status = 'D') or running scans (status = 'U') to hit all dispatched or running scans at once.
This following command will Abort ALL scans
UPDATE scans SET end_time = now(), status = 'A' WHERE status = 'U';
To exit the database enter:
\q
6) Lock the database
Change all the ‘trust’ entries to ‘md5’ in the /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata/pg_hba.conf file.
example: nano /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata/pg_hba.conf
7) Reload the database
sudo -u nxpgsql /opt/rapid7/nexpose/nsc/nxpgsql/pgsql/bin/pg_ctl -D /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata reload
<< Steps 6 & 7 Combined, sets trust to md5 and reload database >>
sudo -u nxpgsql -s sed -ibak 's/trust/md5/g' /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata/pg_hba.conf && sudo -u nxpgsql -s /opt/rapid7/nexpose/nsc/nxpgsql/pgsql/bin/pg_ctl -D /opt/rapid7/nexpose/nsc/nxpgsql/nxpdata reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment