@@ -16,9 +16,9 @@ def initialize(info = {})
16
16
'Name' => 'Windows \'Run As\' Using Powershell' ,
17
17
'Description' => %q( This module will start a process as another user using powershell. ) ,
18
18
'License' => MSF_LICENSE ,
19
- 'Author' => [ 'p3nt4' ] ,
20
- 'Platform' => [ 'win' ] ,
21
- 'SessionTypes' => [ 'meterpreter' ]
19
+ 'Author' => [ 'p3nt4' ] ,
20
+ 'Platform' => [ 'win' ] ,
21
+ 'SessionTypes' => [ 'meterpreter' ]
22
22
)
23
23
)
24
24
register_options (
@@ -41,28 +41,32 @@ def run
41
41
user = datastore [ 'user' ]
42
42
pass = datastore [ 'pass' ]
43
43
domain = datastore [ 'domain' ]
44
- exe = datastore [ 'exe' ] . gsub ( " \\ " , " \\ \\ \\ \\ " )
44
+ exe = datastore [ 'exe' ] . gsub ( '\\' , ' \\\\\\\\' )
45
45
inter = datastore [ 'interactive' ]
46
46
args = datastore [ 'args' ]
47
- path = datastore [ 'path' ] . gsub ( " \\ " , " \\ \\ \\ \\ " )
47
+ path = datastore [ 'path' ] . gsub ( '\\' , ' \\\\\\\\' )
48
48
channelized = datastore [ 'channelize' ]
49
49
hidden = datastore [ 'hidden' ]
50
+ if user . include? '\\'
51
+ domain = user . split ( '\\' ) [ 0 ]
52
+ user = user . split ( '\\' ) [ 1 ]
53
+ end
50
54
# Check if session is interactive
51
- if ( !session . interacting and inter )
52
- print_error ( " Interactive mode can only be used in a meterpreter console" )
55
+ if !session . interacting && inter
56
+ print_error ( ' Interactive mode can only be used in a meterpreter console' )
53
57
print_error ( "Use 'run post/windows/manage/run_as_psh USER=x PASS=X EXE=X' or 'SET INTERACTIVE false'" )
54
58
raise 'Invalide console'
55
59
end
56
60
# Prepare powershell script
57
61
scr = "$pw = convertto-securestring '#{ pass } ' -asplaintext -force; "
58
- scr << "$pp = new-object -typename System.Management.Automation.PSCredential -argumentlist '#{ domain } \\ \\ #{ user } ',$pw; "
62
+ scr << "$pp = new-object -typename System.Management.Automation.PSCredential -argumentlist '#{ domain } \\ #{ user } ',$pw; "
59
63
scr << "Start-process '#{ exe } ' -WorkingDirectory '#{ path } ' -Credential $pp"
60
- if ( args and args != '' )
64
+ if args && args != ''
61
65
scr << " -argumentlist '#{ args } ' "
62
66
end
63
67
if hidden
64
- print_status ( " Hidden mode may not work on older powershell versions, if it fails, try HIDDEN=false" )
65
- scr << " -WindowStyle hidden"
68
+ print_status ( ' Hidden mode may not work on older powershell versions, if it fails, try HIDDEN=false' )
69
+ scr << ' -WindowStyle hidden'
66
70
end
67
71
scr = " -c \" #{ scr } \" "
68
72
# Execute script
@@ -75,12 +79,12 @@ def run
75
79
'InMemory' => false ,
76
80
'UseThreadToken' => false )
77
81
print_status ( "Process #{ p . pid } created." )
78
- print_status ( "Channel #{ p . channel . cid } created." ) if ( p . channel )
82
+ print_status ( "Channel #{ p . channel . cid } created." ) if p . channel
79
83
# Process output
80
- if ( inter and p . channel )
84
+ if inter && p . channel
81
85
client . console . interact_with_channel ( p . channel )
82
86
elsif p . channel
83
- data = p . channel . read ( )
87
+ data = p . channel . read
84
88
print_line ( data ) if data
85
89
end
86
90
end
0 commit comments