Fiddler style application in C# - c#

I need to write a fiddler "lite" Windows forms application to perform some HTTP tracing of messages. Specifically I need to show the request/response XMLs to a server as they are occurring, highlighting certain elements etc.
Could anyone point me to a F/OSS application doing something similar as a starter, or perhaps outline the classes I need to use? I am a bit of a newbie with networking classes in C# and appreciate all help.
p.s. I cannot use Fiddler directly for several reasons, so that's not a valid answer. Thanks.

SharpPcap might be what you want

Check out .NET Network Tracing. Then your project would become mostly an exercise in log parsing.

Related

How to create application links

I'm currently using the Adobe AIR platform. I make applications with Adobe Flash Professional CS6. I was wondering how can I make special links that connect to the app. I mean something like Skype links:
skype:echo123?call
If it can't be created with AIR, please tell me how to create it in C# or other languages.
Thanks!
Hm, I'd say there's not a clear cut answer to your question. It can be done in various ways. It revolves around creating your own "routing" mechanism, or your own "protocol" mechanism for your API or application.
For example, for each "action" in your application you could make such a protocol. Say "File Open".. could become "app:fileopen:filename"..
You mentioned skype, but for example spotify has this method as well..
How you implement is something entirely different, and you'd need to consider following questions:
What benefits will it have? Why are you going to use it?
Should it be applicable inside the application only (e.g. browsing, or giving it through with command line arguments)? Or should it be used inside a browser as well?
Basically it will involve:
Schetsing a good protocol / routing schema for your API/application.
Implementing a framework (in whatever language) to support your routing mechanism.

webbrowser wrapper

