The general man-in-the-middle attack is basically to intercept and modify the contents of the normal HTTP protocol, and there seems to be little introduction to how to intercept and modify the contents of the WebSocket protocol.
Talk is cheap show me the Code
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using Fiddler;namespace intercept_http_requests{public partial class Form1:form {public Form1 () {initializecom Ponent (); Setsslcer (); Fiddlerapplication.onnotification + = Delegate (object sender, Notificationeventargs onea) {Console.WriteLine ("* * Notifyuser: "+ onea.notifystring);}; FiddlerApplication.Log.OnLogString + = Delegate (object sender, Logeventargs OLEA) {Console.WriteLine ("* * logstring:" + O Lea. logstring); }; Fiddlerapplication.onwebsocketmessage + = Fiddlerapplication_onwebsocketmessage; Fiddlerapplication.startup (8877, True, true); } public static byte[] Hexstringtobytes (String hexstring) {hexstring = Hexstring.replace ("-", "" " ); int Length = HEXSTRING.LENGTH/2; char[] Hexchars = Hexstring.tochararray (); Byte[] D = new Byte[length]; for (int i = 0; i < length; i++) {int pos = i * 2; D[i] = (byte) (Chartobyte (Hexchars[pos]) << 4 | chartobyte (Hexchars[pos + 1])); } return D; } private static Byte Chartobyte (char c) {return (byte) "0123456789ABCDEF". IndexOf (c); } private static void Fiddlerapplication_onwebsocketmessage (object sender, Websocketmessageeventargs e) { if (e.owsm.payloadasstring (). Contains ("77-65-69-6c-69-66-61-67-65") && E.owsm.maskingkey = = null) {String payload = E.owsm.payloadasstring (). Replace ("77-65-69-6c-69-66-61-67-65", "79-78-61-73-78-68-61-73-64-68-64-73-61-64-61-73-64-61-73"); E.owsm.setpayload (hexstringtobytes (payload)); }} private void Button1_Click (ObjeCT sender, EventArgs e) {button1. Text = "running.."; } private void Button2_Click (object sender, EventArgs e) {fiddlerapplication.shutdown (); System.Threading.Thread.Sleep (1000); This. Close (); } private bool Setsslcer () {if (certmaker.rootcertismachinetrusted ()) return True ; Bccertmaker.bccertmaker a = new Bccertmaker.bccertmaker (); A.createrootcertificate (); return A.trustrootcertificate (); } }}
The most important problem is that if you want to replace the content is shorter than the original content, you must be in front of 0!!!
Use Fiddler core API to intercept and modify WebSocket data