Commit 0da8bf08 authored by Yash Paliwal's avatar Yash Paliwal

Fixed memory leak issue

Added verbose flag
File write bugs fixed
parent d11e4a9c
# mongoBuster
Hunt Open MongoDB instances
Hunt Open MongoDB instances!
### Features
......@@ -31,4 +31,20 @@ Note: Run it with sudo as Masscan requires sudo access.
|Flag| Description |
|---|---|
|--max-rate= (int)| Defines maximum rate at which packets are generated and sent. Default is 1000.|
|--max-rate= (int)| Defines maximum rate at which packets are generated and sent. Default is 100.|
|--out-file= (string)| Name of file to which vulnerable IPs will be exported.|
|-v| Display error msgs from non-vulnerable servers|
### NOTE -
Using ridiculous values for ```max-rate``` flag like 10000+ will *most likely* bring down your own network infrastructure.
Recommended value is to start with ```--max-rate 500``` for consumer Gigabit routers.
#### Happy Hunting ;)
Final Note :- If you find bunch of insecure insances, ( which you will! ) You might wanna explore them with GUI tools like - [Robo 3t](https://robomongo.org/)
Please report these insecure instances to their respective owners, Lets make a safer internet together <3.
\ No newline at end of file
......@@ -4,14 +4,19 @@ import (
"bufio"
"context"
"flag"
"io/ioutil"
"fmt"
"log"
"os"
"os/exec"
"github.com/mongodb/mongo-go-driver/bson"
"github.com/mongodb/mongo-go-driver/mongo"
)
var maxPtr *string
var outFile *string
var verbose *bool
func main() {
ipAddr := make(chan string)
data := make(chan string)
......@@ -19,16 +24,22 @@ func main() {
masscanInstalled() // Check if masscan binary is installed.
WelcomeMsg()
maxPtr := flag.String("max-rate", "100", "Max rate at which packets will be sent")
outFile := flag.String("out-file", "IPs.log", "Name of file to which vulnerable IPs will be exported")
maxPtr = flag.String("max-rate", "100", "Max rate at which packets will be sent")
outFile = flag.String("out-file", "null", "Name of file to which vulnerable IPs will be exported")
verbose = flag.Bool("v", false, "Display error msgs from non-vulnerable servers")
flag.Parse()
go execMasscan(ipAddr, maxPtr)
go fileWriter(data, outFile)
go execMasscan(ipAddr)
if *outFile != "null" {
go fileWriter(data)
}
workDispatcher(ipAddr, data) // Dont call this func inside execMasscan coz exec.Command is a blocking statement.
}
func execMasscan(ipAddr chan string, maxPtr *string) {
func execMasscan(ipAddr chan string) {
cmd := exec.Command("/bin/bash", "-c", "sudo masscan -p27017 0.0.0.0/0 --exclude 255.255.255.255 --open-only --max-rate "+*maxPtr)
ok, err := cmd.StdoutPipe()
......@@ -74,27 +85,39 @@ func testIP(input string, data chan string) {
err = client.Ping(context.TODO(), nil)
//If we can list databases , we can read records to!
_, err = client.ListDatabaseNames(context.TODO(), bson.D{{}})
dbs, err := client.ListDatabaseNames(context.TODO(), bson.D{{}})
if err != nil {
print("\r\033[K" + input + ": ")
println(err.Error())
if *verbose {
print("\r\033[K" + input + ": ")
println(err.Error())
}
} else {
println("\r\033[K" + input + " is VULNERABLE")
println("")
data <- input
println("\r\033[K" + input + " is VULNERABLE:")
fmt.Printf("%v", dbs)
println("\n")
}
if *outFile != "null" {
data <- input
}
}
client.Disconnect(context.TODO())
return
}
func fileWriter(data chan string, outFile *string) {
func fileWriter(data chan string) {
for value := range data {
toWrite := []byte(value)
err := ioutil.WriteFile(*outFile, toWrite, 0644)
check(err)
f, err := os.OpenFile(*outFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()
if _, err = f.WriteString(value + "\n"); err != nil {
panic(err)
}
}
}
......@@ -6,13 +6,6 @@ import (
"regexp"
)
//Check for errors during file write
func check(e error) {
if e != nil {
panic(e)
}
}
//Masscan outputs some text along with IP addr, this function strips unwanted text.
func filterIP(input string) string {
numBlock := "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment