Astute Explorer (GCHQ Challenge 5 – 10)

Uncategorized
Continuation for http://www.malwaretech.com/2014/09/astute-explorer-gchq-challenge-1-5.html

Vulnerability
On line 26 the function fails if exactly BLOCK_SIZE is not read, this means if there is data available but less than BLOCK_SIZE is present, or the read fails, the function will return NULL. On failure the function does not free szBuffer so there’s a pretty serious memory leak.


Solution
If the read operation fails, the function should free(szBuf) before returning null, it should also be worth considering handling the event that the read function returns less than BLOCK_SIZE.

Vulnerability
I have a hard time understanding the point of this function (it reads the data to a local buffer, which is then disregarded on return), but I’m sure making the function useful is not part of the assignment. The problem exists on line 1009; assuming GetFromInput can read more than 1 byte at a time, it can still exceed MAX_RECEIVE. For example: if MAX_RECEIVE is 10 and GetFromInput reads 20 bytes, siBytesReceived is going to be 20, the loop will exit but the data will have already been written and siBytesRecieved will already have exeeded the limit. There’s also the problem that if GetFromInput can fail or return less than MAX_RECEIVE, the loop has no way of checking this and will continue looping (possibly infinitely).


Solution
The best idea would be to implement a parameter in GetFromInput that allows the user to specify the maximum amount of data to read in a single call. The function can then calculate how much data is left before MAX_RECEIVE is hit and specify a limit to prevent more than that from being read.

Vulnerability
I wasn’t able to find any vulnerabilities here, unless the user supplies invalid pointers to the function (it should be their job to check they’re valid, not the functions). On line 45 the loop will decrement len until it’s 0 then exit, as a result it will always return 0.


Solution
Make a copy of len and then decrement the copy.

Vulnerability
If the aim of this code was to use obscure nested if/else statements to make code auditing almost impossible, then the programmer (who probably works on the security team at oracle) did a great job. I’m really not sure what’s going on with the code or what err is and where it’s set. Assuming err is an actual variable and not pseudo-code a runtime library function like malloc wouldn’t set it; if malloc returns NULL the application is going to try and use that null pointer. There’s also the issue of the use-after-free on line 52 (On error ptr is freed and abrt is set, which means logError will always be passed ptr after it has been freed).


Solution
Stop hiring college kids.

Vulnerability
This piece of code should be instantly recognizable as the apple SSL bug from February (it was all over the news and security sites for months). The extra goto fail; on line 408 means the application will always skip to the cleanup code without setting err, as a result the client doesn’t verify that server owns the private key matching the certificate, which opens the client up to MITM attacks.


Solution
Remove the extra goto fail;

Conclusion

Although the challenges are fun, they are very confusing at times. Most of the code has no context given, leaving the player making massive assumptions about how the code works (I can’t think of a real world scenario where you would have to find vulnerabilities in tiny snippet of code without knowing what they do or how the application uses them). Almost all of the vulnerabilities in this article could be non existent if the application performs check prior to calling the snippets, or if assumptions made about the imaginary functions they call are wrong.
Uncategorized
3
Best Languages to Learn for Malware Analysis

One of the most common questions I’m asked is “what programming language(s) should I learn to get into malware analysis/reverse engineering”, to answer this question I’m going to write about the top 3 languages which I’ve personally found most useful. I’ll focus on native malware (malware which does not require …

Uncategorized
2
Investigating Command and Control Infrastructure (Emotet)

Although the majority of botnets still use a basic client-server model, with most relying on HTTP servers to receive commands, many prominent threats now use more advanced infrastructure to evade endpoint blacklisting and be resilient to take-down. In this article I will go through and explain my process of identifying …

Uncategorized
10
Creating a Simple Free Malware Analysis Environment

Computer Requirements: A CPU with AMD-V or Intel VT-x support (pretty much any modern CPU). 4 GB RAM (more is better). Make sure Virtualization (AMD-V or Intel VT-x) is enabled in the BIOS. To do this, you’ll need to google “enable virtualization” along with your bios or motherboard version, then …