|
10 | 10 | function Find-4624Logons
|
11 | 11 | {
|
12 | 12 |
|
| 13 | +<# |
| 14 | +
|
| 15 | +multiline_comment |
| 16 | +
|
| 17 | +#> |
| 18 | +\r\n\r\n\r\n |
| 19 | +\r\n |
| 20 | +
|
| 21 | +lots \t of whitespace |
| 22 | +
|
| 23 | +\n\n\n\n\n |
| 24 | +\n\n |
| 25 | +
|
| 26 | +
|
| 27 | +# single_line_comment1 |
| 28 | + # single_line_comment2 |
| 29 | + # |
| 30 | + # single_line_comment3 |
13 | 31 | if (-not ($NewLogonAccountDomain -cmatch \"NT\\sAUTHORITY\" -or $NewLogonAccountDomain -cmatch \"Window\\sManager\"))
|
14 | 32 | {
|
15 | 33 | $Key = $AccountName + $AccountDomain + $NewLogonAccountName + $NewLogonAccountDomain + $LogonType + $WorkstationName + $SourceNetworkAddress + $SourcePort
|
|
48 | 66 | """
|
49 | 67 | function Find-4624Logons
|
50 | 68 | {
|
| 69 | +
|
| 70 | +<# |
| 71 | +
|
| 72 | +multiline_comment |
| 73 | +
|
| 74 | +#> |
| 75 | +\r\n\r\n\r\n |
| 76 | +\r\n |
| 77 | +
|
| 78 | +lots \t of whitespace |
| 79 | +
|
| 80 | +\n\n\n\n\n |
| 81 | +\n\n |
| 82 | +
|
| 83 | +
|
| 84 | +# single_line_comment1 |
| 85 | + # single_line_comment2 |
| 86 | + # |
| 87 | + # single_line_comment3 |
51 | 88 | $some_literal = @\"
|
52 | 89 | using System;
|
53 | 90 | using System.Runtime.InteropServices;
|
|
104 | 141 | Rex::Exploitation::Powershell::Script.new(example_script_without_literal)
|
105 | 142 | end
|
106 | 143 |
|
107 |
| - describe "::sub_map_generate" do |
108 |
| - it 'should return some unique variable names' do |
109 |
| - map = subject.sub_map_generate(['blah','parp']) |
110 |
| - map.should be |
111 |
| - map.should be_kind_of Hash |
112 |
| - map.empty?.should be_false |
113 |
| - map.should eq map.uniq |
| 144 | + describe "::strip_comments" do |
| 145 | + it 'should strip a multiline comment' do |
| 146 | + subject.strip_comments |
| 147 | + subject.code.should be |
| 148 | + subject.code.should be_kind_of String |
| 149 | + subject.code.include?('comment').should be_false |
114 | 150 | end
|
115 | 151 |
|
116 |
| - it 'should not match upper or lowercase reserved names' do |
117 |
| - initial_vars = subject.get_var_names |
118 |
| - subject.code << "\r\n$SHELLID" |
119 |
| - subject.code << "\r\n$ShellId" |
120 |
| - subject.code << "\r\n$shellid" |
121 |
| - after_vars = subject.get_var_names |
122 |
| - initial_vars.should eq after_vars |
| 152 | + it 'should strip a single line comment' do |
| 153 | + subject.strip_comments |
| 154 | + subject.code.should be |
| 155 | + subject.code.should be_kind_of String |
| 156 | + subject.code.include?('#').should be_false |
123 | 157 | end
|
124 | 158 | end
|
125 | 159 |
|
| 160 | + describe "::strip_empty_lines" do |
| 161 | + it 'should strip extra windows new lines' do |
| 162 | + subject.strip_empty_lines |
| 163 | + subject.code.should be |
| 164 | + subject.code.should be_kind_of String |
| 165 | + res = (subject.code =~ /\r\n\r\n/) |
| 166 | + res.should be_false |
| 167 | + end |
| 168 | + |
| 169 | + it 'should strip extra unix new lines' do |
| 170 | + subject.strip_empty_lines |
| 171 | + subject.code.should be |
| 172 | + subject.code.should be_kind_of String |
| 173 | + res = (subject.code =~ /\n\n/) |
| 174 | + res.should be_false |
| 175 | + end |
| 176 | + end |
| 177 | + |
| 178 | + describe "::strip_whitespace" do |
| 179 | + it 'should strip additional whitespace' do |
| 180 | + subject.strip_whitespace |
| 181 | + subject.code.should be |
| 182 | + subject.code.should be_kind_of String |
| 183 | + subject.code.include?('lots of whitespace').should be_true |
| 184 | + end |
| 185 | + end |
| 186 | + |
| 187 | + describe "::sub_vars" do |
| 188 | + it 'should replace variables with unique names' do |
| 189 | + subject.sub_vars |
| 190 | + subject.code.should be |
| 191 | + subject.code.should be_kind_of String |
| 192 | + subject.code.include?('$kernel32').should be_false |
| 193 | + subject.code.include?('$Logon').should be_false |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + describe "::sub_funcs" do |
| 198 | + it 'should replace functions with unique names' do |
| 199 | + subject.sub_funcs |
| 200 | + subject.code.should be |
| 201 | + subject.code.should be_kind_of String |
| 202 | + subject.code.include?('Find-4624Logons').should be_false |
| 203 | + end |
| 204 | + end |
| 205 | + |
| 206 | + describe "::standard_subs" do |
| 207 | + it 'should run all substitutions on a script with no literals' do |
| 208 | + subject_no_literal.standard_subs |
| 209 | + subject_no_literal.code.should be |
| 210 | + subject_no_literal.code.should be_kind_of String |
| 211 | + subject_no_literal.code.include?('Find-4624Logons').should be_false |
| 212 | + subject_no_literal.code.include?('lots of whitespace').should be_true |
| 213 | + subject_no_literal.code.include?('$kernel32').should be_false |
| 214 | + subject_no_literal.code.include?('comment').should be_false |
| 215 | + res = (subject_no_literal.code =~ /\r\n\r\n/) |
| 216 | + res.should be_false |
| 217 | + end |
| 218 | + |
| 219 | + it 'should run all substitutions except strip whitespace when literals are present' do |
| 220 | + subject.standard_subs |
| 221 | + subject.code.should be |
| 222 | + subject.code.should be_kind_of String |
| 223 | + subject.code.include?('Find-4624Logons').should be_false |
| 224 | + subject.code.include?('lots of whitespace').should be_false |
| 225 | + subject.code.include?('$kernel32').should be_false |
| 226 | + subject.code.include?('comment').should be_false |
| 227 | + res = (subject.code =~ /\r\n\r\n/) |
| 228 | + res.should be_false |
| 229 | + end |
| 230 | + end |
126 | 231 | end
|
127 | 232 |
|
0 commit comments