Is there any wrapper that would allow me to access and modify raw request data (like the headers, body, cookies directly from the webbrowser object in winforms application using c# ?
The only thing I've seen out there which would let you interrogate what the browser is doing is Fiddler, which has an API. You might want to check that out, but it's not something that I would personally consider using to ship inside my production software unless I had a real solid requirement for it.
You can also try to implement your own Asynchronous Pluggable Protocol. So you'll be able to access and modify requests and then forward them to the destination using, for example, HttpWebRequest or raw sockets.
Some links you might consider useful to get started with:
A Simple protocol to view aspx pages without IIS implemented in C#
Internet Explorer Asynchronous Protocol Library
Although, using Asynchronous Pluggable Protocol in this case still looks like a hack (at least for me).
OK... So I've spent the last 4 days scouring the net for a solid solution to needing functionality like this. Mainly, being able to access the raw outbound request, and the raw inbound response associated with the webBrowser control in .Net. The results are absolutely disappointing. Why is this such a huge deal? Why can't MSFT just fix that control and add properties for the rawRequest and RawResponse? If you look you'll find developers trying to hack their way around this for the last 5-10 years. And nobody has come up with a solution? Really? WTF???
"WebBrowser.CreateSink Method"
Huge can of worms. Going here will break your mind.
"The most complete C# Webbrowser wrapper control"
On Win7, trying to regsrv32 the required old ass ATL DLL from 2006 results in an
Error.
"Subclass the WebBrowser control"
Won't work to gain access to the actual request/response HTTP packet data.
...sigh

Intercept an HTTP request at browser end to alter some html content

I would like to do as follows. What would be the best way? A general answer will also be fine.
I would like to intercept an HTTP request at the client end to alter some html content. For example, I go to CNN.com and rather than an article that's displaying "Two LA Dogs marry", it should say "Ridiculous title blocked".
It should be smooth that even a secure certificate won't be disturbed.
I am using C#.
Thanks!
UPDATE: Thank you all for your answers!
You can do this with Privoxy via their filter files. Their fun filter is a good example of exactly the sort of substitutions you want to do.
To replace "Two LA Dogs Marry" with "Ridiculous Title Blocked" on cnn.com your action file would look something like this:
{ +filter{ridiculous-title-censor} }
.cnn.com
and your filter file would look like
# FILTER: ridiculous-title-censor Remove ridiculous titles
# This keeps CNN from getting too ridiculous
#
s/Two LA Dogs Marry/Ridiculous Title Blocked/ig
Local HTTP proxy is possible and most generic approach.
I.e. you can use Fiddler to see if it works for you. I supports modifying requests/responses in addition to regular watching for traffic.
Another option if you're using Firefox is to use Greasemonkey scripts. Here's an example script which changes the main headline on cnn.com
If you're not familar with the Javascript coding needed to make Greasemoney scripts, you can use the Platypus add-on to edit the page in place and automatically generate a script file.
You could setup a proxy with HTTPListener. But I would think if you wanted to do it right, you'll need a program that is more low level.
Open 2 TCP Ports (80 & 443) and actively listen for incoming connections.
Once received
Go out and make the request on behalf of the requester
Retrieve HTTP Response
Inspect and change the HTTP Response (where appropriate)
Perhaps modifying headers (where appropriate)
Forward on the response to the requester
I'd start with a simple proxy that just forwards all requests and returns back all responses. Once that is in place you can start inspecting the responses.
That is a good place to start.
Such an approach is the least efficient method of doing what you want to achieve.
If this is a client side application, the client may disable it and thus render it useless.
It is also hard to maintain and requires more complex programming to ensure that it works with SSL.
If using a browser plugin, or toolbar, it would need to be made for a specific browser.
If using a listening server to intercept the HTTP request, this provides complexity and difficulty when the content is encrypted, also unnecessary overhead.
If using a local proxy (meaning that the client's browser needs to point to a local proxy service), maybe the most effective client side method, but still have the disadvantages mentioned above (hard to maintain etc.)
I believe that what you are looking to do is completely reinventing the wheel.
The fact that you have offered a bounty begs the question that you indeed need to do this in C# and client side, but 'censoring bad things' means you need to prohibit content, and any client side method would eventually give the power to the client to remove this limitation.
Personally, I have had great success with Squid and it's content adaptation features.
This means, that the clients need to have a controlled Internet source. Meaning that, if they are all in a LAN and sharing a common Internet gateway, this is easily feasible if you have spare a server to act as a proxy.
I recommend you get a small linux box, which can have a simple Ubuntu Server Edition, then add Squid. The net is full of tutorials, but the level of implementation has become easy enough to do even without them.
I may have gone completely off-topic, but I hope I could assist.
you can come to China ^_^
censorship like this is everywhere, you don't have to implement your own.
Ok, that is a joke, the answer is you can implement browser plugins for such kind of tasks. or maybe you need to implement a ROUTING filter ( GFW like ) on the router.
Taken from here.
It can be done via a Layered Service Provider on Windows.
From Wikipedia:
"A Layered Service Provider (LSP) is a feature of the Microsoft Windows Winsock 2 Service Provider Interface (SPI). A Layered Service Provider is a DLL that uses Winsock APIs to insert itself into the TCP/IP stack. Once in the stack, a Layered Service Provider can intercept and modify inbound and outbound Internet traffic. It allows processing all the TCP/IP traffic taking place between the Internet and the applications that are accessing the Internet (such as a web browser, the email client, etc). "
AdMuncher for example is intercepting and inserting http code to avoid ads. Another suggestion is to find an open-source ad blocking program and see how they've implemented it.
Are you saying you want to intercept this for your own site?
In any case, it needs to be done in javascript or jQuery as C# is not a client-side language.
or, you can code a toolbar, or maybe a simple chrome addon, it's really easy but its not C#
you can search for libraries to monitor browsing trough proxy, like this:
http://httpproxynet.codeplex.com/
The same concept used by java in this project:
http://www.charlesproxy.com/
sounds intresting, good luck :)
A long time ago I've implemented this feature for IE using Plugable Mime Filters so after I've searched about it in c# here in stackoverflow I've founded this post that should help you start with it.
Hope this is useful for you.
Asynchronous Pluggable Protocols can be used for this type of thing. Although, as stated here INFO: Implementing HTTP-like Asynchronous Pluggable Protocols: "For various reasons, Microsoft neither supports nor recommends that you replace or wrap the default HTTP protocol."

Implementing an SNMP Reporter (agent) in C# (must run on Mono)?

I am attempting to implement some additional statistics gathering in a C# server application - I have about 20 or so variables I'd like to be able to report to network monitoring tools; so I am assuming (hopefully correctly) that SNMP is the correct way to go.
There are however two problems:
The application is an open source server that cant include proprietary components, and
It needs to run on Mono under *nix environs as well as Windows via .NET.
The "#SNMP" library at http://sharpsnmplib.codeplex.com/ appears to be a promising solution - but there are no samples I can find; and my knowledge of SNMP is lacking.
Does anyone here have any (quick) examples of reporting data via SNMP? (ideally using a library under the LGPL, X/MIT, BSD or Zlib licenses)
Help much appreciated
Edit:
The problem appears to be a lack of libraries capable of acting as SNMP servers, if anyone is aware of any - this would probably solve the problem nicely.
Edit #2:
Basically I'm looking for a SNMP server library or sample reference implementation.
As the author :) I suggest you check out TestAgent sample. It can send out TRAP or INFORM messages to the IP address you specify.
Note that this is a tiny sample, which does not reveal all powers of SNMP.
#SNMP source comes with some samples (they're actually tests, but one can have an idea about how it works).
Another thing you could try is send your snmp queries calling directly the snmpget executable with the Process class. It's not the best way, but it could work (I've used this kind of approach with another language).

Capturing HTTP requests

Is there a way to monitor and capture all outgoing HTTP requests from a machine using C#?
I need a browser independent way of logging visited URLs.
I use fiddler ( http://www.fiddler2.com )
You may want to use existing network interfaces capturing libraries like pcap or winpcap to do so.
Rewriting all the necessary stuff by yourself would be quite time expensive.
Link to Pcap
Link to WinPcap
Edit : Just saw someone also wrote the C# bindings to winpcap : SharpPcap
Sounds like you're after some kind of "packet sniffing" utility.
Here's a couple of links to articles on the Code Project site for packet sniffers (with downloadable source code) written in C#:
Packet Capture and Analayzer
A Network Sniffer in C#
If you're just after capturing visited URL's, these utilities may be overkill, however, you'll be able to extract a URL from your HTTP packets and discard the rest, however, you may also wish to capture all packet information, in which case, these utilities will help.
You're probably going to save lots of time and effort with some kind of proxy setup. A decent local-machine solution would be Fiddler (requires Windows), or something like a Squid server for a networked solution.
I hope if Wirehark works for you.
It's free and cross-platform.
Also,
"Wireshark is the world's foremost network protocol analyzer, and is the de facto (and often de jure) standard across many industries and educational institutions"
Have look,
Wireshark-Wikipedia
Also, writing a simple http proxy for this purpose in C# is a trivial task.

Categories