开发者

How to change socket bind port of program? without source code

开发者 https://www.devze.com 2023-02-02 13:31 出处:网络
PROBLEM: I have a program dummy.exe on windows. this program will bind to UDP port 5060, after started.

PROBLEM:

I have a program dummy.exe on windows. this program will bind to UDP port 5060, after started. but another program also want to bind port 5060.

WHAT I HAVE DONE:

  1. using windbg to start dummy.exe, and set breakpoint on ws2_32!bind
  2. when the breakpoint hit, i changed the parameter (port val开发者_StackOverflow中文版ue) with command ew
  3. this dummy.exe will bind to the new port, and worked well.

QUESTION:

  • How can i do that easily? write a simple windows debugger?
  • Maybe i can hacking or modify the dummy.exe file, but how to do that?
  • what's your way to achieve this?

thanks

EDIT1:

Thanks very much @Cody Gray and @cdhowie

  1. This software do not provide functionality to change port.
  2. I need use this software to communicate with others who also use this software.
  3. For 'simple' debugger, i mean call CreateProcess with flag DEBUG_PROCESS to start dummy.exe, and WaitForDebugEvent, then hook the ws2_32!bind function to modify the port parameter, but i do not sure wheather it works
  4. i used UltraEdit to find the value 0x13C4 (5060), but after i changed the value, it does not works :( , any suggestion?


I see two options here. First, along the lines of what you already mentioned, you can patch the parameters to the bind() call at runtime, using hooking. Popular libraries to do that are Detours or madCodeHook, or example. This would definitely work, I used to do that myself.

The second option you also already mentioned, although I'd suggest not using a hex editor to simply search for those values, there might be multiple occurrences in the file and using only a hex editor, it might be hard to find the right one. What you can do, however, is use a debugger that is able to write a modified image back to disk. OllyDbg offers a very comfortable way to do that.

I'd suggest going for the hooking method though, that way, you can inject code around the binding to read the port from a configuration file, or similar in order to avoid the need to patch the executable or recompile your code time and again.

0

精彩评论

暂无评论...
验证码 换一张
取 消