如何更改程序的套接字绑定端口?没有源代码
问题:
我在 Windows 上有一个程序 dummy.exe。 该程序启动后将绑定到UDP端口5060。 但另一个程序也想绑定端口5060。
我做了什么:
- 使用windbg启动dummy.exe,并在ws2_32上设置断点!bind
- 当断点命中时,我更改了参数(端口值)使用命令 ew
- 这个 dummy.exe 将绑定到新端口,并且运行良好。
问题:
- 我怎样才能轻松做到这一点?写一个 简单的Windows调试器?
- 也许我可以破解或修改 dummy.exe 文件,但如何做到这一点?
- 你有什么办法来实现这个目标?
谢谢
编辑1:
非常感谢@Cody Gray和@cdhowie
- 该软件不提供更改端口的功能。
- 我需要使用该软件与也使用该软件的其他人进行交流。
- 对于“简单”调试器,我的意思是使用标志调用 CreateProcess DEBUG_PROCESS 启动 dummy.exe 和 WaitForDebugEvent,然后挂接 ws2_32!bind 函数修改端口参数,但我不确定它是否有效
- 我使用UltraEdit找到值0x13C4(5060),但在我更改该值之后, 它不起作用:(,有什么建议吗?
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:
- using windbg to start dummy.exe, and set breakpoint on ws2_32!bind
- when the breakpoint hit, i changed the parameter (port value) with command ew
- 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
- This software do not provide functionality to change port.
- I need use this software to communicate with others who also use this software.
- 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 - i used UltraEdit to find the value 0x13C4 (5060), but after i changed the value,
it does not works :( , any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里看到两个选择。首先,按照您已经提到的内容,您可以使用挂钩将参数修补到运行时的
bind()
调用。常用的库有 Detours 或 madCodeHook,或示例。这绝对有效,我自己曾经这样做过。您也已经提到了第二个选项,尽管我建议不要使用十六进制编辑器来简单地搜索这些值,但文件中可能会多次出现,并且仅使用十六进制编辑器,可能很难找到正确的值。但是,您可以做的是使用能够将修改后的映像写回磁盘的调试器。 OllyDbg 提供了一种非常舒适的方式来做到这一点。
不过,我建议采用挂钩方法,这样,您可以在绑定周围注入代码以从配置文件或类似文件中读取端口,以避免需要一次又一次地修补可执行文件或重新编译代码。
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.