Use Fiddler core API to intercept and modify WebSocket data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.