بسم الله الرحمن الرحيم
This tool is designed to enumerate subdomains (uses crt.sh and Subfinder) and perform port scans (uses Naabu), with the results being reported to a Slack channel.
In addition, this tool is designed to be used with crontab (or any scheduler tools), allowing users to schedule scans periodically to ensure the user always receives information about new subdomains and their ports within a specified period of time.
- Fetch subdomains from crt.sh and subfinder.
- Validate and combine subdomain lists.
- Perform port scans using naabu.
- Report live hosts and new subdomains to a Slack channel.
- When rerun (manual or with a scheduler) after having results: it will fetch subdomains from crt.sh. If new subdomains are found, they will be added to the list and scanned with naabu. The results will also be sent to Slack.
Ensure the following dependencies are installed:
- Python 3.x
requestslibraryslack_sdklibrarysubfindernaabu
Ensure that subfinder and naabu can be called directly from the command line.
Note: You can install the required Python libraries using:
pip install requests slack_sdk-
Slack Configuration:
- Obtain a Slack API token (
https://api.slack.com/tutorials/tracks/getting-a-token) and a channel ID where notifications will be sent. - Replace
'AAAAAAAAA'with your Slack token. - Replace
'BBBBBBBBB'with your Slack channel ID. -
slack_token = 'AAAAAAAAA' channel_id = 'BBBBBBBBB' client = WebClient(token=slack_token)```
- Obtain a Slack API token (
-
JSON Configuration:
- Ensure you have a JSON configuration file (
config.json) with the port scan arguments within the same directory. - If you wish to place
config.jsonin another directory, don't forget to define the path in thewith open('config.json') as f:part. - The structure should include a
port_argumentsfield. - Change the value of
port_argumentsto match Naabu's arguments. - For example:
-p 33001,31337 -top-ports 100OR-p 1337,4444,31337,44444 - For detailed instructions, refer to the Naabu documentation at
https://github.com/projectdiscovery/naabu.
- Ensure you have a JSON configuration file (
-
Target Domains:
- Update the
target_domainslist with the domains you wish to monitor. - For a single target, put
['targetA.tld']in thetarget_domains. - For multiple targets, put
['targetA.tld', 'targetB.tld'].
- Update the
- Clone this repository:
git clone <repository-url>
cd <repository-name>-
Modify the script to include your Slack token, channel ID, the path to the config.json file, and the port value inside config.json.
-
Run the script:
python3 Sub-n-Port-Alert.pyYou can explain the usage with crontab as follows:
To use crontab to schedule scans periodically, user can add some changes such as
- Open crontab for editing with the command:
crontab -e- Add a crontab schedule entry with the following format:
# Run the script every day at 6 AM
0 6 * * * cd /path/to/your/script/directory && /usr/bin/python3 Sub-n-Port-Alert.pyPlease note that:
/path/to/your/script/directoryis the directory where the script is located.- Users need to navigate to this directory before running the script so that the output of the script will be in the same directory as the script.
-
Replace
/usr/bin/python3with the path to the Python 3 installation on the system and/path/to/Sub-n-Port-Alert.pywith the path to theSub-n-Port-Alert.pyscript on the OS. -
Be sure to save the changes and exit the crontab editor.
With this entry, the script will run automatically every day at 6 AM. Make sure to adjust the crontab schedule according to your preferences.
Simple logs are stored in a file named domain_monitor.log for each domain being monitored.
- This project is licensed under the MIT License.
- Free to use and modify - for good purposes.