Skip to content

Commit 6651997

Browse files
committed
Filtering the internet_detector tool ICMP requests at fakenet
1 parent a5ba683 commit 6651997

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

packages/fakenet-ng.vm/tools/default.ini

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ DefaultUDPListener: ProxyUDPListener
116116
BlackListPortsTCP: 139
117117
BlackListPortsUDP: 67, 68, 137, 138, 443, 1900, 5355
118118

119+
# Specify ICMP IDs to be ignored when diverting the packets.
120+
# BlackListIDsICMP: 1234
121+
119122
# Specify processes to ignore when diverting traffic. Windows example used
120123
# here.
121-
ProcessBlackList: internet_detector.exe
124+
# ProcessBlackList: java.exe
122125

123126
# Specify processes to consider when diverting traffic (others will be
124127
# ignored). Linux examples used here.

packages/internet_detector.vm/tools/chocolateyinstall.ps1

+17-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ $toolName = 'internet_detector'
55
$category = 'Networking'
66
$packageToolDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
77

8+
# Modify fakenet's configuration to ignore the internet detector traffic
9+
$fakenetConfig = "$Env:RAW_TOOLS_DIR\fakenet\fakenet3.3\configs\config.ini"
10+
VM-Assert-Path $fakenetConfig
11+
12+
$IcmpID = Get-Random -Maximum 0x10000
13+
$config = Get-Content -Path $fakenetConfig
14+
$config = $config -replace '^.*BlackListIDsICMP.*$', "BlackListIDsICMP: $IcmpID"
15+
Set-Content -Path $fakenetConfig -Value $config -Encoding UTF8 -Force
16+
817
# Create tool directory
918
$toolDir = Join-Path ${Env:RAW_TOOLS_DIR} $toolName
1019
New-Item -Path $toolDir -ItemType Directory -Force -ea 0
@@ -14,8 +23,15 @@ VM-Assert-Path $toolDir
1423
$dependencies = "pyinstaller==6.11.1,pywin32==308,icmplib==3.0.4"
1524
VM-Pip-Install $dependencies
1625

26+
# Set the ICMP ID at the tool script
27+
$scriptPath = "$packageToolDir\internet_detector.pyw"
28+
$tempScript = Join-Path ${Env:TEMP} "temp_$([guid]::NewGuid())"
29+
$script = Get-Content -Path $scriptPath
30+
$script = $script -replace '^ICMP_ID.*$', "ICMP_ID = $IcmpID"
31+
Set-Content -Path $tempScript -Value $script -Encoding UTF8 -Force
32+
1733
# This wrapper is needed because PyInstaller emits an error when running as admin and this mitigates the issue.
18-
Start-Process -FilePath 'cmd.exe' -WorkingDirectory $toolDir -ArgumentList "/c pyinstaller --onefile -w --log-level FATAL --distpath $toolDir --workpath $packageToolDir --specpath $packageToolDir $packageToolDir\internet_detector.pyw" -Wait
34+
Start-Process -FilePath 'cmd.exe' -WorkingDirectory "$toolDir" -ArgumentList "/c pyinstaller --onefile -w --log-level FATAL --distpath `"$toolDir`" --workpath `"$packageToolDir`" --specpath `"$packageToolDir`" `"$tempScript`"" -Wait
1935

2036
# Move images to %VM_COMMON_DIR% directory
2137
$imagesPath = Join-Path $packageToolDir "images"

packages/internet_detector.vm/tools/chocolateyuninstall.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ $category = 'Utilities'
66

77
VM-Uninstall $toolName $category
88
Unregister-ScheduledTask -TaskName 'Internet Detector' -Confirm:$false
9+
10+
$fakenetConfig = "$Env:RAW_TOOLS_DIR\fakenet\fakenet3.3\configs\config.ini"
11+
$config = Get-Content -Path $fakenetConfig
12+
$config = $config -replace '^.*BlackListIDsICMP.*$', "# BlackListIDsICMP: 1234"
13+
Set-Content -Path $fakenetConfig -Value $config -Encoding UTF8 -Force

packages/internet_detector.vm/tools/internet_detector.pyw

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CHECK_INTERVAL = 2 # Seconds
3636
# no DNS resolution is needed.
3737
# - The used IP addresses are some of the largest public DNS servers to
3838
# ensure zero or minimal downtime.
39+
ICMP_ID = 1234
3940
TEST_IPS = [
4041
"8.8.8.8", # Google
4142
"8.8.4.4", # Google
@@ -315,7 +316,7 @@ def check_internet():
315316
for ip_address in TEST_IPS:
316317
try:
317318
# Perform internet connectivity tests
318-
ip_host = icmplib.ping(ip_address, 1)
319+
ip_host = icmplib.ping(ip_address, 1, id=ICMP_ID)
319320
if ip_host.is_alive:
320321
print(f"Internet connectivity detected via IP: {ip_address}")
321322
return True

0 commit comments

Comments
 (0)