-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sgsullivan/cobra
Cobra
- Loading branch information
Showing
198 changed files
with
47,038 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/_exe |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
# befehl | ||
Run arbitrary commands over ssh in mass | ||
## Run arbitrary commands over ssh in mass | ||
|
||
- run payload.sh in PWD on IPs in targets.txt in PWD.. up to 100 at a time. | ||
- run payload.sh in PWD on hosts in targets file in PWD.. up to 2000 at a time. | ||
|
||
`./befehl -targets targets.txt -payload payload.sh -routines 100` | ||
`./befehl execute --hosts targets --payload payload.sh -routines 2000` | ||
|
||
Output of each payload run will be in the log directory (by default, its `$HOME/befehl/logs`) in a file named after the machine it ran on. | ||
The targets file should be a plain text file containing all hosts to run the payload on, separated by a new line. | ||
|
||
## Configuration | ||
|
||
You can configure befehl with a config file (~/.befehl.[toml|json|yaml]) any serialization format that upstream viper supports befehl supports for the config file. Valid configuration options: | ||
|
||
```toml | ||
[general] | ||
logdir = "/home/ssullivan/log-special" | ||
[auth] | ||
privatekeyfile = "/home/ssullivan/alt/.ssh/id_rsa" | ||
sshuser = "nonrootuser" | ||
``` | ||
|
||
These options should be self explanatory so I wont describe what each does here. | ||
|
||
## Building | ||
|
||
Once you have your Go environment setup, it should be as simple as cloning this git repo and running `make`. The resulting binary will be located at `_exe/befehl`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/sgsullivan/befehl" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var payload string | ||
var routines int | ||
var hostsList string | ||
|
||
var executeCmd = &cobra.Command{ | ||
Use: "execute", | ||
Short: "Execute the given payload against the given hosts list", | ||
Long: `Executes the given payload on each host in the hosts list. Hosts in the hosts | ||
list should be separated by a new line. You can control how many payloads run concurrently by | ||
passing the routines flag. | ||
By default befehl will use the private key in $HOME/.ssh/id_rsa. This can be overrode by | ||
specifying auth.privatekeyfile in ~/.befehl.[toml|json|yaml]. | ||
By default befehl will write the output of each payload for each host in $HOME/befehl/logs. This | ||
can be overrode by specifying general.logdir in ~/.befehl.[toml|json|yaml]. | ||
By default befehl will attempt to ssh as root. This can be overrode by specifying auth.sshuser | ||
in ~/.befehl.[toml|json|yaml]. | ||
Heres an example specifying all of the above mentioned options: | ||
[general] | ||
logdir = "/home/ssullivan/log-special" | ||
[auth] | ||
privatekeyfile = "/home/ssullivan/alt/id_rsa" | ||
sshuser = "eingeben" | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
for _, value := range []string{payload, hostsList} { | ||
if value == "" { | ||
panic("Missing payload, or hosts; see --help") | ||
} | ||
if routines == 0 { | ||
fmt.Printf("--routines not given, defaulting to 30..\n") | ||
routines = 30 | ||
} | ||
} | ||
befehl.Fire(&hostsList, &payload, &routines, Config) | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(executeCmd) | ||
executeCmd.Flags().StringVarP(&payload, "payload", "", "", "file location to the payload, which contains the commands to execute on the remote hosts") | ||
executeCmd.Flags().StringVarP(&hostsList, "hosts", "", "", "file location to hosts list, which contains all hosts (separated by newline) to run the payload on") | ||
executeCmd.Flags().IntVarP(&routines, "routines", "", 0, "maximum number of payloads that will run at once (defaults to 30)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"os" | ||
) | ||
|
||
var Config *viper.Viper | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "befehl", | ||
Long: `ausführen willkürliche Befehle über ssh in Masse | ||
Dieses Werkzeug sollte mit Vorsicht verwendet werden; gegeben das Macht angeboten.`, | ||
} | ||
|
||
func Execute() { | ||
if err := RootCmd.Execute(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
} | ||
|
||
func initConfig() { | ||
thisViper := viper.New() | ||
thisViper.SetConfigName(".befehl") | ||
configDir := os.Getenv("HOME") | ||
if os.Getenv("BEFEHL_CONFIG_DIR") != "" { | ||
configDir = os.Getenv("BEFEHL_CONFIG_DIR") | ||
} | ||
thisViper.AddConfigPath(configDir) | ||
if err := thisViper.ReadInConfig(); err != nil { | ||
fmt.Printf("Failed reading config (using defaults) [%s]: [%s]\n", thisViper.ConfigFileUsed(), err) | ||
} | ||
Config = thisViper | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/sgsullivan/befehl/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.