Skip to content

Commit e4983f5

Browse files
authored
Merge pull request #1 from H4NM/dev
Update to 1.1 🚀
2 parents 4b72261 + c8407dd commit e4983f5

27 files changed

Lines changed: 539 additions & 299 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Hannes
3+
Copyright (c) 2024 Hannes Michel
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ However, there are some downsides:
2121
- Can start and monitor an executable.
2222
- Can monitor an already running process.
2323
- Can monitor additional related processes based on executable names.
24+
- Executables can be run as other users and in elevated and unelevated states.
2425
- Creates a full packet capture .pcap file per process.
2526
- Records TCPIP activities made by a processes, netflow style.
2627
- Records DNS requests and responses made and retrieved by applications.
@@ -76,9 +77,13 @@ There are other tools that can compliment your quest of application network anal
7677

7778
### Limitations
7879
- **DNS**: In ETW, `Microsoft-Windows-DNS-Client` only logs A and AAAA queries, neglecting other DNS query types such as PTR, TXT, MX, SOA etc. It does capture CNAME and it's respective adresses, which are part of the DNS response. However, with the FPC the requests are captured either way, just not portrayed as in registered DNS traffic by the application.
80+
- **Execution integrity**: It's currently not possible to delegate the privilege of executing applications in an elevated state to other users, meaning that if you want to run the application elevated you need to be signed in as the user with administrator rights.
81+
Furthermore, since WhoYouCalling requires elevated privileges to run (*ETW + FPC*), spawned processes naturally inherits the security token making them also posess the same integrity level - and .NET api does not work too well with creating less privileged processes from an already elevated state.
82+
The best and most reliable approach was to duplicate the low privileged token of the desktop shell in an interactive logon (explorer.exe).
83+
However, there may be use cases in which WhoYouCalling is executed via a remote management tool like PowerShell, SSH or PsExec, where there is no instance of a desktop shell, in these case you need to provide a username and password of a user that may execute it.
7984

