Commit 4f88e98f authored by Madhurendra 's avatar Madhurendra 🤹

[Fix] MongoDB compatibility, insert results in mongodb.

parent 4d5373e8
......@@ -5,13 +5,14 @@ import (
"context"
"flag"
"fmt"
"github.com/pkg/profile"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"os"
"os/exec"
"github.com/mongodb/mongo-go-driver/bson"
"github.com/mongodb/mongo-go-driver/mongo"
"github.com/pkg/profile"
"time"
)
var maxPtr *string
......@@ -27,7 +28,7 @@ func main() {
WelcomeMsg()
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")
outFile = flag.String("out-file", "out", "Name of file to which vulnerable IPs will be exported")
verbose = flag.Bool("v", false, "Display error msgs from non-vulnerable servers")
flag.Parse()
......@@ -76,9 +77,30 @@ func workDispatcher(ipAddr chan string, data chan string) {
}
}
func testIP(input string, data chan string) {
var client *mongo.Client = nil;
client, err := mongo.Connect(context.TODO(), "mongodb://"+input+":27017/test")
func getClient() (*mongo.Client) {
if (client == nil) {
var err error
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, err = mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
if err != nil {
return nil;
}
println("Created new connection...")
// Check the connection
err = client.Ping(context.TODO(), nil)
return client;
} else {
return client;
}
}
func testIP(input string, data chan string) {
clientOptions := options.Client().ApplyURI("mongodb://" + input + ":27017/test")
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
return
......@@ -88,7 +110,7 @@ func testIP(input string, data chan string) {
err = client.Ping(context.TODO(), nil)
//If we can list databases , we can read records to!
dbs, err := client.ListDatabaseNames(context.TODO(), bson.D{{}})
dbs, err := client.ListDatabases(context.TODO(), bson.D{{}})
if err != nil {
if *verbose {
......@@ -97,6 +119,35 @@ func testIP(input string, data chan string) {
}
} else {
local := getClient()
//var result = bson.D{}
//for db := range dbs.Databases {
//
//
//}
collection := local.Database("tik").Collection("mongohunter")
filter := bson.M{"_id": bson.M{"$eq": input}}
updateOp := options.UpdateOptions{}
updateOp.SetUpsert(true)
_, err := collection.UpdateOne(context.Background(),
filter,
bson.D{
{"$set", bson.D{
{"_id", input},
{"dbs", dbs.Databases},
{"totalSize", dbs.TotalSize},
{"updated", time.Now()},
}},
{"$setOnInsert", bson.D{
{"created", time.Now()},
}},
}, &updateOp)
if err != nil {
fmt.Print(err)
return
}
println("\r\033[K" + input + " is VULNERABLE:")
fmt.Printf("%v", dbs)
println("\n")
......
......@@ -39,12 +39,6 @@ https://github.com/robertdavidgraham/masscan
// WelcomeMsg prints welcome msg :D (Go-Lint compatabilty).
func WelcomeMsg() {
print(`
███╗ ███╗ ██████╗ ███╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███████╗████████╗███████╗██████╗
████╗ ████║██╔═══██╗████╗ ██║██╔════╝ ██╔═══██╗ ██╔══██╗██║ ██║██╔════╝╚══██╔══╝██╔════╝██╔══██╗
██╔████╔██║██║ ██║██╔██╗ ██║██║ ███╗██║ ██║█████╗██████╔╝██║ ██║███████╗ ██║ █████╗ ██████╔╝
██║╚██╔╝██║██║ ██║██║╚██╗██║██║ ██║██║ ██║╚════╝██╔══██╗██║ ██║╚════██║ ██║ ██╔══╝ ██╔══██╗
██║ ╚═╝ ██║╚██████╔╝██║ ╚████║╚██████╔╝╚██████╔╝ ██████╔╝╚██████╔╝███████║ ██║ ███████╗██║ ██║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
`)
......
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