Skip to content

Fix various bugs #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions handlers/ClientPong.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ func handleClientPong(user *sessions.User, packet *packets.ClientPong) {

user.SetLastPongTimestamp()

packetProcs := packet.ParseProcessList()
parsed := packet.Parse()

if packetProcs == nil || len(packetProcs) == 0 {
// webhooks.SendAntiCheatProcessLog(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(), user.Info.AvatarUrl.String, []string{"NO PROCESSES PROVIDED"})
// log.Printf("[%v - %v] Sent a Pong packet without any process list\n", user.Info.Id, user.Info.Username)
checkProcesses(user, parsed.Processes)
checkLibraries(user, parsed.Libraries)
}

func checkProcesses(user *sessions.User, processes []packets.Process) {
if processes == nil || len(processes) == 0 {
return
}

dbProcs, err := db.FetchProcesses()
dbProcesses, err := db.FetchProcesses()

if err != nil {
log.Printf("Failed to fetch process from database - %v\n", err)
return
}

detected := detectProcesses(dbProcs, packetProcs)
detected := detectProcesses(dbProcesses, processes)

if len(detected) == 0 {
user.SetLastDetectedProcesses([]string{})
Expand All @@ -44,11 +47,29 @@ func handleClientPong(user *sessions.User, packet *packets.ClientPong) {
}

user.SetLastDetectedProcesses(detected)

webhooks.SendAntiCheatProcessLog(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(), user.Info.AvatarUrl.String, detected)

log.Printf("[%v - #%v] Detected %v flagged processes \n", user.Info.Username, user.Info.Id, len(detected))
}

func checkLibraries(user *sessions.User, libraries []string) {
if libraries == nil || len(libraries) == 0 {
return
}

if slices.Equal(libraries, user.GetLastLibraries()) {
return
}

user.SetLastLibraries(libraries)

webhooks.SendAntiCheatLibraries(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(),
user.Info.AvatarUrl.String, libraries)

log.Printf("[%v - #%v] Detected %v libraries \n", user.Info.Username, user.Info.Id, len(libraries))
}

// Goes through both the db processes and packet processes and checks if any are found
func detectProcesses(dbProcesses []*db.Process, packetProcesses []packets.Process) []string {
detected := make([]string, 0)
Expand Down
6 changes: 0 additions & 6 deletions handlers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ func HandleLogin(conn net.Conn, r *http.Request) error {
return logFailedLogin(conn, err)
}

err = checkSteamAppOwnership(data.Id)

if err != nil {
return logFailedLogin(conn, err)
}

user, err := db.GetUserBySteamId(data.Id)

if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions packets/ClientPong.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (

type ClientPong struct {
Packet
ProcessList string `json:"p"`
Data string `json:"p"`
}

type Processes struct {
type PongPacketData struct {
Processes []Process `json:"Processes"`
Libraries []string `json:"Libraries"`
}

type Process struct {
Expand All @@ -20,15 +21,15 @@ type Process struct {
FileName string `json:"FileName"`
}

func (p *ClientPong) ParseProcessList() []Process {
var data Processes
func (p *ClientPong) Parse() *PongPacketData {
var data PongPacketData

err := json.Unmarshal([]byte(p.ProcessList), &data)
err := json.Unmarshal([]byte(p.Data), &data)

if err != nil {
log.Println(err)
return nil
}

return data.Processes
return &data
}
19 changes: 19 additions & 0 deletions sessions/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type User struct {
// The last detected processes that were discovered on the user
lastDetectedProcesses []string

// Last libraries for the user
lastLibraries []string

// The current client status of the user
status *objects.ClientStatus

Expand Down Expand Up @@ -177,6 +180,22 @@ func (u *User) SetLastDetectedProcesses(processes []string) {
u.lastDetectedProcesses = processes
}

// GetLastLibraries Gets the user's last libraries
func (u *User) GetLastLibraries() []string {
u.Mutex.Lock()
defer u.Mutex.Unlock()

return u.lastLibraries
}

// SetLastLibraries Sets the user's last libraries
func (u *User) SetLastLibraries(libraries []string) {
u.Mutex.Lock()
defer u.Mutex.Unlock()

u.lastLibraries = libraries
}

// GetClientStatus Gets the current user client status
func (u *User) GetClientStatus() *objects.ClientStatus {
u.Mutex.Lock()
Expand Down
10 changes: 10 additions & 0 deletions webhooks/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func SendAntiCheatProcessLog(username string, userId int, url string, icon strin
SendAntiCheat(username, userId, url, icon, "Detected Processes", formatted)
}

func SendAntiCheatLibraries(username string, userId int, url string, icon string, libraries []string) {
formatted := ""

for i, library := range libraries {
formatted += fmt.Sprintf("**%v. %v**\n", i+1, library)
}

SendAntiCheat(username, userId, url, icon, "Detected Libraries", formatted)
}

// SendChatMessage Sends a chat message webhook to Discord
func SendChatMessage(webhook webhook.Client, senderUsername string, senderProfileUrl string, senderAvatarUrl, receiverName string, message string) {
if webhook == nil {
Expand Down
Loading