Skip to content

Commit

Permalink
Let user choose the logon type
Browse files Browse the repository at this point in the history
  • Loading branch information
rkervella committed Nov 3, 2022
1 parent c91740d commit e9945d7
Show file tree
Hide file tree
Showing 11 changed files with 867 additions and 824 deletions.
1 change: 1 addition & 0 deletions client/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,7 @@ func BindCommands(con *console.SliverConsoleClient) {
f.String("u", "username", "", "username of the user to impersonate")
f.String("p", "password", "", "password of the user to impersonate")
f.String("d", "domain", "", "domain of the user to impersonate")
f.String("T", "logon-type", "LOGON_NEW_CREDENTIALS", "logon type to use")
f.Int("t", "timeout", defaultTimeout, "command timeout in seconds")
},
HelpGroup: consts.SliverWinHelpGroup,
Expand Down
10 changes: 10 additions & 0 deletions client/command/help/long-help.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,16 @@ The [[.Bold]]psexec[[.Normal]] command will use the credentials of the Windows u
`
makeTokenHelp = `[[.Bold]]Command:[[.Normal]] make-token -u USERNAME -d DOMAIN -p PASSWORD
[[.Bold]]About:[[.Normal]] Creates a new Logon Session from the specified credentials and impersonate the resulting token.
You can specify a custon Logon Type using the [[.Bold]]--logon-type[[.Normal]] flag, which defaults to [[.Bold]]LOGON32_LOGON_NEW_CREDENTIALS[[.Normal]].
Valid types are:
LOGON_INTERACTIVE
LOGON_NETWORK
LOGON_BATCH
LOGON_SERVICE
LOGON_UNLOCK
LOGON_NETWORK_CLEARTEXT
LOGON_NEW_CREDENTIALS
`

getEnvHelp = `[[.Bold]]Command:[[.Normal]] getenv [name]
Expand Down
25 changes: 21 additions & 4 deletions client/command/privilege/make-token.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ import (
"google.golang.org/protobuf/proto"
)

var logonTypes = map[string]uint32{
"LOGON_INTERACTIVE": 2,
"LOGON_NETWORK": 3,
"LOGON_BATCH": 4,
"LOGON_SERVICE": 5,
"LOGON_UNLOCK": 7,
"LOGON_NETWORK_CLEARTEXT": 8,
"LOGON_NEW_CREDENTIALS": 9,
}

// MakeTokenCmd - Windows only, create a token using "valid" credentails
func MakeTokenCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
session, beacon := con.ActiveTarget.GetInteractive()
Expand All @@ -38,6 +48,12 @@ func MakeTokenCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
username := ctx.Flags.String("username")
password := ctx.Flags.String("password")
domain := ctx.Flags.String("domain")
logonType := ctx.Flags.String("logon-type")

if _, ok := logonTypes[logonType]; !ok {
con.PrintErrorf("Invalid logon type: %s\n", logonType)
return
}

if username == "" || password == "" {
con.PrintErrorf("Pou must provide a username and password\n")
Expand All @@ -48,10 +64,11 @@ func MakeTokenCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
con.SpinUntil("Creating new logon session ...", ctrl)

makeToken, err := con.Rpc.MakeToken(context.Background(), &sliverpb.MakeTokenReq{
Request: con.ActiveTarget.Request(ctx),
Username: username,
Domain: domain,
Password: password,
Request: con.ActiveTarget.Request(ctx),
Username: username,
Domain: domain,
Password: password,
LogonType: logonTypes[logonType],
})
ctrl <- true
<-ctrl
Expand Down
2 changes: 1 addition & 1 deletion implant/sliver/handlers/handlers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func makeTokenHandler(data []byte, resp RPCResponse) {
return
}
makeTokenResp := &sliverpb.MakeToken{}
err = priv.MakeToken(makeTokenReq.Domain, makeTokenReq.Username, makeTokenReq.Password)
err = priv.MakeToken(makeTokenReq.Domain, makeTokenReq.Username, makeTokenReq.Password, makeTokenReq.LogonType)
if err != nil {
makeTokenResp.Response = &commonpb.Response{
Err: err.Error(),
Expand Down
8 changes: 6 additions & 2 deletions implant/sliver/priv/priv_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,12 @@ func impersonateUser(username string) (token windows.Token, err error) {

// MakeToken uses LogonUser to create a new logon session with the supplied username, domain and password.
// It then impersonates the resulting token to allow access to remote network resources as the specified user.
func MakeToken(domain string, username string, password string) error {
func MakeToken(domain string, username string, password string, logonType uint32) error {
var token windows.Token
// Default to LOGON32_LOGON_NEW_CREDENTIALS
if logonType == 0 {
logonType = windows.LOGON32_LOGON_NEW_CREDENTIALS
}

pd, err := windows.UTF16PtrFromString(domain)
if err != nil {
Expand All @@ -239,7 +243,7 @@ func MakeToken(domain string, username string, password string) error {
if err != nil {
return err
}
err = syscalls.LogonUser(pu, pd, pp, syscalls.LOGON32_LOGON_NEW_CREDENTIALS, syscalls.LOGON32_PROVIDER_DEFAULT, &token)
err = syscalls.LogonUser(pu, pd, pp, logonType, syscalls.LOGON32_PROVIDER_DEFAULT, &token)
if err != nil {
// {{if .Config.Debug}}
log.Printf("LogonUser failed: %v\n", err)
Expand Down
4 changes: 2 additions & 2 deletions protobuf/clientpb/client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protobuf/commonpb/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protobuf/dnspb/dns.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protobuf/rpcpb/services.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e9945d7

Please sign in to comment.