iamtheyammer

virtualbox hiding

Aug 24th, 2018
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.24 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import re
  4. import subprocess
  5. import sys
  6. import os
  7. import json
  8.  
  9. from pprint import pprint
  10.  
  11. def cloneMAC():
  12. ifconfig_out = runcmd(["/sbin/ifconfig","eth0"])
  13. regex = r"([0-9A-F]{2}[:-]){5}([0-9A-F]{2})"
  14. pat = re.compile(regex, re.I | re.S | re.M)
  15. for line in ifconfig_out:
  16. if pat.search(line):
  17. mac = pat.match(line).group().split(":")
  18. pprint(mac)
  19. mac[0] = int(mac[0], 16)
  20. mac[1] = int(mac[1], 16)
  21. mac[2] = int(mac[2], 16)
  22. mac[3] = random.randint(0x00, 0x7f)
  23. mac[4] = random.randint(0x00, 0xff)
  24. mac[5] = random.randint(0x00, 0xff)
  25. pprint(mac)
  26. return ''.join(map(lambda x: "%02x" % x, mac))
  27.  
  28. def randomMAC():
  29. # 00:1b:fc = ASUSTek COMPUTER INC.
  30. mac = [ 0x00, 0x1b, 0xfc,
  31. random.randint(0x00, 0x7f),
  32. random.randint(0x00, 0xff),
  33. random.randint(0x00, 0xff) ]
  34. return ''.join(map(lambda x: "%02x" % x, mac))
  35.  
  36. def getnewmac(hostname):
  37. regex = r"(%s)\s+([0-9A-Fa-f]+)\s+([0-9\.]+)" % hostname
  38. pat = re.compile(regex, re.I | re.S | re.M)
  39. with open("/MART/etc/macs.txt") as fh:
  40. for line in fh:
  41. if pat.search(line):
  42. (hostname,mac,ip) = pat.match(line).groups()
  43. if mac:
  44. return mac
  45. return randomMAC()
  46.  
  47. def runcmd(cmd):
  48. try:
  49. print "Executing %s" % ' '.join(cmd)
  50. output = subprocess.check_output(cmd)
  51. print output
  52. return output
  53. except:
  54. print "Failed"
  55. return None
  56.  
  57. # Gather system information
  58. def getdmi():
  59. dmi = {}
  60.  
  61. # Anti-VM detection, DMI BIOS information (type 0)
  62. dmitmp = runcmd(["sudo","dmidecode","-t0"])
  63. dmi['DmiBIOSVendor'] = re.search("Vendor: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  64. dmi['DmiBIOSVersion'] = "string:" + re.search("Version: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  65. dmi['DmiBIOSReleaseDate']= re.search("Release Date: ([0-9\\/\\-]+)", dmitmp, re.I | re.S | re.M).group(1)
  66.  
  67. # Anti-VM detection, DMI BIOS information (type 1)
  68. dmitmp = runcmd(["sudo","dmidecode","-t1"])
  69. dmi['DmiSystemVendor'] = re.search("Manufacturer: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  70. dmi['DmiSystemProduct'] = re.search("Product Name: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  71. dmi['DmiSystemVersion'] = "string:" + re.search("Version: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  72. dmi['DmiSystemSerial'] = "string:" + re.search("Serial Number: ([0-9A-Z\\ \\-]+)", dmitmp, re.I | re.S | re.M).group(1)
  73. dmi['DmiSystemSKU'] = re.search("SKU Number: ([0-9A-Z\\ \\-\\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  74. dmi['DmiSystemFamily'] = re.search("Family: ([0-9A-Z\\ \\-\\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  75. dmi['DmiSystemUuid'] = re.search("UUID: ([0-9A-Z\\-]+)", dmitmp, re.I | re.S | re.M).group(1)
  76.  
  77. # Anti-VM detection, DMI BIOS information (type 2)
  78. MotherboardTypes = [
  79. "Unknown",
  80. "Other",
  81. "Server Blade",
  82. "Connectivity Switch",
  83. "System Management Module",
  84. "Processor Module",
  85. "I/O Module",
  86. "Memory Module",
  87. "Daughter Board",
  88. "Motherboard",
  89. "Processor+Memory Module",
  90. "Processor+I/O Module",
  91. "Interconnect Board"
  92. ]
  93.  
  94. dmitmp = runcmd(["sudo","dmidecode","-t2"])
  95.  
  96. dmi['DmiBoardVendor'] = re.search("Manufacturer: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  97. dmi['DmiBoardProduct'] = re.search("Product Name: ([A-Z0-9\\ \\.\\-/]+)", dmitmp, re.I | re.S | re.M).group(1)
  98. dmi['DmiBoardVersion'] = "string:" + re.search("Version: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  99. dmi['DmiBoardSerial'] = "string:" + re.search("Serial Number: ([0-9A-Z\\ \\-]+)", dmitmp, re.I | re.S | re.M).group(1)
  100. dmi['DmiBoardAssetTag'] = re.search("Asset Tag: ([0-9A-Z\\ \\-\\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  101. dmi['DmiBoardLocInChass'] = re.search("Location In Chassis: ([0-9A-Z\\ \\-\\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  102. dmi['DmiBoardBoardType'] = str(MotherboardTypes.index(re.search("Type: ([0-9A-Z\\ \\-]+)", dmitmp, re.I | re.S | re.M).group(1))+1)
  103.  
  104. # Anti-VM detection, DMI system enclosure or chassis (type 3)
  105. ChassiTypes = [
  106. "Other",
  107. "Unknown",
  108. "Desktop",
  109. "Low Profile Desktop",
  110. "Pizza Box",
  111. "Mini Tower",
  112. "Tower",
  113. "Portable",
  114. "Laptop",
  115. "Notebook",
  116. "Hand Held",
  117. "Docking Station",
  118. "All In One",
  119. "Sub Notebook",
  120. "Space-saving",
  121. "Lunch Box",
  122. "Main Server Chassis",
  123. "Expansion Chassis",
  124. "Sub Chassis",
  125. "Bus Expansion Chassis",
  126. "Peripheral Chassis",
  127. "RAID Chassis",
  128. "Rack Mount Chassis",
  129. "Sealed-case PC",
  130. "Multi-system",
  131. "CompactPCI",
  132. "AdvancedTCA",
  133. "Blade",
  134. "Blade Enclosing"
  135. ]
  136.  
  137. dmitmp = runcmd(["sudo","dmidecode","-t3"])
  138. dmi['DmiChassisVendor'] = re.search("Manufacturer: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  139. dmi['DmiChassisType'] = str(ChassiTypes.index(re.search("Type: ([0-9A-Z\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1))+1)
  140. dmi['DmiChassisVersion'] = "string:" + re.search("Version: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  141. dmi['DmiChassisSerial'] = "string:" + re.search("Serial Number: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  142. dmi['DmiChassisAssetTag'] = re.search("Asset Tag: ([A-Z0-9\\ \\.\\-]+)", dmitmp, re.I | re.S | re.M).group(1)
  143.  
  144. # Anti-VM detection, DMI processor informatiion (type 4)
  145. dmitmp = runcmd(["sudo","dmidecode","-t4"])
  146. dmi['DmiProcManufacturer'] = re.search("Manufacturer: ([A-Z0-9\\ \\.]+)", dmitmp, re.I | re.S | re.M).group(1)
  147. dmi['DmiProcVersion'] = "string:" + re.search("Version: ([A-Z0-9\\ \\.\\(\\)\\-]+)", dmitmp, re.I | re.S | re.M).group(1)
  148.  
  149. for key, value in dmi.iteritems():
  150. if value == None:
  151. del dmi[key]
  152. else:
  153. if isinstance( value, ( int, long ) ):
  154. dmi[key] = str(value)
  155. else:
  156. dmi[key] = value.strip()
  157. return dmi
  158.  
  159. dmi = None
  160. try:
  161. fh = open('/MART/etc/dmi.txt', 'r')
  162. if fh:
  163. dmi = json.load(fh)
  164. fh.close()
  165. except Exception:
  166. dmi = getdmi()
  167. with open('/MART/etc/dmi.txt', 'w') as outfile:
  168. json.dump(dmi, outfile, sort_keys=True, indent=4, separators=(',', ': '))
  169. print json.dumps(dmi, sort_keys=True, indent=4, separators=(',', ': '))
  170.  
  171. # Globals, of sorts
  172. DSDT_BIN="/MART/etc/DSDT.BIN"
  173. VBoxManage = '/usr/bin/VBoxManage'
  174.  
  175. # Get the DSDT
  176. if not os.path.exists(DSDT_BIN):
  177. try:
  178. runcmd(['sudo','acpidump','-t','DSDT','-o',DSDT_BIN,'-b'])
  179. except:
  180. runcmd(['sudo','cat','/sys/firmware/acpi/tables/DSDT','>',DSDT_BIN])
  181.  
  182. for target in sys.argv[1:]:
  183. # Configure all the virtual BIOS setings
  184. for key, value in dmi.iteritems():
  185. runcmd([VBoxManage,"setextradata",target,"VBoxInternal/Devices/pcbios/0/Config/" + key,value])
  186.  
  187. # Configure DSDT
  188. if os.path.exists(DSDT_BIN):
  189. runcmd([VBoxManage,"setextradata",target,"VBoxInternal/Devices/acpi/0/Config/CustomTable",DSDT_BIN])
  190.  
  191. # Setting guest MAC
  192. #newmac = getnewmac(target)
  193. newmac = cloneMAC()
  194. runcmd([VBoxManage,"modifyvm",target,"--macaddress1",newmac])
  195.  
  196. # Enable memory ballooning
  197. runcmd([VBoxManage,"modifyvm",target,"--pagefusion","on"])
  198. dmi = None
  199. try:
  200. fh = open('/MART/etc/dmi.txt', 'r')
  201. if fh:
  202. dmi = json.load(fh)
  203. fh.close()
  204. except Exception:
  205. dmi = getdmi()
  206. with open('/MART/etc/dmi.txt', 'w') as outfile:
  207. json.dump(dmi, outfile, sort_keys=True, indent=4, separators=(',', ': '))
  208. print json.dumps(dmi, sort_keys=True, indent=4, separators=(',', ': '))
  209.  
  210. # Globals, of sorts
  211. DSDT_BIN="/MART/etc/DSDT.BIN"
  212. VBoxManage = '/usr/bin/VBoxManage'
  213.  
  214. # Get the DSDT
  215. if not os.path.exists(DSDT_BIN):
  216. try:
  217. runcmd(['sudo','acpidump','-t','DSDT','-o',DSDT_BIN,'-b'])
  218. except:
  219. runcmd(['sudo','cat','/sys/firmware/acpi/tables/DSDT','>',DSDT_BIN])
  220.  
  221. for target in sys.argv[1:]:
  222. # Configure all the virtual BIOS setings
  223. for key, value in dmi.iteritems():
  224. runcmd([VBoxManage,"setextradata",target,"VBoxInternal/Devices/pcbios/0/Config/" + key,value])
  225.  
  226. # Configure DSDT
  227. if os.path.exists(DSDT_BIN):
  228. runcmd([VBoxManage,"setextradata",target,"VBoxInternal/Devices/acpi/0/Config/CustomTable",DSDT_BIN])
  229.  
  230. # Setting guest MAC
  231. #newmac = getnewmac(target)
  232. newmac = cloneMAC()
  233. runcmd([VBoxManage,"modifyvm",target,"--macaddress1",newmac])
  234.  
  235. # Enable memory ballooning
  236. runcmd([VBoxManage,"modifyvm",target,"--pagefusion","on"])
  237.  
  238. # Configure VRDP
  239. runcmd([VBoxManage,"modifyvm",target,"--vrde","on"])
  240. runcmd([VBoxManage,"modifyvm",target,"--vrdeport",str(3389 + int(target.split("-")[2]))])
Advertisement
Add Comment
Please, Sign In to add comment