Skip to content

Commit aaf759d

Browse files
author
Noah Potash
committed
Fixed IPv4 detection of TCP
1 parent 94a271e commit aaf759d

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

Diff for: src/LibPacketGremlin/LibPacketGremlin.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
<PackageProjectUrl>https://github.com/SapientGuardian/LibPacketGremlin</PackageProjectUrl>
1515
<PackageLicenseUrl>http://opensource.org/licenses/MIT</PackageLicenseUrl>
1616
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
17-
<Version>1.0.1</Version>
18-
<AssemblyVersion>0.1.0.1</AssemblyVersion>
19-
<FileVersion>0.1.0.1</FileVersion>
17+
<Version>1.0.2</Version>
18+
<AssemblyVersion>0.1.0.2</AssemblyVersion>
19+
<FileVersion>0.1.0.2</FileVersion>
2020
</PropertyGroup>
2121

2222
<ItemGroup>

Diff for: src/LibPacketGremlin/Packets/IPv4.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public void CorrectFields()
235235
this.HeaderLength = 5 + this.OptionsAndPadding.Length / 4;
236236
this.TotalLength = (ushort)(this.HeaderLength * 4 + this.Payload.Length());
237237

238-
// TODO: Add TCP when ported over
238+
239239
if (this.Payload is IPv4)
240240
{
241241
this.Protocol = (byte)Protocols.IP;
@@ -248,6 +248,10 @@ public void CorrectFields()
248248
{
249249
this.Protocol = (byte)Protocols.ICMP;
250250
}
251+
else if (this.Payload is TCP)
252+
{
253+
this.Protocol = (byte)Protocols.TCP;
254+
}
251255

252256
this.HeaderChecksum = 0;
253257
this.HeaderChecksum = ComputeChecksum(this.ToArray(), 0, this.HeaderLength * 4);
@@ -382,7 +386,19 @@ internal static bool TryParse(byte[] buffer, int index, int count, out IPv4 pack
382386
}
383387

384388
break;
385-
// TODO: Add TCP when ported over
389+
case (byte)Protocols.TCP:
390+
{
391+
TCP payload;
392+
if (TCP.TryParse(
393+
buffer,
394+
index + (int)br.BaseStream.Position,
395+
payloadLength,
396+
out payload))
397+
{
398+
packet = new IPv4<TCP> { Payload = payload };
399+
}
400+
}
401+
break;
386402
}
387403

388404
if (packet == null)

Diff for: test/LibPacketGremlinTests/LibPacketGremlinTests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34+
<None Update="Resources\msmon80211tcp.bin">
35+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
36+
</None>
3437
<None Update="Resources\radiotap.bin">
3538
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3639
</None>

Diff for: test/LibPacketGremlinTests/Packets/IPv4Tests.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
using Xunit;
1212
using OutbreakLabs.LibPacketGremlin.PacketFactories;
1313
using OutbreakLabs.LibPacketGremlin.Extensions;
14+
using OutbreakLabs.LibPacketGremlin.Abstractions;
15+
using OutbreakLabs.LibPacketGremlin.Utilities;
16+
1417
public class IPv4Tests
1518
{
1619
[Fact]
@@ -43,7 +46,7 @@ public void ParsesBasicFields()
4346
packet.HeaderChecksum.Should().Be(46798);
4447
packet.SourceAddress.Should().Be(IPv4Address.Parse("192.168.1.3"));
4548
packet.DestAddress.Should().Be(IPv4Address.Parse("192.168.1.123"));
46-
49+
4750
}
4851

4952
[Fact]
@@ -58,7 +61,7 @@ public void SerializesCorrectly()
5861
0x9f, 0xd8, 0xb7, 0xc4, 0xc5, 0xa6, 0x07, 0x36, 0xca, 0xce, 0x11, 0x3b,
5962
0x32, 0xcd, 0x87, 0x1c, 0x24, 0x2d, 0xad, 0x15, 0xc4, 0x0f}, out packet).Should().BeTrue();
6063

61-
64+
6265
using (var ms = new MemoryStream())
6366
{
6467
packet.WriteToStream(ms);
@@ -118,5 +121,16 @@ public void CalculatesLength()
118121
packet.Length().Should().Be(packet.ToArray().Length);
119122

120123
}
124+
125+
[Fact]
126+
public void ChainsToTCP()
127+
{
128+
byte[] rawBytes = System.IO.File.ReadAllBytes(Path.Combine("Resources", "msmon80211tcp.bin"));
129+
IPacket encryptedPacket;
130+
var parsed = MSMon802_11Factory.Instance.TryParse(rawBytes, out encryptedPacket);
131+
IPacket decrypted;
132+
IEEE802_11Crypto.TryDecryptWEP(encryptedPacket.Layer<IEEE802_11>(), new byte[] { 0xC5, 0x8D, 0xB1, 0x5E, 0x2B }, out decrypted);
133+
decrypted.Layer<TCP>().Should().NotBeNull();
134+
}
121135
}
122136
}
124 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)