I would love more than anything to make a nice long winded post about POTato, as I'm sure its all the rage rite now. I mean whats not to like about it, well I guess if your Microsoft there might be a reason, but I think they should just suck it up and learn the lesson... tssk tssk! Regardless I might decide to do one sometime soon or get a talk together as there is a lot more to it than most realize.
Sometimes the simplest things are the answer!
I felt like atleast mentioning it because that's why I decided to make this little post in the first place "its written in c#". I honestly sat last night for a hour trying to think of something to write about, and then it came to me. Why not start a gender-bender in c# and since a friend has been giving me little nudges to learn the language I eventually decided to give it a go. Personally I think its way easier to learn than c++ so i might just make the switch.
Enough of the introduction, lets get down to business, I really dont know enough to even tell you what Classes, are etc etc but I'm going to tell you the most basic way to make a forwarder, then you can look at the code and see how I did it. Ill eventually update it and add some more error checking and options as its Extremely useful!
A simple gender-beder or port forwarder goes like this.
SudoCode aka not in c#
sock1 = listen(ip, port) //listen ip and port
when sock1.connects // block until something connects
sock2 = connect(ip, port) // when it does connect to second host
thread1 = relay(sock1, sock2) // spawn relay thread1
thread2 = relay(sock2, sock1) // spawn relay thread2
// we just reuse the same relay "function"
relay(sock-a, sock-b)
data = sock-a.read // read from socket
sock-b.write(data) // write to socket
That's it, I mean really that's all there is to the game.. you cant get any simpler in my opinion. Sure you can do error checking and whatever else you want, but you are ALWAYS going to come back to this.
Listen(Port:IP) <===> App <===> Connect(Port:IP)
You can even Gender-Bend it, as rather than listen you can make the first connection outbound.
Connect1(Port:IP) <===> App <===> Connect2(Port:IP)
You can also do something really interesting if you put 1 more connection into the mix and spawn a few more threads. I like to call it the 3-way, and who doesn't like one of those!
Connect1(Port:IP) <===> App <===> Connect2(Port:IP)
^
||
v
Connect3(Port:IP)
Now not only can you mirror anything but you can also write to both connect 1 and 2.... let that sink in for a bit!
Anyways lets get back to c# as that was the reason of this in the first place. Knowing the simple knowledge above I managed to make something in less than a few hours having never used c# before.
You can check it out here https://github.com/trump0dump/helpful/blob/master/port_redir.cs it comes in under 70lines with some simple error checking. I got sick and tired of dealing with windows crash reporter ;)
Oh and before you go, dont forget, you DONT need Visual Studio to compile this! I guarantee your windows box has everything you need. Just do this, atleast for Win7+
cd C:\Windows\Microsoft.NET\Framework\v4*
csc.exe /out:"C:\Users\YOU\port_redir.exe" /platform:x86 "C:\Users\YOU\port_redir.cs"
Enjoy and have fun!
No comments:
Post a Comment