8085
### Dependencies
81-
This project has been tested and works with .NET 8 with two external libraries for capturing ETW activity and network packets:
86+
This project has been tested and works with .NET 8 with two nuget packages, and drivers for capturing network packets:
8287
- FPC:
8388
- [SharpCap](https://github.com/dotpcap/sharppcap)
8489
- [Npcap](https://npcap.com/#download)
@@ -121,7 +126,6 @@ bin\Release\net8.0\win-x64\WhoYouCalling.exe [arguments]...
121126
### To Do:
122127
- Refactor. Lots and lots to refactor and make more tidy :)
123128
- Add wireshark filter per domain name as their resolved IP addresses can be converted
124-
- Add privileged execution option to spawn the process as administrator
125129
- Add requirement of npcap drivers if pcap interface specified. It would be nice if the drivers are not a requirement when you're specifying `--nopcap` flag.
126130

127131
### Nice to have

WhoYouCalling.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<Platforms>AnyCPU;x64;x86</Platforms>
9-
<FileVersion>1.0</FileVersion>
9+
<FileVersion>1.1</FileVersion>
1010
<ApplicationManifest>WhoYouCalling\app.manifest</ApplicationManifest>
1111
</PropertyGroup>
1212

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+

2+
namespace WhoYouCalling
3+
{
4+
static class Constants
5+
{
6+
public const uint QueryInformation = 0x00000400;
7+
public const uint LogonFlags = 0;
8+
public const uint CreationFlags = 0;
9+
10+
public const Int32 ImpersonationSecurity = 2;
11+
public const Int32 TokenDuplicate = 2;
12+
public const Int32 TokenQuery = 8;
13+
public const Int32 TokenAssignPrimary = 1;
14+
public const Int32 TokenAdjustDefault = 0x80;
15+
public const Int32 TokenAdjustSessionID= 0x100;
16+
17+
public const Int32 PacketCaptureTimeoutMilliseconds = 1000;
18+
19+
public const Int32 ETWSubscriptionTimingTime = 3000;
20+
21+
public const Int32 CombinedFilterProcessID = 0;
22+
23+
24+
// File names
25+
//// Root folder
26+
public const string RootFolderEntirePcapFileName = "Full network packet capture.pcap";
27+
public const string RootFolderAllProcessesFilteredPcapFileName = "All processes network packets.pcap";
28+
public const string RootFolderDFLFilterFileName = "All processes wireshark filter.txt";
29+
public const string RootFolderBPFFilterFileName = "All processes BPF-filter.txt";
30+
public const string RootFolderETWHistoryFileName = "ETW history.txt";
31+
public const string RootFolderJSONProcessDetailsFileName = "Process details.json";
32+
public const string RootFolderJSONDNSResponseFileName = "DNS responses.json";
33+
34+
//// Per Process
35+
public const string ProcessFolderPcapFileName = "Network packets.pcap";
36+
public const string ProcessFolderBPFFilterFileName = "BPF-filter.txt";
37+
public const string ProcessFolderDFLFilterFileName = "Wireshark filter.txt";
38+
public const string ProcessFolderDNSQueriesFileName = "DNS queries.txt";
39+
public const string ProcessFolderIPv4TCPEndpoints = "IPv4 TCP Endpoints.txt";
40+
public const string ProcessFolderIPv6TCPEndpoints = "IPv6 TCP Endpoints.txt";
41+
public const string ProcessFolderIPv4UDPEndpoints = "IPv4 UDP Endpoints.txt";
42+
public const string ProcessFolderIPv6UDPEndpoints = "IPv6 UDP Endpoints.txt";
43+
public const string ProcessFolderIPv4LocalhostEndpoints = "Localhost Endpoints.txt";
44+
public const string ProcessFolderIPv6LocalhostEndpoints = "Localhost Endpoints IPv6.txt";
45+
}
46+
}

WhoYouCalling/ETW/DNSClientListener.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
using Microsoft.Diagnostics.Tracing.Session;
33
using WhoYouCalling.Network.DNS;
44
using WhoYouCalling.Utilities;
5-
using WhoYouCalling.WhoYouCalling.Network;
5+
using WhoYouCalling.Network;
66

77
namespace WhoYouCalling.ETW
88
{
99
internal class DNSClientListener : Listener
1010
{
11+
12+
public DNSClientListener()
13+
{
14+
SourceName = "DNS";
15+
}
16+
1117
public void Listen()
1218
{
1319
using (_session = new TraceEventSession("WhoYouCallingDNSClientSession"))
@@ -35,7 +41,7 @@ private void DnsClientEvent(TraceEvent data)
3541
ConsoleOutput.Print($"Attempted to parse retrieved DNS Query type. Failed to parse it", PrintType.Debug);
3642
queryTypeCode = 999999; // Non-existing DNS type value. Is later looked up
3743
}
38-
string dnsRecordTypeCodeName = DnsTypeLookup.GetName(queryTypeCode); // Retrieve the DNS type code name
44+
string dnsRecordTypeCodeName = DnsCodeLookup.GetDnsTypeName(queryTypeCode); // Retrieve the DNS type code name
3945

4046
DNSQuery dnsQuery = new DNSQuery
4147
{
@@ -89,8 +95,8 @@ private void DnsClientEvent(TraceEvent data)
8995
queryTypeCode = 999999; // Non-existing DNS type value. Is later looked up
9096
}
9197

92-
string dnsRecordTypeCodeName = DnsTypeLookup.GetName(queryTypeCode); // Retrieve the DNS type code name
93-
string dnsResponseStatusCodeName = DnsStatusLookup.GetName(queryStatusCode); // Retrieve the DNS response status code name
98+
string dnsRecordTypeCodeName = DnsCodeLookup.GetDnsTypeName(queryTypeCode); // Retrieve the DNS type code name
99+
string dnsResponseStatusCodeName = DnsCodeLookup.GetDnsStatusName(queryStatusCode); // Retrieve the DNS response status code name
94100

95101
DNSResponse dnsResponseQuery = new DNSResponse
96102
{

WhoYouCalling/ETW/KernelListener.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace WhoYouCalling.ETW
77
{
88
internal class KernelListener : Listener
99
{
10+
public KernelListener()
11+
{
12+
SourceName = "Kernel";
13+
}
14+
1015
public void Listen()
1116
{
1217
using (_session = new TraceEventSession(KernelTraceEventParser.KernelSessionName)) //KernelTraceEventParser
@@ -119,7 +124,7 @@ private void childProcessStarted(ProcessTraceData data)
119124
execObject: data.ImageFileName,
120125
execPID: data.ProcessID,
121126
parentExecPID: data.ParentID);
122-
if (Program.TrackChildProcesses)
127+
if (Program.TrackChildProcesses())
123128
{
124129
Program.AddChildPID(data.ProcessID);
125130
Program.InstantiateProcessVariables(pid: data.ProcessID, executable: data.ImageFileName);

WhoYouCalling/ETW/Listener.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ internal class Listener
99
protected int _trackedProcessId = 0;
1010
protected string _mainExecutableFileName = "";
1111
protected TraceEventSession _session;
12+
public string SourceName = "";
1213

1314
public bool IsAMonitoredProcess(int pid)
1415
{
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+

2+
namespace WhoYouCalling.Network.DNS
3+
{
4+
public enum DnsStatusType : int
5+
{
6+
// Official DNS standard types
7+
NoError = 0,
8+
FormErr = 1,
9+
ServFail = 2,
10+
NXDomain = 3,
11+
NotImp = 4,
12+
Refused = 5,
13+
YXDomain = 6,
14+
YXRRSet = 7,
15+
NXRRSet = 8,
16+
NotAuth = 9,
17+
NotZone = 10,
18+
BADVERS = 16,
19+
BADKEY = 17,
20+
BADTIME = 18,
21+
BADMODE = 19,
22+
BADNAME = 20,
23+
BADALG = 21,
24+
BADTRUNC = 22,
25+
BADCOOKIE = 23,
26+
27+
// Custom Windows types
28+
InvalidParameter = 87,
29+
DnsServerUnableToInterpretFormat = 9001,
30+
DnsServerFailure = 9002,
31+
DnsNameDoesNotExist = 9003,
32+
DnsRequestNotSupportedByNameServer = 9004,
33+
DnsOperationRefused = 9005,
34+
DnsNameThatOughtNotExistDoesExist = 9006,
35+
DnsRRSetThatOughtNotExistDoesExist = 9007,
36+
DnsRRSetThatOughtToExistDoesNotExist = 9008,
37+
DnsServerNotAuthoritativeForZone = 9009,
38+
DnsNameInUpdateOrPrereqIsNotInZone = 9010,
39+
DnsSignatureFailedToVerify = 9016,
40+
DnsBadKey = 9017,
41+
DnsSignatureValidityExpired = 9018,
42+
NoRecordsFoundForGivenDnsQuery = 9501,
43+
BadDnsPacket = 9502,
44+
NoDnsPacket = 9503,
45+
UnsecuredDnsPacket = 9505,
46+
47+
// Custom value for non-existent DNS status
48+
NA = 999999
49+
}
50+
}

WhoYouCalling/Enums/DnsType.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+

2+
namespace WhoYouCalling.Network.DNS
3+
{
4+
public enum DnsType : int
5+
{
6+
A = 1, // Address record
7+
NS = 2, // Name server record
8+
CNAME = 5, // Canonical name record
9+
SOA = 6, // Start of authority record
10+
PTR = 12, // Pointer record (reverse DNS)
11+
MX = 15, // Mail exchange record
12+
TXT = 16, // Text record
13+
AAAA = 28, // IPv6 address record
14+
SRV = 33, // Service locator
15+
ANY = 255, // Any type (wildcard)
16+
RP = 17, // Responsible person
17+
AFSDB = 18, // AFS database record
18+
LOC = 29, // Location record
19+
NAPTR = 35, // Naming authority pointer
20+
KX = 36, // Key exchange
21+
CERT = 37, // Certificate record
22+
DNAME = 39, // Delegation name
23+
OPT = 41, // Option record
24+
APL = 42, // Address prefix list
25+
DS = 43, // Delegation signer
26+
SSHFP = 44, // SSH fingerprint
27+
IPSECKEY = 45, // IPSEC key
28+
RRSIG = 46, // Resource record signature
29+
NSEC = 47, // Next secure record
30+
DNSKEY = 48, // DNS key
31+
DHCID = 49, // DHCP identifier
32+
NSEC3 = 50, // Next secure record version 3
33+
NSEC3PARAM = 51, // NSEC3 parameters
34+
TLSA = 52, // TLSA record
35+
SMIMEA = 53, // S/MIME cert association
36+
HIP = 55, // Host identity protocol
37+
CDS = 59, // Child DS
38+
CDNSKEY = 60, // Child DNSKEY
39+
OPENPGPKEY = 61, // OpenPGP key record
40+
CSYNC = 62, // Child-to-parent synchronization
41+
ZONEMD = 63, // Message digest for DNS zone
42+
SVCB = 64, // Service binding
43+
HTTPS = 65, // HTTPS binding
44+
TKEY = 249, // Transaction key
45+
TSIG = 250, // Transaction signature
46+
IXFR = 251, // Incremental zone transfer
47+
AXFR = 252, // Authoritative zone transfer
48+
URI = 256, // URI record
49+
CAA = 257, // Certification authority authorization
50+
AVC = 258, // Application visibility and control
51+
AMTRELAY = 260, // Automatic multicast tunneling relay
52+
TA = 32768, // DNSSEC Trust Authorities
53+
DLV = 32769, // DNSSEC Lookaside Validation
54+
55+
NA = 999999 // Custom Non-existent DNS Type Value
56+
}
57+
}

0 commit comments

Comments
 (0)