mirror of
https://codeberg.org/ultimateplayer1999/Golang-phish-update.git
synced 2024-11-25 00:28:21 -05:00
Initial commit
This commit is contained in:
commit
a58a39d668
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -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.
|
2
README.md
Normal file
2
README.md
Normal file
@ -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
|
130
dbupdate.go
Normal file
130
dbupdate.go
Normal file
@ -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))
|
||||||
|
}
|
BIN
domain-db-updater
Executable file
BIN
domain-db-updater
Executable file
Binary file not shown.
8
go.mod
Normal file
8
go.mod
Normal file
@ -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
|
||||||
|
)
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -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=
|
Loading…
Reference in New Issue
Block a user