Phython - Firewall/Desktop Action

Job ID: 36487233

Budget: €30 – €250 EUR

Hi,

I am struggeling with that code. I need to block any outgoing traffic except traffic to 80.64.129.139. When program (python) is running then the desktop wallpaper should be changed:

Program runs thru but nothing happens. I still can connect to internet, the desktop is not changed.


import os
import subprocess
import hashlib
import ctypes

# Liest das verschlüsselte Administrator-Passwort aus der Datei
password_file = 'C:\\Program Files (x86)\\Gafa Exam\\Files\\password-sl.txt'
with open(password_file, 'rb') as f:
encrypted_password = f.read()

# Entschlüsselt das Passwort mit MD5
md5_object = hashlib.md5()
md5_object.update(encrypted_password)
decrypted_password = md5_object.hexdigest()

# Netzwerkverbindungen zu Public IP Adressen blockieren
block_cmd = 'netsh advfirewall firewall add rule name=\'Block - All\' dir=out action=block protocol=TCP localip=any remoteip=any'
subprocess.Popen(['runas', '/user:offic', 'cmd', '/c', 'echo', decrypted_password, '|', 'powershell', '-Command', block_cmd], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

# Netzwerkverbindung zur IP-Adresse 80.64.129.139 erlauben
allow_cmd = "netsh advfirewall firewall add rule name='Allow - Gafa' dir=out action=allow protocol=TCP localip=any remoteip=80.64.129.139"
subprocess.Popen(['runas', '/user:offic', 'cmd', '/c', 'echo', decrypted_password, '|', 'powershell', '-Command', allow_cmd], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

# Desktop-Hintergrundbild ändern
image_path = 'C:\\Program Files (x86)\\Gafa Exam\\Images\\block.png'
subprocess.Popen(['runas', '/user:offic', 'cmd', '/c', 'echo', decrypted_password, '|', 'powershell', '-Command', 'REG', 'ADD', 'HKCU\\Control Panel\\Desktop', '/v', 'Wallpaper', '/t', 'REG_SZ', '/d', image_path, '/f'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
subprocess.Popen(['runas', '/user:offic', 'cmd', '/c', 'echo', decrypted_password, '|', 'powershell', '-Command', 'RUNDLL32.EXE', 'user32.dll,UpdatePerUserSystemParameters'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

# Meldung anzeigen, wenn alle Befehle erfolgreich ausgeführt wurden
ctypes.windll.user32.MessageBoxW(None, "Der PC ist nun im Prüfungsmodus.", "Erfolgreich", 0x40 | 0x1)
Related categories: C Programming Python Linux Shell Script C++ Programming