File size: 4,098 Bytes
bad179a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #!/usr/bin/env python3
"""Stand-in for powershell.exe so the Windows editions can be run on Linux.
Collector script on stdin -> emits synthetic Windows-format frames; anything else -> echoes the command."""
import math, random, re, sys, time
src = sys.stdin.read()
if '@@SNAP_BEGIN' not in src:
cmd = src.strip().splitlines()
print('[fake powershell] would run:'); print('\n'.join(cmd[-6:])); sys.exit(0)
iv = float((re.search(r'\$iv\s*=\s*([\d.]+)', src) or [0, 2])[1]); once = '$once = $true' in src
GB = 1 << 30; n = 0; rx = tx = 5e9; cput = {4: 9e9, 620: 1e8, 1200: 5e9, 2040: 3e9, 3311: 1e9, 4100: 2e8, 5000: 7e8}
names = {4: 'System', 620: 'svchost.exe', 1200: 'sqlservr.exe', 2040: 'chrome.exe', 3311: 'explorer.exe', 4100: 'powershell.exe', 5000: 'w3wp.exe'}
boot = time.time() - 4 * 86400 - 3600
while True:
t = time.time(); L = ['@@SNAP_BEGIN']
if n % 15 == 0:
L += ['@@S info', 'hostname=WIN-FAKE01', 'os=Microsoft Windows Server 2022 Standard', 'kernel=10.0.20348', 'arch=64-bit',
'cpumodel=Intel(R) Xeon(R) Gold 6248 CPU @ 2.50GHz', 'mhz=2500', 'virt=Microsoft Corporation Virtual Machine', 'admin=1',
'@@S users'] + [f'{p}|{"NT AUTHORITY\\SYSTEM" if p < 2000 else "WIN-FAKE01\\admin"}' for p in names]
cpu = 35 + 30 * math.sin(t / 20) + random.uniform(-5, 5)
L += ['@@S os', f'ts={int(t * 1000)}', f'uptime={int(t - boot)}', f'memtotal={16 * GB}', f'swaptotal={8 * GB}', f'swapfree={int(6.5 * GB)}', '@@S cpu']
for c in ['_Total', '0', '1', '2', '3']:
v = max(0, min(100, cpu + (0 if c == '_Total' else random.uniform(-15, 15))))
L.append(f'{c}|{v:.0f}|{v * .7:.0f}|{v * .3:.0f}|{v * .03:.0f}|{int(3000 + v * 40)}')
L += ['@@S sys', f'queue={int(max(0, cpu - 50) / 10)}', f'ctxt={int(8000 + cpu * 100)}', 'threads=1832',
'@@S mem', f'avail={int((6 + math.sin(t / 60)) * GB)}', f'free={2 * GB}', f'standby={4 * GB}', f'syscache={GB // 2}', f'modified={GB // 8}',
f'pool={GB}', f'commit={11 * GB}', f'commitlimit={24 * GB}', f'pages={int(random.uniform(0, 40))}', '@@S net']
rx += random.uniform(2e5, 9e5) * iv; tx += random.uniform(5e4, 3e5) * iv
L += [f'Ethernet|Up|10000|Ethernet|{int(rx)}|{int(tx)}|{int(rx / 900)}|{int(tx / 700)}|0|3|Microsoft Hyper-V Network Adapter',
'Loopback Pseudo-Interface 1|Up|1073|Loopback|0|0|0|0|0|0|Software Loopback Interface 1',
'vEthernet (WSL)|Down|0|Ethernet|1200|900|10|9|0|0|Hyper-V Virtual Ethernet Adapter',
'@@S tcp', 'Established 42', 'TimeWait 3', 'CloseWait 1', 'Listen 27', '@@S disk',
f'0 C:|{int(random.uniform(0, 4e6))}|{int(random.uniform(0, 9e6))}|{int(random.uniform(0, 80))}|{int(random.uniform(0, 200))}|{int(random.uniform(60, 100))}',
f'1 D:|0|{int(random.uniform(0, 1e5))}|0|2|99', '@@S df', f'C:\\|Windows|NTFS|{127 * GB}|{int(21.5 * GB)}', f'D:\\|Data|NTFS|{500 * GB}|{310 * GB}', '@@S procs',
f'0|0|{int((t - boot) * 4e7)}|0|4|0|8192|8192|System Idle Process']
for p, nm in names.items():
cput[p] += (random.uniform(0, .02) + (.6 if p == 1200 else .05 if p == 2040 else 0) * (1 + math.sin(t / 15))) * iv * 1e7
L.append(f'{p}|{4 if p > 4 else 0}|{int(cput[p])}|{8 if p != 4100 else 6}|{12 + p % 40}|{int(boot + p)}|{(2 + p % 5) * GB}|{int((.05 + (p % 7) * .11) * GB)}|{nm}')
L += ['@@S sessions', '1']
if n % 5 == 0:
L += ['@@S services', 'Spooler|Running|Auto|0|Print Spooler', 'W3SVC|Running|Auto|0|World Wide Web Publishing Service', 'MSSQLSERVER|Running|Auto|0|SQL Server (MSSQLSERVER)',
'BrokenSvc|Stopped|Auto|1067|Broken Demo Service', 'gupdate|Stopped|Auto|0|Google Update Service', 'RemoteRegistry|Stopped|Disabled|1077|Remote Registry',
'wuauserv|Stopped|Manual|0|Windows Update', 'WinDefend|Running|Auto|0|Microsoft Defender Antivirus Service']
L += ['@@S thermal', f'ACPI\\ThermalZone\\TZ00_0|{45 + cpu / 5:.1f}', '@@SNAP_END']
try: sys.stdout.write('\n'.join(L) + '\n'); sys.stdout.flush()
except OSError: sys.exit(0)
if once: break
n += 1; time.sleep(iv)
|