Skip to content

Commit

Permalink
Port scanning (#231)
Browse files Browse the repository at this point in the history
* Add port scanning alongside network scanning

* drop unnecessary script tag
  • Loading branch information
kdzwinel authored Sep 24, 2024
1 parent 06df702 commit b875490
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
2 changes: 0 additions & 2 deletions privacy-protections/bounce-tracking/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bounce Tracking Test Page</title>

<script src='./main.js' defer></script>
</head>
<body>
<p><a href="../../">[Home]</a><a href="../">[Privacy Protections Tests]</a><strong>[Bounce Tracking Test Page]</strong></p>
Expand Down
43 changes: 37 additions & 6 deletions privacy-protections/local-port-scan/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
<body>
<p><a href="../../">[Home]</a><a href="../">[Privacy Protections Tests]</a><strong>[Local Port Scanning]</strong></p>

<p>Trackers scan local network as a fingerprinting technique. This page runs such a scan.</p>
<p>Trackers scan local network as a fingerprinting technique. This page allows to run a network scan and a port scan.</p>
<p>Depending if this page was loaded over http or https this page will load local resources over the same protocol.</P>

<p>Scan range: <input id="range" value='192.168.1' />.*</p>
<p>Timeout: <input id="timeout" value='1000' />ms</p>
<button id="start">start</button>
<button id="startNetworkScan">start local network scan</button>
<button id="startPortScan">start localhost port scan</button>

<ul id="output"></ul>

<script>
const protocol = location.protocol;
const output = document.getElementById('output');

async function run () {
async function runNetworkScan () {
output.innerHTML = '';
const timeout = Number.parseInt(document.getElementById('timeout').value, 10);
const ipPrefix = document.getElementById('range').value;
Expand All @@ -32,8 +33,7 @@
const url = `${protocol}//${fullIP}/`;
const startTime = Date.now();
try {
const result = await fetch(url, { signal: AbortSignal.timeout(timeout) });
console.log(result);
await fetch(url, { signal: AbortSignal.timeout(timeout) });
} catch {

}
Expand All @@ -43,7 +43,38 @@
}
}

document.getElementById('start').addEventListener('click', run);
async function runPortScan () {
output.innerHTML = '';
// sorted by popularity
const commonPorts = [443, 80, 22, 5060, 8080, 1723, 53, 21, 8000, 3389, 8082, 8081, 993, 25, 23, 4567, 81, 3000];
const timeout = Number.parseInt(document.getElementById('timeout').value, 10);

for (const port of commonPorts) {
const url = `ws://localhost:${port}/`;
const startTime = Date.now();
try {
let res;
const promise = new Promise((resolve, reject) => { res = resolve; });
const ws = new WebSocket(url);
ws.onclose = res;
ws.onerror = res;
setTimeout(() => {
ws.close();
res();
}, timeout);

console.log(await promise);
} catch {

}
const responseTime = Date.now() - startTime;

output.innerHTML += `<li style='color: ${responseTime < 10 ? 'green' : 'red'}'>localhost:${port} (${responseTime}ms)</li>`;
}
}

document.getElementById('startNetworkScan').addEventListener('click', runNetworkScan);
document.getElementById('startPortScan').addEventListener('click', runPortScan);
</script>

</body>
Expand Down

0 comments on commit b875490

Please sign in to comment.