☠️
Uriel Berdeja
  • General
    • Virtual Machines Setup Notes
    • C++17 and C++20 Interesting Features
  • Windows
    • A walkthrough over Themida anti-debug techniques
    • Structured Exception Handlers
    • Win32 Authorization System
    • .NET CLR process internals
    • ClickOnce Technical Details
    • WebDAV Technical Details
    • Monikers
  • Uncategorized
    • Snippets
    • Windows Various Notes
    • Index of ingest resources
    • Tooling Resources
    • TODO List
Powered by GitBook
On this page
  • VirtualBox Network Setup
  • QEMU CentOS 7.2009
  • Cloud-based Virtualization
  • Amazon Web Services
  • Azure Cloud
  • MacOS and iOS
  • Android
  • Best way
  • Rootless
  • Root enabled

Was this helpful?

  1. General

Virtual Machines Setup Notes

Various notes on desktop and mobile virtualization

NextC++17 and C++20 Interesting Features

Last updated 8 months ago

Was this helpful?

VirtualBox Network Setup

For sophisticated malware sample, or mission critical reverse engineering tasks where target sample has advanced anti-VM capabilities or virtualization-based evasions (like an Hypervisor Ransomware) a Type 1 Hypervisor is suggested such as QEMU KVM, VMWare vSphere, Microsoft Hyper-V or Proxmox and nested virtualization enabled.

For scenarios that involve Reverse Engineering internet-based samples (Malware Analysis or Commercial Reverse Engineering) is needed to setup Remnux ( or any linux distro ) as default gateway in order to inspect every network package emitted.

  • REMNux:

    • NAT network

    • Internal Network

  • Windows:

    • Internal Network

Internal Network name must be the same in both machines

With this configuration Windows machine won't be able to access any asset outside the internal network.

In order to make REMNux forward network packages we must set the following option:

sysctl -w net.ipv4.ip_forward=1

And also for IPv6 protocol

sysctl -w net.ipv6.conf.all.forwarding=1

Host-Only shouldn't be used in the Windows machine because it will be possible to communicate with the host directly, instead we need to setup an internal network so Windows gets completely isolated.

REMNux first interface will be able to setup outband connections, but the second interface will handle the traffic coming from the Windows VM and redirect them to the NAT network, so we can enforce iptables rules that block unwanted connections.

Configure the ip address in the Remnux VM, to /etc/netplan/01-netcfg.yaml

network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 192.168.56.1/24
      dhcp4: yes
    eth1:
      addresses:
        - 10.10.1.1/24
        dhcp4: no

Use iptables to forward network packages from internal network interface to NAT interface:

# Masquerade the source IP with the host's IP address
iptables -t nat -A POSTROUTING -o <external_interface> -j MASQUERADE
# Reject incoming packets from the external interface to the internal interface that hasn't been established by the guest VM.
iptables -A FORWARD -i <external_interface> -o <internal_interface> -m state --state NEW -j REJECT
# Accept packets that has been established by the guest VM, and related packets, i.e FTP that uses one connection for control and other for data transm.
iptables -A FORWARD -i <external_interface> -o <internal_interface> -m state --state RELATED,ESTABLISHED -j ACCEPT
# Accept all packets coming from the internal VM network to the external network.
iptables -A FORWARD -i <internal_interface> -o <external_interface> -j ACCEPT

And do it the same for IPv6, note that IPv6 does not uses NAT so we need only to forward outgoing and incoming traffic without masquerading the IP address.

ip6tables -A FORWARD -i eth0 -o eth1 -m state --state NEW -j REJECT
ip6tables -A FORWARD -i <external_interface> -o <internal_interface> -m state --state RELATED,ESTABLISHED -j ACCEPT
ip6tables -A FORWARD -i <internal_interface> -o <external_interface> -j ACCEPT

Internal network as internal_interface and NAT network as external_interface

If you want to redirect traffic to a mitm proxy or another packet inspector:

iptables -t nat -A PREROUTING -i <internal_interface> -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i <internal_interface> -p tcp --dport 443 -j REDIRECT --to-port 8080
# IPv6 equivalent redirection rules
ip6tables -t nat -A PREROUTING -i <internal_interface> -p tcp --dport 80 -j REDIRECT --to-port 8080
ip6tables -t nat -A PREROUTING -i <internal_interface> -p tcp --dport 443 -j REDIRECT --to-port 8080

Iptables can also redirect udp protocol, update accordingly to your requirements.

If you want to change the destination host, as if you were using inetsim or fakenet and the connection is made without DNS resolution (direct IP address connection), use the action -j DNAT, with the --to-destination host:port , this will change the IP destination and port of the outgoing packet, so your server will be contacted.

VMWare sets up virtual machines with disabled promiscuous mode, edit the .vmx file of the VM and add the following lines per each n etwork interface

ethernet0.noPromisc = "FALSE"
ethernet1.noPromisc = "FALSE"

You can persist the iptables rules by saving them:

iptables-save | tee /etc/iptables/rules.v4

Then in the Windows Virtual Machine set up the default gateway and the default DNS server:

Later iptables could be configured to redirect the HTTP/HTTPs traffic to any MITM proxy.

Wireshark, Tshark and TCPdump can be used to inspect traffic flow going through internal network interface:

When using tshark or wireshark you can use "not http and not dns", so you can filter out http and dns requests, leaving all other TCP and UDP packets.

QEMU CentOS 7.2009

GenericCloud image .qcow2 for QEMU:

GenericCloud images for CentOS don't have a root password setup so we need libguestfs-tools package for adding it

virt-customize -a CentOS-7-x86_64-GenericCloud-2009.qcow2 --root-password password:thepass

Start virtual machine from virtual disk image and setup a virtual network emulating a E1000 chipset, then forward port from guest 22 to host 2222, setup the monitor to standard input output console so we can manage snapshots and use the QEMU serial terminal.

qemu-system-x86_64 -m 2048 -drive file=CentOS-7-x86_64-GenericCloud-2009.qcow2,format=qcow2 -netdev user,id=mynet0,hostfwd=tcp::2222-:22
  -device e1000,netdev=mynet0 -serial mon:stdio

If using -nographic setup the guest serial terminal will attach to current tty session, so is needed to redirect monitor terminal to telnet port.

All CentOS (EOL) releases need to be updated to use vault mirrrolists from centos

sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo

Cloud-based Virtualization

This scenario implies that you want to setup your custom virtual machines images that aren't in the cloud image marketplace (i.e Amazon Marketplace) and leverage cloud resources for that.

I strongly suggest to avoid this option if your budget is limited since i got charged up to 1k usd per month while using a top-notch setup like this. Avoid keeping the instances up and running if not needed, disks can be expensive tho.

Amazon Web Services

Amazon does not support nested virtualization so you will need to allocate a bare-metal instance, which also does not support GPUs. 🤷‍♂️

For MacOS virtualization Amazon has M1 chips and MacOS Amazon Machine Images (haven't tried it)

Azure Cloud

Some series support nested virtualization and some few of them has also GPU. D-series (v3, v4, including both standard and storage-optimized variants), E-series (v3, v4, including both standard and memory-optimized variants), F-series (v2, focusing on a balance of CPU and memory), the FX-series (specialized for high compute performance), and the M-series (optimized for memory and CPU performance)

You will need to setup a Windows Server 2022 VM image, since neither Windows 10 or 11 can run Hyper-V.

I suggest picking up a disk that has 12,000 max. uncached IO/s since nested virtual machines are likely to go slow with less that 6,000 IO/s

MacOS and iOS

As mentioned before macOS can be virtualized in AWS, but if you're looking to explore and use experimental features or trying to virtualize iOS outside the xcode iphone simulator keep going

There's work going on in fully virtualized iBoot chain, some useful links to get started:

Corellium offers the Corellium Solo product that charges 3/usd per hour for virtualization instances of iOS (the unique solution in the market)

Android

Best way

More or less depends on the final end and what you're trying to achieve, but the best and stealthier approach is using a physical device, yes, that's out of the scope of this article, and yes, sometimes you're going to need root privileges in the physical device, and since rooting in android is a cat-mouse game against protectors, packers and antiVM solutions the best approach is using a clean physical device, in order to achieve root-level execution you'll need to

a) Deploy a kernel exploit if the kernel of your device is vulnerable to one

