20230829_154940.mp4
This is the overview of the architecture behind the subdomain fetching tool. The service is primarily built in Go with a React frontend. It interfaces with crt.sh to retrieve potential subdomains for a given domain and ensures uniqueness before presenting the results to the user.
- Main function: Entry point of the project.
- godotenv package: Loads assigned port from .env
- Mux package: Used for routing and setting up the server.
- Handler Functions:
- Main handler (/{domain}): To capture and route the domain requests.
- subDomainHandler: Processes the domain from the URL and passes it onward.
- GetDomainList function: Contacts crt.sh to get subdomain list.
- crtResponse struct: Structure for holding response from crt.sh.
- Unique subdomain map: Ensures uniqueness of subdomains.
- React Frontend: Provides UI to the user.
- Middleware: Enables CORS to allow React frontend to communicate with the backend.
- Program starts and enters the Main function.
- Mux sets the .env port and the /{domain} handler function.
- On a request, the handler function invokes subDomainHandler.
- subDomainHandler captures the domain from the URL and sends it to GetDomainList.
- GetDomainList contacts crt.sh and gets the subdomain list.
- The response from crt.sh is decoded into the crtResponse array.
- To ensure uniqueness, a loop checks the crtResponse array against a map and only unique values are added to a new array.
- The unique subdomain list is returned as a string array to subDomainHandler.
- subDomainHandler encodes the response as JSON.
- React frontend allows users to input domain and see results.
- Entry Point (Main function): The service begins its execution here. Routing and server setup are configured via the Mux package and the .env is loaded
- Server Setup with Mux: Mux initializes the .env port for the server and sets up route handlers.
- Domain Request Handling: When a user inputs a domain in the React frontend, a request is sent to the go server, which gets routed to the subDomainHandler function via the /{domain} endpoint.
- Fetching Subdomains: The domain from the request is captured and sent to the GetDomainList function, which contacts crt.sh to retrieve all subdomains associated with that domain.
- Decoding and Ensuring Uniqueness: The response from crt.sh is decoded into an array of type crtResponse. To ensure that the subdomains are unique, a map is utilized. As we iterate over the crtResponse array, any new and unique subdomains are added to a separate array.
- Response Preparation: The list of unique subdomains is converted into a JSON response and sent back to the React frontend.
- Displaying Results: The React frontend processes the JSON response and displays the unique subdomains to the user.
- CORS: To ensure smooth communication between our frontend and backend, a middleware named EnableCors has been added. This allows the React app to fetch data from our backend without CORS-related issues.
1. Clone the project
git cone git@github.com:Bostigger/subdomain-scanner.git
2. Navigate into the cloned folder
cd subdomain-scanner
3. Install the required go packages
go mod tidy
4. Setup your .env with the port variable
PORT="eg.8000"
5. Build the project
go build main.go
6. Run the main.go file
go run main.go
7. Navigate into the web directory
cd web
8. Install necessary packages
npm install
9. Run the react frontend
npm start
10. All set!
Happy hacking...
Technologies used in the project:
- Golang
- React
- Tailwind css
