forked from ropnop/kerbrute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 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,78 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/ropnop/kerbrute/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// bruteuserCmd represents the bruteuser command | ||
var bruteForceCmd = &cobra.Command{ | ||
Use: "bruteforce [flags] <user_pw_file>", | ||
Short: "Bruteforce username:password combos, from a file or stdin", | ||
Long: `Will read username and password combos from a file or stdin (format username:password) and perform a bruteforce attack using Kerberos Pre-Authentication by requesting at TGT from the KDC. Any succesful combinations will be displayed. | ||
If no domain controller is specified, the tool will attempt to look one up via DNS SRV records. | ||
A full domain is required. This domain will be capitalized and used as the Kerberos realm when attempting the bruteforce. | ||
WARNING: failed guesses will count against the lockout threshold`, | ||
Args: cobra.ExactArgs(1), | ||
PreRun: setupSession, | ||
Run: bruteForceCombos, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(bruteForceCmd) | ||
} | ||
|
||
func bruteForceCombos(cmd *cobra.Command, args []string) { | ||
combolist := args[0] | ||
stopOnSuccess = false | ||
|
||
combosChan := make(chan [2]string, threads) | ||
defer cancel() | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(threads) | ||
|
||
if err != nil { | ||
logger.Log.Error(err.Error()) | ||
return | ||
} | ||
defer file.Close() | ||
|
||
for i := 0; i < threads; i++ { | ||
go makeBruteComboWorker(ctx, combosChan, &wg) | ||
} | ||
scanner := bufio.NewScanner(file) | ||
|
||
start := time.Now() | ||
|
||
Scan: | ||
for scanner.Scan() { | ||
select { | ||
case <-ctx.Done(): | ||
break Scan | ||
default: | ||
comboline := scanner.Text() | ||
username, password, err := util.FormatComboLine(comboline) | ||
if err != nil { | ||
logger.Log.Debug("[!] Skipping: %q - %v", comboline, err.Error()) | ||
continue | ||
} | ||
combosChan <- [2]string{username, password} | ||
} | ||
} | ||
close(combosChan) | ||
wg.Wait() | ||
|
||
finalCount := atomic.LoadInt32(&counter) | ||
finalSuccess := atomic.LoadInt32(&successes) | ||
logger.Log.Infof("Done! Tested %d logins (%d successes) in %.3f seconds", finalCount, finalSuccess, time.Since(start).Seconds()) | ||
|
||
if err := scanner.Err(); err != nil { | ||
logger.Log.Error(err.Error()) | ||
} | ||
} |