简体   繁体   English

更改TCP / IP数据包C ++或Java

[英]Changing tcp/ip packets c++ or java

Here is the situation. 这是情况。 There are server and client in network. 网络中有服务器和客户端。 They communicate like this: 他们这样交流:

  1. Client sends request for some function. 客户端发送某些功能的请求。
  2. Server sends to client function parameters. 服务器发送给客户端功能参数。
  3. Client trying to perform function and sends answer to server. 客户端尝试执行功能并将答案发送到服务器。
  4. Server sends to client data which it should show. 服务器向客户端发送应显示的数据。

But sometimes client can't perform function and sends error. 但是有时客户端无法执行功能并发送错误。 I want to catch all packets from step 2, analyze them (I've already have tools for that), prevent some of them to reach client, process them with my program and form packet like in step 3. This must be done on client side. 我想捕获第2步中的所有数据包(分析它们(我已经有相应的工具),阻止其中的某些数据包到达客户端,用我的程序处理它们并像第3步一样形成数据包。这必须在客户端上完成侧。 I have no access neither to server nor to client. 我无权访问服务器或客户端。

So, the question is: Is there libraries for changing, injecting and removing tcp/ip packet in c++ or java? 因此,问题是:是否存在用于在c ++或java中更改,注入和删除tcp / ip数据包的库? The solution should be working in both Win and Linux systems. 该解决方案应该在Win和Linux系统上都可以使用。 Also, may be you have better ideas to expand client functionality? 另外,您是否有更好的想法来扩展客户端功能?

Thanks for any help! 谢谢你的帮助! I tried to google how to change packets, but all I got were unanswered questions and sniffers=( 我试图用谷歌搜索如何更改数据包,但我得到的只是未解决的问题和嗅探器=(

Edit: Actually, I don't really need injecting and removing packets, I can manage it with only changing packet data. 编辑:实际上,我真的不需要注入和删除数据包,只需更改数据包数据就可以对其进行管理。 Also, there is no multiple requests in the same packet, and a single request across multiple packets is not a problem. 同样,在同一数据包中没有多个请求,并且跨多个数据包的单个请求也不是问题。

You have to build a Proxy for your server. 您必须为服务器构建一个代理。 The client connects to the proxy, and the proxy itself connects to the server. 客户端连接到代理,而代理本身连接到服务器。 It just routes all the packages between client and server. 它只是在客户端和服务器之间路由所有软件包。

BUT it is now able to intercept specific messages and to modify them. 但是,现在它可以拦截特定消息并进行修改。 Imagine a filtering HTTP proxy, it works the same way. 想象一下过滤HTTP代理,它的工作方式相同。

I have personal experience with libpcap on linux and freeBSD, a kind of lowlevel library that helps to catch or inject packets. 我在linux和freeBSD上有libpcap的经验,这是一种有助于捕获或注入数据包的低级库。 I did use it in an IPV6 network bridge project... But i know there is a windows port for it. 我确实在IPV6网络桥项目中使用了它……但是我知道有一个Windows端口。 http://sourceforge.net/projects/libpcap/ You can let the library to: http://sourceforge.net/projects/libpcap/您可以让该库执行以下操作:

  1. catch packets using a filter 使用过滤器捕获数据包
  2. extract data from packet 从数据包中提取数据
  3. you can process the data (modify them) 您可以处理数据(修改它们)
  4. reinject it again using the same library 使用相同的库再次注入

But you would have to work with internal data in a quite raw matter. 但是,您将不得不完全处理内部数据。 Best documentation for this library are comments inside its header file, that is the most up to date info. 该库的最佳文档是其头文件中的注释,这是最新信息。 Maybe there are some more comfortable highlevel libraries. 也许有一些更舒适的高级库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM