commit a58a39d668a8f91b4c7ff8d4c431a98926b5e89f Author: ultimateplayer1999 Date: Mon Jan 9 16:55:43 2023 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d783075 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Ultimateplayer1999 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4592c97 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +A free to use update tool which checks phish.sinking.yachts database. +It adds all domains found after custom domains are added. If not needed they can be commented or removed diff --git a/dbupdate.go b/dbupdate.go new file mode 100644 index 0000000..230b3b4 --- /dev/null +++ b/dbupdate.go @@ -0,0 +1,130 @@ +package main + +import ( + "database/sql" + "fmt" + "os" + "log" + "net/http" + "io/ioutil" + "encoding/json" + + "github.com/joho/godotenv" + + _ "github.com/go-sql-driver/mysql" +) + +func main() { + // Load environment variables from .env file + err := godotenv.Load() + if err != nil { + log.Fatal("Error loading .env file") + } + //Connect to the database + db, err := sql.Open("mysql", os.Getenv("DB_USER")+":"+os.Getenv("DB_PASS")+"@tcp("+os.Getenv("DB_HOST")+":"+os.Getenv("DB_PORT")+")/"+os.Getenv("DATABASE")) + if err != nil { + log.Fatal(err) + } + defer db.Close() + + // Verify that the connection is successful + err = db.Ping() + if err != nil { + log.Fatal(err) + } + + // Perform a cleanup on DB + deleter, err := db.Exec("DELETE FROM phish;") + if err != nil { + log.Fatal(err) + } + // Get the number of affected rows + rowsAffected, err := deleter.RowsAffected() + if err != nil { + log.Fatal(err) + } + fmt.Printf("Number of rows affected: %d\n", rowsAffected) + + // Perform a cleanup on DB + aiupdate, err := db.Exec("ALTER TABLE phish AUTO_INCREMENT = 0;") + if err != nil { + log.Fatal(err) + } + // Get the number of affected rows + rowsAffected, err = aiupdate.RowsAffected() + if err != nil { + log.Fatal(err) + } + fmt.Printf("Number of rows affected: %d\n", rowsAffected) + + // Add local records first + insert1, err := db.Exec("INSERT INTO phish (Domain, Reporter, Evidence) VALUES ('iriseperiplo.info', 'Henk', 'https://www.virustotal.com/gui/url/318ac29af0001f6678efdd94c16d3225d78369123ebbbe5f50387b208e0ac523?nocache=1');") + insert2, err2 := db.Exec("INSERT INTO phish (Domain, Reporter, Evidence) VALUES ('storage.com', 'Henk', 'https://www.virustotal.com/gui/url/92fef9276cd4c0433171aac2fe92d140df069ff99d724c850ca1d3ccbdd0ae9f?nocache=1');") + if err != nil { + log.Fatal(err) + } + if err2 != nil { + log.Fatal(err) + } + // Get the number of affected rows + rowsAffected, err = insert1.RowsAffected() + if err != nil { + log.Fatal(err) + } + fmt.Printf("Number of rows affected: %d\n", rowsAffected) + // Get the number of affected rows + rowsAffected, err = insert2.RowsAffected() + if err != nil { + log.Fatal(err) + } + fmt.Printf("Number of rows affected: %d\n", rowsAffected) + + // Define name for use later + // name := os.Getenv("USER_OR_BOTNAME") + + // Make an HTTP request to phish.sinking.yachts alldomains endpoint + req, err := http.NewRequest("GET", "https://phish.sinking.yachts/v2/all", nil) + if err != nil { + log.Fatal(err) + } + req.Header.Set("X-Identity", "ultimatebot db updater via Golang") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + + fmt.Println("Status code: ", resp.StatusCode) + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + var data []string + err = json.Unmarshal(body, &data) + if err != nil { + log.Fatal(err) + } + + // Initialize a variable to keep track of the total number of rows affected + var totalRowsAffected int64 + + for _, element := range data { + // fmt.Println(element) + // Add domains + inserter, err := db.Exec("INSERT INTO phish (Domain) VALUES (?)", element) + if err != nil { + log.Fatal(err) + } + + rowsAffected, err := inserter.RowsAffected() + if err != nil { + log.Fatal(err) + } + + totalRowsAffected += rowsAffected + } + fmt.Printf("Total number of rows affected: %d\n", totalRowsAffected) + // dummy + // fmt.Println("Data: ", string(body)) +} \ No newline at end of file diff --git a/domain-db-updater b/domain-db-updater new file mode 100755 index 0000000..3dfc380 Binary files /dev/null and b/domain-db-updater differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6f44084 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module skywolf.nl/domain-db-updater + +go 1.19 + +require ( + github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/joho/godotenv v1.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7ffa482 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= +github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=