-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuser.go
53 lines (40 loc) · 1.05 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"strings"
"time"
)
type ConsoleUser struct {
username []string
password []string
cookieJar *cookiejar.Jar
}
func (cu *ConsoleUser)Login() {
print_info("Authentication to the console with credentials")
time.Sleep(1)
options := cookiejar.Options{
}
jar, err := cookiejar.New(&options)
if err != nil {
panic_with_msg("Something went wront", err)
}
cu.cookieJar = jar
client := http.Client{Jar: cu.cookieJar}
resp, err := client.PostForm(fmt.Sprintf("http://%s:8080/login", TARGET), url.Values{
"password": cu.password,
"username" : cu.username,
})
if err != nil {
panic_with_msg("Unable to login somehow. Dunno why", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if strings.Contains(string(body), "forgot_password") {
panic_with_msg("Unable to login with credentials ! Something is wrong", err)
}
print_good("Successfully authenticated to the administrator interface ! ")
}