The cloud incident response company Mitiga has published a whitepaper regarding a security flaw by design; allowing attackers to read and write data, effectively gaining full control over the targeted virtual machine instances. The company describes the security issue as “dangerous functionality”.
Not a usual TCP/IP port
According to Mitiga, the getSerialPortOutput API, which lets users retrieve output from serial ports for debugging systems, is not configured as TCP/IP ports in Linux systems; they are stored as files in /dev/ttySX (X means between 0 and 3). Google Cloud Platform exposes many APIs and getSerialPortOutput is one of them, for debugging systems.
The cloud incident response experts of Mitiga have seen the opportunity and tried creating a virtual machine in Google Cloud Platform that is completely firewalled for all inbound and outbound traffic, and continuously writing data to the serial ports. After that, the experts managed to read the data from the serial port. This particular traffic has been reflected as GOOGLE_INTERNAL in Google Cloud Platform’s network monitoring interface. But when the API calls are checked, the abuse of the getSerialPortOutput API can be seen.
While the getSerialPortOutput API alone creates a security risk, accompanying it with setMetadata API makes it even worse; allowing a potential attacker to write data to the system. Those two combined allow both reading and writing data on the VM instance which can effectively end up to a complete takeover by leveraging. And, a Google Cloud Platform credential is the only requirement for achieving it. Mitiga has envisioned two potential attack scenarios.
Attack scenario #1
- An attacker gains access to GCP credentials with appropriate API permissions for both setMetadata and getSerialPortOutput on one or more VMs
- Using traditional network-based methods of lateral movement, the attacker installs malware on the system that communicates using the GCP API
- The attacker sends commands to the victim machine by inserting them into custom metadata using a predetermined key
- The victim system continually reads the key looking for commands; when one is found, the command is executed, and the output is sent to a predetermined serial port
- The adversary continually reads from the serial port and waits to receive the output of the command
Attack scenario #2
- An attacker gains access to GCP credentials with appropriate API permissions for setMetadata, getSerialPortOutput, and reset (that is, compute.instances.reset permissions) on one or more VMs
- The adversary inserts the API-abusing malware into the victim’s system user data
- The adversary “resets” the system, forcing a reboot. Upon reboot, the system will run user data as the administrative user
- The attacker sends commands to the victim machine by inserting them into custom metadata using a predetermined key
- The victim system continually reads the key looking for commands; when one is found, the command is executed, and the output is sent to a predetermined serial port
- The adversary continually reads from the serial port and waits to receive the output of the command
Mitiga also advises the Google Cloud Platform users to take the following actions for better security:
- Don’t use built-in roles. Instead, assign specific permissions as needed to users in adherence with the principle of least privilege.
- Evaluate whether dangerous functionalities such as setMetadata (and similar APIs such as setCommonInstanceMetadata) are necessary. If not, ensure that cloud credentials are configured to lack such permissions.
- Ensure systems only allow remote access via approved remote administration methods, such as SSH or RDP.
- Where possible, run applications or services using low-privileged users. Where possible, harden systems such that service accounts cannot write to serial ports.
- If you do not use the compute.instances.getSerialPortOutput feature, consider adding an IAM deny policy for Compute users for that permission.