File tree Expand file tree Collapse file tree 3 files changed +31
-8
lines changed
lib/rex/exploitation/powershell
spec/lib/rex/exploitation/powershell Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -37,12 +37,26 @@ def populate_params
37
37
# Get start of our block
38
38
idx = scan_with_index ( '(' , code [ start ..-1 ] ) . first . last + start
39
39
pclause = block_extract ( idx )
40
- # Keep lines which declare a variable of some class
41
- vars = pclause . split ( /\n |;/ ) . select { |e | e =~ /\] \$ \w / }
42
- vars . map! { |v | v . split ( '=' , 2 ) . first } . map ( &:strip )
40
+
41
+ func_regex = /\[ (\w +\[ \] )\] \$ (\w +)\s ?=|\[ (\w +)\] \$ (\w +)\s ?=|\[ (\w +\[ \] )\] \s +?\$ (\w +)\s +=|\[ (\w +)\] \s +\$ (\w +)\s ?=/i
42
+ #func_regex = /\[(\w+\[\])\]\.?\$(\w+)\s?=|\[(\w+)\]\s?\$(\w+)\s?=/i
43
+ matches = pclause . scan ( func_regex )
44
+
43
45
# Ignore assignment, create params with class and variable names
44
- vars . map { |e | e . split ( '$' ) } . each do |klass , name |
45
- @params << Param . new ( klass , name )
46
+ matches . each do |param |
47
+ klass = nil
48
+ name = nil
49
+ param . each do |value |
50
+ if value
51
+ if klass
52
+ name = value
53
+ @params << Param . new ( klass , name )
54
+ break
55
+ else
56
+ klass = value
57
+ end
58
+ end
59
+ end
46
60
end
47
61
end
48
62
end
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ module Powershell
8
8
class Param
9
9
attr_accessor :klass , :name
10
10
def initialize ( klass , name )
11
- @klass = klass . strip . gsub ( / \[ | \] | \s / , '' )
11
+ @klass = klass . strip
12
12
@name = name . strip . gsub ( /\s |,/ , '' )
13
13
end
14
14
Original file line number Diff line number Diff line change 35
35
36
36
[Parameter( Position = 1 )]
37
37
[Type]
38
- $ReturnType = [Void]
38
+ $ReturnType = [Void],
39
+
40
+ [String]$Parpy='hello',
41
+ [Integer] $puppy = 1,
42
+
43
+ [Array[]] $stuff = Array[],
39
44
)
40
45
41
46
$Domain = [AppDomain]::CurrentDomain
68
73
function . code . should eq example_function_with_params
69
74
function . to_s . include? ( "function #{ function_name } #{ example_function_with_params } " ) . should be_true
70
75
function . params . should be_kind_of Array
71
- function . params . length . should be == 2
76
+ function . params . length . should be == 5
77
+ function . params [ 0 ] . klass . should eq 'Type[]'
78
+ function . params [ 0 ] . name . should eq 'Parameters'
79
+ function . params [ 1 ] . klass . should eq 'Type'
80
+ function . params [ 1 ] . name . should eq 'ReturnType'
72
81
end
73
82
end
74
83
You can’t perform that action at this time.
0 commit comments