Return pointer to clientList item instead of copy
I've also fixed several issues such as the killswitch and RCE functions failing because of trying to use the struct identifier to access the clientList array
This commit is contained in:
parent
6c77b7d674
commit
0d839daf4e
|
@ -66,7 +66,7 @@ func saveClients(c *gin.Context) {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
as_json, _ := json.MarshalIndent(jsonClients, "", "\t")
|
as_json, _ := json.MarshalIndent(jsonClients, "", "\t")
|
||||||
f.Write(as_json)
|
f.Write(as_json)
|
||||||
log.Println("SUCCESS!")
|
log.Println("Success!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeClient(c *gin.Context) {
|
func removeClient(c *gin.Context) {
|
||||||
|
@ -76,7 +76,7 @@ func removeClient(c *gin.Context) {
|
||||||
c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err)
|
c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client, err := returnClient(intClientID)
|
client, id, err := returnClient(intClientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func removeClient(c *gin.Context) {
|
||||||
|
|
||||||
log.Printf("Removing client %v\n", intClientID)
|
log.Printf("Removing client %v\n", intClientID)
|
||||||
if len(clientList) != 1 {
|
if len(clientList) != 1 {
|
||||||
clientList = append(clientList[:intClientID], clientList[intClientID+1:]...)
|
clientList = append(clientList[:id], clientList[id+1:]...)
|
||||||
} else {
|
} else {
|
||||||
clientList = nil
|
clientList = nil
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func getCommands(c *gin.Context) {
|
||||||
c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err)
|
c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client, err := returnClient(intClientID)
|
client, _, err := returnClient(intClientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusNotFound, "Client not found")
|
c.String(http.StatusNotFound, "Client not found")
|
||||||
return
|
return
|
||||||
|
@ -134,16 +134,20 @@ func sendKillswitch(c *gin.Context) {
|
||||||
c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err)
|
c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_, id, err := returnClient(intClientID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if clientList[intClientID].IsOnline == false {
|
if clientList[id].IsOnline == false {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
inst := Instructions{
|
inst := Instructions{
|
||||||
IsKillswitch: true,
|
IsKillswitch: true,
|
||||||
}
|
}
|
||||||
clientList[intClientID].Instruct(inst)
|
clientList[id].Instruct(inst)
|
||||||
clientList[intClientID].IsOnline = false
|
clientList[id].IsOnline = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func execCMD(c *gin.Context) {
|
func execCMD(c *gin.Context) {
|
||||||
|
@ -154,7 +158,7 @@ func execCMD(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := returnClient(idInt)
|
client, _, err := returnClient(idInt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -166,7 +170,7 @@ func execCMD(c *gin.Context) {
|
||||||
|
|
||||||
command, _ := c.GetPostForm("cmd")
|
command, _ := c.GetPostForm("cmd")
|
||||||
|
|
||||||
out, err := sendCommand(client, command)
|
out, err := sendCommand(*client, command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Sprintf("Error happened executing command: %v\n", err)
|
e := fmt.Sprintf("Error happened executing command: %v\n", err)
|
||||||
c.String(http.StatusOK, e)
|
c.String(http.StatusOK, e)
|
||||||
|
|
|
@ -135,7 +135,7 @@ func sendCommand(client Client, command string) (Output string, err error) {
|
||||||
|
|
||||||
func Heartbeat(ID int) {
|
func Heartbeat(ID int) {
|
||||||
for {
|
for {
|
||||||
client, err := returnClient(ID)
|
client, _, err := returnClient(ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -160,14 +160,14 @@ func Heartbeat(ID int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func returnClient(ID int) (Client, error) {
|
func returnClient(ID int) (*Client, int, error) {
|
||||||
for _, v := range clientList {
|
for i, v := range clientList {
|
||||||
if v.ClientID == ID {
|
if v.ClientID == ID {
|
||||||
return v, nil
|
return &clientList[i], i, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := fmt.Errorf("Client not found\n")
|
err := fmt.Errorf("Client not found\n")
|
||||||
return Client{}, err
|
return &Client{}, -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServerMessageReceiver(conn net.Conn) (Response, error) {
|
func ServerMessageReceiver(conn net.Conn) (Response, error) {
|
||||||
|
|
Loading…
Reference in New Issue