kyoketsu-web.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. GNU GENERAL PUBLIC LICENSE
  3. Version 3, 29 June 2007
  4. kyoketsu, a Client-To-Client Network Enumeration System
  5. Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC
  6. Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  7. Everyone is permitted to copy and distribute verbatim copies
  8. of this license document, but changing it is not allowed.
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License,
  12. or (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. See the GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package main
  21. import (
  22. "database/sql"
  23. "flag"
  24. "fmt"
  25. "log"
  26. "os"
  27. "strings"
  28. "sync"
  29. kyoketsu "git.aetherial.dev/aeth/kyoketsu/pkg"
  30. )
  31. const dbfile = "sqlite.db"
  32. func main() {
  33. port := flag.Int("port", 8080, "Select the port to run the server on")
  34. addr := flag.String("ip", "", "Address to perform the initial network sweep on")
  35. flag.Parse()
  36. if len(strings.Split(*addr, "/")) < 2 {
  37. log.Fatal("You must pass an address that contains valid CIDR notation, i.e. '192.168.50.1/24'")
  38. }
  39. os.Remove(dbfile) // TODO: remove this once i add more smart interaction with the DB
  40. db, err := sql.Open("sqlite3", dbfile)
  41. if err != nil {
  42. log.Fatal(err)
  43. }
  44. hostsRepo := kyoketsu.NewSQLiteRepo(db)
  45. var wg sync.WaitGroup
  46. wg.Add(1)
  47. go kyoketsu.RunHttpServer(*port, hostsRepo)
  48. if err = hostsRepo.Migrate(); err != nil {
  49. log.Fatal(err)
  50. }
  51. log.Println("SUCCESS ::: SQLite database initiated, and open for writing.")
  52. hosts, err := kyoketsu.NetSweep(*addr, kyoketsu.RetrieveScanDirectives().Pairs)
  53. if err != nil {
  54. log.Fatal(err)
  55. }
  56. for i := range hosts {
  57. _, err := hostsRepo.Create(*hosts[i])
  58. if err != nil {
  59. log.Printf("Couldnt create new entry :( error: %s\n", err)
  60. }
  61. fmt.Println("SUCCESS ::: Host found. Adding to the database.")
  62. }
  63. wg.Wait()
  64. }