Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknow tcp option doesnt support reserved options #300

Open
gaoxingliang opened this issue Sep 5, 2022 · 0 comments · May be fixed by #301
Open

Unknow tcp option doesnt support reserved options #300

gaoxingliang opened this issue Sep 5, 2022 · 0 comments · May be fixed by #301

Comments

@gaoxingliang
Copy link

gaoxingliang commented Sep 5, 2022

Hi
The problem here is if some tcp option number is larger than 128 and then the code will throw an error: (version 1.7.3)
an example code:

byte [] bs = Base64.getDecoder().decode("dCWKAicArB9r+H5DCABFAACotN1AAEAG40i3gzI+mlMeFUQISte4gAAARAgAAIAYPjqUzAAA7rULDDC7TXc6A8JA6wKfafNuajj1xuQiQMpvcrwWduPX4QCITE3XjFyr5oAKjnbT6sP3XBVYfGpNonXfd2EUuAwNHlqqSirSaP0/oMEvO7vHI+cRS0QYkb0/k86JRLSsw7NlhBiFDNeTJjWAEKqrjq3r+ScPjm6UryNGvT3lbm4=");
EthernetPacket p = EthernetPacket.newPacket(bs, 0, bs.length);
System.out.println(p);
java.lang.ArrayIndexOutOfBoundsException: arr.length: 182, offset: 56, len: -77, arr: 74258a022700ac1f6bf87e430800450000a8b4dd40004006e348b783323e9a531e1544084ad7b88000004408000080183e3a94cc0000eeb50b0c30bb4d773a03c240eb029f69f36e6a38f5c6e42240ca6f72bc1676e3d7e100884c4dd78c5cabe6800a8e76d3eac3f75c15587c6a4da275df776114b80c0d1e5aaa4a2ad268fd3fa0c12f3bbbc723e7114b441891bd3f93ce8944b4acc3b3658418850cd79326358010aaab8eadebf9270f8e6e94af2346bd3de56e6e
	at org.pcap4j.util.ByteArrays.validateBounds(ByteArrays.java:1078) ~[pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.util.ByteArrays.getSubArray(ByteArrays.java:820) ~[pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.UnknownTcpOption.<init>(UnknownTcpOption.java:77) ~[pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.UnknownTcpOption.newInstance(UnknownTcpOption.java:45) ~[pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.factory.StaticTcpOptionFactory.newInstance(StaticTcpOptionFactory.java:174) ~[pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.factory.StaticTcpOptionFactory.newInstance(StaticTcpOptionFactory.java:168) ~[pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.factory.StaticTcpOptionFactory.newInstance(StaticTcpOptionFactory.java:29) ~[pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.TcpPacket$TcpHeader.<init>(TcpPacket.java:675) [pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.TcpPacket$TcpHeader.<init>(TcpPacket.java:482) [pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.TcpPacket.<init>(TcpPacket.java:64) [pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.TcpPacket.newPacket(TcpPacket.java:60) [pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.factory.StaticIpNumberPacketFactory$4.newInstance(StaticIpNumberPacketFactory.java:83) [pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.factory.AbstractStaticPacketFactory.newInstance(AbstractStaticPacketFactory.java:46) [pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.factory.AbstractStaticPacketFactory.newInstance(AbstractStaticPacketFactory.java:23) [pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.IpV4Packet.<init>(IpV4Packet.java:94) [pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.IpV4Packet.newPacket(IpV4Packet.java:61) [pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.factory.StaticEtherTypePacketFactory$1.newInstance(StaticEtherTypePacketFactory.java:37) [pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.factory.StaticEtherTypePacketFactory.newInstance(StaticEtherTypePacketFactory.java:111) [pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.factory.StaticEtherTypePacketFactory.newInstance(StaticEtherTypePacketFactory.java:24) [pcap4j-packetfactory-static-1.7.3.jar:?]
	at org.pcap4j.packet.EthernetPacket.<init>(EthernetPacket.java:102) [pcap4j-core-1.7.3.jar:?]
	at org.pcap4j.packet.EthernetPacket.newPacket(EthernetPacket.java:61) [pcap4j-core-1.7.3.jar:?]

in this url https://hpd.gasmi.net/, and paste above content, it will shows:

74 25 8A 02 27 00 AC 1F 6B F8 7E 43 08 00 45 00 00 A8 B4 DD 40 00 40 06 E3 48 B7 83 32 3E 9A 53 1E 15 44 08 4A D7 B8 80 00 00 44 08 00 00 80 18 3E 3A 94 CC 00 00 EE B5 0B 0C 30 BB 4D 77 3A 03 C2 40 EB 02 9F 69 F3 6E 6A 38 F5 C6 E4 22 40 CA 6F 72 BC 16 76 E3 D7 E1 00 88 4C 4D D7 8C 5C AB E6 80 0A 8E 76 D3 EA C3 F7 5C 15 58 7C 6A 4D A2 75 DF 77 61 14 B8 0C 0D 1E 5A AA 4A 2A D2 68 FD 3F A0 C1 2F 3B BB C7 23 E7 11 4B 44 18 91 BD 3F 93 CE 89 44 B4 AC C3 B3 65 84 18 85 0C D7 93 26 35 80 10 AA AB 8E AD EB F9 27 0F 8E 6E 94 AF 23 46 BD 3D E5 6E 6E

image

Root cause of this ticket is
the length variable in TcpOption is byte while in java, byte can only represent -128-127. This will cause an exception if the length is larger than this. in my case it's 181 bytes.

and I will fix this.

gaoxingliang added a commit to gaoxingliang/pcap4j that referenced this issue Sep 5, 2022
gaoxingliang added a commit to gaoxingliang/pcap4j that referenced this issue Sep 5, 2022
gaoxingliang added a commit to gaoxingliang/pcap4j that referenced this issue Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant