Slashdot Mirror


Mystery of Duqu Programming Language Solved

wiredmikey writes "Earlier this month, researchers from Kaspersky Lab reached out to the security and programming community in an effort to help solve a mystery related to 'Duqu,' the Trojan often referred to as 'Son of Stuxnet,' which surfaced in October 2010. The mystery rested in a section of code written an unknown programming language and used in the Duqu Framework, a portion of the Payload DLL used by the Trojan to interact with Command & Control (C&C) servers after the malware infected system. Less than two weeks later, Kaspersky Lab experts now say with a high degree of certainty that the Duqu framework was written using a custom object-oriented extension to C, generally called 'OO C' and compiled with Microsoft Visual Studio Compiler 2008 (MSVC 2008) with special options for optimizing code size and inline expansion."

27 of 97 comments (clear)

  1. If this keeps up.... by ElmoGonzo · · Score: 2

    they may have learn MASM to avoid detection.

  2. Re:Well that was disappointing. by jhoegl · · Score: 5, Funny

    Oh no, Allens do exist. Although he spells it Alan.

  3. Re:Let's See It by Baloroth · · Score: 5, Informative
    --
    "None can love freedom heartily, but good men; the rest love not freedom, but license." --John Milton
  4. Source Code? by deemen · · Score: 3, Insightful

    How did they deduce it was an unknown programming language? By looking at the compiled machine code? How could they tell this wasn't just regular C?

    1. Re:Source Code? by CaptainJeff · · Score: 5, Informative

      Different languages compile down very differently. Indeed, different compilers compile the same source code differently (try comparing GCC output to Visual Studio output and you'll see some obvious differences in how the assembly/machine code is crafted). In this case, there were clear signs of an object-oriented approach (data and functions were located around each other in memory, which is not likely to happen in non-OO languages, etc).

    2. Re:Source Code? by tomhath · · Score: 5, Informative

      It seems they recognized a sequence of instructions that are typical of a class constructor, just not like any class constructor they were familiar with.

    3. Re:Source Code? by Baloroth · · Score: 4, Insightful

      There are certain characteristics to the way C++ behaves (the manner in which you pass parameters, etc). Mainly, through having looked at lots and lots of code samples, they can say what they expect the compiled code to look like. If they know C++ compiled code looks like x, regular C looks like y, and this looked like z, it can't be C. Essentially, the code did things you simply can't do in C++ or C (even Objective C) by itself. The problem is, that method only allows you to compare to known languages. More details here.

      It's basically like identifying an animal by footprint. Once you know a deer leaves a certain kind of footprint, you can identify more deer by examining footprints. But you can't identify an unknown animal that way: if you haven't seen a given footprint before, you won't know what animal it is, only what general characteristics it has (weight, etc.)

      --
      "None can love freedom heartily, but good men; the rest love not freedom, but license." --John Milton
    4. Re:Source Code? by Sarten-X · · Score: 4, Insightful

      Knowing the language and techniques used can speed up analysis of future variants found, because they'll know what patterns to look for first.

      --
      You do not have a moral or legal right to do absolutely anything you want.
    5. Re:Source Code? by robi5 · · Score: 3

      The GP's question was something else - how did they initially tell it was _not_ regular C (as that obviously lacks the fingerprint of OO techniques of C++). Or if it didn't look like regular C or anything else, why didn't they just assume it was written in assembly, or some other rare machine code generating language like Common Lisp?

    6. Re:Source Code? by djdanlib · · Score: 5, Informative

      They did open the lines up for suggestions, and some community members suggested that it looked like OO C. How did they know? They probably had experience using and debugging OO C, if I had to guess. There were also plenty of people who said that it definitely wasn't compiler X or language Y from their own experiences. The article links to this discussion: http://www.securelist.com/en/blog/677/The_mystery_of_Duqu_Framework_solved

      But about discovering the specifics of the truth? It's probably like you alluded to in your comment - fingerprinting the machine code. It would take a while, but you could come up with fingerprints for a great many various compilers and features. You could do that for Common Lisp, too. (In fact, someone DID suggest for them to look at various LISP dialects.) It has taken long enough that such a scenario - having a good library of fingerprints - is believable. Given a scanner with a dictionary of fingerprints, one could reasonably say that you either have hand-assembled machine code made to mimic another language, or that you have code generated by a very specific language and compiler. If nothing in your library of fingerprints matched, assuming you had a good handle on hand-assembling machine code, you could look and see if it smells like such a beast. It would be tremendously laborious to hand-assemble code to make it look like a specific compiler generated it, and why would you do that in the first place? I fail to see the benefit when you could just use that compiler. If you were trying to throw off the analysts with a false positive match, there would still be a ton of mysterious data that still needs examination.

      Think about DNA analysis. We can look at our DNA and determine some chunks of it came from virus, and that some of it is "junk" that serves no purpose.

      Also think about image analysis like OCR or various captcha-breaking software. You can map images to characters with a program, and detect anomalies and known signatures.

      Then there is heuristic antivirus scanning. It knows enough to find some previously unthought-of malicious code, even if it does sometimes generate false positives.

      So why not apply those techniques to machine code, and see what you get? If multiple methods give you similar results, you would be onto something, I imagine.

    7. Re:Source Code? by tlhIngan · · Score: 2

      I suppose that you could possibly tell what compiler was used by the arrangement of the machine code, but I still don't see what the point is. Who cares if it was written in assembly language, C or Atari Basic?

      Because knowing the compiler and version helps analysis - each compiler tends to emit code for the same statement very differently. By knowing the compiler, its idiosyncracies in the way it emits code is understood and it makes reversing the assembly back to C much easier.

      Analyszing assembly code is difficult but if you know how higher layer structures are translated into machine code by the compiler used, it's a lot easier to "decompile" the code.

    8. Re:Source Code? by b4dc0d3r · · Score: 4, Interesting

      To tag along - it's hard to tell data from code, and it helps the decompiling app to detect what is code vs. data if it knows which compiler created it.

      It looks like the original blog used IDA Pro, which has library signatures for different compilers. It can identify functions and auto-comment the code, making disassembly easier. Auto-identify stack variables and keep track of them through lots of PUSH and POP and RETURN X statements, it's quite powerful.

      In this case, IDA probably gave a lot of erroneous warnings or disassembled data or refused to disassemble code, requiring lots of manual work. The classes apparently were done inconsistently, making it hard to even write a plug-in to automatically detect them (scripts exist to identify MSVC objects through their RTTI properties, and do a decent job identifying non-RTTI classes, but this would not work with this code).

      http://www.hex-rays.com/products/ida/index.shtml

      When reverse engineering, and your tool basically says "WTF do I do with this?" it's one of those moments where you want to know how the attacker made it.

      Is it hand-rolled? Or a new attack creation kit that script kiddies can cobble something together using?

      And "unknown language" was not a really good way to describe it. "Unrecognized output" would have been better. The assumption is that a language like C would compile to a C-like syntax, C++ would do things differently. But it could have been just C++ with an unknown compiler.

    9. Re:Source Code? by UnknownSoldier · · Score: 2, Insightful

      I can tell you have never taught another programmer nor learned the benefits of reverse engineering so you can write better code! e.g. I used to work on a professional C/C++ compiler for consoles. Customers would sometimes ONLY provide assembly code and it was your job to figure out why the compiler was generating invalid code.

      Here is an perfect example -- a friend of mine was taking a CS course and the assembly code the prof provided was absolute shit -- a perfect example of how to NOT write code. I cleaned up the assembly code into a properly commented assembly and then provided a mid-level source. By having the 3 versions to compare against my friend was able to get a better handle on reading and writing assembly code, understanding how a compiler would translate a mid-level language to a low level language, learn some good commenting styles, etc.

      First, the original crap assembly provided by the Prof:
      0000 RD R5 Inpt // Read the no. of integers to be added from the input buffer
      0004 MOVI R6 0 // Set a counter to reg-6 and initialize to 0
      0008 MOVI R1 0 // Set the Zero register to its value
      000C MOVI R0 0 // Clear Accumulator
      0010 LDI R10 Inpt // Load address of input buffer into reg 10
      0014 LDI R13 Temp // Load address of temp buffer into reg 13
      0018 LOOP1: ADDI R10 4 // Point to the next address of input buffer by adding 4
      001C RD R11 (R10) // Load the content(data) of address in reg-10 in reg-11
      0020 ST (R13) R11 // Store the data in the address pointed to by reg-13
      0024 ADDI R13 4 // Point to the next address of temp buffer
      0028 ADD I R6 1 // Increment the counter
      002C SLT R8 R6 R5 // Set reg-8 to 1 if reg-6 < reg-5, and 0 otherwise
      0030 BNE R8 R1 LOOP1 // Branch if content of Reg- 8 and Reg-1 is not equal
      0034 MOVI R6 0 // Reset the counter to Zero
      0038 LDI R9 Temp // Loading the address temp into reg 9
      003C LOOP2: LW R7 0(R9) // Loads the content of the address in reg-9 in reg-7 , reg-9 is
      // B-reg . 0 is the offset
      0040 ADD R0 R0 R7 // Add the content of accumulator with reg-7 and stored in acc.
      0044 ADDI R6 1 // Incrementing the counter by 1
      0048

    10. Re:Source Code? by plover · · Score: 3, Informative

      It's only a clue, not an answer. But it's one data point more than they had before. And they need somewhere to start looking for the author.

      OO C is very interesting. C++ developers are a dime a dozen (OK, it's 2012, we're four for a quarter.) And you can't swing a dead cat around here without hitting a C coder. But OO C developers are a subset of a subset of people. Nobody who sets out to write a virus for the first time says "I should download a four year old compiler for a language I know nothing about and start writing my virus." They don't read in their copy of "Virus Creation Lab for Dummies" book where it says to torrent a copy of Visual Studio 2008, then download some GNU OO C framework for it. This is a tool that a limited set of experts uses for their day jobs. Possibly it's something a laid off software engineer would still have on his home machine. It might be code generated by a custom library that some gaming house wrote for their own internal stuff, and that by pattern matching with commercial software products they might be able to find the company of origin. They can go back and figure out who they fired in the last three years, and who now is driving the Ferrari. Maybe there's an OO C Google Group this guy participates in. Maybe he published a bogus "please help me with my homework" question on stackoverflow, and they can match some source code to some object code.

      Or maybe it doesn't help find the guy today, but tomorrow if they haul a potential perpetrator before a judge, they can provide as corroborating evidence to the jury that the person who wrote this code was very specialized in his knowledge of this esoteric tool, and the defendant worked with this tool every day.

      Whatever that clue might be, it could be useful knowledge to someone hunting down the author. Either way, it certainly has value.

      --
      John
    11. Re:Source Code? by plover · · Score: 2

      so bigfoot is real... that's what you're trying to say?

      bigfoot is indeed real, unless declared integer.

      --
      John
  5. Microsoft's Big Chance by JoeCommodore · · Score: 4, Funny

    A well publicized article featuring Microsoft Development products of all things, I think they should use that PR in their Microsoft Visual Studio Ads...

    --
    "Enjoy what you're doing! If it becomes drudgery, you're doing it wrong!" - Jim Butterfield
  6. Re:I don't understand the fuss about the language by Brett+Buck · · Score: 3, Informative

    They are trying to do the forensics. If you know the tools used, you have a much better idea where to look for the people who did it. It was almost certainly NOT a matter of determining what it was doing, they wanted to figure something out that would help them track it back to the source.

  7. Re:infective c? by MadKeithV · · Score: 2

    I'd call it "subjugative C".

  8. Old-school or new-school? by j33px0r · · Score: 4, Insightful

    FTFA:

    Why did the authors of Duqu use OO C? While there is no easy explanation why OO C was used instead of C++ for the Duqu Framework, Kaspersky experts say there are two reasonable causes that support its use [More control over the code & Extreme portability]. These two reasons indicate that the code was written by a team of experienced ‘old-school’ developers

    Why OO C? Because it worked, because they new how to use it, because they knew it would throw Kaspersky for a loop, because they thought it was cool. There are many many reasons and they do not all have to be logical.

    Kaspersky experts might want to consider that the programming wheel of life may have turned and that what was once old-school is now new-school. Whose to say that the under-estimated script-kiddies cannot grow up to be formidable adults with a whole new bag of tricks?

    1. Re:Old-school or new-school? by Anonymous Coward · · Score: 2, Informative

      OO C is not Objective-C.

  9. Re:Let's See It by s.petry · · Score: 2

    This is already done to a large degree, at least with what matters in binary code. The "Script kiddie" tools are extremely well documented. This goes way back in time to when a tool came out called (I hope I'm remembering the name right) VCL or Virus Creation Labratory. It became pretty easy to determine VCL based code and the tool set pretty much evaporated.

    What editor you use is really unimportant. The compiler is what counts, and the compiler never sees your editor.

    --

    -The wise argue that there are few absolutes, the fool argues that there are no probabilities.

  10. Re:Let's See It by Sulphur · · Score: 2

    The 'mystery' involved has nothing to do with the actual code. The actual code itself is probably not really all that advanced.

    The reverse compiler UnStux says the program is called Hello World.

  11. What's the animal by Ukab+the+Great · · Score: 4, Funny

    For O'Reilly's "Mastering Duqu"?

    1. Re:What's the animal by GodfatherofSoul · · Score: 4, Funny

      It's a picture of Palpatine holding onto his nutsack.

      --
      I swear to God...I swear to God! That is NOT how you treat your human!
  12. Sure they do, the Stonecutters hide them by IwantToKeepAnon · · Score: 2

    Who keeps Atlantis off the maps?
    Who keeps the Martians under wraps?
    We Do, We Do...

    --
    "Happy families are all alike; every unhappy family is unhappy in its own way." -- Anna Karenina by Leo Tolstoy
  13. Re:Or the most obvious alternative... by b4dc0d3r · · Score: 2

    It was too consistent to be compiler intrinsics, but not consistent enough to be straight assembly. That's the impression I got from the original blog post.

    No question it would have been possible, but given the rest of the code was compiled in MSVC it made sense that some sort of macro, framework, toolkit, or something was in between the course and the output.

  14. It was smart to use a different language.. by gorrepati · · Score: 2

    Smarter than you think. I remember reading somewhere that US radio controllers in WW-II used a native american language to communicate with each other. No amount of analysis will give you any insight, if the other party is careful to not use any trails. To translate on language into another mechanically requires deep knowledge of both the languages.

    If you rolled your own language with its own grammar, you can be secure in the fact that *even* deep analysis will not yield any clues, not atleast by the current technology. I am not sure such a thing can be even done by a turing machine. People with better knowledge of it are welcome to correct me If I am wrong. All the current technology is concentrated on modifying bits for security, but if you do on a sufficiently high level(aka another language) there is no way to crack it.

    This case however has a achilles heel; you can still modify the binary and see what results would be by running it. After a sufficient number of trials, you should be able to decode it.

    --
    You will never have experience until after you needed it.