Ejemplo n.º 1
0
func main() {
	flag.Parse()

	// ossec.conf
	configFile := getOssecConfPath(configfile)
	if configFile == "" {
		log.Errorf("ossec.conf not found. Please specify OSSEC install directory")
		return
	}

	// client.keys
	keysFile := getClientKeysPath(clientkeys)
	if keysFile == "" {
		log.Infof("client.keys not found, creating an empty file")
		createDefaultClientKeys()
	}

	key, err := register(manager, port)
	if err != nil {
		log.Error(err)
		return
	}

	isclient := false

	if !listen {
		isclient = true
	}

	if err := appendkey(keysFile, key, isclient); err != nil {
		log.Error(err)
		return
	}

	if err := writeconfig(configFile, manager); err != nil {
		log.Error(err)
		return
	}

	if restartService {
		if err := ossecsvc.Stop(); err != nil {
			log.Error(err)
		} else {
			log.Infof("Service Stopped")
		}

		if err := ossecsvc.Start(); err != nil {
			log.Error(err)
		} else {
			log.Infof("Service Started")
		}
	}
}
Ejemplo n.º 2
0
Archivo: xfcm.go Proyecto: 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))
		}
	}
}
Ejemplo n.º 3
0
Archivo: xfcm.go Proyecto: cabrel/xfcm
func init() {
	log.EnableDebugLogging()

	flag.StringVar(&add, "add", "", "Server to add to the connection manager")
	flag.StringVar(&connect, "connect", "", "Stored server to connect to")
	flag.StringVar(&domain, "domain", "", "AD domain")
	flag.StringVar(&ip, "ip", "", "Server ip address")
	flag.BoolVar(&list, "list", false, "List the stored servers")
	flag.BoolVar(&nla, "nla", true, "Use network level authentication (yes/no)")
	flag.BoolVar(&debug, "debug", false, "Enable debugging")
	flag.StringVar(&remove, "remove", "", "Server to remove from the connection manager")
	flag.StringVar(&username, "username", "", "AD username")
	flag.StringVar(&app, "app", "", "Remote Application")
	homePath, _ := syscall.Getenv("HOME")
	configFile = path.Join(homePath, ".xfcm")

	// check if the configuration file exists
	filePathExists, err := pathExists(configFile, true)

	// print if we encountered an error checking if the path existed
	if err != nil {
		log.Error(err)
	}

	// if the path didn't exist, create the file
	if !filePathExists {
		createConfigFile(configFile)
	}

}
Ejemplo n.º 4
0
Archivo: xfcm.go Proyecto: 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))
		}
	}
}
Ejemplo n.º 5
0
Archivo: xfcm.go Proyecto: cabrel/xfcm
func getViewport() (geom string) {
	// new X server connection
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Error(err)
	}

	// get root window
	root := xwindow.New(X, X.RootWin())

	// geometry of the root window
	rgeom, err := root.Geometry()
	if err != nil {
		log.Error(err)
	}

	// Get the rectangles for each of the active physical heads.
	// These are returned sorted in order from left to right and then top
	// to bottom.
	// But first check if Xinerama is enabled. If not, use root geometry.
	var heads xinerama.Heads
	if X.ExtInitialized("XINERAMA") {
		heads, err = xinerama.PhysicalHeads(X)
		if err != nil {
			log.Error(err)
		}
	} else {
		heads = xinerama.Heads{rgeom}
	}

	// looking for the first screen, position X: 0, Y: 0
	for _, head := range heads {
		if head.X() == 0 && head.Y() == 0 {
			screenWidth = head.Width()
			screenHeight = head.Height()
		}
	}

	geom = fmt.Sprintf("%dx%d", screenWidth-165, screenHeight-165)

	return geom
}
Ejemplo n.º 6
0
Archivo: xfcm.go Proyecto: cabrel/xfcm
func addServer(name, ip, username, domain string, useNla bool) {
	if ip == "" {
		log.Error("IP required to add server")
	}

	if username == "" {
		log.Error("Username required to add server")
	}

	if domain == "" {
		log.Error("Domain required to add server")
	}

	added := false

	server := RdpConnection{
		Name:     name,
		Ip:       ip,
		Username: username,
		Domain:   domain,
		Nla:      useNla,
	}

	for i, v := range config.Connections {
		if v.Name == name {
			config.Connections[i] = server
			added = true
			break
		}
	}

	if !added {
		config.Connections = append(config.Connections, server)
	}

	mData, _ := json.MarshalIndent(config, "", "    ")
	ioutil.WriteFile(configFile, mData, 0755)

	log.Print("Updated configuration file")
}
Ejemplo n.º 7
0
func init() {
	flag.StringVar(&manager, "manager", "", "Manager IP Address")
	flag.BoolVar(&listen, "listen", false, "Enables running in server mode")
	flag.BoolVar(&restartService, "controlsvc", false, "Enable or disable ossec-agent service control")
	flag.StringVar(&port, "port", "1515", "Manager port")

	h, err := os.Hostname()
	if err != nil {
		log.Error(err)
	}

	if h == "" {
		h = "localhost"
	}

	flag.StringVar(&agentname, "name", h, "Agent name")
	flag.StringVar(&configfile, "config", "", "Path to OSSEC config file (ossec.conf)")
	flag.StringVar(&clientkeys, "keyfile", "", "Path to OSSEC client keys file (client.keys)")
}
Ejemplo n.º 8
0
Archivo: xfcm.go Proyecto: cabrel/xfcm
func main() {
	var (
		option string
		name   string
	)

	// bind the command line flags
	flag.Parse()

	fileContents, err := ioutil.ReadFile(configFile)
	if err != nil {
		log.Error(err)
	}

	// if err := json.Unmarshal(fileContents, &servers); err != nil {
	// 	fmt.Println(servers)
	// 	log.Error(err)
	// }

	if err := json.Unmarshal(fileContents, &config); err != nil {
		log.Error(err)
		return
	}

	if add == "" && connect == "" && remove == "" && !list {
		log.Printf("Expected --add, --connect, --list or --remove")
		return
	}

	if add != "" {
		name = add
		option = "add"
	}

	if connect != "" {
		name = connect
		option = "connect"
	}

	if remove != "" {
		name = remove
		option = "remove"
	}

	if list == true {
		option = "list"
	}

	switch option {
	case "add":
		addServer(name, ip, username, domain, nla)
	case "connect":
		if app == "" {
			connectToServer(name)
		} else {
			connectToRemoteApp(app, name)
		}
	case "remove":
		//removeServer(name)
		log.Warn("remove not implemented")
	case "list":
		// for _, v := range servers {
		// 	fmt.Printf("%v (%v)\n", v.Name, v.Ip)
		// }

		// fmt.Printf("%v total\n", len(servers))
		for _, v := range config.Connections {
			fmt.Printf("%v (%v)\n", v.Name, v.Ip)
		}

		fmt.Printf("%v total\n", len(config.Connections))
	}
}