b) Dump the NAND memory, modify it, and flash it back.

The second solution is preferable as it is an universal solution but hardware technical skills are needed and invest some pennies on tools.

Rootless

Setups that does not need root can be done using commercial emulators if you're in Windows for example Bluestacks.

On Mac M1 the only decent alternative to Android Virtual Device is Genymotion which does not support rootless environment.

In Linux, Android Emulator that has Google Play option are instances without root by default.

For downloading APK files directly from Google Play you need to setup your account (some applications are geo-based, for those you will need to setup a VPN in the host machine, some emulators support toggling locale settings so google play will initiate with the targeted country.

Patching the manifest file for the apk to accept user-level CA certificates can be done for HTTPs interception. Android accepts certificates encoded in base64.

Depending on the setup, some emulators has option for setting up a proxy, android system-wide proxy can be used also if host is reachable from the emulated device, some apps might not be proxy-aware so a workaround is using an application that configures a VPN service to HTTPs proxy like SuperProxy, if the host OS isn't reachable from the emulator you can use adb reverse command for exposing a local port from the OS into the localhost of the emulator device.

Root enabled

All Android Emulator instances without Google Play by default are rooted.

Android x86_64 and x86 images can be used with VirtualBox, use VBoxVGA and disable 3D acceleration in order to use the GUI, if not you'll boot directly to cli-mode.

QEMU can be used for emulating ARM but for performance reasons I highly discourage from doing it, use a Mac with Apple Chip or use Android 11 and later android versions with ARM Translation Tools enabled, some apk files aren't shipped with x86 native binaries/libraries for various reasons but ARM translation tools will interpret the ARM opcodes into x86 opcodes (which comes with performance limitations).

Bluestacks 4 supports root-mode, you need to modify the Bluestacks.conf file to enable the root-access globally or per instance.

AVD can be modified to accept mounting /system directory in read-write mode. Also Bluestacks by tweaking the XML descriptor for the VDI files, accesing the VDI files is possible also in the host system. Almost everything can be tweaked with the system directory mounted, including root CA, so you can add your custom CA and it will be trusted by default.

SSL pinning mechanism vary between applications, also Firebase libraries enforce security checks when trying to reach some endpoints , but that's out of scope in this article.

Start fakedns in RENMux. You will need to use an alternative version of the default one shipped with REMnux: this version supports a lot more features including round-robin and DNS-text request commonly used in Cobalt Strike or Sliver implants, it also supports rebinding, when a query does not matches the regular expression stated in the config file it just acts as a proxy and returns the IP address resolved by the gateway's nameserver.

You probably need to practice your soldering skills a little bit before doing this. For dumping NAND memory you can follow up with the next guide: For writing back

https://github.com/Crypt0s/FakeDns
https://mirrors.cloud.tencent.com/centos-cloud/centos/7/images/CentOS-7-x86_64-GenericCloud-2009.qcow2
https://nickb.website/blog/virtualizing-ios-on-apple-silicon
https://nickb.website/projects/vma2pwn
https://worthdoingbadly.com/macappsios/
https://forensics.wiki/jtag_samsung_galaxy_ace_q_%28sgh-i827d%29/
Flow of the malware analysis setup
JTAG wiring with ultra-thin soldering cables.
Oracle VirtualBox official documentation table
https://www.virtualbox.org/manual/ch06.html
https://github.com/nick-botticelli/vma2pwn