예제 #1
0
func register(host string, port string) (string, error) {
	// see https://github.com/ossec/ossec-hids/blob/master/src/os_auth/main-server.c#L380 for buffer
	// allocated from ossec-auth server
	buf := make([]byte, 2048)

	// TODO(rch): this shouldn't ignore the certificate
	tc := &tls.Config{
		InsecureSkipVerify: true,
	}

	conn, err := tls.Dial("tcp", net.JoinHostPort(host, port), tc)
	if err != nil {
		return "", fmt.Errorf("Error connecting to %s:%s. %v", host, port, err)
	}

	defer conn.Close()

	// timeout reading from the connection if we don't hear a response in 60 seconds
	err = conn.SetReadDeadline(time.Now().Add(time.Second * 60))
	if err != nil {
		return "", fmt.Errorf("timeout waiting for response from server: %v", err)
	}

	// send the request
	n, err := conn.Write([]byte(fmt.Sprintf("OSSEC A:'%s'\n", agentname)))
	if err != nil {
		return "", fmt.Errorf("Error writing to TCP connection: %v", err)
	}

	log.Debugf("Wrote %d bytes to TCP connection", n)

	n, err = conn.Read(buf)
	if err != nil {
		return "", fmt.Errorf("Error reading from TCP connection: %v", err)
	}

	log.Debugf("Read %d bytes to TCP connection", n)

	buffer := bytes.NewBuffer(nil)

	for _, v := range buf {
		if v != byte(0) {
			buffer.WriteByte(v)
		}
	}

	key := buffer.String()
	key = key[9:len(key)-3] + "\n"

	log.Debugf("Received response from ossec-authd: %s", key)
	return key, nil
}
예제 #2
0
func createDefaultClientKeys() error {
	p := filepath.Join(defaultPath, "client.keys")
	log.Debugf("Creating client.keys at %s", p)

	if _, err := os.Create(p); err != nil {
		return err
	}

	return nil
}
예제 #3
0
파일: xfcm.go 프로젝트: cabrel/xfcm
func connectToRemoteApp(name, server string) {
	for _, v := range config.Connections {
		if v.Name == server {
			fmt.Printf("Enter password for %v\\%v: ", v.Domain, v.Username)
			pass := string(gopass.GetPasswd())
			argv := []string{
				fmt.Sprintf("/u:%s", v.Username),
				fmt.Sprintf("/p:%s", pass),
				fmt.Sprintf("/d:%s", v.Domain),
				//        "/size:" + geom,
				fmt.Sprintf("/app:%s", name),
				"/cert-ignore",
				"+sec-ext",
				"+compression",
				fmt.Sprintf("/compression-level:%d", 2),
				"+smart-sizing",
				"+auto-reconnect",
				"+heartbeat",
				fmt.Sprintf("/t:%s", fmt.Sprintf("%s (%s)", v.Name, v.Ip)),
				"+clipboard",
				fmt.Sprintf("/v:%s", v.Ip),
			}

			//log.Infof("%#v", argv)
			cmd := exec.Command("xfreerdp", argv...)

			if !debug {
				err := cmd.Start()
				if err != nil {
					log.Error(err)
				}

				break
			}

			err := cmd.Run()
			if err != nil {
				log.Error(err)
			}

			b, err := cmd.CombinedOutput()
			if err != nil {
				log.Error(err)
			}

			log.Debugf("%s", string(b))
		}
	}
}
예제 #4
0
파일: xfcm.go 프로젝트: cabrel/xfcm
func connectToServer(name string) {
	// get the screen size
	geom := getViewport()

	for _, v := range config.Connections {
		if v.Name == name {
			fmt.Printf("Enter password for %v\\%v (%s): ", v.Domain, v.Username, v.Name)
			pass := string(gopass.GetPasswd())
			argv := []string{
				fmt.Sprintf("/u:%s", v.Username),
				"/p:" + pass,
				fmt.Sprintf("/d:%s", v.Domain),
				fmt.Sprintf("/size:%s", geom),
				"/t:" + fmt.Sprintf("%s (%s)", v.Name, v.Ip),
				fmt.Sprintf("/v:%s", v.Ip),
			}

			for _, o := range config.Options.Flags {
				argv = append(argv, o)
			}

			cmd := exec.Command("xfreerdp", argv...)

			if !debug {
				err := cmd.Start()
				if err != nil {
					log.Error(err)
				}

				break
			}

			if err := cmd.Run(); err != nil {
				log.Error(err)
				return
			}

			b, err := cmd.CombinedOutput()
			if err != nil {
				log.Error(err)
			}

			log.Debugf("%s", string(b))
		}
	}
}