Thread: Force connection through proxy

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    8

    Force connection through proxy

    i'm trying to write a program, that will force a selected program to connect through a local proxy, that proxy will be my program listening, and then i will be able to monitor the packets this program is sending and receiving, and still send the packets to the original client/server, i.e. : act as a proxy.
    i already wrote a code to listen, and when a connection is made to monitor the packets and send them forward to the real server(i already have the address of the server i want to contact), and a code to accept packets from this server and send them back to the client, but i'm having trouble forcing the external program to connect through the localhost(my listening proxy).
    i thought about hooking, but if i'm gonna hook anything than what? and how?
    thanks in advance.

  2. #2
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    since i dont know about your setup, you can have only one thing listening on a port at a time. Otherwise things can get screwy so the other server or service your trying to connect to should be a different actual machine, or a virtual machine unless you have a network card driver with a promiscuous mode on it that just sees all the traffic.

    as for the connecting issue, Are you trying to do something like what TCPTrace does over at sysinternals.com?
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    8
    about the one listening port, its ok, i only have to listen to one port, and one connection, the problem is forcing an external application to connect through my proxy, i.e.: my localhost, insted of the ip it wants to connect to, and i just don't know how to do it, any ideas?

    i do know the port it will use and the ip it attempts to connect to, i need to take control over that.

  4. #4
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    What is your listening code look like? I mean is it in its own thread or in the main app thread?
    What network connection type are you using, like sockets or what? To the app, you would have to specify that you are listening on your IP rather than on localhost. If you tell it to run on localhost it will use a 127.0.0.1 derivative and thats all it will listen for.

    When the program you are connecting to comes into your machine, is it from another machine or is it another application on your machine? And is it connecting to your machines IP as its connection or are you trying to just sniff all net packets for traffic going to a specific server.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    8
    look, what happens when i do nothing is that:
    SOME_APPLICATION -> ITS_SERVER (ITS_PORT)
    SOME_APPLICATION(SOME_OTHER_PORT) <- ITS_SERVER
    what i want to do it that:
    SOME_APPLICATION -> MY_PROGRAM - > ITS_SERVER
    SOME_APPLICATION <- MT_PROGRAM -< ITS_SERVER

    and i want the program to stay blind of that thing, to think its still communicating directly with the server.
    my problem is not listening to the connection or handling it, my problem is making the application connect to my program (which is on the localhost, 127.0.01) and not its server, that is (of course) external, and has its own ip which the program addresses.
    how do i hook or redirect the ip the application is trying to communicate with?
    that is my problem.
    the application and my program are on the same computer.

  6. #6
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    you could listen on a different port and redirect to your computer to the proper port

    I am not sure how the application is configured but most apps that connect to a non-standard port for their traffic make the port configurable. like if it runs on port 567 tell your SOME_APPLICATION to connect to 568 and your MY_PROGRAM would listen on 568 then it would forward to 567 on your ITS_SERVER

    I can see where you were having the issue now. it would be easier if the server application was on a different machine, you could use the proper port on your machine. but since they are one in the same, the easiest route is to do a one off port and forward it to the proper one.

    As I mentioned before, you can experiment with behavior of forwarding tcp traffic using TCPTrace but before i mistakenly put sysinternals, it is really at
    http://www.pocketsoap.com/tcpTrace/
    sorry for the erroneous info

    Check that app out and it will help you form an idea how to step forward with your app. let me know if you have any questions, its pretty straight forward but at first glance can be confusing.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    8
    nothing is configurable in this external application, it doesn't want me to redirect it...
    and, how will listening to a certain port will help me get the connection, if the connection targets a whole other ip?
    considering that i can't change the port, what else can i do?
    and it is a non-standard port.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socks4/5 proxy question
    By carrotcake1029 in forum Networking/Device Communication
    Replies: 7
    Last Post: 11-27-2008, 12:44 PM
  2. Though implementation problem
    By Elysia in forum C++ Programming
    Replies: 296
    Last Post: 05-31-2008, 01:02 PM
  3. Connection to website using Proxy
    By password in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-24-2008, 03:22 AM
  4. Simple Proxy
    By Lina in forum C Programming
    Replies: 0
    Last Post: 04-01-2007, 12:36 PM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM