Skip to content

Commit 59ac921

Browse files
committed
Update v1.0.1
1 parent 571d759 commit 59ac921

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

src/FiddlerMomoPlugin/MomoPlugin.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,33 @@ public MomoPlugin()
7878
private string RSAEncryptWithMomoPublicKey(string data)
7979
{
8080
var encryptEngine = new Pkcs1Encoding(new RsaEngine());
81+
8182
var bytesToEncrypt = Encoding.UTF8.GetBytes(data);
8283

8384
try
8485
{
8586
encryptEngine.Init(true, momoPublicKey);
86-
return Convert.ToBase64String(encryptEngine.ProcessBlock(bytesToEncrypt, 0, bytesToEncrypt.Length));
8787
}
8888
catch (Exception e)
8989
{
9090
CConsole.LogRed("RSAEncryptWithMomoPublicKey error: " + e.Message);
9191
return null;
9292
}
9393

94+
return Convert.ToBase64String(encryptEngine.ProcessBlock(bytesToEncrypt, 0, bytesToEncrypt.Length));
9495
}
9596

9697
private string RSADecryptWithInjectedPrivateKey(string base64_encrypted)
9798
{
98-
var decryptEngine = new Pkcs1Encoding(new RsaEngine());
9999
var bytesToDecrypt = Convert.FromBase64String(base64_encrypted);
100100

101+
var decryptEngine = new Pkcs1Encoding(new RsaEngine());
102+
101103
try
102104
{
103105
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;
105108
}
106109
catch (Exception e)
107110
{
@@ -204,7 +207,7 @@ public void AutoTamperRequestBefore(Session oSession)
204207
oSession.oRequest["requestkey"] = RSAEncryptWithMomoPublicKey(aes_key);
205208

206209
// 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;
208211

209212
// decryption is expensive, check if we had the console opened else it is wasting resources for nothing.
210213
if (CConsole.isOpen)
@@ -214,7 +217,31 @@ public void AutoTamperRequestBefore(Session oSession)
214217
CConsole.LogGray(decrypted_data);
215218
}
216219
}
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+
}
218245

219246
public void AutoTamperResponseBefore(Session oSession)
220247
{
@@ -257,18 +284,18 @@ public void AutoTamperResponseBefore(Session oSession)
257284
// or decrypt the request data
258285
else if (oSession.oRequest["requestkey"] != "")
259286
{
260-
if (oSession.oRequest["requestkey_decrypted"] == "") return;
287+
if (oSession.oRequest["aes_key"] == "") return;
261288

262289
// uncompress the response;
263290
oSession.utilDecodeResponse();
264291

265292
// decrypt the request data
266293
string post_data = Encoding.UTF8.GetString(oSession.RequestBody);
267-
string aes_key = oSession.oRequest["requestkey_decrypted"];
294+
string aes_key = oSession.oRequest["aes_key"];
268295
string decrypted_post_data = AESDecrypt(post_data, aes_key);
269296

270297
oSession.RequestBody = Encoding.UTF8.GetBytes(decrypted_post_data);
271-
oSession.oResponse["requestkey_decrypted"] = aes_key;
298+
oSession.oResponse["aes_key"] = aes_key;
272299
}
273300
}
274301
public void AutoTamperResponseAfter(Session oSession) { }
@@ -330,10 +357,10 @@ public byte[] body
330357
set
331358
{
332359
// 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"] != "")
334361
{
335362
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"]);
337364
jsonResponseViewer.body = Encoding.UTF8.GetBytes(decrypted_body);
338365
}
339366
else
@@ -384,10 +411,10 @@ public byte[] body
384411
set
385412
{
386413
// 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"] != "")
388415
{
389416
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"]);
391418
textResponseViewer.body = Encoding.UTF8.GetBytes(decrypted_body);
392419
}
393420
else

src/FiddlerMomoPlugin/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("1.0.0.0")]
37-
[assembly: AssemblyFileVersion("1.0.0.0")]
36+
[assembly: AssemblyVersion("1.0.1.0")]
37+
[assembly: AssemblyFileVersion("1.0.1.0")]
3838
[assembly: NeutralResourcesLanguage("")]

0 commit comments

Comments
 (0)