|
|
@ -18,6 +18,7 @@ import ( |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"flag" |
|
|
|
"flag" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
@ -27,7 +28,7 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
Version string = "client v0.1.0" |
|
|
|
Version string = "client v0.1.1" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
@ -35,21 +36,25 @@ var ( |
|
|
|
serverAddr *string = flag.String("server", "http://localhost:13370/", "Set scheme://addr:port for receiving server") |
|
|
|
serverAddr *string = flag.String("server", "http://localhost:13370/", "Set scheme://addr:port for receiving server") |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The structure of the generalised per computer data that is identical to the server's
|
|
|
|
|
|
|
|
// representation
|
|
|
|
type Data struct { |
|
|
|
type Data struct { |
|
|
|
Hostname string `json:"hostname"` |
|
|
|
Hostname string `json:"hostname"` |
|
|
|
Username string `json:"username"` |
|
|
|
Username string `json:"username"` |
|
|
|
System map[string]string `json:"system"` |
|
|
|
System map[string]string `json:"system"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Prints notification on the state of things
|
|
|
|
func greeting() { |
|
|
|
func greeting() { |
|
|
|
fmt.Printf( |
|
|
|
fmt.Printf( |
|
|
|
`I'm sorry to inform you, but you've (intentionally or not) launched a spyware on your machine ! |
|
|
|
`I'm sorry to inform you, but you've (intentionally or not) launched a spyware on your machine! |
|
|
|
But rest assured, I will do no harm to your computer and am to withdraw if you would wish so. |
|
|
|
But rest assured, I will do no harm to your computer and am to withdraw if you would wish so. |
|
|
|
No data will be collected and sent without your permission.
|
|
|
|
No data will be collected and sent without your permission.
|
|
|
|
|
|
|
|
|
|
|
|
`) |
|
|
|
`) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Asks for permission to collect all kinds of data on the machine
|
|
|
|
func askForAllPerms() bool { |
|
|
|
func askForAllPerms() bool { |
|
|
|
fmt.Printf(`Would you grant me a permission to [system information; files lookup; ] |
|
|
|
fmt.Printf(`Would you grant me a permission to [system information; files lookup; ] |
|
|
|
(If no -> (optional) specify separate permissions afterwards) y/N: `) |
|
|
|
(If no -> (optional) specify separate permissions afterwards) y/N: `) |
|
|
@ -65,6 +70,7 @@ func askForAllPerms() bool { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Asks for permission to collect system information
|
|
|
|
func askForSystemInfo() bool { |
|
|
|
func askForSystemInfo() bool { |
|
|
|
fmt.Printf("\nWould you allow me to look around and collect some information about your computer ? [y/N]: ") |
|
|
|
fmt.Printf("\nWould you allow me to look around and collect some information about your computer ? [y/N]: ") |
|
|
|
var input string = "n" |
|
|
|
var input string = "n" |
|
|
@ -80,6 +86,7 @@ func askForSystemInfo() bool { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Asks whether a local copy of the whole collected data is needed
|
|
|
|
func localCopyNeeded() bool { |
|
|
|
func localCopyNeeded() bool { |
|
|
|
fmt.Printf("\nDo you want to save a local copy as well ? [y/N]: ") |
|
|
|
fmt.Printf("\nDo you want to save a local copy as well ? [y/N]: ") |
|
|
|
var input string = "n" |
|
|
|
var input string = "n" |
|
|
@ -113,6 +120,7 @@ func main() { |
|
|
|
var data Data |
|
|
|
var data Data |
|
|
|
data.System = nil |
|
|
|
data.System = nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Greet and ask for permissions
|
|
|
|
greeting() |
|
|
|
greeting() |
|
|
|
if askForAllPerms() { |
|
|
|
if askForAllPerms() { |
|
|
|
data.System = osutil.GetSystemInfo() |
|
|
|
data.System = osutil.GetSystemInfo() |
|
|
@ -123,6 +131,7 @@ func main() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if data.System == nil { |
|
|
|
if data.System == nil { |
|
|
|
|
|
|
|
// NOTICE! add new checks for new fields when they're added
|
|
|
|
fmt.Printf("\nNothing to send. Bailing out\n") |
|
|
|
fmt.Printf("\nNothing to send. Bailing out\n") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -135,24 +144,26 @@ func main() { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try to send collected information to the server
|
|
|
|
postBody := bytes.NewBuffer(dataJson) |
|
|
|
postBody := bytes.NewBuffer(dataJson) |
|
|
|
var retries uint8 = 0 |
|
|
|
var retries uint8 = 0 |
|
|
|
|
|
|
|
var response *http.Response |
|
|
|
for { |
|
|
|
for { |
|
|
|
if retries == 5 { |
|
|
|
if retries == 5 { |
|
|
|
fmt.Printf("\nFailed to send data\n") |
|
|
|
fmt.Printf("\nFailed to send data\n") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
response, err := http.Post(*serverAddr, "application/json", postBody) |
|
|
|
response, err = http.Post(*serverAddr, "application/json", postBody) |
|
|
|
if err != nil || response == nil { |
|
|
|
if err != nil || response == nil { |
|
|
|
// try to resend
|
|
|
|
// Try to resend
|
|
|
|
time.Sleep(time.Second * 5) |
|
|
|
time.Sleep(time.Second * 5) |
|
|
|
retries++ |
|
|
|
retries++ |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if response.StatusCode != http.StatusOK { |
|
|
|
if response.StatusCode != http.StatusOK { |
|
|
|
// try to resend
|
|
|
|
// Try to resend
|
|
|
|
time.Sleep(time.Second * 5) |
|
|
|
time.Sleep(time.Second * 5) |
|
|
|
retries++ |
|
|
|
retries++ |
|
|
|
continue |
|
|
|
continue |
|
|
@ -160,8 +171,18 @@ func main() { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("\nSuccesfully sent data. Thank you !\n") |
|
|
|
// Successfully sent
|
|
|
|
|
|
|
|
fmt.Printf("\nSuccesfully sent data\n") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Print thanks from the server
|
|
|
|
|
|
|
|
defer response.Body.Close() |
|
|
|
|
|
|
|
thanks, err := io.ReadAll(response.Body) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
fmt.Printf("\nFailed to read thanks message from the server. Better luck next time. Thank you !\n") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fmt.Printf("\n%s\n", thanks) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create local copy if needed
|
|
|
|
if localCopyNeeded() { |
|
|
|
if localCopyNeeded() { |
|
|
|
wdir, err := os.Getwd() |
|
|
|
wdir, err := os.Getwd() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -182,6 +203,7 @@ func main() { |
|
|
|
fmt.Printf("Saved to %s\n", copyPath) |
|
|
|
fmt.Printf("Saved to %s\n", copyPath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Don't close the console window for windows users
|
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
fmt.Scanln() |
|
|
|
fmt.Scanln() |
|
|
|
} |
|
|
|
} |
|
|
|