@@ -78,30 +78,33 @@ public MomoPlugin()
78
78
private string RSAEncryptWithMomoPublicKey ( string data )
79
79
{
80
80
var encryptEngine = new Pkcs1Encoding ( new RsaEngine ( ) ) ;
81
+
81
82
var bytesToEncrypt = Encoding . UTF8 . GetBytes ( data ) ;
82
83
83
84
try
84
85
{
85
86
encryptEngine . Init ( true , momoPublicKey ) ;
86
- return Convert . ToBase64String ( encryptEngine . ProcessBlock ( bytesToEncrypt , 0 , bytesToEncrypt . Length ) ) ;
87
87
}
88
88
catch ( Exception e )
89
89
{
90
90
CConsole . LogRed ( "RSAEncryptWithMomoPublicKey error: " + e . Message ) ;
91
91
return null ;
92
92
}
93
93
94
+ return Convert . ToBase64String ( encryptEngine . ProcessBlock ( bytesToEncrypt , 0 , bytesToEncrypt . Length ) ) ;
94
95
}
95
96
96
97
private string RSADecryptWithInjectedPrivateKey ( string base64_encrypted )
97
98
{
98
- var decryptEngine = new Pkcs1Encoding ( new RsaEngine ( ) ) ;
99
99
var bytesToDecrypt = Convert . FromBase64String ( base64_encrypted ) ;
100
100
101
+ var decryptEngine = new Pkcs1Encoding ( new RsaEngine ( ) ) ;
102
+
101
103
try
102
104
{
103
105
decryptEngine . Init ( false , injectedPrivateKey ) ;
104
- return Encoding . UTF8 . GetString ( decryptEngine . ProcessBlock ( bytesToDecrypt , 0 , bytesToDecrypt . Length ) ) ;
106
+ var decrypted = Encoding . UTF8 . GetString ( decryptEngine . ProcessBlock ( bytesToDecrypt , 0 , bytesToDecrypt . Length ) ) ;
107
+ return decrypted ;
105
108
}
106
109
catch ( Exception e )
107
110
{
@@ -204,7 +207,7 @@ public void AutoTamperRequestBefore(Session oSession)
204
207
oSession . oRequest [ "requestkey" ] = RSAEncryptWithMomoPublicKey ( aes_key ) ;
205
208
206
209
// put the decrypted key in the header for later usage in the response handling part
207
- oSession . oRequest [ "requestkey_decrypted " ] = aes_key ;
210
+ oSession . oRequest [ "aes_key " ] = aes_key ;
208
211
209
212
// decryption is expensive, check if we had the console opened else it is wasting resources for nothing.
210
213
if ( CConsole . isOpen )
@@ -214,7 +217,31 @@ public void AutoTamperRequestBefore(Session oSession)
214
217
CConsole . LogGray ( decrypted_data ) ;
215
218
}
216
219
}
217
- public void AutoTamperRequestAfter ( Session oSession ) { }
220
+
221
+ // we handle the edit/repeat request here
222
+ public void AutoTamperRequestAfter ( Session oSession ) {
223
+
224
+ if ( ! oSession . url . StartsWith ( "api.momo.vn/" ) && ! oSession . url . StartsWith ( "owa.momo.vn/" ) ) return ;
225
+
226
+ // make sure the request has gone through AutoTamperRequestBefore
227
+ if ( oSession . oRequest [ "aes_key" ] == "" ) return ;
228
+
229
+ string aes_key = oSession . oRequest [ "aes_key" ] ;
230
+
231
+ // if the body is not encrypted, it is probably the user is trying to send something, we should encrypt it.
232
+ try
233
+ {
234
+ string decrypted_data = AESDecrypt ( Encoding . UTF8 . GetString ( oSession . RequestBody ) , aes_key ) ;
235
+ }
236
+ catch ( Exception e )
237
+ {
238
+
239
+ string request_body = Encoding . UTF8 . GetString ( oSession . RequestBody ) ;
240
+ string encrypted_request = AESEncrypt ( request_body , aes_key ) ;
241
+
242
+ oSession . RequestBody = Encoding . UTF8 . GetBytes ( encrypted_request ) ;
243
+ }
244
+ }
218
245
219
246
public void AutoTamperResponseBefore ( Session oSession )
220
247
{
@@ -257,18 +284,18 @@ public void AutoTamperResponseBefore(Session oSession)
257
284
// or decrypt the request data
258
285
else if ( oSession . oRequest [ "requestkey" ] != "" )
259
286
{
260
- if ( oSession . oRequest [ "requestkey_decrypted " ] == "" ) return ;
287
+ if ( oSession . oRequest [ "aes_key " ] == "" ) return ;
261
288
262
289
// uncompress the response;
263
290
oSession . utilDecodeResponse ( ) ;
264
291
265
292
// decrypt the request data
266
293
string post_data = Encoding . UTF8 . GetString ( oSession . RequestBody ) ;
267
- string aes_key = oSession . oRequest [ "requestkey_decrypted " ] ;
294
+ string aes_key = oSession . oRequest [ "aes_key " ] ;
268
295
string decrypted_post_data = AESDecrypt ( post_data , aes_key ) ;
269
296
270
297
oSession . RequestBody = Encoding . UTF8 . GetBytes ( decrypted_post_data ) ;
271
- oSession . oResponse [ "requestkey_decrypted " ] = aes_key ;
298
+ oSession . oResponse [ "aes_key " ] = aes_key ;
272
299
}
273
300
}
274
301
public void AutoTamperResponseAfter ( Session oSession ) { }
@@ -330,10 +357,10 @@ public byte[] body
330
357
set
331
358
{
332
359
// we have already decrypted the key when sending the request
333
- if ( headers [ "requestkey_decrypted "] != "" )
360
+ if ( value != null && value . Length > 0 && headers != null && headers [ "aes_key "] != "" )
334
361
{
335
362
string encrypted_body = Encoding . UTF8 . GetString ( value ) ;
336
- string decrypted_body = MomoPlugin . AESDecrypt ( encrypted_body , headers [ "requestkey_decrypted " ] ) ;
363
+ string decrypted_body = MomoPlugin . AESDecrypt ( encrypted_body , headers [ "aes_key " ] ) ;
337
364
jsonResponseViewer . body = Encoding . UTF8 . GetBytes ( decrypted_body ) ;
338
365
}
339
366
else
@@ -384,10 +411,10 @@ public byte[] body
384
411
set
385
412
{
386
413
// we have already decrypted the key when sending the request
387
- if ( headers [ "requestkey_decrypted "] != "" )
414
+ if ( value != null && value . Length > 0 && headers != null && headers [ "aes_key "] != "" )
388
415
{
389
416
string encrypted_body = Encoding . UTF8 . GetString ( value ) ;
390
- string decrypted_body = MomoPlugin . AESDecrypt ( encrypted_body , headers [ "requestkey_decrypted " ] ) ;
417
+ string decrypted_body = MomoPlugin . AESDecrypt ( encrypted_body , headers [ "aes_key " ] ) ;
391
418
textResponseViewer . body = Encoding . UTF8 . GetBytes ( decrypted_body ) ;
392
419
}
393
420
else
0 commit comments