HNHacker News
TopNewBestAskShowJobs

alexkus

926 karma · joined July 1, 2012

submissionscomments
alexkus··on How We Decoded Some Nasty Multi-Level Encoded Malware
OK, next pick a word you think will be in the output (it's php code so I'll guess the word "function" might be common). You then XOR each 8 character substring with "function", taking note of the position of the substring within the 12 character groupings, and count the resulting characters:-

    $ ./4.pl 12 "function"
    POS: 0: S->78 T->71 U->69
    POS: 1: j->76 l->64 m->59
    POS: 2: L->73 J->67 W->64
    POS: 3: V->65 Q->55 P->49
    POS: 4: m->68 v->50 `->49
    POS: 5: E->54 C->52 O->48
    POS: 6: 6->57 0->56 1->56
    POS: 7: u->56 t->54 x->50
    POS: 8: k->76 l->70 m->66
    POS: 9: R->69 U->57 H->51
    POS: 10: _->69 Y->62 ^->54
    POS: 11: j->70 m->59 l->55
Note that the correct key in each position is usually either the first or second possibility, but there are some times when it isn't there at all.

(It's better if you give it a longer string, if I give it "function " with the trailing space then it gets 9/12 as the most popular, 2/12 as second most popular and the remaining one as the third most popular. There are even better choices, see below, but I chose to go with this as it helps show how to continue with non-perfect information).

Next I knocked up a quick program to allow me to try different keys to decrypt it, it prints out the code in blocks of the appropriate keylength so it's easy to see if a specific character position is correct or not. The program takes various commands from stdin (k = print key, S = set key, s = set individual key character, p = print in keylength sized blocks, P = print entire decrypted block):-

    $ ./5.pl 12
    k
    key is aaaaaaaaaaaa
    S SjLVmE6ukR_j
    key is now SjLVmE6ukR_j
    p
    /)abjutt uy
    stcm&vauiadl
    es\12i`(!Gisue
    t("_UERQER/)
    {$YCIOKNE= $
    HTRPYCOHKIC_
    VATS=$_WOSR=
    &$NTRP_WOSR_
    VATS=$_@ET;&
    $HRTV_GBT_PA
    RS=}\12//cie&w
    itn crrhr
    `u
    ncriin \127_doe
    ($k)}@hbadcr
    ('NTRP/6.1&5
    ...
Getting there, but still a way off. There are a few strings like COIKOE[#n]= which could be COOKIE, so we fiddle with the 3rd column and see some interesting things in the output:-

    s 2 J
    p
    ...
    elseof(oasYp
    ...
    COOKOE[#n]=
    ...
    systcm(#c)=}
    ...
Neither of the other two choices for column 4 produce the right string, but it's simple enough to find the ciphertext and find what is needed to make elseof -> elseif, COOKOE -> COOKIE and systcm -> system. It's k:-

    s 4 k
    k
    key is SjJVkE6ukR_j
    p
    ...
    elseif(oasYp
    ...
    COOKIE[#n]=
    ...
    system(#c)=}
We carry on doing this based on more clues like this (it gets easier and easier!) and we end up with:-

    k
    key is SjJVkE6rkRYj
    p
    //adjust sy
    stem variabl
    es
    if(!@isse
    t($_SERVER))
    {$_COOKIE=&$
    HTTP_COOKIE_
    VARS;$_POST=
    ...
And printing out the entire decrypted buffer without extra linebreaks every 12 chars gives:-

    P
    
    //adjust system variables
    if(!@isset($_SERVER)){$_COOKIE=&$HTTP_COOKIE_VARS;$_POST=&$HTTP_POST_VARS;$_GET=&$HTTP_GET_VARS;}
    //die with error
    function x_die($m){@header('HTTP/1.1 500 '.$m);@die();}
    //check if we can exec
    define('has_passthru',@function_exists('passthru'));
    define('has_system',@function_exists('system'));
    define('has_shell_exec',@function_exists('shell_exec'));
    define('has_popen',@function_exists('popen'));
    ...
Interestingly, trying known plaintext of "define" gives us the entire key as the most probably choice first time:-

    $ ./4.pl 12 "define"
    POS: 0: S->75 X->56 _->54
    POS: 1: j->77 a->51 f->47
    POS: 2: J->71 A->55 F->49
    POS: 3: V->61 ]->44 Z->43
    POS: 4: k->59 h->43 *->40
    POS: 5: E->55 8->48 4->44
    POS: 6: 6->52 w->47 <->43
    POS: 7: r->55 d->43 s->40
    POS: 8: k->75 `->51 g->51
    POS: 9: R->59 Y->55 X->49
    POS: 10: Y->69 R->49 U->47
    POS: 11: j->61 `->43 m->42
alexkus··on How We Decoded Some Nasty Multi-Level Encoded Malware
But you're just looking for the text being in a certain range of characters. The first stage is determining the key length, you can do this by looking at the number of different character values in positions 1,2,3... then 1,3,5,... and 2,4,6,... then 1,4,7,... etc.

    keylength=1 127
    keylength=2 114 116
    keylength=3 107 102 106
    keylength=4 78 94 98 103
    keylength=5 111 118 115 114 119
    keylength=6 81 71 81 77 79 77
    keylength=7 104 112 110 104 110 110 109
    keylength=8 67 85 86 94 68 91 83 86
    keylength=9 87 86 86 90 92 85 83 85 82
    keylength=10 91 97 86 89 90 88 90 90 92 97
    keylength=11 90 101 102 98 99 93 100 100 100 95 93
    keylength=12 45 45 46 53 47 46 41 47 47 51 50 47
    keylength=13 89 85 100 90 89 91 94 95 82 90 86 88 92
    keylength=14 83 84 85 88 82 81 77 72 82 85 73 81 82 86
    keylength=15 73 81 72 76 76 70 75 73 74 72 77 76 73 71 73
    keylength=16 56 68 71 80 60 73 64 73 58 71 70 76 57 76 66 68
    keylength=17 81 86 82 74 77 82 85 87 81 87 78 84 77 77 79 80 82
    keylength=18 59 55 59 55 61 56 59 55 57 59 55 62 62 57 60 58 56 59
    keylength=19 77 80 80 77 71 89 78 76 73 74 68 80 80 80 74 76 78 79 72
The stand out line from that is keylength=12 as it provides a local minima for the number of different characters.

Having a good idea of the key length you can look at which of the possible 256 values for each position of the key produce the top numbers of printable characters. A quick perl script to do this gives:-

    POSS:0: n=211 chars=FHLRSUVZ]
    POSS:1: n=209 chars=cdjkouwx~
    POSS:2: n=208 chars=DIJKLORUW^_
    POSS:3: n=209 chars=BIKSVW
    POSS:4: n=206 chars=bejkntvy~
    POSS:5: n=210 chars=@CDEFKQXZ
    POSS:6: n=208 chars="#)+.023678>?
    POSS:7: n=206 chars=fgmorswz|
    POSS:8: n=208 chars=behjknt~
    POSS:9: n=205 chars=GMORSTW\
    POSS:10: n=207 chars=FLWXY[\
    POSS:11: n=208 chars=cdjkoux~
You'll note that the actual key (SjJVkE6rkRYj) is present in this output. I'll carry on with this if I get a chance tomorrow.
alexkus··on A conundrum for a sed wizard
That was my original suggestion (awaiting moderation):-

    head -35185221 infile.xml > tmp.xml
    echo "<load address=’11c1385b’ size=’08’ />" >> tmp.xml
    tail -n +35185223 infile.xml >> tmp.xml
alexkus··on A conundrum for a sed wizard
Works fine for me:-

    $ cat infile.xml
    1
    <load address=’11c1�����ze=’08′ />
    3
    $ cat seddy.sed
    2s@^.*$@<load address=’11c1385b’ size=’08’ />@
    p
    $ sed -n -f seddy.sed infile.xml
    1
    <load address=’11c1385b’ size=’08’ />
    3
    $
So I'm guessing it's locale related (LC_CTYPE is en_GB.UTF-8 for me), or the string that forms his corrupt line is different from what was pasted. The output of:-

    sed -n '35185222p' infile.xml | hexdump -b
would help in that regard.
alexkus··on How can C Programs be so Reliable? (2008)
Exactly. Writing libraries in C means you have to be much more strict than simple throwaway single execution binaries.

What our company has ended up doing is wrappering most low level functions with the common code around it. For example, fopen() may fail and return EINTR if the process received a signal just as it was opening a file (we use signals to tell processes to reread their config so this does happen albeit rarely) so the wrapper calls fopen() in a do/while loop that repeats on EINTR (and a few others). It saves you from writing the same 50 odd lines each time you want to open a simply open a file.

In an exception led world you'd still have to do the same thing, but with different syntactic sugar. You can't just fail and bubble up the exception without dealing with the few exceptions you must deal with and repeat, and you can't just repeat on every exception as most will just fail again and again. You end up writing code to do the same thing just in different styles.

Checking the return values of every single function call, and dealing with it, can make the code verbose (one line of code and then 10+ lines dealing with errors) but it is worth it in the end for bullet proof programs. Also code where you have to undo all of the work already done in the function up until that point, which can get a little tedious, i.e.:-

    APP_RET makefoo( char *fname )
    {
      char *foo,*bar;
      thingy_t *qux;
      size_t len;
    
      ASSERT( fname );
    
      len = strlen( fname );
    
      foo = malloc( len+1 );
      if( foo == NULL ) {
         return( ENOMEM );
      }
      bar = malloc( (2*len)+1 );
      if( bar == NULL ) {
         free( foo );
         return( ENOMEM );
      }
      qux = malloc( sizeof( thingy_t ) );
      if( qux == NULL ) {
         free( foo );
         free( bar );
         return( ENOMEM );
      }
      ...
      return( APP_OK );
    }
It's the job of anything calling makefoo() to deal with the various errors it can return, but the idea is to return the minimum number of unique error codes as necessary to avoid proliferation of error codes to the higher and higher functions. Many calling functions will only really care about success or failure, and will just use the return code to log out the reason for the failure.

The wrappers help deal with many situations; did fwrite() write all of the bytes we wanted or just some of them? Well, our wrapper around fwrite will handle short writes and repeat the call depending on the result of ferror().

alexkus··on Bitcoin Mining Uses $15 Million's Worth Of Electricity Every Day?
Bitcoin may end up a big flop[1] in the end (who knows) but without trying it there's no way to know, so expending all of this time and effort isn't wasted.

Similar to scientific experimentation; the outcome, regardless of success or failure, is useful in itself.

1. For the majority, there are obviously some people for whom it has been a roaring (financial) success.

alexkus··on Bitcoin Mining Uses $15 Million's Worth Of Electricity Every Day?
Interesting question.

For the same hashrate then less electricity is going to be used given that ASIC mining is far more efficient that GPU mining.

But the overall hashrate is still on an ever upward trend.

I guess it depends on how many people have quit CPU and GPU mining altogether, or whether there are still lots of forgotten machines still burning away contributing very little (in comparison).

alexkus··on Bitcoin Mining Uses $15 Million's Worth Of Electricity Every Day?
Bitcoin mining could use any amount of electricity given that the block difficulty adjusts to the prevailing hashrate.

If more people pile in to mining then the difficulty increases and total $$$ spent on electricity will increase. Conversely if mining hashrate declines then difficulty is decreased to compensate.

I'm not sure how the difficulty adjustment would cope with a severe and abrupt change in mining hashrate (take it to the extreme and imagine the hashrate drops to 1/1000th of what it is now, there are going to be a lot of unconfirmed transactions out there).

alexkus··on Anatomy of a $40M+ Bitcoin heist
Article says 5500BTC.
alexkus··on Europe's Ryanair vs. America's Southwest
> Some digging and there are advance tickets to Ely available for £5, and Ely to Stansted airport is £14 for a regular ticket.

Yes, there are plenty of cases where you can find cheaper tickets by "splitting" the journey. Many can be found with sites like http://www.splityourticket.co.uk/ but not in this particular case, good spot on splitting at Ely.

Ah, that particular case is because there are no advance fares for the train between Ely and Stansted Airport, so most of the train ticket sites don't bother to look for advance fares for any of the legs.

alexkus··on I found Prezi's source code
https://bugcrowd.com/list-of-bug-bounty-programs
alexkus··on F1 2014: All aboard the 'power train' - new rules explained
Diesel also has 1.17 times the energy density (by volume) of petrol/gasoline.
alexkus··on F1 2014: All aboard the 'power train' - new rules explained
Suzuka has a bridge:-

https://en.wikipedia.org/wiki/Suzuka_Circuit

alexkus··on Europe's Ryanair vs. America's Southwest
I think he/she was talking about the train tickets.

Walk-up/on-the-day fares for train tickets in the UK are very expensive.

Picking London to Edinburgh as an example (~400 miles in ~4.5 hours) you'd pay £125 off-peak and £150 peak fare for a train today (there are generally 2 an hour).

Booking in advance (up to ~84 days in advance) you can get those same tickets as cheap as £24 but you're tied to a specific departure time/date (and changing date/time can be expensive).

alexkus··on Citi's Curious Password Handling
> Are there hash algorithms which are upper and lower case agnostic? Or should I assume that they store a hash of both the original password form and a lower cased version?

The hash may not be case insensitive, but I've seen plenty of code in and around password handling code that forces all letters to be lower/upper case prior to hashing.

(There's rarely ever any explanation as to why, nor anyone still around who admits to writing that code.)

alexkus··on Toast Sandwich
By the looks of it the first layer of steak is made up of pieces of two steaks.
alexkus··on Why are there so many tunnels under London?
> The difference between America and England is that the Americans think 100 years is a long time, whereas the English think 100 miles is a long way.

Having lived in both countries I think that's a good way of thinking about it (for the average person.)

(Obviously individuals will differ; 100 miles is a half day cycle ride for me so I don't think of it as that long a way.)

alexkus··on Why are there so many tunnels under London?
It doesn't exist.

There is a tunnel in Aber that was used to store valuables (Crown jewels, etc) during WWII, but it's certainly not a tunnel all the way from London.

Source: http://www.everythingaberystwyth.co.uk/aberystwyth-fact-of-t...

alexkus··on Signholder Receives Over $24,000 In Bitcoin After QR Code Appears On ESPN
1HiMoM...

wonder how long he waited to try and get that as 1HiMom... before giving up

alexkus··on Germans in a Nutshell
Not just the meat that gets regularly inspected. Hence the "poo shelf" on many German toilets.
alexkus··on Once-great SSD manufacturer OCZ filing for bankruptcy
Their IPO was two months ago yesterday. September 27th 2013.
alexkus··on A JavaScript parser and interpreter written in Go
...we accept Bitcoin too!
alexkus··on Farming hard drives: 2 years and $1M later
Untested backups don't exist either.

There are several horror stories of people going to their offsite tape backups to restore some lost data only to find that their backups didn't work due to a malfunctioning tape drive.

Other stories about encrypted backups where the decryption key is lost (backup data is encrypted with a randomly chosen "session" key, session key is encrypted using a public key, no-one could find the appropriate private key to decrypt the session key.

etc...

alexkus··on Farming hard drives: 2 years and $1M later
If the only instance of a thing is on your "back-up" drive then it isn't a back-up.
alexkus··on How Hacker News ranking really works: scoring, controversy, and penalties
If someone wants a 'weekend project': an interesting browser plugin would be one that undoes the effect of the penalties and reorders the page accordingly, it could even allow the user to choose the level of penalties enforced against stories in their view in case they did want some to disappear off the front page.
alexkus··on How Hacker News ranking really works: scoring, controversy, and penalties
> Not sure why the HN submission didn't link to the original post

It's not a duplicate (as far as HN is concerned), the URLs are slightly different.

alexkus··on Ask HN: How do you become a morning person?
My night owl status was cured by having children. I no longer have a choice about what time I wake up.

Semi-seriously though, there's nothing like having to fit something immovable into your schedule for sorting things like this out.

alexkus··on LG says it will push out firmware update for spy TVs, but no apologies
LMGTFY: http://www.urbandictionary.com/define.php?term=le+sigh
alexkus··on AsicMiner's Immersion Cooling Mining Facility
Steady income (as an ASCI manufacturer) vs a gamble (as the consumer).

Do you want to be the punter or the house?

alexkus··on Understanding ARM Assembly, Part 1
Brings back a lot of memories of assembly programming on the Acorn Archimedes[1] (ARM2 core) back in the early 90s.

It certainly was a revelation (all those registers!) after years of messing around with Z80/6502/80[123]?86.

1. https://en.wikipedia.org/wiki/Acorn_Archimedes

← PreviousPage 3 of 14Next →